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

Arguments after struct messed up in native on libffi/Aarch64 #750

Open
ChengJin01 opened this issue Nov 21, 2022 · 2 comments
Open

Arguments after struct messed up in native on libffi/Aarch64 #750

ChengJin01 opened this issue Nov 21, 2022 · 2 comments

Comments

@ChengJin01
Copy link
Contributor

ChengJin01 commented Nov 21, 2022

System Details

Darwin Kernel Version 20.5.0 /arm64

$ clang --version
Apple clang version 13.0.0 (clang-1300.0.29.3)
Target: arm64-apple-darwin20.5.0

Problems Description

The latest code of libffi/Aarch64 at https://github.com/libffi/libffi/tree/master/src/aarch64 was integrated to our code at https://github.com/eclipse-openj9/openj9/tree/master/runtime/libffi/aarch64 to support JNI call to native on macOS/Aarch64 which works good in the majority of tests except test cases with the mixed type arguments, including primitives, struct and function pointers, in which the arguments after struct were messed up (please see eclipse-openj9/openj9#16336 (comment) for details).

Here's one of the failing test cases at sample.c.txt.

Assuming libffi/Aarch64 should work for both macOS and iOS, I am wondering whether anybody here can help us to figure out what happened in such case (more failing test cases can be found at eclipse-openj9/openj9#16336 (comment) and eclipse-openj9/openj9#16336 (comment)).

@ChengJin01
Copy link
Contributor Author

FYI: @atgreen

@knn-k
Copy link

knn-k commented Nov 25, 2022

allocate_to_stack() does not work as expected on macOS when ty->alignment is smaller than 8 with the case (a-2) below.

AArch64 macOS aligns a struct argument as described below when it is passed in the stack:

(a) The size of the struct is 16 bytes or less

(a-1) If all the struct members are 32-bit float:

  • Example: struct { float, float, float }
  • The struct is aligned at 4-byte boundary in the stack. The following argument can also be aligned at 4 without padding.

(a-2) If the struct contains one or more members that is not 32-bit float:

  • Example: struct { float, float, int }
  • The struct is aligned at 8-byte boundary in the stack. The following argument is also be aligned at 8.

(b) The size of the struct is larger than 16 bytes

(b-1) If all the struct members are 64-bit float, and the size of the struct is 32 bytes or less:

  • Example: struct { double, double, double }
  • The struct is aligned at 8-byte boundary in the stack.

(b-2) Other cases:

  • The struct is passed as an indirect pointer. The pointer is aligned at 8-byte boundary in the stack.

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

No branches or pull requests

2 participants