diff options
| author | Flakebi <flakebi@t-online.de> | 2025-03-28 10:15:56 +0100 |
|---|---|---|
| committer | Flakebi <flakebi@t-online.de> | 2025-07-31 10:38:34 +0200 |
| commit | 7a127fba657ed627cc4877f2871abaf7d9819caa (patch) | |
| tree | 9a3b22e4a1cda02755b35525c7c52f996d57a8ed /compiler | |
| parent | eed187cfce988dd669b7d9161f324433e64358ee (diff) | |
| download | rust-7a127fba657ed627cc4877f2871abaf7d9819caa.tar.gz rust-7a127fba657ed627cc4877f2871abaf7d9819caa.zip | |
Fix linker-plugin-lto only doing thin lto
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: https://github.com/llvm/llvm-project/blob/560149b5e3c891c64899e9912e29467a69dc3a4c/clang/lib/CodeGen/BackendUtil.cpp#L1150 The code in LLVM that queries the flag and defaults to thin lto if not set is here: https://github.com/llvm/llvm-project/blob/e258bca9505f35e0a22cb213a305eea9b76d11ea/llvm/lib/Bitcode/Writer/BitcodeWriter.cpp#L4441-L4446
Diffstat (limited to 'compiler')
| -rw-r--r-- | compiler/rustc_codegen_ssa/src/back/write.rs | 4 |
1 files changed, 3 insertions, 1 deletions
diff --git a/compiler/rustc_codegen_ssa/src/back/write.rs b/compiler/rustc_codegen_ssa/src/back/write.rs index 7be274df1d4..0394ddf2bee 100644 --- a/compiler/rustc_codegen_ssa/src/back/write.rs +++ b/compiler/rustc_codegen_ssa/src/back/write.rs @@ -215,7 +215,9 @@ impl ModuleConfig { false ), emit_obj, - emit_thin_lto: sess.opts.unstable_opts.emit_thin_lto, + // thin lto summaries prevent fat lto, so do not emit them if fat + // lto is requested. See PR #136840 for background information. + emit_thin_lto: sess.opts.unstable_opts.emit_thin_lto && sess.lto() != Lto::Fat, emit_thin_lto_summary: if_regular!( sess.opts.output_types.contains_key(&OutputType::ThinLinkBitcode), false |
