When rust provides LLVM bitcode files to lld and the bitcode contains function summaries as used for thin lto, lld defaults to using thin lto. This prevents some optimizations that are only applied for fat lto. We solve this by not creating function summaries when fat lto is enabled. The bitcode for the module is just directly written out. An alternative solution would be to set the `ThinLTO=0` module flag to signal lld to do fat lto. The code in clang that sets this flag is here:560149b5e3/clang/lib/CodeGen/BackendUtil.cpp (L1150)The code in LLVM that queries the flag and defaults to thin lto if not set is here:e258bca950/llvm/lib/Bitcode/Writer/BitcodeWriter.cpp (L4441-L4446)
34 lines
1.1 KiB
Rust
34 lines
1.1 KiB
Rust
// Check that -C lto=fat with -C linker-plugin-lto actually works and can inline functions.
|
|
// A library is created from LLVM IR, defining a single function. Then a dylib is compiled,
|
|
// linking to the library and calling the function from the library.
|
|
// The function from the library should end up inlined and disappear from the output.
|
|
|
|
//@ only-x86_64-unknown-linux-gnu
|
|
//@ needs-rust-lld
|
|
|
|
use run_make_support::{dynamic_lib_name, llvm_as, llvm_objdump, rustc};
|
|
|
|
fn main() {
|
|
llvm_as().input("ir.ll").run();
|
|
rustc()
|
|
.input("main.rs")
|
|
.opt_level("3")
|
|
.lto("fat")
|
|
.linker_plugin_lto("on")
|
|
.link_arg("ir.bc")
|
|
.arg("-Zunstable-options")
|
|
.arg("-Clinker-features=+lld")
|
|
.run();
|
|
|
|
llvm_objdump()
|
|
.input(dynamic_lib_name("main"))
|
|
.arg("--disassemble-symbols=rs_foo")
|
|
.run()
|
|
// The called function should be inlined.
|
|
// Check that we have a ret (to detect tail
|
|
// calls with a jmp) and no call.
|
|
.assert_stdout_contains("foo")
|
|
.assert_stdout_contains("ret")
|
|
.assert_stdout_not_contains("call");
|
|
}
|