-
Notifications
You must be signed in to change notification settings - Fork 774
Description
When invokeNative calls a native function with more than 8 i32 arguments (excluding the WAMR env argument) the additional stack arguments do not come through as expected on Darwin AARCH64 (tested on an m4 macbook running macOS 26.3).
The call works correctly on Linux AARCH64 (same hardware via a VM).
Reproduction case here: edmorrish@956e850
Apologies for the messy logging, I also had to add some padding to the WASMTestType struct in test_invoke_native to get the tests to behave as expected on main.
Logging from tests:
Darwin:
...
##test_native_args_10xi32 result:
arg0: 1, arg1: 2, arg2: 3, arg3: 4, arg4: 5
arg5: 6, arg6: 7, arg7: 8, arg8: 0, arg9: 9
Linux:
...
##test_native_args_10xi32 result:
arg0: 1, arg1: 2, arg2: 3, arg3: 4, arg4: 5
arg5: 6, arg6: 7, arg7: 8, arg8: 9, arg9: 10
It doesn't seem to have the same issues in the existing test that uses a mix of integers and floats.
Happy to assist with debugging this issue, but I'm not familiar with the calling convention differences between AARCH64 Darwin and Linux that are causing this problem.
Thanks in advance for any help!
Update:
I believe this might be an issue with Darwin assuming that 32bit wide function arguments will be packed on the stack, but linux assumes each one gets its own 64bit "slot", so when arg8 is 0 in my example it's reading empty space because it's reading the "high" 32 bits of a 64bit slot. I haven't found any documentation from Apple to back that theory up, but in practice I've tried a workaround of making my native function read 64bit values off the stack for the 8th+ arguments and that seems to work for now.