Commit 32bc0976 authored by Than McIntosh's avatar Than McIntosh Committed by Brad Fitzpatrick

cmd/link: use side table instead of sym.Symbol 'Reachparent' field

The sym.Symbol 'Reachparent' field is used only when field tracking
is enabled. So as to use less memory for the common case where
field tracking is not enabled, remove this field and use a side
table stored in the context to achieve the same functionality.

Updates #26186

Change-Id: Idc5f8b0aa323689d4d51dddb5d1b0341a37bb7d2
Reviewed-on: https://go-review.googlesource.com/121915Reviewed-by: default avatarIan Lance Taylor <iant@golang.org>
parent 0e0cd70e
...@@ -190,7 +190,9 @@ func (d *deadcodepass) mark(s, parent *sym.Symbol) { ...@@ -190,7 +190,9 @@ func (d *deadcodepass) mark(s, parent *sym.Symbol) {
fmt.Printf("%s -> %s\n", p, s.Name) fmt.Printf("%s -> %s\n", p, s.Name)
} }
s.Attr |= sym.AttrReachable s.Attr |= sym.AttrReachable
s.Reachparent = parent if d.ctxt.Reachparent != nil {
d.ctxt.Reachparent[s] = parent
}
d.markQueue = append(d.markQueue, s) d.markQueue = append(d.markQueue, s)
} }
......
...@@ -294,7 +294,7 @@ func fieldtrack(ctxt *Link) { ...@@ -294,7 +294,7 @@ func fieldtrack(ctxt *Link) {
s.Attr |= sym.AttrNotInSymbolTable s.Attr |= sym.AttrNotInSymbolTable
if s.Attr.Reachable() { if s.Attr.Reachable() {
buf.WriteString(s.Name[9:]) buf.WriteString(s.Name[9:])
for p := s.Reachparent; p != nil; p = p.Reachparent { for p := ctxt.Reachparent[s]; p != nil; p = ctxt.Reachparent[p] {
buf.WriteString("\t") buf.WriteString("\t")
buf.WriteString(p.Name) buf.WriteString(p.Name)
} }
......
...@@ -86,6 +86,9 @@ type Link struct { ...@@ -86,6 +86,9 @@ type Link struct {
// unresolvedSymSet is a set of erroneous unresolved references. // unresolvedSymSet is a set of erroneous unresolved references.
// Used to avoid duplicated error messages. // Used to avoid duplicated error messages.
unresolvedSymSet map[unresolvedSymKey]bool unresolvedSymSet map[unresolvedSymKey]bool
// Used to implement field tracking.
Reachparent map[*sym.Symbol]*sym.Symbol
} }
type unresolvedSymKey struct { type unresolvedSymKey struct {
......
...@@ -34,6 +34,7 @@ import ( ...@@ -34,6 +34,7 @@ import (
"bufio" "bufio"
"cmd/internal/objabi" "cmd/internal/objabi"
"cmd/internal/sys" "cmd/internal/sys"
"cmd/link/internal/sym"
"flag" "flag"
"log" "log"
"os" "os"
...@@ -144,6 +145,10 @@ func Main(arch *sys.Arch, theArch Arch) { ...@@ -144,6 +145,10 @@ func Main(arch *sys.Arch, theArch Arch) {
} }
} }
if objabi.Fieldtrack_enabled != 0 {
ctxt.Reachparent = make(map[*sym.Symbol]*sym.Symbol)
}
startProfile() startProfile()
if ctxt.BuildMode == BuildModeUnset { if ctxt.BuildMode == BuildModeUnset {
ctxt.BuildMode = BuildModeExe ctxt.BuildMode = BuildModeExe
......
...@@ -31,17 +31,16 @@ type Symbol struct { ...@@ -31,17 +31,16 @@ type Symbol struct {
// ElfType is set for symbols read from shared libraries by ldshlibsyms. It // ElfType is set for symbols read from shared libraries by ldshlibsyms. It
// is not set for symbols defined by the packages being linked or by symbols // is not set for symbols defined by the packages being linked or by symbols
// read by ldelf (and so is left as elf.STT_NOTYPE). // read by ldelf (and so is left as elf.STT_NOTYPE).
ElfType elf.SymType ElfType elf.SymType
Sub *Symbol Sub *Symbol
Outer *Symbol Outer *Symbol
Gotype *Symbol Gotype *Symbol
Reachparent *Symbol File string
File string Dynimplib string
Dynimplib string Dynimpvers string
Dynimpvers string Sect *Section
Sect *Section FuncInfo *FuncInfo
FuncInfo *FuncInfo Lib *Library // Package defining this symbol
Lib *Library // Package defining this symbol
// P contains the raw symbol data. // P contains the raw symbol data.
P []byte P []byte
R []Reloc R []Reloc
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment