]> git.lizzy.rs Git - rust.git/commitdiff
Auto merge of #101504 - lqd:rust-lld-fix, r=petrochenkov
authorbors <bors@rust-lang.org>
Thu, 8 Sep 2022 05:02:32 +0000 (05:02 +0000)
committerbors <bors@rust-lang.org>
Thu, 8 Sep 2022 05:02:32 +0000 (05:02 +0000)
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.

src/test/run-make/issue-71519/Makefile
src/tools/compiletest/src/header.rs
src/tools/lld-wrapper/src/main.rs

index 4475649ca927293c7a8acb47f467bc32d4da0dda..16d9a56e6bf78c472846074595c86a26aaede6b7 100644 (file)
@@ -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
index 8f097f47b451aae68113a00274340398adf109c0..3ff1cbf20cd26cc84009f42df3998f2b48222649 100644 (file)
@@ -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;
index 1795f3d7fe5bc5a3a0a9b908f333681274971dbb..b5e977b2637d8075fc6d51682e1a6e204187d715 100644 (file)
 //! 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;
@@ -42,7 +43,7 @@ fn unwrap_or_exit_with(self, context: &str) -> T {
 /// 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")
@@ -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)),
     })
 }