about summary refs log tree commit diff
path: root/tests
diff options
context:
space:
mode:
authorbors <bors@rust-lang.org>2024-08-15 14:13:52 +0000
committerbors <bors@rust-lang.org>2024-08-15 14:13:52 +0000
commitd2b5aa6552c8acf67f38a2ad92062a32ec542f08 (patch)
tree1899813d951bc263c5828d2e81de1ee228b84e25 /tests
parent3139ff09e9d07f7700f8d15ed25a231e29c43627 (diff)
parent901c9daa05ec817c3a0f7aad87a928cfcfe00ce2 (diff)
downloadrust-d2b5aa6552c8acf67f38a2ad92062a32ec542f08.tar.gz
rust-d2b5aa6552c8acf67f38a2ad92062a32ec542f08.zip
Auto merge of #128936 - bjorn3:fix_thin_archive_reading, r=jieyouxu
Support reading thin archives in ArArchiveBuilder

And switch to using ArArchiveBuilder with the LLVM backend too now that all regressions are fixed.

Fixes https://github.com/rust-lang/rust/issues/107407
Fixes https://github.com/rust-lang/rust/issues/107162
https://github.com/rust-lang/rust/issues/107495 has been fixed in a previous PR already.
Diffstat (limited to 'tests')
-rw-r--r--tests/run-make/staticlib-thin-archive/bin.rs5
-rw-r--r--tests/run-make/staticlib-thin-archive/rmake.rs23
-rw-r--r--tests/run-make/staticlib-thin-archive/rust_lib.rs6
-rw-r--r--tests/run-make/staticlib-thin-archive/simple_obj.rs4
4 files changed, 38 insertions, 0 deletions
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..97a2751f20b
--- /dev/null
+++ b/tests/run-make/staticlib-thin-archive/bin.rs
@@ -0,0 +1,5 @@
+fn main() {
+    unsafe {
+        rust_lib::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..955c50da201
--- /dev/null
+++ b/tests/run-make/staticlib-thin-archive/rmake.rs
@@ -0,0 +1,23 @@
+// Regression test for https://github.com/rust-lang/rust/issues/107407 which
+// checks that rustc can read thin archive. Before the object crate added thin
+// archive support rustc would add emit object files to the staticlib and after
+// the object crate added thin archive support it would previously crash the
+// compiler due to a missing special case for thin archive members.
+use run_make_support::{llvm_ar, path, rfs, rust_lib_name, rustc, static_lib_name};
+
+fn main() {
+    rfs::create_dir("archive");
+
+    // Build a thin archive
+    rustc().input("simple_obj.rs").emit("obj").output("archive/simple_obj.o").run();
+    llvm_ar()
+        .obj_to_thin_ar()
+        .output_input(path("archive").join(static_lib_name("thin_archive")), "archive/simple_obj.o")
+        .run();
+
+    // Build an rlib which includes the members of this thin archive
+    rustc().input("rust_lib.rs").library_search_path("archive").run();
+
+    // Build a binary which requires a symbol from the thin archive
+    rustc().input("bin.rs").extern_("rust_lib", rust_lib_name("rust_lib")).run();
+}
diff --git a/tests/run-make/staticlib-thin-archive/rust_lib.rs b/tests/run-make/staticlib-thin-archive/rust_lib.rs
new file mode 100644
index 00000000000..c76b0f25433
--- /dev/null
+++ b/tests/run-make/staticlib-thin-archive/rust_lib.rs
@@ -0,0 +1,6 @@
+#![crate_type = "rlib"]
+
+#[link(name = "thin_archive", kind = "static")]
+extern "C" {
+    pub fn simple_fn();
+}
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() {}