From 614cac4270ae171e42d38606b189ac4de80d368d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tom=C3=A1=C5=A1=20Rylek?= Date: Wed, 8 Apr 2020 14:59:53 +0200 Subject: [PATCH] CoreCLR runtime fixes for composite R2R build with shared framework (#34432) In jithelpers, switch the query over to use a ReadyToRunInfo method to make it work in composite mode. Also fix two places in ReadyToRunInfo that were erroneously referring to composite info (inlining tables). Thanks Tomas --- .../DependencyAnalysis/ReadyToRunCodegenNodeFactory.cs | 2 +- src/coreclr/src/tools/r2rdump/TextDumper.cs | 2 +- src/coreclr/src/vm/jithelpers.cpp | 2 +- src/coreclr/src/vm/readytoruninfo.cpp | 9 +++++++-- src/coreclr/src/vm/readytoruninfo.h | 2 ++ 5 files changed, 12 insertions(+), 5 deletions(-) diff --git a/src/coreclr/src/tools/crossgen2/ILCompiler.ReadyToRun/Compiler/DependencyAnalysis/ReadyToRunCodegenNodeFactory.cs b/src/coreclr/src/tools/crossgen2/ILCompiler.ReadyToRun/Compiler/DependencyAnalysis/ReadyToRunCodegenNodeFactory.cs index 4e2f2343d9e5a..e9c977f108680 100644 --- a/src/coreclr/src/tools/crossgen2/ILCompiler.ReadyToRun/Compiler/DependencyAnalysis/ReadyToRunCodegenNodeFactory.cs +++ b/src/coreclr/src/tools/crossgen2/ILCompiler.ReadyToRun/Compiler/DependencyAnalysis/ReadyToRunCodegenNodeFactory.cs @@ -535,7 +535,7 @@ public void AttachToDependencyGraph(DependencyAnalyzerBase graph) AssemblyTableNode assemblyTable = null; - if (CompilationModuleGroup.CompilationModuleSet.Skip(1).Any()) + if (CompilationModuleGroup.IsCompositeBuildMode) { assemblyTable = new AssemblyTableNode(Target); Header.Add(Internal.Runtime.ReadyToRunSectionType.ComponentAssemblies, assemblyTable, assemblyTable); diff --git a/src/coreclr/src/tools/r2rdump/TextDumper.cs b/src/coreclr/src/tools/r2rdump/TextDumper.cs index 9b0d8416610e0..9b67bad70af76 100644 --- a/src/coreclr/src/tools/r2rdump/TextDumper.cs +++ b/src/coreclr/src/tools/r2rdump/TextDumper.cs @@ -413,7 +413,7 @@ internal override void DumpSectionContents(ReadyToRunSection section) MetadataReader globalReader = _r2r.GetGlobalMetadataReader(); assemblyRefCount = globalReader.GetTableRowCount(TableIndex.AssemblyRef) + 1; _writer.WriteLine($"MSIL AssemblyRef's ({assemblyRefCount} entries):"); - for (int assemblyRefIndex = 1; assemblyRefIndex <= assemblyRefCount; assemblyRefIndex++) + for (int assemblyRefIndex = 1; assemblyRefIndex < assemblyRefCount; assemblyRefIndex++) { AssemblyReference assemblyRef = globalReader.GetAssemblyReference(MetadataTokens.AssemblyReferenceHandle(assemblyRefIndex)); string assemblyRefName = globalReader.GetString(assemblyRef.Name); diff --git a/src/coreclr/src/vm/jithelpers.cpp b/src/coreclr/src/vm/jithelpers.cpp index 658e4e6cdd07e..7cc3cb24e4fdc 100644 --- a/src/coreclr/src/vm/jithelpers.cpp +++ b/src/coreclr/src/vm/jithelpers.cpp @@ -3231,7 +3231,7 @@ CORINFO_GENERIC_HANDLE JIT_GenericHandleWorker(MethodDesc * pMD, MethodTable * p #ifdef _DEBUG // Only in R2R mode are the module, dictionary index and dictionary slot provided as an input _ASSERTE(dictionaryIndexAndSlot != (DWORD)-1); - _ASSERT(ExecutionManager::FindReadyToRunModule(dac_cast(signature)) == pModule); + _ASSERT(ReadyToRunInfo::IsNativeImageSharedBy(pModule, ExecutionManager::FindReadyToRunModule(dac_cast(signature)))); #endif dictionaryIndex = (dictionaryIndexAndSlot >> 16); } diff --git a/src/coreclr/src/vm/readytoruninfo.cpp b/src/coreclr/src/vm/readytoruninfo.cpp index a47541991df1e..f4cb41e96351d 100644 --- a/src/coreclr/src/vm/readytoruninfo.cpp +++ b/src/coreclr/src/vm/readytoruninfo.cpp @@ -618,6 +618,11 @@ PTR_ReadyToRunInfo ReadyToRunInfo::Initialize(Module * pModule, AllocMemTracker return new (pMemory) ReadyToRunInfo(pModule, pLayout, pHeader, nativeImage, pamTracker); } +bool ReadyToRunInfo::IsNativeImageSharedBy(PTR_Module pModule1, PTR_Module pModule2) +{ + return pModule1->GetReadyToRunInfo()->m_pComposite == pModule2->GetReadyToRunInfo()->m_pComposite; +} + ReadyToRunInfo::ReadyToRunInfo(Module * pModule, PEImageLayout * pLayout, READYTORUN_HEADER * pHeader, NativeImage *pNativeImage, AllocMemTracker *pamTracker) : m_pModule(pModule), m_pHeader(pHeader), @@ -709,7 +714,7 @@ ReadyToRunInfo::ReadyToRunInfo(Module * pModule, PEImageLayout * pLayout, READYT // For format version 4.1 and later, there is an optional inlining table if (IsImageVersionAtLeast(4, 1)) { - IMAGE_DATA_DIRECTORY* pInlineTrackingInfoDir = m_pComposite->FindSection(ReadyToRunSectionType::InliningInfo2); + IMAGE_DATA_DIRECTORY* pInlineTrackingInfoDir = m_component.FindSection(ReadyToRunSectionType::InliningInfo2); if (pInlineTrackingInfoDir != NULL) { const BYTE* pInlineTrackingMapData = (const BYTE*)m_pComposite->GetImage()->GetDirectoryData(pInlineTrackingInfoDir); @@ -721,7 +726,7 @@ ReadyToRunInfo::ReadyToRunInfo(Module * pModule, PEImageLayout * pLayout, READYT // For format version 2.1 and later, there is an optional inlining table if (m_pPersistentInlineTrackingMap == nullptr && IsImageVersionAtLeast(2, 1)) { - IMAGE_DATA_DIRECTORY * pInlineTrackingInfoDir = m_pComposite->FindSection(ReadyToRunSectionType::InliningInfo); + IMAGE_DATA_DIRECTORY * pInlineTrackingInfoDir = m_component.FindSection(ReadyToRunSectionType::InliningInfo); if (pInlineTrackingInfoDir != NULL) { const BYTE* pInlineTrackingMapData = (const BYTE*)m_pComposite->GetImage()->GetDirectoryData(pInlineTrackingInfoDir); diff --git a/src/coreclr/src/vm/readytoruninfo.h b/src/coreclr/src/vm/readytoruninfo.h index 34acae40d3c96..f4b62b0d48fcf 100644 --- a/src/coreclr/src/vm/readytoruninfo.h +++ b/src/coreclr/src/vm/readytoruninfo.h @@ -90,6 +90,8 @@ class ReadyToRunInfo bool IsComponentAssembly() const { return m_isComponentAssembly; } + static bool IsNativeImageSharedBy(PTR_Module pModule1, PTR_Module pModule2); + PTR_READYTORUN_HEADER GetReadyToRunHeader() const { return m_pHeader; } PTR_NativeImage GetNativeImage() const { return m_pNativeImage; }