]> Cypherpunks repositories - gostls13.git/commitdiff
[dev.link] cmd/link: keep loader symbol info in sym.CompilationUnit
authorThan McIntosh <thanm@google.com>
Thu, 21 Nov 2019 21:03:58 +0000 (16:03 -0500)
committerThan McIntosh <thanm@google.com>
Mon, 6 Jan 2020 18:46:13 +0000 (18:46 +0000)
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 <thanm@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Jeremy Faller <jeremy@golang.org>
src/cmd/link/internal/ld/deadcode.go
src/cmd/link/internal/ld/link.go
src/cmd/link/internal/loader/loader.go
src/cmd/link/internal/sym/compilation_unit.go
src/cmd/link/internal/sym/library.go

index 4a53d7947bb8497625ac42911dd56dc18666797e..ed341288f87c0dfbba0775b02ec19133948de2df 100644 (file)
@@ -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
index 124f7d9001fcad1e551a689b0f7d2e95386cc16a..965c0851d2ded58ab6531eb5e377b9219f13d41b 100644 (file)
@@ -78,6 +78,7 @@ type Link struct {
        Shlibs       []Shlib
        Tlsoffset    int
        Textp        []*sym.Symbol
+       Textp2       []loader.Sym
        Filesyms     []*sym.Symbol
        Moduledata   *sym.Symbol
 
index 89e312e665680138c577a9a88354ca823461e752..28d8c397e0d6cc912485ac0299d3797eb2bebb82 100644 (file)
@@ -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))
                }
        }
 }
index 02fb0cfab85f84cec6aaccaa4c69d053c71c0cba..f3933d85358f398ca970b05b67117046f6d9eec9 100644 (file)
@@ -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)
 }
index 4f2023b8f7fd0c575b36236f22462ddb8194d3b1..21568dfbe2901518caf18b14428086394b2f3000 100644 (file)
@@ -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 {