From: Cherry Zhang Date: Sat, 12 Oct 2019 05:05:03 +0000 (-0400) Subject: [dev.link] cmd/link: let cgo import overwrite contentless data symbol X-Git-Tag: go1.14beta1~292^2^2~49 X-Git-Url: http://www.git.cypherpunks.su/?a=commitdiff_plain;h=7256f50065f1d53f44c1c9562ad04184ee93279d;p=gostls13.git [dev.link] cmd/link: let cgo import overwrite contentless data symbol 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 TryBot-Result: Gobot Gobot Reviewed-by: Jeremy Faller --- diff --git a/src/cmd/link/internal/ld/go.go b/src/cmd/link/internal/ld/go.go index 15d4f9e50f..6c61869ed8 100644 --- a/src/cmd/link/internal/ld/go.go +++ b/src/cmd/link/internal/ld/go.go @@ -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)