From c9e0a3b2e8cb66349820ad3ede4dc35de7d74359 Mon Sep 17 00:00:00 2001 From: Bruce Forstall Date: Fri, 8 Apr 2022 09:35:25 -0700 Subject: [PATCH] Add JitDump output for calls to recordRelocation (#67639) E.g., ``` recordRelocation: 000001ECBD3AE28C (rw: 000001ECBD3AE28C) => 000001ECBD38BC04, type 16 (IMAGE_REL_BASED_DISP32), delta 0 ``` --- src/coreclr/jit/emit.cpp | 31 +++++++++++++++++++------- src/coreclr/jit/emit.h | 41 ++++++++++++++++++++++++++++------- src/coreclr/jit/emitxarch.cpp | 6 ++--- 3 files changed, 59 insertions(+), 19 deletions(-) diff --git a/src/coreclr/jit/emit.cpp b/src/coreclr/jit/emit.cpp index a507cadf36aed..65dee765a7695 100644 --- a/src/coreclr/jit/emit.cpp +++ b/src/coreclr/jit/emit.cpp @@ -9076,20 +9076,35 @@ void emitter::emitStackKillArgs(BYTE* addr, unsigned count, unsigned char callIn /***************************************************************************** * A helper for recording a relocation with the EE. */ -void emitter::emitRecordRelocation(void* location, /* IN */ - void* target, /* IN */ - WORD fRelocType, /* IN */ - WORD slotNum /* = 0 */, /* IN */ - INT32 addlDelta /* = 0 */) /* IN */ + +#ifdef DEBUG + +void emitter::emitRecordRelocationHelp(void* location, /* IN */ + void* target, /* IN */ + uint16_t fRelocType, /* IN */ + const char* relocTypeName, /* IN */ + int32_t addlDelta /* = 0 */) /* IN */ + +#else // !DEBUG + +void emitter::emitRecordRelocation(void* location, /* IN */ + void* target, /* IN */ + uint16_t fRelocType, /* IN */ + int32_t addlDelta /* = 0 */) /* IN */ + +#endif // !DEBUG { - assert(slotNum == 0); // It is unused on all supported platforms. + void* locationRW = (BYTE*)location + writeableOffset; + + JITDUMP("recordRelocation: %p (rw: %p) => %p, type %u (%s), delta %d\n", dspPtr(location), dspPtr(locationRW), + dspPtr(target), fRelocType, relocTypeName, addlDelta); // If we're an unmatched altjit, don't tell the VM anything. We still record the relocation for // late disassembly; maybe we'll need it? if (emitComp->info.compMatchedVM) { - void* locationRW = (BYTE*)location + writeableOffset; - emitCmpHandle->recordRelocation(location, locationRW, target, fRelocType, slotNum, addlDelta); + // slotNum is unused on all supported platforms. + emitCmpHandle->recordRelocation(location, locationRW, target, fRelocType, /* slotNum */ 0, addlDelta); } #if defined(LATE_DISASM) codeGen->getDisAssembler().disRecordRelocation((size_t)location, (size_t)target); diff --git a/src/coreclr/jit/emit.h b/src/coreclr/jit/emit.h index 1571fc00cbafa..880e4a203a6cd 100644 --- a/src/coreclr/jit/emit.h +++ b/src/coreclr/jit/emit.h @@ -2383,15 +2383,40 @@ class emitter COMP_HANDLE emitCmpHandle; - /************************************************************************/ - /* Helpers for interface to EE */ - /************************************************************************/ +/************************************************************************/ +/* Helpers for interface to EE */ +/************************************************************************/ + +#ifdef DEBUG + +#define emitRecordRelocation(location, target, fRelocType) \ + emitRecordRelocationHelp(location, target, fRelocType, #fRelocType) + +#define emitRecordRelocationWithAddlDelta(location, target, fRelocType, addlDelta) \ + emitRecordRelocationHelp(location, target, fRelocType, #fRelocType, addlDelta) - void emitRecordRelocation(void* location, /* IN */ - void* target, /* IN */ - WORD fRelocType, /* IN */ - WORD slotNum = 0, /* IN */ - INT32 addlDelta = 0); /* IN */ + void emitRecordRelocationHelp(void* location, /* IN */ + void* target, /* IN */ + uint16_t fRelocType, /* IN */ + const char* relocTypeName, /* IN */ + int32_t addlDelta = 0); /* IN */ + +#else // !DEBUG + + void emitRecordRelocationWithAddlDelta(void* location, /* IN */ + void* target, /* IN */ + uint16_t fRelocType, /* IN */ + int32_t addlDelta) /* IN */ + { + emitRecordRelocation(location, target, fRelocType, addlDelta); + } + + void emitRecordRelocation(void* location, /* IN */ + void* target, /* IN */ + uint16_t fRelocType, /* IN */ + int32_t addlDelta = 0); /* IN */ + +#endif // !DEBUG #ifdef TARGET_ARM void emitHandlePCRelativeMov32(void* location, /* IN */ diff --git a/src/coreclr/jit/emitxarch.cpp b/src/coreclr/jit/emitxarch.cpp index 2f097108ef937..855f85f1406f9 100644 --- a/src/coreclr/jit/emitxarch.cpp +++ b/src/coreclr/jit/emitxarch.cpp @@ -10607,8 +10607,8 @@ BYTE* emitter::emitOutputAM(BYTE* dst, instrDesc* id, code_t code, CnsVal* addc) #else dst += emitOutputLong(dst, dsp); #endif - emitRecordRelocation((void*)(dst - sizeof(INT32)), (void*)dsp, IMAGE_REL_BASED_DISP32, 0, - addlDelta); + emitRecordRelocationWithAddlDelta((void*)(dst - sizeof(INT32)), (void*)dsp, IMAGE_REL_BASED_DISP32, + addlDelta); } else { @@ -11847,7 +11847,7 @@ BYTE* emitter::emitOutputCV(BYTE* dst, instrDesc* id, code_t code, CnsVal* addc) if (id->idIsDspReloc()) { - emitRecordRelocation((void*)(dst - sizeof(int)), target, IMAGE_REL_BASED_DISP32, 0, addlDelta); + emitRecordRelocationWithAddlDelta((void*)(dst - sizeof(int)), target, IMAGE_REL_BASED_DISP32, addlDelta); } } else