-
Notifications
You must be signed in to change notification settings - Fork 13.2k
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
Several platforms still have incorrectly aligned u128
/i128
#128950
Comments
@rustbot label +A-abi +A-ffi +A-llvm +T-compiler |
For reference: https://godbolt.org/z/frcKoE6vn |
Align i128s to 16 bytes, following the example at https://reviews.llvm.org/D86310. clang already does this implicitly, but do it in backend code too for the benefit of other frontends (see e.g #102783 & rust-lang/rust#128950).
Align i128s to 16 bytes, following the example at https://reviews.llvm.org/D86310. clang already does this implicitly, but do it in backend code too for the benefit of other frontends (see e.g llvm/llvm-project#102783 & rust-lang/rust#128950).
Align i128s to 16 bytes, following the example at https://reviews.llvm.org/D86310. clang already does this implicitly, but do it in backend code too for the benefit of other frontends (see e.g llvm/llvm-project#102783 & rust-lang/rust#128950).
Fixed in LLVM 20. @rustbot label +llvm-fixed-upstream |
We still need to change the data-layout on the rustc side. |
What else is left to do for this issue? |
Windows has an issue with its |
This issue is just waiting on LLVM 20 now. Regarding the Windows issue: I'm guessing your referring to rust-lang/lang-team#255 (comment)? It's not really the same issue as this (alignment mismatch vs return ABI mismatch), so it seems better to open a separate |
Right, I forgot we are waiting on a LLVM upgrade. Regarding Windows, Wesley thinks that Clang is in the wrong here on the MSVC targets https://rust-lang.zulipchat.com/#narrow/channel/131828-t-compiler/topic/MSVC.20.60f16.60.20and.20.60f128.60.20ABI/near/480542167. |
Opened #134288 for the Windows issue. |
If that is the accepted consensus, would be nice to update the issue description. :) |
While updating the issue description, I've realised that the updates to the target specs that have already been merged into |
Rust's 128-bit integers have historically been incompatible with C [1]. However, there have been a number of changes in Rust and LLVM that mean this is no longer the case: * Incorrect alignment of `i128` on x86 [1]: adjusting Rust's alignment proposed at rust-lang/compiler-team#683, implemented at rust-lang#116672. * LLVM version of the above: resolved in LLVM, including ABI fix. Present in LLVM18 (our minimum supported version). * Incorrect alignment of `i128` on 64-bit PowerPC, SPARC, and MIPS [2]: Rust's data layouts adjusted at rust-lang#132422, rust-lang#132741, rust-lang#134115. * LLVM version of the above: done in LLVM 20 llvm/llvm-project#102783. * Incorrect return convention of `i128` on Windows: adjusted to match GCC and Clang at rust-lang#134290. At [3], the lang team considered it acceptable to remove `i128` from `improper_ctypes_definitions` if the LLVM version is known to be compatible. Time has elapsed since then and we have dropped support for LLVM versions that do not have the x86 fixes, meaning a per-llvm-version lint should no longer be necessary. The PowerPC, SPARC, and MIPS changes only came in LLVM 20 but since Rust's datalayouts have also been updated to match, we will be using the correct alignment regardless of LLVM version. Closes: rust-lang#134288 Closes: rust-lang#128950 [1]: rust-lang#54341 [2]: rust-lang#128950 [3]: rust-lang/lang-team#255 (comment)
LLVM 20 has been merged in #135763. |
Edit: This issue has been fixed in LLVM 20 and in the
rustc
target specifications (meaningrustc
-emitted allocations will now use the correct alignment, andstd::mem::align_of::<u128>()
will give the correct result). The only thing remaining is forrustc
to update to LLVM 20 in case LLVM itself uses the alignment in a way that affects the ABI.Original description
I tried this code:
I expected to see this happen: The printed alignment to match the alignment used for
__int128_t
by GCC and Clang.Instead, this happened: On 64-bit PowerPC, 64-bit SPARC and 64-bit MIPS, Rust thinks the alignment is 8 whereas GCC and Clang think the alignment is 16. The PowerPC 64-bit ABI specifications (both ELFv1 and ELFv2) agree with GCC and Clang (I'm not aware of any specification for 128-bit integers on SPARC64 or MIPS64, but GCC/Clang's behaviour seems to be the de-facto standard). This is because the LLVM data layout for the affected platforms doesn't correctly specify the alignment. This is the same as #54341 but on different architectures (cc rust-lang/lang-team#255). I initially discovered this when running abi-cafe on PowerPC64 to test #128643. I've filed an LLVM bug at llvm/llvm-project#102783.
Meta
rustc --version --verbose
:The text was updated successfully, but these errors were encountered: