]> Cypherpunks repositories - gostls13.git/commitdiff
[dev.link] cmd/link: let cgo import overwrite contentless data symbol
authorCherry Zhang <cherryyz@google.com>
Sat, 12 Oct 2019 05:05:03 +0000 (01:05 -0400)
committerCherry Zhang <cherryyz@google.com>
Tue, 15 Oct 2019 19:00:00 +0000 (19:00 +0000)
A contentless data symbol may be a declaration of a cgo-imported
variable, e.g.

//go:cgo_import_dynamic xxx
var xxx uintptr

In this case, we want to mark the symbol imported, instead of
defined with zero value.

We used to load cgo directives before loading the object file, so
we'll mark the symbol SDYNIMPORT first. But in newobj mode,
currently we load cgo directives later. Letting SDYNIMPORT
overwrite contentless data symbol makes it work in both ordering.

Change-Id: I878f52086d6cdb5a347669bf8f848a49bce87b52
Reviewed-on: https://go-review.googlesource.com/c/go/+/201020
Run-TryBot: Cherry Zhang <cherryyz@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Jeremy Faller <jeremy@golang.org>
src/cmd/link/internal/ld/go.go

index 15d4f9e50ff5836c878eb55682a5a6c43ae3d82a..6c61869ed889abaf5e2da7e8b30ace35bde374d7 100644 (file)
@@ -197,7 +197,7 @@ func setCgoAttr(ctxt *Link, file string, pkg string, directives [][]string) {
                                remote, q = remote[:i], remote[i+1:]
                        }
                        s := ctxt.Syms.Lookup(local, 0)
-                       if s.Type == 0 || s.Type == sym.SXREF || s.Type == sym.SHOSTOBJ {
+                       if s.Type == 0 || s.Type == sym.SXREF || s.Type == sym.SBSS || s.Type == sym.SNOPTRBSS || s.Type == sym.SHOSTOBJ {
                                s.SetDynimplib(lib)
                                s.SetExtname(remote)
                                s.SetDynimpvers(q)