Skip to content

Commit 893964b

Browse files
committed
runtime,cmd/link: increase stack guard space when building with -race
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 <[email protected]> Reviewed-by: Keith Randall <[email protected]> TryBot-Result: Gopher Robot <[email protected]> Reviewed-by: Michael Knyszek <[email protected]>
1 parent e18d07d commit 893964b

File tree

6 files changed

+39
-8
lines changed

6 files changed

+39
-8
lines changed

src/cmd/internal/objabi/stack.go

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,17 +15,26 @@ const (
1515
StackSmall = 128
1616
)
1717

18-
// Initialize StackGuard and StackLimit according to target system.
19-
var StackGuard = 928*stackGuardMultiplier() + StackSystem
20-
var StackLimit = StackGuard - StackSystem - StackSmall
18+
func StackLimit(race bool) int {
19+
// This arithmetic must match that in runtime/stack.go:{_StackGuard,_StackLimit}.
20+
stackGuard := 928*stackGuardMultiplier(race) + StackSystem
21+
stackLimit := stackGuard - StackSystem - StackSmall
22+
return stackLimit
23+
}
2124

2225
// stackGuardMultiplier returns a multiplier to apply to the default
2326
// stack guard size. Larger multipliers are used for non-optimized
2427
// builds that have larger stack frames or for specific targets.
25-
func stackGuardMultiplier() int {
28+
func stackGuardMultiplier(race bool) int {
29+
// This arithmetic must match that in runtime/internal/sys/consts.go:StackGuardMultiplier.
30+
n := 1
2631
// On AIX, a larger stack is needed for syscalls.
2732
if buildcfg.GOOS == "aix" {
28-
return 2
33+
n += 1
34+
}
35+
// The race build also needs more stack.
36+
if race {
37+
n += 1
2938
}
30-
return 1
39+
return n
3140
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ func (ctxt *Link) doStackCheck() {
6161
// The call to morestack in every splittable function ensures
6262
// that there are at least StackLimit bytes available below SP
6363
// when morestack returns.
64-
limit := objabi.StackLimit - sc.callSize
64+
limit := objabi.StackLimit(*flagRace) - sc.callSize
6565
if buildcfg.GOARCH == "arm64" {
6666
// Need an extra 8 bytes below SP to save FP.
6767
limit -= 8

src/runtime/internal/sys/consts.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,9 @@ import (
1010
)
1111

1212
// AIX requires a larger stack for syscalls.
13-
const StackGuardMultiplier = 1*(1-goos.IsAix) + 2*goos.IsAix
13+
// The race build also needs more stack. See issue 54291.
14+
// This arithmetic must match that in cmd/internal/objabi/stack.go:stackGuardMultiplier.
15+
const StackGuardMultiplier = 1 + goos.IsAix + isRace
1416

1517
// DefaultPhysPageSize is the default physical page size.
1618
const DefaultPhysPageSize = goarch.DefaultPhysPageSize
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
// Copyright 2022 The Go Authors. All rights reserved.
2+
// Use of this source code is governed by a BSD-style
3+
// license that can be found in the LICENSE file.
4+
5+
//go:build !race
6+
7+
package sys
8+
9+
const isRace = 0
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
// Copyright 2022 The Go Authors. All rights reserved.
2+
// Use of this source code is governed by a BSD-style
3+
// license that can be found in the LICENSE file.
4+
5+
//go:build race
6+
7+
package sys
8+
9+
const isRace = 1

src/runtime/stack.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,7 @@ const (
9898
// The guard leaves enough room for one _StackSmall frame plus
9999
// a _StackLimit chain of NOSPLIT calls plus _StackSystem
100100
// bytes for the OS.
101+
// This arithmetic must match that in cmd/internal/objabi/stack.go:StackLimit.
101102
_StackGuard = 928*sys.StackGuardMultiplier + _StackSystem
102103

103104
// After a stack split check the SP is allowed to be this
@@ -107,6 +108,7 @@ const (
107108

108109
// The maximum number of bytes that a chain of NOSPLIT
109110
// functions can use.
111+
// This arithmetic must match that in cmd/internal/objabi/stack.go:StackLimit.
110112
_StackLimit = _StackGuard - _StackSystem - _StackSmall
111113
)
112114

0 commit comments

Comments
 (0)