2021-04-03 06:05:11 -05:00
|
|
|
//
|
rustc: Fix mixing crates with different `share_generics`
This commit addresses #64319 by removing the `dylib` crate type from the
list of crate type that exports generic symbols. The bug in #64319
arises because a `dylib` crate type was trying to export a symbol in an
uptream crate but it miscalculated the symbol name of the uptream
symbol. This isn't really necessary, though, since `dylib` crates aren't
that heavily used, so we can just conservatively say that the `dylib`
crate type never exports generic symbols, forcibly removing them from
the exported symbol lists if were to otherwise find them.
The fix here happens in two places:
* First is in the `local_crate_exports_generics` method, indicating that
it's now `false` for the `Dylib` crate type. Only rlibs actually
export generics at this point.
* Next is when we load exported symbols from upstream crate. If, for our
compilation session, the crate may be included from a dynamic library,
then its generic symbols are removed. When the crate was linked into a
dynamic library its symbols weren't exported, so we can't consider
them a candidate to link against.
Overally this should avoid situations where we incorrectly calculate the
upstream symbol names in the face of differnet `share_generics` options,
ultimately...
Closes #64319
2019-09-11 10:08:04 -05:00
|
|
|
// no-prefer-dynamic
|
2020-01-20 09:38:42 -06:00
|
|
|
// NOTE: We always compile this test with -Copt-level=0 because higher opt-levels
|
|
|
|
// prevent drop-glue from participating in share-generics.
|
2021-09-19 11:57:19 -05:00
|
|
|
// incremental
|
|
|
|
// compile-flags:-Zprint-mono-items=eager -Zshare-generics=yes -Copt-level=0
|
2018-03-13 08:26:49 -05:00
|
|
|
|
|
|
|
#![crate_type="rlib"]
|
|
|
|
|
|
|
|
// aux-build:shared_generics_aux.rs
|
|
|
|
extern crate shared_generics_aux;
|
|
|
|
|
2020-08-28 08:31:03 -05:00
|
|
|
//~ MONO_ITEM fn foo
|
2018-03-13 08:26:49 -05:00
|
|
|
pub fn foo() {
|
|
|
|
|
2020-08-28 08:31:03 -05:00
|
|
|
//~ MONO_ITEM fn shared_generics_aux::generic_fn::<u16> @@ shared_generics_aux-in-shared_generics.volatile[External]
|
2018-03-13 08:26:49 -05:00
|
|
|
let _ = shared_generics_aux::generic_fn(0u16, 1u16);
|
|
|
|
|
|
|
|
// This should not generate a monomorphization because it's already
|
|
|
|
// available in `shared_generics_aux`.
|
|
|
|
let _ = shared_generics_aux::generic_fn(0.0f32, 3.0f32);
|
|
|
|
|
2020-01-20 09:38:42 -06:00
|
|
|
// The following line will drop an instance of `Foo`, generating a call to
|
|
|
|
// Foo's drop-glue function. However, share-generics should take care of
|
|
|
|
// reusing the drop-glue from the upstream crate, so we do not expect a
|
|
|
|
// mono item for the drop-glue
|
|
|
|
let _ = shared_generics_aux::Foo(1);
|
|
|
|
}
|