From 2b3c1c5937f41cda7650c78fcf1f8e7d28d8c9c2 Mon Sep 17 00:00:00 2001 From: zhouguangyuan Date: Thu, 7 Sep 2023 00:09:31 +0800 Subject: [PATCH] cmd/internal/obj: mark unspill code in prologue preemptible The UnspillReg code should always be preemptible because all the arg registers will be saved by runtime.asyncpreempt. Change-Id: Ie36b5d0cdd1275efcb95661354d83be2e1b00a86 Reviewed-on: https://go-review.googlesource.com/c/go/+/526235 TryBot-Result: Gopher Robot Reviewed-by: Matthew Dempsky Run-TryBot: Cherry Mui Reviewed-by: Cherry Mui --- src/cmd/internal/obj/arm64/obj7.go | 7 ++++--- src/cmd/internal/obj/ppc64/obj9.go | 5 +++-- src/cmd/internal/obj/riscv/obj.go | 3 ++- src/cmd/internal/obj/x86/obj6.go | 7 ++++--- 4 files changed, 13 insertions(+), 9 deletions(-) diff --git a/src/cmd/internal/obj/arm64/obj7.go b/src/cmd/internal/obj/arm64/obj7.go index 9774e0120bd..0e16e287a78 100644 --- a/src/cmd/internal/obj/arm64/obj7.go +++ b/src/cmd/internal/obj/arm64/obj7.go @@ -289,11 +289,12 @@ func (c *ctxt7) stacksplit(p *obj.Prog, framesize int32) *obj.Prog { } call.To.Sym = c.ctxt.Lookup(morestack) - unspill := c.cursym.Func().UnspillRegisterArgs(call, c.newprog) - pcdata = c.ctxt.EndUnsafePoint(unspill, c.newprog, -1) + // The instructions which unspill regs should be preemptible. + pcdata = c.ctxt.EndUnsafePoint(call, c.newprog, -1) + unspill := c.cursym.Func().UnspillRegisterArgs(pcdata, c.newprog) // B start - jmp := obj.Appendp(pcdata, c.newprog) + jmp := obj.Appendp(unspill, c.newprog) jmp.As = AB jmp.To.Type = obj.TYPE_BRANCH jmp.To.SetTarget(startPred.Link) diff --git a/src/cmd/internal/obj/ppc64/obj9.go b/src/cmd/internal/obj/ppc64/obj9.go index 02831b890a3..da95e65079c 100644 --- a/src/cmd/internal/obj/ppc64/obj9.go +++ b/src/cmd/internal/obj/ppc64/obj9.go @@ -1363,11 +1363,12 @@ func (c *ctxt9) stacksplit(p *obj.Prog, framesize int32) *obj.Prog { p.To.Reg = REG_R2 } + // The instructions which unspill regs should be preemptible. + p = c.ctxt.EndUnsafePoint(p, c.newprog, -1) unspill := c.cursym.Func().UnspillRegisterArgs(p, c.newprog) - p = c.ctxt.EndUnsafePoint(unspill, c.newprog, -1) // BR start - p = obj.Appendp(p, c.newprog) + p = obj.Appendp(unspill, c.newprog) p.As = ABR p.To.Type = obj.TYPE_BRANCH p.To.SetTarget(startPred.Link) diff --git a/src/cmd/internal/obj/riscv/obj.go b/src/cmd/internal/obj/riscv/obj.go index 7b5621f6508..675031de73f 100644 --- a/src/cmd/internal/obj/riscv/obj.go +++ b/src/cmd/internal/obj/riscv/obj.go @@ -913,8 +913,9 @@ func stacksplit(ctxt *obj.Link, p *obj.Prog, cursym *obj.LSym, newprog obj.ProgA } jalToSym(ctxt, p, REG_X5) - p = cursym.Func().UnspillRegisterArgs(p, newprog) + // The instructions which unspill regs should be preemptible. p = ctxt.EndUnsafePoint(p, newprog, -1) + p = cursym.Func().UnspillRegisterArgs(p, newprog) // JMP start p = obj.Appendp(p, newprog) diff --git a/src/cmd/internal/obj/x86/obj6.go b/src/cmd/internal/obj/x86/obj6.go index fc4007ec88b..e6ea8985e4f 100644 --- a/src/cmd/internal/obj/x86/obj6.go +++ b/src/cmd/internal/obj/x86/obj6.go @@ -1226,10 +1226,11 @@ func stacksplit(ctxt *obj.Link, cursym *obj.LSym, p *obj.Prog, newprog obj.ProgA progedit(ctxt, callend.Link, newprog) } - pcdata = cursym.Func().UnspillRegisterArgs(callend, newprog) - pcdata = ctxt.EndUnsafePoint(pcdata, newprog, -1) + // The instructions which unspill regs should be preemptible. + pcdata = ctxt.EndUnsafePoint(callend, newprog, -1) + unspill := cursym.Func().UnspillRegisterArgs(pcdata, newprog) - jmp := obj.Appendp(pcdata, newprog) + jmp := obj.Appendp(unspill, newprog) jmp.As = obj.AJMP jmp.To.Type = obj.TYPE_BRANCH jmp.To.SetTarget(startPred.Link)