File tree 6 files changed +39
-8
lines changed 6 files changed +39
-8
lines changed Original file line number Diff line number Diff line change @@ -15,17 +15,26 @@ const (
15
15
StackSmall = 128
16
16
)
17
17
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
+ }
21
24
22
25
// stackGuardMultiplier returns a multiplier to apply to the default
23
26
// stack guard size. Larger multipliers are used for non-optimized
24
27
// 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
26
31
// On AIX, a larger stack is needed for syscalls.
27
32
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
29
38
}
30
- return 1
39
+ return n
31
40
}
Original file line number Diff line number Diff line change @@ -61,7 +61,7 @@ func (ctxt *Link) doStackCheck() {
61
61
// The call to morestack in every splittable function ensures
62
62
// that there are at least StackLimit bytes available below SP
63
63
// when morestack returns.
64
- limit := objabi .StackLimit - sc .callSize
64
+ limit := objabi .StackLimit ( * flagRace ) - sc .callSize
65
65
if buildcfg .GOARCH == "arm64" {
66
66
// Need an extra 8 bytes below SP to save FP.
67
67
limit -= 8
Original file line number Diff line number Diff line change @@ -10,7 +10,9 @@ import (
10
10
)
11
11
12
12
// 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
14
16
15
17
// DefaultPhysPageSize is the default physical page size.
16
18
const DefaultPhysPageSize = goarch .DefaultPhysPageSize
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change @@ -98,6 +98,7 @@ const (
98
98
// The guard leaves enough room for one _StackSmall frame plus
99
99
// a _StackLimit chain of NOSPLIT calls plus _StackSystem
100
100
// bytes for the OS.
101
+ // This arithmetic must match that in cmd/internal/objabi/stack.go:StackLimit.
101
102
_StackGuard = 928 * sys .StackGuardMultiplier + _StackSystem
102
103
103
104
// After a stack split check the SP is allowed to be this
@@ -107,6 +108,7 @@ const (
107
108
108
109
// The maximum number of bytes that a chain of NOSPLIT
109
110
// functions can use.
111
+ // This arithmetic must match that in cmd/internal/objabi/stack.go:StackLimit.
110
112
_StackLimit = _StackGuard - _StackSystem - _StackSmall
111
113
)
112
114
You can’t perform that action at this time.
0 commit comments