cmd/link: put itabs in the .go.type section

For #76038

Change-Id: I4c30d5854fcaacc7fd7f84b4679a5be30379122d
Reviewed-on: https://go-review.googlesource.com/c/go/+/729200
Reviewed-by: Cherry Mui <cherryyz@google.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Auto-Submit: Ian Lance Taylor <iant@golang.org>
Reviewed-by: Mark Freeman <markfreeman@google.com>
Reviewed-by: Pagol Mon <mpagol707@gmail.com>
This commit is contained in:
Ian Lance Taylor
2025-12-10 20:46:43 -08:00
committed by Gopher Robot
parent 703cc8abec
commit bcc369284d
2 changed files with 32 additions and 29 deletions

View File

@@ -2430,6 +2430,7 @@ func (state *dodataState) dodataSect(ctxt *Link, symn sym.SymKind, syms []loader
// Sort type descriptors with the typelink flag first,
// sorted by type string. The reflect package will use
// this to ensure that type descriptor pointers are unique.
// Sort itabs after type descriptors.
// We define type:* for some links.
typeStar := ldr.Lookup("type:*", 0)
@@ -2458,23 +2459,32 @@ func (state *dodataState) dodataSect(ctxt *Link, symn sym.SymKind, syms []loader
}
}
iTypestr, iIsTypelink := typelinkStrings[si]
jTypestr, jIsTypelink := typelinkStrings[sj]
iIsType := !ldr.IsItab(si)
jIsType := !ldr.IsItab(sj)
if iIsType && jIsType {
iTypestr, iIsTypelink := typelinkStrings[si]
jTypestr, jIsTypelink := typelinkStrings[sj]
if iIsTypelink {
if jIsTypelink {
if iIsTypelink && jIsTypelink {
// typelink symbols sort by type string
return iTypestr < jTypestr
} else if iIsTypelink {
// typelink < non-typelink
return true
} else if jIsTypelink {
// non-typelink > typelink
return false
}
// typelink < non-typelink
} else if iIsType {
// type < itab
return true
} else if jIsTypelink {
// non-typelink greater than typelink
} else if jIsType {
// itab > type
return false
}
// non-typelink symbols sort by size as usual
// Otherwise, within non-typelink types and itabs,
// sort by size as usual.
return sortFn(i, j)
})

View File

@@ -459,15 +459,12 @@ func (ctxt *Link) symtab(pcln *pclntab) []sym.SymKind {
ctxt.xdefine("runtime.egcbss", sym.SRODATA, 0)
// pseudo-symbols to mark locations of type, string, and go string data.
var symtype loader.Sym
if !ctxt.DynlinkingGo() {
s = ldr.CreateSymForUpdate("type:*", 0)
s.SetType(sym.STYPE)
s.SetSize(0)
s.SetAlign(int32(ctxt.Arch.PtrSize))
symtype = s.Sym()
setCarrierSym(sym.STYPE, symtype)
}
s = ldr.CreateSymForUpdate("type:*", 0)
s.SetType(sym.STYPE)
s.SetSize(0)
s.SetAlign(int32(ctxt.Arch.PtrSize))
symtype := s.Sym()
setCarrierSym(sym.STYPE, symtype)
groupSym := func(name string, t sym.SymKind) loader.Sym {
s := ldr.CreateSymForUpdate(name, 0)
@@ -523,20 +520,16 @@ func (ctxt *Link) symtab(pcln *pclntab) []sym.SymKind {
case strings.HasPrefix(name, "type:"):
if !ctxt.DynlinkingGo() {
ldr.SetAttrNotInSymbolTable(s, true)
}
symGroupType[s] = sym.STYPE
if symtype != 0 {
ldr.SetCarrierSym(s, symtype)
}
if ctxt.HeadType == objabi.Haix {
// The default alignment is currently 0x20,
// which the AIX external linker doesn't
// seem to support. To get consistent
// alignment on AIX, force alignment to 8.
if symalign(ldr, s) > 8 {
ldr.SetSymAlign(s, 8)
}
symGroupType[s] = sym.STYPE
case ldr.IsItab(s):
if !ctxt.DynlinkingGo() {
ldr.SetAttrNotInSymbolTable(s, true)
ldr.SetCarrierSym(s, symtype)
}
symGroupType[s] = sym.STYPE
}
}