repr(C) AIX Struct Alignment

On PowerPC AIX, there are special layout alignment rules for structs not represented by the repr(C) attribute in Rust. Specifically, the layout of the following struct is misaligned:

#[repr(C)]
#[derive(Copy, Clone)]
pub struct Floats {
    a: f64,
    b: u8, // currently has 7 bytes of padding
    c: f64,
}

While the same struct generated by Clang and GCC

struct Floats {
    double a;
    char b;
    double c;
};

has the following layout

Layout: <ASTRecordLayout
  Size:192
  DataSize:192
  Alignment:32
  PreferredAlignment:64
  FieldOffsets: [0, 64, 96]>
Layout: <CGRecordLayout
  LLVMType:%struct.Floats = type <{ double, i8, [3 x i8], double, [4 x i8] }>
  IsZeroInitializable:1
  BitFields:[
]>

There are already existing infrastructure in rustc_target to customize the target ABI calling convention for extern "C". I'm wondering what would be the best course of action to implement this special layout rule for repr(C)?

This might be a topic better suited for IRLO. (Put a link here if you cross-post.)

3 Likes

Cross Posted on the Internal Forum. repr(C) AIX Struct Alignment - compiler - Rust Internals

3 Likes

This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.