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