-
Notifications
You must be signed in to change notification settings - Fork 1.3k
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
Add -dead_strip / --gc-sections for release builds #4135
Add -dead_strip / --gc-sections for release builds #4135
Conversation
thanks @keith this makes sense based on what @kubamracek was saying on another thread. couple of questions / ideas:
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
CC: @kubamracek (I believe Kuba was involved in the changes for the metadata preservation).
b0b2d01
to
b175e94
Compare
A flag sounds fine to me, would folks prefer opt-in or opt-out? I'm not sure how much testing an opt-in flag would get at this point, but I'll defer to you all for your risk preference. I did test this on Linux and I think |
@keith I would go with opt out given that @kubamracek believes this is safe enough. we need @compnerd init on Windows too. lmk if you need guidance on how to expose a flag and pipe it through the different layers |
I'm definitely supportive of this, I'm not aware of any problems/bugs in this area (but TBH I have mostly only worked with Darwin / Mach-O / ld64, and almost not at all with other platforms / file formats / linkers). I am even supportive in making dead stripping be the default behavior, but I want to point out that there are cases where dead-stripping will affect a program -- and mostly it's "shady" things like dlsym'ing for an otherwise unused symbol, and probably only really affects C code and not Swift code. Before we make dead-stripping the default, we should acknowledge that stuff like this might be affected. I personally think it's the right choice (and programs relying on not-dead-stripping would either need to opt out, or fix their code, there's some simple options like |
its also worth mentioning that at the current state of things, |
Updated with a flag! |
Please do a test build on Windows just to make sure that things don't break. |
@compnerd @shahmishal is there a way to trigger CI for Windows for this change? maybe a dummy PR with cross-repo test? |
@swift-ci please smoke test |
Hopefully soon we will be able to from SwiftPM, however for now you will have to do cross PR to trigger Windows testing. |
thanks @shahmishal created swiftlang/swift#41374 what is the trigger phrase for Windows verification? |
|
@shahmishal does that now trigger a different job? There are two separate builds - the |
this is pending verification on Windows, see discussion on swiftlang/swift#41374 |
@keith in the meantime maybe add an entry in the change log to document the change? |
In the past it was unsafe to pass -dead_strip because there was some swift metadata that could be stripped. It seems that at this point all of those cases are either fixed or marked as @llvm.used, so passing these flags should safely reduce binary size in some cases. If there are other cases where this isn't safe we should likely annotate them as @llvm.used anyways. Related: https://bugs.swift.org/browse/SR-521 swiftlang#215
cc153ab
to
2afc913
Compare
6e3ed66
to
9cc0b75
Compare
@swift-ci please smoke test |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
pending verification on Windows, see discussion on swiftlang/swift#41374
@swift-ci please smoke test |
:-( it seems that something isn't really correct:
Note that the |
I inverted the boolean when we renamed from disable -> enable, fixed, sorry about that! It didn't break the tests because it was inverted there too after that change. Is there a way to test the actual flag behavior (like lit in LLVM)? |
@swift-ci please smoke test |
Built and ran the calculator demo, seems to be fine, and the linker was also fine with the flags. I think that this should be fine from the Windows side at least. And the command line indicates that the flag is now there. |
thanks for testing! |
thanks @keith |
Thanks all! |
@keith: do you remember which linkers and versions did you use to test in Linux ELF? With a recent LLD you have swiftlang/llvm-project@6d2d3bd which enables GC of the start/stop symbols, which seems to be affecting the Swift metadata section symbols in our setup. |
Interesting, I just tried the defaults, do you have a repro case I can debug with? |
Not with the upstream build system, sadly. I was just trying to compile a newer SwiftPM with a recently compiled SwiftPM that includes this (and pointing to a quite recent LLD) and started seeing these linking problems about the I will try to keep looking. For the time being I can work around it with |
I think the assumption from folks here was generally that things should be correctly referenced / non-strippable today, so if that's not the case we may have to temporarily reconsider this default unless we can come up with a fix for those |
I just hit this when building the latest Mar. 9 trunk source snapshot of the toolchain natively on my Android AArch64 phone that uses lld, which is fixed by disabling this flag by default in the SPM source. This may be a recent lld regression, which this new flag triggers for us on Android, as this guy reported the issue on linux with lld 13, unrelated to this SPM flag, on the forum last month, or maybe lld or clang 13 enabled this flag by default all of a sudden on linux too. Strangely, my Android CI, which cross-compiles an Android SDK and several packages against it, worked fine on the first run with this new Mar. 9 SPM, I'll look into that further. There may be issues with this flag and lld on ELF platforms interacting badly with |
In the past it was unsafe to pass -dead_strip because there was some
required swift metadata that was stripped. It seems that at this point all
of those cases are either fixed or marked as @llvm.used, so passing
these flags should safely reduce binary size in some cases. If there are
other cases where this isn't safe we should likely annotate them as
@llvm.used.
Related: https://bugs.swift.org/browse/SR-521 #215