Files
patches/rust/rustc-1.93.1-external-llvm-bootstrap-lld-fallback.patch
T
2026-05-26 02:08:47 -05:00

75 lines
3.9 KiB
Diff

--- a/src/bootstrap/src/core/config/config.rs
+++ b/src/bootstrap/src/core/config/config.rs
@@ -628,7 +628,7 @@
);
}
- let bootstrap_override_lld =
+ let mut bootstrap_override_lld =
rust_bootstrap_override_lld.or(rust_bootstrap_override_lld_legacy).unwrap_or_default();
if rust_optimize.as_ref().is_some_and(|v| matches!(v, RustOptimize::Bool(false))) {
@@ -978,6 +978,20 @@
let is_host_system_llvm =
is_system_llvm(&target_config, llvm_from_ci, host_target, host_target);
+ // Self-contained bootstrap LLD comes from the stage0 sysroot (`rust-lld`), whose LLVM
+ // version may differ from an externally configured host LLVM. In that case, linking LLVM
+ // bitcode objects can fail with "Unknown attribute kind".
+ if is_host_system_llvm
+ && matches!(bootstrap_override_lld, BootstrapOverrideLld::SelfContained)
+ {
+ eprintln!(
+ "WARNING: `rust.bootstrap-override-lld = \"self-contained\"` with external host \
+ `llvm-config` can cause LLVM bitcode version mismatches; falling back to \
+ `rust.bootstrap-override-lld = \"external\"` for bootstrap linking."
+ );
+ bootstrap_override_lld = BootstrapOverrideLld::External;
+ }
+
if llvm_from_ci {
let warn = |option: &str| {
println!(
@@ -1042,21 +1056,27 @@
let default_linux_linker_override = match linker_override {
DefaultLinuxLinkerOverride::Off => continue,
DefaultLinuxLinkerOverride::SelfContainedLldCc => {
- // If we automatically default to the self-contained LLD linker,
- // we also need to handle the rust.lld option.
- match rust_lld_enabled {
- // If LLD was not enabled explicitly, we enable it, unless LLVM config has
- // been set
- None if !is_host_system_llvm => {
- lld_enabled = true;
- Some(DefaultLinuxLinkerOverride::SelfContainedLldCc)
+ // If bootstrap is explicitly using an external `lld` binary, do not also
+ // embed a self-contained rust-lld default into rustc's Linux target spec.
+ if matches!(bootstrap_override_lld, BootstrapOverrideLld::External) {
+ None
+ } else {
+ // If we automatically default to the self-contained LLD linker,
+ // we also need to handle the rust.lld option.
+ match rust_lld_enabled {
+ // If LLD was not enabled explicitly, we enable it, unless LLVM config has
+ // been set
+ None if !is_host_system_llvm => {
+ lld_enabled = true;
+ Some(DefaultLinuxLinkerOverride::SelfContainedLldCc)
+ }
+ None => None,
+ // If it was enabled already, we don't need to do anything
+ Some(true) => Some(DefaultLinuxLinkerOverride::SelfContainedLldCc),
+ // If it was explicitly disabled, we do not apply the
+ // linker override
+ Some(false) => None,
}
- None => None,
- // If it was enabled already, we don't need to do anything
- Some(true) => Some(DefaultLinuxLinkerOverride::SelfContainedLldCc),
- // If it was explicitly disabled, we do not apply the
- // linker override
- Some(false) => None,
}
}
};