[clang] 12c6a41 - [HIP] Fix unbundling archive
Yaxun Liu via cfe-commits
cfe-commits at lists.llvm.org
Wed Oct 12 13:39:53 PDT 2022
Author: Yaxun (Sam) Liu
Date: 2022-10-12T16:36:03-04:00
New Revision: 12c6a41f5249fa97041754d38cac28877ed49611
URL: https://github.com/llvm/llvm-project/commit/12c6a41f5249fa97041754d38cac28877ed49611
DIFF: https://github.com/llvm/llvm-project/commit/12c6a41f5249fa97041754d38cac28877ed49611.diff
LOG: [HIP] Fix unbundling archive
When -lxxx is specified, if there happens to have a directory or
file with name xxx, clang will not look up libxxx.a, but will
try to unbundle xxx instead.
Reviewed by: Saiyedul Islam, Artem Belevich
Differential Revision: https://reviews.llvm.org/D135724
Added:
Modified:
clang/lib/Driver/ToolChains/CommonArgs.cpp
clang/test/Driver/hip-link-bundle-archive.hip
Removed:
################################################################################
diff --git a/clang/lib/Driver/ToolChains/CommonArgs.cpp b/clang/lib/Driver/ToolChains/CommonArgs.cpp
index 21ad9c8b836b..ca8fc7b93972 100644
--- a/clang/lib/Driver/ToolChains/CommonArgs.cpp
+++ b/clang/lib/Driver/ToolChains/CommonArgs.cpp
@@ -1863,10 +1863,14 @@ bool tools::GetSDLFromOffloadArchive(
llvm::Triple Triple(D.getTargetTriple());
bool IsMSVC = Triple.isWindowsMSVCEnvironment();
auto Ext = IsMSVC ? ".lib" : ".a";
- if (!Lib.startswith(":") && llvm::sys::fs::exists(Lib)) {
- ArchiveOfBundles = Lib;
- FoundAOB = true;
+ if (!Lib.startswith(":") && !Lib.startswith("-l")) {
+ if (llvm::sys::fs::exists(Lib)) {
+ ArchiveOfBundles = Lib;
+ FoundAOB = true;
+ }
} else {
+ if (Lib.startswith("-l"))
+ Lib = Lib.drop_front(2);
for (auto LPath : LibraryPaths) {
ArchiveOfBundles.clear();
SmallVector<std::string, 2> AOBFileNames;
@@ -2036,7 +2040,7 @@ void tools::AddStaticDeviceLibs(Compilation *C, const Tool *T,
"omp", "cudart", "m", "gcc", "gcc_s", "pthread", "hip_hcc"};
for (auto SDLName : DriverArgs.getAllArgValues(options::OPT_l)) {
if (!HostOnlyArchives->contains(SDLName)) {
- SDLNames.insert(SDLName);
+ SDLNames.insert(std::string("-l") + SDLName);
}
}
diff --git a/clang/test/Driver/hip-link-bundle-archive.hip b/clang/test/Driver/hip-link-bundle-archive.hip
index 5f5017d998b0..945b45afa20d 100644
--- a/clang/test/Driver/hip-link-bundle-archive.hip
+++ b/clang/test/Driver/hip-link-bundle-archive.hip
@@ -1,14 +1,19 @@
// REQUIRES: x86-registered-target, amdgpu-registered-target
// Check clang unbundle the archive and link them by lld.
+// If there is a directory which has the same name as the
+// value of the '-l' option, it should not interfere with
+// the discovery and unbundling of the archive.
// RUN: rm -rf %t && mkdir %t
// RUN: touch %t/dummy.bc
+// RUN: mkdir hipBundled
// RUN: llvm-ar cr %t/libhipBundled.a %t/dummy.bc
// RUN: %clang -### --offload-arch=gfx906 --offload-arch=gfx1030 \
// RUN: --target=x86_64-unknown-linux-gnu \
// RUN: -nogpulib %s -fgpu-rdc -L%t -lhipBundled \
// RUN: 2>&1 | FileCheck -check-prefixes=GNU,GNU1,GNU-L %s
+// RUN: rm -rf hipBundled
// RUN: %clang -### --offload-arch=gfx906 --offload-arch=gfx1030 \
// RUN: --target=x86_64-unknown-linux-gnu \
@@ -42,6 +47,13 @@
// RUN: -nogpulib %s -fgpu-rdc -L%t libNonArchive.a \
// RUN: 2>&1 | FileCheck -check-prefixes=NONARCHIVE %s
+// Check if a file does not exist, it is not unbundled.
+
+// RUN: %clang -### --offload-arch=gfx906 --offload-arch=gfx1030 \
+// RUN: --target=x86_64-unknown-linux-gnu \
+// RUN: -nogpulib %s -fgpu-rdc %t/NoneExist.a \
+// RUN: 2>&1 | FileCheck -check-prefixes=NONE %s
+
// Check unbundling archive for MSVC.
// RUN: llvm-ar cr %t/hipBundled2.lib %t/dummy.bc
@@ -69,6 +81,7 @@
// GNU-LA: "{{.*}}ld{{.*}}" {{.*}}"-o" "a.out" {{.*}}"-l:libhipBundled.a"
// GNU-A: "{{.*}}ld{{.*}}" {{.*}}"-o" "a.out" "{{.*}}[[LIB]]"
// NONARCHIVE-NOT: "{{.*}}clang-offload-bundler" "-unbundle" "-type=a" "-input={{.*libNonArchive\.a}}"
+// NONE-NOT: "{{.*}}clang-offload-bundler" "-unbundle" "-type=a" "-input={{.*NoneExist\.a}}"
// MSVC: "{{.*}}clang-offload-bundler" "-unbundle" "-type=a" "-input={{.*}}hipBundled2.lib" "-targets=hip-amdgcn-amd-amdhsa-gfx1030" "-output=[[A1030:.*\.a]]" "-allow-missing-bundles"
// MSVC: "{{.*}}lld{{.*}}" {{.*}}"-plugin-opt=mcpu=gfx1030" {{.*}} "[[A1030]]"
More information about the cfe-commits
mailing list