Skip to content

Commit ae0614d

Browse files
pveleskolinehill
andauthored
HIPSPV: Unbundle SDL (#136412)
This fixes the issue of rdc linking static libraries with device code CHIP-SPV/chipStar#984 --------- Co-authored-by: Henry Linjamäki <[email protected]>
1 parent 18302d0 commit ae0614d

File tree

2 files changed

+37
-0
lines changed

2 files changed

+37
-0
lines changed

clang/lib/Driver/ToolChains/HIPSPV.cpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,8 +69,17 @@ void HIPSPV::Linker::constructLinkAndEmitSpirvCommand(
6969

7070
// Link LLVM bitcode.
7171
ArgStringList LinkArgs{};
72+
7273
for (auto Input : Inputs)
7374
LinkArgs.push_back(Input.getFilename());
75+
76+
// Add static device libraries using the common helper function.
77+
// This handles unbundling archives (.a) containing bitcode bundles.
78+
StringRef Arch = getToolChain().getTriple().getArchName();
79+
StringRef Target =
80+
"generic"; // SPIR-V is generic, no specific target ID like -mcpu
81+
tools::AddStaticDeviceLibsLinking(C, *this, JA, Inputs, Args, LinkArgs, Arch,
82+
Target, /*IsBitCodeSDL=*/true);
7483
LinkArgs.append({"-o", TempFile});
7584
const char *LlvmLink =
7685
Args.MakeArgString(getToolChain().GetProgramPath("llvm-link"));
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
// Test HIPSPV static device library linking
2+
// REQUIRES: system-linux
3+
// UNSUPPORTED: system-windows
4+
5+
// Create a dummy archive to test SDL linking
6+
// RUN: rm -rf %t && mkdir %t
7+
// RUN: touch %t/dummy.bc
8+
// RUN: llvm-ar cr %t/libSDL.a %t/dummy.bc
9+
10+
// Test that -l options are passed to llvm-link for --offload=spirv64
11+
// RUN: %clang -### --target=x86_64-linux-gnu --offload=spirv64 \
12+
// RUN: --hip-path=%S/Inputs/hipspv -nohipwrapperinc %s \
13+
// RUN: -L%t -lSDL \
14+
// RUN: 2>&1 | FileCheck -check-prefix=SDL-LINK %s
15+
16+
// Test that .a files are properly unbundled and passed to llvm-link
17+
// RUN: %clang -### --target=x86_64-linux-gnu --offload=spirv64 \
18+
// RUN: --hip-path=%S/Inputs/hipspv -nohipwrapperinc %s \
19+
// RUN: %t/libSDL.a \
20+
// RUN: 2>&1 | FileCheck -check-prefix=SDL-ARCHIVE %s
21+
22+
// Verify that the input files are added before the SDL files in llvm-link command
23+
// This tests the ordering fix to match HIPAMD behavior
24+
// SDL-LINK: "{{.*}}clang-offload-bundler" "-unbundle" "-type=a" "-input={{.*}}libSDL.a" "-targets=hip-spirv64-unknown-unknown-unknown-generic" "-output=[[SDL_A:.*\.a]]" "-allow-missing-bundles"
25+
// SDL-LINK: "{{.*}}llvm-link" "{{.*}}.bc" "[[SDL_A]]" "-o"
26+
27+
// SDL-ARCHIVE: "{{.*}}clang-offload-bundler" "-unbundle" "-type=a" "-input={{.*}}libSDL.a" "-targets=hip-spirv64-unknown-unknown-unknown-generic" "-output=[[SDL_A:.*\.a]]" "-allow-missing-bundles"
28+
// SDL-ARCHIVE: "{{.*}}llvm-link" "{{.*}}.bc" "[[SDL_A]]" "-o"

0 commit comments

Comments
 (0)