Skip to content

Commit 4dca459

Browse files
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.
1 parent 7ef1a69 commit 4dca459

File tree

1 file changed

+9
-0
lines changed

1 file changed

+9
-0
lines changed

src/librustc_trans/back/symbol_names.rs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,15 @@ fn get_symbol_hash<'a, 'tcx>(scx: &SharedCrateContext<'a, 'tcx>,
152152
assert!(!substs.has_erasable_regions());
153153
assert!(!substs.needs_subst());
154154
substs.visit_with(&mut hasher);
155+
156+
// If this is an instance of a generic function, we also hash in
157+
// the ID of the instantiating crate. This avoids symbol conflicts
158+
// in case the same instances is emitted in two crates of the same
159+
// project.
160+
if substs.types().next().is_some() {
161+
hasher.hash(scx.tcx().crate_name.as_str());
162+
hasher.hash(scx.sess().local_crate_disambiguator().as_str());
163+
}
155164
}
156165
});
157166

0 commit comments

Comments
 (0)