[llvm] SafeStack: Check if __safestack_pointer_address is available (PR #147917)
Matt Arsenault via llvm-commits
llvm-commits at lists.llvm.org
Tue Jul 15 05:54:59 PDT 2025
https://github.com/arsenm updated https://github.com/llvm/llvm-project/pull/147917
>From 72eb9295207db8ae032238098d0db5a7f7ffe947 Mon Sep 17 00:00:00 2001
From: Matt Arsenault <Matthew.Arsenault at amd.com>
Date: Thu, 10 Jul 2025 15:48:10 +0900
Subject: [PATCH] SafeStack: Check if __safestack_pointer_address is available
Start using RuntimeLibcalls in the base implementation of
getSafeStackPointerLocation instead of hardcoding the function
names.
---
llvm/lib/CodeGen/TargetLoweringBase.cpp | 17 ++++++++++++++---
.../safestack-pointer-address-libcall-error.ll | 4 ++--
2 files changed, 16 insertions(+), 5 deletions(-)
diff --git a/llvm/lib/CodeGen/TargetLoweringBase.cpp b/llvm/lib/CodeGen/TargetLoweringBase.cpp
index 6feeb19bb8589..d4a34555ed820 100644
--- a/llvm/lib/CodeGen/TargetLoweringBase.cpp
+++ b/llvm/lib/CodeGen/TargetLoweringBase.cpp
@@ -1965,15 +1965,26 @@ TargetLoweringBase::getDefaultSafeStackPointerLocation(IRBuilderBase &IRB,
Value *
TargetLoweringBase::getSafeStackPointerLocation(IRBuilderBase &IRB) const {
+ // FIXME: Can this triple check be replaced with SAFESTACK_POINTER_ADDRESS
+ // being available?
if (!TM.getTargetTriple().isAndroid())
return getDefaultSafeStackPointerLocation(IRB, true);
- // Android provides a libc function to retrieve the address of the current
- // thread's unsafe stack pointer.
Module *M = IRB.GetInsertBlock()->getParent()->getParent();
auto *PtrTy = PointerType::getUnqual(M->getContext());
+
+ const char *SafestackPointerAddressName =
+ getLibcallName(RTLIB::SAFESTACK_POINTER_ADDRESS);
+ if (!SafestackPointerAddressName) {
+ M->getContext().emitError(
+ "no libcall available for safestack pointer address");
+ return PoisonValue::get(PtrTy);
+ }
+
+ // Android provides a libc function to retrieve the address of the current
+ // thread's unsafe stack pointer.
FunctionCallee Fn =
- M->getOrInsertFunction("__safestack_pointer_address", PtrTy);
+ M->getOrInsertFunction(SafestackPointerAddressName, PtrTy);
return IRB.CreateCall(Fn);
}
diff --git a/llvm/test/Transforms/SafeStack/NVPTX/safestack-pointer-address-libcall-error.ll b/llvm/test/Transforms/SafeStack/NVPTX/safestack-pointer-address-libcall-error.ll
index 9bf84585e5468..f41dcff76b248 100644
--- a/llvm/test/Transforms/SafeStack/NVPTX/safestack-pointer-address-libcall-error.ll
+++ b/llvm/test/Transforms/SafeStack/NVPTX/safestack-pointer-address-libcall-error.ll
@@ -1,6 +1,6 @@
-; RUN: not opt -disable-output -mtriple=nvptx64-- -safestack-use-pointer-address -mcpu=sm_90 -passes=safe-stack %s 2>&1 | FileCheck %s
+; RUN: not opt -disable-output -mtriple=nvptx64-- -safestack-use-pointer-address -mcpu=sm_90 -passes=safe-stack %s 2>&1 | FileCheck -check-prefix=ERR %s
-; CHECK: error: no libcall available for safestack pointer address
+; ERR: 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)
More information about the llvm-commits
mailing list