Use cgu name instead of function name as base for inline asm wrapper name
This fixes using #[inline] functions containing inline assembly from multiple cgus
This commit is contained in:
parent
dfbc7eb6c7
commit
1222192374
@ -71,8 +71,6 @@ pub(crate) fn codegen_fn<'tcx>(
|
||||
clif_comments,
|
||||
source_info_set: indexmap::IndexSet::new(),
|
||||
next_ssa_var: 0,
|
||||
|
||||
inline_asm_index: 0,
|
||||
};
|
||||
|
||||
let arg_uninhabited = fx
|
||||
|
@ -255,8 +255,6 @@ pub(crate) struct FunctionCx<'m, 'clif, 'tcx: 'm> {
|
||||
|
||||
/// This should only be accessed by `CPlace::new_var`.
|
||||
pub(crate) next_ssa_var: u32,
|
||||
|
||||
pub(crate) inline_asm_index: u32,
|
||||
}
|
||||
|
||||
impl<'tcx> LayoutOfHelpers<'tcx> for FunctionCx<'_, '_, 'tcx> {
|
||||
|
@ -123,6 +123,7 @@ fn module_codegen(
|
||||
backend_config.clone(),
|
||||
module.isa(),
|
||||
tcx.sess.opts.debuginfo != DebugInfo::None,
|
||||
cgu_name,
|
||||
);
|
||||
super::predefine_mono_items(tcx, &mut module, &mono_items);
|
||||
for (mono_item, _) in mono_items {
|
||||
|
@ -11,6 +11,7 @@ use cranelift_codegen::binemit::{NullStackMapSink, NullTrapSink};
|
||||
use rustc_codegen_ssa::CrateInfo;
|
||||
use rustc_middle::mir::mono::MonoItem;
|
||||
use rustc_session::Session;
|
||||
use rustc_span::Symbol;
|
||||
|
||||
use cranelift_jit::{JITBuilder, JITModule};
|
||||
|
||||
@ -75,7 +76,13 @@ fn create_jit_module<'tcx>(
|
||||
jit_builder.symbols(imported_symbols);
|
||||
let mut jit_module = JITModule::new(jit_builder);
|
||||
|
||||
let mut cx = crate::CodegenCx::new(tcx, backend_config.clone(), jit_module.isa(), false);
|
||||
let mut cx = crate::CodegenCx::new(
|
||||
tcx,
|
||||
backend_config.clone(),
|
||||
jit_module.isa(),
|
||||
false,
|
||||
Symbol::intern("dummy_cgu_name"),
|
||||
);
|
||||
|
||||
crate::allocator::codegen(tcx, &mut jit_module, &mut cx.unwind_context);
|
||||
crate::main_shim::maybe_create_entry_wrapper(
|
||||
@ -245,7 +252,13 @@ fn jit_fn(instance_ptr: *const Instance<'static>, trampoline_ptr: *const u8) ->
|
||||
|
||||
jit_module.prepare_for_function_redefine(func_id).unwrap();
|
||||
|
||||
let mut cx = crate::CodegenCx::new(tcx, backend_config, jit_module.isa(), false);
|
||||
let mut cx = crate::CodegenCx::new(
|
||||
tcx,
|
||||
backend_config,
|
||||
jit_module.isa(),
|
||||
false,
|
||||
Symbol::intern("dummy_cgu_name"),
|
||||
);
|
||||
tcx.sess.time("codegen fn", || crate::base::codegen_fn(&mut cx, jit_module, instance));
|
||||
|
||||
assert!(cx.global_asm.is_empty());
|
||||
|
@ -121,9 +121,10 @@ pub(crate) fn codegen_inline_asm<'tcx>(
|
||||
asm_gen.allocate_registers();
|
||||
asm_gen.allocate_stack_slots();
|
||||
|
||||
let inline_asm_index = fx.inline_asm_index;
|
||||
fx.inline_asm_index += 1;
|
||||
let asm_name = format!("{}__inline_asm_{}", fx.symbol_name, inline_asm_index);
|
||||
let inline_asm_index = fx.cx.inline_asm_index.get();
|
||||
fx.cx.inline_asm_index.set(inline_asm_index + 1);
|
||||
let asm_name =
|
||||
format!("{}__inline_asm_{}", fx.cx.cgu_name.as_str().replace('.', "__").replace('-', "_"), inline_asm_index);
|
||||
|
||||
let generated_asm = asm_gen.generate_asm_wrapper(&asm_name);
|
||||
fx.cx.global_asm.push_str(&generated_asm);
|
||||
|
@ -26,6 +26,7 @@ extern crate rustc_target;
|
||||
extern crate rustc_driver;
|
||||
|
||||
use std::any::Any;
|
||||
use std::cell::Cell;
|
||||
|
||||
use rustc_codegen_ssa::traits::CodegenBackend;
|
||||
use rustc_codegen_ssa::CodegenResults;
|
||||
@ -34,6 +35,7 @@ use rustc_metadata::EncodedMetadata;
|
||||
use rustc_middle::dep_graph::{WorkProduct, WorkProductId};
|
||||
use rustc_session::config::OutputFilenames;
|
||||
use rustc_session::Session;
|
||||
use rustc_span::Symbol;
|
||||
|
||||
use cranelift_codegen::isa::TargetIsa;
|
||||
use cranelift_codegen::settings::{self, Configurable};
|
||||
@ -123,9 +125,11 @@ impl<F: Fn() -> String> Drop for PrintOnPanic<F> {
|
||||
struct CodegenCx<'tcx> {
|
||||
tcx: TyCtxt<'tcx>,
|
||||
global_asm: String,
|
||||
inline_asm_index: Cell<usize>,
|
||||
cached_context: Context,
|
||||
debug_context: Option<DebugContext<'tcx>>,
|
||||
unwind_context: UnwindContext,
|
||||
cgu_name: Symbol,
|
||||
}
|
||||
|
||||
impl<'tcx> CodegenCx<'tcx> {
|
||||
@ -134,6 +138,7 @@ impl<'tcx> CodegenCx<'tcx> {
|
||||
backend_config: BackendConfig,
|
||||
isa: &dyn TargetIsa,
|
||||
debug_info: bool,
|
||||
cgu_name: Symbol,
|
||||
) -> Self {
|
||||
assert_eq!(pointer_ty(tcx), isa.pointer_type());
|
||||
|
||||
@ -143,9 +148,11 @@ impl<'tcx> CodegenCx<'tcx> {
|
||||
CodegenCx {
|
||||
tcx,
|
||||
global_asm: String::new(),
|
||||
inline_asm_index: Cell::new(0),
|
||||
cached_context: Context::new(),
|
||||
debug_context,
|
||||
unwind_context,
|
||||
cgu_name,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user