From: Carol Eidt Date: Sat, 8 Aug 2020 15:08:42 +0000 (-0700) Subject: Superpmi: adjust relocations (#40563) X-Git-Tag: submit/tizen/20210909.063632~6128 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=110c7dcb1d19694907641e5040acddef39e4fedd;p=platform%2Fupstream%2Fdotnet%2Fruntime.git Superpmi: adjust relocations (#40563) Fix #39908 --- 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 {