Skip to content

Commit

Permalink
cmd/internal/obj/ppc64: fix incorrect base reg causing segv
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
laboger authored and gopherbot committed Mar 24, 2023
1 parent 59d7c69 commit 2716dfd
Showing 1 changed file with 11 additions and 4 deletions.
15 changes: 11 additions & 4 deletions src/cmd/internal/obj/ppc64/asm9.go
Expand Up @@ -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
Expand Down Expand Up @@ -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)
}

Expand Down

0 comments on commit 2716dfd

Please sign in to comment.