From 824315a7220895b0e21783726eb2b7856bc27406 Mon Sep 17 00:00:00 2001 From: Masaki Hara Date: Mon, 10 Sep 2018 23:01:46 +0900 Subject: Distinguish vtable shims in symbol paths. --- src/librustc_codegen_utils/symbol_names.rs | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) (limited to 'src/librustc_codegen_utils') diff --git a/src/librustc_codegen_utils/symbol_names.rs b/src/librustc_codegen_utils/symbol_names.rs index c1e80234a77..27700bab245 100644 --- a/src/librustc_codegen_utils/symbol_names.rs +++ b/src/librustc_codegen_utils/symbol_names.rs @@ -219,6 +219,9 @@ fn get_symbol_hash<'a, 'tcx>( .hash_stable(&mut hcx, &mut hasher); (&tcx.crate_disambiguator(instantiating_crate)).hash_stable(&mut hcx, &mut hasher); } + + let is_vtable_shim = instance.is_vtable_shim(); + is_vtable_shim.hash_stable(&mut hcx, &mut hasher); }); // 64 bits should be enough to avoid collisions. @@ -322,7 +325,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 -- cgit 1.4.1-3-g733a5 From 207531606476a1fa03de815c2a112f3909cda48a Mon Sep 17 00:00:00 2001 From: Masaki Hara Date: Thu, 27 Sep 2018 00:14:38 +0900 Subject: Include InstanceDef's discriminant in the symbol hash. --- src/librustc_codegen_utils/symbol_names.rs | 6 ++++-- src/test/ui/symbol-names/basic.stderr | 2 +- src/test/ui/symbol-names/impl1.stderr | 4 ++-- 3 files changed, 7 insertions(+), 5 deletions(-) (limited to 'src/librustc_codegen_utils') diff --git a/src/librustc_codegen_utils/symbol_names.rs b/src/librustc_codegen_utils/symbol_names.rs index 27700bab245..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 { @@ -220,8 +221,9 @@ fn get_symbol_hash<'a, 'tcx>( (&tcx.crate_disambiguator(instantiating_crate)).hash_stable(&mut hcx, &mut hasher); } - let is_vtable_shim = instance.is_vtable_shim(); - is_vtable_shim.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. diff --git a/src/test/ui/symbol-names/basic.stderr b/src/test/ui/symbol-names/basic.stderr index 5e910caf3c0..551c5bb4a75 100644 --- a/src/test/ui/symbol-names/basic.stderr +++ b/src/test/ui/symbol-names/basic.stderr @@ -1,4 +1,4 @@ -error: symbol-name(_ZN5basic4main17h6ab1850bb0b9f417E) +error: symbol-name(_ZN5basic4main17h08bcaf310214ed52E) --> $DIR/basic.rs:13:1 | LL | #[rustc_symbol_name] //~ ERROR _ZN5basic4main diff --git a/src/test/ui/symbol-names/impl1.stderr b/src/test/ui/symbol-names/impl1.stderr index 46e260bc28c..73c8d7b9721 100644 --- a/src/test/ui/symbol-names/impl1.stderr +++ b/src/test/ui/symbol-names/impl1.stderr @@ -1,4 +1,4 @@ -error: symbol-name(_ZN5impl13foo3Foo3bar17h99c48478d64a0eb0E) +error: symbol-name(_ZN5impl13foo3Foo3bar17hc487d6ec13fe9124E) --> $DIR/impl1.rs:18:9 | LL | #[rustc_symbol_name] //~ ERROR _ZN5impl13foo3Foo3bar @@ -10,7 +10,7 @@ error: item-path(foo::Foo::bar) LL | #[rustc_item_path] //~ ERROR item-path(foo::Foo::bar) | ^^^^^^^^^^^^^^^^^^ -error: symbol-name(_ZN5impl13bar33_$LT$impl$u20$impl1..foo..Foo$GT$3baz17hebf13830acf865d9E) +error: symbol-name(_ZN5impl13bar33_$LT$impl$u20$impl1..foo..Foo$GT$3baz17h38577281258e1527E) --> $DIR/impl1.rs:28:9 | LL | #[rustc_symbol_name] //~ ERROR _ZN5impl13bar33_$LT$impl$u20$impl1..foo..Foo$GT$3baz -- cgit 1.4.1-3-g733a5