]> Cypherpunks repositories - gostls13.git/commitdiff
runtime: allocate at desired address when race detector is on
authorCherry Zhang <cherryyz@google.com>
Thu, 29 Oct 2020 19:50:53 +0000 (15:50 -0400)
committerCherry Zhang <cherryyz@google.com>
Fri, 30 Oct 2020 01:31:10 +0000 (01:31 +0000)
Currently, on all supported platforms, the race detector (LLVM
TSAN) expects the Go heap is at 0xc000000000 - 0xe000000000.
Move the raceenabled condition first, so we always allocate
there.

This means on Linux/ARM64 when race detector is on we will
allocate to 0xc000000000 - 0xe000000000, instead of 0x4000000000.
The old address is meant for 39-bit VMA. But the race detector
only supports 48-bit VMA anyway. So this is fine.

Change-Id: I51ac8eff68297b37c8c651a93145cc94f83a939d
Reviewed-on: https://go-review.googlesource.com/c/go/+/266372
Trust: Cherry Zhang <cherryyz@google.com>
Reviewed-by: Ian Lance Taylor <iant@golang.org>
src/runtime/malloc.go

index d0b8c668c3b16dc9298695de6e5761d58a843e6c..0563f49d175cbf8a15a9f772ff73e1e840c8d441 100644 (file)
@@ -521,6 +521,14 @@ func mallocinit() {
                for i := 0x7f; i >= 0; i-- {
                        var p uintptr
                        switch {
+                       case raceenabled:
+                               // The TSAN runtime requires the heap
+                               // to be in the range [0x00c000000000,
+                               // 0x00e000000000).
+                               p = uintptr(i)<<32 | uintptrMask&(0x00c0<<32)
+                               if p >= uintptrMask&0x00e000000000 {
+                                       continue
+                               }
                        case GOARCH == "arm64" && GOOS == "ios":
                                p = uintptr(i)<<40 | uintptrMask&(0x0013<<28)
                        case GOARCH == "arm64":
@@ -532,14 +540,6 @@ func mallocinit() {
                                        continue
                                }
                                p = uintptr(i)<<40 | uintptrMask&(0xa0<<52)
-                       case raceenabled:
-                               // The TSAN runtime requires the heap
-                               // to be in the range [0x00c000000000,
-                               // 0x00e000000000).
-                               p = uintptr(i)<<32 | uintptrMask&(0x00c0<<32)
-                               if p >= uintptrMask&0x00e000000000 {
-                                       continue
-                               }
                        default:
                                p = uintptr(i)<<40 | uintptrMask&(0x00c0<<32)
                        }