Skip to content

Commit c2181d6

Browse files
committed
Always record relocation
1 parent 50bdf31 commit c2181d6

File tree

7 files changed

+52
-62
lines changed

7 files changed

+52
-62
lines changed

src/coreclr/inc/utilcode.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3360,12 +3360,12 @@ void PutLoongArch64PC12(UINT32 * pCode, INT64 imm);
33603360
void PutLoongArch64JIR(UINT32 * pCode, INT64 imm);
33613361

33623362
//*****************************************************************************
3363-
// Extract the PC-Relative offset from auipc + I-type adder (addi/ld/jalr)
3363+
// Extract the PC-Relative offset from auipc + I-type adder (addi/load/jalr)
33643364
//*****************************************************************************
33653365
INT64 GetRiscV64AuipcItype(UINT32 * pCode);
33663366

33673367
//*****************************************************************************
3368-
// Deposit the PC-Relative offset into auipc + I-type adder (addi/ld/jalr)
3368+
// Deposit the PC-Relative offset into auipc + I-type adder (addi/load/jalr)
33693369
//*****************************************************************************
33703370
void PutRiscV64AuipcItype(UINT32 * pCode, INT64 offset);
33713371

src/coreclr/jit/codegenriscv64.cpp

Lines changed: 10 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -902,10 +902,6 @@ void CodeGen::instGen_Set_Reg_To_Imm(emitAttr size,
902902
assert(genIsValidIntReg(reg));
903903
if (EA_IS_RELOC(size))
904904
{
905-
if (!compiler->opts.compReloc)
906-
{
907-
size = EA_SIZE(size); // Strip any Reloc flags from size if we aren't doing relocs.
908-
}
909905
emit->emitIns_R_AI(INS_addi, size, reg, imm);
910906
}
911907
else
@@ -2426,6 +2422,11 @@ instruction CodeGen::genGetInsForOper(GenTree* treeNode)
24262422
break;
24272423

24282424
default:
2425+
2426+
char message[256];
2427+
_snprintf_s(message, ArrLen(message), _TRUNCATE, "Unhandled oper in genGetInsForOper() - float: %s",
2428+
GenTree::OpName(oper));
2429+
NYIRAW(message);
24292430
NO_WAY("Unhandled oper in genGetInsForOper() - float");
24302431
break;
24312432
}
@@ -2743,8 +2744,7 @@ void CodeGen::genCodeForReturnTrap(GenTreeOp* tree)
27432744
params.callType = EC_INDIR_R;
27442745
params.ireg = REG_DEFAULT_HELPER_CALL_TARGET;
27452746

2746-
emitAttr attr = compiler->opts.compReloc ? EA_PTR_DSP_RELOC : EA_PTRSIZE;
2747-
GetEmitter()->emitIns_R_AI(INS_ld, attr, params.ireg, (ssize_t)helperFunction.addr);
2747+
GetEmitter()->emitIns_R_AI(INS_ld, EA_PTR_DSP_RELOC, params.ireg, (ssize_t)helperFunction.addr);
27482748
regSet.verifyRegUsed(params.ireg);
27492749
}
27502750

