1#!/bin/sh 2 3set -e 4 5SRCS=" 6 tsan_go.cc 7 ../rtl/tsan_clock.cc 8 ../rtl/tsan_flags.cc 9 ../rtl/tsan_interface_atomic.cc 10 ../rtl/tsan_md5.cc 11 ../rtl/tsan_mutex.cc 12 ../rtl/tsan_report.cc 13 ../rtl/tsan_rtl.cc 14 ../rtl/tsan_rtl_mutex.cc 15 ../rtl/tsan_rtl_report.cc 16 ../rtl/tsan_rtl_thread.cc 17 ../rtl/tsan_stack_trace.cc 18 ../rtl/tsan_stat.cc 19 ../rtl/tsan_suppressions.cc 20 ../rtl/tsan_sync.cc 21 ../../sanitizer_common/sanitizer_allocator.cc 22 ../../sanitizer_common/sanitizer_common.cc 23 ../../sanitizer_common/sanitizer_deadlock_detector2.cc 24 ../../sanitizer_common/sanitizer_flag_parser.cc 25 ../../sanitizer_common/sanitizer_flags.cc 26 ../../sanitizer_common/sanitizer_libc.cc 27 ../../sanitizer_common/sanitizer_persistent_allocator.cc 28 ../../sanitizer_common/sanitizer_printf.cc 29 ../../sanitizer_common/sanitizer_suppressions.cc 30 ../../sanitizer_common/sanitizer_thread_registry.cc 31 ../../sanitizer_common/sanitizer_stackdepot.cc 32 ../../sanitizer_common/sanitizer_stacktrace.cc 33 ../../sanitizer_common/sanitizer_symbolizer.cc 34" 35 36if [ "`uname -a | grep Linux`" != "" ]; then 37 SUFFIX="linux_amd64" 38 OSCFLAGS="-fPIC -ffreestanding -Wno-maybe-uninitialized -Wno-unused-const-variable -Werror -Wno-unknown-warning-option" 39 OSLDFLAGS="-lpthread -fPIC -fpie" 40 SRCS=" 41 $SRCS 42 ../rtl/tsan_platform_linux.cc 43 ../../sanitizer_common/sanitizer_posix.cc 44 ../../sanitizer_common/sanitizer_posix_libcdep.cc 45 ../../sanitizer_common/sanitizer_procmaps_common.cc 46 ../../sanitizer_common/sanitizer_procmaps_linux.cc 47 ../../sanitizer_common/sanitizer_linux.cc 48 ../../sanitizer_common/sanitizer_stoptheworld_linux_libcdep.cc 49 " 50elif [ "`uname -a | grep FreeBSD`" != "" ]; then 51 SUFFIX="freebsd_amd64" 52 OSCFLAGS="-fno-strict-aliasing -fPIC -Werror" 53 OSLDFLAGS="-lpthread -fPIC -fpie" 54 SRCS=" 55 $SRCS 56 ../rtl/tsan_platform_linux.cc 57 ../../sanitizer_common/sanitizer_posix.cc 58 ../../sanitizer_common/sanitizer_posix_libcdep.cc 59 ../../sanitizer_common/sanitizer_procmaps_common.cc 60 ../../sanitizer_common/sanitizer_procmaps_freebsd.cc 61 ../../sanitizer_common/sanitizer_linux.cc 62 ../../sanitizer_common/sanitizer_stoptheworld_linux_libcdep.cc 63 " 64elif [ "`uname -a | grep Darwin`" != "" ]; then 65 SUFFIX="darwin_amd64" 66 OSCFLAGS="-fPIC -Wno-unused-const-variable -Wno-unknown-warning-option" 67 OSLDFLAGS="-lpthread -fPIC -fpie" 68 SRCS=" 69 $SRCS 70 ../rtl/tsan_platform_mac.cc 71 ../../sanitizer_common/sanitizer_mac.cc 72 ../../sanitizer_common/sanitizer_posix.cc 73 ../../sanitizer_common/sanitizer_posix_libcdep.cc 74 ../../sanitizer_common/sanitizer_procmaps_mac.cc 75 " 76elif [ "`uname -a | grep MINGW`" != "" ]; then 77 SUFFIX="windows_amd64" 78 OSCFLAGS="-Wno-error=attributes -Wno-attributes -Wno-unused-const-variable -Wno-unknown-warning-option" 79 OSLDFLAGS="" 80 SRCS=" 81 $SRCS 82 ../rtl/tsan_platform_windows.cc 83 ../../sanitizer_common/sanitizer_win.cc 84 " 85else 86 echo Unknown platform 87 exit 1 88fi 89 90CC=${CC:-gcc} 91IN_TMPDIR=${IN_TMPDIR:-0} 92SILENT=${SILENT:-0} 93 94if [ $IN_TMPDIR != "0" ]; then 95 DIR=$(mktemp -qd /tmp/gotsan.XXXXXXXXXX) 96 cleanup() { 97 rm -rf $DIR 98 } 99 trap cleanup EXIT 100else 101 DIR=. 102fi 103 104SRCS="$SRCS $ADD_SRCS" 105 106rm -f $DIR/gotsan.cc 107for F in $SRCS; do 108 cat $F >> $DIR/gotsan.cc 109done 110 111FLAGS=" -I../rtl -I../.. -I../../sanitizer_common -I../../../include -std=c++11 -m64 -Wall -fno-exceptions -fno-rtti -DSANITIZER_GO -DSANITIZER_DEADLOCK_DETECTOR_VERSION=2 $OSCFLAGS" 112if [ "$DEBUG" = "" ]; then 113 FLAGS="$FLAGS -DSANITIZER_DEBUG=0 -O3 -msse3 -fomit-frame-pointer" 114else 115 FLAGS="$FLAGS -DSANITIZER_DEBUG=1 -g" 116fi 117 118if [ "$SILENT" != "1" ]; then 119 echo $CC gotsan.cc -c -o $DIR/race_$SUFFIX.syso $FLAGS $CFLAGS 120fi 121$CC $DIR/gotsan.cc -c -o $DIR/race_$SUFFIX.syso $FLAGS $CFLAGS 122 123$CC test.c $DIR/race_$SUFFIX.syso -m64 -o $DIR/test $OSLDFLAGS 124 125export GORACE="exitcode=0 atexit_sleep_ms=0" 126if [ "$SILENT" != "1" ]; then 127 $DIR/test 128else 129 $DIR/test 2>/dev/null 130fi 131