From 199d2d4615ffb207ba6a5a4664800e63e6076f21 Mon Sep 17 00:00:00 2001 From: Mark Rousskov Date: Sat, 30 Aug 2025 14:06:06 -0400 Subject: [PATCH] Use absolute path to llvm-bolt, merge-fdata rather than PATH This unconditionally uses the provided LLVM toolchain's BOLT. I'm not sure that makes sense, but since we don't build BOLT as part of Rust's build of LLVM today, it's probably the right option for now. This avoids breaking the build on not being able to find the llvm-bolt executable. --- src/tools/opt-dist/src/bolt.rs | 5 +++-- src/tools/opt-dist/src/environment.rs | 8 ++++++++ src/tools/opt-dist/src/main.rs | 4 ++-- src/tools/opt-dist/src/training.rs | 3 ++- 4 files changed, 15 insertions(+), 5 deletions(-) diff --git a/src/tools/opt-dist/src/bolt.rs b/src/tools/opt-dist/src/bolt.rs index a06e59fcc412c..3ee9912b8c26d 100644 --- a/src/tools/opt-dist/src/bolt.rs +++ b/src/tools/opt-dist/src/bolt.rs @@ -9,6 +9,7 @@ use crate::utils::io::copy_file; /// Instruments an artifact at the given `path` (in-place) with BOLT and then calls `func`. /// After this function finishes, the original file will be restored. pub fn with_bolt_instrumented anyhow::Result, R>( + env: &Environment, path: &Utf8Path, func: F, ) -> anyhow::Result { @@ -26,7 +27,7 @@ pub fn with_bolt_instrumented anyhow::Result, R>( let profile_prefix = Utf8Path::from_path(&profile_prefix).unwrap(); // Instrument the original file with BOLT, saving the result into `instrumented_path` - cmd(&["llvm-bolt"]) + cmd(&[env.llvm_bolt().as_str()]) .arg("-instrument") .arg(path) .arg(&format!("--instrumentation-file={profile_prefix}")) @@ -61,7 +62,7 @@ pub fn bolt_optimize( let split_strategy = if env.host_tuple().starts_with("aarch64") { "profile2" } else { "cdsplit" }; - cmd(&["llvm-bolt"]) + cmd(&[env.llvm_bolt().as_str()]) .arg(temp_path.display()) .arg("-data") .arg(&profile.0) diff --git a/src/tools/opt-dist/src/environment.rs b/src/tools/opt-dist/src/environment.rs index 2cae0785f33bf..7cc51901a83c0 100644 --- a/src/tools/opt-dist/src/environment.rs +++ b/src/tools/opt-dist/src/environment.rs @@ -116,6 +116,14 @@ impl Environment { pub fn stage0(&self) -> Utf8PathBuf { self.stage0_root.clone().unwrap_or_else(|| self.build_artifacts().join("stage0")) } + + pub fn llvm_bolt(&self) -> Utf8PathBuf { + self.host_llvm_dir().join(format!("bin/llvm-bolt{}", executable_extension())) + } + + pub fn merge_fdata(&self) -> Utf8PathBuf { + self.host_llvm_dir().join(format!("bin/merge-fdata{}", executable_extension())) + } } /// What is the extension of binary executables on this platform? diff --git a/src/tools/opt-dist/src/main.rs b/src/tools/opt-dist/src/main.rs index 339c25552adad..48b25f235dd6a 100644 --- a/src/tools/opt-dist/src/main.rs +++ b/src/tools/opt-dist/src/main.rs @@ -329,7 +329,7 @@ fn execute_pipeline( // FIXME(kobzol): try gather profiles together, at once for LLVM and rustc // Instrument the libraries and gather profiles - let llvm_profile = with_bolt_instrumented(&llvm_lib, |llvm_profile_dir| { + let llvm_profile = with_bolt_instrumented(env, &llvm_lib, |llvm_profile_dir| { stage.section("Gather profiles", |_| { gather_bolt_profiles(env, "LLVM", llvm_benchmarks(env), llvm_profile_dir) }) @@ -354,7 +354,7 @@ fn execute_pipeline( log::info!("Optimizing {rustc_lib} with BOLT"); // Instrument it and gather profiles - let rustc_profile = with_bolt_instrumented(&rustc_lib, |rustc_profile_dir| { + let rustc_profile = with_bolt_instrumented(env, &rustc_lib, |rustc_profile_dir| { stage.section("Gather profiles", |_| { gather_bolt_profiles(env, "rustc", rustc_benchmarks(env), rustc_profile_dir) }) diff --git a/src/tools/opt-dist/src/training.rs b/src/tools/opt-dist/src/training.rs index ae062d5c60c66..4f9352d11b12c 100644 --- a/src/tools/opt-dist/src/training.rs +++ b/src/tools/opt-dist/src/training.rs @@ -195,7 +195,8 @@ pub fn gather_bolt_profiles( let profiles: Vec<_> = glob::glob(&format!("{profile_prefix}*"))?.collect::, _>>()?; - let mut merge_args = vec!["merge-fdata"]; + let fdata = env.merge_fdata(); + let mut merge_args = vec![fdata.as_str()]; merge_args.extend(profiles.iter().map(|p| p.to_str().unwrap())); with_log_group("Merging BOLT profiles", || {