RFR: 7903314: Jextract doesn't honor pack pragmas

Jorn Vernee jvernee at openjdk.org
Mon Mar 13 19:13:01 UTC 2023


On Mon, 13 Mar 2023 18:08:45 GMT, Maurizio Cimadamore <mcimadamore at openjdk.org> wrote:

> This patch fixes a long standing issue where jextract ignores alignment directives (e.g. `pragma pack`). Because of this issue, jextract can sometiems generate layouts whose alignment is incorrect (e.g. jextract might attempt to add a `i32` to a struct at an offset that is not 32-bit aligned).
> 
> The fix is in `RecordLayoutComputer` - when we need to emit the layout of a given struct field, we need to additionally pass in the offset at which the field is added. Then we check that the offset conforms to the field alignment. If not, we force-align the layout to the available alignment. This should only affect instances of `ValueLayout`.
> 
> During code generation, when we lookup a value layout, we first drop both name and custom alignment (so that the lookup will find what it's looking for). Additional name and/or alignment is added back when the layout is turned back into a string.

Marked as reviewed by jvernee (Committer).

-------------

PR: https://git.openjdk.org/jextract/pull/113


More information about the jextract-dev mailing list