Skip to content

Commit cdfde23

Browse files
committed
RuntimeLibcalls: Move __stack_chk_fail config to tablegen
1 parent 9404c93 commit cdfde23

File tree

2 files changed

+30
-18
lines changed

2 files changed

+30
-18
lines changed

llvm/include/llvm/IR/RuntimeLibcalls.td

Lines changed: 29 additions & 15 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,9 +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-
711709
// Safe stack.
712710
def __safestack_pointer_address : RuntimeLibcallImpl<SAFESTACK_POINTER_ADDRESS>;
713711

@@ -955,6 +953,9 @@ def exp10l_f80 : RuntimeLibcallImpl<EXP10_F80, "exp10l">;
955953
def exp10l_f128 : RuntimeLibcallImpl<EXP10_F128, "exp10l">;
956954
def exp10l_ppcf128 : RuntimeLibcallImpl<EXP10_PPCF128, "exp10l">;
957955

956+
// Stack Protector Fail
957+
def __stack_chk_fail : RuntimeLibcallImpl<STACKPROTECTOR_CHECK_FAIL>;
958+
958959
//--------------------------------------------------------------------
959960
// compiler-rt/libgcc but 64-bit only, not available by default
960961
//--------------------------------------------------------------------
@@ -1149,6 +1150,8 @@ defvar LibmHasLdexpF80 = LibcallImpls<(add ldexp_f80), isNotOSWindowsOrIsCygwinM
11491150
defvar LibmHasFrexpF128 = LibcallImpls<(add frexp_f128), isNotOSWindowsOrIsCygwinMinGW>;
11501151
defvar LibmHasLdexpF128 = LibcallImpls<(add ldexp_f128), isNotOSWindowsOrIsCygwinMinGW>;
11511152

1153+
defvar has__stack_chk_fail = LibcallImpls<(add __stack_chk_fail), isNotOSOpenBSD>;
1154+
11521155
//===----------------------------------------------------------------------===//
11531156
// Objective-C Runtime Libcalls
11541157
//===----------------------------------------------------------------------===//
@@ -1225,7 +1228,8 @@ def AArch64SystemLibrary : SystemRuntimeLibrary<
12251228
LibcallImpls<(add bzero), isOSDarwin>,
12261229
DarwinExp10, DarwinSinCosStret,
12271230
LibmHasSinCosF32, LibmHasSinCosF64, LibmHasSinCosF128,
1228-
DefaultLibmExp10)
1231+
DefaultLibmExp10,
1232+
has__stack_chk_fail)
12291233
>;
12301234

12311235
// Prepend a # to every name
@@ -1241,7 +1245,7 @@ defset list<RuntimeLibcallImpl> WinArm64ECDefaultRuntimeLibcallImpls = {
12411245

12421246
def WindowsARM64ECSystemLibrary
12431247
: SystemRuntimeLibrary<isWindowsArm64EC,
1244-
(add WinArm64ECDefaultRuntimeLibcallImpls)>;
1248+
(add WinArm64ECDefaultRuntimeLibcallImpls, __stack_chk_fail)>;
12451249

12461250
//===----------------------------------------------------------------------===//
12471251
// AMDGPU Runtime Libcalls
@@ -1501,7 +1505,8 @@ def ARMSystemLibrary
15011505
// Use divmod compiler-rt calls for iOS 5.0 and later.
15021506
LibcallImpls<(add __divmodsi4, __udivmodsi4),
15031507
RuntimeLibcallPredicate<[{TT.isOSBinFormatMachO() &&
1504-
(!TT.isiOS() || !TT.isOSVersionLT(5, 0))}]>>)> {
1508+
(!TT.isiOS() || !TT.isOSVersionLT(5, 0))}]>>,
1509+
has__stack_chk_fail)> {
15051510
let DefaultLibcallCallingConv = LibcallCallingConv<[{
15061511
(!TT.isOSDarwin() && !TT.isiOS() && !TT.isWatchOS() && !TT.isDriverKit()) ?
15071512
(FloatABI == FloatABI::Hard ? CallingConv::ARM_AAPCS_VFP
@@ -1612,7 +1617,7 @@ def HexagonSystemLibrary
16121617
__umoddi3, __divdf3, __muldf3, __divsi3, __subdf3, sqrtf,
16131618
__divdi3, __umodsi3, __moddi3, __modsi3), HexagonLibcalls,
16141619
LibmHasSinCosF32, LibmHasSinCosF64, LibmHasSinCosF128,
1615-
exp10f, exp10, exp10l_f128)>;
1620+
exp10f, exp10, exp10l_f128, __stack_chk_fail)>;
16161621

16171622
//===----------------------------------------------------------------------===//
16181623
// Lanai Runtime Libcalls
@@ -1622,7 +1627,8 @@ def isLanai : RuntimeLibcallPredicate<"TT.getArch() == Triple::lanai">;
16221627

16231628
// Use fast calling convention for library functions.
16241629
def LanaiSystemLibrary
1625-
: SystemRuntimeLibrary<isLanai, (add DefaultRuntimeLibcallImpls)> {
1630+
: SystemRuntimeLibrary<isLanai, (add DefaultRuntimeLibcallImpls,
1631+
__stack_chk_fail)> {
16261632
let DefaultLibcallCallingConv = FASTCC;
16271633
}
16281634

@@ -1914,8 +1920,10 @@ def MSP430SystemLibrary
19141920
// TODO: __mspabi_[srli/srai/slli] ARE implemented in libgcc
19151921
__mspabi_srll,
19161922
__mspabi_sral,
1917-
__mspabi_slll
1923+
__mspabi_slll,
19181924
// __mspabi_[srlll/srall/sllll/rlli/rlll] are NOT implemented in libgcc
1925+
1926+
__stack_chk_fail
19191927
)
19201928
>;
19211929

@@ -2006,7 +2014,8 @@ def PPCSystemLibrary
20062014
LibmHasSinCosF32, LibmHasSinCosF64, LibmHasSinCosF128,
20072015
LibmHasSinCosPPCF128,
20082016
AvailableIf<memcpy, isNotAIX>,
2009-
LibcallImpls<(add Int128RTLibcalls), isPPC64>)>;
2017+
LibcallImpls<(add Int128RTLibcalls), isPPC64>,
2018+
has__stack_chk_fail)>;
20102019

