Commit a55b1313 authored by Keith Randall's avatar Keith Randall

cmd/dist, runtime: Make stack guard larger for non-optimized builds

Kind of a hack, but makes the non-optimized builds pass.

Fixes #10079

Change-Id: I26f41c546867f8f3f16d953dc043e784768f2aff
Reviewed-on: https://go-review.googlesource.com/9552Reviewed-by: 's avatarRuss Cox <rsc@golang.org>
parent 7fbb1b36
...@@ -7,6 +7,7 @@ package main ...@@ -7,6 +7,7 @@ package main
import ( import (
"fmt" "fmt"
"os" "os"
"strings"
) )
/* /*
...@@ -18,6 +19,9 @@ import ( ...@@ -18,6 +19,9 @@ import (
// package runtime // package runtime
// const defaultGoroot = <goroot> // const defaultGoroot = <goroot>
// const theVersion = <version> // const theVersion = <version>
// const goexperiment = <goexperiment>
// const stackGuardMultiplier = <multiplier value>
// const buildVersion = <build version>
// //
func mkzversion(dir, file string) { func mkzversion(dir, file string) {
out := fmt.Sprintf( out := fmt.Sprintf(
...@@ -28,7 +32,8 @@ func mkzversion(dir, file string) { ...@@ -28,7 +32,8 @@ func mkzversion(dir, file string) {
"const defaultGoroot = `%s`\n"+ "const defaultGoroot = `%s`\n"+
"const theVersion = `%s`\n"+ "const theVersion = `%s`\n"+
"const goexperiment = `%s`\n"+ "const goexperiment = `%s`\n"+
"var buildVersion = theVersion\n", goroot_final, findgoversion(), os.Getenv("GOEXPERIMENT")) "const stackGuardMultiplier = %d\n"+
"var buildVersion = theVersion\n", goroot_final, findgoversion(), os.Getenv("GOEXPERIMENT"), stackGuardMultiplier())
writefile(out, file, 0) writefile(out, file, 0)
} }
...@@ -44,6 +49,7 @@ func mkzversion(dir, file string) { ...@@ -44,6 +49,7 @@ func mkzversion(dir, file string) {
// const defaultGOARCH = runtime.GOARCH // const defaultGOARCH = runtime.GOARCH
// const defaultGO_EXTLINK_ENABLED = <goextlinkenabled> // const defaultGO_EXTLINK_ENABLED = <goextlinkenabled>
// const version = <version> // const version = <version>
// const stackGuardMultiplier = <multiplier value>
// const goexperiment = <goexperiment> // const goexperiment = <goexperiment>
// //
// The use of runtime.GOOS and runtime.GOARCH makes sure that // The use of runtime.GOOS and runtime.GOARCH makes sure that
...@@ -70,8 +76,21 @@ func mkzbootstrap(file string) { ...@@ -70,8 +76,21 @@ func mkzbootstrap(file string) {
"const defaultGOARCH = runtime.GOARCH\n"+ "const defaultGOARCH = runtime.GOARCH\n"+
"const defaultGO_EXTLINK_ENABLED = `%s`\n"+ "const defaultGO_EXTLINK_ENABLED = `%s`\n"+
"const version = `%s`\n"+ "const version = `%s`\n"+
"const stackGuardMultiplier = %d\n"+
"const goexperiment = `%s`\n", "const goexperiment = `%s`\n",
goroot_final, go386, goarm, goextlinkenabled, findgoversion(), os.Getenv("GOEXPERIMENT")) goroot_final, go386, goarm, goextlinkenabled, findgoversion(), stackGuardMultiplier(), os.Getenv("GOEXPERIMENT"))
writefile(out, file, 0) writefile(out, file, 0)
} }
// 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.
func stackGuardMultiplier() int {
for _, s := range strings.Split(os.Getenv("GO_GCFLAGS"), " ") {
if s == "-N" {
return 2
}
}
return 1
}
...@@ -41,7 +41,7 @@ const ( ...@@ -41,7 +41,7 @@ const (
STACKSYSTEM = 0 STACKSYSTEM = 0
StackSystem = STACKSYSTEM StackSystem = STACKSYSTEM
StackBig = 4096 StackBig = 4096
StackGuard = 640 + StackSystem StackGuard = 640*stackGuardMultiplier + StackSystem
StackSmall = 128 StackSmall = 128
StackLimit = StackGuard - StackSystem - StackSmall StackLimit = StackGuard - StackSystem - StackSmall
) )
......
...@@ -691,7 +691,7 @@ func mstart() { ...@@ -691,7 +691,7 @@ func mstart() {
// Cgo may have left stack size in stack.hi. // Cgo may have left stack size in stack.hi.
size := _g_.stack.hi size := _g_.stack.hi
if size == 0 { if size == 0 {
size = 8192 size = 8192 * stackGuardMultiplier
} }
_g_.stack.hi = uintptr(noescape(unsafe.Pointer(&size))) _g_.stack.hi = uintptr(noescape(unsafe.Pointer(&size)))
_g_.stack.lo = _g_.stack.hi - size + 1024 _g_.stack.lo = _g_.stack.hi - size + 1024
...@@ -890,7 +890,7 @@ func allocm(_p_ *p, fn func()) *m { ...@@ -890,7 +890,7 @@ func allocm(_p_ *p, fn func()) *m {
if iscgo || GOOS == "solaris" || GOOS == "windows" || GOOS == "plan9" { if iscgo || GOOS == "solaris" || GOOS == "windows" || GOOS == "plan9" {
mp.g0 = malg(-1) mp.g0 = malg(-1)
} else { } else {
mp.g0 = malg(8192) mp.g0 = malg(8192 * stackGuardMultiplier)
} }
mp.g0.m = mp mp.g0.m = mp
......
...@@ -84,7 +84,7 @@ const ( ...@@ -84,7 +84,7 @@ const (
// The stack guard is a pointer this many bytes above the // The stack guard is a pointer this many bytes above the
// bottom of the stack. // bottom of the stack.
_StackGuard = 640 + _StackSystem _StackGuard = 640*stackGuardMultiplier + _StackSystem
// After a stack split check the SP is allowed to be this // After a stack split check the SP is allowed to be this
// many bytes below the stack guard. This saves an instruction // many bytes below the stack guard. This saves an instruction
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment