[llvm] 2feb72b - [cmake] Don't pass -z discard-unused to Illumos ld
Rainer Orth via llvm-commits
llvm-commits at lists.llvm.org
Fri Jun 12 00:57:19 PDT 2020
Author: Rainer Orth
Date: 2020-06-12T09:56:42+02:00
New Revision: 2feb72bcd58cabb9f71538cb17fab459b6afc8ef
URL: https://github.com/llvm/llvm-project/commit/2feb72bcd58cabb9f71538cb17fab459b6afc8ef
DIFF: https://github.com/llvm/llvm-project/commit/2feb72bcd58cabb9f71538cb17fab459b6afc8ef.diff
LOG: [cmake] Don't pass -z discard-unused to Illumos ld
I'm currently working to port `libc++` to Solaris. There exists a slightly
bitrotten port already, which was done on Illumos, an OpenSolaris
derivative. In order not to break that port with my work, I need to test
the result on both Solaris and Illumos. While doing so, it turned out that
Illumos `ld` doesn't support the `-z discard-sections=unused` option
currently used on SunOS unconditionally.
While there exists a patch
<https://github.com/OpenIndiana/oi-userland/blob/oi/hipster/components/developer/clang-90/patches/02-cmake_modules_AddLLVM.cmake.patch>
for LLVM 9.0 in the OpenIndiana repository, it apparently hasn't been
submitted upstream and is completely wrong: it replaces
`-z discard-sections=unused` with `-z ignore`. In terms of the equivalent
`gld` options, this means replacing `--gc-sections` with `--as-needed`.
This patch instead tests if the linker actually supports the option before
using it.
Tested on `amd64-pc-solaris2.11` (all of Solaris 11.4, 11.3 and OpenIndiana
2020.04).
Differential Revision: https://reviews.llvm.org/D81545
Added:
Modified:
llvm/cmake/modules/AddLLVM.cmake
Removed:
################################################################################
diff --git a/llvm/cmake/modules/AddLLVM.cmake b/llvm/cmake/modules/AddLLVM.cmake
index f4dbd364262b..e25c72f3cae3 100644
--- a/llvm/cmake/modules/AddLLVM.cmake
+++ b/llvm/cmake/modules/AddLLVM.cmake
@@ -240,8 +240,14 @@ function(add_link_opts target_name)
set_property(TARGET ${target_name} APPEND_STRING PROPERTY
LINK_FLAGS " -Wl,-dead_strip")
elseif(${CMAKE_SYSTEM_NAME} MATCHES "SunOS")
- set_property(TARGET ${target_name} APPEND_STRING PROPERTY
- LINK_FLAGS " -Wl,-z -Wl,discard-unused=sections")
+ # Support for ld -z discard-unused=sections was only added in
+ # Solaris 11.4.
+ include(CheckLinkerFlag)
+ check_linker_flag("-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")
+ endif()
elseif(NOT WIN32 AND NOT LLVM_LINKER_IS_GOLD AND
NOT ${CMAKE_SYSTEM_NAME} MATCHES "OpenBSD|AIX")
# Object files are compiled with -ffunction-data-sections.
More information about the llvm-commits
mailing list