5 if [ "`uname -a | grep Linux`" != "" ]; then
7 if [ "`uname -a | grep ppc64le`" != "" ]; then
9 elif [ "`uname -a | grep x86_64`" != "" ]; then
11 elif [ "`uname -a | grep aarch64`" != "" ]; then
13 elif [ "`uname -a | grep -i mips64`" != "" ]; then
14 if [ "`lscpu | grep -i Little`" != "" ]; then
15 HOST_GOARCH
="mips64le"
19 elif [ "`uname -a | grep s390x`" != "" ]; then
22 elif [ "`uname -a | grep FreeBSD`" != "" ]; then
25 elif [ "`uname -a | grep NetBSD`" != "" ]; then
28 elif [ "`uname -a | grep Darwin`" != "" ]; then
30 if [ "`uname -a | grep x86_64`" != "" ]; then
32 elif [ "`uname -a | grep arm64`" != "" ]; then
35 elif [ "`uname -a | grep MINGW`" != "" ]; then
40 GOOS
=${GOOS:-$HOST_GOOS}
41 GOARCH
=${GOARCH:-$HOST_GOARCH}
42 SUFFIX
="${GOOS}_${GOARCH}"
46 ../rtl/tsan_external.cpp
48 ../rtl/tsan_interface_atomic.cpp
50 ../rtl/tsan_report.cpp
52 ../rtl/tsan_rtl_access.cpp
53 ../rtl/tsan_rtl_mutex.cpp
54 ../rtl/tsan_rtl_report.cpp
55 ../rtl/tsan_rtl_thread.cpp
56 ../rtl/tsan_rtl_proc.cpp
57 ../rtl/tsan_stack_trace.cpp
58 ../rtl/tsan_suppressions.cpp
60 ../rtl/tsan_vector_clock.cpp
61 ../../sanitizer_common/sanitizer_allocator.cpp
62 ../../sanitizer_common/sanitizer_common.cpp
63 ../../sanitizer_common/sanitizer_common_libcdep.cpp
64 ../../sanitizer_common/sanitizer_deadlock_detector2.cpp
65 ../../sanitizer_common/sanitizer_file.cpp
66 ../../sanitizer_common/sanitizer_flag_parser.cpp
67 ../../sanitizer_common/sanitizer_flags.cpp
68 ../../sanitizer_common/sanitizer_libc.cpp
69 ../../sanitizer_common/sanitizer_mutex.cpp
70 ../../sanitizer_common/sanitizer_printf.cpp
71 ../../sanitizer_common/sanitizer_suppressions.cpp
72 ../../sanitizer_common/sanitizer_thread_registry.cpp
73 ../../sanitizer_common/sanitizer_stack_store.cpp
74 ../../sanitizer_common/sanitizer_stackdepot.cpp
75 ../../sanitizer_common/sanitizer_stacktrace.cpp
76 ../../sanitizer_common/sanitizer_symbolizer.cpp
77 ../../sanitizer_common/sanitizer_symbolizer_report.cpp
78 ../../sanitizer_common/sanitizer_termination.cpp
81 if [ "$GOOS" = "linux" ]; then
82 OSCFLAGS
="-fPIC -Wno-maybe-uninitialized"
83 OSLDFLAGS
="-lpthread -fPIC -fpie"
86 ../rtl/tsan_platform_linux.cpp
87 ../../sanitizer_common/sanitizer_posix.cpp
88 ../../sanitizer_common/sanitizer_posix_libcdep.cpp
89 ../../sanitizer_common/sanitizer_procmaps_common.cpp
90 ../../sanitizer_common/sanitizer_procmaps_linux.cpp
91 ../../sanitizer_common/sanitizer_linux.cpp
92 ../../sanitizer_common/sanitizer_linux_libcdep.cpp
93 ../../sanitizer_common/sanitizer_stoptheworld_linux_libcdep.cpp
94 ../../sanitizer_common/sanitizer_stoptheworld_netbsd_libcdep.cpp
96 if [ "$GOARCH" = "ppc64le" ]; then
97 ARCHCFLAGS
="-m64 -mcpu=power8 -fno-function-sections"
98 elif [ "$GOARCH" = "amd64" ]; then
99 if [ "$GOAMD64" = "v3" ]; then
100 ARCHCFLAGS
="-m64 -msse4.2"
102 ARCHCFLAGS
="-m64 -msse3"
104 OSCFLAGS
="$OSCFLAGS -ffreestanding -Wno-unused-const-variable -Wno-unknown-warning-option"
105 elif [ "$GOARCH" = "arm64" ]; then
107 elif [ "$GOARCH" = "mips64le" ]; then
108 ARCHCFLAGS
="-mips64 -EL"
109 elif [ "$GOARCH" = "mips64" ]; then
110 ARCHCFLAGS
="-mips64 -EB"
111 elif [ "$GOARCH" = "s390x" ]; then
112 SRCS
="$SRCS ../../sanitizer_common/sanitizer_linux_s390.cpp"
115 elif [ "$GOOS" = "freebsd" ]; then
116 # The resulting object still depends on libc.
117 # We removed this dependency for Go runtime for other OSes,
118 # and we should remove it for FreeBSD as well, but there is no pressing need.
120 OSCFLAGS
="-fno-strict-aliasing -fPIC -Werror"
122 OSLDFLAGS
="-lpthread -fPIC -fpie"
125 ../rtl/tsan_platform_linux.cpp
126 ../../sanitizer_common/sanitizer_posix.cpp
127 ../../sanitizer_common/sanitizer_posix_libcdep.cpp
128 ../../sanitizer_common/sanitizer_procmaps_bsd.cpp
129 ../../sanitizer_common/sanitizer_procmaps_common.cpp
130 ../../sanitizer_common/sanitizer_linux.cpp
131 ../../sanitizer_common/sanitizer_linux_libcdep.cpp
132 ../../sanitizer_common/sanitizer_stoptheworld_linux_libcdep.cpp
133 ../../sanitizer_common/sanitizer_stoptheworld_netbsd_libcdep.cpp
135 elif [ "$GOOS" = "netbsd" ]; then
136 # The resulting object still depends on libc.
137 # We removed this dependency for Go runtime for other OSes,
138 # and we should remove it for NetBSD as well, but there is no pressing need.
140 OSCFLAGS
="-fno-strict-aliasing -fPIC -Werror"
142 OSLDFLAGS
="-lpthread -fPIC -fpie"
145 ../rtl/tsan_platform_linux.cpp
146 ../../sanitizer_common/sanitizer_posix.cpp
147 ../../sanitizer_common/sanitizer_posix_libcdep.cpp
148 ../../sanitizer_common/sanitizer_procmaps_bsd.cpp
149 ../../sanitizer_common/sanitizer_procmaps_common.cpp
150 ../../sanitizer_common/sanitizer_linux.cpp
151 ../../sanitizer_common/sanitizer_linux_libcdep.cpp
152 ../../sanitizer_common/sanitizer_netbsd.cpp
153 ../../sanitizer_common/sanitizer_stoptheworld_linux_libcdep.cpp
154 ../../sanitizer_common/sanitizer_stoptheworld_netbsd_libcdep.cpp
156 elif [ "$GOOS" = "darwin" ]; then
157 OSCFLAGS
="-fPIC -Wno-unused-const-variable -Wno-unknown-warning-option -mmacosx-version-min=10.7"
158 OSLDFLAGS
="-lpthread -fPIC -fpie -mmacosx-version-min=10.7"
161 ../rtl/tsan_platform_mac.cpp
162 ../../sanitizer_common/sanitizer_mac.cpp
163 ../../sanitizer_common/sanitizer_mac_libcdep.cpp
164 ../../sanitizer_common/sanitizer_posix.cpp
165 ../../sanitizer_common/sanitizer_posix_libcdep.cpp
166 ../../sanitizer_common/sanitizer_procmaps_mac.cpp
168 if [ "$GOARCH" = "amd64" ]; then
170 elif [ "$GOARCH" = "arm64" ]; then
173 elif [ "$GOOS" = "windows" ]; then
174 OSCFLAGS
="-Wno-error=attributes -Wno-attributes -Wno-unused-const-variable -Wno-unknown-warning-option"
179 ../rtl/tsan_platform_windows.cpp
180 ../../sanitizer_common/sanitizer_win.cpp
183 echo Unknown platform
188 IN_TMPDIR
=${IN_TMPDIR:-0}
191 if [ $IN_TMPDIR != "0" ]; then
192 DIR
=$
(mktemp
-qd /tmp
/gotsan.XXXXXXXXXX
)
201 SRCS
="$SRCS $ADD_SRCS"
203 echo "#line 1 \"$F\""
205 done > $DIR/gotsan.cpp
207 FLAGS
=" -I../rtl -I../.. -I../../sanitizer_common -I../../../include -std=c++17 -Wall -fno-exceptions -fno-rtti -DSANITIZER_GO=1 -DSANITIZER_DEADLOCK_DETECTOR_VERSION=2 $OSCFLAGS $ARCHCFLAGS $EXTRA_CFLAGS"
208 DEBUG_FLAGS
="$FLAGS -DSANITIZER_DEBUG=1 -g"
209 FLAGS
="$FLAGS -DSANITIZER_DEBUG=0 -O3 -fomit-frame-pointer"
211 if [ "$DEBUG" = "" ]; then
212 # Do a build test with debug flags.
213 $CC $DIR/gotsan.cpp
-c -o $DIR/race_debug_
$SUFFIX.syso
$DEBUG_FLAGS $CFLAGS
218 if [ "$SILENT" != "1" ]; then
219 echo $CC gotsan.cpp
-c -o $DIR/race_
$SUFFIX.syso
$FLAGS $CFLAGS
221 $CC $DIR/gotsan.cpp
-c -o $DIR/race_
$SUFFIX.syso
$FLAGS $CFLAGS
223 $CC $OSCFLAGS $ARCHCFLAGS test.c
$DIR/race_
$SUFFIX.syso
-g -o $DIR/test $OSLDFLAGS $LDFLAGS
225 # Verify that no libc specific code is present.
226 if [ "$DEPENDS_ON_LIBC" != "1" ]; then
227 if nm
$DIR/race_
$SUFFIX.syso |
grep -q __libc_
; then
228 printf -- '%s seems to link to libc\n' "race_$SUFFIX.syso"
233 if [ "$SKIP_TEST" = "1" ]; then
237 if [ "`uname -a | grep NetBSD`" != "" ]; then
238 # Turn off ASLR in the test binary.
239 /usr
/sbin
/paxctl
+a
$DIR/test
241 export GORACE
="exitcode=0 atexit_sleep_ms=0"
242 if [ "$SILENT" != "1" ]; then
245 $DIR/test 2>/dev
/null