Skip to content

Commit bafb963

Browse files
authored
Enable linker dead stripping on Darwin (#22839)
* Enable linker dead stripping on Darwin See r://48283130. This shaves 6MB+ off of swift and SourceKitService, 26.8MB off of swift-llvm-opt, 29.4MB off sil-passpipeline-dumper, etc. * Disable dead stripping in Debug builds It can hide linker errors caused by dependency cycles.
1 parent 1f7acb6 commit bafb963

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed

cmake/modules/AddSwift.cmake

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -488,6 +488,20 @@ function(_add_variant_link_flags)
488488
endif()
489489
endif()
490490

491+
# Enable dead stripping. Portions of this logic were copied from llvm's
492+
# `add_link_opts` function (which, perhaps, should have been used here in the
493+
# first place, but at this point it's hard to say whether that's feasible).
494+
#
495+
# TODO: Evaluate/enable -f{function,data}-sections --gc-sections for bfd,
496+
# gold, and lld.
497+
if(NOT CMAKE_BUILD_TYPE STREQUAL Debug)
498+
if(${CMAKE_SYSTEM_NAME} MATCHES "Darwin")
499+
# See rdar://48283130: This gives 6MB+ size reductions for swift and
500+
# SourceKitService, and much larger size reductions for sil-opt etc.
501+
list(APPEND result "-Wl,-dead_strip")
502+
endif()
503+
endif()
504+
491505
set("${LFLAGS_RESULT_VAR_NAME}" "${result}" PARENT_SCOPE)
492506
set("${LFLAGS_LINK_LIBRARIES_VAR_NAME}" "${link_libraries}" PARENT_SCOPE)
493507
set("${LFLAGS_LIBRARY_SEARCH_DIRECTORIES_VAR_NAME}" "${library_search_directories}" PARENT_SCOPE)

0 commit comments

Comments
 (0)