]> git.lizzy.rs Git - rust.git/commitdiff
trans: Disambiguate generic instance symbol names by instantiating crate.
authorMichael Woerister <michaelwoerister@posteo.net>
Fri, 6 Jan 2017 15:51:37 +0000 (10:51 -0500)
committerMichael Woerister <michaelwoerister@posteo.net>
Mon, 9 Jan 2017 15:06:58 +0000 (10:06 -0500)
Two crates will often instantiate the same generic functions. Since
we don't make any attempt to re-use these instances cross-crate, we
would run into symbol conflicts for anything with external linkage.

In order to avoid this, this commit makes the compiler incorporate
the ID of the instantiating crate into the symbol hash. This way
equal generic instances will have different symbols names when
used in different crates.

src/librustc_trans/back/symbol_names.rs

index 938848054fee24266522d561ce951da69cef6d55..8f8c48a06b2c086bc749b72513442d3067b46ae4 100644 (file)
@@ -152,6 +152,15 @@ fn get_symbol_hash<'a, 'tcx>(scx: &SharedCrateContext<'a, 'tcx>,
             assert!(!substs.has_erasable_regions());
             assert!(!substs.needs_subst());
             substs.visit_with(&mut hasher);
+
+            // If this is an instance of a generic function, we also hash in
+            // the ID of the instantiating crate. This avoids symbol conflicts
+            // in case the same instances is emitted in two crates of the same
+            // project.
+            if substs.types().next().is_some() {
+                hasher.hash(scx.tcx().crate_name.as_str());
+                hasher.hash(scx.sess().local_crate_disambiguator().as_str());
+            }
         }
     });