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() {}