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 loongarch64`" != "" ]; then
15 elif [ "`uname -a | grep -i mips64`" != "" ]; then
16 if [ "`lscpu | grep -i Little`" != "" ]; then
17 HOST_GOARCH
="mips64le"
21 elif [ "`uname -a | grep s390x`" != "" ]; then
24 elif [ "`uname -a | grep FreeBSD`" != "" ]; then
27 elif [ "`uname -a | grep NetBSD`" != "" ]; then
30 elif [ "`uname -a | grep Darwin`" != "" ]; then
32 if [ "`uname -a | grep x86_64`" != "" ]; then
34 elif [ "`uname -a | grep arm64`" != "" ]; then
37 elif [ "`uname -a | grep MINGW`" != "" ]; then
42 GOOS
=${GOOS:-$HOST_GOOS}
43 GOARCH
=${GOARCH:-$HOST_GOARCH}
44 SUFFIX
="${GOOS}_${GOARCH}"
48 ../rtl/tsan_external.cpp
50 ../rtl/tsan_interface_atomic.cpp
52 ../rtl/tsan_report.cpp
54 ../rtl/tsan_rtl_access.cpp
55 ../rtl/tsan_rtl_mutex.cpp
56 ../rtl/tsan_rtl_report.cpp
57 ../rtl/tsan_rtl_thread.cpp
58 ../rtl/tsan_rtl_proc.cpp
59 ../rtl/tsan_stack_trace.cpp
60 ../rtl/tsan_suppressions.cpp
62 ../rtl/tsan_vector_clock.cpp
63 ../../sanitizer_common/sanitizer_allocator.cpp
64 ../../sanitizer_common/sanitizer_common.cpp
65 ../../sanitizer_common/sanitizer_common_libcdep.cpp
66 ../../sanitizer_common/sanitizer_deadlock_detector2.cpp
67 ../../sanitizer_common/sanitizer_file.cpp
68 ../../sanitizer_common/sanitizer_flag_parser.cpp
69 ../../sanitizer_common/sanitizer_flags.cpp
70 ../../sanitizer_common/sanitizer_libc.cpp
71 ../../sanitizer_common/sanitizer_mutex.cpp
72 ../../sanitizer_common/sanitizer_printf.cpp
73 ../../sanitizer_common/sanitizer_suppressions.cpp
74 ../../sanitizer_common/sanitizer_thread_registry.cpp
75 ../../sanitizer_common/sanitizer_stack_store.cpp
76 ../../sanitizer_common/sanitizer_stackdepot.cpp
77 ../../sanitizer_common/sanitizer_stacktrace.cpp
78 ../../sanitizer_common/sanitizer_symbolizer.cpp
79 ../../sanitizer_common/sanitizer_symbolizer_report.cpp
80 ../../sanitizer_common/sanitizer_termination.cpp
83 if [ "$GOOS" = "linux" ]; then
84 OSCFLAGS
="-fPIC -Wno-maybe-uninitialized"
85 OSLDFLAGS
="-lpthread -fPIC -fpie"
88 ../rtl/tsan_platform_linux.cpp
89 ../../sanitizer_common/sanitizer_posix.cpp
90 ../../sanitizer_common/sanitizer_posix_libcdep.cpp
91 ../../sanitizer_common/sanitizer_procmaps_common.cpp
92 ../../sanitizer_common/sanitizer_procmaps_linux.cpp
93 ../../sanitizer_common/sanitizer_linux.cpp
94 ../../sanitizer_common/sanitizer_linux_libcdep.cpp
95 ../../sanitizer_common/sanitizer_stoptheworld_linux_libcdep.cpp
96 ../../sanitizer_common/sanitizer_stoptheworld_netbsd_libcdep.cpp
98 if [ "$GOARCH" = "ppc64le" ]; then
99 ARCHCFLAGS
="-m64 -mcpu=power8 -fno-function-sections"
100 elif [ "$GOARCH" = "amd64" ]; then
101 if [ "$GOAMD64" = "v3" ]; then
102 ARCHCFLAGS
="-m64 -msse4.2"
104 ARCHCFLAGS
="-m64 -msse3"
106 OSCFLAGS
="$OSCFLAGS -ffreestanding -Wno-unused-const-variable -Wno-unknown-warning-option"
107 elif [ "$GOARCH" = "arm64" ]; then
109 elif [ "$GOARCH" = "mips64le" ]; then
110 ARCHCFLAGS
="-mips64 -EL"
111 elif [ "$GOARCH" = "mips64" ]; then
112 ARCHCFLAGS
="-mips64 -EB"
113 elif [ "$GOARCH" = "s390x" ]; then
114 SRCS
="$SRCS ../../sanitizer_common/sanitizer_linux_s390.cpp"
117 elif [ "$GOOS" = "freebsd" ]; then
118 # The resulting object still depends on libc.
119 # We removed this dependency for Go runtime for other OSes,
120 # and we should remove it for FreeBSD as well, but there is no pressing need.
122 OSCFLAGS
="-fno-strict-aliasing -fPIC -Werror"
124 OSLDFLAGS
="-lpthread -fPIC -fpie"
127 ../rtl/tsan_platform_linux.cpp
128 ../../sanitizer_common/sanitizer_posix.cpp
129 ../../sanitizer_common/sanitizer_posix_libcdep.cpp
130 ../../sanitizer_common/sanitizer_procmaps_bsd.cpp
131 ../../sanitizer_common/sanitizer_procmaps_common.cpp
132 ../../sanitizer_common/sanitizer_linux.cpp
133 ../../sanitizer_common/sanitizer_linux_libcdep.cpp
134 ../../sanitizer_common/sanitizer_stoptheworld_linux_libcdep.cpp
135 ../../sanitizer_common/sanitizer_stoptheworld_netbsd_libcdep.cpp
137 elif [ "$GOOS" = "netbsd" ]; then
138 # The resulting object still depends on libc.
139 # We removed this dependency for Go runtime for other OSes,
140 # and we should remove it for NetBSD as well, but there is no pressing need.
142 OSCFLAGS
="-fno-strict-aliasing -fPIC -Werror"
144 OSLDFLAGS
="-lpthread -fPIC -fpie"
147 ../rtl/tsan_platform_linux.cpp
148 ../../sanitizer_common/sanitizer_posix.cpp
149 ../../sanitizer_common/sanitizer_posix_libcdep.cpp
150 ../../sanitizer_common/sanitizer_procmaps_bsd.cpp
151 ../../sanitizer_common/sanitizer_procmaps_common.cpp
152 ../../sanitizer_common/sanitizer_linux.cpp
153 ../../sanitizer_common/sanitizer_linux_libcdep.cpp
154 ../../sanitizer_common/sanitizer_netbsd.cpp
155 ../../sanitizer_common/sanitizer_stoptheworld_linux_libcdep.cpp
156 ../../sanitizer_common/sanitizer_stoptheworld_netbsd_libcdep.cpp
158 elif [ "$GOOS" = "darwin" ]; then
159 OSCFLAGS
="-fPIC -Wno-unused-const-variable -Wno-unknown-warning-option -mmacosx-version-min=10.7"
160 OSLDFLAGS
="-lpthread -fPIC -fpie -mmacosx-version-min=10.7"
163 ../rtl/tsan_platform_mac.cpp
164 ../../sanitizer_common/sanitizer_mac.cpp
165 ../../sanitizer_common/sanitizer_mac_libcdep.cpp
166 ../../sanitizer_common/sanitizer_posix.cpp
167 ../../sanitizer_common/sanitizer_posix_libcdep.cpp
168 ../../sanitizer_common/sanitizer_procmaps_mac.cpp
170 if [ "$GOARCH" = "amd64" ]; then
172 elif [ "$GOARCH" = "arm64" ]; then
175 elif [ "$GOOS" = "windows" ]; then
176 OSCFLAGS
="-Wno-error=attributes -Wno-attributes -Wno-unused-const-variable -Wno-unknown-warning-option"
181 ../rtl/tsan_platform_windows.cpp
182 ../../sanitizer_common/sanitizer_win.cpp
185 echo Unknown platform
190 IN_TMPDIR
=${IN_TMPDIR:-0}
193 if [ $IN_TMPDIR != "0" ]; then
194 DIR
=$
(mktemp
-qd /tmp
/gotsan.XXXXXXXXXX
)
203 SRCS
="$SRCS $ADD_SRCS"
205 echo "#line 1 \"$F\""
207 done > $DIR/gotsan.cpp
209 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"
210 DEBUG_FLAGS
="$FLAGS -DSANITIZER_DEBUG=1 -g"
211 FLAGS
="$FLAGS -DSANITIZER_DEBUG=0 -O3 -fomit-frame-pointer"
213 if [ "$DEBUG" = "" ]; then
214 # Do a build test with debug flags.
215 $CC $DIR/gotsan.cpp
-c -o $DIR/race_debug_
$SUFFIX.syso
$DEBUG_FLAGS $CFLAGS
220 if [ "$SILENT" != "1" ]; then
221 echo $CC gotsan.cpp
-c -o $DIR/race_
$SUFFIX.syso
$FLAGS $CFLAGS
223 $CC $DIR/gotsan.cpp
-c -o $DIR/race_
$SUFFIX.syso
$FLAGS $CFLAGS
225 $CC $OSCFLAGS $ARCHCFLAGS test.c
$DIR/race_
$SUFFIX.syso
-g -o $DIR/test $OSLDFLAGS $LDFLAGS
227 # Verify that no libc specific code is present.
228 if [ "$DEPENDS_ON_LIBC" != "1" ]; then
229 if nm
$DIR/race_
$SUFFIX.syso |
grep -q __libc_
; then
230 printf -- '%s seems to link to libc\n' "race_$SUFFIX.syso"
235 if [ "$SKIP_TEST" = "1" ]; then
239 if [ "`uname -a | grep NetBSD`" != "" ]; then
240 # Turn off ASLR in the test binary.
241 /usr
/sbin
/paxctl
+a
$DIR/test
243 export GORACE
="exitcode=0 atexit_sleep_ms=0"
244 if [ "$SILENT" != "1" ]; then
247 $DIR/test 2>/dev
/null