Skip to content

Commit a604303

Browse files
committed
Auto merge of rust-lang#128356 - Oneirical:real-estate-reaLTOr, r=jieyouxu
Migrate `cross-lang-lto-clang` and `cross-lang-lto-pgo-smoketest` `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). This has the same problem outlined by rust-lang#126180, where the tests do not actually run as no test-running CI enviroment has `RUSTBUILD_FORCE_CLANG_BASED_TESTS` set. However, I still find it interesting to turn the Makefiles into the rmake format until the Clang issue is fixed. This should technically be tested on MSVC... if MSVC actually ran Clang tests. try-job: x86_64-gnu-debug
2 parents eefd2ea + 290a260 commit a604303

File tree

13 files changed

+200
-121
lines changed

13 files changed

+200
-121
lines changed

src/tools/run-make-support/src/external_deps/clang.rs

+3-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use std::path::Path;
22

33
use crate::command::Command;
4-
use crate::{bin_name, env_var};
4+
use crate::{bin_name, cwd, env_var};
55

66
/// Construct a new `clang` invocation. `clang` is not always available for all targets.
77
#[track_caller]
@@ -23,7 +23,8 @@ impl Clang {
2323
#[track_caller]
2424
pub fn new() -> Self {
2525
let clang = env_var("CLANG");
26-
let cmd = Command::new(clang);
26+
let mut cmd = Command::new(clang);
27+
cmd.arg("-L").arg(cwd());
2728
Self { cmd }
2829
}
2930

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

+6
Original file line numberDiff line numberDiff line change
@@ -246,6 +246,12 @@ impl LlvmObjdump {
246246
self.cmd.arg(path.as_ref());
247247
self
248248
}
249+
250+
/// Disassemble all executable sections found in the input files.
251+
pub fn disassemble(&mut self) -> &mut Self {
252+
self.cmd.arg("-d");
253+
self
254+
}
249255
}
250256

251257
impl LlvmAr {

src/tools/tidy/src/allowed_run_make_makefiles.txt

-2
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
run-make/branch-protection-check-IBT/Makefile
22
run-make/cat-and-grep-sanity-check/Makefile
33
run-make/cdylib-dylib-linkage/Makefile
4-
run-make/cross-lang-lto-clang/Makefile
5-
run-make/cross-lang-lto-pgo-smoketest/Makefile
64
run-make/cross-lang-lto-upstream-rlibs/Makefile
75
run-make/dep-info-doesnt-run-much/Makefile
86
run-make/dep-info-spaces/Makefile

tests/run-make/cross-lang-lto-clang/Makefile

-25
This file was deleted.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
// This test checks that cross-language inlining actually works by checking
2+
// the generated machine code.
3+
// See https://github.com/rust-lang/rust/pull/57514
4+
5+
//@ needs-force-clang-based-tests
6+
// NOTE(#126180): This test only runs on `x86_64-gnu-debug`, because that CI job sets
7+
// RUSTBUILD_FORCE_CLANG_BASED_TESTS and only runs tests which contain "clang" in their
8+
// name.
9+
10+
use run_make_support::{clang, env_var, llvm_ar, llvm_objdump, rustc, static_lib_name};
11+
12+
fn main() {
13+
rustc()
14+
.linker_plugin_lto("on")
15+
.output(static_lib_name("rustlib-xlto"))
16+
.opt_level("2")
17+
.codegen_units(1)
18+
.input("rustlib.rs")
19+
.run();
20+
clang()
21+
.lto("thin")
22+
.use_ld("lld")
23+
.arg("-lrustlib-xlto")
24+
.out_exe("cmain")
25+
.input("cmain.c")
26+
.arg("-O3")
27+
.run();
28+
// Make sure we don't find a call instruction to the function we expect to
29+
// always be inlined.
30+
llvm_objdump()
31+
.disassemble()
32+
.input("cmain")
33+
.run()
34+
.assert_stdout_not_contains_regex("call.*rust_always_inlined");
35+
// As a sanity check, make sure we do find a call instruction to a
36+
// non-inlined function
37+
llvm_objdump()
38+
.disassemble()
39+
.input("cmain")
40+
.run()
41+
.assert_stdout_contains_regex("call.*rust_never_inlined");
42+
clang().input("clib.c").lto("thin").arg("-c").out_exe("clib.o").arg("-O2").run();
43+
llvm_ar().obj_to_ar().output_input(static_lib_name("xyz"), "clib.o").run();
44+
rustc()
45+
.linker_plugin_lto("on")
46+
.opt_level("2")
47+
.linker(&env_var("CLANG"))
48+
.link_arg("-fuse-ld=lld")
49+
.input("main.rs")
50+
.output("rsmain")
51+
.run();
52+
llvm_objdump()
53+
.disassemble()
54+
.input("rsmain")
55+
.run()
56+
.assert_stdout_not_contains_regex("call.*c_always_inlined");
57+
llvm_objdump()
58+
.disassemble()
59+
.input("rsmain")
60+
.run()
61+
.assert_stdout_contains_regex("call.*c_never_inlined");
62+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,120 @@
1+
// This test makes sure that cross-language inlining can be used in conjunction
2+
// with profile-guided optimization. The test only tests that the whole workflow
3+
// can be executed without anything crashing. It does not test whether PGO or
4+
// xLTO have any specific effect on the generated code.
5+
// See https://github.com/rust-lang/rust/pull/61036
6+
7+
//@ needs-force-clang-based-tests
8+
// NOTE(#126180): This test would only run on `x86_64-gnu-debug`, because that CI job sets
9+
// RUSTBUILD_FORCE_CLANG_BASED_TESTS and only runs tests which contain "clang" in their
10+
// name.
11+
12+
//@ needs-profiler-support
13+
// FIXME(Oneirical): Except that due to the reliance on llvm-profdata, this test
14+
// never runs, because `x86_64-gnu-debug` does not have the `profiler_builtins` crate.
15+
16+
//FIXME(Oneirical): There was a strange workaround for MSVC on this test
17+
// which added -C panic=abort to every RUSTC call. It was justified as follows:
18+
19+
// "LLVM doesn't support instrumenting binaries that use SEH:
20+
// https://bugs.llvm.org/show_bug.cgi?id=41279
21+
// Things work fine with -Cpanic=abort though."
22+
23+
// This isn't very pertinent, however, as the test does not get run on any
24+
// MSVC platforms.
25+
26+
use run_make_support::{
27+
clang, env_var, has_extension, has_prefix, llvm_ar, llvm_profdata, rfs, run, rustc,
28+
shallow_find_files, static_lib_name,
29+
};
30+
31+
fn main() {
32+
rustc()
33+
.linker_plugin_lto("on")
34+
.output(static_lib_name("rustlib-xlto"))
35+
.opt_level("3")
36+
.codegen_units(1)
37+
.input("rustlib.rs")
38+
.arg("-Cprofile-generate=cpp-profdata")
39+
.run();
40+
clang()
41+
.lto("thin")
42+
.arg("-fprofile-generate=cpp-profdata")
43+
.use_ld("lld")
44+
.arg("-lrustlib-xlto")
45+
.out_exe("cmain")
46+
.input("cmain.c")
47+
.arg("-O3")
48+
.run();
49+
run("cmain");
50+
// Postprocess the profiling data so it can be used by the compiler
51+
let profraw_files = shallow_find_files("cpp-profdata", |path| {
52+
has_prefix(path, "default") && has_extension(path, "profraw")
53+
});
54+
let profraw_file = profraw_files.get(0).unwrap();
55+
llvm_profdata().merge().output("cpp-profdata/merged.profdata").input(profraw_file).run();
56+
rustc()
57+
.linker_plugin_lto("on")
58+
.profile_use("cpp-profdata/merged.profdata")
59+
.output(static_lib_name("rustlib-xlto"))
60+
.opt_level("3")
61+
.codegen_units(1)
62+
.input("rustlib.rs")
63+
.run();
64+
clang()
65+
.lto("thin")
66+
.arg("-fprofile-use=cpp-profdata/merged.profdata")
67+
.use_ld("lld")
68+
.arg("-lrustlib-xlto")
69+
.out_exe("cmain")
70+
.input("cmain.c")
71+
.arg("-O3")
72+
.run();
73+
74+
clang()
75+
.input("clib.c")
76+
.arg("-fprofile-generate=rs-profdata")
77+
.lto("thin")
78+
.arg("-c")
79+
.out_exe("clib.o")
80+
.arg("-O3")
81+
.run();
82+
llvm_ar().obj_to_ar().output_input(static_lib_name("xyz"), "clib.o").run();
83+
rustc()
84+
.linker_plugin_lto("on")
85+
.opt_level("3")
86+
.codegen_units(1)
87+
.arg("-Cprofile-generate=rs-profdata")
88+
.linker(&env_var("CLANG"))
89+
.link_arg("-fuse-ld=lld")
90+
.input("main.rs")
91+
.output("rsmain")
92+
.run();
93+
run("rsmain");
94+
// Postprocess the profiling data so it can be used by the compiler
95+
let profraw_files = shallow_find_files("rs-profdata", |path| {
96+
has_prefix(path, "default") && has_extension(path, "profraw")
97+
});
98+
let profraw_file = profraw_files.get(0).unwrap();
99+
llvm_profdata().merge().output("rs-profdata/merged.profdata").input(profraw_file).run();
100+
clang()
101+
.input("clib.c")
102+
.arg("-fprofile-use=rs-profdata/merged.profdata")
103+
.arg("-c")
104+
.lto("thin")
105+
.out_exe("clib.o")
106+
.arg("-O3")
107+
.run();
108+
rfs::remove_file(static_lib_name("xyz"));
109+
llvm_ar().obj_to_ar().output_input(static_lib_name("xyz"), "clib.o").run();
110+
rustc()
111+
.linker_plugin_lto("on")
112+
.opt_level("3")
113+
.codegen_units(1)
114+
.arg("-Cprofile-use=rs-profdata/merged.profdata")
115+
.linker(&env_var("CLANG"))
116+
.link_arg("-fuse-ld=lld")
117+
.input("main.rs")
118+
.output("rsmain")
119+
.run();
120+
}

tests/run-make/cross-lang-lto-pgo-smoketest/Makefile

-90
This file was deleted.

tests/run-make/cross-lang-lto-riscv-abi/rmake.rs

+5-2
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,11 @@
33
//@ needs-force-clang-based-tests
44
//@ needs-llvm-components riscv
55

6-
// FIXME(#126180): This test doesn't actually run anywhere, because the only
7-
// CI job that sets RUSTBUILD_FORCE_CLANG_BASED_TESTS runs very few tests.
6+
//@ needs-force-clang-based-tests
7+
// FIXME(#126180): This test can only run on `x86_64-gnu-debug`, because that CI job sets
8+
// RUSTBUILD_FORCE_CLANG_BASED_TESTS and only runs tests which contain "clang" in their
9+
// name.
10+
// However, this test does not run at all as its name does not contain "clang".
811

912
use std::path::PathBuf;
1013
use std::process::{Command, Output};

tests/run-make/wasm-override-linker/rmake.rs

+4
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,10 @@
22
// $ RUSTBUILD_FORCE_CLANG_BASED_TESTS=1 ./x.py test tests/run-make/wasm-override-linker/
33

44
//@ needs-force-clang-based-tests
5+
// FIXME(#126180): This test can only run on `x86_64-gnu-debug`, because that CI job sets
6+
// RUSTBUILD_FORCE_CLANG_BASED_TESTS and only runs tests which contain "clang" in their
7+
// name.
8+
// However, this test does not run at all as its name does not contain "clang".
59

610
use run_make_support::{env_var, rustc, target};
711

0 commit comments

Comments
 (0)