]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/compile: add memory argument to GetCallerSP
authorKeith Randall <khr@golang.org>
Sat, 26 Nov 2022 23:03:51 +0000 (15:03 -0800)
committerKeith Randall <khr@google.com>
Thu, 19 Jan 2023 22:43:22 +0000 (22:43 +0000)
We need to make sure that when we get the stack pointer, we get it
at the right time.

V = GetCallerSP
Call()
W = GetCallerSP

If Call causes a stack growth, then we will be in a situation
where V != W. So it matters when GetCallerSP operations get scheduled.
Add a memory argument to GetCallerSP so it can't be reordered with
things like calls.

Change-Id: I6cc801134c38e358c5a1ec0c09d38379a16a4184
Reviewed-on: https://go-review.googlesource.com/c/go/+/453515
Reviewed-by: Martin Möhrmann <moehrmann@google.com>
Run-TryBot: Keith Randall <khr@golang.org>
Reviewed-by: Martin Möhrmann <martin@golang.org>
Reviewed-by: Robert Griesemer <gri@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>

15 files changed:
src/cmd/compile/internal/ssa/_gen/386Ops.go
src/cmd/compile/internal/ssa/_gen/AMD64Ops.go
src/cmd/compile/internal/ssa/_gen/ARM64Ops.go
src/cmd/compile/internal/ssa/_gen/ARMOps.go
src/cmd/compile/internal/ssa/_gen/LOONG64Ops.go
src/cmd/compile/internal/ssa/_gen/MIPS64Ops.go
src/cmd/compile/internal/ssa/_gen/MIPSOps.go
src/cmd/compile/internal/ssa/_gen/PPC64Ops.go
src/cmd/compile/internal/ssa/_gen/RISCV64Ops.go
src/cmd/compile/internal/ssa/_gen/S390XOps.go
src/cmd/compile/internal/ssa/_gen/WasmOps.go
src/cmd/compile/internal/ssa/_gen/genericOps.go
src/cmd/compile/internal/ssa/expand_calls.go
src/cmd/compile/internal/ssa/opGen.go
src/cmd/compile/internal/ssagen/ssa.go

