Skip to content

WIP: bootstrap: remove use-lld #116182

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 0 additions & 9 deletions config.example.toml
Original file line number Diff line number Diff line change
@@ -625,15 +625,6 @@ changelog-seen = 2
# rustc to execute.
#lld = false

# Indicates whether LLD will be used to link Rust crates during bootstrap on
# supported platforms. The LLD from the bootstrap distribution will be used
# and not the LLD compiled during the bootstrap.
#
# LLD will not be used if we're cross linking.
#
# Explicitly setting the linker for a target will override this option when targeting MSVC.
#use-lld = false

# Indicates whether some LLVM tools, like llvm-objdump, will be made available in the
# sysroot.
#llvm-tools = false
3 changes: 0 additions & 3 deletions src/bootstrap/bin/rustc.rs
Original file line number Diff line number Diff line change
@@ -115,9 +115,6 @@ fn main() {
if let Ok(host_linker) = env::var("RUSTC_HOST_LINKER") {
cmd.arg(format!("-Clinker={host_linker}"));
}
if env::var_os("RUSTC_HOST_FUSE_LD_LLD").is_some() {
cmd.arg("-Clink-args=-fuse-ld=lld");
}

if let Ok(s) = env::var("RUSTC_HOST_CRT_STATIC") {
if s == "true" {
4 changes: 0 additions & 4 deletions src/bootstrap/bin/rustdoc.rs
Original file line number Diff line number Diff line change
@@ -53,10 +53,6 @@ fn main() {
arg.push(&linker);
cmd.arg(arg);
}
if let Ok(no_threads) = env::var("RUSTDOC_LLD_NO_THREADS") {
cmd.arg("-Clink-arg=-fuse-ld=lld");
cmd.arg(format!("-Clink-arg=-Wl,{no_threads}"));
}
// Cargo doesn't pass RUSTDOCFLAGS to proc_macros:
// https://github.com/rust-lang/cargo/issues/4423
// Thus, if we are on stage 0, we explicitly set `--cfg=bootstrap`.
13 changes: 0 additions & 13 deletions src/bootstrap/builder.rs
Original file line number Diff line number Diff line change
@@ -1174,9 +1174,6 @@ impl<'a> Builder<'a> {
if let Some(linker) = self.linker(compiler.host) {
cmd.env("RUSTDOC_LINKER", linker);
}
if self.is_fuse_ld_lld(compiler.host) {
cmd.env("RUSTDOC_FUSE_LD_LLD", "1");
}
cmd
}

@@ -1657,21 +1654,11 @@ impl<'a> Builder<'a> {
if let Some(host_linker) = self.linker(compiler.host) {
cargo.env("RUSTC_HOST_LINKER", host_linker);
}
if self.is_fuse_ld_lld(compiler.host) {
cargo.env("RUSTC_HOST_FUSE_LD_LLD", "1");
cargo.env("RUSTDOC_FUSE_LD_LLD", "1");
}

if let Some(target_linker) = self.linker(target) {
let target = crate::envify(&target.triple);
cargo.env(&format!("CARGO_TARGET_{target}_LINKER"), target_linker);
}
if self.is_fuse_ld_lld(target) {
rustflags.arg("-Clink-args=-fuse-ld=lld");
}
self.lld_flags(target).for_each(|flag| {
rustdocflags.arg(&flag);
});

if !(["build", "check", "clippy", "fix", "rustc"].contains(&cmd)) && want_rustdoc {
cargo.env("RUSTDOC_LIBDIR", self.rustc_libdir(compiler));
6 changes: 3 additions & 3 deletions src/bootstrap/compile.rs
Original file line number Diff line number Diff line change
@@ -822,9 +822,9 @@ impl Step for Rustc {
// is already on by default in MSVC optimized builds, which is interpreted as --icf=all:
// https://github.com/llvm/llvm-project/blob/3329cec2f79185bafd678f310fafadba2a8c76d2/lld/COFF/Driver.cpp#L1746
// https://github.com/rust-lang/rust/blob/f22819bcce4abaff7d1246a56eec493418f9f4ee/compiler/rustc_codegen_ssa/src/back/linker.rs#L827
if builder.config.use_lld && !compiler.host.contains("msvc") {
cargo.rustflag("-Clink-args=-Wl,--icf=all");
}
// if builder.config.use_lld && !compiler.host.contains("msvc") {
// cargo.rustflag("-Clink-args=-Wl,--icf=all");
// }

let is_collecting = if let Some(path) = &builder.config.rust_profile_generate {
if compiler.stage == 1 {
3 changes: 0 additions & 3 deletions src/bootstrap/config.rs
Original file line number Diff line number Diff line change
@@ -193,7 +193,6 @@ pub struct Config {
pub llvm_from_ci: bool,
pub llvm_build_config: HashMap<String, String>,

pub use_lld: bool,
pub lld_enabled: bool,
pub llvm_tools_enabled: bool,

@@ -989,7 +988,6 @@ define_config! {
save_toolstates: Option<String> = "save-toolstates",
codegen_backends: Option<Vec<String>> = "codegen-backends",
lld: Option<bool> = "lld",
use_lld: Option<bool> = "use-lld",
llvm_tools: Option<bool> = "llvm-tools",
deny_warnings: Option<bool> = "deny-warnings",
backtrace_on_ice: Option<bool> = "backtrace-on-ice",
@@ -1407,7 +1405,6 @@ impl Config {
if let Some(true) = rust.incremental {
config.incremental = true;
}
set(&mut config.use_lld, rust.use_lld);
set(&mut config.lld_enabled, rust.lld);
set(&mut config.llvm_tools_enabled, rust.llvm_tools);
config.rustc_parallel = rust.parallel_compiler.unwrap_or(false);
26 changes: 0 additions & 26 deletions src/bootstrap/lib.rs
Original file line number Diff line number Diff line change
@@ -229,7 +229,6 @@ pub struct Build {

initial_rustc: PathBuf,
initial_cargo: PathBuf,
initial_lld: PathBuf,
initial_libdir: PathBuf,
initial_sysroot: PathBuf,

@@ -392,7 +391,6 @@ impl Build {
)
};
let initial_target_dir = Path::new(&initial_target_libdir_str).parent().unwrap();
let initial_lld = initial_target_dir.join("bin").join("rust-lld");

let initial_sysroot = if config.dry_run() {
"/dummy".to_string()
@@ -435,7 +433,6 @@ impl Build {
let mut build = Build {
initial_rustc: config.initial_rustc.clone(),
initial_cargo: config.initial_cargo.clone(),
initial_lld,
initial_libdir,
initial_sysroot: initial_sysroot.into(),
local_rebuild: config.local_rebuild,
@@ -1254,34 +1251,11 @@ impl Build {
&& !target.contains("msvc")
{
Some(self.cc(target))
} else if self.config.use_lld && !self.is_fuse_ld_lld(target) && self.build == target {
Some(self.initial_lld.clone())
} else {
None
}
}

// LLD is used through `-fuse-ld=lld` rather than directly.
// Only MSVC targets use LLD directly at the moment.
fn is_fuse_ld_lld(&self, target: TargetSelection) -> bool {
self.config.use_lld && !target.contains("msvc")
}

fn lld_flags(&self, target: TargetSelection) -> impl Iterator<Item = String> {
let mut options = [None, None];

if self.config.use_lld {
if self.is_fuse_ld_lld(target) {
options[0] = Some("-Clink-arg=-fuse-ld=lld".to_string());
}

let no_threads = util::lld_flag_no_threads(target.contains("windows"));
options[1] = Some(format!("-Clink-arg=-Wl,{no_threads}"));
}

IntoIterator::into_iter(options).flatten()
}

/// Returns if this target should statically link the C runtime, if specified
fn crt_static(&self, target: TargetSelection) -> Option<bool> {
if target.contains("pc-windows-msvc") {
8 changes: 0 additions & 8 deletions src/bootstrap/test.rs
Original file line number Diff line number Diff line change
@@ -856,12 +856,6 @@ impl Step for RustdocTheme {
if let Some(linker) = builder.linker(self.compiler.host) {
cmd.env("RUSTDOC_LINKER", linker);
}
if builder.is_fuse_ld_lld(self.compiler.host) {
cmd.env(
"RUSTDOC_LLD_NO_THREADS",
util::lld_flag_no_threads(self.compiler.host.contains("windows")),
);
}
builder.run_delaying_failure(&mut cmd);
}
}
@@ -1637,14 +1631,12 @@ note: if you're sure you want to do this, please open an issue as to why. In the

let mut hostflags = flags.clone();
hostflags.push(format!("-Lnative={}", builder.test_helpers_out(compiler.host).display()));
hostflags.extend(builder.lld_flags(compiler.host));
for flag in hostflags {
cmd.arg("--host-rustcflags").arg(flag);
}

let mut targetflags = flags;
targetflags.push(format!("-Lnative={}", builder.test_helpers_out(target).display()));
targetflags.extend(builder.lld_flags(target));
for flag in targetflags {
cmd.arg("--target-rustcflags").arg(flag);
}
14 changes: 0 additions & 14 deletions src/bootstrap/util.rs
Original file line number Diff line number Diff line change
@@ -14,7 +14,6 @@ use std::time::{Instant, SystemTime, UNIX_EPOCH};

use crate::builder::Builder;
use crate::config::{Config, TargetSelection};
use crate::OnceCell;

/// A helper macro to `unwrap` a result except also print out details like:
///
@@ -479,19 +478,6 @@ pub fn get_clang_cl_resource_dir(clang_cl_path: &str) -> PathBuf {
clang_rt_dir.to_path_buf()
}

pub fn lld_flag_no_threads(is_windows: bool) -> &'static str {
static LLD_NO_THREADS: OnceCell<(&'static str, &'static str)> = OnceCell::new();
let (windows, other) = LLD_NO_THREADS.get_or_init(|| {
let out = output(Command::new("lld").arg("-flavor").arg("ld").arg("--version"));
let newer = match (out.find(char::is_numeric), out.find('.')) {
(Some(b), Some(e)) => out.as_str()[b..e].parse::<i32>().ok().unwrap_or(14) > 10,
_ => true,
};
if newer { ("/threads:1", "--threads=1") } else { ("/no-threads", "--no-threads") }
});
if is_windows { windows } else { other }
}

pub fn dir_is_empty(dir: &Path) -> bool {
t!(std::fs::read_dir(dir)).next().is_none()
}
1 change: 0 additions & 1 deletion src/ci/docker/host-x86_64/dist-x86_64-linux/Dockerfile
Original file line number Diff line number Diff line change
@@ -83,7 +83,6 @@ ENV RUST_CONFIGURE_ARGS \
--set llvm.thin-lto=true \
--set llvm.ninja=false \
--set rust.jemalloc \
--set rust.use-lld=true \
--set rust.lto=thin

ENV SCRIPT python3 ../x.py build --set rust.debug=true opt-dist && \