Two R2RDump fixes for Crossgen output (#19585)
authorTomáš Rylek <trylek@microsoft.com>
Thu, 23 Aug 2018 19:23:42 +0000 (21:23 +0200)
committerGitHub <noreply@github.com>
Thu, 23 Aug 2018 19:23:42 +0000 (21:23 +0200)
1) In some situations, Crossgen emits a section with EntrySize = 0.
Apparently the engine defaults to size_t in such case.

2) Similarly, Crossgen sometimes emits a section with the UNKNOWN
kind. I have relaxed the section kind check to just treat all
non-eager section kinds the same.

Thanks

Tomas

src/tools/r2rdump/R2RReader.cs

index 417b0c8..80664fc 100644 (file)
@@ -401,6 +401,25 @@ namespace R2RDump
                 R2RImportSection.CorCompileImportFlags flags = (R2RImportSection.CorCompileImportFlags)NativeReader.ReadUInt16(Image, ref offset);
                 byte type = NativeReader.ReadByte(Image, ref offset);
                 byte entrySize = NativeReader.ReadByte(Image, ref offset);
+                if (entrySize == 0)
+                {
+                    switch (Machine)
+                    {
+                        case Machine.I386:
+                        case Machine.ArmThumb2:
+                            entrySize = 4;
+                            break;
+
+                        case Machine.Amd64:
+                        case Machine.IA64:
+                        case Machine.Arm64:
+                            entrySize = 8;
+                            break;
+
+                        default:
+                            throw new NotImplementedException(Machine.ToString());
+                    }
+                }
                 int entryCount = 0;
                 if (entrySize != 0)
                 {
@@ -434,8 +453,7 @@ namespace R2RDump
                             }
                         }
                         break;
-                    case R2RImportSection.CorCompileImportFlags.CORCOMPILE_IMPORT_FLAGS_CODE:
-                    case R2RImportSection.CorCompileImportFlags.CORCOMPILE_IMPORT_FLAGS_PCODE:
+                    default:
                         for (int i = 0; i < entryCount; i++)
                         {
                             int entryOffset = sectionOffset - startOffset;