github.com/bir3/gocompiler@v0.3.205/src/cmd/internal/objabi/stack.go (about) 1 // Copyright 2011 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 package objabi 6 7 import "github.com/bir3/gocompiler/src/internal/buildcfg" 8 9 // For the linkers. Must match Go definitions. 10 11 const ( 12 STACKSYSTEM = 0 13 StackSystem = STACKSYSTEM 14 StackBig = 4096 15 StackSmall = 128 16 ) 17 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 } 24 25 // stackGuardMultiplier returns a multiplier to apply to the default 26 // stack guard size. Larger multipliers are used for non-optimized 27 // builds that have larger stack frames or for specific targets. 28 func stackGuardMultiplier(race bool) int { 29 // This arithmetic must match that in runtime/internal/sys/consts.go:StackGuardMultiplier. 30 n := 1 31 // On AIX, a larger stack is needed for syscalls. 32 if buildcfg.GOOS == "aix" { 33 n += 1 34 } 35 // The race build also needs more stack. 36 if race { 37 n += 1 38 } 39 return n 40 }