Skip to content

Commit fe22941

Browse files
committed
Give global_asm mangled names
`global_asm!` themselves don't need symbol names; they currently only have a symbol name during mono collecion to identify them to partitioning algorithm. However it will have shims generated under it which will need unique symbol names. The name themselves ultimately doesn't matter, so they're generated like other shim instances.
1 parent f130244 commit fe22941

File tree

3 files changed

+16
-2
lines changed

3 files changed

+16
-2
lines changed

compiler/rustc_middle/src/mir/mono.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ impl<'tcx> MonoItem<'tcx> {
8787
MonoItem::Fn(instance) => tcx.symbol_name(instance),
8888
MonoItem::Static(def_id) => tcx.symbol_name(Instance::mono(tcx, def_id)),
8989
MonoItem::GlobalAsm(item_id) => {
90-
SymbolName::new(tcx, &format!("global_asm_{:?}", item_id.owner_id))
90+
tcx.symbol_name(Instance::mono(tcx, item_id.owner_id.to_def_id()))
9191
}
9292
}
9393
}

compiler/rustc_symbol_mangling/src/legacy.rs

+5
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,11 @@ pub(super) fn mangle<'tcx>(
3333
debug!(?instance_ty);
3434
break;
3535
}
36+
DefPathData::GlobalAsm => {
37+
// `global_asm!` doesn't have a type.
38+
instance_ty = tcx.types.unit;
39+
break;
40+
}
3641
_ => {
3742
// if we're making a symbol for something, there ought
3843
// to be a value or type-def or something in there

compiler/rustc_symbol_mangling/src/v0.rs

+10-1
Original file line numberDiff line numberDiff line change
@@ -792,6 +792,16 @@ impl<'tcx> Printer<'tcx> for SymbolMangler<'tcx> {
792792
// are effectively living in their parent modules.
793793
DefPathData::ForeignMod => return print_prefix(self),
794794

795+
// Global asm are handled similar to shims.
796+
DefPathData::GlobalAsm => {
797+
return self.path_append_ns(
798+
print_prefix,
799+
'S',
800+
disambiguated_data.disambiguator as u64,
801+
"global_asm",
802+
);
803+
}
804+
795805
// Uppercase categories are more stable than lowercase ones.
796806
DefPathData::TypeNs(_) => 't',
797807
DefPathData::ValueNs(_) => 'v',
@@ -803,7 +813,6 @@ impl<'tcx> Printer<'tcx> for SymbolMangler<'tcx> {
803813
// These should never show up as `path_append` arguments.
804814
DefPathData::CrateRoot
805815
| DefPathData::Use
806-
| DefPathData::GlobalAsm
807816
| DefPathData::Impl
808817
| DefPathData::MacroNs(_)
809818
| DefPathData::LifetimeNs(_) => {

0 commit comments

Comments
 (0)