[clang] b82c2b9 - Reland "Fix __cfi_check not aligned to 4k on relocatable files with no executable code"
Yi Kong via cfe-commits
cfe-commits at lists.llvm.org
Fri Aug 4 00:05:17 PDT 2023
Author: Yi Kong
Date: 2023-08-04T16:02:27+09:00
New Revision: b82c2b9ac2baae0f2a9dd65770cfb37fdc2a80a9
URL: https://github.com/llvm/llvm-project/commit/b82c2b9ac2baae0f2a9dd65770cfb37fdc2a80a9
DIFF: https://github.com/llvm/llvm-project/commit/b82c2b9ac2baae0f2a9dd65770cfb37fdc2a80a9.diff
LOG: Reland "Fix __cfi_check not aligned to 4k on relocatable files with no executable code"
This reverts commit a093598e50e7b252205f1164751ac9c74874e254.
Fixed test breakage.
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 0aadaeaba69f3d..07e204387804c8 100644
--- a/clang/lib/CodeGen/CGExpr.cpp
+++ b/clang/lib/CodeGen/CGExpr.cpp
@@ -3431,14 +3431,12 @@ 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);
- // 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);
+ // 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);
llvm::ReturnInst::Create(Ctx, nullptr, BB);
}
@@ -3532,9 +3530,6 @@ 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 a4d940641090e5..2f12cee9dec602 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 %0, ptr %1, ptr %2)
+// CHECK: define weak void @__cfi_check(i64 %[[TYPE:.*]], ptr %[[ADDR:.*]], ptr %[[DATA:.*]]) align 4096
// CHECK-NOT: }
-// CHECK: call void @llvm.trap()
+// CHECK: call void @__cfi_check_fail(ptr %[[DATA]], ptr %[[ADDR]])
// CHECK-NEXT: ret void
More information about the cfe-commits
mailing list