Skip to content

Commit fd45d9d

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 28a58f2 + 3eedcfa commit fd45d9d

File tree

6 files changed

+183
-4
lines changed

6 files changed

+183
-4
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/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 renamed to tests/run-make/cross-lang-lto-clang/_Makefile

+4
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
# FIXME(Oneirical): This is already implemented as an rmake.rs file, but due to #126180,
2+
# the rmake.rs is not ran on CI. Once the rmake test has been proven to work, remove this
3+
# Makefile.
4+
15
# needs-force-clang-based-tests
26

37
# This test makes sure that cross-language inlining actually works by checking
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
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+
// 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.
8+
9+
use run_make_support::{clang, env_var, llvm_ar, llvm_objdump, rustc, static_lib_name};
10+
11+
fn main() {
12+
rustc()
13+
.linker_plugin_lto("on")
14+
.output(static_lib_name("rustlib-xlto"))
15+
.opt_level("2")
16+
.codegen_units(1)
17+
.input("rustlib.rs")
18+
.run();
19+
clang()
20+
.lto("thin")
21+
.use_ld("lld")
22+
.arg("-lrustlib-xlto")
23+
.out_exe("cmain")
24+
.input("cmain.c")
25+
.arg("-O3")
26+
.run();
27+
// Make sure we don't find a call instruction to the function we expect to
28+
// always be inlined.
29+
llvm_objdump()
30+
.arg("-d")
31+
.input("cmain")
32+
.run()
33+
.assert_stdout_not_contains_regex("call.*rust_always_inlined");
34+
// As a sanity check, make sure we do find a call instruction to a
35+
// non-inlined function
36+
llvm_objdump()
37+
.arg("-d")
38+
.input("cmain")
39+
.run()
40+
.assert_stdout_contains_regex("call.*rust_never_inlined");
41+
clang().input("clib.c").lto("thin").arg("-c").out_exe("clib.o").arg("-O2").run();
42+
llvm_ar().obj_to_ar().output_input(static_lib_name("xyz"), "clib.o").run();
43+
rustc()
44+
.linker_plugin_lto("on")
45+
.opt_level("2")
46+
.linker(&env_var("CLANG"))
47+
.link_arg("-fuse-ld=lld")
48+
.input("main.rs")
49+
.output("rsmain")
50+
.run();
51+
llvm_objdump()
52+
.arg("-d")
53+
.input("rsmain")
54+
.run()
55+
.assert_stdout_not_contains_regex("call.*c_always_inlined");
56+
llvm_objdump()
57+
.arg("-d")
58+
.input("rsmain")
59+
.run()
60+
.assert_stdout_contains_regex("call.*c_never_inlined");
61+
}

tests/run-make/cross-lang-lto-pgo-smoketest/Makefile renamed to tests/run-make/cross-lang-lto-pgo-smoketest/_Makefile

+4
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
# FIXME(Oneirical): This is already implemented as an rmake.rs file, but due to #126180,
2+
# the rmake.rs is not ran on CI. Once the rmake test has been proven to work, remove this
3+
# Makefile.
4+
15
# needs-force-clang-based-tests
26

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

0 commit comments

Comments
 (0)