runtime
runtime copied to clipboard
[Ryujit/ARM32][ReadyToRun] Assertion when invoking method from NI file
When running NI file which is generated by ReadyToRun using Ryujit/ARM32, assertion fails when invoking method through ZapIndirectHelperThunk.
Example
JIT/CodeGenBringUpTests/Add1/Add1.exe
using System;
using System.Runtime.CompilerServices;
public class BringUpTest
{
const int Pass = 100;
const int Fail = -1;
[MethodImplAttribute(MethodImplOptions.NoInlining)]
public static int Add1(int x) { return x+1; }
public static int Main()
{
int y = Add1(1);
if (y == 2) return Pass;
else return Fail;
}
}
$ COMPlus_AltJitNgen=* ./crossgen /ReadyToRun /Platform_Assemblies_Paths /mnt/albireo/mywork/device/rpi3/unittests/coreoverlays/coreoverlay.test20170315debug Add1.exe
Microsoft (R) CoreCLR Native Image Generator - Version 4.5.22220.0
Copyright (c) Microsoft Corporation. All rights reserved.
Native image /mnt/albireo/mywork/device/rpi3/unittests/mytest/Add1/log.new/Add1.ni.exe generated successfully.
$ ./corerun Add1.ni.exe
Assert failure(PID 445 [0x000001bd], Thread: 445 [0x01bd]): pImportSection == pModule->GetImportSectionForRVA(rva)
File: /opt/code/github/hqueue/coreclr/src/vm/prestub.cpp Line: 1856
Image: /mnt/albireo/mywork/device/rpi3/unittests/coreoverlays/coreoverlay.test20170315debug/corerun
Aborted (core dumped)
Analysis
Main method
; Assembly listing for method BringUpTest:Main():int
; Emitting BLENDED_CODE for generic ARM CPU
; optimized code
; sp based frame
; partially interruptible
; Final local variable assignments
;
; V00 loc0 [V00,T00] ( 2, 2 ) int -> r0
;# V01 OutArgs [V01 ] ( 1, 1 ) lclBlk ( 0) [sp+0x00]
;
; Lcl frame size = 4
G_M27682_IG01:
000000 B508 push {r3,lr}
G_M27682_IG02:
000002 2001 movs r0, 1
000004 F240 0300 movw r3, LOW RELOC 0x74409a2c
000008 F2C0 0300 movt r3, HIGH RELOC 0x74409a2c
00000C 681B ldr r3, [r3]
00000E 4798 blx r3 // BringUpTest:Add1(int):int
000010 2802 cmp r0, 2
000012 D101 bne SHORT G_M27682_IG04
000014 2064 movs r0, 100
G_M27682_IG03:
000016 BD08 pop {r3,pc}
G_M27682_IG04:
000018 F04F 30FF mov r0, -1
G_M27682_IG05:
00001C BD08 pop {r3,pc}
; Total bytes of code 30, prolog size 2 for method BringUpTest:Main():int
; ============================================================
Native image /mnt/albireo/mywork/device/rpi3/unittests/mytest/Add1/log.new/Add1.ni.exe generated successfully.
From above blx r3 , code jump and link to following ZapIndirectHelperThunk which accept r12 as a paramenter.
0x40218f: str.w r12, [sp, #-4]!
0x402193: mov.w r12, dotnet/coreclr#1
0x402197: str.w r12, [sp, #-4]!
0x40219b: movw r12, dotnet/coreclr#4096 ; 0x1000
0x40219f: movt r12, dotnet/coreclr#64 ; 0x40
0x4021a3: ldr.w r12, [r12]
0x4021a7: str.w r12, [sp, #-4]!
0x4021ab: movw r12, dotnet/runtime#5499 ; 0x1008
0x4021af: movt r12, dotnet/coreclr#64 ; 0x40
0x4021b3: ldr.w r12, [r12]
0x4021b7: bx r12
Expected code
We think following code is right.
movs r0, 1
movw r12, LOW RELOC 0x74409a2c
movt r12, HIGH RELOC 0x74409a2c
ldr r3, [r12]
blx r3 // BringUpTest:Add1(int):int
(This is related to dotnet/runtime#7099.)
/cc: @sjsinju @hseok-oh