Skip to content

Mark swift sections as 1 byte aligned #16906

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

Merged
merged 1 commit into from
Jun 8, 2018

Conversation

mundaym
Copy link
Contributor

@mundaym mundaym commented May 30, 2018

The C compiler on some platforms (such as s390x) assumes that the
data pointed to by symbols meets certain alignment requirements.
The swift sections do not necessarily meet these alignment
requirements so this change adds alignment attributes to them to
force the compiler to emit the instruction sequences and relocations
required to address unaligned data.

This fixes a 'R_390_PC32DBL target misaligned' warning issued by
gold on s390x.

The C compiler on some platforms (such as s390x) assumes that the
data pointed to by symbols meets certain alignment requirements.
The swift sections do not necessarily meet these alignment
requirements so this change adds alignment attributes to them to
force the compiler to emit the instruction sequences and relocations
required to address unaligned data.

This fixes a 'R_390_PC32DBL target misaligned' warning issued by
gold on s390x.
@jrose-apple
Copy link
Contributor

Hm. Do we actually have alignment constraints on these sections? Will this mess with those?

@jckarter
Copy link
Contributor

jckarter commented May 30, 2018

I think they're all at least four-byte-aligned. What alignment does s390x normally assume for global variables? It shouldn't hurt anything to assume they're less aligned here, though.

@mundaym
Copy link
Contributor Author

mundaym commented May 30, 2018

s390x normally assumes 2-byte alignment for global variables. We ran into this issue because the length of one of the sections was an odd number of bytes meaning that the end symbol wasn't 2-byte aligned. If the start of each section is guaranteed to always be 4-byte aligned then we could just add the __aligned__(1) attribute to the end symbol.

It won't hurt on x86 to assume a lower alignment on both the start and end symbols though. I don't know if it will affect the code generation on arm. I suspect arm assumes a 1-byte alignment for global char arrays, which would mean this change would have no effect.

Copy link
Member

@compnerd compnerd left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@jrose-apple it shouldn't mess with any other alignments. Because these will be coalesced into the section, the highest alignment in the section will determine the data alignment. The symbols being marked with 1-byte alignment here are actually local to the file, so the loading of the pointer is the only thing which should be impacted. I agree with @jckarter - I don't think that this will harm anything.

@jrose-apple
Copy link
Contributor

@swift-ci Please test

@compnerd
Copy link
Member

compnerd commented Jun 7, 2018

@jrose-apple - any reason to not just merge this?

@jckarter jckarter merged commit c85a881 into swiftlang:master Jun 8, 2018
@jckarter
Copy link
Contributor

jckarter commented Jun 8, 2018

No, thanks for the ping!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants