Skip to content

[NativeAOT] Do not emit safe point for TLS_GET_ADDR calls into native runtime. #102237

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
May 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion src/coreclr/jit/codegen.h
Original file line number Diff line number Diff line change
Expand Up @@ -506,7 +506,8 @@ class CodeGen final : public CodeGenInterface
MULTIREG_HAS_SECOND_GC_RET_ONLY_ARG(emitAttr secondRetSize),
const DebugInfo& di,
regNumber base,
bool isJump);
bool isJump,
bool noSafePoint = false);
// clang-format on

// clang-format off
Expand Down
5 changes: 4 additions & 1 deletion src/coreclr/jit/codegenarmarch.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3599,6 +3599,7 @@ void CodeGen::genCallInstruction(GenTreeCall* call)
// We just need to emit "call reg" in this case.
//
assert(genIsValidIntReg(target->GetRegNum()));
bool noSafePoint = false;

#ifdef TARGET_ARM64
bool isTlsHandleTarget =
Expand All @@ -3612,6 +3613,7 @@ void CodeGen::genCallInstruction(GenTreeCall* call)
GenTreeIntCon* iconNode = target->AsIntCon();
methHnd = (CORINFO_METHOD_HANDLE)iconNode->gtIconVal;
retSize = EA_SET_FLG(retSize, EA_CNS_TLSGD_RELOC);
noSafePoint = true;

// For NativeAOT, linux/arm64, linker wants the following pattern, so we will generate
// it as part of the call. Generating individual instructions is tricky to get it
Expand Down Expand Up @@ -3647,7 +3649,8 @@ void CodeGen::genCallInstruction(GenTreeCall* call)
MULTIREG_HAS_SECOND_GC_RET_ONLY_ARG(secondRetSize),
di,
target->GetRegNum(),
call->IsFastTailCall());
call->IsFastTailCall(),
noSafePoint);

#ifdef TARGET_ARM64
if (isTlsHandleTarget)
Expand Down
6 changes: 4 additions & 2 deletions src/coreclr/jit/codegenlinear.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2246,6 +2246,7 @@ void CodeGen::genTransferRegGCState(regNumber dst, regNumber src)
// pass in 'addr' for a relative call or 'base' for a indirect register call
// methHnd - optional, only used for pretty printing
// retSize - emitter type of return for GC purposes, should be EA_BYREF, EA_GCREF, or EA_PTRSIZE(not GC)
// noSafePoint - force not making this call a safe point in partially interruptible code
//
// clang-format off
void CodeGen::genEmitCall(int callType,
Expand All @@ -2257,7 +2258,8 @@ void CodeGen::genEmitCall(int callType,
MULTIREG_HAS_SECOND_GC_RET_ONLY_ARG(emitAttr secondRetSize),
const DebugInfo& di,
regNumber base,
bool isJump)
bool isJump,
bool noSafePoint)
{
#if !defined(TARGET_X86)
int argSize = 0;
Expand All @@ -2277,7 +2279,7 @@ void CodeGen::genEmitCall(int callType,
gcInfo.gcVarPtrSetCur,
gcInfo.gcRegGCrefSetCur,
gcInfo.gcRegByrefSetCur,
di, base, REG_NA, 0, 0, isJump);
di, base, REG_NA, 0, 0, isJump, noSafePoint);
}
// clang-format on

