diff options
author | Shilei Tian <i@tianshilei.me> | 2023-04-30 23:34:31 -0400 |
---|---|---|
committer | Shilei Tian <i@tianshilei.me> | 2023-04-30 23:34:56 -0400 |
commit | fb53a7044a04cc05001aaf96cf14d390ac5ec33a (patch) | |
tree | e175195bc12cc4d28d29e51f5d0388ab44e0ae8c /openmp | |
parent | e876ba5db98830db427395ed9b3718d20bf519fb (diff) | |
download | llvm-fb53a7044a04cc05001aaf96cf14d390ac5ec33a.tar.gz |
[OpenMP] Only enable version script if supported
The linker flag `--version-script` may not be supported by all linkers, such as
macOS's linker. `libomp` is already capable of detecting whether the linker supports
it and append the linker flag accordingly. Since currently we assume `libomptarget`
only works on Linux, we don't do the check accordingly. This patch simply adds
the check before adding it to linker flag. This will be the first patch to make
OpenMP target offloading work on macOS. Note that CMake files in `plugins` are
not touched before they are going to be removed pretty soon anyway.
Reviewed By: jhuber6
Differential Revision: https://reviews.llvm.org/D149555
Diffstat (limited to 'openmp')
4 files changed, 21 insertions, 6 deletions
diff --git a/openmp/libomptarget/plugins-nextgen/CMakeLists.txt b/openmp/libomptarget/plugins-nextgen/CMakeLists.txt index 95e359cdbf2e..af02f050f467 100644 --- a/openmp/libomptarget/plugins-nextgen/CMakeLists.txt +++ b/openmp/libomptarget/plugins-nextgen/CMakeLists.txt @@ -52,11 +52,15 @@ if(CMAKE_SYSTEM_PROCESSOR MATCHES "${tmachine}$") PluginInterface ${LIBOMPTARGET_DEP_LIBFFI_LIBRARIES} ${OPENMP_PTHREAD_LIB} - "-Wl,--version-script=${CMAKE_CURRENT_SOURCE_DIR}/../exports" NO_INSTALL_RPATH ) + if (LIBOMP_HAVE_VERSION_SCRIPT_FLAG) + target_link_libraries("omptarget.rtl.${tmachine_libname}.nextgen" PRIVATE + "-Wl,--version-script=${CMAKE_CURRENT_SOURCE_DIR}/../exports") + endif() + # Install plugin under the lib destination folder. install(TARGETS "omptarget.rtl.${tmachine_libname}.nextgen" LIBRARY DESTINATION "${OPENMP_INSTALL_LIBDIR}") diff --git a/openmp/libomptarget/plugins-nextgen/amdgpu/CMakeLists.txt b/openmp/libomptarget/plugins-nextgen/amdgpu/CMakeLists.txt index b813497ab4d8..b689ff5a38d5 100644 --- a/openmp/libomptarget/plugins-nextgen/amdgpu/CMakeLists.txt +++ b/openmp/libomptarget/plugins-nextgen/amdgpu/CMakeLists.txt @@ -85,12 +85,16 @@ add_llvm_library(omptarget.rtl.amdgpu.nextgen SHARED PluginInterface ${LIBOMPTARGET_DEP_LIBRARIES} ${OPENMP_PTHREAD_LIB} - "-Wl,--version-script=${CMAKE_CURRENT_SOURCE_DIR}/../exports" ${LDFLAGS_UNDEFINED} NO_INSTALL_RPATH ) +if (LIBOMP_HAVE_VERSION_SCRIPT_FLAG) + target_link_libraries(omptarget.rtl.amdgpu.nextgen PRIVATE + "-Wl,--version-script=${CMAKE_CURRENT_SOURCE_DIR}/../exports") +endif() + target_include_directories( omptarget.rtl.amdgpu.nextgen PRIVATE diff --git a/openmp/libomptarget/plugins-nextgen/cuda/CMakeLists.txt b/openmp/libomptarget/plugins-nextgen/cuda/CMakeLists.txt index 6b7d2d743c73..397b06b67692 100644 --- a/openmp/libomptarget/plugins-nextgen/cuda/CMakeLists.txt +++ b/openmp/libomptarget/plugins-nextgen/cuda/CMakeLists.txt @@ -38,11 +38,16 @@ add_llvm_library(omptarget.rtl.cuda.nextgen SHARED MemoryManager PluginInterface ${OPENMP_PTHREAD_LIB} - "-Wl,--version-script=${CMAKE_CURRENT_SOURCE_DIR}/../exports,-z,defs" NO_INSTALL_RPATH ) +if (LIBOMP_HAVE_VERSION_SCRIPT_FLAG) + target_link_libraries(omptarget.rtl.cuda.nextgen PRIVATE + "-Wl,--version-script=${CMAKE_CURRENT_SOURCE_DIR}/../exports,-z,defs") +endif() + + if(LIBOMPTARGET_DEP_CUDA_FOUND AND NOT LIBOMPTARGET_FORCE_DLOPEN_LIBCUDA) libomptarget_say("Building CUDA plugin linked against libcuda") target_link_libraries(omptarget.rtl.cuda.nextgen PRIVATE CUDA::cuda_driver) diff --git a/openmp/libomptarget/src/CMakeLists.txt b/openmp/libomptarget/src/CMakeLists.txt index 2a6cd93c6ec9..ef3a6270b78a 100644 --- a/openmp/libomptarget/src/CMakeLists.txt +++ b/openmp/libomptarget/src/CMakeLists.txt @@ -31,13 +31,15 @@ add_llvm_library(omptarget Support Object - LINK_LIBS - PRIVATE - "-Wl,--version-script=${CMAKE_CURRENT_SOURCE_DIR}/exports" NO_INSTALL_RPATH ) target_include_directories(omptarget PRIVATE ${LIBOMPTARGET_INCLUDE_DIR}) +if (LIBOMP_HAVE_VERSION_SCRIPT_FLAG) + target_link_libraries(omptarget PRIVATE + "-Wl,--version-script=${CMAKE_CURRENT_SOURCE_DIR}/exports") +endif() + # 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}/..") |