From 13fb147e60ba17457366630c60b5dbbe2d6a4304 Mon Sep 17 00:00:00 2001 From: Cherry Zhang Date: Sun, 10 Nov 2019 23:48:56 -0500 Subject: [PATCH] cmd/internal/obj/arm64: save LR after decrementing SP on darwin iOS does not support SA_ONSTACK. The signal handler runs on the G stack. Any writes below the SP may be clobbered by the signal handler (even without call injection). So we save LR after decrementing SP on iOS. Updates #35439. Change-Id: Ia6d7a0669e0bcf417b44c031d2e26675c1184165 Reviewed-on: https://go-review.googlesource.com/c/go/+/206418 Run-TryBot: Cherry Zhang TryBot-Result: Gobot Gobot Reviewed-by: Keith Randall --- src/cmd/internal/obj/arm64/obj7.go | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/src/cmd/internal/obj/arm64/obj7.go b/src/cmd/internal/obj/arm64/obj7.go index e7cb16be7b..a2a019f5eb 100644 --- a/src/cmd/internal/obj/arm64/obj7.go +++ b/src/cmd/internal/obj/arm64/obj7.go @@ -629,6 +629,19 @@ func preprocess(ctxt *obj.Link, cursym *obj.LSym, newprog obj.ProgAlloc) { q1.To.Reg = REGSP q1.Spadj = c.autosize + if c.ctxt.Headtype == objabi.Hdarwin { + // iOS does not support SA_ONSTACK. We will run the signal handler + // on the G stack. If we write below SP, it may be clobbered by + // the signal handler. So we save LR after decrementing SP. + q1 = obj.Appendp(q1, c.newprog) + q1.Pos = p.Pos + q1.As = AMOVD + q1.From.Type = obj.TYPE_REG + q1.From.Reg = REGLINK + q1.To.Type = obj.TYPE_MEM + q1.To.Reg = REGSP + } + q1 = c.ctxt.EndUnsafePoint(q1, c.newprog, -1) } else { // small frame, update SP and save LR in a single MOVD.W instruction -- 2.50.0