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