Skip to content

Commit 377806a

Browse files
committed
[HIP] Fix static lib name on windows
clang by default assumes static library name to be xxx.lib when -lxxx is specified on Windows with MSVC environment, instead of libxxx.a. This patch fixes static device library unbundling for that. It falls back to libxxx.a if xxx.lib is not found. Reviewed by: Artem Belevich Differential Revision: https://reviews.llvm.org/D126681
1 parent a2ea5b4 commit 377806a

File tree

2 files changed

+27
-8
lines changed

2 files changed

+27
-8
lines changed

clang/lib/Driver/ToolChains/CommonArgs.cpp

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1782,8 +1782,13 @@ bool tools::GetSDLFromOffloadArchive(
17821782
for (auto LPath : LibraryPaths) {
17831783
ArchiveOfBundles.clear();
17841784

1785-
AOBFileNames.push_back(Twine(LPath + "/libdevice/lib" + Lib + ".a").str());
1786-
AOBFileNames.push_back(Twine(LPath + "/lib" + Lib + ".a").str());
1785+
llvm::Triple Triple(D.getTargetTriple());
1786+
bool IsMSVC = Triple.isWindowsMSVCEnvironment();
1787+
for (auto Prefix : {"/libdevice/", "/"}) {
1788+
if (IsMSVC)
1789+
AOBFileNames.push_back(Twine(LPath + Prefix + Lib + ".lib").str());
1790+
AOBFileNames.push_back(Twine(LPath + Prefix + "lib" + Lib + ".a").str());
1791+
}
17871792

17881793
for (auto AOB : AOBFileNames) {
17891794
if (llvm::sys::fs::exists(AOB)) {
Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,28 @@
11
// REQUIRES: x86-registered-target, amdgpu-registered-target
22

3-
// RUN: touch %T/libhipBundled.a
43

54
// Check clang unbundle the archive and link them by lld.
65

6+
// RUN: touch %T/libhipBundled.a
77
// RUN: %clang -### --offload-arch=gfx906 --offload-arch=gfx1030 \
8+
// RUN: -target x86_64-unknown-linux-gnu \
89
// RUN: -nogpulib %s -fgpu-rdc -L%T -lhipBundled \
9-
// RUN: 2>&1 | FileCheck -check-prefix=CHECK %s
10+
// RUN: 2>&1 | FileCheck -check-prefix=GNU %s
11+
12+
// RUN: touch %T/hipBundled2.lib
13+
// RUN: %clang -### --offload-arch=gfx906 --offload-arch=gfx1030 \
14+
// RUN: -target x86_64-pc-windows-msvc \
15+
// RUN: -nogpulib %s -fgpu-rdc -L%T -lhipBundled2 \
16+
// RUN: 2>&1 | FileCheck -check-prefix=MSVC %s
17+
18+
// GNU: "{{.*}}clang-offload-bundler" "-unbundle" "-type=a" "-input={{.*}}libhipBundled.a" "-targets=hip-amdgcn-amd-amdhsa-gfx1030" "-output=[[A1030:.*\.a]]" "-allow-missing-bundles"
19+
// GNU: "{{.*}}lld{{.*}}" {{.*}}"-plugin-opt=mcpu=gfx1030" {{.*}} "[[A1030]]"
20+
// GNU: "{{.*}}clang-offload-bundler" "-unbundle" "-type=a" "-input={{.*}}libhipBundled.a" "-targets=hip-amdgcn-amd-amdhsa-gfx906" "-output=[[A906:.*\.a]]" "-allow-missing-bundles"
21+
// GNU: "{{.*}}lld{{.*}}" {{.*}}"-plugin-opt=mcpu=gfx906" {{.*}} "[[A906]]"
22+
// GNU: "{{.*}}ld{{.*}}" {{.*}}"-o" "a.out" {{.*}}"-lhipBundled"
1023

11-
// CHECK: "{{.*}}clang-offload-bundler" "-unbundle" "-type=a" "-input={{.*}}libhipBundled.a" "-targets=hip-amdgcn-amd-amdhsa-gfx1030" "-output=[[A1030:.*\.a]]" "-allow-missing-bundles"
12-
// CHECK: "{{.*}}lld{{.*}}" {{.*}}"-plugin-opt=mcpu=gfx1030" {{.*}} "[[A1030]]"
13-
// CHECK: "{{.*}}clang-offload-bundler" "-unbundle" "-type=a" "-input={{.*}}libhipBundled.a" "-targets=hip-amdgcn-amd-amdhsa-gfx906" "-output=[[A906:.*\.a]]" "-allow-missing-bundles"
14-
// CHECK: "{{.*}}lld{{.*}}" {{.*}}"-plugin-opt=mcpu=gfx906" {{.*}} "[[A906]]"
24+
// MSVC: "{{.*}}clang-offload-bundler" "-unbundle" "-type=a" "-input={{.*}}hipBundled2.lib" "-targets=hip-amdgcn-amd-amdhsa-gfx1030" "-output=[[A1030:.*\.a]]" "-allow-missing-bundles"
25+
// MSVC: "{{.*}}lld{{.*}}" {{.*}}"-plugin-opt=mcpu=gfx1030" {{.*}} "[[A1030]]"
26+
// MSVC: "{{.*}}clang-offload-bundler" "-unbundle" "-type=a" "-input={{.*}}hipBundled2.lib" "-targets=hip-amdgcn-amd-amdhsa-gfx906" "-output=[[A906:.*\.a]]" "-allow-missing-bundles"
27+
// MSVC: "{{.*}}lld{{.*}}" {{.*}}"-plugin-opt=mcpu=gfx906" {{.*}} "[[A906]]"
28+
// MSVC: "{{.*}}link{{.*}}" {{.*}}"-out:a.exe" {{.*}}"hipBundled2.lib"

0 commit comments

Comments
 (0)