Skip to content

Commit 2858409

Browse files
committed
Auto merge of #126437 - Oneirical:test-we-forget, r=<try>
Migrate `issue-64153`, `invalid-staticlib` and `no-builtins-lto` `run-make` tests to `rmake` Part of #121876 and the associated [Google Summer of Code project](https://blog.rust-lang.org/2024/05/01/gsoc-2024-selected-projects.html). try-job: x86_64-msvc
2 parents 1138036 + aa57942 commit 2858409

File tree

11 files changed

+107
-44
lines changed

11 files changed

+107
-44
lines changed

src/tools/run-make-support/src/lib.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,8 @@ pub use cc::{cc, extra_c_flags, extra_cxx_flags, Cc};
3030
pub use clang::{clang, Clang};
3131
pub use diff::{diff, Diff};
3232
pub use llvm::{
33-
llvm_filecheck, llvm_profdata, llvm_readobj, LlvmFilecheck, LlvmProfdata, LlvmReadobj,
33+
llvm_filecheck, llvm_objdump, llvm_profdata, llvm_readobj, LlvmFilecheck, LlvmObjdump,
34+
LlvmProfdata, LlvmReadobj,
3435
};
3536
pub use run::{cmd, run, run_fail, run_with_args};
3637
pub use rustc::{aux_build, rustc, Rustc};

src/tools/run-make-support/src/llvm.rs

+30
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,12 @@ pub fn llvm_filecheck() -> LlvmFilecheck {
2323
LlvmFilecheck::new()
2424
}
2525

26+
/// Construct a new `llvm-objdump` invocation. This assumes that `llvm-objdump` is available
27+
/// at `$LLVM_BIN_DIR/llvm-objdump`.
28+
pub fn llvm_objdump() -> LlvmObjdump {
29+
LlvmObjdump::new()
30+
}
31+
2632
/// A `llvm-readobj` invocation builder.
2733
#[derive(Debug)]
2834
#[must_use]
@@ -44,9 +50,17 @@ pub struct LlvmFilecheck {
4450
cmd: Command,
4551
}
4652

53+
/// A `llvm-objdump` invocation builder.
54+
#[derive(Debug)]
55+
#[must_use]
56+
pub struct LlvmObjdump {
57+
cmd: Command,
58+
}
59+
4760
crate::impl_common_helpers!(LlvmReadobj);
4861
crate::impl_common_helpers!(LlvmProfdata);
4962
crate::impl_common_helpers!(LlvmFilecheck);
63+
crate::impl_common_helpers!(LlvmObjdump);
5064

5165
/// Generate the path to the bin directory of LLVM.
5266
#[must_use]
@@ -131,3 +145,19 @@ impl LlvmFilecheck {
131145
self
132146
}
133147
}
148+
149+
impl LlvmObjdump {
150+
/// Construct a new `llvm-objdump` invocation. This assumes that `llvm-objdump` is available
151+
/// at `$LLVM_BIN_DIR/llvm-objdump`.
152+
pub fn new() -> Self {
153+
let llvm_objdump = llvm_bin_dir().join("llvm-objdump");
154+
let cmd = Command::new(llvm_objdump);
155+
Self { cmd }
156+
}
157+
158+
/// Provide an input file.
159+
pub fn input<P: AsRef<Path>>(&mut self, path: P) -> &mut Self {
160+
self.cmd.arg(path.as_ref());
161+
self
162+
}
163+
}

src/tools/tidy/src/allowed_run_make_makefiles.txt

-3
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,6 @@ run-make/interdependent-c-libraries/Makefile
7272
run-make/intrinsic-unreachable/Makefile
7373
run-make/invalid-library/Makefile
7474
run-make/invalid-so/Makefile
75-
run-make/invalid-staticlib/Makefile
7675
run-make/issue-107094/Makefile
7776
run-make/issue-10971-temps-dir/Makefile
7877
run-make/issue-109934-lto-debuginfo/Makefile
@@ -93,7 +92,6 @@ run-make/issue-40535/Makefile
9392
run-make/issue-47384/Makefile
9493
run-make/issue-47551/Makefile
9594
run-make/issue-51671/Makefile
96-
run-make/issue-64153/Makefile
9795
run-make/issue-68794-textrel-on-minimal-lib/Makefile
9896
run-make/issue-69368/Makefile
9997
run-make/issue-83045/Makefile
@@ -145,7 +143,6 @@ run-make/native-link-modifier-verbatim-rustc/Makefile
145143
run-make/native-link-modifier-whole-archive/Makefile
146144
run-make/no-alloc-shim/Makefile
147145
run-make/no-builtins-attribute/Makefile
148-
run-make/no-builtins-lto/Makefile
149146
run-make/no-duplicate-libs/Makefile
150147
run-make/obey-crate-type-flag/Makefile
151148
run-make/optimization-remarks-dir-pgo/Makefile

