]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/internal/obj: add Align field to LSym
authorIan Lance Taylor <iant@golang.org>
Thu, 4 Dec 2025 21:45:57 +0000 (13:45 -0800)
committerGopher Robot <gobot@golang.org>
Wed, 11 Feb 2026 03:40:05 +0000 (19:40 -0800)
This will permit the compiler and assembler to specify the alignment
of symbols that they create.

Careful placement of the new field, plus rearranging an existing field,
means that LSym does not change size (as tested by TestSizeof).
The new alignment field is int16, permitting alignment up to 16384,
more than we ever need in practice. If necessary we could change the
field to uint8 and store the alignment as a power of two,
as is done in the linker.

This replaces the Align field in FuncInfo.

For #6853
For #36313

Change-Id: I421e8238ab57958fea8e4eab0649ce5288e7f92f
Reviewed-on: https://go-review.googlesource.com/c/go/+/727020
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Reviewed-by: Keith Randall <khr@golang.org>
Auto-Submit: Ian Lance Taylor <iant@golang.org>
Reviewed-by: Cherry Mui <cherryyz@google.com>
Reviewed-by: Keith Randall <khr@google.com>
src/cmd/internal/obj/link.go
src/cmd/internal/obj/loong64/asm.go
src/cmd/internal/obj/objfile.go
src/cmd/internal/obj/ppc64/asm9.go
src/cmd/internal/obj/riscv/obj.go
src/cmd/internal/obj/util.go

index 05ffba11ea1ad04a9d43510dbf1ad8fc57394f13..088a7c57aada9fb505ef8c68e1fd4520e8855a50 100644 (file)
@@ -456,9 +456,10 @@ const (
 // It represents Go symbols in a flat pkg+"."+name namespace.
 type LSym struct {
        Name string
-       Type objabi.SymKind
        Attribute
+       Type objabi.SymKind
 
+       Align  int16
        Size   int64
        Gotype *LSym
        P      []byte
@@ -475,7 +476,6 @@ type LSym struct {
 type FuncInfo struct {
        Args      int32
        Locals    int32
-       Align     int32
        FuncID    abi.FuncID
        FuncFlag  abi.FuncFlag
        StartLine int32
index f9925180153aeabcc78e2d2aac8b0523c1ed4605..2cf608fb8471d42a699979b922c092a5cd09b63a 100644 (file)
@@ -549,8 +549,8 @@ func span0(ctxt *obj.Link, cursym *obj.LSym, newprog obj.ProgAlloc) {
                                alignedValue := p.From.Offset
                                m = pcAlignPadLength(ctxt, pc, alignedValue)
                                // Update the current text symbol alignment value.
-                               if int32(alignedValue) > cursym.Func().Align {
-                                       cursym.Func().Align = int32(alignedValue)
+                               if int16(alignedValue) > cursym.Align {
+                                       cursym.Align = int16(alignedValue)
                                }
                                break
                        case obj.ANOP, obj.AFUNCDATA, obj.APCDATA:
index 4401f1bb74e0a9ed358d9754905b0d4f11804665..53691ccb6c6421c11696bc9ebe90806257c60671 100644 (file)
@@ -369,11 +369,8 @@ func (w *writer) Sym(s *LSym) {
        if strings.HasPrefix(name, "gofile..") {
                name = filepath.ToSlash(name)
        }
-       var align uint32
-       if fn := s.Func(); fn != nil {
-               align = uint32(fn.Align)
-       }
-       if s.ContentAddressable() && s.Size != 0 {
+       align := uint32(s.Align)
+       if s.ContentAddressable() && s.Size != 0 && align == 0 {
                // We generally assume data symbols are naturally aligned
                // (e.g. integer constants), except for strings and a few
                // compiler-emitted funcdata. If we dedup a string symbol and
@@ -895,10 +892,10 @@ func (ctxt *Link) writeSymDebugNamed(s *LSym, name string) {
        if s.Func() != nil && s.Func().FuncFlag&abi.FuncFlagAsm != 0 {
                fmt.Fprintf(ctxt.Bso, "asm ")
        }
-       fmt.Fprintf(ctxt.Bso, "size=%d", s.Size)
+       fmt.Fprintf(ctxt.Bso, "size=%d align=%#x", s.Size, s.Align)
        if s.Type.IsText() {
                fn := s.Func()
-               fmt.Fprintf(ctxt.Bso, " args=%#x locals=%#x funcid=%#x align=%#x", uint64(fn.Args), uint64(fn.Locals), uint64(fn.FuncID), uint64(fn.Align))
+               fmt.Fprintf(ctxt.Bso, " args=%#x locals=%#x funcid=%#x", uint64(fn.Args), uint64(fn.Locals), uint64(fn.FuncID))
                if s.Leaf() {
                        fmt.Fprintf(ctxt.Bso, " leaf")
                }
index a39c206c22da9e687b41efaeb8f186afc399f380..06ad72eed8358428ac520173be4146521b1f3041 100644 (file)
@@ -595,8 +595,8 @@ func addpad(pc, a int64, ctxt *obj.Link, cursym *obj.LSym) int {
                // requested then the function alignment must also be promoted.
                // The function alignment is not promoted on AIX at this time.
                // TODO: Investigate AIX function alignment.
-               if ctxt.Headtype != objabi.Haix && cursym.Func().Align < int32(a) {
-                       cursym.Func().Align = int32(a)
+               if ctxt.Headtype != objabi.Haix && cursym.Align < int16(a) {
+                       cursym.Align = int16(a)
                }
                if pc&(a-1) != 0 {
                        return int(a - (pc & (a - 1)))
@@ -796,7 +796,7 @@ func span9(ctxt *obj.Link, cursym *obj.LSym, newprog obj.ProgAlloc) {
        }
 
        c.cursym.Size = pc
-       c.cursym.Func().Align = falign
+       c.cursym.Align = int16(falign)
        c.cursym.Grow(c.cursym.Size)
 
        // lay out the code, emitting code and data relocations.
index 043be17c07c0f0ba048968bf3f67a606a8bb0098..24e0a454cd4f1692e8b8342b15147340a499f078 100644 (file)
@@ -793,8 +793,8 @@ func preprocess(ctxt *obj.Link, cursym *obj.LSym, newprog obj.ProgAlloc) {
                                ctxt.Diag("alignment value of an instruction must be a power of two and in the range [4, 2048], got %d\n", alignedValue)
                        }
                        // Update the current text symbol alignment value.
-                       if int32(alignedValue) > cursym.Func().Align {
-                               cursym.Func().Align = int32(alignedValue)
+                       if int16(alignedValue) > cursym.Align {
+                               cursym.Align = int16(alignedValue)
                        }
                }
        }
index 7d87bff94918b4b8500fbfc93906ccd1de68afe9..86ba4deb739e13935debac1924b2eda0da5dc9bb 100644 (file)
@@ -737,7 +737,7 @@ func AlignmentPaddingLength(pc int32, p *Prog, ctxt *Link) int {
 // the required code alignment
 func requireAlignment(a int64, ctxt *Link, cursym *LSym) {
        // TODO remove explicit knowledge about AIX.
-       if ctxt.Headtype != objabi.Haix && cursym.Func().Align < int32(a) {
-               cursym.Func().Align = int32(a)
+       if ctxt.Headtype != objabi.Haix && cursym.Align < int16(a) {
+               cursym.Align = int16(a)
        }
 }