[clang] a093598 - Revert "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
Thu Aug 3 06:04:02 PDT 2023
Author: Yi Kong
Date: 2023-08-03T22:03:43+09:00
New Revision: a093598e50e7b252205f1164751ac9c74874e254
URL: https://github.com/llvm/llvm-project/commit/a093598e50e7b252205f1164751ac9c74874e254
DIFF: https://github.com/llvm/llvm-project/commit/a093598e50e7b252205f1164751ac9c74874e254.diff
LOG: Revert "Fix __cfi_check not aligned to 4k on relocatable files with no executable code"
This reverts commit c7cacb2f6efe07fa4a1129bb7e2389312670b84a.
Broken tests.
Added:
Modified:
clang/lib/CodeGen/CGExpr.cpp
Removed:
clang/test/CodeGen/cfi-cross-dso-align.c
################################################################################
diff --git a/clang/lib/CodeGen/CGExpr.cpp b/clang/lib/CodeGen/CGExpr.cpp
index 15aa1b730d268b..ed6095f7cfeb0d 100644
--- a/clang/lib/CodeGen/CGExpr.cpp
+++ b/clang/lib/CodeGen/CGExpr.cpp
@@ -3445,12 +3445,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);
}
@@ -3544,6 +3546,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-cross-dso-align.c b/clang/test/CodeGen/cfi-cross-dso-align.c
deleted file mode 100644
index e023601184fe99..00000000000000
--- a/clang/test/CodeGen/cfi-cross-dso-align.c
+++ /dev/null
@@ -1,8 +0,0 @@
-// RUN: %clang_cc1 -triple x86_64-unknown-linux -O0 -fsanitize-cfi-cross-dso \
-// RUN: -emit-llvm -o - %s | FileCheck %s
-
-int a;
-
-// CHECK: define weak void @__cfi_check(i64 %[[TYPE:.*]], ptr %[[ADDR:.*]], ptr %[[DATA:.*]]) align 4096
-// CHECK-NEXT: entry:
-// CHECK-NEXT: call void @__cfi_check_fail(ptr %[[DATA]], ptr %[[ADDR]])
More information about the cfe-commits
mailing list