Skip to content

Commit 6d68f23

Browse files
committed
Auto merge of rust-lang#116182 - Kobzol:bootstrap-remove-use-lld, r=<try>
WIP: bootstrap: remove use-lld Removes the `use-lld` flag, which doesn't seem very useful - it's only used on one place in our CI explicitly, and setting of `lld` is far from being as simple as a boolean option. I think that we should just use lld based on the target specs or other inferred LLD usage. Opening a PR to see what CI has to say about it.
2 parents 5899a80 + 608d444 commit 6d68f23

File tree

10 files changed

+3
-84
lines changed

10 files changed

+3
-84
lines changed

config.example.toml

-9
Original file line numberDiff line numberDiff line change
@@ -625,15 +625,6 @@ changelog-seen = 2
625625
# rustc to execute.
626626
#lld = false
627627

628-
# Indicates whether LLD will be used to link Rust crates during bootstrap on
629-
# supported platforms. The LLD from the bootstrap distribution will be used
630-
# and not the LLD compiled during the bootstrap.
631-
#
632-
# LLD will not be used if we're cross linking.
633-
#
634-
# Explicitly setting the linker for a target will override this option when targeting MSVC.
635-
#use-lld = false
636-
637628
# Indicates whether some LLVM tools, like llvm-objdump, will be made available in the
638629
# sysroot.
639630
#llvm-tools = false

src/bootstrap/bin/rustc.rs

