Skip to content

Commit 44adfcc

Browse files
committed
Auto merge of #101504 - lqd:rust-lld-fix, r=petrochenkov
Fix `-Zgcc-ld=lld` `-Zgcc-ld=lld` is currently broken. CI is currently ignoring its tests. cc `@Mark-Simulacrum` on the `compiletest` change: I'm not sure which of `bootstrap`'s test step or `compiletest` is currently incorrect wrt windows' `--compile-lib-path`. Since `sysroot/bin` is passed on windows, that means that `compiletest` can't find `rust-lld` on windows and tests are currently ignored: it's looking for something that is in `sysroot/lib` instead. They are currently ignored on unixes for a different reason: the lld wrapper has a different name than what is checked. (I've changed `compiletest` in this PR, just because I could make a very targeted change there, whereas completely changing the intentional lib path that is passed seemed it'd have wider reaching implications on all tests.) And in both unix/win cases, I've changed the detection to look for `rust-lld` rather than the wrappers in `bin/gcc-ld/`. It seems like the more stable of all these executable names. r? `@petrochenkov` I've tested the `lld-wrapper` change on linux and osx, but couldn't test on windows gnu targets (I only have MSVC targets, and these can't use `rust-lld` via `-Zgcc-ld=lld`, nor do they use the lld wrapper IIUC). I'd expect it to work whether or not the wrapper is called with or without an executable suffix. But at least now CI should test it in these targets. Fixes #101370.
2 parents 4af35b8 + 318d0eb commit 44adfcc

File tree

3 files changed

+23
-8
lines changed

3 files changed

+23
-8
lines changed

Diff for: src/test/run-make/issue-71519/Makefile

+1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
include ../../run-make-fulldeps/tools.mk
22

3+
# ignore-msvc
34
# needs-rust-lld
45
all:
56
RUSTC_LOG=rustc_codegen_ssa::back::link=info $(RUSTC) -Z gcc-ld=lld -C link-args=-Wl,-v main.rs 2> $(TMPDIR)/output.txt

Diff for: src/tools/compiletest/src/header.rs

+15-3
Original file line numberDiff line numberDiff line change
@@ -897,15 +897,27 @@ pub fn make_test_description<R: Read>(
897897
let has_hwasan = util::HWASAN_SUPPORTED_TARGETS.contains(&&*config.target);
898898
let has_memtag = util::MEMTAG_SUPPORTED_TARGETS.contains(&&*config.target);
899899
let has_shadow_call_stack = util::SHADOWCALLSTACK_SUPPORTED_TARGETS.contains(&&*config.target);
900-
// for `-Z gcc-ld=lld`
900+
901+
// For tests using the `needs-rust-lld` directive (e.g. for `-Zgcc-ld=lld`), we need to find
902+
// whether `rust-lld` is present in the compiler under test.
903+
//
904+
// The --compile-lib-path is the path to host shared libraries, but depends on the OS. For
905+
// example:
906+
// - on linux, it can be <sysroot>/lib
907+
// - on windows, it can be <sysroot>/bin
908+
//
909+
// However, `rust-lld` is only located under the lib path, so we look for it there.
901910
let has_rust_lld = config
902911
.compile_lib_path
912+
.parent()
913+
.expect("couldn't traverse to the parent of the specified --compile-lib-path")
914+
.join("lib")
903915
.join("rustlib")
904916
.join(&config.target)
905917
.join("bin")
906-
.join("gcc-ld")
907-
.join(if config.host.contains("windows") { "ld.exe" } else { "ld" })
918+
.join(if config.host.contains("windows") { "rust-lld.exe" } else { "rust-lld" })
908919
.exists();
920+
909921
iter_header(path, src, &mut |revision, ln| {
910922
if revision.is_some() && revision != cfg {
911923
return;

Diff for: src/tools/lld-wrapper/src/main.rs

+7-5
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,10 @@
1111
//! obtained from the wrapper's name as the first two arguments.
1212
//! On Windows it spawns a `..\rust-lld.exe` child process.
1313
14+
use std::env::{self, consts::EXE_SUFFIX};
1415
use std::fmt::Display;
1516
use std::path::{Path, PathBuf};
16-
use std::{env, process};
17+
use std::process;
1718

1819
trait UnwrapOrExitWith<T> {
1920
fn unwrap_or_exit_with(self, context: &str) -> T;
@@ -42,7 +43,7 @@ impl<T, E: Display> UnwrapOrExitWith<T> for Result<T, E> {
4243
/// Exits if the parent directory cannot be determined.
4344
fn get_rust_lld_path(current_exe_path: &Path) -> PathBuf {
4445
let mut rust_lld_exe_name = "rust-lld".to_owned();
45-
rust_lld_exe_name.push_str(env::consts::EXE_SUFFIX);
46+
rust_lld_exe_name.push_str(EXE_SUFFIX);
4647
let mut rust_lld_path = current_exe_path
4748
.parent()
4849
.unwrap_or_exit_with("directory containing current executable could not be determined")
@@ -55,13 +56,14 @@ fn get_rust_lld_path(current_exe_path: &Path) -> PathBuf {
5556

5657
/// Extract LLD flavor name from the lld-wrapper executable name.
5758
fn get_lld_flavor(current_exe_path: &Path) -> Result<&'static str, String> {
58-
let stem = current_exe_path.file_stem();
59-
Ok(match stem.and_then(|s| s.to_str()) {
59+
let file = current_exe_path.file_name();
60+
let stem = file.and_then(|s| s.to_str()).map(|s| s.trim_end_matches(EXE_SUFFIX));
61+
Ok(match stem {
6062
Some("ld.lld") => "gnu",
6163
Some("ld64.lld") => "darwin",
6264
Some("lld-link") => "link",
6365
Some("wasm-ld") => "wasm",
64-
_ => return Err(format!("{:?}", stem)),
66+
_ => return Err(format!("{:?}", file)),
6567
})
6668
}
6769

0 commit comments

Comments
 (0)