[Mono-bugs] [Bug 375160] Wrong struct packing.

bugzilla_noreply at novell.com bugzilla_noreply at novell.com
Fri Mar 28 22:02:25 EDT 2008


User jan.oravec at 6com.sk added comment

--- Comment #1 from Jan Oravec <jan.oravec at 6com.sk>  2008-03-28 20:02:24 MST ---
Just found this code (class.c:1265):

        if (layout != TYPE_ATTRIBUTE_EXPLICIT_LAYOUT) {
                 * For small structs, set min_align to at least the struct size
to improve
                 * performance, and since the JIT memset/memcpy code assumes
this and generates 
                 * unaligned accesses otherwise. See #78990 for a testcase.
                if (class->instance_size <= sizeof (MonoObject) + sizeof
                        class->min_align = MAX (class->min_align,
class->instance_size - sizeof (MonoObject));

I am not sure, if runtime can choose struct packing arbitrarily, but I see
another problems:

a) it forces high minimum alignments on structures which could be heavily used
in other structures... these other structures are massively oversized because
of that

b) class->instance_size - sizeof (MonoObject) isn't necessarily 2^N, e.g.:

class X
  int a; short b; byte c;

class Y
  int a; X x;

sizeof (X) == 7, sizeof (Y) == 17, while adding another byte to X makes sizeof
(Y) == 16, which is even lower!

Something very bad may happen when min_align = 7...

Configure bugmail: https://bugzilla.novell.com/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are the QA contact for the bug.
You are the assignee for the bug.

More information about the mono-bugs mailing list