From 10f1c7061c0445e647bf4acaf4af7fa61e02b063 Mon Sep 17 00:00:00 2001 From: Jakob Botsch Nielsen Date: Mon, 24 Nov 2025 13:41:02 +0100 Subject: [PATCH 1/8] Clean up JIT<->EE relocation type Introduce a `CorInfoReloc` enum and use it exclusively to communicate relocation types between the EE and JIT. Translate it in crossgen2/ILC to the file-format relocation type when necessary. --- src/coreclr/inc/corinfo.h | 86 +++-- src/coreclr/inc/corjit.h | 4 +- src/coreclr/inc/icorjitinfoimpl_generated.h | 4 +- src/coreclr/inc/jiteeversionguid.h | 10 +- .../jit/ICorJitInfo_wrapper_generated.hpp | 6 +- src/coreclr/jit/codegeninterface.h | 2 +- src/coreclr/jit/codegenxarch.cpp | 6 +- src/coreclr/jit/compiler.h | 2 +- src/coreclr/jit/ee_il_dll.cpp | 4 +- src/coreclr/jit/emit.cpp | 28 +- src/coreclr/jit/emit.h | 26 +- src/coreclr/jit/emitarm.cpp | 4 +- src/coreclr/jit/emitarm64.cpp | 24 +- src/coreclr/jit/emitxarch.cpp | 77 ++-- src/coreclr/jit/gentree.cpp | 8 +- src/coreclr/jit/instr.cpp | 2 +- src/coreclr/jit/targetx86.h | 6 - .../tools/Common/JitInterface/CorInfoImpl.cs | 112 ++---- .../JitInterface/CorInfoImpl_generated.cs | 8 +- .../tools/Common/JitInterface/CorInfoTypes.cs | 40 +++ .../ThunkGenerator/ThunkInput.txt | 5 +- .../aot/jitinterface/jitinterface_generated.h | 10 +- .../superpmi-shared/compileresult.cpp | 102 +++--- .../superpmi/superpmi-shared/compileresult.h | 4 +- .../superpmi-shared/methodcontext.cpp | 12 +- .../superpmi/superpmi-shared/methodcontext.h | 4 +- .../superpmi-shim-collector/icorjitinfo.cpp | 6 +- .../icorjitinfo_generated.cpp | 4 +- .../icorjitinfo_generated.cpp | 4 +- .../tools/superpmi/superpmi/icorjitinfo.cpp | 14 +- src/coreclr/vm/jitinterface.cpp | 332 +++++++++--------- src/coreclr/vm/jitinterface.h | 4 +- 32 files changed, 472 insertions(+), 488 deletions(-) diff --git a/src/coreclr/inc/corinfo.h b/src/coreclr/inc/corinfo.h index 339c624aa45049..a045a48dd93d55 100644 --- a/src/coreclr/inc/corinfo.h +++ b/src/coreclr/inc/corinfo.h @@ -852,6 +852,48 @@ enum InfoAccessType IAT_RELPVALUE // The value needs to be accessed via a relative indirection }; +enum class CorInfoReloc +{ + NONE, + + // General relocation types + DIR32, // Direct/absolute 32 bit address + DIR64, // Direct/absolute 64 bit address + REL32, // 32-bit relative address from byte following reloc + + // Arm64 relocs + ARM64_BRANCH26, // Arm64: B, BL + ARM64_PAGEBASE_REL21, // ADRP + ARM64_PAGEOFFSET_12A, // ADD/ADDS (immediate) with zero shift, for page offset + // Linux arm64 + ARM64_LIN_TLSDESC_ADR_PAGE21, + ARM64_LIN_TLSDESC_LD64_LO12, + ARM64_LIN_TLSDESC_ADD_LO12, + ARM64_LIN_TLSDESC_CALL, + // Windows arm64 + ARM64_WIN_TLS_SECREL_HIGH12A, // ADD high 12-bit offset for tls + ARM64_WIN_TLS_SECREL_LOW12A, // ADD low 12-bit offset for tls + + // Windows x64 + AMD64_WIN_SECREL, + + // Linux x64 + // GD model + AMD64_LIN_TLSGD, + + // Arm32 relocs + ARM32_THUMB_BRANCH24, // Thumb2: B, BL + ARM32_THUMB_MOV32, // Thumb2: MOVW/MOVT + ARM32_THUMB_MOV32_PCREL, // Thumb2: MOVW/MOVT + + // LoongArch64 relocs + LOONGARCH64_PC, // LoongArch64: pcalau12i+imm12 + LOONGARCH64_JIR, // LoongArch64: pcaddu18i+jirl + + // RISCV64 relocs + RISCV64_PC, // RiscV64: auipc +}; + enum CorInfoGCType { TYPE_GC_NONE, // no embedded objectrefs @@ -3394,50 +3436,6 @@ class ICorDynamicInfo : public ICorStaticInfo virtual CORINFO_METHOD_HANDLE getSpecialCopyHelper(CORINFO_CLASS_HANDLE type) = 0; }; -/**********************************************************************************/ - -// It would be nicer to use existing IMAGE_REL_XXX constants instead of defining our own here... -#define IMAGE_REL_BASED_REL32 0x10 -#define IMAGE_REL_BASED_THUMB_BRANCH24 0x13 -#define IMAGE_REL_SECREL 0x104 - -// Linux x64 -// GD model -#define IMAGE_REL_TLSGD 0x105 - -// Linux arm64 -// TLSDESC (dynamic) -#define IMAGE_REL_AARCH64_TLSDESC_ADR_PAGE21 0x107 -#define IMAGE_REL_AARCH64_TLSDESC_LD64_LO12 0x108 -#define IMAGE_REL_AARCH64_TLSDESC_ADD_LO12 0x109 -#define IMAGE_REL_AARCH64_TLSDESC_CALL 0x10A - -// The identifier for ARM32-specific PC-relative address -// computation corresponds to the following instruction -// sequence: -// l0: movw rX, #imm_lo // 4 byte -// l4: movt rX, #imm_hi // 4 byte -// l8: add rX, pc <- after this instruction rX = relocTarget -// -// Program counter at l8 is address of l8 + 4 -// Address of relocated movw/movt is l0 -// So, imm should be calculated as the following: -// imm = relocTarget - (l8 + 4) = relocTarget - (l0 + 8 + 4) = relocTarget - (l_0 + 12) -// So, the value of offset correction is 12 -// -#define IMAGE_REL_BASED_REL_THUMB_MOV32_PCREL 0x14 - -// -// LOONGARCH64 relocation types -// -#define IMAGE_REL_LOONGARCH64_PC 0x0003 -#define IMAGE_REL_LOONGARCH64_JIR 0x0004 - -// -// RISCV64 relocation types -// -#define IMAGE_REL_RISCV64_PC 0x0003 - /**********************************************************************************/ #ifdef TARGET_64BIT #define USE_PER_FRAME_PINVOKE_INIT diff --git a/src/coreclr/inc/corjit.h b/src/coreclr/inc/corjit.h index 10d980d9cfa3cc..7cbe2573ffc9db 100644 --- a/src/coreclr/inc/corjit.h +++ b/src/coreclr/inc/corjit.h @@ -425,11 +425,11 @@ class ICorJitInfo : public ICorDynamicInfo void * location, /* IN */ void * locationRW, /* IN */ void * target, /* IN */ - uint16_t fRelocType, /* IN */ + CorInfoReloc fRelocType, /* IN */ int32_t addlDelta = 0 /* IN */ ) = 0; - virtual uint16_t getRelocTypeHint(void * target) = 0; + virtual CorInfoReloc getRelocTypeHint(void * target) = 0; // For what machine does the VM expect the JIT to generate code? The VM // returns one of the CorInfoArch values. Note that if the VM is cross diff --git a/src/coreclr/inc/icorjitinfoimpl_generated.h b/src/coreclr/inc/icorjitinfoimpl_generated.h index 8ab46ba76c5c30..0be459ad10d94a 100644 --- a/src/coreclr/inc/icorjitinfoimpl_generated.h +++ b/src/coreclr/inc/icorjitinfoimpl_generated.h @@ -743,10 +743,10 @@ void recordRelocation( void* location, void* locationRW, void* target, - uint16_t fRelocType, + CorInfoReloc fRelocType, int32_t addlDelta) override; -uint16_t getRelocTypeHint( +CorInfoReloc getRelocTypeHint( void* target) override; uint32_t getExpectedTargetArchitecture() override; diff --git a/src/coreclr/inc/jiteeversionguid.h b/src/coreclr/inc/jiteeversionguid.h index 8fd5c04b5f93da..45fffd0935c944 100644 --- a/src/coreclr/inc/jiteeversionguid.h +++ b/src/coreclr/inc/jiteeversionguid.h @@ -37,11 +37,11 @@ #include -constexpr GUID JITEEVersionIdentifier = { /* 2d5333ab-eda7-4fd9-afc9-4a073dc0f7ec */ - 0x2d5333ab, - 0xeda7, - 0x4fd9, - {0xaf, 0xc9, 0x4a, 0x07, 0x3d, 0xc0, 0xf7, 0xec} +constexpr GUID JITEEVersionIdentifier = { /* 567f89f4-2ddb-4d80-9107-0ce8c30a18ff */ + 0x567f89f4, + 0x2ddb, + 0x4d80, + {0x91, 0x07, 0x0c, 0xe8, 0xc3, 0x0a, 0x18, 0xff} }; #endif // JIT_EE_VERSIONING_GUID_H diff --git a/src/coreclr/jit/ICorJitInfo_wrapper_generated.hpp b/src/coreclr/jit/ICorJitInfo_wrapper_generated.hpp index 6ad0a136a09b47..0f1ff35e09c461 100644 --- a/src/coreclr/jit/ICorJitInfo_wrapper_generated.hpp +++ b/src/coreclr/jit/ICorJitInfo_wrapper_generated.hpp @@ -1723,7 +1723,7 @@ void WrapICorJitInfo::recordRelocation( void* location, void* locationRW, void* target, - uint16_t fRelocType, + CorInfoReloc fRelocType, int32_t addlDelta) { API_ENTER(recordRelocation); @@ -1731,11 +1731,11 @@ void WrapICorJitInfo::recordRelocation( API_LEAVE(recordRelocation); } -uint16_t WrapICorJitInfo::getRelocTypeHint( +CorInfoReloc WrapICorJitInfo::getRelocTypeHint( void* target) { API_ENTER(getRelocTypeHint); - uint16_t temp = wrapHnd->getRelocTypeHint(target); + CorInfoReloc temp = wrapHnd->getRelocTypeHint(target); API_LEAVE(getRelocTypeHint); return temp; } diff --git a/src/coreclr/jit/codegeninterface.h b/src/coreclr/jit/codegeninterface.h index 7dda0e0630478b..39b963dc3d674e 100644 --- a/src/coreclr/jit/codegeninterface.h +++ b/src/coreclr/jit/codegeninterface.h @@ -270,7 +270,7 @@ class CodeGenInterface #ifdef TARGET_XARCH #ifdef TARGET_AMD64 // There are no reloc hints on x86 - unsigned short genAddrRelocTypeHint(size_t addr); + CorInfoReloc genAddrRelocTypeHint(size_t addr); #endif bool genDataIndirAddrCanBeEncodedAsPCRelOffset(size_t addr); bool genCodeIndirAddrCanBeEncodedAsPCRelOffset(size_t addr); diff --git a/src/coreclr/jit/codegenxarch.cpp b/src/coreclr/jit/codegenxarch.cpp index cfe344c76b0f0d..0837ad63e90019 100644 --- a/src/coreclr/jit/codegenxarch.cpp +++ b/src/coreclr/jit/codegenxarch.cpp @@ -11722,7 +11722,7 @@ void CodeGen::instGen_MemoryBarrier(BarrierKind barrierKind) // Returns // relocation type hint // -unsigned short CodeGenInterface::genAddrRelocTypeHint(size_t addr) +CorInfoReloc CodeGenInterface::genAddrRelocTypeHint(size_t addr) { return compiler->eeGetRelocTypeHint((void*)addr); } @@ -11742,7 +11742,7 @@ unsigned short CodeGenInterface::genAddrRelocTypeHint(size_t addr) bool CodeGenInterface::genDataIndirAddrCanBeEncodedAsPCRelOffset(size_t addr) { #ifdef TARGET_AMD64 - return genAddrRelocTypeHint(addr) == IMAGE_REL_BASED_REL32; + return genAddrRelocTypeHint(addr) == CorInfoReloc::REL32; #else // x86: PC-relative addressing is available only for control flow instructions (jmp and call) return false; @@ -11763,7 +11763,7 @@ bool CodeGenInterface::genDataIndirAddrCanBeEncodedAsPCRelOffset(size_t addr) bool CodeGenInterface::genCodeIndirAddrCanBeEncodedAsPCRelOffset(size_t addr) { #ifdef TARGET_AMD64 - return genAddrRelocTypeHint(addr) == IMAGE_REL_BASED_REL32; + return genAddrRelocTypeHint(addr) == CorInfoReloc::REL32; #else // x86: PC-relative addressing is available only for control flow instructions (jmp and call) return true; diff --git a/src/coreclr/jit/compiler.h b/src/coreclr/jit/compiler.h index 5130ca5eb122d6..a0054a48f9a732 100644 --- a/src/coreclr/jit/compiler.h +++ b/src/coreclr/jit/compiler.h @@ -8573,7 +8573,7 @@ class Compiler void eeSetEHinfo(unsigned EHnumber, const CORINFO_EH_CLAUSE* clause); - WORD eeGetRelocTypeHint(void* target); + CorInfoReloc eeGetRelocTypeHint(void* target); // ICorStaticInfo wrapper functions diff --git a/src/coreclr/jit/ee_il_dll.cpp b/src/coreclr/jit/ee_il_dll.cpp index b0959b9a9d95e5..c425d8174895f3 100644 --- a/src/coreclr/jit/ee_il_dll.cpp +++ b/src/coreclr/jit/ee_il_dll.cpp @@ -1276,7 +1276,7 @@ void Compiler::eeSetEHinfo(unsigned EHnumber, const CORINFO_EH_CLAUSE* clause) } } -WORD Compiler::eeGetRelocTypeHint(void* target) +CorInfoReloc Compiler::eeGetRelocTypeHint(void* target) { if (info.compMatchedVM) { @@ -1285,7 +1285,7 @@ WORD Compiler::eeGetRelocTypeHint(void* target) else { // No hints - return (WORD)-1; + return CorInfoReloc::NONE; } } diff --git a/src/coreclr/jit/emit.cpp b/src/coreclr/jit/emit.cpp index 631332e98f0174..2709cbbd1656d8 100644 --- a/src/coreclr/jit/emit.cpp +++ b/src/coreclr/jit/emit.cpp @@ -8525,7 +8525,7 @@ void emitter::emitOutputDataSec(dataSecDsc* sec, BYTE* dst) bDstRW[i] = (target_size_t)(size_t)target; if (emitComp->opts.compReloc) { - uint16_t relocType = TARGET_POINTER_SIZE == 8 ? IMAGE_REL_BASED_DIR64 : IMAGE_REL_BASED_HIGHLOW; + CorInfoReloc relocType = TARGET_POINTER_SIZE == 8 ? CorInfoReloc::DIR64 : CorInfoReloc::DIR32; emitRecordRelocation(&(bDstRW[i]), target, relocType); } @@ -8572,7 +8572,7 @@ void emitter::emitOutputDataSec(dataSecDsc* sec, BYTE* dst) aDstRW[i].DiagnosticIP = (target_size_t)(uintptr_t)target; if (emitComp->opts.compReloc) { - uint16_t relocType = TARGET_POINTER_SIZE == 8 ? IMAGE_REL_BASED_DIR64 : IMAGE_REL_BASED_HIGHLOW; + CorInfoReloc relocType = TARGET_POINTER_SIZE == 8 ? CorInfoReloc::DIR64 : CorInfoReloc::DIR32; emitRecordRelocation(&aDstRW[i].Resume, emitAsyncResumeStubEntryPoint, relocType); if (target != nullptr) { @@ -10518,25 +10518,25 @@ void emitter::emitStackKillArgs(BYTE* addr, unsigned count, unsigned char callIn #ifdef DEBUG -void emitter::emitRecordRelocationHelp(void* location, /* IN */ - void* target, /* IN */ - uint16_t fRelocType, /* IN */ - const char* relocTypeName, /* IN */ - int32_t addlDelta /* = 0 */) /* IN */ +void emitter::emitRecordRelocationHelp(void* location, /* IN */ + void* target, /* IN */ + CorInfoReloc 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 */ +void emitter::emitRecordRelocation(void* location, /* IN */ + void* target, /* IN */ + CorInfoReloc fRelocType, /* IN */ + int32_t addlDelta /* = 0 */) /* IN */ #endif // !DEBUG { 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); + dspPtr(target), (unsigned)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? @@ -10563,11 +10563,11 @@ void emitter::emitHandlePCRelativeMov32(void* location, /* IN */ { if (emitComp->opts.jitFlags->IsSet(JitFlags::JIT_FLAG_RELATIVE_CODE_RELOCS)) { - emitRecordRelocation(location, target, IMAGE_REL_BASED_REL_THUMB_MOV32_PCREL); + emitRecordRelocation(location, target, CorInfoReloc::ARM32_THUMB_MOV32_PCREL); } else { - emitRecordRelocation(location, target, IMAGE_REL_BASED_THUMB_MOV32); + emitRecordRelocation(location, target, CorInfoReloc::ARM32_THUMB_MOV32); } } #endif // TARGET_ARM diff --git a/src/coreclr/jit/emit.h b/src/coreclr/jit/emit.h index 2c843f03483d74..b806a71d15eb89 100644 --- a/src/coreclr/jit/emit.h +++ b/src/coreclr/jit/emit.h @@ -3591,26 +3591,26 @@ class emitter #define emitRecordRelocationWithAddlDelta(location, target, fRelocType, addlDelta) \ emitRecordRelocationHelp(location, target, fRelocType, #fRelocType, addlDelta) - void emitRecordRelocationHelp(void* location, /* IN */ - void* target, /* IN */ - uint16_t fRelocType, /* IN */ - const char* relocTypeName, /* IN */ - int32_t addlDelta = 0); /* IN */ + void emitRecordRelocationHelp(void* location, /* IN */ + void* target, /* IN */ + CorInfoReloc 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 */ + void emitRecordRelocationWithAddlDelta(void* location, /* IN */ + void* target, /* IN */ + CorInfoReloc 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 */ + void emitRecordRelocation(void* location, /* IN */ + void* target, /* IN */ + CorInfoReloc fRelocType, /* IN */ + int32_t addlDelta = 0); /* IN */ #endif // !DEBUG diff --git a/src/coreclr/jit/emitarm.cpp b/src/coreclr/jit/emitarm.cpp index 59fea049044420..8f2a2796ce553c 100644 --- a/src/coreclr/jit/emitarm.cpp +++ b/src/coreclr/jit/emitarm.cpp @@ -5553,7 +5553,7 @@ BYTE* emitter::emitOutputLJ(insGroup* ig, BYTE* dst, instrDesc* i) if (emitComp->info.compMatchedVM) { void* target = emitOffsetToPtr(dstOffs); - emitRecordRelocation((void*)dst, target, IMAGE_REL_BASED_THUMB_BRANCH24); + emitRecordRelocation((void*)dst, target, CorInfoReloc::ARM32_THUMB_BRANCH24); } } } @@ -6476,7 +6476,7 @@ size_t emitter::emitOutputInstr(insGroup* ig, instrDesc* id, BYTE** dp) callInstrSize = SafeCvtAssert(emitOutput_Thumb2Instr(dst, code)); dst += callInstrSize; if (emitComp->info.compMatchedVM) - emitRecordRelocation((void*)(dst - 4), addr, IMAGE_REL_BASED_THUMB_BRANCH24); + emitRecordRelocation((void*)(dst - 4), addr, CorInfoReloc::ARM32_THUMB_BRANCH24); } else { diff --git a/src/coreclr/jit/emitarm64.cpp b/src/coreclr/jit/emitarm64.cpp index e88e10568712d3..e89bd623ba810e 100644 --- a/src/coreclr/jit/emitarm64.cpp +++ b/src/coreclr/jit/emitarm64.cpp @@ -10603,7 +10603,7 @@ BYTE* emitter::emitOutputLJ(insGroup* ig, BYTE* dst, instrDesc* i) if (emitComp->info.compMatchedVM) { void* target = emitOffsetToPtr(dstOffs); - emitRecordRelocation((void*)dst, target, IMAGE_REL_ARM64_BRANCH26); + emitRecordRelocation((void*)dst, target, CorInfoReloc::ARM64_BRANCH26); } } @@ -11007,7 +11007,7 @@ size_t emitter::emitOutputInstr(insGroup* ig, instrDesc* id, BYTE** dp) sz = id->idIsLargeCall() ? sizeof(instrDescCGCA) : sizeof(instrDesc); dst += emitOutputCall(ig, dst, id, code); // Always call RecordRelocation so that we wire in a JumpStub when we don't reach - emitRecordRelocation(odst, id->idAddr()->iiaAddr, IMAGE_REL_ARM64_BRANCH26); + emitRecordRelocation(odst, id->idAddr()->iiaAddr, CorInfoReloc::ARM64_BRANCH26); break; case IF_BI_1A: // BI_1A ......iiiiiiiiii iiiiiiiiiiittttt Rt simm19:00 @@ -11043,7 +11043,7 @@ size_t emitter::emitOutputInstr(insGroup* ig, instrDesc* id, BYTE** dp) if (emitComp->IsTargetAbi(CORINFO_NATIVEAOT_ABI) && id->idIsTlsGD()) { emitRecordRelocation(odst, (CORINFO_METHOD_HANDLE)id->idAddr()->iiaAddr, - IMAGE_REL_AARCH64_TLSDESC_CALL); + CorInfoReloc::ARM64_LIN_TLSDESC_CALL); code |= insEncodeReg_Rn(REG_R2); // nnnnn } else @@ -11083,7 +11083,7 @@ size_t emitter::emitOutputInstr(insGroup* ig, instrDesc* id, BYTE** dp) dst += emitOutput_Instr(dst, code); if (id->idIsTlsGD()) { - emitRecordRelocation(odst, (void*)emitGetInsSC(id), IMAGE_REL_AARCH64_TLSDESC_LD64_LO12); + emitRecordRelocation(odst, (void*)emitGetInsSC(id), CorInfoReloc::ARM64_LIN_TLSDESC_LD64_LO12); } break; @@ -11382,8 +11382,8 @@ size_t emitter::emitOutputInstr(insGroup* ig, instrDesc* id, BYTE** dp) code |= insEncodeReg_Rd(id->idReg1()); // ddddd dst += emitOutput_Instr(dst, code); emitRecordRelocation(odst, id->idAddr()->iiaAddr, - id->idIsTlsGD() ? IMAGE_REL_AARCH64_TLSDESC_ADR_PAGE21 - : IMAGE_REL_ARM64_PAGEBASE_REL21); + id->idIsTlsGD() ? CorInfoReloc::ARM64_LIN_TLSDESC_ADR_PAGE21 + : CorInfoReloc::ARM64_PAGEBASE_REL21); } else { @@ -11426,7 +11426,7 @@ size_t emitter::emitOutputInstr(insGroup* ig, instrDesc* id, BYTE** dp) { assert(sz == sizeof(instrDesc)); assert(id->idAddr()->iiaAddr != nullptr); - emitRecordRelocation(odst, id->idAddr()->iiaAddr, IMAGE_REL_ARM64_PAGEOFFSET_12A); + emitRecordRelocation(odst, id->idAddr()->iiaAddr, CorInfoReloc::ARM64_PAGEOFFSET_12A); } else { @@ -11437,25 +11437,27 @@ size_t emitter::emitOutputInstr(insGroup* ig, instrDesc* id, BYTE** dp) if (id->idIsReloc()) { // This is first "add" of "add/add" pair - emitRecordRelocation(odst, id->idAddr()->iiaAddr, IMAGE_REL_ARM64_SECREL_HIGH12A); + emitRecordRelocation(odst, id->idAddr()->iiaAddr, + CorInfoReloc::ARM64_WIN_TLS_SECREL_HIGH12A); } else { // This is second "add" of "add/add" pair - emitRecordRelocation(odst, id->idAddr()->iiaAddr, IMAGE_REL_ARM64_SECREL_LOW12A); + emitRecordRelocation(odst, id->idAddr()->iiaAddr, + CorInfoReloc::ARM64_WIN_TLS_SECREL_LOW12A); } } else { // For unix/arm64 it is the "add" of "adrp/add" pair - emitRecordRelocation(odst, id->idAddr()->iiaAddr, IMAGE_REL_AARCH64_TLSDESC_ADD_LO12); + emitRecordRelocation(odst, id->idAddr()->iiaAddr, CorInfoReloc::ARM64_LIN_TLSDESC_ADD_LO12); } } else if (id->idIsReloc()) { assert(sz == sizeof(instrDesc)); assert(id->idAddr()->iiaAddr != nullptr); - emitRecordRelocation(odst, id->idAddr()->iiaAddr, IMAGE_REL_ARM64_PAGEOFFSET_12A); + emitRecordRelocation(odst, id->idAddr()->iiaAddr, CorInfoReloc::ARM64_PAGEOFFSET_12A); } } break; diff --git a/src/coreclr/jit/emitxarch.cpp b/src/coreclr/jit/emitxarch.cpp index 5dbad2a7d9cd3f..38210c9dbc0a6f 100644 --- a/src/coreclr/jit/emitxarch.cpp +++ b/src/coreclr/jit/emitxarch.cpp @@ -14250,6 +14250,14 @@ BYTE* emitter::emitOutputAlign(insGroup* ig, instrDesc* id, BYTE* dst) return emitOutputNOP(dst, paddingToAdd); } +#ifdef TARGET_64BIT +static constexpr CorInfoReloc RELOC_DISP32 = CorInfoReloc::REL32; +static constexpr CorInfoReloc RELOC_MOFFSET = CorInfoReloc::DIR64; +#else +static constexpr CorInfoReloc RELOC_DISP32 = CorInfoReloc::DIR32; +static constexpr CorInfoReloc RELOC_MOFFSET = CorInfoReloc::DIR32; +#endif + /***************************************************************************** * * Output an instruction involving an address mode. @@ -14683,7 +14691,7 @@ BYTE* emitter::emitOutputAM(BYTE* dst, instrDesc* id, code_t code, CnsVal* addc) if (id->idIsDspReloc()) { - emitRecordRelocation((void*)(dst - TARGET_POINTER_SIZE), (void*)dsp, IMAGE_REL_BASED_MOFFSET); + emitRecordRelocation((void*)(dst - TARGET_POINTER_SIZE), (void*)dsp, RELOC_MOFFSET); } #endif // TARGET_X86 @@ -14752,13 +14760,13 @@ BYTE* emitter::emitOutputAM(BYTE* dst, instrDesc* id, code_t code, CnsVal* addc) if (!IsSimdInstruction(ins) && id->idIsTlsGD()) { addlDelta = -4; - emitRecordRelocationWithAddlDelta((void*)(dst - sizeof(INT32)), (void*)dsp, IMAGE_REL_TLSGD, - addlDelta); + emitRecordRelocationWithAddlDelta((void*)(dst - sizeof(INT32)), (void*)dsp, + CorInfoReloc::AMD64_LIN_TLSGD, addlDelta); } else { - emitRecordRelocationWithAddlDelta((void*)(dst - sizeof(INT32)), (void*)dsp, - IMAGE_REL_BASED_DISP32, addlDelta); + emitRecordRelocationWithAddlDelta((void*)(dst - sizeof(INT32)), (void*)dsp, RELOC_DISP32, + addlDelta); } } else @@ -14777,7 +14785,7 @@ BYTE* emitter::emitOutputAM(BYTE* dst, instrDesc* id, code_t code, CnsVal* addc) // This addr mode should never be used while generating relocatable AOT code nor if // the addr can be encoded as pc-relative address. noway_assert(!emitComp->opts.compReloc); - noway_assert(codeGen->genAddrRelocTypeHint((size_t)dsp) != IMAGE_REL_BASED_REL32); + noway_assert(codeGen->genAddrRelocTypeHint((size_t)dsp) != CorInfoReloc::REL32); noway_assert((int)dsp == dsp); // This requires, specifying a SIB byte after ModRM byte. @@ -14814,7 +14822,7 @@ BYTE* emitter::emitOutputAM(BYTE* dst, instrDesc* id, code_t code, CnsVal* addc) if (id->idIsDspReloc()) { - emitRecordRelocation((void*)(dst - sizeof(INT32)), (void*)dsp, IMAGE_REL_BASED_HIGHLOW); + emitRecordRelocation((void*)(dst - sizeof(INT32)), (void*)dsp, CorInfoReloc::DIR32); } } } @@ -14832,7 +14840,7 @@ BYTE* emitter::emitOutputAM(BYTE* dst, instrDesc* id, code_t code, CnsVal* addc) if (id->idIsDspReloc()) { - emitRecordRelocation((void*)(dst - sizeof(INT32)), (void*)dsp, IMAGE_REL_BASED_HIGHLOW); + emitRecordRelocation((void*)(dst - sizeof(INT32)), (void*)dsp, CorInfoReloc::DIR32); } } break; @@ -14864,7 +14872,7 @@ BYTE* emitter::emitOutputAM(BYTE* dst, instrDesc* id, code_t code, CnsVal* addc) if (id->idIsDspReloc()) { - emitRecordRelocation((void*)(dst - sizeof(INT32)), (void*)dsp, IMAGE_REL_BASED_HIGHLOW); + emitRecordRelocation((void*)(dst - sizeof(INT32)), (void*)dsp, CorInfoReloc::DIR32); } } } @@ -14890,7 +14898,7 @@ BYTE* emitter::emitOutputAM(BYTE* dst, instrDesc* id, code_t code, CnsVal* addc) if (id->idIsDspReloc()) { - emitRecordRelocation((void*)(dst - sizeof(INT32)), (void*)dsp, IMAGE_REL_BASED_HIGHLOW); + emitRecordRelocation((void*)(dst - sizeof(INT32)), (void*)dsp, CorInfoReloc::DIR32); } } break; @@ -14922,7 +14930,7 @@ BYTE* emitter::emitOutputAM(BYTE* dst, instrDesc* id, code_t code, CnsVal* addc) if (id->idIsDspReloc()) { - emitRecordRelocation((void*)(dst - sizeof(INT32)), (void*)dsp, IMAGE_REL_BASED_HIGHLOW); + emitRecordRelocation((void*)(dst - sizeof(INT32)), (void*)dsp, CorInfoReloc::DIR32); } } } @@ -14951,7 +14959,7 @@ BYTE* emitter::emitOutputAM(BYTE* dst, instrDesc* id, code_t code, CnsVal* addc) if (id->idIsDspReloc()) { - emitRecordRelocation((void*)(dst - sizeof(INT32)), (void*)dsp, IMAGE_REL_BASED_HIGHLOW); + emitRecordRelocation((void*)(dst - sizeof(INT32)), (void*)dsp, CorInfoReloc::DIR32); } } } @@ -15001,7 +15009,7 @@ BYTE* emitter::emitOutputAM(BYTE* dst, instrDesc* id, code_t code, CnsVal* addc) if (id->idIsDspReloc()) { - emitRecordRelocation((void*)(dst - sizeof(INT32)), (void*)dsp, IMAGE_REL_BASED_HIGHLOW); + emitRecordRelocation((void*)(dst - sizeof(INT32)), (void*)dsp, CorInfoReloc::DIR32); } } } @@ -15027,7 +15035,7 @@ BYTE* emitter::emitOutputAM(BYTE* dst, instrDesc* id, code_t code, CnsVal* addc) if (id->idIsDspReloc()) { - emitRecordRelocation((void*)(dst - sizeof(INT32)), (void*)dsp, IMAGE_REL_BASED_HIGHLOW); + emitRecordRelocation((void*)(dst - sizeof(INT32)), (void*)dsp, CorInfoReloc::DIR32); } } } @@ -15057,7 +15065,7 @@ BYTE* emitter::emitOutputAM(BYTE* dst, instrDesc* id, code_t code, CnsVal* addc) dst += emitOutputLong(dst, dsp); if (id->idIsDspReloc()) { - emitRecordRelocation((void*)(dst - sizeof(INT32)), (void*)dsp, IMAGE_REL_BASED_HIGHLOW); + emitRecordRelocation((void*)(dst - sizeof(INT32)), (void*)dsp, CorInfoReloc::DIR32); } } } @@ -15090,7 +15098,7 @@ BYTE* emitter::emitOutputAM(BYTE* dst, instrDesc* id, code_t code, CnsVal* addc) if (id->idIsDspReloc()) { - emitRecordRelocation((void*)(dst - sizeof(INT32)), (void*)dsp, IMAGE_REL_BASED_HIGHLOW); + emitRecordRelocation((void*)(dst - sizeof(INT32)), (void*)dsp, CorInfoReloc::DIR32); } } } @@ -15116,7 +15124,7 @@ BYTE* emitter::emitOutputAM(BYTE* dst, instrDesc* id, code_t code, CnsVal* addc) if (id->idIsDspReloc()) { - emitRecordRelocation((void*)(dst - sizeof(INT32)), (void*)dsp, IMAGE_REL_BASED_HIGHLOW); + emitRecordRelocation((void*)(dst - sizeof(INT32)), (void*)dsp, CorInfoReloc::DIR32); } } } @@ -15152,7 +15160,7 @@ BYTE* emitter::emitOutputAM(BYTE* dst, instrDesc* id, code_t code, CnsVal* addc) if (addc->cnsReloc) { - emitRecordRelocation((void*)(dst - sizeof(INT32)), (void*)(size_t)cval, IMAGE_REL_BASED_HIGHLOW); + emitRecordRelocation((void*)(dst - sizeof(INT32)), (void*)(size_t)cval, CorInfoReloc::DIR32); assert(opsz == 4); } } @@ -15684,7 +15692,7 @@ BYTE* emitter::emitOutputSV(BYTE* dst, instrDesc* id, code_t code, CnsVal* addc) if (addc->cnsReloc) { - emitRecordRelocation((void*)(dst - sizeof(INT32)), (void*)(size_t)cval, IMAGE_REL_BASED_HIGHLOW); + emitRecordRelocation((void*)(dst - sizeof(INT32)), (void*)(size_t)cval, CorInfoReloc::DIR32); assert(opsz == 4); } } @@ -16149,7 +16157,7 @@ BYTE* emitter::emitOutputCV(BYTE* dst, instrDesc* id, code_t code, CnsVal* addc) if (id->idIsDspReloc()) { - emitRecordRelocationWithAddlDelta((void*)(dst - sizeof(int)), target, IMAGE_REL_BASED_DISP32, addlDelta); + emitRecordRelocationWithAddlDelta((void*)(dst - sizeof(int)), target, RELOC_DISP32, addlDelta); } } else @@ -16165,7 +16173,7 @@ BYTE* emitter::emitOutputCV(BYTE* dst, instrDesc* id, code_t code, CnsVal* addc) if (id->idIsDspReloc()) { - emitRecordRelocation((void*)(dst - TARGET_POINTER_SIZE), target, IMAGE_REL_BASED_MOFFSET); + emitRecordRelocation((void*)(dst - TARGET_POINTER_SIZE), target, RELOC_MOFFSET); } #endif // TARGET_X86 @@ -16200,7 +16208,7 @@ BYTE* emitter::emitOutputCV(BYTE* dst, instrDesc* id, code_t code, CnsVal* addc) } if (addc->cnsReloc) { - emitRecordRelocation((void*)(dst - sizeof(INT32)), (void*)(size_t)cval, IMAGE_REL_BASED_HIGHLOW); + emitRecordRelocation((void*)(dst - sizeof(INT32)), (void*)(size_t)cval, CorInfoReloc::DIR32); assert(opsz == 4); } } @@ -17232,13 +17240,13 @@ BYTE* emitter::emitOutputRI(BYTE* dst, instrDesc* id) { if (emitComp->IsTargetAbi(CORINFO_NATIVEAOT_ABI) && id->idAddr()->iiaSecRel) { - // For section relative, the immediate offset is relocatable and hence need IMAGE_REL_SECREL - emitRecordRelocation((void*)(dst - (unsigned)EA_SIZE(size)), (void*)(size_t)val, IMAGE_REL_SECREL); + // For section relative, the immediate offset is relocatable and hence needs SECREL relocation + emitRecordRelocation((void*)(dst - (unsigned)EA_SIZE(size)), (void*)(size_t)val, + CorInfoReloc::AMD64_WIN_SECREL); } else { - emitRecordRelocation((void*)(dst - (unsigned)EA_SIZE(size)), (void*)(size_t)val, - IMAGE_REL_BASED_MOFFSET); + emitRecordRelocation((void*)(dst - (unsigned)EA_SIZE(size)), (void*)(size_t)val, RELOC_MOFFSET); } } @@ -17411,7 +17419,7 @@ BYTE* emitter::emitOutputRI(BYTE* dst, instrDesc* id) if (id->idIsCnsReloc()) { - emitRecordRelocation((void*)(dst - sizeof(INT32)), (void*)(size_t)val, IMAGE_REL_BASED_HIGHLOW); + emitRecordRelocation((void*)(dst - sizeof(INT32)), (void*)(size_t)val, CorInfoReloc::DIR32); assert(size == EA_4BYTE); } } @@ -17585,7 +17593,7 @@ BYTE* emitter::emitOutputIV(BYTE* dst, instrDesc* id) dst += emitOutputLong(dst, val); if (id->idIsCnsReloc()) { - emitRecordRelocation((void*)(dst - sizeof(INT32)), (void*)(size_t)val, IMAGE_REL_BASED_HIGHLOW); + emitRecordRelocation((void*)(dst - sizeof(INT32)), (void*)(size_t)val, CorInfoReloc::DIR32); } } break; @@ -17942,12 +17950,12 @@ BYTE* emitter::emitOutputLJ(insGroup* ig, BYTE* dst, instrDesc* i) { if (!relAddr) { - emitRecordRelocation((void*)(dst - sizeof(int32_t)), (void*)distVal, IMAGE_REL_BASED_HIGHLOW); + emitRecordRelocation((void*)(dst - sizeof(int32_t)), (void*)distVal, CorInfoReloc::DIR32); } else if (crossJump) { assert(id->idjKeepLong); - emitRecordRelocation((void*)(dst - sizeof(int32_t)), dst + distVal, IMAGE_REL_BASED_REL32); + emitRecordRelocation((void*)(dst - sizeof(int32_t)), dst + distVal, CorInfoReloc::REL32); } } } @@ -18496,7 +18504,8 @@ size_t emitter::emitOutputInstr(insGroup* ig, instrDesc* id, BYTE** dp) #else dst += emitOutputLong(dst, (int)(ssize_t)addr); #endif - emitRecordRelocation((void*)(dst - sizeof(int)), addr, IMAGE_REL_BASED_DISP32); + + emitRecordRelocation((void*)(dst - sizeof(int)), addr, RELOC_DISP32); } else { @@ -18507,7 +18516,7 @@ size_t emitter::emitOutputInstr(insGroup* ig, instrDesc* id, BYTE** dp) // This addr mode should never be used while generating relocatable AOT code nor if // the addr can be encoded as pc-relative address. noway_assert(!emitComp->opts.compReloc); - noway_assert(codeGen->genAddrRelocTypeHint((size_t)addr) != IMAGE_REL_BASED_REL32); + noway_assert(codeGen->genAddrRelocTypeHint((size_t)addr) != CorInfoReloc::REL32); noway_assert(static_cast(reinterpret_cast(addr)) == (ssize_t)addr); // This requires, specifying a SIB byte after ModRM byte. @@ -18560,7 +18569,7 @@ size_t emitter::emitOutputInstr(insGroup* ig, instrDesc* id, BYTE** dp) if (id->idIsDspReloc()) { - emitRecordRelocation((void*)(dst - sizeof(INT32)), addr, IMAGE_REL_BASED_REL32); + emitRecordRelocation((void*)(dst - sizeof(INT32)), addr, CorInfoReloc::REL32); } DONE_CALL: @@ -18897,7 +18906,7 @@ size_t emitter::emitOutputInstr(insGroup* ig, instrDesc* id, BYTE** dp) if (id->idIsCnsReloc()) { - emitRecordRelocation((void*)(dst - sizeof(INT32)), (void*)(size_t)val, IMAGE_REL_BASED_HIGHLOW); + emitRecordRelocation((void*)(dst - sizeof(INT32)), (void*)(size_t)val, CorInfoReloc::DIR32); assert(size == EA_4BYTE); } } diff --git a/src/coreclr/jit/gentree.cpp b/src/coreclr/jit/gentree.cpp index 79ae1abdcaa96b..cb916b63c10a1f 100644 --- a/src/coreclr/jit/gentree.cpp +++ b/src/coreclr/jit/gentree.cpp @@ -18312,7 +18312,7 @@ bool GenTreeIntConCommon::FitsInAddrBase(Compiler* comp) { // During AOT JIT is always asked to generate relocatable code. // Hence JIT will try to encode only icon handles as pc-relative offsets. - return IsIconHandle() && (IMAGE_REL_BASED_REL32 == comp->eeGetRelocTypeHint((void*)IconValue())); + return IsIconHandle() && (comp->eeGetRelocTypeHint((void*)IconValue()) == CorInfoReloc::REL32); } else { @@ -18333,7 +18333,7 @@ bool GenTreeIntConCommon::FitsInAddrBase(Compiler* comp) // offsets. Note that JIT will always attempt to relocate code addresses (.e.g call addr). // After an overflow, VM will assume any relocation recorded is for a code address and will // emit jump thunk if it cannot be encoded as pc-relative offset. - return (IMAGE_REL_BASED_REL32 == comp->eeGetRelocTypeHint((void*)IconValue())) || FitsInI32(); + return (comp->eeGetRelocTypeHint((void*)IconValue()) == CorInfoReloc::REL32) || FitsInI32(); } } @@ -18344,11 +18344,11 @@ bool GenTreeIntConCommon::AddrNeedsReloc(Compiler* comp) { // During AOT JIT is always asked to generate relocatable code. // Hence JIT will try to encode only icon handles as pc-relative offsets. - return IsIconHandle() && (IMAGE_REL_BASED_REL32 == comp->eeGetRelocTypeHint((void*)IconValue())); + return IsIconHandle() && (comp->eeGetRelocTypeHint((void*)IconValue()) == CorInfoReloc::REL32); } else { - return IMAGE_REL_BASED_REL32 == comp->eeGetRelocTypeHint((void*)IconValue()); + return comp->eeGetRelocTypeHint((void*)IconValue()) == CorInfoReloc::REL32; } } diff --git a/src/coreclr/jit/instr.cpp b/src/coreclr/jit/instr.cpp index 77e0e0427b4183..e96f3f5506d8b3 100644 --- a/src/coreclr/jit/instr.cpp +++ b/src/coreclr/jit/instr.cpp @@ -1901,7 +1901,7 @@ bool CodeGenInterface::validImmForBL(ssize_t addr) // If we are running the altjit for AOT, then assume we can use the "BL" instruction. // This matches the usual behavior for AOT, since we normally do generate "BL". (!compiler->info.compMatchedVM && compiler->IsAot()) || - (compiler->eeGetRelocTypeHint((void*)addr) == IMAGE_REL_BASED_THUMB_BRANCH24); + (compiler->eeGetRelocTypeHint((void*)addr) == CorInfoReloc::ARM32_THUMB_BRANCH24); } #endif // TARGET_ARM diff --git a/src/coreclr/jit/targetx86.h b/src/coreclr/jit/targetx86.h index c9b22a16c165ee..997ab9b3a93e0f 100644 --- a/src/coreclr/jit/targetx86.h +++ b/src/coreclr/jit/targetx86.h @@ -331,12 +331,6 @@ #define RBM_PROFILER_LEAVE_TRASH RBM_NONE #define RBM_PROFILER_TAILCALL_TRASH (RBM_CALLEE_TRASH & ~RBM_ARG_REGS) - // What sort of reloc do we use for [disp32] address mode - #define IMAGE_REL_BASED_DISP32 IMAGE_REL_BASED_HIGHLOW - - // What sort of reloc to we use for 'moffset' address mode (for 'mov eax, moffset' or 'mov moffset, eax') - #define IMAGE_REL_BASED_MOFFSET IMAGE_REL_BASED_HIGHLOW - // Pointer-sized string move instructions #define INS_movsp INS_movsd #define INS_r_movsp INS_r_movsd diff --git a/src/coreclr/tools/Common/JitInterface/CorInfoImpl.cs b/src/coreclr/tools/Common/JitInterface/CorInfoImpl.cs index 033463c341485b..62c775326e6805 100644 --- a/src/coreclr/tools/Common/JitInterface/CorInfoImpl.cs +++ b/src/coreclr/tools/Common/JitInterface/CorInfoImpl.cs @@ -4063,84 +4063,37 @@ private ref ArrayBuilder findRelocBlock(BlockType blockType, out int } } - // Translates relocation type constants used by JIT (defined in winnt.h) to RelocType enumeration - private static RelocType GetRelocType(TargetArchitecture targetArchitecture, ushort fRelocType) - { - switch (targetArchitecture) - { - case TargetArchitecture.ARM64: - { - const ushort IMAGE_REL_ARM64_BRANCH26 = 3; - const ushort IMAGE_REL_ARM64_PAGEBASE_REL21 = 4; - const ushort IMAGE_REL_ARM64_PAGEOFFSET_12A = 6; - const ushort IMAGE_REL_ARM64_SECREL_LOW12A = 9; - const ushort IMAGE_REL_ARM64_SECREL_HIGH12A = 0xA; - const ushort IMAGE_REL_ARM64_TLSDESC_ADR_PAGE21 = 0x107; - const ushort IMAGE_REL_ARM64_TLSDESC_LD64_LO12 = 0x108; - const ushort IMAGE_REL_ARM64_TLSDESC_ADD_LO12 = 0x109; - const ushort IMAGE_REL_ARM64_TLSDESC_CALL = 0x10A; - - - switch (fRelocType) - { - case IMAGE_REL_ARM64_BRANCH26: - return RelocType.IMAGE_REL_BASED_ARM64_BRANCH26; - case IMAGE_REL_ARM64_PAGEBASE_REL21: - return RelocType.IMAGE_REL_BASED_ARM64_PAGEBASE_REL21; - case IMAGE_REL_ARM64_PAGEOFFSET_12A: - return RelocType.IMAGE_REL_BASED_ARM64_PAGEOFFSET_12A; - case IMAGE_REL_ARM64_TLSDESC_ADR_PAGE21: - return RelocType.IMAGE_REL_AARCH64_TLSDESC_ADR_PAGE21; - case IMAGE_REL_ARM64_TLSDESC_ADD_LO12: - return RelocType.IMAGE_REL_AARCH64_TLSDESC_ADD_LO12; - case IMAGE_REL_ARM64_TLSDESC_LD64_LO12: - return RelocType.IMAGE_REL_AARCH64_TLSDESC_LD64_LO12; - case IMAGE_REL_ARM64_TLSDESC_CALL: - return RelocType.IMAGE_REL_AARCH64_TLSDESC_CALL; - case IMAGE_REL_ARM64_SECREL_HIGH12A: - return RelocType.IMAGE_REL_ARM64_TLS_SECREL_HIGH12A; - case IMAGE_REL_ARM64_SECREL_LOW12A: - return RelocType.IMAGE_REL_ARM64_TLS_SECREL_LOW12A; - default: - Debug.Fail("Invalid RelocType: " + fRelocType); - return 0; - } - } - case TargetArchitecture.LoongArch64: - { - const ushort IMAGE_REL_LOONGARCH64_PC = 3; - const ushort IMAGE_REL_LOONGARCH64_JIR = 4; - - switch (fRelocType) - { - case IMAGE_REL_LOONGARCH64_PC: - return RelocType.IMAGE_REL_BASED_LOONGARCH64_PC; - case IMAGE_REL_LOONGARCH64_JIR: - return RelocType.IMAGE_REL_BASED_LOONGARCH64_JIR; - default: - Debug.Fail("Invalid RelocType: " + fRelocType); - return 0; - } - } - case TargetArchitecture.RiscV64: - { - const ushort IMAGE_REL_RISCV64_PC = 3; - - switch (fRelocType) - { - case IMAGE_REL_RISCV64_PC: - return RelocType.IMAGE_REL_BASED_RISCV64_PC; - default: - Debug.Fail("Invalid RelocType: " + fRelocType); - return 0; - } - } + // Translates relocation type constants used by JIT to RelocType enumeration + private static RelocType GetRelocType(CorInfoReloc reloc) + { + switch (reloc) + { + case CorInfoReloc.DIR32: return RelocType.IMAGE_REL_BASED_HIGHLOW; + case CorInfoReloc.DIR64: return RelocType.IMAGE_REL_BASED_DIR64; + case CorInfoReloc.REL32: return RelocType.IMAGE_REL_BASED_REL32; + case CorInfoReloc.ARM64_BRANCH26: return RelocType.IMAGE_REL_BASED_ARM64_BRANCH26; + case CorInfoReloc.ARM64_PAGEBASE_REL21: return RelocType.IMAGE_REL_BASED_ARM64_PAGEBASE_REL21; + case CorInfoReloc.ARM64_PAGEOFFSET_12A: return RelocType.IMAGE_REL_BASED_ARM64_PAGEOFFSET_12A; + case CorInfoReloc.ARM64_LIN_TLSDESC_ADR_PAGE21: return RelocType.IMAGE_REL_AARCH64_TLSDESC_ADR_PAGE21; + case CorInfoReloc.ARM64_LIN_TLSDESC_LD64_LO12: return RelocType.IMAGE_REL_AARCH64_TLSDESC_LD64_LO12; + case CorInfoReloc.ARM64_LIN_TLSDESC_ADD_LO12: return RelocType.IMAGE_REL_AARCH64_TLSDESC_ADD_LO12; + case CorInfoReloc.ARM64_LIN_TLSDESC_CALL: return RelocType.IMAGE_REL_AARCH64_TLSDESC_CALL; + case CorInfoReloc.ARM64_WIN_TLS_SECREL_HIGH12A: return RelocType.IMAGE_REL_ARM64_TLS_SECREL_HIGH12A; + case CorInfoReloc.ARM64_WIN_TLS_SECREL_LOW12A: return RelocType.IMAGE_REL_ARM64_TLS_SECREL_LOW12A; + case CorInfoReloc.AMD64_WIN_SECREL: return RelocType.IMAGE_REL_SECREL; + case CorInfoReloc.AMD64_LIN_TLSGD: return RelocType.IMAGE_REL_TLSGD; + case CorInfoReloc.ARM32_THUMB_BRANCH24: return RelocType.IMAGE_REL_BASED_THUMB_BRANCH24; + case CorInfoReloc.ARM32_THUMB_MOV32: return RelocType.IMAGE_REL_BASED_THUMB_MOV32; + case CorInfoReloc.ARM32_THUMB_MOV32_PCREL: return RelocType.IMAGE_REL_BASED_THUMB_MOV32_PCREL; + case CorInfoReloc.LOONGARCH64_PC: return RelocType.IMAGE_REL_BASED_LOONGARCH64_PC; + case CorInfoReloc.LOONGARCH64_JIR: return RelocType.IMAGE_REL_BASED_LOONGARCH64_JIR; + case CorInfoReloc.RISCV64_PC: return RelocType.IMAGE_REL_BASED_RISCV64_PC; default: - return (RelocType)fRelocType; + throw new ArgumentException("Unsupported relocation type: " + reloc); } } - private void recordRelocation(void* location, void* locationRW, void* target, ushort fRelocType, int addlDelta) + private void recordRelocation(void* location, void* locationRW, void* target, CorInfoReloc fRelocType, int addlDelta) { int relocOffset; BlockType locationBlock = findKnownBlock(location, out relocOffset); @@ -4195,8 +4148,7 @@ private void recordRelocation(void* location, void* locationRW, void* target, us relocDelta += addlDelta; - TargetArchitecture targetArchitecture = _compilation.TypeSystemContext.Target.Architecture; - RelocType relocType = GetRelocType(targetArchitecture, fRelocType); + RelocType relocType = GetRelocType(fRelocType); // relocDelta is stored as the value Relocation.WriteValue(relocType, location, relocDelta); @@ -4205,20 +4157,20 @@ private void recordRelocation(void* location, void* locationRW, void* target, us sourceBlock.Add(new Relocation(relocType, relocOffset, relocTarget)); } - private ushort getRelocTypeHint(void* target) + private CorInfoReloc getRelocTypeHint(void* target) { switch (_compilation.TypeSystemContext.Target.Architecture) { case TargetArchitecture.X64: - return (ushort)RelocType.IMAGE_REL_BASED_REL32; + return CorInfoReloc.REL32; #if READYTORUN case TargetArchitecture.ARM: - return (ushort)RelocType.IMAGE_REL_BASED_THUMB_BRANCH24; + return CorInfoReloc.ARM32_THUMB_BRANCH24; #endif default: - return ushort.MaxValue; + return CorInfoReloc.NONE; } } diff --git a/src/coreclr/tools/Common/JitInterface/CorInfoImpl_generated.cs b/src/coreclr/tools/Common/JitInterface/CorInfoImpl_generated.cs index 73a82ead1edd1d..772c840e422a37 100644 --- a/src/coreclr/tools/Common/JitInterface/CorInfoImpl_generated.cs +++ b/src/coreclr/tools/Common/JitInterface/CorInfoImpl_generated.cs @@ -2559,7 +2559,7 @@ private static void _recordCallSite(IntPtr thisHandle, IntPtr* ppException, uint } [UnmanagedCallersOnly] - private static void _recordRelocation(IntPtr thisHandle, IntPtr* ppException, void* location, void* locationRW, void* target, ushort fRelocType, int addlDelta) + private static void _recordRelocation(IntPtr thisHandle, IntPtr* ppException, void* location, void* locationRW, void* target, CorInfoReloc fRelocType, int addlDelta) { var _this = GetThis(thisHandle); try @@ -2573,7 +2573,7 @@ private static void _recordRelocation(IntPtr thisHandle, IntPtr* ppException, vo } [UnmanagedCallersOnly] - private static ushort _getRelocTypeHint(IntPtr thisHandle, IntPtr* ppException, void* target) + private static CorInfoReloc _getRelocTypeHint(IntPtr thisHandle, IntPtr* ppException, void* target) { var _this = GetThis(thisHandle); try @@ -2810,8 +2810,8 @@ private static IntPtr GetUnmanagedCallbacks() callbacks[170] = (delegate* unmanaged)&_getPgoInstrumentationResults; callbacks[171] = (delegate* unmanaged)&_allocPgoInstrumentationBySchema; callbacks[172] = (delegate* unmanaged)&_recordCallSite; - callbacks[173] = (delegate* unmanaged)&_recordRelocation; - callbacks[174] = (delegate* unmanaged)&_getRelocTypeHint; + callbacks[173] = (delegate* unmanaged)&_recordRelocation; + callbacks[174] = (delegate* unmanaged)&_getRelocTypeHint; callbacks[175] = (delegate* unmanaged)&_getExpectedTargetArchitecture; callbacks[176] = (delegate* unmanaged)&_getJitFlags; callbacks[177] = (delegate* unmanaged)&_getSpecialCopyHelper; diff --git a/src/coreclr/tools/Common/JitInterface/CorInfoTypes.cs b/src/coreclr/tools/Common/JitInterface/CorInfoTypes.cs index 11e1570c8dbb16..405db1098a2f31 100644 --- a/src/coreclr/tools/Common/JitInterface/CorInfoTypes.cs +++ b/src/coreclr/tools/Common/JitInterface/CorInfoTypes.cs @@ -461,6 +461,46 @@ public enum InfoAccessType IAT_RELPVALUE // The value needs to be accessed via a relative indirection } + public enum CorInfoReloc + { + NONE, + + // General relocation types + DIR32, // Direct/absolute 32 bit address + DIR64, // Direct/absolute 64 bit address + REL32, // 32-bit relative address from byte following reloc + + // Arm64 relocs + ARM64_BRANCH26, // Arm64: B, BL + ARM64_PAGEBASE_REL21, // ADRP + ARM64_PAGEOFFSET_12A, // ADD/ADDS (immediate) with zero shift, for page offset + // Linux arm64 + ARM64_LIN_TLSDESC_ADR_PAGE21, + ARM64_LIN_TLSDESC_LD64_LO12, + ARM64_LIN_TLSDESC_ADD_LO12, + ARM64_LIN_TLSDESC_CALL, + // Windows arm64 + ARM64_WIN_TLS_SECREL_HIGH12A, // ADD high 12-bit offset for tls + ARM64_WIN_TLS_SECREL_LOW12A, // ADD low 12-bit offset for tls + + // Windows x64 + AMD64_WIN_SECREL, + // Linux x64 + AMD64_LIN_TLSGD, + + // Arm32 relocs + ARM32_THUMB_BRANCH24, // Thumb2: based B, BL + ARM32_THUMB_MOV32, // Thumb2: based MOVW/MOVT + ARM32_THUMB_MOV32_PCREL, // Thumb2: based MOVW/MOVT + + // LoongArch64 relocs + LOONGARCH64_PC, // LoongArch64: pcalau12i+imm12 + LOONGARCH64_JIR, // LoongArch64: pcaddu18i+jirl + + // RISCV64 relocs + RISCV64_PC, // RiscV64: auipc + } + public enum CorInfoGCType { TYPE_GC_NONE, // no embedded objectrefs diff --git a/src/coreclr/tools/Common/JitInterface/ThunkGenerator/ThunkInput.txt b/src/coreclr/tools/Common/JitInterface/ThunkGenerator/ThunkInput.txt index fff938a53009d5..c584192347b3e1 100644 --- a/src/coreclr/tools/Common/JitInterface/ThunkGenerator/ThunkInput.txt +++ b/src/coreclr/tools/Common/JitInterface/ThunkGenerator/ThunkInput.txt @@ -127,6 +127,7 @@ CorInfoTypeWithMod CorInfoCallConvExtension InfoAccessType InfoAccessType*, ref InfoAccessType +CorInfoReloc CORINFO_LOOKUP_KIND CORINFO_ACCESS_FLAGS CORINFO_CALLINFO_FLAGS @@ -342,8 +343,8 @@ FUNCTIONS JITINTERFACE_HRESULT getPgoInstrumentationResults(CORINFO_METHOD_HANDLE ftnHnd, ICorJitInfo::PgoInstrumentationSchema** pSchema, uint32_t* pCountSchemaItems, uint8_t**pInstrumentationData, ICorJitInfo::PgoSource* pPgoSource, bool* pDynamicPgo) JITINTERFACE_HRESULT allocPgoInstrumentationBySchema(CORINFO_METHOD_HANDLE ftnHnd, ICorJitInfo::PgoInstrumentationSchema* pSchema, uint32_t countSchemaItems, uint8_t** pInstrumentationData) void recordCallSite(uint32_t instrOffset, CORINFO_SIG_INFO* callSig, CORINFO_METHOD_HANDLE methodHandle) - void recordRelocation(void* location, void* locationRW, void* target, uint16_t fRelocType, int32_t addlDelta) - uint16_t getRelocTypeHint(void* target) + void recordRelocation(void* location, void* locationRW, void* target, CorInfoReloc fRelocType, int32_t addlDelta) + CorInfoReloc getRelocTypeHint(void* target) uint32_t getExpectedTargetArchitecture() uint32_t getJitFlags(CORJIT_FLAGS* flags, uint32_t sizeInBytes) CORINFO_METHOD_HANDLE getSpecialCopyHelper(CORINFO_CLASS_HANDLE type) = 0; diff --git a/src/coreclr/tools/aot/jitinterface/jitinterface_generated.h b/src/coreclr/tools/aot/jitinterface/jitinterface_generated.h index ac78ed4c2a1144..7d83f1102afc80 100644 --- a/src/coreclr/tools/aot/jitinterface/jitinterface_generated.h +++ b/src/coreclr/tools/aot/jitinterface/jitinterface_generated.h @@ -184,8 +184,8 @@ struct JitInterfaceCallbacks JITINTERFACE_HRESULT (* getPgoInstrumentationResults)(void * thisHandle, CorInfoExceptionClass** ppException, CORINFO_METHOD_HANDLE ftnHnd, ICorJitInfo::PgoInstrumentationSchema** pSchema, uint32_t* pCountSchemaItems, uint8_t** pInstrumentationData, ICorJitInfo::PgoSource* pPgoSource, bool* pDynamicPgo); JITINTERFACE_HRESULT (* allocPgoInstrumentationBySchema)(void * thisHandle, CorInfoExceptionClass** ppException, CORINFO_METHOD_HANDLE ftnHnd, ICorJitInfo::PgoInstrumentationSchema* pSchema, uint32_t countSchemaItems, uint8_t** pInstrumentationData); void (* recordCallSite)(void * thisHandle, CorInfoExceptionClass** ppException, uint32_t instrOffset, CORINFO_SIG_INFO* callSig, CORINFO_METHOD_HANDLE methodHandle); - void (* recordRelocation)(void * thisHandle, CorInfoExceptionClass** ppException, void* location, void* locationRW, void* target, uint16_t fRelocType, int32_t addlDelta); - uint16_t (* getRelocTypeHint)(void * thisHandle, CorInfoExceptionClass** ppException, void* target); + void (* recordRelocation)(void * thisHandle, CorInfoExceptionClass** ppException, void* location, void* locationRW, void* target, CorInfoReloc fRelocType, int32_t addlDelta); + CorInfoReloc (* getRelocTypeHint)(void * thisHandle, CorInfoExceptionClass** ppException, void* target); uint32_t (* getExpectedTargetArchitecture)(void * thisHandle, CorInfoExceptionClass** ppException); uint32_t (* getJitFlags)(void * thisHandle, CorInfoExceptionClass** ppException, CORJIT_FLAGS* flags, uint32_t sizeInBytes); CORINFO_METHOD_HANDLE (* getSpecialCopyHelper)(void * thisHandle, CorInfoExceptionClass** ppException, CORINFO_CLASS_HANDLE type); @@ -1903,7 +1903,7 @@ class JitInterfaceWrapper : public ICorJitInfo void* location, void* locationRW, void* target, - uint16_t fRelocType, + CorInfoReloc fRelocType, int32_t addlDelta) { CorInfoExceptionClass* pException = nullptr; @@ -1911,11 +1911,11 @@ class JitInterfaceWrapper : public ICorJitInfo if (pException != nullptr) throw pException; } - virtual uint16_t getRelocTypeHint( + virtual CorInfoReloc getRelocTypeHint( void* target) { CorInfoExceptionClass* pException = nullptr; - uint16_t temp = _callbacks->getRelocTypeHint(_thisHandle, &pException, target); + CorInfoReloc temp = _callbacks->getRelocTypeHint(_thisHandle, &pException, target); if (pException != nullptr) throw pException; return temp; } diff --git a/src/coreclr/tools/superpmi/superpmi-shared/compileresult.cpp b/src/coreclr/tools/superpmi/superpmi-shared/compileresult.cpp index e878cd59d82ff3..0e77a45517416c 100644 --- a/src/coreclr/tools/superpmi/superpmi-shared/compileresult.cpp +++ b/src/coreclr/tools/superpmi/superpmi-shared/compileresult.cpp @@ -671,57 +671,49 @@ void CompileResult::dmpReportFatalError(DWORD key, DWORD value) printf("ReportFatalError key Count-%u, value result-%08X", key, value); } -void CompileResult::recRecordRelocation(void* location, void* target, uint16_t fRelocType, int32_t addlDelta) +void CompileResult::recRecordRelocation(void* location, void* target, CorInfoReloc fRelocType, int32_t addlDelta) { repRecordRelocation(location, target, fRelocType, addlDelta); } -const char* relocationTypeToString(uint16_t fRelocType) +const char* relocationTypeToString(CorInfoReloc fRelocType) { switch (fRelocType) { - // From winnt.h - case IMAGE_REL_BASED_ABSOLUTE: - return "absolute"; - case IMAGE_REL_BASED_HIGH: - return "high"; - case IMAGE_REL_BASED_LOW: - return "low"; - case IMAGE_REL_BASED_HIGHLOW: - return "highlow"; - case IMAGE_REL_BASED_HIGHADJ: - return "highadj"; - case IMAGE_REL_BASED_DIR64: - return "dir64"; - - // From corinfo.h - case IMAGE_REL_BASED_REL32: - return "rel32"; - case IMAGE_REL_SECREL: - return "secrel"; - case IMAGE_REL_TLSGD: - return "tlsgd"; - case IMAGE_REL_AARCH64_TLSDESC_ADR_PAGE21: - return "tlsdesc_high21"; - case IMAGE_REL_AARCH64_TLSDESC_LD64_LO12: - return "tlsdesc_lo12"; - case IMAGE_REL_AARCH64_TLSDESC_ADD_LO12: - return "tlsdesc_add_lo12"; - case IMAGE_REL_AARCH64_TLSDESC_CALL: - return "tlsdesc_call"; - case IMAGE_REL_BASED_THUMB_BRANCH24: - return "thumb_branch24"; +#define ADD_CASE(name) case CorInfoReloc::name: return #name + ADD_CASE(NONE); + ADD_CASE(DIR32); + ADD_CASE(DIR64); + ADD_CASE(REL32); + ADD_CASE(ARM64_BRANCH26); + ADD_CASE(ARM64_PAGEBASE_REL21); + ADD_CASE(ARM64_PAGEOFFSET_12A); + ADD_CASE(ARM64_LIN_TLSDESC_ADR_PAGE21); + ADD_CASE(ARM64_LIN_TLSDESC_LD64_LO12); + ADD_CASE(ARM64_LIN_TLSDESC_ADD_LO12); + ADD_CASE(ARM64_LIN_TLSDESC_CALL); + ADD_CASE(ARM64_WIN_TLS_SECREL_HIGH12A); + ADD_CASE(ARM64_WIN_TLS_SECREL_LOW12A); + ADD_CASE(AMD64_WIN_SECREL); + ADD_CASE(AMD64_LIN_TLSGD); + ADD_CASE(ARM32_THUMB_BRANCH24); + ADD_CASE(ARM32_THUMB_MOV32); + ADD_CASE(ARM32_THUMB_MOV32_PCREL); + ADD_CASE(LOONGARCH64_PC); + ADD_CASE(LOONGARCH64_JIR); + ADD_CASE(RISCV64_PC); default: return "UNKNOWN"; +#undef ADD_CASE } } void CompileResult::dmpRecordRelocation(DWORD key, const Agnostic_RecordRelocation& value) { printf("RecordRelocation key %u, value loc-%016" PRIX64 " tgt-%016" PRIX64 " fRelocType-%u(%s) addlDelta:%d", key, - value.location, value.target, value.fRelocType, relocationTypeToString((uint16_t)value.fRelocType), + value.location, value.target, value.fRelocType, relocationTypeToString((CorInfoReloc)value.fRelocType), (int32_t)value.addlDelta); } -void CompileResult::repRecordRelocation(void* location, void* target, uint16_t fRelocType, int32_t addlDelta) +void CompileResult::repRecordRelocation(void* location, void* target, CorInfoReloc fRelocType, int32_t addlDelta) { if (RecordRelocation == nullptr) RecordRelocation = new DenseLightWeightMap(); @@ -781,14 +773,14 @@ void CompileResult::applyRelocs(RelocContext* rc, unsigned char* block1, ULONG b const SPMI_TARGET_ARCHITECTURE targetArch = GetSpmiTargetArchitecture(); - const DWORD relocType = tmp.fRelocType; + const CorInfoReloc relocType = (CorInfoReloc)tmp.fRelocType; bool wasRelocHandled = false; // Do platform specific relocations first. if ((targetArch == SPMI_TARGET_ARCHITECTURE_X86) || (targetArch == SPMI_TARGET_ARCHITECTURE_ARM)) { - if (relocType == IMAGE_REL_BASED_HIGHLOW) + if (relocType == CorInfoReloc::DIR32) { DWORDLONG fixupLocation = tmp.location; @@ -810,8 +802,8 @@ void CompileResult::applyRelocs(RelocContext* rc, unsigned char* block1, ULONG b switch (relocType) { - case IMAGE_REL_BASED_THUMB_MOV32: - case IMAGE_REL_BASED_REL_THUMB_MOV32_PCREL: + case CorInfoReloc::ARM32_THUMB_MOV32: + case CorInfoReloc::ARM32_THUMB_MOV32_PCREL: { INT32 delta = (INT32)(tmp.target - fixupLocation); if ((section_begin <= address) && (address < section_end)) // A reloc for our section? @@ -822,7 +814,7 @@ void CompileResult::applyRelocs(RelocContext* rc, unsigned char* block1, ULONG b } break; - case IMAGE_REL_BASED_THUMB_BRANCH24: + case CorInfoReloc::ARM32_THUMB_BRANCH24: { INT32 delta = (INT32)(tmp.target - fixupLocation); if ((section_begin <= address) && (address < section_end)) // A reloc for our section? @@ -850,7 +842,7 @@ void CompileResult::applyRelocs(RelocContext* rc, unsigned char* block1, ULONG b switch (relocType) { - case IMAGE_REL_ARM64_BRANCH26: // 26 bit offset << 2 & sign ext, for B and BL + case CorInfoReloc::ARM64_BRANCH26: // 26 bit offset << 2 & sign ext, for B and BL { if ((section_begin <= address) && (address < section_end)) // A reloc for our section? { @@ -863,8 +855,8 @@ void CompileResult::applyRelocs(RelocContext* rc, unsigned char* block1, ULONG b } break; - case IMAGE_REL_ARM64_PAGEBASE_REL21: // ADRP 21 bit PC-relative page address - case IMAGE_REL_AARCH64_TLSDESC_ADR_PAGE21: // ADRP 21 bit for TLSDesc + case CorInfoReloc::ARM64_PAGEBASE_REL21: // ADRP 21 bit PC-relative page address + case CorInfoReloc::ARM64_LIN_TLSDESC_ADR_PAGE21: // ADRP 21 bit for TLSDesc { if ((section_begin <= address) && (address < section_end)) // A reloc for our section? { @@ -878,7 +870,7 @@ void CompileResult::applyRelocs(RelocContext* rc, unsigned char* block1, ULONG b } break; - case IMAGE_REL_ARM64_PAGEOFFSET_12A: // ADD 12 bit page offset + case CorInfoReloc::ARM64_PAGEOFFSET_12A: // ADD 12 bit page offset { if ((section_begin <= address) && (address < section_end)) // A reloc for our section? { @@ -889,11 +881,11 @@ void CompileResult::applyRelocs(RelocContext* rc, unsigned char* block1, ULONG b } break; - case IMAGE_REL_ARM64_SECREL_HIGH12A: // TLSDESC ADD for High-12 Add - case IMAGE_REL_ARM64_SECREL_LOW12A: // TLSDESC ADD for Low-12 Add - case IMAGE_REL_AARCH64_TLSDESC_LD64_LO12: - case IMAGE_REL_AARCH64_TLSDESC_ADD_LO12: // TLSDESC ADD for corresponding ADRP - case IMAGE_REL_AARCH64_TLSDESC_CALL: + case CorInfoReloc::ARM64_WIN_TLS_SECREL_HIGH12A: // TLSDESC ADD for High-12 Add + case CorInfoReloc::ARM64_WIN_TLS_SECREL_LOW12A: // TLSDESC ADD for Low-12 Add + case CorInfoReloc::ARM64_LIN_TLSDESC_LD64_LO12: + case CorInfoReloc::ARM64_LIN_TLSDESC_ADD_LO12: // TLSDESC ADD for corresponding ADRP + case CorInfoReloc::ARM64_LIN_TLSDESC_CALL: { // These are patched later by linker during actual execution // and do not need relocation. @@ -913,7 +905,7 @@ void CompileResult::applyRelocs(RelocContext* rc, unsigned char* block1, ULONG b switch (relocType) { - case IMAGE_REL_RISCV64_PC: + case CorInfoReloc::RISCV64_PC: { if ((section_begin <= address) && (address < section_end)) // A reloc for our section? { @@ -933,7 +925,7 @@ void CompileResult::applyRelocs(RelocContext* rc, unsigned char* block1, ULONG b if (IsSpmiTarget64Bit()) { - if (!wasRelocHandled && (relocType == IMAGE_REL_BASED_DIR64)) + if (!wasRelocHandled && (relocType == CorInfoReloc::DIR64)) { DWORDLONG fixupLocation = tmp.location; @@ -948,7 +940,7 @@ void CompileResult::applyRelocs(RelocContext* rc, unsigned char* block1, ULONG b wasRelocHandled = true; } - else if (relocType == IMAGE_REL_TLSGD) + else if (relocType == CorInfoReloc::AMD64_LIN_TLSGD) { // These are patched later by linker during actual execution // and do not need relocation. @@ -960,7 +952,7 @@ void CompileResult::applyRelocs(RelocContext* rc, unsigned char* block1, ULONG b continue; // Now do all-platform relocations. - if ((tmp.fRelocType == IMAGE_REL_BASED_REL32) || (tmp.fRelocType == IMAGE_REL_SECREL)) + if ((relocType == CorInfoReloc::REL32) || (relocType == CorInfoReloc::AMD64_WIN_SECREL)) { DWORDLONG fixupLocation = tmp.location; @@ -995,8 +987,8 @@ void CompileResult::applyRelocs(RelocContext* rc, unsigned char* block1, ULONG b int index = rc->mc->GetRelocTypeHint->GetIndex(key); if (index != -1) { - WORD retVal = (WORD)rc->mc->GetRelocTypeHint->Get(key); - if (retVal == IMAGE_REL_BASED_REL32) + CorInfoReloc retVal = (CorInfoReloc)rc->mc->GetRelocTypeHint->Get(key); + if (retVal == CorInfoReloc::REL32) { LogDebug(" REL32 target used as argument to getRelocTypeHint: setting delta=%d (0x%X)", (int)key, (int)key); diff --git a/src/coreclr/tools/superpmi/superpmi-shared/compileresult.h b/src/coreclr/tools/superpmi/superpmi-shared/compileresult.h index 5326be7d8dd167..eb252d47dff0c8 100644 --- a/src/coreclr/tools/superpmi/superpmi-shared/compileresult.h +++ b/src/coreclr/tools/superpmi/superpmi-shared/compileresult.h @@ -180,9 +180,9 @@ class CompileResult void recReportFatalError(CorJitResult result); void dmpReportFatalError(DWORD key, DWORD value); - void recRecordRelocation(void* location, void* target, uint16_t fRelocType, int32_t addlDelta); + void recRecordRelocation(void* location, void* target, CorInfoReloc fRelocType, int32_t addlDelta); void dmpRecordRelocation(DWORD key, const Agnostic_RecordRelocation& value); - void repRecordRelocation(void* location, void* target, uint16_t fRelocType, int32_t addlDelta); + void repRecordRelocation(void* location, void* target, CorInfoReloc fRelocType, int32_t addlDelta); void applyRelocs(RelocContext* rc, unsigned char* block1, ULONG blocksize1, void* originalAddr); void recProcessName(const char* name); diff --git a/src/coreclr/tools/superpmi/superpmi-shared/methodcontext.cpp b/src/coreclr/tools/superpmi/superpmi-shared/methodcontext.cpp index 5202cd73661c44..163104b4592d61 100644 --- a/src/coreclr/tools/superpmi/superpmi-shared/methodcontext.cpp +++ b/src/coreclr/tools/superpmi/superpmi-shared/methodcontext.cpp @@ -6454,7 +6454,7 @@ void MethodContext::repGetFpStructLowering(CORINFO_CLASS_HANDLE structHnd, CORIN } } -void MethodContext::recGetRelocTypeHint(void* target, WORD result) +void MethodContext::recGetRelocTypeHint(void* target, CorInfoReloc result) { if (GetRelocTypeHint == nullptr) GetRelocTypeHint = new LightWeightMap(); @@ -6468,7 +6468,7 @@ void MethodContext::dmpGetRelocTypeHint(DWORDLONG key, DWORD value) { printf("GetRelocTypeHint key tgt-%016" PRIX64 ", value hint-%u", key, value); } -WORD MethodContext::repGetRelocTypeHint(void* target) +CorInfoReloc MethodContext::repGetRelocTypeHint(void* target) { DWORDLONG key = CastPointer(target); @@ -6476,21 +6476,21 @@ WORD MethodContext::repGetRelocTypeHint(void* target) { #ifdef sparseMC LogDebug("Sparse - repGetRelocTypeHint yielding fake answer..."); - return 65535; + return CorInfoReloc::NONE; #else LogException(EXCEPTIONCODE_MC, "Didn't find %016" PRIX64 "", key); #endif } int index = GetRelocTypeHint->GetIndex(key); - WORD retVal = 0; + CorInfoReloc retVal; if (index == -1) { - retVal = IMAGE_REL_BASED_REL32; + retVal = CorInfoReloc::REL32; } else { - retVal = (WORD)GetRelocTypeHint->Get(key); + retVal = (CorInfoReloc)GetRelocTypeHint->Get(key); } DEBUG_REP(dmpGetRelocTypeHint(key, (DWORD)retVal)); diff --git a/src/coreclr/tools/superpmi/superpmi-shared/methodcontext.h b/src/coreclr/tools/superpmi/superpmi-shared/methodcontext.h index bf853790fb9d8d..e8c9ee85cd80f9 100644 --- a/src/coreclr/tools/superpmi/superpmi-shared/methodcontext.h +++ b/src/coreclr/tools/superpmi/superpmi-shared/methodcontext.h @@ -790,9 +790,9 @@ class MethodContext void dmpGetFpStructLowering(DWORDLONG key, const Agnostic_GetFpStructLowering& value); void repGetFpStructLowering(CORINFO_CLASS_HANDLE structHnd, CORINFO_FPSTRUCT_LOWERING* pLowering); - void recGetRelocTypeHint(void* target, WORD result); + void recGetRelocTypeHint(void* target, CorInfoReloc result); void dmpGetRelocTypeHint(DWORDLONG key, DWORD value); - WORD repGetRelocTypeHint(void* target); + CorInfoReloc repGetRelocTypeHint(void* target); void recGetExpectedTargetArchitecture(DWORD result); void dmpGetExpectedTargetArchitecture(DWORD key, DWORD result); diff --git a/src/coreclr/tools/superpmi/superpmi-shim-collector/icorjitinfo.cpp b/src/coreclr/tools/superpmi/superpmi-shim-collector/icorjitinfo.cpp index 09544216cb913f..333c425d9af715 100644 --- a/src/coreclr/tools/superpmi/superpmi-shim-collector/icorjitinfo.cpp +++ b/src/coreclr/tools/superpmi/superpmi-shim-collector/icorjitinfo.cpp @@ -2014,7 +2014,7 @@ void interceptor_ICJI::recordCallSite(uint32_t instrOffset, /* IN * void interceptor_ICJI::recordRelocation(void* location, /* IN */ void* locationRW, /* IN */ void* target, /* IN */ - uint16_t fRelocType, /* IN */ + CorInfoReloc fRelocType, /* IN */ int32_t addlDelta /* IN */ ) { @@ -2023,10 +2023,10 @@ void interceptor_ICJI::recordRelocation(void* location, /* IN */ mc->cr->recRecordRelocation(location, target, fRelocType, addlDelta); } -uint16_t interceptor_ICJI::getRelocTypeHint(void* target) +CorInfoReloc interceptor_ICJI::getRelocTypeHint(void* target) { mc->cr->AddCall("getRelocTypeHint"); - WORD result = original_ICorJitInfo->getRelocTypeHint(target); + CorInfoReloc result = original_ICorJitInfo->getRelocTypeHint(target); mc->recGetRelocTypeHint(target, result); return result; } diff --git a/src/coreclr/tools/superpmi/superpmi-shim-counter/icorjitinfo_generated.cpp b/src/coreclr/tools/superpmi/superpmi-shim-counter/icorjitinfo_generated.cpp index 6e39de50c5d89e..c261b9c0bbe217 100644 --- a/src/coreclr/tools/superpmi/superpmi-shim-counter/icorjitinfo_generated.cpp +++ b/src/coreclr/tools/superpmi/superpmi-shim-counter/icorjitinfo_generated.cpp @@ -1426,14 +1426,14 @@ void interceptor_ICJI::recordRelocation( void* location, void* locationRW, void* target, - uint16_t fRelocType, + CorInfoReloc fRelocType, int32_t addlDelta) { mcs->AddCall("recordRelocation"); original_ICorJitInfo->recordRelocation(location, locationRW, target, fRelocType, addlDelta); } -uint16_t interceptor_ICJI::getRelocTypeHint( +CorInfoReloc interceptor_ICJI::getRelocTypeHint( void* target) { mcs->AddCall("getRelocTypeHint"); diff --git a/src/coreclr/tools/superpmi/superpmi-shim-simple/icorjitinfo_generated.cpp b/src/coreclr/tools/superpmi/superpmi-shim-simple/icorjitinfo_generated.cpp index fcb77f747663d9..5fda8e24f1c5cf 100644 --- a/src/coreclr/tools/superpmi/superpmi-shim-simple/icorjitinfo_generated.cpp +++ b/src/coreclr/tools/superpmi/superpmi-shim-simple/icorjitinfo_generated.cpp @@ -1253,13 +1253,13 @@ void interceptor_ICJI::recordRelocation( void* location, void* locationRW, void* target, - uint16_t fRelocType, + CorInfoReloc fRelocType, int32_t addlDelta) { original_ICorJitInfo->recordRelocation(location, locationRW, target, fRelocType, addlDelta); } -uint16_t interceptor_ICJI::getRelocTypeHint( +CorInfoReloc interceptor_ICJI::getRelocTypeHint( void* target) { return original_ICorJitInfo->getRelocTypeHint(target); diff --git a/src/coreclr/tools/superpmi/superpmi/icorjitinfo.cpp b/src/coreclr/tools/superpmi/superpmi/icorjitinfo.cpp index 38aaca767c9d36..ce1cdf2ecad824 100644 --- a/src/coreclr/tools/superpmi/superpmi/icorjitinfo.cpp +++ b/src/coreclr/tools/superpmi/superpmi/icorjitinfo.cpp @@ -1825,21 +1825,21 @@ void MyICJI::recordCallSite(uint32_t instrOffset, /* IN */ // A relocation is recorded if we are pre-jitting. // A jump thunk may be inserted if we are jitting -void MyICJI::recordRelocation(void* location, /* IN */ - void* locationRW, /* IN */ - void* target, /* IN */ - uint16_t fRelocType, /* IN */ - int32_t addlDelta /* IN */ +void MyICJI::recordRelocation(void* location, /* IN */ + void* locationRW, /* IN */ + void* target, /* IN */ + CorInfoReloc fRelocType, /* IN */ + int32_t addlDelta /* IN */ ) { jitInstance->mc->cr->AddCall("recordRelocation"); jitInstance->mc->cr->repRecordRelocation(location, target, fRelocType, addlDelta); } -uint16_t MyICJI::getRelocTypeHint(void* target) +CorInfoReloc MyICJI::getRelocTypeHint(void* target) { jitInstance->mc->cr->AddCall("getRelocTypeHint"); - uint16_t result = jitInstance->mc->repGetRelocTypeHint(target); + CorInfoReloc result = jitInstance->mc->repGetRelocTypeHint(target); return result; } diff --git a/src/coreclr/vm/jitinterface.cpp b/src/coreclr/vm/jitinterface.cpp index ab7f320f69e8ab..9c21880e07db94 100644 --- a/src/coreclr/vm/jitinterface.cpp +++ b/src/coreclr/vm/jitinterface.cpp @@ -11812,7 +11812,7 @@ void CEEJitInfo::recordCallSite(uint32_t instrOffset, void CEEJitInfo::recordRelocation(void * location, void * locationRW, void * target, - WORD fRelocType, + CorInfoReloc fRelocType, INT32 addlDelta) { CONTRACTL { @@ -11828,229 +11828,224 @@ void CEEJitInfo::recordRelocation(void * location, switch (fRelocType) { -#ifdef TARGET_64BIT - case IMAGE_REL_BASED_DIR64: - // Write 64-bits into location - *((UINT64 *) locationRW) = (UINT64) target; + + case CorInfoReloc::DIR64: + *((UINT64 *) locationRW) = (UINT64)(uintptr_t)target; break; -#else - case IMAGE_REL_BASED_HIGHLOW: - // Write 32-bits into location - *((UINT32 *) locationRW) = (UINT32) target; + + case CorInfoReloc::DIR32: + *((UINT32 *) locationRW) = (UINT32)(uintptr_t)target; break; -#endif #ifdef TARGET_AMD64 - case IMAGE_REL_BASED_REL32: - { - target = (BYTE *)target + addlDelta; + case CorInfoReloc::REL32: + { + target = (BYTE *)target + addlDelta; - INT32 * fixupLocation = (INT32 *) location; - INT32 * fixupLocationRW = (INT32 *) locationRW; - BYTE * baseAddr = (BYTE *)fixupLocation + sizeof(INT32); + INT32 * fixupLocation = (INT32 *) location; + INT32 * fixupLocationRW = (INT32 *) locationRW; + BYTE * baseAddr = (BYTE *)fixupLocation + sizeof(INT32); - delta = (INT64)((BYTE *)target - baseAddr); + delta = (INT64)((BYTE *)target - baseAddr); - // - // Do we need to insert a jump stub to make the source reach the target? - // - // Note that we cannot stress insertion of jump stub by inserting it unconditionally. JIT records the relocations - // for intra-module jumps and calls. It does not expect the register used by the jump stub to be trashed. - // - if (!FitsInI4(delta)) + // + // Do we need to insert a jump stub to make the source reach the target? + // + // Note that we cannot stress insertion of jump stub by inserting it unconditionally. JIT records the relocations + // for intra-module jumps and calls. It does not expect the register used by the jump stub to be trashed. + // + if (!FitsInI4(delta)) + { + if (m_fAllowRel32) { - if (m_fAllowRel32) + // + // When m_fAllowRel32 == TRUE, the JIT will use REL32s for both data addresses and direct code targets. + // Since we cannot tell what the relocation is for, we have to defensively retry. + // + m_fJumpStubOverflow = TRUE; + delta = 0; + } + else + { + if (m_fJumpStubOverflow) { - // - // When m_fAllowRel32 == TRUE, the JIT will use REL32s for both data addresses and direct code targets. - // Since we cannot tell what the relocation is for, we have to defensively retry. - // - m_fJumpStubOverflow = TRUE; + // Do not attempt to allocate more jump stubs. We are going to throw away the code and retry anyway. delta = 0; } else { - if (m_fJumpStubOverflow) - { - // Do not attempt to allocate more jump stubs. We are going to throw away the code and retry anyway. - delta = 0; - } - else + // + // When m_fAllowRel32 == FALSE, the JIT will use a REL32s for direct code targets only. + // Use jump stub. + // + delta = rel32UsingJumpStub(fixupLocation, (PCODE)target, m_pMethodBeingCompiled, NULL, false /* throwOnOutOfMemoryWithinRange */); + if (delta == 0) { - // - // When m_fAllowRel32 == FALSE, the JIT will use a REL32s for direct code targets only. - // Use jump stub. - // - delta = rel32UsingJumpStub(fixupLocation, (PCODE)target, m_pMethodBeingCompiled, NULL, false /* throwOnOutOfMemoryWithinRange */); - if (delta == 0) - { - // This forces the JIT to retry the method, which allows us to reserve more space for jump stubs and have a higher chance that - // we will find space for them. - m_fJumpStubOverflow = TRUE; - } + // This forces the JIT to retry the method, which allows us to reserve more space for jump stubs and have a higher chance that + // we will find space for them. + m_fJumpStubOverflow = TRUE; } - - // Keep track of conservative estimate of how much memory may be needed by jump stubs. We will use it to reserve extra memory - // on retry to increase chances that the retry succeeds. - m_reserveForJumpStubs = max((size_t)0x400, m_reserveForJumpStubs + 0x10); } + + // Keep track of conservative estimate of how much memory may be needed by jump stubs. We will use it to reserve extra memory + // on retry to increase chances that the retry succeeds. + m_reserveForJumpStubs = max((size_t)0x400, m_reserveForJumpStubs + 0x10); } + } - LOG((LF_JIT, LL_INFO100000, "Encoded a PCREL32 at" FMT_ADDR "to" FMT_ADDR "+%d, delta is 0x%04x\n", - DBG_ADDR(fixupLocation), DBG_ADDR(target), addlDelta, delta)); + LOG((LF_JIT, LL_INFO100000, "Encoded a PCREL32 at" FMT_ADDR "to" FMT_ADDR "+%d, delta is 0x%04x\n", + DBG_ADDR(fixupLocation), DBG_ADDR(target), addlDelta, delta)); - // Write the 32-bits pc-relative delta into location - *fixupLocationRW = (INT32) delta; - } + // Write the 32-bits pc-relative delta into location + *fixupLocationRW = (INT32) delta; break; + } #endif // TARGET_AMD64 #ifdef TARGET_ARM64 - case IMAGE_REL_ARM64_BRANCH26: // 26 bit offset << 2 & sign ext, for B and BL - { - _ASSERTE(addlDelta == 0); + case CorInfoReloc::ARM64_BRANCH26: // 26 bit offset << 2 & sign ext, for B and BL + { + _ASSERTE(addlDelta == 0); - PCODE branchTarget = (PCODE) target; - _ASSERTE((branchTarget & 0x3) == 0); // the low two bits must be zero + PCODE branchTarget = (PCODE) target; + _ASSERTE((branchTarget & 0x3) == 0); // the low two bits must be zero - PCODE fixupLocation = (PCODE) location; - PCODE fixupLocationRW = (PCODE) locationRW; - _ASSERTE((fixupLocation & 0x3) == 0); // the low two bits must be zero + PCODE fixupLocation = (PCODE) location; + PCODE fixupLocationRW = (PCODE) locationRW; + _ASSERTE((fixupLocation & 0x3) == 0); // the low two bits must be zero - delta = (INT64)(branchTarget - fixupLocation); - _ASSERTE((delta & 0x3) == 0); // the low two bits must be zero + delta = (INT64)(branchTarget - fixupLocation); + _ASSERTE((delta & 0x3) == 0); // the low two bits must be zero - UINT32 branchInstr = *((UINT32*) fixupLocationRW); - branchInstr &= 0xFC000000; // keep bits 31-26 - _ASSERTE((branchInstr & 0x7FFFFFFF) == 0x14000000); // Must be B or BL + UINT32 branchInstr = *((UINT32*) fixupLocationRW); + branchInstr &= 0xFC000000; // keep bits 31-26 + _ASSERTE((branchInstr & 0x7FFFFFFF) == 0x14000000); // Must be B or BL - // - // Do we need to insert a jump stub to make the source reach the target? - // - // - if (!FitsInRel28(delta)) + // + // Do we need to insert a jump stub to make the source reach the target? + // + // + if (!FitsInRel28(delta)) + { + TADDR jumpStubAddr; + + if (m_fJumpStubOverflow) + { + // Do not attempt to allocate more jump stubs. We are going to throw away the code and retry anyway. + jumpStubAddr = 0; + } + else { - TADDR jumpStubAddr; - if (m_fJumpStubOverflow) - { - // Do not attempt to allocate more jump stubs. We are going to throw away the code and retry anyway. - jumpStubAddr = 0; - } - else - { + // Use jump stub. + // + TADDR baseAddr = (TADDR)fixupLocation; + TADDR loAddr = baseAddr - 0x08000000; // -2^27 + TADDR hiAddr = baseAddr + 0x07FFFFFF; // +2^27-1 - // Use jump stub. - // - TADDR baseAddr = (TADDR)fixupLocation; - TADDR loAddr = baseAddr - 0x08000000; // -2^27 - TADDR hiAddr = baseAddr + 0x07FFFFFF; // +2^27-1 - - // Check for the wrap around cases - if (loAddr > baseAddr) - loAddr = UINT64_MIN; // overflow - if (hiAddr < baseAddr) - hiAddr = UINT64_MAX; // overflow - - jumpStubAddr = ExecutionManager::jumpStub(m_pMethodBeingCompiled, - (PCODE) target, - (BYTE *) loAddr, - (BYTE *) hiAddr, - NULL, - false); - } + // Check for the wrap around cases + if (loAddr > baseAddr) + loAddr = UINT64_MIN; // overflow + if (hiAddr < baseAddr) + hiAddr = UINT64_MAX; // overflow - // Keep track of conservative estimate of how much memory may be needed by jump stubs. We will use it to reserve extra memory - // on retry to increase chances that the retry succeeds. - m_reserveForJumpStubs = max((size_t)0x400, m_reserveForJumpStubs + 2*BACK_TO_BACK_JUMP_ALLOCATE_SIZE); + jumpStubAddr = ExecutionManager::jumpStub(m_pMethodBeingCompiled, + (PCODE) target, + (BYTE *) loAddr, + (BYTE *) hiAddr, + NULL, + false); + } - if (jumpStubAddr == 0) - { - // This forces the JIT to retry the method, which allows us to reserve more space for jump stubs and have a higher chance that - // we will find space for them. - m_fJumpStubOverflow = TRUE; - break; - } + // Keep track of conservative estimate of how much memory may be needed by jump stubs. We will use it to reserve extra memory + // on retry to increase chances that the retry succeeds. + m_reserveForJumpStubs = max((size_t)0x400, m_reserveForJumpStubs + 2*BACK_TO_BACK_JUMP_ALLOCATE_SIZE); - delta = (INT64)(jumpStubAddr - fixupLocation); + if (jumpStubAddr == 0) + { + // This forces the JIT to retry the method, which allows us to reserve more space for jump stubs and have a higher chance that + // we will find space for them. + m_fJumpStubOverflow = TRUE; + break; + } - if (!FitsInRel28(delta)) - { - _ASSERTE(!"jump stub was not in expected range"); - EEPOLICY_HANDLE_FATAL_ERROR(COR_E_EXECUTIONENGINE); - } + delta = (INT64)(jumpStubAddr - fixupLocation); - LOG((LF_JIT, LL_INFO100000, "Using JumpStub at" FMT_ADDR "that jumps to" FMT_ADDR "\n", - DBG_ADDR(jumpStubAddr), DBG_ADDR(target))); + if (!FitsInRel28(delta)) + { + _ASSERTE(!"jump stub was not in expected range"); + EEPOLICY_HANDLE_FATAL_ERROR(COR_E_EXECUTIONENGINE); } - LOG((LF_JIT, LL_INFO100000, "Encoded a BRANCH26 at" FMT_ADDR "to" FMT_ADDR ", delta is 0x%04x\n", - DBG_ADDR(fixupLocation), DBG_ADDR(target), delta)); + LOG((LF_JIT, LL_INFO100000, "Using JumpStub at" FMT_ADDR "that jumps to" FMT_ADDR "\n", + DBG_ADDR(jumpStubAddr), DBG_ADDR(target))); + } - _ASSERTE(FitsInRel28(delta)); + LOG((LF_JIT, LL_INFO100000, "Encoded a BRANCH26 at" FMT_ADDR "to" FMT_ADDR ", delta is 0x%04x\n", + DBG_ADDR(fixupLocation), DBG_ADDR(target), delta)); - PutArm64Rel28((UINT32*) fixupLocationRW, (INT32)delta); - } + _ASSERTE(FitsInRel28(delta)); + + PutArm64Rel28((UINT32*) fixupLocationRW, (INT32)delta); break; + } - case IMAGE_REL_ARM64_PAGEBASE_REL21: - { - _ASSERTE(addlDelta == 0); + case CorInfoReloc::ARM64_PAGEBASE_REL21: + { + _ASSERTE(addlDelta == 0); - // Write the 21 bits pc-relative page address into location. - INT64 targetPage = (INT64)target & 0xFFFFFFFFFFFFF000LL; - INT64 locationPage = (INT64)location & 0xFFFFFFFFFFFFF000LL; - INT64 relPage = (INT64)(targetPage - locationPage); - INT32 imm21 = (INT32)(relPage >> 12) & 0x1FFFFF; - PutArm64Rel21((UINT32 *)locationRW, imm21); - } + // Write the 21 bits pc-relative page address into location. + INT64 targetPage = (INT64)target & 0xFFFFFFFFFFFFF000LL; + INT64 locationPage = (INT64)location & 0xFFFFFFFFFFFFF000LL; + INT64 relPage = (INT64)(targetPage - locationPage); + INT32 imm21 = (INT32)(relPage >> 12) & 0x1FFFFF; + PutArm64Rel21((UINT32 *)locationRW, imm21); break; + } - case IMAGE_REL_ARM64_PAGEOFFSET_12A: - { - _ASSERTE(addlDelta == 0); + case CorInfoReloc::ARM64_PAGEOFFSET_12A: + { + _ASSERTE(addlDelta == 0); - // Write the 12 bits page offset into location. - INT32 imm12 = (INT32)(SIZE_T)target & 0xFFFLL; - PutArm64Rel12((UINT32 *)locationRW, imm12); - } + // Write the 12 bits page offset into location. + INT32 imm12 = (INT32)(SIZE_T)target & 0xFFFLL; + PutArm64Rel12((UINT32 *)locationRW, imm12); break; + } #endif // TARGET_ARM64 #ifdef TARGET_LOONGARCH64 - case IMAGE_REL_LOONGARCH64_PC: - { - _ASSERTE(addlDelta == 0); + case CorInfoReloc::LOONGARCH64_PC: + { + _ASSERTE(addlDelta == 0); - INT64 imm = (INT64)target - ((INT64)location & 0xFFFFFFFFFFFFF000LL); - imm += ((INT64)target & 0x800) << 1; - PutLoongArch64PC12((UINT32 *)locationRW, imm); - } + INT64 imm = (INT64)target - ((INT64)location & 0xFFFFFFFFFFFFF000LL); + imm += ((INT64)target & 0x800) << 1; + PutLoongArch64PC12((UINT32 *)locationRW, imm); break; + } - case IMAGE_REL_LOONGARCH64_JIR: - { - _ASSERTE(addlDelta == 0); + case CorInfoReloc::LOONGARCH64_JIR: + { + _ASSERTE(addlDelta == 0); - INT64 imm = (INT64)target - (INT64)location; - PutLoongArch64JIR((UINT32 *)locationRW, imm); - } + INT64 imm = (INT64)target - (INT64)location; + PutLoongArch64JIR((UINT32 *)locationRW, imm); break; - + } #endif // TARGET_LOONGARCH64 #ifdef TARGET_RISCV64 - case IMAGE_REL_RISCV64_PC: - { - _ASSERTE(addlDelta == 0); + case CorInfoReloc::RISCV64_PC: + { + _ASSERTE(addlDelta == 0); - INT64 offset = (INT64)target - (INT64)location; - PutRiscV64AuipcItype((UINT32 *)locationRW, offset); - } + INT64 offset = (INT64)target - (INT64)location; + PutRiscV64AuipcItype((UINT32 *)locationRW, offset); break; - + } #endif // TARGET_RISCV64 default: @@ -12087,7 +12082,7 @@ void CEEJitInfo::recordRelocation(void * location, // // Under these assumptions we should only hit the "recovery" case once the // preferred range is actually full. -WORD CEEJitInfo::getRelocTypeHint(void * target) +CorInfoReloc CEEJitInfo::getRelocTypeHint(void * target) { CONTRACTL { THROWS; @@ -12099,12 +12094,12 @@ WORD CEEJitInfo::getRelocTypeHint(void * target) if (m_fAllowRel32) { if (ExecutableAllocator::IsPreferredExecutableRange(target)) - return IMAGE_REL_BASED_REL32; + return CorInfoReloc::REL32; } #endif // TARGET_AMD64 // No hints - return (WORD)-1; + return CorInfoReloc::NONE; } void CEEInfo::JitProcessShutdownWork() @@ -14950,7 +14945,7 @@ void CEEInfo::recordRelocation( void * location, /* IN */ void * locationRW, /* IN */ void * target, /* IN */ - WORD fRelocType, /* IN */ + CorInfoReloc fRelocType, /* IN */ INT32 addlDelta /* IN */ ) { @@ -14958,10 +14953,11 @@ void CEEInfo::recordRelocation( UNREACHABLE(); // only called on derived class. } -WORD CEEInfo::getRelocTypeHint(void * target) +CorInfoReloc CEEInfo::getRelocTypeHint(void * target) { LIMITED_METHOD_CONTRACT; - UNREACHABLE_RET(); // only called on derived class. + UNREACHABLE(); // only called on derived class. + return CorInfoReloc::NONE; } uint32_t CEEInfo::getExpectedTargetArchitecture() diff --git a/src/coreclr/vm/jitinterface.h b/src/coreclr/vm/jitinterface.h index f4be045060f437..d71dc3d59304b5 100644 --- a/src/coreclr/vm/jitinterface.h +++ b/src/coreclr/vm/jitinterface.h @@ -716,10 +716,10 @@ class CEEJitInfo final : public CEECodeGenInfo void *location, void *locationRW, void *target, - uint16_t fRelocType, + CorInfoReloc fRelocType, int32_t addlDelta) override; - uint16_t getRelocTypeHint(void * target) override; + CorInfoReloc getRelocTypeHint(void * target) override; void SetDebugInfo(PTR_BYTE pDebugInfo) override; From b02fa4a8642779ec128a9cb75c8e13293087b637 Mon Sep 17 00:00:00 2001 From: Jakob Botsch Nielsen Date: Mon, 24 Nov 2025 13:47:37 +0100 Subject: [PATCH 2/8] Clean up switch --- .../tools/Common/JitInterface/CorInfoImpl.cs | 51 +++++++++---------- 1 file changed, 24 insertions(+), 27 deletions(-) diff --git a/src/coreclr/tools/Common/JitInterface/CorInfoImpl.cs b/src/coreclr/tools/Common/JitInterface/CorInfoImpl.cs index 62c775326e6805..4d288ec6475e63 100644 --- a/src/coreclr/tools/Common/JitInterface/CorInfoImpl.cs +++ b/src/coreclr/tools/Common/JitInterface/CorInfoImpl.cs @@ -4065,33 +4065,30 @@ private ref ArrayBuilder findRelocBlock(BlockType blockType, out int // Translates relocation type constants used by JIT to RelocType enumeration private static RelocType GetRelocType(CorInfoReloc reloc) - { - switch (reloc) - { - case CorInfoReloc.DIR32: return RelocType.IMAGE_REL_BASED_HIGHLOW; - case CorInfoReloc.DIR64: return RelocType.IMAGE_REL_BASED_DIR64; - case CorInfoReloc.REL32: return RelocType.IMAGE_REL_BASED_REL32; - case CorInfoReloc.ARM64_BRANCH26: return RelocType.IMAGE_REL_BASED_ARM64_BRANCH26; - case CorInfoReloc.ARM64_PAGEBASE_REL21: return RelocType.IMAGE_REL_BASED_ARM64_PAGEBASE_REL21; - case CorInfoReloc.ARM64_PAGEOFFSET_12A: return RelocType.IMAGE_REL_BASED_ARM64_PAGEOFFSET_12A; - case CorInfoReloc.ARM64_LIN_TLSDESC_ADR_PAGE21: return RelocType.IMAGE_REL_AARCH64_TLSDESC_ADR_PAGE21; - case CorInfoReloc.ARM64_LIN_TLSDESC_LD64_LO12: return RelocType.IMAGE_REL_AARCH64_TLSDESC_LD64_LO12; - case CorInfoReloc.ARM64_LIN_TLSDESC_ADD_LO12: return RelocType.IMAGE_REL_AARCH64_TLSDESC_ADD_LO12; - case CorInfoReloc.ARM64_LIN_TLSDESC_CALL: return RelocType.IMAGE_REL_AARCH64_TLSDESC_CALL; - case CorInfoReloc.ARM64_WIN_TLS_SECREL_HIGH12A: return RelocType.IMAGE_REL_ARM64_TLS_SECREL_HIGH12A; - case CorInfoReloc.ARM64_WIN_TLS_SECREL_LOW12A: return RelocType.IMAGE_REL_ARM64_TLS_SECREL_LOW12A; - case CorInfoReloc.AMD64_WIN_SECREL: return RelocType.IMAGE_REL_SECREL; - case CorInfoReloc.AMD64_LIN_TLSGD: return RelocType.IMAGE_REL_TLSGD; - case CorInfoReloc.ARM32_THUMB_BRANCH24: return RelocType.IMAGE_REL_BASED_THUMB_BRANCH24; - case CorInfoReloc.ARM32_THUMB_MOV32: return RelocType.IMAGE_REL_BASED_THUMB_MOV32; - case CorInfoReloc.ARM32_THUMB_MOV32_PCREL: return RelocType.IMAGE_REL_BASED_THUMB_MOV32_PCREL; - case CorInfoReloc.LOONGARCH64_PC: return RelocType.IMAGE_REL_BASED_LOONGARCH64_PC; - case CorInfoReloc.LOONGARCH64_JIR: return RelocType.IMAGE_REL_BASED_LOONGARCH64_JIR; - case CorInfoReloc.RISCV64_PC: return RelocType.IMAGE_REL_BASED_RISCV64_PC; - default: - throw new ArgumentException("Unsupported relocation type: " + reloc); - } - } + => reloc switch + { + CorInfoReloc.DIR32 => RelocType.IMAGE_REL_BASED_HIGHLOW, + CorInfoReloc.DIR64 => RelocType.IMAGE_REL_BASED_DIR64, + CorInfoReloc.REL32 => RelocType.IMAGE_REL_BASED_REL32, + CorInfoReloc.ARM64_BRANCH26 => RelocType.IMAGE_REL_BASED_ARM64_BRANCH26, + CorInfoReloc.ARM64_PAGEBASE_REL21 => RelocType.IMAGE_REL_BASED_ARM64_PAGEBASE_REL21, + CorInfoReloc.ARM64_PAGEOFFSET_12A => RelocType.IMAGE_REL_BASED_ARM64_PAGEOFFSET_12A, + CorInfoReloc.ARM64_LIN_TLSDESC_ADR_PAGE21 => RelocType.IMAGE_REL_AARCH64_TLSDESC_ADR_PAGE21, + CorInfoReloc.ARM64_LIN_TLSDESC_LD64_LO12 => RelocType.IMAGE_REL_AARCH64_TLSDESC_LD64_LO12, + CorInfoReloc.ARM64_LIN_TLSDESC_ADD_LO12 => RelocType.IMAGE_REL_AARCH64_TLSDESC_ADD_LO12, + CorInfoReloc.ARM64_LIN_TLSDESC_CALL => RelocType.IMAGE_REL_AARCH64_TLSDESC_CALL, + CorInfoReloc.ARM64_WIN_TLS_SECREL_HIGH12A => RelocType.IMAGE_REL_ARM64_TLS_SECREL_HIGH12A, + CorInfoReloc.ARM64_WIN_TLS_SECREL_LOW12A => RelocType.IMAGE_REL_ARM64_TLS_SECREL_LOW12A, + CorInfoReloc.AMD64_WIN_SECREL => RelocType.IMAGE_REL_SECREL, + CorInfoReloc.AMD64_LIN_TLSGD => RelocType.IMAGE_REL_TLSGD, + CorInfoReloc.ARM32_THUMB_BRANCH24 => RelocType.IMAGE_REL_BASED_THUMB_BRANCH24, + CorInfoReloc.ARM32_THUMB_MOV32 => RelocType.IMAGE_REL_BASED_THUMB_MOV32, + CorInfoReloc.ARM32_THUMB_MOV32_PCREL => RelocType.IMAGE_REL_BASED_THUMB_MOV32_PCREL, + CorInfoReloc.LOONGARCH64_PC => RelocType.IMAGE_REL_BASED_LOONGARCH64_PC, + CorInfoReloc.LOONGARCH64_JIR => RelocType.IMAGE_REL_BASED_LOONGARCH64_JIR, + CorInfoReloc.RISCV64_PC => RelocType.IMAGE_REL_BASED_RISCV64_PC, + _ => throw new ArgumentException("Unsupported relocation type: " + reloc); + }; private void recordRelocation(void* location, void* locationRW, void* target, CorInfoReloc fRelocType, int addlDelta) { From 548701f87148e957f1bff38f6344afb513061325 Mon Sep 17 00:00:00 2001 From: Jakob Botsch Nielsen Date: Mon, 24 Nov 2025 14:10:44 +0100 Subject: [PATCH 3/8] Remove remaining references --- src/coreclr/jit/emitloongarch64.cpp | 4 ++-- src/coreclr/jit/emitriscv64.cpp | 4 ++-- src/coreclr/jit/instr.cpp | 2 +- src/coreclr/jit/targetamd64.h | 6 ------ 4 files changed, 5 insertions(+), 11 deletions(-) diff --git a/src/coreclr/jit/emitloongarch64.cpp b/src/coreclr/jit/emitloongarch64.cpp index 85c5589212dbf1..6e33ba7271dde3 100644 --- a/src/coreclr/jit/emitloongarch64.cpp +++ b/src/coreclr/jit/emitloongarch64.cpp @@ -2646,7 +2646,7 @@ unsigned emitter::emitOutputCall(insGroup* ig, BYTE* dst, instrDesc* id, code_t #endif emitOutput_Instr(dst, 0x4c000000 | ((int)REG_DEFAULT_HELPER_CALL_TARGET << 5) | reg2); - emitRecordRelocation(dst - 4, (BYTE*)addr, IMAGE_REL_LOONGARCH64_JIR); + emitRecordRelocation(dst - 4, (BYTE*)addr, CorInfoReloc::LOONGARCH64_JIR); } else { @@ -3259,7 +3259,7 @@ size_t emitter::emitOutputInstr(insGroup* ig, instrDesc* id, BYTE** dp) dstRW += 4; - emitRecordRelocation(dstRW - 8 - writeableOffset, id->idAddr()->iiaAddr, IMAGE_REL_LOONGARCH64_PC); + emitRecordRelocation(dstRW - 8 - writeableOffset, id->idAddr()->iiaAddr, CorInfoReloc::LOONGARCH64_PC); sz = sizeof(instrDesc); } diff --git a/src/coreclr/jit/emitriscv64.cpp b/src/coreclr/jit/emitriscv64.cpp index 0bd4d67b38c43b..653c48536b0071 100644 --- a/src/coreclr/jit/emitriscv64.cpp +++ b/src/coreclr/jit/emitriscv64.cpp @@ -2022,7 +2022,7 @@ unsigned emitter::emitOutputCall(const insGroup* ig, BYTE* dst, instrDesc* id) dst += emitOutput_ITypeInstr(dst, INS_jalr, linkReg, tempReg, 0); assert(id->idIsDspReloc()); - emitRecordRelocation(origDst, (BYTE*)addr, IMAGE_REL_RISCV64_PC); + emitRecordRelocation(origDst, (BYTE*)addr, CorInfoReloc::RISCV64_PC); } // If the method returns a GC ref, mark INTRET (A0) appropriately. @@ -2884,7 +2884,7 @@ BYTE* emitter::emitOutputInstr_OptsReloc(BYTE* dst, const instrDesc* id, instruc dst += emitOutput_ITypeInstr(dst, *ins, reg1, reg1, 0); - emitRecordRelocation(dstBase, id->idAddr()->iiaAddr, IMAGE_REL_RISCV64_PC); + emitRecordRelocation(dstBase, id->idAddr()->iiaAddr, CorInfoReloc::RISCV64_PC); return dst; } diff --git a/src/coreclr/jit/instr.cpp b/src/coreclr/jit/instr.cpp index 857be2441bb26b..edc03acaa53348 100644 --- a/src/coreclr/jit/instr.cpp +++ b/src/coreclr/jit/instr.cpp @@ -1911,7 +1911,7 @@ bool CodeGenInterface::validImmForBL(ssize_t addr) { // On arm64, we always assume a call target is in range and generate a 28-bit relative // 'bl' instruction. If this isn't sufficient range, the VM will generate a jump stub when - // we call recordRelocation(). See the IMAGE_REL_ARM64_BRANCH26 case in jitinterface.cpp + // we call recordRelocation(). See the CorInfoReloc::ARM64_BRANCH26 case in jitinterface.cpp // (for JIT) or zapinfo.cpp (for AOT). If we cannot allocate a jump stub, it is fatal. return true; } diff --git a/src/coreclr/jit/targetamd64.h b/src/coreclr/jit/targetamd64.h index c6cdf213bcb5a4..a298b9c989fcdf 100644 --- a/src/coreclr/jit/targetamd64.h +++ b/src/coreclr/jit/targetamd64.h @@ -548,12 +548,6 @@ #define REG_ASYNC_CONTINUATION_RET REG_RCX #define RBM_ASYNC_CONTINUATION_RET RBM_RCX - // What sort of reloc do we use for [disp32] address mode - #define IMAGE_REL_BASED_DISP32 IMAGE_REL_BASED_REL32 - - // What sort of reloc to we use for 'moffset' address mode (for 'mov eax, moffset' or 'mov moffset, eax') - #define IMAGE_REL_BASED_MOFFSET IMAGE_REL_BASED_DIR64 - // Pointer-sized string move instructions #define INS_movsp INS_movsq #define INS_r_movsp INS_r_movsq From a0a651d724faea512a4620d3c796d746b79c272e Mon Sep 17 00:00:00 2001 From: Jakob Botsch Nielsen Date: Mon, 24 Nov 2025 14:12:31 +0100 Subject: [PATCH 4/8] Retain a comment, fix indentation --- src/coreclr/inc/corinfo.h | 12 ++++++++++++ src/coreclr/inc/corjit.h | 2 +- 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/src/coreclr/inc/corinfo.h b/src/coreclr/inc/corinfo.h index c9915f916fdda4..42e47776225d04 100644 --- a/src/coreclr/inc/corinfo.h +++ b/src/coreclr/inc/corinfo.h @@ -884,6 +884,18 @@ enum class CorInfoReloc // Arm32 relocs ARM32_THUMB_BRANCH24, // Thumb2: B, BL ARM32_THUMB_MOV32, // Thumb2: MOVW/MOVT + // The identifier for ARM32-specific PC-relative address + // computation corresponds to the following instruction + // sequence: + // l0: movw rX, #imm_lo // 4 byte + // l4: movt rX, #imm_hi // 4 byte + // l8: add rX, pc <- after this instruction rX = relocTarget + // + // Program counter at l8 is address of l8 + 4 + // Address of relocated movw/movt is l0 + // So, imm should be calculated as the following: + // imm = relocTarget - (l8 + 4) = relocTarget - (l0 + 8 + 4) = relocTarget - (l_0 + 12) + // So, the value of offset correction is 12 ARM32_THUMB_MOV32_PCREL, // Thumb2: MOVW/MOVT // LoongArch64 relocs diff --git a/src/coreclr/inc/corjit.h b/src/coreclr/inc/corjit.h index 7cbe2573ffc9db..126640eaa3ab01 100644 --- a/src/coreclr/inc/corjit.h +++ b/src/coreclr/inc/corjit.h @@ -425,7 +425,7 @@ class ICorJitInfo : public ICorDynamicInfo void * location, /* IN */ void * locationRW, /* IN */ void * target, /* IN */ - CorInfoReloc fRelocType, /* IN */ + CorInfoReloc fRelocType, /* IN */ int32_t addlDelta = 0 /* IN */ ) = 0; From 00f127c67c2f3edc94b9984a3967125a634bea30 Mon Sep 17 00:00:00 2001 From: Jakob Botsch Nielsen Date: Mon, 24 Nov 2025 14:32:34 +0100 Subject: [PATCH 5/8] Fix build after nit --- src/coreclr/tools/Common/JitInterface/CorInfoImpl.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/coreclr/tools/Common/JitInterface/CorInfoImpl.cs b/src/coreclr/tools/Common/JitInterface/CorInfoImpl.cs index 6d50a23bd03a5f..b1e862ef85102d 100644 --- a/src/coreclr/tools/Common/JitInterface/CorInfoImpl.cs +++ b/src/coreclr/tools/Common/JitInterface/CorInfoImpl.cs @@ -4088,7 +4088,7 @@ private static RelocType GetRelocType(CorInfoReloc reloc) CorInfoReloc.LOONGARCH64_PC => RelocType.IMAGE_REL_BASED_LOONGARCH64_PC, CorInfoReloc.LOONGARCH64_JIR => RelocType.IMAGE_REL_BASED_LOONGARCH64_JIR, CorInfoReloc.RISCV64_PC => RelocType.IMAGE_REL_BASED_RISCV64_PC, - _ => throw new ArgumentException("Unsupported relocation type: " + reloc); + _ => throw new ArgumentException("Unsupported relocation type: " + reloc), }; private void recordRelocation(void* location, void* locationRW, void* target, CorInfoReloc fRelocType, int addlDelta) From 1c94885594ad9a7d7ca35cba4fef52097a653256 Mon Sep 17 00:00:00 2001 From: Jakob Botsch Nielsen Date: Mon, 24 Nov 2025 16:51:05 +0100 Subject: [PATCH 6/8] Combine DIR32/DIR64 -> DIRECT, rename REL32 -> RELATIVE32 --- src/coreclr/inc/corinfo.h | 5 +- src/coreclr/jit/codegenxarch.cpp | 4 +- src/coreclr/jit/emit.cpp | 8 ++- src/coreclr/jit/emitxarch.cpp | 52 +++++++++---------- src/coreclr/jit/gentree.cpp | 8 +-- .../tools/Common/JitInterface/CorInfoImpl.cs | 9 ++-- .../tools/Common/JitInterface/CorInfoTypes.cs | 5 +- .../superpmi-shared/compileresult.cpp | 37 +++++++------ .../superpmi-shared/methodcontext.cpp | 2 +- src/coreclr/vm/jitinterface.cpp | 16 +++--- 10 files changed, 68 insertions(+), 78 deletions(-) diff --git a/src/coreclr/inc/corinfo.h b/src/coreclr/inc/corinfo.h index 42e47776225d04..7cd408af5905bb 100644 --- a/src/coreclr/inc/corinfo.h +++ b/src/coreclr/inc/corinfo.h @@ -857,9 +857,8 @@ enum class CorInfoReloc NONE, // General relocation types - DIR32, // Direct/absolute 32 bit address - DIR64, // Direct/absolute 64 bit address - REL32, // 32-bit relative address from byte following reloc + DIRECT, // Direct/absolute pointer sized address + RELATIVE32, // 32-bit relative address from byte following reloc // Arm64 relocs ARM64_BRANCH26, // Arm64: B, BL diff --git a/src/coreclr/jit/codegenxarch.cpp b/src/coreclr/jit/codegenxarch.cpp index 0837ad63e90019..47256aa050acec 100644 --- a/src/coreclr/jit/codegenxarch.cpp +++ b/src/coreclr/jit/codegenxarch.cpp @@ -11742,7 +11742,7 @@ CorInfoReloc CodeGenInterface::genAddrRelocTypeHint(size_t addr) bool CodeGenInterface::genDataIndirAddrCanBeEncodedAsPCRelOffset(size_t addr) { #ifdef TARGET_AMD64 - return genAddrRelocTypeHint(addr) == CorInfoReloc::REL32; + return genAddrRelocTypeHint(addr) == CorInfoReloc::RELATIVE32; #else // x86: PC-relative addressing is available only for control flow instructions (jmp and call) return false; @@ -11763,7 +11763,7 @@ bool CodeGenInterface::genDataIndirAddrCanBeEncodedAsPCRelOffset(size_t addr) bool CodeGenInterface::genCodeIndirAddrCanBeEncodedAsPCRelOffset(size_t addr) { #ifdef TARGET_AMD64 - return genAddrRelocTypeHint(addr) == CorInfoReloc::REL32; + return genAddrRelocTypeHint(addr) == CorInfoReloc::RELATIVE32; #else // x86: PC-relative addressing is available only for control flow instructions (jmp and call) return true; diff --git a/src/coreclr/jit/emit.cpp b/src/coreclr/jit/emit.cpp index 498ecc091471bd..4f7dad8596a071 100644 --- a/src/coreclr/jit/emit.cpp +++ b/src/coreclr/jit/emit.cpp @@ -8521,8 +8521,7 @@ void emitter::emitOutputDataSec(dataSecDsc* sec, BYTE* dst) bDstRW[i] = (target_size_t)(size_t)target; if (emitComp->opts.compReloc) { - CorInfoReloc relocType = TARGET_POINTER_SIZE == 8 ? CorInfoReloc::DIR64 : CorInfoReloc::DIR32; - emitRecordRelocation(&(bDstRW[i]), target, relocType); + emitRecordRelocation(&(bDstRW[i]), target, CorInfoReloc::DIRECT); } JITDUMP(" " FMT_BB ": 0x%p\n", block->bbNum, bDstRW[i]); @@ -8568,11 +8567,10 @@ void emitter::emitOutputDataSec(dataSecDsc* sec, BYTE* dst) aDstRW[i].DiagnosticIP = (target_size_t)(uintptr_t)target; if (emitComp->opts.compReloc) { - CorInfoReloc relocType = TARGET_POINTER_SIZE == 8 ? CorInfoReloc::DIR64 : CorInfoReloc::DIR32; - emitRecordRelocation(&aDstRW[i].Resume, emitAsyncResumeStubEntryPoint, relocType); + emitRecordRelocation(&aDstRW[i].Resume, emitAsyncResumeStubEntryPoint, CorInfoReloc::DIRECT); if (target != nullptr) { - emitRecordRelocation(&aDstRW[i].DiagnosticIP, target, relocType); + emitRecordRelocation(&aDstRW[i].DiagnosticIP, target, CorInfoReloc::DIRECT); } } diff --git a/src/coreclr/jit/emitxarch.cpp b/src/coreclr/jit/emitxarch.cpp index 38210c9dbc0a6f..f2afdc15d88049 100644 --- a/src/coreclr/jit/emitxarch.cpp +++ b/src/coreclr/jit/emitxarch.cpp @@ -14251,11 +14251,11 @@ BYTE* emitter::emitOutputAlign(insGroup* ig, instrDesc* id, BYTE* dst) } #ifdef TARGET_64BIT -static constexpr CorInfoReloc RELOC_DISP32 = CorInfoReloc::REL32; -static constexpr CorInfoReloc RELOC_MOFFSET = CorInfoReloc::DIR64; +static constexpr CorInfoReloc RELOC_DISP32 = CorInfoReloc::RELATIVE32; +static constexpr CorInfoReloc RELOC_MOFFSET = CorInfoReloc::DIRECT; #else -static constexpr CorInfoReloc RELOC_DISP32 = CorInfoReloc::DIR32; -static constexpr CorInfoReloc RELOC_MOFFSET = CorInfoReloc::DIR32; +static constexpr CorInfoReloc RELOC_DISP32 = CorInfoReloc::DIRECT; +static constexpr CorInfoReloc RELOC_MOFFSET = CorInfoReloc::DIRECT; #endif /***************************************************************************** @@ -14785,7 +14785,7 @@ BYTE* emitter::emitOutputAM(BYTE* dst, instrDesc* id, code_t code, CnsVal* addc) // This addr mode should never be used while generating relocatable AOT code nor if // the addr can be encoded as pc-relative address. noway_assert(!emitComp->opts.compReloc); - noway_assert(codeGen->genAddrRelocTypeHint((size_t)dsp) != CorInfoReloc::REL32); + noway_assert(codeGen->genAddrRelocTypeHint((size_t)dsp) != CorInfoReloc::RELATIVE32); noway_assert((int)dsp == dsp); // This requires, specifying a SIB byte after ModRM byte. @@ -14822,7 +14822,7 @@ BYTE* emitter::emitOutputAM(BYTE* dst, instrDesc* id, code_t code, CnsVal* addc) if (id->idIsDspReloc()) { - emitRecordRelocation((void*)(dst - sizeof(INT32)), (void*)dsp, CorInfoReloc::DIR32); + emitRecordRelocation((void*)(dst - sizeof(INT32)), (void*)dsp, RELOC_DISP32); } } } @@ -14840,7 +14840,7 @@ BYTE* emitter::emitOutputAM(BYTE* dst, instrDesc* id, code_t code, CnsVal* addc) if (id->idIsDspReloc()) { - emitRecordRelocation((void*)(dst - sizeof(INT32)), (void*)dsp, CorInfoReloc::DIR32); + emitRecordRelocation((void*)(dst - sizeof(INT32)), (void*)dsp, RELOC_DISP32); } } break; @@ -14872,7 +14872,7 @@ BYTE* emitter::emitOutputAM(BYTE* dst, instrDesc* id, code_t code, CnsVal* addc) if (id->idIsDspReloc()) { - emitRecordRelocation((void*)(dst - sizeof(INT32)), (void*)dsp, CorInfoReloc::DIR32); + emitRecordRelocation((void*)(dst - sizeof(INT32)), (void*)dsp, RELOC_DISP32); } } } @@ -14898,7 +14898,7 @@ BYTE* emitter::emitOutputAM(BYTE* dst, instrDesc* id, code_t code, CnsVal* addc) if (id->idIsDspReloc()) { - emitRecordRelocation((void*)(dst - sizeof(INT32)), (void*)dsp, CorInfoReloc::DIR32); + emitRecordRelocation((void*)(dst - sizeof(INT32)), (void*)dsp, RELOC_DISP32); } } break; @@ -14930,7 +14930,7 @@ BYTE* emitter::emitOutputAM(BYTE* dst, instrDesc* id, code_t code, CnsVal* addc) if (id->idIsDspReloc()) { - emitRecordRelocation((void*)(dst - sizeof(INT32)), (void*)dsp, CorInfoReloc::DIR32); + emitRecordRelocation((void*)(dst - sizeof(INT32)), (void*)dsp, RELOC_DISP32); } } } @@ -14959,7 +14959,7 @@ BYTE* emitter::emitOutputAM(BYTE* dst, instrDesc* id, code_t code, CnsVal* addc) if (id->idIsDspReloc()) { - emitRecordRelocation((void*)(dst - sizeof(INT32)), (void*)dsp, CorInfoReloc::DIR32); + emitRecordRelocation((void*)(dst - sizeof(INT32)), (void*)dsp, RELOC_DISP32); } } } @@ -15009,7 +15009,7 @@ BYTE* emitter::emitOutputAM(BYTE* dst, instrDesc* id, code_t code, CnsVal* addc) if (id->idIsDspReloc()) { - emitRecordRelocation((void*)(dst - sizeof(INT32)), (void*)dsp, CorInfoReloc::DIR32); + emitRecordRelocation((void*)(dst - sizeof(INT32)), (void*)dsp, RELOC_DISP32); } } } @@ -15035,7 +15035,7 @@ BYTE* emitter::emitOutputAM(BYTE* dst, instrDesc* id, code_t code, CnsVal* addc) if (id->idIsDspReloc()) { - emitRecordRelocation((void*)(dst - sizeof(INT32)), (void*)dsp, CorInfoReloc::DIR32); + emitRecordRelocation((void*)(dst - sizeof(INT32)), (void*)dsp, RELOC_DISP32); } } } @@ -15065,7 +15065,7 @@ BYTE* emitter::emitOutputAM(BYTE* dst, instrDesc* id, code_t code, CnsVal* addc) dst += emitOutputLong(dst, dsp); if (id->idIsDspReloc()) { - emitRecordRelocation((void*)(dst - sizeof(INT32)), (void*)dsp, CorInfoReloc::DIR32); + emitRecordRelocation((void*)(dst - sizeof(INT32)), (void*)dsp, RELOC_DISP32); } } } @@ -15098,7 +15098,7 @@ BYTE* emitter::emitOutputAM(BYTE* dst, instrDesc* id, code_t code, CnsVal* addc) if (id->idIsDspReloc()) { - emitRecordRelocation((void*)(dst - sizeof(INT32)), (void*)dsp, CorInfoReloc::DIR32); + emitRecordRelocation((void*)(dst - sizeof(INT32)), (void*)dsp, RELOC_DISP32); } } } @@ -15124,7 +15124,7 @@ BYTE* emitter::emitOutputAM(BYTE* dst, instrDesc* id, code_t code, CnsVal* addc) if (id->idIsDspReloc()) { - emitRecordRelocation((void*)(dst - sizeof(INT32)), (void*)dsp, CorInfoReloc::DIR32); + emitRecordRelocation((void*)(dst - sizeof(INT32)), (void*)dsp, RELOC_DISP32); } } } @@ -15160,7 +15160,7 @@ BYTE* emitter::emitOutputAM(BYTE* dst, instrDesc* id, code_t code, CnsVal* addc) if (addc->cnsReloc) { - emitRecordRelocation((void*)(dst - sizeof(INT32)), (void*)(size_t)cval, CorInfoReloc::DIR32); + emitRecordRelocation((void*)(dst - sizeof(INT32)), (void*)(size_t)cval, RELOC_DISP32); assert(opsz == 4); } } @@ -15692,7 +15692,7 @@ BYTE* emitter::emitOutputSV(BYTE* dst, instrDesc* id, code_t code, CnsVal* addc) if (addc->cnsReloc) { - emitRecordRelocation((void*)(dst - sizeof(INT32)), (void*)(size_t)cval, CorInfoReloc::DIR32); + emitRecordRelocation((void*)(dst - sizeof(INT32)), (void*)(size_t)cval, RELOC_DISP32); assert(opsz == 4); } } @@ -16208,7 +16208,7 @@ BYTE* emitter::emitOutputCV(BYTE* dst, instrDesc* id, code_t code, CnsVal* addc) } if (addc->cnsReloc) { - emitRecordRelocation((void*)(dst - sizeof(INT32)), (void*)(size_t)cval, CorInfoReloc::DIR32); + emitRecordRelocation((void*)(dst - sizeof(INT32)), (void*)(size_t)cval, RELOC_DISP32); assert(opsz == 4); } } @@ -17419,7 +17419,7 @@ BYTE* emitter::emitOutputRI(BYTE* dst, instrDesc* id) if (id->idIsCnsReloc()) { - emitRecordRelocation((void*)(dst - sizeof(INT32)), (void*)(size_t)val, CorInfoReloc::DIR32); + emitRecordRelocation((void*)(dst - sizeof(INT32)), (void*)(size_t)val, RELOC_DISP32); assert(size == EA_4BYTE); } } @@ -17593,7 +17593,7 @@ BYTE* emitter::emitOutputIV(BYTE* dst, instrDesc* id) dst += emitOutputLong(dst, val); if (id->idIsCnsReloc()) { - emitRecordRelocation((void*)(dst - sizeof(INT32)), (void*)(size_t)val, CorInfoReloc::DIR32); + emitRecordRelocation((void*)(dst - sizeof(INT32)), (void*)(size_t)val, RELOC_DISP32); } } break; @@ -17950,12 +17950,12 @@ BYTE* emitter::emitOutputLJ(insGroup* ig, BYTE* dst, instrDesc* i) { if (!relAddr) { - emitRecordRelocation((void*)(dst - sizeof(int32_t)), (void*)distVal, CorInfoReloc::DIR32); + emitRecordRelocation((void*)(dst - sizeof(int32_t)), (void*)distVal, RELOC_DISP32); } else if (crossJump) { assert(id->idjKeepLong); - emitRecordRelocation((void*)(dst - sizeof(int32_t)), dst + distVal, CorInfoReloc::REL32); + emitRecordRelocation((void*)(dst - sizeof(int32_t)), dst + distVal, CorInfoReloc::RELATIVE32); } } } @@ -18516,7 +18516,7 @@ size_t emitter::emitOutputInstr(insGroup* ig, instrDesc* id, BYTE** dp) // This addr mode should never be used while generating relocatable AOT code nor if // the addr can be encoded as pc-relative address. noway_assert(!emitComp->opts.compReloc); - noway_assert(codeGen->genAddrRelocTypeHint((size_t)addr) != CorInfoReloc::REL32); + noway_assert(codeGen->genAddrRelocTypeHint((size_t)addr) != CorInfoReloc::RELATIVE32); noway_assert(static_cast(reinterpret_cast(addr)) == (ssize_t)addr); // This requires, specifying a SIB byte after ModRM byte. @@ -18569,7 +18569,7 @@ size_t emitter::emitOutputInstr(insGroup* ig, instrDesc* id, BYTE** dp) if (id->idIsDspReloc()) { - emitRecordRelocation((void*)(dst - sizeof(INT32)), addr, CorInfoReloc::REL32); + emitRecordRelocation((void*)(dst - sizeof(INT32)), addr, CorInfoReloc::RELATIVE32); } DONE_CALL: @@ -18906,7 +18906,7 @@ size_t emitter::emitOutputInstr(insGroup* ig, instrDesc* id, BYTE** dp) if (id->idIsCnsReloc()) { - emitRecordRelocation((void*)(dst - sizeof(INT32)), (void*)(size_t)val, CorInfoReloc::DIR32); + emitRecordRelocation((void*)(dst - sizeof(INT32)), (void*)(size_t)val, RELOC_DISP32); assert(size == EA_4BYTE); } } diff --git a/src/coreclr/jit/gentree.cpp b/src/coreclr/jit/gentree.cpp index 8f8d66fea12449..fb008955730152 100644 --- a/src/coreclr/jit/gentree.cpp +++ b/src/coreclr/jit/gentree.cpp @@ -18314,7 +18314,7 @@ bool GenTreeIntConCommon::FitsInAddrBase(Compiler* comp) { // During AOT JIT is always asked to generate relocatable code. // Hence JIT will try to encode only icon handles as pc-relative offsets. - return IsIconHandle() && (comp->eeGetRelocTypeHint((void*)IconValue()) == CorInfoReloc::REL32); + return IsIconHandle() && (comp->eeGetRelocTypeHint((void*)IconValue()) == CorInfoReloc::RELATIVE32); } else { @@ -18335,7 +18335,7 @@ bool GenTreeIntConCommon::FitsInAddrBase(Compiler* comp) // offsets. Note that JIT will always attempt to relocate code addresses (.e.g call addr). // After an overflow, VM will assume any relocation recorded is for a code address and will // emit jump thunk if it cannot be encoded as pc-relative offset. - return (comp->eeGetRelocTypeHint((void*)IconValue()) == CorInfoReloc::REL32) || FitsInI32(); + return (comp->eeGetRelocTypeHint((void*)IconValue()) == CorInfoReloc::RELATIVE32) || FitsInI32(); } } @@ -18346,11 +18346,11 @@ bool GenTreeIntConCommon::AddrNeedsReloc(Compiler* comp) { // During AOT JIT is always asked to generate relocatable code. // Hence JIT will try to encode only icon handles as pc-relative offsets. - return IsIconHandle() && (comp->eeGetRelocTypeHint((void*)IconValue()) == CorInfoReloc::REL32); + return IsIconHandle() && (comp->eeGetRelocTypeHint((void*)IconValue()) == CorInfoReloc::RELATIVE32); } else { - return comp->eeGetRelocTypeHint((void*)IconValue()) == CorInfoReloc::REL32; + return comp->eeGetRelocTypeHint((void*)IconValue()) == CorInfoReloc::RELATIVE32; } } diff --git a/src/coreclr/tools/Common/JitInterface/CorInfoImpl.cs b/src/coreclr/tools/Common/JitInterface/CorInfoImpl.cs index b1e862ef85102d..ca41749d348bd0 100644 --- a/src/coreclr/tools/Common/JitInterface/CorInfoImpl.cs +++ b/src/coreclr/tools/Common/JitInterface/CorInfoImpl.cs @@ -4065,12 +4065,11 @@ private ref ArrayBuilder findRelocBlock(BlockType blockType, out int } // Translates relocation type constants used by JIT to RelocType enumeration - private static RelocType GetRelocType(CorInfoReloc reloc) + private RelocType GetRelocType(CorInfoReloc reloc) => reloc switch { - CorInfoReloc.DIR32 => RelocType.IMAGE_REL_BASED_HIGHLOW, - CorInfoReloc.DIR64 => RelocType.IMAGE_REL_BASED_DIR64, - CorInfoReloc.REL32 => RelocType.IMAGE_REL_BASED_REL32, + CorInfoReloc.DIRECT => PointerSize == 8 ? RelocType.IMAGE_REL_BASED_DIR64 : RelocType.IMAGE_REL_BASED_HIGHLOW, + CorInfoReloc.RELATIVE32 => RelocType.IMAGE_REL_BASED_REL32, CorInfoReloc.ARM64_BRANCH26 => RelocType.IMAGE_REL_BASED_ARM64_BRANCH26, CorInfoReloc.ARM64_PAGEBASE_REL21 => RelocType.IMAGE_REL_BASED_ARM64_PAGEBASE_REL21, CorInfoReloc.ARM64_PAGEOFFSET_12A => RelocType.IMAGE_REL_BASED_ARM64_PAGEOFFSET_12A, @@ -4160,7 +4159,7 @@ private CorInfoReloc getRelocTypeHint(void* target) switch (_compilation.TypeSystemContext.Target.Architecture) { case TargetArchitecture.X64: - return CorInfoReloc.REL32; + return CorInfoReloc.RELATIVE32; #if READYTORUN case TargetArchitecture.ARM: diff --git a/src/coreclr/tools/Common/JitInterface/CorInfoTypes.cs b/src/coreclr/tools/Common/JitInterface/CorInfoTypes.cs index 411bed582e8cd0..db2153d1b35d14 100644 --- a/src/coreclr/tools/Common/JitInterface/CorInfoTypes.cs +++ b/src/coreclr/tools/Common/JitInterface/CorInfoTypes.cs @@ -466,9 +466,8 @@ public enum CorInfoReloc NONE, // General relocation types - DIR32, // Direct/absolute 32 bit address - DIR64, // Direct/absolute 64 bit address - REL32, // 32-bit relative address from byte following reloc + DIRECT, // Direct/absolute pointer sized address + RELATIVE32, // 32-bit relative address from byte following reloc // Arm64 relocs ARM64_BRANCH26, // Arm64: B, BL diff --git a/src/coreclr/tools/superpmi/superpmi-shared/compileresult.cpp b/src/coreclr/tools/superpmi/superpmi-shared/compileresult.cpp index 0e77a45517416c..486721cc306964 100644 --- a/src/coreclr/tools/superpmi/superpmi-shared/compileresult.cpp +++ b/src/coreclr/tools/superpmi/superpmi-shared/compileresult.cpp @@ -682,9 +682,8 @@ const char* relocationTypeToString(CorInfoReloc fRelocType) { #define ADD_CASE(name) case CorInfoReloc::name: return #name ADD_CASE(NONE); - ADD_CASE(DIR32); - ADD_CASE(DIR64); - ADD_CASE(REL32); + ADD_CASE(DIRECT); + ADD_CASE(RELATIVE32); ADD_CASE(ARM64_BRANCH26); ADD_CASE(ARM64_PAGEBASE_REL21); ADD_CASE(ARM64_PAGEOFFSET_12A); @@ -780,7 +779,7 @@ void CompileResult::applyRelocs(RelocContext* rc, unsigned char* block1, ULONG b if ((targetArch == SPMI_TARGET_ARCHITECTURE_X86) || (targetArch == SPMI_TARGET_ARCHITECTURE_ARM)) { - if (relocType == CorInfoReloc::DIR32) + if (relocType == CorInfoReloc::DIRECT) { DWORDLONG fixupLocation = tmp.location; @@ -925,7 +924,7 @@ void CompileResult::applyRelocs(RelocContext* rc, unsigned char* block1, ULONG b if (IsSpmiTarget64Bit()) { - if (!wasRelocHandled && (relocType == CorInfoReloc::DIR64)) + if (!wasRelocHandled && (relocType == CorInfoReloc::DIRECT)) { DWORDLONG fixupLocation = tmp.location; @@ -952,7 +951,7 @@ void CompileResult::applyRelocs(RelocContext* rc, unsigned char* block1, ULONG b continue; // Now do all-platform relocations. - if ((relocType == CorInfoReloc::REL32) || (relocType == CorInfoReloc::AMD64_WIN_SECREL)) + if ((relocType == CorInfoReloc::RELATIVE32) || (relocType == CorInfoReloc::AMD64_WIN_SECREL)) { DWORDLONG fixupLocation = tmp.location; @@ -970,9 +969,9 @@ void CompileResult::applyRelocs(RelocContext* rc, unsigned char* block1, ULONG b { // For just AMD64: // The VM attempts to allocate the JIT code buffer near the CLR assemblies, so 32-bit - // offsets (and REL32 relocations) can be used in the code. If this doesn't work out, - // such that a REL32 relocation doesn't fit, the VM throws away the JIT result, disables - // using REL32 relocations, and restarts compilation. SuperPMI doesn't know where the + // offsets (and RELATIVE32 relocations) can be used in the code. If this doesn't work out, + // such that a RELATIVE32 relocation doesn't fit, the VM throws away the JIT result, disables + // using RELATIVE32 relocations, and restarts compilation. SuperPMI doesn't know where the // original compilation (during the collection) was allocated (though maybe we should // add that to the MC, not just the CompileResult), and we don't have any control over // where the JIT buffer is allocated. To handle this, if the getRelocTypeHint() was @@ -988,9 +987,9 @@ void CompileResult::applyRelocs(RelocContext* rc, unsigned char* block1, ULONG b if (index != -1) { CorInfoReloc retVal = (CorInfoReloc)rc->mc->GetRelocTypeHint->Get(key); - if (retVal == CorInfoReloc::REL32) + if (retVal == CorInfoReloc::RELATIVE32) { - LogDebug(" REL32 target used as argument to getRelocTypeHint: setting delta=%d (0x%X)", + LogDebug(" RELATIVE32 target used as argument to getRelocTypeHint: setting delta=%d (0x%X)", (int)key, (int)key); delta = (INT64)(int)key; deltaIsFinal = true; @@ -1002,7 +1001,7 @@ void CompileResult::applyRelocs(RelocContext* rc, unsigned char* block1, ULONG b if (!deltaIsFinal) { // Check if tmp.target is the result of a call to getHelperFtn(). If so, the VM would create a - // jump stub if the REL32 address doesn't fit. We don't want to fail with a REL32 overflow if + // jump stub if the RELATIVE32 address doesn't fit. We don't want to fail with a RELATIVE32 overflow if // the actual target address doesn't fit, so use the low-order 32 bits of the address. // We need to iterate the entire table since we don't know the helper function id. @@ -1013,7 +1012,7 @@ void CompileResult::applyRelocs(RelocContext* rc, unsigned char* block1, ULONG b Agnostic_GetHelperFtn value = rc->mc->GetHelperFtn->GetItem(idx); if (value.helperLookup.handle == tmp.target) { - LogDebug(" REL32 target is result of getHelperFtn(): setting delta=%d (0x%X)", + LogDebug(" RELATIVE32 target is result of getHelperFtn(): setting delta=%d (0x%X)", (int)tmp.target, (int)tmp.target); delta = (INT64)(int)tmp.target; deltaIsFinal = true; @@ -1026,7 +1025,7 @@ void CompileResult::applyRelocs(RelocContext* rc, unsigned char* block1, ULONG b if (!deltaIsFinal) { // Check if tmp.target is the result of a call to GetFunctionEntryPoint(). As for helper - // functions, above, the VM would create a jump stub if the REL32 address doesn't fit. + // functions, above, the VM would create a jump stub if the RELATIVE32 address doesn't fit. if (rc->mc->GetFunctionEntryPoint != nullptr) { @@ -1035,7 +1034,7 @@ void CompileResult::applyRelocs(RelocContext* rc, unsigned char* block1, ULONG b DLD value = rc->mc->GetFunctionEntryPoint->GetItem(idx); if (value.A == tmp.target) { - LogDebug(" REL32 target is result of getFunctionEntryPoint(): setting delta=%d (0x%X)", + LogDebug(" RELATIVE32 target is result of getFunctionEntryPoint(): setting delta=%d (0x%X)", (int)tmp.target, (int)tmp.target); delta = (INT64)(int)tmp.target; deltaIsFinal = true; @@ -1065,7 +1064,7 @@ void CompileResult::applyRelocs(RelocContext* rc, unsigned char* block1, ULONG b ro_section_fake_start = rc->originalHotCodeAddress + rc->hotCodeSize; delta = (INT64)(ro_section_fake_start + ro_section_offset - baseAddr); deltaIsFinal = true; - LogDebug(" REL32 hot code target is in RO data section: setting delta=%d (0x%X)", + LogDebug(" RELATIVE32 hot code target is in RO data section: setting delta=%d (0x%X)", delta, delta); } else if ((rc->originalColdCodeAddress <= (size_t)fixupLocation) && @@ -1075,7 +1074,7 @@ void CompileResult::applyRelocs(RelocContext* rc, unsigned char* block1, ULONG b ro_section_fake_start = rc->originalColdCodeAddress + rc->coldCodeSize; delta = (INT64)(ro_section_fake_start + ro_section_offset - baseAddr); deltaIsFinal = true; - LogDebug(" REL32 cold code target is in RO data section: setting delta=%d (0x%X)", + LogDebug(" RELATIVE32 cold code target is in RO data section: setting delta=%d (0x%X)", delta, delta); } } @@ -1089,7 +1088,7 @@ void CompileResult::applyRelocs(RelocContext* rc, unsigned char* block1, ULONG b target = (DWORDLONG)originalAddr + (DWORDLONG)blocksize1; INT64 newdelta = (INT64)(target - baseAddr); - LogDebug(" REL32 overflow. Mapping target to %016" PRIX64 ". Mapping delta: %016" PRIX64 " => %016" PRIX64, + LogDebug(" RELATIVE32 overflow. Mapping target to %016" PRIX64 ". Mapping delta: %016" PRIX64 " => %016" PRIX64, target, delta, newdelta); delta = newdelta; @@ -1106,7 +1105,7 @@ void CompileResult::applyRelocs(RelocContext* rc, unsigned char* block1, ULONG b { if (delta != (INT64)(int)delta) { - LogError("REL32 relocation overflows field! delta=0x%016" PRIX64, delta); + LogError("RELATIVE32 relocation overflows field! delta=0x%016" PRIX64, delta); } } diff --git a/src/coreclr/tools/superpmi/superpmi-shared/methodcontext.cpp b/src/coreclr/tools/superpmi/superpmi-shared/methodcontext.cpp index 04e088257e1848..9dbb8b8d6a40ff 100644 --- a/src/coreclr/tools/superpmi/superpmi-shared/methodcontext.cpp +++ b/src/coreclr/tools/superpmi/superpmi-shared/methodcontext.cpp @@ -6488,7 +6488,7 @@ CorInfoReloc MethodContext::repGetRelocTypeHint(void* target) CorInfoReloc retVal; if (index == -1) { - retVal = CorInfoReloc::REL32; + retVal = CorInfoReloc::RELATIVE32; } else { diff --git a/src/coreclr/vm/jitinterface.cpp b/src/coreclr/vm/jitinterface.cpp index 16a4ae5503d027..7469e8e8216ad2 100644 --- a/src/coreclr/vm/jitinterface.cpp +++ b/src/coreclr/vm/jitinterface.cpp @@ -11830,16 +11830,12 @@ void CEEJitInfo::recordRelocation(void * location, switch (fRelocType) { - case CorInfoReloc::DIR64: - *((UINT64 *) locationRW) = (UINT64)(uintptr_t)target; - break; - - case CorInfoReloc::DIR32: - *((UINT32 *) locationRW) = (UINT32)(uintptr_t)target; + case CorInfoReloc::DIRECT: + *(void**)locationRW = target; break; #ifdef TARGET_AMD64 - case CorInfoReloc::REL32: + case CorInfoReloc::RELATIVE32: { target = (BYTE *)target + addlDelta; @@ -11860,7 +11856,7 @@ void CEEJitInfo::recordRelocation(void * location, if (m_fAllowRel32) { // - // When m_fAllowRel32 == TRUE, the JIT will use REL32s for both data addresses and direct code targets. + // When m_fAllowRel32 == TRUE, the JIT will use RELATIVE32s for both data addresses and direct code targets. // Since we cannot tell what the relocation is for, we have to defensively retry. // m_fJumpStubOverflow = TRUE; @@ -11876,7 +11872,7 @@ void CEEJitInfo::recordRelocation(void * location, else { // - // When m_fAllowRel32 == FALSE, the JIT will use a REL32s for direct code targets only. + // When m_fAllowRel32 == FALSE, the JIT will use a RELATIVE32s for direct code targets only. // Use jump stub. // delta = rel32UsingJumpStub(fixupLocation, (PCODE)target, m_pMethodBeingCompiled, NULL, false /* throwOnOutOfMemoryWithinRange */); @@ -12095,7 +12091,7 @@ CorInfoReloc CEEJitInfo::getRelocTypeHint(void * target) if (m_fAllowRel32) { if (ExecutableAllocator::IsPreferredExecutableRange(target)) - return CorInfoReloc::REL32; + return CorInfoReloc::RELATIVE32; } #endif // TARGET_AMD64 From 32cfe4880b91537c36b4840d10ae4a1ad142f7a8 Mon Sep 17 00:00:00 2001 From: Jakob Botsch Nielsen Date: Mon, 24 Nov 2025 17:07:36 +0100 Subject: [PATCH 7/8] Remove RELOC_MOFFSET --- src/coreclr/jit/emitxarch.cpp | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/src/coreclr/jit/emitxarch.cpp b/src/coreclr/jit/emitxarch.cpp index f2afdc15d88049..b262a6872411ab 100644 --- a/src/coreclr/jit/emitxarch.cpp +++ b/src/coreclr/jit/emitxarch.cpp @@ -14251,11 +14251,9 @@ BYTE* emitter::emitOutputAlign(insGroup* ig, instrDesc* id, BYTE* dst) } #ifdef TARGET_64BIT -static constexpr CorInfoReloc RELOC_DISP32 = CorInfoReloc::RELATIVE32; -static constexpr CorInfoReloc RELOC_MOFFSET = CorInfoReloc::DIRECT; +static constexpr CorInfoReloc RELOC_DISP32 = CorInfoReloc::RELATIVE32; #else -static constexpr CorInfoReloc RELOC_DISP32 = CorInfoReloc::DIRECT; -static constexpr CorInfoReloc RELOC_MOFFSET = CorInfoReloc::DIRECT; +static constexpr CorInfoReloc RELOC_DISP32 = CorInfoReloc::DIRECT; #endif /***************************************************************************** @@ -14691,7 +14689,7 @@ BYTE* emitter::emitOutputAM(BYTE* dst, instrDesc* id, code_t code, CnsVal* addc) if (id->idIsDspReloc()) { - emitRecordRelocation((void*)(dst - TARGET_POINTER_SIZE), (void*)dsp, RELOC_MOFFSET); + emitRecordRelocation((void*)(dst - TARGET_POINTER_SIZE), (void*)dsp, CorInfoReloc::DIRECT); } #endif // TARGET_X86 @@ -16173,7 +16171,7 @@ BYTE* emitter::emitOutputCV(BYTE* dst, instrDesc* id, code_t code, CnsVal* addc) if (id->idIsDspReloc()) { - emitRecordRelocation((void*)(dst - TARGET_POINTER_SIZE), target, RELOC_MOFFSET); + emitRecordRelocation((void*)(dst - TARGET_POINTER_SIZE), target, CorInfoReloc::DIRECT); } #endif // TARGET_X86 @@ -17246,7 +17244,7 @@ BYTE* emitter::emitOutputRI(BYTE* dst, instrDesc* id) } else { - emitRecordRelocation((void*)(dst - (unsigned)EA_SIZE(size)), (void*)(size_t)val, RELOC_MOFFSET); + emitRecordRelocation((void*)(dst - (unsigned)EA_SIZE(size)), (void*)(size_t)val, CorInfoReloc::DIRECT); } } From 571e0ff2bc1eb3c9c30ffd3a9e072a00e737aba0 Mon Sep 17 00:00:00 2001 From: Jakob Botsch Nielsen Date: Mon, 24 Nov 2025 17:21:29 +0100 Subject: [PATCH 8/8] Fix another case of indentation --- src/coreclr/vm/jitinterface.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/coreclr/vm/jitinterface.cpp b/src/coreclr/vm/jitinterface.cpp index 7469e8e8216ad2..8b56532fca25a5 100644 --- a/src/coreclr/vm/jitinterface.cpp +++ b/src/coreclr/vm/jitinterface.cpp @@ -11810,11 +11810,11 @@ void CEEJitInfo::recordCallSite(uint32_t instrOffset, // A relocation is recorded if we are pre-jitting. // A jump thunk may be inserted if we are jitting -void CEEJitInfo::recordRelocation(void * location, - void * locationRW, - void * target, +void CEEJitInfo::recordRelocation(void * location, + void * locationRW, + void * target, CorInfoReloc fRelocType, - INT32 addlDelta) + INT32 addlDelta) { CONTRACTL { THROWS;