-
Notifications
You must be signed in to change notification settings - Fork 13.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
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
- Loading branch information
1 parent
5d531ae
commit 50c57d8
Showing
15 changed files
with
93 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -368,4 +368,3 @@ fn verify_ok(tcx: TyCtxt<'_>, list: &[Linkage]) { | |
} | ||
} | ||
} | ||
|
1 change: 1 addition & 0 deletions
1
src/test/codegen-units/partitioning/auxiliary/shared_generics_aux.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
// compile-flags:-Zshare-generics=yes | ||
// no-prefer-dynamic | ||
|
||
#![crate_type="rlib"] | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
-include ../tools.mk | ||
|
||
# Different optimization levels imply different values for `-Zshare-generics`, | ||
# so try out a whole bunch of combinations to make sure everything is compatible | ||
all: | ||
# First up, try some defaults | ||
$(RUSTC) --crate-type rlib foo.rs | ||
$(RUSTC) --crate-type dylib bar.rs -C opt-level=3 | ||
|
||
# Next try mixing up some things explicitly | ||
$(RUSTC) --crate-type rlib foo.rs -Z share-generics=no | ||
$(RUSTC) --crate-type dylib bar.rs -Z share-generics=no | ||
$(RUSTC) --crate-type rlib foo.rs -Z share-generics=no | ||
$(RUSTC) --crate-type dylib bar.rs -Z share-generics=yes | ||
$(RUSTC) --crate-type rlib foo.rs -Z share-generics=yes | ||
$(RUSTC) --crate-type dylib bar.rs -Z share-generics=no | ||
$(RUSTC) --crate-type rlib foo.rs -Z share-generics=yes | ||
$(RUSTC) --crate-type dylib bar.rs -Z share-generics=yes | ||
|
||
# Now combine a whole bunch of options together | ||
$(RUSTC) --crate-type rlib foo.rs | ||
$(RUSTC) --crate-type dylib bar.rs | ||
$(RUSTC) --crate-type dylib bar.rs -Z share-generics=no | ||
$(RUSTC) --crate-type dylib bar.rs -Z share-generics=yes | ||
$(RUSTC) --crate-type dylib bar.rs -C opt-level=1 | ||
$(RUSTC) --crate-type dylib bar.rs -C opt-level=1 -Z share-generics=no | ||
$(RUSTC) --crate-type dylib bar.rs -C opt-level=1 -Z share-generics=yes | ||
$(RUSTC) --crate-type dylib bar.rs -C opt-level=2 | ||
$(RUSTC) --crate-type dylib bar.rs -C opt-level=2 -Z share-generics=no | ||
$(RUSTC) --crate-type dylib bar.rs -C opt-level=2 -Z share-generics=yes | ||
$(RUSTC) --crate-type dylib bar.rs -C opt-level=3 | ||
$(RUSTC) --crate-type dylib bar.rs -C opt-level=3 -Z share-generics=no | ||
$(RUSTC) --crate-type dylib bar.rs -C opt-level=3 -Z share-generics=yes | ||
$(RUSTC) --crate-type dylib bar.rs -C opt-level=s | ||
$(RUSTC) --crate-type dylib bar.rs -C opt-level=s -Z share-generics=no | ||
$(RUSTC) --crate-type dylib bar.rs -C opt-level=s -Z share-generics=yes | ||
$(RUSTC) --crate-type dylib bar.rs -C opt-level=z | ||
$(RUSTC) --crate-type dylib bar.rs -C opt-level=z -Z share-generics=no | ||
$(RUSTC) --crate-type dylib bar.rs -C opt-level=z -Z share-generics=yes |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
extern crate foo; | ||
|
||
pub fn bar() { | ||
foo::foo(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
pub fn foo() { | ||
bar::<usize>(); | ||
} | ||
|
||
pub fn bar<T>() { | ||
baz(); | ||
} | ||
|
||
fn baz() {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters