@@ -6,7 +6,6 @@ use std::fmt::Write;
6
6
7
7
use rustc_ast:: ast:: { InlineAsmOptions , InlineAsmTemplatePiece } ;
8
8
use rustc_middle:: mir:: InlineAsmOperand ;
9
- use rustc_middle:: ty:: SymbolName ;
10
9
use rustc_span:: sym;
11
10
use rustc_target:: asm:: * ;
12
11
@@ -30,7 +29,7 @@ enum CInlineAsmOperand<'tcx> {
30
29
value : String ,
31
30
} ,
32
31
Symbol {
33
- symbol : SymbolName < ' tcx > ,
32
+ symbol : String ,
34
33
} ,
35
34
}
36
35
@@ -263,15 +262,37 @@ pub(crate) fn codegen_inline_asm<'tcx>(
263
262
substs,
264
263
)
265
264
. unwrap ( ) ;
266
- CInlineAsmOperand :: Symbol { symbol : fx. tcx . symbol_name ( instance) }
265
+ let symbol = fx. tcx . symbol_name ( instance) ;
266
+
267
+ // Pass a wrapper rather than the function itself as the function itself may not
268
+ // be exported from the main codegen unit and may thus be unreachable from the
269
+ // object file created by an external assembler.
270
+ let inline_asm_index = fx. cx . inline_asm_index . get ( ) ;
271
+ fx. cx . inline_asm_index . set ( inline_asm_index + 1 ) ;
272
+ let wrapper_name = format ! (
273
+ "__inline_asm_{}_wrapper_n{}" ,
274
+ fx. cx. cgu_name. as_str( ) . replace( '.' , "__" ) . replace( '-' , "_" ) ,
275
+ inline_asm_index
276
+ ) ;
277
+ let sig =
278
+ get_function_sig ( fx. tcx , fx. target_config . default_call_conv , instance) ;
279
+ create_wrapper_function (
280
+ fx. module ,
281
+ & mut fx. cx . unwind_context ,
282
+ sig,
283
+ & wrapper_name,
284
+ symbol. name ,
285
+ ) ;
286
+
287
+ CInlineAsmOperand :: Symbol { symbol : wrapper_name }
267
288
} else {
268
289
span_bug ! ( span, "invalid type for asm sym (fn)" ) ;
269
290
}
270
291
}
271
292
InlineAsmOperand :: SymStatic { def_id } => {
272
293
assert ! ( fx. tcx. is_static( def_id) ) ;
273
294
let instance = Instance :: mono ( fx. tcx , def_id) . polymorphize ( fx. tcx ) ;
274
- CInlineAsmOperand :: Symbol { symbol : fx. tcx . symbol_name ( instance) }
295
+ CInlineAsmOperand :: Symbol { symbol : fx. tcx . symbol_name ( instance) . name . to_owned ( ) }
275
296
}
276
297
} )
277
298
. collect :: < Vec < _ > > ( ) ;
@@ -630,7 +651,7 @@ impl<'tcx> InlineAssemblyGenerator<'_, 'tcx> {
630
651
CInlineAsmOperand :: Const { ref value } => {
631
652
generated_asm. push_str ( value) ;
632
653
}
633
- CInlineAsmOperand :: Symbol { symbol } => generated_asm. push_str ( symbol. name ) ,
654
+ CInlineAsmOperand :: Symbol { ref symbol } => generated_asm. push_str ( symbol) ,
634
655
}
635
656
}
636
657
}
0 commit comments