Skip to content

Commit e9be069

Browse files
authored
JIT: Switch GS cookie check temp reg to use r10 for tailcalls (#120941)
rax was used before, but rax is used as an argument for the indirection cell for R2R tailcalls. r10 has a use for some pinvokes, but we do not tailcall for these. Fix #120780
1 parent b7a761c commit e9be069

File tree

2 files changed

+11
-7
lines changed

2 files changed

+11
-7
lines changed

src/coreclr/jit/codegencommon.cpp

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2519,17 +2519,17 @@ CorInfoHelpFunc CodeGenInterface::genWriteBarrierHelperForWriteBarrierForm(GCInf
25192519
//
25202520
regMaskTP CodeGenInterface::genGetGSCookieTempRegs(bool tailCall)
25212521
{
2522-
#ifdef TARGET_XARCH
2522+
#ifdef TARGET_AMD64
25232523
if (tailCall)
25242524
{
2525-
// If we are tailcalling then return registers are available for use
2526-
return RBM_RAX;
2525+
// If we are tailcalling then arg regs cannot be used. For both SysV and winx64 that
2526+
// leaves rax, r10, r11. rax and r11 are used for indirection cells, so we pick r10.
2527+
return RBM_R10;
25272528
}
2528-
2529-
#ifdef TARGET_AMD64
25302529
// Otherwise on x64 (win-x64 and SysV) r8 is never used for return values
25312530
return RBM_R8;
2532-
#else
2531+
#elif TARGET_X86
2532+
assert(!tailCall);
25332533
// On x86 it's more difficult: we have only eax, ecx and edx available as volatile
25342534
// registers, and all of them may be used for return values (longs + async continuation).
25352535
if (compiler->compIsAsync())
@@ -2540,7 +2540,6 @@ regMaskTP CodeGenInterface::genGetGSCookieTempRegs(bool tailCall)
25402540

25412541
// Outside async ecx is not used for returns.
25422542
return RBM_ECX;
2543-
#endif
25442543
#else
25452544
return RBM_GSCOOKIE_TMP;
25462545
#endif

src/coreclr/jit/morph.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1773,6 +1773,11 @@ void CallArgs::AddFinalArgsAndDetermineABIInfo(Compiler* comp, GenTreeCall* call
17731773
InsertAfterThisOrFirst(comp, NewCallArg::Primitive(arg).WellKnown(WellKnownArg::PInvokeCookie));
17741774
// put destination into R10/EAX
17751775
arg = comp->gtClone(call->gtCallAddr, true);
1776+
// On x64 the pinvoke target is passed in r11 which is the same
1777+
// register as the gs cookie check may use. That would be a problem if
1778+
// this was a tailcall, but we do not tailcall functions with
1779+
// non-standard added args except indirection cells currently.
1780+
assert(!call->IsFastTailCall());
17761781
InsertAfterThisOrFirst(comp, NewCallArg::Primitive(arg).WellKnown(WellKnownArg::PInvokeTarget));
17771782

17781783
// finally change this call to a helper call

0 commit comments

Comments
 (0)