diff options
author | Cherry Zhang <cherryyz@google.com> | 2020-03-31 22:31:25 -0400 |
---|---|---|
committer | Cherry Zhang <cherryyz@google.com> | 2020-04-01 18:28:03 +0000 |
commit | a4129a1d205f9078e70822ff00c4d267cfa948e5 (patch) | |
tree | ddf44f4a9e677dcad6ea80f1a6d61819c98185dc | |
parent | 6dab0942a43039b8dea365ba8629cdc519cfb143 (diff) | |
download | go-git-a4129a1d205f9078e70822ff00c4d267cfa948e5.tar.gz |
[dev.link] cmd/internal/goobj: use new style accessors
We already move to new style accessors in the linker. This will
allow us to get rid of the read side of old style ones.
Change-Id: Id0c171c5634a5977fe8a6f764cb0d48203993ab7
Reviewed-on: https://go-review.googlesource.com/c/go/+/226799
Reviewed-by: Jeremy Faller <jeremy@golang.org>
Reviewed-by: Than McIntosh <thanm@google.com>
-rw-r--r-- | src/cmd/internal/goobj/readnew.go | 54 |
1 files changed, 25 insertions, 29 deletions
diff --git a/src/cmd/internal/goobj/readnew.go b/src/cmd/internal/goobj/readnew.go index e09260fb18..3a5a016514 100644 --- a/src/cmd/internal/goobj/readnew.go +++ b/src/cmd/internal/goobj/readnew.go @@ -57,9 +57,8 @@ func (r *objReader) readNew() { pkg := pkglist[p] return SymID{fmt.Sprintf("%s.<#%d>", pkg, s.SymIdx), 0} } - sym := goobj2.Sym{} - sym.Read(rr, rr.SymOff(i)) - return SymID{sym.Name, abiToVer(sym.ABI)} + sym := rr.Sym2(i) + return SymID{sym.Name(rr), abiToVer(sym.ABI())} } // Read things for the current goobj API for now. @@ -69,16 +68,15 @@ func (r *objReader) readNew() { n := rr.NSym() + rr.NNonpkgdef() + rr.NNonpkgref() ndef := rr.NSym() + rr.NNonpkgdef() for i := 0; i < n; i++ { - osym := goobj2.Sym{} - osym.Read(rr, rr.SymOff(i)) - if osym.Name == "" { + osym := rr.Sym2(i) + if osym.Name(rr) == "" { continue // not a real symbol } // In a symbol name in an object file, "". denotes the // prefix for the package in which the object file has been found. // Expand it. - name := strings.ReplaceAll(osym.Name, `"".`, r.pkgprefix) - symID := SymID{Name: name, Version: abiToVer(osym.ABI)} + name := strings.ReplaceAll(osym.Name(rr), `"".`, r.pkgprefix) + symID := SymID{Name: name, Version: abiToVer(osym.ABI())} r.p.SymRefs = append(r.p.SymRefs, symID) if i >= ndef { @@ -91,45 +89,43 @@ func (r *objReader) readNew() { sym := Sym{ SymID: symID, - Kind: objabi.SymKind(osym.Type), + Kind: objabi.SymKind(osym.Type()), DupOK: osym.Dupok(), - Size: int64(osym.Siz), + Size: int64(osym.Siz()), Data: Data{int64(start + dataOff), siz}, } r.p.Syms = append(r.p.Syms, &sym) // Reloc - nreloc := rr.NReloc(i) - sym.Reloc = make([]Reloc, nreloc) - for j := 0; j < nreloc; j++ { - rel := goobj2.Reloc{} - rel.Read(rr, rr.RelocOff(i, j)) + relocs := rr.Relocs2(i) + sym.Reloc = make([]Reloc, len(relocs)) + for j := range relocs { + rel := &relocs[j] sym.Reloc[j] = Reloc{ - Offset: int64(rel.Off), - Size: int64(rel.Siz), - Type: objabi.RelocType(rel.Type), - Add: rel.Add, - Sym: resolveSymRef(rel.Sym), + Offset: int64(rel.Off()), + Size: int64(rel.Siz()), + Type: objabi.RelocType(rel.Type()), + Add: rel.Add(), + Sym: resolveSymRef(rel.Sym()), } } // Aux symbol info isym := -1 funcdata := make([]goobj2.SymRef, 0, 4) - naux := rr.NAux(i) - for j := 0; j < naux; j++ { - a := goobj2.Aux{} - a.Read(rr, rr.AuxOff(i, j)) - switch a.Type { + auxs := rr.Auxs2(i) + for j := range auxs { + a := &auxs[j] + switch a.Type() { case goobj2.AuxGotype: - sym.Type = resolveSymRef(a.Sym) + sym.Type = resolveSymRef(a.Sym()) case goobj2.AuxFuncInfo: - if a.Sym.PkgIdx != goobj2.PkgIdxSelf { + if a.Sym().PkgIdx != goobj2.PkgIdxSelf { panic("funcinfo symbol not defined in current package") } - isym = int(a.Sym.SymIdx) + isym = int(a.Sym().SymIdx) case goobj2.AuxFuncdata: - funcdata = append(funcdata, a.Sym) + funcdata = append(funcdata, a.Sym()) case goobj2.AuxDwarfInfo, goobj2.AuxDwarfLoc, goobj2.AuxDwarfRanges, goobj2.AuxDwarfLines: // nothing to do default: |