Skip to content

Commit 32bc097

Browse files
thanmbradfitz
authored andcommitted
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/121915 Reviewed-by: Ian Lance Taylor <[email protected]>
1 parent 0e0cd70 commit 32bc097

File tree

5 files changed

+22
-13
lines changed

5 files changed

+22
-13
lines changed

src/cmd/link/internal/ld/deadcode.go

+3-1
Original file line numberDiff line numberDiff line change
@@ -190,7 +190,9 @@ func (d *deadcodepass) mark(s, parent *sym.Symbol) {
190190
fmt.Printf("%s -> %s\n", p, s.Name)
191191
}
192192
s.Attr |= sym.AttrReachable
193-
s.Reachparent = parent
193+
if d.ctxt.Reachparent != nil {
194+
d.ctxt.Reachparent[s] = parent
195+
}
194196
d.markQueue = append(d.markQueue, s)
195197
}
196198

src/cmd/link/internal/ld/go.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -294,7 +294,7 @@ func fieldtrack(ctxt *Link) {
294294
s.Attr |= sym.AttrNotInSymbolTable
295295
if s.Attr.Reachable() {
296296
buf.WriteString(s.Name[9:])
297-
for p := s.Reachparent; p != nil; p = p.Reachparent {
297+
for p := ctxt.Reachparent[s]; p != nil; p = ctxt.Reachparent[p] {
298298
buf.WriteString("\t")
299299
buf.WriteString(p.Name)
300300
}

src/cmd/link/internal/ld/link.go

+3
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,9 @@ type Link struct {
8686
// unresolvedSymSet is a set of erroneous unresolved references.
8787
// Used to avoid duplicated error messages.
8888
unresolvedSymSet map[unresolvedSymKey]bool
89+
90+
// Used to implement field tracking.
91+
Reachparent map[*sym.Symbol]*sym.Symbol
8992
}
9093

9194
type unresolvedSymKey struct {

src/cmd/link/internal/ld/main.go

+5
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ import (
3434
"bufio"
3535
"cmd/internal/objabi"
3636
"cmd/internal/sys"
37+
"cmd/link/internal/sym"
3738
"flag"
3839
"log"
3940
"os"
@@ -144,6 +145,10 @@ func Main(arch *sys.Arch, theArch Arch) {
144145
}
145146
}
146147

148+
if objabi.Fieldtrack_enabled != 0 {
149+
ctxt.Reachparent = make(map[*sym.Symbol]*sym.Symbol)
150+
}
151+
147152
startProfile()
148153
if ctxt.BuildMode == BuildModeUnset {
149154
ctxt.BuildMode = BuildModeExe

src/cmd/link/internal/sym/symbol.go

+10-11
Original file line numberDiff line numberDiff line change
@@ -31,17 +31,16 @@ type Symbol struct {
3131
// ElfType is set for symbols read from shared libraries by ldshlibsyms. It
3232
// is not set for symbols defined by the packages being linked or by symbols
3333
// read by ldelf (and so is left as elf.STT_NOTYPE).
34-
ElfType elf.SymType
35-
Sub *Symbol
36-
Outer *Symbol
37-
Gotype *Symbol
38-
Reachparent *Symbol
39-
File string
40-
Dynimplib string
41-
Dynimpvers string
42-
Sect *Section
43-
FuncInfo *FuncInfo
44-
Lib *Library // Package defining this symbol
34+
ElfType elf.SymType
35+
Sub *Symbol
36+
Outer *Symbol
37+
Gotype *Symbol
38+
File string
39+
Dynimplib string
40+
Dynimpvers string
41+
Sect *Section
42+
FuncInfo *FuncInfo
43+
Lib *Library // Package defining this symbol
4544
// P contains the raw symbol data.
4645
P []byte
4746
R []Reloc

0 commit comments

Comments
 (0)