Skip to content

Commit

Permalink
Reland^2 "Fix __cfi_check not aligned to 4k on relocatable files with…
Browse files Browse the repository at this point in the history
… no executable code"

This reverts commit 043d03d.
  • Loading branch information
kongy committed Aug 17, 2023
1 parent 3cd8196 commit 3568976
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 8 deletions.
10 changes: 4 additions & 6 deletions clang/lib/CodeGen/CGExpr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand Down
4 changes: 2 additions & 2 deletions clang/test/CodeGen/cfi-check-fail.c
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit 3568976

Please sign in to comment.