[ARM/Linux] Regression in 'JIT.Methodical.xxobj.sizeof._il_dbgsizeof32._il_dbgsizeof32'
In ARM/Linux, the exitcode of CoreCLR is 108 instead of 100 for the unittest JIT.Methodical.xxobj.sizeof._il_dbgsizeof32._il_dbgsizeof32:
$ Linux.amr-softfp.Debug/corerun ut/JIT/Methodical/xxobj/sizeof/_il_dbgsizeof32/_il_dbgsizeof32.exe || echo $?
108
Interestingly, the exitcode is same even for CoreCLR in AMD64/Linux.
While analyzing this issue, I found one suspicious point.
Recently, we decide to use unittest built for x86 architecture since ARM is also 32-bit architecture, which make us to use sizeof32.il instead of 64sizeof32.il in src/JIT/Methodical/xxobj/sizeof.
Both IL code shares the same lexical definitions for the struct of interest:
.class private sequential ansi sealed beforefieldinit JitTest.SimpleStruct
extends [mscorlib]System.ValueType
{
.field public int32 m_int
.field public uint32 m_uint
.field public uint8 m_byte
.field public int8 m_sbyte
.field public char m_char
.field public int16 m_short
.field public uint16 m_ushort
.field public int64 m_long
.field public uint64 m_ulong
} // end of class JitTest.SimpleStruct
.class private sequential ansi sealed beforefieldinit JitTest.RefComplexStruct
extends [mscorlib]System.ValueType
{
.field public valuetype JitTest.SimpleStruct ss1
.field public valuetype JitTest.SimpleStruct[0...] ss_array
.field public valuetype JitTest.SimpleStruct ss2
} // end of class JitTest.RefComplexStruct
The only difference is the size of ss_array in RefComplexStruct.
The testcase seems to assume that sizeof(RefComplexStruct) is 68 (which is true if the size of ss_array is same as that of any pointers in ARM), but the actual size is 72.
@jkotas Could you let me know who is responsible to this test? It seems that the test itself has some invalid assumptions.
CC @lemmaa
cc: @dotnet/jit-contrib
After further analysis, sizeof JitTest.RefComplexStruct is 72 for coreclr in ARM32 due to AlignmentRequirement of nested JitTest.SimpleStruct.
In short, coreclr works as indended and it looks that TC should be rewritten.
I will describe what happens with above JitTest.SimpleStruct and JitTest.RefComplexStruct.
- sizeof
JitTest.SimpleStructis 32 (=4+4+1+1+2+4+4+8+8) and there is no padding for alignment. - sizeof
JitTest.RefComplexStructis 72 with paddings for alignment and computed as follows.
RefCompexStruct contains three fields.
- Size of 1st field ss1 is 32 and AlignmentReuqirement is 8 for ss1.
- Size of 2nd field ss_array is 1 according to coreclr. (This is treated as NFT_ILLEGAL in coreclr and size is 1 during compilation.)
- Size of 3rd field ss2 is 32 and AlignmentReuqirement is 8 for ss2.
AlignmentRequirement for JitTest.SimpleStruct is 8, because .field public int64 m_long and .field public uint64 m_ulong in JitTest.SimpleStruct has AlignmentRequirement of 8.
See: https://github.com/dotnet/coreclr/blob/master/src/vm/fieldmarshaler.h#L210-L216
As a result, layout of RefComplexStruct is as follows { offset 0 to 31 : ss1 (32 bytes) offset 32: ss_array (1 byte) (7 bytes alignment for ss2) offset 40 to 71: ss2 (32 bytes) }
Therefore total size of JitTest.RefComplexStruct is 72 for ARM32 and I think x86 is same, because sizeof RefComplexStruct itself is always 72 due to alignment padding for 3rd field ss2.
Sorry for not following up sooner. @hqueue You are correct that the test is not valid for ARM. You can see in the project file that there was an attempt to use the corresponding 64sizeof32.il for non-x86 platforms. Unfortunately, that doesn't work in this case if you run tests built for x86 on ARM. It should work if the tests were built for ARM. I'm not sure if our build system allows cross-building the IL tests, and as you may know it's sadly not yet possible to build IL tests outside of Windows.
If you search for BuildArch in files under tests/src, you'll find other tests that use this flawed pattern:
JIT\Directed\PREFIX\unaligned\1\arglist.ilproj
JIT\Directed\PREFIX\unaligned\2\arglist.ilproj
JIT\Directed\PREFIX\unaligned\4\arglist.ilproj
JIT\Directed\PREFIX\volatile\1\arglist.ilproj
JIT\Methodical\ELEMENT_TYPE_IU\_il_dbgi_array_merge.ilproj
JIT\Methodical\ELEMENT_TYPE_IU\_il_dbgsizeof.ilproj
JIT\Methodical\ELEMENT_TYPE_IU\_il_dbgu_array_merge.ilproj
JIT\Methodical\ELEMENT_TYPE_IU\_il_reli_array_merge.ilproj
JIT\Methodical\ELEMENT_TYPE_IU\_il_relsizeof.ilproj
JIT\Methodical\ELEMENT_TYPE_IU\_il_relu_array_merge.ilproj
JIT\Methodical\xxobj\sizeof\_il_dbgsizeof.ilproj
JIT\Methodical\xxobj\sizeof\_il_dbgsizeof32.ilproj
JIT\Methodical\xxobj\sizeof\_il_dbgsizeof64.ilproj
JIT\Methodical\xxobj\sizeof\_il_relsizeof.ilproj
JIT\Methodical\xxobj\sizeof\_il_relsizeof32.ilproj
JIT\Methodical\xxobj\sizeof\_il_relsizeof64.ilproj
Some of them are compatible with the "use the same bitness for running and building" approach, but not all. The arglist tests even have ARM(32)-specific versions, though those are already disabled because arglist isn't currently supported by .NET Core.
It's a poor design decision on our part to make IL tests depend on the build architecture, since almost all IL tests are platform-independent. To test such architecturally variant behavior, there should be a runtime decision--either in the runner script or inside the test itself--that alters the behavior based on runtime architecture. That way, IL components can remain platform neutral across the board.
@RussKeldorph Thank you for addressing test issue and I definitely agree with you on this. I will also find ways to enable architecture-specific tests with less effort and I'm willing to open a discussion later if possible.
However for this JIT/Methodical/xxobj/sizeof test cases, I still have some questions, because I thought these tests have same behavior on ARM and x86. (Maybe I'm wrong.)
Do _il_dbgsizeof and _il_dbgsizeof32work on x86 correctly now ?
I didn't run this test with coreclr for x86 and just guessed after reviewing coreclr code, becuase I don't have stable x86 test environment yet. Do you know result of these test on x86 ?
I thought we don't need a target specific tests for JIT\Methodical\xxobj\sizeof and was trying to make and test a fix(1f49b9b3b0750ddae5d0733ac9a6d05ecc413f00) for _il_xxxsizeof cases. However if x86 and ARM show different behaviors, we need new approaches as you mentioned above.
FYI. Other tests such as JIT\Methodical\ELEMENT_TYPE_IU works well for ARM when compiled for x86 with current BuildArch approach.
Do _il_dbgsizeof and _il_dbgsizeof32work on x86 correctly now ?
@hqueue It may help for you, http://dotnet-ci.cloudapp.net/job/dotnet_coreclr/job/master/job/x86_lb_release_windows_nt/lastCompletedBuild/testReport/JIT/Methodical_xxobj_sizeof__il_dbgsizeof32__il_dbgsizeof32/ , I guess.
@hqueue Very sorry for the delay. I was out of the office.
I believe the tests you mention do pass on x86 now. Looking only at the project file contents, other than the arglist tests (which are disabled for another reason) I think _il_dbgsizeof32 is the only existing test that doesn't pass on ARM when running the x86-built version. I suspect it has something to do with the sizeof of the questionable/invalid(?) ss_array field in JitTest.SimpleStruct. I'm not familiar with the history, but my guess would be that the original CLR implementation (x86) assigned that field a size of zero (0). Perhaps the implementers considered that an oversight and chose not to repeat it on later architectures.
So, I think the best approach is to change the test approach, for better or worse.
@RussKeldorph Nice to see you :)
I think _il_dbgsizeof32 is the only existing test that doesn't pass on ARM when running the x86-built version.
Until recent commit 19346e58c6443638c245f85ee0b31a8c6e7af872, I also confirmed that and there is no significant change to test result by now.
So, I think the best approach is to change the test approach, for better or worse.
I agree with you, because we need explicitly different test for ARM32 in this case. :)
@lemmaa @parjong @wateret @hseok-oh How about exclduing these tests from ARM test, because there is no way to build tests for ARM now.
@hqueue Agreed. Excluding is best short term.
Removing this from RyuJIT/ARM32 project, as it doesn't block shipping RyuJIT/ARM32.
@RussKeldorph Do you want to keep this issue open, because you (or someone) will fix the tests eventually? Or should we close it with the assumption that any pass through the "testsUnsupportedOnARM32.txt" (and similar files) will rediscover the problem?