Skip to content

Commit

Permalink
Auto merge of #101504 - lqd:rust-lld-fix, r=petrochenkov
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
bors committed Sep 8, 2022
2 parents 4af35b8 + 318d0eb commit 44adfcc
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 8 deletions.
1 change: 1 addition & 0 deletions src/test/run-make/issue-71519/Makefile
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
include ../../run-make-fulldeps/tools.mk

# ignore-msvc
# needs-rust-lld
all:
RUSTC_LOG=rustc_codegen_ssa::back::link=info $(RUSTC) -Z gcc-ld=lld -C link-args=-Wl,-v main.rs 2> $(TMPDIR)/output.txt
Expand Down
18 changes: 15 additions & 3 deletions src/tools/compiletest/src/header.rs
Original file line number Diff line number Diff line change
Expand Up @@ -897,15 +897,27 @@ pub fn make_test_description<R: Read>(
let has_hwasan = util::HWASAN_SUPPORTED_TARGETS.contains(&&*config.target);
let has_memtag = util::MEMTAG_SUPPORTED_TARGETS.contains(&&*config.target);
let has_shadow_call_stack = util::SHADOWCALLSTACK_SUPPORTED_TARGETS.contains(&&*config.target);
// for `-Z gcc-ld=lld`

// For tests using the `needs-rust-lld` directive (e.g. for `-Zgcc-ld=lld`), we need to find
// whether `rust-lld` is present in the compiler under test.
//
// The --compile-lib-path is the path to host shared libraries, but depends on the OS. For
// example:
// - on linux, it can be <sysroot>/lib
// - on windows, it can be <sysroot>/bin
//
// However, `rust-lld` is only located under the lib path, so we look for it there.
let has_rust_lld = config
.compile_lib_path
.parent()
.expect("couldn't traverse to the parent of the specified --compile-lib-path")
.join("lib")
.join("rustlib")
.join(&config.target)
.join("bin")
.join("gcc-ld")
.join(if config.host.contains("windows") { "ld.exe" } else { "ld" })
.join(if config.host.contains("windows") { "rust-lld.exe" } else { "rust-lld" })
.exists();

iter_header(path, src, &mut |revision, ln| {
if revision.is_some() && revision != cfg {
return;
Expand Down
12 changes: 7 additions & 5 deletions src/tools/lld-wrapper/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,10 @@
//! obtained from the wrapper's name as the first two arguments.
//! On Windows it spawns a `..\rust-lld.exe` child process.
use std::env::{self, consts::EXE_SUFFIX};
use std::fmt::Display;
use std::path::{Path, PathBuf};
use std::{env, process};
use std::process;

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

/// Extract LLD flavor name from the lld-wrapper executable name.
fn get_lld_flavor(current_exe_path: &Path) -> Result<&'static str, String> {
let stem = current_exe_path.file_stem();
Ok(match stem.and_then(|s| s.to_str()) {
let file = current_exe_path.file_name();
let stem = file.and_then(|s| s.to_str()).map(|s| s.trim_end_matches(EXE_SUFFIX));
Ok(match stem {
Some("ld.lld") => "gnu",
Some("ld64.lld") => "darwin",
Some("lld-link") => "link",
Some("wasm-ld") => "wasm",
_ => return Err(format!("{:?}", stem)),
_ => return Err(format!("{:?}", file)),
})
}

Expand Down

0 comments on commit 44adfcc

Please sign in to comment.