@@ -3615,8 +3615,7 @@ void CodeGen::genEmitHelperCall(unsigned helper, int argSize, emitAttr retSize,
36153615
// assert that all registers in callTargetMask are in the callKillSet
36163616
noway_assert((callTargetMask & killSet) == callTargetMask);
36173617

3618-
emitAttr attr = compiler->opts.compReloc ? EA_PTR_DSP_RELOC : EA_PTRSIZE;
3619-
GetEmitter()->emitIns_R_AI(INS_ld, attr, callTargetReg, (ssize_t)pAddr);
3618+
GetEmitter()->emitIns_R_AI(INS_ld, EA_PTR_DSP_RELOC, callTargetReg, (ssize_t)pAddr);
36203619
regSet.verifyRegUsed(callTargetReg);
36213620

36223621
params.callType = EC_INDIR_R;
@@ -4420,8 +4419,7 @@ void CodeGen::genSetGSSecurityCookie(regNumber initReg, bool* pInitRegZeroed)
44204419
}
44214420
else
44224421
{
4423-
emitAttr attr = compiler->opts.compReloc ? EA_PTR_DSP_RELOC : EA_PTRSIZE;
4424-
emit->emitIns_R_AI(INS_ld, attr, initReg, (ssize_t)compiler->gsGlobalSecurityCookieAddr);
4422+
emit->emitIns_R_AI(INS_ld, EA_PTR_DSP_RELOC, initReg, (ssize_t)compiler->gsGlobalSecurityCookieAddr);
44254423

44264424
regSet.verifyRegUsed(initReg);
44274425
emit->emitIns_S_R(INS_sd, EA_PTRSIZE, initReg, compiler->lvaGSSecurityCookie, 0);
@@ -4456,8 +4454,7 @@ void CodeGen::genEmitGSCookieCheck(bool pushReg)
44564454
else
44574455
{
44584456
// AOT case - GS cookie constant needs to be accessed through an indirection.
4459-
emitAttr attr = compiler->opts.compReloc ? EA_PTR_DSP_RELOC : EA_PTRSIZE;
4460-
GetEmitter()->emitIns_R_AI(INS_ld, attr, regGSConst, (ssize_t)compiler->gsGlobalSecurityCookieAddr);
4457+
GetEmitter()->emitIns_R_AI(INS_ld, EA_PTR_DSP_RELOC, regGSConst, (ssize_t)compiler->gsGlobalSecurityCookieAddr);
44614458
regSet.verifyRegUsed(regGSConst);
44624459
}
44634460
// Load this method's GS value from the stack frame
@@ -6481,8 +6478,7 @@ void CodeGen::genJumpToThrowHlpBlk_la(
64816478
// TODO-RISCV64-RVC: Remove hardcoded branch offset here
64826479
ssize_t imm = (3 + 1) << 2;
64836480
emit->emitIns_R_R_I(ins, EA_PTRSIZE, reg1, reg2, imm);
6484-
emitAttr attr = compiler->opts.compReloc ? EA_PTR_DSP_RELOC : EA_PTRSIZE;
6485-
emit->emitIns_R_AI(INS_ld, attr, params.ireg, (ssize_t)pAddr);
6481+
emit->emitIns_R_AI(INS_ld, EA_PTR_DSP_RELOC, params.ireg, (ssize_t)pAddr);
64866482
regSet.verifyRegUsed(params.ireg);
64876483
}
64886484

src/coreclr/jit/emitriscv64.cpp

Lines changed: 12 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ size_t emitter::emitSizeOfInsDsc(instrDesc* id) const
9494

9595
case INS_OPTS_RC:
9696
case INS_OPTS_RL:
97-
case INS_OPTS_PCREL:
97+
case INS_OPTS_RELOC:
9898
case INS_OPTS_NONE:
9999
return sizeof(instrDesc);
100100
case INS_OPTS_I:
@@ -1242,12 +1242,14 @@ void emitter::emitIns_R_AR(instruction ins, emitAttr attr, regNumber ireg, regNu
12421242
NYI_RISCV64("emitIns_R_AR-----unimplemented/unused on RISCV64 yet----");
12431243
}
12441244

1245-
// This computes address from the immediate which is PC-relative.
1245+
// This computes address from the immediate which is relocatable.
12461246
void emitter::emitIns_R_AI(instruction ins,
12471247
emitAttr attr,
12481248
regNumber reg,
12491249
ssize_t addr DEBUGARG(size_t targetHandle) DEBUGARG(GenTreeFlags gtFlags))
12501250
{
1251+
assert(EA_IS_RELOC(attr));
1252+
assert(ins == INS_addi || emitInsIsLoad(ins));
12511253
assert(isGeneralRegister(reg));
12521254
// 2-ins:
12531255
// auipc reg, off-hi-20bits
@@ -1259,7 +1261,7 @@ void emitter::emitIns_R_AI(instruction ins,
12591261
assert(reg != REG_R0); // for special. reg Must not be R0.
12601262
id->idReg1(reg); // destination register that will get the constant value.
12611263

1262-
id->idInsOpt(INS_OPTS_PCREL);
1264+
id->idInsOpt(INS_OPTS_RELOC);
12631265

12641266
id->idOpSize(EA_SIZE(attr));
12651267
if (EA_IS_GCREF(attr))
@@ -3198,32 +3200,18 @@ static ssize_t UpperWordOfDoubleWordDoubleSignExtend(ssize_t doubleWord)
31983200
return static_cast<unsigned>(LowerNBitsOfWord<21>(imm21));
31993201
}
32003202

3201-
BYTE* emitter::emitOutputInstr_OptsPcRel(BYTE* dst, const instrDesc* id, instruction* ins)
3203+
BYTE* emitter::emitOutputInstr_OptsReloc(BYTE* dst, const instrDesc* id, instruction* ins)
32023204
{
32033205
BYTE* const dstBase = dst;
32043206
const regNumber reg1 = id->idReg1();
32053207
assert(isGeneralRegister(reg1));
32063208

3207-
unsigned hi20 = 0;
3208-
unsigned lo12 = 0;
3209-
if (!id->idIsReloc())
3210-
{
3211-
UNATIVE_OFFSET srcOffs = emitCurCodeOffs(dst);
3212-
const BYTE* srcAddr = emitOffsetToPtr(srcOffs);
3213-
ssize_t distance = (ssize_t)(id->idAddr()->iiaAddr - srcAddr);
3214-
assert(isValidSimm32(distance));
3215-
hi20 = UpperNBitsOfWordSignExtend<20>(distance);
3216-
lo12 = LowerNBitsOfWord<12>(distance);
3217-
}
3218-
32193209
*ins = id->idIns();
32203210
assert(*ins == INS_addi || emitInsIsLoad(*ins));
3221-
dst += emitOutput_UTypeInstr(dst, INS_auipc, reg1, hi20);
3222-
dst += emitOutput_ITypeInstr(dst, *ins, reg1, reg1, lo12);
3223-
3224-
if (id->idIsReloc())
3225-
emitRecordRelocation(dstBase, id->idAddr()->iiaAddr, IMAGE_REL_RISCV64_PC);
3211+
dst += emitOutput_UTypeInstr(dst, INS_auipc, reg1, 0);
3212+
dst += emitOutput_ITypeInstr(dst, *ins, reg1, reg1, 0);
32263213

3214+
emitRecordRelocation(dstBase, id->idAddr()->iiaAddr, IMAGE_REL_RISCV64_PC);
32273215
return dst;
32283216
}
32293217

@@ -3431,8 +3419,8 @@ size_t emitter::emitOutputInstr(insGroup* ig, instrDesc* id, BYTE** dp)
34313419

34323420
switch (insOp)
34333421
{
3434-
case INS_OPTS_PCREL:
3435-
dst = emitOutputInstr_OptsPcRel(dst, id, &ins);
3422+
case INS_OPTS_RELOC:
3423+
dst = emitOutputInstr_OptsReloc(dst, id, &ins);
34363424
sz = sizeof(instrDesc);
34373425
break;
34383426
case INS_OPTS_RC:
@@ -5153,7 +5141,7 @@ void emitter::emitInsLoadStoreOp(instruction ins, emitAttr attr, regNumber dataR
51535141

51545142
if (addr->IsIconHandle(GTF_ICON_FTN_ADDR))
51555143
{
5156-
emitIns_R_AI(ins, attr, dataReg, (size_t)cns, cns, addr->GetIconHandleFlag());
5144+
emitIns_R_AI(ins, EA_PTR_DSP_RELOC, dataReg, (size_t)cns, cns, addr->GetIconHandleFlag());
51575145
}
51585146
else
51595147
{

src/coreclr/jit/emitriscv64.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,7 @@ unsigned emitOutput_BTypeInstr_InvertComparation(
135135
BYTE* dst, instruction ins, regNumber rs1, regNumber rs2, unsigned imm13) const;
136136
unsigned emitOutput_JTypeInstr(BYTE* dst, instruction ins, regNumber rd, unsigned imm21) const;
137137

138-
BYTE* emitOutputInstr_OptsPcRel(BYTE* dst, const instrDesc* id, instruction* ins);
138+
BYTE* emitOutputInstr_OptsReloc(BYTE* dst, const instrDesc* id, instruction* ins);
139139
BYTE* emitOutputInstr_OptsRc(BYTE* dst, const instrDesc* id, instruction* ins);
140140
BYTE* emitOutputInstr_OptsRl(BYTE* dst, instrDesc* id, instruction* ins);
141141
BYTE* emitOutputInstr_OptsJalr(BYTE* dst, instrDescJmp* jmp, const insGroup* ig, instruction* ins);

src/coreclr/jit/instr.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -558,7 +558,7 @@ enum insOpts : unsigned
558558
INS_OPTS_J_cond, // see ::emitIns_J_cond_la().
559559
INS_OPTS_I, // see ::emitLoadImmediate().
560560
INS_OPTS_C, // see ::emitIns_Call().
561-
INS_OPTS_PCREL, // see ::emitIns_R_AI().
561+
INS_OPTS_RELOC, // see ::emitIns_R_AI().
562562
};
563563

564564
enum insBarrier : unsigned

src/coreclr/tools/superpmi/superpmi-shared/spmiutil.cpp

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -478,30 +478,33 @@ void PutArm32MovtConstant(UINT32* p, unsigned con)
478478
}
479479

480480
//*****************************************************************************
481-
// Extract the PC-Relative offset from auipc + I-type adder (addi/ld/jalr)
481+
// Extract the PC-Relative offset from auipc + I-type adder (addi/load/jalr)
482482
//*****************************************************************************
483483
INT64 GetRiscV64AuipcItype(UINT32 * pCode)
484484
{
485485
enum
486486
{
487-
OpcodeAuipc = 0x00000017,
488-
OpcodeAddi = 0x00000013,
489-
OpcodeLd = 0x00003003,
490-
OpcodeJalr = 0x00000067,
491-
OpcodeUTypeMask = 0x0000007F,
492-
OpcodeITypeMask = 0x0000307F,
487+
OpcodeAuipc = 0x17,
488+
OpcodeAddi = 0x13,
489+
OpcodeLoad = 0x03,
490+
OpcodeJalr = 0x67,
491+
OpcodeMask = 0x7F,
492+
493+
Funct3AddiJalr = 0x0000,
494+
Funct3Mask = 0x7000,
493495
};
494496

495497
UINT32 auipc = pCode[0];
496-
_ASSERTE((auipc & OpcodeUTypeMask) == OpcodeAuipc);
498+
_ASSERTE((auipc & OpcodeMask) == OpcodeAuipc);
497499
int auipcRegDest = (auipc >> 7) & 0x1F;
498500
_ASSERTE(auipcRegDest != 0);
499501

500502
INT64 hi20 = (INT32(auipc) >> 12) << 12;
501503

502504
UINT32 iType = pCode[1];
503-
UINT32 opcode = iType & OpcodeITypeMask;
504-
_ASSERTE(opcode == OpcodeAddi || opcode == OpcodeLd || opcode == OpcodeJalr);
505+
UINT32 opcode = iType & OpcodeMask;
506+
UINT32 funct3 = iType & Funct3Mask;
507+
_ASSERTE(opcode == OpcodeLoad || ((opcode == OpcodeAddi || opcode == OpcodeJalr) && funct3 == Funct3AddiJalr));
505508
int iTypeRegSrc = (iType >> 15) & 0x1F;
506509
_ASSERTE(auipcRegDest == iTypeRegSrc);
507510

src/coreclr/utilcode/util.cpp

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2334,30 +2334,33 @@ void PutLoongArch64JIR(UINT32 * pCode, INT64 imm38)
23342334

23352335

23362336
//*****************************************************************************
2337-
// Extract the PC-Relative offset from auipc + I-type adder (addi/ld/jalr)
2337+
// Extract the PC-Relative offset from auipc + I-type adder (addi/load/jalr)
23382338
//*****************************************************************************
23392339
INT64 GetRiscV64AuipcItype(UINT32 * pCode)
23402340
{
23412341
enum
23422342
{
2343-
OpcodeAuipc = 0x00000017,
2344-
OpcodeAddi = 0x00000013,
2345-
OpcodeLd = 0x00003003,
2346-
OpcodeJalr = 0x00000067,
2347-
OpcodeUTypeMask = 0x0000007F,
2348-
OpcodeITypeMask = 0x0000307F,
2343+
OpcodeAuipc = 0x17,
2344+
OpcodeAddi = 0x13,
2345+
OpcodeLoad = 0x03,
2346+
OpcodeJalr = 0x67,
2347+
OpcodeMask = 0x7F,
2348+
2349+
Funct3AddiJalr = 0x0000,
2350+
Funct3Mask = 0x7000,
23492351
};
23502352

23512353
UINT32 auipc = pCode[0];
2352-
_ASSERTE((auipc & OpcodeUTypeMask) == OpcodeAuipc);
2354+
_ASSERTE((auipc & OpcodeMask) == OpcodeAuipc);
23532355
int auipcRegDest = (auipc >> 7) & 0x1F;
23542356
_ASSERTE(auipcRegDest != 0);
23552357

23562358
INT64 hi20 = (INT32(auipc) >> 12) << 12;
23572359

23582360
UINT32 iType = pCode[1];
2359-
UINT32 opcode = iType & OpcodeITypeMask;
2360-
_ASSERTE(opcode == OpcodeAddi || opcode == OpcodeLd || opcode == OpcodeJalr);
2361+
UINT32 opcode = iType & OpcodeMask;
2362+
UINT32 funct3 = iType & Funct3Mask;
2363+
_ASSERTE(opcode == OpcodeLoad || ((opcode == OpcodeAddi || opcode == OpcodeJalr) && funct3 == Funct3AddiJalr));
23612364
int iTypeRegSrc = (iType >> 15) & 0x1F;
23622365
_ASSERTE(auipcRegDest == iTypeRegSrc);
23632366

0 commit comments

Comments
 (0)