Skip to content

Commit 11081a6

Browse files
committed
tsan: allow to cross-build Go runtime
Allow user to provide target GOOS/GOARCH. If not provided, use the host GOOS/GOARCH as we do now. This allows to cross-compile the runtime. Also provide SKIP_TEST knob for cross-compilation since the test will most likely not run on host. Reviewed By: vitalybuka Differential Revision: https://reviews.llvm.org/D150650
1 parent 0b9571f commit 11081a6

File tree

1 file changed

+58
-28
lines changed

1 file changed

+58
-28
lines changed

compiler-rt/lib/tsan/go/buildgo.sh

Lines changed: 58 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,45 @@
22

33
set -e
44

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"
18+
fi
19+
elif [ "`uname -a | grep s390x`" != "" ]; then
20+
HOST_GOARCH="s390x"
21+
fi
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"
34+
fi
35+
elif [ "`uname -a | grep MINGW`" != "" ]; then
36+
HOST_GOOS="windows"
37+
HOST_GOARCH="amd64"
38+
fi
39+
40+
GOOS=${GOOS:-$HOST_GOOS}
41+
GOARCH=${GOARCH:-$HOST_GOARCH}
42+
SUFFIX="${GOOS}_${GOARCH}"
43+
544
SRCS="
645
tsan_go.cpp
746
../rtl/tsan_external.cpp
@@ -39,7 +78,7 @@ SRCS="
3978
../../sanitizer_common/sanitizer_termination.cpp
4079
"
4180

