Skip to content

Commit b82c2b9

Browse files
committed
Reland "Fix __cfi_check not aligned to 4k on relocatable files with no executable code"
This reverts commit a093598. Fixed test breakage.
1 parent 5066551 commit b82c2b9

File tree

2 files changed

+6
-11
lines changed

2 files changed

+6
-11
lines changed

clang/lib/CodeGen/CGExpr.cpp

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3431,14 +3431,12 @@ void CodeGenFunction::EmitCfiCheckStub() {
34313431
llvm::Function *F = llvm::Function::Create(
34323432
llvm::FunctionType::get(VoidTy, {Int64Ty, Int8PtrTy, Int8PtrTy}, false),
34333433
llvm::GlobalValue::WeakAnyLinkage, "__cfi_check", M);
3434+
F->setAlignment(llvm::Align(4096));
34343435
CGM.setDSOLocal(F);
34353436
llvm::BasicBlock *BB = llvm::BasicBlock::Create(Ctx, "entry", F);
3436-
// FIXME: consider emitting an intrinsic call like
3437-
// call void @llvm.cfi_check(i64 %0, i8* %1, i8* %2)
3438-
// which can be lowered in CrossDSOCFI pass to the actual contents of
3439-
// __cfi_check. This would allow inlining of __cfi_check calls.
3440-
llvm::CallInst::Create(
3441-
llvm::Intrinsic::getDeclaration(M, llvm::Intrinsic::trap), "", BB);
3437+
// CrossDSOCFI pass is not executed if there is no executable code.
3438+
SmallVector<llvm::Value*> Args{F->getArg(2), F->getArg(1)};
3439+
llvm::CallInst::Create(M->getFunction("__cfi_check_fail"), Args, "", BB);
34423440
llvm::ReturnInst::Create(Ctx, nullptr, BB);
34433441
}
34443442

@@ -3532,9 +3530,6 @@ void CodeGenFunction::EmitCfiCheckFail() {
35323530
}
35333531

35343532
FinishFunction();
3535-
// The only reference to this function will be created during LTO link.
3536-
// Make sure it survives until then.
3537-
CGM.addUsedGlobal(F);
35383533
}
35393534

35403535
void CodeGenFunction::EmitUnreachable(SourceLocation Loc) {

clang/test/CodeGen/cfi-check-fail.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ void caller(void (*f)(void)) {
7272
// CHECK: [[CONT5]]:
7373
// CHECK: ret void
7474

75-
// CHECK: define weak void @__cfi_check(i64 %0, ptr %1, ptr %2)
75+
// CHECK: define weak void @__cfi_check(i64 %[[TYPE:.*]], ptr %[[ADDR:.*]], ptr %[[DATA:.*]]) align 4096
7676
// CHECK-NOT: }
77-
// CHECK: call void @llvm.trap()
77+
// CHECK: call void @__cfi_check_fail(ptr %[[DATA]], ptr %[[ADDR]])
7878
// CHECK-NEXT: ret void

0 commit comments

Comments
 (0)