From b55cee1893283cc55e99fb041fc0067f56924926 Mon Sep 17 00:00:00 2001 From: Cherry Zhang Date: Fri, 21 Oct 2016 18:22:13 -0400 Subject: [PATCH] cmd/internal/obj/mips: store LR before update SP in function prologue 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 TryBot-Result: Gobot Gobot Reviewed-by: Austin Clements --- src/cmd/internal/obj/mips/obj0.go | 25 +++++++++++++++---------- 1 file changed, 15 insertions(+), 10 deletions(-) diff --git a/src/cmd/internal/obj/mips/obj0.go b/src/cmd/internal/obj/mips/obj0.go index 5a6474c92f..af515a67c6 100644 --- a/src/cmd/internal/obj/mips/obj0.go +++ b/src/cmd/internal/obj/mips/obj0.go @@ -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 // -- 2.48.1