Skip to content

Commit b5b0282

Browse files
committed
Fix rebase and fix test
In CI, the cross-lang-lto-clang passed on x86_64 but not on aarch64. I don’t have a good way to debug this, but with some local changes (my clang to cross-compiling to aarch64 uses different target features, so nothing gets inlined by default; and I wasn’t able to link a rust std for aarch64), I think I found the culprit. With fat lto on aarch64, the inline(never) rust function gets inlined. This is the same behavior as with linking a C library into a Rust binary, just that it’s different between aarch64 and x86 (fat lto on x86 inlines the noinline C function into the Rust binary but it does not inline the inline(never) Rust function into the C binary).
1 parent ac274ce commit b5b0282

File tree

5 files changed

+32
-19
lines changed

5 files changed

+32
-19
lines changed

src/tools/run-make-support/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ pub use crate::external_deps::clang::{Clang, clang};
6363
pub use crate::external_deps::htmldocck::htmldocck;
6464
pub use crate::external_deps::llvm::{
6565
self, LlvmAr, LlvmBcanalyzer, LlvmDis, LlvmDwarfdump, LlvmFilecheck, LlvmNm, LlvmObjcopy,
66-
LlvmObjdump, LlvmProfdata, LlvmReadobj, llvm_ar, llvm_bcanalyzer, llvm_dis, llvm_dwarfdump,
66+
LlvmObjdump, LlvmProfdata, LlvmReadobj, llvm_ar, llvm_as, llvm_bcanalyzer, llvm_dis, llvm_dwarfdump,
6767
llvm_filecheck, llvm_nm, llvm_objcopy, llvm_objdump, llvm_profdata, llvm_readobj,
6868
};
6969
pub use crate::external_deps::python::python_command;

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

Lines changed: 17 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ fn main() {
3535
fn test_lto(fat_lto: bool) {
3636
let lto = if fat_lto { "fat" } else { "thin" };
3737
let clang_lto = if fat_lto { "full" } else { "thin" };
38+
println!("Running {lto} lto");
3839

3940
rustc()
4041
.lto(lto)
@@ -52,20 +53,25 @@ fn test_lto(fat_lto: bool) {
5253
.input("cmain.c")
5354
.arg("-O3")
5455
.run();
56+
57+
let dump = llvm_objdump().disassemble().input("cmain").run();
5558
// Make sure we don't find a call instruction to the function we expect to
5659
// always be inlined.
57-
llvm_objdump()
58-
.disassemble()
59-
.input("cmain")
60-
.run()
61-
.assert_stdout_not_contains_regex(RUST_ALWAYS_INLINED_PATTERN);
60+
dump.assert_stdout_not_contains_regex(RUST_ALWAYS_INLINED_PATTERN);
6261
// As a sanity check, make sure we do find a call instruction to a
6362
// non-inlined function
64-
llvm_objdump()
65-
.disassemble()
66-
.input("cmain")
67-
.run()
68-
.assert_stdout_contains_regex(RUST_NEVER_INLINED_PATTERN);
63+
#[cfg(any(target_arch = "x86", target_arch = "x86_64"))]
64+
dump.assert_stdout_contains_regex(RUST_NEVER_INLINED_PATTERN);
65+
#[cfg(any(target_arch = "aarch64", target_arch = "arm"))]
66+
{
67+
if !fat_lto {
68+
dump.assert_stdout_contains_regex(RUST_NEVER_INLINED_PATTERN);
69+
} else {
70+
// fat lto inlines this anyway
71+
dump.assert_stdout_not_contains_regex(RUST_NEVER_INLINED_PATTERN);
72+
}
73+
}
74+
6975
clang().input("clib.c").lto(clang_lto).arg("-c").out_exe("clib.o").arg("-O2").run();
7076
llvm_ar().obj_to_ar().output_input(static_lib_name("xyz"), "clib.o").run();
7177
rustc()
@@ -77,13 +83,9 @@ fn test_lto(fat_lto: bool) {
7783
.input("main.rs")
7884
.output("rsmain")
7985
.run();
80-
llvm_objdump()
81-
.disassemble()
82-
.input("rsmain")
83-
.run()
84-
.assert_stdout_not_contains_regex(C_ALWAYS_INLINED_PATTERN);
8586

8687
let dump = llvm_objdump().disassemble().input("rsmain").run();
88+
dump.assert_stdout_not_contains_regex(C_ALWAYS_INLINED_PATTERN);
8789
if !fat_lto {
8890
dump.assert_stdout_contains_regex(C_NEVER_INLINED_PATTERN);
8991
} else {
Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,13 @@
1+
#![allow(internal_features)]
12
#![feature(no_core, lang_items)]
23
#![no_core]
34
#![crate_type = "rlib"]
45

6+
#[lang = "pointee_sized"]
7+
trait PointeeSized {}
8+
#[lang = "meta_sized"]
9+
trait MetaSized: PointeeSized {}
510
#[lang = "sized"]
6-
trait Sized {}
11+
trait Sized: MetaSized {}
712

813
pub fn foo() {}

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

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,14 @@
1+
#![allow(internal_features)]
12
#![feature(no_core, lang_items)]
23
#![no_core]
34
#![crate_type = "cdylib"]
45

6+
#[lang = "pointee_sized"]
7+
trait PointeeSized {}
8+
#[lang = "meta_sized"]
9+
trait MetaSized: PointeeSized {}
510
#[lang = "sized"]
6-
trait Sized {}
11+
trait Sized: MetaSized {}
712

813
extern "C" {
914
fn ir_callee();

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,8 @@ fn main() {
1616
.lto("fat")
1717
.linker_plugin_lto("on")
1818
.link_arg("ir.bc")
19-
.arg("-Zlinker-features=+lld")
19+
.arg("-Zunstable-options")
20+
.arg("-Clinker-features=+lld")
2021
.run();
2122

2223
llvm_objdump()

0 commit comments

Comments
 (0)