From 4276a7148399cb37a1bcc588401a942b250490d8 Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" <41898282+github-actions[bot]@users.noreply.github.com> Date: Tue, 8 Mar 2022 13:11:34 -0800 Subject: [PATCH] Disable R2R code for all associated components of a composite image - 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. (#65536) Fixes #61471 Co-authored-by: David Wrighton --- src/coreclr/vm/ceeload.cpp | 8 ++++---- src/coreclr/vm/nativeimage.cpp | 1 + src/coreclr/vm/nativeimage.h | 13 +++++++++++++ src/coreclr/vm/readytoruninfo.cpp | 6 +++--- src/coreclr/vm/readytoruninfo.h | 10 ++++++++-- 5 files changed, 29 insertions(+), 9 deletions(-) diff --git a/src/coreclr/vm/ceeload.cpp b/src/coreclr/vm/ceeload.cpp index b8e7ab0b4d81d..0f4904d29bf10 100644 --- a/src/coreclr/vm/ceeload.cpp +++ b/src/coreclr/vm/ceeload.cpp @@ -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 diff --git a/src/coreclr/vm/nativeimage.cpp b/src/coreclr/vm/nativeimage.cpp index 8338dbc60960b..60105f5cdb6e6 100644 --- a/src/coreclr/vm/nativeimage.cpp +++ b/src/coreclr/vm/nativeimage.cpp @@ -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) diff --git a/src/coreclr/vm/nativeimage.h b/src/coreclr/vm/nativeimage.h index 447e600297ae3..6c50dba998abf 100644 --- a/src/coreclr/vm/nativeimage.h +++ b/src/coreclr/vm/nativeimage.h @@ -91,6 +91,7 @@ class NativeImage Crst m_eagerFixupsLock; bool m_eagerFixupsHaveRun; + bool m_readyToRunCodeDisabled; private: NativeImage(AssemblyLoadContext *pAssemblyLoadContext, PEImageLayout *peImageLayout, LPCUTF8 imageFileName); @@ -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(); }; diff --git a/src/coreclr/vm/readytoruninfo.cpp b/src/coreclr/vm/readytoruninfo.cpp index 0253d59e09c22..34ab854c8d273 100644 --- a/src/coreclr/vm/readytoruninfo.cpp +++ b/src/coreclr/vm/readytoruninfo.cpp @@ -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()) @@ -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); @@ -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 diff --git a/src/coreclr/vm/readytoruninfo.h b/src/coreclr/vm/readytoruninfo.h index acc909ab5dda3..89b7ab4a47573 100644 --- a/src/coreclr/vm/readytoruninfo.h +++ b/src/coreclr/vm/readytoruninfo.h @@ -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; @@ -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()