]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/link: set alignment for string symbols in symtab pass
authorCherry Mui <cherryyz@google.com>
Thu, 30 Sep 2021 21:42:15 +0000 (17:42 -0400)
committerCherry Mui <cherryyz@google.com>
Fri, 1 Oct 2021 14:30:33 +0000 (14:30 +0000)
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>
src/cmd/link/internal/ld/data.go
src/cmd/link/internal/ld/symtab.go

index 1d65c49381f37eaad8af836c3d038b33df02e94f..21169f66ef340f82cdd67cb5950d07d1aa8df742 100644 (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 {
index 76cca41d25775c1a017a61a82ef85280432d0407..4d099b1133f7fad92c0e8c0a66c6010ccd318f57 100644 (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.
+                       }
                }
        }