|
3 | 3 | use std::fmt::Write; |
4 | 4 |
|
5 | 5 | use cranelift_codegen::isa::CallConv; |
| 6 | +use rustc_abi::CanonAbi; |
6 | 7 | use rustc_ast::ast::{InlineAsmOptions, InlineAsmTemplatePiece}; |
7 | 8 | use rustc_hir::LangItem; |
| 9 | +use rustc_middle::ty::layout::FnAbiOf; |
8 | 10 | use rustc_span::sym; |
9 | 11 | use rustc_target::asm::*; |
10 | 12 | use rustc_target::spec::Arch; |
@@ -120,21 +122,30 @@ pub(crate) fn codegen_inline_asm_terminator<'tcx>( |
120 | 122 | .unwrap(); |
121 | 123 | let symbol = fx.tcx.symbol_name(instance); |
122 | 124 |
|
123 | | - // Pass a wrapper rather than the function itself as the function itself may not |
124 | | - // be exported from the main codegen unit and may thus be unreachable from the |
125 | | - // object file created by an external assembler. |
126 | | - let wrapper_name = format!( |
127 | | - "{}__inline_asm_{}_wrapper_n{}", |
128 | | - fx.symbol_name, |
129 | | - fx.cgu_name.as_str().replace('.', "__").replace('-', "_"), |
130 | | - fx.inline_asm_index, |
131 | | - ); |
132 | | - fx.inline_asm_index += 1; |
133 | | - let sig = |
134 | | - get_function_sig(fx.tcx, fx.target_config.default_call_conv, instance); |
135 | | - create_wrapper_function(fx.module, sig, &wrapper_name, symbol.name); |
136 | | - |
137 | | - CInlineAsmOperand::Symbol { symbol: wrapper_name } |
| 125 | + if FullyMonomorphizedLayoutCx(fx.tcx) |
| 126 | + .fn_abi_of_instance(instance, ty::List::empty()) |
| 127 | + .conv |
| 128 | + == CanonAbi::Custom |
| 129 | + { |
| 130 | + // We can't create a wrapper for custom ABI functions. |
| 131 | + CInlineAsmOperand::Symbol { symbol: symbol.name.to_owned() } |
| 132 | + } else { |
| 133 | + // Pass a wrapper rather than the function itself as the function itself may not |
| 134 | + // be exported from the main codegen unit and may thus be unreachable from the |
| 135 | + // object file created by an external assembler. |
| 136 | + let wrapper_name = format!( |
| 137 | + "{}__inline_asm_{}_wrapper_n{}", |
| 138 | + fx.symbol_name, |
| 139 | + fx.cgu_name.as_str().replace('.', "__").replace('-', "_"), |
| 140 | + fx.inline_asm_index, |
| 141 | + ); |
| 142 | + fx.inline_asm_index += 1; |
| 143 | + let sig = |
| 144 | + get_function_sig(fx.tcx, fx.target_config.default_call_conv, instance); |
| 145 | + create_wrapper_function(fx.module, sig, &wrapper_name, symbol.name); |
| 146 | + |
| 147 | + CInlineAsmOperand::Symbol { symbol: wrapper_name } |
| 148 | + } |
138 | 149 | } else { |
139 | 150 | span_bug!(span, "invalid type for asm sym (fn)"); |
140 | 151 | } |
|
0 commit comments