@@ -42,9 +42,9 @@ use crate::core::config::toml::install::Install;
4242use crate :: core:: config:: toml:: llvm:: Llvm ;
4343use crate :: core:: config:: toml:: rust:: {
4444 BootstrapOverrideLld , Rust , RustOptimize , check_incompatible_options_for_ci_rustc,
45- default_lld_opt_in_targets , parse_codegen_backends,
45+ parse_codegen_backends,
4646} ;
47- use crate :: core:: config:: toml:: target:: { Target , TomlTarget } ;
47+ use crate :: core:: config:: toml:: target:: { DefaultLinuxLinkerOverride , Target , TomlTarget } ;
4848use crate :: core:: config:: {
4949 CompilerBuiltins , DebuginfoLevel , DryRun , GccCiMode , LlvmLibunwind , Merge , ReplaceOpt ,
5050 RustcLto , SplitDebuginfo , StringOrBool , threads_from_config,
@@ -623,6 +623,8 @@ impl Config {
623623 let bootstrap_override_lld =
624624 rust_bootstrap_override_lld. or ( rust_bootstrap_override_lld_legacy) . unwrap_or_default ( ) ;
625625
626+ let lld_enabled = rust_lld_enabled. unwrap_or ( false ) ;
627+
626628 if rust_optimize. as_ref ( ) . is_some_and ( |v| matches ! ( v, RustOptimize :: Bool ( false ) ) ) {
627629 eprintln ! (
628630 "WARNING: setting `optimize` to `false` is known to cause errors and \
@@ -837,6 +839,7 @@ impl Config {
837839 ar : target_ar,
838840 ranlib : target_ranlib,
839841 default_linker : target_default_linker,
842+ default_linker_linux : target_default_linker_linux,
840843 linker : target_linker,
841844 split_debuginfo : target_split_debuginfo,
842845 llvm_config : target_llvm_config,
@@ -860,6 +863,28 @@ impl Config {
860863
861864 let mut target = Target :: from_triple ( & triple) ;
862865
866+ if let Some ( linux_override) = target_default_linker_linux. as_ref ( ) {
867+ if target_default_linker. is_some ( ) || rust_default_linker. is_some ( ) {
868+ panic ! (
869+ "cannot set both `default-linker` and `default-linker-linux` for target {triple}"
870+ ) ;
871+ }
872+ if !triple. contains ( "linux-gnu" ) {
873+ panic ! (
874+ "`default-linker-linux` can only be set for Linux GNU targets, not for {triple}"
875+ ) ;
876+ }
877+ match linux_override {
878+ DefaultLinuxLinkerOverride :: SelfContainedLldCc => {
879+ if !lld_enabled {
880+ panic ! (
881+ "Trying to override the default Linux linker for {triple} to be self-contained LLD, but LLD is not being built. Enable it with rust.lld = true."
882+ ) ;
883+ }
884+ }
885+ }
886+ }
887+
863888 if let Some ( ref s) = target_llvm_config {
864889 if download_rustc_commit. is_some ( ) && triple == * host_target. triple {
865890 panic ! (
@@ -893,6 +918,7 @@ impl Config {
893918 target. linker = target_linker. map ( PathBuf :: from) ;
894919 target. crt_static = target_crt_static;
895920 target. default_linker = target_default_linker;
921+ target. default_linker_linux = target_default_linker_linux;
896922 target. musl_root = target_musl_root. map ( PathBuf :: from) ;
897923 target. musl_libdir = target_musl_libdir. map ( PathBuf :: from) ;
898924 target. wasi_root = target_wasi_root. map ( PathBuf :: from) ;
@@ -926,28 +952,6 @@ impl Config {
926952 llvm_assertions,
927953 ) ;
928954
929- // We make `x86_64-unknown-linux-gnu` use the self-contained linker by default, so we will
930- // build our internal lld and use it as the default linker, by setting the `rust.lld` config
931- // to true by default:
932- // - on the `x86_64-unknown-linux-gnu` target
933- // - when building our in-tree llvm (i.e. the target has not set an `llvm-config`), so that
934- // we're also able to build the corresponding lld
935- // - or when using an external llvm that's downloaded from CI, which also contains our prebuilt
936- // lld
937- // - otherwise, we'd be using an external llvm, and lld would not necessarily available and
938- // thus, disabled
939- // - similarly, lld will not be built nor used by default when explicitly asked not to, e.g.
940- // when the config sets `rust.lld = false`
941- let lld_enabled = if default_lld_opt_in_targets ( ) . contains ( & host_target. triple . to_string ( ) )
942- && hosts == [ host_target]
943- {
944- let no_llvm_config =
945- target_config. get ( & host_target) . is_none_or ( |config| config. llvm_config . is_none ( ) ) ;
946- rust_lld_enabled. unwrap_or ( llvm_from_ci || no_llvm_config)
947- } else {
948- rust_lld_enabled. unwrap_or ( false )
949- } ;
950-
951955 if llvm_from_ci {
952956 let warn = |option : & str | {
953957 println ! (
0 commit comments