Skip to content

Commit 5dd0f91

Browse files
committed
SafeStack: Check if __safestack_pointer_address is available
Start using RuntimeLibcalls in the base implementation of getSafeStackPointerLocation instead of hardcoding the function names.
1 parent fcf040c commit 5dd0f91

File tree

2 files changed

+18
-5
lines changed

2 files changed

+18
-5
lines changed

llvm/lib/CodeGen/TargetLoweringBase.cpp

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1965,15 +1965,26 @@ TargetLoweringBase::getDefaultSafeStackPointerLocation(IRBuilderBase &IRB,
19651965

19661966
Value *
19671967
TargetLoweringBase::getSafeStackPointerLocation(IRBuilderBase &IRB) const {
1968+
// FIXME: Can this triple check be replaced with SAFESTACK_POINTER_ADDRESS
1969+
// being available?
19681970
if (!TM.getTargetTriple().isAndroid())
19691971
return getDefaultSafeStackPointerLocation(IRB, true);
19701972

1971-
// Android provides a libc function to retrieve the address of the current
1972-
// thread's unsafe stack pointer.
19731973
Module *M = IRB.GetInsertBlock()->getParent()->getParent();
19741974
auto *PtrTy = PointerType::getUnqual(M->getContext());
1975+
1976+
const char *SafestackPointerAddressName =
1977+
getLibcallName(RTLIB::SAFESTACK_POINTER_ADDRESS);
1978+
if (!SafestackPointerAddressName) {
1979+
M->getContext().emitError(
1980+
"no libcall available for safestack pointer address");
1981+
return PoisonValue::get(PtrTy);
1982+
}
1983+
1984+
// Android provides a libc function to retrieve the address of the current
1985+
// thread's unsafe stack pointer.
19751986
FunctionCallee Fn =
1976-
M->getOrInsertFunction("__safestack_pointer_address", PtrTy);
1987+
M->getOrInsertFunction(SafestackPointerAddressName, PtrTy);
19771988
return IRB.CreateCall(Fn);
19781989
}
19791990

llvm/test/Transforms/SafeStack/NVPTX/safestack-pointer-address-libcall-error.ll

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
1-
; RUN: not opt -disable-output -mtriple=nvptx64-- -safestack-use-pointer-address -mcpu=sm_90 -passes=safe-stack %s 2>&1 | FileCheck %s
1+
; RUN: not opt -disable-output -mtriple=nvptx64-- -safestack-use-pointer-address -mcpu=sm_90 -passes=safe-stack %s 2>&1 | FileCheck -check-prefix=ERR1 %s
2+
; RUN: not opt -disable-output -mtriple=nvptx64-unknown-android -mcpu=sm_90 -passes=safe-stack %s 2>&1 | FileCheck -check-prefix=ERR2 %s
23

3-
; CHECK: error: no libcall available for safestack pointer address
4+
; ERR1: error: no libcall available for safestack pointer address
5+
; ERR2: error: no libcall available for stackprotector check fail
46
define void @foo(i32 %t) #0 {
57
%vla = alloca i32, i32 %t, align 4
68
call void @baz(ptr %vla)

0 commit comments

Comments
 (0)