]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/internal/obj/arm64: save LR after decrementing SP on darwin
authorCherry Zhang <cherryyz@google.com>
Mon, 11 Nov 2019 04:48:56 +0000 (23:48 -0500)
committerCherry Zhang <cherryyz@google.com>
Tue, 12 Nov 2019 22:28:47 +0000 (22:28 +0000)
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 <cherryyz@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Keith Randall <khr@golang.org>
src/cmd/internal/obj/arm64/obj7.go

index e7cb16be7b76c11ca1f883eafc210172e9300b44..a2a019f5eb94b49037832f319090971058934980 100644 (file)
@@ -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