[PATCH] D84559: [compiler-rt][cmake] Don't pass --version-script to Illumos ld

Rainer Orth via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Fri Jul 24 14:59:35 PDT 2020


ro created this revision.
ro added a reviewer: Sanitizers.
ro added a project: Sanitizers.
Herald added subscribers: fedor.sergeev, mgorny, dberris.

Neither the Illumos `ld` nor the Solaris 11.3 one support the `--version-script` and
`z gnu-linker-script-compat` options, which breaks the `compiler-rt` build.

This patch checks for both options instead of hardcoding their use.

Tested on `amd-pc-solaris2.11` (all of Solaris 11.4, 11.3, and Illumos).

It should be possible to remove the `UNIX` resp. `FUCHSIA OR UNIX` conditions in
`compiler-rt/lib/asan/CMakeLists.txt` and `compiler-rt/lib/ubsan/CMakeLists.txt`.
However, until this has been tested on a wider range of platforms, I've kept them to
be safe.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D84559

Files:
  compiler-rt/cmake/config-ix.cmake
  compiler-rt/lib/asan/CMakeLists.txt
  compiler-rt/lib/ubsan/CMakeLists.txt


Index: compiler-rt/lib/ubsan/CMakeLists.txt
===================================================================
--- compiler-rt/lib/ubsan/CMakeLists.txt
+++ compiler-rt/lib/ubsan/CMakeLists.txt
@@ -200,7 +200,7 @@
       CFLAGS ${UBSAN_CXXFLAGS}
       PARENT_TARGET ubsan)
 
-    if (FUCHSIA OR UNIX)
+    if ((FUCHSIA OR UNIX) AND COMPILER_RT_HAS_VERSION_SCRIPT)
       file(WRITE ${CMAKE_CURRENT_BINARY_DIR}/dummy.cpp "")
       add_compiler_rt_object_libraries(RTUbsan_dynamic_version_script_dummy
         ARCHS ${UBSAN_SUPPORTED_ARCH}
@@ -216,7 +216,7 @@
             -Wl,--version-script,${CMAKE_CURRENT_BINARY_DIR}/clang_rt.ubsan_standalone-dynamic-${arch}.vers)
         # The Solaris 11.4 linker supports a subset of GNU ld version scripts,
         # but requires a special option to enable it.
-        if (OS_NAME MATCHES "SunOS")
+        if (COMPILER_RT_HAS_GNU_VERSION_SCRIPT_COMPAT)
             list(APPEND VERSION_SCRIPT_FLAG -Wl,-z,gnu-version-script-compat)
         endif()
         set_property(SOURCE
Index: compiler-rt/lib/asan/CMakeLists.txt
===================================================================
--- compiler-rt/lib/asan/CMakeLists.txt
+++ compiler-rt/lib/asan/CMakeLists.txt
@@ -224,7 +224,7 @@
     PARENT_TARGET asan)
 
   foreach(arch ${ASAN_SUPPORTED_ARCH})
-    if (UNIX)
+    if (UNIX AND COMPILER_RT_HAS_VERSION_SCRIPT)
       add_sanitizer_rt_version_list(clang_rt.asan-dynamic-${arch}
                                     LIBS clang_rt.asan-${arch} clang_rt.asan_cxx-${arch}
                                     EXTRA asan.syms.extra)
@@ -232,7 +232,7 @@
            -Wl,--version-script,${CMAKE_CURRENT_BINARY_DIR}/clang_rt.asan-dynamic-${arch}.vers)
       # The Solaris 11.4 linker supports a subset of GNU ld version scripts,
       # but requires a special option to enable it.
-      if (OS_NAME MATCHES "SunOS")
+      if (COMPILER_RT_HAS_GNU_VERSION_SCRIPT_COMPAT)
           list(APPEND VERSION_SCRIPT_FLAG -Wl,-z,gnu-version-script-compat)
       endif()
       set_property(SOURCE
Index: compiler-rt/cmake/config-ix.cmake
===================================================================
--- compiler-rt/cmake/config-ix.cmake
+++ compiler-rt/cmake/config-ix.cmake
@@ -157,6 +157,19 @@
 check_linker_flag("-Wl,-z,text" COMPILER_RT_HAS_Z_TEXT)
 check_linker_flag("-fuse-ld=lld" COMPILER_RT_HAS_FUSE_LD_LLD_FLAG)
 
+set(VERS_COMPAT_OPTION "-Wl,-z,gnu-version-script-compat")
+check_linker_flag("${VERS_COMPAT_OPTION}" COMPILER_RT_HAS_GNU_VERSION_SCRIPT_COMPAT)
+
+set(DUMMY_VERS ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeTmp/dummy.vers)
+file(WRITE ${DUMMY_VERS} "{};")
+set(VERS_OPTION "-Wl,--version-script,${DUMMY_VERS}")
+if(COMPILER_RT_HAS_GNU_VERSION_SCRIPT_COMPAT)
+  # Solaris 11.4 ld only supports --version-script with
+  # -z gnu-version-script-compat. 
+  string(APPEND VERS_OPTION " ${VERS_COMPAT_OPTION}")
+endif()
+check_linker_flag("${VERS_OPTION}" COMPILER_RT_HAS_VERSION_SCRIPT)
+
 if(ANDROID)
   check_linker_flag("-Wl,-z,global" COMPILER_RT_HAS_Z_GLOBAL)
   check_library_exists(log __android_log_write "" COMPILER_RT_HAS_LIBLOG)


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D84559.280595.patch
Type: text/x-patch
Size: 3117 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20200724/28a501c2/attachment-0001.bin>


More information about the llvm-commits mailing list