From 517aa5418980574fe5ca92e8774c2084b18e8e97 Mon Sep 17 00:00:00 2001 From: Andrew Au Date: Mon, 17 Feb 2020 16:09:56 -0800 Subject: [PATCH] R2RDump fixes --- .../Amd64/UnwindInfo.cs | 2 +- .../ReadyToRunHeader.cs | 2 +- .../ReadyToRunReader.cs | 15 ++++++++++++--- 3 files changed, 14 insertions(+), 5 deletions(-) diff --git a/src/coreclr/src/tools/crossgen2/ILCompiler.Reflection.ReadyToRun/Amd64/UnwindInfo.cs b/src/coreclr/src/tools/crossgen2/ILCompiler.Reflection.ReadyToRun/Amd64/UnwindInfo.cs index ab309ab105a4fa..2c03e78445659f 100644 --- a/src/coreclr/src/tools/crossgen2/ILCompiler.Reflection.ReadyToRun/Amd64/UnwindInfo.cs +++ b/src/coreclr/src/tools/crossgen2/ILCompiler.Reflection.ReadyToRun/Amd64/UnwindInfo.cs @@ -237,7 +237,7 @@ private void ParseUnwindCode(ref int i) code.NextFrameOffset = (int)offset * 16; if ((UnwindCodeArray[i].FrameOffset & 0xF0000000) != 0) { - Console.WriteLine("Warning: Illegal unwindInfo unscaled offset: too large"); + throw new BadImageFormatException("Warning: Illegal unwindInfo unscaled offset: too large"); } } break; diff --git a/src/coreclr/src/tools/crossgen2/ILCompiler.Reflection.ReadyToRun/ReadyToRunHeader.cs b/src/coreclr/src/tools/crossgen2/ILCompiler.Reflection.ReadyToRun/ReadyToRunHeader.cs index edf65c38e88640..1cf5af44481b9d 100644 --- a/src/coreclr/src/tools/crossgen2/ILCompiler.Reflection.ReadyToRun/ReadyToRunHeader.cs +++ b/src/coreclr/src/tools/crossgen2/ILCompiler.Reflection.ReadyToRun/ReadyToRunHeader.cs @@ -78,7 +78,7 @@ public void ParseCoreHeader(byte[] image, ref int curOffset) var sectionType = (ReadyToRunSectionType)type; if (!Enum.IsDefined(typeof(ReadyToRunSectionType), type)) { - Console.WriteLine("Warning: Invalid ReadyToRun section type"); + throw new BadImageFormatException("Warning: Invalid ReadyToRun section type"); } int sectionStartRva = NativeReader.ReadInt32(image, ref curOffset); int sectionLength = NativeReader.ReadInt32(image, ref curOffset); diff --git a/src/coreclr/src/tools/crossgen2/ILCompiler.Reflection.ReadyToRun/ReadyToRunReader.cs b/src/coreclr/src/tools/crossgen2/ILCompiler.Reflection.ReadyToRun/ReadyToRunReader.cs index 6e319f33dc27f3..132f31c74ffbb6 100644 --- a/src/coreclr/src/tools/crossgen2/ILCompiler.Reflection.ReadyToRun/ReadyToRunReader.cs +++ b/src/coreclr/src/tools/crossgen2/ILCompiler.Reflection.ReadyToRun/ReadyToRunReader.cs @@ -381,8 +381,17 @@ private bool TryLocateNativeReadyToRunHeader() return false; } - private MetadataReader GetSystemModuleMetadataReader() => - _systemModuleReader ??= _assemblyResolver.FindAssembly(SystemModuleName, Filename); + private MetadataReader GetSystemModuleMetadataReader() + { + if (_systemModuleReader == null) + { + if (_assemblyResolver != null) + { + _systemModuleReader = _assemblyResolver.FindAssembly(SystemModuleName, Filename); + } + } + return _systemModuleReader; + } public MetadataReader GetGlobalMetadataReader() { @@ -630,7 +639,7 @@ private void ParseInstanceMethodEntrypoints(bool[] isEntryPoint) if (_composite) { // The only types that don't have module overrides on them in composite images are primitive types within the system module - mdReader ??= GetSystemModuleMetadataReader(); + mdReader = GetSystemModuleMetadataReader(); } owningType = decoder.ReadTypeSignatureNoEmit(); }