-
Notifications
You must be signed in to change notification settings - Fork 10.5k
Add a -emit-dead-strippable-symbols flag that emits functions/variable/metadata in a dead_strip-friendly way. #34281
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
Conversation
What happens if we remove even the |
…e/metadata in a dead_strip-friendly way. This enables static linking to remove unused functions and classes even across modules.
2e730c7
to
30fa52b
Compare
Updated the PR, added more tests.
Good point. I realized it's not needed for this purpose. I originally thought that it might be needed for LTO/ThinLTO, but it turns out it's not needed for that either. I dropped those changes. |
@swift-ci please test |
Build failed |
@swift-ci please test |
@jckarter @airspeedswift any more feedback or this good to go in? |
break; | ||
case llvm::Triple::XCOFF: | ||
case llvm::Triple::COFF: | ||
sectionName = ".sw5prt$B"; |
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.
One question I have is if this information around sectionName is something that is also somewhere else. Seems like we should have that centralized so it isn't out of sync, no?
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.
I guess it was just below? Nm.
LGTM Kuba. |
Hi @kubamracek, thanks for putting up this patch! |
@SharonXSharon Do you know what symbols are getting incorrectly stripped? Can we mark them used? Ideally we should always emit code this way and it wouldn't need to be a distinct mode. |
@jckarter It looks some function
|
@SharonXSharon One debugging option is to dump out the symbols that get changed by this flag, and compare the existence of this set between no fullLTO vs fullLTO. |
I thought marking things public or open means they will be used across swift modules, does this patch not honor that and it requires extra annotation for symbols used across modules? |
I am aware of a few problems with this change, and I don't plan on landing this as it is. I think the only way to get this dead-stripping to work correctly is by requiring LTO/ThinLTO and acknowledging that there cannot be any non-visible Swift code using any of the classes/structs/protocols defined in the module. |
What are the other problems? Do you mean they can all be solved by bundling this flag with LTO/thinLTO? |
Uses between images should be limited to |
The "live_support" flag is 1) only supported by ld64, so it won't work on Linux, and 2) limited and won't allow dead_stripping of protocol conformances because ld64's behavior treats multiple references from a live_support atom as a "keep live if any reference is alive", but we really want a "keep live if all references are alive" behavior. My plan is to emit slightly different IR and rely on LTO/ThinLTO and the compiler to do the dead-stripping (in GlobalDCE) instead of the linker. |
This change is really desirable for us, are there any updates on next steps or blockers to helping this land? |
Abandoning in favor of VFE/WME/CRR/internalization which is now implemented under -experimental-hermetic-seal-at-link flag:
|
Add a -emit-dead-strippable-symbols flag that emits functions/variable/metadata in a dead_strip-friendly way. This enables static linking to remove unused functions and classes even across modules. For now, I'm adding the flag as an opt-in experimental mode, but the goal is to eventually be able to emit symbols this way for everything. This way we could see nice code size savings when e.g. including a lot of package dependencies where not everything is actually used.