Skip to content

[CMake] Add support for building on illumos #74930

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jan 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion clang/tools/clang-shlib/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ add_clang_library(clang-cpp
${_DEPS})
# Optimize function calls for default visibility definitions to avoid PLT and
# reduce dynamic relocations.
if (NOT APPLE AND NOT MINGW)
if (NOT APPLE AND NOT MINGW AND NOT LLVM_LINKER_IS_SOLARISLD_ILLUMOS)
target_link_options(clang-cpp PRIVATE LINKER:-Bsymbolic-functions)
endif()
if (MINGW OR CYGWIN)
Expand Down
19 changes: 15 additions & 4 deletions clang/tools/libclang/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -185,11 +185,22 @@ if(ENABLE_SHARED)
endif()
endif()
if (USE_VERSION_SCRIPT)
target_link_options(libclang PRIVATE "-Wl,--version-script,${CMAKE_CURRENT_SOURCE_DIR}/libclang.map")
# The Solaris 11.4 linker supports a subset of GNU ld version scripts,
# but requires a special option to enable it.
if (${CMAKE_SYSTEM_NAME} MATCHES "SunOS")
target_link_options(libclang PRIVATE "-Wl,-z,gnu-version-script-compat")
include(CheckLinkerFlag)
# The Solaris 11.4 linker supports a subset of GNU ld version scripts,
# but requires a special option to enable it.
llvm_check_linker_flag(CXX "-Wl,-z,gnu-version-script-compat"
LINKER_SUPPORTS_Z_GNU_VERSION_SCRIPT_COMPAT)
# Older Solaris (and illumos) linker does not support GNU ld version scripts
# and does not support GNU version script compat.
if (LINKER_SUPPORTS_Z_GNU_VERSION_SCRIPT_COMPAT)
target_link_options(libclang PRIVATE "-Wl,--version-script,${CMAKE_CURRENT_SOURCE_DIR}/libclang.map")
target_link_options(libclang PRIVATE "-Wl,-z,gnu-version-script-compat")
else()
target_link_options(libclang PRIVATE "-Wl,-M,${CMAKE_CURRENT_SOURCE_DIR}/libclang.map")
endif()
else()
target_link_options(libclang PRIVATE "-Wl,--version-script,${CMAKE_CURRENT_SOURCE_DIR}/libclang.map")
endif()
# Ensure that libclang.so gets rebuilt when the linker script changes.
set_property(SOURCE ARCMigrate.cpp APPEND PROPERTY
Expand Down
6 changes: 6 additions & 0 deletions llvm/cmake/modules/AddLLVM.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -241,6 +241,12 @@ if (NOT DEFINED LLVM_LINKER_DETECTED AND NOT WIN32)
set(LLVM_LINKER_DETECTED YES CACHE INTERNAL "")
set(LLVM_LINKER_IS_GNULD YES CACHE INTERNAL "")
message(STATUS "Linker detection: GNU ld")
elseif("${stderr}" MATCHES "(illumos)" OR
"${stdout}" MATCHES "(illumos)")
set(LLVM_LINKER_DETECTED YES CACHE INTERNAL "")
set(LLVM_LINKER_IS_SOLARISLD YES CACHE INTERNAL "")
set(LLVM_LINKER_IS_SOLARISLD_ILLUMOS YES CACHE INTERNAL "")
message(STATUS "Linker detection: Solaris ld (illumos)")
elseif("${stderr}" MATCHES "Solaris Link Editors" OR
"${stdout}" MATCHES "Solaris Link Editors")
set(LLVM_LINKER_DETECTED YES CACHE INTERNAL "")
Expand Down
2 changes: 1 addition & 1 deletion llvm/tools/llvm-shlib/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ if(LLVM_BUILD_LLVM_DYLIB)
# Solaris ld does not accept global: *; so there is no way to version *all* global symbols
set(LIB_NAMES -Wl,--version-script,${LLVM_LIBRARY_DIR}/tools/llvm-shlib/simple_version_script.map ${LIB_NAMES})
endif()
if (NOT MINGW)
if (NOT MINGW AND NOT LLVM_LINKER_IS_SOLARISLD_ILLUMOS)
# Optimize function calls for default visibility definitions to avoid PLT and
# reduce dynamic relocations.
# Note: for -fno-pic default, the address of a function may be different from
Expand Down