]> Cypherpunks repositories - gostls13.git/commitdiff
runtime: give nosplit functions 32 more bytes of headroom
authorRuss Cox <rsc@golang.org>
Wed, 27 Aug 2014 18:08:26 +0000 (14:08 -0400)
committerRuss Cox <rsc@golang.org>
Wed, 27 Aug 2014 18:08:26 +0000 (14:08 -0400)
The Go calling convention uses more stack space than C.
On 64-bit systems we've been right up against the limit
(128 bytes, so only 16 words) and doing awful things to
our source code to work around it. Instead of continuing
to do awful things, raise the limit to 160 bytes.
I am prepared to raise the limit to 192 bytes if necessary,
but I think this will be enough.

Should fix current link-time stack overflow errors on
        - nacl/arm
        - netbsd/amd64
        - openbsd/amd64
        - solaris/amd64
        - windows/amd64

TBR=r
CC=golang-codereviews, iant
https://golang.org/cl/131450043

src/pkg/runtime/stack.h
src/pkg/runtime/stack_test.go
test/nosplit.go

index ee5fd351d5f8281d7fc8634ee3ea9897667ef1dd..b2de78d898db3f4a157453bf46873736202ed471 100644 (file)
@@ -94,7 +94,7 @@ enum {
        // After a stack split check the SP is allowed to be this
        // many bytes below the stack guard.  This saves an instruction
        // in the checking sequence for tiny frames.
-       StackSmall = 128,
+       StackSmall = 96,
 
        // The maximum number of bytes that a chain of NOSPLIT
        // functions can use.
index 08282afd42a8114a42fd2b8e9377d3d7d6e35c44..956c282136d4a931ebfcd0ccd89d5095c2043aff 100644 (file)
@@ -15,7 +15,8 @@ import (
 // See stack.h.
 const (
        StackGuard = 256
-       StackLimit = 128
+       StackSmall = 96
+       StackLimit = StackGuard - StackSmall
 )
 
 // Test stack split logic by calling functions of every frame size
index 35aa51017a287935bad68ebb67963458feb0f1af..39bb3fcb47868342b0764c0c3dbddcc3f68e76f2 100644 (file)
@@ -242,7 +242,7 @@ TestCases:
                        if line == "" {
                                continue
                        }
-                       for _, subline := range strings.Split(line, ";") {
+                       for i, subline := range strings.Split(line, ";") {
                                subline = strings.TrimSpace(subline)
                                if subline == "" {
                                        continue
@@ -255,6 +255,14 @@ TestCases:
                                }
                                name := m[1]
                                size, _ := strconv.Atoi(m[2])
+
+                               // CL 131450043 raised the limit from 128 to 160.
+                               // Instead of rewriting the test cases above, adjust
+                               // the first stack frame to use up the extra 32 bytes.
+                               if i == 0 {
+                                       size += 32
+                               }
+
                                if goarch == "amd64" && size%8 == 4 {
                                        continue TestCases
                                }