xref: /aosp_15_r20/external/compiler-rt/lib/tsan/go/buildgo.sh (revision 7c3d14c8b49c529e04be81a3ce6f5cc23712e4c6)
1*7c3d14c8STreehugger Robot#!/bin/sh
2*7c3d14c8STreehugger Robot
3*7c3d14c8STreehugger Robotset -e
4*7c3d14c8STreehugger Robot
5*7c3d14c8STreehugger RobotSRCS="
6*7c3d14c8STreehugger Robot	tsan_go.cc
7*7c3d14c8STreehugger Robot	../rtl/tsan_clock.cc
8*7c3d14c8STreehugger Robot	../rtl/tsan_flags.cc
9*7c3d14c8STreehugger Robot	../rtl/tsan_interface_atomic.cc
10*7c3d14c8STreehugger Robot	../rtl/tsan_md5.cc
11*7c3d14c8STreehugger Robot	../rtl/tsan_mutex.cc
12*7c3d14c8STreehugger Robot	../rtl/tsan_report.cc
13*7c3d14c8STreehugger Robot	../rtl/tsan_rtl.cc
14*7c3d14c8STreehugger Robot	../rtl/tsan_rtl_mutex.cc
15*7c3d14c8STreehugger Robot	../rtl/tsan_rtl_report.cc
16*7c3d14c8STreehugger Robot	../rtl/tsan_rtl_thread.cc
17*7c3d14c8STreehugger Robot	../rtl/tsan_rtl_proc.cc
18*7c3d14c8STreehugger Robot	../rtl/tsan_stack_trace.cc
19*7c3d14c8STreehugger Robot	../rtl/tsan_stat.cc
20*7c3d14c8STreehugger Robot	../rtl/tsan_suppressions.cc
21*7c3d14c8STreehugger Robot	../rtl/tsan_sync.cc
22*7c3d14c8STreehugger Robot	../../sanitizer_common/sanitizer_allocator.cc
23*7c3d14c8STreehugger Robot	../../sanitizer_common/sanitizer_common.cc
24*7c3d14c8STreehugger Robot	../../sanitizer_common/sanitizer_common_libcdep.cc
25*7c3d14c8STreehugger Robot	../../sanitizer_common/sanitizer_deadlock_detector2.cc
26*7c3d14c8STreehugger Robot	../../sanitizer_common/sanitizer_flag_parser.cc
27*7c3d14c8STreehugger Robot	../../sanitizer_common/sanitizer_flags.cc
28*7c3d14c8STreehugger Robot	../../sanitizer_common/sanitizer_libc.cc
29*7c3d14c8STreehugger Robot	../../sanitizer_common/sanitizer_persistent_allocator.cc
30*7c3d14c8STreehugger Robot	../../sanitizer_common/sanitizer_printf.cc
31*7c3d14c8STreehugger Robot	../../sanitizer_common/sanitizer_suppressions.cc
32*7c3d14c8STreehugger Robot	../../sanitizer_common/sanitizer_thread_registry.cc
33*7c3d14c8STreehugger Robot	../../sanitizer_common/sanitizer_stackdepot.cc
34*7c3d14c8STreehugger Robot	../../sanitizer_common/sanitizer_stacktrace.cc
35*7c3d14c8STreehugger Robot	../../sanitizer_common/sanitizer_symbolizer.cc
36*7c3d14c8STreehugger Robot	../../sanitizer_common/sanitizer_termination.cc
37*7c3d14c8STreehugger Robot"
38*7c3d14c8STreehugger Robot
39*7c3d14c8STreehugger Robotif [ "`uname -a | grep Linux`" != "" ]; then
40*7c3d14c8STreehugger Robot	SUFFIX="linux_amd64"
41*7c3d14c8STreehugger Robot	OSCFLAGS="-fPIC -ffreestanding -Wno-maybe-uninitialized -Wno-unused-const-variable -Werror -Wno-unknown-warning-option"
42*7c3d14c8STreehugger Robot	OSLDFLAGS="-lpthread -fPIC -fpie"
43*7c3d14c8STreehugger Robot	SRCS="
44*7c3d14c8STreehugger Robot		$SRCS
45*7c3d14c8STreehugger Robot		../rtl/tsan_platform_linux.cc
46*7c3d14c8STreehugger Robot		../../sanitizer_common/sanitizer_posix.cc
47*7c3d14c8STreehugger Robot		../../sanitizer_common/sanitizer_posix_libcdep.cc
48*7c3d14c8STreehugger Robot		../../sanitizer_common/sanitizer_procmaps_common.cc
49*7c3d14c8STreehugger Robot		../../sanitizer_common/sanitizer_procmaps_linux.cc
50*7c3d14c8STreehugger Robot		../../sanitizer_common/sanitizer_linux.cc
51*7c3d14c8STreehugger Robot		../../sanitizer_common/sanitizer_linux_libcdep.cc
52*7c3d14c8STreehugger Robot		../../sanitizer_common/sanitizer_stoptheworld_linux_libcdep.cc
53*7c3d14c8STreehugger Robot	"
54*7c3d14c8STreehugger Robotelif [ "`uname -a | grep FreeBSD`" != "" ]; then
55*7c3d14c8STreehugger Robot	SUFFIX="freebsd_amd64"
56*7c3d14c8STreehugger Robot	OSCFLAGS="-fno-strict-aliasing -fPIC -Werror"
57*7c3d14c8STreehugger Robot	OSLDFLAGS="-lpthread -fPIC -fpie"
58*7c3d14c8STreehugger Robot	SRCS="
59*7c3d14c8STreehugger Robot		$SRCS
60*7c3d14c8STreehugger Robot		../rtl/tsan_platform_linux.cc
61*7c3d14c8STreehugger Robot		../../sanitizer_common/sanitizer_posix.cc
62*7c3d14c8STreehugger Robot		../../sanitizer_common/sanitizer_posix_libcdep.cc
63*7c3d14c8STreehugger Robot		../../sanitizer_common/sanitizer_procmaps_common.cc
64*7c3d14c8STreehugger Robot		../../sanitizer_common/sanitizer_procmaps_freebsd.cc
65*7c3d14c8STreehugger Robot		../../sanitizer_common/sanitizer_linux.cc
66*7c3d14c8STreehugger Robot		../../sanitizer_common/sanitizer_linux_libcdep.cc
67*7c3d14c8STreehugger Robot		../../sanitizer_common/sanitizer_stoptheworld_linux_libcdep.cc
68*7c3d14c8STreehugger Robot	"
69*7c3d14c8STreehugger Robotelif [ "`uname -a | grep Darwin`" != "" ]; then
70*7c3d14c8STreehugger Robot	SUFFIX="darwin_amd64"
71*7c3d14c8STreehugger Robot	OSCFLAGS="-fPIC -Wno-unused-const-variable -Wno-unknown-warning-option -mmacosx-version-min=10.7"
72*7c3d14c8STreehugger Robot	OSLDFLAGS="-lpthread -fPIC -fpie -mmacosx-version-min=10.7"
73*7c3d14c8STreehugger Robot	SRCS="
74*7c3d14c8STreehugger Robot		$SRCS
75*7c3d14c8STreehugger Robot		../rtl/tsan_platform_mac.cc
76*7c3d14c8STreehugger Robot		../../sanitizer_common/sanitizer_mac.cc
77*7c3d14c8STreehugger Robot		../../sanitizer_common/sanitizer_posix.cc
78*7c3d14c8STreehugger Robot		../../sanitizer_common/sanitizer_posix_libcdep.cc
79*7c3d14c8STreehugger Robot		../../sanitizer_common/sanitizer_procmaps_mac.cc
80*7c3d14c8STreehugger Robot	"
81*7c3d14c8STreehugger Robotelif [ "`uname -a | grep MINGW`" != "" ]; then
82*7c3d14c8STreehugger Robot	SUFFIX="windows_amd64"
83*7c3d14c8STreehugger Robot	OSCFLAGS="-Wno-error=attributes -Wno-attributes -Wno-unused-const-variable -Wno-unknown-warning-option"
84*7c3d14c8STreehugger Robot	OSLDFLAGS=""
85*7c3d14c8STreehugger Robot	SRCS="
86*7c3d14c8STreehugger Robot		$SRCS
87*7c3d14c8STreehugger Robot		../rtl/tsan_platform_windows.cc
88*7c3d14c8STreehugger Robot		../../sanitizer_common/sanitizer_win.cc
89*7c3d14c8STreehugger Robot	"
90*7c3d14c8STreehugger Robotelse
91*7c3d14c8STreehugger Robot	echo Unknown platform
92*7c3d14c8STreehugger Robot	exit 1
93*7c3d14c8STreehugger Robotfi
94*7c3d14c8STreehugger Robot
95*7c3d14c8STreehugger RobotCC=${CC:-gcc}
96*7c3d14c8STreehugger RobotIN_TMPDIR=${IN_TMPDIR:-0}
97*7c3d14c8STreehugger RobotSILENT=${SILENT:-0}
98*7c3d14c8STreehugger Robot
99*7c3d14c8STreehugger Robotif [ $IN_TMPDIR != "0" ]; then
100*7c3d14c8STreehugger Robot  DIR=$(mktemp -qd /tmp/gotsan.XXXXXXXXXX)
101*7c3d14c8STreehugger Robot  cleanup() {
102*7c3d14c8STreehugger Robot    rm -rf $DIR
103*7c3d14c8STreehugger Robot  }
104*7c3d14c8STreehugger Robot  trap cleanup EXIT
105*7c3d14c8STreehugger Robotelse
106*7c3d14c8STreehugger Robot  DIR=.
107*7c3d14c8STreehugger Robotfi
108*7c3d14c8STreehugger Robot
109*7c3d14c8STreehugger RobotSRCS="$SRCS $ADD_SRCS"
110*7c3d14c8STreehugger Robot
111*7c3d14c8STreehugger Robotrm -f $DIR/gotsan.cc
112*7c3d14c8STreehugger Robotfor F in $SRCS; do
113*7c3d14c8STreehugger Robot	cat $F >> $DIR/gotsan.cc
114*7c3d14c8STreehugger Robotdone
115*7c3d14c8STreehugger Robot
116*7c3d14c8STreehugger RobotFLAGS=" -I../rtl -I../.. -I../../sanitizer_common -I../../../include -std=c++11 -m64 -Wall -fno-exceptions -fno-rtti -DSANITIZER_GO -DSANITIZER_DEADLOCK_DETECTOR_VERSION=2 $OSCFLAGS"
117*7c3d14c8STreehugger Robotif [ "$DEBUG" = "" ]; then
118*7c3d14c8STreehugger Robot	FLAGS="$FLAGS -DSANITIZER_DEBUG=0 -O3 -msse3 -fomit-frame-pointer"
119*7c3d14c8STreehugger Robotelse
120*7c3d14c8STreehugger Robot	FLAGS="$FLAGS -DSANITIZER_DEBUG=1 -g"
121*7c3d14c8STreehugger Robotfi
122*7c3d14c8STreehugger Robot
123*7c3d14c8STreehugger Robotif [ "$SILENT" != "1" ]; then
124*7c3d14c8STreehugger Robot  echo $CC gotsan.cc -c -o $DIR/race_$SUFFIX.syso $FLAGS $CFLAGS
125*7c3d14c8STreehugger Robotfi
126*7c3d14c8STreehugger Robot$CC $DIR/gotsan.cc -c -o $DIR/race_$SUFFIX.syso $FLAGS $CFLAGS
127*7c3d14c8STreehugger Robot
128*7c3d14c8STreehugger Robot$CC $OSCFLAGS test.c $DIR/race_$SUFFIX.syso -m64 -g -o $DIR/test $OSLDFLAGS
129*7c3d14c8STreehugger Robot
130*7c3d14c8STreehugger Robotexport GORACE="exitcode=0 atexit_sleep_ms=0"
131*7c3d14c8STreehugger Robotif [ "$SILENT" != "1" ]; then
132*7c3d14c8STreehugger Robot  $DIR/test
133*7c3d14c8STreehugger Robotelse
134*7c3d14c8STreehugger Robot  $DIR/test 2>/dev/null
135*7c3d14c8STreehugger Robotfi
136