]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/link: fix file-local checks in xcoff
authorAustin Clements <austin@google.com>
Fri, 16 Apr 2021 02:27:37 +0000 (22:27 -0400)
committerAustin Clements <austin@google.com>
Fri, 16 Apr 2021 17:19:08 +0000 (17:19 +0000)
The xcoff writer has several "ldr.SymVersion(s) != 0" checks. The
intent of these is to check for file-local (or static) symbols. Prior
to the introduction of symbol ABIs, this was indeed equivalent since
only file-local symbols has non-zero versions, but ABIs also use the
symbol version space. This still happened to work until much more
recently because we were only ever cgo-exporting version 0 symbols,
but CL 309341 changed this, causing these checks to fail on symbols
that were okay to export.

Replace these checks with ldr.IsFileLocal(s).

This should fix the AIX builder.

(Originally based on CL 309772.)

Fixes #45553.
Updates #40724.

Change-Id: I0a3a7f621ad8f9fe078d34e667286275257691ea
Reviewed-on: https://go-review.googlesource.com/c/go/+/310729
Trust: Austin Clements <austin@google.com>
Run-TryBot: Austin Clements <austin@google.com>
Reviewed-by: Than McIntosh <thanm@google.com>
Reviewed-by: Cherry Zhang <cherryyz@google.com>
src/cmd/link/internal/ld/xcoff.go

index ba818eaa961e525293d4f573bdf7f62af56bfae1..d412c6966bc3bc0e5ea09f4694d02200c15cbe3a 100644 (file)
@@ -825,7 +825,7 @@ func (f *xcoffFile) writeSymbolFunc(ctxt *Link, x loader.Sym) []xcoffSym {
                Nnumaux: 2,
        }
 
-       if ldr.SymVersion(x) != 0 || ldr.AttrVisibilityHidden(x) || ldr.AttrLocal(x) {
+       if ldr.IsFileLocal(x) || ldr.AttrVisibilityHidden(x) || ldr.AttrLocal(x) {
                s.Nsclass = C_HIDEXT
        }
 
@@ -914,7 +914,7 @@ func putaixsym(ctxt *Link, x loader.Sym, t SymbolType) {
                        Nnumaux: 1,
                }
 
-               if ldr.SymVersion(x) != 0 || ldr.AttrVisibilityHidden(x) || ldr.AttrLocal(x) {
+               if ldr.IsFileLocal(x) || ldr.AttrVisibilityHidden(x) || ldr.AttrLocal(x) {
                        // There is more symbols in the case of a global data
                        // which are related to the assembly generated
                        // to access such symbols.
@@ -1318,19 +1318,14 @@ func (ctxt *Link) doxcoff() {
                        if !ldr.AttrCgoExport(s) {
                                continue
                        }
-                       if ldr.SymVersion(s) != 0 { // sanity check
-                               panic("cgo_export on non-version 0 symbol")
+                       if ldr.IsFileLocal(s) {
+                               panic("cgo_export on static symbol")
                        }
 
                        if ldr.SymType(s) == sym.STEXT || ldr.SymType(s) == sym.SABIALIAS {
                                // 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.
-                               //
-                               // CgoExport attribute should only be set on a version 0
-                               // symbol, which can be TEXT or ABIALIAS.
-                               // (before, setupdynexp copies the attribute from the
-                               // alias to the aliased. Now we are before setupdynexp.)
                                name := ldr.SymExtname(s)
                                ldr.SetSymExtname(s, "."+name)
 
@@ -1787,8 +1782,8 @@ func xcoffCreateExportFile(ctxt *Link) (fname string) {
                if !strings.HasPrefix(extname, "._cgoexp_") {
                        continue
                }
-               if ldr.SymVersion(s) != 0 {
-                       continue // Only export version 0 symbols. See the comment in doxcoff.
+               if ldr.IsFileLocal(s) {
+                       continue // Only export non-static symbols
                }
 
                // Retrieve the name of the initial symbol