-
Notifications
You must be signed in to change notification settings - Fork 1.3k
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
LLVM and Rust u128 alignment update breaks #[account(zero_copy)]
with u128
#3114
Comments
Thanks for creating the issue but Anchor itself doesn't have any alignment assumptions when using Solana usually keeps layouts consistent — it might be worth creating an issue in https://github.com/anza-xyz/llvm-project. |
The issue isn't that the Solana layout changed -- it's that it didn't change while everyone else's did. If you are trying to deserialize
Older Anchor programs (and new ones using While technically bytemuck is doing the heavy lifting its anchor that adds the
Anchor fixed this issue in 0.20 but a lot of existing programs cannot change their representations. There are a lot of important programs using |
I pushed a self-contained reproduction here: https://github.com/matt-allan/anchor-layout-issue In this case the issue between On
The offset is
On stable I don't get the expected value:
The offset of the field has changed:
9944 is the size of |
Long story short. The previous versions of rust and llvm treat u128 as 8 alignments incorrectly on x86_64. so does
#[Account(zero_copy)]
. A recent update fixed this issue, but breaks all existing#[account(zero_copy)]
with u128I'm surprised that nobody mentioned this issue here. So I'm just links related issues.
https://blog.rust-lang.org/2024/03/30/i128-layout-update.html
drift-labs/protocol-v2#891
rust-lang/rust#54341
A workaround would be defining a
struct u128([u64; 2])
and replace all primitive type u128, inspired by https://solana.stackexchange.com/questions/7720/using-u128-without-sacrificing-alignment-8The text was updated successfully, but these errors were encountered: