Skip to content

Commit

Permalink
[libomptarget][amdgpu] use --allow-shlib-undefined to link on FreeBSD
Browse files Browse the repository at this point in the history
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
  • Loading branch information
DimitryAndric committed Aug 8, 2021
1 parent ab4b468 commit 400cd6d
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion openmp/libomptarget/plugins/amdgpu/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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)
Expand Down

0 comments on commit 400cd6d

Please sign in to comment.