From 110c7dcb1d19694907641e5040acddef39e4fedd Mon Sep 17 00:00:00 2001 From: Carol Eidt Date: Sat, 8 Aug 2020 08:08:42 -0700 Subject: [PATCH] Superpmi: adjust relocations (#40563) Fix #39908 --- .../src/ToolBox/superpmi/superpmi-shared/compileresult.cpp | 10 ++++++++++ src/coreclr/src/jit/emit.cpp | 2 +- 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/src/coreclr/src/ToolBox/superpmi/superpmi-shared/compileresult.cpp b/src/coreclr/src/ToolBox/superpmi/superpmi-shared/compileresult.cpp index e27491b..75d8ab5 100644 --- a/src/coreclr/src/ToolBox/superpmi/superpmi-shared/compileresult.cpp +++ b/src/coreclr/src/ToolBox/superpmi/superpmi-shared/compileresult.cpp @@ -796,6 +796,16 @@ void CompileResult::applyRelocs(unsigned char* block1, ULONG blocksize1, void* o size_t address = section_begin + (size_t)fixupLocation - (size_t)originalAddr; if ((section_begin <= address) && (address < section_end)) // A reloc for our section? { +#if defined(TARGET_AMD64) + // During an actual compile, recordRelocation() will be called before the compile + // is actually finished, and it will write the relative offset into the fixupLocation. + // Then, emitEndCodeGen() will patch forward jumps by subtracting any adjustment due + // to overestimation of instruction sizes. Because we're applying the relocs after the + // compile has finished, we need to reverse that: i.e. add in the (negative) adjustment + // that's now in the fixupLocation. + INT32 adjustment = *(INT32*)address; + delta += adjustment; +#endif LogDebug(" fixupLoc-%016llX (@%p) : %08X => %08X", fixupLocation, address, *(DWORD*)address, delta); *(DWORD*)address = (DWORD)delta; diff --git a/src/coreclr/src/jit/emit.cpp b/src/coreclr/src/jit/emit.cpp index ab1c281..7a957b1 100644 --- a/src/coreclr/src/jit/emit.cpp +++ b/src/coreclr/src/jit/emit.cpp @@ -3867,7 +3867,7 @@ AGAIN: { if (tgtIG) { - printf("to G_M%03u_IG%02u\n", emitComp->compMethodID, tgtIG->igNum); + printf(" to G_M%03u_IG%02u\n", emitComp->compMethodID, tgtIG->igNum); } else { -- 2.7.4