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
@@ -16,14 +16,12 @@ use std::{env, fs};
 #[cfg(feature = "tracing")]
 use tracing::instrument;

-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, StepMetadata, cargo_profile_var,
-};
-use crate::core::config::{DebuginfoLevel, RustcLto, TargetSelection};
+
+use crate::core::builder::{Builder, Cargo as CargoCommand, RunConfig, ShouldRun, Step, StepMetadata};
+use crate::core::config::{DebuginfoLevel, TargetSelection};
 use crate::utils::exec::{BootstrapCommand, command};
 use crate::utils::helpers::{add_dylib_path, exe, t};
 use crate::{Compiler, FileType, Kind, Mode, gha};
@@ -160,20 +158,7 @@ impl Step for ToolBuild {
             cargo.env("RUSTC_WRAPPER", ccache);
         }

-        // Rustc tools (miri, clippy, cargo, rustfmt, rust-analyzer)
-        // could use the additional optimizations.
-        if self.mode == Mode::ToolRustc && is_lto_stage(&self.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");
         if !self.allow_features.is_empty() {
             cargo.allow_features(self.allow_features);
         }
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
@@ -13,7 +13,7 @@
 #[cfg(feature = "tracing")]
 use tracing::instrument;
 
-pub use self::cargo::{Cargo, cargo_profile_var};
+pub use self::cargo::Cargo;
 pub use crate::Compiler;
 use crate::core::build_steps::compile::{Std, StdLink};
 use crate::core::build_steps::{
