Skip to content

Commit

Permalink
SPMI: Handle "successful error cases" in near differ on arm64
Browse files Browse the repository at this point in the history
After dotnet#89654 SPMI replay will succeed instead of result in replay errors
in expected error cases (such as BADCODE or EE exception). To support
diffing such contexts, we record zero-sized assembly that the near
differ uses. However, on arm64 there is some additional code that calls
repCompileMethod to make some additional adjustments to the code blob,
and in the "EE exception" cases we cannot replay this function,
resulting in crash during asmdiff. This fixes the problem by only making
the adjustments when we know there is any code.

An alternative solution could be to avoid invoking the neardiffer at all
in the succeeding error cases, but this seemed like an ok pragmatic
solution.

Fix dotnet#91257
  • Loading branch information
jakobbotsch committed Sep 8, 2023
1 parent a76527d commit 66576a8
Showing 1 changed file with 22 additions and 21 deletions.
43 changes: 22 additions & 21 deletions src/coreclr/tools/superpmi/superpmi/neardiffer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1247,28 +1247,29 @@ bool NearDiffer::compare(MethodContext* mc, CompileResult* cr1, CompileResult* c
// is a sum of their sizes. The following is to adjust their sizes and the roDataBlock_{1,2} pointers.
if (GetSpmiTargetArchitecture() == SPMI_TARGET_ARCHITECTURE_ARM64)
{
BYTE* nativeEntry_1;
ULONG nativeSizeOfCode_1;
CorJitResult jitResult_1;

BYTE* nativeEntry_2;
ULONG nativeSizeOfCode_2;
CorJitResult jitResult_2;

cr1->repCompileMethod(&nativeEntry_1, &nativeSizeOfCode_1, &jitResult_1);
cr2->repCompileMethod(&nativeEntry_2, &nativeSizeOfCode_2, &jitResult_2);

roDataSize_1 = hotCodeSize_1 - nativeSizeOfCode_1;
roDataSize_2 = hotCodeSize_2 - nativeSizeOfCode_2;

roDataBlock_1 = hotCodeBlock_1 + nativeSizeOfCode_1;
roDataBlock_2 = hotCodeBlock_2 + nativeSizeOfCode_2;

orig_roDataBlock_1 = (void*)((size_t)orig_hotCodeBlock_1 + nativeSizeOfCode_1);
orig_roDataBlock_2 = (void*)((size_t)orig_hotCodeBlock_2 + nativeSizeOfCode_2);
if (hotCodeSize_1 > 0)
{
BYTE* nativeEntry_1;
ULONG nativeSizeOfCode_1;
CorJitResult jitResult_1;
cr1->repCompileMethod(&nativeEntry_1, &nativeSizeOfCode_1, &jitResult_1);
roDataSize_1 = hotCodeSize_1 - nativeSizeOfCode_1;
roDataBlock_1 = hotCodeBlock_1 + nativeSizeOfCode_1;
orig_roDataBlock_1 = (void*)((size_t)orig_hotCodeBlock_1 + nativeSizeOfCode_1);
hotCodeSize_1 = nativeSizeOfCode_1;
}

hotCodeSize_1 = nativeSizeOfCode_1;
hotCodeSize_2 = nativeSizeOfCode_2;
if (hotCodeSize_2 > 0)
{
BYTE* nativeEntry_2;
ULONG nativeSizeOfCode_2;
CorJitResult jitResult_2;
cr2->repCompileMethod(&nativeEntry_2, &nativeSizeOfCode_2, &jitResult_2);
roDataSize_2 = hotCodeSize_2 - nativeSizeOfCode_2;
roDataBlock_2 = hotCodeBlock_2 + nativeSizeOfCode_2;
orig_roDataBlock_2 = (void*)((size_t)orig_hotCodeBlock_2 + nativeSizeOfCode_2);
hotCodeSize_2 = nativeSizeOfCode_2;
}
}

LogDebug("HCS1 %d CCS1 %d RDS1 %d xcpnt1 %d flag1 %08X, HCB %p CCB %p RDB %p ohcb %p occb %p odb %p", hotCodeSize_1,
Expand Down

0 comments on commit 66576a8

Please sign in to comment.