From ce68809d41291f671b440abce41f8f71c95428aa Mon Sep 17 00:00:00 2001
From: Alexander Kanavin <alex@linutronix.de>
Date: Mon, 3 Feb 2025 20:06:46 +0100
Subject: [PATCH] src/core/build_steps/tool.rs: switch off lto for rustdoc

For reasons currently unknown, librustdoc binary ends up with
non-reproducible .llvm.<number> suffixes in its symbols - but
not any other binary.

Disabling lto avoids creating these suffixes. More info about the option:
https://doc.rust-lang.org/rustc/codegen-options/index.html#lto

As seen below, there's a comment in the source tree saying not to tweak the options
but this only creates a mix of lto and non-lto optimized binary objects from
various crates, which should be safe to mix.

Upstream-Status: Inappropriate [reported at https://github.com/rust-lang/rust/issues/134589]
Signed-off-by: Alexander Kanavin <alex@linutronix.de>
---
 src/bootstrap/src/core/build_steps/tool.rs | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/src/bootstrap/src/core/build_steps/tool.rs b/src/bootstrap/src/core/build_steps/tool.rs
index 087df2f8a..00790affb 100644
--- a/src/bootstrap/src/core/build_steps/tool.rs
+++ b/src/bootstrap/src/core/build_steps/tool.rs
@@ -1,14 +1,11 @@
 use std::path::PathBuf;
 use std::{env, fs};
 
-use crate::core::build_steps::compile::is_lto_stage;
 use crate::core::build_steps::toolstate::ToolState;
 use crate::core::build_steps::{compile, llvm};
 use crate::core::builder;
-use crate::core::builder::{
-    Builder, Cargo as CargoCommand, RunConfig, ShouldRun, Step, cargo_profile_var,
-};
-use crate::core::config::{DebuginfoLevel, RustcLto, TargetSelection};
+use crate::core::builder::{Builder, Cargo as CargoCommand, RunConfig, ShouldRun, Step};
+use crate::core::config::{DebuginfoLevel, TargetSelection};
 use crate::utils::channel::GitInfo;
 use crate::utils::exec::{BootstrapCommand, command};
 use crate::utils::helpers::{add_dylib_path, exe, t};
@@ -658,19 +655,7 @@
             SourceType::InTree,
             features.as_slice(),
         );
-
-        // rustdoc is performance sensitive, so apply LTO to it.
-        if is_lto_stage(&build_compiler) {
-            let lto = match builder.config.rust_lto {
-                RustcLto::Off => Some("off"),
-                RustcLto::Thin => Some("thin"),
-                RustcLto::Fat => Some("fat"),
-                RustcLto::ThinLocal => None,
-            };
-            if let Some(lto) = lto {
-                cargo.env(cargo_profile_var("LTO", &builder.config), lto);
-            }
-        }
+        cargo.rustflag("-Clto=off");
 
         let _guard = builder.msg_tool(
             Kind::Build,
diff --git a/src/bootstrap/src/core/builder/mod.rs b/src/bootstrap/src/core/builder/mod.rs
--- a/src/bootstrap/src/core/builder/mod.rs
+++ b/src/bootstrap/src/core/builder/mod.rs
@@ -11,7 +11,7 @@
 
 use clap::ValueEnum;
 
-pub use self::cargo::{Cargo, cargo_profile_var};
+pub use self::cargo::Cargo;
 pub use crate::Compiler;
 use crate::core::build_steps::{
     check, clean, clippy, compile, dist, doc, gcc, install, llvm, run, setup, test, tool, vendor,
