diff options
| author | Jakub Beránek <berykubik@gmail.com> | 2023-12-03 10:23:54 +0100 |
|---|---|---|
| committer | Jakub Beránek <berykubik@gmail.com> | 2023-12-10 11:21:35 +0100 |
| commit | cbfe6327a1e1d4abc4df9c3394b0b96c8a9c95e3 (patch) | |
| tree | e72ef5e0cb40ec1ab74d03d28e6513b1352346f3 /src/bootstrap | |
| parent | 50865745e1aa3b6af6fe98d121ba68516fcce669 (diff) | |
| download | rust-cbfe6327a1e1d4abc4df9c3394b0b96c8a9c95e3.tar.gz rust-cbfe6327a1e1d4abc4df9c3394b0b96c8a9c95e3.zip | |
Do not invoke external lld to figure out thread flags in self-contained mode
Diffstat (limited to 'src/bootstrap')
| -rw-r--r-- | src/bootstrap/src/utils/helpers.rs | 31 |
1 files changed, 23 insertions, 8 deletions
diff --git a/src/bootstrap/src/utils/helpers.rs b/src/bootstrap/src/utils/helpers.rs index b2aa37d0691..8a818fb87ff 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::<i32>().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::<i32>().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 |
