Skip to content

Commit c9888bd

Browse files
committed
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. Fixes #63830 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]>
1 parent ac85f2b commit c9888bd

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
@@ -850,21 +850,24 @@ func preprocess(ctxt *obj.Link, cursym *obj.LSym, newprog obj.ProgAlloc) {
850850
p.To = obj.Addr{}
851851
if c.cursym.Func().Text.Mark&LEAF != 0 {
852852
if c.autosize != 0 {
853+
// Restore frame pointer.
854+
// ADD $framesize-8, RSP, R29
853855
p.As = AADD
854856
p.From.Type = obj.TYPE_CONST
855-
p.From.Offset = int64(c.autosize)
857+
p.From.Offset = int64(c.autosize) - 8
858+
p.Reg = REGSP
856859
p.To.Type = obj.TYPE_REG
857-
p.To.Reg = REGSP
858-
p.Spadj = -c.autosize
860+
p.To.Reg = REGFP
859861

860-
// Frame pointer.
862+
// Pop stack frame.
863+
// ADD $framesize, RSP, RSP
861864
p = obj.Appendp(p, c.newprog)
862-
p.As = ASUB
865+
p.As = AADD
863866
p.From.Type = obj.TYPE_CONST
864-
p.From.Offset = 8
865-
p.Reg = REGSP
867+
p.From.Offset = int64(c.autosize)
866868
p.To.Type = obj.TYPE_REG
867-
p.To.Reg = REGFP
869+
p.To.Reg = REGSP
870+
p.Spadj = -c.autosize
868871
}
869872
} else {
870873
aoffset := c.autosize

0 commit comments

Comments
 (0)