]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/link: do size fixups after symbol references are loaded
authorCherry Mui <cherryyz@google.com>
Thu, 10 Jul 2025 04:46:00 +0000 (00:46 -0400)
committerCherry Mui <cherryyz@google.com>
Fri, 11 Jul 2025 14:32:16 +0000 (07:32 -0700)
When we do a size fixup, we need to clone the symbol to an
external symbol so we can modify it. This includes cloning the
relocations, which includes resolving the relocations. If the
symbol being fixed has a relocation referencing a non-Go symbol,
that symbol has not yet been created, it will be resolved to an
empty symbol. Load the references first, so the referenced symbol,
even if it is a non-Go symbol, exists.

Fixes #74537.

Change-Id: I81525bd7c3e232b80eefeb0f18e13ba5331e1510
Reviewed-on: https://go-review.googlesource.com/c/go/+/687315
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Reviewed-by: David Chase <drchase@google.com>
src/cmd/link/internal/loader/loader.go

index b1891bac43d858bd00d9c033a72d9380692deddf..a02a268880c5fd5f48c1661f2e66602473a2504e 100644 (file)
@@ -2298,10 +2298,6 @@ func (l *Loader) LoadSyms(arch *sys.Arch) {
                st.preloadSyms(r, hashedDef)
                st.preloadSyms(r, nonPkgDef)
        }
-       for _, sf := range l.sizeFixups {
-               pp := l.cloneToExternal(sf.sym)
-               pp.size = int64(sf.size)
-       }
        for _, vr := range st.linknameVarRefs {
                l.checkLinkname(vr.pkg, vr.name, vr.sym)
        }
@@ -2309,6 +2305,10 @@ func (l *Loader) LoadSyms(arch *sys.Arch) {
        for _, r := range l.objs[goObjStart:] {
                loadObjRefs(l, r, arch)
        }
+       for _, sf := range l.sizeFixups {
+               pp := l.cloneToExternal(sf.sym)
+               pp.size = int64(sf.size)
+       }
        l.values = make([]int64, l.NSym(), l.NSym()+1000) // +1000 make some room for external symbols
        l.outer = make([]Sym, l.NSym(), l.NSym()+1000)
 }