From: Cherry Zhang Date: Thu, 29 Oct 2020 19:50:53 +0000 (-0400) Subject: runtime: allocate at desired address when race detector is on X-Git-Tag: go1.16beta1~400 X-Git-Url: http://www.git.cypherpunks.su/?a=commitdiff_plain;h=f7e26467b4e7ee0bb3219c26e71292ff4aac7da9;p=gostls13.git runtime: allocate at desired address when race detector is on 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 Reviewed-by: Ian Lance Taylor --- diff --git a/src/runtime/malloc.go b/src/runtime/malloc.go index d0b8c668c3..0563f49d17 100644 --- a/src/runtime/malloc.go +++ b/src/runtime/malloc.go @@ -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) }