diff --git a/compiler/rustc_target/src/spec/mod.rs b/compiler/rustc_target/src/spec/mod.rs index 9c99c5bf7b399..6dc2ba60e5257 100644 --- a/compiler/rustc_target/src/spec/mod.rs +++ b/compiler/rustc_target/src/spec/mod.rs @@ -619,6 +619,12 @@ impl LinkSelfContained { _ => "crt-objects-fallback", } } + + /// Creates a `LinkSelfContained` enabling the self-contained linker for target specs (the + /// equivalent of `-Clink-self-contained=+linker` on the CLI). + pub(crate) fn with_linker() -> LinkSelfContained { + LinkSelfContained::WithComponents(LinkSelfContainedComponents::LINKER) + } } impl From for LinkSelfContained { diff --git a/compiler/rustc_target/src/spec/x86_64_unknown_linux_gnu.rs b/compiler/rustc_target/src/spec/x86_64_unknown_linux_gnu.rs index 2f970f87cc642..bdfd1c2a4a102 100644 --- a/compiler/rustc_target/src/spec/x86_64_unknown_linux_gnu.rs +++ b/compiler/rustc_target/src/spec/x86_64_unknown_linux_gnu.rs @@ -1,3 +1,4 @@ +use crate::spec::LinkSelfContained; use crate::spec::{Cc, LinkerFlavor, Lld, SanitizerSet, StackProbeType, Target}; pub fn target() -> Target { @@ -5,6 +6,8 @@ pub fn target() -> Target { base.cpu = "x86-64".into(); base.plt_by_default = false; base.max_atomic_width = Some(64); + base.linker_flavor = LinkerFlavor::Gnu(Cc::Yes, Lld::Yes); + base.link_self_contained = LinkSelfContained::with_linker(); base.add_pre_link_args(LinkerFlavor::Gnu(Cc::Yes, Lld::No), &["-m64"]); base.stack_probes = StackProbeType::X86; base.static_position_independent_executables = true;