]> Cypherpunks repositories - gostls13.git/commitdiff
runtime, cmd: support race detector on darwin/arm64
authorCherry Zhang <cherryyz@google.com>
Thu, 29 Oct 2020 15:27:17 +0000 (11:27 -0400)
committerCherry Zhang <cherryyz@google.com>
Fri, 30 Oct 2020 19:00:33 +0000 (19:00 +0000)
https://reviews.llvm.org/D90435 is the counterpart in LLVM TSAN.

race_linux_arm64.syso is built with LLVM commit
00da38ce2d36c07f12c287dc515d37bb7bc410e9 on a macOS/ARM64 machine.
(It is not built on a builder with golang.org/x/build/cmd/racebuild
as we don't have darwin/arm64 builder for now.)

Updates #38485.

Change-Id: I391efdacd9480197e308370bfccd05777deb4aee
Reviewed-on: https://go-review.googlesource.com/c/go/+/266373
Trust: Cherry Zhang <cherryyz@google.com>
Reviewed-by: Ian Lance Taylor <iant@golang.org>
src/cmd/dist/test.go
src/cmd/go/internal/work/init.go
src/cmd/internal/sys/supported.go
src/cmd/link/internal/ld/config.go
src/cmd/link/internal/loadmacho/ldmacho.go
src/runtime/race/README
src/runtime/race/race.go
src/runtime/race/race_darwin_arm64.syso [new file with mode: 0644]
src/runtime/race_arm64.s

index 7c454dd38d57a845edd1cdf68fef6c0f6f9d7a86..9c25392cc03ba228b8df8f954c6bf8ac1851906e 100644 (file)
@@ -1619,7 +1619,9 @@ func raceDetectorSupported(goos, goarch string) bool {
        switch goos {
        case "linux":
                return goarch == "amd64" || goarch == "ppc64le" || goarch == "arm64"
-       case "darwin", "freebsd", "netbsd", "windows":
+       case "darwin":
+               return goarch == "amd64" || goarch == "arm64"
+       case "freebsd", "netbsd", "windows":
                return goarch == "amd64"
        default:
                return false
index d65c076c6a82a6c04de190c06865538bbf054d79..102def48383d07042b52e7bd9e7ae426d32bc519 100644 (file)
@@ -79,7 +79,7 @@ func instrumentInit() {
        }
        if cfg.BuildRace {
                if !sys.RaceDetectorSupported(cfg.Goos, cfg.Goarch) {
-                       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])
+                       fmt.Fprintf(os.Stderr, "go %s: -race is only supported on linux/amd64, linux/ppc64le, linux/arm64, freebsd/amd64, netbsd/amd64, darwin/amd64, darwin/arm64, and windows/amd64\n", flag.Args()[0])
                        base.SetExitStatus(2)
                        base.Exit()
                }
index 3c750774ed2fdb86c59044f4709c21d796792075..69d75914406cadaf45219cb268449d389e31d7f2 100644 (file)
@@ -13,7 +13,9 @@ func RaceDetectorSupported(goos, goarch string) bool {
        switch goos {
        case "linux":
                return goarch == "amd64" || goarch == "ppc64le" || goarch == "arm64"
-       case "darwin", "freebsd", "netbsd", "windows":
+       case "darwin":
+               return goarch == "amd64" || goarch == "arm64"
+       case "freebsd", "netbsd", "windows":
                return goarch == "amd64"
        default:
                return false
index 0cb3cc25c06408b96ee3acbddda80e11553623e7..cd64d86a4afbbc1026a7d9fb1e93270eaa5f0d66 100644 (file)
@@ -206,7 +206,7 @@ func mustLinkExternal(ctxt *Link) (res bool, reason string) {
        // When the race flag is set, the LLVM tsan relocatable file is linked
        // into the final binary, which means external linking is required because
        // internal linking does not support it.
-       if *flagRace && ctxt.Arch.InFamily(sys.PPC64) {
+       if *flagRace && (ctxt.Arch.InFamily(sys.PPC64) || ctxt.IsDarwin() && ctxt.IsARM64()) {
                return true, "race on " + objabi.GOARCH
        }
 
index d12f2bc2ac7ca2eed9c9dd97d0b33157a0911a37..d26869e23a734180944bb74cdb1797e3be7b04a3 100644 (file)
@@ -47,7 +47,7 @@ THE SOFTWARE.
 const (
        MACHO_X86_64_RELOC_UNSIGNED = 0
        MACHO_X86_64_RELOC_SIGNED   = 1
-       MACHO_FAKE_GOTPCREL         = 100
+       MACHO_ARM64_RELOC_ADDEND    = 10
 )
 
 type ldMachoObj struct {
@@ -707,11 +707,11 @@ func Load(l *loader.Loader, arch *sys.Arch, localSymVersion int, f *bio.Reader,
                }
 
                sb := l.MakeSymbolUpdater(sect.sym)
+               var rAdd int64
                for j := uint32(0); j < sect.nreloc; j++ {
                        var (
                                rOff  int32
                                rSize uint8
-                               rAdd  int64
                                rType objabi.RelocType
                                rSym  loader.Sym
                        )
@@ -722,6 +722,14 @@ func Load(l *loader.Loader, arch *sys.Arch, localSymVersion int, f *bio.Reader,
                                return errorf("%v: unexpected scattered relocation", s)
                        }
 
+                       if arch.Family == sys.ARM64 && rel.type_ == MACHO_ARM64_RELOC_ADDEND {
+                               // Two relocations. This addend will be applied to the next one.
+                               rAdd = int64(rel.symnum)
+                               continue
+                       } else {
+                               rAdd = 0
+                       }
+
                        rSize = rel.length
                        rType = objabi.MachoRelocOffset + (objabi.RelocType(rel.type_) << 1) + objabi.RelocType(rel.pcrel)
                        rOff = int32(rel.addr)
index b36d82ccfd62101fd7e165fa94b074da846fad18..178ab94ab571d6a011aaaf1f3ea1ba7f0f025c7c 100644 (file)
@@ -11,3 +11,4 @@ race_linux_ppc64le.syso built with LLVM 89f7ccea6f6488c443655880229c54db1f180153
 race_netbsd_amd64.syso built with LLVM 89f7ccea6f6488c443655880229c54db1f180153 and Go f62d3202bf9dbb3a00ad2a2c63ff4fa4188c5d3b.
 race_windows_amd64.syso built with LLVM 89f7ccea6f6488c443655880229c54db1f180153 and Go f62d3202bf9dbb3a00ad2a2c63ff4fa4188c5d3b.
 race_linux_arm64.syso built with LLVM 89f7ccea6f6488c443655880229c54db1f180153 and Go f62d3202bf9dbb3a00ad2a2c63ff4fa4188c5d3b.
+race_darwin_arm64.syso built with LLVM 00da38ce2d36c07f12c287dc515d37bb7bc410e9 and Go fe70a3a0fd31441bcbb9932ecab11a6083cf2119.
index c894de5f722269105bb092b2aed3e95128b2b3eb..d6a14b79e71fdc92b9cf1345eedc3c849b7c93e7 100644 (file)
@@ -2,7 +2,7 @@
 // Use of this source code is governed by a BSD-style
 // license that can be found in the LICENSE file.
 
-// +build race,linux,amd64 race,freebsd,amd64 race,netbsd,amd64 race,darwin,amd64 race,windows,amd64 race,linux,ppc64le race,linux,arm64
+// +build race,linux,amd64 race,freebsd,amd64 race,netbsd,amd64 race,darwin,amd64 race,windows,amd64 race,linux,ppc64le race,linux,arm64 race,darwin,arm64
 
 package race
 
diff --git a/src/runtime/race/race_darwin_arm64.syso b/src/runtime/race/race_darwin_arm64.syso
new file mode 100644 (file)
index 0000000..f6eaa62
Binary files /dev/null and b/src/runtime/race/race_darwin_arm64.syso differ
index 9b909ac021698d7d551c1d42c3c055a794bf9248..59373a9f3f4cc23017191d77cbcb69e2859a64c1 100644 (file)
 
 // The race ctx, ThreadState *thr below, is passed in R0 and loaded in racecalladdr.
 
+#ifdef TLS_darwin
+#define TP_ALIGN       AND     $~7, R0
+#else
+#define TP_ALIGN
+#endif
+
 #define load_g \
        MRS_TPIDR_R0 \
+       TP_ALIGN \
        MOVD    runtime·tls_g(SB), R11 \
        ADD     R11, R0 \
        MOVD    0(R0), g
@@ -423,7 +430,13 @@ TEXT       runtime·racecallbackthunk(SB), NOSPLIT|NOFRAME, $0
        // benefit from this fast path.
        CBNZ    R0, rest
        MOVD    g, R13
+#ifdef TLS_darwin
+       MOVD    R27, R12 // save R27 a.k.a. REGTMP (callee-save in C). load_g clobbers it
+#endif
        load_g
+#ifdef TLS_darwin
+       MOVD    R12, R27
+#endif
        MOVD    g_m(g), R0
        MOVD    m_p(R0), R0
        MOVD    p_raceprocctx(R0), R0
@@ -477,5 +490,7 @@ noswitch:
        BL      runtime·racecallback(SB)
        JMP     ret
 
+#ifndef TLSG_IS_VARIABLE
 // tls_g, g value for each thread in TLS
 GLOBL runtime·tls_g+0(SB), TLSBSS+DUPOK, $8
+#endif