From: Cherry Mui Date: Mon, 20 Dec 2021 17:45:04 +0000 (-0500) Subject: cmd/internal/obj/riscv: mark stack bounds check prologue nonpreemptible X-Git-Tag: go1.18beta2~203 X-Git-Url: http://www.git.cypherpunks.su/?a=commitdiff_plain;h=59d04d104d9e08322712e837b35f4cd54c9bae1a;p=gostls13.git cmd/internal/obj/riscv: mark stack bounds check prologue nonpreemptible This is similar to CL 207350, for RISCV64. May fix #50263. Updates #35470. Change-Id: I0d39e195e8254d65fa1aca1cdf1fc553aa8b7cba Reviewed-on: https://go-review.googlesource.com/c/go/+/373434 Trust: Cherry Mui Run-TryBot: Cherry Mui Reviewed-by: David Chase TryBot-Result: Gopher Robot --- diff --git a/src/cmd/internal/obj/riscv/obj.go b/src/cmd/internal/obj/riscv/obj.go index 5755b118db..9f16de0c8c 100644 --- a/src/cmd/internal/obj/riscv/obj.go +++ b/src/cmd/internal/obj/riscv/obj.go @@ -790,6 +790,12 @@ func stacksplit(ctxt *obj.Link, p *obj.Prog, cursym *obj.LSym, newprog obj.ProgA p.To.Type = obj.TYPE_REG p.To.Reg = REG_X10 + // Mark the stack bound check and morestack call async nonpreemptible. + // If we get preempted here, when resumed the preemption request is + // cleared, but we'll still call morestack, which will double the stack + // unnecessarily. See issue #35470. + p = ctxt.StartUnsafePoint(p, newprog) + var to_done, to_more *obj.Prog if framesize <= objabi.StackSmall { @@ -854,7 +860,7 @@ func stacksplit(ctxt *obj.Link, p *obj.Prog, cursym *obj.LSym, newprog obj.ProgA to_done = p } - p = ctxt.EmitEntryLiveness(cursym, p, newprog) + p = ctxt.EmitEntryStackMap(cursym, p, newprog) // CALL runtime.morestack(SB) p = obj.Appendp(p, newprog) @@ -872,6 +878,8 @@ func stacksplit(ctxt *obj.Link, p *obj.Prog, cursym *obj.LSym, newprog obj.ProgA } jalToSym(ctxt, p, REG_X5) + p = ctxt.EndUnsafePoint(p, newprog, -1) + // JMP start p = obj.Appendp(p, newprog) p.As = AJAL