From 3c42dc24ae23d2501aaae81273762d0698d83ff7 Mon Sep 17 00:00:00 2001
From: Chris Denton <chris@chrisdenton.dev>
Date: Mon, 28 Apr 2025 14:15:30 +0000
Subject: [PATCH] Workaround for windows-gnu rust-lld test failure

The test run-make/amdgpu-kd has an issue where rust-lld will sometimes fail with error 0xc0000374 (STATUS_HEAP_CORRUPTION).
---
 tests/run-make/amdgpu-kd/rmake.rs | 6 ++++++
 1 file changed, 6 insertions(+)

diff --git a/tests/run-make/amdgpu-kd/rmake.rs b/tests/run-make/amdgpu-kd/rmake.rs
index a787fa1da93aa..cba9030641dec 100644
--- a/tests/run-make/amdgpu-kd/rmake.rs
+++ b/tests/run-make/amdgpu-kd/rmake.rs
@@ -6,13 +6,19 @@
 //@ needs-llvm-components: amdgpu
 //@ needs-rust-lld
 
+use run_make_support::targets::is_windows_gnu;
 use run_make_support::{llvm_readobj, rustc};
 
 fn main() {
+    // FIXME(#115985): rust-lld on gnu targets may spuriously fail with
+    // STATUS_HEAP_CORRUPTION (0xc0000374).
+    // To try to mitigate this we pass --threads=1 to the linker.
+    let extra_args: &[&str] = if is_windows_gnu() { &["-C", "link-arg=--threads=1"] } else { &[] };
     rustc()
         .crate_name("foo")
         .target("amdgcn-amd-amdhsa")
         .arg("-Ctarget-cpu=gfx900")
+        .args(&extra_args)
         .crate_type("cdylib")
         .input("foo.rs")
         .run();