Skip to content

Commit 61c2cc9

Browse files
authored
[clang][clang-linker-wrapper] Use the correct triple for clang-offload-bundler and AMD SPIR-V. (#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 ```
1 parent ed60cd2 commit 61c2cc9

File tree

2 files changed

+21
-2
lines changed

2 files changed

+21
-2
lines changed
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
// RUN: %clang -cc1 %s -triple "spirv64-amd-amdhsa" -emit-llvm-bc -o %t.bc
2+
// RUN: llvm-offload-binary -o %t.out "--image=file=%t.bc,triple=spirv64-amd-amdhsa,arch=amdgcnspirv,kind=hip"
3+
// RUN: clang-linker-wrapper \
4+
// RUN: "--should-extract=amdgcnspirv" \
5+
// RUN: "--host-triple=spirv64-amd-amdhsa" \
6+
// RUN: "--linker-path=clang-offload-bundler" \
7+
// RUN: "--emit-fatbin-only" \
8+
// RUN: "-o" "%t.hipfb" \
9+
// RUN: "%t.out" \
10+
// RUN: --dry-run \
11+
// RUN: 2>&1 | FileCheck %s
12+
13+
// clang-linker-wrapper was previously calling clang-offload-bundler with -targets=...,hip-amdgcn-amd-amdhsa--amdgcnspirv
14+
// This caused the runtime not to recognise the triple for the AMD SPIR-V code.
15+
16+
// CHECK: {{".*clang-offload-bundler.*"}} {{.*}} -targets={{.*}},hip-spirv64-amd-amdhsa--amdgcnspirv

clang/tools/clang-linker-wrapper/ClangLinkerWrapper.cpp

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -439,8 +439,11 @@ fatbinary(ArrayRef<std::pair<StringRef, StringRef>> InputFiles,
439439
Args.MakeArgString(Twine("-compression-level=") + Arg->getValue()));
440440

441441
SmallVector<StringRef> Targets = {"-targets=host-x86_64-unknown-linux-gnu"};
442-
for (const auto &[File, Arch] : InputFiles)
443-
Targets.push_back(Saver.save("hip-amdgcn-amd-amdhsa--" + Arch));
442+
for (const auto &[File, Arch] : InputFiles) {
443+
Targets.push_back(Saver.save(Arch == "amdgcnspirv"
444+
? "hip-spirv64-amd-amdhsa--" + Arch
445+
: "hip-amdgcn-amd-amdhsa--" + Arch));
446+
}
444447
CmdArgs.push_back(Saver.save(llvm::join(Targets, ",")));
445448

446449
#ifdef _WIN32

0 commit comments

Comments
 (0)