[compiler-rt] r321373 - [Sanitizers, CMake] Basic sanitizer Solaris support (PR 33274)

Alex Shlyapnikov via llvm-commits llvm-commits at lists.llvm.org
Fri Dec 22 10:04:20 PST 2017


Author: alekseyshl
Date: Fri Dec 22 10:04:20 2017
New Revision: 321373

URL: http://llvm.org/viewvc/llvm-project?rev=321373&view=rev
Log:
[Sanitizers, CMake] Basic sanitizer Solaris support (PR 33274)

Summary:
This patch, on top of https://reviews.llvm.org/D40898, contains the build system
changes necessary to enable the Solaris/x86 sanitizer port.

The only issue of note is the libclang_rt.sancov_{begin, end} libraries: clang relies on the
linker automatically defining __start_SECNAME and __stop_SECNAME labels for
sections whose names are valid C identifiers.  This is a GNU ld extension not present
in the ELF gABI, also implemented by gold and lld, but not by Solaris ld.  To work around
this, I automatically link the sancov_{begin,end} libraries into every executable for now.
There seems to be now way to build individual startup objects like crtbegin.o/crtend.o,
so I've followed the lead of libclang_rt.asan-preinit which also contains just a single
object.

Reviewers: kcc, alekseyshl

Reviewed By: alekseyshl

Subscribers: srhines, kubamracek, mgorny, fedor.sergeev, llvm-commits, #sanitizers

Tags: #sanitizers

Differential Revision: https://reviews.llvm.org/D40899

Added:
    compiler-rt/trunk/lib/sanitizer_common/sancov_begin.S
    compiler-rt/trunk/lib/sanitizer_common/sancov_end.S
Modified:
    compiler-rt/trunk/cmake/config-ix.cmake
    compiler-rt/trunk/lib/asan/CMakeLists.txt
    compiler-rt/trunk/lib/asan/scripts/asan_symbolize.py
    compiler-rt/trunk/lib/sanitizer_common/CMakeLists.txt

