]> Cypherpunks repositories - gostls13.git/commitdiff
[dev.link] cmd/link: remove ctxt.Syms.Allsym
authorCherry Zhang <cherryyz@google.com>
Sat, 25 Apr 2020 02:45:05 +0000 (22:45 -0400)
committerCherry Zhang <cherryyz@google.com>
Mon, 27 Apr 2020 15:49:37 +0000 (15:49 +0000)
Replace remaining uses with loader.Syms. Reduces some memory
usage.

Change-Id: I6f295b42b8cd734c6c18f08c61a5473506675075
Reviewed-on: https://go-review.googlesource.com/c/go/+/229992
Reviewed-by: Jeremy Faller <jeremy@golang.org>
Reviewed-by: Than McIntosh <thanm@google.com>
src/cmd/link/internal/ld/data2.go
src/cmd/link/internal/ld/elf2.go
src/cmd/link/internal/ld/lib.go
src/cmd/link/internal/ld/main.go
src/cmd/link/internal/ld/xcoff.go
src/cmd/link/internal/loader/loader.go
src/cmd/link/internal/sym/symbols.go

index 5c88fbaa574c6b705733261c1a35088524241e4b..e11988fbbd616aec882e546d1a5d35e492c46bb8 100644 (file)
@@ -28,7 +28,10 @@ func (ctxt *Link) dodata() {
 
        // Collect data symbols by type into data.
        state := dodataState{ctxt: ctxt}
-       for _, s := range ctxt.Syms.Allsym {
+       for _, s := range ctxt.loader.Syms {
+               if s == nil {
+                       continue
+               }
                if !s.Attr.Reachable() || s.Attr.Special() || s.Attr.SubSymbol() {
                        continue
                }
index e77510f4a67d0d6b299b3b2ad3d3a1156a433e40..c6e11d87bf4a05ec61abc5ff3b592d95e88a18b9 100644 (file)
@@ -51,7 +51,10 @@ func elfdynhash(ctxt *Link) {
        chain := make([]uint32, nsym)
        buckets := make([]uint32, nbucket)
 
-       for _, sy := range ctxt.Syms.Allsym {
+       for _, sy := range ctxt.loader.Syms {
+               if sy == nil {
+                       continue
+               }
                if sy.Dynid <= 0 {
                        continue
                }
index 5d01babd5f0f5cc74edac5decae3be8f30261e06..a43aff22ee8c36c5475a72679347b4cb8d759b98 100644 (file)
@@ -2555,7 +2555,10 @@ func genasmsym(ctxt *Link, put func(*Link, *sym.Symbol, string, SymbolType, int6
                return true
        }
 
-       for _, s := range ctxt.Syms.Allsym {
+       for _, s := range ctxt.loader.Syms {
+               if s == nil {
+                       continue
+               }
                if !shouldBeInSymbolTable(s) {
                        continue
                }
@@ -2909,7 +2912,10 @@ func (ctxt *Link) loadlibfull(symGroupType []sym.SymKind) {
 }
 
 func (ctxt *Link) dumpsyms() {
-       for _, s := range ctxt.Syms.Allsym {
+       for _, s := range ctxt.loader.Syms {
+               if s == nil {
+                       continue
+               }
                fmt.Printf("%s %s reachable=%v onlist=%v outer=%v sub=%v\n", s, s.Type, s.Attr.Reachable(), s.Attr.OnList(), s.Outer, s.Sub)
                for i := range s.R {
                        fmt.Println("\t", s.R[i].Type, s.R[i].Sym)
index a5f2092f0f9b94681b1ceda6ea63f539c6d073d5..837cfe59ca4a5e31f5604c449e5a18471f8bdcb5 100644 (file)
@@ -364,7 +364,7 @@ func Main(arch *sys.Arch, theArch Arch) {
        bench.Start("hostlink")
        ctxt.hostlink()
        if ctxt.Debugvlog != 0 {
-               ctxt.Logf("%d symbols\n", len(ctxt.Syms.Allsym))
+               ctxt.Logf("%d symbols, %d reachable\n", len(ctxt.loader.Syms), ctxt.loader.NReachableSym())
                ctxt.Logf("%d liveness data\n", liveness)
        }
        bench.Start("Flush")
index e4f30ffb31c5eada73da93dee39400b0f28b512e..379ecec6e74b7f68f70ce80eaa68b1e3ea90915c 100644 (file)
@@ -1646,7 +1646,10 @@ func xcoffCreateExportFile(ctxt *Link) (fname string) {
        fname = filepath.Join(*flagTmpdir, "export_file.exp")
        var buf bytes.Buffer
 
-       for _, s := range ctxt.Syms.Allsym {
+       for _, s := range ctxt.loader.Syms {
+               if s == nil {
+                       continue
+               }
                if !s.Attr.CgoExport() {
                        continue
                }
index 30121d4cbaed9d7be2e3584f5d096c2c77347cf1..1eebb0f2d12daea556719d00e5949d56f57b047d 100644 (file)
@@ -147,6 +147,16 @@ func (bm Bitmap) Has(i Sym) bool {
 func (bm Bitmap) Len() int {
        return len(bm) * 32
 }
+
+// return the number of bits set.
+func (bm Bitmap) Count() int {
+       s := 0
+       for _, x := range bm {
+               s += bits.OnesCount32(x)
+       }
+       return s
+}
+
 func MakeBitmap(n int) Bitmap {
        return make(Bitmap, (n+31)/32)
 }
@@ -625,6 +635,11 @@ func (l *Loader) NDef() int {
        return int(l.extStart)
 }
 
+// Number of reachable symbols.
+func (l *Loader) NReachableSym() int {
+       return l.attrReachable.Count()
+}
+
 // Returns the raw (unpatched) name of the i-th symbol.
 func (l *Loader) RawSymName(i Sym) string {
        if l.IsExternal(i) {
@@ -2195,7 +2210,6 @@ func (l *Loader) ExtractSymbols(syms *sym.Symbols) {
                if s == nil {
                        continue
                }
-               syms.Allsym = append(syms.Allsym, s) // XXX still add to Allsym for now, as there are code looping through Allsym
                if s.Version < 0 {
                        s.Version = int16(anonVerReplacement)
                }
@@ -2209,7 +2223,6 @@ func (l *Loader) ExtractSymbols(syms *sym.Symbols) {
                }
                s := l.allocSym(name, ver)
                l.installSym(i, s)
-               syms.Allsym = append(syms.Allsym, s) // XXX see above
                return s
        }
        syms.Lookup = l.SymLookup
@@ -2221,7 +2234,6 @@ func (l *Loader) ExtractSymbols(syms *sym.Symbols) {
                i := l.newExtSym(name, ver)
                s := l.allocSym(name, ver)
                l.installSym(i, s)
-               syms.Allsym = append(syms.Allsym, s) // XXX see above
                return s
        }
 }
index d36be11ee819131025bd2997171e88fdd2034307..0d7b7e6a46d6edead39121948a779bc3a515c8a6 100644 (file)
@@ -34,8 +34,6 @@ type Symbols struct {
        // Symbol lookup based on name and indexed by version.
        versions int
 
-       Allsym []*Symbol
-
        // Provided by the loader
 
        // Look up the symbol with the given name and version, creating the
@@ -55,7 +53,6 @@ type Symbols struct {
 func NewSymbols() *Symbols {
        return &Symbols{
                versions: SymVerStatic,
-               Allsym:   make([]*Symbol, 0, 100000),
        }
 }