about summary refs log tree commit diff
diff options
context:
space:
mode:
authorbjorn3 <17426603+bjorn3@users.noreply.github.com>2024-08-10 17:43:22 +0000
committerbjorn3 <17426603+bjorn3@users.noreply.github.com>2024-08-10 17:43:22 +0000
commita57f73d32060ac27bfdb6635b98025f362598574 (patch)
treee16763a8c39ea73fd8e1f1d0e838a2b2b362ee57
parent4f8042e22ebaf962ebbffc6056373b387dc65515 (diff)
Add test for thin archive reading support
-rw-r--r--src/tools/run-make-support/src/external_deps/llvm.rs6
-rw-r--r--tests/run-make/staticlib-thin-archive/bin.rs10
-rw-r--r--tests/run-make/staticlib-thin-archive/rmake.rs13
-rw-r--r--tests/run-make/staticlib-thin-archive/rust_archive.rs4
-rw-r--r--tests/run-make/staticlib-thin-archive/simple_obj.rs4
5 files changed, 37 insertions, 0 deletions
diff --git a/src/tools/run-make-support/src/external_deps/llvm.rs b/src/tools/run-make-support/src/external_deps/llvm.rs
index dc651fdd820..4003287d762 100644
--- a/src/tools/run-make-support/src/external_deps/llvm.rs
+++ b/src/tools/run-make-support/src/external_deps/llvm.rs
@@ -271,6 +271,12 @@ impl LlvmAr {
         self
     }
 
+    /// Like `obj_to_ar` except creating a thin archive.
+    pub fn obj_to_thin_ar(&mut self) -> &mut Self {
+        self.cmd.arg("rcus").arg("--thin");
+        self
+    }
+
     /// Extract archive members back to files.
     pub fn extract(&mut self) -> &mut Self {
         self.cmd.arg("x");
diff --git a/tests/run-make/staticlib-thin-archive/bin.rs b/tests/run-make/staticlib-thin-archive/bin.rs
new file mode 100644
index 00000000000..b37107d9c94
--- /dev/null
+++ b/tests/run-make/staticlib-thin-archive/bin.rs
@@ -0,0 +1,10 @@
+#[link(name = "rust_archive", kind = "static")]
+extern "C" {
+    fn simple_fn();
+}
+
+fn main() {
+    unsafe {
+        simple_fn();
+    }
+}
diff --git a/tests/run-make/staticlib-thin-archive/rmake.rs b/tests/run-make/staticlib-thin-archive/rmake.rs
new file mode 100644
index 00000000000..137dffcc33f
--- /dev/null
+++ b/tests/run-make/staticlib-thin-archive/rmake.rs
@@ -0,0 +1,13 @@
+// Regression test for https://github.com/rust-lang/rust/issues/107407
+
+use run_make_support::{llvm_ar, rustc, static_lib_name};
+
+fn main() {
+    rustc().input("simple_obj.rs").emit("obj").run();
+    llvm_ar().obj_to_thin_ar().output_input(static_lib_name("thin_archive"), "simple_obj.o").run();
+    rustc().input("rust_archive.rs").run();
+    // Disable lld as it ignores the symbol table in the archive file.
+    rustc()
+        .input("bin.rs") /*.arg("-Zlinker-features=-lld")*/
+        .run();
+}
diff --git a/tests/run-make/staticlib-thin-archive/rust_archive.rs b/tests/run-make/staticlib-thin-archive/rust_archive.rs
new file mode 100644
index 00000000000..3d11f02df20
--- /dev/null
+++ b/tests/run-make/staticlib-thin-archive/rust_archive.rs
@@ -0,0 +1,4 @@
+#![crate_type = "staticlib"]
+
+#[link(name = "thin_archive", kind = "static")]
+extern "C" {}
diff --git a/tests/run-make/staticlib-thin-archive/simple_obj.rs b/tests/run-make/staticlib-thin-archive/simple_obj.rs
new file mode 100644
index 00000000000..a120c9b3e67
--- /dev/null
+++ b/tests/run-make/staticlib-thin-archive/simple_obj.rs
@@ -0,0 +1,4 @@
+#![crate_type = "staticlib"]
+
+#[no_mangle]
+extern "C" fn simple_fn() {}