@@ -1551,6 +1551,7 @@ impl Config {
15511551 let mut debuginfo_level_tests = None ;
15521552 let mut optimize = None ;
15531553 let mut omit_git_hash = None ;
1554+ let mut lld_enabled = None ;
15541555
15551556 if let Some ( rust) = toml. rust {
15561557 let Rust {
@@ -1584,7 +1585,7 @@ impl Config {
15841585 dist_src,
15851586 save_toolstates,
15861587 codegen_backends,
1587- lld,
1588+ lld : lld_enabled_toml ,
15881589 llvm_tools,
15891590 llvm_bitcode_linker,
15901591 deny_warnings,
@@ -1639,6 +1640,7 @@ impl Config {
16391640 debuginfo_level_std = debuginfo_level_std_toml;
16401641 debuginfo_level_tools = debuginfo_level_tools_toml;
16411642 debuginfo_level_tests = debuginfo_level_tests_toml;
1643+ lld_enabled = lld_enabled_toml;
16421644
16431645 config. rust_split_debuginfo_for_build_triple = split_debuginfo
16441646 . as_deref ( )
@@ -1672,18 +1674,8 @@ impl Config {
16721674 config. incremental = true ;
16731675 }
16741676 set ( & mut config. lld_mode , lld_mode) ;
1675- set ( & mut config. lld_enabled , lld) ;
16761677 set ( & mut config. llvm_bitcode_linker_enabled , llvm_bitcode_linker) ;
16771678
1678- if matches ! ( config. lld_mode, LldMode :: SelfContained )
1679- && !config. lld_enabled
1680- && flags. stage . unwrap_or ( 0 ) > 0
1681- {
1682- panic ! (
1683- "Trying to use self-contained lld as a linker, but LLD is not being added to the sysroot. Enable it with rust.lld = true."
1684- ) ;
1685- }
1686-
16871679 config. llvm_tools_enabled = llvm_tools. unwrap_or ( true ) ;
16881680 config. rustc_parallel =
16891681 parallel_compiler. unwrap_or ( config. channel == "dev" || config. channel == "nightly" ) ;
@@ -1973,6 +1965,43 @@ impl Config {
19731965 config. llvm_plugins = llvm_plugins. unwrap_or ( false ) ;
19741966 config. rust_optimize = optimize. unwrap_or ( RustOptimize :: Bool ( true ) ) ;
19751967
1968+ // We make `x86_64-unknown-linux-gnu` use the self-contained linker by default, so we will
1969+ // build our internal lld and use it as the default linker, by setting the `rust.lld` config
1970+ // to true by default:
1971+ // - on the `x86_64-unknown-linux-gnu` target
1972+ // - on the `dev` and `nightly` channels
1973+ // - when building our in-tree llvm (i.e. the target has not set an `llvm-config`), so that
1974+ // we're also able to build the corresponding lld
1975+ // - or when using an external llvm that's downloaded from CI, which also contains our prebuilt
1976+ // lld
1977+ // - otherwise, we'd be using an external llvm, and lld would not necessarily available and
1978+ // thus, disabled
1979+ // - similarly, lld will not be built nor used by default when explicitly asked not to, e.g.
1980+ // when the config sets `rust.lld = false`
1981+ if config. build . triple == "x86_64-unknown-linux-gnu"
1982+ && config. hosts == & [ config. build ]
1983+ && ( config. channel == "dev" || config. channel == "nightly" )
1984+ {
1985+ let no_llvm_config = config
1986+ . target_config
1987+ . get ( & config. build )
1988+ . is_some_and ( |target_config| target_config. llvm_config . is_none ( ) ) ;
1989+ let enable_lld = config. llvm_from_ci || no_llvm_config;
1990+ // Prefer the config setting in case an explicit opt-out is needed.
1991+ config. lld_enabled = lld_enabled. unwrap_or ( enable_lld) ;
1992+ } else {
1993+ set ( & mut config. lld_enabled , lld_enabled) ;
1994+ }
1995+
1996+ if matches ! ( config. lld_mode, LldMode :: SelfContained )
1997+ && !config. lld_enabled
1998+ && flags. stage . unwrap_or ( 0 ) > 0
1999+ {
2000+ panic ! (
2001+ "Trying to use self-contained lld as a linker, but LLD is not being added to the sysroot. Enable it with rust.lld = true."
2002+ ) ;
2003+ }
2004+
19762005 let default = debug == Some ( true ) ;
19772006 config. rust_debug_assertions = debug_assertions. unwrap_or ( default) ;
19782007 config. rust_debug_assertions_std =
0 commit comments