[PATCH] D62483: [CUDA][HIP] Emit dependent libs for host only

Yaxun Liu via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Mon May 27 05:18:35 PDT 2019


yaxunl created this revision.
yaxunl added a reviewer: tra.

Recently D60274 <https://reviews.llvm.org/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.


https://reviews.llvm.org/D62483

Files:
  lib/CodeGen/CodeGenModule.cpp
  test/CodeGenCUDA/dependent-libs.cu


Index: test/CodeGenCUDA/dependent-libs.cu
===================================================================
--- /dev/null
+++ test/CodeGenCUDA/dependent-libs.cu
@@ -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")
Index: lib/CodeGen/CodeGenModule.cpp
===================================================================
--- lib/CodeGen/CodeGenModule.cpp
+++ lib/CodeGen/CodeGenModule.cpp
@@ -460,7 +460,12 @@
   // 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);


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D62483.201501.patch
Type: text/x-patch
Size: 1419 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20190527/fa2c78a9/attachment.bin>


More information about the cfe-commits mailing list