Skip to content

Commit 7528234

Browse files
Add regression test for issue #64153.
1 parent e369d87 commit 7528234

File tree

3 files changed

+32
-0
lines changed

3 files changed

+32
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
-include ../tools.mk
2+
3+
# Staticlibs don't include Rust object files from upstream crates if the same
4+
# code was already pulled into the lib via LTO. However, the bug described in
5+
# https://github.com/rust-lang/rust/issues/64153 lead to this exclusion not
6+
# working properly if the upstream crate was compiled with an explicit filename
7+
# (via `-o`).
8+
#
9+
# This test makes sure that functions defined in the upstream crates do not
10+
# appear twice in the final staticlib when listing all the symbols from it.
11+
12+
all:
13+
$(RUSTC) --crate-type rlib upstream.rs -o $(TMPDIR)/libupstream.rlib -Ccodegen-units=1
14+
$(RUSTC) --crate-type staticlib downstream.rs -Clto -Ccodegen-units=1 -o $(TMPDIR)/libdownstream.a
15+
# Dump all the symbols from the staticlib into `syms`
16+
nm $(TMPDIR)/libdownstream.a > $(TMPDIR)/syms
17+
# Count the global instances of `issue64153_test_function`. There'll be 2
18+
# if the `upstream` object file got erronously included twice.
19+
grep -c -e "[[:space:]]T[[:space:]]issue64153_test_function" $(TMPDIR)/syms > $(TMPDIR)/count
20+
[ "$$(cat $(TMPDIR)/count)" -eq "1" ]
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
extern crate upstream;
2+
3+
#[no_mangle]
4+
pub extern "C" fn foo() {
5+
print!("1 + 1 = {}", upstream::issue64153_test_function(1));
6+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
// Make this function extern "C", public, and no-mangle, so that it gets
2+
// exported from the downstream staticlib.
3+
#[no_mangle]
4+
pub extern "C" fn issue64153_test_function(x: u32) -> u32 {
5+
x + 1
6+
}

0 commit comments

Comments
 (0)