]> Cypherpunks repositories - gostls13.git/commitdiff
[dev.link] cmd/link: use Extname in doxcoff
authorCherry Zhang <cherryyz@google.com>
Sat, 21 Mar 2020 20:06:57 +0000 (16:06 -0400)
committerCherry Zhang <cherryyz@google.com>
Tue, 24 Mar 2020 16:43:33 +0000 (16:43 +0000)
On AIX, when external linking, we need to change the function
names to start with a dot and make function descriptors with the
names without the dot. Currently this is done through symbol
renaming, which is not friendly for switching to the loader.

In this CL we use symbol's external name for this. This allows us
to get rid of symbol renaming.

Change-Id: If72602d17e96f0339fdac2e2321f1edfb292b5f9
Reviewed-on: https://go-review.googlesource.com/c/go/+/224940
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/xcoff.go
src/cmd/link/internal/loader/loader.go
src/cmd/link/internal/sym/symbols.go

index 74889b3833bf99102127a44e5f760ec9b2bb4f89..5d36622bad47a58cbd5f996d1eca9522ee103d91 100644 (file)
@@ -1186,9 +1186,9 @@ func (ctxt *Link) doxcoff() {
        if ctxt.LinkMode == LinkExternal {
                // Change rt0_go name to match name in runtime/cgo:main().
                rt0 := ctxt.Syms.ROLookup("runtime.rt0_go", 0)
-               ctxt.Syms.Rename(rt0.Name, "runtime_rt0_go", 0)
+               rt0.SetExtname("runtime_rt0_go")
 
-               for _, s := range ctxt.Syms.Allsym {
+               for _, s := range ctxt.Textp {
                        if !s.Attr.CgoExport() {
                                continue
                        }
@@ -1198,9 +1198,19 @@ func (ctxt *Link) doxcoff() {
                                // On AIX, a exported function must have two symbols:
                                // - a .text symbol which must start with a ".".
                                // - a .data symbol which is a function descriptor.
-                               ctxt.Syms.Rename(s.Name, "."+name, 0)
-
-                               desc := ctxt.Syms.Lookup(name, 0)
+                               //
+                               // XXX the old code was quite confusing -- it always
+                               // rename a version 0 symbol, even if s.Version is not
+                               // 0, but the descriptor still points to s.
+                               // And in xcoffCreateExportFile, it seems to expect a
+                               // name before the renaming.
+                               // I guess this happens to work as the ABIALIAS symbol
+                               // and the TEXT symbol have the same address.
+                               // (Do the same here for now, but using Extname.)
+                               s0 := ctxt.Syms.ROLookup(s.Name, 0)
+                               s0.SetExtname("." + name)
+
+                               desc := ctxt.Syms.Newsym(name, 0)
                                desc.Type = sym.SNOPTRDATA
                                desc.AddAddr(ctxt.Arch, s)
                                desc.AddAddr(ctxt.Arch, toc)
@@ -1662,7 +1672,7 @@ func xcoffCreateExportFile(ctxt *Link) (fname string) {
                if !s.Attr.CgoExport() {
                        continue
                }
-               if !strings.HasPrefix(s.String(), "_cgoexp_") {
+               if !strings.HasPrefix(s.Extname(), "_cgoexp_") {
                        continue
                }
 
index b06e92214eb07a671186f01457c05a01dfb8a73f..2c180af0a4e794aeb32710127a5bf20b6a950f90 100644 (file)
@@ -2060,35 +2060,12 @@ func (l *Loader) ExtractSymbols(syms *sym.Symbols, rp map[*sym.Symbol]*sym.Symbo
                i := l.Lookup(name, ver)
                return l.Syms[i]
        }
-       syms.Rename = func(old, new string, ver int) {
-               // annoying... maybe there is a better way to do this
-               if ver >= 2 {
-                       panic("cannot rename static symbol")
-               }
-               i := l.Lookup(old, ver)
-               s := l.Syms[i]
-               s.Name = new
-               if s.Extname() == old {
-                       s.SetExtname(new)
-               }
-               delete(l.symsByName[ver], old)
-
-               // This mirrors the old code. But I'm not sure if the logic of
-               // handling dup in the old code actually works, or necessary.
-               dupi := l.symsByName[ver][new]
-               dup := l.Syms[dupi]
-               if dup == nil {
-                       l.symsByName[ver][new] = i
-               } else {
-                       if s.Type == 0 {
-                               dup.Attr |= s.Attr
-                               *s = *dup
-                       } else if dup.Type == 0 {
-                               s.Attr |= dup.Attr
-                               *dup = *s
-                               l.symsByName[ver][new] = i
-                       }
-               }
+       syms.Newsym = func(name string, ver int) *sym.Symbol {
+               i := l.newExtSym(name, ver)
+               s := l.allocSym(name, ver)
+               l.installSym(i, s)
+               syms.Allsym = append(syms.Allsym, s) // XXX see above
+               return s
        }
 }
 
index 10e4ac5f543bdc931a61dcd643736832c5143e4e..d36be11ee819131025bd2997171e88fdd2034307 100644 (file)
@@ -46,8 +46,10 @@ type Symbols struct {
        // if it is not found.
        ROLookup func(name string, v int) *Symbol
 
-       // Rename renames a symbol.
-       Rename func(old, new string, v int)
+       // Create a symbol with the given name and version. The new symbol
+       // is not added to the lookup table and is not dedup'd with existing
+       // symbols (if any).
+       Newsym func(name string, v int) *Symbol
 }
 
 func NewSymbols() *Symbols {