-
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
[mono] Force Mono to respect explicit struct size when LayoutKind.Sequential is used #101529
[mono] Force Mono to respect explicit struct size when LayoutKind.Sequential is used #101529
Conversation
ef2083b
to
18e622f
Compare
/azp run runtime-extra-platforms |
Azure Pipelines successfully started running 1 pipeline(s). |
@grendello @jonpryor @lewing @rolfbjarne @dalexsoto We're going to change mono to respect the explicit Previously Mono would align the struct size up to the alignment of the most restricted struct element. This was so that arrays would always have their elements such that every struct member would be at its natural alignment. But as a result, if you had a struct inside another struct followed by a member with a less restricted alignment there would always be padding after the struct. So we would behave as if the This is needed for Swift interop (frozen swift structs also behave this way). (See #101432) For example: [StructLayout(Sequential, Size=12)]
struct DoubleAndInt1
{
public double D1;
public int I2;
};
[StructLayout(Sequential)]
struct DoubleAndInt2
{
public double D1;
public double I2;
} Previously in Mono both That means if you do We're running a functional test on Android arm32 to check whether we need to do some work in the JIT in order to issue an unaligned load/store for arrays like Questions Is this change going to be a problem for your existing interop code in XI, XA or wasm? |
I didn't find any
|
XI doesn't have any sequential StructLayouts with explicit size, so it's good on our side. Additionally we use CoreCLR for macOS, and we haven't found any such issues there. |
That one should be unaffected by this PR. Here we only modify the behavior for |
I'm not aware of any issues on the wasm side |
18e622f
to
66272bb
Compare
We have tested this change on Arm64 VMs emulating Arm32 without any issues. We also performed successful local testing on armv7 Raspberry (thanks to @akoeplinger). |
src/tests/Interop/ArrayMarshalling/UnalignedStructArray/MarshalUnalignedStructArray.cs
Outdated
Show resolved
Hide resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
lgtm, thanks!
/azp run runtime-extra-platforms |
Azure Pipelines successfully started running 1 pipeline(s). |
The WASM failures are unrelated and are matched using Build Analysis. The |
…uential is used (dotnet#101529) * respect explicit size with sequential layout * test for sequential layout with explicit size
…uential is used (dotnet#101529) * respect explicit size with sequential layout * test for sequential layout with explicit size
…uential is used (dotnet#101529) * respect explicit size with sequential layout * test for sequential layout with explicit size
We encountered an issue with Mono not respecting explicit size when
LayoutKind.Sequential
was used (#101432). We fix this by eliminating addition of alignment padding when explicit size is set.