Skip to content

Commit 978cfa8

Browse files
zorrorffmcherrymui
authored andcommitted
cmd,runtime: enable race detector on arm64
Changes include: 1. enable compiler option -race for arm64 2. add runtime/race_arm64.s to manage the calls from Go to the compiler-rt runtime 3. change racewalk.go to call racefuncenterfp instead of racefuncenter on arm64 to allow the caller pc to be obtained in the asm code before calling the tsan version 4. race_linux_arm64.syso comes from compiler-rt which just supports 48bit VA, compiler-rt is fetched from master branch which latest commit is 3aa2b775d08f903f804246af10b Fixes #25682 Change-Id: I04364c580b8157fd117deecae74a4656ba16e005 Reviewed-on: https://go-review.googlesource.com/c/138675 Run-TryBot: Cherry Zhang <[email protected]> TryBot-Result: Gobot Gobot <[email protected]> Reviewed-by: Cherry Zhang <[email protected]>
1 parent e787b13 commit 978cfa8

File tree

10 files changed

+457
-10
lines changed

10 files changed

+457
-10
lines changed

src/cmd/compile/internal/gc/racewalk.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -71,14 +71,14 @@ func instrument(fn *Node) {
7171
lno := lineno
7272
lineno = src.NoXPos
7373

74-
if thearch.LinkArch.Arch == sys.ArchPPC64LE {
74+
if thearch.LinkArch.Arch.Family != sys.AMD64 {
7575
fn.Func.Enter.Prepend(mkcall("racefuncenterfp", nil, nil))
7676
fn.Func.Exit.Append(mkcall("racefuncexit", nil, nil))
7777
} else {
7878

7979
// nodpc is the PC of the caller as extracted by
8080
// getcallerpc. We use -widthptr(FP) for x86.
81-
// BUG: This only works for amd64. This will not
81+
// This only works for amd64. This will not
8282
// work on arm or others that might support
8383
// race in the future.
8484
nodpc := nodfp.copy()

src/cmd/go/internal/work/init.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ func instrumentInit() {
4949
}
5050
if cfg.BuildRace {
5151
if !sys.RaceDetectorSupported(cfg.Goos, cfg.Goarch) {
52-
fmt.Fprintf(os.Stderr, "go %s: -race is only supported on linux/amd64, linux/ppc64le, freebsd/amd64, netbsd/amd64, darwin/amd64 and windows/amd64\n", flag.Args()[0])
52+
fmt.Fprintf(os.Stderr, "go %s: -race is only supported on linux/amd64, linux/ppc64le, linux/arm64, freebsd/amd64, netbsd/amd64, darwin/amd64 and windows/amd64\n", flag.Args()[0])
5353
os.Exit(2)
5454
}
5555
}

src/cmd/internal/sys/supported.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ package sys
99
func RaceDetectorSupported(goos, goarch string) bool {
1010
switch goos {
1111
case "linux":
12-
return goarch == "amd64" || goarch == "ppc64le"
12+
return goarch == "amd64" || goarch == "ppc64le" || goarch == "arm64"
1313
case "darwin", "freebsd", "netbsd", "windows":
1414
return goarch == "amd64"
1515
default:

src/cmd/link/internal/ld/config.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -199,8 +199,8 @@ func mustLinkExternal(ctxt *Link) (res bool, reason string) {
199199
// When the race flag is set, the LLVM tsan relocatable file is linked
200200
// into the final binary, which means external linking is required because
201201
// internal linking does not support it.
202-
if *flagRace && ctxt.Arch.InFamily(sys.PPC64) {
203-
return true, "race on ppc64le"
202+
if *flagRace && ctxt.Arch.InFamily(sys.PPC64, sys.ARM64) {
203+
return true, "race on " + objabi.GOARCH
204204
}
205205

206206
// Some build modes require work the internal linker cannot do (yet).

src/race.bash

+2-2
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, freebsd/amd64, netbsd/amd64 and darwin/amd64' 1>&2
12+
echo 'race detector is only supported on linux/amd64, linux/ppc64le, linux/arm64, freebsd/amd64, netbsd/amd64 and darwin/amd64' 1>&2
1313
exit 1
1414
}
1515

@@ -21,7 +21,7 @@ case $(uname) in
2121
fi
2222
;;
2323
"Linux")
24-
if [ $(uname -m) != "x86_64" ] && [ $(uname -m) != "ppc64le" ]; then
24+
if [ $(uname -m) != "x86_64" ] && [ $(uname -m) != "ppc64le" ] && [ $(uname -m) != "aarch64" ]; then
2525
usage
2626
fi
2727
;;

src/runtime/asm_arm64.s

+2-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,8 @@ TEXT runtime·rt0_go(SB),NOSPLIT,$0
1818
// create istack out of the given (operating system) stack.
1919
// _cgo_init may update stackguard.
2020
MOVD $runtime·g0(SB), g
21-
MOVD RSP, R7
21+
BL runtime·save_g(SB)
22+
MOVD RSP, R7
2223
MOVD $(-64*1024)(R7), R0
2324
MOVD R0, g_stackguard0(g)
2425
MOVD R0, g_stackguard1(g)

src/runtime/race/README

+1
Original file line numberDiff line numberDiff line change
@@ -10,3 +10,4 @@ race_linux_amd64.syso built with LLVM fe2c72c59aa7f4afa45e3f65a5d16a374b6cce26 a
1010
race_linux_ppc64le.syso built with LLVM fe2c72c59aa7f4afa45e3f65a5d16a374b6cce26 and Go 323c85862a7afbde66a3bba0776bf4ba6cd7c030.
1111
race_netbsd_amd64.syso built with LLVM fe2c72c59aa7f4afa45e3f65a5d16a374b6cce26 and Go 323c85862a7afbde66a3bba0776bf4ba6cd7c030.
1212
race_windows_amd64.syso built with LLVM ae08a22cc215448aa3ad5a6fb099f6df77e9fa01 and Go 323c85862a7afbde66a3bba0776bf4ba6cd7c030.
13+
race_linux_arm64.syso built with LLVM 3aa2b775d08f903f804246af10b80a439c16b436 and Go ef2c48659880c7e8a989e6721a21f018790f7793.

src/runtime/race/race.go

+1-1
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-
// +build race,linux,amd64 race,freebsd,amd64 race,netbsd,amd64 race,darwin,amd64 race,windows,amd64 race,linux,ppc64le
5+
// +build race,linux,amd64 race,freebsd,amd64 race,netbsd,amd64 race,darwin,amd64 race,windows,amd64 race,linux,ppc64le race,linux,arm64
66

77
package race
88

408 KB
Binary file not shown.

0 commit comments

Comments
 (0)