]> Cypherpunks repositories - gostls13.git/commitdiff
[dev.link] cmd/internal/goobj: use new style accessors
authorCherry Zhang <cherryyz@google.com>
Wed, 1 Apr 2020 02:31:25 +0000 (22:31 -0400)
committerCherry Zhang <cherryyz@google.com>
Wed, 1 Apr 2020 18:28:03 +0000 (18:28 +0000)
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>
src/cmd/internal/goobj/readnew.go

index e09260fb18b9d814e1a13548bbb8310bc02c9e8f..3a5a0165147099e9eb354fb941a0aa6ca0e8046e 100644 (file)
@@ -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: