Skip to content

Commit 043d03d

Browse files
committed
Revert "Reland "Fix __cfi_check not aligned to 4k on relocatable files with no executable code""
Broke sanitizer build bots This reverts commit b82c2b9.
1 parent f037b89 commit 043d03d

File tree

2 files changed

+11
-6
lines changed

2 files changed

+11
-6
lines changed

clang/lib/CodeGen/CGExpr.cpp

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3431,12 +3431,14 @@ 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));
34353434
CGM.setDSOLocal(F);
34363435
llvm::BasicBlock *BB = llvm::BasicBlock::Create(Ctx, "entry", F);
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);
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);
34403442
llvm::ReturnInst::Create(Ctx, nullptr, BB);
34413443
}
34423444

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

35323534
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);
35333538
}
35343539

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

0 commit comments

Comments
 (0)