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:
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)
This commit is contained in:
Flakebi
2025-03-28 10:15:56 +01:00
parent eed187cfce
commit 7a127fba65
11 changed files with 189 additions and 25 deletions

View File

@@ -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