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/20149
Reviewed-by: Minux Ma <minux@golang.org>
Run-TryBot: Minux Ma <minux@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
This commit is contained in:
Michael Munday 2016-03-02 21:24:04 -05:00 committed by Minux Ma
parent b0f4ee533a
commit 90cb1fdaf2
14 changed files with 19 additions and 6 deletions

View File

@ -33,6 +33,7 @@ package amd64
const (
thechar = '6'
MaxAlign = 32 // max data alignment
MinAlign = 1 // min data alignment
FuncAlign = 16
)

View File

@ -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

View File

@ -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
)

View File

@ -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

View File

@ -64,6 +64,7 @@ package arm64
const (
thechar = '7'
MaxAlign = 32 // max data alignment
MinAlign = 1 // min data alignment
FuncAlign = 8
MINLC = 4
)

View File

@ -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

View File

@ -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
}

View File

@ -88,6 +88,7 @@ type Arch struct {
Regsize int
Funcalign int
Maxalign int
Minalign int
Minlc int
Dwarfregsp int
Dwarfreglr int

View File

@ -64,6 +64,7 @@ package mips64
const (
thechar = '0'
MaxAlign = 32 // max data alignment
MinAlign = 1 // min data alignment
FuncAlign = 8
MINLC = 4
)

View File

@ -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

View File

@ -64,6 +64,7 @@ package ppc64
const (
thechar = '9'
MaxAlign = 32 // max data alignment
MinAlign = 1 // min data alignment
FuncAlign = 8
MINLC = 4
)

View File

@ -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

View File

@ -34,6 +34,7 @@ const (
thechar = '8'
PtrSize = 4
MaxAlign = 32 // max data alignment
MinAlign = 1 // min data alignment
FuncAlign = 16
MINLC = 1
)

View File

@ -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