arm32 compile error
Hi, I try to compile some sample on arm32 target, as:
./corerun ilc.dll @Hello.ilc.rsp
and I got the following error(bt):
#0 0xae5c1b5e in DBG_DebugBreak () from libclrjitilc.so
#1 0xae521fb6 in DebugBreak () at coreclr/src/pal/src/debug/debug.cpp:404
#2 0xae34c686 in assertAbort (why=0xae5f4def "(!value) != (!pValue)", file=0xae5f42d0 "coreclr/src/jit/gentree.cpp", line=6638)
at coreclr/src/jit/error.cpp:289
#3 0xae38c756 in Compiler::gtNewIconEmbHndNode (this=0x12aa18, value=0x0, pValue=0x0, flags=536870912, handle1=0, handle2=0x0, compileTimeHandle=0xcccccccc)
at coreclr/src/jit/gentree.cpp:6638
#4 0xae3b48a6 in Compiler::impLookupToTree (this=0x12aa18, pResolvedToken=0xbeffd9fc, pLookup=0xbeffc1c0, handleFlags=536870912, compileTimeHandle=0xcccccccc)
at coreclr/src/jit/importer.cpp:1781
#5 0xae3b47bc in Compiler::impTokenToHandle (this=0x12aa18, pResolvedToken=0xbeffd9fc, pRuntimeLookup=0x0, mustRestoreHandle=1, importParent=0)
at coreclr/src/jit/importer.cpp:1755
#6 0xae3cdd0e in Compiler::impImportBlockCode (this=<error reading variable: Cannot access memory at address 0xccccdd0c>,
block=<error reading variable: Cannot access memory at address 0xccccdd08>) at coreclr/src/jit/importer.cpp:13718
Backtrace stopped: Cannot access memory at address 0xcccccce0
I tried to understand what was wrong and found that there was a call to the function "embedGenericHandle" from "impTokenToHandle" function in CoreCLR/src/jit/importer.cpp#1726 And if "embedGenericHandle" called from CoreCLR - it's ok, but if it called from CoreRT, the structure with CORINFO_GENERICHANDLE_RESULT type that is received is incorrect. I found that definition in CoreRT in src/JitInterface/src/CorInfoTypes.cs is wrong:
public struct CORINFO_LOOKUP
{
[FieldOffset(0)]
public CORINFO_LOOKUP_KIND lookupKind;
// If kind.needsRuntimeLookup then this indicates how to do the lookup
[FieldOffset(24)]
public CORINFO_RUNTIME_LOOKUP runtimeLookup;
// If the handle is obtained at compile-time, then this handle is the "exact" handle (class, method, or field)
// Otherwise, it's a representative... If accessType is
// IAT_VALUE --> "handle" stores the real handle or "addr " stores the computed address
// IAT_PVALUE --> "addr" stores a pointer to a location which will hold the real handle
// IAT_PPVALUE --> "addr" stores a double indirection to a location which will hold the real handle
[FieldOffset(24)]
public CORINFO_CONST_LOOKUP constLookup;
}
If I changed "FieldOffset(24)" to "FieldOffset(16)", CoreCLR gets the right values, I think it's architecture dependence value. Then the previous error disappears, but I get a new one(bt):
*** stack smashing detected ***: corerun terminated
Thread 1 "corerun" received signal SIGSEGV, Segmentation fault.
0xb6dc643c in _Unwind_VRS_Pop () from /lib/libgcc_s.so.1
#0 0xb6dc643c in _Unwind_VRS_Pop () from /lib/libgcc_s.so.1
#1 0xb6dc6908 in ?? () from /lib/libgcc_s.so.1
#2 0xb6dc61fe in ?? () from /lib/libgcc_s.so.1
#3 0xb6dc5ff6 in ?? () from /lib/libgcc_s.so.1
#4 0xb6dc6786 in _Unwind_Backtrace () from /lib/libgcc_s.so.1
#5 0xb6d51184 in __GI___backtrace (array=array@entry=0xbeffb848, size=size@entry=64) at ../sysdeps/arm/backtrace.c:105
#6 0xb6c8b098 in backtrace_and_maps (do_abort=do_abort@entry=2, written=written@entry=true, fd=fd@entry=84) at ../sysdeps/unix/sysv/linux/libc_fatal.c:47
#7 0xb6cda0d8 in __libc_message (do_abort=do_abort@entry=2, fmt=<optimized out>) at ../sysdeps/posix/libc_fatal.c:172
#8 0xb6d54404 in __GI___fortify_fail (msg=0xb6d8ed88 "stack smashing detected") at fortify_fail.c:30
#9 0xb6d543c0 in __stack_chk_fail () at stack_chk_fail.c:28
#10 0xae97094c in Compiler::impTokenToHandle (this=0x12ccb0, pResolvedToken=0xbeffd864, pRuntimeLookup=0x0, mustRestoreHandle=1, importParent=0)
at CoreCLR/src/inc/simplerhash.h:73
#11 0xae989802 in Compiler::impImportBlockCode (this=<error reading variable: Cannot access memory at address 0x4213c8>,
block=<error reading variable: Cannot access memory at address 0x4213c4>) at CoreCLR/src/jit/importer.cpp:13743
Backtrace stopped: previous frame inner to this frame (corrupt stack?)
I think there's a wrong shift somewhere else( Also, resolved token pResolvedToken has a very strange value. When it calls CoreCLR, pResolvedToken->hClass has value like: 0xAF54035C, 0xB59862D8 and so on and it's ok, but if it calls CoreRT this value is like 0x00420228
@Dmitri-Botcharnikov @sergign60 @jkotas
CORINFO_LOOKUP needs to be fixed to be bit-ness independent to work well on ARM32 host. It can be something like:
public struct CORINFO_LOOKUP
{
public CORINFO_LOOKUP_KIND lookupKind;
// If kind.needsRuntimeLookup then this indicates how to do the lookup
public CORINFO_RUNTIME_LOOKUP runtimeLookup;
// If the handle is obtained at compile-time, then this handle is the "exact" handle (class, method, or field)
// Otherwise, it's a representative... If accessType is
// IAT_VALUE --> "handle" stores the real handle or "addr " stores the computed address
// IAT_PVALUE --> "addr" stores a pointer to a location which will hold the real handle
// IAT_PPVALUE --> "addr" stores a double indirection to a location which will hold the real handle
public ref CORINFO_CONST_LOOKUP constLookup
{
get
{
// constLookup is union with runtimeLookup
Debug.Assert(sizeof(CORINFO_RUNTIME_LOOKUP) >= sizeof(CORINFO_CONST_LOOKUP));
fixed (CORINFO_RUNTIME_LOOKUP * p = &runtimeLookup)
return ref *(CORINFO_CONST_LOOKUP *)p;
}
}
}
Thanks. It's ok without hardcoded offset now, but the "stack smashing" error remained. I'll try to find where the stack is damaged.
I fixed the bug, this was due to the dereferencing of the token's pointer from the CoreRT, but it's not a pointer, it's an index on the array in terms of the CoreRT. I'll create PR later.