Skip to content

Enable linker dead stripping on Darwin #22839

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Feb 25, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions cmake/modules/AddSwift.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -488,6 +488,20 @@ function(_add_variant_link_flags)
endif()
endif()

# Enable dead stripping. Portions of this logic were copied from llvm's
# `add_link_opts` function (which, perhaps, should have been used here in the
# first place, but at this point it's hard to say whether that's feasible).
#
# TODO: Evaluate/enable -f{function,data}-sections --gc-sections for bfd,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

BFD is an unsupported linker (it cannot handle the protected semantics needed for swift)

# gold, and lld.
if(NOT CMAKE_BUILD_TYPE STREQUAL Debug)
if(${CMAKE_SYSTEM_NAME} MATCHES "Darwin")
# See rdar://48283130: This gives 6MB+ size reductions for swift and
# SourceKitService, and much larger size reductions for sil-opt etc.
list(APPEND result "-Wl,-dead_strip")
endif()
endif()

set("${LFLAGS_RESULT_VAR_NAME}" "${result}" PARENT_SCOPE)
set("${LFLAGS_LINK_LIBRARIES_VAR_NAME}" "${link_libraries}" PARENT_SCOPE)
set("${LFLAGS_LIBRARY_SEARCH_DIRECTORIES_VAR_NAME}" "${library_search_directories}" PARENT_SCOPE)
Expand Down