index c66650cdacafb35ff6f303f70045b68ae05e3f73..589bf133a5c426f3475b12a4d7dd307c471a190f 100644 (file)
@@ -511,8 +511,8 @@ func init() {
                // the result should be the PC within f that g will return to.
                // See runtime/stubs.go for a more detailed discussion.
                {name: "LoweredGetCallerPC", reg: gp01, rematerializeable: true},
-               // LoweredGetCallerSP returns the SP of the caller of the current function.
-               {name: "LoweredGetCallerSP", reg: gp01, rematerializeable: true},
+               // LoweredGetCallerSP returns the SP of the caller of the current function. arg0=mem
+               {name: "LoweredGetCallerSP", argLength: 1, reg: gp01, rematerializeable: true},
                //arg0=ptr,arg1=mem, returns void.  Faults if ptr is nil.
                {name: "LoweredNilCheck", argLength: 2, reg: regInfo{inputs: []regMask{gpsp}}, clobberFlags: true, nilCheck: true, faultOnNilArg0: true},
 
index cbe1f5b761bbd0b6b5f34c3e62650229273572a3..3cb70531054e5c34ebe076e97efebade34824eaf 100644 (file)
@@ -930,8 +930,8 @@ func init() {
                // the result should be the PC within f that g will return to.
                // See runtime/stubs.go for a more detailed discussion.
                {name: "LoweredGetCallerPC", reg: gp01, rematerializeable: true},
-               // LoweredGetCallerSP returns the SP of the caller of the current function.
-               {name: "LoweredGetCallerSP", reg: gp01, rematerializeable: true},
+               // LoweredGetCallerSP returns the SP of the caller of the current function. arg0=mem
+               {name: "LoweredGetCallerSP", argLength: 1, reg: gp01, rematerializeable: true},
                //arg0=ptr,arg1=mem, returns void.  Faults if ptr is nil.
                {name: "LoweredNilCheck", argLength: 2, reg: regInfo{inputs: []regMask{gpsp}}, clobberFlags: true, nilCheck: true, faultOnNilArg0: true},
                // LoweredWB invokes runtime.gcWriteBarrier. arg0=destptr, arg1=srcptr, arg2=mem, aux=runtime.gcWriteBarrier
index f7cc47bae2b0dc3577d5a560df9936537ba87903..badaf95e9aaf63a8763a01803b7c9be501afe5f0 100644 (file)
@@ -603,8 +603,8 @@ func init() {
                // use of R26 (arm64.REGCTXT, the closure pointer)
                {name: "LoweredGetClosurePtr", reg: regInfo{outputs: []regMask{buildReg("R26")}}, zeroWidth: true},
 
-               // LoweredGetCallerSP returns the SP of the caller of the current function.
-               {name: "LoweredGetCallerSP", reg: gp01, rematerializeable: true},
+               // LoweredGetCallerSP returns the SP of the caller of the current function. arg0=mem
+               {name: "LoweredGetCallerSP", argLength: 1, reg: gp01, rematerializeable: true},
 
                // LoweredGetCallerPC evaluates to the PC to which its "caller" will return.
                // I.e., if f calls g "calls" getcallerpc,
index de477a22af8ce9270eeca4d8f8b1068b75321a64..f4a400b35b487b2986e85c408a8cbd098cbc7734 100644 (file)
@@ -531,8 +531,8 @@ func init() {
                // use of R7 (arm.REGCTXT, the closure pointer)
                {name: "LoweredGetClosurePtr", reg: regInfo{outputs: []regMask{buildReg("R7")}}, zeroWidth: true},
 
-               // LoweredGetCallerSP returns the SP of the caller of the current function.
-               {name: "LoweredGetCallerSP", reg: gp01, rematerializeable: true},
+               // LoweredGetCallerSP returns the SP of the caller of the current function. arg0=mem.
+               {name: "LoweredGetCallerSP", argLength: 1, reg: gp01, rematerializeable: true},
 
                // LoweredGetCallerPC evaluates to the PC to which its "caller" will return.
                // I.e., if f calls g "calls" getcallerpc,
index 22a83fb300a110b24241614eac996951d33a0619..40e7a6801e5ae1ff49d5f683304295133cfd141b 100644 (file)
@@ -432,8 +432,8 @@ func init() {
                // use of R22 (loong64.REGCTXT, the closure pointer)
                {name: "LoweredGetClosurePtr", reg: regInfo{outputs: []regMask{buildReg("R29")}}, zeroWidth: true},
 
-               // LoweredGetCallerSP returns the SP of the caller of the current function.
-               {name: "LoweredGetCallerSP", reg: gp01, rematerializeable: true},
+               // LoweredGetCallerSP returns the SP of the caller of the current function. arg0=mem.
+               {name: "LoweredGetCallerSP", argLength: 1, reg: gp01, rematerializeable: true},
 
                // LoweredGetCallerPC evaluates to the PC to which its "caller" will return.
                // I.e., if f calls g "calls" getcallerpc,
index 89c87720ed317117416efe3f4534b650e688658a..58ea40f86e21f7f457e04261d6c63735339d4f92 100644 (file)
@@ -432,8 +432,8 @@ func init() {
                // use of R22 (mips.REGCTXT, the closure pointer)
                {name: "LoweredGetClosurePtr", reg: regInfo{outputs: []regMask{buildReg("R22")}}, zeroWidth: true},
 
-               // LoweredGetCallerSP returns the SP of the caller of the current function.
-               {name: "LoweredGetCallerSP", reg: gp01, rematerializeable: true},
+               // LoweredGetCallerSP returns the SP of the caller of the current function. arg0=mem.
+               {name: "LoweredGetCallerSP", argLength: 1, reg: gp01, rematerializeable: true},
 
                // LoweredGetCallerPC evaluates to the PC to which its "caller" will return.
                // I.e., if f calls g "calls" getcallerpc,
index 22a7a5c867dfd838b32e0a2407a724efb2a986b9..4b7741a6cdaad62a66b40a8b67d5d851f161360b 100644 (file)
@@ -385,8 +385,8 @@ func init() {
                // use of R22 (mips.REGCTXT, the closure pointer)
                {name: "LoweredGetClosurePtr", reg: regInfo{outputs: []regMask{buildReg("R22")}}, zeroWidth: true},
 
-               // LoweredGetCallerSP returns the SP of the caller of the current function.
-               {name: "LoweredGetCallerSP", reg: gp01, rematerializeable: true},
+               // LoweredGetCallerSP returns the SP of the caller of the current function. arg0=mem.
+               {name: "LoweredGetCallerSP", argLength: 1, reg: gp01, rematerializeable: true},
 
                // LoweredGetCallerPC evaluates to the PC to which its "caller" will return.
                // I.e., if f calls g "calls" getcallerpc,
index 2d651dd780332eb885ec20ef7ac33b926fdacbf5..88d85ed946d1ada68efa4589d7e11dfcccbaac99 100644 (file)
@@ -430,8 +430,8 @@ func init() {
                // use of the closure pointer.
                {name: "LoweredGetClosurePtr", reg: regInfo{outputs: []regMask{ctxt}}, zeroWidth: true},
 
-               // LoweredGetCallerSP returns the SP of the caller of the current function.
-               {name: "LoweredGetCallerSP", reg: gp01, rematerializeable: true},
+               // LoweredGetCallerSP returns the SP of the caller of the current function. arg0=mem.
+               {name: "LoweredGetCallerSP", argLength: 1, reg: gp01, rematerializeable: true},
 
                // LoweredGetCallerPC evaluates to the PC to which its "caller" will return.
                // I.e., if f calls g "calls" getcallerpc,
index 09b1620962654af535faaf5f350787aa40668549..82d21b48f00e25a239abc5874ef600a35d243c5a 100644 (file)
@@ -379,8 +379,8 @@ func init() {
                {name: "LoweredNilCheck", argLength: 2, faultOnNilArg0: true, nilCheck: true, reg: regInfo{inputs: []regMask{gpspMask}}}, // arg0=ptr,arg1=mem, returns void.  Faults if ptr is nil.
                {name: "LoweredGetClosurePtr", reg: regInfo{outputs: []regMask{regCtxt}}},                                                // scheduler ensures only at beginning of entry block
 
-               // LoweredGetCallerSP returns the SP of the caller of the current function.
-               {name: "LoweredGetCallerSP", reg: gp01, rematerializeable: true},
+               // LoweredGetCallerSP returns the SP of the caller of the current function. arg0=mem.
+               {name: "LoweredGetCallerSP", argLength: 1, reg: gp01, rematerializeable: true},
 
                // LoweredGetCallerPC evaluates to the PC to which its "caller" will return.
                // I.e., if f calls g "calls" getcallerpc,
index 896fdaa20fd75433bb6ab986b2592d486f200074..f2184ad11fef87ee0cfba5951c7581ab9c8ffc53 100644 (file)
@@ -492,8 +492,8 @@ func init() {
                // use of R12 (the closure pointer)
                {name: "LoweredGetClosurePtr", reg: regInfo{outputs: []regMask{buildReg("R12")}}, zeroWidth: true},
                // arg0=ptr,arg1=mem, returns void.  Faults if ptr is nil.
-               // LoweredGetCallerSP returns the SP of the caller of the current function.
-               {name: "LoweredGetCallerSP", reg: gp01, rematerializeable: true},
+               // LoweredGetCallerSP returns the SP of the caller of the current function. arg0=mem.
+               {name: "LoweredGetCallerSP", argLength: 1, reg: gp01, rematerializeable: true},
                // LoweredGetCallerPC evaluates to the PC to which its "caller" will return.
                // I.e., if f calls g "calls" getcallerpc,
                // the result should be the PC within f that g will return to.
index cd127b5f06ce1f9b1e301fb4cb4aaadf4cf8aacf..c9409bcfcc22be2e07b39e5c10f7e6ecaae24d40 100644 (file)
@@ -131,7 +131,7 @@ func init() {
 
                {name: "LoweredGetClosurePtr", reg: gp01},                                                                          // returns wasm.REG_CTXT, the closure pointer
                {name: "LoweredGetCallerPC", reg: gp01, rematerializeable: true},                                                   // returns the PC of the caller of the current function
-               {name: "LoweredGetCallerSP", reg: gp01, rematerializeable: true},                                                   // returns the SP of the caller of the current function
+               {name: "LoweredGetCallerSP", argLength: 1, reg: gp01, rematerializeable: true},                                     // returns the SP of the caller of the current function. arg0=mem.
                {name: "LoweredNilCheck", argLength: 2, reg: regInfo{inputs: []regMask{gp}}, nilCheck: true, faultOnNilArg0: true}, // panic if arg0 is nil. arg1=mem
                {name: "LoweredWB", argLength: 3, reg: regInfo{inputs: []regMask{gp, gp}}, aux: "Sym", symEffect: "None"},          // invokes runtime.gcWriteBarrier. arg0=destptr, arg1=srcptr, arg2=mem, aux=runtime.gcWriteBarrier
 
index 40c9baf5f1e82bcae4586b111689822de84a4206..cb4470a99be7024bfe850652030845dc68d23a5c 100644 (file)
@@ -475,7 +475,7 @@ var genericOps = []opData{
        {name: "GetG", argLength: 1, zeroWidth: true}, // runtime.getg() (read g pointer). arg0=mem
        {name: "GetClosurePtr"},                       // get closure pointer from dedicated register
        {name: "GetCallerPC"},                         // for getcallerpc intrinsic
-       {name: "GetCallerSP"},                         // for getcallersp intrinsic
+       {name: "GetCallerSP", argLength: 1},           // for getcallersp intrinsic. arg0=mem.
 
        // Indexing operations
        {name: "PtrIndex", argLength: 2},             // arg0=ptr, arg1=index. Computes ptr+sizeof(*v.type)*index, where index is extended to ptrwidth type
index 949a8d3a2487ef8dac8c71f12988857df05289fe..26a944dfaeb8c5779142cad588c2247d201440f8 100644 (file)
@@ -1090,7 +1090,7 @@ func (x *expandState) rewriteArgs(v *Value, firstArg int) {
        if v.Op == OpTailLECall {
                // For tail call, we unwind the frame before the call so we'll use the caller's
                // SP.
-               sp = x.f.Entry.NewValue0(src.NoXPos, OpGetCallerSP, x.typs.Uintptr)
+               sp = x.f.Entry.NewValue1(src.NoXPos, OpGetCallerSP, x.typs.Uintptr, mem)
        }
        for i, a := range v.Args[firstArg : len(v.Args)-1] { // skip leading non-parameter SSA Args and trailing mem SSA Arg.
                oldArgs = append(oldArgs, a)
index c59cfdd9ef1933e7db3f62286d04cef55e7bc2f1..597dc9c72e438246a09b3a8eaed99e8b51df39ae 100644 (file)
@@ -6296,7 +6296,7 @@ var opcodeTable = [...]opInfo{
        },
        {
                name:              "LoweredGetCallerSP",
-               argLen:            0,
+               argLen:            1,
                rematerializeable: true,
                reg: regInfo{
                        outputs: []outputInfo{
@@ -13501,7 +13501,7 @@ var opcodeTable = [...]opInfo{
        },
        {
                name:              "LoweredGetCallerSP",
-               argLen:            0,
+               argLen:            1,
                rematerializeable: true,
                reg: regInfo{
                        outputs: []outputInfo{
@@ -18363,7 +18363,7 @@ var opcodeTable = [...]opInfo{
        },
        {
                name:              "LoweredGetCallerSP",
-               argLen:            0,
+               argLen:            1,
                rematerializeable: true,
                reg: regInfo{
                        outputs: []outputInfo{
@@ -22329,7 +22329,7 @@ var opcodeTable = [...]opInfo{
        },
        {
                name:              "LoweredGetCallerSP",
-               argLen:            0,
+               argLen:            1,
                rematerializeable: true,
                reg: regInfo{
                        outputs: []outputInfo{
@@ -24507,7 +24507,7 @@ var opcodeTable = [...]opInfo{
        },
        {
                name:              "LoweredGetCallerSP",
-               argLen:            0,
+               argLen:            1,
                rematerializeable: true,
                reg: regInfo{
                        outputs: []outputInfo{
@@ -25987,7 +25987,7 @@ var opcodeTable = [...]opInfo{
        },
        {
                name:              "LoweredGetCallerSP",
-               argLen:            0,
+               argLen:            1,
                rematerializeable: true,
                reg: regInfo{
                        outputs: []outputInfo{
@@ -27662,7 +27662,7 @@ var opcodeTable = [...]opInfo{
        },
        {
                name:              "LoweredGetCallerSP",
-               argLen:            0,
+               argLen:            1,
                rematerializeable: true,
                reg: regInfo{
                        outputs: []outputInfo{
@@ -30189,7 +30189,7 @@ var opcodeTable = [...]opInfo{
        },
        {
                name:              "LoweredGetCallerSP",
-               argLen:            0,
+               argLen:            1,
                rematerializeable: true,
                reg: regInfo{
                        outputs: []outputInfo{
@@ -31996,7 +31996,7 @@ var opcodeTable = [...]opInfo{
        },
        {
                name:              "LoweredGetCallerSP",
-               argLen:            0,
+               argLen:            1,
                rematerializeable: true,
                reg: regInfo{
                        outputs: []outputInfo{
@@ -35511,7 +35511,7 @@ var opcodeTable = [...]opInfo{
        },
        {
                name:              "LoweredGetCallerSP",
-               argLen:            0,
+               argLen:            1,
                rematerializeable: true,
                reg: regInfo{
                        outputs: []outputInfo{
@@ -36220,7 +36220,7 @@ var opcodeTable = [...]opInfo{
        },
        {
                name:              "LoweredGetCallerSP",
-               argLen:            0,
+               argLen:            1,
                rematerializeable: true,
                reg: regInfo{
                        outputs: []outputInfo{
@@ -39148,7 +39148,7 @@ var opcodeTable = [...]opInfo{
        },
        {
                name:    "GetCallerSP",
-               argLen:  0,
+               argLen:  1,
                generic: true,
        },
        {
index 52f94030df7e20abe3021b8ccc5e9c97115217ea..9bad115defec9bc5b238755af214a3ad98efd5b4 100644 (file)
@@ -3304,7 +3304,7 @@ func (s *state) exprCheckPtr(n ir.Node, checkPtrOK bool) *ssa.Value {
 
        case ir.OGETCALLERSP:
                n := n.(*ir.CallExpr)
-               return s.newValue0(ssa.OpGetCallerSP, n.Type())
+               return s.newValue1(ssa.OpGetCallerSP, n.Type(), s.mem())
 
        case ir.OAPPEND:
                return s.append(n.(*ir.CallExpr), false)
@@ -3989,7 +3989,7 @@ func InitTables() {
 
        add("runtime", "getcallersp",
                func(s *state, n *ir.CallExpr, args []*ssa.Value) *ssa.Value {
-                       return s.newValue0(ssa.OpGetCallerSP, s.f.Config.Types.Uintptr)
+                       return s.newValue1(ssa.OpGetCallerSP, s.f.Config.Types.Uintptr, s.mem())
                },
                all...)