Skip to content
Merged
Show file tree
Hide file tree
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
12 changes: 11 additions & 1 deletion llvm/lib/Transforms/IPO/ThinLTOBitcodeWriter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -350,12 +350,20 @@ void splitAndWriteThinLTOBitcode(
});
}

auto MustEmitToMergedModule = [](const GlobalValue *GV) {
// The __cfi_check definition is filled in by the CrossDSOCFI pass which
// runs only in the merged module.
return GV->getName() == "__cfi_check";
};

ValueToValueMapTy VMap;
std::unique_ptr<Module> MergedM(
CloneModule(M, VMap, [&](const GlobalValue *GV) -> bool {
if (const auto *C = GV->getComdat())
if (MergedMComdats.count(C))
return true;
if (MustEmitToMergedModule(GV))
return true;
if (auto *F = dyn_cast<Function>(GV))
return EligibleVirtualFns.count(F);
if (auto *GVar =
Expand All @@ -372,7 +380,7 @@ void splitAndWriteThinLTOBitcode(
cloneUsedGlobalVariables(M, *MergedM, /*CompilerUsed*/ true);

for (Function &F : *MergedM)
if (!F.isDeclaration()) {
if (!F.isDeclaration() && !MustEmitToMergedModule(&F)) {
// Reset the linkage of all functions eligible for virtual constant
// propagation. The canonical definitions live in the thin LTO module so
// that they can be imported.
Expand All @@ -398,6 +406,8 @@ void splitAndWriteThinLTOBitcode(
if (const auto *C = GV->getComdat())
if (MergedMComdats.count(C))
return false;
if (MustEmitToMergedModule(GV))
return false;
return true;
});

Expand Down
19 changes: 19 additions & 0 deletions llvm/test/Transforms/ThinLTOBitcodeWriter/cfi-check.ll
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
; RUN: opt -thinlto-bc -thinlto-split-lto-unit -o %t %s
; RUN: llvm-modextract -b -n 0 -o - %t | llvm-dis | FileCheck --check-prefix=M0 %s
; RUN: llvm-modextract -b -n 1 -o - %t | llvm-dis | FileCheck --check-prefix=M1 %s

; Check that __cfi_check is emitted on the full LTO side with
; attributes preserved.

; M0: define void @f()
define void @f() !type !{!"f1", i32 0} {
ret void
}

; M1: define void @__cfi_check() #0
define void @__cfi_check() #0 {
ret void
}

; M1: attributes #0 = { "branch-target-enforcement" }
attributes #0 = { "branch-target-enforcement" }