Do not use fragile native image content when generating R2R images (dotnet/coreclr...
authorJan Kotas <jkotas@microsoft.com>
Sat, 11 Jun 2016 14:49:03 +0000 (07:49 -0700)
committerGitHub <noreply@github.com>
Sat, 11 Jun 2016 14:49:03 +0000 (07:49 -0700)
Commit migrated from https://github.com/dotnet/coreclr/commit/e266aff51403794bb2bd925a7ebb1ea53b119575

src/coreclr/src/vm/clsload.cpp
src/coreclr/src/vm/pefile.cpp

index f1fbe57..5af8f19 100644 (file)
@@ -100,8 +100,9 @@ PTR_Module ClassLoader::ComputeLoaderModuleWorker(
 
 #ifndef DACCESS_COMPILE
 #ifdef FEATURE_NATIVE_IMAGE_GENERATION
-    // Check we're NGEN'ing
-    if (IsCompilationProcess())
+    // Check we're NGEN'ing. ComputeLoaderModuleForCompilation algorithm assumes that there is fragile
+    // NGen image for CoreLib that is not the case for ReadyToRun compilation.
+    if (IsCompilationProcess() && !IsReadyToRunCompilation())
     {
         RETURN(ComputeLoaderModuleForCompilation(pDefinitionModule, token, classInst, methodInst));
     }
index deddc67..440281e 100644 (file)
@@ -499,7 +499,7 @@ static void ValidatePEFileMachineType(PEFile *peFile)
     if (actualMachineType == IMAGE_FILE_MACHINE_I386 && ((peKind & (peILonly | pe32BitRequired)) == peILonly))
         return;    // Image is marked CPU-agnostic.
 
-    if (actualMachineType != IMAGE_FILE_MACHINE_NATIVE)
+    if (actualMachineType != IMAGE_FILE_MACHINE_NATIVE && actualMachineType != IMAGE_FILE_MACHINE_NATIVE_NI)
     {
 #ifdef _TARGET_AMD64_
         // v4.0 64-bit compatibility workaround. The 64-bit v4.0 CLR's Reflection.Load(byte[]) api does not detect cpu-matches. We should consider fixing that in
@@ -2334,6 +2334,12 @@ BOOL PEFile::ShouldTreatNIAsMSIL()
 {
     LIMITED_METHOD_CONTRACT;
 
+    // Never use fragile native image content during ReadyToRun compilation. It would
+    // produces non-version resilient images because of wrong cached values for 
+    // MethodTable::IsLayoutFixedInCurrentVersionBubble, etc.
+    if (IsReadyToRunCompilation())
+        return TRUE;
+
     // Ask profiling API & config vars whether NGENd images should be avoided
     // completely.
     if (!NGENImagesAllowed())