@@ -3445,12 +3445,14 @@ void CodeGenFunction::EmitCfiCheckStub() {
3445
3445
llvm::Function *F = llvm::Function::Create (
3446
3446
llvm::FunctionType::get (VoidTy, {Int64Ty, Int8PtrTy, Int8PtrTy}, false ),
3447
3447
llvm::GlobalValue::WeakAnyLinkage, " __cfi_check" , M);
3448
- F->setAlignment (llvm::Align (4096 ));
3449
3448
CGM.setDSOLocal (F);
3450
3449
llvm::BasicBlock *BB = llvm::BasicBlock::Create (Ctx, " entry" , F);
3451
- // CrossDSOCFI pass is not executed if there is no executable code.
3452
- SmallVector<llvm::Value*> Args{F->getArg (2 ), F->getArg (1 )};
3453
- llvm::CallInst::Create (M->getFunction (" __cfi_check_fail" ), Args, " " , BB);
3450
+ // FIXME: consider emitting an intrinsic call like
3451
+ // call void @llvm.cfi_check(i64 %0, i8* %1, i8* %2)
3452
+ // which can be lowered in CrossDSOCFI pass to the actual contents of
3453
+ // __cfi_check. This would allow inlining of __cfi_check calls.
3454
+ llvm::CallInst::Create (
3455
+ llvm::Intrinsic::getDeclaration (M, llvm::Intrinsic::trap), " " , BB);
3454
3456
llvm::ReturnInst::Create (Ctx, nullptr , BB);
3455
3457
}
3456
3458
@@ -3544,6 +3546,9 @@ void CodeGenFunction::EmitCfiCheckFail() {
3544
3546
}
3545
3547
3546
3548
FinishFunction ();
3549
+ // The only reference to this function will be created during LTO link.
3550
+ // Make sure it survives until then.
3551
+ CGM.addUsedGlobal (F);
3547
3552
}
3548
3553
3549
3554
void CodeGenFunction::EmitUnreachable (SourceLocation Loc) {
0 commit comments