Skip to content

Commit 9c4972f

Browse files
authored
Merge pull request #42366 from kateinoigakukun/katei/fix-hermetic-seal-with-lld
[IRGen] Emit mod summary for full LTO to enable hermetic seal with lld
2 parents 9151db5 + 6206090 commit 9c4972f

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
@@ -85,6 +85,7 @@
8585
#include "llvm/Transforms/Instrumentation/SanitizerCoverage.h"
8686
#include "llvm/Transforms/Instrumentation/ThreadSanitizer.h"
8787
#include "llvm/Transforms/ObjCARC.h"
88+
#include "llvm/Transforms/Scalar.h"
8889

8990
#include <thread>
9091

@@ -808,10 +809,29 @@ bool swift::compileAndWriteLLVM(llvm::Module *module,
808809
EmitPasses.add(createPrintModulePass(out));
809810
break;
810811
case IRGenOutputKind::LLVMBitcode: {
812+
// Emit a module summary by default for Regular LTO except ld64-based ones
813+
// (which use the legacy LTO API).
814+
bool EmitRegularLTOSummary =
815+
targetMachine->getTargetTriple().getVendor() != llvm::Triple::Apple;
816+
817+
if (EmitRegularLTOSummary || opts.LLVMLTOKind == IRGenLLVMLTOKind::Thin) {
818+
// Rename anon globals to be able to export them in the summary.
819+
EmitPasses.add(createNameAnonGlobalPass());
820+
}
821+
811822
if (opts.LLVMLTOKind == IRGenLLVMLTOKind::Thin) {
812823
EmitPasses.add(createWriteThinLTOBitcodePass(out));
813824
} else {
814-
EmitPasses.add(createBitcodeWriterPass(out));
825+
if (EmitRegularLTOSummary) {
826+
module->addModuleFlag(llvm::Module::Error, "ThinLTO", uint32_t(0));
827+
// Assume other sources are compiled with -fsplit-lto-unit (it's enabled
828+
// by default when -flto is specified on platforms that support regular
829+
// lto summary.)
830+
module->addModuleFlag(llvm::Module::Error, "EnableSplitLTOUnit",
831+
uint32_t(1));
832+
}
833+
EmitPasses.add(createBitcodeWriterPass(
834+
out, /*ShouldPreserveUseListOrder*/ false, EmitRegularLTOSummary));
815835
}
816836
break;
817837
}

0 commit comments

Comments
 (0)