-
Notifications
You must be signed in to change notification settings - Fork 13k
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 #65435 - michaelwoerister:fix-issue-64153, r=alexcrichton
Fix #64153 This PR changes how the compiler detects if an object file from an upstream crate is a Rust object file or not. Instead of checking if the name starts with the crate name and ends with `.o` (which is not always the case, as described in #64153), it now just checks if the filename ends with `.rcgu.o`. This fixes #64153. However, ideally we'd clean up the code around filename generation some more. Then this check could be made more robust. r? @alexcrichton
- Loading branch information
Showing
6 changed files
with
68 additions
and
21 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
-include ../tools.mk | ||
|
||
# `llvm-objdump`'s output looks different on windows than on other platforms. | ||
# It should be enough to check on Unix platforms, so: | ||
# ignore-windows | ||
|
||
# Staticlibs don't include Rust object files from upstream crates if the same | ||
# code was already pulled into the lib via LTO. However, the bug described in | ||
# https://github.com/rust-lang/rust/issues/64153 lead to this exclusion not | ||
# working properly if the upstream crate was compiled with an explicit filename | ||
# (via `-o`). | ||
# | ||
# This test makes sure that functions defined in the upstream crates do not | ||
# appear twice in the final staticlib when listing all the symbols from it. | ||
|
||
all: | ||
$(RUSTC) --crate-type rlib upstream.rs -o $(TMPDIR)/libupstream.rlib -Ccodegen-units=1 | ||
$(RUSTC) --crate-type staticlib downstream.rs -Clto -Ccodegen-units=1 -o $(TMPDIR)/libdownstream.a | ||
# Dump all the symbols from the staticlib into `syms` | ||
"$(LLVM_BIN_DIR)"/llvm-objdump -t $(TMPDIR)/libdownstream.a > $(TMPDIR)/syms | ||
# Count the global instances of `issue64153_test_function`. There'll be 2 | ||
# if the `upstream` object file got erronously included twice. | ||
# The line we are testing for with the regex looks something like: | ||
# 0000000000000000 g F .text.issue64153_test_function 00000023 issue64153_test_function | ||
grep -c -e "[[:space:]]g[[:space:]]*F[[:space:]].*issue64153_test_function" $(TMPDIR)/syms > $(TMPDIR)/count | ||
[ "$$(cat $(TMPDIR)/count)" -eq "1" ] |
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,6 @@ | ||
extern crate upstream; | ||
|
||
#[no_mangle] | ||
pub extern "C" fn foo() { | ||
print!("1 + 1 = {}", upstream::issue64153_test_function(1)); | ||
} |
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,6 @@ | ||
// Make this function extern "C", public, and no-mangle, so that it gets | ||
// exported from the downstream staticlib. | ||
#[no_mangle] | ||
pub extern "C" fn issue64153_test_function(x: u32) -> u32 { | ||
x + 1 | ||
} |
missing semicolon?