From 186e783730e144e99e2f5e2e8b9e02656f7e2c9f Mon Sep 17 00:00:00 2001 From: Than McIntosh Date: Thu, 21 Nov 2019 16:03:58 -0500 Subject: [PATCH] [dev.link] cmd/link: keep loader symbol info in sym.CompilationUnit In sym.Library and sym.CompilationUnit there are slices of *sym.Symbol pointer that hold text symbols contained in the unit lib. To support DWARF generation with new loader, add equivalent slices that hold loader.Sym values for functions in scope. This will be needed if at some point we push the sym.Symbol creation "wavefront" beyond dwarf gen. This patch also insures that live host object symbols are added to the context Textp2 slice, since they would not make it on otherwise. [NB: not sure if this is the best way to do this.] Change-Id: I4f440e12cebc525b1e37082ad39cf7338aeb6b99 Reviewed-on: https://go-review.googlesource.com/c/go/+/208231 Run-TryBot: Than McIntosh TryBot-Result: Gobot Gobot Reviewed-by: Jeremy Faller --- src/cmd/link/internal/ld/deadcode.go | 18 ++++++++++++++++-- src/cmd/link/internal/ld/link.go | 1 + src/cmd/link/internal/loader/loader.go | 3 +++ src/cmd/link/internal/sym/compilation_unit.go | 8 ++++++++ src/cmd/link/internal/sym/library.go | 3 +++ 5 files changed, 31 insertions(+), 2 deletions(-) diff --git a/src/cmd/link/internal/ld/deadcode.go b/src/cmd/link/internal/ld/deadcode.go index 4a53d7947bb..ed341288f87 100644 --- a/src/cmd/link/internal/ld/deadcode.go +++ b/src/cmd/link/internal/ld/deadcode.go @@ -54,6 +54,18 @@ func addToTextp(ctxt *Link) { } } + // Append the sym.Symbol's that correspond to the reachable + // loader.Sym's created by the new host object loader. + // FIXME: is this the right way to do this? Or should there be + // some way to associated a given host object symbol with the Go + // package that refers to it? + for _, s := range ctxt.Textp2 { + if !ctxt.loader.AttrReachable(s) { + continue + } + textp = append(textp, ctxt.loader.Syms[s]) + } + // Put reachable text symbols into Textp. // do it in postorder so that packages are laid down in dependency order // internal first, then everything else @@ -64,21 +76,23 @@ func addToTextp(ctxt *Link) { continue } libtextp := lib.Textp[:0] - for _, s := range lib.Textp { + for idx, s := range lib.Textp { if s.Attr.Reachable() { textp = append(textp, s) libtextp = append(libtextp, s) if s.Unit != nil { s.Unit.Textp = append(s.Unit.Textp, s) + s.Unit.Textp2 = append(s.Unit.Textp2, lib.Textp2[idx]) } } } - for _, s := range lib.DupTextSyms { + for idx, s := range lib.DupTextSyms { if s.Attr.Reachable() && !s.Attr.OnList() { textp = append(textp, s) libtextp = append(libtextp, s) if s.Unit != nil { s.Unit.Textp = append(s.Unit.Textp, s) + s.Unit.Textp2 = append(s.Unit.Textp2, lib.DupTextSyms2[idx]) } s.Attr |= sym.AttrOnList // dupok symbols may be defined in multiple packages. its diff --git a/src/cmd/link/internal/ld/link.go b/src/cmd/link/internal/ld/link.go index 124f7d9001f..965c0851d2d 100644 --- a/src/cmd/link/internal/ld/link.go +++ b/src/cmd/link/internal/ld/link.go @@ -78,6 +78,7 @@ type Link struct { Shlibs []Shlib Tlsoffset int Textp []*sym.Symbol + Textp2 []loader.Sym Filesyms []*sym.Symbol Moduledata *sym.Symbol diff --git a/src/cmd/link/internal/loader/loader.go b/src/cmd/link/internal/loader/loader.go index 89e312e6656..28d8c397e0d 100644 --- a/src/cmd/link/internal/loader/loader.go +++ b/src/cmd/link/internal/loader/loader.go @@ -1775,6 +1775,7 @@ func loadObjFull(l *Loader, r *oReader) { s := l.Syms[dupsym] if s.Type == sym.STEXT { lib.DupTextSyms = append(lib.DupTextSyms, s) + lib.DupTextSyms2 = append(lib.DupTextSyms2, sym.LoaderSym(dupsym)) } } continue @@ -1996,10 +1997,12 @@ func loadObjFull(l *Loader, r *oReader) { } s.Attr.Set(sym.AttrOnList, true) lib.Textp = append(lib.Textp, s) + lib.Textp2 = append(lib.Textp2, sym.LoaderSym(isym)) } else { // there may be a dup in another package // put into a temp list and add to text later lib.DupTextSyms = append(lib.DupTextSyms, s) + lib.DupTextSyms2 = append(lib.DupTextSyms2, sym.LoaderSym(isym)) } } } diff --git a/src/cmd/link/internal/sym/compilation_unit.go b/src/cmd/link/internal/sym/compilation_unit.go index 02fb0cfab85..f3933d85358 100644 --- a/src/cmd/link/internal/sym/compilation_unit.go +++ b/src/cmd/link/internal/sym/compilation_unit.go @@ -6,6 +6,8 @@ package sym import "cmd/internal/dwarf" +type LoaderSym int + // CompilationUnit is an abstraction used by DWARF to represent a chunk of // debug-related data. We create a CompilationUnit per Object file in a // library (so, one for all the Go code, one for each assembly file, etc.). @@ -20,4 +22,10 @@ type CompilationUnit struct { RangeSyms []*Symbol // Symbols for debug_range Textp []*Symbol // Text symbols in this CU DWARFFileTable []string // The file table used to generate the .debug_lines + + Consts2 LoaderSym // Package constants DIEs (loader) + FuncDIEs2 []LoaderSym // Function DIE subtrees (loader) + AbsFnDIEs2 []LoaderSym // Abstract function DIE subtrees (loader) + RangeSyms2 []LoaderSym // Symbols for debug_range (loader) + Textp2 []LoaderSym // Text symbols in this CU (loader) } diff --git a/src/cmd/link/internal/sym/library.go b/src/cmd/link/internal/sym/library.go index 4f2023b8f7f..21568dfbe29 100644 --- a/src/cmd/link/internal/sym/library.go +++ b/src/cmd/link/internal/sym/library.go @@ -18,6 +18,9 @@ type Library struct { Main bool Safe bool Units []*CompilationUnit + + Textp2 []LoaderSym // text syms defined in this library + DupTextSyms2 []LoaderSym // dupok text syms defined in this library } func (l Library) String() string {