@@ -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- pub fn lld_flag_no_threads ( is_windows : bool ) -> & ' static str {
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+ fn lld_flag_no_threads ( lld_mode : LldMode , is_windows : bool ) -> & ' static str {
447450 static LLD_NO_THREADS : OnceLock < ( & ' static str , & ' static str ) > = 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- if newer { ( "/threads:1" , "--threads=1" ) } else { ( "/no-threads" , "--no-threads" ) }
466+ if newer_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
459471pub fn dir_is_empty ( dir : & Path ) -> bool {
@@ -512,7 +524,10 @@ pub fn linker_flags(
512524 }
513525
514526 if matches ! ( 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