[go] cmd/internal/obj: add Align field to LSym

3 views
Skip to first unread message

Ian Lance Taylor (Gerrit)

unread,
Dec 4, 2025, 4:52:11 PM12/4/25
to goph...@pubsubhelper.golang.org, Ian Lance Taylor, golang-co...@googlegroups.com

Ian Lance Taylor has uploaded the change for review

Commit message

cmd/internal/obj: add Align field to LSym

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

Change diff

diff --git a/src/cmd/internal/obj/link.go b/src/cmd/internal/obj/link.go
index c70c1d9..adf5b65 100644
--- a/src/cmd/internal/obj/link.go
+++ b/src/cmd/internal/obj/link.go
@@ -456,9 +456,10 @@
// 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 FuncInfo struct {
Args int32
Locals int32
- Align int32
FuncID abi.FuncID
FuncFlag abi.FuncFlag
StartLine int32
diff --git a/src/cmd/internal/obj/loong64/asm.go b/src/cmd/internal/obj/loong64/asm.go
index f992518..2cf608f 100644
--- a/src/cmd/internal/obj/loong64/asm.go
+++ b/src/cmd/internal/obj/loong64/asm.go
@@ -549,8 +549,8 @@
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:
diff --git a/src/cmd/internal/obj/objfile.go b/src/cmd/internal/obj/objfile.go
index 4401f1b..53691cc 100644
--- a/src/cmd/internal/obj/objfile.go
+++ b/src/cmd/internal/obj/objfile.go
@@ -369,11 +369,8 @@
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 @@
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")
}
diff --git a/src/cmd/internal/obj/ppc64/asm9.go b/src/cmd/internal/obj/ppc64/asm9.go
index a39c206..06ad72e 100644
--- a/src/cmd/internal/obj/ppc64/asm9.go
+++ b/src/cmd/internal/obj/ppc64/asm9.go
@@ -595,8 +595,8 @@
// 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 @@
}

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.
diff --git a/src/cmd/internal/obj/riscv/obj.go b/src/cmd/internal/obj/riscv/obj.go
index 043be17..24e0a45 100644
--- a/src/cmd/internal/obj/riscv/obj.go
+++ b/src/cmd/internal/obj/riscv/obj.go
@@ -793,8 +793,8 @@
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)
}
}
}
diff --git a/src/cmd/internal/obj/util.go b/src/cmd/internal/obj/util.go
index 7d87bff..86ba4de 100644
--- a/src/cmd/internal/obj/util.go
+++ b/src/cmd/internal/obj/util.go
@@ -737,7 +737,7 @@
// 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)
}
}

Change information

Files:
  • M src/cmd/internal/obj/link.go
  • M src/cmd/internal/obj/loong64/asm.go
  • M src/cmd/internal/obj/objfile.go
  • M src/cmd/internal/obj/ppc64/asm9.go
  • M src/cmd/internal/obj/riscv/obj.go
  • M src/cmd/internal/obj/util.go
Change size: S
Delta: 6 files changed, 15 insertions(+), 18 deletions(-)
Open in Gerrit

Related details

Attention set is empty
Submit Requirements:
  • requirement is not satisfiedCode-Review
  • requirement satisfiedNo-Unresolved-Comments
  • requirement is not satisfiedReview-Enforcement
  • requirement is not satisfiedTryBots-Pass
Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. DiffyGerrit
Gerrit-MessageType: newchange
Gerrit-Project: go
Gerrit-Branch: master
Gerrit-Change-Id: I421e8238ab57958fea8e4eab0649ce5288e7f92f
Gerrit-Change-Number: 727020
Gerrit-PatchSet: 1
Gerrit-Owner: Ian Lance Taylor <ia...@golang.org>
unsatisfied_requirement
satisfied_requirement
open
diffy

Ian Lance Taylor (Gerrit)

unread,
Dec 4, 2025, 4:52:39 PM12/4/25
to Ian Lance Taylor, goph...@pubsubhelper.golang.org, golang-co...@googlegroups.com

Ian Lance Taylor voted Commit-Queue+1

Commit-Queue+1
Open in Gerrit

Related details

Attention set is empty
Submit Requirements:
  • requirement is not satisfiedCode-Review
  • requirement satisfiedNo-Unresolved-Comments
  • requirement is not satisfiedReview-Enforcement
  • requirement is not satisfiedTryBots-Pass
Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. DiffyGerrit
Gerrit-MessageType: comment
Gerrit-Project: go
Gerrit-Branch: master
Gerrit-Change-Id: I421e8238ab57958fea8e4eab0649ce5288e7f92f
Gerrit-Change-Number: 727020
Gerrit-PatchSet: 1
Gerrit-Owner: Ian Lance Taylor <ia...@golang.org>
Gerrit-Reviewer: Ian Lance Taylor <ia...@golang.org>
Gerrit-Comment-Date: Thu, 04 Dec 2025 21:52:35 +0000
Gerrit-HasComments: No
Gerrit-Has-Labels: Yes
unsatisfied_requirement
satisfied_requirement
open
diffy

Ian Lance Taylor (Gerrit)

unread,
Feb 6, 2026, 8:08:02 PM (6 hours ago) Feb 6
to Ian Lance Taylor, goph...@pubsubhelper.golang.org, Go LUCI, abner chenc, Meidan Li, golang-co...@googlegroups.com

Ian Lance Taylor voted Commit-Queue+1

Commit-Queue+1
Open in Gerrit

Related details

Attention set is empty
Submit Requirements:
  • requirement is not satisfiedCode-Review
  • requirement satisfiedNo-Unresolved-Comments
  • requirement is not satisfiedReview-Enforcement
  • requirement is not satisfiedTryBots-Pass
Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. DiffyGerrit
Gerrit-MessageType: comment
Gerrit-Project: go
Gerrit-Branch: master
Gerrit-Change-Id: I421e8238ab57958fea8e4eab0649ce5288e7f92f
Gerrit-Change-Number: 727020
Gerrit-PatchSet: 10
Gerrit-Owner: Ian Lance Taylor <ia...@golang.org>
Gerrit-Reviewer: Ian Lance Taylor <ia...@golang.org>
Gerrit-CC: Meidan Li <lime...@loongson.cn>
Gerrit-CC: abner chenc <chen...@loongson.cn>
Gerrit-Comment-Date: Sat, 07 Feb 2026 01:07:58 +0000
Gerrit-HasComments: No
Gerrit-Has-Labels: Yes
unsatisfied_requirement
satisfied_requirement
open
diffy
Reply all
Reply to author
Forward
0 new messages