RFR: 8340205: Native linker allows MemoryLayout consisting of only PaddingLayout [v5]

Maurizio Cimadamore mcimadamore at openjdk.org
Mon Oct 7 14:20:37 UTC 2024


On Mon, 7 Oct 2024 12:54:00 GMT, Vladimir Kozelkov <duke at openjdk.org> wrote:

> > I think the new rules should explicitly ban zero-element sequence layouts.
> 
> Even in the rules with the latest edits, I don't see what exactly should prohibit such sequences.
> 
> Also, if they are banned, won't that break jextract and some user code? Additionally, I think many people might use zero-length sequences for layouts that are architecture-dependent.

Let me clarify. The javadoc rules we're talking about try to define a set of suported layout across _all linkers_. As such, the rules have to try and find some lowest common denominator between the various platforms.

While GCC does seem to support empty struct fields and empty sequence fields in structs, other compilers (e.g. MSVC) do not. As such, the set of minimally supported layouts should not allow such fields.

Here's a refined set of rules to see if a group layout is in this minimally supported set:


{@code L} is a group layout {@code G} and all the following conditions hold:
1. the alignment constraint of {@code G} is set to its <a href="MemoryLayout.html#layout-align">natural alignment</a>;</li>
2. the size of {@code G} is a multiple of its alignment constraint;
3. each member layout in {@code G.memberLayouts()} is either a padding layout or a layout supported by {@code NL}
4. {@code G} contains at least a non-padding member layout
5. each padding member layout in {@code G} is naturaly aligned
6. each non-padding member layout in {@code G} follows an optional padding member layout, whose size is the minimum size required to align E;
7. {@code G} contains an optional trailing padding member layout, whose size is the minimum size that satisfies (2)


(and, we need an additional restriction, to say that zero-element sequence layouts are not part of the minimally supported set).

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

PR Comment: https://git.openjdk.org/jdk/pull/21041#issuecomment-2397064613


More information about the core-libs-dev mailing list