[llvm-branch-commits] [clang] Backport of #136412 to release/20.x (PR #165843)
https://github.com/pvelesko created
https://github.com/llvm/llvm-project/pull/165843
Backport of #136412 to release/20.x
HIPSPV: Unbundle SDL
This fixes the issue of rdc linking static libraries with device code
>From 9daca4741404ac35e48cd7ddda66f50b3e0b0434 Mon Sep 17 00:00:00 2001
From: Paulius Velesko
Date: Mon, 28 Jul 2025 21:22:23 +0300
Subject: [PATCH] HIPSPV: Unbundle SDL (#136412)
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
This fixes the issue of rdc linking static libraries with device code
https://github.com/CHIP-SPV/chipStar/issues/984
-
Co-authored-by: Henry Linjamäki
---
clang/lib/Driver/ToolChains/HIPSPV.cpp| 9 ++
.../Driver/hipspv-link-static-library.hip | 28 +++
2 files changed, 37 insertions(+)
create mode 100644 clang/test/Driver/hipspv-link-static-library.hip
diff --git a/clang/lib/Driver/ToolChains/HIPSPV.cpp
b/clang/lib/Driver/ToolChains/HIPSPV.cpp
index bdbcf9109129d..2e16c6107e348 100644
--- a/clang/lib/Driver/ToolChains/HIPSPV.cpp
+++ b/clang/lib/Driver/ToolChains/HIPSPV.cpp
@@ -70,8 +70,17 @@ 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"));
diff --git a/clang/test/Driver/hipspv-link-static-library.hip
b/clang/test/Driver/hipspv-link-static-library.hip
new file mode 100644
index 0..03126ae589a09
--- /dev/null
+++ b/clang/test/Driver/hipspv-link-static-library.hip
@@ -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"
___
llvm-branch-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits
[llvm-branch-commits] [clang] Backport of #136412 to release/19.x (PR #165844)
https://github.com/pvelesko created
https://github.com/llvm/llvm-project/pull/165844
Backport of #136412 to release/19.x
HIPSPV: Unbundle SDL
This fixes the issue of rdc linking static libraries with device code
>From 228ae9e1a3269a4211cbf97ec10fc619731fd023 Mon Sep 17 00:00:00 2001
From: Paulius Velesko
Date: Mon, 28 Jul 2025 21:22:23 +0300
Subject: [PATCH] HIPSPV: Unbundle SDL (#136412)
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
This fixes the issue of rdc linking static libraries with device code
https://github.com/CHIP-SPV/chipStar/issues/984
-
Co-authored-by: Henry Linjamäki
---
clang/lib/Driver/ToolChains/HIPSPV.cpp| 9 ++
.../Driver/hipspv-link-static-library.hip | 28 +++
2 files changed, 37 insertions(+)
create mode 100644 clang/test/Driver/hipspv-link-static-library.hip
diff --git a/clang/lib/Driver/ToolChains/HIPSPV.cpp
b/clang/lib/Driver/ToolChains/HIPSPV.cpp
index bdbcf9109129d..2e16c6107e348 100644
--- a/clang/lib/Driver/ToolChains/HIPSPV.cpp
+++ b/clang/lib/Driver/ToolChains/HIPSPV.cpp
@@ -70,8 +70,17 @@ 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"));
diff --git a/clang/test/Driver/hipspv-link-static-library.hip
b/clang/test/Driver/hipspv-link-static-library.hip
new file mode 100644
index 0..03126ae589a09
--- /dev/null
+++ b/clang/test/Driver/hipspv-link-static-library.hip
@@ -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"
___
llvm-branch-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits
[llvm-branch-commits] [clang] Backport of #136412 to release/18.x (PR #165845)
https://github.com/pvelesko created
https://github.com/llvm/llvm-project/pull/165845
Backport of #136412 to release/18.x
HIPSPV: Unbundle SDL
This fixes the issue of rdc linking static libraries with device code
>From 6890820ddaa312a08a1095e7e7422d156177f64d Mon Sep 17 00:00:00 2001
From: Paulius Velesko
Date: Mon, 28 Jul 2025 21:22:23 +0300
Subject: [PATCH] HIPSPV: Unbundle SDL (#136412)
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
This fixes the issue of rdc linking static libraries with device code
https://github.com/CHIP-SPV/chipStar/issues/984
-
Co-authored-by: Henry Linjamäki
---
clang/lib/Driver/ToolChains/HIPSPV.cpp| 9 ++
.../Driver/hipspv-link-static-library.hip | 28 +++
2 files changed, 37 insertions(+)
create mode 100644 clang/test/Driver/hipspv-link-static-library.hip
diff --git a/clang/lib/Driver/ToolChains/HIPSPV.cpp
b/clang/lib/Driver/ToolChains/HIPSPV.cpp
index a144b28057f4c..332e82c950ba1 100644
--- a/clang/lib/Driver/ToolChains/HIPSPV.cpp
+++ b/clang/lib/Driver/ToolChains/HIPSPV.cpp
@@ -70,8 +70,17 @@ 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"));
diff --git a/clang/test/Driver/hipspv-link-static-library.hip
b/clang/test/Driver/hipspv-link-static-library.hip
new file mode 100644
index 0..03126ae589a09
--- /dev/null
+++ b/clang/test/Driver/hipspv-link-static-library.hip
@@ -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"
___
llvm-branch-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits
[llvm-branch-commits] [clang] Backport of #136412 to release/17.x (PR #165846)
https://github.com/pvelesko created
https://github.com/llvm/llvm-project/pull/165846
Backport of #136412 to release/17.x
HIPSPV: Unbundle SDL
This fixes the issue of rdc linking static libraries with device code
>From 1d0990045e0796b489db6fd51663ed05453fac1e Mon Sep 17 00:00:00 2001
From: Paulius Velesko
Date: Mon, 28 Jul 2025 21:22:23 +0300
Subject: [PATCH] HIPSPV: Unbundle SDL (#136412)
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
This fixes the issue of rdc linking static libraries with device code
https://github.com/CHIP-SPV/chipStar/issues/984
-
Co-authored-by: Henry Linjamäki
---
clang/lib/Driver/ToolChains/HIPSPV.cpp| 9 ++
.../Driver/hipspv-link-static-library.hip | 28 +++
2 files changed, 37 insertions(+)
create mode 100644 clang/test/Driver/hipspv-link-static-library.hip
diff --git a/clang/lib/Driver/ToolChains/HIPSPV.cpp
b/clang/lib/Driver/ToolChains/HIPSPV.cpp
index ea6a16029130d..8cc6149fecccf 100644
--- a/clang/lib/Driver/ToolChains/HIPSPV.cpp
+++ b/clang/lib/Driver/ToolChains/HIPSPV.cpp
@@ -70,8 +70,17 @@ 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"));
diff --git a/clang/test/Driver/hipspv-link-static-library.hip
b/clang/test/Driver/hipspv-link-static-library.hip
new file mode 100644
index 0..03126ae589a09
--- /dev/null
+++ b/clang/test/Driver/hipspv-link-static-library.hip
@@ -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"
___
llvm-branch-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits
[llvm-branch-commits] [clang] Backport of #136412 to release/21.x (PR #165842)
https://github.com/pvelesko created
https://github.com/llvm/llvm-project/pull/165842
Backport of #136412 to release/21.x
HIPSPV: Unbundle SDL
This fixes the issue of rdc linking static libraries with device code
>From 0c148827761bdaeea743efb41681219cf5383927 Mon Sep 17 00:00:00 2001
From: Paulius Velesko
Date: Mon, 28 Jul 2025 21:22:23 +0300
Subject: [PATCH] HIPSPV: Unbundle SDL (#136412)
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
This fixes the issue of rdc linking static libraries with device code
https://github.com/CHIP-SPV/chipStar/issues/984
-
Co-authored-by: Henry Linjamäki
---
clang/lib/Driver/ToolChains/HIPSPV.cpp| 9 ++
.../Driver/hipspv-link-static-library.hip | 28 +++
2 files changed, 37 insertions(+)
create mode 100644 clang/test/Driver/hipspv-link-static-library.hip
diff --git a/clang/lib/Driver/ToolChains/HIPSPV.cpp
b/clang/lib/Driver/ToolChains/HIPSPV.cpp
index 53649ca40d99b..90fec72e826f4 100644
--- a/clang/lib/Driver/ToolChains/HIPSPV.cpp
+++ b/clang/lib/Driver/ToolChains/HIPSPV.cpp
@@ -69,8 +69,17 @@ 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"));
diff --git a/clang/test/Driver/hipspv-link-static-library.hip
b/clang/test/Driver/hipspv-link-static-library.hip
new file mode 100644
index 0..03126ae589a09
--- /dev/null
+++ b/clang/test/Driver/hipspv-link-static-library.hip
@@ -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"
___
llvm-branch-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits
