Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
97 changes: 53 additions & 44 deletions src/coreclr/inc/corinfo.h
Original file line number Diff line number Diff line change
Expand Up @@ -852,6 +852,59 @@ enum InfoAccessType
IAT_RELPVALUE // The value needs to be accessed via a relative indirection
};

enum class CorInfoReloc
{
NONE,

// General relocation types
DIRECT, // Direct/absolute pointer sized address
RELATIVE32, // 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
// 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
LOONGARCH64_PC, // LoongArch64: pcalau12i+imm12
LOONGARCH64_JIR, // LoongArch64: pcaddu18i+jirl

// RISCV64 relocs
RISCV64_PC, // RiscV64: auipc
};

enum CorInfoGCType
{
TYPE_GC_NONE, // no embedded objectrefs
Expand Down Expand Up @@ -3399,50 +3452,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
Expand Down
4 changes: 2 additions & 2 deletions src/coreclr/inc/corjit.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions src/coreclr/inc/icorjitinfoimpl_generated.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
10 changes: 5 additions & 5 deletions src/coreclr/inc/jiteeversionguid.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,11 @@

#include <minipal/guid.h>

constexpr GUID JITEEVersionIdentifier = { /* c3e8a087-931a-4aa4-a311-13e6736e509a */
0xc3e8a087,
0x931a,
0x4aa4,
{0xa3, 0x11, 0x13, 0xe6, 0x73, 0x6e, 0x50, 0x9a}
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
6 changes: 3 additions & 3 deletions src/coreclr/jit/ICorJitInfo_wrapper_generated.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -1723,19 +1723,19 @@ void WrapICorJitInfo::recordRelocation(
void* location,
void* locationRW,
void* target,
uint16_t fRelocType,
CorInfoReloc fRelocType,
int32_t addlDelta)
{
API_ENTER(recordRelocation);
wrapHnd->recordRelocation(location, locationRW, target, fRelocType, addlDelta);
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;
}
Expand Down
2 changes: 1 addition & 1 deletion src/coreclr/jit/codegeninterface.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
6 changes: 3 additions & 3 deletions src/coreclr/jit/codegenxarch.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand All @@ -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::RELATIVE32;
#else
// x86: PC-relative addressing is available only for control flow instructions (jmp and call)
return false;
Expand All @@ -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::RELATIVE32;
#else
// x86: PC-relative addressing is available only for control flow instructions (jmp and call)
return true;
Expand Down
2 changes: 1 addition & 1 deletion src/coreclr/jit/compiler.h
Original file line number Diff line number Diff line change
Expand Up @@ -8575,7 +8575,7 @@ class Compiler

void eeSetEHinfo(unsigned EHnumber, const CORINFO_EH_CLAUSE* clause);

WORD eeGetRelocTypeHint(void* target);
CorInfoReloc eeGetRelocTypeHint(void* target);

// ICorStaticInfo wrapper functions

Expand Down
4 changes: 2 additions & 2 deletions src/coreclr/jit/ee_il_dll.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand All @@ -1285,7 +1285,7 @@ WORD Compiler::eeGetRelocTypeHint(void* target)
else
{
// No hints
return (WORD)-1;
return CorInfoReloc::NONE;
}
}

Expand Down
32 changes: 15 additions & 17 deletions src/coreclr/jit/emit.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8521,8 +8521,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;
emitRecordRelocation(&(bDstRW[i]), target, relocType);
emitRecordRelocation(&(bDstRW[i]), target, CorInfoReloc::DIRECT);
}

JITDUMP(" " FMT_BB ": 0x%p\n", block->bbNum, bDstRW[i]);
Expand Down Expand Up @@ -8568,11 +8567,10 @@ 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;
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);
}
}

Expand Down Expand Up @@ -10514,25 +10512,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?
Expand All @@ -10559,11 +10557,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
Expand Down
26 changes: 13 additions & 13 deletions src/coreclr/jit/emit.h
Original file line number Diff line number Diff line change
Expand Up @@ -3586,26 +3586,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

Expand Down
4 changes: 2 additions & 2 deletions src/coreclr/jit/emitarm.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
}
Expand Down Expand Up @@ -6476,7 +6476,7 @@ size_t emitter::emitOutputInstr(insGroup* ig, instrDesc* id, BYTE** dp)
callInstrSize = SafeCvtAssert<unsigned char>(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
{
Expand Down
Loading
Loading