[llvm] [clang] [llvm] Add support for building on illumos (PR #74930)
Brad Smith via llvm-commits
llvm-commits at lists.llvm.org
Sat Dec 9 04:34:15 PST 2023
https://github.com/brad0 updated https://github.com/llvm/llvm-project/pull/74930
>From 58f07d552bb73244e1641078aebdbce64d5219e9 Mon Sep 17 00:00:00 2001
From: Brad Smith <brad at comstyle.com>
Date: Sat, 9 Dec 2023 01:43:09 -0500
Subject: [PATCH] [llvm] 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.
---
clang/tools/clang-shlib/CMakeLists.txt | 2 +-
clang/tools/libclang/CMakeLists.txt | 19 +++++++++++++++----
llvm/cmake/modules/AddLLVM.cmake | 13 ++++++++++---
llvm/tools/llvm-shlib/CMakeLists.txt | 4 ++--
4 files changed, 28 insertions(+), 10 deletions(-)
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..ca146ad699ff6c 100644
--- a/llvm/cmake/modules/AddLLVM.cmake
+++ b/llvm/cmake/modules/AddLLVM.cmake
@@ -115,7 +115,7 @@ function(add_llvm_symbol_exports target_name export_file)
DEPENDS ${export_file}
VERBATIM
COMMENT "Creating export file for ${target_name}")
- if (${LLVM_LINKER_IS_SOLARISLD})
+ if ((${LLVM_LINKER_IS_SOLARISLD}) OR (${LLVM_LINKER_IS_SOLARISLD_ILLUMOS}))
set_property(TARGET ${target_name} APPEND_STRING PROPERTY
LINK_FLAGS " -Wl,-M,\"${CMAKE_CURRENT_BINARY_DIR}/${native_export_file}\"")
else()
@@ -241,6 +241,11 @@ 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_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 "")
@@ -282,11 +287,13 @@ function(add_link_opts target_name)
# ld64's implementation of -dead_strip breaks tools that use plugins.
set_property(TARGET ${target_name} APPEND_STRING PROPERTY
LINK_FLAGS " -Wl,-dead_strip")
- elseif(${CMAKE_SYSTEM_NAME} MATCHES "SunOS" AND LLVM_LINKER_IS_SOLARISLD)
+ elseif(${CMAKE_SYSTEM_NAME} MATCHES "SunOS" AND (LLVM_LINKER_IS_SOLARISLD OR
+ LLVM_LINKER_IS_SOLARISLD_ILLUMOS))
# Support for ld -z discard-unused=sections was only added in
# Solaris 11.4. GNU ld ignores it, but warns every time.
include(LLVMCheckLinkerFlag)
- llvm_check_linker_flag(CXX "-Wl,-z,discard-unused=sections" LINKER_SUPPORTS_Z_DISCARD_UNUSED)
+ llvm_check_linker_flag(CXX "-Wl,-z,discard-unused=sections"
+ LINKER_SUPPORTS_Z_DISCARD_UNUSED)
if (LINKER_SUPPORTS_Z_DISCARD_UNUSED)
set_property(TARGET ${target_name} APPEND_STRING PROPERTY
LINK_FLAGS " -Wl,-z,discard-unused=sections")
diff --git a/llvm/tools/llvm-shlib/CMakeLists.txt b/llvm/tools/llvm-shlib/CMakeLists.txt
index 64d6f631ffadd5..119247582da28b 100644
--- a/llvm/tools/llvm-shlib/CMakeLists.txt
+++ b/llvm/tools/llvm-shlib/CMakeLists.txt
@@ -45,11 +45,11 @@ if(LLVM_BUILD_LLVM_DYLIB)
# GNU ld doesn't resolve symbols in the version script.
set(LIB_NAMES -Wl,--whole-archive ${LIB_NAMES} -Wl,--no-whole-archive)
- if (NOT LLVM_LINKER_IS_SOLARISLD AND NOT MINGW)
+ if (NOT LLVM_LINKER_IS_SOLARISLD AND NOT LLVM_LINKER_IS_SOLARISLD_ILLUMOS AND NOT MINGW)
# 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
More information about the llvm-commits
mailing list