@@ -3431,12 +3431,14 @@ void CodeGenFunction::EmitCfiCheckStub() {
3431
3431
llvm::Function *F = llvm::Function::Create (
3432
3432
llvm::FunctionType::get (VoidTy, {Int64Ty, Int8PtrTy, Int8PtrTy}, false ),
3433
3433
llvm::GlobalValue::WeakAnyLinkage, " __cfi_check" , M);
3434
- F->setAlignment (llvm::Align (4096 ));
3435
3434
CGM.setDSOLocal (F);
3436
3435
llvm::BasicBlock *BB = llvm::BasicBlock::Create (Ctx, " entry" , F);
3437
- // CrossDSOCFI pass is not executed if there is no executable code.
3438
- SmallVector<llvm::Value*> Args{F->getArg (2 ), F->getArg (1 )};
3439
- llvm::CallInst::Create (M->getFunction (" __cfi_check_fail" ), Args, " " , BB);
3436
+ // FIXME: consider emitting an intrinsic call like
3437
+ // call void @llvm.cfi_check(i64 %0, i8* %1, i8* %2)
3438
+ // which can be lowered in CrossDSOCFI pass to the actual contents of
3439
+ // __cfi_check. This would allow inlining of __cfi_check calls.
3440
+ llvm::CallInst::Create (
3441
+ llvm::Intrinsic::getDeclaration (M, llvm::Intrinsic::trap), " " , BB);
3440
3442
llvm::ReturnInst::Create (Ctx, nullptr , BB);
3441
3443
}
3442
3444
@@ -3530,6 +3532,9 @@ void CodeGenFunction::EmitCfiCheckFail() {
3530
3532
}
3531
3533
3532
3534
FinishFunction ();
3535
+ // The only reference to this function will be created during LTO link.
3536
+ // Make sure it survives until then.
3537
+ CGM.addUsedGlobal (F);
3533
3538
}
3534
3539
3535
3540
void CodeGenFunction::EmitUnreachable (SourceLocation Loc) {
0 commit comments