Modified: compiler-rt/trunk/cmake/config-ix.cmake
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/cmake/config-ix.cmake?rev=321373&r1=321372&r2=321373&view=diff
==============================================================================
--- compiler-rt/trunk/cmake/config-ix.cmake (original)
+++ compiler-rt/trunk/cmake/config-ix.cmake Fri Dec 22 10:04:20 2017
@@ -486,7 +486,7 @@ set(COMPILER_RT_SANITIZERS_TO_BUILD all
 list_replace(COMPILER_RT_SANITIZERS_TO_BUILD all "${ALL_SANITIZERS}")
 
 if (SANITIZER_COMMON_SUPPORTED_ARCH AND NOT LLVM_USE_SANITIZER AND
-    (OS_NAME MATCHES "Android|Darwin|Linux|FreeBSD|NetBSD|Fuchsia" OR
+    (OS_NAME MATCHES "Android|Darwin|Linux|FreeBSD|NetBSD|Fuchsia|SunOS" OR
     (OS_NAME MATCHES "Windows" AND (NOT MINGW AND NOT CYGWIN))))
   set(COMPILER_RT_HAS_SANITIZER_COMMON TRUE)
 else()
@@ -505,7 +505,7 @@ else()
   set(COMPILER_RT_HAS_ASAN FALSE)
 endif()
 
-if (OS_NAME MATCHES "Linux|FreeBSD|Windows|NetBSD")
+if (OS_NAME MATCHES "Linux|FreeBSD|Windows|NetBSD|SunOS")
   set(COMPILER_RT_ASAN_HAS_STATIC_RUNTIME TRUE)
 else()
   set(COMPILER_RT_ASAN_HAS_STATIC_RUNTIME FALSE)
@@ -556,7 +556,7 @@ else()
 endif()
 
 if (COMPILER_RT_HAS_SANITIZER_COMMON AND UBSAN_SUPPORTED_ARCH AND
-    OS_NAME MATCHES "Darwin|Linux|FreeBSD|NetBSD|Windows|Android|Fuchsia")
+    OS_NAME MATCHES "Darwin|Linux|FreeBSD|NetBSD|Windows|Android|Fuchsia|SunOS")
   set(COMPILER_RT_HAS_UBSAN TRUE)
 else()
   set(COMPILER_RT_HAS_UBSAN FALSE)

Modified: compiler-rt/trunk/lib/asan/CMakeLists.txt
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/asan/CMakeLists.txt?rev=321373&r1=321372&r2=321373&view=diff
==============================================================================
--- compiler-rt/trunk/lib/asan/CMakeLists.txt (original)
+++ compiler-rt/trunk/lib/asan/CMakeLists.txt Fri Dec 22 10:04:20 2017
@@ -175,6 +175,11 @@ else()
                                     EXTRA asan.syms.extra)
       set(VERSION_SCRIPT_FLAG
            -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")
+          list(APPEND VERSION_SCRIPT_FLAG -Wl,-z,gnu-version-script-compat)
+      endif()
       set_property(SOURCE
         ${CMAKE_CURRENT_BINARY_DIR}/dummy.cc
         APPEND PROPERTY

Modified: compiler-rt/trunk/lib/asan/scripts/asan_symbolize.py
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/asan/scripts/asan_symbolize.py?rev=321373&r1=321372&r2=321373&view=diff
==============================================================================
--- compiler-rt/trunk/lib/asan/scripts/asan_symbolize.py (original)
+++ compiler-rt/trunk/lib/asan/scripts/asan_symbolize.py Fri Dec 22 10:04:20 2017
@@ -280,7 +280,7 @@ def BreakpadSymbolizerFactory(binary):
 def SystemSymbolizerFactory(system, addr, binary, arch):
   if system == 'Darwin':
     return DarwinSymbolizer(addr, binary, arch)
-  elif system in ['Linux', 'FreeBSD', 'NetBSD']:
+  elif system in ['Linux', 'FreeBSD', 'NetBSD', 'SunOS']:
     return Addr2LineSymbolizer(binary)
 
 
@@ -370,7 +370,7 @@ class SymbolizationLoop(object):
       self.binary_name_filter = binary_name_filter
       self.dsym_hint_producer = dsym_hint_producer
       self.system = os.uname()[0]
-      if self.system not in ['Linux', 'Darwin', 'FreeBSD', 'NetBSD']:
+      if self.system not in ['Linux', 'Darwin', 'FreeBSD', 'NetBSD','SunOS']:
         raise Exception('Unknown system')
       self.llvm_symbolizers = {}
       self.last_llvm_symbolizer = None

Modified: compiler-rt/trunk/lib/sanitizer_common/CMakeLists.txt
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/sanitizer_common/CMakeLists.txt?rev=321373&r1=321372&r2=321373&view=diff
==============================================================================
--- compiler-rt/trunk/lib/sanitizer_common/CMakeLists.txt (original)
+++ compiler-rt/trunk/lib/sanitizer_common/CMakeLists.txt Fri Dec 22 10:04:20 2017
@@ -20,12 +20,15 @@ set(SANITIZER_SOURCES_NOTERMINATION
   sanitizer_platform_limits_linux.cc
   sanitizer_platform_limits_netbsd.cc
   sanitizer_platform_limits_posix.cc
+  sanitizer_platform_limits_solaris.cc
   sanitizer_posix.cc
   sanitizer_printf.cc
   sanitizer_procmaps_common.cc
   sanitizer_procmaps_freebsd.cc
   sanitizer_procmaps_linux.cc
   sanitizer_procmaps_mac.cc
+  sanitizer_procmaps_solaris.cc
+  sanitizer_solaris.cc
   sanitizer_stackdepot.cc
   sanitizer_stacktrace.cc
   sanitizer_stacktrace_printer.cc
@@ -40,7 +43,7 @@ set(SANITIZER_SOURCES_NOTERMINATION
   sanitizer_thread_registry.cc
   sanitizer_win.cc)
 
-if(UNIX AND NOT APPLE)
+if(UNIX AND NOT APPLE AND NOT OS_NAME MATCHES "SunOS")
   list(APPEND SANITIZER_SOURCES_NOTERMINATION
     sanitizer_linux_x86_64.S)
   list(APPEND SANITIZER_SOURCES_NOTERMINATION
@@ -122,6 +125,7 @@ set(SANITIZER_HEADERS
   sanitizer_platform_interceptors.h
   sanitizer_platform_limits_netbsd.h
   sanitizer_platform_limits_posix.h
+  sanitizer_platform_limits_solaris.h
   sanitizer_posix.h
   sanitizer_procmaps.h
   sanitizer_quarantine.h
@@ -216,6 +220,38 @@ add_compiler_rt_object_libraries(RTSanit
   CFLAGS ${SANITIZER_NO_WEAK_HOOKS_CFLAGS}
   DEFS ${SANITIZER_COMMON_DEFINITIONS})
 
+if(OS_NAME MATCHES "SunOS")
+  # Solaris ld doesn't support the non-standard GNU ld extension of adding
+  # __start_SECNAME and __stop_SECNAME labels to sections whose names are
+  # valid C identifiers.  Instead we add our own definitions for the
+  # __sancov_guards section.
+  add_compiler_rt_object_libraries(SancovBegin
+    ARCHS ${SANITIZER_COMMON_SUPPORTED_ARCH}
+    SOURCES sancov_begin.S
+    CFLAGS ${SANITIZER_CFLAGS}
+    DEFS ${SANITIZER_COMMON_DEFINITIONS})
+
+  add_compiler_rt_runtime(clang_rt.sancov_begin
+    STATIC
+    ARCHS ${SANITIZER_COMMON_SUPPORTED_ARCH}
+    OBJECT_LIBS SancovBegin
+    CFLAGS ${SANITIZER_CFLAGS}
+    DEFS ${SANITIZER_COMMON_DEFINITIONS})
+
+  add_compiler_rt_object_libraries(SancovEnd
+    ARCHS ${SANITIZER_COMMON_SUPPORTED_ARCH}
+    SOURCES sancov_end.S
+    CFLAGS ${SANITIZER_CFLAGS}
+    DEFS ${SANITIZER_COMMON_DEFINITIONS})
+
+  add_compiler_rt_runtime(clang_rt.sancov_end
+    STATIC
+    ARCHS ${SANITIZER_COMMON_SUPPORTED_ARCH}
+    OBJECT_LIBS SancovEnd
+    CFLAGS ${SANITIZER_CFLAGS}
+    DEFS ${SANITIZER_COMMON_DEFINITIONS})
+endif()
+
 if(WIN32)
   add_compiler_rt_object_libraries(SanitizerCommonWeakInterception
     ${SANITIZER_COMMON_SUPPORTED_OS}

Added: compiler-rt/trunk/lib/sanitizer_common/sancov_begin.S
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/sanitizer_common/sancov_begin.S?rev=321373&view=auto
==============================================================================
--- compiler-rt/trunk/lib/sanitizer_common/sancov_begin.S (added)
+++ compiler-rt/trunk/lib/sanitizer_common/sancov_begin.S Fri Dec 22 10:04:20 2017
@@ -0,0 +1,5 @@
+	.type		__start___sancov_guards, at object
+	.globl		__start___sancov_guards
+        .section        __sancov_guards,"aw", at progbits
+        .p2align        2
+__start___sancov_guards:

Added: compiler-rt/trunk/lib/sanitizer_common/sancov_end.S
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/sanitizer_common/sancov_end.S?rev=321373&view=auto
==============================================================================
--- compiler-rt/trunk/lib/sanitizer_common/sancov_end.S (added)
+++ compiler-rt/trunk/lib/sanitizer_common/sancov_end.S Fri Dec 22 10:04:20 2017
@@ -0,0 +1,5 @@
+	.type		__stop___sancov_guards, at object
+	.globl		__stop___sancov_guards
+        .section        __sancov_guards,"aw", at progbits
+        .p2align        2
+__stop___sancov_guards:




More information about the llvm-commits mailing list