Skip to content

fix: add align(8) to rcl_context_s and rmw_context_s for ARM32#614

Open
roadmore wants to merge 1 commit intoros2-rust:mainfrom
roadmore:main
Open

fix: add align(8) to rcl_context_s and rmw_context_s for ARM32#614
roadmore wants to merge 1 commit intoros2-rust:mainfrom
roadmore:main

Conversation

@roadmore
Copy link
Copy Markdown

Summary

  • Add #[repr(C, align(8))] to rcl_context_s and rmw_context_s in the Humble bindings to fix SIGBUS (BUS_ADRALN) on ARM32 Linux.

Problem

On ARM32 Linux (kernel 4.19), rcl_context_s.instance_id_storage is declared as [u8; 8] (alignment = 1), which gives the struct an alignment of 4 (from pointer fields). In C, this field is atomic_uint_least64_t (alignment = 8), so the C struct naturally gets 8-byte alignment.

When librcl.so accesses the instance_id_storage field using a Thumb-2 LDRD instruction from a 4-byte-aligned (but not 8-byte-aligned) address, the kernel's alignment fixup handler cannot handle Thumb-2 LDRD, resulting in SIGBUS.

Fix

Add explicit align(8) to match the C struct's alignment. This is a no-op on 64-bit platforms (pointer alignment is already 8), and only affects 32-bit platforms where it corrects the struct alignment from 4 to 8.

Test plan

  • Verified on ARM32 device (ARMv7, Linux 4.19.87-rt35) — SIGBUS resolved
  • Verified 64-bit builds unaffected (no layout change)
  • Docker e2e tests pass (x86_64)

🤖 Generated with Claude Code

On ARM32 Linux (kernel 4.19), rcl_context_s.instance_id_storage is
declared as [u8; 8] which gives the struct alignment of 4 instead of 8.
When librcl.so accesses this field with a Thumb-2 LDRD instruction from
a 4-byte-aligned address, it triggers BUS_ADRALN (SIGBUS) because the
kernel alignment fixup handler cannot handle Thumb-2 LDRD.

In C, instance_id_storage is atomic_uint_least64_t (align=8), so the
struct naturally gets 8-byte alignment. The Rust binding must match.

Similarly, rmw_context_s has instance_id: u64 which already implies
align(8) in repr(C), but adding explicit align(8) for safety.
@roadmore roadmore closed this Mar 19, 2026
@roadmore roadmore reopened this Mar 19, 2026
@esteve
Copy link
Copy Markdown
Collaborator

esteve commented Mar 28, 2026

@roadmore these bindings are automatically generated by rust-bindgen, we don't aim to maintain them ourselves, they are just there for convenience.

Can you give us more details of the platform you're running ros2-rust on? 4.19.87 is a rather old kernel, which none of the platforms that ROS currently support ship with.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants