Auto merge of #126437 - Oneirical:test-we-forget, r=jieyouxu · rust-lang/rust@af3d100 (original) (raw)

11 files changed

lines changed

Original file line number Diff line number Diff line change
@@ -30,7 +30,8 @@ pub use cc::{cc, extra_c_flags, extra_cxx_flags, Cc};
30 30 pub use clang::{clang, Clang};
31 31 pub use diff::{diff, Diff};
32 32 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,
34 35 };
35 36 pub use run::{cmd, run, run_fail, run_with_args};
36 37 pub use rustc::{aux_build, rustc, Rustc};
Original file line number Diff line number Diff line change
@@ -23,6 +23,12 @@ pub fn llvm_filecheck() -> LlvmFilecheck {
23 23 LlvmFilecheck::new()
24 24 }
25 25
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 +
26 32 /// A `llvm-readobj` invocation builder.
27 33 #[derive(Debug)]
28 34 #[must_use]
@@ -44,9 +50,17 @@ pub struct LlvmFilecheck {
44 50 cmd: Command,
45 51 }
46 52
53 +/// A `llvm-objdump` invocation builder.
54 +#[derive(Debug)]
55 +#[must_use]
56 +pub struct LlvmObjdump {
57 +cmd: Command,
58 +}
59 +
47 60 crate::impl_common_helpers!(LlvmReadobj);
48 61 crate::impl_common_helpers!(LlvmProfdata);
49 62 crate::impl_common_helpers!(LlvmFilecheck);
63 +crate::impl_common_helpers!(LlvmObjdump);
50 64
51 65 /// Generate the path to the bin directory of LLVM.
52 66 #[must_use]
@@ -131,3 +145,19 @@ impl LlvmFilecheck {
131 145 self
132 146 }
133 147 }
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 +}
Original file line number Diff line number Diff line change
@@ -68,7 +68,6 @@ run-make/interdependent-c-libraries/Makefile
68 68 run-make/intrinsic-unreachable/Makefile
69 69 run-make/invalid-library/Makefile
70 70 run-make/invalid-so/Makefile
71 -run-make/invalid-staticlib/Makefile
72 71 run-make/issue-107094/Makefile
73 72 run-make/issue-109934-lto-debuginfo/Makefile
74 73 run-make/issue-14698/Makefile
@@ -87,7 +86,6 @@ run-make/issue-40535/Makefile
87 86 run-make/issue-47384/Makefile
88 87 run-make/issue-47551/Makefile
89 88 run-make/issue-51671/Makefile
90 -run-make/issue-64153/Makefile
91 89 run-make/issue-68794-textrel-on-minimal-lib/Makefile
92 90 run-make/issue-69368/Makefile
93 91 run-make/issue-83045/Makefile
@@ -137,7 +135,6 @@ run-make/native-link-modifier-verbatim-rustc/Makefile
137 135 run-make/native-link-modifier-whole-archive/Makefile
138 136 run-make/no-alloc-shim/Makefile
139 137 run-make/no-builtins-attribute/Makefile
140 -run-make/no-builtins-lto/Makefile
141 138 run-make/no-duplicate-libs/Makefile
142 139 run-make/obey-crate-type-flag/Makefile
143 140 run-make/optimization-remarks-dir-pgo/Makefile
Original file line number Diff line number Diff 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 +}

File renamed without changes.

Original file line number Diff line number Diff 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 +}

File renamed without changes.

Original file line number Diff line number Diff 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 +}