Index: compiler-rt/trunk/lib/tsan/CMakeLists.txt =================================================================== --- compiler-rt/trunk/lib/tsan/CMakeLists.txt +++ compiler-rt/trunk/lib/tsan/CMakeLists.txt @@ -158,6 +158,15 @@ VERBATIM) elseif(arch STREQUAL "aarch64") add_asm_sources(TSAN_ASM_SOURCES rtl/tsan_rtl_aarch64.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}" + 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) elseif(arch MATCHES "powerpc64|powerpc64le") add_asm_sources(TSAN_ASM_SOURCES rtl/tsan_rtl_ppc64.S) # Sanity check for Go runtime. Index: compiler-rt/trunk/lib/tsan/go/buildgo.sh =================================================================== --- compiler-rt/trunk/lib/tsan/go/buildgo.sh +++ compiler-rt/trunk/lib/tsan/go/buildgo.sh @@ -55,13 +55,19 @@ " if [ "`uname -a | grep ppc64le`" != "" ]; then SUFFIX="linux_ppc64le" + ARCHCFLAGS="-m64" elif [ "`uname -a | grep x86_64`" != "" ]; then SUFFIX="linux_amd64" + ARCHCFLAGS="-m64" OSCFLAGS="$OSCFLAGS -ffreestanding -Wno-unused-const-variable -Werror -Wno-unknown-warning-option" + elif [ "`uname -a | grep aarch64`" != "" ]; then + SUFFIX="linux_arm64" + ARCHCFLAGS="" fi elif [ "`uname -a | grep FreeBSD`" != "" ]; then SUFFIX="freebsd_amd64" OSCFLAGS="-fno-strict-aliasing -fPIC -Werror" + ARCHCFLAGS="-m64" OSLDFLAGS="-lpthread -fPIC -fpie" SRCS=" $SRCS @@ -77,6 +83,7 @@ elif [ "`uname -a | grep NetBSD`" != "" ]; then SUFFIX="netbsd_amd64" OSCFLAGS="-fno-strict-aliasing -fPIC -Werror" + ARCHCFLAGS="-m64" OSLDFLAGS="-lpthread -fPIC -fpie" SRCS=" $SRCS @@ -92,6 +99,7 @@ elif [ "`uname -a | grep Darwin`" != "" ]; then SUFFIX="darwin_amd64" OSCFLAGS="-fPIC -Wno-unused-const-variable -Wno-unknown-warning-option -mmacosx-version-min=10.7" + ARCHCFLAGS="-m64" OSLDFLAGS="-lpthread -fPIC -fpie -mmacosx-version-min=10.7" SRCS=" $SRCS @@ -104,6 +112,7 @@ elif [ "`uname -a | grep MINGW`" != "" ]; then SUFFIX="windows_amd64" OSCFLAGS="-Wno-error=attributes -Wno-attributes -Wno-unused-const-variable -Wno-unknown-warning-option" + ARCHCFLAGS="-m64" OSLDFLAGS="" SRCS=" $SRCS @@ -136,7 +145,7 @@ cat $F >> $DIR/gotsan.cc done -FLAGS=" -I../rtl -I../.. -I../../sanitizer_common -I../../../include -std=c++11 -m64 -Wall -fno-exceptions -fno-rtti -DSANITIZER_GO=1 -DSANITIZER_DEADLOCK_DETECTOR_VERSION=2 $OSCFLAGS" +FLAGS=" -I../rtl -I../.. -I../../sanitizer_common -I../../../include -std=c++11 -Wall -fno-exceptions -fno-rtti -DSANITIZER_GO=1 -DSANITIZER_DEADLOCK_DETECTOR_VERSION=2 $OSCFLAGS $ARCHCFLAGS" if [ "$DEBUG" = "" ]; then FLAGS="$FLAGS -DSANITIZER_DEBUG=0 -O3 -fomit-frame-pointer" if [ "$SUFFIX" = "linux_ppc64le" ]; then @@ -153,7 +162,7 @@ fi $CC $DIR/gotsan.cc -c -o $DIR/race_$SUFFIX.syso $FLAGS $CFLAGS -$CC $OSCFLAGS test.c $DIR/race_$SUFFIX.syso -m64 -g -o $DIR/test $OSLDFLAGS $LDFLAGS +$CC $OSCFLAGS $ARCHCFLAGS test.c $DIR/race_$SUFFIX.syso -g -o $DIR/test $OSLDFLAGS $LDFLAGS export GORACE="exitcode=0 atexit_sleep_ms=0" if [ "$SILENT" != "1" ]; then Index: compiler-rt/trunk/lib/tsan/rtl/tsan_platform.h =================================================================== --- compiler-rt/trunk/lib/tsan/rtl/tsan_platform.h +++ compiler-rt/trunk/lib/tsan/rtl/tsan_platform.h @@ -458,6 +458,32 @@ static const uptr kAppMemEnd = 0x00e000000000ull; }; +#elif SANITIZER_GO && defined(__aarch64__) + +/* Go on linux/aarch64 (48-bit VMA) +0000 0000 1000 - 0000 1000 0000: executable +0000 1000 0000 - 00c0 0000 0000: - +00c0 0000 0000 - 00e0 0000 0000: heap +00e0 0000 0000 - 2000 0000 0000: - +2000 0000 0000 - 3000 0000 0000: shadow +3000 0000 0000 - 3000 0000 0000: - +3000 0000 0000 - 4000 0000 0000: metainfo (memory blocks and sync objects) +4000 0000 0000 - 6000 0000 0000: - +6000 0000 0000 - 6200 0000 0000: traces +6200 0000 0000 - 8000 0000 0000: - +*/ + +struct Mapping48 { + static const uptr kMetaShadowBeg = 0x300000000000ull; + static const uptr kMetaShadowEnd = 0x400000000000ull; + static const uptr kTraceMemBeg = 0x600000000000ull; + static const uptr kTraceMemEnd = 0x620000000000ull; + static const uptr kShadowBeg = 0x200000000000ull; + static const uptr kShadowEnd = 0x300000000000ull; + static const uptr kAppMemBeg = 0x000000001000ull; + static const uptr kAppMemEnd = 0x00e000000000ull; +}; + // Indicates the runtime will define the memory regions at runtime. #define TSAN_RUNTIME_VMA 1 @@ -525,8 +551,10 @@ uptr MappingArchImpl(void) { #if defined(__aarch64__) && !defined(__APPLE__) switch (vmaSize) { +#if !SANITIZER_GO case 39: return MappingImpl(); case 42: return MappingImpl(); +#endif case 48: return MappingImpl(); } DCHECK(0); @@ -682,8 +710,10 @@ bool IsAppMem(uptr mem) { #if defined(__aarch64__) && !defined(__APPLE__) switch (vmaSize) { +#if !SANITIZER_GO case 39: return IsAppMemImpl(mem); case 42: return IsAppMemImpl(mem); +#endif case 48: return IsAppMemImpl(mem); } DCHECK(0); @@ -713,8 +743,10 @@ bool IsShadowMem(uptr mem) { #if defined(__aarch64__) && !defined(__APPLE__) switch (vmaSize) { +#if !SANITIZER_GO case 39: return IsShadowMemImpl(mem); case 42: return IsShadowMemImpl(mem); +#endif case 48: return IsShadowMemImpl(mem); } DCHECK(0); @@ -744,8 +776,10 @@ bool IsMetaMem(uptr mem) { #if defined(__aarch64__) && !defined(__APPLE__) switch (vmaSize) { +#if !SANITIZER_GO case 39: return IsMetaMemImpl(mem); case 42: return IsMetaMemImpl(mem); +#endif case 48: return IsMetaMemImpl(mem); } DCHECK(0); @@ -785,8 +819,10 @@ uptr MemToShadow(uptr x) { #if defined(__aarch64__) && !defined(__APPLE__) switch (vmaSize) { +#if !SANITIZER_GO case 39: return MemToShadowImpl(x); case 42: return MemToShadowImpl(x); +#endif case 48: return MemToShadowImpl(x); } DCHECK(0); @@ -828,8 +864,10 @@ u32 *MemToMeta(uptr x) { #if defined(__aarch64__) && !defined(__APPLE__) switch (vmaSize) { +#if !SANITIZER_GO case 39: return MemToMetaImpl(x); case 42: return MemToMetaImpl(x); +#endif case 48: return MemToMetaImpl(x); } DCHECK(0); @@ -884,8 +922,10 @@ uptr ShadowToMem(uptr s) { #if defined(__aarch64__) && !defined(__APPLE__) switch (vmaSize) { +#if !SANITIZER_GO case 39: return ShadowToMemImpl(s); case 42: return ShadowToMemImpl(s); +#endif case 48: return ShadowToMemImpl(s); } DCHECK(0); @@ -923,8 +963,10 @@ uptr GetThreadTrace(int tid) { #if defined(__aarch64__) && !defined(__APPLE__) switch (vmaSize) { +#if !SANITIZER_GO case 39: return GetThreadTraceImpl(tid); case 42: return GetThreadTraceImpl(tid); +#endif case 48: return GetThreadTraceImpl(tid); } DCHECK(0); @@ -957,8 +999,10 @@ uptr GetThreadTraceHeader(int tid) { #if defined(__aarch64__) && !defined(__APPLE__) switch (vmaSize) { +#if !SANITIZER_GO case 39: return GetThreadTraceHeaderImpl(tid); case 42: return GetThreadTraceHeaderImpl(tid); +#endif case 48: return GetThreadTraceHeaderImpl(tid); } DCHECK(0); Index: compiler-rt/trunk/lib/tsan/rtl/tsan_platform_linux.cc =================================================================== --- compiler-rt/trunk/lib/tsan/rtl/tsan_platform_linux.cc +++ compiler-rt/trunk/lib/tsan/rtl/tsan_platform_linux.cc @@ -212,11 +212,19 @@ vmaSize = (MostSignificantSetBitIndex(GET_CURRENT_FRAME()) + 1); #if defined(__aarch64__) +# if !SANITIZER_GO if (vmaSize != 39 && vmaSize != 42 && vmaSize != 48) { Printf("FATAL: ThreadSanitizer: unsupported VMA range\n"); Printf("FATAL: Found %zd - Supported 39, 42 and 48\n", vmaSize); Die(); } +#else + if (vmaSize != 48) { + Printf("FATAL: ThreadSanitizer: unsupported VMA range\n"); + Printf("FATAL: Found %zd - Supported 48\n", vmaSize); + Die(); + } +#endif #elif defined(__powerpc64__) # if !SANITIZER_GO if (vmaSize != 44 && vmaSize != 46 && vmaSize != 47) {