Skip to content

Commit 47232f0

Browse files
committed
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: Ian Lance Taylor <iant@golang.org>
1 parent 374c284 commit 47232f0

File tree

1 file changed

+18
-13
lines changed

1 file changed

+18
-13
lines changed

src/cmd/internal/obj/arm64/obj7.go

+18-13
Original file line numberDiff line numberDiff line change
@@ -812,22 +812,27 @@ func preprocess(ctxt *obj.Link, cursym *obj.LSym, newprog obj.ProgAlloc) {
812812

813813
aoffset := c.autosize
814814

815-
if aoffset > 0xF0 {
816-
aoffset = 0xF0
817-
}
818-
p.As = AMOVD
819-
p.From.Type = obj.TYPE_MEM
820-
p.Scond = C_XPOST
821-
p.From.Offset = int64(aoffset)
822-
p.From.Reg = REGSP
823-
p.To.Type = obj.TYPE_REG
824-
p.To.Reg = REGLINK
825-
p.Spadj = -aoffset
826-
if c.autosize > aoffset {
815+
if aoffset <= 0xF0 {
816+
p.As = AMOVD
817+
p.From.Type = obj.TYPE_MEM
818+
p.Scond = C_XPOST
819+
p.From.Offset = int64(aoffset)
820+
p.From.Reg = REGSP
821+
p.To.Type = obj.TYPE_REG
822+
p.To.Reg = REGLINK
823+
p.Spadj = -aoffset
824+
} else {
825+
p.As = AMOVD
826+
p.From.Type = obj.TYPE_MEM
827+
p.From.Offset = 0
828+
p.From.Reg = REGSP
829+
p.To.Type = obj.TYPE_REG
830+
p.To.Reg = REGLINK
831+
827832
q = newprog()
828833
q.As = AADD
829834
q.From.Type = obj.TYPE_CONST
830-
q.From.Offset = int64(c.autosize) - int64(aoffset)
835+
q.From.Offset = int64(aoffset)
831836
q.To.Type = obj.TYPE_REG
832837
q.To.Reg = REGSP
833838
q.Link = p.Link

0 commit comments

Comments
 (0)