]> granicus.if.org Git - clang/commitdiff
[CUDA][HIP] Emit dependent libs for host only
authorYaxun Liu <Yaxun.Liu@amd.com>
Tue, 28 May 2019 21:18:59 +0000 (21:18 +0000)
committerYaxun Liu <Yaxun.Liu@amd.com>
Tue, 28 May 2019 21:18:59 +0000 (21:18 +0000)
Recently D60274 was introduced to allow lld to handle dependent libs. However current
usage of dependent libs (e.g. pragma comment(lib, *) in windows header files) are intended
for host only. Emitting the metadata in device IR causes link error in device path.

Until there is a way to different it dependent libs for device or host, metadata for dependent
libs should be emitted for host only. This patch enforces that.

Differential Revision: https://reviews.llvm.org/D62483

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@361880 91177308-0d34-0410-b5e6-96231b3b80d8

lib/CodeGen/CodeGenModule.cpp
test/CodeGenCUDA/dependent-libs.cu [new file with mode: 0644]

index 6daea419281379c3f96abd44e0f4e30cfa24b26a..8c9e240a680fc3ed4b53b3c5a900a75a3edf2089 100644 (file)
@@ -457,7 +457,12 @@ void CodeGenModule::Release() {
   // that ELF linkers tend to handle libraries in a more complicated fashion
   // than on other platforms. This forces us to defer handling the dependent
   // libs to the linker.
-  if (!ELFDependentLibraries.empty()) {
+  //
+  // CUDA/HIP device and host libraries are different. Currently there is no
+  // way to differentiate dependent libraries for host or device. Existing
+  // usage of #pragma comment(lib, *) is intended for host libraries on
+  // Windows. Therefore emit llvm.dependent-libraries only for host.
+  if (!ELFDependentLibraries.empty() && !Context.getLangOpts().CUDAIsDevice) {
     auto *NMD = getModule().getOrInsertNamedMetadata("llvm.dependent-libraries");
     for (auto *MD : ELFDependentLibraries)
       NMD->addOperand(MD);
diff --git a/test/CodeGenCUDA/dependent-libs.cu b/test/CodeGenCUDA/dependent-libs.cu
new file mode 100644 (file)
index 0000000..6f59e66
--- /dev/null
@@ -0,0 +1,6 @@
+// RUN: %clang_cc1 -emit-llvm -o - -fcuda-is-device -x hip %s | FileCheck --check-prefix=DEV %s
+// RUN: %clang_cc1 -emit-llvm -o - -x hip %s | FileCheck --check-prefix=HOST %s
+
+// DEV-NOT: llvm.dependent-libraries
+// HOST: llvm.dependent-libraries
+#pragma comment(lib, "libabc")