From 429d3d4e9d8dd9f8a07c5304b7d840395521c882 Mon Sep 17 00:00:00 2001 From: Joseph Huber Date: Thu, 20 Oct 2022 10:51:46 -0500 Subject: [PATCH] [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 --- openmp/libomptarget/plugins/CMakeLists.txt | 3 ++- openmp/libomptarget/plugins/amdgpu/CMakeLists.txt | 3 ++- openmp/libomptarget/plugins/cuda/CMakeLists.txt | 3 ++- openmp/libomptarget/plugins/ve/CMakeLists.txt | 3 ++- 4 files changed, 8 insertions(+), 4 deletions(-) diff --git a/openmp/libomptarget/plugins/CMakeLists.txt b/openmp/libomptarget/plugins/CMakeLists.txt index 8ec24b5..005a372 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 dfd3671..6816c4e 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 244060e..796ff69 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 ef2906f..a949031 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} -- 2.7.4