Commit 5777ffd6 authored by Cherry Zhang's avatar Cherry Zhang

[dev.link] cmd/link: allow either of duplicated symbols being dupok

If two symbols have the same name, the old code allows either one
being dupok (preferably both, but either is ok). Currently, the
new code only works when the new symbol being dupok (or both).
Allow only old symbol being dupok as well.

One example for this is the tls_g variable on ARM64 and PPC64
when the race detector is enabled.

Should fix Linux/ARM64 build.

Change-Id: I8dd21c017e826847f13471c30dfd71bf225d8076
Reviewed-on: https://go-review.googlesource.com/c/go/+/201642
Run-TryBot: Cherry Zhang <cherryyz@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: default avatarThan McIntosh <thanm@google.com>
parent c3459eaa
......@@ -152,14 +152,17 @@ func (l *Loader) AddSym(name string, ver int, i Sym, r *oReader, dupok bool, typ
if dupok {
return false
}
oldr, li := l.toLocal(oldi)
oldsym := goobj2.Sym{}
oldsym.Read(oldr.Reader, oldr.SymOff(li))
if oldsym.Dupok() {
return false
}
overwrite := r.DataSize(int(i-l.startIndex(r))) != 0
if overwrite {
// new symbol overwrites old symbol.
oldr, li := l.toLocal(oldi)
oldsym := goobj2.Sym{}
oldsym.Read(oldr.Reader, oldr.SymOff(li))
oldtyp := sym.AbiSymKindToSymKind[objabi.SymKind(oldsym.Type)]
if !oldsym.Dupok() && !((oldtyp == sym.SDATA || oldtyp == sym.SNOPTRDATA || oldtyp == sym.SBSS || oldtyp == sym.SNOPTRBSS) && oldr.DataSize(li) == 0) { // only allow overwriting 0-sized data symbol
if !((oldtyp == sym.SDATA || oldtyp == sym.SNOPTRDATA || oldtyp == sym.SBSS || oldtyp == sym.SNOPTRBSS) && oldr.DataSize(li) == 0) { // only allow overwriting 0-sized data symbol
log.Fatalf("duplicated definition of symbol " + name)
}
l.overwrite[oldi] = i
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment