Skip to content

Commit

Permalink
respect explicit size with sequential layout
Browse files Browse the repository at this point in the history
  • Loading branch information
matouskozak committed Apr 25, 2024
1 parent dd24e9c commit 66272bb
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 3 deletions.
2 changes: 1 addition & 1 deletion src/mono/mono/metadata/class-init.c
Original file line number Diff line number Diff line change
Expand Up @@ -2331,7 +2331,7 @@ mono_class_layout_fields (MonoClass *klass, int base_instance_size, int packing_

instance_size = MAX (real_size, instance_size);

if (instance_size & (min_align - 1)) {
if (instance_size & (min_align - 1) && !explicit_size) {
instance_size += min_align - 1;
instance_size &= ~(min_align - 1);
}
Expand Down
7 changes: 5 additions & 2 deletions src/mono/mono/metadata/marshal.c
Original file line number Diff line number Diff line change
Expand Up @@ -5749,7 +5749,7 @@ MonoMarshalType *
mono_marshal_load_type_info (MonoClass* klass)
{
int j, count = 0;
guint32 native_size = 0, min_align = 1, packing;
guint32 native_size = 0, min_align = 1, packing, explicit_size = 0;
MonoMarshalType *info;
MonoClassField* field;
gpointer iter;
Expand Down Expand Up @@ -5793,7 +5793,7 @@ mono_marshal_load_type_info (MonoClass* klass)
info->num_fields = count;

/* Try to find a size for this type in metadata */
mono_metadata_packing_from_typedef (m_class_get_image (klass), m_class_get_type_token (klass), NULL, &native_size);
explicit_size = mono_metadata_packing_from_typedef (m_class_get_image (klass), m_class_get_type_token (klass), NULL, &native_size);

if (m_class_get_parent (klass)) {
int parent_size = mono_class_native_size (m_class_get_parent (klass), NULL);
Expand Down Expand Up @@ -5879,6 +5879,9 @@ mono_marshal_load_type_info (MonoClass* klass)
align_size = FALSE;
else
min_align = MIN (min_align, packing);
} else if (layout == TYPE_ATTRIBUTE_SEQUENTIAL_LAYOUT) {
if (explicit_size && native_size == info->native_size)
align_size = FALSE;
}
}

Expand Down

0 comments on commit 66272bb

Please sign in to comment.