diff options
| author | Russ Cox <rsc@golang.org> | 2024-11-05 13:33:17 -0500 |
|---|---|---|
| committer | Russ Cox <rsc@golang.org> | 2024-11-07 12:17:10 +0000 |
| commit | 5b20eec8a0eb3bd4681e315c0c4023c5164ea7b9 (patch) | |
| tree | 184613d170d137337c65c238153caafe4ececa21 /src/cmd/internal/obj/arm | |
| parent | 4ce8c0604ee1c36c221b1a3d767dfa131d5cce8c (diff) | |
| download | go-5b20eec8a0eb3bd4681e315c0c4023c5164ea7b9.tar.xz | |
cmd/internal/obj: replace obj.Addrel func with LSym.AddRel method
The old API was to do
r := obj.AddRel(sym)
r.Type = this
r.Off = that
etc
The new API is:
sym.AddRel(ctxt, obj.Reloc{Type: this: Off: that, etc})
This new API is more idiomatic and avoids ever having relocations
that are only partially constructed. Most importantly, it sets up
for sym.AddRel being able to check relocation validity in the future.
(Passing ctxt is for use in validity checking.)
Passes golang.org/x/tools/cmd/toolstash/buildall.
Change-Id: I042ea76e61bb3bf6402f98ca11291a13f4799972
Reviewed-on: https://go-review.googlesource.com/c/go/+/625616
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Reviewed-by: Cherry Mui <cherryyz@google.com>
Diffstat (limited to 'src/cmd/internal/obj/arm')
| -rw-r--r-- | src/cmd/internal/obj/arm/asm5.go | 70 |
1 files changed, 36 insertions, 34 deletions
diff --git a/src/cmd/internal/obj/arm/asm5.go b/src/cmd/internal/obj/arm/asm5.go index bf9623c206..0ef13b81f6 100644 --- a/src/cmd/internal/obj/arm/asm5.go +++ b/src/cmd/internal/obj/arm/asm5.go @@ -1589,13 +1589,14 @@ func (c *ctxt5) asmout(p *obj.Prog, o *Optab, out []uint32) { v := int32(-8) if p.To.Sym != nil { - rel := obj.Addrel(c.cursym) - rel.Off = int32(c.pc) - rel.Siz = 4 - rel.Sym = p.To.Sym v += int32(p.To.Offset) - rel.Add = int64(o1) | (int64(v)>>2)&0xffffff - rel.Type = objabi.R_CALLARM + c.cursym.AddRel(c.ctxt, obj.Reloc{ + Type: objabi.R_CALLARM, + Off: int32(c.pc), + Siz: 4, + Sym: p.To.Sym, + Add: int64(o1) | (int64(v)>>2)&0xffffff, + }) break } @@ -1620,10 +1621,10 @@ func (c *ctxt5) asmout(p *obj.Prog, o *Optab, out []uint32) { } o1 = c.oprrr(p, ABL, int(p.Scond)) o1 |= (uint32(p.To.Reg) & 15) << 0 - rel := obj.Addrel(c.cursym) - rel.Off = int32(c.pc) - rel.Siz = 0 - rel.Type = objabi.R_CALLIND + c.cursym.AddRel(c.ctxt, obj.Reloc{ + Type: objabi.R_CALLIND, + Off: int32(c.pc), + }) case 8: /* sll $c,[R],R -> mov (R<<$c),R */ c.aclass(&p.From) @@ -1663,23 +1664,23 @@ func (c *ctxt5) asmout(p *obj.Prog, o *Optab, out []uint32) { if p.To.Sym != nil { // This case happens with words generated // in the PC stream as part of the literal pool (c.pool). - rel := obj.Addrel(c.cursym) - - rel.Off = int32(c.pc) - rel.Siz = 4 - rel.Sym = p.To.Sym - rel.Add = p.To.Offset - + typ := objabi.R_ADDR + add := p.To.Offset if c.ctxt.Flag_shared { if p.To.Name == obj.NAME_GOTREF { - rel.Type = objabi.R_GOTPCREL + typ = objabi.R_GOTPCREL } else { - rel.Type = objabi.R_PCREL + typ = objabi.R_PCREL } - rel.Add += c.pc - p.Rel.Pc - 8 - } else { - rel.Type = objabi.R_ADDR + add += c.pc - p.Rel.Pc - 8 } + c.cursym.AddRel(c.ctxt, obj.Reloc{ + Type: typ, + Off: int32(c.pc), + Siz: 4, + Sym: p.To.Sym, + Add: add, + }) o1 = 0 } @@ -2159,12 +2160,12 @@ func (c *ctxt5) asmout(p *obj.Prog, o *Optab, out []uint32) { } // This case happens with words generated in the PC stream as part of // the literal c.pool. - rel := obj.Addrel(c.cursym) - - rel.Off = int32(c.pc) - rel.Siz = 4 - rel.Sym = p.To.Sym - rel.Type = objabi.R_TLS_LE + c.cursym.AddRel(c.ctxt, obj.Reloc{ + Type: objabi.R_TLS_LE, + Off: int32(c.pc), + Siz: 4, + Sym: p.To.Sym, + }) o1 = 0 case 104: /* word tlsvar, initial exec */ @@ -2174,12 +2175,13 @@ func (c *ctxt5) asmout(p *obj.Prog, o *Optab, out []uint32) { if p.To.Offset != 0 { c.ctxt.Diag("offset against tls var in %v", p) } - rel := obj.Addrel(c.cursym) - rel.Off = int32(c.pc) - rel.Siz = 4 - rel.Sym = p.To.Sym - rel.Type = objabi.R_TLS_IE - rel.Add = c.pc - p.Rel.Pc - 8 - int64(rel.Siz) + c.cursym.AddRel(c.ctxt, obj.Reloc{ + Type: objabi.R_TLS_IE, + Off: int32(c.pc), + Siz: 4, + Sym: p.To.Sym, + Add: c.pc - p.Rel.Pc - 8 - 4, + }) case 68: /* floating point store -> ADDR */ o1 = c.omvl(p, &p.To, REGTMP) |
