Skip to content

Commit 6fe852a

Browse files
authored
Do not overwrite gcrefs masks present in reg1/reg2 fields (#112469)
1 parent 7b5f7f0 commit 6fe852a

File tree

1 file changed

+18
-7
lines changed

1 file changed

+18
-7
lines changed

src/coreclr/jit/emitarm64.cpp

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -217,7 +217,6 @@ void emitter::emitInsSanityCheck(instrDesc* id)
217217
case IF_BR_1B: // BR_1B ................ ......nnnnn..... Rn
218218
if (emitComp->IsTargetAbi(CORINFO_NATIVEAOT_ABI) && id->idIsTlsGD())
219219
{
220-
assert(isGeneralRegister(id->idReg1()));
221220
assert(id->idAddr()->iiaAddr != nullptr);
222221
}
223222
else
@@ -9239,11 +9238,14 @@ void emitter::emitIns_Call(EmitCallType callType,
92399238
if (emitComp->IsTargetAbi(CORINFO_NATIVEAOT_ABI) && EA_IS_CNS_TLSGD_RELOC(retSize))
92409239
{
92419240
// For NativeAOT linux/arm64, we need to also record the relocation of methHnd.
9242-
// Since we do not have space to embed it in instrDesc, we store the register in
9243-
// reg1 and instead use the `iiaAdd` to store the method handle. Likewise, during
9244-
// emitOutputInstr, we retrieve the register from reg1 for this specific case.
9241+
// Since we do not have space to embed it in instrDesc, we use the `iiaAddr` to
9242+
// store the method handle.
9243+
// The target handle need to be always in R2 and hence the assert check.
9244+
// We cannot use reg1 and reg2 fields of instrDesc because they contain the gc
9245+
// registers (emitEncodeCallGCregs()) that are live across the call.
9246+
9247+
assert(ireg == REG_R2);
92459248
id->idSetTlsGD();
9246-
id->idReg1(ireg);
92479249
id->idAddr()->iiaAddr = (BYTE*)methHnd;
92489250
}
92499251
else
@@ -11045,12 +11047,13 @@ size_t emitter::emitOutputInstr(insGroup* ig, instrDesc* id, BYTE** dp)
1104511047
{
1104611048
emitRecordRelocation(odst, (CORINFO_METHOD_HANDLE)id->idAddr()->iiaAddr,
1104711049
IMAGE_REL_AARCH64_TLSDESC_CALL);
11048-
code |= insEncodeReg_Rn(id->idReg1()); // nnnnn
11050+
code |= insEncodeReg_Rn(REG_R2); // nnnnn
1104911051
}
1105011052
else
1105111053
{
1105211054
code |= insEncodeReg_Rn(id->idReg3()); // nnnnn
1105311055
}
11056+
1105411057
dst += emitOutputCall(ig, dst, id, code);
1105511058
sz = id->idIsLargeCall() ? sizeof(instrDescCGCA) : sizeof(instrDesc);
1105611059
break;
@@ -13375,7 +13378,15 @@ void emitter::emitDispInsHelp(
1337513378
case IF_BR_1B: // BR_1B ................ ......nnnnn..... Rn
1337613379
// The size of a branch target is always EA_PTRSIZE
1337713380
assert(insOptsNone(id->idInsOpt()));
13378-
emitDispReg(id->idReg3(), EA_PTRSIZE, false);
13381+
13382+
if (emitComp->IsTargetAbi(CORINFO_NATIVEAOT_ABI) && id->idIsTlsGD())
13383+
{
13384+
emitDispReg(REG_R2, EA_PTRSIZE, false);
13385+
}
13386+
else
13387+
{
13388+
emitDispReg(id->idReg3(), EA_PTRSIZE, false);
13389+
}
1337913390
break;
1338013391

1338113392
case IF_LS_1A: // LS_1A XX...V..iiiiiiii iiiiiiiiiiittttt Rt PC imm(1MB)

0 commit comments

Comments
 (0)