Skip to content

Commit 6206090

Browse files
[IRGen] Emit mod summary for full LTO to enable hermetic seal with lld
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.
1 parent d6cc8e8 commit 6206090

File tree

1 file changed

+21
-1
lines changed

1 file changed

+21
-1
lines changed

lib/IRGen/IRGen.cpp

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,7 @@
8282
#include "llvm/Transforms/Instrumentation/SanitizerCoverage.h"
8383
#include "llvm/Transforms/Instrumentation/ThreadSanitizer.h"
8484
#include "llvm/Transforms/ObjCARC.h"
85+
#include "llvm/Transforms/Scalar.h"
8586

8687
#include <thread>
8788

@@ -601,10 +602,29 @@ bool swift::compileAndWriteLLVM(llvm::Module *module,
601602
EmitPasses.add(createPrintModulePass(out));
602603
break;
603604
case IRGenOutputKind::LLVMBitcode: {
605+
// Emit a module summary by default for Regular LTO except ld64-based ones
606+
// (which use the legacy LTO API).
607+
bool EmitRegularLTOSummary =
608+
targetMachine->getTargetTriple().getVendor() != llvm::Triple::Apple;
609+
610+
if (EmitRegularLTOSummary || opts.LLVMLTOKind == IRGenLLVMLTOKind::Thin) {
611+
// Rename anon globals to be able to export them in the summary.
612+
EmitPasses.add(createNameAnonGlobalPass());
613+
}
614+
604615
if (opts.LLVMLTOKind == IRGenLLVMLTOKind::Thin) {
605616
EmitPasses.add(createWriteThinLTOBitcodePass(out));
606617
} else {
607-
EmitPasses.add(createBitcodeWriterPass(out));
618+
if (EmitRegularLTOSummary) {
619+
module->addModuleFlag(llvm::Module::Error, "ThinLTO", uint32_t(0));
620+
// Assume other sources are compiled with -fsplit-lto-unit (it's enabled
621+
// by default when -flto is specified on platforms that support regular
622+
// lto summary.)
623+
module->addModuleFlag(llvm::Module::Error, "EnableSplitLTOUnit",
624+
uint32_t(1));
625+
}
626+
EmitPasses.add(createBitcodeWriterPass(
627+
out, /*ShouldPreserveUseListOrder*/ false, EmitRegularLTOSummary));
608628
}
609629
break;
610630
}

0 commit comments

Comments
 (0)