Skip to content

Commit 7bf2a69

Browse files
committed
RuntimeLibcalls: Move __stack_chk_fail config to tablegen
1 parent 0b21d22 commit 7bf2a69

File tree

2 files changed

+32
-21
lines changed

2 files changed

+32
-21
lines changed

llvm/include/llvm/IR/RuntimeLibcalls.td

Lines changed: 31 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ class DuplicateLibcallImplWithPrefix<RuntimeLibcallImpl Impl, string prefix>
1818
/// Libcall Predicates
1919
def isOSDarwin : RuntimeLibcallPredicate<"TT.isOSDarwin()">;
2020
def isOSOpenBSD : RuntimeLibcallPredicate<"TT.isOSOpenBSD()">;
21+
def isNotOSOpenBSD : RuntimeLibcallPredicate<"!TT.isOSOpenBSD()">;
2122
def isOSWindows : RuntimeLibcallPredicate<"TT.isOSWindows()">;
2223
def isNotOSWindows : RuntimeLibcallPredicate<"!TT.isOSWindows()">;
2324
def isNotOSMSVCRT : RuntimeLibcallPredicate<"!TT.isOSMSVCRT()">;
@@ -705,12 +706,6 @@ foreach lc = LibCalls__atomic in {
705706
def __#!tolower(!cast<string>(lc)) : RuntimeLibcallImpl<lc>;
706707
}
707708

708-
// Stack Protector Fail
709-
def __stack_chk_fail : RuntimeLibcallImpl<STACKPROTECTOR_CHECK_FAIL>;
710-
711-
// Safe stack.
712-
def __safestack_pointer_address : RuntimeLibcallImpl<SAFESTACK_POINTER_ADDRESS>;
713-
714709
// Deoptimization
715710
def __llvm_deoptimize : RuntimeLibcallImpl<DEOPTIMIZE>;
716711

@@ -955,6 +950,12 @@ def exp10l_f80 : RuntimeLibcallImpl<EXP10_F80, "exp10l">;
955950
def exp10l_f128 : RuntimeLibcallImpl<EXP10_F128, "exp10l">;
956951
def exp10l_ppcf128 : RuntimeLibcallImpl<EXP10_PPCF128, "exp10l">;
957952

953+
// Stack Protector Fail
954+
def __stack_chk_fail : RuntimeLibcallImpl<STACKPROTECTOR_CHECK_FAIL>;
955+
956+
// Safe stack.
957+
def __safestack_pointer_address : RuntimeLibcallImpl<SAFESTACK_POINTER_ADDRESS>;
958+
958959
//--------------------------------------------------------------------
959960
// compiler-rt/libgcc but 64-bit only, not available by default
960961
//--------------------------------------------------------------------
@@ -1144,6 +1145,7 @@ defvar LibmHasLdexpF80 = LibcallImpls<(add ldexp_f80), isNotOSWindowsOrIsCygwinM
11441145
defvar LibmHasFrexpF128 = LibcallImpls<(add frexp_f128), isNotOSWindowsOrIsCygwinMinGW>;
11451146
defvar LibmHasLdexpF128 = LibcallImpls<(add ldexp_f128), isNotOSWindowsOrIsCygwinMinGW>;
11461147

1148+
defvar has__stack_chk_fail = LibcallImpls<(add __stack_chk_fail), isNotOSOpenBSD>;
11471149

11481150
//===----------------------------------------------------------------------===//
11491151
// Objective-C Runtime Libcalls
@@ -1221,7 +1223,8 @@ def AArch64SystemLibrary : SystemRuntimeLibrary<
12211223
LibcallImpls<(add bzero), isOSDarwin>,
12221224
DarwinExp10, DarwinSinCosStret,
12231225
LibmHasSinCosF32, LibmHasSinCosF64, LibmHasSinCosF128,
1224-
LibmHasExp10F32, LibmHasExp10F64, LibmHasExp10F128)
1226+
LibmHasExp10F32, LibmHasExp10F64, LibmHasExp10F128,
1227+
has__stack_chk_fail)
12251228
>;
12261229

