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
Closed

Comments

@mundaym
Copy link
Member

mundaym 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
Copy link
Member

minux commented Mar 2, 2016 via email

@randall77
Copy link
Contributor

Sounds good.

@mdempsky
Copy link
Member

mdempsky 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
Copy link
Member Author

mundaym 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
Copy link
Member

mdempsky commented Mar 2, 2016

SGTM

@gopherbot
Copy link

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

@gopherbot
Copy link

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

gopherbot pushed a commit that referenced this issue Mar 4, 2016
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.
Projects
None yet
Development

No branches or pull requests

5 participants