Author: Brad Smith Date: 2024-01-08T23:28:04-05:00 New Revision: 49c35f69ac6884a07f07e7c09ca7b79282707f49
URL: https://github.com/llvm/llvm-project/commit/49c35f69ac6884a07f07e7c09ca7b79282707f49 DIFF: https://github.com/llvm/llvm-project/commit/49c35f69ac6884a07f07e7c09ca7b79282707f49.diff LOG: [CMake] Add support for building on illumos (#74930) 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. Build tested on Solaris 11.4 and OpenIndiana 2023.10. /usr/bin/ld --version ld: Software Generation Utilities - Solaris Link Editors: 5.11-1.3260 ld: Software Generation Utilities - Solaris Link Editors: 5.11-1.1790 (illumos) Added: Modified: clang/tools/clang-shlib/CMakeLists.txt clang/tools/libclang/CMakeLists.txt llvm/cmake/modules/AddLLVM.cmake llvm/tools/llvm-shlib/CMakeLists.txt Removed: ################################################################################ diff --git a/clang/tools/clang-shlib/CMakeLists.txt b/clang/tools/clang-shlib/CMakeLists.txt index aa7fcd1efed45b..298d3a9d18fec8 100644 --- a/clang/tools/clang-shlib/CMakeLists.txt +++ b/clang/tools/clang-shlib/CMakeLists.txt @@ -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) diff --git a/clang/tools/libclang/CMakeLists.txt b/clang/tools/libclang/CMakeLists.txt index 4f23065a247274..1cfc46eb1a52f6 100644 --- a/clang/tools/libclang/CMakeLists.txt +++ b/clang/tools/libclang/CMakeLists.txt @@ -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 diff --git a/llvm/cmake/modules/AddLLVM.cmake b/llvm/cmake/modules/AddLLVM.cmake index c9bca30c8f33d1..14c0837c35964d 100644 --- a/llvm/cmake/modules/AddLLVM.cmake +++ b/llvm/cmake/modules/AddLLVM.cmake @@ -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 "") diff --git a/llvm/tools/llvm-shlib/CMakeLists.txt b/llvm/tools/llvm-shlib/CMakeLists.txt index 64d6f631ffadd5..a47a0ec84c625c 100644 --- a/llvm/tools/llvm-shlib/CMakeLists.txt +++ b/llvm/tools/llvm-shlib/CMakeLists.txt @@ -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 diff erent from _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits