Skip to content
This repository was archived by the owner on May 28, 2025. It is now read-only.

Commit feff72b

Browse files
committed
support self-contained linker for ld.lld linker flavor
1 parent e964cca commit feff72b

File tree

1 file changed

+23
-2
lines changed
  • compiler/rustc_codegen_ssa/src/back

1 file changed

+23
-2
lines changed

compiler/rustc_codegen_ssa/src/back/link.rs

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1369,8 +1369,29 @@ pub fn linker_and_flavor(sess: &Session) -> (PathBuf, LinkerFlavor) {
13691369
"cc"
13701370
}
13711371
}
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)
13741395
| LinkerFlavor::WasmLld(..)
13751396
| LinkerFlavor::Msvc(Lld::Yes) => "lld",
13761397
LinkerFlavor::Gnu(..) | LinkerFlavor::Darwin(..) | LinkerFlavor::Unix(..) => {

0 commit comments

Comments
 (0)