]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/link: use side table instead of sym.Symbol 'Reachparent' field
authorThan McIntosh <thanm@google.com>
Thu, 28 Jun 2018 19:42:20 +0000 (15:42 -0400)
committerBrad Fitzpatrick <bradfitz@golang.org>
Tue, 3 Jul 2018 14:48:30 +0000 (14:48 +0000)
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 <iant@golang.org>
src/cmd/link/internal/ld/deadcode.go
src/cmd/link/internal/ld/go.go
src/cmd/link/internal/ld/link.go
src/cmd/link/internal/ld/main.go
src/cmd/link/internal/sym/symbol.go

index ce0fe1f7a132913bf8d8019893e117e00368da84..540f4068cb8ea8be8a2816a0f0631f4ce49c745b 100644 (file)
@@ -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)
 }
 
index 8d50332c7c6e15efde22cd02faf873c330e75dd4..eb6c2ccc83128cbb5b1d45d32b33069bdaaddb53 100644 (file)
@@ -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)
                                }
index 2e66cf857c3edb4a7d418a7bdebc6b6c98ebdfec..bf5754435786fa930ec20cedfc778449f1fd7698 100644 (file)
@@ -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 {
index d7929d59fdddffe7d451f6be97e04b1efb05916a..23462f1154b7ea766f22b4d070d9cbf31d8d05b6 100644 (file)
@@ -34,6 +34,7 @@ import (
        "bufio"
        "cmd/internal/objabi"
        "cmd/internal/sys"
+       "cmd/link/internal/sym"
        "flag"
        "log"
        "os"
@@ -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
index b3ff6c4e19079dc8fc658f5486d70623312eef6b..8893dcf0d69e1133c7a8cc1210bda95f18929a90 100644 (file)
@@ -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