Fix loading of native images on Unix
authorJan Kotas <jkotas@microsoft.com>
Sun, 7 Feb 2016 03:40:58 +0000 (19:40 -0800)
committerJan Kotas <jkotas@microsoft.com>
Sun, 7 Feb 2016 03:40:58 +0000 (19:40 -0800)
R2R images that were compiled from architecture-specific IL images failed to load with bad image format exception on Unix. The fix is to take IMAGE_FILE_MACHINE_NATIVE_OS_OVERRIDE into account for the platform check.

Commit migrated from https://github.com/dotnet/coreclr/commit/fbeed7cd9580ed1f8c2a6c04591361c89e36cb27

src/coreclr/src/inc/pedecoder.inl

index 234698b..b75c495 100644 (file)
@@ -1340,11 +1340,20 @@ inline void PEDecoder::GetPEKindAndMachine(DWORD * pdwPEKind, DWORD *pdwMachine)
                 dwKind |= (DWORD)pe32Unmanaged;
             }
 
-            if (HasReadyToRunHeader() && (GetReadyToRunHeader()->Flags & READYTORUN_FLAG_PLATFORM_NEUTRAL_SOURCE) != 0)
+            if (HasReadyToRunHeader())
             {
-                // Supply the original PEKind/Machine to the assembly binder to make the full assembly name look like the original
-                dwKind = peILonly;
-                dwMachine = IMAGE_FILE_MACHINE_I386;
+                if (dwMachine == IMAGE_FILE_MACHINE_NATIVE_NI)
+                {
+                    // Supply the original machine type to the assembly binder
+                    dwMachine = IMAGE_FILE_MACHINE_NATIVE;
+                }
+
+                if ((GetReadyToRunHeader()->Flags & READYTORUN_FLAG_PLATFORM_NEUTRAL_SOURCE) != 0)
+                {
+                    // Supply the original PEKind/Machine to the assembly binder to make the full assembly name look like the original
+                    dwKind = peILonly;
+                    dwMachine = IMAGE_FILE_MACHINE_I386;
+                }
             }
         }
         else