-
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] Mono doesn't respect explicit size for structures when marked with LayoutKind.Sequential #101432
Comments
This goes back a long time to 6fcc759
Here: runtime/src/mono/mono/metadata/class-init.c Lines 2391 to 2396 in 2e75aac
It might be possible to change this to respect the specified size also for sequential layouts, not just explicit. But I'm not sure how much code that will break downstream of mono. |
It's more evidence that something like #100896 is necessary, even without generics. These kind of struct layouts are necessary to model Swift structures in C#. cc @jkoritzinsky @matouskozak if you are blocked on the Swift work I can give you some instructions on generating the Swift unit tests with |
What happens in swift if you allocate an array of frozen structs that have a size that is not a multiple of the minimum alignment of any members? Do the array elements end up packing tightly and misaligning the members? |
Swift has the notion of "stride" for this:
I believe the stride is used for array allocations, but for struct layout Swift allows fields to pack into the "tail padding" of previous structures, like as follows: [StructLayout(LayoutKind.Sequential, Size = 12)]
struct F3_S0_S0
{
public nint F0;
public uint F1;
public F3_S0_S0(nint f0, uint f1)
{
F0 = f0;
F1 = f1;
}
}
[StructLayout(LayoutKind.Sequential, Pack = 16)]
public struct S
{
public F3_S0_S0 S;
public int X; // at offset 12
} |
that makes sense, thanks |
Fixed in #101529 |
Mono doesn't respect explicit struct size when combined with sequential layout, i.e., when using
[StructLayout(LayoutKind.Sequential, Size = X)]
, the structure doesn't have the desired sizeX
.Repro code:
Mono output:
CoreCLR output:
The text was updated successfully, but these errors were encountered: