AIX repr(C) struct layout does not always match C compiler
Nobody has claimed this yet.
- Dominant language
- Rust
- Stars
- 119k
- Forks
- 16.1k
- PR merge metrics
- PR metrics pending
Description
The layout rules for the f64 type on AIX are very special, and we do not always correctly implement them. https://github.com/rust-lang/rust/pull/149880 improved the situation, but to my knowledge some cases are still wrong. @workingjubilee please correct be if I am wrong.
Our current best understanding of the rather confusingly-written documentation for this is that
f64generally only has an alignment requirement of 4- However, sometimes
f64fields will be 8-aligned (and possibly this also affects fields of struct types where the struct containsf64)
In particular, we currently compute the wrong layout for this type:
#[repr(C)]
struct Struct {
a1: f64,
a2: u8,
}
The size should be 16, but it is 12.
Another one (with the comments indicating what the layout should be):
// Size: 24
#[repr(C)]
struct Floats {
a: f64, // at offset 0
b: u8, // at offset 8
c: f64, // at offset 12
}
Currently we compute the same offsets but we give the type a size of 20.
This can't be fully fixed on the Rust side without something like https://github.com/rust-lang/rfcs/pull/3845 to resolve the conflict between the platform C layout and using the standard layout algorithm that repr(C) uses everywhere else.
Contributor 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.
Research direction
Start by reviewing the AIX repr(C) layout handling and Rust PR #149880, then compare the reported Struct and Floats layouts against the platform C compiler. Confirm which f64 alignment cases remain incorrect and whether the RFC conflict blocks a Rust-side fix; done means the remaining cases are corrected or the limitation is clearly established.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- rust
- Domain
- compilers
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100