Skip to content

TargetLowering: Replace android triple check with libcall check #148800

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 8 additions & 3 deletions llvm/include/llvm/IR/RuntimeLibcalls.td
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ def isNotOSMSVCRT : RuntimeLibcallPredicate<"!TT.isOSMSVCRT()">;
def isPS : RuntimeLibcallPredicate<"TT.isPS()">;
def isNotOSWindowsOrIsCygwinMinGW
: RuntimeLibcallPredicate<"!TT.isOSWindows() || TT.isOSCygMing()">;

def isAndroid : RuntimeLibcallPredicate<"TT.isAndroid()">;

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

defvar LibcSafestackPointerAddress =
LibcallImpls<(add __safestack_pointer_address), isAndroid>;

//===----------------------------------------------------------------------===//
// Objective-C Runtime Libcalls
Expand Down Expand Up @@ -1211,7 +1213,8 @@ def AArch64SystemLibrary : SystemRuntimeLibrary<
LibcallImpls<(add Int128RTLibcalls), isAArch64_ILP64>,
LibcallImpls<(add bzero), isOSDarwin>,
DarwinExp10, DarwinSinCosStret,
LibmHasSinCosF32, LibmHasSinCosF64, LibmHasSinCosF128)
LibmHasSinCosF32, LibmHasSinCosF64, LibmHasSinCosF128,
LibcSafestackPointerAddress)
>;

// Prepend a # to every name
Expand Down Expand Up @@ -1482,6 +1485,7 @@ def ARMSystemLibrary
AEABIDivRemCalls,
DarwinSinCosStret, DarwinExp10,
LibmHasSinCosF32, LibmHasSinCosF64, LibmHasSinCosF128,
LibcSafestackPointerAddress,

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

defvar Windows32DivRemMulCalls =
Expand Down
33 changes: 12 additions & 21 deletions llvm/lib/CodeGen/TargetLoweringBase.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1965,27 +1965,18 @@ 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);

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(SafestackPointerAddressName, PtrTy);
return IRB.CreateCall(Fn);
if (const char *SafestackPointerAddressName =
getLibcallName(RTLIB::SAFESTACK_POINTER_ADDRESS)) {
// Android provides a libc function to retrieve the address of the current
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would prefer if the "Android" part of this comment was moved next to the isAndroid check, and this comment was left as a vague "Some systems provide...."

// thread's unsafe stack pointer.
Module *M = IRB.GetInsertBlock()->getParent()->getParent();
auto *PtrTy = PointerType::getUnqual(M->getContext());
FunctionCallee Fn =
M->getOrInsertFunction(SafestackPointerAddressName, PtrTy);
return IRB.CreateCall(Fn);
}

return getDefaultSafeStackPointerLocation(IRB, true);
}

//===----------------------------------------------------------------------===//
Expand Down
Loading