Skip to content

Commit 9250139

Browse files
authored
SafeStack: Emit __safestack_pointer_address call through RuntimeLibcalls (#147916)
Stop using hardcoded function named and check availability. This only fixes the forced usage via command line in the pass itself; the implementations inside of TargetLoweringBase hide additional call emission.
1 parent a64bfd8 commit 9250139

File tree

3 files changed

+27
-1
lines changed

3 files changed

+27
-1
lines changed

llvm/include/llvm/IR/RuntimeLibcalls.td

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -362,6 +362,9 @@ defset list<RuntimeLibcall> LibCalls__OutOfLineAtomic = {
362362
def STACKPROTECTOR_CHECK_FAIL : RuntimeLibcall;
363363
def STACK_SMASH_HANDLER : RuntimeLibcall;
364364

365+
// Safe stack
366+
def SAFESTACK_POINTER_ADDRESS : RuntimeLibcall;
367+
365368
// Deoptimization
366369
def DEOPTIMIZE : RuntimeLibcall;
367370

@@ -702,6 +705,9 @@ foreach lc = LibCalls__atomic in {
702705
// Stack Protector Fail
703706
def __stack_chk_fail : RuntimeLibcallImpl<STACKPROTECTOR_CHECK_FAIL>;
704707

708+
// Safe stack.
709+
def __safestack_pointer_address : RuntimeLibcallImpl<SAFESTACK_POINTER_ADDRESS>;
710+
705711
// Deoptimization
706712
def __llvm_deoptimize : RuntimeLibcallImpl<DEOPTIMIZE>;
707713

llvm/lib/CodeGen/SafeStack.cpp

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -799,8 +799,16 @@ bool SafeStack::run() {
799799
IRB.SetCurrentDebugLocation(
800800
DILocation::get(SP->getContext(), SP->getScopeLine(), 0, SP));
801801
if (SafeStackUsePointerAddress) {
802+
const char *SafestackPointerAddressName =
803+
TL.getLibcallName(RTLIB::SAFESTACK_POINTER_ADDRESS);
804+
if (!SafestackPointerAddressName) {
805+
F.getContext().emitError(
806+
"no libcall available for safestack pointer address");
807+
return false;
808+
}
809+
802810
FunctionCallee Fn = F.getParent()->getOrInsertFunction(
803-
"__safestack_pointer_address", IRB.getPtrTy(0));
811+
SafestackPointerAddressName, IRB.getPtrTy(0));
804812
UnsafeStackPtr = IRB.CreateCall(Fn);
805813
} else {
806814
UnsafeStackPtr = TL.getSafeStackPointerLocation(IRB);
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-- -safestack-use-pointer-address -mcpu=sm_90 -passes=safe-stack %s 2>&1 | FileCheck %s
2+
3+
; CHECK: error: no libcall available for safestack pointer address
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)