[clang] [clang][clang-linker-wrapper] Use the correct triple for clang-offload-bundler and AMD SPIR-V. (PR #168521)
Manuel Carrasco via cfe-commits
cfe-commits at lists.llvm.org
Tue Nov 18 03:52:13 PST 2025
https://github.com/mgcarrasco created https://github.com/llvm/llvm-project/pull/168521
`clang-linker-wrapper` was incorrectly calling `clang-offload-bundler` for AMD SPIR-V. This resulted in a binary that couldn't be executed if built using the new driver.
The runtime couldn't recognise the triple triggering this error at execution time:
```
No compatible code objects found for: gfx90a:sramecc+:xnack-,
```
With this PR, this is solved:
```
Creating ISA for: gfx90a:sramecc+:xnack- from spirv
```
>From 1407826451ab218a473403dfd937d5dd0f26cacd Mon Sep 17 00:00:00 2001
From: Manuel Carrasco <Manuel.Carrasco at amd.com>
Date: Tue, 18 Nov 2025 05:41:31 -0600
Subject: [PATCH] [clang][clang-linker-wrapper] Use the correct triple for
clang-offload-bundler and AMD SPIR-V.
---
.../Driver/linker-wrapper-hip-amdgcnspirv.c | 19 +++++++++++++++++++
.../ClangLinkerWrapper.cpp | 7 +++++--
2 files changed, 24 insertions(+), 2 deletions(-)
create mode 100644 clang/test/Driver/linker-wrapper-hip-amdgcnspirv.c
diff --git a/clang/test/Driver/linker-wrapper-hip-amdgcnspirv.c b/clang/test/Driver/linker-wrapper-hip-amdgcnspirv.c
new file mode 100644
index 0000000000000..314feada5986e
--- /dev/null
+++ b/clang/test/Driver/linker-wrapper-hip-amdgcnspirv.c
@@ -0,0 +1,19 @@
+// UNSUPPORTED: system-windows
+// REQUIRES: amdgpu-registered-target
+
+// RUN: %clang -cc1 %s -triple "spirv64-amd-amdhsa" -emit-llvm-bc -o %t.bc
+// RUN: llvm-offload-binary -o %t.out "--image=file=%t.bc,triple=spirv64-amd-amdhsa,arch=amdgcnspirv,kind=hip"
+// RUN: clang-linker-wrapper \
+// RUN: "--should-extract=amdgcnspirv" \
+// RUN: "--host-triple=spirv64-amd-amdhsa" \
+// RUN: "--linker-path=clang-offload-bundler" \
+// RUN: "--emit-fatbin-only" \
+// RUN: "-o" "%t.hipfb" \
+// RUN: "%t.out" \
+// RUN: --dry-run \
+// RUN: 2>&1 | FileCheck %s
+
+// clang-linker-wrapper was previously calling clang-offload-bundler with -targets=...,hip-amdgcn-amd-amdhsa--amdgcnspirv
+// This caused the runtime not to recognise the triple for the AMD SPIR-V code.
+
+// CHECK: {{".*clang-offload-bundler.*"}} {{.*}} -targets={{.*}},hip-spirv64-amd-amdhsa--amdgcnspirv
diff --git a/clang/tools/clang-linker-wrapper/ClangLinkerWrapper.cpp b/clang/tools/clang-linker-wrapper/ClangLinkerWrapper.cpp
index bd4b40192c9f2..4a4a43db6ef25 100644
--- a/clang/tools/clang-linker-wrapper/ClangLinkerWrapper.cpp
+++ b/clang/tools/clang-linker-wrapper/ClangLinkerWrapper.cpp
@@ -439,8 +439,11 @@ fatbinary(ArrayRef<std::pair<StringRef, StringRef>> InputFiles,
Args.MakeArgString(Twine("-compression-level=") + Arg->getValue()));
SmallVector<StringRef> Targets = {"-targets=host-x86_64-unknown-linux-gnu"};
- for (const auto &[File, Arch] : InputFiles)
- Targets.push_back(Saver.save("hip-amdgcn-amd-amdhsa--" + Arch));
+ for (const auto &[File, Arch] : InputFiles) {
+ Targets.push_back(Saver.save(Arch == "amdgcnspirv"
+ ? "hip-spirv64-amd-amdhsa--" + Arch
+ : "hip-amdgcn-amd-amdhsa--" + Arch));
+ }
CmdArgs.push_back(Saver.save(llvm::join(Targets, ",")));
#ifdef _WIN32
More information about the cfe-commits
mailing list