forked from rust-lang/rust
-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Auto merge of rust-lang#113695 - bjorn3:fix_rlib_cdylib_metadata_hand…
…ling, r=pnkfelix,petrochenkov Verify that all crate sources are in sync This ensures that rustc will not attempt to link against a cdylib as if it is a rust dylib when an rlib for the same crate is available. Previously rustc didn't actually check if any further formats of a crate which has been loaded are of the same version and if they are actually valid. This caused a cdylib to be interpreted as rust dylib as soon as the corresponding rlib was loaded. As cdylibs don't export any rust symbols, linking would fail if rustc decides to link against the cdylib rather than the rlib. Two crates depended on the previous behavior by separately compiling a test crate as both rlib and dylib. These have been changed to capture their original spirit to the best of my ability while still working when rustc verifies that all crates are in sync. It is unlikely that build systems depend on the current behavior and in any case we are taking a lot of measures to ensure that any change to either the source or the compilation options (including crate type) results in rustc rejecting it as incompatible. We merely didn't do this check here for now obsolete perf reasons. Fixes rust-lang#10786 Fixes rust-lang#82151 Fixes rust-lang#82972 Closes bevy-cheatbook/bevy-cheatbook#114
- Loading branch information
Showing
17 changed files
with
100 additions
and
79 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
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
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 @@ | ||
pub fn f() {} |
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,16 @@ | ||
# ignore-cross-compile | ||
include ../tools.mk | ||
|
||
# Test that rustc will not attempt to link against a cdylib as if | ||
# it is a rust dylib when an rlib for the same crate is available. | ||
# Previously rustc didn't actually check if any further formats of | ||
# a crate which has been loaded are of the same version and if | ||
# they are actually valid. This caused a cdylib to be interpreted | ||
# as rust dylib as soon as the corresponding rlib was loaded. As | ||
# cdylibs don't export any rust symbols, linking would fail if | ||
# rustc decides to link against the cdylib rather than the rlib. | ||
|
||
all: | ||
$(RUSTC) bar.rs --crate-type=rlib --crate-type=cdylib | ||
$(RUSTC) foo.rs -C prefer-dynamic | ||
$(call RUN,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 @@ | ||
pub fn bar() {} |
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 bar; | ||
|
||
fn main() { | ||
bar::bar(); | ||
} |
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,16 @@ | ||
# ignore-cross-compile | ||
include ../tools.mk | ||
|
||
# Test that using rlibs and rmeta dep crates work together. Specifically, that | ||
# there can be both an rmeta and an rlib file and rustc will prefer the rmeta | ||
# file. | ||
# | ||
# This behavior is simply making sure this doesn't accidentally change; in this | ||
# case we want to make sure that the rlib isn't being used as that would cause | ||
# bugs in -Zbinary-dep-depinfo (see #68298). | ||
|
||
all: | ||
$(RUSTC) rmeta_aux.rs --crate-type=rlib --emit link,metadata | ||
$(RUSTC) lib.rs --crate-type=rlib --emit dep-info -Zbinary-dep-depinfo | ||
$(CGREP) "librmeta_aux.rmeta" < $(TMPDIR)/lib.d | ||
$(CGREP) -v "librmeta_aux.rlib" < $(TMPDIR)/lib.d |
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,3 @@ | ||
pub struct Foo { | ||
pub field: i32, | ||
} |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.