Skip to content

Commit

Permalink
Remove support for non-indirect code headers (#100351)
Browse files Browse the repository at this point in the history
- We use indirect code headers on all platforms (except for Windows X86, which has no particular reason to not use them)
  - Indirect code headers are required to support funclet style codegen, but work just fine in all cases.
- This removes one of the ways in which Windows X86 is different from all other platforms
  • Loading branch information
davidwrighton authored Mar 28, 2024
1 parent ccc2d3b commit d7c4f02
Show file tree
Hide file tree
Showing 12 changed files with 4 additions and 145 deletions.
5 changes: 0 additions & 5 deletions src/coreclr/debug/daccess/fntableaccess.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,8 @@
#ifndef TARGET_UNIX
#define DEBUGSUPPORT_STUBS_HAVE_UNWIND_INFO
#endif // !TARGET_UNIX

#ifndef USE_INDIRECT_CODEHEADER
#define USE_INDIRECT_CODEHEADER
#endif // USE_INDIRECT_CODEHEADER
#endif


struct FakeEEJitManager
{
LPVOID __VFN_table;
Expand Down
1 change: 0 additions & 1 deletion src/coreclr/inc/nibblemapmacros.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@

#if defined(HOST_64BIT)
// TODO: bump up the windows CODE_ALIGN to 16 and iron out any nibble map bugs that exist.
// TODO: there is something wrong with USE_INDIRECT_CODEHEADER with CODE_ALIGN=16
# define CODE_ALIGN 4
# define LOG2_CODE_ALIGN 2
#else
Expand Down
3 changes: 0 additions & 3 deletions src/coreclr/vm/amd64/cgencpu.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,6 @@ EXTERN_C void FastCallFinalizeWorker(Object *obj, PCODE funcPtr);
#define SIZEOF_LOAD_AND_JUMP_THUNK 22 // # bytes to mov r10, X; jmp Z
#define SIZEOF_LOAD2_AND_JUMP_THUNK 32 // # bytes to mov r10, X; mov r11, Y; jmp Z

// Also in CorCompile.h, FnTableAccess.h
#define USE_INDIRECT_CODEHEADER // use CodeHeader, RealCodeHeader construct

#define HAS_NDIRECT_IMPORT_PRECODE 1
#define HAS_FIXUP_PRECODE 1

Expand Down
3 changes: 0 additions & 3 deletions src/coreclr/vm/arm/cgencpu.h
Original file line number Diff line number Diff line change
Expand Up @@ -75,9 +75,6 @@ EXTERN_C void checkStack(void);

#define HAS_NDIRECT_IMPORT_PRECODE 1

#define USE_INDIRECT_CODEHEADER


EXTERN_C void getFPReturn(int fpSize, INT64 *pRetVal);
EXTERN_C void setFPReturn(int fpSize, INT64 retVal);

Expand Down
2 changes: 0 additions & 2 deletions src/coreclr/vm/arm64/cgencpu.h
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,6 @@ extern PCODE GetPreStubEntryPoint();

#define HAS_NDIRECT_IMPORT_PRECODE 1

#define USE_INDIRECT_CODEHEADER

#define HAS_FIXUP_PRECODE 1

// ThisPtrRetBufPrecode one is necessary for closed delegates over static methods with return buffer
Expand Down
14 changes: 4 additions & 10 deletions src/coreclr/vm/codeman.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2812,9 +2812,7 @@ void* EEJitManager::allocCodeRaw(CodeHeapRequestInfo *pInfo,

void EEJitManager::allocCode(MethodDesc* pMD, size_t blockSize, size_t reserveForJumpStubs, CorJitAllocMemFlag flag, CodeHeader** ppCodeHeader, CodeHeader** ppCodeHeaderRW,
size_t* pAllocatedSize, HeapList** ppCodeHeap
#ifdef USE_INDIRECT_CODEHEADER
, BYTE** ppRealHeader
#endif
#ifdef FEATURE_EH_FUNCLETS
, UINT nUnwindInfos
#endif
Expand Down Expand Up @@ -2867,8 +2865,11 @@ void EEJitManager::allocCode(MethodDesc* pMD, size_t blockSize, size_t reserveFo
#endif
requestInfo.setReserveForJumpStubs(reserveForJumpStubs);

#if defined(USE_INDIRECT_CODEHEADER)
#ifdef FEATURE_EH_FUNCLETS
SIZE_T realHeaderSize = offsetof(RealCodeHeader, unwindInfos[0]) + (sizeof(T_RUNTIME_FUNCTION) * nUnwindInfos);
#else
SIZE_T realHeaderSize = sizeof(RealCodeHeader);
#endif

// if this is a LCG method then we will be allocating the RealCodeHeader
// following the code so that the code block can be removed easily by
Expand All @@ -2878,7 +2879,6 @@ void EEJitManager::allocCode(MethodDesc* pMD, size_t blockSize, size_t reserveFo
totalSize = ALIGN_UP(totalSize, sizeof(void*)) + realHeaderSize;
static_assert_no_msg(CODE_SIZE_ALIGN >= sizeof(void*));
}
#endif // USE_INDIRECT_CODEHEADER

// Scope the lock
{
Expand Down Expand Up @@ -2908,7 +2908,6 @@ void EEJitManager::allocCode(MethodDesc* pMD, size_t blockSize, size_t reserveFo
pCodeHdrRW = pCodeHdr;
}

#ifdef USE_INDIRECT_CODEHEADER
if (requestInfo.IsDynamicDomain())
{
// Set the real code header to the writeable mapping so that we can set its members via the CodeHeader methods below
Expand All @@ -2922,7 +2921,6 @@ void EEJitManager::allocCode(MethodDesc* pMD, size_t blockSize, size_t reserveFo
BYTE* pRealHeader = (BYTE*)(void*)pMD->GetLoaderAllocator()->GetLowFrequencyHeap()->AllocMem(S_SIZE_T(realHeaderSize));
pCodeHdrRW->SetRealCodeHeader(pRealHeader);
}
#endif

pCodeHdrRW->SetDebugInfo(NULL);
pCodeHdrRW->SetEHInfo(NULL);
Expand All @@ -2932,7 +2930,6 @@ void EEJitManager::allocCode(MethodDesc* pMD, size_t blockSize, size_t reserveFo
pCodeHdrRW->SetNumberOfUnwindInfos(nUnwindInfos);
#endif

#ifdef USE_INDIRECT_CODEHEADER
if (requestInfo.IsDynamicDomain())
{
*ppRealHeader = (BYTE*)pCode + ALIGN_UP(blockSize, sizeof(void*));
Expand All @@ -2941,7 +2938,6 @@ void EEJitManager::allocCode(MethodDesc* pMD, size_t blockSize, size_t reserveFo
{
*ppRealHeader = NULL;
}
#endif // USE_INDIRECT_CODEHEADER
}

*ppCodeHeader = pCodeHdr;
Expand Down Expand Up @@ -3878,9 +3874,7 @@ void CodeHeader::EnumMemoryRegions(CLRDataEnumMemoryFlags flags, IJitManager* pJ

DAC_ENUM_DTHIS();

#ifdef USE_INDIRECT_CODEHEADER
this->pRealCodeHeader.EnumMem();
#endif // USE_INDIRECT_CODEHEADER

#ifdef FEATURE_ON_STACK_REPLACEMENT
BOOL hasFlagByte = TRUE;
Expand Down
103 changes: 0 additions & 103 deletions src/coreclr/vm/codeman.h
Original file line number Diff line number Diff line change
Expand Up @@ -69,10 +69,6 @@ Module Name:
#include "gcinfo.h"
#include "eexcp.h"

#if defined(FEATURE_EH_FUNCLETS) && !defined(USE_INDIRECT_CODEHEADER)
#error "FEATURE_EH_FUNCLETS requires USE_INDIRECT_CODEHEADER"
#endif // FEATURE_EH_FUNCLETS && !USE_INDIRECT_CODEHEADER

class MethodDesc;
class ICorJitCompiler;
class IJitManager;
Expand Down Expand Up @@ -125,20 +121,10 @@ enum StubCodeBlockKind : int
// Today CodeHeader is used by the EEJitManager.
// The GCInfo version is always current GCINFO_VERSION in this header.

#ifdef USE_INDIRECT_CODEHEADER
typedef DPTR(struct _hpRealCodeHdr) PTR_RealCodeHeader;
typedef DPTR(struct _hpCodeHdr) PTR_CodeHeader;

#else // USE_INDIRECT_CODEHEADER
typedef DPTR(struct _hpCodeHdr) PTR_CodeHeader;

#endif // USE_INDIRECT_CODEHEADER

#ifdef USE_INDIRECT_CODEHEADER
typedef struct _hpRealCodeHdr
#else // USE_INDIRECT_CODEHEADER
typedef struct _hpCodeHdr
#endif // USE_INDIRECT_CODEHEADER
{
public:
PTR_BYTE phdrDebugInfo;
Expand All @@ -160,95 +146,9 @@ typedef struct _hpCodeHdr
#endif // FEATURE_EH_FUNCLETS

public:
#ifndef USE_INDIRECT_CODEHEADER
//
// Note: that the JITted code follows immediately after the MethodDesc*
//
PTR_BYTE GetDebugInfo()
{
SUPPORTS_DAC;

return phdrDebugInfo;
}
PTR_EE_ILEXCEPTION GetEHInfo()
{
return phdrJitEHInfo;
}
PTR_BYTE GetGCInfo()
{
SUPPORTS_DAC;
return phdrJitGCInfo;
}
PTR_MethodDesc GetMethodDesc()
{
SUPPORTS_DAC;
return phdrMDesc;
}
#if defined(FEATURE_GDBJIT)
VOID* GetCalledMethods()
{
SUPPORTS_DAC;
return pCalledMethods;
}
#endif
TADDR GetCodeStartAddress()
{
SUPPORTS_DAC;
return dac_cast<TADDR>(dac_cast<PTR_CodeHeader>(this) + 1);
}
StubCodeBlockKind GetStubCodeBlockKind()
{
SUPPORTS_DAC;
return (StubCodeBlockKind)dac_cast<TADDR>(phdrMDesc);
}
BOOL IsStubCodeBlock()
{
SUPPORTS_DAC;
// Note that it is important for this comparison to be unsigned
return dac_cast<TADDR>(phdrMDesc) <= (TADDR)STUB_CODE_BLOCK_LAST;
}

void SetDebugInfo(PTR_BYTE pDI)
{
phdrDebugInfo = pDI;
}
void SetEHInfo(PTR_EE_ILEXCEPTION pEH)
{
phdrJitEHInfo = pEH;
}
void SetGCInfo(PTR_BYTE pGC)
{
phdrJitGCInfo = pGC;
}
void SetMethodDesc(PTR_MethodDesc pMD)
{
phdrMDesc = pMD;
}
#if defined(FEATURE_GDBJIT)
void SetCalledMethods(VOID* pCM)
{
pCalledMethods = pCM;
}
#endif
void SetStubCodeBlockKind(StubCodeBlockKind kind)
{
phdrMDesc = (PTR_MethodDesc)kind;
}
#endif // !USE_INDIRECT_CODEHEADER

// if we're using the indirect codeheaders then all enumeration is done by the code header
#ifndef USE_INDIRECT_CODEHEADER
#ifdef DACCESS_COMPILE
void EnumMemoryRegions(CLRDataEnumMemoryFlags flags, IJitManager* pJitMan);
#endif // DACCESS_COMPILE
#endif // USE_INDIRECT_CODEHEADER
#ifdef USE_INDIRECT_CODEHEADER
} RealCodeHeader;
#else // USE_INDIRECT_CODEHEADER
} CodeHeader;
#endif // USE_INDIRECT_CODEHEADER

#ifdef USE_INDIRECT_CODEHEADER
typedef struct _hpCodeHdr
{
PTR_RealCodeHeader pRealCodeHeader;
Expand Down Expand Up @@ -355,7 +255,6 @@ typedef struct _hpCodeHdr
#endif // DACCESS_COMPILE

} CodeHeader;
#endif // USE_INDIRECT_CODEHEADER


//-----------------------------------------------------------------------------
Expand Down Expand Up @@ -1871,9 +1770,7 @@ class EEJitManager : public IJitManager

void allocCode(MethodDesc* pFD, size_t blockSize, size_t reserveForJumpStubs, CorJitAllocMemFlag flag, CodeHeader** ppCodeHeader, CodeHeader** ppCodeHeaderRW,
size_t* pAllocatedSize, HeapList** ppCodeHeap
#ifdef USE_INDIRECT_CODEHEADER
, BYTE** ppRealHeader
#endif
#ifdef FEATURE_EH_FUNCLETS
, UINT nUnwindInfos
#endif
Expand Down
4 changes: 0 additions & 4 deletions src/coreclr/vm/i386/cgencpu.h
Original file line number Diff line number Diff line change
Expand Up @@ -51,10 +51,6 @@ EXTERN_C void SinglecastDelegateInvokeStub();
#define JUMP_ALLOCATE_SIZE 8 // # bytes to allocate for a jump instruction
#define BACK_TO_BACK_JUMP_ALLOCATE_SIZE 8 // # bytes to allocate for a back to back jump instruction

#ifdef FEATURE_EH_FUNCLETS
#define USE_INDIRECT_CODEHEADER
#endif // FEATURE_EH_FUNCLETS

#define HAS_COMPACT_ENTRYPOINTS 1

// Needed for PInvoke inlining in ngened images
Expand Down
4 changes: 0 additions & 4 deletions src/coreclr/vm/jitinterface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10855,14 +10855,12 @@ void CEEJitInfo::WriteCodeBytes()
{
LIMITED_METHOD_CONTRACT;

#ifdef USE_INDIRECT_CODEHEADER
if (m_pRealCodeHeader != NULL)
{
// Restore the read only version of the real code header
m_CodeHeaderRW->SetRealCodeHeader(m_pRealCodeHeader);
m_pRealCodeHeader = NULL;
}
#endif // USE_INDIRECT_CODEHEADER

if (m_CodeHeaderRW != m_CodeHeader)
{
Expand Down Expand Up @@ -12247,9 +12245,7 @@ void CEEJitInfo::allocMem (AllocMemArgs *pArgs)
}

m_jitManager->allocCode(m_pMethodBeingCompiled, totalSize.Value(), GetReserveForJumpStubs(), pArgs->flag, &m_CodeHeader, &m_CodeHeaderRW, &m_codeWriteBufferSize, &m_pCodeHeap
#ifdef USE_INDIRECT_CODEHEADER
, &m_pRealCodeHeader
#endif
#ifdef FEATURE_EH_FUNCLETS
, m_totalUnwindInfos
#endif
Expand Down
6 changes: 0 additions & 6 deletions src/coreclr/vm/jitinterface.h
Original file line number Diff line number Diff line change
Expand Up @@ -688,9 +688,7 @@ class CEEJitInfo : public CEEInfo
m_CodeHeaderRW = NULL;

m_codeWriteBufferSize = 0;
#ifdef USE_INDIRECT_CODEHEADER
m_pRealCodeHeader = NULL;
#endif
m_pCodeHeap = NULL;

if (m_pOffsetMapping != NULL)
Expand Down Expand Up @@ -801,9 +799,7 @@ class CEEJitInfo : public CEEInfo
m_CodeHeader(NULL),
m_CodeHeaderRW(NULL),
m_codeWriteBufferSize(0),
#ifdef USE_INDIRECT_CODEHEADER
m_pRealCodeHeader(NULL),
#endif
m_pCodeHeap(NULL),
m_ILHeader(header),
#ifdef FEATURE_EH_FUNCLETS
Expand Down Expand Up @@ -951,9 +947,7 @@ protected :
CodeHeader* m_CodeHeader; // descriptor for JITTED code - read/execute address
CodeHeader* m_CodeHeaderRW; // descriptor for JITTED code - code write scratch buffer address
size_t m_codeWriteBufferSize;
#ifdef USE_INDIRECT_CODEHEADER
BYTE* m_pRealCodeHeader;
#endif
HeapList* m_pCodeHeap;
COR_ILMETHOD_DECODER * m_ILHeader; // the code header as exist in the file
#ifdef FEATURE_EH_FUNCLETS
Expand Down
2 changes: 0 additions & 2 deletions src/coreclr/vm/loongarch64/cgencpu.h
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,6 @@ extern PCODE GetPreStubEntryPoint();

#define HAS_NDIRECT_IMPORT_PRECODE 1

#define USE_INDIRECT_CODEHEADER

#define HAS_FIXUP_PRECODE 1
#define HAS_FIXUP_PRECODE_CHUNKS 1

Expand Down
2 changes: 0 additions & 2 deletions src/coreclr/vm/riscv64/cgencpu.h
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,6 @@ extern PCODE GetPreStubEntryPoint();

#define HAS_NDIRECT_IMPORT_PRECODE 1

#define USE_INDIRECT_CODEHEADER

#define HAS_FIXUP_PRECODE 1

// ThisPtrRetBufPrecode one is necessary for closed delegates over static methods with return buffer
Expand Down

0 comments on commit d7c4f02

Please sign in to comment.