diff --git a/src/coreclr/jit/emitarm64.cpp b/src/coreclr/jit/emitarm64.cpp index 2a5c947de175c5..624a737234fcbb 100644 --- a/src/coreclr/jit/emitarm64.cpp +++ b/src/coreclr/jit/emitarm64.cpp @@ -217,7 +217,6 @@ void emitter::emitInsSanityCheck(instrDesc* id) case IF_BR_1B: // BR_1B ................ ......nnnnn..... Rn if (emitComp->IsTargetAbi(CORINFO_NATIVEAOT_ABI) && id->idIsTlsGD()) { - assert(isGeneralRegister(id->idReg1())); assert(id->idAddr()->iiaAddr != nullptr); } else @@ -9184,11 +9183,14 @@ void emitter::emitIns_Call(EmitCallType callType, if (emitComp->IsTargetAbi(CORINFO_NATIVEAOT_ABI) && EA_IS_CNS_TLSGD_RELOC(retSize)) { // For NativeAOT linux/arm64, we need to also record the relocation of methHnd. - // Since we do not have space to embed it in instrDesc, we store the register in - // reg1 and instead use the `iiaAdd` to store the method handle. Likewise, during - // emitOutputInstr, we retrieve the register from reg1 for this specific case. + // Since we do not have space to embed it in instrDesc, we use the `iiaAddr` to + // store the method handle. + // The target handle need to be always in R2 and hence the assert check. + // We cannot use reg1 and reg2 fields of instrDesc because they contain the gc + // registers (emitEncodeCallGCregs()) that are live across the call. + + assert(ireg == REG_R2); id->idSetTlsGD(); - id->idReg1(ireg); id->idAddr()->iiaAddr = (BYTE*)methHnd; } else @@ -10990,12 +10992,13 @@ size_t emitter::emitOutputInstr(insGroup* ig, instrDesc* id, BYTE** dp) { emitRecordRelocation(odst, (CORINFO_METHOD_HANDLE)id->idAddr()->iiaAddr, IMAGE_REL_AARCH64_TLSDESC_CALL); - code |= insEncodeReg_Rn(id->idReg1()); // nnnnn + code |= insEncodeReg_Rn(REG_R2); // nnnnn } else { code |= insEncodeReg_Rn(id->idReg3()); // nnnnn } + dst += emitOutputCall(ig, dst, id, code); sz = id->idIsLargeCall() ? sizeof(instrDescCGCA) : sizeof(instrDesc); break; @@ -13315,7 +13318,15 @@ void emitter::emitDispInsHelp( case IF_BR_1B: // BR_1B ................ ......nnnnn..... Rn // The size of a branch target is always EA_PTRSIZE assert(insOptsNone(id->idInsOpt())); - emitDispReg(id->idReg3(), EA_PTRSIZE, false); + + if (emitComp->IsTargetAbi(CORINFO_NATIVEAOT_ABI) && id->idIsTlsGD()) + { + emitDispReg(REG_R2, EA_PTRSIZE, false); + } + else + { + emitDispReg(id->idReg3(), EA_PTRSIZE, false); + } break; case IF_LS_1A: // LS_1A XX...V..iiiiiiii iiiiiiiiiiittttt Rt PC imm(1MB)