sonic-rs does not compile for 32-bit x86: `MetaNode` is 12 bytes because `u64` is 4-byte aligned
Maintainers usually reply within 1 day
Assessment
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Newbie friendliness
- 72/100
- Issue type
- Bug
- Clarity
- Clearly specified
- Activity status
- Active
- Tech stack
- rust
- Domain
- build-system
Research direction
Start in src/value/node.rs at the MetaNode size assertion and the transmute sites, then inspect visit_container_end and forward_find_shared for their pointer-alignment assumptions. Reproduce with cargo check --target i586-unknown-linux-gnu, and run the test suite on 32-bit x86; done means the target builds and tests do not hit misaligned pointer dereferences.
Written by the indexing model from the issue text.
Description
Describe the bug
sonic-rs does not compile for 32-bit x86 targets. The size assertion next to MetaNode in src/value/node.rs fails:
error[E0080]: evaluation panicked: MetaNode and Value must have the same size for transmute safety
--> src/value/node.rs:1542:15
error[E0512]: cannot transmute between types of different sizes, or dependently-sized types
--> src/value/node.rs:1642:13
= note: source type: `MetaNode` (96 bits)
= note: target type: `Value` (128 bits)
#[repr(C)]
struct MetaNode {
shared: *const Shared,
canary: u64,
}
On the i386 System V ABI u64 has 4-byte alignment, so MetaNode is 4 + 8 = 12 bytes while Value is 16. On other 32-bit targets (wasm32, armv7) u64 is 8-byte aligned, MetaNode is padded to 16 bytes and the assertion holds, so only x86 is affected.
To Reproduce
rustup target add i586-unknown-linux-gnu
RUSTFLAGS=-g cargo check --target i586-unknown-linux-gnu
RUSTFLAGS overrides the repository's .cargo/config.toml (target-cpu=native), which would otherwise enable SSE2/AVX2 and stop the build earlier in sonic-simd (#228). Downstream crates do not get that config, so for them i586 reaches this error directly, and i686 reaches it once #228 is fixed.
Expected behavior
sonic-rs builds for 32-bit x86, as it does for wasm32.
sonic-rs version:
0.5.10 and main at 7eca25c.
Environment:
Rust 1.99.0, i586-unknown-linux-gnu (checked in a rust:1-bookworm container).
Additional context
Raising the alignment (#[repr(C, align(8))]) makes it compile but is not a fix: a MetaNode is also written and read through pointers into Value arrays (&mut *(hdr as *mut MetaNode) in visit_container_end, and forward_find_shared), and those are only 4-byte aligned on i386. With align(8) the test suite aborts with:
panicked at src/value/node.rs:1600:24:
misaligned pointer dereference: address must be a multiple of 0x8 but is 0xf6601a84
Padding the struct explicitly on 32-bit targets keeps the alignment and gives 16 bytes; I can send a PR.
- Dominant language
- Rust
- Stars
- 951
- Forks
- 81
- Avg merge
- 3d 19h
- Merged PRs (30d)
- 8
Getting set up
- No Dockerfile or Docker Compose file
- No pull request template
- Read the contributing guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from cloudwego/sonic-rs
-
Difficulty 1/5 Under an hour Newbie friendliness 82/100
cloudwego/sonic-rs#246 · 1 reaction ·
Maintainers usually reply within 1 day
-
sonic-simd fails to build on 32-bit x86 (i686): `arch::x86_64` imported under a `target_feature = "sse2"` gatePossibly taken @alex09x claimed this 120 days ago. Open
Difficulty 2/5 1-3 hours Newbie friendliness 82/100
cloudwego/sonic-rs#228 · 1 comment · 2 reactions ·
Maintainers usually reply within 1 day
-
Serialize to io::Write without staging every string in a 6x bufferPossibly taken @MattJackson claimed this 1 day ago. Open
Difficulty 4/5 3-5 days Newbie friendliness 35/100
Maintainers usually reply within 1 day
-
Difficulty 4/5 3-5 days Newbie friendliness 15/100
Maintainers usually reply within 1 day
-
Difficulty 2/5 Half a day Newbie friendliness 45/100
cloudwego/sonic-rs#266 · 1 reaction ·
Maintainers usually reply within 1 day
All issues in cloudwego/sonic-rs
Similar issues
-
Difficulty 2/5 1-3 hours Newbie friendliness 84/100
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
jelmer/buildlog-consultant#364 ·
-
Difficulty 2/5 1-3 hours Newbie friendliness 82/100
solutionscay/skiff#310 · 1 comment ·
Maintainers usually reply within 1 day
-
Difficulty 1/5 Under an hour Newbie friendliness 75/100
valkey-io/valkey-large-object#222 ·
Maintainers usually reply within 1 day
-
bug user-priority/P1
Difficulty 2/5 1-3 hours Newbie friendliness 68/100
Maintainers usually reply within 1 day