[dev.link] cmd/link: remove ctxt.Syms.Allsym

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>
This commit is contained in:
Cherry Zhang 2020-04-24 22:45:05 -04:00
parent 2a874562bf
commit a742d0ed5f
7 changed files with 36 additions and 12 deletions

View file

@ -28,7 +28,10 @@ func (ctxt *Link) dodata() {
// Collect data symbols by type into data. // Collect data symbols by type into data.
state := dodataState{ctxt: ctxt} 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() { if !s.Attr.Reachable() || s.Attr.Special() || s.Attr.SubSymbol() {
continue continue
} }

View file

@ -51,7 +51,10 @@ func elfdynhash(ctxt *Link) {
chain := make([]uint32, nsym) chain := make([]uint32, nsym)
buckets := make([]uint32, nbucket) buckets := make([]uint32, nbucket)
for _, sy := range ctxt.Syms.Allsym { for _, sy := range ctxt.loader.Syms {
if sy == nil {
continue
}
if sy.Dynid <= 0 { if sy.Dynid <= 0 {
continue continue
} }

View file

@ -2555,7 +2555,10 @@ func genasmsym(ctxt *Link, put func(*Link, *sym.Symbol, string, SymbolType, int6
return true return true
} }
for _, s := range ctxt.Syms.Allsym { for _, s := range ctxt.loader.Syms {
if s == nil {
continue
}
if !shouldBeInSymbolTable(s) { if !shouldBeInSymbolTable(s) {
continue continue
} }
@ -2909,7 +2912,10 @@ func (ctxt *Link) loadlibfull(symGroupType []sym.SymKind) {
} }
func (ctxt *Link) dumpsyms() { 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) 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 { for i := range s.R {
fmt.Println("\t", s.R[i].Type, s.R[i].Sym) fmt.Println("\t", s.R[i].Type, s.R[i].Sym)

View file

@ -364,7 +364,7 @@ func Main(arch *sys.Arch, theArch Arch) {
bench.Start("hostlink") bench.Start("hostlink")
ctxt.hostlink() ctxt.hostlink()
if ctxt.Debugvlog != 0 { 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) ctxt.Logf("%d liveness data\n", liveness)
} }
bench.Start("Flush") bench.Start("Flush")

View file

@ -1646,7 +1646,10 @@ func xcoffCreateExportFile(ctxt *Link) (fname string) {
fname = filepath.Join(*flagTmpdir, "export_file.exp") fname = filepath.Join(*flagTmpdir, "export_file.exp")
var buf bytes.Buffer var buf bytes.Buffer
for _, s := range ctxt.Syms.Allsym { for _, s := range ctxt.loader.Syms {
if s == nil {
continue
}
if !s.Attr.CgoExport() { if !s.Attr.CgoExport() {
continue continue
} }

View file

@ -147,6 +147,16 @@ func (bm Bitmap) Has(i Sym) bool {
func (bm Bitmap) Len() int { func (bm Bitmap) Len() int {
return len(bm) * 32 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 { func MakeBitmap(n int) Bitmap {
return make(Bitmap, (n+31)/32) return make(Bitmap, (n+31)/32)
} }
@ -625,6 +635,11 @@ func (l *Loader) NDef() int {
return int(l.extStart) 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. // Returns the raw (unpatched) name of the i-th symbol.
func (l *Loader) RawSymName(i Sym) string { func (l *Loader) RawSymName(i Sym) string {
if l.IsExternal(i) { if l.IsExternal(i) {
@ -2195,7 +2210,6 @@ func (l *Loader) ExtractSymbols(syms *sym.Symbols) {
if s == nil { if s == nil {
continue 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 { if s.Version < 0 {
s.Version = int16(anonVerReplacement) s.Version = int16(anonVerReplacement)
} }
@ -2209,7 +2223,6 @@ func (l *Loader) ExtractSymbols(syms *sym.Symbols) {
} }
s := l.allocSym(name, ver) s := l.allocSym(name, ver)
l.installSym(i, s) l.installSym(i, s)
syms.Allsym = append(syms.Allsym, s) // XXX see above
return s return s
} }
syms.Lookup = l.SymLookup syms.Lookup = l.SymLookup
@ -2221,7 +2234,6 @@ func (l *Loader) ExtractSymbols(syms *sym.Symbols) {
i := l.newExtSym(name, ver) i := l.newExtSym(name, ver)
s := l.allocSym(name, ver) s := l.allocSym(name, ver)
l.installSym(i, s) l.installSym(i, s)
syms.Allsym = append(syms.Allsym, s) // XXX see above
return s return s
} }
} }

View file

@ -34,8 +34,6 @@ type Symbols struct {
// Symbol lookup based on name and indexed by version. // Symbol lookup based on name and indexed by version.
versions int versions int
Allsym []*Symbol
// Provided by the loader // Provided by the loader
// Look up the symbol with the given name and version, creating the // Look up the symbol with the given name and version, creating the
@ -55,7 +53,6 @@ type Symbols struct {
func NewSymbols() *Symbols { func NewSymbols() *Symbols {
return &Symbols{ return &Symbols{
versions: SymVerStatic, versions: SymVerStatic,
Allsym: make([]*Symbol, 0, 100000),
} }
} }