Skip to content
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions clang/lib/Driver/ToolChains/HIPSPV.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,16 @@ void HIPSPV::Linker::constructLinkAndEmitSpirvCommand(

// Link LLVM bitcode.
ArgStringList LinkArgs{};

for (auto Input : Inputs)
LinkArgs.push_back(Input.getFilename());

// Add static device libraries using the common helper function.
// This handles unbundling archives (.a) containing bitcode bundles.
StringRef Arch = getToolChain().getTriple().getArchName();
StringRef Target = "generic"; // SPIR-V is generic, no specific target ID like -mcpu
tools::AddStaticDeviceLibsLinking(C, *this, JA, Inputs, Args, LinkArgs, Arch,
Target, /*IsBitCodeSDL=*/true);
LinkArgs.append({"-o", TempFile});
const char *LlvmLink =
Args.MakeArgString(getToolChain().GetProgramPath("llvm-link"));
Expand Down
28 changes: 28 additions & 0 deletions clang/test/Driver/hipspv-link-static-library.hip
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
// Test HIPSPV static device library linking
// REQUIRES: system-linux
// UNSUPPORTED: system-windows

// Create a dummy archive to test SDL linking
// RUN: rm -rf %t && mkdir %t
// RUN: touch %t/dummy.bc
// RUN: llvm-ar cr %t/libSDL.a %t/dummy.bc

// Test that -l options are passed to llvm-link for --offload=spirv64
// RUN: %clang -### --target=x86_64-linux-gnu --offload=spirv64 \
// RUN: --hip-path=%S/Inputs/hipspv -nohipwrapperinc %s \
// RUN: -L%t -lSDL \
// RUN: 2>&1 | FileCheck -check-prefix=SDL-LINK %s

// Test that .a files are properly unbundled and passed to llvm-link
// RUN: %clang -### --target=x86_64-linux-gnu --offload=spirv64 \
// RUN: --hip-path=%S/Inputs/hipspv -nohipwrapperinc %s \
// RUN: %t/libSDL.a \
// RUN: 2>&1 | FileCheck -check-prefix=SDL-ARCHIVE %s

// Verify that the input files are added before the SDL files in llvm-link command
// This tests the ordering fix to match HIPAMD behavior
// 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"
// SDL-LINK: "{{.*}}llvm-link" "{{.*}}.bc" "[[SDL_A]]" "-o"

// 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"
// SDL-ARCHIVE: "{{.*}}llvm-link" "{{.*}}.bc" "[[SDL_A]]" "-o"
Loading