Bug 20788 - marshal7: test hardcodes the wrong structure size for 32-bit Intel Linux
Summary: marshal7: test hardcodes the wrong structure size for 32-bit Intel Linux
Alias: None
Product: Runtime
Classification: Mono
Component: General ()
Version: unspecified
Hardware: PC Linux
: --- normal
Target Milestone: ---
Assignee: Bugzilla
Depends on:
Reported: 2014-06-21 10:13 UTC by Damien Diederen
Modified: 2014-07-01 13:53 UTC (History)
3 users (show)

Is this bug a regression?: ---
Last known good build:

Notice (2018-05-24): bugzilla.xamarin.com is now in read-only mode.

Please join us on Visual Studio Developer Community and in the Xamarin and Mono organizations on GitHub to continue tracking issues. Bugzilla will remain available for reference in read-only mode. We will continue to work on open Bugzilla bugs, copy them to the new locations as needed for follow-up, and add the new items under Related Links.

Our sincere thanks to everyone who has contributed on this bug tracker over the years. Thanks also for your understanding as we make these adjustments and improvements for the future.

Please create a new report on GitHub or Developer Community with your current version information, steps to reproduce, and relevant error messages or log files if you are hitting an issue that looks similar to this resolved bug and you do not yet see a matching new report.

Related Links:

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

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 $?

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;
    $ 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?

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