[Openmp-commits] [PATCH] D133276: [RFC][OpenMP][Offloading] dlopen plugins with version

Shilei Tian via Phabricator via Openmp-commits openmp-commits at lists.llvm.org
Sun Sep 4 12:08:06 PDT 2022


tianshilei1992 created this revision.
tianshilei1992 added reviewers: jdoerfert, JonChesterfield, jhuber6, RaviNarayanaswamy.
Herald added subscribers: guansong, yaxunl, mgorny.
Herald added a project: All.
tianshilei1992 requested review of this revision.
Herald added subscribers: openmp-commits, sstefan1.
Herald added a project: OpenMP.

Currently we open a plugin using its name such as `libomptarget.rtl.cuda.so`. We
don't verify its version, and always assume the backward compatibility, by
restricting changes of the plugin interfaces. Since LLVM 15, we made the plugin
a LLVM library, which means now it has version, because LLVM libraries are not
guaranteed backward compatible among major versions. Given that fact, in this
patch, we load a plugin w/ version in its name. This could at least prevent the
problem caused by incompatible LLVM components.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D133276

Files:
  openmp/libomptarget/src/CMakeLists.txt
  openmp/libomptarget/src/rtl.cpp


Index: openmp/libomptarget/src/rtl.cpp
===================================================================
--- openmp/libomptarget/src/rtl.cpp
+++ openmp/libomptarget/src/rtl.cpp
@@ -25,17 +25,30 @@
 using namespace llvm;
 using namespace llvm::sys;
 
+#ifndef LLVM_VERSION
+#define PLUGIN_VERSION ""
+#else
+#define VERSION_STR(X) #X
+#define PLUGIN_VERSION "." VERSION_STR(LLVM_VERSION)
+#endif
+
 // List of all plugins that can support offloading.
+
 static const char *RTLNames[] = {
-    /* PowerPC target       */ "libomptarget.rtl.ppc64.so",
-    /* x86_64 target        */ "libomptarget.rtl.x86_64.so",
-    /* CUDA target          */ "libomptarget.rtl.cuda.so",
-    /* AArch64 target       */ "libomptarget.rtl.aarch64.so",
-    /* SX-Aurora VE target  */ "libomptarget.rtl.ve.so",
-    /* AMDGPU target        */ "libomptarget.rtl.amdgpu.so",
-    /* Remote target        */ "libomptarget.rtl.rpc.so",
+    /* PowerPC target       */ "libomptarget.rtl.ppc64.so" PLUGIN_VERSION,
+    /* x86_64 target        */ "libomptarget.rtl.x86_64.so" PLUGIN_VERSION,
+    /* CUDA target          */ "libomptarget.rtl.cuda.so" PLUGIN_VERSION,
+    /* AArch64 target       */ "libomptarget.rtl.aarch64.so" PLUGIN_VERSION,
+    /* SX-Aurora VE target  */ "libomptarget.rtl.ve.so" PLUGIN_VERSION,
+    /* AMDGPU target        */ "libomptarget.rtl.amdgpu.so" PLUGIN_VERSION,
+    /* Remote target        */ "libomptarget.rtl.rpc.so" PLUGIN_VERSION,
 };
 
+#undef PLUGIN_VERSION
+#ifdef VERSION_STR
+#undef VERSION_STR
+#endif
+
 PluginManager *PM;
 
 static char *ProfileTraceFile = nullptr;
Index: openmp/libomptarget/src/CMakeLists.txt
===================================================================
--- openmp/libomptarget/src/CMakeLists.txt
+++ openmp/libomptarget/src/CMakeLists.txt
@@ -30,13 +30,15 @@
   Support
   Object
 
-  LINK_LIBS 
+  LINK_LIBS
   PRIVATE
   "-Wl,--version-script=${CMAKE_CURRENT_SOURCE_DIR}/exports"
   NO_INSTALL_RPATH
 )
 target_include_directories(omptarget PRIVATE ${LIBOMPTARGET_INCLUDE_DIR})
 
+target_compile_definitions(omptarget PRIVATE LLVM_VERSION=${LLVM_VERSION_MAJOR}${LLVM_VERSION_SUFFIX})
+
 # libomptarget.so needs to be aware of where the plugins live as they
 # are now separated in the build directory.
 set_target_properties(omptarget PROPERTIES INSTALL_RPATH "$ORIGIN" BUILD_RPATH "$ORIGIN:${CMAKE_CURRENT_BINARY_DIR}/..")


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D133276.457870.patch
Type: text/x-patch
Size: 2374 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/openmp-commits/attachments/20220904/23edd5ff/attachment.bin>


More information about the Openmp-commits mailing list