aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorThan McIntosh <thanm@google.com>2021-07-15 16:29:36 -0400
committerCarlos Amedee <carlos@golang.org>2021-08-02 22:26:52 +0000
commit3d5afa9610c5b0e45783868ae964152855a736ac (patch)
tree6271b7865523bcc98d33a103b2f8382b63485afd /src
parent0fb1e1438b02072bb9c3c566b40ad66b1ffed365 (diff)
downloadgo-3d5afa9610c5b0e45783868ae964152855a736ac.tar.gz
go-3d5afa9610c5b0e45783868ae964152855a736ac.zip
[release-branch.go1.16] cmd/{compile,link}: fix bug in map.zero handling
In CL 326211 a change was made to switch "go.map.zero" symbols from non-pkg DUPOK symbols to hashed symbols. The intent of this change was ensure that in cases where there are multiple competing go.map.zero symbols feeding into a link, the largest map.zero symbol is selected. The change was buggy, however, and resulted in duplicate symbols in the final binary (see bug cited below for details). This duplication was relatively benign for linux/ELF, but causes duplicate definition errors on Windows. This patch switches "go.map.zero" symbols back from hashed symbols to non-pkg DUPOK symbols, and updates the relevant code in the loader to ensure that we do the right thing when there are multiple competing DUPOK symbols with different sizes. Fixes #47289. Change-Id: I8aeb910c65827f5380144d07646006ba553c9251 Reviewed-on: https://go-review.googlesource.com/c/go/+/334930 Trust: Than McIntosh <thanm@google.com> Run-TryBot: Than McIntosh <thanm@google.com> TryBot-Result: Go Bot <gobot@golang.org> Reviewed-by: Cherry Mui <cherryyz@google.com> (cherry picked from commit 49402bee36fd3d5cee9f4b2d2e1e8560ead0203b) Reviewed-on: https://go-review.googlesource.com/c/go/+/335629
Diffstat (limited to 'src')
-rw-r--r--src/cmd/compile/internal/gc/obj.go2
-rw-r--r--src/cmd/link/internal/loader/loader.go9
2 files changed, 10 insertions, 1 deletions
diff --git a/src/cmd/compile/internal/gc/obj.go b/src/cmd/compile/internal/gc/obj.go
index 579e8bd823..da1869e945 100644
--- a/src/cmd/compile/internal/gc/obj.go
+++ b/src/cmd/compile/internal/gc/obj.go
@@ -163,7 +163,7 @@ func dumpdata() {
if zerosize > 0 {
zero := mappkg.Lookup("zero")
ggloblsym(zero.Linksym(), int32(zerosize), obj.DUPOK|obj.RODATA)
- zero.Linksym().Set(obj.AttrContentAddressable, true)
+ zero.Linksym().Set(obj.AttrStatic, true)
}
addGCLocals()
diff --git a/src/cmd/link/internal/loader/loader.go b/src/cmd/link/internal/loader/loader.go
index 971cc432ff..85b948990a 100644
--- a/src/cmd/link/internal/loader/loader.go
+++ b/src/cmd/link/internal/loader/loader.go
@@ -474,6 +474,15 @@ func (st *loadState) addSym(name string, ver int, r *oReader, li uint32, kind in
if l.flags&FlagStrictDups != 0 {
l.checkdup(name, r, li, oldi)
}
+ // Fix for issue #47185 -- given two dupok symbols with
+ // different sizes, favor symbol with larger size. See
+ // also issue #46653.
+ szdup := l.SymSize(oldi)
+ sz := int64(r.Sym(li).Siz())
+ if szdup < sz {
+ // new symbol overwrites old symbol.
+ l.objSyms[oldi] = objSym{r.objidx, li}
+ }
return oldi
}
oldr, oldli := l.toLocal(oldi)