]> Cypherpunks repositories - gostls13.git/commitdiff
[dev.link] cmd/link: allow either of duplicated symbols being dupok
authorCherry Zhang <cherryyz@google.com>
Thu, 17 Oct 2019 22:42:38 +0000 (18:42 -0400)
committerCherry Zhang <cherryyz@google.com>
Sat, 19 Oct 2019 15:18:32 +0000 (15:18 +0000)
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: Than McIntosh <thanm@google.com>
src/cmd/link/internal/loader/loader.go

index 6ad37d60618eb11d3d23914a33773a0b27feb670..6f4bc982346d27d782ddfda62420e7129a593451 100644 (file)
@@ -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