From 4913f41a0974056dbd36b0644db8890883a9f0e7 Mon Sep 17 00:00:00 2001 From: Qiao Pengcheng Date: Tue, 10 Feb 2026 19:20:50 +0800 Subject: [PATCH] [LoongArch64] Place async resumption info in read-write section which reference dotnet#123433. --- src/coreclr/jit/codegenloongarch64.cpp | 10 ++++++++-- src/coreclr/jit/emitloongarch64.cpp | 9 +++++---- 2 files changed, 13 insertions(+), 6 deletions(-) diff --git a/src/coreclr/jit/codegenloongarch64.cpp b/src/coreclr/jit/codegenloongarch64.cpp index 02c2812cf1c490..8fe9f426b8773c 100644 --- a/src/coreclr/jit/codegenloongarch64.cpp +++ b/src/coreclr/jit/codegenloongarch64.cpp @@ -2279,7 +2279,7 @@ void CodeGen::genJumpTable(GenTree* treeNode) // Access to inline data is 'abstracted' by a special type of static member // (produced by eeFindJitDataOffs) which the emitter recognizes as being a reference // to constant data, not a real static field. - GetEmitter()->emitIns_R_C(INS_bl, emitActualTypeSize(TYP_I_IMPL), treeNode->GetRegNum(), REG_NA, + GetEmitter()->emitIns_R_C(INS_bl, EA_PTRSIZE, treeNode->GetRegNum(), REG_NA, m_compiler->eeFindJitDataOffs(jmpTabBase), 0); genProduceReg(treeNode); } @@ -2292,7 +2292,13 @@ void CodeGen::genJumpTable(GenTree* treeNode) // void CodeGen::genAsyncResumeInfo(GenTreeVal* treeNode) { - GetEmitter()->emitIns_R_C(INS_bl, emitActualTypeSize(TYP_I_IMPL), treeNode->GetRegNum(), REG_NA, + emitAttr attr = EA_PTRSIZE; + if (m_compiler->eeDataWithCodePointersNeedsRelocs()) + { + attr = EA_SET_FLG(EA_PTRSIZE, EA_CNS_RELOC_FLG); + } + + GetEmitter()->emitIns_R_C(INS_bl, attr, treeNode->GetRegNum(), REG_NA, genEmitAsyncResumeInfo((unsigned)treeNode->gtVal1), 0); genProduceReg(treeNode); } diff --git a/src/coreclr/jit/emitloongarch64.cpp b/src/coreclr/jit/emitloongarch64.cpp index 83d6425480678e..19705723859fd4 100644 --- a/src/coreclr/jit/emitloongarch64.cpp +++ b/src/coreclr/jit/emitloongarch64.cpp @@ -1972,8 +1972,8 @@ void emitter::emitIns_R_R_R_R( /***************************************************************************** * * Add an instruction with a register + static member operands. - * Constant is stored into JIT data which is adjacent to code. - * For LOONGARCH64, maybe not the best, here just supports the func-interface. + * Usually constants are stored into JIT data adjacent to code, in which case no + * relocation is needed. PC-relative offset will be encoded directly into instruction. * */ void emitter::emitIns_R_C( @@ -2000,6 +2000,7 @@ void emitter::emitIns_R_C( // load reg, r21 + addr_bits[11:0] instrDesc* id = emitNewInstr(attr); + id->idSetRelocFlags(attr); id->idIns(ins); assert(reg != REG_R0); // for special. reg Must not be R0. @@ -2007,7 +2008,8 @@ void emitter::emitIns_R_C( id->idSmallCns(offs); // usually is 0. id->idInsOpt(INS_OPTS_RC); - if (m_compiler->opts.compReloc) + + if (m_compiler->opts.compReloc || id->idIsReloc()) { id->idSetIsDspReloc(); id->idCodeSize(8); @@ -2030,7 +2032,6 @@ void emitter::emitIns_R_C( id->idOpSize(EA_PTRSIZE); } - // TODO-LoongArch64: this maybe deleted. id->idSetIsBound(); // We won't patch address since we will know the exact distance // once JIT code and data are allocated together.