[Openmp-commits] [openmp] 400cd6d - [libomptarget][amdgpu] use --allow-shlib-undefined to link on FreeBSD

Dimitry Andric via Openmp-commits openmp-commits at lists.llvm.org
Sun Aug 8 04:52:57 PDT 2021


Author: Dimitry Andric
Date: 2021-08-08T13:52:44+02:00
New Revision: 400cd6d2f0496e913e25285615a86f9c29811171

URL: https://github.com/llvm/llvm-project/commit/400cd6d2f0496e913e25285615a86f9c29811171
DIFF: https://github.com/llvm/llvm-project/commit/400cd6d2f0496e913e25285615a86f9c29811171.diff

LOG: [libomptarget][amdgpu] use --allow-shlib-undefined to link on FreeBSD

On FreeBSD, the `environ` symbol is undefined at link time for shared
libraries, but resolved by the dynamic linker at runtime. Therefore,
allow the symbol to be undefined when creating a shared library, by
using the `--allow-shlib-undefined` linker flag, instead of `-z defs`
(a.k.a `--no-undefined`).

Reviewed By: JonChesterfield

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

Added: 
    

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

Removed: 
    


################################################################################
diff  --git a/openmp/libomptarget/plugins/amdgpu/CMakeLists.txt b/openmp/libomptarget/plugins/amdgpu/CMakeLists.txt
index 2904bb386c00d..c464d1202735e 100644
--- a/openmp/libomptarget/plugins/amdgpu/CMakeLists.txt
+++ b/openmp/libomptarget/plugins/amdgpu/CMakeLists.txt
@@ -78,6 +78,15 @@ add_library(omptarget.rtl.amdgpu SHARED
 # When we build for debug, OPENMP_LIBDIR_SUFFIX get set to -debug
 install(TARGETS omptarget.rtl.amdgpu LIBRARY DESTINATION "lib${OPENMP_LIBDIR_SUFFIX}")
 
+if(CMAKE_SYSTEM_NAME MATCHES "FreeBSD")
+  # On FreeBSD, the 'environ' symbol is undefined at link time, but resolved by
+  # the dynamic linker at runtime. Therefore, allow the symbol to be undefined
+  # when creating a shared library.
+  set(LDFLAGS_UNDEFINED "-Wl,--allow-shlib-undefined")
+else()
+  set(LDFLAGS_UNDEFINED "-Wl,-z,defs")
+endif()
+
 set_property(TARGET omptarget.rtl.amdgpu PROPERTY INSTALL_RPATH "$ORIGIN")
 target_link_libraries(
   omptarget.rtl.amdgpu
@@ -88,7 +97,7 @@ target_link_libraries(
   ${LIBOMPTARGET_DEP_LIBELF_LIBRARIES}
   ${OPENMP_PTHREAD_LIB}
   "-Wl,--version-script=${CMAKE_CURRENT_SOURCE_DIR}/../exports"
-  "-Wl,-z,defs"
+  ${LDFLAGS_UNDEFINED}
   )
 
 if (LLVM_BINARY_DIR)


        


More information about the Openmp-commits mailing list