From 69f3bc04e5c005df170071278e71121c0cd16611 Mon Sep 17 00:00:00 2001 From: Cherry Zhang Date: Thu, 9 Apr 2020 19:56:05 -0400 Subject: [PATCH] [dev.link] cmd/link: use new-style Reloc accessors in loadxcoff Change-Id: I606b60807b4a8b6e5c0f489db3c5d9e75bd1e728 Reviewed-on: https://go-review.googlesource.com/c/go/+/227898 Run-TryBot: Cherry Zhang TryBot-Result: Gobot Gobot Reviewed-by: Than McIntosh --- src/cmd/link/internal/loadxcoff/ldxcoff.go | 33 ++++++++++++---------- 1 file changed, 18 insertions(+), 15 deletions(-) diff --git a/src/cmd/link/internal/loadxcoff/ldxcoff.go b/src/cmd/link/internal/loadxcoff/ldxcoff.go index 906e871b09..a5744216d6 100644 --- a/src/cmd/link/internal/loadxcoff/ldxcoff.go +++ b/src/cmd/link/internal/loadxcoff/ldxcoff.go @@ -119,15 +119,16 @@ func Load(l *loader.Loader, arch *sys.Arch, localSymVersion int, input *bio.Read if sect.Type != xcoff.STYP_TEXT && sect.Type != xcoff.STYP_DATA { continue } - rs := make([]loader.Reloc, sect.Nreloc) - for i, rx := range sect.Relocs { - r := &rs[i] - - r.Sym = l.LookupOrCreateSym(rx.Symbol.Name, 0) + sb := l.MakeSymbolUpdater(sect.sym) + for _, rx := range sect.Relocs { + rSym := l.LookupOrCreateSym(rx.Symbol.Name, 0) if uint64(int32(rx.VirtualAddress)) != rx.VirtualAddress { return errorf("virtual address of a relocation is too big: 0x%x", rx.VirtualAddress) } - r.Off = int32(rx.VirtualAddress) + rOff := int32(rx.VirtualAddress) + var rSize uint8 + var rType objabi.RelocType + var rAdd int64 switch rx.Type { default: return errorf("section %s: unknown relocation of type 0x%x", sect.Name, rx.Type) @@ -137,19 +138,21 @@ func Load(l *loader.Loader, arch *sys.Arch, localSymVersion int, input *bio.Read if rx.Length != 64 { return errorf("section %s: relocation R_POS has length different from 64: %d", sect.Name, rx.Length) } - r.Size = 8 - r.Type = objabi.R_CONST - r.Add = int64(rx.Symbol.Value) + rSize = 8 + rType = objabi.R_CONST + rAdd = int64(rx.Symbol.Value) case xcoff.R_RBR: - r.Size = 4 - r.Type = objabi.R_CALLPOWER - r.Add = 0 // - + rSize = 4 + rType = objabi.R_CALLPOWER + rAdd = 0 } + r, _ := sb.AddRel(rType) + r.SetOff(rOff) + r.SetSiz(rSize) + r.SetSym(rSym) + r.SetAdd(rAdd) } - bld := l.MakeSymbolUpdater(sect.sym) - bld.SetRelocs(rs[:sect.Nreloc]) } return textp, nil