Skip to content

RuntimeLibcalls: Move __stack_chk_fail config to tablegen #148789

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: users/arsenm/runtime-libcalls/remove-darwin-half-convert-libcall-case
Choose a base branch
from

Conversation

arsenm
Copy link
Contributor

@arsenm arsenm commented Jul 15, 2025

No description provided.

@arsenm arsenm marked this pull request as ready for review July 15, 2025 06:59
@llvmbot
Copy link
Member

llvmbot commented Jul 15, 2025

@llvm/pr-subscribers-tablegen
@llvm/pr-subscribers-llvm-ir

@llvm/pr-subscribers-backend-arm

Author: Matt Arsenault (arsenm)

Changes

Full diff: https://github.com/llvm/llvm-project/pull/148789.diff

2 Files Affected:

  • (modified) llvm/include/llvm/IR/RuntimeLibcalls.td (+21-11)
  • (modified) llvm/lib/IR/RuntimeLibcalls.cpp (-4)
diff --git a/llvm/include/llvm/IR/RuntimeLibcalls.td b/llvm/include/llvm/IR/RuntimeLibcalls.td
index af339e2a55cf2..4d7d0fbd1a511 100644
--- a/llvm/include/llvm/IR/RuntimeLibcalls.td
+++ b/llvm/include/llvm/IR/RuntimeLibcalls.td
@@ -18,6 +18,7 @@ class DuplicateLibcallImplWithPrefix<RuntimeLibcallImpl Impl, string prefix>
 /// Libcall Predicates
 def isOSDarwin : RuntimeLibcallPredicate<"TT.isOSDarwin()">;
 def isOSOpenBSD : RuntimeLibcallPredicate<"TT.isOSOpenBSD()">;
+def isNotOSOpenBSD : RuntimeLibcallPredicate<"!TT.isOSOpenBSD()">;
 def isOSWindows : RuntimeLibcallPredicate<"TT.isOSWindows()">;
 def isNotOSWindows : RuntimeLibcallPredicate<"!TT.isOSWindows()">;
 def isNotOSMSVCRT : RuntimeLibcallPredicate<"!TT.isOSMSVCRT()">;
@@ -698,9 +699,6 @@ foreach lc = LibCalls__atomic in {
   def __#!tolower(!cast<string>(lc)) : RuntimeLibcallImpl<lc>;
 }
 
-// Stack Protector Fail
-def __stack_chk_fail : RuntimeLibcallImpl<STACKPROTECTOR_CHECK_FAIL>;
-
 // Deoptimization
 def __llvm_deoptimize : RuntimeLibcallImpl<DEOPTIMIZE>;
 
@@ -945,6 +943,9 @@ def exp10l_f80 : RuntimeLibcallImpl<EXP10_F80, "exp10l">;
 def exp10l_f128 : RuntimeLibcallImpl<EXP10_F128, "exp10l">;
 def exp10l_ppcf128 : RuntimeLibcallImpl<EXP10_PPCF128, "exp10l">;
 
+// Stack Protector Fail
+def __stack_chk_fail : RuntimeLibcallImpl<STACKPROTECTOR_CHECK_FAIL>;
+
 //--------------------------------------------------------------------
 // compiler-rt/libgcc but 64-bit only, not available by default
 //--------------------------------------------------------------------
@@ -1128,6 +1129,7 @@ defvar LibmHasLdexpF80 = LibcallImpls<(add ldexp_f80), isNotOSWindowsOrIsCygwinM
 defvar LibmHasFrexpF128 = LibcallImpls<(add frexp_f128), isNotOSWindowsOrIsCygwinMinGW>;
 defvar LibmHasLdexpF128 = LibcallImpls<(add ldexp_f128), isNotOSWindowsOrIsCygwinMinGW>;
 
+defvar has__stack_chk_fail = LibcallImpls<(add __stack_chk_fail), isNotOSOpenBSD>;
 
 //===----------------------------------------------------------------------===//
 // Objective-C Runtime Libcalls
@@ -1205,7 +1207,8 @@ def AArch64SystemLibrary : SystemRuntimeLibrary<
        LibcallImpls<(add bzero), isOSDarwin>,
        DarwinExp10, DarwinSinCosStret,
        LibmHasSinCosF32, LibmHasSinCosF64, LibmHasSinCosF128,
-       LibmHasExp10F32, LibmHasExp10F64, LibmHasExp10F128)
+       LibmHasExp10F32, LibmHasExp10F64, LibmHasExp10F128,
+       has__stack_chk_fail)
 >;
 
 // Prepend a # to every name
