Skip to content

Commit

Permalink
trans: Disambiguate generic instance symbol names by instantiating cr…
Browse files Browse the repository at this point in the history
…ate.

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.
  • Loading branch information
michaelwoerister committed Jan 9, 2017
1 parent 7ef1a69 commit 4dca459
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions src/librustc_trans/back/symbol_names.rs
Expand Up @@ -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());
}
}
});

Expand Down

0 comments on commit 4dca459

Please sign in to comment.