From 5f25154813b6eeb353bd7f0f758c4475cd239ffd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9my=20Rakic?= Date: Tue, 6 Sep 2022 15:54:20 +0200 Subject: [PATCH 1/3] fix lld-wrapper lld flavor detection --- src/tools/lld-wrapper/src/main.rs | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/src/tools/lld-wrapper/src/main.rs b/src/tools/lld-wrapper/src/main.rs index 1795f3d7fe5bc..b5e977b2637d8 100644 --- a/src/tools/lld-wrapper/src/main.rs +++ b/src/tools/lld-wrapper/src/main.rs @@ -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 { fn unwrap_or_exit_with(self, context: &str) -> T; @@ -42,7 +43,7 @@ impl UnwrapOrExitWith for Result { /// 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)), }) } From c805c62562e2d19116e8a4099c498276ae08aebf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9my=20Rakic?= Date: Tue, 6 Sep 2022 17:19:46 +0200 Subject: [PATCH 2/3] fix compiletest detection of needs-rust-lld tests for both windows and unixes --- src/tools/compiletest/src/header.rs | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/src/tools/compiletest/src/header.rs b/src/tools/compiletest/src/header.rs index 8f097f47b451a..3ff1cbf20cd26 100644 --- a/src/tools/compiletest/src/header.rs +++ b/src/tools/compiletest/src/header.rs @@ -897,15 +897,27 @@ pub fn make_test_description( 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 /lib + // - on windows, it can be /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; From 318d0eba8b5ffc02651ae40738e4276c1f4cf950 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9my=20Rakic?= Date: Tue, 6 Sep 2022 23:39:37 +0200 Subject: [PATCH 3/3] ignore `-Zgcc-ld=lld` test on msvc now that CI correctly detects rust-lld in run-make tests, we ignore this test since it relies on `-Zgcc-ld=lld` which is not made to work on the windows-msvc targets: it requires a gcc flavor. --- src/test/run-make/issue-71519/Makefile | 1 + 1 file changed, 1 insertion(+) diff --git a/src/test/run-make/issue-71519/Makefile b/src/test/run-make/issue-71519/Makefile index 4475649ca9272..16d9a56e6bf78 100644 --- a/src/test/run-make/issue-71519/Makefile +++ b/src/test/run-make/issue-71519/Makefile @@ -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