Skip to content

[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

Merged
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
22 changes: 21 additions & 1 deletion lib/IRGen/IRGen.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@
#include "llvm/Transforms/Instrumentation/SanitizerCoverage.h"
#include "llvm/Transforms/Instrumentation/ThreadSanitizer.h"
#include "llvm/Transforms/ObjCARC.h"
#include "llvm/Transforms/Scalar.h"

#include <thread>

Expand Down Expand Up @@ -601,10 +602,29 @@ bool swift::compileAndWriteLLVM(llvm::Module *module,
EmitPasses.add(createPrintModulePass(out));
break;
case IRGenOutputKind::LLVMBitcode: {
// 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;
Copy link
Member

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()?

Copy link
Contributor

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?

Copy link
Member Author

Choose a reason for hiding this comment

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


if (EmitRegularLTOSummary || opts.LLVMLTOKind == IRGenLLVMLTOKind::Thin) {
// Rename anon globals to be able to export them in the summary.
EmitPasses.add(createNameAnonGlobalPass());
}

if (opts.LLVMLTOKind == IRGenLLVMLTOKind::Thin) {
EmitPasses.add(createWriteThinLTOBitcodePass(out));
} else {
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
Copy link
Member

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?

Copy link
Member Author

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?

// by default when -flto is specified on platforms that support regular
// lto summary.)
module->addModuleFlag(llvm::Module::Error, "EnableSplitLTOUnit",
uint32_t(1));
}
EmitPasses.add(createBitcodeWriterPass(
out, /*ShouldPreserveUseListOrder*/ false, EmitRegularLTOSummary));
}
break;
}
Expand Down