]> Cypherpunks.ru repositories - gostls13.git/commitdiff
internal/abi, runtime, cmd: merge StackSmall, StackBig consts into internal/abi
authorAustin Clements <austin@google.com>
Wed, 19 Apr 2023 17:21:02 +0000 (13:21 -0400)
committerGopher Robot <gobot@golang.org>
Fri, 21 Apr 2023 19:28:53 +0000 (19:28 +0000)
For #59670.

Change-Id: I91448363be2fc678964ce119d85cd5fae34a14da
Reviewed-on: https://go-review.googlesource.com/c/go/+/486975
Reviewed-by: Cherry Mui <cherryyz@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Run-TryBot: Austin Clements <austin@google.com>
Auto-Submit: Austin Clements <austin@google.com>

12 files changed:
src/cmd/internal/obj/arm/obj5.go
src/cmd/internal/obj/arm64/obj7.go
src/cmd/internal/obj/loong64/obj.go
src/cmd/internal/obj/mips/obj0.go
src/cmd/internal/obj/ppc64/obj9.go
src/cmd/internal/obj/riscv/obj.go
src/cmd/internal/obj/s390x/objz.go
src/cmd/internal/obj/wasm/wasmobj.go
src/cmd/internal/obj/x86/obj6.go
src/cmd/internal/objabi/stack.go
src/internal/abi/stack.go [new file with mode: 0644]
src/runtime/stack.go

