@@ -42,9 +42,9 @@ use crate::core::config::toml::install::Install;
42
42
use crate :: core:: config:: toml:: llvm:: Llvm ;
43
43
use crate :: core:: config:: toml:: rust:: {
44
44
BootstrapOverrideLld , Rust , RustOptimize , check_incompatible_options_for_ci_rustc,
45
- default_lld_opt_in_targets , parse_codegen_backends,
45
+ parse_codegen_backends,
46
46
} ;
47
- use crate :: core:: config:: toml:: target:: { Target , TomlTarget } ;
47
+ use crate :: core:: config:: toml:: target:: { DefaultLinuxLinkerOverride , Target , TomlTarget } ;
48
48
use crate :: core:: config:: {
49
49
CompilerBuiltins , DebuginfoLevel , DryRun , GccCiMode , LlvmLibunwind , Merge , ReplaceOpt ,
50
50
RustcLto , SplitDebuginfo , StringOrBool , threads_from_config,
@@ -623,6 +623,8 @@ impl Config {
623
623
let bootstrap_override_lld =
624
624
rust_bootstrap_override_lld. or ( rust_bootstrap_override_lld_legacy) . unwrap_or_default ( ) ;
625
625
626
+ let lld_enabled = rust_lld_enabled. unwrap_or ( false ) ;
627
+
626
628
if rust_optimize. as_ref ( ) . is_some_and ( |v| matches ! ( v, RustOptimize :: Bool ( false ) ) ) {
627
629
eprintln ! (
628
630
"WARNING: setting `optimize` to `false` is known to cause errors and \
@@ -837,6 +839,7 @@ impl Config {
837
839
ar : target_ar,
838
840
ranlib : target_ranlib,
839
841
default_linker : target_default_linker,
842
+ default_linker_linux : target_default_linker_linux,
840
843
linker : target_linker,
841
844
split_debuginfo : target_split_debuginfo,
842
845
llvm_config : target_llvm_config,
@@ -860,6 +863,28 @@ impl Config {
860
863
861
864
let mut target = Target :: from_triple ( & triple) ;
862
865
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
+
863
888
if let Some ( ref s) = target_llvm_config {
864
889
if download_rustc_commit. is_some ( ) && triple == * host_target. triple {
865
890
panic ! (
@@ -893,6 +918,7 @@ impl Config {
893
918
target. linker = target_linker. map ( PathBuf :: from) ;
894
919
target. crt_static = target_crt_static;
895
920
target. default_linker = target_default_linker;
921
+ target. default_linker_linux = target_default_linker_linux;
896
922
target. musl_root = target_musl_root. map ( PathBuf :: from) ;
897
923
target. musl_libdir = target_musl_libdir. map ( PathBuf :: from) ;
898
924
target. wasi_root = target_wasi_root. map ( PathBuf :: from) ;
@@ -926,28 +952,6 @@ impl Config {
926
952
llvm_assertions,
927
953
) ;
928
954
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
-
951
955
if llvm_from_ci {
952
956
let warn = |option : & str | {
953
957
println ! (
0 commit comments