]> Cypherpunks repositories - gostls13.git/commitdiff
[dev.link] cmd/link: stop populating lib/unit.Textp
authorCherry Zhang <cherryyz@google.com>
Fri, 10 Apr 2020 23:13:01 +0000 (19:13 -0400)
committerCherry Zhang <cherryyz@google.com>
Mon, 13 Apr 2020 17:48:39 +0000 (17:48 +0000)
lib.Textp was used for text address assignment and trampoline
insertion. Now that it has been converted to using the loader,
no need to populate lib.Textp.

Port the logic of canonicalizing dupok symbol's package to the
loader.

unit.Textp was used for DWARF generation, which has also been
converted to using the loader.

Change-Id: I22d4dd30a52a29dd5b1b7b795d43a19f6215e4ac
Reviewed-on: https://go-review.googlesource.com/c/go/+/228140
Run-TryBot: Cherry Zhang <cherryyz@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Than McIntosh <thanm@google.com>
src/cmd/link/internal/ld/data.go
src/cmd/link/internal/ld/deadcode.go
src/cmd/link/internal/loader/loader.go
src/cmd/link/internal/sym/library.go

index 44eea8429e5216c460c8328b895beea968a4ed4d..d8c11fa4c00a545a923adf0e4a3f5889d5f91244 100644 (file)
@@ -413,7 +413,7 @@ func relocsym(target *Target, ldr *loader.Loader, err *ErrorReporter, syms *Arch
                case objabi.R_ADDRCUOFF:
                        // debug_range and debug_loc elements use this relocation type to get an
                        // offset from the start of the compile unit.
-                       o = Symaddr(r.Sym) + r.Add - Symaddr(r.Sym.Unit.Textp[0])
+                       o = Symaddr(r.Sym) + r.Add - Symaddr(ldr.Syms[r.Sym.Unit.Textp2[0]])
 
                        // r->sym can be null when CALL $(constant) is transformed from absolute PC to relative PC call.
                case objabi.R_GOTPCREL:
index 13ddcdac24c4f482f6a1c08c98561d9d636283c9..e5bd73cd942e18f51e643206c7741b58c99aede2 100644 (file)
@@ -5,7 +5,6 @@
 package ld
 
 import (
-       "cmd/internal/objabi"
        "cmd/link/internal/sym"
 )
 
@@ -46,11 +45,9 @@ func deadcode(ctxt *Link) {
 }
 
 // addToTextp populates the context Textp slice (needed in various places
-// in the linker) and also the unit Textp slices (needed by the "old"
-// phase 2 DWARF generation).
+// in the linker).
 func addToTextp(ctxt *Link) {
-
-       // First set up ctxt.Textp, based on ctxt.Textp2.
+       // Set up ctxt.Textp, based on ctxt.Textp2.
        textp := make([]*sym.Symbol, 0, len(ctxt.Textp2))
        haveshlibs := len(ctxt.Shlibs) > 0
        for _, tsym := range ctxt.Textp2 {
@@ -64,37 +61,4 @@ func addToTextp(ctxt *Link) {
                textp = append(textp, sp)
        }
        ctxt.Textp = textp
-
-       // Dupok symbols may be defined in multiple packages; the
-       // associated package for a dupok sym is chosen sort of
-       // arbitrarily (the first containing package that the linker
-       // loads). The loop below canonicalizes the File to the package
-       // with which it will be laid down in text. Assumes that
-       // ctxt.Library is already in postorder.
-       for _, doInternal := range [2]bool{true, false} {
-               for _, lib := range ctxt.Library {
-                       if isRuntimeDepPkg(lib.Pkg) != doInternal {
-                               continue
-                       }
-                       for _, dsym := range lib.DupTextSyms2 {
-                               tsp := ctxt.loader.Syms[dsym]
-                               if !tsp.Attr.OnList() {
-                                       tsp.Attr |= sym.AttrOnList
-                                       tsp.File = objabi.PathToPrefix(lib.Pkg)
-                               }
-                       }
-               }
-       }
-
-       // Finally, set up compilation unit Textp slices. Can be removed
-       // once loader-Sym DWARF-gen phase 2 is always enabled.
-       for _, lib := range ctxt.Library {
-               for _, unit := range lib.Units {
-                       for _, usym := range unit.Textp2 {
-                               usp := ctxt.loader.Syms[usym]
-                               usp.Attr |= sym.AttrOnList
-                               unit.Textp = append(unit.Textp, usp)
-                       }
-               }
-       }
 }
index daf91dd258216c89bcd85eb2461c422389f27c34..ff5d8ed32275e6794254a52d7e1669e8ef55e999 100644 (file)
@@ -1252,10 +1252,10 @@ func (l *Loader) SymUnit(i Sym) *sym.CompilationUnit {
 // shared library), will hold the library name.
 // NOTE: this correspondes to sym.Symbol.File field.
 func (l *Loader) SymPkg(i Sym) string {
+       if f, ok := l.symPkg[i]; ok {
+               return f
+       }
        if l.IsExternal(i) {
-               if f, ok := l.symPkg[i]; ok {
-                       return f
-               }
                pp := l.getPayload(i)
                if pp.objidx != 0 {
                        r := l.objs[pp.objidx].r
@@ -1275,9 +1275,6 @@ func (l *Loader) SetSymPkg(i Sym, pkg string) {
        if i >= Sym(len(l.objSyms)) || i == 0 {
                panic("bad symbol index in SetSymPkg")
        }
-       if !l.IsExternal(i) {
-               panic("can't set file for non-external sym")
-       }
        l.symPkg[i] = pkg
 }
 
@@ -2452,7 +2449,6 @@ func (l *Loader) CreateStaticSym(name string) Sym {
 }
 
 func loadObjFull(l *Loader, r *oReader) {
-       lib := r.unit.Lib
        resolveSymRef := func(s goobj2.SymRef) *sym.Symbol {
                i := l.resolve(r, s)
                return l.Syms[i]
@@ -2463,34 +2459,16 @@ func loadObjFull(l *Loader, r *oReader) {
                // content will actually be provided by a different object
                // (to which its global index points). Skip those symbols.
                gi := l.toGlobal(r, i)
-               var isdup bool
                if r2, i2 := l.toLocal(gi); r2 != r || i2 != i {
-                       isdup = true
-               }
-
-               osym := r.Sym(i)
-               dupok := osym.Dupok()
-               if dupok && isdup {
-                       if l.attrReachable.Has(gi) {
-                               // A dupok symbol is resolved to another package. We still need
-                               // to record its presence in the current package, as the trampoline
-                               // pass expects packages are laid out in dependency order.
-                               s := l.Syms[gi]
-                               if s.Type == sym.STEXT {
-                                       lib.DupTextSyms = append(lib.DupTextSyms, s)
-                               }
-                       }
                        continue
                }
-
-               if isdup {
-                       continue // come from a different object
-               }
                s := l.Syms[gi]
                if s == nil {
                        continue
                }
 
+               osym := r.Sym(i)
+               dupok := osym.Dupok()
                local := osym.Local()
                makeTypelink := osym.Typelink()
                size := osym.Siz()
@@ -2711,7 +2689,7 @@ func (l *Loader) AssignTextSymbolOrder(libs []*sym.Library, intlibs []bool, exts
                        }
                        libtextp2 := []sym.LoaderSym{}
                        lists := [2][]sym.LoaderSym{lib.Textp2, lib.DupTextSyms2}
-                       for _, list := range lists {
+                       for i, list := range lists {
                                for _, s := range list {
                                        sym := Sym(s)
                                        if l.attrReachable.Has(sym) && !assignedToUnit.Has(sym) {
@@ -2722,6 +2700,14 @@ func (l *Loader) AssignTextSymbolOrder(libs []*sym.Library, intlibs []bool, exts
                                                        unit.Textp2 = append(unit.Textp2, s)
                                                        assignedToUnit.Set(sym)
                                                }
+                                               // Dupok symbols may be defined in multiple packages; the
+                                               // associated package for a dupok sym is chosen sort of
+                                               // arbitrarily (the first containing package that the linker
+                                               // loads). Canonicalizes its Pkg to the package with which
+                                               // it will be laid down in text.
+                                               if i == 1 /* DupTextSyms2 */ && l.SymPkg(sym) != lib.Pkg {
+                                                       l.SetSymPkg(sym, lib.Pkg)
+                                               }
                                        }
                                }
                        }
index 21568dfbe2901518caf18b14428086394b2f3000..bed16565baac5aecc6b2fdf3f99800210672b8e0 100644 (file)
@@ -13,8 +13,6 @@ type Library struct {
        Hash          string
        ImportStrings []string
        Imports       []*Library
-       Textp         []*Symbol // text symbols defined in this library
-       DupTextSyms   []*Symbol // dupok text symbols defined in this library
        Main          bool
        Safe          bool
        Units         []*CompilationUnit