[RISCV][VLOPT] Add vector narrowing integer right shift instructions to isSupportedIn...
[llvm-project.git] / compiler-rt / lib / tsan / go / buildgo.sh
blob78ba41a0bdc6d612a9035fbcd86ff2da9a356f61
1 #!/bin/sh
3 set -e
5 if [ "`uname -a | grep Linux`" != "" ]; then
6 HOST_GOOS="linux"
7 if [ "`uname -a | grep ppc64le`" != "" ]; then
8 HOST_GOARCH="ppc64le"
9 elif [ "`uname -a | grep x86_64`" != "" ]; then
10 HOST_GOARCH="amd64"
11 elif [ "`uname -a | grep aarch64`" != "" ]; then
12 HOST_GOARCH="arm64"
13 elif [ "`uname -a | grep loongarch64`" != "" ]; then
14 HOST_GOARCH="loong64"
15 elif [ "`uname -a | grep -i mips64`" != "" ]; then
16 if [ "`lscpu | grep -i Little`" != "" ]; then
17 HOST_GOARCH="mips64le"
18 else
19 HOST_GOARCH="mips64"
21 elif [ "`uname -a | grep s390x`" != "" ]; then
22 HOST_GOARCH="s390x"
24 elif [ "`uname -a | grep FreeBSD`" != "" ]; then
25 HOST_GOOS="freebsd"
26 HOST_GOARCH="amd64"
27 elif [ "`uname -a | grep NetBSD`" != "" ]; then
28 HOST_GOOS="netbsd"
29 HOST_GOARCH="amd64"
30 elif [ "`uname -a | grep Darwin`" != "" ]; then
31 HOST_GOOS="darwin"
32 if [ "`uname -a | grep x86_64`" != "" ]; then
33 HOST_GOARCH="amd64"
34 elif [ "`uname -a | grep arm64`" != "" ]; then
35 HOST_GOARCH="arm64"
37 elif [ "`uname -a | grep MINGW`" != "" ]; then
38 HOST_GOOS="windows"
39 HOST_GOARCH="amd64"
42 GOOS=${GOOS:-$HOST_GOOS}
43 GOARCH=${GOARCH:-$HOST_GOARCH}
44 SUFFIX="${GOOS}_${GOARCH}"
46 SRCS="
47 tsan_go.cpp
48 ../rtl/tsan_external.cpp
49 ../rtl/tsan_flags.cpp
50 ../rtl/tsan_interface_atomic.cpp
51 ../rtl/tsan_md5.cpp
52 ../rtl/tsan_report.cpp
53 ../rtl/tsan_rtl.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
61 ../rtl/tsan_sync.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"
86 SRCS="
87 $SRCS
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"
103 else
104 ARCHCFLAGS="-m64 -msse3"
106 OSCFLAGS="$OSCFLAGS -ffreestanding -Wno-unused-const-variable -Wno-unknown-warning-option"
107 elif [ "$GOARCH" = "arm64" ]; then
108 ARCHCFLAGS=""
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"
115 ARCHCFLAGS=""
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.
121 DEPENDS_ON_LIBC=1
122 OSCFLAGS="-fno-strict-aliasing -fPIC -Werror"
123 ARCHCFLAGS="-m64"
124 OSLDFLAGS="-lpthread -fPIC -fpie"
125 SRCS="
126 $SRCS
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.
141 DEPENDS_ON_LIBC=1
142 OSCFLAGS="-fno-strict-aliasing -fPIC -Werror"
143 ARCHCFLAGS="-m64"
144 OSLDFLAGS="-lpthread -fPIC -fpie"
145 SRCS="
146 $SRCS
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"
161 SRCS="
162 $SRCS
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
171 ARCHCFLAGS="-m64"
172 elif [ "$GOARCH" = "arm64" ]; then
173 ARCHCFLAGS=""
175 elif [ "$GOOS" = "windows" ]; then
176 OSCFLAGS="-Wno-error=attributes -Wno-attributes -Wno-unused-const-variable -Wno-unknown-warning-option"
177 ARCHCFLAGS="-m64"
178 OSLDFLAGS=""
179 SRCS="
180 $SRCS
181 ../rtl/tsan_platform_windows.cpp
182 ../../sanitizer_common/sanitizer_win.cpp
184 else
185 echo Unknown platform
186 exit 1
189 CC=${CC:-gcc}
190 IN_TMPDIR=${IN_TMPDIR:-0}
191 SILENT=${SILENT:-0}
193 if [ $IN_TMPDIR != "0" ]; then
194 DIR=$(mktemp -qd /tmp/gotsan.XXXXXXXXXX)
195 cleanup() {
196 rm -rf $DIR
198 trap cleanup EXIT
199 else
200 DIR=.
203 SRCS="$SRCS $ADD_SRCS"
204 for F in $SRCS; do
205 echo "#line 1 \"$F\""
206 cat $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
216 else
217 FLAGS="$DEBUG_FLAGS"
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"
231 exit 1
235 if [ "$SKIP_TEST" = "1" ]; then
236 exit 0
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
245 $DIR/test
246 else
247 $DIR/test 2>/dev/null