[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:25:21 PDT 2021
JonChesterfield updated this revision to Diff 368909.
JonChesterfield added a comment.
- raise dladdr failure to fatal
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,17 @@
}
DP("Loading RTLs...\n");
+ const std::string LibomptargetPath = findLibomptargetDirectory();
+ const bool NoLibomptargetPath = LibomptargetPath == "";
// 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 = NoLibomptargetPath
+ ? nullptr
+ : 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.368909.patch
Type: text/x-patch
Size: 1667 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/openmp-commits/attachments/20210826/820d1d65/attachment.bin>
More information about the Openmp-commits
mailing list