Skip to content

Commit bd2250d

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 83e7f93 commit bd2250d

File tree

3 files changed

+16
-2
lines changed

3 files changed

+16
-2
lines changed

compiler/rustc_middle/src/mir/mono.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ impl<'tcx> MonoItem<'tcx> {
121121
MonoItem::Fn(instance) => tcx.symbol_name(instance),
122122
MonoItem::Static(def_id) => tcx.symbol_name(Instance::mono(tcx, def_id)),
123123
MonoItem::GlobalAsm(item_id) => {
124-
SymbolName::new(tcx, &format!("global_asm_{:?}", item_id.owner_id))
124+
tcx.symbol_name(Instance::mono(tcx, item_id.owner_id.to_def_id()))
125125
}
126126
}
127127
}

compiler/rustc_symbol_mangling/src/legacy.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,11 @@ pub(super) fn mangle<'tcx>(
3636
debug!(?instance_ty);
3737
break;
3838
}
39+
DefPathData::GlobalAsm => {
40+
// `global_asm!` doesn't have a type.
41+
instance_ty = tcx.types.unit;
42+
break;
43+
}
3944
_ => {
4045
// if we're making a symbol for something, there ought
4146
// to be a value or type-def or something in there

compiler/rustc_symbol_mangling/src/v0.rs

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -867,6 +867,16 @@ impl<'tcx> Printer<'tcx> for SymbolMangler<'tcx> {
867867
// are effectively living in their parent modules.
868868
DefPathData::ForeignMod => return print_prefix(self),
869869

870+
// Global asm are handled similar to shims.
871+
DefPathData::GlobalAsm => {
872+
return self.path_append_ns(
873+
print_prefix,
874+
'S',
875+
disambiguated_data.disambiguator as u64,
876+
"global_asm",
877+
);
878+
}
879+
870880
// Uppercase categories are more stable than lowercase ones.
871881
DefPathData::TypeNs(_) => 't',
872882
DefPathData::ValueNs(_) => 'v',
@@ -880,7 +890,6 @@ impl<'tcx> Printer<'tcx> for SymbolMangler<'tcx> {
880890
// These should never show up as `path_append` arguments.
881891
DefPathData::CrateRoot
882892
| DefPathData::Use
883-
| DefPathData::GlobalAsm
884893
| DefPathData::Impl
885894
| DefPathData::MacroNs(_)
886895
| DefPathData::LifetimeNs(_)

0 commit comments

Comments
 (0)