cmd/link: set alignment for carrier symbols

For carrier symbols like type.*, currently we don't set its
alignment. Normally it doesn't actually matter as we still align
the inner symbols. But in some cases it does make the symbol table
a bit weird, e.g. on darwin/arm64,

0000000000070000 s _runtime.types
0000000000070001 s _type.*

The address of the symbol _type.* is a bit weird. And the new
darwin linker from Xcode 14 beta doesn't like that (see issue
53372).

This CL aligns them.

Fixes #53372.

Change-Id: I1cb19dcf172e9a6bca248d85a7e54da76cbbc8a4
Reviewed-on: https://go-review.googlesource.com/c/go/+/411912
Reviewed-by: Than McIntosh <thanm@google.com>
Run-TryBot: Cherry Mui <cherryyz@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
This commit is contained in:
Cherry Mui 2022-06-14 16:47:57 -04:00
parent 36147dd1e8
commit c2c76c6f19

View file

@ -475,16 +475,19 @@ func (ctxt *Link) symtab(pcln *pclntab) []sym.SymKind {
s = ldr.CreateSymForUpdate("type.*", 0)
s.SetType(sym.STYPE)
s.SetSize(0)
s.SetAlign(int32(ctxt.Arch.PtrSize))
symtype = s.Sym()
s = ldr.CreateSymForUpdate("typerel.*", 0)
s.SetType(sym.STYPERELRO)
s.SetSize(0)
s.SetAlign(int32(ctxt.Arch.PtrSize))
symtyperel = s.Sym()
} else {
s = ldr.CreateSymForUpdate("type.*", 0)
s.SetType(sym.STYPE)
s.SetSize(0)
s.SetAlign(int32(ctxt.Arch.PtrSize))
symtype = s.Sym()
symtyperel = s.Sym()
}
@ -496,6 +499,7 @@ func (ctxt *Link) symtab(pcln *pclntab) []sym.SymKind {
s := ldr.CreateSymForUpdate(name, 0)
s.SetType(t)
s.SetSize(0)
s.SetAlign(int32(ctxt.Arch.PtrSize))
s.SetLocal(true)
setCarrierSym(t, s.Sym())
return s.Sym()