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

Conversation

vedantk
Copy link
Contributor

@vedantk vedantk commented Feb 23, 2019

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.

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.
@vedantk
Copy link
Contributor Author

vedantk commented Feb 23, 2019

@swift-ci smoke test

@vedantk
Copy link
Contributor Author

vedantk commented Feb 23, 2019

@akyrtzi Do you know of any build/link issues with plugins that could be triggered by dead stripping? Or are all those problems resolved at this point?

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")
Copy link
Contributor

Choose a reason for hiding this comment

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

add_link_opts only adds the option for a release build. It may be useful to avoid stripping in debug builds because stripping can hide linker errors caused by dependency cycles.
Or try to just delegate to add_link_opts ?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'll add a Debug check. It'll take extensive refactoring to pull in the definition of add_link_opts here (just including AddLLVM breaks the swift build due to conflicting variables).

Copy link
Contributor

Choose a reason for hiding this comment

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

Hmm, I'm certainly no CMake expert but just want to point out that I've added a call to add_link_opts in here:
https://github.com/apple/swift/blob/34f8670d2a8d1ce05c6da32da8e484e543e8ec5e/tools/libSwiftSyntaxParser/CMakeLists.txt#L21
without issues, but maybe this particular file is problematic for it.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah, add_link_opts requires that a target exists (it sets properties on the target directly). Most of swift's cmake logic collects properties, and then creates a target.

Maybe we should just factor out the core logic in add_link_opts into a helper which returns a list (in llvm), then use that here?

@akyrtzi
Copy link
Contributor

akyrtzi commented Feb 23, 2019

@akyrtzi Do you know of any build/link issues with plugins that could be triggered by dead stripping? Or are all those problems resolved at this point?

I'm not aware of any such problems, AFAIK we don't support loading plugins from swift or SourceKitService.

It can hide linker errors caused by dependency cycles.
@vedantk
Copy link
Contributor Author

vedantk commented Feb 23, 2019

@swift-ci smoke test

Copy link
Member

@compnerd compnerd left a comment

Choose a reason for hiding this comment

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

Amazing!

# `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)

@vedantk
Copy link
Contributor Author

vedantk commented Feb 25, 2019

@swift-ci smoke test Linux platform

@vedantk vedantk merged commit bafb963 into swiftlang:master Feb 25, 2019
@vedantk vedantk deleted the dead-strip branch February 25, 2019 18:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants