Skip to content

Commit

Permalink
cmd/link: use side table instead of sym.Symbol 'Reachparent' field
Browse files Browse the repository at this point in the history
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/121915
Reviewed-by: Ian Lance Taylor <[email protected]>
  • Loading branch information
thanm authored and bradfitz committed Jul 3, 2018
1 parent 0e0cd70 commit 32bc097
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 13 deletions.
4 changes: 3 additions & 1 deletion src/cmd/link/internal/ld/deadcode.go
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,9 @@ func (d *deadcodepass) mark(s, parent *sym.Symbol) {
fmt.Printf("%s -> %s\n", p, s.Name)
}
s.Attr |= sym.AttrReachable
s.Reachparent = parent
if d.ctxt.Reachparent != nil {
d.ctxt.Reachparent[s] = parent
}
d.markQueue = append(d.markQueue, s)
}

Expand Down
2 changes: 1 addition & 1 deletion src/cmd/link/internal/ld/go.go
Original file line number Diff line number Diff line change
Expand Up @@ -294,7 +294,7 @@ func fieldtrack(ctxt *Link) {
s.Attr |= sym.AttrNotInSymbolTable
if s.Attr.Reachable() {
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(p.Name)
}
Expand Down
3 changes: 3 additions & 0 deletions src/cmd/link/internal/ld/link.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,9 @@ type Link struct {
// unresolvedSymSet is a set of erroneous unresolved references.
// Used to avoid duplicated error messages.
unresolvedSymSet map[unresolvedSymKey]bool

// Used to implement field tracking.
Reachparent map[*sym.Symbol]*sym.Symbol
}

type unresolvedSymKey struct {
Expand Down
5 changes: 5 additions & 0 deletions src/cmd/link/internal/ld/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ import (
"bufio"
"cmd/internal/objabi"
"cmd/internal/sys"
"cmd/link/internal/sym"
"flag"
"log"
"os"
Expand Down Expand Up @@ -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()
if ctxt.BuildMode == BuildModeUnset {
ctxt.BuildMode = BuildModeExe
Expand Down
21 changes: 10 additions & 11 deletions src/cmd/link/internal/sym/symbol.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,17 +31,16 @@ type Symbol struct {
// 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
// read by ldelf (and so is left as elf.STT_NOTYPE).
ElfType elf.SymType
Sub *Symbol
Outer *Symbol
Gotype *Symbol
Reachparent *Symbol
File string
Dynimplib string
Dynimpvers string
Sect *Section
FuncInfo *FuncInfo
Lib *Library // Package defining this symbol
ElfType elf.SymType
Sub *Symbol
Outer *Symbol
Gotype *Symbol
File string
Dynimplib string
Dynimpvers string
Sect *Section
FuncInfo *FuncInfo
Lib *Library // Package defining this symbol
// P contains the raw symbol data.
P []byte
R []Reloc
Expand Down

0 comments on commit 32bc097

Please sign in to comment.