Author: Yi Kong Date: 2023-08-17T16:33:46+09:00 New Revision: 3568976375e305a7a41d62b9164ede7571ee16c5
URL: https://github.com/llvm/llvm-project/commit/3568976375e305a7a41d62b9164ede7571ee16c5 DIFF: https://github.com/llvm/llvm-project/commit/3568976375e305a7a41d62b9164ede7571ee16c5.diff LOG: Reland^2 "Fix __cfi_check not aligned to 4k on relocatable files with no executable code" This reverts commit 043d03d25bd7eadef66685de298342b35fe6b466. 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 0f06f3d4089ad8..76bbeba468db64 100644 --- a/clang/lib/CodeGen/CGExpr.cpp +++ b/clang/lib/CodeGen/CGExpr.cpp @@ -3430,14 +3430,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); } 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 _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits