]> Cypherpunks repositories - gostls13.git/commitdiff
[dev.link] cmd/link: add dupok symbols resolved to another package to textp
authorCherry Zhang <cherryyz@google.com>
Fri, 11 Oct 2019 21:43:32 +0000 (17:43 -0400)
committerCherry Zhang <cherryyz@google.com>
Tue, 15 Oct 2019 18:59:52 +0000 (18:59 +0000)
When 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. At the
point after deadcode where we populate symbol contents for
reachable symbols (add relocations and read symbol data), make a
note of the dupok text symbols for each package. Later in
addToTextp we will visit packages in dependency order, process
the dup text symbol list for each package and select a final lib
for each dup text symbol.

Change-Id: Ib885e0a7e2343229d853aa629e3e337111df6011
Reviewed-on: https://go-review.googlesource.com/c/go/+/200797
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/objfile/objfile2.go

index 21454cf2479be5930a860c8e553304083e3c51de..d37f73776ff4d6a3126f4221e3f065aae4bde7c1 100644 (file)
@@ -559,20 +559,36 @@ func loadObjFull(l *Loader, r *oReader) {
 
        pcdataBase := r.PcdataBase()
        for i, n := 0, r.NSym()+r.NNonpkgdef(); i < n; i++ {
-               s := l.Syms[istart+Sym(i)]
-               if s == nil || s.Name == "" {
-                       continue
-               }
-
                osym := goobj2.Sym{}
                osym.Read(r.Reader, r.SymOff(i))
                name := strings.Replace(osym.Name, "\"\".", r.pkgprefix, -1)
+               if name == "" {
+                       continue
+               }
+               ver := abiToVer(osym.ABI, r.version)
+               dupok := osym.Flag&goobj2.SymFlagDupok != 0
+               if dupsym := l.symsByName[nameVer{name, ver}]; dupsym != istart+Sym(i) {
+                       if dupok && l.Reachable.Has(dupsym) {
+                               // 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[dupsym]
+                               if s.Type == sym.STEXT {
+                                       lib.DupTextSyms = append(lib.DupTextSyms, s)
+                               }
+                       }
+                       continue
+               }
+
+               s := l.Syms[istart+Sym(i)]
+               if s == nil {
+                       continue
+               }
                if s.Name != name { // Sanity check. We can remove it in the final version.
                        fmt.Println("name mismatch:", lib, i, s.Name, name)
                        panic("name mismatch")
                }
 
-               dupok := osym.Flag&goobj2.SymFlagDupok != 0
                local := osym.Flag&goobj2.SymFlagLocal != 0
                makeTypelink := osym.Flag&goobj2.SymFlagTypelink != 0
                size := osym.Siz