]> Cypherpunks repositories - gostls13.git/commitdiff
[dev.link] cmd/link: resolve ABI aliases for external symbols
authorCherry Zhang <cherryyz@google.com>
Fri, 1 Nov 2019 01:53:49 +0000 (21:53 -0400)
committerCherry Zhang <cherryyz@google.com>
Fri, 1 Nov 2019 13:51:36 +0000 (13:51 +0000)
ABI alias references in Go symbols are resolved during
loadObjFull. But for external symbols they are not resolved. If
there is a reference from an external symbol to a Go ABIInternal
symbol, this reference will be invalid as it is not resolved.

The old code resolve ABI aliases in the deadcode pass. But the
new deadcode pass doesn't do it, as it works with indices instead
of Symbols. We do this in LoadFull.

This makes all internal cgo linking tests pass on Mach-O.

Change-Id: Iac6c084c03f5ddbcc9455527800ce7ed7313f9a7
Reviewed-on: https://go-review.googlesource.com/c/go/+/204698
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/lib.go
src/cmd/link/internal/loader/loader.go

index b882df29a11f70ac4ce922fdaca627725fc6a6cf..e46457d8584a635fc1a22128bb431c9953c9b542 100644 (file)
@@ -2620,7 +2620,7 @@ func (ctxt *Link) loadlibfull() {
 
 func (ctxt *Link) dumpsyms() {
        for _, s := range ctxt.Syms.Allsym {
-               fmt.Printf("%s %s %p\n", s, s.Type, s)
+               fmt.Printf("%s %s %p %v %v\n", s, s.Type, s, s.Attr.Reachable(), s.Attr.OnList())
                for i := range s.R {
                        fmt.Println("\t", s.R[i].Type, s.R[i].Sym)
                }
index 0ce6f54ef792ebfdbe565f67a9471f9e57ea70ab..67c4c9719c8ff61b59c0546b3b7f7ec2b1dcec2e 100644 (file)
@@ -753,6 +753,21 @@ func (l *Loader) LoadFull(arch *sys.Arch, syms *sym.Symbols) {
        for _, o := range l.objs[1:] {
                loadObjFull(l, o.r)
        }
+
+       // Resolve ABI aliases for external symbols. This is only
+       // needed for internal cgo linking.
+       // (The old code does this in deadcode, but deadcode2 doesn't
+       // do this.)
+       for i := l.extStart; i <= l.max; i++ {
+               if s := l.Syms[i]; s != nil && s.Attr.Reachable() {
+                       for ri := range s.R {
+                               r := &s.R[ri]
+                               if r.Sym != nil && r.Sym.Type == sym.SABIALIAS {
+                                       r.Sym = r.Sym.R[0].Sym
+                               }
+                       }
+               }
+       }
 }
 
 // ExtractSymbols grabs the symbols out of the loader for work that hasn't been