Skip to content

Migrate staticlib-blank-lib, rlib-format-packed-bundled-libs-3 and issue-97463-abi-param-passing run-make tests to rmake #127778

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Jul 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions src/tools/run-make-support/src/external_deps/llvm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -229,6 +229,8 @@ impl LlvmAr {
Self { cmd }
}

/// Automatically pass the commonly used arguments `rcus`, used for combining one or more
/// input object files into one output static library file.
pub fn obj_to_ar(&mut self) -> &mut Self {
self.cmd.arg("rcus");
self
Expand Down
3 changes: 0 additions & 3 deletions src/tools/tidy/src/allowed_run_make_makefiles.txt
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,6 @@ run-make/issue-47551/Makefile
run-make/issue-69368/Makefile
run-make/issue-84395-lto-embed-bitcode/Makefile
run-make/issue-88756-default-output/Makefile
run-make/issue-97463-abi-param-passing/Makefile
run-make/jobserver-error/Makefile
run-make/libs-through-symlinks/Makefile
run-make/libtest-json/Makefile
Expand Down Expand Up @@ -92,7 +91,6 @@ run-make/reproducible-build-2/Makefile
run-make/reproducible-build/Makefile
run-make/return-non-c-like-enum-from-c/Makefile
run-make/rlib-format-packed-bundled-libs-2/Makefile
run-make/rlib-format-packed-bundled-libs-3/Makefile
run-make/rlib-format-packed-bundled-libs/Makefile
run-make/sanitizer-cdylib-link/Makefile
run-make/sanitizer-dylib-link/Makefile
Expand All @@ -102,7 +100,6 @@ run-make/simd-ffi/Makefile
run-make/split-debuginfo/Makefile
run-make/stable-symbol-names/Makefile
run-make/static-dylib-by-default/Makefile
run-make/staticlib-blank-lib/Makefile
run-make/staticlib-dylib-linkage/Makefile
run-make/symbol-mangling-hashed/Makefile
run-make/symbol-visibility/Makefile
Expand Down
15 changes: 0 additions & 15 deletions tests/run-make/issue-97463-abi-param-passing/Makefile

This file was deleted.

35 changes: 0 additions & 35 deletions tests/run-make/rlib-format-packed-bundled-libs-3/Makefile

This file was deleted.

84 changes: 84 additions & 0 deletions tests/run-make/rlib-format-packed-bundled-libs-3/rmake.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
// `-Z packed_bundled_libs` is an unstable rustc flag that makes the compiler
// only require a native library and no supplementary object files to compile.
// #105601 made it possible to have this behaviour without an unstable flag by
// passing +bundle in modifiers, and this test checks that this feature successfully
// compiles and includes only the static libraries, with no object files.
// See https://github.com/rust-lang/rust/pull/105601

use run_make_support::{
build_native_static_lib, is_msvc, llvm_ar, regex, rfs, rust_lib_name, rustc, static_lib_name,
};

//@ ignore-cross-compile
// Reason: Invalid library format (not ELF) causes compilation failure
// in the final `rustc` call.

//@ only-linux
// Reason: differences in the native lib compilation process causes differences
// in the --print link-args output

fn main() {
build_native_static_lib("native_dep_1");
build_native_static_lib("native_dep_2");
build_native_static_lib("native_dep_3");
build_native_static_lib("native_dep_4");
// Test cfg with packed bundle.
rustc().input("rust_dep_cfg.rs").crate_type("rlib").run();
rustc()
.input("main.rs")
.extern_("rust_dep", rust_lib_name("rust_dep_cfg"))
.crate_type("staticlib")
.cfg("should_add")
.run();
// Only static libraries should appear, no object files at all.
llvm_ar()
.arg("t")
.arg(rust_lib_name("rust_dep_cfg"))
.run()
.assert_stdout_contains(static_lib_name("native_dep_1"));
llvm_ar()
.arg("t")
.arg(rust_lib_name("rust_dep_cfg"))
.run()
.assert_stdout_contains(static_lib_name("native_dep_2"));
llvm_ar().arg("t").arg(static_lib_name("main")).run().assert_stdout_contains("native_dep_1.o");
llvm_ar()
.arg("t")
.arg(static_lib_name("main"))
.run()
.assert_stdout_not_contains("native_dep_2.o");

// Test bundle with whole archive.
rustc().input("rust_dep.rs").crate_type("rlib").run();
// Only deps with `+bundle` should appear.
llvm_ar().arg("t").arg(rust_lib_name("rust_dep")).run().assert_stdout_contains("native_dep_1");
llvm_ar().arg("t").arg(rust_lib_name("rust_dep")).run().assert_stdout_contains("native_dep_3");
llvm_ar()
.arg("t")
.arg(rust_lib_name("rust_dep"))
.run()
.assert_stdout_not_contains("native_dep_2");
llvm_ar()
.arg("t")
.arg(rust_lib_name("rust_dep"))
.run()
.assert_stdout_not_contains("native_dep_4");

// The compiler shouldn't use files which it doesn't know about.
rfs::remove_file(static_lib_name("native_dep_1"));
rfs::remove_file(static_lib_name("native_dep_3"));

let out = rustc()
.input("main.rs")
.extern_("rust_dep", rust_lib_name("rust_dep"))
.print("link-args")
.run()
.assert_stdout_not_contains("native_dep_3")
.stdout_utf8();

let re = regex::Regex::new(
"--whole-archive.*native_dep_1.*--whole-archive.*lnative_dep_2.*no-whole-archive.*lnative_dep_4"
).unwrap();

assert!(re.is_match(&out));
}
6 changes: 0 additions & 6 deletions tests/run-make/staticlib-blank-lib/Makefile

This file was deleted.

13 changes: 13 additions & 0 deletions tests/run-make/staticlib-blank-lib/rmake.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
// In this test, the static library foo is made blank, which used to cause
// a compilation error. As the compiler now returns Ok upon encountering a blank
// staticlib as of #12379, this test checks that compilation is successful despite
// the blank staticlib.
// See https://github.com/rust-lang/rust/pull/12379

use run_make_support::{llvm_ar, rustc, static_lib_name};

fn main() {
llvm_ar().obj_to_ar().output_input(static_lib_name("foo"), "foo.rs").run();
llvm_ar().arg("d").output_input(static_lib_name("foo"), "foo.rs").run();
rustc().input("foo.rs").run();
}
25 changes: 25 additions & 0 deletions tests/run-make/zero-extend-abi-param-passing/rmake.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
// This test was created in response to an obscure miscompilation bug, only
// visible with the -O3 flag passed to the cc compiler when trying to obtain
// a native static library for the sake of foreign function interface. This
// flag could cause certain integer types to fail to be zero-extended, resulting
// in type casting errors. After the fix in #97800, this test attempts integer casting
// while simultaneously interfacing with a C library and using the -O3 flag.
// See https://github.com/rust-lang/rust/issues/97463

//@ ignore-msvc
// Reason: the rustc compilation fails due to an unresolved external symbol

//@ ignore-cross-compile
// Reason: The compiled binary is executed.

use run_make_support::{cc, is_msvc, llvm_ar, run, rustc, static_lib_name};

fn main() {
// The issue exercised by this test specifically needs needs `-O`
// flags (like `-O3`) to reproduce. Thus, we call `cc()` instead of
// the nicer `build_native_static_lib`.
cc().arg("-c").arg("-O3").out_exe("bad.o").input("bad.c").run();
llvm_ar().obj_to_ar().output_input(static_lib_name("bad"), "bad.o").run();
rustc().input("param_passing.rs").arg("-lbad").opt_level("3").run();
run("param_passing");
}
Loading