Skip to content

SharedVector ABI Mismatch on ARM Cortex-M7 Breaks All Layouts #10097

@task-jp

Description

@task-jp

Bug Description

Summary

SharedVector is ABI-incompatible between Rust and C++ on ARM Cortex-M7 (32-bit).
Rust’s portable_atomic::AtomicIsize requires stricter alignment than C++’s std::atomic<std::intptr_t>, causing SharedVectorHeader to have different sizes on the two sides.

This results in a 4-byte mismatch in the computed data pointer (inner + 1), corrupting all vectors used by the layout engine.
UI layout becomes completely invalid on ARM32 devices.


Affected Platforms

  • ARM Cortex-M7 (ARMv7-M 32-bit)
  • Likely all ARM32 targets using portable-atomic fallback

Unaffected: x86-64, ARM64 (alignment happens to match)


Symptoms

On ARM32, UI layout behaves incorrectly:

  • Item positions shifted / wrong ordering
  • Incorrect sizes emitted by layout solver
  • Overlapping / disappearing widgets
  • All SharedVector-backed arrays contain corrupted data when read from C++

Rust-side logging shows correct values, but C++ reads wrong addresses.


Root Cause

1. Different atomic ABI between Rust and C++

Rust uses:

portable_atomic::AtomicIsize

On ARM32, this uses an 8-byte alignment fallback, even though the stored value is 32-bit.

C++ uses:

std::atomic<std::intptr_t>

which is 4-byte aligned on ARM32.

2. SharedVectorHeader size differs across languages

Field Rust (AtomicIsize) C++ (std::atomic<std::intptr_t>)
Alignment 8 bytes 4 bytes
Size 4 bytes + padding 4 bytes

Therefore:

  • Rust: sizeof(SharedVectorHeader) == 16
  • C++: sizeof(SharedVectorHeader) == 12

3. C++ computes data pointer as header + 1

auto data = reinterpret_cast<T*>(header + 1);

C++ believes data begins 12 bytes after the header,
while Rust places it 16 bytes after the header.

4. A consistent 4-byte underflow occurs

Rust memory:  [ header (16 bytes) ] [ data... ]
C++ reads:                  ^ starts here (−4 bytes)

Every vector read by C++ is shifted by 4 bytes, corrupting:

  • child lists
  • layout geometric properties
  • repeated item vectors
  • animation keyframes
  • any SharedVector<T>

Reproducible Code (if applicable)

export component MainWindow inherits Window {
    width: 800px;
    height: 600px;

    HorizontalLayout {
        Rectangle {
            width: 300px;
            height: 200px;
            background: red;
        }
        Rectangle {
            width: 200px;
            height: 300px;
            background: blue;
        }
    }
}

Environment Details

  • Slint Version: pre v1.15
  • Platform/OS: NXP MIMXRT1170-EVK/Zephyr
  • Programming Language:C++
  • Backend/Renderer:

Product Impact

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    a:language-c++C++ API, codegen, CMake build system (mS,mO)need triagingIssue that the owner of the area still need to triage

    Type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions