From a295c463a8adb37f2a1912f67aadc8ce45b20052 Mon Sep 17 00:00:00 2001 From: Katelyn Gadd Date: Fri, 13 Sep 2024 14:27:30 -0700 Subject: [PATCH] Improve error message when failing to locate an RVA in the R2R reader --- .../ILCompiler.Reflection.ReadyToRun/PEReaderExtensions.cs | 5 ++++- .../aot/ILCompiler.Reflection.ReadyToRun/ReadyToRunReader.cs | 2 +- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/src/coreclr/tools/aot/ILCompiler.Reflection.ReadyToRun/PEReaderExtensions.cs b/src/coreclr/tools/aot/ILCompiler.Reflection.ReadyToRun/PEReaderExtensions.cs index 97fce016e68bd..aed29174fbb15 100644 --- a/src/coreclr/tools/aot/ILCompiler.Reflection.ReadyToRun/PEReaderExtensions.cs +++ b/src/coreclr/tools/aot/ILCompiler.Reflection.ReadyToRun/PEReaderExtensions.cs @@ -110,7 +110,10 @@ public static int GetOffset(this PEReader reader, int rva) int index = reader.PEHeaders.GetContainingSectionIndex(rva); if (index == -1) { - throw new BadImageFormatException("Failed to convert invalid RVA to offset: " + rva); + var sectionInfo = new StringBuilder(); + foreach (var sh in reader.PEHeaders.SectionHeaders) + sectionInfo.AppendLine($" {sh.Name} PTRD={sh.PointerToRawData} SORD={sh.SizeOfRawData} VA={sh.VirtualAddress} VS={sh.VirtualSize}"); + throw new BadImageFormatException($"Failed to convert invalid RVA to offset: {rva}.\nSections:\n{sectionInfo}"); } SectionHeader containingSection = reader.PEHeaders.SectionHeaders[index]; return rva - containingSection.VirtualAddress + containingSection.PointerToRawData; diff --git a/src/coreclr/tools/aot/ILCompiler.Reflection.ReadyToRun/ReadyToRunReader.cs b/src/coreclr/tools/aot/ILCompiler.Reflection.ReadyToRun/ReadyToRunReader.cs index 5c7dc7fe177fd..518dbee710d44 100644 --- a/src/coreclr/tools/aot/ILCompiler.Reflection.ReadyToRun/ReadyToRunReader.cs +++ b/src/coreclr/tools/aot/ILCompiler.Reflection.ReadyToRun/ReadyToRunReader.cs @@ -1380,7 +1380,7 @@ private void FindOwnerCompositeExecutable() } /// - /// based on ZapImportSectionsTable::Save + /// originally based on ZapImportSectionsTable::Save /// private void EnsureImportSections() {