[Openmp-commits] [PATCH] D102043: [libomptarget] Look for plugins next to libomptarget.so

Jon Chesterfield via Phabricator via Openmp-commits openmp-commits at lists.llvm.org
Thu Aug 26 09:05:22 PDT 2021


JonChesterfield updated this revision to Diff 368904.
JonChesterfield added a comment.

- Simplify, rename variables


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D102043/new/

https://reviews.llvm.org/D102043

Files:
  openmp/libomptarget/src/rtl.cpp


Index: openmp/libomptarget/src/rtl.cpp
===================================================================
--- openmp/libomptarget/src/rtl.cpp
+++ openmp/libomptarget/src/rtl.cpp
@@ -69,6 +69,22 @@
 #endif
 }
 
+namespace {
+std::string findLibomptargetDirectory() {
+  Dl_info Dlinfo;
+  // look up a symbol which is known to be from libomptarget.so as a portable
+  // way of locating the path to libomptarget.so from within libomtarget
+  if (dladdr((void *)&__tgt_register_lib, &Dlinfo) != 0) {
+    std::string LibomptargetPath = std::string(Dlinfo.dli_fname);
+    size_t Slash = LibomptargetPath.find_last_of('/');
+    if (Slash != std::string::npos) {
+      return LibomptargetPath.substr(0, Slash + 1); // keep the /
+    }
+  }
+  return "";
+}
+} // namespace
+
 void RTLsTy::LoadRTLs() {
   // Parse environment variable OMP_TARGET_OFFLOAD (if set)
   PM->TargetOffloadPolicy =
@@ -78,12 +94,14 @@
   }
 
   DP("Loading RTLs...\n");
+  std::string LibomptargetPath = findLibomptargetDirectory();
 
   // Attempt to open all the plugins and, if they exist, check if the interface
   // is correct and if they are supporting any devices.
   for (auto *Name : RTLNames) {
     DP("Loading library '%s'...\n", Name);
-    void *dynlib_handle = dlopen(Name, RTLD_NOW);
+    std::string AdjacentPluginName = LibomptargetPath + std::string(Name);
+    void *dynlib_handle = dlopen(AdjacentPluginName.c_str(), RTLD_NOW);
 
     if (!dynlib_handle) {
       // Library does not exist or cannot be found.


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D102043.368904.patch
Type: text/x-patch
Size: 1509 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/openmp-commits/attachments/20210826/9df775e4/attachment.bin>


More information about the Openmp-commits mailing list