Skip to content

Commit

Permalink
Generalize SuperPMI for cross-compilation scenarios (#46114)
Browse files Browse the repository at this point in the history
Now, you can do Linux arm32 asm diffs on Windows x86, using the
pre-created Linux arm collection, as follows:

```
src\coreclr\scripts\superpmi.py asmdiffs -arch x86 -target_arch arm -jit_name clrjit_unix_arm_x86.dll -target_os Linux
```

You can do the same on Windows x64, using:
```
src\coreclr\scripts\superpmi.py asmdiffs -arch x64 -target_arch arm -jit_name clrjit_unix_arm_x64.dll -target_os Linux
```
but there are many failures in that scenario that still need to be investigated.

This change:
1. Fixes a bug with 32-bit pointer to 64-bit unsigned integer sign extension
(we don't want sign extension).
2. Allows more general specification of target to account for more general
coredistools (removes the "arm64 on x64" and "arm32 on x86" only rule).

Fixes #46095
  • Loading branch information
BruceForstall authored Dec 16, 2020
1 parent 93e767b commit 03e4f5e
Show file tree
Hide file tree
Showing 10 changed files with 745 additions and 707 deletions.
3 changes: 2 additions & 1 deletion src/coreclr/ToolBox/superpmi/mcs/verbdumpmap.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
#include "methodcontextiterator.h"
#include "verbdumpmap.h"
#include "verbildump.h"
#include "spmiutil.h"

// Dump the CSV format header for all the columns we're going to dump.
void DumpMapHeader()
Expand Down Expand Up @@ -37,7 +38,7 @@ void DumpMap(int index, MethodContext* mc)
// Also, dump the full method signature
printf("\"");
DumpAttributeToConsoleBare(mc->repGetMethodAttribs(cmi.ftn));
DumpPrimToConsoleBare(mc, cmi.args.retType, (DWORDLONG)cmi.args.retTypeClass);
DumpPrimToConsoleBare(mc, cmi.args.retType, CastHandle(cmi.args.retTypeClass));
printf(" %s(", methodName);
DumpSigToConsoleBare(mc, &cmi.args);
printf(")\"\n");
Expand Down
5 changes: 3 additions & 2 deletions src/coreclr/ToolBox/superpmi/mcs/verbildump.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
#include "methodcontext.h"
#include "methodcontextiterator.h"
#include "verbildump.h"
#include "spmiutil.h"

void DumpPrimToConsoleBare(MethodContext* mc, CorInfoType prim, DWORDLONG classHandle)
{
Expand Down Expand Up @@ -94,7 +95,7 @@ void DumpSigToConsoleBare(MethodContext* mc, CORINFO_SIG_INFO* pSig)
CorInfoTypeWithMod type = mc->repGetArgType(pSig, currentItem, (CORINFO_CLASS_HANDLE*)&dl, &exceptionCode);
CorInfoType cit = strip(type);
if (cit == CORINFO_TYPE_CLASS)
dl = (DWORDLONG)mc->repGetArgClass(pSig, currentItem, &exceptionCode);
dl = CastHandle(mc->repGetArgClass(pSig, currentItem, &exceptionCode));
if ((type & CORINFO_TYPE_MOD_PINNED) == CORINFO_TYPE_MOD_PINNED)
printf("pinned ");
DumpPrimToConsoleBare(mc, cit, dl);
Expand Down Expand Up @@ -942,7 +943,7 @@ void DumpIL(MethodContext* mc)
printf("{\n");
printf(" .method ");
DumpAttributeToConsoleBare(mc->repGetMethodAttribs(cmi.ftn));
DumpPrimToConsoleBare(mc, cmi.args.retType, (DWORDLONG)cmi.args.retTypeClass);
DumpPrimToConsoleBare(mc, cmi.args.retType, CastHandle(cmi.args.retTypeClass));
printf(" %s(", methodName);
DumpSigToConsoleBare(mc, &cmi.args);
printf(")\n");
Expand Down
3 changes: 2 additions & 1 deletion src/coreclr/ToolBox/superpmi/superpmi-shared/callutils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
#include "typeutils.h"
#include "errorhandling.h"
#include "logging.h"
#include "spmiutil.h"

// String representations of the JIT helper functions
const char* kHelperName[CORINFO_HELP_COUNT] = {
Expand Down Expand Up @@ -143,7 +144,7 @@ CallType CallUtils::GetDirectCallSiteInfo(MethodContext* mc,
CORINFO_METHOD_HANDLE methodHandle;

// Try to first obtain a method handle associated with this call target
functionEntryPoint.A = (DWORDLONG)callTarget;
functionEntryPoint.A = CastPointer(callTarget);
functionEntryPoint.B = 0; // TODO-Cleanup: we should be more conscious of this...

if (mc->fndGetFunctionEntryPoint(functionEntryPoint, &methodHandle))
Expand Down
65 changes: 33 additions & 32 deletions src/coreclr/ToolBox/superpmi/superpmi-shared/compileresult.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
#include "standardpch.h"
#include "compileresult.h"
#include "methodcontext.h"
#include "spmiutil.h"

CompileResult::CompileResult()
{
Expand Down Expand Up @@ -159,9 +160,9 @@ void CompileResult::recAllocMemCapture()
(DWORD)AllocMem->AddBuffer((const unsigned char*)allocMemDets.coldCodeBlock, allocMemDets.coldCodeSize);
value.roDataBlock_offset =
(DWORD)AllocMem->AddBuffer((const unsigned char*)allocMemDets.roDataBlock, allocMemDets.roDataSize);
value.hotCodeBlock = (DWORDLONG)allocMemDets.hotCodeBlock;
value.coldCodeBlock = (DWORDLONG)allocMemDets.coldCodeBlock;
value.roDataBlock = (DWORDLONG)allocMemDets.roDataBlock;
value.hotCodeBlock = CastPointer(allocMemDets.hotCodeBlock);
value.coldCodeBlock = CastPointer(allocMemDets.coldCodeBlock);
value.roDataBlock = CastPointer(allocMemDets.roDataBlock);

AllocMem->Add(0, value);
}
Expand Down Expand Up @@ -227,7 +228,7 @@ void CompileResult::recSetBoundaries(CORINFO_METHOD_HANDLE ftn, ULONG32 cMap, IC

Agnostic_SetBoundaries value;

value.ftn = (DWORDLONG)ftn;
value.ftn = CastHandle(ftn);
value.cMap = (DWORD)cMap;
value.pMap_offset =
(DWORD)SetBoundaries->AddBuffer((const unsigned char*)pMap, sizeof(ICorDebugInfo::OffsetMapping) * cMap);
Expand Down Expand Up @@ -274,7 +275,7 @@ void CompileResult::recSetVars(CORINFO_METHOD_HANDLE ftn, ULONG32 cVars, ICorDeb

Agnostic_SetVars value;

value.ftn = (DWORDLONG)ftn;
value.ftn = CastHandle(ftn);
value.cVars = (DWORD)cVars;
value.vars_offset = (DWORD)SetVars->AddBuffer((const unsigned char*)vars,
sizeof(ICorDebugInfo::NativeVarInfo) *
Expand Down Expand Up @@ -393,7 +394,7 @@ void CompileResult::recCompileMethod(BYTE** nativeEntry, ULONG* nativeSizeOfCode
CompileMethod = new LightWeightMap<DWORD, Agnostic_CompileMethodResults>();

Agnostic_CompileMethodResults value;
value.nativeEntry = (DWORDLONG)*nativeEntry;
value.nativeEntry = CastPointer(*nativeEntry);
value.nativeSizeOfCode = (DWORD)*nativeSizeOfCode;
value.CorJitResult = (DWORD)result;

Expand Down Expand Up @@ -443,7 +444,7 @@ void CompileResult::recClassMustBeLoadedBeforeCodeIsRun(CORINFO_CLASS_HANDLE cls
if (ClassMustBeLoadedBeforeCodeIsRun == nullptr)
ClassMustBeLoadedBeforeCodeIsRun = new DenseLightWeightMap<DWORDLONG>();

ClassMustBeLoadedBeforeCodeIsRun->Append((DWORDLONG)cls);
ClassMustBeLoadedBeforeCodeIsRun->Append(CastHandle(cls));
}
void CompileResult::dmpClassMustBeLoadedBeforeCodeIsRun(DWORD key, DWORDLONG value)
{
Expand All @@ -460,8 +461,8 @@ void CompileResult::recReportInliningDecision(CORINFO_METHOD_HANDLE inlinerHnd,

Agnostic_ReportInliningDecision value;

value.inlinerHnd = (DWORDLONG)inlinerHnd;
value.inlineeHnd = (DWORDLONG)inlineeHnd;
value.inlinerHnd = CastHandle(inlinerHnd);
value.inlineeHnd = CastHandle(inlineeHnd);
value.inlineResult = (DWORD)inlineResult;
if (reason != nullptr)
value.reason_offset =
Expand All @@ -488,7 +489,7 @@ CorInfoInline CompileResult::repReportInliningDecision(CORINFO_METHOD_HANDLE inl
unsigned int cnt = ReportInliningDecision->GetCount();
for (unsigned int i = 0; i < cnt; i++)
{
if ((items[i].inlinerHnd == (DWORDLONG)inlinerHnd) && (items[i].inlineeHnd == (DWORDLONG)inlineeHnd) &&
if ((items[i].inlinerHnd == CastHandle(inlinerHnd)) && (items[i].inlineeHnd == CastHandle(inlineeHnd)) &&
(items[i].inlineResult == INLINE_PASS))
result = INLINE_PASS;
}
Expand Down Expand Up @@ -574,17 +575,17 @@ void CompileResult::recSetMethodAttribs(CORINFO_METHOD_HANDLE ftn, CorInfoMethod
if (SetMethodAttribs == nullptr)
SetMethodAttribs = new LightWeightMap<DWORDLONG, DWORD>();

SetMethodAttribs->Add((DWORDLONG)ftn, (DWORD)attribs);
SetMethodAttribs->Add(CastHandle(ftn), (DWORD)attribs);
}
void CompileResult::dmpSetMethodAttribs(DWORDLONG key, DWORD value)
{
printf("SetMethodAttribs key ftn-%016llX, value attr-%08X", key, value);
}
CorInfoMethodRuntimeFlags CompileResult::repSetMethodAttribs(CORINFO_METHOD_HANDLE ftn)
{
if ((SetMethodAttribs == nullptr) || (SetMethodAttribs->GetIndex((DWORDLONG)ftn) == -1))
if ((SetMethodAttribs == nullptr) || (SetMethodAttribs->GetIndex(CastHandle(ftn)) == -1))
return (CorInfoMethodRuntimeFlags)0;
CorInfoMethodRuntimeFlags result = (CorInfoMethodRuntimeFlags)SetMethodAttribs->Get((DWORDLONG)ftn);
CorInfoMethodRuntimeFlags result = (CorInfoMethodRuntimeFlags)SetMethodAttribs->Get(CastHandle(ftn));
return result;
}

Expand All @@ -593,7 +594,7 @@ void CompileResult::recMethodMustBeLoadedBeforeCodeIsRun(CORINFO_METHOD_HANDLE m
if (MethodMustBeLoadedBeforeCodeIsRun == nullptr)
MethodMustBeLoadedBeforeCodeIsRun = new DenseLightWeightMap<DWORDLONG>();

MethodMustBeLoadedBeforeCodeIsRun->Append((DWORDLONG)method);
MethodMustBeLoadedBeforeCodeIsRun->Append(CastHandle(method));
}
void CompileResult::dmpMethodMustBeLoadedBeforeCodeIsRun(DWORD key, DWORDLONG value)
{
Expand All @@ -611,8 +612,8 @@ void CompileResult::recReportTailCallDecision(CORINFO_METHOD_HANDLE callerHnd,

Agnostic_ReportTailCallDecision value;

value.callerHnd = (DWORDLONG)callerHnd;
value.calleeHnd = (DWORDLONG)calleeHnd;
value.callerHnd = CastHandle(callerHnd);
value.calleeHnd = CastHandle(calleeHnd);
value.fIsTailPrefix = (DWORD)fIsTailPrefix;
value.tailCallResult = (DWORD)tailCallResult;
if (reason != nullptr) // protect strlen
Expand Down Expand Up @@ -688,8 +689,8 @@ void CompileResult::repRecordRelocation(void* location, void* target, WORD fRelo

Agnostic_RecordRelocation value;

value.location = (DWORDLONG)location;
value.target = (DWORDLONG)target;
value.location = CastPointer(location);
value.target = CastPointer(target);
value.fRelocType = (DWORD)fRelocType;
value.slotNum = (DWORD)slotNum;
value.addlDelta = (DWORD)addlDelta;
Expand Down Expand Up @@ -882,10 +883,10 @@ void CompileResult::recAddressMap(void* originalAddress, void* replayAddress, un

Agnostic_AddressMap value;

value.Address = (DWORDLONG)originalAddress;
value.Address = CastPointer(originalAddress);
value.size = (DWORD)size;

AddressMap->Add((DWORDLONG)replayAddress, value);
AddressMap->Add(CastPointer(replayAddress), value);
}
void CompileResult::dmpAddressMap(DWORDLONG key, const Agnostic_AddressMap& value)
{
Expand All @@ -896,12 +897,12 @@ void* CompileResult::repAddressMap(void* replayAddress)
if (AddressMap == nullptr)
return nullptr;

int index = AddressMap->GetIndex((DWORDLONG)replayAddress);
int index = AddressMap->GetIndex(CastPointer(replayAddress));

if (index != -1)
{
Agnostic_AddressMap value;
value = AddressMap->Get((DWORDLONG)replayAddress);
value = AddressMap->Get(CastPointer(replayAddress));
return (void*)value.Address;
}

Expand All @@ -915,8 +916,8 @@ void* CompileResult::searchAddressMap(void* newAddress)
{
DWORDLONG replayAddress = AddressMap->GetRawKeys()[i];
Agnostic_AddressMap value = AddressMap->Get(replayAddress);
if ((replayAddress <= (DWORDLONG)newAddress) && ((DWORDLONG)newAddress < (replayAddress + value.size)))
return (void*)(value.Address + ((DWORDLONG)newAddress - replayAddress));
if ((replayAddress <= CastPointer(newAddress)) && (CastPointer(newAddress) < (replayAddress + value.size)))
return (void*)(value.Address + (CastPointer(newAddress) - replayAddress));
}
return (void*)-1;
}
Expand Down Expand Up @@ -952,8 +953,8 @@ void CompileResult::recAllocUnwindInfo(BYTE* pHotCode,
AllocUnwindInfo = new DenseLightWeightMap<Agnostic_AllocUnwindInfo>();

Agnostic_AllocUnwindInfo value;
value.pHotCode = (DWORDLONG)pHotCode;
value.pColdCode = (DWORDLONG)pColdCode;
value.pHotCode = CastPointer(pHotCode);
value.pColdCode = CastPointer(pColdCode);
value.startOffset = (DWORD)startOffset;
value.endOffset = (DWORD)endOffset;
value.unwindSize = (DWORD)unwindSize;
Expand Down Expand Up @@ -1007,8 +1008,8 @@ void CompileResult::repRecordCallSite(ULONG instrOffset, CORINFO_SIG_INFO* callS
Agnostic_RecordCallSite value;
ZeroMemory(&value, sizeof(Agnostic_RecordCallSite));
value.callSig.callConv = (DWORD)callSig->callConv;
value.callSig.retTypeClass = (DWORDLONG)callSig->retTypeClass;
value.callSig.retTypeSigClass = (DWORDLONG)callSig->retTypeSigClass;
value.callSig.retTypeClass = CastHandle(callSig->retTypeClass);
value.callSig.retTypeSigClass = CastHandle(callSig->retTypeSigClass);
value.callSig.retType = (DWORD)callSig->retType;
value.callSig.flags = (DWORD)callSig->flags;
value.callSig.numArgs = (DWORD)callSig->numArgs;
Expand All @@ -1020,17 +1021,17 @@ void CompileResult::repRecordCallSite(ULONG instrOffset, CORINFO_SIG_INFO* callS
value.callSig.sigInst_methInst_Index =
RecordCallSiteWithSignature->AddBuffer((unsigned char*)callSig->sigInst.methInst,
callSig->sigInst.methInstCount * 8); // porting issue
value.callSig.args = (DWORDLONG)callSig->args;
value.callSig.args = CastHandle(callSig->args);
value.callSig.cbSig = (DWORD)callSig->cbSig;
value.callSig.pSig_Index = (DWORD)RecordCallSiteWithSignature->AddBuffer((unsigned char*)callSig->pSig, callSig->cbSig);
value.callSig.scope = (DWORDLONG)callSig->scope;
value.callSig.scope = CastHandle(callSig->scope);
value.callSig.token = (DWORD)callSig->token;
value.methodHandle = (DWORDLONG)methodHandle;
value.methodHandle = CastHandle(methodHandle);
RecordCallSiteWithSignature->Add(instrOffset, value);
}
else
{
RecordCallSiteWithoutSignature->Add(instrOffset, (DWORDLONG)methodHandle);
RecordCallSiteWithoutSignature->Add(instrOffset, CastHandle(methodHandle));
}
}

Expand Down
Loading

0 comments on commit 03e4f5e

Please sign in to comment.