]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/dist, runtime: Make stack guard larger for non-optimized builds
authorKeith Randall <khr@golang.org>
Thu, 30 Apr 2015 23:57:23 +0000 (16:57 -0700)
committerKeith Randall <khr@golang.org>
Fri, 1 May 2015 15:41:55 +0000 (15:41 +0000)
Kind of a hack, but makes the non-optimized builds pass.

Fixes #10079

Change-Id: I26f41c546867f8f3f16d953dc043e784768f2aff
Reviewed-on: https://go-review.googlesource.com/9552
Reviewed-by: Russ Cox <rsc@golang.org>
src/cmd/dist/buildruntime.go
src/cmd/internal/obj/stack.go
src/runtime/proc1.go
src/runtime/stack2.go

index 73f4d8eaf16ab5d0b187aebef19b019d6fbe4fe9..70aafe9183f9db143f7212f0a3e5e6f47cd39189 100644 (file)
@@ -7,6 +7,7 @@ package main
 import (
        "fmt"
        "os"
+       "strings"
 )
 
 /*
@@ -18,6 +19,9 @@ import (
 //     package runtime
 //     const defaultGoroot = <goroot>
 //     const theVersion = <version>
+//     const goexperiment = <goexperiment>
+//     const stackGuardMultiplier = <multiplier value>
+//     const buildVersion = <build version>
 //
 func mkzversion(dir, file string) {
        out := fmt.Sprintf(
@@ -28,7 +32,8 @@ func mkzversion(dir, file string) {
                        "const defaultGoroot = `%s`\n"+
                        "const theVersion = `%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)
 }
@@ -44,6 +49,7 @@ func mkzversion(dir, file string) {
 //     const defaultGOARCH = runtime.GOARCH
 //     const defaultGO_EXTLINK_ENABLED = <goextlinkenabled>
 //     const version = <version>
+//     const stackGuardMultiplier = <multiplier value>
 //     const goexperiment = <goexperiment>
 //
 // The use of runtime.GOOS and runtime.GOARCH makes sure that
@@ -70,8 +76,21 @@ func mkzbootstrap(file string) {
                        "const defaultGOARCH = runtime.GOARCH\n"+
                        "const defaultGO_EXTLINK_ENABLED = `%s`\n"+
                        "const version = `%s`\n"+
+                       "const stackGuardMultiplier = %d\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)
 }
+
+// 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
+}
index 9324ef6d1bf1ac0bbc25e4d568772fd474d895b4..87698b3eeb82e148f53b82cfd919c65e69ed2411 100644 (file)
@@ -41,7 +41,7 @@ const (
        STACKSYSTEM = 0
        StackSystem = STACKSYSTEM
        StackBig    = 4096
-       StackGuard  = 640 + StackSystem
+       StackGuard  = 640*stackGuardMultiplier + StackSystem
        StackSmall  = 128
        StackLimit  = StackGuard - StackSystem - StackSmall
 )
index 8b87f818d3eac0e4ec9444351238082c52d8e436..1c81b1252aec7399770abb4fd156c5699befee73 100644 (file)
@@ -691,7 +691,7 @@ func mstart() {
                // Cgo may have left stack size in stack.hi.
                size := _g_.stack.hi
                if size == 0 {
-                       size = 8192
+                       size = 8192 * stackGuardMultiplier
                }
                _g_.stack.hi = uintptr(noescape(unsafe.Pointer(&size)))
                _g_.stack.lo = _g_.stack.hi - size + 1024
@@ -890,7 +890,7 @@ func allocm(_p_ *p, fn func()) *m {
        if iscgo || GOOS == "solaris" || GOOS == "windows" || GOOS == "plan9" {
                mp.g0 = malg(-1)
        } else {
-               mp.g0 = malg(8192)
+               mp.g0 = malg(8192 * stackGuardMultiplier)
        }
        mp.g0.m = mp
 
index 07a7d38f0c1a56fdac53a87e38cf98e5950d072a..5ec8d8d060f6e4308fd4d328722648298af47158 100644 (file)
@@ -84,7 +84,7 @@ const (
 
        // The stack guard is a pointer this many bytes above the
        // bottom of the stack.
-       _StackGuard = 640 + _StackSystem
+       _StackGuard = 640*stackGuardMultiplier + _StackSystem
 
        // After a stack split check the SP is allowed to be this
        // many bytes below the stack guard.  This saves an instruction