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.
This commit is contained in:
Matt Arsenault 2025-07-15 19:01:00 +09:00 committed by GitHub
parent a64bfd8a51
commit 92501396b4
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 27 additions and 1 deletions

View File

@ -362,6 +362,9 @@ defset list<RuntimeLibcall> LibCalls__OutOfLineAtomic = {
def STACKPROTECTOR_CHECK_FAIL : RuntimeLibcall; def STACKPROTECTOR_CHECK_FAIL : RuntimeLibcall;
def STACK_SMASH_HANDLER : RuntimeLibcall; def STACK_SMASH_HANDLER : RuntimeLibcall;
// Safe stack
def SAFESTACK_POINTER_ADDRESS : RuntimeLibcall;
// Deoptimization // Deoptimization
def DEOPTIMIZE : RuntimeLibcall; def DEOPTIMIZE : RuntimeLibcall;
@ -702,6 +705,9 @@ foreach lc = LibCalls__atomic in {
// Stack Protector Fail // Stack Protector Fail
def __stack_chk_fail : RuntimeLibcallImpl<STACKPROTECTOR_CHECK_FAIL>; def __stack_chk_fail : RuntimeLibcallImpl<STACKPROTECTOR_CHECK_FAIL>;
// Safe stack.
def __safestack_pointer_address : RuntimeLibcallImpl<SAFESTACK_POINTER_ADDRESS>;
// Deoptimization // Deoptimization
def __llvm_deoptimize : RuntimeLibcallImpl<DEOPTIMIZE>; def __llvm_deoptimize : RuntimeLibcallImpl<DEOPTIMIZE>;

View File

@ -799,8 +799,16 @@ bool SafeStack::run() {
IRB.SetCurrentDebugLocation( IRB.SetCurrentDebugLocation(
DILocation::get(SP->getContext(), SP->getScopeLine(), 0, SP)); DILocation::get(SP->getContext(), SP->getScopeLine(), 0, SP));
if (SafeStackUsePointerAddress) { if (SafeStackUsePointerAddress) {
const char *SafestackPointerAddressName =
TL.getLibcallName(RTLIB::SAFESTACK_POINTER_ADDRESS);
if (!SafestackPointerAddressName) {
F.getContext().emitError(
"no libcall available for safestack pointer address");
return false;
}
FunctionCallee Fn = F.getParent()->getOrInsertFunction( FunctionCallee Fn = F.getParent()->getOrInsertFunction(
"__safestack_pointer_address", IRB.getPtrTy(0)); SafestackPointerAddressName, IRB.getPtrTy(0));
UnsafeStackPtr = IRB.CreateCall(Fn); UnsafeStackPtr = IRB.CreateCall(Fn);
} else { } else {
UnsafeStackPtr = TL.getSafeStackPointerLocation(IRB); UnsafeStackPtr = TL.getSafeStackPointerLocation(IRB);

View File

@ -0,0 +1,12 @@
; RUN: not opt -disable-output -mtriple=nvptx64-- -safestack-use-pointer-address -mcpu=sm_90 -passes=safe-stack %s 2>&1 | FileCheck %s
; CHECK: error: no libcall available for safestack pointer address
define void @foo(i32 %t) #0 {
%vla = alloca i32, i32 %t, align 4
call void @baz(ptr %vla)
ret void
}
declare void @baz(ptr)
attributes #0 = { nounwind safestack sspstrong }