From 66eb69ed282c2d35fc64f94e76cf3eeaf83edb5c Mon Sep 17 00:00:00 2001 From: Jan Kotas Date: Thu, 24 Feb 2022 15:42:47 -0800 Subject: [PATCH 1/3] Cleanup fragile NGen leftovers --- src/coreclr/inc/corcompile.h | 50 ------------- src/coreclr/inc/corinfo.h | 11 --- src/coreclr/inc/jiteeversionguid.h | 10 +-- src/coreclr/inc/jithelpers.h | 20 ----- .../Common/JitInterface/CorInfoHelpFunc.cs | 11 --- src/coreclr/vm/cgensys.h | 1 - src/coreclr/vm/i386/asmhelpers.S | 41 ----------- src/coreclr/vm/i386/asmhelpers.asm | 73 ------------------- src/coreclr/vm/prestub.cpp | 54 ++------------ 9 files changed, 10 insertions(+), 261 deletions(-) diff --git a/src/coreclr/inc/corcompile.h b/src/coreclr/inc/corcompile.h index 3c7a7caa97a2c1..fda31203094425 100644 --- a/src/coreclr/inc/corcompile.h +++ b/src/coreclr/inc/corcompile.h @@ -33,8 +33,6 @@ typedef DPTR(struct CORCOMPILE_EXCEPTION_LOOKUP_TABLE_ENTRY) PTR_CORCOMPILE_EXCEPTION_LOOKUP_TABLE_ENTRY; typedef DPTR(struct CORCOMPILE_EXCEPTION_CLAUSE) PTR_CORCOMPILE_EXCEPTION_CLAUSE; -typedef DPTR(struct CORCOMPILE_EXTERNAL_METHOD_THUNK) - PTR_CORCOMPILE_EXTERNAL_METHOD_THUNK; typedef DPTR(struct CORCOMPILE_EXTERNAL_METHOD_DATA_ENTRY) PTR_CORCOMPILE_EXTERNAL_METHOD_DATA_ENTRY; typedef DPTR(struct CORCOMPILE_IMPORT_SECTION) @@ -139,54 +137,6 @@ inline BOOL CORCOMPILE_IS_FIXUP_TAGGED(SIZE_T fixup, PTR_CORCOMPILE_IMPORT_SECTI return ((((SIZE_T)(fixup)) & CORCOMPILE_TOKEN_TAG) == CORCOMPILE_TOKEN_TAG); } -/*********************************************************************************/ - -#if defined(TARGET_X86) || defined(TARGET_AMD64) - -#define _PRECODE_EXTERNAL_METHOD_THUNK 0x41 - struct CORCOMPILE_EXTERNAL_METHOD_THUNK - { - BYTE callJmp[5]; // Call/Jmp Pc-Rel32 - BYTE precodeType; // 0x41 _PRECODE_EXTERNAL_METHOD_THUNK - WORD padding; - }; - -#elif defined(TARGET_ARM) - - struct CORCOMPILE_EXTERNAL_METHOD_THUNK - { - // Array of words to do the following: - // - // mov r12, pc ; Save the current address relative to which we will get GCRef bitmap and address to patch. - // ldr pc, [pc, #4] ; Load the target address. Initially it will point to the helper stub that will patch it - // ; to point to the actual target on the first run. - WORD m_rgCode[3]; - - WORD m_padding; - - // The target address - initially, this will point to ExternalMethodFixupStub. - // Post patchup by the stub, it will point to the actual method body. - PCODE m_pTarget; - }; - -#elif defined(TARGET_ARM64) - struct CORCOMPILE_EXTERNAL_METHOD_THUNK - { - // Array of words to do the following: - // adr x12, #0 ; Save the current address relative to which we will get slot ID and address to patch. - // ldr x10, [x12, #16] ; Load the target address. - // br x10 ; Jump to the target - DWORD m_rgCode[3]; - - DWORD m_padding; //aligning stack to 16 bytes - - // The target address - initially, this will point to ExternalMethodFixupStub. - // Post patchup by the stub, it will point to the actual method body. - PCODE m_pTarget; - }; - -#endif - // // GCRefMap blob starts with DWORDs lookup index of relative offsets into the blob. This lookup index is used to limit amount // of linear scanning required to find entry in the GCRefMap. The size of this lookup index is diff --git a/src/coreclr/inc/corinfo.h b/src/coreclr/inc/corinfo.h index 28f4c880b62a1f..99dd1fb7c2831a 100644 --- a/src/coreclr/inc/corinfo.h +++ b/src/coreclr/inc/corinfo.h @@ -582,7 +582,6 @@ enum CorInfoHelpFunc CORINFO_HELP_ARE_TYPES_EQUIVALENT, // Check whether two TypeHandles (native structure pointers) are equivalent CORINFO_HELP_VIRTUAL_FUNC_PTR, // look up a virtual method at run-time - //CORINFO_HELP_VIRTUAL_FUNC_PTR_LOG, // look up a virtual method at run-time, with IBC logging // Not a real helpers. Instead of taking handle arguments, these helpers point to a small stub that loads the handle argument and calls the static helper. CORINFO_HELP_READYTORUN_NEW, @@ -595,16 +594,6 @@ enum CorInfoHelpFunc CORINFO_HELP_READYTORUN_DELEGATE_CTOR, CORINFO_HELP_READYTORUN_GENERIC_STATIC_BASE, - CORINFO_HELP_EE_PRESTUB, // Not real JIT helper. Used in native images. - - CORINFO_HELP_EE_PRECODE_FIXUP, // Not real JIT helper. Used for Precode fixup in native images. - CORINFO_HELP_EE_PINVOKE_FIXUP, // Not real JIT helper. Used for PInvoke target fixup in native images. - CORINFO_HELP_EE_VSD_FIXUP, // Not real JIT helper. Used for VSD cell fixup in native images. - CORINFO_HELP_EE_EXTERNAL_FIXUP, // Not real JIT helper. Used for to fixup external method thunks in native images. - CORINFO_HELP_EE_VTABLE_FIXUP, // Not real JIT helper. Used for inherited vtable slot fixup in native images. - - CORINFO_HELP_EE_REMOTING_THUNK, // Not real JIT helper. Used for remoting precode in native images. - CORINFO_HELP_EE_PERSONALITY_ROUTINE,// Not real JIT helper. Used in native images. CORINFO_HELP_EE_PERSONALITY_ROUTINE_FILTER_FUNCLET,// Not real JIT helper. Used in native images to detect filter funclets. diff --git a/src/coreclr/inc/jiteeversionguid.h b/src/coreclr/inc/jiteeversionguid.h index 303f97b6e7779a..1b0afc9a057359 100644 --- a/src/coreclr/inc/jiteeversionguid.h +++ b/src/coreclr/inc/jiteeversionguid.h @@ -43,11 +43,11 @@ typedef const GUID *LPCGUID; #define GUID_DEFINED #endif // !GUID_DEFINED -constexpr GUID JITEEVersionIdentifier = { /* 80a6aaf7-7fb3-44b2-8fe5-95fd47308798 */ - 0x80a6aaf7, - 0x7fb3, - 0x44b2, - {0x8f, 0xe5, 0x95, 0xfd, 0x47, 0x30, 0x87, 0x98} +constexpr GUID JITEEVersionIdentifier = { /* bcc99ca6-5291-4cc0-a5d9-2758456053f3 */ + 0xbcc99ca6, + 0x5291, + 0x4cc0, + { 0xa5, 0xd9, 0x27, 0x58, 0x45, 0x60, 0x53, 0xf3 } }; ////////////////////////////////////////////////////////////////////////////////////////////////////////// diff --git a/src/coreclr/inc/jithelpers.h b/src/coreclr/inc/jithelpers.h index 82b43a7ab01f56..e2c4e0e8fcbf06 100644 --- a/src/coreclr/inc/jithelpers.h +++ b/src/coreclr/inc/jithelpers.h @@ -252,7 +252,6 @@ JITHELPER(CORINFO_HELP_ARE_TYPES_EQUIVALENT, NULL, CORINFO_HELP_SIG_REG_ONLY) JITHELPER(CORINFO_HELP_VIRTUAL_FUNC_PTR, JIT_VirtualFunctionPointer, CORINFO_HELP_SIG_4_STACK) - //JITHELPER(CORINFO_HELP_VIRTUAL_FUNC_PTR_LOG,JIT_VirtualFunctionPointerLogging) JITHELPER(CORINFO_HELP_READYTORUN_NEW, NULL, CORINFO_HELP_SIG_NO_ALIGN_STUB) JITHELPER(CORINFO_HELP_READYTORUN_NEWARR_1, NULL, CORINFO_HELP_SIG_NO_ALIGN_STUB) @@ -264,25 +263,6 @@ JITHELPER(CORINFO_HELP_READYTORUN_DELEGATE_CTOR, NULL, CORINFO_HELP_SIG_NO_ALIGN_STUB) JITHELPER(CORINFO_HELP_READYTORUN_GENERIC_STATIC_BASE, NULL, CORINFO_HELP_SIG_NO_ALIGN_STUB) - JITHELPER(CORINFO_HELP_EE_PRESTUB, ThePreStub, CORINFO_HELP_SIG_NO_ALIGN_STUB) - -#if defined(HAS_FIXUP_PRECODE) - JITHELPER(CORINFO_HELP_EE_PRECODE_FIXUP, PrecodeFixupThunk, CORINFO_HELP_SIG_NO_ALIGN_STUB) -#else - JITHELPER(CORINFO_HELP_EE_PRECODE_FIXUP, NULL, CORINFO_HELP_SIG_NO_ALIGN_STUB) -#endif - - JITHELPER(CORINFO_HELP_EE_PINVOKE_FIXUP, NDirectImportThunk, CORINFO_HELP_SIG_NO_ALIGN_STUB) - - JITHELPER(CORINFO_HELP_EE_VSD_FIXUP, NULL, CORINFO_HELP_SIG_NO_ALIGN_STUB) - JITHELPER(CORINFO_HELP_EE_EXTERNAL_FIXUP, ExternalMethodFixupStub, CORINFO_HELP_SIG_NO_ALIGN_STUB) - JITHELPER(CORINFO_HELP_EE_VTABLE_FIXUP, NULL, CORINFO_HELP_SIG_NO_ALIGN_STUB) - - JITHELPER(CORINFO_HELP_EE_REMOTING_THUNK, NULL, CORINFO_HELP_SIG_UNDEF) - -// We do not need this to be saved in ngen images on Mac64 since the exception dispatch -// is not done via the OS and thus, there wont be any need to know this information -// by anyone. #ifdef FEATURE_EH_FUNCLETS JITHELPER(CORINFO_HELP_EE_PERSONALITY_ROUTINE, ProcessCLRException, CORINFO_HELP_SIG_UNDEF) JITHELPER(CORINFO_HELP_EE_PERSONALITY_ROUTINE_FILTER_FUNCLET, ProcessCLRException,CORINFO_HELP_SIG_UNDEF) diff --git a/src/coreclr/tools/Common/JitInterface/CorInfoHelpFunc.cs b/src/coreclr/tools/Common/JitInterface/CorInfoHelpFunc.cs index 0e5f836ff21102..e39535645034e0 100644 --- a/src/coreclr/tools/Common/JitInterface/CorInfoHelpFunc.cs +++ b/src/coreclr/tools/Common/JitInterface/CorInfoHelpFunc.cs @@ -229,7 +229,6 @@ which is the right helper to use to allocate an object of a given type. */ CORINFO_HELP_ARE_TYPES_EQUIVALENT, // Check whether two TypeHandles (native structure pointers) are equivalent CORINFO_HELP_VIRTUAL_FUNC_PTR, // look up a virtual method at run-time - //CORINFO_HELP_VIRTUAL_FUNC_PTR_LOG, // look up a virtual method at run-time, with IBC logging // Not a real helpers. Instead of taking handle arguments, these helpers point to a small stub that loads the handle argument and calls the static helper. CORINFO_HELP_READYTORUN_NEW, @@ -242,16 +241,6 @@ which is the right helper to use to allocate an object of a given type. */ CORINFO_HELP_READYTORUN_DELEGATE_CTOR, CORINFO_HELP_READYTORUN_GENERIC_STATIC_BASE, - CORINFO_HELP_EE_PRESTUB, // Not real JIT helper. Used in native images. - - CORINFO_HELP_EE_PRECODE_FIXUP, // Not real JIT helper. Used for Precode fixup in native images. - CORINFO_HELP_EE_PINVOKE_FIXUP, // Not real JIT helper. Used for PInvoke target fixup in native images. - CORINFO_HELP_EE_VSD_FIXUP, // Not real JIT helper. Used for VSD cell fixup in native images. - CORINFO_HELP_EE_EXTERNAL_FIXUP, // Not real JIT helper. Used for to fixup external method thunks in native images. - CORINFO_HELP_EE_VTABLE_FIXUP, // Not real JIT helper. Used for inherited vtable slot fixup in native images. - - CORINFO_HELP_EE_REMOTING_THUNK, // Not real JIT helper. Used for remoting precode in native images. - CORINFO_HELP_EE_PERSONALITY_ROUTINE,// Not real JIT helper. Used in native images. CORINFO_HELP_EE_PERSONALITY_ROUTINE_FILTER_FUNCLET,// Not real JIT helper. Used in native images to detect filter funclets. diff --git a/src/coreclr/vm/cgensys.h b/src/coreclr/vm/cgensys.h index e9312f157a042b..ad02efe70d13d1 100644 --- a/src/coreclr/vm/cgensys.h +++ b/src/coreclr/vm/cgensys.h @@ -17,7 +17,6 @@ class CrawlFrame; struct EE_ILEXCEPTION_CLAUSE; struct TransitionBlock; struct VASigCookie; -struct CORCOMPILE_EXTERNAL_METHOD_THUNK; class ComPlusCallMethodDesc; #include diff --git a/src/coreclr/vm/i386/asmhelpers.S b/src/coreclr/vm/i386/asmhelpers.S index 20d179f37fa504..141ac8921ba4d5 100644 --- a/src/coreclr/vm/i386/asmhelpers.S +++ b/src/coreclr/vm/i386/asmhelpers.S @@ -663,47 +663,6 @@ LOCAL_LABEL(GoCallCalliWorker): jmp C_FUNC(GenericPInvokeCalliHelper) LEAF_END GenericPInvokeCalliHelper, _TEXT -// ========================================================================== -NESTED_ENTRY ExternalMethodFixupStub, _TEXT_ NoHandler - // pop off the return address to the stub - // leaving the actual caller's return address on top of the stack - pop eax - - STUB_PROLOG - - mov esi, esp - - // EAX is return address into CORCOMPILE_EXTERNAL_METHOD_THUNK. Subtract 5 to get start address. - sub eax, 5 - -.att_syntax - pushl $0 - pushl $0 -.intel_syntax noprefix - - push eax - - // pTransitionBlock - push esi - - call C_FUNC(ExternalMethodFixupWorker) - - // eax now contains replacement stub. PreStubWorker will never return - // NULL (it throws an exception if stub creation fails.) - - // From here on, mustn't trash eax - - STUB_EPILOG - -PATCH_LABEL ExternalMethodFixupPatchLabel - // Tailcall target - jmp eax - - // This will never be executed. It is just to help out stack-walking logic - // which disassembles the epilog to unwind the stack. - ret -NESTED_END ExternalMethodFixupStub, _TEXT - #ifdef FEATURE_READYTORUN NESTED_ENTRY DynamicHelperArgsStub, _TEXT, NoHandler .cfi_def_cfa_offset 16 diff --git a/src/coreclr/vm/i386/asmhelpers.asm b/src/coreclr/vm/i386/asmhelpers.asm index 896c249822c552..6fe70b80d825dc 100644 --- a/src/coreclr/vm/i386/asmhelpers.asm +++ b/src/coreclr/vm/i386/asmhelpers.asm @@ -47,10 +47,6 @@ EXTERN _NDirectImportWorker@4:PROC EXTERN _VarargPInvokeStubWorker@12:PROC EXTERN _GenericPInvokeCalliStubWorker@12:PROC -ifndef FEATURE_CORECLR -EXTERN _CopyCtorCallStubWorker@4:PROC -endif - EXTERN _PreStubWorker@8:PROC EXTERN _TheUMEntryPrestubWorker@4:PROC @@ -1266,75 +1262,6 @@ FASTCALL_ENDFUNC endif ; FEATURE_COMINTEROP -ifndef FEATURE_CORECLR - -;========================================================================== -; This is small stub whose purpose is to record current stack pointer and -; call CopyCtorCallStubWorker to invoke copy constructors and destructors -; as appropriate. This stub operates on arguments already pushed to the -; stack by JITted IL stub and must not create a new frame, i.e. it must tail -; call to the target for it to see the arguments that copy ctors have been -; called on. -; -_CopyCtorCallStub@0 proc public - ; there may be an argument in ecx - save it - push ecx - - ; push pointer to arguments - lea edx, [esp + 8] - push edx - - call _CopyCtorCallStubWorker@4 - - ; restore ecx and tail call to the target - pop ecx - jmp eax -_CopyCtorCallStub@0 endp - -endif ; !FEATURE_CORECLR - -;========================================================================== -_ExternalMethodFixupStub@0 proc public - - pop eax ; pop off the return address to the stub - ; leaving the actual caller's return address on top of the stack - - STUB_PROLOG - - mov esi, esp - - ; EAX is return address into CORCOMPILE_EXTERNAL_METHOD_THUNK. Subtract 5 to get start address. - sub eax, 5 - - push 0 - push 0 - - push eax - - ; pTransitionBlock - push esi - - call _ExternalMethodFixupWorker@16 - - ; eax now contains replacement stub. PreStubWorker will never return - ; NULL (it throws an exception if stub creation fails.) - - ; From here on, mustn't trash eax - - STUB_EPILOG - -_ExternalMethodFixupPatchLabel@0: -public _ExternalMethodFixupPatchLabel@0 - - ; Tailcall target - jmp eax - - ; This will never be executed. It is just to help out stack-walking logic - ; which disassembles the epilog to unwind the stack. - ret - -_ExternalMethodFixupStub@0 endp - ifdef FEATURE_READYTORUN ;========================================================================== _DelayLoad_MethodCall@0 proc public diff --git a/src/coreclr/vm/prestub.cpp b/src/coreclr/vm/prestub.cpp index 681301621f72ff..4d8d954891ce7e 100644 --- a/src/coreclr/vm/prestub.cpp +++ b/src/coreclr/vm/prestub.cpp @@ -2326,44 +2326,8 @@ static PCODE PatchNonVirtualExternalMethod(MethodDesc * pMD, PCODE pCode, PTR_CO } #endif //HAS_FIXUP_PRECODE - if (pImportSection->Flags & CORCOMPILE_IMPORT_FLAGS_CODE) - { - CORCOMPILE_EXTERNAL_METHOD_THUNK * pThunk = (CORCOMPILE_EXTERNAL_METHOD_THUNK *)pIndirection; - -#if defined(TARGET_X86) || defined(TARGET_AMD64) - INT64 oldValue = *(INT64*)pThunk; - BYTE* pOldValue = (BYTE*)&oldValue; - - if (pOldValue[0] == X86_INSTR_CALL_REL32) - { - INT64 newValue = oldValue; - BYTE* pNewValue = (BYTE*)&newValue; - pNewValue[0] = X86_INSTR_JMP_REL32; - - *(INT32 *)(pNewValue+1) = rel32UsingJumpStub((INT32*)(&pThunk->callJmp[1]), pCode, pMD, NULL); - - _ASSERTE(IS_ALIGNED((size_t)pThunk, sizeof(INT64))); - ExecutableWriterHolder thunkWriterHolder((INT64*)pThunk, sizeof(INT64)); - FastInterlockCompareExchangeLong(thunkWriterHolder.GetRW(), newValue, oldValue); - - FlushInstructionCache(GetCurrentProcess(), pThunk, 8); - } -#elif defined(TARGET_ARM) || defined(TARGET_ARM64) - // Patchup the thunk to point to the actual implementation of the cross module external method - pThunk->m_pTarget = pCode; - - #if defined(TARGET_ARM) - // ThumbBit must be set on the target address - _ASSERTE(pCode & THUMB_CODE); - #endif -#else - PORTABILITY_ASSERT("ExternalMethodFixupWorker"); -#endif - } - else - { - *(TADDR *)pIndirection = pCode; - } + _ASSERTE((pImportSection->Flags & CORCOMPILE_IMPORT_FLAGS_CODE) == 0); + *(TADDR *)pIndirection = pCode; return pCode; } @@ -2468,17 +2432,9 @@ EXTERN_C PCODE STDCALL ExternalMethodFixupWorker(TransitionBlock * pTransitionBl } _ASSERTE(pImportSection != NULL); - COUNT_T index; - if (pImportSection->Flags & CORCOMPILE_IMPORT_FLAGS_CODE) - { - _ASSERTE(pImportSection->EntrySize == sizeof(CORCOMPILE_EXTERNAL_METHOD_THUNK)); - index = (rva - pImportSection->Section.VirtualAddress) / sizeof(CORCOMPILE_EXTERNAL_METHOD_THUNK); - } - else - { - _ASSERTE(pImportSection->EntrySize == sizeof(TADDR)); - index = (rva - pImportSection->Section.VirtualAddress) / sizeof(TADDR); - } + _ASSERTE((pImportSection->Flags & CORCOMPILE_IMPORT_FLAGS_CODE) == 0); + _ASSERTE(pImportSection->EntrySize == sizeof(TADDR)); + COUNT_T index = (rva - pImportSection->Section.VirtualAddress) / sizeof(TADDR); PTR_DWORD pSignatures = dac_cast(pNativeImage->GetRvaData(pImportSection->Signatures)); From e1833a8772e02bb86bb064d792e5570df808650b Mon Sep 17 00:00:00 2001 From: Jan Kotas Date: Thu, 24 Feb 2022 17:40:06 -0800 Subject: [PATCH 2/3] CR feedback, fix build breaks --- .../vm/amd64/ExternalMethodFixupThunk.asm | 25 +---------- .../vm/amd64/externalmethodfixupthunk.S | 24 +---------- src/coreclr/vm/arm/asmhelpers.S | 42 ++----------------- src/coreclr/vm/arm/asmhelpers.asm | 41 +----------------- src/coreclr/vm/arm64/asmhelpers.S | 39 +---------------- src/coreclr/vm/arm64/asmhelpers.asm | 40 ++---------------- src/coreclr/vm/i386/asmhelpers.S | 5 ++- src/coreclr/vm/i386/asmhelpers.asm | 7 +++- 8 files changed, 22 insertions(+), 201 deletions(-) diff --git a/src/coreclr/vm/amd64/ExternalMethodFixupThunk.asm b/src/coreclr/vm/amd64/ExternalMethodFixupThunk.asm index 1a0671e8f1c6a6..c205d43957031c 100644 --- a/src/coreclr/vm/amd64/ExternalMethodFixupThunk.asm +++ b/src/coreclr/vm/amd64/ExternalMethodFixupThunk.asm @@ -11,27 +11,6 @@ ifdef FEATURE_READYTORUN extern DynamicHelperWorker:proc endif -;============================================================================================ -;; EXTERN_C VOID __stdcall ExternalMethodFixupStub() - -NESTED_ENTRY ExternalMethodFixupStub, _TEXT, ProcessCLRException - - PROLOG_WITH_TRANSITION_BLOCK 0, 8, rdx - - lea rcx, [rsp + __PWTB_TransitionBlock] ; pTransitionBlock - sub rdx, 5 ; pThunk - mov r8, 0 ; sectionIndex - mov r9, 0 ; pModule - - call ExternalMethodFixupWorker - - EPILOG_WITH_TRANSITION_BLOCK_TAILCALL -PATCH_LABEL ExternalMethodFixupPatchLabel - TAILJMP_RAX - -NESTED_END ExternalMethodFixupStub, _TEXT - - ifdef FEATURE_READYTORUN NESTED_ENTRY DelayLoad_MethodCall, _TEXT @@ -45,8 +24,8 @@ NESTED_ENTRY DelayLoad_MethodCall, _TEXT EPILOG_WITH_TRANSITION_BLOCK_TAILCALL - ; Share the patch label - jmp ExternalMethodFixupPatchLabel +PATCH_LABEL ExternalMethodFixupPatchLabel + TAILJMP_RAX NESTED_END DelayLoad_MethodCall, _TEXT diff --git a/src/coreclr/vm/amd64/externalmethodfixupthunk.S b/src/coreclr/vm/amd64/externalmethodfixupthunk.S index 217e9dde7b9b17..2c8f104446e7ff 100644 --- a/src/coreclr/vm/amd64/externalmethodfixupthunk.S +++ b/src/coreclr/vm/amd64/externalmethodfixupthunk.S @@ -5,26 +5,6 @@ #include "unixasmmacros.inc" #include "asmconstants.h" -//============================================================================================ -// EXTERN_C VOID __stdcall ExternalMethodFixupStub() - -NESTED_ENTRY ExternalMethodFixupStub, _TEXT, NoHandler - - PROLOG_WITH_TRANSITION_BLOCK 0, 8, rsi, 0, 0 - - lea rdi, [rsp + __PWTB_TransitionBlock] // pTransitionBlock - sub rsi, 5 // pThunk - mov rdx, 0 // sectionIndex - mov rcx, 0 // pModule - - call C_FUNC(ExternalMethodFixupWorker) - - EPILOG_WITH_TRANSITION_BLOCK_TAILCALL -PATCH_LABEL ExternalMethodFixupPatchLabel - TAILJMP_RAX - -NESTED_END ExternalMethodFixupStub, _TEXT - #ifdef FEATURE_READYTORUN NESTED_ENTRY DelayLoad_MethodCall, _TEXT, NoHandler @@ -38,8 +18,8 @@ NESTED_ENTRY DelayLoad_MethodCall, _TEXT, NoHandler EPILOG_WITH_TRANSITION_BLOCK_TAILCALL - // Share the patch label - jmp C_FUNC(ExternalMethodFixupPatchLabel) +PATCH_LABEL ExternalMethodFixupPatchLabel + TAILJMP_RAX NESTED_END DelayLoad_MethodCall, _TEXT diff --git a/src/coreclr/vm/arm/asmhelpers.S b/src/coreclr/vm/arm/asmhelpers.S index d1695b2054d1d9..bfa1d1d604b9ca 100644 --- a/src/coreclr/vm/arm/asmhelpers.S +++ b/src/coreclr/vm/arm/asmhelpers.S @@ -591,43 +591,6 @@ LOCAL_LABEL(stackProbe_loop): bx lr NESTED_END stackProbe, _TEXT -//------------------------------------------------ -// ExternalMethodFixupStub -// -// In NGEN images, calls to cross-module external methods initially -// point to a jump thunk that calls into the following function that will -// call into a VM helper. The VM helper is responsible for patching up the -// thunk, upon executing the precode, so that all subsequent calls go directly -// to the actual method body. -// -// This is done lazily for performance reasons. -// -// On entry: -// -// R12 = Address of thunk + 4 - - NESTED_ENTRY ExternalMethodFixupStub, _TEXT, NoHandler - - PROLOG_WITH_TRANSITION_BLOCK - - add r0, sp, #__PWTB_TransitionBlock // pTransitionBlock - - // Adjust (read comment above for details) and pass the address of the thunk - sub r1, r12, #4 // pThunk - - mov r2, #0 // sectionIndex - mov r3, #0 // pModule - bl C_FUNC(ExternalMethodFixupWorker) - - // mov the address we patched to in R12 so that we can tail call to it - mov r12, r0 - - EPILOG_WITH_TRANSITION_BLOCK_TAILCALL - PATCH_LABEL ExternalMethodFixupPatchLabel - bx r12 - - NESTED_END ExternalMethodFixupStub, _TEXT - //------------------------------------------------ // JIT_RareDisableHelper // @@ -936,8 +899,9 @@ DelayLoad_MethodCall: EPILOG_WITH_TRANSITION_BLOCK_TAILCALL - // Share the patch label - b C_FUNC(ExternalMethodFixupPatchLabel) + EPILOG_WITH_TRANSITION_BLOCK_TAILCALL + PATCH_LABEL ExternalMethodFixupPatchLabel + bx r12 NESTED_END DelayLoad_MethodCall_FakeProlog, _TEXT diff --git a/src/coreclr/vm/arm/asmhelpers.asm b/src/coreclr/vm/arm/asmhelpers.asm index db7584235e50e5..0afdbf444f2a11 100644 --- a/src/coreclr/vm/arm/asmhelpers.asm +++ b/src/coreclr/vm/arm/asmhelpers.asm @@ -1028,43 +1028,6 @@ stackProbe_loop EPILOG_RETURN NESTED_END -;------------------------------------------------ -; ExternalMethodFixupStub -; -; In NGEN images, calls to cross-module external methods initially -; point to a jump thunk that calls into the following function that will -; call into a VM helper. The VM helper is responsible for patching up the -; thunk, upon executing the precode, so that all subsequent calls go directly -; to the actual method body. -; -; This is done lazily for performance reasons. -; -; On entry: -; -; R12 = Address of thunk + 4 - - NESTED_ENTRY ExternalMethodFixupStub - - PROLOG_WITH_TRANSITION_BLOCK - - add r0, sp, #__PWTB_TransitionBlock ; pTransitionBlock - - ; Adjust (read comment above for details) and pass the address of the thunk - sub r1, r12, #4 ; pThunk - - mov r2, #0 ; sectionIndex - mov r3, #0 ; pModule - bl ExternalMethodFixupWorker - - ; mov the address we patched to in R12 so that we can tail call to it - mov r12, r0 - - EPILOG_WITH_TRANSITION_BLOCK_TAILCALL - PATCH_LABEL ExternalMethodFixupPatchLabel - EPILOG_BRANCH_REG r12 - - NESTED_END - ;------------------------------------------------ ; JIT_RareDisableHelper ; @@ -1676,8 +1639,8 @@ DelayLoad_MethodCall EPILOG_WITH_TRANSITION_BLOCK_TAILCALL - ; Share the patch label - EPILOG_BRANCH ExternalMethodFixupPatchLabel + PATCH_LABEL ExternalMethodFixupPatchLabel + EPILOG_BRANCH_REG r12 NESTED_END diff --git a/src/coreclr/vm/arm64/asmhelpers.S b/src/coreclr/vm/arm64/asmhelpers.S index ac85299cf1ad3c..937d69f41ec39e 100644 --- a/src/coreclr/vm/arm64/asmhelpers.S +++ b/src/coreclr/vm/arm64/asmhelpers.S @@ -500,41 +500,6 @@ LEAF_ENTRY JIT_PatchedCodeLast, _TEXT ret lr LEAF_END JIT_PatchedCodeLast, _TEXT -//------------------------------------------------ -// ExternalMethodFixupStub -// -// In NGEN images, calls to cross-module external methods initially -// point to a jump thunk that calls into the following function that will -// call into a VM helper. The VM helper is responsible for patching up the -// thunk, upon executing the precode, so that all subsequent calls go directly -// to the actual method body. -// -// This is done lazily for performance reasons. -// -// On entry: -// -// x12 = Address of thunk - -NESTED_ENTRY ExternalMethodFixupStub, _TEXT, NoHandler - - PROLOG_WITH_TRANSITION_BLOCK - - add x0, sp, #__PWTB_TransitionBlock // pTransitionBlock - mov x1, x12 // pThunk - mov x2, #0 // sectionIndex - mov x3, #0 // pModule - - bl C_FUNC(ExternalMethodFixupWorker) - - // mov the address we patched to in x12 so that we can tail call to it - mov x12, x0 - - EPILOG_WITH_TRANSITION_BLOCK_TAILCALL - PATCH_LABEL ExternalMethodFixupPatchLabel - EPILOG_BRANCH_REG x12 - -NESTED_END ExternalMethodFixupStub, _TEXT - // void SinglecastDelegateInvokeStub(Delegate *pThis) LEAF_ENTRY SinglecastDelegateInvokeStub, _TEXT cmp x0, #0 @@ -858,8 +823,8 @@ C_FUNC(DelayLoad_MethodCall): mov x12, x0 EPILOG_WITH_TRANSITION_BLOCK_TAILCALL - // Share patch label - b C_FUNC(ExternalMethodFixupPatchLabel) + PATCH_LABEL ExternalMethodFixupPatchLabel + EPILOG_BRANCH_REG x12 NESTED_END DelayLoad_MethodCall_FakeProlog, _TEXT diff --git a/src/coreclr/vm/arm64/asmhelpers.asm b/src/coreclr/vm/arm64/asmhelpers.asm index f383c577c3ae1b..ee3ada08942f87 100644 --- a/src/coreclr/vm/arm64/asmhelpers.asm +++ b/src/coreclr/vm/arm64/asmhelpers.asm @@ -550,41 +550,6 @@ Exit ret lr LEAF_END -;------------------------------------------------ -; ExternalMethodFixupStub -; -; In NGEN images, calls to cross-module external methods initially -; point to a jump thunk that calls into the following function that will -; call into a VM helper. The VM helper is responsible for patching up the -; thunk, upon executing the precode, so that all subsequent calls go directly -; to the actual method body. -; -; This is done lazily for performance reasons. -; -; On entry: -; -; x12 = Address of thunk - - NESTED_ENTRY ExternalMethodFixupStub - - PROLOG_WITH_TRANSITION_BLOCK - - add x0, sp, #__PWTB_TransitionBlock ; pTransitionBlock - mov x1, x12 ; pThunk - mov x2, #0 ; sectionIndex - mov x3, #0 ; pModule - - bl ExternalMethodFixupWorker - - ; mov the address we patched to in x12 so that we can tail call to it - mov x12, x0 - - EPILOG_WITH_TRANSITION_BLOCK_TAILCALL - PATCH_LABEL ExternalMethodFixupPatchLabel - EPILOG_BRANCH_REG x12 - - NESTED_END - ; void SinglecastDelegateInvokeStub(Delegate *pThis) LEAF_ENTRY SinglecastDelegateInvokeStub cmp x0, #0 @@ -1217,8 +1182,9 @@ Fail mov x12, x0 EPILOG_WITH_TRANSITION_BLOCK_TAILCALL - ; Share patch label - b ExternalMethodFixupPatchLabel + PATCH_LABEL ExternalMethodFixupPatchLabel + EPILOG_BRANCH_REG x12 + NESTED_END MACRO diff --git a/src/coreclr/vm/i386/asmhelpers.S b/src/coreclr/vm/i386/asmhelpers.S index 141ac8921ba4d5..ee675c838bc563 100644 --- a/src/coreclr/vm/i386/asmhelpers.S +++ b/src/coreclr/vm/i386/asmhelpers.S @@ -698,8 +698,9 @@ NESTED_ENTRY DelayLoad_MethodCall, _TEXT, NoHandler STUB_EPILOG - // Share the patch label - jmp C_FUNC(ExternalMethodFixupPatchLabel) +PATCH_LABEL ExternalMethodFixupPatchLabel + // Tailcall target + jmp eax // This will never be executed. It is just to help out stack-walking logic // which disassembles the epilog to unwind the stack. diff --git a/src/coreclr/vm/i386/asmhelpers.asm b/src/coreclr/vm/i386/asmhelpers.asm index 6fe70b80d825dc..9258b7848f39f7 100644 --- a/src/coreclr/vm/i386/asmhelpers.asm +++ b/src/coreclr/vm/i386/asmhelpers.asm @@ -1287,8 +1287,11 @@ _DelayLoad_MethodCall@0 proc public STUB_EPILOG - ; Share the patch label - jmp _ExternalMethodFixupPatchLabel@0 +_ExternalMethodFixupPatchLabel@0: +public _ExternalMethodFixupPatchLabel@0 + + ; Tailcall target + jmp eax ; This will never be executed. It is just to help out stack-walking logic ; which disassembles the epilog to unwind the stack. From 53740d2f940b3e74975c199a6654b1fd3000a1d2 Mon Sep 17 00:00:00 2001 From: Jan Kotas Date: Thu, 24 Feb 2022 19:22:38 -0800 Subject: [PATCH 3/3] Update src/coreclr/vm/arm/asmhelpers.S --- src/coreclr/vm/arm/asmhelpers.S | 1 - 1 file changed, 1 deletion(-) diff --git a/src/coreclr/vm/arm/asmhelpers.S b/src/coreclr/vm/arm/asmhelpers.S index bfa1d1d604b9ca..f49ed946bfec7c 100644 --- a/src/coreclr/vm/arm/asmhelpers.S +++ b/src/coreclr/vm/arm/asmhelpers.S @@ -899,7 +899,6 @@ DelayLoad_MethodCall: EPILOG_WITH_TRANSITION_BLOCK_TAILCALL - EPILOG_WITH_TRANSITION_BLOCK_TAILCALL PATCH_LABEL ExternalMethodFixupPatchLabel bx r12