]> Cypherpunks.ru repositories - gostls13.git/commitdiff
cmd/internal/obj/ppc64: fix incorrect base reg causing segv
authorLynn Boger <laboger@linux.vnet.ibm.com>
Thu, 23 Mar 2023 18:19:02 +0000 (13:19 -0500)
committerGopher Robot <gobot@golang.org>
Fri, 24 Mar 2023 18:14:29 +0000 (18:14 +0000)
This fixes a segv that was reported due to building minio. The
problem occurred because of an incorrect selection of the
base register, which was introduced by CL 306369.

Fixes #59196

Change-Id: Ieb77b2afa8fb4e6f3943df5ce138679f6750d376
Reviewed-on: https://go-review.googlesource.com/c/go/+/478920
Run-TryBot: Lynn Boger <laboger@linux.vnet.ibm.com>
Reviewed-by: Dmitri Shuralyov <dmitshur@google.com>
Reviewed-by: Archana Ravindar <aravind5@in.ibm.com>
Reviewed-by: Heschi Kreinick <heschi@google.com>
Auto-Submit: Lynn Boger <laboger@linux.vnet.ibm.com>
Reviewed-by: Paul Murphy <murp@ibm.com>
TryBot-Result: Gopher Robot <gobot@golang.org>

src/cmd/internal/obj/ppc64/asm9.go

index dbc1a5b81950fb618d3a40ca53665e8177fb870c..9516ea3cd6155c33cbe84ea731c19d1fc29dca26 100644 (file)
@@ -3288,8 +3288,15 @@ func asmout(c *ctxt9, p *obj.Prog, o *Optab, out *[5]uint32) {
                        o1 |= uint32((v >> 16) & 0x3FFFF)
                        o2 |= uint32(v & 0xFFFF)
                } else {
-                       o1 = AOP_IRR(OP_ADDIS, uint32(p.To.Reg), uint32(r), uint32(high16adjusted(v)))
-                       o2 = AOP_IRR(c.opload(p.As), uint32(p.To.Reg), uint32(p.To.Reg), uint32(v))
+                       if o.a6 == C_REG {
+                               // Reuse the base register when loading a GPR (C_REG) to avoid
+                               // using REGTMP (R31) when possible.
+                               o1 = AOP_IRR(OP_ADDIS, uint32(p.To.Reg), uint32(r), uint32(high16adjusted(v)))
+                               o2 = AOP_IRR(c.opload(p.As), uint32(p.To.Reg), uint32(p.To.Reg), uint32(v))
+                       } else {
+                               o1 = AOP_IRR(OP_ADDIS, uint32(REGTMP), uint32(r), uint32(high16adjusted(v)))
+                               o2 = AOP_IRR(c.opload(p.As), uint32(p.To.Reg), uint32(REGTMP), uint32(v))
+                       }
                }
 
                // Sign extend MOVB if needed
@@ -3681,8 +3688,8 @@ func asmout(c *ctxt9, p *obj.Prog, o *Optab, out *[5]uint32) {
                                rel.Type = objabi.R_ADDRPOWER_TOCREL_DS
                        }
                default:
-                       reuseBaseReg := p.As != AFMOVD && p.As != AFMOVS
-                       // Reuse To.Reg as base register if not FP move.
+                       reuseBaseReg := o.a6 == C_REG
+                       // Reuse To.Reg as base register if it is a GPR.
                        o1, o2, rel = c.symbolAccess(p.From.Sym, v, p.To.Reg, inst, reuseBaseReg)
                }