[Mono-dev] Test failures during 'make check' on MacBook Pro

Blake Ramsdell blake182 at mac.com
Sat Apr 29 19:26:35 EDT 2006


On Apr 29, 2006, at 5:41 AM, Zac Bowling wrote:
> I'm guessing its maybe alignment issues of going from structures from
> managed to native or maybe big endian/little endian on some the  
> ints in
> there somewhere.

I note the following output:

blake-ramsdells-macbook-pro:~/Source/OpenSource/mono-1.1.15.blake  
blake$ cat mono/tests/pinvoke2.exe.stdout
test_0_amd64_struct2 failed: got 1, expected 0
test_0_amd64_struct3 failed: got 1, expected 0
test_0_ia64_struct5 failed: got 1, expected 0
Regression tests: 61 ran, 3 failed in Tests


A quick diagnostic added to mono/tests/libtest.c:

diff -ru mono-1.1.15/mono/tests/libtest.c mono-1.1.15.blake/mono/ 
tests/libtest.c
--- mono-1.1.15/mono/tests/libtest.c    2006-04-14 10:47:07.000000000  
-0700
+++ mono-1.1.15.blake/mono/tests/libtest.c      2006-04-29  
16:08:08.000000000 -0700
@@ -1325,6 +1325,11 @@
STDCALL amd64_struct2
mono_test_marshal_amd64_pass_return_struct2 (amd64_struct2 s)
{
+       fprintf(stderr, "&s = %p, i = %d, j = %d\n", (void*) &s, s.i,  
s.j);
+       fprintf(stderr, "offsetof(i) = %d, offsetof(j) = %d\n",
+               (int) offsetof(amd64_struct2, i),
+               (int) offsetof(amd64_struct2, j)
+               );
         s.i ++;
         s.j ++;

yielded:

blake-ramsdells-macbook-pro:~/Source/OpenSource/mono-1.1.15.blake/ 
mono/tests blake$ cat pinvoke2.exe.stderr
&s = 0xbffff310, i = -1073745092, j = 5
offsetof(i) = 0, offsetof(j) = 4


The test in pinvoke2.cs:

s.i = 5;
s.j = -5;


So my first guess is that it blew the root address of the struct when  
it went to marshal the data. I modified the test again:

diff -ru mono-1.1.15/mono/tests/libtest.c mono-1.1.15.blake/mono/ 
tests/libtest.c
--- mono-1.1.15/mono/tests/libtest.c    2006-04-14 10:47:07.000000000  
-0700
+++ mono-1.1.15.blake/mono/tests/libtest.c      2006-04-29  
15:53:05.000000000 -0700
@@ -1320,13 +1320,21 @@
typedef struct amd64_struct2 {
         int i;
         int j;
+       int k;
} amd64_struct2;
STDCALL amd64_struct2
mono_test_marshal_amd64_pass_return_struct2 (amd64_struct2 s)
{
+       fprintf(stderr, "i = %d, j = %d, k = %d\n", s.i, s.j, s.k);
+       fprintf(stderr, "offsetof(i) = %d, offsetof(j) = %d, offsetof 
(k) = %d\n",
+               (int) offsetof(amd64_struct2, i),
+               (int) offsetof(amd64_struct2, j),
+               (int) offsetof(amd64_struct2, k)
+               );
         s.i ++;
         s.j ++;
+       s.k ++;
         return s;
}


And the output changed to:

blake-ramsdells-macbook-pro:~/Source/OpenSource/mono-1.1.15.blake/ 
mono/tests blake$ cat pinvoke2.exe.stderr
&s = 0xbffff314, i = 5, j = -5, k = 793103
offsetof(i) = 0, offsetof(j) = 4, offsetof(k) = 8

Now i and j are the right values. And the test_0_amd64_struct2 test  
passes now. So I think it does have to do with the base address of  
the structure.

So I don't know if I altered the "by value" behavior by adding the  
third member, and if this is a relevant finding. Note that the  
address of the struct shifted 32 bits, which seems to have aligned it  
with the C# understanding of the struct base address.

> I've been running into some strange bugs myself like this on my new
> intel mac mini but I'm to busy to bug hunt it down myself. Let someone
> else figure that out. :-p

Well, I'm halfway into it now, so we'll see how far I get. I don't  
know nuthin' about how it all works, but hopefully the tests will  
catch me if I mess it all up.

My big problem is not messing up the word for the "amd64" aspect of  
this (which I can't test).

In any case, I presume I can make this work for the Intel Macs, but I  
don't know what I'm going to break for everyone else. I'll look at  
it, submit a patch, and see where it ends up from there.

Blake
--
Blake Ramsdell | http://www.blakeramsdell.com





More information about the Mono-devel-list mailing list