Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

proposal: cmd/link: align symbols to an architecture specific minimum value #14604

Closed
mundaym opened this issue Mar 2, 2016 · 7 comments

Comments

Projects
None yet
5 participants
@mundaym
Copy link
Member

commented Mar 2, 2016

In the upcoming z (s390x) port all data symbols (i.e. global variables and constants) need to be 2-byte aligned to facilitate relative addressing. To implement this I propose:

  • adding a Minalign field to complement the Maxalign field in ld.Arch
  • enforcing Minalign in the symalign function in cmd/link/internal/ld/data.go

For all preexisting architectures the value of Minalign would be 1.

Other architectures could also use this property to enable some optimizations. For example on platforms where single byte loads are more expensive than n byte loads Minalign could be set to n to ensure that all global bool variables are aligned to n bytes enabling the use of n byte loads/stores.

Note: this would only apply to global variables (or constants), not struct fields or array elements. So in the following example a, b and c would all consume, and be aligned to, 2 bytes in the data section. Currently a would only consume 1 byte and all of them would be aligned to 1 byte:

package main
var a bool
var b struct { x, y bool }
var c [2]byte
...

CL to follow shortly. Currently setting Minalign to a value > 8 breaks the code that reads firstmoduledata.

@minux

This comment has been minimized.

Copy link
Member

commented Mar 2, 2016

@randall77

This comment has been minimized.

Copy link
Contributor

commented Mar 2, 2016

Sounds good.

@mdempsky

This comment has been minimized.

Copy link
Member

commented Mar 2, 2016

Does this affect the alignment for 1-byte values allocated on the stack or in the heap? (It sounds like no, but I want to be clear.)

@mundaym

This comment has been minimized.

Copy link
Member Author

commented Mar 2, 2016

No, it won't affect heap/stack data alignment at all.

Minalign will only affect data that can be the target of a relocation. So only statically allocated global variables/constants (and functions, although functions are usually already aligned to a higher value anyway).

@mdempsky

This comment has been minimized.

Copy link
Member

commented Mar 2, 2016

SGTM

@gopherbot

This comment has been minimized.

Copy link

commented Mar 3, 2016

CL https://golang.org/cl/20149 mentions this issue.

@gopherbot gopherbot closed this in 90cb1fd Mar 3, 2016

@gopherbot

This comment has been minimized.

Copy link

commented Mar 4, 2016

CL https://golang.org/cl/20214 mentions this issue.

gopherbot pushed a commit that referenced this issue Mar 4, 2016

cmd/link: align string data to Minalign when merging strings
Minalign > 1 implies that relocations inserted by the linker cannot
target arbitrary bytes.

Related to #14604

Change-Id: Ie68d14887bc4047d9b29b0cb1149a8d14b6c62e2
Reviewed-on: https://go-review.googlesource.com/20214
Reviewed-by: David Crawshaw <crawshaw@golang.org>
Run-TryBot: David Crawshaw <crawshaw@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>

@golang golang locked and limited conversation to collaborators Mar 13, 2017

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
You can’t perform that action at this time.