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

u128 alignment is incorrect on x86_64 #54949

Closed
strega-nil opened this issue Oct 10, 2018 · 2 comments
Closed

u128 alignment is incorrect on x86_64 #54949

strega-nil opened this issue Oct 10, 2018 · 2 comments

Comments

@strega-nil
Copy link
Contributor

strega-nil commented Oct 10, 2018

In C and C++, on x86_64 Linux, alignof(__int128) is equal to 16. However, in Rust, align_of::<u128>() is equal to 8.

C++: https://gcc.godbolt.org/z/YAq1XC
Rust: https://gcc.godbolt.org/z/QvZeqK

This will cause subtle UB if you ever try to use i128s across FFI boundaries; for example:

C++: https://gcc.godbolt.org/z/PrtHlp
Rust: https://gcc.godbolt.org/z/_SdVqD

@strega-nil strega-nil changed the title u128 ABI is incorrect u128 alignment is incorrect on x86_64 Oct 10, 2018
@leonardo-m
Copy link

See also: #54341

@nagisa
Copy link
Member

nagisa commented Oct 10, 2018

Duplicate of #54341, yes.

@nagisa nagisa closed this as completed Oct 10, 2018
bocharov added a commit to bocharov/entropy-map that referenced this issue Oct 18, 2024
The `aarch64` and `x86_64` architectures have alignment differences for `u128` type:
* `aarch64` has 16 bytes alignment
* `x86_64` has 8 bytes aligment

In order to fix the issue we're going to use `[u8; 16]` instead of `u128`, which will always have alignment of 8 bytes and have backwards compatibility with existing `x86_64` serialized data.

See the following issues for more details:
* rust-lang/rust#54949
* rkyv/rkyv#409
* rust-lang/rust#54341
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

No branches or pull requests

3 participants