12271230
// Prepend a # to every name
@@ -1237,7 +1240,7 @@ defset list<RuntimeLibcallImpl> WinArm64ECDefaultRuntimeLibcallImpls = {
12371240

12381241
def WindowsARM64ECSystemLibrary
12391242
: SystemRuntimeLibrary<isWindowsArm64EC,
1240-
(add WinArm64ECDefaultRuntimeLibcallImpls)>;
1243+
(add WinArm64ECDefaultRuntimeLibcallImpls, __stack_chk_fail)>;
12411244

12421245
//===----------------------------------------------------------------------===//
12431246
// AMDGPU Runtime Libcalls
@@ -1497,7 +1500,8 @@ def ARMSystemLibrary
14971500
// Use divmod compiler-rt calls for iOS 5.0 and later.
14981501
LibcallImpls<(add __divmodsi4, __udivmodsi4),
14991502
RuntimeLibcallPredicate<[{TT.isOSBinFormatMachO() &&
1500-
(!TT.isiOS() || !TT.isOSVersionLT(5, 0))}]>>)> {
1503+
(!TT.isiOS() || !TT.isOSVersionLT(5, 0))}]>>,
1504+
has__stack_chk_fail)> {
15011505
let DefaultLibcallCallingConv = LibcallCallingConv<[{
15021506
(!TT.isOSDarwin() && !TT.isiOS() && !TT.isWatchOS() && !TT.isDriverKit()) ?
15031507
(FloatABI == FloatABI::Hard ? CallingConv::ARM_AAPCS_VFP
@@ -1608,7 +1612,7 @@ def HexagonSystemLibrary
16081612
__umoddi3, __divdf3, __muldf3, __divsi3, __subdf3, sqrtf,
16091613
__divdi3, __umodsi3, __moddi3, __modsi3), HexagonLibcalls,
16101614
LibmHasSinCosF32, LibmHasSinCosF64, LibmHasSinCosF128,
1611-
exp10f, exp10, exp10l_f128)>;
1615+
exp10f, exp10, exp10l_f128, __stack_chk_fail)>;
16121616

16131617
//===----------------------------------------------------------------------===//
16141618
// Lanai Runtime Libcalls
@@ -1618,7 +1622,8 @@ def isLanai : RuntimeLibcallPredicate<"TT.getArch() == Triple::lanai">;
16181622

16191623
// Use fast calling convention for library functions.
16201624
def LanaiSystemLibrary
1621-
: SystemRuntimeLibrary<isLanai, (add DefaultRuntimeLibcallImpls)> {
1625+
: SystemRuntimeLibrary<isLanai, (add DefaultRuntimeLibcallImpls,
1626+
__stack_chk_fail)> {
16221627
let DefaultLibcallCallingConv = FASTCC;
16231628
}
16241629

@@ -1910,8 +1915,10 @@ def MSP430SystemLibrary
19101915
// TODO: __mspabi_[srli/srai/slli] ARE implemented in libgcc
19111916
__mspabi_srll,
19121917
__mspabi_sral,
1913-
__mspabi_slll
1918+
__mspabi_slll,
19141919
// __mspabi_[srlll/srall/sllll/rlli/rlll] are NOT implemented in libgcc
1920+
1921+
__stack_chk_fail
19151922
)
19161923
>;
19171924

@@ -2002,7 +2009,8 @@ def PPCSystemLibrary
20022009
LibmHasSinCosF32, LibmHasSinCosF64, LibmHasSinCosF128,
20032010
LibmHasSinCosPPCF128,
20042011
AvailableIf<memcpy, isNotAIX>,
2005-
LibcallImpls<(add Int128RTLibcalls), isPPC64>)>;
2012+
LibcallImpls<(add Int128RTLibcalls), isPPC64>,
2013+
has__stack_chk_fail)>;
20062014

