ARM/Linux "structinregs" unit test fail
Unit test JIT.Methodical.structs.systemvbringup.structinregs fails in ARM/Linux.
...
Native S1: 1, 2, 3, 4
S1: 1, 2, 3, 4
S1R: 1, 2, 3, 4
Native S2: 1, 2, 3.000000
S2: 1, 2, 3
S2R: 1, 2, 3
Native S3: 1, 2, 3.000000
S3: 1, 2, 3
S3R: 1, 2, 3
Native S4: 1073741824, 157501122515305666310423183360.000000
Program received signal SIGSEGV, Segmentation fault.
0x00000000 in ?? ()
(gdb) bt
#0 0x00000000 in ?? ()
dotnet/coreclr#1 0x6ffe75e0 in InvokeCallback4R (callback=0x1, s=...) at structinregs.cpp:367
dotnet/coreclr#2 0x6ffd6860 in ?? ()
Backtrace stopped: previous frame identical to this frame (corrupt stack?)
P/Invoke to InvokeCallback4R() in structpinvoketests.cs fails. While InvokeCallback{1-3}R() works fine.
In the frame InvokeCallback4R, parameters are supposed to be:
callback : the callback function pointer
s.x : 1
s.y : 2.0
While the actual value is:
(gdb) p callback
$11 = (PFNACTION4) 0x1
(gdb) p/x (long long)s
$16 = 0x6ffe74f040000000
Which is:
callback : 1
s.x : 0x40000000 <2.0>
s.y : 0x6ffe74f0 <InvokeCallback4R(PFNACTION4, S4)>
Are both the arguments of InvokeCallback4R passed in registers? Can you please post disass of the InvokeCallback4R and dump of the registers at entry to that function here? The strange thing is that S2 and S4 differ only a little and still test with S2 works and the one with S4 does not.
Here are the definitions of S2 and S4:
struct S2
{
int x;
int y;
float z;
};
struct S4
{
int x;
float y;
};
@janvorli,
To make things simpler, I got rid of all the test code other than S2 and S4 in Program3:Main1() then ran the test again.
Looking at the parts calling InvokeCallback2R and InvokeCallback4R,
271 G_M30233_IG06:
272 00026C AB31 add r3, sp, 196 // [V00 loc0]
273 00026E 689A ldr r2, [r3+8]
274 000270 9200 str r2, [sp] // [V41 OutArgs]
275 000272 681A ldr r2, [r3]
276 000274 685B ldr r3, [r3+4]
277 000276 A824 add r0, sp, 144 // [V13 tmp6]
278 000278 991A ldr r1, [sp+0x68] // [V12 tmp5]
279 00027A F245 4E8D movw lr, 0x548d
280 00027E F2C7 1EC3 movt lr, 0x71c3
281 000282 47F0 blx lr // structinreg.Program3:InvokeCallback2R(ref,struct):struct
...
454 G_M30233_IG15:
455 000434 AB2F add r3, sp, 188 // [V01 loc1]
456 000436 681A ldr r2, [r3]
457 000438 685B ldr r3, [r3+4]
458 00043A A821 add r0, sp, 132 // [V20 tmp13]
459 00043C 9915 ldr r1, [sp+0x54] // [V19 tmp12]
460 00043E F245 4EAD movw lr, 0x54ad
461 000442 F2C7 1EC3 movt lr, 0x71c3
462 000446 47F0 blx lr // structinreg.Program3:InvokeCallback4R(ref,struct):struct
It seems like InvokeCallback2R needs an on-stack argument(V41 OutArgs) cause the function returns a large struct and which one more argument. However InvokeCallback4R can still hold all arguments in the registers r0-r3. I'm guessing that there may be something with Function Call ABI.
The whole disasm file is attached: structpasstest-S2S4.txt
disasm of jitstructtests_lib.so: jitstructtests_lib.txt
It could be that the stub that sits between the jitted code and the native codeis generated incorrectly. Likely missing the fact that it needs the return buffer for the result in this case - guessing from your stack trace where the callback value is shown as 1, which is the S2.x and so that means that S2.x was passed in R1 and the callback in R0. Could you please also disass the caller of the native method? It should be just a relatively short piece of code (it is dynamically generated).
On current master(dd15b12e48afdda9b7a5f1b19c2af2c928294843),
arm : pass
arm-softfp : fail
S11: 1, 2, 3, 4, 5
S11R: 1, 2, 3, 4, 5
Native S12: 1, 2, 3, 4, 5, 6, 7, 8, 9
S12: 1, 2, 3, 4, 5, 6, 7, 8, 9
S12R: 1, 2, 3, 4, 5, 6, 7, 8, 9
Native S13: 1, 2
S13: 1, 2
S13R: 1, 2
Native S13: 1, 2
S14: 1, 2
S14R: 1, 2
Native S15: 1, 2, 3, 4, 5, 6, 7, 8, 9
S15: 1, 2, 3, 4, 5, 6, 7, 8, 9
S15R: 1, 2, 3, 4, 5, 6, 7, 8, 9
Native S16: 1, 2
S16: 1, 2
S16R: 1, 2
Native S17: 2.000000, -0.000000
Program received signal SIGSEGV, Segmentation fault.
0x3f800000 in ?? ()
(gdb) bt
#0 0x3f800000 in ?? ()
dotnet/coreclr#1 0xafb5c0e8 in InvokeCallback17R (callback=0x3f800000, s=...)
at structinregs.cpp:445
dotnet/coreclr#2 0xafb4eafe in ?? ()
Backtrace stopped: previous frame identical to this frame (corrupt stack?)
It seems like dotnet/coreclr#5010 actually fixed this issue, but there is something wrong with arm-softfp itself.
So I looked at disasm of InvokeCallback17R both caller and callee .
- Callee (Compiled by Clang 3.5)
//// r0 : RetBuf
//// r1 : callback
//// r2 : s.x
//// r3 : s.y
00002080 <InvokeCallback17R>:
2080: e92d4bf0 push {r4, r5, r6, r7, r8, r9, fp, lr}
2084: e28db018 add fp, sp, dotnet/coreclr#24
2088: e24dd008 sub sp, sp, dotnet/coreclr#8
208c: e1a04003 mov r4, r3 //// r4 = r3 = s.y
2090: e1a08000 mov r8, r0 //// r8 = r0 = RetBuf
2094: e1a05002 mov r5, r2 //// r5 = r2 = s.x
2098: e1a09001 mov r9, r1 //// r9 = r1 = callback
209c: e1a00004 mov r0, r4
20a0: ebfffaff bl ca4 <_init+0x38>
20a4: e1a06000 mov r6, r0
20a8: e1a00005 mov r0, r5
20ac: e1a07001 mov r7, r1
20b0: ebfffafb bl ca4 <_init+0x38>
20b4: e1a02000 mov r2, r0
20b8: e59f003c ldr r0, [pc, dotnet/runtime#3880] ; 20fc <InvokeCallback17R+0x7c>
20bc: e59f303c ldr r3, [pc, dotnet/runtime#3880] ; 2100 <InvokeCallback17R+0x80>
20c0: e88d00c0 stm sp, {r6, r7}
20c4: e08f0000 add r0, pc, r0
20c8: e0830000 add r0, r3, r0
20cc: e1a03001 mov r3, r1
20d0: ebfffaf0 bl c98 <_init+0x2c> //// [CALL printf]
20d4: e1a00005 mov r0, r5 //// r0 = s.x
20d8: e1a01004 mov r1, r4 //// r1 = s.y
20dc: e1a02009 mov r2, r9
20e0: e1a0e00f mov lr, pc
20e4: e12fff12 bx r2 //// [CALL callback]
20e8: e5885000 str r5, [r8] //// Fill RetBuf
20ec: e5884004 str r4, [r8, dotnet/coreclr#4] //// Fill RetBuf
20f0: e24bd018 sub sp, fp, dotnet/coreclr#24
20f4: e8bd4bf0 pop {r4, r5, r6, r7, r8, r9, fp, lr}
20f8: e12fff1e bx lr
20fc: 00008f34 .word 0x00008f34
2100: ffff75d6 .word 0xffff75d6
- Caller Code (JITed)
//// r0 : callback
//// r1 : s.x
//// r2 : s.y
G_M9690_IG155:
003AB6 F60D 2300 addw r3, sp, 0xa00 // [V17 loc17]
003ABA 6819 ldr r1, [r3]
003ABC 685A ldr r2, [r3+4]
003ABE F8DD 059C ldr r0, [sp+0x59c] // [V250 tmp185]
003AC2 F24B 531D movw r3, 0xb51d
003AC6 F2CB 13CF movt r3, 0xb1cf
003ACA 4798 blx r3 // structinreg.Program3:InvokeCallback17R(ref,struct):struct
003ACC F240 5A94 movw r10, 0x594 // [V251 tmp186]
003AD0 44EA add r10, sp
003AD2 ED8A 0B00 vstr d0, [r10]
003AD6 F20D 5394 addw r3, sp, 0x594 // [V251 tmp186]
003ADA F60D 02B0 addw r2, sp, 0x8b0 // [V40 loc40]
Calling convention mismatches. There is no RetBuf in caller side and after the call it tries loc40 = tmp186 but tmp186 was not even passed. I think tmp186 is supposed to be RetBuf.
@papaslavik FYI