aboutsummaryrefslogtreecommitdiff
path: root/src/cmd/link
diff options
context:
space:
mode:
authorCherry Mui <cherryyz@google.com>2026-02-23 18:27:22 -0500
committerCherry Mui <cherryyz@google.com>2026-04-01 11:00:41 -0700
commit8d1c4631fa15023156740e3623b294bb5ed8dabf (patch)
tree64463db73571912f2ad8dcb9a659fbcc5f616d98 /src/cmd/link
parent46755cb4dea406093296ead4250ff5f7091c04a2 (diff)
downloadgo-8d1c4631fa15023156740e3623b294bb5ed8dabf.tar.xz
cmd/link: make dupok symbol handling path clearer
When the linker sees two symbols with the same name, if both are dupok, pick the one with larger size. If one is dupok, one is not, pick the one that is not dupok, as "dupok" is sort of like weak symbol in C terms. Change-Id: I0a95d1ddfdd70ffb5ecc06645fb345591039af49 Reviewed-on: https://go-review.googlesource.com/c/go/+/749943 Reviewed-by: David Chase <drchase@google.com> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Diffstat (limited to 'src/cmd/link')
-rw-r--r--src/cmd/link/internal/loader/loader.go21
1 files changed, 13 insertions, 8 deletions
diff --git a/src/cmd/link/internal/loader/loader.go b/src/cmd/link/internal/loader/loader.go
index 100ebd4dce..c9ffe7d37f 100644
--- a/src/cmd/link/internal/loader/loader.go
+++ b/src/cmd/link/internal/loader/loader.go
@@ -446,19 +446,24 @@ func (st *loadState) addSym(name string, ver int, r *oReader, li uint32, kind in
// issue #46653 and #72032.
oldsz := l.SymSize(oldi)
sz := int64(r.Sym(li).Siz())
+ oldr, oldli := l.toLocal(oldi)
+ oldsym := oldr.Sym(oldli)
if osym.Dupok() {
- if l.flags&FlagStrictDups != 0 {
- l.checkdup(name, r, li, oldi)
- }
- if oldsz < sz {
- // new symbol overwrites old symbol.
- l.objSyms[oldi] = objSym{r.objidx, li}
+ if oldsym.Dupok() {
+ if l.flags&FlagStrictDups != 0 {
+ l.checkdup(name, r, li, oldi)
+ }
+ if oldsz < sz {
+ // new symbol overwrites old symbol.
+ l.objSyms[oldi] = objSym{r.objidx, li}
+ }
}
return oldi
}
- oldr, oldli := l.toLocal(oldi)
- oldsym := oldr.Sym(oldli)
if oldsym.Dupok() {
+ // oldsym is Dupok, new is not.
+ // new symbol overwrites old symbol.
+ l.objSyms[oldi] = objSym{r.objidx, li}
return oldi
}
// If one is a DATA symbol (i.e. has content, DataSize != 0,