From fbeed7cd9580ed1f8c2a6c04591361c89e36cb27 Mon Sep 17 00:00:00 2001 From: Jan Kotas Date: Sat, 6 Feb 2016 19:40:58 -0800 Subject: [PATCH] Fix loading of native images on Unix 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. --- src/inc/pedecoder.inl | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/src/inc/pedecoder.inl b/src/inc/pedecoder.inl index 234698b54007..b75c4959f9b2 100644 --- a/src/inc/pedecoder.inl +++ b/src/inc/pedecoder.inl @@ -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