20072015
//===----------------------------------------------------------------------===//
20082016
// RISCV Runtime Libcalls
@@ -2016,7 +2024,8 @@ def RISCVSystemLibrary
20162024
(add DefaultRuntimeLibcallImpls,
20172025
exp10f, exp10, exp10l_f128,
20182026
__riscv_flush_icache,
2019-
LibcallImpls<(add Int128RTLibcalls), isRISCV64>)>;
2027+
LibcallImpls<(add Int128RTLibcalls), isRISCV64>,
2028+
has__stack_chk_fail)>;
20202029

20212030
//===----------------------------------------------------------------------===//
20222031
// SPARC Runtime Libcalls
@@ -2083,7 +2092,8 @@ def SPARCSystemLibrary
20832092
sparc_umul, sparc_div, sparc_udiv, sparc_rem, sparc_urem,
20842093
LibcallImpls<(add _Q_qtoll, _Q_qtoull, _Q_lltoq, _Q_ulltoq), isSPARC32>,
20852094
LibcallImpls<(add SPARC64_MulDivCalls, Int128RTLibcalls), isSPARC64>,
2086-
LibmHasSinCosF32, LibmHasSinCosF64, LibmHasSinCosF128)
2095+
LibmHasSinCosF32, LibmHasSinCosF64, LibmHasSinCosF128,
2096+
has__stack_chk_fail)
20872097
>;
20882098

20892099
//===----------------------------------------------------------------------===//
@@ -2143,7 +2153,8 @@ defvar X86CommonLibcalls =
21432153
LibcallImpls<(add MostPowI), isNotOSMSVCRT>,
21442154
// FIXME: MSVCRT doesn't have powi. The f128 case is added as a
21452155
// hack for one test relying on it.
2146-
__powitf2_f128
2156+
__powitf2_f128,
2157+
has__stack_chk_fail
21472158
);
21482159

21492160
defvar Windows32DivRemMulCalls =
@@ -2288,7 +2299,8 @@ def WasmSystemLibrary
22882299
(add DefaultRuntimeLibcallImpls, Int128RTLibcalls,
22892300
CompilerRTOnlyInt64Libcalls, CompilerRTOnlyInt128Libcalls,
22902301
exp10f, exp10,
2291-
emscripten_return_address)>;
2302+
emscripten_return_address,
2303+
__stack_chk_fail)>;
22922304

22932305
//===----------------------------------------------------------------------===//
22942306
// Legacy Default Runtime Libcalls
@@ -2310,5 +2322,6 @@ def LegacyDefaultSystemLibrary
23102322
LibmHasSinCosF32, LibmHasSinCosF64, LibmHasSinCosF128,
23112323
exp10f, exp10, exp10l_f128,
23122324
__powisf2, __powidf2, __powitf2_f128,
2313-
LibcallImpls<(add Int128RTLibcalls), isArch64Bit>
2325+
LibcallImpls<(add Int128RTLibcalls), isArch64Bit>,
2326+
has__stack_chk_fail
23142327
)>;

llvm/lib/IR/RuntimeLibcalls.cpp

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -78,10 +78,8 @@ void RuntimeLibcallsInfo::initLibcalls(const Triple &TT,
7878
setLibcallImpl(RTLIB::UNWIND_RESUME, RTLIB::_Unwind_SjLj_Resume);
7979
}
8080

81-
if (TT.isOSOpenBSD()) {
82-
setLibcallImpl(RTLIB::STACKPROTECTOR_CHECK_FAIL, RTLIB::Unsupported);
81+
if (TT.isOSOpenBSD())
8382
setLibcallImpl(RTLIB::STACK_SMASH_HANDLER, RTLIB::__stack_smash_handler);
84-
}
8583

8684
if (TT.isARM() || TT.isThumb()) {
8785
setARMLibcallNames(*this, TT, FloatABI, EABIVersion);

0 commit comments

Comments
 (0)