sonic-rs does not compile for 32-bit x86: `MetaNode` is 12 bytes because `u64` is 4-byte aligned

Open
#258 0 comments 1 reaction 0 assignees View on GitHub

Maintainers usually reply within 1 day

@JamBalaya56562 is already working on this.

Since Oct 3, 2026.

  • #259 by @JamBalaya56562 — open

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

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from cloudwego/sonic-rs

All issues in cloudwego/sonic-rs

Similar issues

More Rust issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.