From f886ff7b417739cf2269267e7b057a7cfdc85324 Mon Sep 17 00:00:00 2001 From: Cherry Zhang Date: Tue, 28 Apr 2020 18:59:57 -0400 Subject: [PATCH] [dev.link] cmd/link: free loader memory after LoadFull MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit After LoadFull, we'll be using sym.Symbols mostly. We still need the loader information for symbol index mappings and name lookups, but not much else. Free some memory. Linking cmd/compile, name old time/op new time/op delta Loadlibfull_GC 44.5M ± 0% 35.8M ± 0% -19.66% (p=0.008 n=5+5) Archive_GC 46.4M ± 0% 37.6M ± 0% -18.89% (p=0.008 n=5+5) Linking cmd/compile with external linking, name old time/op new time/op delta Loadlibfull_GC 82.5M ± 0% 57.4M ± 0% -30.41% (p=0.008 n=5+5) Archive_GC 86.8M ± 0% 61.7M ± 0% -28.90% (p=0.008 n=5+5) Change-Id: I6859d488172ef8968918b86de527fbfed6832ebf Reviewed-on: https://go-review.googlesource.com/c/go/+/230300 Run-TryBot: Cherry Zhang TryBot-Result: Gobot Gobot Reviewed-by: Jeremy Faller --- src/cmd/link/internal/ld/pe.go | 2 +- src/cmd/link/internal/loader/loader.go | 32 ++++++++++++++++++++++++++ 2 files changed, 33 insertions(+), 1 deletion(-) diff --git a/src/cmd/link/internal/ld/pe.go b/src/cmd/link/internal/ld/pe.go index 547200fbee..362d2fd0a5 100644 --- a/src/cmd/link/internal/ld/pe.go +++ b/src/cmd/link/internal/ld/pe.go @@ -1130,7 +1130,7 @@ func addimports(ctxt *Link, datsect *peSection) { for m := d.ms; m != nil; m = m.next { m.off = uint64(pefile.nextSectOffset) + uint64(ctxt.Out.Offset()) - uint64(startoff) ctxt.Out.Write16(0) // hint - strput(ctxt.Out, ldr.SymExtname(m.s)) + strput(ctxt.Out, ldr.Syms[m.s].Extname()) } } diff --git a/src/cmd/link/internal/loader/loader.go b/src/cmd/link/internal/loader/loader.go index e3dec5feee..a6d9417c00 100644 --- a/src/cmd/link/internal/loader/loader.go +++ b/src/cmd/link/internal/loader/loader.go @@ -2124,6 +2124,38 @@ func (l *Loader) LoadFull(arch *sys.Arch, syms *sym.Symbols, needReloc bool) { } } } + + // Free some memory. + // At this point we still need basic index mapping, and some fields of + // external symbol payloads, but not much else. + l.values = nil + l.symSects = nil + l.outdata = nil + l.itablink = nil + l.attrOnList = nil + l.attrLocal = nil + l.attrNotInSymbolTable = nil + l.attrVisibilityHidden = nil + l.attrDuplicateOK = nil + l.attrShared = nil + l.attrExternal = nil + l.attrReadOnly = nil + l.attrTopFrame = nil + l.attrSpecial = nil + l.attrCgoExportDynamic = nil + l.attrCgoExportStatic = nil + l.outer = nil + l.align = nil + l.dynimplib = nil + l.dynimpvers = nil + l.localentry = nil + l.extname = nil + l.elfType = nil + l.plt = nil + l.got = nil + l.dynid = nil + l.relocVariant = nil + l.extRelocs = nil } // ResolveABIAlias given a symbol returns the ABI alias target of that