From d32d5eeeb565c3c6f4288976e4bc07d82d9694fd Mon Sep 17 00:00:00 2001
From: Kleis Auke Wolthuizen <github@kleisauke.nl>
Date: Sat, 10 Feb 2024 14:47:03 +0100
Subject: [PATCH] Sync x86 chkstk intrinsics with LLVM

Incorporates the following commits:
https://github.com/llvm/llvm-project/commit/885d7b759b5c166c07c07f4c58c6e0ba110fb0c2
https://github.com/llvm/llvm-project/commit/1f9eff100ce8faea1284d68b779d844c6e019b77
https://github.com/llvm/llvm-project/commit/7a5cba8bea8f774d48db1b0426bcc102edd2b69f
---

diff --git a/vendor/compiler_builtins/src/x86.rs b/vendor/compiler_builtins/src/x86.rs
index fd1f32e3..5016816e 100644
--- a/vendor/compiler_builtins/src/x86.rs
+++ b/vendor/compiler_builtins/src/x86.rs
@@ -6,7 +6,6 @@ use core::intrinsics;
 // calling convention which can't be implemented using a normal Rust function
 
 // NOTE These functions are never mangled as they are not tested against compiler-rt
-// and mangling ___chkstk would break the `jmp ___chkstk` instruction in __alloca
 
 intrinsics! {
     #[naked]
@@ -15,50 +14,8 @@ intrinsics! {
         target_env = "gnu",
         not(feature = "no-asm")
     ))]
-    pub unsafe extern "C" fn ___chkstk_ms() {
-        core::arch::asm!(
-            "push   %ecx",
-            "push   %eax",
-            "cmp    $0x1000,%eax",
-            "lea    12(%esp),%ecx",
-            "jb     1f",
-            "2:",
-            "sub    $0x1000,%ecx",
-            "test   %ecx,(%ecx)",
-            "sub    $0x1000,%eax",
-            "cmp    $0x1000,%eax",
-            "ja     2b",
-            "1:",
-            "sub    %eax,%ecx",
-            "test   %ecx,(%ecx)",
-            "pop    %eax",
-            "pop    %ecx",
-            "ret",
-            options(noreturn, att_syntax)
-        );
-    }
-
-    // FIXME: __alloca should be an alias to __chkstk
-    #[naked]
-    #[cfg(all(
-        windows,
-        target_env = "gnu",
-        not(feature = "no-asm")
-    ))]
-    pub unsafe extern "C" fn __alloca() {
-        core::arch::asm!(
-            "jmp ___chkstk", // Jump to ___chkstk since fallthrough may be unreliable"
-            options(noreturn, att_syntax)
-        );
-    }
-
-    #[naked]
-    #[cfg(all(
-        windows,
-        target_env = "gnu",
-        not(feature = "no-asm")
-    ))]
-    pub unsafe extern "C" fn ___chkstk() {
+    pub unsafe extern "C" fn _alloca() {
+        // _chkstk and _alloca are the same function
         core::arch::asm!(
             "push   %ecx",
             "cmp    $0x1000,%eax",
