From dfe5a567ae58eeaff8faa0ad636124f8ef25248d Mon Sep 17 00:00:00 2001 From: kulst Date: Thu, 9 Jul 2026 18:38:44 +0200 Subject: [PATCH] Prevent compiletest from overwriting the linker for cross-built tests Compiletest already avoids passing its default `--target` when a test provides one explicitly through compile-flags. However, it would still pass the globally configured target linker via `-Clinker`. This is problematic for cross-built tests, where the effective compilation target can differ from compiletest's configured target. For example, when compiletest is running with `x86_64-unknown-linux-musl` as its configured target, a test that explicitly compiles for `nvptx64-nvidia-cuda` can incorrectly inherit the musl linker. Avoid passing the configured target linker when the test provides a custom `--target`, so cross-built tests can use their target's linker defaults or test-provided linker flags. --- src/tools/compiletest/src/runtest.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/tools/compiletest/src/runtest.rs b/src/tools/compiletest/src/runtest.rs index 4243c60001244..0a5aa37722f41 100644 --- a/src/tools/compiletest/src/runtest.rs +++ b/src/tools/compiletest/src/runtest.rs @@ -1899,7 +1899,7 @@ impl<'test> TestCx<'test> { { compiler.arg(format!("-Clinker={linker}")); } - } else { + } else if !custom_target { self.maybe_add_external_args(&mut compiler, &self.config.target_rustcflags); if compiler_kind == CompilerKind::Rustc && let Some(ref linker) = self.config.target_linker