-
Notifications
You must be signed in to change notification settings - Fork 10.5k
[IRGen] Emit mod summary for full LTO to enable hermetic seal with lld #42366
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
[IRGen] Emit mod summary for full LTO to enable hermetic seal with lld #42366
Conversation
LTO pipeline requires consistent `EnableSplitLTOUnit` and module summary in regular full LTO bitcode, and clang enables `EnableSplitLTOUnit` and emit regular lto module summary on non-ld64 platforms. Therefore, swiftc has to emit them for the consistency with clang.
@swift-ci Please test |
Please test with following PR: @swift-ci Please test Linux platform |
@kubamracek Could you take a look if you have time? |
I'm afraid I don't understand LTO enough to review this. @compnerd? |
Hi @compnerd, you've also reviewed the cherry-picked swiftlang/llvm-project#4228 LLVM patch on Apple's fork. Would you be available to review this PR as well? Thank you! |
Ping @compnerd. |
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'm not super familiar with this part of the compiler, but the change seems good to me :)
Ping @gottesmm |
// Emit a module summary by default for Regular LTO except ld64-based ones | ||
// (which use the legacy LTO API). | ||
bool EmitRegularLTOSummary = | ||
targetMachine->getTargetTriple().getVendor() != llvm::Triple::Apple; |
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.
Why the vendor check rather than !targetMachine->getTargetTriple().isOSDarwin()
?
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.
@kubamracek Which form do we prefer here? != Apple
or isOSDarwin
?
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.
EmitPasses.add(createBitcodeWriterPass(out)); | ||
if (EmitRegularLTOSummary) { | ||
module->addModuleFlag(llvm::Module::Error, "ThinLTO", uint32_t(0)); | ||
// Assume other sources are compiled with -fsplit-lto-unit (it's enabled |
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.
Can we avoid this assumption? Why do we need this assumption in the first place? Perhaps we should serialize and reference this from the Swift module?
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.
Other sources mean not only Swiftc-oriented LTO summary but also including Clang-oriented summary. So we can't propagate that information through swiftmodule.
Another option to remove that assumption is adding -split-lto-unit
in swiftc also. What do you think?
@eeckstein -- Any thoughts on the proposed changes to the LTO settings here? |
I know too little about LTO. That would be a question for @gottesmm or @aschwaighofer |
Hi @gottesmm @aschwaighofer, would you have a moment to take a look at this PR? Thanks! |
I am not an LTO expert either. The changes seem reasonable to me but I can't predict the consequences of unconditionally (on linux) adding the module flags:
The code seems to indeed follow what clang does. Can we take this change and deal with any fallout (which I expect to be only on linux) or do you have concerns with doing so @kubamracek ? |
No concerns with that. |
Thanks for the reviews! Can we merge then? |
re-trigger testing because it looks like the last test is quite a bit in the past |
@swift-ci test |
Could be this merged now? |
@swift-ci Please test and merge |
LTO pipeline requires consistent
EnableSplitLTOUnit
and module summaryin regular full LTO bitcode, and clang enables
EnableSplitLTOUnit
andemit regular lto module summary on non-ld64 platforms.
Therefore, swiftc has to emit them for the consistency with clang.
This patch unlocks stdlib to be linked with a simple code with
--hermetic-seal-at-link
and lld on LinuxThere are still some remaining issues:
test/IRGen/conditional-dead-strip-exec.swift
doesn't pass yet.test/IRGen/virtual-function-elimination-exec.swift
andtest/IRGen/witness-method-elimination-exec.swift
are failing with the following preemption error.It would be appreciated if you have any ideas.
Depends on swiftlang/llvm-project#4228