-
Notifications
You must be signed in to change notification settings - Fork 4.7k
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
Non-POD arguments passed incorrectly on ARM64 #106471
Comments
It's caused by ABI difference on ARM64. You can see more details at https://learn.microsoft.com/cpp/build/arm64-windows-abi-conventions In short, the default constructor in C++ code make it no longer considered HFA on ARM64:
The argument passing schema for HFA and regular structs are different on ARM64. On x64 there's no such concept and all structs are passed in the same way. I'm not sure whether .NET supports passing HFAs as a single argument at all. |
Thank you for the explanation. As a workaround it was possible in my case to change the default constructor to |
…get passed correctly by interop layer in arm64 dotnet/runtime#106471
…get passed correctly by interop layer in arm64 dotnet/runtime#106471
…get passed correctly by interop layer in arm64 dotnet/runtime#106471
This commit also rebuilds the x64 binaries to ensure both use the same source code after applying workaorund from dotnet/runtime#106471
This commit also rebuilds the x64 binaries to ensure both use the same source code after applying workaorund from dotnet/runtime#106471
.NET interop targets C ABI. The The calling convention details for non-POD (Plain Old Data) C++ types are often different from the calling convention details of plain C structs as you have discovered. This came up a few times before (e.g. in #12312). We should mention this in the docs. |
Description
While trying to run ImGui.NET on win-arm64 I ran into some sort of argument passing issue from managed to native code when calling https://github.com/cimgui/cimgui/blob/35a4e8f8932c6395156ffacee288b9c30e50cb63/cimgui.cpp#L207 via the managed wrapper https://github.com/ImGuiNET/ImGui.NET/blob/70a87022f775025b90dbe2194e44983c79de0911/src/ImGui.NET/Generated/ImGui.gen.cs#L21374
I managed to reproduce it with following stripped down version. Note that this code runs fine in
win-x64
. It also runs fine inwin-arm64
when removing the default constructor from theVector2
struct. This makes me wonder whether it's even a dotnet issue, therefor feel free to point me to the appropriate channels if it isn't.Reproduction Steps
C#
C++
Attached is a little VS solution containing the above code
PInvoke.zip
Expected behavior
MyFunction
should receive0
asvalue
.Actual behavior
MyFunction
receives some random number asvalue
.Regression?
No response
Known Workarounds
No response
Configuration
.net8, Windows 11, ARM64
Other information
I've also tried building the project with clang but got the same result.
The text was updated successfully, but these errors were encountered: