Skip to content

Commit 25b2f48

Browse files
committed
Auto merge of #76378 - petrochenkov:lldtest, r=Mark-Simulacrum
rustbuild: Build tests with LLD if `use-lld = true` was passed Addresses #76127 (comment). Our test suite is generally ready to run with an explicitly specified linker (#45191), so LLD specified with `use-lld = true` works as well. Only 4 tests fail (on `x86_64-pc-windows-msvc`): ``` ui/panic-runtime/lto-unwind.rs run-make-fulldeps/debug-assertions run-make-fulldeps/foreign-exceptions run-make-fulldeps/test-harness ``` All of them are legitimate issues with LLD (or at least with combination Rust+LLD) and manifest in segfaults on access to TLS (#76127 (comment)). UPD: These issues are caused by #72145 and appear because I had `-Ctarget-cpu=native` set. UPD: Further commits build tests with LLD for non-MSVC targets and propagate LLD to more places when `use-lld` is enabled.
2 parents a18b34d + 75a2c68 commit 25b2f48

File tree

7 files changed

+41
-21
lines changed

7 files changed

+41
-21
lines changed

config.toml.example

+1-1
Original file line numberDiff line numberDiff line change
@@ -431,7 +431,7 @@
431431
# supported platforms. The LLD from the bootstrap distribution will be used
432432
# and not the LLD compiled during the bootstrap.
433433
#
434-
# LLD will not be used if we're cross linking or running tests.
434+
# LLD will not be used if we're cross linking.
435435
#
436436
# Explicitly setting the linker for a target will override this option when targeting MSVC.
437437
#use-lld = false

src/bootstrap/bin/rustc.rs

