Skip to content

Commit b7e90fe

Browse files
committed
rewrite cross-lang-lto-pgo-smoketest to rmake
1 parent eb3c932 commit b7e90fe

File tree

4 files changed

+144
-1
lines changed

4 files changed

+144
-1
lines changed

src/tools/tidy/src/allowed_run_make_makefiles.txt

-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +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-pgo-smoketest/Makefile
54
run-make/cross-lang-lto-upstream-rlibs/Makefile
65
run-make/cross-lang-lto/Makefile
76
run-make/dep-info-doesnt-run-much/Makefile
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
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+
5+
# needs-force-clang-based-tests
6+
7+
# This test makes sure that cross-language inlining actually works by checking
8+
# the generated machine code.
9+
10+
include ../tools.mk
11+
12+
all: cpp-executable rust-executable
13+
14+
cpp-executable:
15+
$(RUSTC) -Clinker-plugin-lto=on -o $(TMPDIR)/librustlib-xlto.a -Copt-level=2 -Ccodegen-units=1 ./rustlib.rs
16+
$(CLANG) -flto=thin -fuse-ld=lld -L $(TMPDIR) -lrustlib-xlto -o $(TMPDIR)/cmain ./cmain.c -O3
17+
# Make sure we don't find a call instruction to the function we expect to
18+
# always be inlined.
19+
"$(LLVM_BIN_DIR)"/llvm-objdump -d $(TMPDIR)/cmain | $(CGREP) -v -e "call.*rust_always_inlined"
20+
# As a sanity check, make sure we do find a call instruction to a
21+
# non-inlined function
22+
"$(LLVM_BIN_DIR)"/llvm-objdump -d $(TMPDIR)/cmain | $(CGREP) -e "call.*rust_never_inlined"
23+
24+
rust-executable:
25+
$(CLANG) ./clib.c -flto=thin -c -o $(TMPDIR)/clib.o -O2
26+
(cd $(TMPDIR); $(AR) crus ./libxyz.a ./clib.o)
27+
$(RUSTC) -Clinker-plugin-lto=on -L$(TMPDIR) -Copt-level=2 -Clinker=$(CLANG) -Clink-arg=-fuse-ld=lld ./main.rs -o $(TMPDIR)/rsmain
28+
"$(LLVM_BIN_DIR)"/llvm-objdump -d $(TMPDIR)/rsmain | $(CGREP) -e "call.*c_never_inlined"
29+
"$(LLVM_BIN_DIR)"/llvm-objdump -d $(TMPDIR)/rsmain | $(CGREP) -v -e "call.*c_always_inlined"

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)