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

Make i128 aligned to 16 bytes on all 64bit plats #38871

Closed
wants to merge 2 commits into from

Conversation

nagisa
Copy link
Member

@nagisa nagisa commented Jan 6, 2017

Fixes #38762

This is based on #38870.

The alignment expected by the sysv ABI for i128 (16 bytes) does not match the alignment expected by
rustc (8 bytes). Anything containing `i128`, then, when passed across the ABI boundary may result
in stack/memory being trashed by the callee.
Not sure if its minimal required alignment on non-x86_64 targets but extra alignment cannot
influence correctness, so its fine.
@nagisa
Copy link
Member Author

nagisa commented Jan 6, 2017

r? @eddyb

@rust-highfive rust-highfive assigned eddyb and unassigned nrc Jan 6, 2017
@rust-highfive
Copy link
Collaborator

r? @nrc

(rust_highfive has picked a reviewer for you, use r? to override)

@eddyb
Copy link
Member

eddyb commented Jan 6, 2017

Why all architectures? I only heard something about x64 SysV. Do you have links to more information?

@@ -343,6 +343,7 @@ pub fn compute_abi_info(ccx: &CrateContext, fty: &mut FnType) {
arg.make_indirect(ccx);
if let Some(attr) = ind_attr {
arg.attrs.set(attr);
arg.attrs.set_align(ty_align(arg.ty, 0) as u64);
Copy link
Member

Choose a reason for hiding this comment

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

Isn't this a noop? (same for all the other cabi_* changes)

Copy link
Member Author

Choose a reason for hiding this comment

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

See #38870 for this.

@nagisa
Copy link
Member Author

nagisa commented Jan 6, 2017

Why all architectures? I only heard something about x64 SysV. Do you have links to more information?

Only 64 bit ones¹. Because I have no idea what expected alignment on those arches are for i128. Having larger alignment is not incorrect, only potentially wasteful, whereas alignment being 8 instead of expected 16 might end up in similar hard-to-debug issues again.

I’d rather have all 64 bit arches have i128 aligned to 16 bytes and reduce the alignment later on, rather than go around looking for some weird “codegen bug” where something somewhere gets overwritten on stack on some very obscure platform that nobody really has access to.

¹: 32 bit arches do not matter because C compilers do not support int128 on 32 bit machines.

@eddyb
Copy link
Member

eddyb commented Jan 6, 2017

Having larger alignment is not incorrect, only potentially wasteful

... except when using it inside a struct where you have alignment padding.

If you found clang code giving custom alignments to i128, please link to it, that'd be a better starting point.

@nagisa
Copy link
Member Author

nagisa commented Jan 6, 2017

If you found clang code giving custom alignments to i128

That’s https://github.com/llvm-mirror/clang/blob/ec16cb9b5a481d62a73ad47fa59034ced4d62022/lib/AST/ASTContext.cpp#L416, also linked in the referenced issue.

@eddyb
Copy link
Member

eddyb commented Jan 6, 2017

also linked in the referenced issue

Oops, had not read that in detail.

@eddyb
Copy link
Member

eddyb commented Jan 6, 2017

clang has // int128_t is 128-bit aligned on all targets. which agrees, should be in description.
Although I'm wondering if at this point patching LLVM is not a better solution, seems like their bug.

@bors
Copy link
Contributor

bors commented Jan 17, 2017

☔ The latest upstream changes (presumably #39095) made this pull request unmergeable. Please resolve the merge conflicts.

@nagisa
Copy link
Member Author

nagisa commented Jan 19, 2017

Better solved in LLVM.

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.

5 participants