Skip to content

Commit baf9765

Browse files
committed
Auto merge of rust-lang#128356 - Oneirical:real-estate-reaLTOr, r=<try>
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 e60ebb2 + cc31c99 commit baf9765

File tree

11 files changed

+183
-119
lines changed

11 files changed

+183
-119
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
@@ -232,6 +232,12 @@ impl LlvmObjdump {
232232
self.cmd.arg(path.as_ref());
233233
self
234234
}
235+
236+
/// Disassemble all executable sections found in the input files.
237+
pub fn disassemble(&mut self) -> &mut Self {
238+
self.cmd.arg("-d");
239+
self
240+
}
235241
}
236242

237243
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/cross-lang-lto/Makefile
86
run-make/dep-info-doesnt-run-much/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,112 @@
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 only runs 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+
//FIXME(Oneirical): There was a strange workaround for MSVC on this test
13+
// which added -C panic=abort to every RUSTC call. It was justified as follows:
14+
// LLVM doesn't support instrumenting binaries that use SEH:
15+
// https://bugs.llvm.org/show_bug.cgi?id=41279
16+
// Things work fine with -Cpanic=abort though.
17+
18+
use run_make_support::{
19+
clang, env_var, has_extension, has_prefix, llvm_ar, llvm_profdata, rfs, run, rustc,
20+
shallow_find_files, static_lib_name,
21+
};
22+
23+
fn main() {
24+
rustc()
25+
.linker_plugin_lto("on")
26+
.output(static_lib_name("rustlib-xlto"))
27+
.opt_level("3")
28+
.codegen_units(1)
29+
.input("rustlib.rs")
30+
.arg("-Cprofile-generate=cpp-profdata")
31+
.run();
32+
clang()
33+
.lto("thin")
34+
.arg("-fprofile-generate=cpp-profdata")
35+
.use_ld("lld")
36+
.arg("-lrustlib-xlto")
37+
.out_exe("cmain")
38+
.input("cmain.c")
39+
.arg("-O3")
40+
.run();
41+
run("cmain");
42+
// Postprocess the profiling data so it can be used by the compiler
43+
let profraw_files = shallow_find_files("cpp-profdata", |path| {
44+
has_prefix(path, "default") && has_extension(path, "profraw")
45+
});
46+
let profraw_file = profraw_files.get(0).unwrap();
47+
llvm_profdata().merge().output("cpp-profdata/merged.profdata").input(profraw_file).run();
48+
rustc()
49+
.linker_plugin_lto("on")
50+
.profile_use("cpp-profdata/merged.profdata")
51+
.output(static_lib_name("rustlib-xlto"))
52+
.opt_level("3")
53+
.codegen_units(1)
54+
.input("rustlib.rs")
55+
.run();
56+
clang()
57+
.lto("thin")
58+
.arg("-fprofile-use=cpp-profdata/merged.profdata")
59+
.use_ld("lld")
60+
.arg("-lrustlib-xlto")
61+
.out_exe("cmain")
62+
.input("cmain.c")
63+
.arg("-O3")
64+
.run();
65+
66+
clang()
67+
.input("clib.c")
68+
.arg("-fprofile-generate=rs-profdata")
69+
.lto("thin")
70+
.arg("-c")
71+
.out_exe("clib.o")
72+
.arg("-O3")
73+
.run();
74+
llvm_ar().obj_to_ar().output_input(static_lib_name("xyz"), "clib.o").run();
75+
rustc()
76+
.linker_plugin_lto("on")
77+
.opt_level("3")
78+
.codegen_units(1)
79+
.arg("-Cprofile-generate=rs-profdata")
80+
.linker(&env_var("CLANG"))
81+
.link_arg("-fuse-ld=lld")
82+
.input("main.rs")
83+
.output("rsmain")
84+
.run();
85+
run("rsmain");
86+
// Postprocess the profiling data so it can be used by the compiler
87+
let profraw_files = shallow_find_files("rs-profdata", |path| {
88+
has_prefix(path, "default") && has_extension(path, "profraw")
89+
});
90+
let profraw_file = profraw_files.get(0).unwrap();
91+
llvm_profdata().merge().output("rs-profdata/merged.profdata").input(profraw_file).run();
92+
clang()
93+
.input("clib.c")
94+
.arg("-fprofile-use=rs-profdata/merged.profdata")
95+
.arg("-c")
96+
.lto("thin")
97+
.out_exe("clib.o")
98+
.arg("-O3")
99+
.run();
100+
rfs::remove_file(static_lib_name("xyz"));
101+
llvm_ar().obj_to_ar().output_input(static_lib_name("xyz"), "clib.o").run();
102+
rustc()
103+
.linker_plugin_lto("on")
104+
.opt_level("3")
105+
.codegen_units(1)
106+
.arg("-Cprofile-use=rs-profdata/merged.profdata")
107+
.linker(&env_var("CLANG"))
108+
.link_arg("-fuse-ld=lld")
109+
.input("main.rs")
110+
.output("rsmain")
111+
.run();
112+
}

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

-90
This file was deleted.

0 commit comments

Comments
 (0)