Skip to content

Commit

Permalink
Enable GC sections and ICF for binary distributions to reduce file size
Browse files Browse the repository at this point in the history
  • Loading branch information
rui314 committed Oct 6, 2024
1 parent 3070e79 commit 3441cbb
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 6 deletions.
18 changes: 12 additions & 6 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -50,12 +50,6 @@ include(CMakeDependentOption)
include(CheckSymbolExists)
include(GNUInstallDirs)

# Build mold itself using mold if -DMOLD_USE_MOLD=ON
option(MOLD_USE_MOLD "Use mold to build mold" OFF)
if(MOLD_USE_MOLD)
add_link_options(-fuse-ld=mold -Wl,--gdb-index)
endif()

add_executable(mold)
target_compile_features(mold PRIVATE cxx_std_20)

Expand All @@ -65,11 +59,23 @@ else()
target_link_libraries(mold PRIVATE ${CMAKE_DL_LIBS})
endif()

# Build mold itself using mold if -DMOLD_USE_MOLD=ON
option(MOLD_USE_MOLD "Use mold to build mold" OFF)
if(MOLD_USE_MOLD)
target_link_options(mold PRIVATE -fuse-ld=mold -Wl,--gdb-index)

if(CMAKE_BUILD_TYPE STREQUAL "Release")
target_link_options(mold PRIVATE -Wl,--gc-sections,--icf=safe)
endif()
endif()

if(NOT "${CMAKE_CXX_COMPILER_FRONTEND_VARIANT}" STREQUAL "MSVC")
target_compile_options(mold PRIVATE
-fno-exceptions
-fno-unwind-tables
-fno-asynchronous-unwind-tables
-ffunction-sections
-fdata-sections
-Wall
-Wextra
-Wno-sign-compare
Expand Down
1 change: 1 addition & 0 deletions dist.sh
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,7 @@ cd /build
cmake -DCMAKE_BUILD_TYPE=Release -DMOLD_MOSTLY_STATIC=On /mold
cmake --build . -j\$(nproc)
mv mold mold2
cmake -DCMAKE_EXE_LINKER_FLAGS='-Wl,--gc-sections,--icf=safe' .
./mold2 -run cmake --build . -j\$(nproc)
ctest -j\$(nproc)
cmake --install . --prefix $dest --strip
Expand Down

0 comments on commit 3441cbb

Please sign in to comment.