about summary refs log tree commit diff
path: root/src/librustc_codegen_utils
diff options
context:
space:
mode:
Diffstat (limited to 'src/librustc_codegen_utils')
-rw-r--r--src/librustc_codegen_utils/symbol_names.rs13
1 files changed, 12 insertions, 1 deletions
diff --git a/src/librustc_codegen_utils/symbol_names.rs b/src/librustc_codegen_utils/symbol_names.rs
index c1e80234a77..0d95b0c7bbc 100644
--- a/src/librustc_codegen_utils/symbol_names.rs
+++ b/src/librustc_codegen_utils/symbol_names.rs
@@ -114,6 +114,7 @@ use rustc_mir::monomorphize::Instance;
 use syntax_pos::symbol::Symbol;
 
 use std::fmt::Write;
+use std::mem::discriminant;
 
 pub fn provide(providers: &mut Providers) {
     *providers = Providers {
@@ -219,6 +220,10 @@ fn get_symbol_hash<'a, 'tcx>(
                 .hash_stable(&mut hcx, &mut hasher);
             (&tcx.crate_disambiguator(instantiating_crate)).hash_stable(&mut hcx, &mut hasher);
         }
+
+        // We want to avoid accidental collision between different types of instances.
+        // Especially, VtableShim may overlap with its original instance without this.
+        discriminant(&instance.def).hash_stable(&mut hcx, &mut hasher);
     });
 
     // 64 bits should be enough to avoid collisions.
@@ -322,7 +327,13 @@ fn compute_symbol_name<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, instance: Instance
 
     let hash = get_symbol_hash(tcx, def_id, instance, instance_ty, substs);
 
-    SymbolPathBuffer::from_interned(tcx.def_symbol_name(def_id)).finish(hash)
+    let mut buf = SymbolPathBuffer::from_interned(tcx.def_symbol_name(def_id));
+
+    if instance.is_vtable_shim() {
+        buf.push("{{vtable-shim}}");
+    }
+
+    buf.finish(hash)
 }
 
 // Follow C++ namespace-mangling style, see