@@ -1481,7 +1484,8 @@ def ARMSystemLibrary
            // Use divmod compiler-rt calls for iOS 5.0 and later.
            LibcallImpls<(add __divmodsi4, __udivmodsi4),
                         RuntimeLibcallPredicate<[{TT.isOSBinFormatMachO() &&
-                                                  (!TT.isiOS() || !TT.isOSVersionLT(5, 0))}]>>)> {
+                                                  (!TT.isiOS() || !TT.isOSVersionLT(5, 0))}]>>,
+           has__stack_chk_fail)> {
   let DefaultLibcallCallingConv = LibcallCallingConv<[{
      (!TT.isOSDarwin() && !TT.isiOS() && !TT.isWatchOS() && !TT.isDriverKit()) ?
         (FloatABI == FloatABI::Hard ? CallingConv::ARM_AAPCS_VFP
@@ -1976,7 +1980,8 @@ def PPCSystemLibrary
            LibmHasSinCosF32, LibmHasSinCosF64, LibmHasSinCosF128,
            LibmHasSinCosPPCF128,
            AvailableIf<memcpy, isNotAIX>,
-           LibcallImpls<(add Int128RTLibcalls), isPPC64>)>;
+           LibcallImpls<(add Int128RTLibcalls), isPPC64>,
+           has__stack_chk_fail)>;
 
 //===----------------------------------------------------------------------===//
 // RISCV Runtime Libcalls
@@ -1990,7 +1995,8 @@ def RISCVSystemLibrary
       (add DefaultRuntimeLibcallImpls,
            exp10f, exp10, exp10l_f128,
            __riscv_flush_icache,
-           LibcallImpls<(add Int128RTLibcalls), isRISCV64>)>;
+           LibcallImpls<(add Int128RTLibcalls), isRISCV64>,
+           has__stack_chk_fail)>;
 
 //===----------------------------------------------------------------------===//
 // SPARC Runtime Libcalls
@@ -2057,7 +2063,8 @@ def SPARCSystemLibrary
             sparc_umul, sparc_div, sparc_udiv, sparc_rem, sparc_urem,
        LibcallImpls<(add _Q_qtoll, _Q_qtoull, _Q_lltoq, _Q_ulltoq), isSPARC32>,
        LibcallImpls<(add SPARC64_MulDivCalls, Int128RTLibcalls), isSPARC64>,
-       LibmHasSinCosF32, LibmHasSinCosF64, LibmHasSinCosF128)
+       LibmHasSinCosF32, LibmHasSinCosF64, LibmHasSinCosF128,
+       has__stack_chk_fail)
 >;
 
 //===----------------------------------------------------------------------===//
@@ -2106,7 +2113,8 @@ defvar X86CommonLibcalls =
        LibcallImpls<(add MostPowI), isNotOSMSVCRT>,
        // FIXME: MSVCRT doesn't have powi. The f128 case is added as a
        // hack for one test relying on it.
-       __powitf2_f128
+       __powitf2_f128,
+       has__stack_chk_fail
 );
 
 defvar Windows32DivRemMulCalls =
@@ -2251,7 +2259,8 @@ def WasmSystemLibrary
       (add DefaultRuntimeLibcallImpls, Int128RTLibcalls,
            CompilerRTOnlyInt64Libcalls, CompilerRTOnlyInt128Libcalls,
            exp10f, exp10,
-           emscripten_return_address)>;
+           emscripten_return_address,
+           __stack_chk_fail)>;
 
 //===----------------------------------------------------------------------===//
 // Legacy Default Runtime Libcalls
@@ -2274,5 +2283,6 @@ def LegacyDefaultSystemLibrary
          LibmHasSinCosF32, LibmHasSinCosF64, LibmHasSinCosF128,
          exp10f, exp10, exp10l_f128,
          __powisf2, __powidf2, __powitf2_f128,
-         LibcallImpls<(add Int128RTLibcalls), isArch64Bit>
+         LibcallImpls<(add Int128RTLibcalls), isArch64Bit>,
+         has__stack_chk_fail
 )>;
diff --git a/llvm/lib/IR/RuntimeLibcalls.cpp b/llvm/lib/IR/RuntimeLibcalls.cpp
index 8ca31dff900cb..12aa9dc8d3943 100644
--- a/llvm/lib/IR/RuntimeLibcalls.cpp
+++ b/llvm/lib/IR/RuntimeLibcalls.cpp
@@ -77,10 +77,6 @@ void RuntimeLibcallsInfo::initLibcalls(const Triple &TT,
       setLibcallImpl(RTLIB::UNWIND_RESUME, RTLIB::_Unwind_SjLj_Resume);
   }
 
-  if (TT.isOSOpenBSD()) {
-    setLibcallImpl(RTLIB::STACKPROTECTOR_CHECK_FAIL, RTLIB::Unsupported);
-  }
-
   if (TT.isARM() || TT.isThumb()) {
     setARMLibcallNames(*this, TT, FloatABI, EABIVersion);
     return;

@arsenm arsenm force-pushed the users/arsenm/runtime-libcalls/move-_stack_chk_fail-tablegen branch from d9e08a6 to 4717482 Compare July 15, 2025 07:14
@arsenm arsenm force-pushed the users/arsenm/runtime-libcalls/remove-darwin-half-convert-libcall-case branch from 39867e3 to b5bbf7f Compare July 15, 2025 07:21
@arsenm arsenm force-pushed the users/arsenm/runtime-libcalls/move-_stack_chk_fail-tablegen branch from 4717482 to 407ba2c Compare July 15, 2025 07:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants