RFR: 7903314: Jextract doesn't honor pack pragmas
Maurizio Cimadamore
mcimadamore at openjdk.org
Mon Mar 13 18:14:08 UTC 2023
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.
-------------
Commit messages:
- Initial push
Changes: https://git.openjdk.org/jextract/pull/113/files
Webrev: https://webrevs.openjdk.org/?repo=jextract&pr=113&range=00
Issue: https://bugs.openjdk.org/browse/CODETOOLS-7903314
Stats: 167 lines in 10 files changed: 143 ins; 11 del; 13 mod
Patch: https://git.openjdk.org/jextract/pull/113.diff
Fetch: git fetch https://git.openjdk.org/jextract pull/113/head:pull/113
PR: https://git.openjdk.org/jextract/pull/113
More information about the jextract-dev
mailing list