Skip to content

Commit 2240175

Browse files
am11filipnavara
andauthored
Fix relocs for linux-riscv64 AOT (#112331)
Co-authored-by: Filip Navara <[email protected]>
1 parent 02f99e5 commit 2240175

File tree

2 files changed

+19
-2
lines changed

2 files changed

+19
-2
lines changed

src/coreclr/jit/codegenriscv64.cpp

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3581,7 +3581,24 @@ void CodeGen::genCodeForJumpCompare(GenTreeOpCC* tree)
35813581
unreached();
35823582
}
35833583

3584-
emit->emitLoadImmediate(EA_PTRSIZE, REG_RA, imm);
3584+
GenTreeIntCon* con = op2->AsIntCon();
3585+
3586+
emitAttr attr = emitActualTypeSize(op2Type);
3587+
// TODO-CQ: Currently we cannot do this for all handles because of
3588+
// https://github.com/dotnet/runtime/issues/60712
3589+
if (con->ImmedValNeedsReloc(compiler))
3590+
{
3591+
attr = EA_SET_FLG(attr, EA_CNS_RELOC_FLG);
3592+
}
3593+
3594+
if (op2Type == TYP_BYREF)
3595+
{
3596+
attr = EA_SET_FLG(attr, EA_BYREF_FLG);
3597+
}
3598+
3599+
instGen_Set_Reg_To_Imm(attr, REG_RA, imm,
3600+
INS_FLAGS_DONT_CARE DEBUGARG(con->gtTargetHandle) DEBUGARG(con->gtFlags));
3601+
regSet.verifyRegUsed(REG_RA);
35853602
regs = (int)REG_RA << 5;
35863603
}
35873604
else

src/coreclr/tools/Common/Compiler/DependencyAnalysis/Target_RiscV64/RiscV64Emitter.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ public void EmitRETIfZero(Register regSrc)
126126

127127
public void EmitJMPIfZero(Register regSrc, ISymbolNode symbol)
128128
{
129-
uint offset = symbol.RepresentsIndirectionCell ? 28u : 8u;
129+
uint offset = symbol.RepresentsIndirectionCell ? 28u : 12u;
130130
uint encodedOffset = ((offset & 0x1e) << 7) | ((offset & 0x7e0) << 20) | ((offset & 0x800) >> 4) | ((offset & 0x1000) << 19);
131131
// bne regSrc, x0, offset
132132
Builder.EmitUInt((uint)(0x00001063 | ((uint)regSrc << 15) | encodedOffset));

0 commit comments

Comments
 (0)