42-
if [ "`uname -a | grep Linux`" != "" ]; then
81+
if [ "$GOOS" == "linux" ]; then
4382
OSCFLAGS="-fPIC -Wno-maybe-uninitialized"
4483
OSLDFLAGS="-lpthread -fPIC -fpie"
4584
SRCS="
@@ -54,39 +93,30 @@ if [ "`uname -a | grep Linux`" != "" ]; then
5493
../../sanitizer_common/sanitizer_stoptheworld_linux_libcdep.cpp
5594
../../sanitizer_common/sanitizer_stoptheworld_netbsd_libcdep.cpp
5695
"
57-
if [ "`uname -a | grep ppc64le`" != "" ]; then
58-
SUFFIX="linux_ppc64le"
96+
if [ "$GOARCH" == "ppc64le" ]; then
5997
ARCHCFLAGS="-m64 -mcpu=power8 -fno-function-sections"
60-
elif [ "`uname -a | grep x86_64`" != "" ]; then
61-
SUFFIX="linux_amd64"
98+
elif [ "$GOARCH" == "amd64" ]; then
6299
if [ "$GOAMD64" = "v3" ]; then
63100
ARCHCFLAGS="-m64 -msse4.2"
64101
else
65102
ARCHCFLAGS="-m64 -msse3"
66103
fi
67104
OSCFLAGS="$OSCFLAGS -ffreestanding -Wno-unused-const-variable -Wno-unknown-warning-option"
68-
elif [ "`uname -a | grep aarch64`" != "" ]; then
69-
SUFFIX="linux_arm64"
105+
elif [ "$GOARCH" == "arm64" ]; then
70106
ARCHCFLAGS=""
71-
elif [ "`uname -a | grep -i mips64`" != "" ]; then
72-
if [ "`lscpu | grep -i Little`" != "" ]; then
73-
SUFFIX="linux_mips64le"
74-
ARCHCFLAGS="-mips64 -EL"
75-
else
76-
SUFFIX="linux_mips64"
77-
ARCHCFLAGS="-mips64 -EB"
78-
fi
79-
elif [ "`uname -a | grep s390x`" != "" ]; then
107+
elif [ "$GOARCH" == "mips64le" ]; then
108+
ARCHCFLAGS="-mips64 -EL"
109+
elif [ "$GOARCH" == "mips64" ]; then
110+
ARCHCFLAGS="-mips64 -EB"
111+
elif [ "$GOARCH" == "s390x" ]; then
80112
SRCS="$SRCS ../../sanitizer_common/sanitizer_linux_s390.cpp"
81-
SUFFIX="linux_s390x"
82113
ARCHCFLAGS=""
83114
fi
84-
elif [ "`uname -a | grep FreeBSD`" != "" ]; then
115+
elif [ "$GOOS" == "freebsd" ]; then
85116
# The resulting object still depends on libc.
86117
# We removed this dependency for Go runtime for other OSes,
87118
# and we should remove it for FreeBSD as well, but there is no pressing need.
88119
DEPENDS_ON_LIBC=1
89-
SUFFIX="freebsd_amd64"
90120
OSCFLAGS="-fno-strict-aliasing -fPIC -Werror"
91121
ARCHCFLAGS="-m64"
92122
OSLDFLAGS="-lpthread -fPIC -fpie"
@@ -102,12 +132,11 @@ elif [ "`uname -a | grep FreeBSD`" != "" ]; then
102132
../../sanitizer_common/sanitizer_stoptheworld_linux_libcdep.cpp
103133
../../sanitizer_common/sanitizer_stoptheworld_netbsd_libcdep.cpp
104134
"
105-
elif [ "`uname -a | grep NetBSD`" != "" ]; then
135+
elif [ "$GOOS" == "netbsd" ]; then
106136
# The resulting object still depends on libc.
107137
# We removed this dependency for Go runtime for other OSes,
108138
# and we should remove it for NetBSD as well, but there is no pressing need.
109139
DEPENDS_ON_LIBC=1
110-
SUFFIX="netbsd_amd64"
111140
OSCFLAGS="-fno-strict-aliasing -fPIC -Werror"
112141
ARCHCFLAGS="-m64"
113142
OSLDFLAGS="-lpthread -fPIC -fpie"
@@ -124,7 +153,7 @@ elif [ "`uname -a | grep NetBSD`" != "" ]; then
124153
../../sanitizer_common/sanitizer_stoptheworld_linux_libcdep.cpp
125154
../../sanitizer_common/sanitizer_stoptheworld_netbsd_libcdep.cpp
126155
"
127-
elif [ "`uname -a | grep Darwin`" != "" ]; then
156+
elif [ "$GOOS" == "darwin" ]; then
128157
OSCFLAGS="-fPIC -Wno-unused-const-variable -Wno-unknown-warning-option -mmacosx-version-min=10.7"
129158
OSLDFLAGS="-lpthread -fPIC -fpie -mmacosx-version-min=10.7"
130159
SRCS="
@@ -136,15 +165,12 @@ elif [ "`uname -a | grep Darwin`" != "" ]; then
136165
../../sanitizer_common/sanitizer_posix_libcdep.cpp
137166
../../sanitizer_common/sanitizer_procmaps_mac.cpp
138167
"
139-
if [ "`uname -a | grep x86_64`" != "" ]; then
140-
SUFFIX="darwin_amd64"
168+
if [ "$GOARCH" == "amd64" ]; then
141169
ARCHCFLAGS="-m64"
142-
elif [ "`uname -a | grep arm64`" != "" ]; then
143-
SUFFIX="darwin_arm64"
170+
elif [ "$GOARCH" == "arm64" ]; then
144171
ARCHCFLAGS=""
145172
fi
146-
elif [ "`uname -a | grep MINGW`" != "" ]; then
147-
SUFFIX="windows_amd64"
173+
elif [ "$GOOS" == "windows" ]; then
148174
OSCFLAGS="-Wno-error=attributes -Wno-attributes -Wno-unused-const-variable -Wno-unknown-warning-option"
149175
ARCHCFLAGS="-m64"
150176
OSLDFLAGS=""
@@ -204,6 +230,10 @@ if [ "$DEPENDS_ON_LIBC" != "1" ]; then
204230
fi
205231
fi
206232

233+
if [ "$SKIP_TEST" == "1" ]; then
234+
exit 0
235+
fi
236+
207237
if [ "`uname -a | grep NetBSD`" != "" ]; then
208238
# Turn off ASLR in the test binary.
209239
/usr/sbin/paxctl +a $DIR/test

0 commit comments

Comments
 (0)