Skip to content

Commit

Permalink
Cleanup fragile NGen leftovers (dotnet#65869)
Browse files Browse the repository at this point in the history
  • Loading branch information
jkotas committed Feb 25, 2022
1 parent c32b1f5 commit 30f30a3
Show file tree
Hide file tree
Showing 15 changed files with 31 additions and 462 deletions.
50 changes: 0 additions & 50 deletions src/coreclr/inc/corcompile.h
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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
Expand Down
11 changes: 0 additions & 11 deletions src/coreclr/inc/corinfo.h
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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.

Expand Down
10 changes: 5 additions & 5 deletions src/coreclr/inc/jiteeversionguid.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 }
};

//////////////////////////////////////////////////////////////////////////////////////////////////////////
Expand Down
20 changes: 0 additions & 20 deletions src/coreclr/inc/jithelpers.h
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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)
Expand Down
11 changes: 0 additions & 11 deletions src/coreclr/tools/Common/JitInterface/CorInfoHelpFunc.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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.

Expand Down
25 changes: 2 additions & 23 deletions src/coreclr/vm/amd64/ExternalMethodFixupThunk.asm
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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

Expand Down
24 changes: 2 additions & 22 deletions src/coreclr/vm/amd64/externalmethodfixupthunk.S
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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

Expand Down
41 changes: 2 additions & 39 deletions src/coreclr/vm/arm/asmhelpers.S
Original file line number Diff line number Diff line change
Expand Up @@ -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
//
Expand Down Expand Up @@ -936,8 +899,8 @@ DelayLoad_MethodCall:

EPILOG_WITH_TRANSITION_BLOCK_TAILCALL

// Share the patch label
b C_FUNC(ExternalMethodFixupPatchLabel)
PATCH_LABEL ExternalMethodFixupPatchLabel
bx r12

NESTED_END DelayLoad_MethodCall_FakeProlog, _TEXT

Expand Down
41 changes: 2 additions & 39 deletions src/coreclr/vm/arm/asmhelpers.asm
Original file line number Diff line number Diff line change
Expand Up @@ -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
;
Expand Down Expand Up @@ -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

Expand Down
Loading

0 comments on commit 30f30a3

Please sign in to comment.