Skip to content

Commit

Permalink
Add JitDump output for calls to recordRelocation (#67639)
Browse files Browse the repository at this point in the history
E.g.,

```
recordRelocation: 000001ECBD3AE28C (rw: 000001ECBD3AE28C) => 000001ECBD38BC04, type 16 (IMAGE_REL_BASED_DISP32), delta 0
```
  • Loading branch information
BruceForstall authored Apr 8, 2022
1 parent 20c4bde commit c9e0a3b
Show file tree
Hide file tree
Showing 3 changed files with 59 additions and 19 deletions.
31 changes: 23 additions & 8 deletions src/coreclr/jit/emit.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
41 changes: 33 additions & 8 deletions src/coreclr/jit/emit.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 */
Expand Down
6 changes: 3 additions & 3 deletions src/coreclr/jit/emitxarch.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit c9e0a3b

Please sign in to comment.