[PATCH] D155736: Fix __cfi_check not aligned to 4k on relocatable files with no executable code
Yi Kong via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Thu Aug 3 03:54:24 PDT 2023
This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
Closed by commit rGc7cacb2f6efe: Fix __cfi_check not aligned to 4k on relocatable files with no executable code (authored by kongyi).
Herald added a project: clang.
Herald added a subscriber: cfe-commits.
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D155736/new/
https://reviews.llvm.org/D155736
Files:
clang/lib/CodeGen/CGExpr.cpp
clang/test/CodeGen/cfi-cross-dso-align.c
Index: clang/test/CodeGen/cfi-cross-dso-align.c
===================================================================
--- /dev/null
+++ clang/test/CodeGen/cfi-cross-dso-align.c
@@ -0,0 +1,8 @@
+// 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]])
Index: clang/lib/CodeGen/CGExpr.cpp
===================================================================
--- clang/lib/CodeGen/CGExpr.cpp
+++ clang/lib/CodeGen/CGExpr.cpp
@@ -3445,14 +3445,12 @@
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);
}
@@ -3546,9 +3544,6 @@
}
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) {
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D155736.546795.patch
Type: text/x-patch
Size: 1917 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20230803/cb1214d7/attachment.bin>
More information about the cfe-commits
mailing list