Skip to content

Commit 418eb1d

Browse files
committed
enable rust-lld on x86_64-unknown-linux-gnu when requested
the `rust.lld` config enables rustc's `CFG_USE_SELF_CONTAINED_LINKER` env var, and we: - set the linker-flavor to use lld - enable the self-contained linker this makes the target use the rust-lld linker by default
1 parent 37d7139 commit 418eb1d

File tree

2 files changed

+13
-0
lines changed

2 files changed

+13
-0
lines changed

compiler/rustc_target/src/spec/mod.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -625,6 +625,12 @@ impl LinkSelfContainedDefault {
625625
_ => "crt-objects-fallback",
626626
}
627627
}
628+
629+
/// Creates a `LinkSelfContainedDefault` enabling the self-contained linker for target specs
630+
/// (the equivalent of `-Clink-self-contained=+linker` on the CLI).
631+
pub fn with_linker() -> LinkSelfContainedDefault {
632+
LinkSelfContainedDefault::WithComponents(LinkSelfContainedComponents::LINKER)
633+
}
628634
}
629635

630636
bitflags::bitflags! {

compiler/rustc_target/src/spec/targets/x86_64_unknown_linux_gnu.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,13 @@ pub fn target() -> Target {
1818
| SanitizerSet::THREAD;
1919
base.supports_xray = true;
2020

21+
// When we're asked to use the `rust-lld` linker by default, set the appropriate lld-using
22+
// linker flavor, and self-contained linker component.
23+
if option_env!("CFG_USE_SELF_CONTAINED_LINKER").is_some() {
24+
base.linker_flavor = LinkerFlavor::Gnu(Cc::Yes, Lld::Yes);
25+
base.link_self_contained = crate::spec::LinkSelfContainedDefault::with_linker();
26+
}
27+
2128
Target {
2229
llvm_target: "x86_64-unknown-linux-gnu".into(),
2330
metadata: crate::spec::TargetMetadata {

0 commit comments

Comments
 (0)