Commit 90cb1fda authored by Michael Munday's avatar Michael Munday Committed by Minux Ma

cmd/link: add Minalign field to ld.Arch

The new Minalign field sets the minimum alignment for all symbols.
This is required for the upcoming s390x port which requires symbols
be 2-byte aligned for efficient relative addressing.

All preexisting architectures have Minalign set to 1 which means
that this commit should have no effect.

I tested values of 2, 4 and 8 on linux amd64 and the tests appear to
pass. Increasing Minalign to 16 appears to break the runtime. I
think this is due to assumptions made about the layout of module
data.

toolstash -cmp on linux amd64 shows no changes due to this commit.

Resolves #14604

Change-Id: I0fe042d52c4e4732eba5fabcd0c31102a2408764
Reviewed-on: https://go-review.googlesource.com/20149Reviewed-by: default avatarMinux Ma <minux@golang.org>
Run-TryBot: Minux Ma <minux@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
parent b0f4ee53
......@@ -33,6 +33,7 @@ package amd64
const (
thechar = '6'
MaxAlign = 32 // max data alignment
MinAlign = 1 // min data alignment
FuncAlign = 16
)
......
......@@ -57,6 +57,7 @@ func linkarchinit() {
ld.Thearch.Regsize = ld.Thelinkarch.Regsize
ld.Thearch.Funcalign = FuncAlign
ld.Thearch.Maxalign = MaxAlign
ld.Thearch.Minalign = MinAlign
ld.Thearch.Minlc = MINLC
ld.Thearch.Dwarfregsp = DWARFREGSP
ld.Thearch.Dwarfreglr = DWARFREGLR
......
......@@ -65,6 +65,7 @@ package arm
const (
thechar = '5'
MaxAlign = 8 // max data alignment
MinAlign = 1 // min data alignment
FuncAlign = 4 // single-instruction alignment
MINLC = 4
)
......
......@@ -54,6 +54,7 @@ func linkarchinit() {
ld.Thearch.Regsize = ld.Thelinkarch.Regsize
ld.Thearch.Funcalign = FuncAlign
ld.Thearch.Maxalign = MaxAlign
ld.Thearch.Minalign = MinAlign
ld.Thearch.Minlc = MINLC
ld.Thearch.Dwarfregsp = DWARFREGSP
ld.Thearch.Dwarfreglr = DWARFREGLR
......
......@@ -64,6 +64,7 @@ package arm64
const (
thechar = '7'
MaxAlign = 32 // max data alignment
MinAlign = 1 // min data alignment
FuncAlign = 8
MINLC = 4
)
......
......@@ -54,6 +54,7 @@ func linkarchinit() {
ld.Thearch.Regsize = ld.Thelinkarch.Regsize
ld.Thearch.Funcalign = FuncAlign
ld.Thearch.Maxalign = MaxAlign
ld.Thearch.Minalign = MinAlign
ld.Thearch.Minlc = MINLC
ld.Thearch.Dwarfregsp = DWARFREGSP
ld.Thearch.Dwarfreglr = DWARFREGLR
......
......@@ -1026,18 +1026,18 @@ func dosymtype() {
}
}
// symalign returns the required alignment for the given symbol s.
func symalign(s *LSym) int32 {
if s.Align != 0 {
min := int32(Thearch.Minalign)
if s.Align >= min {
return s.Align
} else if s.Align != 0 {
return min
}
align := int32(Thearch.Maxalign)
for int64(align) > s.Size && align > 1 {
for int64(align) > s.Size && align > min {
align >>= 1
}
if align < s.Align {
align = s.Align
}
return align
}
......
......@@ -88,6 +88,7 @@ type Arch struct {
Regsize int
Funcalign int
Maxalign int
Minalign int
Minlc int
Dwarfregsp int
Dwarfreglr int
......
......@@ -64,6 +64,7 @@ package mips64
const (
thechar = '0'
MaxAlign = 32 // max data alignment
MinAlign = 1 // min data alignment
FuncAlign = 8
MINLC = 4
)
......
......@@ -58,6 +58,7 @@ func linkarchinit() {
ld.Thearch.Regsize = ld.Thelinkarch.Regsize
ld.Thearch.Funcalign = FuncAlign
ld.Thearch.Maxalign = MaxAlign
ld.Thearch.Minalign = MinAlign
ld.Thearch.Minlc = MINLC
ld.Thearch.Dwarfregsp = DWARFREGSP
ld.Thearch.Dwarfreglr = DWARFREGLR
......
......@@ -64,6 +64,7 @@ package ppc64
const (
thechar = '9'
MaxAlign = 32 // max data alignment
MinAlign = 1 // min data alignment
FuncAlign = 8
MINLC = 4
)
......
......@@ -58,6 +58,7 @@ func linkarchinit() {
ld.Thearch.Regsize = ld.Thelinkarch.Regsize
ld.Thearch.Funcalign = FuncAlign
ld.Thearch.Maxalign = MaxAlign
ld.Thearch.Minalign = MinAlign
ld.Thearch.Minlc = MINLC
ld.Thearch.Dwarfregsp = DWARFREGSP
ld.Thearch.Dwarfreglr = DWARFREGLR
......
......@@ -34,6 +34,7 @@ const (
thechar = '8'
PtrSize = 4
MaxAlign = 32 // max data alignment
MinAlign = 1 // min data alignment
FuncAlign = 16
MINLC = 1
)
......
......@@ -54,6 +54,7 @@ func linkarchinit() {
ld.Thearch.Regsize = ld.Thelinkarch.Regsize
ld.Thearch.Funcalign = FuncAlign
ld.Thearch.Maxalign = MaxAlign
ld.Thearch.Minalign = MinAlign
ld.Thearch.Minlc = MINLC
ld.Thearch.Dwarfregsp = DWARFREGSP
ld.Thearch.Dwarfreglr = DWARFREGLR
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment