Skip to content

Commit 8bcda6c

Browse files
committed
runtime/race: add race detector support for linux/riscv64
This enables support for the race detector on linux/riscv64. Fixes golang#64345 Cq-Include-Trybots: luci.golang.try:gotip-linux-riscv64 Change-Id: I98962827e91455404858549b0f9691ee438f104b Reviewed-on: https://go-review.googlesource.com/c/go/+/690497 Reviewed-by: Cherry Mui <[email protected]> LUCI-TryBot-Result: Go LUCI <[email protected]> Reviewed-by: Meng Zhuo <[email protected]> Reviewed-by: Carlos Amedee <[email protected]>
1 parent 8377ada commit 8bcda6c

File tree

10 files changed

+572
-8
lines changed

10 files changed

+572
-8
lines changed

src/cmd/dist/test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1698,7 +1698,7 @@ func (t *tester) makeGOROOTUnwritable() (undo func()) {
16981698
func raceDetectorSupported(goos, goarch string) bool {
16991699
switch goos {
17001700
case "linux":
1701-
return goarch == "amd64" || goarch == "ppc64le" || goarch == "arm64" || goarch == "s390x" || goarch == "loong64"
1701+
return goarch == "amd64" || goarch == "arm64" || goarch == "loong64" || goarch == "ppc64le" || goarch == "riscv64" || goarch == "s390x"
17021702
case "darwin":
17031703
return goarch == "amd64" || goarch == "arm64"
17041704
case "freebsd", "netbsd", "windows":

src/cmd/go/alldocs.go

Lines changed: 3 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/cmd/go/internal/work/build.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -77,8 +77,9 @@ and test commands:
7777
The default is GOMAXPROCS, normally the number of CPUs available.
7878
-race
7979
enable data race detection.
80-
Supported only on linux/amd64, freebsd/amd64, darwin/amd64, darwin/arm64, windows/amd64,
81-
linux/ppc64le and linux/arm64 (only for 48-bit VMA).
80+
Supported only on darwin/amd64, darwin/arm64, freebsd/amd64, linux/amd64,
81+
linux/arm64 (only for 48-bit VMA), linux/ppc64le, linux/riscv64 and
82+
windows/amd64.
8283
-msan
8384
enable interoperation with memory sanitizer.
8485
Supported only on linux/amd64, linux/arm64, linux/loong64, freebsd/amd64

src/internal/platform/supported.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ func (p OSArch) String() string {
2323
func RaceDetectorSupported(goos, goarch string) bool {
2424
switch goos {
2525
case "linux":
26-
return goarch == "amd64" || goarch == "ppc64le" || goarch == "arm64" || goarch == "s390x" || goarch == "loong64"
26+
return goarch == "amd64" || goarch == "arm64" || goarch == "loong64" || goarch == "ppc64le" || goarch == "riscv64" || goarch == "s390x"
2727
case "darwin":
2828
return goarch == "amd64" || goarch == "arm64"
2929
case "freebsd", "netbsd", "windows":

src/race.bash

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
set -e
1010

1111
function usage {
12-
echo 'race detector is only supported on linux/amd64, linux/ppc64le, linux/arm64, linux/loong64, linux/s390x, freebsd/amd64, netbsd/amd64, openbsd/amd64, darwin/amd64, and darwin/arm64' 1>&2
12+
echo 'race detector is only supported on linux/amd64, linux/ppc64le, linux/arm64, linux/loong64, linux/riscv64, linux/s390x, freebsd/amd64, netbsd/amd64, openbsd/amd64, darwin/amd64, and darwin/arm64' 1>&2
1313
exit 1
1414
}
1515

@@ -20,6 +20,7 @@ case $(uname -s -m) in
2020
"Linux ppc64le") ;;
2121
"Linux aarch64") ;;
2222
"Linux loongarch64") ;;
23+
"Linux riscv64") ;;
2324
"Linux s390x") ;;
2425
"FreeBSD amd64") ;;
2526
"NetBSD amd64") ;;

src/runtime/malloc.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -588,11 +588,20 @@ func mallocinit() {
588588
// possible to use RISCV_HWPROBE_KEY_HIGHEST_VIRT_ADDRESS at some
589589
// point in the future - for now use the system stack address.
590590
vmaSize = sys.Len64(uint64(getg().m.g0.stack.hi)) + 1
591+
if raceenabled && vmaSize != 39 && vmaSize != 48 {
592+
println("vma size = ", vmaSize)
593+
throw("riscv64 vma size is unknown and race mode is enabled")
594+
}
591595
}
592596

593597
for i := 0x7f; i >= 0; i-- {
594598
var p uintptr
595599
switch {
600+
case raceenabled && GOARCH == "riscv64" && vmaSize == 39:
601+
p = uintptr(i)<<28 | uintptrMask&(0x0013<<28)
602+
if p >= uintptrMask&0x000f00000000 {
603+
continue
604+
}
596605
case raceenabled:
597606
// The TSAN runtime requires the heap
598607
// to be in the range [0x00c000000000,

src/runtime/race/README

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,4 +15,5 @@ race_darwin_arm64.syso built with LLVM 51bfeff0e4b0757ff773da6882f4d538996c9b04
1515
race_linux_arm64.syso built with LLVM 51bfeff0e4b0757ff773da6882f4d538996c9b04 and Go e7d582b55dda36e76ce4d0ce770139ca0915b7c5.
1616
race_linux_loong64.syso built with LLVM 83fe85115da9dc25fa270d2ea8140113c8d49670 and Go 037112464b4439571b45536de9ebe4bc9e10ecb7.
1717
race_linux_ppc64le.syso built with LLVM 51bfeff0e4b0757ff773da6882f4d538996c9b04 and Go e7d582b55dda36e76ce4d0ce770139ca0915b7c5.
18+
race_linux_riscv64.syso built with LLVM c3c24be13f7928460ca1e2fe613a1146c868854e and Go a21249436b6e1fd47356361d53dc053bbc074f90.
1819
race_linux_s390x.syso built with LLVM 51bfeff0e4b0757ff773da6882f4d538996c9b04 and Go e7d582b55dda36e76ce4d0ce770139ca0915b7c5.

src/runtime/race/race.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
// Use of this source code is governed by a BSD-style
33
// license that can be found in the LICENSE file.
44

5-
//go:build race && ((linux && (amd64 || arm64 || loong64 || ppc64le || s390x)) || ((freebsd || netbsd || openbsd || windows) && amd64))
5+
//go:build race && ((linux && (amd64 || arm64 || loong64 || ppc64le || riscv64 || s390x)) || ((freebsd || netbsd || openbsd || windows) && amd64))
66

77
package race
88

1.36 MB
Binary file not shown.

0 commit comments

Comments
 (0)