Skip to content

Commit 9bef28b

Browse files
authored
Cleanup unused JIT stubs in vm (#111237)
* Undef JIT_TailCall on non-Windows x86 * JIT_TailCallReturnFromVSD * JIT_TailCallVSDLeave and JIT_TailCallLeave * Move JIT_ProfilerEnterLeaveTailcallStub to asm * GetCONTEXTFromRedirectedStubStackFrame * RedirectForThrowControl and empty unixstubs * Update comment mentioning RedirectForThrowControl * Link to issue for stack probing * Remove GetCONTEXTFromRedirectedStubStackFrame(T_DISPATCHER_CONTEXT) on all unix * Remove defines for other archs in Windows specific handler
1 parent 82ab892 commit 9bef28b

27 files changed

+41
-229
lines changed

src/coreclr/debug/ee/debugger.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3994,6 +3994,8 @@ HANDLE OpenWin32EventOrThrow(
39943994
// Returns true if the specified IL offset has a special meaning (eg. prolog, etc.)
39953995
bool DbgIsSpecialILOffset(DWORD offset);
39963996

3997+
#if defined(TARGET_WINDOWS)
39973998
void FixupDispatcherContext(T_DISPATCHER_CONTEXT* pDispatcherContext, T_CONTEXT* pContext, PEXCEPTION_ROUTINE pUnwindPersonalityRoutine = NULL);
3999+
#endif
39984000

39994001
#endif /* DEBUGGER_H_ */

src/coreclr/jit/lower.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3411,7 +3411,7 @@ void Lowering::RehomeArgForFastTailCall(unsigned int lclNum,
34113411
//------------------------------------------------------------------------
34123412
// LowerTailCallViaJitHelper: lower a call via the tailcall JIT helper. Morph
34133413
// has already inserted tailcall helper special arguments. This function inserts
3414-
// actual data for some placeholders. This function is only used on x86.
3414+
// actual data for some placeholders. This function is only used on Windows x86.
34153415
//
34163416
// Lower
34173417
// tail.call(<function args>, int numberOfOldStackArgs, int dummyNumberOfNewStackArgs, int flags, void* dummyArg)

src/coreclr/jit/morph.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6319,7 +6319,7 @@ void Compiler::fgMorphTailCallViaJitHelper(GenTreeCall* call)
63196319
// For the helper-assisted tail calls, we need to push all the arguments
63206320
// into a single list, and then add a few extra at the beginning or end.
63216321
//
6322-
// For x86, the tailcall helper is defined as:
6322+
// For Windows x86, the tailcall helper is defined as:
63236323
//
63246324
// JIT_TailCall(<function args>, int numberOfOldStackArgsWords, int numberOfNewStackArgsWords, int flags, void*
63256325
// callTarget)

src/coreclr/vm/CMakeLists.txt

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -855,12 +855,6 @@ elseif(CLR_CMAKE_TARGET_ARCH_RISCV64)
855855
)
856856
endif()
857857

858-
if(CLR_CMAKE_HOST_UNIX)
859-
list(APPEND VM_SOURCES_WKS_ARCH
860-
${ARCH_SOURCES_DIR}/unixstubs.cpp
861-
)
862-
endif(CLR_CMAKE_HOST_UNIX)
863-
864858
set(VM_SOURCES_DAC_ARCH
865859
exceptionhandling.cpp
866860
)

src/coreclr/vm/amd64/asmhelpers.S

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,14 @@
4444
#
4545
# ***********************************************************
4646

47+
# EXTERN_C void JIT_ProfilerEnterLeaveTailcallStub(UINT_PTR ProfilerHandle);
48+
# <NOTE>
49+
#
50+
# </NOTE>
51+
LEAF_ENTRY JIT_ProfilerEnterLeaveTailcallStub, _TEXT
52+
ret
53+
LEAF_END JIT_ProfilerEnterLeaveTailcallStub, _TEXT
54+
4755
# EXTERN_C void ProfileEnterNaked(FunctionIDOrClientID functionIDOrClientID, size_t profiledRsp);
4856
# <NOTE>
4957
#

src/coreclr/vm/amd64/excepamd64.cpp

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -48,12 +48,14 @@ inline PTR_CONTEXT GetCONTEXTFromRedirectedStubStackFrameWorker(UINT_PTR establi
4848
return *ppContext;
4949
}
5050

51+
#ifdef TARGET_WINDOWS
5152
PTR_CONTEXT GetCONTEXTFromRedirectedStubStackFrame(DISPATCHER_CONTEXT * pDispatcherContext)
5253
{
5354
LIMITED_METHOD_DAC_CONTRACT;
5455

5556
return GetCONTEXTFromRedirectedStubStackFrameWorker(pDispatcherContext->EstablisherFrame);
5657
}
58+
#endif // TARGET_WINDOWS
5759

5860
PTR_CONTEXT GetCONTEXTFromRedirectedStubStackFrame(CONTEXT * pContext)
5961
{
@@ -63,17 +65,14 @@ PTR_CONTEXT GetCONTEXTFromRedirectedStubStackFrame(CONTEXT * pContext)
6365
}
6466

6567
#if !defined(DACCESS_COMPILE)
66-
68+
#ifdef TARGET_WINDOWS
6769
FaultingExceptionFrame *GetFrameFromRedirectedStubStackFrame (DISPATCHER_CONTEXT *pDispatcherContext)
6870
{
6971
LIMITED_METHOD_CONTRACT;
7072

7173
return (FaultingExceptionFrame*)(pDispatcherContext->EstablisherFrame + THROWSTUB_ESTABLISHER_OFFSET_FaultingExceptionFrame);
7274
}
73-
74-
#endif // !DACCESS_COMPILE
75-
76-
#if !defined(DACCESS_COMPILE)
75+
#endif // TARGET_WINDOWS
7776

7877
#define AMD64_SIZE64_PREFIX 0x48
7978
#define AMD64_ADD_IMM8_OP 0x83

src/coreclr/vm/amd64/excepcpu.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,14 +40,18 @@ EXTERN_C void RedirectForThrowControl();
4040
// Retrieves the redirected CONTEXT* from the stack frame of one of the
4141
// RedirectedHandledJITCaseForXXX_Stub's.
4242
//
43+
#ifdef TARGET_WINDOWS
4344
PTR_CONTEXT GetCONTEXTFromRedirectedStubStackFrame(DISPATCHER_CONTEXT * pDispatcherContext);
45+
#endif // TARGET_WINDOWS
4446
PTR_CONTEXT GetCONTEXTFromRedirectedStubStackFrame(CONTEXT * pContext);
4547

48+
#ifdef TARGET_WINDOWS
4649
//
4750
// Retrieves the FaultingExceptionFrame* from the stack frame of
4851
// RedirectForThrowControl.
4952
//
5053
FaultingExceptionFrame *GetFrameFromRedirectedStubStackFrame (DISPATCHER_CONTEXT *pDispatcherContext);
54+
#endif // TARGET_WINDOWS
5155

5256
//
5357
// Functions that wrap RtlVirtualUnwind to make sure that in the AMD64 case all the

src/coreclr/vm/amd64/unixstubs.cpp

Lines changed: 0 additions & 11 deletions
This file was deleted.

src/coreclr/vm/arm/exceparm.cpp

Lines changed: 0 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -7,15 +7,6 @@
77
#include "asmconstants.h"
88
#include "virtualcallstub.h"
99

10-
PTR_CONTEXT GetCONTEXTFromRedirectedStubStackFrame(T_DISPATCHER_CONTEXT * pDispatcherContext)
11-
{
12-
LIMITED_METHOD_DAC_CONTRACT;
13-
14-
UINT_PTR stackSlot = pDispatcherContext->EstablisherFrame + REDIRECTSTUB_SP_OFFSET_CONTEXT;
15-
PTR_PTR_CONTEXT ppContext = dac_cast<PTR_PTR_CONTEXT>((TADDR)stackSlot);
16-
return *ppContext;
17-
}
18-
1910
PTR_CONTEXT GetCONTEXTFromRedirectedStubStackFrame(T_CONTEXT * pContext)
2011
{
2112
LIMITED_METHOD_DAC_CONTRACT;
@@ -27,32 +18,6 @@ PTR_CONTEXT GetCONTEXTFromRedirectedStubStackFrame(T_CONTEXT * pContext)
2718

2819
#if !defined(DACCESS_COMPILE)
2920

30-
// The next two functions help retrieve data kept relative to FaultingExceptionFrame that is setup
31-
// for handling async exceptions (e.g. AV, NullRef, ThreadAbort, etc).
32-
//
33-
// FEF (and related data) is available relative to R4 - the thing to be kept in mind is that the
34-
// DispatcherContext->ContextRecord:
35-
//
36-
// 1) represents the caller context in the first pass.
37-
// 2) represents the current context in the second pass.
38-
//
39-
// Since R4 is a non-volatile register, this works for us since we setup the value of R4
40-
// in the redirection helpers (e.g. RedirectForThreadAbort) but do not
41-
// change it in their respective callee functions (e.g. RedirectForThreadAbort2)
42-
// that have the personality routines associated with them (which perform the collided unwind and also
43-
// invoke the two functions below).
44-
//
45-
// Thus, when our personality routine gets called in either passes, DC->ContextRecord->R4 will
46-
// have the same value.
47-
48-
// Returns the pointer to the FEF
49-
FaultingExceptionFrame *GetFrameFromRedirectedStubStackFrame (T_DISPATCHER_CONTEXT *pDispatcherContext)
50-
{
51-
LIMITED_METHOD_CONTRACT;
52-
53-
return (FaultingExceptionFrame*)((TADDR)pDispatcherContext->ContextRecord->R4);
54-
}
55-
5621
// Returns TRUE if caller should resume execution.
5722
BOOL
5823
AdjustContextForVirtualStub(

src/coreclr/vm/arm/excepcpu.h

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -26,15 +26,8 @@ class FaultingExceptionFrame;
2626
// Retrieves the redirected CONTEXT* from the stack frame of one of the
2727
// RedirectedHandledJITCaseForXXX_Stub's.
2828
//
29-
PTR_CONTEXT GetCONTEXTFromRedirectedStubStackFrame(T_DISPATCHER_CONTEXT * pDispatcherContext);
3029
PTR_CONTEXT GetCONTEXTFromRedirectedStubStackFrame(T_CONTEXT * pContext);
3130

32-
//
33-
// Retrieves the FaultingExceptionFrame* from the stack frame of
34-
// RedirectForThrowControl.
35-
//
36-
FaultingExceptionFrame *GetFrameFromRedirectedStubStackFrame (T_DISPATCHER_CONTEXT *pDispatcherContext);
37-
3831
inline
3932
PCODE GetAdjustedCallAddress(PCODE returnAddress)
4033
{

src/coreclr/vm/arm/unixstubs.cpp

Lines changed: 0 additions & 4 deletions
This file was deleted.

src/coreclr/vm/arm64/excepcpu.h

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,14 +28,18 @@ class FaultingExceptionFrame;
2828
// Retrieves the redirected CONTEXT* from the stack frame of one of the
2929
// RedirectedHandledJITCaseForXXX_Stub's.
3030
//
31+
#ifdef TARGET_WINDOWS
3132
PTR_CONTEXT GetCONTEXTFromRedirectedStubStackFrame(T_DISPATCHER_CONTEXT * pDispatcherContext);
33+
#endif // TARGET_WINDOWS
3234
PTR_CONTEXT GetCONTEXTFromRedirectedStubStackFrame(T_CONTEXT * pContext);
3335

36+
#ifdef TARGET_WINDOWS
3437
//
3538
// Retrieves the FaultingExceptionFrame* from the stack frame of
36-
// RedirectForThrowControl.
39+
// RedirectForThreadAbort.
3740
//
3841
FaultingExceptionFrame *GetFrameFromRedirectedStubStackFrame (T_DISPATCHER_CONTEXT *pDispatcherContext);
42+
#endif // TARGET_WINDOWS
3943

4044
inline
4145
PCODE GetAdjustedCallAddress(PCODE returnAddress)

src/coreclr/vm/arm64/stubs.cpp

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -859,11 +859,6 @@ void emitCOMStubCall (ComCallMethodDesc *pCOMMethodRX, ComCallMethodDesc *pCOMMe
859859
}
860860
#endif // FEATURE_COMINTEROP
861861

862-
void JIT_TailCall()
863-
{
864-
_ASSERTE(!"ARM64:NYI");
865-
}
866-
867862
#if !defined(DACCESS_COMPILE)
868863
EXTERN_C void JIT_UpdateWriteBarrierState(bool skipEphemeralCheck, size_t writeableOffset);
869864

@@ -917,6 +912,7 @@ void InitJITHelpers1()
917912
void UpdateWriteBarrierState(bool) {}
918913
#endif // !defined(DACCESS_COMPILE)
919914

915+
#ifdef TARGET_WINDOWS
920916
PTR_CONTEXT GetCONTEXTFromRedirectedStubStackFrame(T_DISPATCHER_CONTEXT * pDispatcherContext)
921917
{
922918
LIMITED_METHOD_DAC_CONTRACT;
@@ -925,6 +921,7 @@ PTR_CONTEXT GetCONTEXTFromRedirectedStubStackFrame(T_DISPATCHER_CONTEXT * pDispa
925921
PTR_PTR_CONTEXT ppContext = dac_cast<PTR_PTR_CONTEXT>((TADDR)stackSlot);
926922
return *ppContext;
927923
}
924+
#endif // TARGET_WINDOWS
928925

929926
PTR_CONTEXT GetCONTEXTFromRedirectedStubStackFrame(T_CONTEXT * pContext)
930927
{
@@ -936,13 +933,14 @@ PTR_CONTEXT GetCONTEXTFromRedirectedStubStackFrame(T_CONTEXT * pContext)
936933
}
937934

938935
#if !defined(DACCESS_COMPILE)
936+
#ifdef TARGET_WINDOWS
939937
FaultingExceptionFrame *GetFrameFromRedirectedStubStackFrame (DISPATCHER_CONTEXT *pDispatcherContext)
940938
{
941939
LIMITED_METHOD_CONTRACT;
942940

943941
return (FaultingExceptionFrame*)((TADDR)pDispatcherContext->ContextRecord->X19);
944942
}
945-
943+
#endif // TARGET_WINDOWS
946944

947945
BOOL
948946
AdjustContextForVirtualStub(

src/coreclr/vm/arm64/unixstubs.cpp

Lines changed: 0 additions & 4 deletions
This file was deleted.

src/coreclr/vm/exceptionhandling.cpp

Lines changed: 5 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -5867,7 +5867,7 @@ void TrackerAllocator::FreeTrackerMemory(ExceptionTracker* pTracker)
58675867
InterlockedExchangeT(&(pTracker->m_pThread), NULL);
58685868
}
58695869

5870-
#ifndef TARGET_UNIX
5870+
#ifdef TARGET_WINDOWS
58715871
// This is Windows specific implementation as it is based upon the notion of collided unwind that is specific
58725872
// to Windows 64bit.
58735873
//
@@ -5890,8 +5890,8 @@ void FixupDispatcherContext(DISPATCHER_CONTEXT* pDispatcherContext, CONTEXT* pCo
58905890
}
58915891

58925892
pDispatcherContext->ControlPc = (UINT_PTR) GetIP(pDispatcherContext->ContextRecord);
5893-
5894-
#if defined(TARGET_ARM) || defined(TARGET_ARM64) || defined(TARGET_LOONGARCH64) || defined(TARGET_RISCV64)
5893+
5894+
#if defined(TARGET_ARM64)
58955895
// Since this routine is used to fixup contexts for async exceptions,
58965896
// clear the CONTEXT_UNWOUND_TO_CALL flag since, semantically, frames
58975897
// where such exceptions have happened do not have callsites. On a similar
@@ -5911,21 +5911,10 @@ void FixupDispatcherContext(DISPATCHER_CONTEXT* pDispatcherContext, CONTEXT* pCo
59115911
// be fixing it at their end, in their implementation of collided unwind.
59125912
pDispatcherContext->ContextRecord->ContextFlags &= ~CONTEXT_DEBUG_REGISTERS;
59135913

5914-
#ifdef TARGET_ARM
5915-
// But keep the architecture flag set (its part of CONTEXT_DEBUG_REGISTERS)
5916-
pDispatcherContext->ContextRecord->ContextFlags |= CONTEXT_ARM;
5917-
#elif defined(TARGET_LOONGARCH64)
5918-
// But keep the architecture flag set (its part of CONTEXT_DEBUG_REGISTERS)
5919-
pDispatcherContext->ContextRecord->ContextFlags |= CONTEXT_LOONGARCH64;
5920-
#elif defined(TARGET_RISCV64)
5921-
// But keep the architecture flag set (its part of CONTEXT_DEBUG_REGISTERS)
5922-
pDispatcherContext->ContextRecord->ContextFlags |= CONTEXT_RISCV64;
5923-
#else // TARGET_ARM64
59245914
// But keep the architecture flag set (its part of CONTEXT_DEBUG_REGISTERS)
59255915
pDispatcherContext->ContextRecord->ContextFlags |= CONTEXT_ARM64;
5926-
#endif // TARGET_ARM
59275916

5928-
#endif // TARGET_ARM || TARGET_ARM64 || TARGET_LOONGARCH64 || TARGET_RISCV64
5917+
#endif // TARGET_ARM64
59295918

59305919
INDEBUG(pDispatcherContext->FunctionEntry = (PT_RUNTIME_FUNCTION)INVALID_POINTER_CD);
59315920
INDEBUG(pDispatcherContext->ImageBase = INVALID_POINTER_CD);
@@ -6101,7 +6090,7 @@ HijackHandler(IN PEXCEPTION_RECORD pExceptionRecord,
61016090
}
61026091

61036092

6104-
#endif // !TARGET_UNIX
6093+
#endif // !TARGET_WINDOWS
61056094

61066095
#ifdef _DEBUG
61076096
// IsSafeToUnwindFrameChain:

src/coreclr/vm/i386/excepcpu.h

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -89,9 +89,6 @@ EXTERN_C LPVOID STDCALL COMPlusEndCatch(LPVOID ebp, DWORD ebx, DWORD edi, DWORD
8989
// RedirectedHandledJITCaseForXXX_Stub's.
9090
//
9191
PTR_CONTEXT GetCONTEXTFromRedirectedStubStackFrame(CONTEXT * pContext);
92-
#ifdef FEATURE_EH_FUNCLETS
93-
PTR_CONTEXT GetCONTEXTFromRedirectedStubStackFrame(T_DISPATCHER_CONTEXT * pDispatcherContext);
94-
#endif // FEATURE_EH_FUNCLETS
9592

9693
// Determine the address of the instruction that made the current call.
9794
inline

src/coreclr/vm/i386/unixstubs.cpp

Lines changed: 0 additions & 30 deletions
This file was deleted.

src/coreclr/vm/i386/virtualcallstubcpu.hpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -690,8 +690,10 @@ StubCallSite::StubCallSite(TADDR siteAddrForRegisterIndirect, PCODE returnAddr)
690690
}
691691
}
692692

693+
#ifndef UNIX_X86_ABI
693694
// the special return address for VSD tailcalls
694695
extern "C" void STDCALL JIT_TailCallReturnFromVSD();
696+
#endif // UNIX_X86_ABI
695697

696698
PCODE StubCallSite::GetCallerAddress()
697699
{

src/coreclr/vm/jitinterface.h

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -352,24 +352,19 @@ extern "C"
352352
{
353353
#ifndef FEATURE_EH_FUNCLETS
354354
void STDCALL JIT_EndCatch(); // JIThelp.asm/JIThelp.s
355-
#endif // TARGET_X86
355+
#endif // FEATURE_EH_FUNCLETS
356356

357357
void STDCALL JIT_ByRefWriteBarrier(); // JIThelp.asm/JIThelp.s
358358

359-
#if defined(TARGET_AMD64) || defined(TARGET_ARM)
360-
361-
FCDECL2VA(void, JIT_TailCall, PCODE copyArgs, PCODE target);
362-
363-
#else // TARGET_AMD64 || TARGET_ARM
364-
359+
#if defined(TARGET_X86) && !defined(UNIX_X86_ABI)
365360
void STDCALL JIT_TailCall(); // JIThelp.asm
366-
367-
#endif // TARGET_AMD64 || TARGET_ARM
361+
#endif // defined(TARGET_X86) && !defined(UNIX_X86_ABI)
368362

369363
void STDMETHODCALLTYPE JIT_ProfilerEnterLeaveTailcallStub(UINT_PTR ProfilerHandle);
370364
#if !defined(TARGET_ARM64) && !defined(TARGET_LOONGARCH64) && !defined(TARGET_RISCV64)
365+
// TODO: implement stack probing for other architectures https://github.com/dotnet/runtime/issues/13519
371366
void STDCALL JIT_StackProbe();
372-
#endif // TARGET_ARM64
367+
#endif // !defined(TARGET_ARM64) && !defined(TARGET_LOONGARCH64) && !defined(TARGET_RISCV64)
373368
};
374369

375370
/*********************************************************************/

0 commit comments

Comments
 (0)