From 13cfb9d902564ec3ed85c2feb320bbe14ebd2d70 Mon Sep 17 00:00:00 2001 From: Filip Navara Date: Mon, 10 Feb 2025 04:43:00 +0200 Subject: [PATCH] Fix relocs for linux-riscv64 AOT --- src/coreclr/jit/codegenriscv64.cpp | 19 ++++++++++++++++++- .../Target_RiscV64/RiscV64Emitter.cs | 2 +- 2 files changed, 19 insertions(+), 2 deletions(-) diff --git a/src/coreclr/jit/codegenriscv64.cpp b/src/coreclr/jit/codegenriscv64.cpp index 8efe6e0827125c..4cec710abe0325 100644 --- a/src/coreclr/jit/codegenriscv64.cpp +++ b/src/coreclr/jit/codegenriscv64.cpp @@ -3581,7 +3581,24 @@ void CodeGen::genCodeForJumpCompare(GenTreeOpCC* tree) unreached(); } - emit->emitLoadImmediate(EA_PTRSIZE, REG_RA, imm); + GenTreeIntCon* con = op2->AsIntCon(); + + emitAttr attr = emitActualTypeSize(op2Type); + // TODO-CQ: Currently we cannot do this for all handles because of + // https://github.com/dotnet/runtime/issues/60712 + if (con->ImmedValNeedsReloc(compiler)) + { + attr = EA_SET_FLG(attr, EA_CNS_RELOC_FLG); + } + + if (op2Type == TYP_BYREF) + { + attr = EA_SET_FLG(attr, EA_BYREF_FLG); + } + + instGen_Set_Reg_To_Imm(attr, REG_RA, imm, + INS_FLAGS_DONT_CARE DEBUGARG(con->gtTargetHandle) DEBUGARG(con->gtFlags)); + regSet.verifyRegUsed(REG_RA); regs = (int)REG_RA << 5; } else diff --git a/src/coreclr/tools/Common/Compiler/DependencyAnalysis/Target_RiscV64/RiscV64Emitter.cs b/src/coreclr/tools/Common/Compiler/DependencyAnalysis/Target_RiscV64/RiscV64Emitter.cs index aed078619dfd13..caf1dad16a1af5 100644 --- a/src/coreclr/tools/Common/Compiler/DependencyAnalysis/Target_RiscV64/RiscV64Emitter.cs +++ b/src/coreclr/tools/Common/Compiler/DependencyAnalysis/Target_RiscV64/RiscV64Emitter.cs @@ -126,7 +126,7 @@ public void EmitRETIfZero(Register regSrc) public void EmitJMPIfZero(Register regSrc, ISymbolNode symbol) { - uint offset = symbol.RepresentsIndirectionCell ? 28u : 8u; + uint offset = symbol.RepresentsIndirectionCell ? 28u : 12u; uint encodedOffset = ((offset & 0x1e) << 7) | ((offset & 0x7e0) << 20) | ((offset & 0x800) >> 4) | ((offset & 0x1000) << 19); // bne regSrc, x0, offset Builder.EmitUInt((uint)(0x00001063 | ((uint)regSrc << 15) | encodedOffset));