Bug 20788

Summary: marshal7: test hardcodes the wrong structure size for 32-bit Intel Linux
Product: [Mono] Runtime Reporter: Damien Diederen <dd>
Component: GeneralAssignee: Bugzilla <bugzilla>
Status: RESOLVED FIXED    
Severity: normal CC: mono-bugs+mono, mono-bugs+runtime, vargaz
Priority: ---    
Version: unspecified   
Target Milestone: ---   
Hardware: PC   
OS: Linux   
Tags: Is this bug a regression?: ---
Last known good build:

Description Damien Diederen 2014-06-21 10:13:30 UTC
Hello,

I am observing the following failure on the Tizen/x86 2.2.0
Linux distribution, with recent Mono HEAD (51c454f6):

    $ cd mono/tests
    $ mono marshal7.exe; echo $?
    14

It corresponds to the following check:

    if (Marshal.SizeOf (typeof (TestStruct8)) != 16)
        return 14;

I believe this test is wrong.  My current build of Mono returns 12,
which seems reasonable according to GCC on the same machine (and on
any other 32-bit Linux I could test it on):

    $ cat > foo.c
    #include <stdio.h>
    #include <stddef.h>
    #include <stdint.h>

    struct TestStruct8 {
            int a;
            uint64_t b;
    };

    int main(int argc, char **argv) {
            size_t size = sizeof(struct TestStruct8);
            size_t offset_a = offsetof(struct TestStruct8, a);
            size_t offset_b = offsetof(struct TestStruct8, b);

            printf("Size: %zu, Offset A: %zu, Offset B: %zu\n",
                   size, offset_a, offset_b);
            return 0;
    }
    ^D
    $ gcc -m32 -g -Wall -o foo foo.c
    $ ./foo
    Size: 12, Offset A: 0, Offset B: 4

So the runtime is fine if Mono is supposed to match GCC.

There is already a specific branch for 32-bit OS X; should
the conditional say (IsOSX() || IsLinux()) && ... here:

    if (IsOSX () && IntPtr.Size == 4) {
            if (Marshal.SizeOf (typeof (TestStruct8)) != 12)
                    return 14;
            ...

The test was last modified with the fix to Bug #4510, which is
relatively recent.  Could it be that nobody has had a chance to
verify it on a 32-bit Linux machine?

Thanks,
Damien
Comment 1 Zoltan Varga 2014-07-01 13:53:54 UTC
Fixed in mono master cb0e956570cfe4b0ba7f28951d515176bf330ffb.