aboutsummaryrefslogtreecommitdiff
path: root/src/cmd/internal
diff options
context:
space:
mode:
authorCherry Mui <cherryyz@google.com>2021-10-01 12:21:36 -0400
committerCherry Mui <cherryyz@google.com>2021-10-04 22:46:23 +0000
commit17674e2f174280c38ea7ae8297571c09b6eb076b (patch)
tree6a9ca87bfe8d5da20eaad3b7357e7cfbdb060543 /src/cmd/internal
parentc2483a5c034152fcdfbb2e6dbcf48b0103d8db6a (diff)
downloadgo-17674e2f174280c38ea7ae8297571c09b6eb076b.tar.gz
go-17674e2f174280c38ea7ae8297571c09b6eb076b.zip
cmd/internal/obj, cmd/link: move symbol alignment logic to object file writer
Change-Id: I827a9702dfa01b712b88331668434f8db94df249 Reviewed-on: https://go-review.googlesource.com/c/go/+/353569 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>
Diffstat (limited to 'src/cmd/internal')
-rw-r--r--src/cmd/internal/obj/objfile.go26
1 files changed, 20 insertions, 6 deletions
diff --git a/src/cmd/internal/obj/objfile.go b/src/cmd/internal/obj/objfile.go
index 4fd2119b96..b6b922e02b 100644
--- a/src/cmd/internal/obj/objfile.go
+++ b/src/cmd/internal/obj/objfile.go
@@ -332,14 +332,27 @@ func (w *writer) Sym(s *LSym) {
if fn := s.Func(); fn != nil {
align = uint32(fn.Align)
}
- if s.ContentAddressable() {
- // We generally assume data symbols are natually aligned,
- // except for strings. If we dedup a string symbol and a
- // non-string symbol with the same content, we should keep
+ if s.ContentAddressable() && s.Size != 0 {
+ // We generally assume data symbols are natually aligned
+ // (e.g. integer constants), except for strings and a few
+ // compiler-emitted funcdata. If we dedup a string symbol and
+ // a non-string symbol with the same content, we should keep
// the largest alignment.
// TODO: maybe the compiler could set the alignment for all
// data symbols more carefully.
- if s.Size != 0 && !strings.HasPrefix(s.Name, "go.string.") {
+ switch {
+ case strings.HasPrefix(s.Name, "go.string."),
+ strings.HasPrefix(name, "type..namedata."),
+ strings.HasPrefix(name, "type..importpath."),
+ strings.HasSuffix(name, ".opendefer"),
+ strings.HasSuffix(name, ".arginfo0"),
+ strings.HasSuffix(name, ".arginfo1"):
+ // These are just bytes, or varints.
+ align = 1
+ case strings.HasPrefix(name, "gclocals·"):
+ // It has 32-bit fields.
+ align = 4
+ default:
switch {
case w.ctxt.Arch.PtrSize == 8 && s.Size%8 == 0:
align = 8
@@ -347,8 +360,9 @@ func (w *writer) Sym(s *LSym) {
align = 4
case s.Size%2 == 0:
align = 2
+ default:
+ align = 1
}
- // don't bother setting align to 1.
}
}
if s.Size > cutoff {