Skip to content

Commit ca092d0

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 4f2768a commit ca092d0

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
@@ -120,7 +120,7 @@ impl<'tcx> MonoItem<'tcx> {
120120
MonoItem::Fn(instance) => tcx.symbol_name(instance),
121121
MonoItem::Static(def_id) => tcx.symbol_name(Instance::mono(tcx, def_id)),
122122
MonoItem::GlobalAsm(item_id) => {
123-
SymbolName::new(tcx, &format!("global_asm_{:?}", item_id.owner_id))
123+
tcx.symbol_name(Instance::mono(tcx, item_id.owner_id.to_def_id()))
124124
}
125125
}
126126
}

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
@@ -873,6 +873,16 @@ impl<'tcx> Printer<'tcx> for SymbolMangler<'tcx> {
873873
// are effectively living in their parent modules.
874874
DefPathData::ForeignMod => return print_prefix(self),
875875

876+
// Global asm are handled similar to shims.
877+
DefPathData::GlobalAsm => {
878+
return self.path_append_ns(
879+
print_prefix,
880+
'S',
881+
disambiguated_data.disambiguator as u64,
882+
"global_asm",
883+
);
884+
}
885+
876886
// Uppercase categories are more stable than lowercase ones.
877887
DefPathData::TypeNs(_) => 't',
878888
DefPathData::ValueNs(_) => 'v',
@@ -886,7 +896,6 @@ impl<'tcx> Printer<'tcx> for SymbolMangler<'tcx> {
886896
// These should never show up as `path_append` arguments.
887897
DefPathData::CrateRoot
888898
| DefPathData::Use
889-
| DefPathData::GlobalAsm
890899
| DefPathData::Impl
891900
| DefPathData::MacroNs(_)
892901
| DefPathData::LifetimeNs(_)

0 commit comments

Comments
 (0)