File tree 3 files changed +73
-2
lines changed
3 files changed +73
-2
lines changed Original file line number Diff line number Diff line change @@ -133,8 +133,8 @@ See [rust-lang/rust#35437][0].
133
133
- [x] udivsi3.c
134
134
- [x] umoddi3.c
135
135
- [x] umodsi3.c
136
- - [ ] x86_64/chkstk.S
137
- - [ ] x86_64/chkstk2.S
136
+ - [x ] x86_64/chkstk.S
137
+ - [x ] x86_64/chkstk2.S
138
138
139
139
These builtins are needed to support 128-bit integers, which are in the process of being added to Rust.
140
140
Original file line number Diff line number Diff line change @@ -23,6 +23,9 @@ extern crate rlibc;
23
23
#[ cfg( target_arch = "arm" ) ]
24
24
pub mod arm;
25
25
26
+ #[ cfg( target_arch = "x86_64" ) ]
27
+ pub mod x86_64;
28
+
26
29
pub mod udiv;
27
30
pub mod mul;
28
31
pub mod shift;
Original file line number Diff line number Diff line change
1
+ use core:: intrinsics;
2
+
3
+ // NOTE These functions are implemented using assembly because they using a custom
4
+ // calling convention which can't be implemented using a normal Rust function
5
+
6
+ // NOTE These functions are never mangled as they are not tested against compiler-rt
7
+ // and mangling ___chkstk would break the `jmp ___chkstk` instruction in __alloca
8
+
9
+ #[ cfg( windows) ]
10
+ #[ naked]
11
+ #[ no_mangle]
12
+ pub unsafe fn ___chkstk_ms ( ) {
13
+ asm ! ( "push %rcx
14
+ push %rax
15
+ cmp $$0x1000,%rax
16
+ lea 24(%rsp),%rcx
17
+ jb 1f
18
+ 2:
19
+ sub $$0x1000,%rcx
20
+ test %rcx,(%rcx)
21
+ sub $$0x1000,%rax
22
+ cmp $$0x1000,%rax
23
+ ja 2b
24
+ 1:
25
+ sub %rax,%rcx
26
+ test %rcx,(%rcx)
27
+ pop %rax
28
+ pop %rcx
29
+ ret" ) ;
30
+ intrinsics:: unreachable ( ) ;
31
+ }
32
+
33
+ #[ cfg( windows) ]
34
+ #[ naked]
35
+ #[ no_mangle]
36
+ pub unsafe fn __alloca ( ) {
37
+ asm ! ( "mov %rcx,%rax // x64 _alloca is a normal function with parameter in rcx
38
+ jmp ___chkstk // Jump to ___chkstk since fallthrough may be unreliable" ) ;
39
+ intrinsics:: unreachable ( ) ;
40
+ }
41
+
42
+ #[ cfg( windows) ]
43
+ #[ naked]
44
+ #[ no_mangle]
45
+ pub unsafe fn ___chkstk ( ) {
46
+ asm ! ( "push %rcx
47
+ cmp $$0x1000,%rax
48
+ lea 16(%rsp),%rcx // rsp before calling this routine -> rcx
49
+ jb 1f
50
+ 2:
51
+ sub $$0x1000,%rcx
52
+ test %rcx,(%rcx)
53
+ sub $$0x1000,%rax
54
+ cmp $$0x1000,%rax
55
+ ja 2b
56
+ 1:
57
+ sub %rax,%rcx
58
+ test %rcx,(%rcx)
59
+
60
+ lea 8(%rsp),%rax // load pointer to the return address into rax
61
+ mov %rcx,%rsp // install the new top of stack pointer into rsp
62
+ mov -8(%rax),%rcx // restore rcx
63
+ push (%rax) // push return address onto the stack
64
+ sub %rsp,%rax // restore the original value in rax
65
+ ret" ) ;
66
+ intrinsics:: unreachable ( ) ;
67
+ }
68
+
You can’t perform that action at this time.
0 commit comments