]> Cypherpunks repositories - gostls13.git/commitdiff
runtime,cmd/link: increase stack guard space when building with -race
authorKeith Randall <khr@golang.org>
Wed, 16 Nov 2022 20:56:40 +0000 (12:56 -0800)
committerKeith Randall <khr@google.com>
Fri, 18 Nov 2022 16:26:25 +0000 (16:26 +0000)
More stuff to do = more stack needed. Bump up the guard space when
building with the race detector.

Fixes #54291

Change-Id: I701bc8800507921bed568047d35b8f49c26e7df7
Reviewed-on: https://go-review.googlesource.com/c/go/+/451217
Run-TryBot: Keith Randall <khr@golang.org>
Reviewed-by: Keith Randall <khr@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Michael Knyszek <mknyszek@google.com>
src/cmd/internal/objabi/stack.go
src/cmd/link/internal/ld/stackcheck.go
src/runtime/internal/sys/consts.go
src/runtime/internal/sys/consts_norace.go [new file with mode: 0644]
src/runtime/internal/sys/consts_race.go [new file with mode: 0644]
src/runtime/stack.go

index 80bd1c079934a29dc6febe6924e0e4d21f868ed6..88b4990d5e1b177196d608682eba8bd287f3f5ce 100644 (file)
@@ -15,17 +15,26 @@ const (
        StackSmall  = 128
 )
 
-// Initialize StackGuard and StackLimit according to target system.
-var StackGuard = 928*stackGuardMultiplier() + StackSystem
-var StackLimit = StackGuard - StackSystem - StackSmall
+func StackLimit(race bool) int {
+       // This arithmetic must match that in runtime/stack.go:{_StackGuard,_StackLimit}.
+       stackGuard := 928*stackGuardMultiplier(race) + StackSystem
+       stackLimit := stackGuard - StackSystem - StackSmall
+       return stackLimit
+}
 
 // stackGuardMultiplier returns a multiplier to apply to the default
 // stack guard size. Larger multipliers are used for non-optimized
 // builds that have larger stack frames or for specific targets.
-func stackGuardMultiplier() int {
+func stackGuardMultiplier(race bool) int {
+       // This arithmetic must match that in runtime/internal/sys/consts.go:StackGuardMultiplier.
+       n := 1
        // On AIX, a larger stack is needed for syscalls.
        if buildcfg.GOOS == "aix" {
-               return 2
+               n += 1
+       }
+       // The race build also needs more stack.
+       if race {
+               n += 1
        }
-       return 1
+       return n
 }
index f0e13670681c77055653a4e7ecddcda739b04419..c82dafe51edbf02b7710e78f0180d9e6cead9761 100644 (file)
@@ -61,7 +61,7 @@ func (ctxt *Link) doStackCheck() {
        // The call to morestack in every splittable function ensures
        // that there are at least StackLimit bytes available below SP
        // when morestack returns.
-       limit := objabi.StackLimit - sc.callSize
+       limit := objabi.StackLimit(*flagRace) - sc.callSize
        if buildcfg.GOARCH == "arm64" {
                // Need an extra 8 bytes below SP to save FP.
                limit -= 8
index c60371658013566cedbe60a37675cd977b4dd624..98c0f09ef163d1de56a9f0074716daed180e1929 100644 (file)
@@ -10,7 +10,9 @@ import (
 )
 
 // AIX requires a larger stack for syscalls.
-const StackGuardMultiplier = 1*(1-goos.IsAix) + 2*goos.IsAix
+// The race build also needs more stack. See issue 54291.
+// This arithmetic must match that in cmd/internal/objabi/stack.go:stackGuardMultiplier.
+const StackGuardMultiplier = 1 + goos.IsAix + isRace
 
 // DefaultPhysPageSize is the default physical page size.
 const DefaultPhysPageSize = goarch.DefaultPhysPageSize
diff --git a/src/runtime/internal/sys/consts_norace.go b/src/runtime/internal/sys/consts_norace.go
new file mode 100644 (file)
index 0000000..a9613b8
--- /dev/null
@@ -0,0 +1,9 @@
+// Copyright 2022 The Go Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style
+// license that can be found in the LICENSE file.
+
+//go:build !race
+
+package sys
+
+const isRace = 0
diff --git a/src/runtime/internal/sys/consts_race.go b/src/runtime/internal/sys/consts_race.go
new file mode 100644 (file)
index 0000000..f824fb3
--- /dev/null
@@ -0,0 +1,9 @@
+// Copyright 2022 The Go Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style
+// license that can be found in the LICENSE file.
+
+//go:build race
+
+package sys
+
+const isRace = 1
index 546f9978816645719b103a9ca6156c285684a70c..d5e587a2091d0580c79af82425dfea72de6d38a7 100644 (file)
@@ -98,6 +98,7 @@ const (
        // The guard leaves enough room for one _StackSmall frame plus
        // a _StackLimit chain of NOSPLIT calls plus _StackSystem
        // bytes for the OS.
+       // This arithmetic must match that in cmd/internal/objabi/stack.go:StackLimit.
        _StackGuard = 928*sys.StackGuardMultiplier + _StackSystem
 
        // After a stack split check the SP is allowed to be this
@@ -107,6 +108,7 @@ const (
 
        // The maximum number of bytes that a chain of NOSPLIT
        // functions can use.
+       // This arithmetic must match that in cmd/internal/objabi/stack.go:StackLimit.
        _StackLimit = _StackGuard - _StackSystem - _StackSmall
 )