[TSan] Add SystemZ SANITIZER_GO support
authorIlya Leoshkevich <iii@linux.ibm.com>
Fri, 2 Jul 2021 00:49:30 +0000 (02:49 +0200)
committerIlya Leoshkevich <iii@linux.ibm.com>
Thu, 15 Jul 2021 10:18:48 +0000 (12:18 +0200)
Define the address ranges (similar to the C/C++ ones, but with the heap
range merged into the app range) and enable the sanity check.

Reviewed By: dvyukov

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

compiler-rt/lib/tsan/CMakeLists.txt
compiler-rt/lib/tsan/go/buildgo.sh
compiler-rt/lib/tsan/rtl/tsan_platform.h
compiler-rt/test/tsan/CMakeLists.txt

index e0d3d6a..c1fa34f 100644 (file)
@@ -223,6 +223,16 @@ else()
       add_asm_sources(TSAN_ASM_SOURCES
         rtl/tsan_rtl_s390x.S
         )
+      # Sanity check for Go runtime.
+      set(BUILDGO_SCRIPT ${CMAKE_CURRENT_SOURCE_DIR}/go/buildgo.sh)
+      add_custom_target(GotsanRuntimeCheck
+       COMMAND env "CC=${CMAKE_C_COMPILER} ${CMAKE_C_COMPILER_ARG1}"
+               EXTRA_CFLAGS=${EXTRA_CFLAGS}
+               IN_TMPDIR=1 SILENT=1 ${BUILDGO_SCRIPT}
+       DEPENDS clang_rt.tsan-${arch} ${BUILDGO_SCRIPT}
+       WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/go
+       COMMENT "Checking TSan Go runtime..."
+       VERBATIM)
     else()
       set(TSAN_ASM_SOURCES)
     endif()
index 0902d10..87f2f3b 100755 (executable)
@@ -72,6 +72,10 @@ if [ "`uname -a | grep Linux`" != "" ]; then
                        SUFFIX="linux_mips64"
                        ARCHCFLAGS="-mips64 -EB"
                fi
+       elif [ "`uname -a | grep s390x`" != "" ]; then
+               SRCS="$SRCS ../../sanitizer_common/sanitizer_linux_s390.cpp"
+               SUFFIX="linux_s390x"
+               ARCHCFLAGS=""
        fi
 elif [ "`uname -a | grep FreeBSD`" != "" ]; then
        # The resulting object still depends on libc.
index 1893ca3..8bd218e 100644 (file)
@@ -560,6 +560,28 @@ struct Mapping47 {
 
 #define TSAN_RUNTIME_VMA 1
 
+#elif SANITIZER_GO && defined(__s390x__)
+/*
+Go on linux/s390x
+0000 0000 1000 - 1000 0000 0000: executable and heap - 16 TiB
+1000 0000 0000 - 4000 0000 0000: -
+4000 0000 0000 - 8000 0000 0000: shadow - 64TiB (4 * app)
+8000 0000 0000 - 9000 0000 0000: -
+9000 0000 0000 - 9800 0000 0000: metainfo - 8TiB (0.5 * app)
+9800 0000 0000 - a000 0000 0000: -
+a000 0000 0000 - b000 0000 0000: traces - 16TiB (max history * 128k threads)
+*/
+struct Mapping {
+  static const uptr kMetaShadowBeg = 0x900000000000ull;
+  static const uptr kMetaShadowEnd = 0x980000000000ull;
+  static const uptr kTraceMemBeg   = 0xa00000000000ull;
+  static const uptr kTraceMemEnd   = 0xb00000000000ull;
+  static const uptr kShadowBeg     = 0x400000000000ull;
+  static const uptr kShadowEnd     = 0x800000000000ull;
+  static const uptr kAppMemBeg     = 0x000000001000ull;
+  static const uptr kAppMemEnd     = 0x100000000000ull;
+};
+
 #else
 # error "Unknown platform"
 #endif
index c8f8eba..318a91f 100644 (file)
@@ -1,7 +1,7 @@
 set(TSAN_LIT_SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR})
 
 set(TSAN_TEST_DEPS ${SANITIZER_COMMON_LIT_TEST_DEPS})
-if(${COMPILER_RT_DEFAULT_TARGET_ARCH} MATCHES "x86_64")
+if(${COMPILER_RT_DEFAULT_TARGET_ARCH} MATCHES "(x86_64|s390x)")
   list(APPEND TSAN_TEST_DEPS GotsanRuntimeCheck)
 endif()
 if(NOT COMPILER_RT_STANDALONE_BUILD)