about summary refs log tree commit diff
diff options
context:
space:
mode:
authorbjorn3 <17426603+bjorn3@users.noreply.github.com>2025-02-14 10:04:19 +0000
committerbjorn3 <17426603+bjorn3@users.noreply.github.com>2025-02-14 10:54:56 +0000
commit9147b6dd2878763208d90b41bca18d9144fd5bf8 (patch)
treeda8397a2fbebc19318035a3c413e1c8d8e26e75b
parent736ef0a4cee37e35caa6efb1121a776e00a9de4a (diff)
downloadrust-9147b6dd2878763208d90b41bca18d9144fd5bf8.tar.gz
rust-9147b6dd2878763208d90b41bca18d9144fd5bf8.zip
Add test
-rw-r--r--tests/run-make/staticlib-broken-bitcode/rmake.rs23
-rw-r--r--tests/run-make/staticlib-broken-bitcode/rust_lib.rs6
2 files changed, 29 insertions, 0 deletions
diff --git a/tests/run-make/staticlib-broken-bitcode/rmake.rs b/tests/run-make/staticlib-broken-bitcode/rmake.rs
new file mode 100644
index 00000000000..f8c61d70819
--- /dev/null
+++ b/tests/run-make/staticlib-broken-bitcode/rmake.rs
@@ -0,0 +1,23 @@
+// Regression test for https://github.com/rust-lang/rust/issues/128955#issuecomment-2657811196
+// which checks that rustc can read an archive containing LLVM bitcode with a
+// newer version from the one rustc links against.
+use run_make_support::{llvm_ar, path, rfs, rustc, static_lib_name};
+
+fn main() {
+    rfs::create_dir("archive");
+
+    let mut bitcode = b"BC\xC0\xDE".to_vec();
+    bitcode.extend(std::iter::repeat(b'a').take(50));
+    rfs::write("archive/invalid_bitcode.o", &bitcode);
+
+    llvm_ar()
+        .obj_to_thin_ar()
+        .output_input(
+            path("archive").join(static_lib_name("thin_archive")),
+            "archive/invalid_bitcode.o",
+        )
+        .run();
+
+    // Build an rlib which includes the members of this thin archive
+    rustc().input("rust_lib.rs").library_search_path("archive").run();
+}
diff --git a/tests/run-make/staticlib-broken-bitcode/rust_lib.rs b/tests/run-make/staticlib-broken-bitcode/rust_lib.rs
new file mode 100644
index 00000000000..c76b0f25433
--- /dev/null
+++ b/tests/run-make/staticlib-broken-bitcode/rust_lib.rs
@@ -0,0 +1,6 @@
+#![crate_type = "rlib"]
+
+#[link(name = "thin_archive", kind = "static")]
+extern "C" {
+    pub fn simple_fn();
+}