[clang] 043d03d - Revert "Reland "Fix __cfi_check not aligned to 4k on relocatable files with no executable code""
Florian Mayer via cfe-commits
cfe-commits at lists.llvm.org
Fri Aug 4 14:24:38 PDT 2023
Author: Florian Mayer
Date: 2023-08-04T14:24:26-07:00
New Revision: 043d03d25bd7eadef66685de298342b35fe6b466
URL: https://github.com/llvm/llvm-project/commit/043d03d25bd7eadef66685de298342b35fe6b466
DIFF: https://github.com/llvm/llvm-project/commit/043d03d25bd7eadef66685de298342b35fe6b466.diff
LOG: Revert "Reland "Fix __cfi_check not aligned to 4k on relocatable files with no executable code""
Broke sanitizer build bots
This reverts commit b82c2b9ac2baae0f2a9dd65770cfb37fdc2a80a9.
Added:
Modified:
clang/lib/CodeGen/CGExpr.cpp
clang/test/CodeGen/cfi-check-fail.c
Removed:
################################################################################
diff --git a/clang/lib/CodeGen/CGExpr.cpp b/clang/lib/CodeGen/CGExpr.cpp
index 07e204387804c8..0aadaeaba69f3d 100644
--- a/clang/lib/CodeGen/CGExpr.cpp
+++ b/clang/lib/CodeGen/CGExpr.cpp
@@ -3431,12 +3431,14 @@ void CodeGenFunction::EmitCfiCheckStub() {
llvm::Function *F = llvm::Function::Create(
llvm::FunctionType::get(VoidTy, {Int64Ty, Int8PtrTy, Int8PtrTy}, false),
llvm::GlobalValue::WeakAnyLinkage, "__cfi_check", M);
- F->setAlignment(llvm::Align(4096));
CGM.setDSOLocal(F);
llvm::BasicBlock *BB = llvm::BasicBlock::Create(Ctx, "entry", F);
- // CrossDSOCFI pass is not executed if there is no executable code.
- SmallVector<llvm::Value*> Args{F->getArg(2), F->getArg(1)};
- llvm::CallInst::Create(M->getFunction("__cfi_check_fail"), Args, "", BB);
+ // FIXME: consider emitting an intrinsic call like
+ // call void @llvm.cfi_check(i64 %0, i8* %1, i8* %2)
+ // which can be lowered in CrossDSOCFI pass to the actual contents of
+ // __cfi_check. This would allow inlining of __cfi_check calls.
+ llvm::CallInst::Create(
+ llvm::Intrinsic::getDeclaration(M, llvm::Intrinsic::trap), "", BB);
llvm::ReturnInst::Create(Ctx, nullptr, BB);
}
@@ -3530,6 +3532,9 @@ void CodeGenFunction::EmitCfiCheckFail() {
}
FinishFunction();
+ // The only reference to this function will be created during LTO link.
+ // Make sure it survives until then.
+ CGM.addUsedGlobal(F);
}
void CodeGenFunction::EmitUnreachable(SourceLocation Loc) {
diff --git a/clang/test/CodeGen/cfi-check-fail.c b/clang/test/CodeGen/cfi-check-fail.c
index 2f12cee9dec602..a4d940641090e5 100644
--- a/clang/test/CodeGen/cfi-check-fail.c
+++ b/clang/test/CodeGen/cfi-check-fail.c
@@ -72,7 +72,7 @@ void caller(void (*f)(void)) {
// CHECK: [[CONT5]]:
// CHECK: ret void
-// CHECK: define weak void @__cfi_check(i64 %[[TYPE:.*]], ptr %[[ADDR:.*]], ptr %[[DATA:.*]]) align 4096
+// CHECK: define weak void @__cfi_check(i64 %0, ptr %1, ptr %2)
// CHECK-NOT: }
-// CHECK: call void @__cfi_check_fail(ptr %[[DATA]], ptr %[[ADDR]])
+// CHECK: call void @llvm.trap()
// CHECK-NEXT: ret void
More information about the cfe-commits
mailing list