index 285fb885cb6b5ec384ccea0a83b3606c1db9a1a4..fb7c260f89c7d7332f191c6c7d5c6888dfa68c08 100644 (file)
@@ -709,7 +709,7 @@ func (c *ctxt5) stacksplit(p *obj.Prog, framesize int32) *obj.Prog {
        // unnecessarily. See issue #35470.
        p = c.ctxt.StartUnsafePoint(p, c.newprog)
 
-       if framesize <= objabi.StackSmall {
+       if framesize <= abi.StackSmall {
                // small stack: SP < stackguard
                //      CMP     stackguard, SP
                p = obj.Appendp(p, c.newprog)
@@ -718,7 +718,7 @@ func (c *ctxt5) stacksplit(p *obj.Prog, framesize int32) *obj.Prog {
                p.From.Type = obj.TYPE_REG
                p.From.Reg = REG_R1
                p.Reg = REGSP
-       } else if framesize <= objabi.StackBig {
+       } else if framesize <= abi.StackBig {
                // large stack: SP-framesize < stackguard-StackSmall
                //      MOVW $-(framesize-StackSmall)(SP), R2
                //      CMP stackguard, R2
@@ -727,7 +727,7 @@ func (c *ctxt5) stacksplit(p *obj.Prog, framesize int32) *obj.Prog {
                p.As = AMOVW
                p.From.Type = obj.TYPE_ADDR
                p.From.Reg = REGSP
-               p.From.Offset = -(int64(framesize) - objabi.StackSmall)
+               p.From.Offset = -(int64(framesize) - abi.StackSmall)
                p.To.Type = obj.TYPE_REG
                p.To.Reg = REG_R2
 
@@ -754,7 +754,7 @@ func (c *ctxt5) stacksplit(p *obj.Prog, framesize int32) *obj.Prog {
                p.As = ASUB
                p.Scond = C_SBIT
                p.From.Type = obj.TYPE_CONST
-               p.From.Offset = int64(framesize) - objabi.StackSmall
+               p.From.Offset = int64(framesize) - abi.StackSmall
                p.Reg = REGSP
                p.To.Type = obj.TYPE_REG
                p.To.Reg = REG_R2
index fca064a85bf176c6fedcf2ed1afa687b067244d6..f963f62dcd1d2406755179ddc7b1dddeb5374d9c 100644 (file)
@@ -170,7 +170,7 @@ func (c *ctxt7) stacksplit(p *obj.Prog, framesize int32) *obj.Prog {
        p = c.ctxt.StartUnsafePoint(p, c.newprog)
 
        q := (*obj.Prog)(nil)
-       if framesize <= objabi.StackSmall {
+       if framesize <= abi.StackSmall {
                // small stack: SP < stackguard
                //      CMP     stackguard, SP
 
@@ -179,7 +179,7 @@ func (c *ctxt7) stacksplit(p *obj.Prog, framesize int32) *obj.Prog {
                p.From.Type = obj.TYPE_REG
                p.From.Reg = REGRT1
                p.Reg = REGSP
-       } else if framesize <= objabi.StackBig {
+       } else if framesize <= abi.StackBig {
                // large stack: SP-framesize < stackguard-StackSmall
                //      SUB     $(framesize-StackSmall), SP, RT2
                //      CMP     stackguard, RT2
@@ -187,7 +187,7 @@ func (c *ctxt7) stacksplit(p *obj.Prog, framesize int32) *obj.Prog {
 
                p.As = ASUB
                p.From.Type = obj.TYPE_CONST
-               p.From.Offset = int64(framesize) - objabi.StackSmall
+               p.From.Offset = int64(framesize) - abi.StackSmall
                p.Reg = REGSP
                p.To.Type = obj.TYPE_REG
                p.To.Reg = REGRT2
@@ -213,7 +213,7 @@ func (c *ctxt7) stacksplit(p *obj.Prog, framesize int32) *obj.Prog {
                p = obj.Appendp(p, c.newprog)
                p.As = ASUBS
                p.From.Type = obj.TYPE_CONST
-               p.From.Offset = int64(framesize) - objabi.StackSmall
+               p.From.Offset = int64(framesize) - abi.StackSmall
                p.Reg = REGSP
                p.To.Type = obj.TYPE_REG
                p.To.Reg = REGRT2
@@ -583,7 +583,7 @@ func preprocess(ctxt *obj.Link, cursym *obj.LSym, newprog obj.ProgAlloc) {
                                }
                        }
 
-                       if p.Mark&LEAF != 0 && c.autosize < objabi.StackSmall {
+                       if p.Mark&LEAF != 0 && c.autosize < abi.StackSmall {
                                // A leaf function with a small stack can be marked
                                // NOSPLIT, avoiding a stack check.
                                p.From.Sym.Set(obj.AttrNoSplit, true)
index 86a0bdd01540e7b6a87f6e42bde3b8612ab1c876..1eedd46c6998e67a2a11624901da3f5696c46c1f 100644 (file)
@@ -6,7 +6,6 @@ package loong64
 
 import (
        "cmd/internal/obj"
-       "cmd/internal/objabi"
        "cmd/internal/sys"
        "internal/abi"
        "log"
@@ -594,7 +593,7 @@ func (c *ctxt0) stacksplit(p *obj.Prog, framesize int32) *obj.Prog {
        p = c.ctxt.StartUnsafePoint(p, c.newprog)
 
        var q *obj.Prog
-       if framesize <= objabi.StackSmall {
+       if framesize <= abi.StackSmall {
                // small stack: SP < stackguard
                //      AGTU    SP, stackguard, R19
                p = obj.Appendp(p, c.newprog)
@@ -607,8 +606,8 @@ func (c *ctxt0) stacksplit(p *obj.Prog, framesize int32) *obj.Prog {
                p.To.Reg = REG_R19
        } else {
                // large stack: SP-framesize < stackguard-StackSmall
-               offset := int64(framesize) - objabi.StackSmall
-               if framesize > objabi.StackBig {
+               offset := int64(framesize) - abi.StackSmall
+               if framesize > abi.StackBig {
                        // Such a large stack we need to protect against underflow.
                        // The runtime guarantees SP > objabi.StackBig, but
                        // framesize is large enough that SP-framesize may
index e8b9c31c6002aac8849f34fb9ae352b77778e0f5..d3a8566958b9f7a0c3ba4e69f2554ce752d4dda6 100644 (file)
@@ -31,7 +31,6 @@ package mips
 
 import (
        "cmd/internal/obj"
-       "cmd/internal/objabi"
        "cmd/internal/sys"
        "encoding/binary"
        "fmt"
@@ -775,7 +774,7 @@ func (c *ctxt0) stacksplit(p *obj.Prog, framesize int32) *obj.Prog {
        p = c.ctxt.StartUnsafePoint(p, c.newprog)
 
        var q *obj.Prog
-       if framesize <= objabi.StackSmall {
+       if framesize <= abi.StackSmall {
                // small stack: SP < stackguard
                //      AGTU    SP, stackguard, R1
                p = obj.Appendp(p, c.newprog)
@@ -788,8 +787,8 @@ func (c *ctxt0) stacksplit(p *obj.Prog, framesize int32) *obj.Prog {
                p.To.Reg = REG_R1
        } else {
                // large stack: SP-framesize < stackguard-StackSmall
-               offset := int64(framesize) - objabi.StackSmall
-               if framesize > objabi.StackBig {
+               offset := int64(framesize) - abi.StackSmall
+               if framesize > abi.StackBig {
                        // Such a large stack we need to protect against underflow.
                        // The runtime guarantees SP > objabi.StackBig, but
                        // framesize is large enough that SP-framesize may
index a0ef52685517b38e40afa4fc91f776275e6bc95b..e10cd56e044de705abb91f49e0bee712efb8ac66 100644 (file)
@@ -633,7 +633,7 @@ func preprocess(ctxt *obj.Link, cursym *obj.LSym, newprog obj.ProgAlloc) {
                                autosize += int32(c.ctxt.Arch.FixedFrameSize)
                        }
 
-                       if p.Mark&LEAF != 0 && autosize < objabi.StackSmall {
+                       if p.Mark&LEAF != 0 && autosize < abi.StackSmall {
                                // A leaf function with a small stack can be marked
                                // NOSPLIT, avoiding a stack check.
                                p.From.Sym.Set(obj.AttrNoSplit, true)
@@ -1178,7 +1178,7 @@ func (c *ctxt9) stacksplit(p *obj.Prog, framesize int32) *obj.Prog {
        p = c.ctxt.StartUnsafePoint(p, c.newprog)
 
        var q *obj.Prog
-       if framesize <= objabi.StackSmall {
+       if framesize <= abi.StackSmall {
                // small stack: SP < stackguard
                //      CMP     stackguard, SP
                p = obj.Appendp(p, c.newprog)
@@ -1190,8 +1190,8 @@ func (c *ctxt9) stacksplit(p *obj.Prog, framesize int32) *obj.Prog {
                p.To.Reg = REGSP
        } else {
                // large stack: SP-framesize < stackguard-StackSmall
-               offset := int64(framesize) - objabi.StackSmall
-               if framesize > objabi.StackBig {
+               offset := int64(framesize) - abi.StackSmall
+               if framesize > abi.StackBig {
                        // Such a large stack we need to protect against underflow.
                        // The runtime guarantees SP > objabi.StackBig, but
                        // framesize is large enough that SP-framesize may
index 38ea19531d60fb931c2671504b8afed24436c756..68a25c7f153c6f9b89f7be90feb2355ae05ce9d4 100644 (file)
@@ -829,7 +829,7 @@ func stacksplit(ctxt *obj.Link, p *obj.Prog, cursym *obj.LSym, newprog obj.ProgA
 
        var to_done, to_more *obj.Prog
 
-       if framesize <= objabi.StackSmall {
+       if framesize <= abi.StackSmall {
                // small stack
                //      // if SP > stackguard { goto done }
                //      BLTU    stackguard, SP, done
@@ -842,8 +842,8 @@ func stacksplit(ctxt *obj.Link, p *obj.Prog, cursym *obj.LSym, newprog obj.ProgA
                to_done = p
        } else {
                // large stack: SP-framesize < stackguard-StackSmall
-               offset := int64(framesize) - objabi.StackSmall
-               if framesize > objabi.StackBig {
+               offset := int64(framesize) - abi.StackSmall
+               if framesize > abi.StackBig {
                        // Such a large stack we need to protect against underflow.
                        // The runtime guarantees SP > objabi.StackBig, but
                        // framesize is large enough that SP-framesize may
index 3bab614af616c336c565cbc1a602c77ca3892175..80b233d832f75920a532a3d8dbaab4cfbdb9d684 100644 (file)
@@ -314,7 +314,7 @@ func preprocess(ctxt *obj.Link, cursym *obj.LSym, newprog obj.ProgAlloc) {
                                autosize += int32(c.ctxt.Arch.FixedFrameSize)
                        }
 
-                       if p.Mark&LEAF != 0 && autosize < objabi.StackSmall {
+                       if p.Mark&LEAF != 0 && autosize < abi.StackSmall {
                                // A leaf function with a small stack can be marked
                                // NOSPLIT, avoiding a stack check.
                                p.From.Sym.Set(obj.AttrNoSplit, true)
@@ -663,7 +663,7 @@ func (c *ctxtz) stacksplitPre(p *obj.Prog, framesize int32) (pPre, pPreempt, pCh
        // unnecessarily. See issue #35470.
        p = c.ctxt.StartUnsafePoint(p, c.newprog)
 
-       if framesize <= objabi.StackSmall {
+       if framesize <= abi.StackSmall {
                // small stack: SP < stackguard
                //      CMPUBGE stackguard, SP, label-of-call-to-morestack
 
@@ -679,8 +679,8 @@ func (c *ctxtz) stacksplitPre(p *obj.Prog, framesize int32) (pPre, pPreempt, pCh
 
        // large stack: SP-framesize < stackguard-StackSmall
 
-       offset := int64(framesize) - objabi.StackSmall
-       if framesize > objabi.StackBig {
+       offset := int64(framesize) - abi.StackSmall
+       if framesize > abi.StackBig {
                // Such a large stack we need to protect against underflow.
                // The runtime guarantees SP > objabi.StackBig, but
                // framesize is large enough that SP-framesize may
index 6bf49c602d2eee693e77118517bee2bb9dc06e07..83b9329f12ac4350b03422c084af8c4361b450b1 100644 (file)
@@ -11,6 +11,7 @@ import (
        "cmd/internal/sys"
        "encoding/binary"
        "fmt"
+       "internal/abi"
        "io"
        "math"
 )
@@ -472,7 +473,7 @@ func preprocess(ctxt *obj.Link, s *obj.LSym, newprog obj.ProgAlloc) {
        if needMoreStack {
                p := pMorestack
 
-               if framesize <= objabi.StackSmall {
+               if framesize <= abi.StackSmall {
                        // small stack: SP <= stackguard
                        // Get SP
                        // Get g
@@ -500,7 +501,7 @@ func preprocess(ctxt *obj.Link, s *obj.LSym, newprog obj.ProgAlloc) {
                        p = appendp(p, AGet, regAddr(REGG))
                        p = appendp(p, AI32WrapI64)
                        p = appendp(p, AI32Load, constAddr(2*int64(ctxt.Arch.PtrSize))) // G.stackguard0
-                       p = appendp(p, AI32Const, constAddr(framesize-objabi.StackSmall))
+                       p = appendp(p, AI32Const, constAddr(framesize-abi.StackSmall))
                        p = appendp(p, AI32Add)
                        p = appendp(p, AI32LeU)
                }
index 7f202dadca131eb83a0b32a45166725ba5ec0c3d..46a136d48178d775a272aa750c1ca9acd480d388 100644 (file)
@@ -642,7 +642,7 @@ func preprocess(ctxt *obj.Link, cursym *obj.LSym, newprog obj.ProgAlloc) {
        }
 
        // TODO(rsc): Remove 'ctxt.Arch.Family == sys.AMD64 &&'.
-       if ctxt.Arch.Family == sys.AMD64 && autoffset < objabi.StackSmall && !p.From.Sym.NoSplit() {
+       if ctxt.Arch.Family == sys.AMD64 && autoffset < abi.StackSmall && !p.From.Sym.NoSplit() {
                leaf := true
        LeafSearch:
                for q := p; q != nil; q = q.Link {
@@ -656,7 +656,7 @@ func preprocess(ctxt *obj.Link, cursym *obj.LSym, newprog obj.ProgAlloc) {
                                }
                                fallthrough
                        case obj.ADUFFCOPY, obj.ADUFFZERO:
-                               if autoffset >= objabi.StackSmall-8 {
+                               if autoffset >= abi.StackSmall-8 {
                                        leaf = false
                                        break LeafSearch
                                }
@@ -1088,7 +1088,7 @@ func stacksplit(ctxt *obj.Link, cursym *obj.LSym, p *obj.Prog, newprog obj.ProgA
        p, rg = loadG(ctxt, cursym, p, newprog)
 
        var q1 *obj.Prog
-       if framesize <= objabi.StackSmall {
+       if framesize <= abi.StackSmall {
                // small stack: SP <= stackguard
                //      CMPQ SP, stackguard
                p = obj.Appendp(p, newprog)
@@ -1108,7 +1108,7 @@ func stacksplit(ctxt *obj.Link, cursym *obj.LSym, p *obj.Prog, newprog obj.ProgA
                // cleared, but we'll still call morestack, which will double the stack
                // unnecessarily. See issue #35470.
                p = ctxt.StartUnsafePoint(p, newprog)
-       } else if framesize <= objabi.StackBig {
+       } else if framesize <= abi.StackBig {
                // large stack: SP-framesize <= stackguard-StackSmall
                //      LEAQ -xxx(SP), tmp
                //      CMPQ tmp, stackguard
@@ -1117,7 +1117,7 @@ func stacksplit(ctxt *obj.Link, cursym *obj.LSym, p *obj.Prog, newprog obj.ProgA
                p.As = lea
                p.From.Type = obj.TYPE_MEM
                p.From.Reg = REG_SP
-               p.From.Offset = -(int64(framesize) - objabi.StackSmall)
+               p.From.Offset = -(int64(framesize) - abi.StackSmall)
                p.To.Type = obj.TYPE_REG
                p.To.Reg = tmp
 
@@ -1160,7 +1160,7 @@ func stacksplit(ctxt *obj.Link, cursym *obj.LSym, p *obj.Prog, newprog obj.ProgA
                p = obj.Appendp(p, newprog)
                p.As = sub
                p.From.Type = obj.TYPE_CONST
-               p.From.Offset = int64(framesize) - objabi.StackSmall
+               p.From.Offset = int64(framesize) - abi.StackSmall
                p.To.Type = obj.TYPE_REG
                p.To.Reg = tmp
 
index 88b4990d5e1b177196d608682eba8bd287f3f5ce..5a2f641a751dc2e86b3c9403fcdb0cda16210ecf 100644 (file)
@@ -4,21 +4,22 @@
 
 package objabi
 
-import "internal/buildcfg"
+import (
+       "internal/abi"
+       "internal/buildcfg"
+)
 
 // For the linkers. Must match Go definitions.
 
 const (
        STACKSYSTEM = 0
        StackSystem = STACKSYSTEM
-       StackBig    = 4096
-       StackSmall  = 128
 )
 
 func StackLimit(race bool) int {
        // This arithmetic must match that in runtime/stack.go:{_StackGuard,_StackLimit}.
        stackGuard := 928*stackGuardMultiplier(race) + StackSystem
-       stackLimit := stackGuard - StackSystem - StackSmall
+       stackLimit := stackGuard - StackSystem - abi.StackSmall
        return stackLimit
 }
 
diff --git a/src/internal/abi/stack.go b/src/internal/abi/stack.go
new file mode 100644 (file)
index 0000000..9efd21b
--- /dev/null
@@ -0,0 +1,25 @@
+// Copyright 2023 The Go Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style
+// license that can be found in the LICENSE file.
+
+package abi
+
+const (
+       // We have three different sequences for stack bounds checks, depending on
+       // whether the stack frame of a function is small, big, or huge.
+
+       // After a stack split check the SP is allowed to be StackSmall bytes below
+       // the stack guard.
+       //
+       // Functions that need frames <= StackSmall can perform the stack check
+       // using a single comparison directly between the stack guard and the SP
+       // because we ensure that StackSmall bytes of stack space are available
+       // beyond the stack guard.
+       StackSmall = 128
+
+       // Functions that need frames <= StackBig can assume that neither
+       // SP-framesize nor stackGuard-StackSmall will underflow, and thus use a
+       // more efficient check. In order to ensure this, StackBig must be <= the
+       // size of the unmapped space at zero.
+       StackBig = 4096
+)
index a1095382d31649017442bad9471a0fb3456a247c..6d75301556299226bc110041991814af2d0ab61e 100644 (file)
@@ -85,13 +85,6 @@ const (
        _FixedStack6 = _FixedStack5 | (_FixedStack5 >> 16)
        _FixedStack  = _FixedStack6 + 1
 
-       // Functions that need frames bigger than this use an extra
-       // instruction to do the stack split check, to avoid overflow
-       // in case SP - framesize wraps below zero.
-       // This value can be no bigger than the size of the unmapped
-       // space at zero.
-       _StackBig = 4096
-
        // The stack guard is a pointer this many bytes above the
        // bottom of the stack.
        //
@@ -101,15 +94,10 @@ const (
        // This arithmetic must match that in cmd/internal/objabi/stack.go:StackLimit.
        _StackGuard = 928*sys.StackGuardMultiplier + _StackSystem
 
-       // 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
-
        // The maximum number of bytes that a chain of NOSPLIT
        // functions can use.
        // This arithmetic must match that in cmd/internal/objabi/stack.go:StackLimit.
-       _StackLimit = _StackGuard - _StackSystem - _StackSmall
+       _StackLimit = _StackGuard - _StackSystem - abi.StackSmall
 )
 
 const (