Skip to content

Commit 1222192

Browse files
committed
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
1 parent dfbc7eb commit 1222192

File tree

6 files changed

+27
-9
lines changed

6 files changed

+27
-9
lines changed

src/base.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -71,8 +71,6 @@ pub(crate) fn codegen_fn<'tcx>(
7171
clif_comments,
7272
source_info_set: indexmap::IndexSet::new(),
7373
next_ssa_var: 0,
74-
75-
inline_asm_index: 0,
7674
};
7775

7876
let arg_uninhabited = fx

src/common.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -255,8 +255,6 @@ pub(crate) struct FunctionCx<'m, 'clif, 'tcx: 'm> {
255255

256256
/// This should only be accessed by `CPlace::new_var`.
257257
pub(crate) next_ssa_var: u32,
258-
259-
pub(crate) inline_asm_index: u32,
260258
}
261259

262260
impl<'tcx> LayoutOfHelpers<'tcx> for FunctionCx<'_, '_, 'tcx> {

src/driver/aot.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,7 @@ fn module_codegen(
123123
backend_config.clone(),
124124
module.isa(),
125125
tcx.sess.opts.debuginfo != DebugInfo::None,
126+
cgu_name,
126127
);
127128
super::predefine_mono_items(tcx, &mut module, &mono_items);
128129
for (mono_item, _) in mono_items {

src/driver/jit.rs

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ use cranelift_codegen::binemit::{NullStackMapSink, NullTrapSink};
1111
use rustc_codegen_ssa::CrateInfo;
1212
use rustc_middle::mir::mono::MonoItem;
1313
use rustc_session::Session;
14+
use rustc_span::Symbol;
1415

1516
use cranelift_jit::{JITBuilder, JITModule};
1617

@@ -75,7 +76,13 @@ fn create_jit_module<'tcx>(
7576
jit_builder.symbols(imported_symbols);
7677
let mut jit_module = JITModule::new(jit_builder);
7778

78-
let mut cx = crate::CodegenCx::new(tcx, backend_config.clone(), jit_module.isa(), false);
79+
let mut cx = crate::CodegenCx::new(
80+
tcx,
81+
backend_config.clone(),
82+
jit_module.isa(),
83+
false,
84+
Symbol::intern("dummy_cgu_name"),
85+
);
7986

8087
crate::allocator::codegen(tcx, &mut jit_module, &mut cx.unwind_context);
8188
crate::main_shim::maybe_create_entry_wrapper(
@@ -245,7 +252,13 @@ fn jit_fn(instance_ptr: *const Instance<'static>, trampoline_ptr: *const u8) ->
245252

246253
jit_module.prepare_for_function_redefine(func_id).unwrap();
247254

248-
let mut cx = crate::CodegenCx::new(tcx, backend_config, jit_module.isa(), false);
255+
let mut cx = crate::CodegenCx::new(
256+
tcx,
257+
backend_config,
258+
jit_module.isa(),
259+
false,
260+
Symbol::intern("dummy_cgu_name"),
261+
);
249262
tcx.sess.time("codegen fn", || crate::base::codegen_fn(&mut cx, jit_module, instance));
250263

251264
assert!(cx.global_asm.is_empty());

src/inline_asm.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -121,9 +121,10 @@ pub(crate) fn codegen_inline_asm<'tcx>(
121121
asm_gen.allocate_registers();
122122
asm_gen.allocate_stack_slots();
123123

124-
let inline_asm_index = fx.inline_asm_index;
125-
fx.inline_asm_index += 1;
126-
let asm_name = format!("{}__inline_asm_{}", fx.symbol_name, inline_asm_index);
124+
let inline_asm_index = fx.cx.inline_asm_index.get();
125+
fx.cx.inline_asm_index.set(inline_asm_index + 1);
126+
let asm_name =
127+
format!("{}__inline_asm_{}", fx.cx.cgu_name.as_str().replace('.', "__").replace('-', "_"), inline_asm_index);
127128

128129
let generated_asm = asm_gen.generate_asm_wrapper(&asm_name);
129130
fx.cx.global_asm.push_str(&generated_asm);

src/lib.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ extern crate rustc_target;
2626
extern crate rustc_driver;
2727

2828
use std::any::Any;
29+
use std::cell::Cell;
2930

3031
use rustc_codegen_ssa::traits::CodegenBackend;
3132
use rustc_codegen_ssa::CodegenResults;
@@ -34,6 +35,7 @@ use rustc_metadata::EncodedMetadata;
3435
use rustc_middle::dep_graph::{WorkProduct, WorkProductId};
3536
use rustc_session::config::OutputFilenames;
3637
use rustc_session::Session;
38+
use rustc_span::Symbol;
3739

3840
use cranelift_codegen::isa::TargetIsa;
3941
use cranelift_codegen::settings::{self, Configurable};
@@ -123,9 +125,11 @@ impl<F: Fn() -> String> Drop for PrintOnPanic<F> {
123125
struct CodegenCx<'tcx> {
124126
tcx: TyCtxt<'tcx>,
125127
global_asm: String,
128+
inline_asm_index: Cell<usize>,
126129
cached_context: Context,
127130
debug_context: Option<DebugContext<'tcx>>,
128131
unwind_context: UnwindContext,
132+
cgu_name: Symbol,
129133
}
130134

131135
impl<'tcx> CodegenCx<'tcx> {
@@ -134,6 +138,7 @@ impl<'tcx> CodegenCx<'tcx> {
134138
backend_config: BackendConfig,
135139
isa: &dyn TargetIsa,
136140
debug_info: bool,
141+
cgu_name: Symbol,
137142
) -> Self {
138143
assert_eq!(pointer_ty(tcx), isa.pointer_type());
139144

@@ -143,9 +148,11 @@ impl<'tcx> CodegenCx<'tcx> {
143148
CodegenCx {
144149
tcx,
145150
global_asm: String::new(),
151+
inline_asm_index: Cell::new(0),
146152
cached_context: Context::new(),
147153
debug_context,
148154
unwind_context,
155+
cgu_name,
149156
}
150157
}
151158
}

0 commit comments

Comments
 (0)