@@ -47,6 +47,73 @@ extern "C" {
4747 pub fn __rust_probestack ( ) ;
4848}
4949
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( target_vendor = "apple" )
58+ ) ) ]
59+ macro_rules! define_rust_probestack {
60+ ( $body: expr) => {
61+ concat!(
62+ "
63+ // We are about to define a 'function within a function.' Because the
64+ // compiler will have emitted a .cfi_startproc at the beginning of
65+ // __rust_probestack_wrapper, we need .cfi_endproc before we can define
66+ // the contents of __rust_probestack.
67+ .cfi_endproc
68+
69+ .pushsection .text.__rust_probestack
70+ .globl __rust_probestack
71+ .type __rust_probestack, @function
72+ __rust_probestack:
73+ .cfi_startproc
74+
75+ " ,
76+ $body,
77+ "
78+
79+ .cfi_endproc
80+
81+ .size __rust_probestack, . - __rust_probestack
82+ .popsection
83+
84+ // Similar to above, we add .cfi_startproc here to match the
85+ // .cfi_endproc emitted at the end of __rust_probestack_wrapper.
86+ .cfi_startproc
87+ "
88+ )
89+ } ;
90+ }
91+
92+ // Same as above, but for Mach-O.
93+ #[ cfg( all(
94+ any( target_arch = "x86_64" , target_arch = "x86" ) ,
95+ target_vendor = "apple"
96+ ) ) ]
97+ macro_rules! define_rust_probestack {
98+ ( $body: expr) => {
99+ concat!(
100+ "
101+ .cfi_endproc
102+ .globl __rust_probestack
103+ __rust_probestack:
104+ .cfi_startproc
105+
106+ " ,
107+ $body,
108+ "
109+
110+ .cfi_endproc
111+ .cfi_startproc
112+ "
113+ )
114+ } ;
115+ }
116+
50117#[ naked]
51118#[ no_mangle]
52119#[ cfg( all( target_arch = "x86_64" , not( feature = "mangled-names" ) ) ) ]
@@ -56,18 +123,7 @@ pub unsafe extern "C" fn __rust_probestack_wrapper() {
56123 //
57124 // The ABI here is that the stack frame size is located in `%rax`. Upon
58125 // 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
126+ asm ! ( define_rust_probestack!( "
71127 pushq %rbp
72128 .cfi_adjust_cfa_offset 8
73129 .cfi_offset %rbp, -16
@@ -114,15 +170,7 @@ pub unsafe extern "C" fn __rust_probestack_wrapper() {
114170 .cfi_def_cfa_register %rsp
115171 .cfi_adjust_cfa_offset -8
116172 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" ) ;
173+ " ) :: : "memory" : "volatile" ) ;
126174 :: core:: intrinsics:: unreachable ( ) ;
127175}
128176
@@ -135,14 +183,7 @@ pub unsafe extern "C" fn __rust_probestack_wrapper() {
135183 // function basically can't tamper with anything.
136184 //
137185 // 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
186+ asm ! ( define_rust_probestack!( "
146187 push %ebp
147188 .cfi_adjust_cfa_offset 4
148189 .cfi_offset %ebp, -8
@@ -170,12 +211,6 @@ pub unsafe extern "C" fn __rust_probestack_wrapper() {
170211 .cfi_def_cfa_register %esp
171212 .cfi_adjust_cfa_offset -4
172213 ret
173- .cfi_endproc
174-
175- .size __rust_probestack, . - __rust_probestack
176- .popsection
177-
178- .cfi_startproc
179- " :: : "memory" : "volatile" ) ;
214+ " ) :: : "memory" : "volatile" ) ;
180215 :: core:: intrinsics:: unreachable ( ) ;
181216}
0 commit comments