Skip to content

Commit d7dc536

Browse files
authored
SafeStack: Emit call to __stack_chk_fail through RuntimeLibcalls (#147915)
Avoid hardcoding the function name, and query if it's really supported or not.
1 parent e68ef11 commit d7dc536

File tree

3 files changed

+23
-1
lines changed

3 files changed

+23
-1
lines changed

llvm/lib/CodeGen/SafeStack.cpp

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -475,8 +475,16 @@ void SafeStack::checkStackGuard(IRBuilder<> &IRB, Function &F, Instruction &RI,
475475
SplitBlockAndInsertIfThen(Cmp, &RI, /* Unreachable */ true, Weights, DTU);
476476
IRBuilder<> IRBFail(CheckTerm);
477477
// FIXME: respect -fsanitize-trap / -ftrap-function here?
478+
const char *StackChkFailName =
479+
TL.getLibcallName(RTLIB::STACKPROTECTOR_CHECK_FAIL);
480+
if (!StackChkFailName) {
481+
F.getContext().emitError(
482+
"no libcall available for stackprotector check fail");
483+
return;
484+
}
485+
478486
FunctionCallee StackChkFail =
479-
F.getParent()->getOrInsertFunction("__stack_chk_fail", IRB.getVoidTy());
487+
F.getParent()->getOrInsertFunction(StackChkFailName, IRB.getVoidTy());
480488
IRBFail.CreateCall(StackChkFail, {});
481489
}
482490

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
if not "NVPTX" in config.root.targets:
2+
config.unsupported = True
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
; RUN: not opt -disable-output -mtriple=nvptx64-- -mcpu=sm_90 -passes=safe-stack %s 2>&1 | FileCheck %s
2+
3+
; CHECK: error: no libcall available for stackprotector check fail
4+
define void @foo(i32 %t) #0 {
5+
%vla = alloca i32, i32 %t, align 4
6+
call void @baz(ptr %vla)
7+
ret void
8+
}
9+
10+
declare void @baz(ptr)
11+
12+
attributes #0 = { nounwind safestack sspstrong }

0 commit comments

Comments
 (0)