[clang][modules] Don't prevent translation of FW_Private includes when explicitly...
[llvm-project.git] / compiler-rt / lib / tsan / go / buildgo.sh
blob0bd59368cc4673682858e36b52e80faf0074aaa0
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 -i mips64`" != "" ]; then
14 if [ "`lscpu | grep -i Little`" != "" ]; then
15 HOST_GOARCH="mips64le"
16 else
17 HOST_GOARCH="mips64"
19 elif [ "`uname -a | grep s390x`" != "" ]; then
20 HOST_GOARCH="s390x"
22 elif [ "`uname -a | grep FreeBSD`" != "" ]; then
23 HOST_GOOS="freebsd"
24 HOST_GOARCH="amd64"
25 elif [ "`uname -a | grep NetBSD`" != "" ]; then
26 HOST_GOOS="netbsd"
27 HOST_GOARCH="amd64"
28 elif [ "`uname -a | grep Darwin`" != "" ]; then
29 HOST_GOOS="darwin"
30 if [ "`uname -a | grep x86_64`" != "" ]; then
31 HOST_GOARCH="amd64"
32 elif [ "`uname -a | grep arm64`" != "" ]; then
33 HOST_GOARCH="arm64"
35 elif [ "`uname -a | grep MINGW`" != "" ]; then
36 HOST_GOOS="windows"
37 HOST_GOARCH="amd64"
40 GOOS=${GOOS:-$HOST_GOOS}
41 GOARCH=${GOARCH:-$HOST_GOARCH}
42 SUFFIX="${GOOS}_${GOARCH}"
44 SRCS="
45 tsan_go.cpp
46 ../rtl/tsan_external.cpp
47 ../rtl/tsan_flags.cpp
48 ../rtl/tsan_interface_atomic.cpp
49 ../rtl/tsan_md5.cpp
50 ../rtl/tsan_report.cpp
51 ../rtl/tsan_rtl.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
59 ../rtl/tsan_sync.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"
84 SRCS="
85 $SRCS
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"
101 else
102 ARCHCFLAGS="-m64 -msse3"
104 OSCFLAGS="$OSCFLAGS -ffreestanding -Wno-unused-const-variable -Wno-unknown-warning-option"
105 elif [ "$GOARCH" = "arm64" ]; then
106 ARCHCFLAGS=""
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"
113 ARCHCFLAGS=""
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.
119 DEPENDS_ON_LIBC=1
120 OSCFLAGS="-fno-strict-aliasing -fPIC -Werror"
121 ARCHCFLAGS="-m64"
122 OSLDFLAGS="-lpthread -fPIC -fpie"
123 SRCS="
124 $SRCS
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.
139 DEPENDS_ON_LIBC=1
140 OSCFLAGS="-fno-strict-aliasing -fPIC -Werror"
141 ARCHCFLAGS="-m64"
142 OSLDFLAGS="-lpthread -fPIC -fpie"
143 SRCS="
144 $SRCS
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"
159 SRCS="
160 $SRCS
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
169 ARCHCFLAGS="-m64"
170 elif [ "$GOARCH" = "arm64" ]; then
171 ARCHCFLAGS=""
173 elif [ "$GOOS" = "windows" ]; then
174 OSCFLAGS="-Wno-error=attributes -Wno-attributes -Wno-unused-const-variable -Wno-unknown-warning-option"
175 ARCHCFLAGS="-m64"
176 OSLDFLAGS=""
177 SRCS="
178 $SRCS
179 ../rtl/tsan_platform_windows.cpp
180 ../../sanitizer_common/sanitizer_win.cpp
182 else
183 echo Unknown platform
184 exit 1
187 CC=${CC:-gcc}
188 IN_TMPDIR=${IN_TMPDIR:-0}
189 SILENT=${SILENT:-0}
191 if [ $IN_TMPDIR != "0" ]; then
192 DIR=$(mktemp -qd /tmp/gotsan.XXXXXXXXXX)
193 cleanup() {
194 rm -rf $DIR
196 trap cleanup EXIT
197 else
198 DIR=.
201 SRCS="$SRCS $ADD_SRCS"
202 for F in $SRCS; do
203 echo "#line 1 \"$F\""
204 cat $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
214 else
215 FLAGS="$DEBUG_FLAGS"
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"
229 exit 1
233 if [ "$SKIP_TEST" = "1" ]; then
234 exit 0
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
243 $DIR/test
244 else
245 $DIR/test 2>/dev/null