From 47232f0d929bd7ca44aeea23ad3f1806dfa55c5e Mon Sep 17 00:00:00 2001 From: Cherry Zhang Date: Thu, 7 Nov 2019 22:40:50 -0500 Subject: [PATCH] cmd/internal/obj/arm64: make function epilogue async-signal safe When the frame size is large, we generate MOVD.P 0xf0(SP), LR ADD $(framesize-0xf0), SP This is problematic: after the first instruction, we have a partial frame of size (framesize-0xf0). If we try to unwind the stack at this point, we'll try to read the LR from the stack at 0(SP) (the new SP) as the frame size is not 0. But this slot does not contain a valid LR. Fix this by not changing SP in two instructions. Instead, generate MOVD (SP), LR ADD $framesize, SP This affects not only async preemption but also profiling. So we change the generated instructions, instead of marking unsafe point. Change-Id: I4e78c62d50ffc4acff70ccfbfec16a5ccae17f24 Reviewed-on: https://go-review.googlesource.com/c/go/+/206057 Run-TryBot: Cherry Zhang TryBot-Result: Gobot Gobot Reviewed-by: Ian Lance Taylor --- src/cmd/internal/obj/arm64/obj7.go | 31 +++++++++++++++++------------- 1 file changed, 18 insertions(+), 13 deletions(-) diff --git a/src/cmd/internal/obj/arm64/obj7.go b/src/cmd/internal/obj/arm64/obj7.go index 464cbb4b50..e7cb16be7b 100644 --- a/src/cmd/internal/obj/arm64/obj7.go +++ b/src/cmd/internal/obj/arm64/obj7.go @@ -812,22 +812,27 @@ func preprocess(ctxt *obj.Link, cursym *obj.LSym, newprog obj.ProgAlloc) { aoffset := c.autosize - if aoffset > 0xF0 { - aoffset = 0xF0 - } - p.As = AMOVD - p.From.Type = obj.TYPE_MEM - p.Scond = C_XPOST - p.From.Offset = int64(aoffset) - p.From.Reg = REGSP - p.To.Type = obj.TYPE_REG - p.To.Reg = REGLINK - p.Spadj = -aoffset - if c.autosize > aoffset { + if aoffset <= 0xF0 { + p.As = AMOVD + p.From.Type = obj.TYPE_MEM + p.Scond = C_XPOST + p.From.Offset = int64(aoffset) + p.From.Reg = REGSP + p.To.Type = obj.TYPE_REG + p.To.Reg = REGLINK + p.Spadj = -aoffset + } else { + p.As = AMOVD + p.From.Type = obj.TYPE_MEM + p.From.Offset = 0 + p.From.Reg = REGSP + p.To.Type = obj.TYPE_REG + p.To.Reg = REGLINK + q = newprog() q.As = AADD q.From.Type = obj.TYPE_CONST - q.From.Offset = int64(c.autosize) - int64(aoffset) + q.From.Offset = int64(aoffset) q.To.Type = obj.TYPE_REG q.To.Reg = REGSP q.Link = p.Link -- 2.50.0