tests/run-make/invalid-staticlib/Makefile

-5
This file was deleted.
+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
// If the static library provided is not valid (in this test,
2+
// created as an empty file),
3+
// rustc should print a normal error message and not throw
4+
// an internal compiler error (ICE).
5+
// See https://github.com/rust-lang/rust/pull/28673
6+
7+
use run_make_support::{fs_wrapper, rustc, static_lib_name};
8+
9+
fn main() {
10+
fs_wrapper::create_file(static_lib_name("foo"));
11+
rustc()
12+
.arg("-")
13+
.crate_type("rlib")
14+
.arg("-lstatic=foo")
15+
.run_fail()
16+
.assert_stderr_contains("failed to add native library");
17+
}

tests/run-make/issue-64153/Makefile

-26
This file was deleted.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
// ignore-tidy-tab
2+
// Staticlibs don't include Rust object files from upstream crates if the same
3+
// code was already pulled into the lib via LTO. However, the bug described in
4+
// https://github.com/rust-lang/rust/issues/64153 lead to this exclusion not
5+
// working properly if the upstream crate was compiled with an explicit filename
6+
// (via `-o`).
7+
8+
// This test makes sure that functions defined in the upstream crates do not
9+
// appear twice in the final staticlib when listing all the symbols from it.
10+
11+
//FIXME(Oneirical): temporarily remove ignorewindows
12+
// Reason: `llvm-objdump`'s output looks different on windows than on other platforms.
13+
// Only checking on Unix platforms should suffice.
14+
15+
use run_make_support::{llvm_objdump, regex, rust_lib_name, rustc, static_lib_name};
16+
17+
fn main() {
18+
rustc()
19+
.crate_type("rlib")
20+
.input("upstream.rs")
21+
.output(rust_lib_name("upstream"))
22+
.codegen_units(1)
23+
.run();
24+
rustc()
25+
.crate_type("staticlib")
26+
.input("downstream.rs")
27+
.arg("-Clto")
28+
.output(static_lib_name("downstream"))
29+
.codegen_units(1)
30+
.run();
31+
let syms = llvm_objdump().arg("-t").input(static_lib_name("downstream")).run().stdout_utf8();
32+
let re = regex::Regex::new(r#"\s*g\s*F\s.*issue64153_test_function"#).unwrap();
33+
// Count the global instances of `issue64153_test_function`. There'll be 2
34+
// if the `upstream` object file got erroneously included twice.
35+
// The line we are testing for with the regex looks something like:
36+
// 0000000000000000 g F .text.issue64153_test_function 00000023 issue64153_test_function
37+
assert_eq!(re.find_iter(syms.as_str()).count(), 1);
38+
}

tests/run-make/no-builtins-lto/Makefile

-9
This file was deleted.
+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
// The rlib produced by a no_builtins crate should be explicitely linked
2+
// during compilation, and as a result be present in the linker arguments.
3+
// See the comments inside this file for more details.
4+
// See https://github.com/rust-lang/rust/pull/35637
5+
6+
use run_make_support::{rust_lib_name, rustc};
7+
8+
fn main() {
9+
// Compile a `#![no_builtins]` rlib crate
10+
rustc().input("no_builtins.rs").run();
11+
// Build an executable that depends on that crate using LTO. The no_builtins crate doesn't
12+
// participate in LTO, so its rlib must be explicitly
13+
// linked into the final binary. Verify this by grepping the linker arguments.
14+
rustc()
15+
.input("main.rs")
16+
.arg("-Clto")
17+
.print("link-args")
18+
.run()
19+
.assert_stdout_contains(rust_lib_name("no_builtins"));
20+
}

0 commit comments

Comments
 (0)