Expand Down
3 changes: 2 additions & 1 deletion src/coreclr/jit/codegenxarch.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6396,7 +6396,8 @@ void CodeGen::genCallInstruction(GenTreeCall* call X86_ARG(target_ssize_t stackA
MULTIREG_HAS_SECOND_GC_RET_ONLY_ARG(secondRetSize),
di,
target->GetRegNum(),
call->IsFastTailCall());
call->IsFastTailCall(),
true); // noSafePoint
// clang-format on
}
}
Expand Down
7 changes: 5 additions & 2 deletions src/coreclr/jit/emitarm.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4660,6 +4660,8 @@ void emitter::emitIns_J_R(instruction ins, emitAttr attr, BasicBlock* dst, regNu
*
* For ARM xreg, xmul and disp are never used and should always be 0/REG_NA.
*
* noSafePoint - force not making this call a safe point in partially interruptible code
*
* Please consult the "debugger team notification" comment in genFnProlog().
*/

Expand All @@ -4677,7 +4679,8 @@ void emitter::emitIns_Call(EmitCallType callType,
regNumber xreg /* = REG_NA */,
unsigned xmul /* = 0 */,
ssize_t disp /* = 0 */,
bool isJump /* = false */)
bool isJump /* = false */,
bool noSafePoint /* = false */)
{
/* Sanity check the arguments depending on callType */

Expand Down Expand Up @@ -4769,7 +4772,7 @@ void emitter::emitIns_Call(EmitCallType callType,
emitThisByrefRegs = byrefRegs;

// for the purpose of GC safepointing tail-calls are not real calls
id->idSetIsNoGC(isJump || emitNoGChelper(methHnd));
id->idSetIsNoGC(isJump || noSafePoint || emitNoGChelper(methHnd));

/* Set the instruction - special case jumping a function */
instruction ins;
Expand Down
13 changes: 7 additions & 6 deletions src/coreclr/jit/emitarm.h
Original file line number Diff line number Diff line change
Expand Up @@ -330,12 +330,13 @@ void emitIns_Call(EmitCallType callType,
VARSET_VALARG_TP ptrVars,
regMaskTP gcrefRegs,
regMaskTP byrefRegs,
const DebugInfo& di = DebugInfo(),
regNumber ireg = REG_NA,
regNumber xreg = REG_NA,
unsigned xmul = 0,
ssize_t disp = 0,
bool isJump = false);
const DebugInfo& di = DebugInfo(),
regNumber ireg = REG_NA,
regNumber xreg = REG_NA,
unsigned xmul = 0,
ssize_t disp = 0,
bool isJump = false,
bool noSafePoint = false);

/*****************************************************************************
*
Expand Down
7 changes: 5 additions & 2 deletions src/coreclr/jit/emitarm64.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8967,6 +8967,8 @@ void emitter::emitIns_J(instruction ins, BasicBlock* dst, int instrCount)
*
* For ARM xreg, xmul and disp are never used and should always be 0/REG_NA.
*
* noSafePoint - force not making this call a safe point in partially interruptible code
*
* Please consult the "debugger team notification" comment in genFnProlog().
*/

Expand All @@ -8985,7 +8987,8 @@ void emitter::emitIns_Call(EmitCallType callType,
regNumber xreg /* = REG_NA */,
unsigned xmul /* = 0 */,
ssize_t disp /* = 0 */,
bool isJump /* = false */)
bool isJump /* = false */,
bool noSafePoint /* = false */)
{
/* Sanity check the arguments depending on callType */

Expand Down Expand Up @@ -9079,7 +9082,7 @@ void emitter::emitIns_Call(EmitCallType callType,
emitThisByrefRegs = byrefRegs;

// for the purpose of GC safepointing tail-calls are not real calls
id->idSetIsNoGC(isJump || emitNoGChelper(methHnd));
id->idSetIsNoGC(isJump || noSafePoint || emitNoGChelper(methHnd));

/* Set the instruction - special case jumping a function */
instruction ins;
Expand Down
3 changes: 2 additions & 1 deletion src/coreclr/jit/emitarm64.h
Original file line number Diff line number Diff line change
Expand Up @@ -1745,7 +1745,8 @@ void emitIns_Call(EmitCallType callType,
regNumber xreg,
unsigned xmul,
ssize_t disp,
bool isJump);
bool isJump,
bool noSafePoint = false);

BYTE* emitOutputLJ(insGroup* ig, BYTE* dst, instrDesc* i);
unsigned emitOutputCall(insGroup* ig, BYTE* dst, instrDesc* i, code_t code);
Expand Down
7 changes: 5 additions & 2 deletions src/coreclr/jit/emitloongarch64.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2375,6 +2375,8 @@ void emitter::emitIns_I_la(emitAttr size, regNumber reg, ssize_t imm)
*
* For LOONGARCH xreg, xmul and disp are never used and should always be 0/REG_NA.
*
* noSafePoint - force not making this call a safe point in partially interruptible code
*
* Please consult the "debugger team notification" comment in genFnProlog().
*/

Expand All @@ -2392,7 +2394,8 @@ void emitter::emitIns_Call(EmitCallType callType,
regNumber xreg /* = REG_NA */,
unsigned xmul /* = 0 */,
ssize_t disp /* = 0 */,
bool isJump /* = false */)
bool isJump /* = false */,
bool noSafePoint /* = false */)
{
/* Sanity check the arguments depending on callType */

Expand Down Expand Up @@ -2489,7 +2492,7 @@ void emitter::emitIns_Call(EmitCallType callType,
emitThisByrefRegs = byrefRegs;

// for the purpose of GC safepointing tail-calls are not real calls
id->idSetIsNoGC(isJump || emitNoGChelper(methHnd));
id->idSetIsNoGC(isJump || noSafePoint || emitNoGChelper(methHnd));

/* Set the instruction - special case jumping a function */
instruction ins;
Expand Down
11 changes: 6 additions & 5 deletions src/coreclr/jit/emitloongarch64.h
Original file line number Diff line number Diff line change
Expand Up @@ -345,11 +345,12 @@ void emitIns_Call(EmitCallType callType,
regMaskTP gcrefRegs,
regMaskTP byrefRegs,
const DebugInfo& di,
regNumber ireg = REG_NA,
regNumber xreg = REG_NA,
unsigned xmul = 0,
ssize_t disp = 0,
bool isJump = false);
regNumber ireg = REG_NA,
regNumber xreg = REG_NA,
unsigned xmul = 0,
ssize_t disp = 0,
bool isJump = false,
bool noSafePoint = false);

unsigned emitOutputCall(insGroup* ig, BYTE* dst, instrDesc* id, code_t code);

Expand Down
7 changes: 5 additions & 2 deletions src/coreclr/jit/emitriscv64.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1287,6 +1287,8 @@ void emitter::emitLoadImmediate(emitAttr size, regNumber reg, ssize_t imm)
* If callType is one of these emitCallTypes, addr has to be NULL.
* EC_INDIR_R : "call ireg".
*
* noSafePoint - force not making this call a safe point in partially interruptible code
*
*/

void emitter::emitIns_Call(EmitCallType callType,
Expand All @@ -1303,7 +1305,8 @@ void emitter::emitIns_Call(EmitCallType callType,
regNumber xreg /* = REG_NA */,
unsigned xmul /* = 0 */,
ssize_t disp /* = 0 */,
bool isJump /* = false */)
bool isJump /* = false */,
bool noSafePoint /* = false */)
{
/* Sanity check the arguments depending on callType */

Expand Down Expand Up @@ -1400,7 +1403,7 @@ void emitter::emitIns_Call(EmitCallType callType,
emitThisByrefRegs = byrefRegs;

// for the purpose of GC safepointing tail-calls are not real calls
id->idSetIsNoGC(isJump || emitNoGChelper(methHnd));
id->idSetIsNoGC(isJump || noSafePoint || emitNoGChelper(methHnd));

/* Set the instruction - special case jumping a function */
instruction ins;
Expand Down
11 changes: 6 additions & 5 deletions src/coreclr/jit/emitriscv64.h
Original file line number Diff line number Diff line change
Expand Up @@ -331,11 +331,12 @@ void emitIns_Call(EmitCallType callType,
regMaskTP gcrefRegs,
regMaskTP byrefRegs,
const DebugInfo& di,
regNumber ireg = REG_NA,
regNumber xreg = REG_NA,
unsigned xmul = 0,
ssize_t disp = 0,
bool isJump = false);
regNumber ireg = REG_NA,
regNumber xreg = REG_NA,
unsigned xmul = 0,
ssize_t disp = 0,
bool isJump = false,
bool noSafePoint = false);

unsigned emitOutputCall(const insGroup* ig, BYTE* dst, instrDesc* id, code_t code);

Expand Down
7 changes: 5 additions & 2 deletions src/coreclr/jit/emitxarch.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9646,6 +9646,8 @@ void emitter::emitAdjustStackDepth(instruction ins, ssize_t val)
* EC_INDIR_C : "call clsVar<disp>" (eg. call [clsVarAddr])
* EC_INDIR_ARD : "call [ireg+xreg*xmul+disp]"
*
* noSafePoint - force not making this call a safe point in partially interruptible code
*
*/

// clang-format off
Expand All @@ -9664,7 +9666,8 @@ void emitter::emitIns_Call(EmitCallType callType,
regNumber xreg,
unsigned xmul,
ssize_t disp,
bool isJump)
bool isJump,
bool noSafePoint)
// clang-format on
{
/* Sanity check the arguments depending on callType */
Expand Down Expand Up @@ -9790,7 +9793,7 @@ void emitter::emitIns_Call(EmitCallType callType,
id->idIns(ins);

// for the purpose of GC safepointing tail-calls are not real calls
id->idSetIsNoGC(isJump || emitNoGChelper(methHnd));
id->idSetIsNoGC(isJump || noSafePoint || emitNoGChelper(methHnd));

UNATIVE_OFFSET sz;

Expand Down
3 changes: 2 additions & 1 deletion src/coreclr/jit/emitxarch.h
Original file line number Diff line number Diff line change
Expand Up @@ -1017,7 +1017,8 @@ void emitIns_Call(EmitCallType callType,
regNumber xreg = REG_NA,
unsigned xmul = 0,
ssize_t disp = 0,
bool isJump = false);
bool isJump = false,
bool noSafePoint = false);
// clang-format on

#ifdef TARGET_AMD64
Expand Down
Loading