Skip to content

Commit 09489cc

Browse files
committed
Test thin+fat lto in cross-lang-lto-clang
Also add `.lto()` helper to `run-make-support` and use it in the added tests.
1 parent b692fa0 commit 09489cc

File tree

4 files changed

+31
-10
lines changed

4 files changed

+31
-10
lines changed

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

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -171,6 +171,12 @@ impl Rustc {
171171
self
172172
}
173173

174+
/// This flag enables LTO in the specified form.
175+
pub fn lto(&mut self, option: &str) -> &mut Self {
176+
self.cmd.arg(format!("-Clto={option}"));
177+
self
178+
}
179+
174180
/// This flag defers LTO optimizations to the linker.
175181
pub fn linker_plugin_lto(&mut self, option: &str) -> &mut Self {
176182
self.cmd.arg(format!("-Clinker-plugin-lto={option}"));

tests/run-make/cross-lang-lto-clang/rmake.rs

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -28,15 +28,23 @@ static C_NEVER_INLINED_PATTERN: &'static str = "bl.*<c_never_inlined>";
2828
static C_NEVER_INLINED_PATTERN: &'static str = "call.*c_never_inlined";
2929

3030
fn main() {
31+
test_lto("thin");
32+
test_lto("fat");
33+
}
34+
35+
fn test_lto(lto: &str) {
36+
let clang_lto = if lto == "fat" { "full" } else { lto };
37+
3138
rustc()
39+
.lto(lto)
3240
.linker_plugin_lto("on")
3341
.output(static_lib_name("rustlib-xlto"))
3442
.opt_level("2")
3543
.codegen_units(1)
3644
.input("rustlib.rs")
3745
.run();
3846
clang()
39-
.lto("thin")
47+
.lto(clang_lto)
4048
.use_ld("lld")
4149
.arg("-lrustlib-xlto")
4250
.out_exe("cmain")
@@ -57,9 +65,10 @@ fn main() {
5765
.input("cmain")
5866
.run()
5967
.assert_stdout_contains_regex(RUST_NEVER_INLINED_PATTERN);
60-
clang().input("clib.c").lto("thin").arg("-c").out_exe("clib.o").arg("-O2").run();
68+
clang().input("clib.c").lto(clang_lto).arg("-c").out_exe("clib.o").arg("-O2").run();
6169
llvm_ar().obj_to_ar().output_input(static_lib_name("xyz"), "clib.o").run();
6270
rustc()
71+
.lto(lto)
6372
.linker_plugin_lto("on")
6473
.opt_level("2")
6574
.linker(&env_var("CLANG"))
@@ -72,9 +81,12 @@ fn main() {
7281
.input("rsmain")
7382
.run()
7483
.assert_stdout_not_contains_regex(C_ALWAYS_INLINED_PATTERN);
75-
llvm_objdump()
76-
.disassemble()
77-
.input("rsmain")
78-
.run()
79-
.assert_stdout_contains_regex(C_NEVER_INLINED_PATTERN);
84+
85+
let dump = llvm_objdump().disassemble().input("rsmain").run();
86+
if lto == "thin" {
87+
dump.assert_stdout_contains_regex(C_NEVER_INLINED_PATTERN);
88+
} else {
89+
// fat lto inlines this anyway
90+
dump.assert_stdout_not_contains_regex(C_NEVER_INLINED_PATTERN);
91+
}
8092
}

tests/run-make/fat-then-thin-lto/rmake.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@
88
use run_make_support::{dynamic_lib_name, llvm_objdump, rustc};
99

1010
fn main() {
11-
rustc().input("lib.rs").opt_level("3").arg("-Clto=fat").run();
12-
rustc().input("main.rs").panic("abort").opt_level("3").arg("-Clto=thin").run();
11+
rustc().input("lib.rs").opt_level("3").lto("fat").run();
12+
rustc().input("main.rs").panic("abort").opt_level("3").lto("thin").run();
1313

1414
llvm_objdump()
1515
.input(dynamic_lib_name("main"))

tests/run-make/linker-plugin-lto-fat/rmake.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,10 @@ fn main() {
1313
rustc()
1414
.input("main.rs")
1515
.opt_level("3")
16-
.args(&["-Clto=fat", "-Clinker-plugin-lto", "-Zlinker-features=+lld", "-Clink-arg=ir.bc"])
16+
.lto("fat")
17+
.linker_plugin_lto("on")
18+
.link_arg("ir.bc")
19+
.arg("-Zlinker-features=+lld")
1720
.run();
1821

1922
llvm_objdump()

0 commit comments

Comments
 (0)