5
5
// LLVM generates a call to this to allocate more stack space in a function
6
6
// prolog when we run out.
7
7
8
- #if defined(__APPLE__) || defined(_WIN32)
9
- #define UPCALL_NEW_STACK _upcall_new_stack
10
- #define UPCALL_DEL_STACK _upcall_del_stack
11
- #define RUST_GET_TASK _rust_get_task
12
- #define UPCALL_CALL_C _upcall_call_shim_on_c_stack
8
+ #if defined(__APPLE__)
9
+ #define RUST_GET_TASK L_rust_get_task$stub
10
+ #define UPCALL_CALL_C L_upcall_call_shim_on_c_stack$stub
13
11
#define MORESTACK ___morestack
14
12
#else
13
+ #if defined(__linux__)
15
14
#define UPCALL_NEW_STACK upcall_new_stack
16
15
#define UPCALL_DEL_STACK upcall_del_stack
17
16
#define RUST_GET_TASK rust_get_task
18
17
#define UPCALL_CALL_C upcall_call_shim_on_c_stack
19
18
#define MORESTACK __morestack
19
+ #else
20
+ #define UPCALL_NEW_STACK _upcall_new_stack
21
+ #define UPCALL_DEL_STACK _upcall_del_stack
22
+ #define RUST_GET_TASK _rust_get_task
23
+ #define UPCALL_CALL_C _upcall_call_shim_on_c_stack
24
+ #define MORESTACK __morestack
25
+ #endif
20
26
#endif
21
27
22
28
// FIXME: Future LLVM patches remove these 8 alignment bytes from
43
49
.type MORESTACK,@function
44
50
#endif
45
51
46
- #if defined(__linux__)
52
+ #if defined(__linux__) || defined(__APPLE__)
47
53
MORESTACK:
48
54
49
55
pushl %ebp
50
56
movl %esp , %ebp
51
57
52
58
// FIXME (1226): main is compiled with the split-stack prologue,
53
59
// causing it to call __morestack, so we have to jump back out
54
- subl $24 ,%esp
60
+ subl $20 ,%esp
55
61
calll RUST_GET_TASK
56
62
testl %eax ,%eax
57
63
jz .L$bail
58
64
59
65
// The arguments to rust_new_stack2
60
- movl 36 (%esp ),%eax // Size of stack arguments
66
+ movl 32 (%esp ),%eax // Size of stack arguments
61
67
movl %eax ,16 (%esp )
62
- leal 44 +ALIGNMENT(%esp ),%eax // Address of stack arguments
68
+ leal 40 +ALIGNMENT(%esp ),%eax // Address of stack arguments
63
69
movl %eax ,12 (%esp )
64
- movl 32 (%esp ),%eax // The amount of stack needed
70
+ movl 28 (%esp ),%eax // The amount of stack needed
65
71
movl %eax ,8 (%esp )
66
72
73
+ #ifdef __APPLE__
74
+ call 1f
75
+ 1: popl %ebx
76
+ movl L_upcall_new_stack$non_lazy_ptr-1b(%ebx ),%ecx
77
+ movl %ecx , 4 (%esp )
78
+ #else
67
79
movl $UPCALL_NEW_STACK,4 (%esp )
80
+ #endif
81
+
68
82
leal 8 (%esp ), %eax
69
83
movl %eax ,(%esp )
70
84
call UPCALL_CALL_C
71
85
72
- movl 28 (%esp ),%edx // Grab the return pointer.
86
+ movl 24 (%esp ),%edx // Grab the return pointer.
73
87
addl $RETURN_OFFSET,%edx // Skip past the `add esp,4` and the `ret`.
74
88
75
89
movl %eax ,%esp // Switch stacks.
@@ -81,7 +95,15 @@ MORESTACK:
81
95
// Switch back to the rust stack
82
96
movl %ebp , %esp
83
97
98
+ #ifdef __APPLE__
99
+ call 1f
100
+ 1: popl %ebx
101
+ movl L_upcall_del_stack$non_lazy_ptr-1b(%ebx ),%ecx
102
+ pushl %ecx
103
+ #else
84
104
pushl $UPCALL_DEL_STACK
105
+ #endif
106
+
85
107
pushl $0
86
108
call UPCALL_CALL_C
87
109
@@ -90,10 +112,10 @@ MORESTACK:
90
112
retl $8
91
113
92
114
.L$bail:
93
- movl 28 (%esp ),%edx
115
+ movl 24 (%esp ),%edx
94
116
addl $RETURN_OFFSET,%edx
95
117
96
- addl $24 , %esp
118
+ addl $20 , %esp
97
119
popl %ebp
98
120
addl $4 +8 +ALIGNMENT,%esp
99
121
@@ -107,13 +129,25 @@ MORESTACK:
107
129
108
130
#ifdef __APPLE__
109
131
110
- .section __IMPORT,__pointers,non_lazy_symbol_pointers
111
- rust_new_stack_sym:
112
- .indirect_symbol RUST_NEW_STACK
113
- .long 0
114
- rust_del_stack_sym:
115
- .indirect_symbol RUST_DEL_STACK
116
- .long 0
132
+ .section __IMPORT,__pointers,non_lazy_symbol_pointers
133
+ L_upcall_new_stack$non_lazy_ptr:
134
+ .indirect_symbol _upcall_new_stack
135
+ .long 0
136
+ L_upcall_del_stack$non_lazy_ptr:
137
+ .indirect_symbol _upcall_del_stack
138
+ .long 0
139
+
140
+ .section __IMPORT,__jump_table,symbol_stubs,pure_instructions+self_modifying_code,5
141
+
142
+ // Linker will replace the hlts (the ascii) with jmp
143
+ L_rust_get_task$stub:
144
+ .indirect_symbol _rust_get_task
145
+ .ascii "\364\364\364\364\364"
146
+
147
+ L_upcall_call_shim_on_c_stack$stub:
148
+ .indirect_symbol _upcall_call_shim_on_c_stack
149
+ .ascii "\364\364\364\364\364"
117
150
151
+ .subsections_via_symbols
118
152
#endif
119
153
0 commit comments