+3
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,9 @@ fn main() {
112112
if let Ok(host_linker) = env::var("RUSTC_HOST_LINKER") {
113113
cmd.arg(format!("-Clinker={}", host_linker));
114114
}
115+
if env::var_os("RUSTC_HOST_FUSE_LD_LLD").is_some() {
116+
cmd.arg("-Clink-args=-fuse-ld=lld");
117+
}
115118

116119
if let Ok(s) = env::var("RUSTC_HOST_CRT_STATIC") {
117120
if s == "true" {

src/bootstrap/bin/rustdoc.rs

+4-1
Original file line numberDiff line numberDiff line change
@@ -42,11 +42,14 @@ fn main() {
4242
if env::var_os("RUSTC_FORCE_UNSTABLE").is_some() {
4343
cmd.arg("-Z").arg("force-unstable-if-unmarked");
4444
}
45-
if let Some(linker) = env::var_os("RUSTC_TARGET_LINKER") {
45+
if let Some(linker) = env::var_os("RUSTDOC_LINKER") {
4646
let mut arg = OsString::from("-Clinker=");
4747
arg.push(&linker);
4848
cmd.arg(arg);
4949
}
50+
if env::var_os("RUSTDOC_FUSE_LD_LLD").is_some() {
51+
cmd.arg("-Clink-args=-fuse-ld=lld");
52+
}
5053

5154
// Needed to be able to run all rustdoc tests.
5255
if let Some(ref x) = env::var_os("RUSTDOC_RESOURCE_SUFFIX") {

src/bootstrap/builder.rs

+11-6
Original file line numberDiff line numberDiff line change
@@ -756,8 +756,11 @@ impl<'a> Builder<'a> {
756756
cmd.env_remove("MAKEFLAGS");
757757
cmd.env_remove("MFLAGS");
758758

759-
if let Some(linker) = self.linker(compiler.host, true) {
760-
cmd.env("RUSTC_TARGET_LINKER", linker);
759+
if let Some(linker) = self.linker(compiler.host) {
760+
cmd.env("RUSTDOC_LINKER", linker);
761+
}
762+
if self.is_fuse_ld_lld(compiler.host) {
763+
cmd.env("RUSTDOC_FUSE_LD_LLD", "1");
761764
}
762765
cmd
763766
}
@@ -1042,16 +1045,18 @@ impl<'a> Builder<'a> {
10421045
}
10431046
}
10441047

1045-
if let Some(host_linker) = self.linker(compiler.host, true) {
1048+
if let Some(host_linker) = self.linker(compiler.host) {
10461049
cargo.env("RUSTC_HOST_LINKER", host_linker);
10471050
}
1051+
if self.is_fuse_ld_lld(compiler.host) {
1052+
cargo.env("RUSTC_HOST_FUSE_LD_LLD", "1");
1053+
}
10481054

1049-
if let Some(target_linker) = self.linker(target, true) {
1055+
if let Some(target_linker) = self.linker(target) {
10501056
let target = crate::envify(&target.triple);
10511057
cargo.env(&format!("CARGO_TARGET_{}_LINKER", target), target_linker);
10521058
}
1053-
1054-
if self.config.use_lld && !target.contains("msvc") {
1059+
if self.is_fuse_ld_lld(target) {
10551060
rustflags.arg("-Clink-args=-fuse-ld=lld");
10561061
}
10571062

src/bootstrap/lib.rs

+8-7
Original file line numberDiff line numberDiff line change
@@ -844,7 +844,7 @@ impl Build {
844844
}
845845

846846
/// Returns the path to the linker for the given target if it needs to be overridden.
847-
fn linker(&self, target: TargetSelection, can_use_lld: bool) -> Option<&Path> {
847+
fn linker(&self, target: TargetSelection) -> Option<&Path> {
848848
if let Some(linker) = self.config.target_config.get(&target).and_then(|c| c.linker.as_ref())
849849
{
850850
Some(linker)
@@ -857,18 +857,19 @@ impl Build {
857857
&& !target.contains("msvc")
858858
{
859859
Some(self.cc(target))
860-
} else if target.contains("msvc")
861-
&& can_use_lld
862-
&& self.config.use_lld
863-
&& self.build == target
864-
{
865-
// Currently we support using LLD directly via `rust.use_lld` option only with MSVC
860+
} else if self.config.use_lld && !self.is_fuse_ld_lld(target) && self.build == target {
866861
Some(&self.initial_lld)
867862
} else {
868863
None
869864
}
870865
}
871866

867+
// LLD is used through `-fuse-ld=lld` rather than directly.
868+
// Only MSVC targets use LLD directly at the moment.
869+
fn is_fuse_ld_lld(&self, target: TargetSelection) -> bool {
870+
self.config.use_lld && !target.contains("msvc")
871+
}
872+
872873
/// Returns if this target should statically link the C runtime, if specified
873874
fn crt_static(&self, target: TargetSelection) -> Option<bool> {
874875
if target.contains("pc-windows-msvc") {

src/bootstrap/test.rs

+12-4
Original file line numberDiff line numberDiff line change
@@ -600,8 +600,11 @@ impl Step for RustdocTheme {
600600
.env("CFG_RELEASE_CHANNEL", &builder.config.channel)
601601
.env("RUSTDOC_REAL", builder.rustdoc(self.compiler))
602602
.env("RUSTC_BOOTSTRAP", "1");
603-
if let Some(linker) = builder.linker(self.compiler.host, true) {
604-
cmd.env("RUSTC_TARGET_LINKER", linker);
603+
if let Some(linker) = builder.linker(self.compiler.host) {
604+
cmd.env("RUSTDOC_LINKER", linker);
605+
}
606+
if builder.is_fuse_ld_lld(self.compiler.host) {
607+
cmd.env("RUSTDOC_FUSE_LD_LLD", "1");
605608
}
606609
try_run(builder, &mut cmd);
607610
}
@@ -1061,17 +1064,22 @@ impl Step for Compiletest {
10611064
flags.push("-Zunstable-options".to_string());
10621065
flags.push(builder.config.cmd.rustc_args().join(" "));
10631066

1064-
// Don't use LLD here since we want to test that rustc finds and uses a linker by itself.
1065-
if let Some(linker) = builder.linker(target, false) {
1067+
if let Some(linker) = builder.linker(target) {
10661068
cmd.arg("--linker").arg(linker);
10671069
}
10681070

10691071
let mut hostflags = flags.clone();
10701072
hostflags.push(format!("-Lnative={}", builder.test_helpers_out(compiler.host).display()));
1073+
if builder.is_fuse_ld_lld(compiler.host) {
1074+
hostflags.push("-Clink-args=-fuse-ld=lld".to_string());
1075+
}
10711076
cmd.arg("--host-rustcflags").arg(hostflags.join(" "));
10721077

10731078
let mut targetflags = flags;
10741079
targetflags.push(format!("-Lnative={}", builder.test_helpers_out(target).display()));
1080+
if builder.is_fuse_ld_lld(target) {
1081+
targetflags.push("-Clink-args=-fuse-ld=lld".to_string());
1082+
}
10751083
cmd.arg("--target-rustcflags").arg(targetflags.join(" "));
10761084

10771085
cmd.arg("--docck-python").arg(builder.python());

src/test/run-make-fulldeps/tools.mk

+2-2
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@ BARE_RUSTDOC := $(HOST_RPATH_ENV) '$(RUSTDOC)'
1111
RUSTC := $(BARE_RUSTC) --out-dir $(TMPDIR) -L $(TMPDIR) $(RUSTFLAGS)
1212
RUSTDOC := $(BARE_RUSTDOC) -L $(TARGET_RPATH_DIR)
1313
ifdef RUSTC_LINKER
14-
RUSTC := $(RUSTC) -Clinker=$(RUSTC_LINKER)
15-
RUSTDOC := $(RUSTDOC) -Clinker=$(RUSTC_LINKER)
14+
RUSTC := $(RUSTC) -Clinker='$(RUSTC_LINKER)'
15+
RUSTDOC := $(RUSTDOC) -Clinker='$(RUSTC_LINKER)'
1616
endif
1717
#CC := $(CC) -L $(TMPDIR)
1818
HTMLDOCCK := '$(PYTHON)' '$(S)/src/etc/htmldocck.py'

0 commit comments

Comments
 (0)