@@ -1369,8 +1369,29 @@ pub fn linker_and_flavor(sess: &Session) -> (PathBuf, LinkerFlavor) {
1369
1369
"cc"
1370
1370
}
1371
1371
}
1372
- LinkerFlavor :: Gnu ( _, Lld :: Yes )
1373
- | LinkerFlavor :: Darwin ( _, Lld :: Yes )
1372
+ LinkerFlavor :: Gnu ( _, Lld :: Yes ) => {
1373
+ // Here, we're asked to use lld without a linker driver, so we'll check
1374
+ // whether the self-contained linker is enabled on the CLI or explicitly by
1375
+ // the target, to launch `rust-lld` instead of the system `lld`.
1376
+ let self_contained_cli = & sess. opts . cg . link_self_contained ;
1377
+ let self_contained_target = match sess. target . link_self_contained {
1378
+ LinkSelfContainedDefault :: WithComponents ( components) => {
1379
+ components. is_linker_enabled ( )
1380
+ }
1381
+ _ => {
1382
+ // We don't try to infer whether the self-contained linker component
1383
+ // is enabled: on some targets (mingw), the component inference
1384
+ // actually uses the linker to compute whether self-contained
1385
+ // linking is enabled, but we're computing the linker to use here.
1386
+ false
1387
+ }
1388
+ } ;
1389
+ let self_contained_linker = ( self_contained_cli. is_linker_enabled ( )
1390
+ || self_contained_target)
1391
+ && !self_contained_cli. is_linker_disabled ( ) ;
1392
+ if self_contained_linker { "rust-lld" } else { "lld" }
1393
+ }
1394
+ LinkerFlavor :: Darwin ( _, Lld :: Yes )
1374
1395
| LinkerFlavor :: WasmLld ( ..)
1375
1396
| LinkerFlavor :: Msvc ( Lld :: Yes ) => "lld" ,
1376
1397
LinkerFlavor :: Gnu ( ..) | LinkerFlavor :: Darwin ( ..) | LinkerFlavor :: Unix ( ..) => {
0 commit comments