| 1 | #!/bin/shscip-shell filesystem . . `/bin/sh`. |
| 2 | |
| 3 | set -e |
| 4 | |
| 5 | if [scip-shell system . . `[`. "`unamescip-shell system . . uname. -a | grepscip-shell system . . grep. Linux`" != "" ]; then |
| 6 | HOST_GOOS="linux" |
| 7 | if [scip-shell system . . `[`. "`unamescip-shell system . . uname. -a | grepscip-shell system . . grep. ppc64le`" != "" ]; then |
| 8 | HOST_GOARCH="ppc64le" |
| 9 | elif [scip-shell system . . `[`. "`unamescip-shell system . . uname. -a | grepscip-shell system . . grep. x86_64`" != "" ]; then |
| 10 | HOST_GOARCH="amd64" |
| 11 | elif [scip-shell system . . `[`. "`unamescip-shell system . . uname. -a | grepscip-shell system . . grep. aarch64`" != "" ]; then |
| 12 | HOST_GOARCH="arm64" |
| 13 | elif [scip-shell system . . `[`. "`unamescip-shell system . . uname. -a | grepscip-shell system . . grep. loongarch64`" != "" ]; then |
| 14 | HOST_GOARCH="loong64" |
| 15 | elif [scip-shell system . . `[`. "`unamescip-shell system . . uname. -a | grepscip-shell system . . grep. -i mips64`" != "" ]; then |
| 16 | if [scip-shell system . . `[`. "`lscpuscip-shell system . . lscpu. | grepscip-shell system . . grep. -i Little`" != "" ]; then |
| 17 | HOST_GOARCH="mips64le" |
| 18 | else |
| 19 | HOST_GOARCH="mips64" |
| 20 | fi |
| 21 | elif [scip-shell system . . `[`. "`unamescip-shell system . . uname. -a | grepscip-shell system . . grep. riscv64`" != "" ]; then |
| 22 | HOST_GOARCH="riscv64" |
| 23 | elif [scip-shell system . . `[`. "`unamescip-shell system . . uname. -a | grepscip-shell system . . grep. s390x`" != "" ]; then |
| 24 | HOST_GOARCH="s390x" |
| 25 | fi |
| 26 | elif [scip-shell system . . `[`. "`unamescip-shell system . . uname. -a | grepscip-shell system . . grep. FreeBSD`" != "" ]; then |
| 27 | HOST_GOOS="freebsd" |
| 28 | HOST_GOARCH="amd64" |
| 29 | elif [scip-shell system . . `[`. "`unamescip-shell system . . uname. -a | grepscip-shell system . . grep. NetBSD`" != "" ]; then |
| 30 | HOST_GOOS="netbsd" |
| 31 | HOST_GOARCH="amd64" |
| 32 | elif [scip-shell system . . `[`. "`unamescip-shell system . . uname. -a | grepscip-shell system . . grep. Darwin`" != "" ]; then |
| 33 | HOST_GOOS="darwin" |
| 34 | if [scip-shell system . . `[`. "`unamescip-shell system . . uname. -a | grepscip-shell system . . grep. x86_64`" != "" ]; then |
| 35 | HOST_GOARCH="amd64" |
| 36 | elif [scip-shell system . . `[`. "`unamescip-shell system . . uname. -a | grepscip-shell system . . grep. arm64`" != "" ]; then |
| 37 | HOST_GOARCH="arm64" |
| 38 | fi |
| 39 | elif [scip-shell system . . `[`. "`unamescip-shell system . . uname. -a | grepscip-shell system . . grep. MINGW`" != "" ]; then |
| 40 | HOST_GOOS="windows" |
| 41 | HOST_GOARCH="amd64" |
| 42 | fi |
| 43 | |
| 44 | GOOS=${GOOS:-$HOST_GOOS} |
| 45 | GOARCH=${GOARCH:-$HOST_GOARCH} |
| 46 | SUFFIX="${GOOS}_${GOARCH}" |
| 47 | |
| 48 | SRCS=" |
| 49 | tsan_go.cpp |
| 50 | ../rtl/tsan_external.cpp |
| 51 | ../rtl/tsan_flags.cpp |
| 52 | ../rtl/tsan_interface_atomic.cpp |
| 53 | ../rtl/tsan_md5.cpp |
| 54 | ../rtl/tsan_report.cpp |
| 55 | ../rtl/tsan_rtl.cpp |
| 56 | ../rtl/tsan_rtl_access.cpp |
| 57 | ../rtl/tsan_rtl_mutex.cpp |
| 58 | ../rtl/tsan_rtl_report.cpp |
| 59 | ../rtl/tsan_rtl_thread.cpp |
| 60 | ../rtl/tsan_rtl_proc.cpp |
| 61 | ../rtl/tsan_stack_trace.cpp |
| 62 | ../rtl/tsan_suppressions.cpp |
| 63 | ../rtl/tsan_sync.cpp |
| 64 | ../rtl/tsan_vector_clock.cpp |
| 65 | ../../sanitizer_common/sanitizer_allocator.cpp |
| 66 | ../../sanitizer_common/sanitizer_common.cpp |
| 67 | ../../sanitizer_common/sanitizer_common_libcdep.cpp |
| 68 | ../../sanitizer_common/sanitizer_deadlock_detector2.cpp |
| 69 | ../../sanitizer_common/sanitizer_file.cpp |
| 70 | ../../sanitizer_common/sanitizer_flag_parser.cpp |
| 71 | ../../sanitizer_common/sanitizer_flags.cpp |
| 72 | ../../sanitizer_common/sanitizer_libc.cpp |
| 73 | ../../sanitizer_common/sanitizer_mutex.cpp |
| 74 | ../../sanitizer_common/sanitizer_printf.cpp |
| 75 | ../../sanitizer_common/sanitizer_suppressions.cpp |
| 76 | ../../sanitizer_common/sanitizer_thread_registry.cpp |
| 77 | ../../sanitizer_common/sanitizer_stack_store.cpp |
| 78 | ../../sanitizer_common/sanitizer_stackdepot.cpp |
| 79 | ../../sanitizer_common/sanitizer_stacktrace.cpp |
| 80 | ../../sanitizer_common/sanitizer_symbolizer.cpp |
| 81 | ../../sanitizer_common/sanitizer_symbolizer_report.cpp |
| 82 | ../../sanitizer_common/sanitizer_termination.cpp |
| 83 | " |
| 84 | |
| 85 | if [scip-shell system . . `[`. "$GOOS" = "linux" ]; then |
| 86 | OSCFLAGS="-fPIC -Wno-maybe-uninitialized" |
| 87 | OSLDFLAGS="-lpthread -fPIC -fpie" |
| 88 | SRCS=" |
| 89 | $SRCS |
| 90 | ../rtl/tsan_platform_linux.cpp |
| 91 | ../../sanitizer_common/sanitizer_posix.cpp |
| 92 | ../../sanitizer_common/sanitizer_posix_libcdep.cpp |
| 93 | ../../sanitizer_common/sanitizer_procmaps_common.cpp |
| 94 | ../../sanitizer_common/sanitizer_procmaps_linux.cpp |
| 95 | ../../sanitizer_common/sanitizer_linux.cpp |
| 96 | ../../sanitizer_common/sanitizer_linux_libcdep.cpp |
| 97 | ../../sanitizer_common/sanitizer_stoptheworld_linux_libcdep.cpp |
| 98 | ../../sanitizer_common/sanitizer_stoptheworld_netbsd_libcdep.cpp |
| 99 | " |
| 100 | if [scip-shell system . . `[`. "$GOARCH" = "ppc64le" ]; then |
| 101 | ARCHCFLAGS="-m64 -mcpu=power8 -fno-function-sections" |
| 102 | elif [scip-shell system . . `[`. "$GOARCH" = "amd64" ]; then |
| 103 | if [scip-shell system . . `[`. "$GOAMD64" = "v3" ]; then |
| 104 | ARCHCFLAGS="-m64 -msse4.2" |
| 105 | else |
| 106 | ARCHCFLAGS="-m64 -msse3" |
| 107 | fi |
| 108 | OSCFLAGS="$OSCFLAGS -ffreestanding -Wno-unused-const-variable -Wno-unknown-warning-option" |
| 109 | elif [scip-shell system . . `[`. "$GOARCH" = "arm64" ]; then |
| 110 | ARCHCFLAGS="" |
| 111 | elif [scip-shell system . . `[`. "$GOARCH" = "mips64le" ]; then |
| 112 | ARCHCFLAGS="-mips64 -EL" |
| 113 | elif [scip-shell system . . `[`. "$GOARCH" = "mips64" ]; then |
| 114 | ARCHCFLAGS="-mips64 -EB" |
| 115 | elif [scip-shell system . . `[`. "$GOARCH" = "riscv64" ]; then |
| 116 | if [scip-shell system . . `[`. "$GORISCV64" = "rva23u64" ]; then |
| 117 | ARCHCFLAGS="-march=rv64gcv" |
| 118 | else |
| 119 | ARCHCFLAGS="-march=rv64gc" |
| 120 | fi |
| 121 | elif [scip-shell system . . `[`. "$GOARCH" = "s390x" ]; then |
| 122 | SRCS="$SRCS ../../sanitizer_common/sanitizer_linux_s390.cpp" |
| 123 | ARCHCFLAGS="" |
| 124 | fi |
| 125 | elif [scip-shell system . . `[`. "$GOOS" = "freebsd" ]; then |
| 126 | # The resulting object still depends on libc. |
| 127 | # We removed this dependency for Go runtime for other OSes, |
| 128 | # and we should remove it for FreeBSD as well, but there is no pressing need. |
| 129 | DEPENDS_ON_LIBC=1 |
| 130 | OSCFLAGS="-fno-strict-aliasing -fPIC -Werror" |
| 131 | ARCHCFLAGS="-m64" |
| 132 | OSLDFLAGS="-lpthread -fPIC -fpie" |
| 133 | SRCS=" |
| 134 | $SRCS |
| 135 | ../rtl/tsan_platform_linux.cpp |
| 136 | ../../sanitizer_common/sanitizer_posix.cpp |
| 137 | ../../sanitizer_common/sanitizer_posix_libcdep.cpp |
| 138 | ../../sanitizer_common/sanitizer_procmaps_bsd.cpp |
| 139 | ../../sanitizer_common/sanitizer_procmaps_common.cpp |
| 140 | ../../sanitizer_common/sanitizer_linux.cpp |
| 141 | ../../sanitizer_common/sanitizer_linux_libcdep.cpp |
| 142 | ../../sanitizer_common/sanitizer_stoptheworld_linux_libcdep.cpp |
| 143 | ../../sanitizer_common/sanitizer_stoptheworld_netbsd_libcdep.cpp |
| 144 | " |
| 145 | elif [scip-shell system . . `[`. "$GOOS" = "netbsd" ]; then |
| 146 | # The resulting object still depends on libc. |
| 147 | # We removed this dependency for Go runtime for other OSes, |
| 148 | # and we should remove it for NetBSD as well, but there is no pressing need. |
| 149 | DEPENDS_ON_LIBC=1 |
| 150 | OSCFLAGS="-fno-strict-aliasing -fPIC -Werror" |
| 151 | ARCHCFLAGS="-m64" |
| 152 | OSLDFLAGS="-lpthread -fPIC -fpie" |
| 153 | SRCS=" |
| 154 | $SRCS |
| 155 | ../rtl/tsan_platform_linux.cpp |
| 156 | ../../sanitizer_common/sanitizer_posix.cpp |
| 157 | ../../sanitizer_common/sanitizer_posix_libcdep.cpp |
| 158 | ../../sanitizer_common/sanitizer_procmaps_bsd.cpp |
| 159 | ../../sanitizer_common/sanitizer_procmaps_common.cpp |
| 160 | ../../sanitizer_common/sanitizer_linux.cpp |
| 161 | ../../sanitizer_common/sanitizer_linux_libcdep.cpp |
| 162 | ../../sanitizer_common/sanitizer_netbsd.cpp |
| 163 | ../../sanitizer_common/sanitizer_stoptheworld_linux_libcdep.cpp |
| 164 | ../../sanitizer_common/sanitizer_stoptheworld_netbsd_libcdep.cpp |
| 165 | " |
| 166 | elif [scip-shell system . . `[`. "$GOOS" = "darwin" ]; then |
| 167 | OSCFLAGS="-fPIC -Wno-unused-const-variable -Wno-unknown-warning-option -mmacosx-version-min=10.7" |
| 168 | OSLDFLAGS="-lpthread -fPIC -fpie -mmacosx-version-min=10.7 -Wl,-U,__dyld_get_dyld_header" |
| 169 | SRCS=" |
| 170 | $SRCS |
| 171 | ../rtl/tsan_platform_mac.cpp |
| 172 | ../../sanitizer_common/sanitizer_mac.cpp |
| 173 | ../../sanitizer_common/sanitizer_mac_libcdep.cpp |
| 174 | ../../sanitizer_common/sanitizer_posix.cpp |
| 175 | ../../sanitizer_common/sanitizer_posix_libcdep.cpp |
| 176 | ../../sanitizer_common/sanitizer_procmaps_mac.cpp |
| 177 | " |
| 178 | if [scip-shell system . . `[`. "$GOARCH" = "amd64" ]; then |
| 179 | ARCHCFLAGS="-m64" |
| 180 | elif [scip-shell system . . `[`. "$GOARCH" = "arm64" ]; then |
| 181 | ARCHCFLAGS="" |
| 182 | fi |
| 183 | elif [scip-shell system . . `[`. "$GOOS" = "windows" ]; then |
| 184 | OSCFLAGS="-Wno-error=attributes -Wno-attributes -Wno-unused-const-variable -Wno-unknown-warning-option" |
| 185 | ARCHCFLAGS="-m64" |
| 186 | OSLDFLAGS="" |
| 187 | SRCS=" |
| 188 | $SRCS |
| 189 | ../rtl/tsan_platform_windows.cpp |
| 190 | ../../sanitizer_common/sanitizer_win.cpp |
| 191 | " |
| 192 | else |
| 193 | echoscip-shell system . . echo. Unknown platform |
| 194 | exit 1 |
| 195 | fi |
| 196 | |
| 197 | CC=${CC:-gcc} |
| 198 | IN_TMPDIR=${IN_TMPDIR:-0} |
| 199 | SILENT=${SILENT:-0} |
| 200 | |
| 201 | if [scip-shell system . . `[`. $IN_TMPDIR != "0" ]; then |
| 202 | DIR=$(mktempscip-shell system . . mktemp. -qd /tmp/gotsan.XXXXXXXXXXscip-shell filesystem . . `/tmp/gotsan.XXXXXXXXXX`.) |
| 203 | cleanupscip-shell shell llvm-toolchain-22 1:22.1.7-1 cleanup().() { |
| 204 | rmscip-shell system . . rm. -rf $DIR |
| 205 | } |
| 206 | trap cleanup EXIT |
| 207 | else |
| 208 | DIR=. |
| 209 | fi |
| 210 | |
| 211 | SRCS="$SRCS $ADD_SRCS" |
| 212 | for F in $SRCS; do |
| 213 | echoscip-shell system . . echo. "#line 1 \"$F\"" |
| 214 | catscip-shell system . . cat. $F |
| 215 | done > $DIR/gotsan.cpp |
| 216 | |
| 217 | 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" |
| 218 | DEBUG_FLAGS="$FLAGS -DSANITIZER_DEBUG=1 -g" |
| 219 | FLAGS="$FLAGS -DSANITIZER_DEBUG=0 -O3 -fomit-frame-pointer" |
| 220 | |
| 221 | if [scip-shell system . . `[`. "$DEBUG" = "" ]; then |
| 222 | # Do a build test with debug flags. |
| 223 | $CC $DIR/gotsan.cpp -c -o $DIR/race_debug_$SUFFIX.syso $DEBUG_FLAGS $CFLAGS |
| 224 | else |
| 225 | FLAGS="$DEBUG_FLAGS" |
| 226 | fi |
| 227 | |
| 228 | if [scip-shell system . . `[`. "$SILENT" != "1" ]; then |
| 229 | echoscip-shell system . . echo. $CC gotsan.cpp -c -o $DIR/race_$SUFFIX.syso $FLAGS $CFLAGS |
| 230 | fi |
| 231 | $CC $DIR/gotsan.cpp -c -o $DIR/race_$SUFFIX.syso $FLAGS $CFLAGS |
| 232 | |
| 233 | $CC $OSCFLAGS $ARCHCFLAGS test.c $DIR/race_$SUFFIX.syso -g -o $DIR/test $OSLDFLAGS $LDFLAGS |
| 234 | |
| 235 | # Verify that no libc specific code is present. |
| 236 | if [scip-shell system . . `[`. "$DEPENDS_ON_LIBC" != "1" ]; then |
| 237 | if nmscip-shell system . . nm. $DIR/race_$SUFFIX.syso | grepscip-shell system . . grep. -q __libc_; then |
| 238 | printfscip-shell system . . printf. -- '%s seems to link to libc\n' "race_$SUFFIX.syso" |
| 239 | exit 1 |
| 240 | fi |
| 241 | fi |
| 242 | |
| 243 | if [scip-shell system . . `[`. "$SKIP_TEST" = "1" ]; then |
| 244 | exit 0 |
| 245 | fi |
| 246 | |
| 247 | if [scip-shell system . . `[`. "`unamescip-shell system . . uname. -a | grepscip-shell system . . grep. NetBSD`" != "" ]; then |
| 248 | # Turn off ASLR in the test binary. |
| 249 | /usr/sbin/paxctlscip-shell filesystem . . `/usr/sbin/paxctl`. +a $DIR/test |
| 250 | fi |
| 251 | export GORACE="exitcode=0 atexit_sleep_ms=0" |
| 252 | if [scip-shell system . . `[`. "$SILENT" != "1" ]; then |
| 253 | $DIR/test |
| 254 | else |
| 255 | $DIR/test 2>/dev/nullscip-shell filesystem . . `/dev/null`. |
| 256 | fi |