diff options
| author | Michael Woerister <michaelwoerister@posteo.net> | 2017-01-06 10:51:37 -0500 |
|---|---|---|
| committer | Michael Woerister <michaelwoerister@posteo.net> | 2017-01-09 10:06:58 -0500 |
| commit | 4dca459e86b85a87e1c5d19c97b8936c842bab05 (patch) | |
| tree | 461a58e8af80c3d4ccebccb242642b7638d814be | |
| parent | 7ef1a69d2e05d86e0893763d2c86677e9c5f3d99 (diff) | |
| download | rust-4dca459e86b85a87e1c5d19c97b8936c842bab05.tar.gz rust-4dca459e86b85a87e1c5d19c97b8936c842bab05.zip | |
trans: Disambiguate generic instance symbol names by instantiating crate.
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.
| -rw-r--r-- | src/librustc_trans/back/symbol_names.rs | 9 |
1 files changed, 9 insertions, 0 deletions
diff --git a/src/librustc_trans/back/symbol_names.rs b/src/librustc_trans/back/symbol_names.rs index 938848054fe..8f8c48a06b2 100644 --- a/src/librustc_trans/back/symbol_names.rs +++ b/src/librustc_trans/back/symbol_names.rs @@ -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()); + } } }); |
