1
0
mirror of https://github.com/golang/go synced 2024-11-23 09:40:04 -07:00

cmd/link: set alignment for string symbols in symtab pass

Set alignment for string symbols in symtab pass, so we don't need
to look at symbol name in symalign in dodata pass. (Ideally we
should not use symbol name like this in symtab pass either, but
we already use the names there anyway.)

Change-Id: I9fd61e0dd0824c50e3d0d7c07f75b967c8654796
Reviewed-on: https://go-review.googlesource.com/c/go/+/353470
Trust: Cherry Mui <cherryyz@google.com>
Run-TryBot: Cherry Mui <cherryyz@google.com>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Than McIntosh <thanm@google.com>
This commit is contained in:
Cherry Mui 2021-09-30 17:42:15 -04:00
parent 96d3ba868a
commit 8d494b0818
2 changed files with 6 additions and 7 deletions

View File

@ -1165,13 +1165,6 @@ func symalign(ldr *loader.Loader, s loader.Sym) int32 {
} else if align != 0 {
return min
}
// FIXME: figure out a way to avoid checking by name here.
sname := ldr.SymName(s)
if strings.HasPrefix(sname, "go.string.") || strings.HasPrefix(sname, "type..namedata.") {
// String data is just bytes.
// If we align it, we waste a lot of space to padding.
return min
}
align = int32(thearch.Maxalign)
ssz := ldr.SymSize(s)
for int64(align) > ssz && align > min {

View File

@ -549,6 +549,9 @@ func (ctxt *Link) symtab(pcln *pclntab) []sym.SymKind {
symGroupType[s] = sym.SGOSTRING
ldr.SetAttrNotInSymbolTable(s, true)
ldr.SetCarrierSym(s, symgostring)
if ldr.SymAlign(s) == 0 {
ldr.SetSymAlign(s, 1) // String data is just bytes, no padding.
}
case strings.HasPrefix(name, "runtime.gcbits."):
symGroupType[s] = sym.SGCBITS
@ -608,6 +611,9 @@ func (ctxt *Link) symtab(pcln *pclntab) []sym.SymKind {
ldr.SetCarrierSym(s, symtype)
}
}
if strings.HasPrefix(name, "type..namedata.") && ldr.SymAlign(s) == 0 {
ldr.SetSymAlign(s, 1) // String data is just bytes, no padding.
}
}
}