Skip to content

Commit 1a7aa75

Browse files
author
Jonathan Turner
authored
Rollup merge of rust-lang#36960 - michaelwoerister:linker-regression, r=eddyb
Linker regression This should fix the symbol conflicts reported in rust-lang#36852. The PR also makes some debug output a bit more informative. r? @eddyb
2 parents 9f1089b + 2d34ad0 commit 1a7aa75

File tree

2 files changed

+23
-6
lines changed

2 files changed

+23
-6
lines changed

src/librustc_trans/closure.rs

+7-1
Original file line numberDiff line numberDiff line change
@@ -217,6 +217,10 @@ fn trans_fn_once_adapter_shim<'a, 'tcx>(
217217
llreffn: ValueRef)
218218
-> ValueRef
219219
{
220+
if let Some(&llfn) = ccx.instances().borrow().get(&method_instance) {
221+
return llfn;
222+
}
223+
220224
debug!("trans_fn_once_adapter_shim(closure_def_id={:?}, substs={:?}, llreffn={:?})",
221225
closure_def_id, substs, Value(llreffn));
222226

@@ -257,7 +261,7 @@ fn trans_fn_once_adapter_shim<'a, 'tcx>(
257261

258262
// Create the by-value helper.
259263
let function_name = method_instance.symbol_name(ccx.shared());
260-
let lloncefn = declare::declare_fn(ccx, &function_name, llonce_fn_ty);
264+
let lloncefn = declare::define_internal_fn(ccx, &function_name, llonce_fn_ty);
261265
attributes::set_frame_pointer_elimination(ccx, lloncefn);
262266

263267
let (block_arena, fcx): (TypedArena<_>, FunctionContext);
@@ -312,5 +316,7 @@ fn trans_fn_once_adapter_shim<'a, 'tcx>(
312316

313317
fcx.finish(bcx, DebugLoc::None);
314318

319+
ccx.instances().borrow_mut().insert(method_instance, lloncefn);
320+
315321
lloncefn
316322
}

src/librustc_trans/partitioning.rs

+16-5
Original file line numberDiff line numberDiff line change
@@ -267,14 +267,14 @@ pub fn partition<'a, 'tcx, I>(scx: &SharedCrateContext<'a, 'tcx>,
267267
let mut initial_partitioning = place_root_translation_items(scx,
268268
trans_items);
269269

270-
debug_dump(tcx, "INITIAL PARTITONING:", initial_partitioning.codegen_units.iter());
270+
debug_dump(scx, "INITIAL PARTITONING:", initial_partitioning.codegen_units.iter());
271271

272272
// If the partitioning should produce a fixed count of codegen units, merge
273273
// until that count is reached.
274274
if let PartitioningStrategy::FixedUnitCount(count) = strategy {
275275
merge_codegen_units(&mut initial_partitioning, count, &tcx.crate_name[..]);
276276

277-
debug_dump(tcx, "POST MERGING:", initial_partitioning.codegen_units.iter());
277+
debug_dump(scx, "POST MERGING:", initial_partitioning.codegen_units.iter());
278278
}
279279

280280
// In the next step, we use the inlining map to determine which addtional
@@ -284,7 +284,7 @@ pub fn partition<'a, 'tcx, I>(scx: &SharedCrateContext<'a, 'tcx>,
284284
let post_inlining = place_inlined_translation_items(initial_partitioning,
285285
inlining_map);
286286

287-
debug_dump(tcx, "POST INLINING:", post_inlining.0.iter());
287+
debug_dump(scx, "POST INLINING:", post_inlining.0.iter());
288288

289289
// Finally, sort by codegen unit name, so that we get deterministic results
290290
let mut result = post_inlining.0;
@@ -552,7 +552,7 @@ fn numbered_codegen_unit_name(crate_name: &str, index: usize) -> InternedString
552552
index)[..])
553553
}
554554

555-
fn debug_dump<'a, 'b, 'tcx, I>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
555+
fn debug_dump<'a, 'b, 'tcx, I>(scx: &SharedCrateContext<'a, 'tcx>,
556556
label: &str,
557557
cgus: I)
558558
where I: Iterator<Item=&'b CodegenUnit<'tcx>>,
@@ -561,10 +561,21 @@ fn debug_dump<'a, 'b, 'tcx, I>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
561561
if cfg!(debug_assertions) {
562562
debug!("{}", label);
563563
for cgu in cgus {
564+
let symbol_map = SymbolMap::build(scx, cgu.items
565+
.iter()
566+
.map(|(&trans_item, _)| trans_item));
564567
debug!("CodegenUnit {}:", cgu.name);
565568

566569
for (trans_item, linkage) in &cgu.items {
567-
debug!(" - {} [{:?}]", trans_item.to_string(tcx), linkage);
570+
let symbol_name = symbol_map.get_or_compute(scx, *trans_item);
571+
let symbol_hash_start = symbol_name.rfind('h');
572+
let symbol_hash = symbol_hash_start.map(|i| &symbol_name[i ..])
573+
.unwrap_or("<no hash>");
574+
575+
debug!(" - {} [{:?}] [{}]",
576+
trans_item.to_string(scx.tcx()),
577+
linkage,
578+
symbol_hash);
568579
}
569580

570581
debug!("");

0 commit comments

Comments
 (0)