Skip to content

Commit 26c7769

Browse files
committed
Use LTO to reduce binary size of runtime
240k -> 192k on my machine.
1 parent 4ff495c commit 26c7769

File tree

1 file changed

+3
-2
lines changed

1 file changed

+3
-2
lines changed

src/build-runtime.cmake

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,15 +22,15 @@ else()
2222
endif()
2323

2424
set(runtime_cflags
25-
-std=c99 -ffunction-sections -fdata-sections
25+
-std=c99 -ffunction-sections -fdata-sections -flto
2626
-DGIT_COMMIT=\\"${GIT_COMMIT}\\"
2727
-I${squashfuse_INCLUDE_DIRS}
2828
-I${PROJECT_SOURCE_DIR}/include
2929
-I${PROJECT_SOURCE_DIR}/lib/libappimage/include
3030
-I${PROJECT_SOURCE_DIR}/lib/libappimage/src/libappimage_hashlib/include
3131
${DEPENDENCIES_CFLAGS}
3232
)
33-
set(runtime_ldflags -s -Wl,--gc-sections ${DEPENDENCIES_LDFLAGS})
33+
set(runtime_ldflags -s -Wl,--gc-sections -flto ${DEPENDENCIES_LDFLAGS})
3434

3535
if(BUILD_DEBUG)
3636
message(WARNING "Debug build, adding debug information")
@@ -110,6 +110,7 @@ add_executable(runtime ${CMAKE_CURRENT_BINARY_DIR}/runtime.4.o notify.c)
110110
# CMake gets confused by the .o object, therefore we need to tell it that it shall link everything using the C compiler
111111
set_property(TARGET runtime PROPERTY LINKER_LANGUAGE C)
112112
target_link_libraries(runtime PRIVATE libsquashfuse dl xz libzlib pthread libappimage_shared libappimage_hashlib)
113+
target_link_options(runtime PRIVATE ${runtime_ldflags})
113114
target_include_directories(runtime PRIVATE ${PROJECT_SOURCE_DIR}/include)
114115

115116
if(BUILD_DEBUG)

0 commit comments

Comments
 (0)