Skip to content

Commit af3d100

Browse files
committed
Auto merge of rust-lang#126437 - Oneirical:test-we-forget, r=jieyouxu
Migrate `issue-64153`, `invalid-staticlib` and `no-builtins-lto` `run-make` tests to `rmake` Part of rust-lang#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 c1f62a7 + df6d873 commit af3d100

File tree

11 files changed

+109
-44
lines changed

11 files changed

+109
-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
@@ -68,7 +68,6 @@ run-make/interdependent-c-libraries/Makefile
6868
run-make/intrinsic-unreachable/Makefile
6969
run-make/invalid-library/Makefile
7070
run-make/invalid-so/Makefile
71-
run-make/invalid-staticlib/Makefile
7271
run-make/issue-107094/Makefile
7372
run-make/issue-109934-lto-debuginfo/Makefile
7473
run-make/issue-14698/Makefile
@@ -87,7 +86,6 @@ run-make/issue-40535/Makefile
8786
run-make/issue-47384/Makefile
8887
run-make/issue-47551/Makefile
8988
run-make/issue-51671/Makefile
90-
run-make/issue-64153/Makefile
9189
run-make/issue-68794-textrel-on-minimal-lib/Makefile
9290
run-make/issue-69368/Makefile
9391
run-make/issue-83045/Makefile
@@ -137,7 +135,6 @@ run-make/native-link-modifier-verbatim-rustc/Makefile
137135
run-make/native-link-modifier-whole-archive/Makefile
138136
run-make/no-alloc-shim/Makefile
139137
run-make/no-builtins-attribute/Makefile
140-
run-make/no-builtins-lto/Makefile
141138
run-make/no-duplicate-libs/Makefile
142139
run-make/obey-crate-type-flag/Makefile
143140
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,40 @@
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+
//@ ignore-windows
12+
// Reason: `llvm-objdump`'s output looks different on windows than on other platforms.
13+
// Only checking on Unix platforms should suffice.
14+
//FIXME(Oneirical): This could be adapted to work on Windows by checking how
15+
// that output differs.
16+
17+
use run_make_support::{llvm_objdump, regex, rust_lib_name, rustc, static_lib_name};
18+
19+
fn main() {
20+
rustc()
21+
.crate_type("rlib")
22+
.input("upstream.rs")
23+
.output(rust_lib_name("upstream"))
24+
.codegen_units(1)
25+
.run();
26+
rustc()
27+
.crate_type("staticlib")
28+
.input("downstream.rs")
29+
.arg("-Clto")
30+
.output(static_lib_name("downstream"))
31+
.codegen_units(1)
32+
.run();
33+
let syms = llvm_objdump().arg("-t").input(static_lib_name("downstream")).run().stdout_utf8();
34+
let re = regex::Regex::new(r#"\s*g\s*F\s.*issue64153_test_function"#).unwrap();
35+
// Count the global instances of `issue64153_test_function`. There'll be 2
36+
// if the `upstream` object file got erroneously included twice.
37+
// The line we are testing for with the regex looks something like:
38+
// 0000000000000000 g F .text.issue64153_test_function 00000023 issue64153_test_function
39+
assert_eq!(re.find_iter(syms.as_str()).count(), 1);
40+
}

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)