Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[powerpc][AIX] fix layout issues for nested struct types #805

Merged
merged 7 commits into from
Nov 23, 2023

Conversation

daltenty
Copy link
Contributor

@daltenty daltenty commented Oct 27, 2023

On AIX under the default power alignment rules, the layout of struct types which are nested inside other structs may observe different alignment requirements than when we layout of those types on their own, resulting in a different total layout.

Specifically the first member double rules which would apply an eight byte alignment if that type appears in the first position of a struct:

  1. apply recursively if a struct containing a first member double appear in the first member
    of another struct
  2. do not apply if that struct is itself a member of another struct
    and not the first member.

The current implementation of the rules in libffi doesn't handle these cases, causing a mismatch with the compiler and causing some crashes we see when OpenJ9 is used with libffi on AIX.

This PR corrects this and adds some representative test cases.

On AIX under the default power alignment rules, the layout
of struct types which are nested inside other structs may
be different than the layout of those types on their own.

Specifically the first member double rules which would
apply an eight byte alignment if that type appears in the
first position of a struct:

 1) apply recursively if the struct appear in the first member
    of another struct
 2) do not apply if that struct is itself a member of another struct
    and not the first member.

The current implementation of the rules in libffi doesn't handle these
cases, causing a mismatch with the compiler and causing some crashes
we see when OpenJ9 is used with libffi on AIX.

This PR corrects this and adds some representative test cases.
ChengJin01 pushed a commit to ChengJin01/openj9 that referenced this pull request Oct 27, 2023
The change simply adopts the fix at
libffi/libffi#805
to resolve the the issue with the nested struct in libffi on AIX.

Signed-off-by: ChengJin01 <jincheng@ca.ibm.com>
@ChengJin01
Copy link

FYI: @atgreen

testsuite/libffi.call/callback2.c Show resolved Hide resolved
testsuite/libffi.call/callback3.c Show resolved Hide resolved
src/powerpc/ffi_darwin.c Outdated Show resolved Hide resolved
src/powerpc/ffi_darwin.c Outdated Show resolved Hide resolved
src/powerpc/ffi_darwin.c Outdated Show resolved Hide resolved
@daltenty
Copy link
Contributor Author

daltenty commented Nov 3, 2023

I've made some updates to correctly handle nested structs which have tail padding (and added such a test case)

ChengJin01 pushed a commit to ChengJin01/openj9 that referenced this pull request Nov 13, 2023
The change simply adopts the fix at libffi/libffi#805
to resolve the the issue with the nested struct in libffi on AIX.

Related: eclipse-openj9#18287

Signed-off-by: ChengJin01 <jincheng@ca.ibm.com>
@daltenty
Copy link
Contributor Author

Gentle ping

@atgreen atgreen merged commit 7f960d9 into libffi:master Nov 23, 2023
41 of 48 checks passed
@daltenty daltenty deleted the daltenty/fix-aix-layout branch November 23, 2023 15:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

6 participants