Skip to content

Commit

Permalink
Disable R2R code for all associated components of a composite image -…
Browse files Browse the repository at this point in the history
… When loading a composite image, capture the detail that the composite image code cannot be used into the NativeImage structure, and flow that data into all associated ReadyToRunInfo structures. (dotnet#65536)

Fixes dotnet#61471

Co-authored-by: David Wrighton <davidwr@microsoft.com>
  • Loading branch information
github-actions[bot] and davidwrighton authored Mar 8, 2022
1 parent 5b5ffb0 commit 4276a71
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 9 deletions.
8 changes: 4 additions & 4 deletions src/coreclr/vm/ceeload.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9965,16 +9965,16 @@ void Module::RunEagerFixups()
{
// For composite images, multiple modules may request initializing eager fixups
// from multiple threads so we need to lock their resolution.
if (compositeNativeImage->EagerFixupsHaveRun())
{
return;
}
CrstHolder compositeEagerFixups(compositeNativeImage->EagerFixupsLock());
if (compositeNativeImage->EagerFixupsHaveRun())
{
if (compositeNativeImage->ReadyToRunCodeDisabled())
GetReadyToRunInfo()->DisableAllR2RCode();
return;
}
RunEagerFixupsUnlocked();
if (GetReadyToRunInfo()->ReadyToRunCodeDisabled())
compositeNativeImage->DisableAllR2RCode();
compositeNativeImage->SetEagerFixupsHaveRun();
}
else
Expand Down
1 change: 1 addition & 0 deletions src/coreclr/vm/nativeimage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ NativeImage::NativeImage(AssemblyLoadContext *pAssemblyLoadContext, PEImageLayou
m_pImageLayout = pImageLayout;
m_fileName = imageFileName;
m_eagerFixupsHaveRun = false;
m_readyToRunCodeDisabled = false;
}

void NativeImage::Initialize(READYTORUN_HEADER *pHeader, LoaderAllocator *pLoaderAllocator, AllocMemTracker *pamTracker)
Expand Down
13 changes: 13 additions & 0 deletions src/coreclr/vm/nativeimage.h
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ class NativeImage

Crst m_eagerFixupsLock;
bool m_eagerFixupsHaveRun;
bool m_readyToRunCodeDisabled;

private:
NativeImage(AssemblyLoadContext *pAssemblyLoadContext, PEImageLayout *peImageLayout, LPCUTF8 imageFileName);
Expand Down Expand Up @@ -126,6 +127,18 @@ class NativeImage

void CheckAssemblyMvid(Assembly *assembly) const;

void DisableAllR2RCode()
{
LIMITED_METHOD_CONTRACT;
m_readyToRunCodeDisabled = true;
}

bool ReadyToRunCodeDisabled()
{
LIMITED_METHOD_CONTRACT;
return m_readyToRunCodeDisabled;
}

private:
IMDInternalImport *LoadManifestMetadata();
};
Expand Down
6 changes: 3 additions & 3 deletions src/coreclr/vm/readytoruninfo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -837,7 +837,7 @@ bool ReadyToRunInfo::GetPgoInstrumentationData(MethodDesc * pMD, BYTE** pAllocat
return false;

// If R2R code is disabled for this module, simply behave as if it is never found
if (m_readyToRunCodeDisabled)
if (ReadyToRunCodeDisabled())
return false;

if (m_pgoInstrumentationDataHashtable.IsNull())
Expand Down Expand Up @@ -907,7 +907,7 @@ PCODE ReadyToRunInfo::GetEntryPoint(MethodDesc * pMD, PrepareCodeConfig* pConfig
goto done;

// If R2R code is disabled for this module, simply behave as if it is never found
if (m_readyToRunCodeDisabled)
if (ReadyToRunCodeDisabled())
goto done;

ETW::MethodLog::GetR2RGetEntryPointStart(pMD);
Expand Down Expand Up @@ -1106,7 +1106,7 @@ BOOL ReadyToRunInfo::MethodIterator::Next()
}
CONTRACTL_END;

if (m_pInfo->m_readyToRunCodeDisabled)
if (m_pInfo->ReadyToRunCodeDisabled())
return FALSE;

// Enumerate non-generic methods
Expand Down
10 changes: 8 additions & 2 deletions src/coreclr/vm/readytoruninfo.h
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ class ReadyToRunInfo
PTR_CORCOMPILE_IMPORT_SECTION m_pImportSections;
DWORD m_nImportSections;

bool m_readyToRunCodeDisabled;
bool m_readyToRunCodeDisabled; // Is

NativeFormat::NativeReader m_nativeReader;
NativeFormat::NativeArray m_methodDefEntryPoints;
Expand Down Expand Up @@ -125,7 +125,13 @@ class ReadyToRunInfo
void DisableAllR2RCode()
{
LIMITED_METHOD_CONTRACT;
m_readyToRunCodeDisabled = TRUE;
m_readyToRunCodeDisabled = true;
}

bool ReadyToRunCodeDisabled()
{
LIMITED_METHOD_CONTRACT;
return m_readyToRunCodeDisabled;
}

BOOL HasNonShareablePInvokeStubs()
Expand Down

0 comments on commit 4276a71

Please sign in to comment.