1
0
mirror of https://github.com/golang/go synced 2024-11-23 18:20:04 -07:00

[dev.link] cmd/link: drop fields of external symbols after LoadFull

Free some memory.

Linking cmd/compile with external linking,

name             old live-B     new live-B     delta
Loadlibfull_GC     55.3M ± 0%     52.2M ± 0%    -5.50%  (p=0.008 n=5+5)

Change-Id: Ib8de2e61f2b012efaf6bdd98f9e5c56a19910b47
Reviewed-on: https://go-review.googlesource.com/c/go/+/231224
Reviewed-by: Jeremy Faller <jeremy@golang.org>
Reviewed-by: Than McIntosh <thanm@google.com>
This commit is contained in:
Cherry Zhang 2020-04-30 17:45:00 -04:00
parent 83db26ac4a
commit 7aa6e0faf2

View File

@ -2128,12 +2128,14 @@ func (l *Loader) LoadFull(arch *sys.Arch, syms *sym.Symbols, needReloc bool) {
// Resolve ABI aliases for external symbols. This is only
// needed for internal cgo linking.
for _, i := range l.extReader.syms {
if s := l.Syms[i]; s != nil && s.Attr.Reachable() {
for ri := range s.R {
r := &s.R[ri]
if r.Sym != nil && r.Sym.Type == sym.SABIALIAS {
r.Sym = r.Sym.R[0].Sym
if needReloc {
for _, i := range l.extReader.syms {
if s := l.Syms[i]; s != nil && s.Attr.Reachable() {
for ri := range s.R {
r := &s.R[ri]
if r.Sym != nil && r.Sym.Type == sym.SABIALIAS {
r.Sym = r.Sym.R[0].Sym
}
}
}
}
@ -2170,6 +2172,16 @@ func (l *Loader) LoadFull(arch *sys.Arch, syms *sym.Symbols, needReloc bool) {
l.dynid = nil
l.relocVariant = nil
l.extRelocs = nil
// Drop fields that are no longer needed.
for _, i := range l.extReader.syms {
pp := l.getPayload(i)
pp.name = ""
pp.relocs = nil
pp.reltypes = nil
pp.auxs = nil
pp.data = nil
}
}
// ResolveABIAlias given a symbol returns the ABI alias target of that