aboutsummaryrefslogtreecommitdiff
path: root/src/cmd
diff options
context:
space:
mode:
authorIan Lance Taylor <iant@golang.org>2026-01-27 17:34:46 -0800
committerCherry Mui <cherryyz@google.com>2026-01-29 08:14:53 -0800
commit11722941452d04aa0364a5c6b60acffaa2776b1c (patch)
tree5832bb8f46f2d47c768c209a9947ff2dcd8aee64 /src/cmd
parent2bd7f15dd7423b6817939b199cd2c8032e3b79cc (diff)
downloadgo-11722941452d04aa0364a5c6b60acffaa2776b1c.tar.xz
runtime, cmd/link: store type descriptor length, not end
Storing the type descriptor length lets us save a relocation. It also avoids a problem for Darwin dynamic linking. For #6853 Fixes #77350 Change-Id: If5c94330fe10d75690325f3d0b0658060ef3eb2d Reviewed-on: https://go-review.googlesource.com/c/go/+/739681 Reviewed-by: Cherry Mui <cherryyz@google.com> Reviewed-by: Dmitri Shuralyov <dmitshur@google.com> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Diffstat (limited to 'src/cmd')
-rw-r--r--src/cmd/link/internal/ld/data.go30
-rw-r--r--src/cmd/link/internal/ld/link.go2
-rw-r--r--src/cmd/link/internal/ld/symtab.go4
3 files changed, 20 insertions, 16 deletions
diff --git a/src/cmd/link/internal/ld/data.go b/src/cmd/link/internal/ld/data.go
index 51163c2c8b..682ae267bf 100644
--- a/src/cmd/link/internal/ld/data.go
+++ b/src/cmd/link/internal/ld/data.go
@@ -1535,10 +1535,6 @@ func fixZeroSizedSymbols(ctxt *Link) {
types.SetSize(8)
ldr.SetAttrSpecial(types.Sym(), false)
- etypedesc := ldr.CreateSymForUpdate("runtime.etypedesc", 0)
- etypedesc.SetType(sym.STYPE)
- ldr.SetAttrSpecial(etypedesc.Sym(), false)
-
etypes := ldr.CreateSymForUpdate("runtime.etypes", 0)
etypes.SetType(sym.STYPE)
ldr.SetAttrSpecial(etypes.Sym(), false)
@@ -2218,7 +2214,6 @@ func (state *dodataState) allocateDataSections(ctxt *Link) {
sect = createRelroSect(".go.type", sym.STYPE)
ldr.SetSymSect(ldr.LookupOrCreateSym("runtime.types", 0), sect)
- ldr.SetSymSect(ldr.LookupOrCreateSym("runtime.etypedesc", 0), sect)
ldr.SetSymSect(ldr.LookupOrCreateSym("runtime.etypes", 0), sect)
sect = createRelroSect(".go.func", sym.SGOFUNC)
@@ -2437,20 +2432,30 @@ func (state *dodataState) dodataSect(ctxt *Link, symn sym.SymKind, syms []loader
})
// Find the end of the typelink descriptors.
- // The offset starts at 1 to match the increment in
+ // The size starts at 1 to match the increment in
// createRelroSect in allocateDataSections.
// TODO: This wastes some space.
- offset := int64(1)
+ typeLinkSize := int64(1)
for i := range sl {
si := sl[i].sym
+ if si == head {
+ continue
+ }
if _, isTypelink := typelinkStrings[si]; !isTypelink {
break
}
- offset = Rnd(offset, int64(symalign(ldr, si)))
- offset += sl[i].sz
+ typeLinkSize = Rnd(typeLinkSize, int64(symalign(ldr, si)))
+ typeLinkSize += sl[i].sz
}
- ldr.SetSymValue(ldr.LookupOrCreateSym("runtime.etypedesc", 0), offset)
+ // Store the length of the typelink descriptors
+ // in the typedesclen field of moduledata.
+ if ctxt.moduledataTypeDescOffset == 0 {
+ Errorf("internal error: phase error: moduledataTypeDescOffset not set in dodataSect")
+ } else {
+ su := ldr.MakeSymbolUpdater(ctxt.Moduledata)
+ su.SetUint(ctxt.Arch, ctxt.moduledataTypeDescOffset, uint64(typeLinkSize))
+ }
default:
sort.Slice(sl, sortFn)
@@ -3098,12 +3103,9 @@ func (ctxt *Link) address() []*sym.Segment {
ctxt.xdefine("runtime.rodata", sym.SRODATA, int64(rodata.Vaddr))
ctxt.xdefine("runtime.erodata", sym.SRODATA, int64(rodata.Vaddr+rodata.Length))
ctxt.xdefine("runtime.types", sym.SRODATA, int64(types.Vaddr))
- // etypedesc was set to the offset from the symbol start in dodataSect.
- s := ldr.Lookup("runtime.etypedesc", 0)
- ctxt.xdefine("runtime.etypedesc", sym.SRODATA, int64(types.Vaddr+uint64(ldr.SymValue(s))))
ctxt.xdefine("runtime.etypes", sym.SRODATA, int64(types.Vaddr+types.Length))
- s = ldr.Lookup("runtime.gcdata", 0)
+ s := ldr.Lookup("runtime.gcdata", 0)
ldr.SetAttrLocal(s, true)
ctxt.xdefine("runtime.egcdata", sym.SRODATA, ldr.SymAddr(s)+ldr.SymSize(s))
ldr.SetSymSect(ldr.LookupOrCreateSym("runtime.egcdata", 0), ldr.SymSect(s))
diff --git a/src/cmd/link/internal/ld/link.go b/src/cmd/link/internal/ld/link.go
index 2276d39d88..aa4f655cc9 100644
--- a/src/cmd/link/internal/ld/link.go
+++ b/src/cmd/link/internal/ld/link.go
@@ -96,6 +96,8 @@ type Link struct {
Textp []loader.Sym
Moduledata loader.Sym
+ moduledataTypeDescOffset int64
+
PackageFile map[string]string
PackageShlib map[string]string
diff --git a/src/cmd/link/internal/ld/symtab.go b/src/cmd/link/internal/ld/symtab.go
index d63a96d12b..142fb15785 100644
--- a/src/cmd/link/internal/ld/symtab.go
+++ b/src/cmd/link/internal/ld/symtab.go
@@ -433,7 +433,6 @@ func (ctxt *Link) symtab(pcln *pclntab) []sym.SymKind {
ctxt.xdefine("runtime.rodata", sym.SRODATA, 0)
ctxt.xdefine("runtime.erodata", sym.SRODATAEND, 0)
ctxt.xdefine("runtime.types", sym.SRODATA, 0)
- ctxt.xdefine("runtime.etypedesc", sym.SRODATA, 0)
ctxt.xdefine("runtime.etypes", sym.SRODATA, 0)
ctxt.xdefine("runtime.noptrdata", sym.SNOPTRDATA, 0)
ctxt.xdefine("runtime.enoptrdata", sym.SNOPTRDATAEND, 0)
@@ -619,7 +618,8 @@ func (ctxt *Link) symtab(pcln *pclntab) []sym.SymKind {
moduledata.AddAddr(ctxt.Arch, ldr.Lookup("runtime.gcdata", 0))
moduledata.AddAddr(ctxt.Arch, ldr.Lookup("runtime.gcbss", 0))
moduledata.AddAddr(ctxt.Arch, ldr.Lookup("runtime.types", 0))
- moduledata.AddAddr(ctxt.Arch, ldr.Lookup("runtime.etypedesc", 0))
+ ctxt.moduledataTypeDescOffset = moduledata.Size()
+ moduledata.AddUint(ctxt.Arch, 0) // filled in by dodataSect
moduledata.AddAddr(ctxt.Arch, ldr.Lookup("runtime.etypes", 0))
moduledata.AddAddr(ctxt.Arch, ldr.Lookup("runtime.rodata", 0))
moduledata.AddAddr(ctxt.Arch, ldr.Lookup("go:func.*", 0))