summaryrefslogtreecommitdiffstats
path: root/tests/run-make/crate-hash-rustc-version
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-17 12:20:29 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-17 12:20:29 +0000
commit631cd5845e8de329d0e227aaa707d7ea228b8f8f (patch)
treea1b87c8f8cad01cf18f7c5f57a08f102771ed303 /tests/run-make/crate-hash-rustc-version
parentAdding debian version 1.69.0+dfsg1-1. (diff)
downloadrustc-631cd5845e8de329d0e227aaa707d7ea228b8f8f.tar.xz
rustc-631cd5845e8de329d0e227aaa707d7ea228b8f8f.zip
Merging upstream version 1.70.0+dfsg1.
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'tests/run-make/crate-hash-rustc-version')
-rw-r--r--tests/run-make/crate-hash-rustc-version/Makefile38
-rw-r--r--tests/run-make/crate-hash-rustc-version/a.rs4
-rw-r--r--tests/run-make/crate-hash-rustc-version/b.rs8
3 files changed, 50 insertions, 0 deletions
diff --git a/tests/run-make/crate-hash-rustc-version/Makefile b/tests/run-make/crate-hash-rustc-version/Makefile
new file mode 100644
index 000000000..f1d2a3604
--- /dev/null
+++ b/tests/run-make/crate-hash-rustc-version/Makefile
@@ -0,0 +1,38 @@
+# ignore-cross-compile
+include ../tools.mk
+
+# Ensure that crates compiled with different rustc versions cannot
+# be dynamically linked.
+
+FLAGS := -Cprefer-dynamic -Zsymbol-mangling-version=v0
+UNAME := $(shell uname)
+ifeq ($(UNAME),Linux)
+ EXT=".so"
+ NM_CMD := nm -D
+endif
+ifeq ($(UNAME),Darwin)
+ EXT=".dylib"
+ NM_CMD := nm
+endif
+
+ifndef NM_CMD
+all:
+ exit 0
+else
+all:
+ # a.rs is a dylib
+ $(RUSTC) a.rs --crate-type=dylib $(FLAGS)
+ # Write symbols to disk.
+ $(NM_CMD) $(call DYLIB,a) > $(TMPDIR)/symbolsbefore
+ # b.rs is a binary
+ $(RUSTC) b.rs --extern a=$(TMPDIR)/liba$(EXT) --crate-type=bin -Crpath $(FLAGS)
+ $(call RUN,b)
+ # Now re-compile a.rs with another rustc version
+ RUSTC_FORCE_RUSTC_VERSION=deadfeed $(RUSTC) a.rs --crate-type=dylib $(FLAGS)
+ # After compiling with a different rustc version, write symbols to disk again.
+ $(NM_CMD) $(call DYLIB,a) > $(TMPDIR)/symbolsafter
+ # As a sanity check, test if the symbols changed:
+ # If the symbols are identical, there's been an error.
+ if diff $(TMPDIR)/symbolsbefore $(TMPDIR)/symbolsafter; then exit 1; fi
+ $(call FAIL,b)
+endif
diff --git a/tests/run-make/crate-hash-rustc-version/a.rs b/tests/run-make/crate-hash-rustc-version/a.rs
new file mode 100644
index 000000000..d65b5ce8e
--- /dev/null
+++ b/tests/run-make/crate-hash-rustc-version/a.rs
@@ -0,0 +1,4 @@
+pub fn foo(mut x: String) -> String {
+ x.push_str(", world!");
+ x
+}
diff --git a/tests/run-make/crate-hash-rustc-version/b.rs b/tests/run-make/crate-hash-rustc-version/b.rs
new file mode 100644
index 000000000..316ac26e7
--- /dev/null
+++ b/tests/run-make/crate-hash-rustc-version/b.rs
@@ -0,0 +1,8 @@
+extern crate a;
+
+use a::foo;
+
+fn main() {
+ let x = String::from("Hello");
+ println!("{}", foo(x));
+}