Skip to content

Commit cbfe632

Browse files
committed
Do not invoke external lld to figure out thread flags in self-contained mode
1 parent 5086574 commit cbfe632

1 file changed

Lines changed: 23 additions & 8 deletions

File tree

‎src/bootstrap/src/utils/helpers.rs‎

Lines changed: 23 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -443,17 +443,29 @@ pub fn get_clang_cl_resource_dir(clang_cl_path: &str) -> PathBuf {
443443
clang_rt_dir.to_path_buf()
444444
}
445445

446-
pubfnlld_flag_no_threads(is_windows:bool) -> &'staticstr{
446+
/// Returns a flag that configures LLD to use only a single thread.
447+
/// If we use an external LLD, we need to find out which version is it to know which flag should we
448+
/// pass to it (LLD older than version 10 had a different flag).
449+
fnlld_flag_no_threads(lld_mode:LldMode,is_windows:bool) -> &'staticstr{
447450
staticLLD_NO_THREADS:OnceLock<(&'staticstr,&'staticstr)> = OnceLock::new();
448-
let(windows, other) = LLD_NO_THREADS.get_or_init(|| {
449-
let out = output(Command::new("lld").arg("-flavor").arg("ld").arg("--version"));
450-
let newer = match(out.find(char::is_numeric), out.find('.')){
451-
(Some(b),Some(e)) => out.as_str()[b..e].parse::<i32>().ok().unwrap_or(14) > 10,
451+
452+
let new_flags = ("/threads:1","--threads=1");
453+
let old_flags = ("/no-threads","--no-threads");
454+
455+
let(windows_flag, other_flag) = LLD_NO_THREADS.get_or_init(|| {
456+
let newer_version = match lld_mode {
457+
LldMode::External => {
458+
let out = output(Command::new("lld").arg("-flavor").arg("ld").arg("--version"));
459+
match(out.find(char::is_numeric), out.find('.')){
460+
(Some(b),Some(e)) => out.as_str()[b..e].parse::<i32>().ok().unwrap_or(14) > 10,
461+
_ => true,
462+
}
463+
}
452464
_ => true,
453465
};
454-
ifnewer{("/threads:1","--threads=1")}else{("/no-threads","--no-threads")}
466+
ifnewer_version{new_flags }else{old_flags}
455467
});
456-
if is_windows {windows}else{other}
468+
if is_windows {windows_flag}else{other_flag}
457469
}
458470

459471
pubfndir_is_empty(dir:&Path) -> bool{
@@ -512,7 +524,10 @@ pub fn linker_flags(
512524
}
513525

514526
ifmatches!(lld_threads,LldThreads::No){
515-
args.push(format!("-Clink-arg=-Wl,{}", lld_flag_no_threads(target.is_msvc())));
527+
args.push(format!(
528+
"-Clink-arg=-Wl,{}",
529+
lld_flag_no_threads(builder.config.lld_mode.clone(), target.is_msvc())
530+
));
516531
}
517532
}
518533
args

0 commit comments

Comments
 (0)