@@ -47,6 +47,75 @@ extern "C" {
47
47
pub fn __rust_probestack ( ) ;
48
48
}
49
49
50
+ // A wrapper for our implementation of __rust_probestack, which allows us to
51
+ // keep the assembly inline while controlling all CFI directives in the assembly
52
+ // emitted for the function.
53
+ //
54
+ // This is the ELF version.
55
+ #[ cfg( all(
56
+ any( target_arch = "x86_64" , target_arch = "x86" ) ,
57
+ not( feature = "mangled-names" ) ,
58
+ not( target_vendor = "apple" )
59
+ ) ) ]
60
+ macro_rules! define_rust_probestack {
61
+ ( $body: expr) => {
62
+ concat!(
63
+ "
64
+ // We are about to define a 'function within a function.' Because the
65
+ // compiler will have emitted a .cfi_startproc at the beginning of
66
+ // __rust_probestack_wrapper, we need .cfi_endproc before we can define
67
+ // the contents of __rust_probestack.
68
+ .cfi_endproc
69
+
70
+ .pushsection .text.__rust_probestack
71
+ .globl __rust_probestack
72
+ .type __rust_probestack, @function
73
+ __rust_probestack:
74
+ .cfi_startproc
75
+
76
+ " ,
77
+ $body,
78
+ "
79
+
80
+ .cfi_endproc
81
+
82
+ .size __rust_probestack, . - __rust_probestack
83
+ .popsection
84
+
85
+ // Similar to above, we add .cfi_startproc here to match the
86
+ // .cfi_endproc emitted at the end of __rust_probestack_wrapper.
87
+ .cfi_startproc
88
+ "
89
+ )
90
+ } ;
91
+ }
92
+
93
+ // Same as above, but for Mach-O.
94
+ #[ cfg( all(
95
+ any( target_arch = "x86_64" , target_arch = "x86" ) ,
96
+ not( feature = "mangled-names" ) ,
97
+ target_vendor = "apple"
98
+ ) ) ]
99
+ macro_rules! define_rust_probestack {
100
+ ( $body: expr) => {
101
+ concat!(
102
+ "
103
+ .cfi_endproc
104
+ .globl __rust_probestack
105
+ __rust_probestack:
106
+ .cfi_startproc
107
+
108
+ " ,
109
+ $body,
110
+ "
111
+
112
+ .cfi_endproc
113
+ .cfi_startproc
114
+ "
115
+ )
116
+ } ;
117
+ }
118
+
50
119
#[ naked]
51
120
#[ no_mangle]
52
121
#[ cfg( all( target_arch = "x86_64" , not( feature = "mangled-names" ) ) ) ]
@@ -56,18 +125,7 @@ pub unsafe extern "C" fn __rust_probestack_wrapper() {
56
125
//
57
126
// The ABI here is that the stack frame size is located in `%rax`. Upon
58
127
// return we're not supposed to modify `%rsp` or `%rax`.
59
- asm ! ( "
60
- // We are about to define a 'function within a function.' Because the
61
- // compiler will have emitted a .cfi_startproc at the beginning of
62
- // __rust_probestack_wrapper, we need .cfi_endproc before we can define
63
- // the contents of __rust_probestack.
64
- .cfi_endproc
65
-
66
- .pushsection .text.__rust_probestack
67
- .globl __rust_probestack
68
- .type __rust_probestack, @function
69
- __rust_probestack:
70
- .cfi_startproc
128
+ asm ! ( define_rust_probestack!( "
71
129
pushq %rbp
72
130
.cfi_adjust_cfa_offset 8
73
131
.cfi_offset %rbp, -16
@@ -114,15 +172,7 @@ pub unsafe extern "C" fn __rust_probestack_wrapper() {
114
172
.cfi_def_cfa_register %rsp
115
173
.cfi_adjust_cfa_offset -8
116
174
ret
117
- .cfi_endproc
118
-
119
- .size __rust_probestack, . - __rust_probestack
120
- .popsection
121
-
122
- // Similar to above, we add .cfi_startproc here to match the
123
- // .cfi_endproc emitted at the end of __rust_probestack_wrapper.
124
- .cfi_startproc
125
- " :: : "memory" : "volatile" ) ;
175
+ " ) :: : "memory" : "volatile" ) ;
126
176
:: core:: intrinsics:: unreachable ( ) ;
127
177
}
128
178
@@ -135,14 +185,7 @@ pub unsafe extern "C" fn __rust_probestack_wrapper() {
135
185
// function basically can't tamper with anything.
136
186
//
137
187
// The ABI here is the same as x86_64, except everything is 32-bits large.
138
- asm ! ( "
139
- .cfi_endproc
140
-
141
- .pushsection .text.__rust_probestack
142
- .globl __rust_probestack
143
- .type __rust_probestack, @function
144
- __rust_probestack:
145
- .cfi_startproc
188
+ asm ! ( define_rust_probestack!( "
146
189
push %ebp
147
190
.cfi_adjust_cfa_offset 4
148
191
.cfi_offset %ebp, -8
@@ -170,12 +213,6 @@ pub unsafe extern "C" fn __rust_probestack_wrapper() {
170
213
.cfi_def_cfa_register %esp
171
214
.cfi_adjust_cfa_offset -4
172
215
ret
173
- .cfi_endproc
174
-
175
- .size __rust_probestack, . - __rust_probestack
176
- .popsection
177
-
178
- .cfi_startproc
179
- " :: : "memory" : "volatile" ) ;
216
+ " ) :: : "memory" : "volatile" ) ;
180
217
:: core:: intrinsics:: unreachable ( ) ;
181
218
}
0 commit comments