@@ -34,7 +34,7 @@ use filetime::FileTime;
34
34
use once_cell:: sync:: OnceCell ;
35
35
36
36
use crate :: builder:: Kind ;
37
- use crate :: config:: { LldMode , LlvmLibunwind , TargetSelection } ;
37
+ use crate :: config:: { LlvmLibunwind , TargetSelection } ;
38
38
use crate :: util:: {
39
39
dir_is_empty, exe, libdir, mtime, output, run, run_suppressed, symlink_dir, try_run_suppressed,
40
40
} ;
@@ -90,6 +90,7 @@ mod job {
90
90
pub use crate :: builder:: PathSet ;
91
91
use crate :: cache:: { Interned , INTERNER } ;
92
92
pub use crate :: config:: Config ;
93
+ pub use crate :: config:: LldMode ;
93
94
pub use crate :: flags:: Subcommand ;
94
95
use termcolor:: { ColorChoice , StandardStream , WriteColor } ;
95
96
@@ -1281,29 +1282,11 @@ impl Build {
1281
1282
target. is_msvc ( )
1282
1283
}
1283
1284
1284
- // Returns the gcc-ld directory of the snapshot compiler's rust-lld.
1285
- fn initial_lld_root ( & self ) -> PathBuf {
1286
- let mut rust_lld_path = self . initial_lld . clone ( ) ;
1287
- rust_lld_path. pop ( ) ;
1288
- rust_lld_path. join ( "gcc-ld" )
1289
- }
1290
-
1291
1285
fn lld_flags ( & self , target : TargetSelection , test : bool ) -> Vec < String > {
1292
1286
let mut flags = vec ! [ ] ;
1293
1287
1294
1288
if !self . is_lld_direct_linker ( target) {
1295
- match self . config . lld_mode {
1296
- LldMode :: SelfContained => {
1297
- // FIXME: replace with MCP510 (-Clinker-flavor + -Clink-self-contained)
1298
- // once gcc-ld is available in stage0-sysroot.
1299
- flags. push ( "-Clink-arg=-fuse-ld=lld" . to_string ( ) ) ;
1300
- flags. push ( format ! ( "-Clink-arg=-B{}" , self . initial_lld_root( ) . display( ) ) ) ;
1301
- }
1302
- LldMode :: External => {
1303
- flags. push ( "-Clink-arg=-fuse-ld=lld" . to_string ( ) ) ;
1304
- }
1305
- LldMode :: Unused => { }
1306
- } ;
1289
+ flags. extend ( get_lld_flags ( & self . config . lld_mode ) ) ;
1307
1290
}
1308
1291
1309
1292
// For tests, we want to disable multi-threading.
@@ -1322,7 +1305,16 @@ impl Build {
1322
1305
/// and lld version.
1323
1306
fn lld_single_thread_flag ( & self , target : TargetSelection ) -> & ' static str {
1324
1307
let new_flags = if let LldMode :: External = self . config . lld_mode {
1325
- util:: is_lld_newer_than_10 ( )
1308
+ // Finds out if the LLD is newer than LLD 10
1309
+ static LLD_NO_THREADS : OnceCell < bool > = OnceCell :: new ( ) ;
1310
+ * LLD_NO_THREADS . get_or_init ( || {
1311
+ let out = output ( Command :: new ( "lld" ) . arg ( "-flavor" ) . arg ( "ld" ) . arg ( "--version" ) ) ;
1312
+ let newer = match ( out. find ( char:: is_numeric) , out. find ( '.' ) ) {
1313
+ ( Some ( b) , Some ( e) ) => out. as_str ( ) [ b..e] . parse :: < i32 > ( ) . ok ( ) . unwrap_or ( 14 ) > 10 ,
1314
+ _ => true ,
1315
+ } ;
1316
+ newer
1317
+ } )
1326
1318
} else {
1327
1319
true
1328
1320
} ;
@@ -1910,3 +1902,18 @@ pub fn find_recent_config_change_ids(current_id: usize) -> Vec<usize> {
1910
1902
. cloned ( )
1911
1903
. collect ( )
1912
1904
}
1905
+
1906
+ pub fn get_lld_flags ( lld_mode : & LldMode ) -> Vec < String > {
1907
+ let mut flags = vec ! [ ] ;
1908
+ match lld_mode {
1909
+ LldMode :: SelfContained => {
1910
+ flags. push ( "-Clinker-flavor=gnu-lld-cc" . to_string ( ) ) ;
1911
+ flags. push ( "-Clink-self-contained=+linker" . to_string ( ) ) ;
1912
+ }
1913
+ LldMode :: External => {
1914
+ flags. push ( "-Clinker-flavor=gnu-lld-cc" . to_string ( ) ) ;
1915
+ }
1916
+ LldMode :: Unused => { }
1917
+ } ;
1918
+ flags
1919
+ }
0 commit comments