Skip to content

Commit 3e4f693

Browse files
committed
TargetLowering: Replace android triple check with libcall check
Instead of directly checking if the target is android, check if __safestack_pointer_address is available and configure android to have the call.
1 parent f4a394f commit 3e4f693

File tree

2 files changed

+20
-24
lines changed

2 files changed

+20
-24
lines changed

llvm/include/llvm/IR/RuntimeLibcalls.td

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ def isNotOSMSVCRT : RuntimeLibcallPredicate<"!TT.isOSMSVCRT()">;
2424
def isPS : RuntimeLibcallPredicate<"TT.isPS()">;
2525
def isNotOSWindowsOrIsCygwinMinGW
2626
: RuntimeLibcallPredicate<"!TT.isOSWindows() || TT.isOSCygMing()">;
27-
27+
def isAndroid : RuntimeLibcallPredicate<"TT.isAndroid()">;
2828

2929
def isGNUEnvironment : RuntimeLibcallPredicate<"TT.isGNUEnvironment()">;
3030
def darwinHasSinCosStret : RuntimeLibcallPredicate<"darwinHasSinCosStret(TT)">;
@@ -1135,6 +1135,8 @@ defvar LibmHasLdexpF80 = LibcallImpls<(add ldexp_f80), isNotOSWindowsOrIsCygwinM
11351135
defvar LibmHasFrexpF128 = LibcallImpls<(add frexp_f128), isNotOSWindowsOrIsCygwinMinGW>;
11361136
defvar LibmHasLdexpF128 = LibcallImpls<(add ldexp_f128), isNotOSWindowsOrIsCygwinMinGW>;
11371137

1138+
defvar LibcSafestackPointerAddress =
1139+
LibcallImpls<(add __safestack_pointer_address), isAndroid>;
11381140

11391141
//===----------------------------------------------------------------------===//
11401142
// Objective-C Runtime Libcalls
@@ -1211,7 +1213,8 @@ def AArch64SystemLibrary : SystemRuntimeLibrary<
12111213
LibcallImpls<(add Int128RTLibcalls), isAArch64_ILP64>,
12121214
LibcallImpls<(add bzero), isOSDarwin>,
12131215
DarwinExp10, DarwinSinCosStret,
1214-
LibmHasSinCosF32, LibmHasSinCosF64, LibmHasSinCosF128)
1216+
LibmHasSinCosF32, LibmHasSinCosF64, LibmHasSinCosF128,
1217+
LibcSafestackPointerAddress)
12151218
>;
12161219

12171220
// Prepend a # to every name
@@ -1482,6 +1485,7 @@ def ARMSystemLibrary
14821485
AEABIDivRemCalls,
14831486
DarwinSinCosStret, DarwinExp10,
14841487
LibmHasSinCosF32, LibmHasSinCosF64, LibmHasSinCosF128,
1488+
LibcSafestackPointerAddress,
14851489

14861490
// Use divmod compiler-rt calls for iOS 5.0 and later.
14871491
LibcallImpls<(add __divmodsi4, __udivmodsi4),
@@ -2125,7 +2129,8 @@ defvar X86CommonLibcalls =
21252129
// FIXME: MSVCRT doesn't have powi. The f128 case is added as a
21262130
// hack for one test relying on it.
21272131
__powitf2_f128,
2128-
LibcallImpls<(add MostPowI), isNotOSMSVCRT>
2132+
LibcallImpls<(add MostPowI), isNotOSMSVCRT>,
2133+
LibcSafestackPointerAddress
21292134
);
21302135

21312136
defvar Windows32DivRemMulCalls =

llvm/lib/CodeGen/TargetLoweringBase.cpp

Lines changed: 12 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1965,27 +1965,18 @@ 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?
1970-
if (!TM.getTargetTriple().isAndroid())
1971-
return getDefaultSafeStackPointerLocation(IRB, true);
1972-
1973-
Module *M = IRB.GetInsertBlock()->getParent()->getParent();
1974-
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.
1986-
FunctionCallee Fn =
1987-
M->getOrInsertFunction(SafestackPointerAddressName, PtrTy);
1988-
return IRB.CreateCall(Fn);
1968+
if (const char *SafestackPointerAddressName =
1969+
getLibcallName(RTLIB::SAFESTACK_POINTER_ADDRESS)) {
1970+
// Android provides a libc function to retrieve the address of the current
1971+
// thread's unsafe stack pointer.
1972+
Module *M = IRB.GetInsertBlock()->getParent()->getParent();
1973+
auto *PtrTy = PointerType::getUnqual(M->getContext());
1974+
FunctionCallee Fn =
1975+
M->getOrInsertFunction(SafestackPointerAddressName, PtrTy);
1976+
return IRB.CreateCall(Fn);
1977+
}
1978+
1979+
return getDefaultSafeStackPointerLocation(IRB, true);
19891980
}
19901981

19911982
//===----------------------------------------------------------------------===//

0 commit comments

Comments
 (0)