Skip to content

Commit 7d54255

Browse files
committed
Extract out the minimal structure to support referencing information from a R2R image without requiring the PE format
1 parent 2ba7fe7 commit 7d54255

File tree

13 files changed

+110
-32
lines changed

13 files changed

+110
-32
lines changed

src/coreclr/debug/daccess/request.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1232,7 +1232,7 @@ HRESULT ClrDataAccess::GetTieredVersions(
12321232
PTR_Module pModule = (PTR_Module)pMD->GetModule();
12331233
if (pModule->IsReadyToRun())
12341234
{
1235-
PTR_PEImageLayout pImage = pModule->GetReadyToRunInfo()->GetImage();
1235+
PTR_ReadyToRunLoadedImage pImage = pModule->GetReadyToRunInfo()->GetImage();
12361236
r2rImageBase = dac_cast<TADDR>(pImage->GetBase());
12371237
r2rImageEnd = r2rImageBase + pImage->GetVirtualSize();
12381238
}

src/coreclr/vm/ceeload.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2046,7 +2046,7 @@ BOOL Module::IsVisibleToDebugger()
20462046
return TRUE;
20472047
}
20482048

2049-
PEImageLayout * Module::GetReadyToRunImage()
2049+
ReadyToRunLoadedImage * Module::GetReadyToRunImage()
20502050
{
20512051
LIMITED_METHOD_CONTRACT;
20522052

@@ -3566,7 +3566,7 @@ void Module::RunEagerFixupsUnlocked()
35663566
{
35673567
COUNT_T nSections;
35683568
PTR_READYTORUN_IMPORT_SECTION pSections = GetImportSections(&nSections);
3569-
PEImageLayout *pNativeImage = GetReadyToRunImage();
3569+
ReadyToRunLoadedImage *pNativeImage = GetReadyToRunImage();
35703570

35713571
for (COUNT_T iSection = 0; iSection < nSections; iSection++)
35723572
{

src/coreclr/vm/ceeload.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1437,7 +1437,7 @@ class Module : public ModuleBase
14371437
LPCUTF8 GetDebugName() { WRAPPER_NO_CONTRACT; return m_pPEAssembly->GetDebugName(); }
14381438
#endif
14391439

1440-
PEImageLayout * GetReadyToRunImage();
1440+
ReadyToRunLoadedImage * GetReadyToRunImage();
14411441
PTR_READYTORUN_IMPORT_SECTION GetImportSections(COUNT_T *pCount);
14421442
PTR_READYTORUN_IMPORT_SECTION GetImportSectionFromIndex(COUNT_T index);
14431443
PTR_READYTORUN_IMPORT_SECTION GetImportSectionForRVA(RVA rva);
@@ -1482,7 +1482,7 @@ class Module : public ModuleBase
14821482
BOOL FixupDelayListAux(TADDR pFixupList,
14831483
Ptr pThis, FixupNativeEntryCallback pfnCB,
14841484
PTR_READYTORUN_IMPORT_SECTION pImportSections, COUNT_T nImportSections,
1485-
PEDecoder * pNativeImage, BOOL mayUsePrecompiledPInvokeMethods = TRUE);
1485+
ReadyToRunLoadedImage * pNativeImage, BOOL mayUsePrecompiledPInvokeMethods = TRUE);
14861486
void RunEagerFixups();
14871487
void RunEagerFixupsUnlocked();
14881488

src/coreclr/vm/ceeload.inl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -352,7 +352,7 @@ template<typename Ptr, typename FixupNativeEntryCallback>
352352
BOOL Module::FixupDelayListAux(TADDR pFixupList,
353353
Ptr pThis, FixupNativeEntryCallback pfnCB,
354354
PTR_READYTORUN_IMPORT_SECTION pImportSections, COUNT_T nImportSections,
355-
PEDecoder * pNativeImage, BOOL mayUsePrecompiledPInvokeMethods)
355+
ReadyToRunLoadedImage * pNativeImage, BOOL mayUsePrecompiledPInvokeMethods)
356356
{
357357
CONTRACTL
358358
{

src/coreclr/vm/codeman.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6289,7 +6289,7 @@ unsigned ReadyToRunJitManager::InitializeEHEnumeration(const METHODTOKEN& Method
62896289
if (pExceptionInfoDir == NULL)
62906290
return 0;
62916291

6292-
PEImageLayout * pLayout = pReadyToRunInfo->GetImage();
6292+
ReadyToRunLoadedImage * pLayout = pReadyToRunInfo->GetImage();
62936293

62946294
PTR_CORCOMPILE_EXCEPTION_LOOKUP_TABLE pExceptionLookupTable = dac_cast<PTR_CORCOMPILE_EXCEPTION_LOOKUP_TABLE>(pLayout->GetRvaData(pExceptionInfoDir->VirtualAddress));
62956295

src/coreclr/vm/frames.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -840,7 +840,7 @@ static PTR_BYTE FindGCRefMap(PTR_Module pZapModule, TADDR ptr)
840840
{
841841
LIMITED_METHOD_DAC_CONTRACT;
842842

843-
PEImageLayout *pNativeImage = pZapModule->GetReadyToRunImage();
843+
ReadyToRunLoadedImage *pNativeImage = pZapModule->GetReadyToRunImage();
844844

845845
RVA rva = pNativeImage->GetDataRva(ptr);
846846

src/coreclr/vm/nativeimage.cpp

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ NativeImageIndexTraits::count_t NativeImageIndexTraits::Hash(LPCUTF8 a)
4141
return SString(SString::Utf8Literal, a).HashCaseInsensitive();
4242
}
4343

44-
NativeImage::NativeImage(AssemblyBinder *pAssemblyBinder, PEImageLayout *pImageLayout, LPCUTF8 imageFileName)
44+
NativeImage::NativeImage(AssemblyBinder *pAssemblyBinder, ReadyToRunLoadedImage *pImageLayout, LPCUTF8 imageFileName)
4545
: m_eagerFixupsLock(CrstNativeImageEagerFixups)
4646
{
4747
CONTRACTL
@@ -236,7 +236,14 @@ NativeImage *NativeImage::Open(
236236
{
237237
COMPlusThrowHR(COR_E_BADIMAGEFORMAT);
238238
}
239-
NewHolder<NativeImage> image = new NativeImage(pAssemblyBinder, peLoadedImage.Extract(), nativeImageFileName);
239+
240+
NewHolder<ReadyToRunLoadedImage> peLoadedImageHolder = new ReadyToRunLoadedImage(
241+
(TADDR)peLoadedImage->GetBase(),
242+
peLoadedImage->GetSize(),
243+
peLoadedImage.Extract(),
244+
[](void* img) { delete (PEImageLayout*)img; });
245+
246+
NewHolder<NativeImage> image = new NativeImage(pAssemblyBinder, peLoadedImageHolder.Extract(), nativeImageFileName);
240247
AllocMemTracker amTracker;
241248
image->Initialize(pHeader, pLoaderAllocator, &amTracker);
242249
pExistingImage = AppDomain::GetCurrentDomain()->SetNativeImage(nativeImageFileName, image);

src/coreclr/vm/nativeimage.h

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,10 @@ struct AssemblyNameIndex
1212
{
1313
LPCUTF8 Name;
1414
int32_t Index;
15-
15+
1616
AssemblyNameIndex() : Name(NULL), Index(-1) {}
1717
AssemblyNameIndex(LPCUTF8 name, int32_t index) : Name(name), Index(index) {}
18-
18+
1919
static AssemblyNameIndex GetNull() { return AssemblyNameIndex(); }
2020
bool IsNull() const { return Index < 0; }
2121
};
@@ -57,6 +57,7 @@ class NativeImageIndexTraits : public NoRemoveSHashTraits<MapSHashTraits<LPCUTF8
5757
};
5858

5959
class ReadyToRunInfo;
60+
class ReadyToRunLoadedImage;
6061
class PEAssembly;
6162
class PEImage;
6263

@@ -83,21 +84,21 @@ class NativeImage
8384
AssemblyBinder *m_pAssemblyBinder;
8485
ReadyToRunInfo *m_pReadyToRunInfo;
8586
IMDInternalImport *m_pManifestMetadata;
86-
PEImageLayout *m_pImageLayout;
87+
ReadyToRunLoadedImage *m_pImageLayout;
8788
PTR_Assembly *m_pNativeMetadataAssemblyRefMap;
8889
PTR_ModuleBase m_pNativeManifestModule;
89-
90+
9091
IMAGE_DATA_DIRECTORY *m_pComponentAssemblies;
9192
uint32_t m_componentAssemblyCount;
9293
uint32_t m_manifestAssemblyCount;
9394
SHash<AssemblyNameIndexHashTraits> m_assemblySimpleNameToIndexMap;
94-
95+
9596
Crst m_eagerFixupsLock;
9697
bool m_eagerFixupsHaveRun;
9798
bool m_readyToRunCodeDisabled;
9899

99100
private:
100-
NativeImage(AssemblyBinder *pAssemblyBinder, PEImageLayout *peImageLayout, LPCUTF8 imageFileName);
101+
NativeImage(AssemblyBinder *pAssemblyBinder, ReadyToRunLoadedImage *peImageLayout, LPCUTF8 imageFileName);
101102

102103
protected:
103104
void Initialize(READYTORUN_HEADER *header, LoaderAllocator *loaderAllocator, AllocMemTracker *pamTracker);
@@ -125,7 +126,7 @@ class NativeImage
125126
AssemblyBinder *GetAssemblyBinder() const { return m_pAssemblyBinder; }
126127

127128
Assembly *LoadManifestAssembly(uint32_t rowid, Assembly *pParentAssembly);
128-
129+
129130
PTR_READYTORUN_CORE_HEADER GetComponentAssemblyHeader(LPCUTF8 assemblySimpleName);
130131

131132
void CheckAssemblyMvid(Assembly *assembly) const;

src/coreclr/vm/pgo.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1002,13 +1002,13 @@ class R2RInstrumentationDataReader
10021002
{
10031003
ReadyToRunInfo *m_pReadyToRunInfo;
10041004
Module* m_pModule;
1005-
PEDecoder* m_pNativeImage;
1005+
ReadyToRunLoadedImage* m_pNativeImage;
10061006

10071007
public:
10081008
StackSArray<ICorJitInfo::PgoInstrumentationSchema> schemaArray;
10091009
StackSArray<BYTE> instrumentationData;
10101010

1011-
R2RInstrumentationDataReader(ReadyToRunInfo *pReadyToRunInfo, Module* pModule, PEDecoder* pNativeImage) :
1011+
R2RInstrumentationDataReader(ReadyToRunInfo *pReadyToRunInfo, Module* pModule, ReadyToRunLoadedImage* pNativeImage) :
10121012
m_pReadyToRunInfo(pReadyToRunInfo),
10131013
m_pModule(pModule),
10141014
m_pNativeImage(pNativeImage)
@@ -1103,7 +1103,7 @@ class R2RInstrumentationDataReader
11031103

11041104
HRESULT PgoManager::getPgoInstrumentationResultsFromR2RFormat(ReadyToRunInfo *pReadyToRunInfo,
11051105
Module* pModule,
1106-
PEDecoder* pNativeImage,
1106+
ReadyToRunLoadedImage* pNativeImage,
11071107
BYTE* pR2RFormatData,
11081108
size_t pR2RFormatDataMaxSize,
11091109
BYTE** pAllocatedData,

src/coreclr/vm/pgo.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
#include "shash.h"
88

99
class ReadyToRunInfo;
10+
class ReadyToRunLoadedImage;
1011

1112
// PgoManager handles in-process and out of band profile data for jitted code.
1213
class PgoManager
@@ -26,7 +27,7 @@ class PgoManager
2627
static HRESULT allocPgoInstrumentationBySchema(MethodDesc* pMD, ICorJitInfo::PgoInstrumentationSchema* pSchema, UINT32 countSchemaItems, BYTE** pInstrumentationData);
2728
static HRESULT getPgoInstrumentationResultsFromR2RFormat(ReadyToRunInfo *pReadyToRunInfo,
2829
Module* pModule,
29-
PEDecoder* pNativeImage,
30+
ReadyToRunLoadedImage* pNativeImage,
3031
BYTE* pR2RFormatData,
3132
size_t pR2RFormatDataMaxSize,
3233
BYTE** pAllocatedData,

0 commit comments

Comments
 (0)