-3
Original file line numberDiff line numberDiff line change
@@ -115,9 +115,6 @@ fn main() {
115115
if let Ok(host_linker) = env::var("RUSTC_HOST_LINKER") {
116116
cmd.arg(format!("-Clinker={host_linker}"));
117117
}
118-
if env::var_os("RUSTC_HOST_FUSE_LD_LLD").is_some() {
119-
cmd.arg("-Clink-args=-fuse-ld=lld");
120-
}
121118

122119
if let Ok(s) = env::var("RUSTC_HOST_CRT_STATIC") {
123120
if s == "true" {

src/bootstrap/bin/rustdoc.rs

-4
Original file line numberDiff line numberDiff line change
@@ -53,10 +53,6 @@ fn main() {
5353
arg.push(&linker);
5454
cmd.arg(arg);
5555
}
56-
if let Ok(no_threads) = env::var("RUSTDOC_LLD_NO_THREADS") {
57-
cmd.arg("-Clink-arg=-fuse-ld=lld");
58-
cmd.arg(format!("-Clink-arg=-Wl,{no_threads}"));
59-
}
6056
// Cargo doesn't pass RUSTDOCFLAGS to proc_macros:
6157
// https://github.com/rust-lang/cargo/issues/4423
6258
// Thus, if we are on stage 0, we explicitly set `--cfg=bootstrap`.

src/bootstrap/builder.rs

-13
Original file line numberDiff line numberDiff line change
@@ -1174,9 +1174,6 @@ impl<'a> Builder<'a> {
11741174
if let Some(linker) = self.linker(compiler.host) {
11751175
cmd.env("RUSTDOC_LINKER", linker);
11761176
}
1177-
if self.is_fuse_ld_lld(compiler.host) {
1178-
cmd.env("RUSTDOC_FUSE_LD_LLD", "1");
1179-
}
11801177
cmd
11811178
}
11821179

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

16651658
if let Some(target_linker) = self.linker(target) {
16661659
let target = crate::envify(&target.triple);
16671660
cargo.env(&format!("CARGO_TARGET_{target}_LINKER"), target_linker);
16681661
}
1669-
if self.is_fuse_ld_lld(target) {
1670-
rustflags.arg("-Clink-args=-fuse-ld=lld");
1671-
}
1672-
self.lld_flags(target).for_each(|flag| {
1673-
rustdocflags.arg(&flag);
1674-
});
16751662

16761663
if !(["build", "check", "clippy", "fix", "rustc"].contains(&cmd)) && want_rustdoc {
16771664
cargo.env("RUSTDOC_LIBDIR", self.rustc_libdir(compiler));

src/bootstrap/compile.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -822,9 +822,9 @@ impl Step for Rustc {
822822
// is already on by default in MSVC optimized builds, which is interpreted as --icf=all:
823823
// https://github.com/llvm/llvm-project/blob/3329cec2f79185bafd678f310fafadba2a8c76d2/lld/COFF/Driver.cpp#L1746
824824
// https://github.com/rust-lang/rust/blob/f22819bcce4abaff7d1246a56eec493418f9f4ee/compiler/rustc_codegen_ssa/src/back/linker.rs#L827
825-
if builder.config.use_lld && !compiler.host.contains("msvc") {
826-
cargo.rustflag("-Clink-args=-Wl,--icf=all");
827-
}
825+
// if builder.config.use_lld && !compiler.host.contains("msvc") {
826+
// cargo.rustflag("-Clink-args=-Wl,--icf=all");
827+
// }
828828

829829
let is_collecting = if let Some(path) = &builder.config.rust_profile_generate {
830830
if compiler.stage == 1 {

src/bootstrap/config.rs

-3
Original file line numberDiff line numberDiff line change
@@ -193,7 +193,6 @@ pub struct Config {
193193
pub llvm_from_ci: bool,
194194
pub llvm_build_config: HashMap<String, String>,
195195

196-
pub use_lld: bool,
197196
pub lld_enabled: bool,
198197
pub llvm_tools_enabled: bool,
199198

@@ -989,7 +988,6 @@ define_config! {
989988
save_toolstates: Option<String> = "save-toolstates",
990989
codegen_backends: Option<Vec<String>> = "codegen-backends",
991990
lld: Option<bool> = "lld",
992-
use_lld: Option<bool> = "use-lld",
993991
llvm_tools: Option<bool> = "llvm-tools",
994992
deny_warnings: Option<bool> = "deny-warnings",
995993
backtrace_on_ice: Option<bool> = "backtrace-on-ice",
@@ -1407,7 +1405,6 @@ impl Config {
14071405
if let Some(true) = rust.incremental {
14081406
config.incremental = true;
14091407
}
1410-
set(&mut config.use_lld, rust.use_lld);
14111408
set(&mut config.lld_enabled, rust.lld);
14121409
set(&mut config.llvm_tools_enabled, rust.llvm_tools);
14131410
config.rustc_parallel = rust.parallel_compiler.unwrap_or(false);

src/bootstrap/lib.rs

-26
Original file line numberDiff line numberDiff line change
@@ -229,7 +229,6 @@ pub struct Build {
229229

230230
initial_rustc: PathBuf,
231231
initial_cargo: PathBuf,
232-
initial_lld: PathBuf,
233232
initial_libdir: PathBuf,
234233
initial_sysroot: PathBuf,
235234

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

397395
let initial_sysroot = if config.dry_run() {
398396
"/dummy".to_string()
@@ -435,7 +433,6 @@ impl Build {
435433
let mut build = Build {
436434
initial_rustc: config.initial_rustc.clone(),
437435
initial_cargo: config.initial_cargo.clone(),
438-
initial_lld,
439436
initial_libdir,
440437
initial_sysroot: initial_sysroot.into(),
441438
local_rebuild: config.local_rebuild,
@@ -1254,34 +1251,11 @@ impl Build {
12541251
&& !target.contains("msvc")
12551252
{
12561253
Some(self.cc(target))
1257-
} else if self.config.use_lld && !self.is_fuse_ld_lld(target) && self.build == target {
1258-
Some(self.initial_lld.clone())
12591254
} else {
12601255
None
12611256
}
12621257
}
12631258

1264-
// LLD is used through `-fuse-ld=lld` rather than directly.
1265-
// Only MSVC targets use LLD directly at the moment.
1266-
fn is_fuse_ld_lld(&self, target: TargetSelection) -> bool {
1267-
self.config.use_lld && !target.contains("msvc")
1268-
}
1269-
1270-
fn lld_flags(&self, target: TargetSelection) -> impl Iterator<Item = String> {
1271-
let mut options = [None, None];
1272-
1273-
if self.config.use_lld {
1274-
if self.is_fuse_ld_lld(target) {
1275-
options[0] = Some("-Clink-arg=-fuse-ld=lld".to_string());
1276-
}
1277-
1278-
let no_threads = util::lld_flag_no_threads(target.contains("windows"));
1279-
options[1] = Some(format!("-Clink-arg=-Wl,{no_threads}"));
1280-
}
1281-
1282-
IntoIterator::into_iter(options).flatten()
1283-
}
1284-
12851259
/// Returns if this target should statically link the C runtime, if specified
12861260
fn crt_static(&self, target: TargetSelection) -> Option<bool> {
12871261
if target.contains("pc-windows-msvc") {

src/bootstrap/test.rs

-8
Original file line numberDiff line numberDiff line change
@@ -856,12 +856,6 @@ impl Step for RustdocTheme {
856856
if let Some(linker) = builder.linker(self.compiler.host) {
857857
cmd.env("RUSTDOC_LINKER", linker);
858858
}
859-
if builder.is_fuse_ld_lld(self.compiler.host) {
860-
cmd.env(
861-
"RUSTDOC_LLD_NO_THREADS",
862-
util::lld_flag_no_threads(self.compiler.host.contains("windows")),
863-
);
864-
}
865859
builder.run_delaying_failure(&mut cmd);
866860
}
867861
}
@@ -1637,14 +1631,12 @@ note: if you're sure you want to do this, please open an issue as to why. In the
16371631

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

16451638
let mut targetflags = flags;
16461639
targetflags.push(format!("-Lnative={}", builder.test_helpers_out(target).display()));
1647-
targetflags.extend(builder.lld_flags(target));
16481640
for flag in targetflags {
16491641
cmd.arg("--target-rustcflags").arg(flag);
16501642
}

src/bootstrap/util.rs

-14
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ use std::time::{Instant, SystemTime, UNIX_EPOCH};
1414

1515
use crate::builder::Builder;
1616
use crate::config::{Config, TargetSelection};
17-
use crate::OnceCell;
1817

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

482-
pub fn lld_flag_no_threads(is_windows: bool) -> &'static str {
483-
static LLD_NO_THREADS: OnceCell<(&'static str, &'static str)> = OnceCell::new();
484-
let (windows, other) = LLD_NO_THREADS.get_or_init(|| {
485-
let out = output(Command::new("lld").arg("-flavor").arg("ld").arg("--version"));
486-
let newer = match (out.find(char::is_numeric), out.find('.')) {
487-
(Some(b), Some(e)) => out.as_str()[b..e].parse::<i32>().ok().unwrap_or(14) > 10,
488-
_ => true,
489-
};
490-
if newer { ("/threads:1", "--threads=1") } else { ("/no-threads", "--no-threads") }
491-
});
492-
if is_windows { windows } else { other }
493-
}
494-
495481
pub fn dir_is_empty(dir: &Path) -> bool {
496482
t!(std::fs::read_dir(dir)).next().is_none()
497483
}

src/ci/docker/host-x86_64/dist-x86_64-linux/Dockerfile

-1
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,6 @@ ENV RUST_CONFIGURE_ARGS \
8383
--set llvm.thin-lto=true \
8484
--set llvm.ninja=false \
8585
--set rust.jemalloc \
86-
--set rust.use-lld=true \
8786
--set rust.lto=thin
8887

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

0 commit comments

Comments
 (0)