Re: [bp:tip-x86-alternatives 1/1] error[E0588]: packed type cannot transitively contain a `#[repr(align)]` type

From: Borislav Petkov
Date: Tue Dec 27 2022 - 16:15:23 EST


On Tue, Dec 27, 2022 at 12:31:17PM -0800, Alexander Altman wrote:
> That caused Rust’s bindgen (bindings generator) to generate a type for the
> altered field that indirectly included a representation of the
> bitfields...which have a greater-than-natural alignment because of their
> encoding (they’re represented as an array of 4 8-bit unsigned integers, but
> aligned as if they’re a single 16-bit unsigned integer). This interacts
> badly with the top-level command to make the alt_instr struct packed, which
> bindgen faithfully translates from C __packed to Rust #[repr(packed)].

This sounds like a rust problem to me. Because, AFAICT, this is
perfectly valid C and both compilers haven't complained even with all
the possible warnings turned on.

> One way to resolve this temporarily would be to add the following line above
> the offending struct:
> /// <div rustbindgen hide></div>

Nah, I don't think I'll accept a fix for the shortcomings of yet another tool.

> This will cause bindgen to ignore the struct entirely and not translate it. If it’s
> actually needed for Rust code, now or later, then we can’t do that and need
> to actually replace it with something translatable, or else leave it hidden and
> manually create its translation on the Rust side. For the latter, just using a
> u32 for the entire bitfield-containing union would be sufficient.

Yap, that sounds like the right thing to do.

Thx.

--
Regards/Gruss,
Boris.

https://people.kernel.org/tglx/notes-about-netiquette