[Openmp-commits] [openmp] 429d3d4 - [Libomptarget] Build plugins with protected visibility by default

Joseph Huber via Openmp-commits openmp-commits at lists.llvm.org
Thu Oct 20 09:12:31 PDT 2022


Author: Joseph Huber
Date: 2022-10-20T11:12:18-05:00
New Revision: 429d3d4e9d8dd9f8a07c5304b7d840395521c882

URL: https://github.com/llvm/llvm-project/commit/429d3d4e9d8dd9f8a07c5304b7d840395521c882
DIFF: https://github.com/llvm/llvm-project/commit/429d3d4e9d8dd9f8a07c5304b7d840395521c882.diff

LOG: [Libomptarget] Build plugins with protected visibility by default

The plugins all define the same interface symbols. This is generally not
a problem when calling the plugin directly from the dynamic library's
handle. However, when calling from within the plugin itself it is
possible for another plugin's symbols to preempt the symbols. This was
observed with the `__tgt_rtl_is_valid_binary` call in the
`__tgt_rtl_is_valid_binary_info` function being mapped to the x86_64
plugin.

This patch changes the default visibility to `protected` intead. This
visibility ensures that these symbols are all externally visible from
the plugin, but ensures their definitions are fixed within the shared
library. Having protected visiiblity makes such symbol preemption
impossible.

Reviewed By: tianshilei1992

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

Added: 
    

Modified: 
    openmp/libomptarget/plugins/CMakeLists.txt
    openmp/libomptarget/plugins/amdgpu/CMakeLists.txt
    openmp/libomptarget/plugins/cuda/CMakeLists.txt
    openmp/libomptarget/plugins/ve/CMakeLists.txt

Removed: 
    


################################################################################
diff  --git a/openmp/libomptarget/plugins/CMakeLists.txt b/openmp/libomptarget/plugins/CMakeLists.txt
index 8ec24b595673..005a3721b1f7 100644
--- a/openmp/libomptarget/plugins/CMakeLists.txt
+++ b/openmp/libomptarget/plugins/CMakeLists.txt
@@ -52,7 +52,8 @@ if(CMAKE_SYSTEM_PROCESSOR MATCHES "${tmachine}$")
     install(TARGETS "omptarget.rtl.${tmachine_libname}"
       LIBRARY DESTINATION "${OPENMP_INSTALL_LIBDIR}")
     set_target_properties("omptarget.rtl.${tmachine_libname}" PROPERTIES
-      INSTALL_RPATH "$ORIGIN" BUILD_RPATH "$ORIGIN:${CMAKE_CURRENT_BINARY_DIR}/..")
+      INSTALL_RPATH "$ORIGIN" BUILD_RPATH "$ORIGIN:${CMAKE_CURRENT_BINARY_DIR}/.."
+      CXX_VISIBILITY_PRESET protected)
 
     target_include_directories( "omptarget.rtl.${tmachine_libname}" PRIVATE
       ${LIBOMPTARGET_INCLUDE_DIR}

diff  --git a/openmp/libomptarget/plugins/amdgpu/CMakeLists.txt b/openmp/libomptarget/plugins/amdgpu/CMakeLists.txt
index dfd3671b9a8f..6816c4e06333 100644
--- a/openmp/libomptarget/plugins/amdgpu/CMakeLists.txt
+++ b/openmp/libomptarget/plugins/amdgpu/CMakeLists.txt
@@ -102,7 +102,8 @@ target_include_directories(
 # Install plugin under the lib destination folder.
 install(TARGETS omptarget.rtl.amdgpu LIBRARY DESTINATION "${OPENMP_INSTALL_LIBDIR}")
 set_target_properties(omptarget.rtl.amdgpu PROPERTIES 
-  INSTALL_RPATH "$ORIGIN" BUILD_RPATH "$ORIGIN:${CMAKE_CURRENT_BINARY_DIR}/..")
+  INSTALL_RPATH "$ORIGIN" BUILD_RPATH "$ORIGIN:${CMAKE_CURRENT_BINARY_DIR}/.."
+  CXX_VISIBILITY_PRESET protected)
 
 # Report to the parent scope that we are building a plugin for hsa.
 # This controls whether tests are run for the nvptx offloading target

diff  --git a/openmp/libomptarget/plugins/cuda/CMakeLists.txt b/openmp/libomptarget/plugins/cuda/CMakeLists.txt
index 244060efca60..796ff690abbf 100644
--- a/openmp/libomptarget/plugins/cuda/CMakeLists.txt
+++ b/openmp/libomptarget/plugins/cuda/CMakeLists.txt
@@ -87,7 +87,8 @@ add_dependencies(omptarget.rtl.cuda omptarget.devicertl.nvptx)
 # Install plugin under the lib destination folder.
 install(TARGETS omptarget.rtl.cuda LIBRARY DESTINATION "${OPENMP_INSTALL_LIBDIR}")
 set_target_properties(omptarget.rtl.cuda PROPERTIES 
-  INSTALL_RPATH "$ORIGIN" BUILD_RPATH "$ORIGIN:${CMAKE_CURRENT_BINARY_DIR}/..")
+  INSTALL_RPATH "$ORIGIN" BUILD_RPATH "$ORIGIN:${CMAKE_CURRENT_BINARY_DIR}/.."
+  CXX_VISIBILITY_PRESET protected)
 
 target_include_directories(omptarget.rtl.cuda PRIVATE
   ${LIBOMPTARGET_INCLUDE_DIR}

diff  --git a/openmp/libomptarget/plugins/ve/CMakeLists.txt b/openmp/libomptarget/plugins/ve/CMakeLists.txt
index ef2906fd6e39..a949031efaf4 100644
--- a/openmp/libomptarget/plugins/ve/CMakeLists.txt
+++ b/openmp/libomptarget/plugins/ve/CMakeLists.txt
@@ -44,7 +44,8 @@ if(${LIBOMPTARGET_DEP_VEO_FOUND})
   # Install plugin under the lib destination folder.
   install(TARGETS  "omptarget.rtl.${tmachine_libname}" LIBRARY DESTINATION "${OPENMP_INSTALL_LIBDIR}")
   set_target_properties("omptarget.rtl.${tmachine_libname}" PROPERTIES 
-    INSTALL_RPATH "$ORIGIN" BUILD_RPATH "$ORIGIN:${CMAKE_CURRENT_BINARY_DIR}/..")
+    INSTALL_RPATH "$ORIGIN" BUILD_RPATH "$ORIGIN:${CMAKE_CURRENT_BINARY_DIR}/.."
+    CXX_VISIBILITY_PRESET protected)
 
   target_include_directories("omptarget.rtl.${tmachine_libname}" PRIVATE
     ${LIBOMPTARGET_INCLUDE_DIR}


        


More information about the Openmp-commits mailing list