Skip to content

Commit

Permalink
enable rust-lld on x86_64-unknown-linux-gnu when requested
Browse files Browse the repository at this point in the history
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
  • Loading branch information
lqd committed May 16, 2024
1 parent 5f04f6d commit 7695e5a
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 0 deletions.
6 changes: 6 additions & 0 deletions compiler/rustc_target/src/spec/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -612,6 +612,12 @@ impl LinkSelfContainedDefault {
_ => "crt-objects-fallback",
}
}

/// Creates a `LinkSelfContainedDefault` enabling the self-contained linker for target specs
/// (the equivalent of `-Clink-self-contained=+linker` on the CLI).
pub fn with_linker() -> LinkSelfContainedDefault {
LinkSelfContainedDefault::WithComponents(LinkSelfContainedComponents::LINKER)
}
}

bitflags::bitflags! {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,13 @@ pub fn target() -> Target {
| SanitizerSet::THREAD;
base.supports_xray = true;

// When we're asked to use the `rust-lld` linker by default, set the appropriate lld-using
// linker flavor, and self-contained linker component.
if option_env!("CFG_USE_SELF_CONTAINED_LINKER").is_some() {
base.linker_flavor = LinkerFlavor::Gnu(Cc::Yes, Lld::Yes);
base.link_self_contained = crate::spec::LinkSelfContainedDefault::with_linker();
}

Target {
llvm_target: "x86_64-unknown-linux-gnu".into(),
metadata: crate::spec::TargetMetadata {
Expand Down

0 comments on commit 7695e5a

Please sign in to comment.