From 15e839e00604815898e16ec25835ef9b33bb5205 Mon Sep 17 00:00:00 2001 From: bjorn3 <17426603+bjorn3@users.noreply.github.com> Date: Fri, 6 Mar 2026 15:22:17 +0000 Subject: [PATCH] Fallback to fat LTO for -Clto=thin in cg_gcc Fallback to no LTO doesn't work in practice as Cargo asks rustc to produce LTO-only rlibs with -Clinker-plugin-lto without providing any indication if they will be used for thin or fat LTO, so we can't disable -Clinker-plugin-lto for ThinLTO when using cg_gcc. --- compiler/rustc_session/src/errors.rs | 2 +- compiler/rustc_session/src/session.rs | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/compiler/rustc_session/src/errors.rs b/compiler/rustc_session/src/errors.rs index 219ec5c51279e..cb3f7363957ef 100644 --- a/compiler/rustc_session/src/errors.rs +++ b/compiler/rustc_session/src/errors.rs @@ -539,5 +539,5 @@ pub(crate) struct UnexpectedBuiltinCfg { } #[derive(Diagnostic)] -#[diag("ThinLTO is not supported by the codegen backend")] +#[diag("ThinLTO is not supported by the codegen backend, using fat LTO instead")] pub(crate) struct ThinLtoNotSupportedByBackend; diff --git a/compiler/rustc_session/src/session.rs b/compiler/rustc_session/src/session.rs index 30840a4872733..0548380331bef 100644 --- a/compiler/rustc_session/src/session.rs +++ b/compiler/rustc_session/src/session.rs @@ -620,9 +620,9 @@ impl Session { config::LtoCli::Thin => { // The user explicitly asked for ThinLTO if !self.thin_lto_supported { - // Backend doesn't support ThinLTO, disable LTO. + // Backend doesn't support ThinLTO, fallback to fat LTO. self.dcx().emit_warn(errors::ThinLtoNotSupportedByBackend); - return config::Lto::No; + return config::Lto::Fat; } return config::Lto::Thin; }