[foreign-jextract] RFR: 8261578: jextract crashes with Crossing storage unit boundaries

Athijegannathan Sundararajan sundar at openjdk.java.net
Mon Feb 15 12:37:45 UTC 2021

On Mon, 15 Feb 2021 12:19:30 GMT, Maurizio Cimadamore <mcimadamore at openjdk.org> wrote:

> This patch overhauls the logic for bitfield detection, after discovering a number of related failures. The current logic attempts to find a unique container size for a bunch of adjacent bitfields (either 8, 16, 32 or 64 bits) and then allocates the bitfields into subsequent containers of same size.
> The fact that the container size is decided once and for all at the beginning of parsing of the bitfield sequence is problematic, and breaks down in cases where containers are used only partially, or where padding is inserted.
> To overcome these issues, I've now switched to a more flexible algorithm which, instead of fixing a container size before hands, just emits a new container whenever the cumulative offset of adjacent bitfield has reached a word boundary (either 8, 16, 32, 64 bits).
> This makes the algorithm less strict, and less prone to crashes. However, since we're still reverse engineering bitfield information (as libclang doesn't give us that information), the solution will probably require more tweaks, especially in order to support packed structures, in which compilers emit bitfields which happily span across a word boundary.
> For this reason, I did not included some of the examples listed in JDK-8261578 which make use of the `packed` attribute/pragma - that is unsupported anyway, see JDK-8259832. We should come back to these examples when support for pragma is added (for now I've added a link from the pragma JBS issue to this one, so that we'll not forget).
> As for testing, I followed what other tests in this area did in the past - but I believe at some point we probably need to write better tests which use the jextract API to query bitfield offsets and sizes, because the tests, as currently written, do not assert much, other than that jextract is not failing badly.

Marked as reviewed by sundar (Committer).


PR: https://git.openjdk.java.net/panama-foreign/pull/451

More information about the panama-dev mailing list