Skip to content

Commit d32d5ee

Browse files
committed
Sync x86 chkstk intrinsics with LLVM
Incorporates the following commits: llvm/llvm-project@885d7b7 llvm/llvm-project@1f9eff1 llvm/llvm-project@7a5cba8
1 parent 9e11560 commit d32d5ee

File tree

3 files changed

+2
-91
lines changed

3 files changed

+2
-91
lines changed

README.md

-2
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,6 @@ features = ["c"]
163163
- [ ] i386/ashldi3.S
164164
- [ ] i386/ashrdi3.S
165165
- [x] i386/chkstk.S
166-
- [x] i386/chkstk2.S
167166
- [ ] i386/divdi3.S
168167
- [ ] i386/lshrdi3.S
169168
- [ ] i386/moddi3.S
@@ -192,7 +191,6 @@ features = ["c"]
192191
- [x] umoddi3.c
193192
- [x] umodsi3.c
194193
- [x] x86_64/chkstk.S
195-
- [x] x86_64/chkstk2.S
196194

197195
These builtins are needed to support 128-bit integers, which are in the process of being added to Rust.
198196

src/x86.rs

+2-45
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ use core::intrinsics;
66
// calling convention which can't be implemented using a normal Rust function
77

88
// NOTE These functions are never mangled as they are not tested against compiler-rt
9-
// and mangling ___chkstk would break the `jmp ___chkstk` instruction in __alloca
109

1110
intrinsics! {
1211
#[naked]
@@ -15,50 +14,8 @@ intrinsics! {
1514
target_env = "gnu",
1615
not(feature = "no-asm")
1716
))]
18-
pub unsafe extern "C" fn ___chkstk_ms() {
19-
core::arch::asm!(
20-
"push %ecx",
21-
"push %eax",
22-
"cmp $0x1000,%eax",
23-
"lea 12(%esp),%ecx",
24-
"jb 1f",
25-
"2:",
26-
"sub $0x1000,%ecx",
27-
"test %ecx,(%ecx)",
28-
"sub $0x1000,%eax",
29-
"cmp $0x1000,%eax",
30-
"ja 2b",
31-
"1:",
32-
"sub %eax,%ecx",
33-
"test %ecx,(%ecx)",
34-
"pop %eax",
35-
"pop %ecx",
36-
"ret",
37-
options(noreturn, att_syntax)
38-
);
39-
}
40-
41-
// FIXME: __alloca should be an alias to __chkstk
42-
#[naked]
43-
#[cfg(all(
44-
windows,
45-
target_env = "gnu",
46-
not(feature = "no-asm")
47-
))]
48-
pub unsafe extern "C" fn __alloca() {
49-
core::arch::asm!(
50-
"jmp ___chkstk", // Jump to ___chkstk since fallthrough may be unreliable"
51-
options(noreturn, att_syntax)
52-
);
53-
}
54-
55-
#[naked]
56-
#[cfg(all(
57-
windows,
58-
target_env = "gnu",
59-
not(feature = "no-asm")
60-
))]
61-
pub unsafe extern "C" fn ___chkstk() {
17+
pub unsafe extern "C" fn _alloca() {
18+
// _chkstk and _alloca are the same function
6219
core::arch::asm!(
6320
"push %ecx",
6421
"cmp $0x1000,%eax",

src/x86_64.rs

-44
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ use core::intrinsics;
66
// calling convention which can't be implemented using a normal Rust function
77

88
// NOTE These functions are never mangled as they are not tested against compiler-rt
9-
// and mangling ___chkstk would break the `jmp ___chkstk` instruction in __alloca
109

1110
intrinsics! {
1211
#[naked]
@@ -36,49 +35,6 @@ intrinsics! {
3635
options(noreturn, att_syntax)
3736
);
3837
}
39-
40-
#[naked]
41-
#[cfg(all(
42-
any(all(windows, target_env = "gnu"), target_os = "uefi"),
43-
not(feature = "no-asm")
44-
))]
45-
pub unsafe extern "C" fn __alloca() {
46-
core::arch::asm!(
47-
"mov %rcx,%rax", // x64 _alloca is a normal function with parameter in rcx
48-
"jmp ___chkstk", // Jump to ___chkstk since fallthrough may be unreliable"
49-
options(noreturn, att_syntax)
50-
);
51-
}
52-
53-
#[naked]
54-
#[cfg(all(
55-
any(all(windows, target_env = "gnu"), target_os = "uefi"),
56-
not(feature = "no-asm")
57-
))]
58-
pub unsafe extern "C" fn ___chkstk() {
59-
core::arch::asm!(
60-
"push %rcx",
61-
"cmp $0x1000,%rax",
62-
"lea 16(%rsp),%rcx", // rsp before calling this routine -> rcx
63-
"jb 1f",
64-
"2:",
65-
"sub $0x1000,%rcx",
66-
"test %rcx,(%rcx)",
67-
"sub $0x1000,%rax",
68-
"cmp $0x1000,%rax",
69-
"ja 2b",
70-
"1:",
71-
"sub %rax,%rcx",
72-
"test %rcx,(%rcx)",
73-
"lea 8(%rsp),%rax", // load pointer to the return address into rax
74-
"mov %rcx,%rsp", // install the new top of stack pointer into rsp
75-
"mov -8(%rax),%rcx", // restore rcx
76-
"push (%rax)", // push return address onto the stack
77-
"sub %rsp,%rax", // restore the original value in rax
78-
"ret",
79-
options(noreturn, att_syntax)
80-
);
81-
}
8238
}
8339

8440
// HACK(https://github.com/rust-lang/rust/issues/62785): x86_64-unknown-uefi needs special LLVM

0 commit comments

Comments
 (0)