Skip to content

Commit b630092

Browse files
committed
[CMake] Add support for building on illumos
illumos has an older version of the Solaris linker that does not support the GNU version script compat nor version scripts and does not support -Bsymbolic-functions. Treat illumos linker separately. The libclang/CMakeLists part lifted from NetBSD's pkgsrc.
1 parent 700a192 commit b630092

File tree

4 files changed

+23
-6
lines changed

4 files changed

+23
-6
lines changed

clang/tools/clang-shlib/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ add_clang_library(clang-cpp
5050
${_DEPS})
5151
# Optimize function calls for default visibility definitions to avoid PLT and
5252
# reduce dynamic relocations.
53-
if (NOT APPLE AND NOT MINGW)
53+
if (NOT APPLE AND NOT MINGW AND NOT LLVM_LINKER_IS_SOLARISLD_ILLUMOS)
5454
target_link_options(clang-cpp PRIVATE LINKER:-Bsymbolic-functions)
5555
endif()
5656
if (MINGW OR CYGWIN)

clang/tools/libclang/CMakeLists.txt

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -185,11 +185,22 @@ if(ENABLE_SHARED)
185185
endif()
186186
endif()
187187
if (USE_VERSION_SCRIPT)
188-
target_link_options(libclang PRIVATE "-Wl,--version-script,${CMAKE_CURRENT_SOURCE_DIR}/libclang.map")
189-
# The Solaris 11.4 linker supports a subset of GNU ld version scripts,
190-
# but requires a special option to enable it.
191188
if (${CMAKE_SYSTEM_NAME} MATCHES "SunOS")
192-
target_link_options(libclang PRIVATE "-Wl,-z,gnu-version-script-compat")
189+
include(CheckLinkerFlag)
190+
# The Solaris 11.4 linker supports a subset of GNU ld version scripts,
191+
# but requires a special option to enable it.
192+
llvm_check_linker_flag(CXX "-Wl,-z,gnu-version-script-compat"
193+
LINKER_SUPPORTS_Z_GNU_VERSION_SCRIPT_COMPAT)
194+
# Older Solaris (and illumos) linker does not support GNU ld version scripts
195+
# and does not support GNU version script compat.
196+
if (LINKER_SUPPORTS_Z_GNU_VERSION_SCRIPT_COMPAT)
197+
target_link_options(libclang PRIVATE "-Wl,--version-script,${CMAKE_CURRENT_SOURCE_DIR}/libclang.map")
198+
target_link_options(libclang PRIVATE "-Wl,-z,gnu-version-script-compat")
199+
else()
200+
target_link_options(libclang PRIVATE "-Wl,-M,${CMAKE_CURRENT_SOURCE_DIR}/libclang.map")
201+
endif()
202+
else()
203+
target_link_options(libclang PRIVATE "-Wl,--version-script,${CMAKE_CURRENT_SOURCE_DIR}/libclang.map")
193204
endif()
194205
# Ensure that libclang.so gets rebuilt when the linker script changes.
195206
set_property(SOURCE ARCMigrate.cpp APPEND PROPERTY

llvm/cmake/modules/AddLLVM.cmake

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -241,6 +241,12 @@ if (NOT DEFINED LLVM_LINKER_DETECTED AND NOT WIN32)
241241
set(LLVM_LINKER_DETECTED YES CACHE INTERNAL "")
242242
set(LLVM_LINKER_IS_GNULD YES CACHE INTERNAL "")
243243
message(STATUS "Linker detection: GNU ld")
244+
elseif("${stderr}" MATCHES "(illumos)" OR
245+
"${stdout}" MATCHES "(illumos)")
246+
set(LLVM_LINKER_DETECTED YES CACHE INTERNAL "")
247+
set(LLVM_LINKER_IS_SOLARISLD YES CACHE INTERNAL "")
248+
set(LLVM_LINKER_IS_SOLARISLD_ILLUMOS YES CACHE INTERNAL "")
249+
message(STATUS "Linker detection: Solaris ld (illumos)")
244250
elseif("${stderr}" MATCHES "Solaris Link Editors" OR
245251
"${stdout}" MATCHES "Solaris Link Editors")
246252
set(LLVM_LINKER_DETECTED YES CACHE INTERNAL "")

llvm/tools/llvm-shlib/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ if(LLVM_BUILD_LLVM_DYLIB)
4949
# Solaris ld does not accept global: *; so there is no way to version *all* global symbols
5050
set(LIB_NAMES -Wl,--version-script,${LLVM_LIBRARY_DIR}/tools/llvm-shlib/simple_version_script.map ${LIB_NAMES})
5151
endif()
52-
if (NOT MINGW)
52+
if (NOT MINGW AND NOT LLVM_LINKER_IS_SOLARISLD_ILLUMOS)
5353
# Optimize function calls for default visibility definitions to avoid PLT and
5454
# reduce dynamic relocations.
5555
# Note: for -fno-pic default, the address of a function may be different from

0 commit comments

Comments
 (0)