Skip to content

Commit 2fdad8a

Browse files
randall77mknyszek
authored andcommitted
[release-branch.go1.21] cmd/internal/obj/arm64: fix frame pointer restore in epilogue
For leaf but nonzero-frame functions. Currently we're not restoring it properly. We also need to restore it before popping the stack frame, so that the frame won't get clobbered by a signal handler in the meantime. For #63830 Fixes #65449 Needs a test, but I'm not at all sure how we would actually do that. Leaving for inspiration. Change-Id: I273a25f2a838f05a959c810145cccc5428eaf164 Reviewed-on: https://go-review.googlesource.com/c/go/+/538635 Reviewed-by: Cherry Mui <[email protected]> Reviewed-by: Eric Fang <[email protected]> LUCI-TryBot-Result: Go LUCI <[email protected]> Reviewed-by: David Chase <[email protected]> (cherry picked from commit c9888bd) Reviewed-on: https://go-review.googlesource.com/c/go/+/560735 TryBot-Bypass: Michael Knyszek <[email protected]> Reviewed-by: Keith Randall <[email protected]>
1 parent 01c93ad commit 2fdad8a

File tree

1 file changed

+11
-8
lines changed

1 file changed

+11
-8
lines changed

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

+11-8
Original file line numberDiff line numberDiff line change
@@ -826,21 +826,24 @@ func preprocess(ctxt *obj.Link, cursym *obj.LSym, newprog obj.ProgAlloc) {
826826
p.To = obj.Addr{}
827827
if c.cursym.Func().Text.Mark&LEAF != 0 {
828828
if c.autosize != 0 {
829+
// Restore frame pointer.
830+
// ADD $framesize-8, RSP, R29
829831
p.As = AADD
830832
p.From.Type = obj.TYPE_CONST
831-
p.From.Offset = int64(c.autosize)
833+
p.From.Offset = int64(c.autosize) - 8
834+
p.Reg = REGSP
832835
p.To.Type = obj.TYPE_REG
833-
p.To.Reg = REGSP
834-
p.Spadj = -c.autosize
836+
p.To.Reg = REGFP
835837

836-
// Frame pointer.
838+
// Pop stack frame.
839+
// ADD $framesize, RSP, RSP
837840
p = obj.Appendp(p, c.newprog)
838-
p.As = ASUB
841+
p.As = AADD
839842
p.From.Type = obj.TYPE_CONST
840-
p.From.Offset = 8
841-
p.Reg = REGSP
843+
p.From.Offset = int64(c.autosize)
842844
p.To.Type = obj.TYPE_REG
843-
p.To.Reg = REGFP
845+
p.To.Reg = REGSP
846+
p.Spadj = -c.autosize
844847
}
845848
} else {
846849
aoffset := c.autosize

0 commit comments

Comments
 (0)