Skip to content

Commit 5f04f6d

Browse files
committed
bootstrap: enable rust-lld when necessary for x86_64-unknown-linux-gnu
`x86_64-unknown-linux-gnu` has switched to using the self-contained linker by default (unless asked not to), so we have to build rust-lld: - when we build our own llvm - when we use download-ci-llvm - otherwise, when using an external llvm we can't enable it
1 parent 28ce76e commit 5f04f6d

File tree

1 file changed

+40
-11
lines changed

1 file changed

+40
-11
lines changed

src/bootstrap/src/core/config/config.rs

+40-11
Original file line numberDiff line numberDiff line change
@@ -1532,6 +1532,7 @@ impl Config {
15321532
let mut debuginfo_level_tests = None;
15331533
let mut optimize = None;
15341534
let mut omit_git_hash = None;
1535+
let mut lld_enabled = None;
15351536

15361537
if let Some(rust) = toml.rust {
15371538
let Rust {
@@ -1565,7 +1566,7 @@ impl Config {
15651566
dist_src,
15661567
save_toolstates,
15671568
codegen_backends,
1568-
lld,
1569+
lld: lld_enabled_toml,
15691570
llvm_tools,
15701571
llvm_bitcode_linker,
15711572
deny_warnings,
@@ -1620,6 +1621,7 @@ impl Config {
16201621
debuginfo_level_std = debuginfo_level_std_toml;
16211622
debuginfo_level_tools = debuginfo_level_tools_toml;
16221623
debuginfo_level_tests = debuginfo_level_tests_toml;
1624+
lld_enabled = lld_enabled_toml;
16231625

16241626
config.rust_split_debuginfo_for_build_triple = split_debuginfo
16251627
.as_deref()
@@ -1653,18 +1655,8 @@ impl Config {
16531655
config.incremental = true;
16541656
}
16551657
set(&mut config.lld_mode, lld_mode);
1656-
set(&mut config.lld_enabled, lld);
16571658
set(&mut config.llvm_bitcode_linker_enabled, llvm_bitcode_linker);
16581659

1659-
if matches!(config.lld_mode, LldMode::SelfContained)
1660-
&& !config.lld_enabled
1661-
&& flags.stage.unwrap_or(0) > 0
1662-
{
1663-
panic!(
1664-
"Trying to use self-contained lld as a linker, but LLD is not being added to the sysroot. Enable it with rust.lld = true."
1665-
);
1666-
}
1667-
16681660
config.llvm_tools_enabled = llvm_tools.unwrap_or(true);
16691661
config.rustc_parallel =
16701662
parallel_compiler.unwrap_or(config.channel == "dev" || config.channel == "nightly");
@@ -1954,6 +1946,43 @@ impl Config {
19541946
config.llvm_plugins = llvm_plugins.unwrap_or(false);
19551947
config.rust_optimize = optimize.unwrap_or(RustOptimize::Bool(true));
19561948

1949+
// We make `x86_64-unknown-linux-gnu` use the self-contained linker by default, so we will
1950+
// build our internal lld and use it as the default linker, by setting the `rust.lld` config
1951+
// to true by default:
1952+
// - on the `x86_64-unknown-linux-gnu` target
1953+
// - on the `dev` and `nightly` channels
1954+
// - when building our in-tree llvm (i.e. the target has not set an `llvm-config`), so that
1955+
// we're also able to build the corresponding lld
1956+
// - or when using an external llvm that's downloaded from CI, which also contains our prebuilt
1957+
// lld
1958+
// - otherwise, we'd be using an external llvm, and lld would not necessarily available and
1959+
// thus, disabled
1960+
// - similarly, lld will not be built nor used by default when explicitly asked not to, e.g.
1961+
// when the config sets `rust.lld = false`
1962+
if config.build.triple == "x86_64-unknown-linux-gnu"
1963+
&& config.hosts == [config.build]
1964+
&& (config.channel == "dev" || config.channel == "nightly")
1965+
{
1966+
let no_llvm_config = config
1967+
.target_config
1968+
.get(&config.build)
1969+
.is_some_and(|target_config| target_config.llvm_config.is_none());
1970+
let enable_lld = config.llvm_from_ci || no_llvm_config;
1971+
// Prefer the config setting in case an explicit opt-out is needed.
1972+
config.lld_enabled = lld_enabled.unwrap_or(enable_lld);
1973+
} else {
1974+
set(&mut config.lld_enabled, lld_enabled);
1975+
}
1976+
1977+
if matches!(config.lld_mode, LldMode::SelfContained)
1978+
&& !config.lld_enabled
1979+
&& flags.stage.unwrap_or(0) > 0
1980+
{
1981+
panic!(
1982+
"Trying to use self-contained lld as a linker, but LLD is not being added to the sysroot. Enable it with rust.lld = true."
1983+
);
1984+
}
1985+
19571986
let default = debug == Some(true);
19581987
config.rust_debug_assertions = debug_assertions.unwrap_or(default);
19591988
config.rust_debug_assertions_std =

0 commit comments

Comments
 (0)