Commit 47232f0d authored by Cherry Zhang's avatar Cherry Zhang

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 <cherryyz@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: default avatarIan Lance Taylor <iant@golang.org>
parent 374c2847
...@@ -812,22 +812,27 @@ func preprocess(ctxt *obj.Link, cursym *obj.LSym, newprog obj.ProgAlloc) { ...@@ -812,22 +812,27 @@ func preprocess(ctxt *obj.Link, cursym *obj.LSym, newprog obj.ProgAlloc) {
aoffset := c.autosize aoffset := c.autosize
if aoffset > 0xF0 { if aoffset <= 0xF0 {
aoffset = 0xF0 p.As = AMOVD
} p.From.Type = obj.TYPE_MEM
p.As = AMOVD p.Scond = C_XPOST
p.From.Type = obj.TYPE_MEM p.From.Offset = int64(aoffset)
p.Scond = C_XPOST p.From.Reg = REGSP
p.From.Offset = int64(aoffset) p.To.Type = obj.TYPE_REG
p.From.Reg = REGSP p.To.Reg = REGLINK
p.To.Type = obj.TYPE_REG p.Spadj = -aoffset
p.To.Reg = REGLINK } else {
p.Spadj = -aoffset p.As = AMOVD
if c.autosize > aoffset { 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 = newprog()
q.As = AADD q.As = AADD
q.From.Type = obj.TYPE_CONST 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.Type = obj.TYPE_REG
q.To.Reg = REGSP q.To.Reg = REGSP
q.Link = p.Link q.Link = p.Link
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment