]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/internal/obj/mips: store LR before update SP in function prologue
authorCherry Zhang <cherryyz@google.com>
Fri, 21 Oct 2016 22:22:13 +0000 (18:22 -0400)
committerCherry Zhang <cherryyz@google.com>
Mon, 24 Oct 2016 22:39:15 +0000 (22:39 +0000)
This prevents the traceback code from seeing a half-updated
stack frame when a profiling signal comes during the execution
of function prologue. Also fixes mips64x part of #17381.

Change-Id: Iec9683427e546e3648b2e8b1dde956d13f6eb938
Reviewed-on: https://go-review.googlesource.com/31721
Run-TryBot: Cherry Zhang <cherryyz@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Austin Clements <austin@google.com>
src/cmd/internal/obj/mips/obj0.go

index 5a6474c92fc79bbb47b939434d0c4cdc66f6a6aa..af515a67c6347ee3b445ada336d4b5859ad80315 100644 (file)
@@ -281,7 +281,21 @@ func preprocess(ctxt *obj.Link, cursym *obj.LSym) {
                        q = p
 
                        if autosize != 0 {
-                               q = obj.Appendp(ctxt, p)
+                               // Make sure to save link register for non-empty frame, even if
+                               // it is a leaf function, so that traceback works.
+                               // Store link register before decrement SP, so if a signal comes
+                               // during the execution of the function prologue, the traceback
+                               // code will not see a half-updated stack frame.
+                               q = obj.Appendp(ctxt, q)
+                               q.As = AMOVV
+                               q.Lineno = p.Lineno
+                               q.From.Type = obj.TYPE_REG
+                               q.From.Reg = REGLINK
+                               q.To.Type = obj.TYPE_MEM
+                               q.To.Offset = int64(-autosize)
+                               q.To.Reg = REGSP
+
+                               q = obj.Appendp(ctxt, q)
                                q.As = AADDV
                                q.Lineno = p.Lineno
                                q.From.Type = obj.TYPE_CONST
@@ -304,15 +318,6 @@ func preprocess(ctxt *obj.Link, cursym *obj.LSym) {
                                break
                        }
 
-                       q = obj.Appendp(ctxt, q)
-                       q.As = AMOVV
-                       q.Lineno = p.Lineno
-                       q.From.Type = obj.TYPE_REG
-                       q.From.Reg = REGLINK
-                       q.To.Type = obj.TYPE_MEM
-                       q.To.Offset = int64(0)
-                       q.To.Reg = REGSP
-
                        if cursym.Text.From3.Offset&obj.WRAPPER != 0 {
                                // if(g->panic != nil && g->panic->argp == FP) g->panic->argp = bottom-of-frame
                                //