From cbfe6327a1e1d4abc4df9c3394b0b96c8a9c95e3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jakub=20Ber=C3=A1nek?= Date: Sun, 3 Dec 2023 10:23:54 +0100 Subject: [PATCH] Do not invoke external lld to figure out thread flags in self-contained mode --- src/bootstrap/src/utils/helpers.rs | 31 ++++++++++++++++++++++-------- 1 file changed, 23 insertions(+), 8 deletions(-) diff --git a/src/bootstrap/src/utils/helpers.rs b/src/bootstrap/src/utils/helpers.rs index b2aa37d069177..8a818fb87ffde 100644 --- a/src/bootstrap/src/utils/helpers.rs +++ b/src/bootstrap/src/utils/helpers.rs @@ -443,17 +443,29 @@ pub fn get_clang_cl_resource_dir(clang_cl_path: &str) -> PathBuf { clang_rt_dir.to_path_buf() } -pub fn lld_flag_no_threads(is_windows: bool) -> &'static str { +/// Returns a flag that configures LLD to use only a single thread. +/// If we use an external LLD, we need to find out which version is it to know which flag should we +/// pass to it (LLD older than version 10 had a different flag). +fn lld_flag_no_threads(lld_mode: LldMode, is_windows: bool) -> &'static str { static LLD_NO_THREADS: OnceLock<(&'static str, &'static str)> = OnceLock::new(); - let (windows, other) = LLD_NO_THREADS.get_or_init(|| { - let out = output(Command::new("lld").arg("-flavor").arg("ld").arg("--version")); - let newer = match (out.find(char::is_numeric), out.find('.')) { - (Some(b), Some(e)) => out.as_str()[b..e].parse::().ok().unwrap_or(14) > 10, + + let new_flags = ("/threads:1", "--threads=1"); + let old_flags = ("/no-threads", "--no-threads"); + + let (windows_flag, other_flag) = LLD_NO_THREADS.get_or_init(|| { + let newer_version = match lld_mode { + LldMode::External => { + let out = output(Command::new("lld").arg("-flavor").arg("ld").arg("--version")); + match (out.find(char::is_numeric), out.find('.')) { + (Some(b), Some(e)) => out.as_str()[b..e].parse::().ok().unwrap_or(14) > 10, + _ => true, + } + } _ => true, }; - if newer { ("/threads:1", "--threads=1") } else { ("/no-threads", "--no-threads") } + if newer_version { new_flags } else { old_flags } }); - if is_windows { windows } else { other } + if is_windows { windows_flag } else { other_flag } } pub fn dir_is_empty(dir: &Path) -> bool { @@ -512,7 +524,10 @@ pub fn linker_flags( } if matches!(lld_threads, LldThreads::No) { - args.push(format!("-Clink-arg=-Wl,{}", lld_flag_no_threads(target.is_msvc()))); + args.push(format!( + "-Clink-arg=-Wl,{}", + lld_flag_no_threads(builder.config.lld_mode.clone(), target.is_msvc()) + )); } } args