20112020
//===----------------------------------------------------------------------===//
20122021
// RISCV Runtime Libcalls
@@ -2020,7 +2029,8 @@ def RISCVSystemLibrary
20202029
(add DefaultRuntimeLibcallImpls,
20212030
exp10f, exp10, exp10l_f128,
20222031
__riscv_flush_icache,
2023-
LibcallImpls<(add Int128RTLibcalls), isRISCV64>)>;
2032+
LibcallImpls<(add Int128RTLibcalls), isRISCV64>,
2033+
has__stack_chk_fail)>;
20242034

20252035
//===----------------------------------------------------------------------===//
20262036
// SPARC Runtime Libcalls
@@ -2087,7 +2097,8 @@ def SPARCSystemLibrary
20872097
sparc_umul, sparc_div, sparc_udiv, sparc_rem, sparc_urem,
20882098
LibcallImpls<(add _Q_qtoll, _Q_qtoull, _Q_lltoq, _Q_ulltoq), isSPARC32>,
20892099
LibcallImpls<(add SPARC64_MulDivCalls, Int128RTLibcalls), isSPARC64>,
2090-
LibmHasSinCosF32, LibmHasSinCosF64, LibmHasSinCosF128)
2100+
LibmHasSinCosF32, LibmHasSinCosF64, LibmHasSinCosF128,
2101+
has__stack_chk_fail)
20912102
>;
20922103

20932104
//===----------------------------------------------------------------------===//
@@ -2147,7 +2158,8 @@ defvar X86CommonLibcalls =
21472158
LibcallImpls<(add MostPowI), isNotOSMSVCRT>,
21482159
// FIXME: MSVCRT doesn't have powi. The f128 case is added as a
21492160
// hack for one test relying on it.
2150-
__powitf2_f128
2161+
__powitf2_f128,
2162+
has__stack_chk_fail
21512163
);
21522164

21532165
defvar Windows32DivRemMulCalls =
@@ -2292,7 +2304,8 @@ def WasmSystemLibrary
22922304
(add DefaultRuntimeLibcallImpls, Int128RTLibcalls,
22932305
CompilerRTOnlyInt64Libcalls, CompilerRTOnlyInt128Libcalls,
22942306
exp10f, exp10,
2295-
emscripten_return_address)>;
2307+
emscripten_return_address,
2308+
__stack_chk_fail)>;
22962309

22972310
//===----------------------------------------------------------------------===//
22982311
// Legacy Default Runtime Libcalls
@@ -2314,5 +2327,6 @@ def LegacyDefaultSystemLibrary
23142327
LibmHasSinCosF32, LibmHasSinCosF64, LibmHasSinCosF128,
23152328
exp10f, exp10, exp10l_f128,
23162329
__powisf2, __powidf2, __powitf2_f128,
2317-
LibcallImpls<(add Int128RTLibcalls), isArch64Bit>
2330+
LibcallImpls<(add Int128RTLibcalls), isArch64Bit>,
2331+
has__stack_chk_fail
23182332
)>;

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)