Sync x86 chkstk intrinsics with LLVM

Incorporates the following commits:
885d7b759b
1f9eff100c
7a5cba8bea
This commit is contained in:
Kleis Auke Wolthuizen 2024-02-10 14:47:03 +01:00
parent 2e5b0ec1fe
commit f04f8a6a9d
3 changed files with 2 additions and 91 deletions

View file

@ -163,7 +163,6 @@ features = ["c"]
- [ ] i386/ashldi3.S
- [ ] i386/ashrdi3.S
- [x] i386/chkstk.S
- [x] i386/chkstk2.S
- [ ] i386/divdi3.S
- [ ] i386/lshrdi3.S
- [ ] i386/moddi3.S
@ -192,7 +191,6 @@ features = ["c"]
- [x] umoddi3.c
- [x] umodsi3.c
- [x] x86_64/chkstk.S
- [x] x86_64/chkstk2.S
These builtins are needed to support 128-bit integers, which are in the process of being added to Rust.

View file

@ -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",

View file

@ -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]
@ -36,49 +35,6 @@ intrinsics! {
options(noreturn, att_syntax)
);
}
#[naked]
#[cfg(all(
any(all(windows, target_env = "gnu"), target_os = "uefi"),
not(feature = "no-asm")
))]
pub unsafe extern "C" fn __alloca() {
core::arch::asm!(
"mov %rcx,%rax", // x64 _alloca is a normal function with parameter in rcx
"jmp ___chkstk", // Jump to ___chkstk since fallthrough may be unreliable"
options(noreturn, att_syntax)
);
}
#[naked]
#[cfg(all(
any(all(windows, target_env = "gnu"), target_os = "uefi"),
not(feature = "no-asm")
))]
pub unsafe extern "C" fn ___chkstk() {
core::arch::asm!(
"push %rcx",
"cmp $0x1000,%rax",
"lea 16(%rsp),%rcx", // rsp before calling this routine -> rcx
"jb 1f",
"2:",
"sub $0x1000,%rcx",
"test %rcx,(%rcx)",
"sub $0x1000,%rax",
"cmp $0x1000,%rax",
"ja 2b",
"1:",
"sub %rax,%rcx",
"test %rcx,(%rcx)",
"lea 8(%rsp),%rax", // load pointer to the return address into rax
"mov %rcx,%rsp", // install the new top of stack pointer into rsp
"mov -8(%rax),%rcx", // restore rcx
"push (%rax)", // push return address onto the stack
"sub %rsp,%rax", // restore the original value in rax
"ret",
options(noreturn, att_syntax)
);
}
}
// HACK(https://github.com/rust-lang/rust/issues/62785): x86_64-unknown-uefi needs special LLVM