Fixes towards making the runtime compiled without FEATURE_PREJIT defined (#19864)
authorJan Kotas <jkotas@microsoft.com>
Fri, 7 Sep 2018 22:22:40 +0000 (15:22 -0700)
committerGitHub <noreply@github.com>
Fri, 7 Sep 2018 22:22:40 +0000 (15:22 -0700)
21 files changed:
src/debug/daccess/daccess.cpp
src/debug/daccess/dacdbiimpl.cpp
src/inc/corpriv.h
src/inc/fixuppointer.h
src/md/runtime/mdinternalro.h
src/md/winmd/winmdimport.cpp
src/vm/ceeload.h
src/vm/ceeload.inl
src/vm/codeman.h
src/vm/domainfile.cpp
src/vm/exceptionhandling.h
src/vm/inlinetracking.h
src/vm/interoputil.cpp
src/vm/method.hpp
src/vm/methodtablebuilder.cpp
src/vm/pefile.cpp
src/vm/pefile.h
src/vm/peimage.inl
src/vm/readytoruninfo.h
src/vm/stubmgr.cpp
src/vm/zapsig.h

index e7bef87..685f23f 100644 (file)
@@ -5844,7 +5844,9 @@ ClrDataAccess::RawGetMethodName(
 #endif
         if (pStubManager == PrecodeStubManager::g_pManager)
         {
+#ifdef FEATURE_PREJIT
         PrecodeStub:
+#endif
             PCODE alignedAddress = AlignDown(TO_TADDR(address), PRECODE_ALIGNMENT);
 
 #ifdef _TARGET_ARM_
@@ -5892,7 +5894,9 @@ ClrDataAccess::RawGetMethodName(
         else
         if (pStubManager == JumpStubStubManager::g_pManager)
         {
+#ifdef FEATURE_PREJIT
         JumpStub:
+#endif
             PCODE pTarget = decodeBackToBackJump(TO_TADDR(address));
 
             HRESULT hr = GetRuntimeNameByAddress(pTarget, flags, bufLen, symbolLen, symbolBuf, NULL);
index 07fd438..bed03ad 100644 (file)
@@ -4056,9 +4056,9 @@ BOOL DacDbiInterfaceImpl::GetModuleNGenPath(VMPTR_Module vmModule,
             return TRUE;
         }
     }
+NoFileName:
 #endif // FEATURE_PREJIT
 
-NoFileName:
     // no ngen filename
     IfFailThrow(pStrFilename->AssignCopy(W("")));
     return FALSE;
index 9641b05..81143e6 100644 (file)
@@ -383,17 +383,6 @@ DECLARE_INTERFACE_(ICeeGenInternal, IUnknown)
     STDMETHOD (SetInitialGrowth) (DWORD growth) PURE;
 };
 
-// ===========================================================================
-#ifdef FEATURE_PREJIT
-// ===========================================================================
-
-
-// Use the default JIT compiler
-#define DEFAULT_NGEN_COMPILER_DLL_NAME W("clrjit.dll")
-
-
-struct CORCOMPILE_ASSEMBLY_SIGNATURE;
-
 //
 // IGetIMDInternalImport
 //
@@ -403,7 +392,7 @@ struct CORCOMPILE_ASSEMBLY_SIGNATURE;
 //    RegMeta, WinMDImport - supports the internal GetMetaDataInternalInterfaceFromPublic() "api".
 //
 // {92B2FEF9-F7F5-420d-AD42-AECEEE10A1EF}
-EXTERN_GUID(IID_IGetIMDInternalImport,  0x92b2fef9, 0xf7f5, 0x420d, 0xad, 0x42, 0xae, 0xce, 0xee, 0x10, 0xa1, 0xef);
+EXTERN_GUID(IID_IGetIMDInternalImport, 0x92b2fef9, 0xf7f5, 0x420d, 0xad, 0x42, 0xae, 0xce, 0xee, 0x10, 0xa1, 0xef);
 #undef  INTERFACE
 #define INTERFACE IGetIMDInternalImport
 DECLARE_INTERFACE_(IGetIMDInternalImport, IUnknown)
@@ -413,7 +402,12 @@ DECLARE_INTERFACE_(IGetIMDInternalImport, IUnknown)
     ) PURE;
 };
 
+// ===========================================================================
+#ifdef FEATURE_PREJIT
+// ===========================================================================
 
+// Use the default JIT compiler
+#define DEFAULT_NGEN_COMPILER_DLL_NAME W("clrjit.dll")
 
 #ifndef DACCESS_COMPILE
 
@@ -484,54 +478,6 @@ STDAPI GetCORVersionInternal(
                                   DWORD  cchBuffer,
     __out                         DWORD *pdwLength);
 
-
-#ifdef FEATURE_PREJIT
-
-//**********************************************************************
-// Access to native image validation logic in the runtime.
-//
-// An interface only a mother could live as this logic should really be encapsulated in
-// the native binder. But for historical reasons, it lives in the VM directory
-// and is shared by the desktop and coreclr's which have separate native binders.
-// Hence, this interface inherits a lot of "baggage."
-
-
-
-// A small shim around PEAssemblies/IBindResult that allow us to write Fusion/CLR-agnostic code
-// for logging native bind failures to the Fusion log/CLR log.
-//
-// These objects are stack-based and non-thread-safe. They are created for the duration of a single RuntimeVerify call.
-// The methods are expected to compute their data lazily as they are only used in bind failures or in checked builds.
-//
-// This class also exposes the IFusionBindLog pointer. This isn't really the appropriate place to expose that but 
-// it serves to avoid compiling references to IFUsionBindLog into code that doesn't define FEATURE_FUSION.
-class LoggableAssembly
-{
-  public:
-    virtual SString         DisplayString() = 0;        // Returns an unspecified representation suitable for injecting into log messages.   
-};
-
-
-// Validates that an NI matches the running CLR, OS, CPU, etc.
-BOOL RuntimeVerifyNativeImageVersion(const CORCOMPILE_VERSION_INFO *pVerInfo, LoggableAssembly *pLogAsm);
-
-// Validates that an NI matches the required flavor (debug, instrumented, etc.)
-BOOL RuntimeVerifyNativeImageFlavor(const CORCOMPILE_VERSION_INFO *pVerInfo, LoggableAssembly *pLogAsm);
-
-// Validates that a hard-dep matches the a parent NI's compile-time hard-dep.
-BOOL RuntimeVerifyNativeImageDependency(const CORCOMPILE_NGEN_SIGNATURE &ngenSigExpected,
-                                        const CORCOMPILE_VERSION_INFO *pActual,
-                                        LoggableAssembly              *pLogAsm);
-
-BOOL RuntimeVerifyNativeImageDependency(const CORCOMPILE_DEPENDENCY   *pExpected,
-                                        const CORCOMPILE_VERSION_INFO *pActual,
-                                        LoggableAssembly              *pLogAsm);
-
-#endif // FEATURE_PREJIT
-
-
-
-
 #endif  // _CORPRIV_H_
 // EOF =======================================================================
 
index abed1f9..18886c0 100644 (file)
@@ -588,16 +588,13 @@ public:
     BOOL IsTagged(TADDR base) const
     {
         LIMITED_METHOD_DAC_CONTRACT;
-        return IsTagged();
+        return FALSE;
     }
 
     // Returns whether the indirection cell contain fixup that has not been converted to real pointer yet.
     BOOL IsTagged() const
     {
         LIMITED_METHOD_DAC_CONTRACT;
-        TADDR addr = m_ptr;
-        if ((addr & FIXUP_POINTER_INDIRECTION) != 0)
-             return (*PTR_TADDR(addr - FIXUP_POINTER_INDIRECTION) & 1) != 0;
         return FALSE;
     }
 
@@ -613,9 +610,6 @@ public:
     PTR_TYPE * GetValuePtr() const
     {
         LIMITED_METHOD_CONTRACT;
-        TADDR addr = m_ptr;
-        if ((addr & FIXUP_POINTER_INDIRECTION) != 0)
-            return (PTR_TYPE *)(addr - FIXUP_POINTER_INDIRECTION);
         return (PTR_TYPE *)&m_ptr;
     }
 #endif // !DACCESS_COMPILE
@@ -655,12 +649,27 @@ public:
         return dac_cast<DPTR(PlainPointer<PTR_TYPE>)>(base)->GetValueMaybeNull(base);
     }
 
+    // Returns value of the encoded pointer.
+    // Allows the value to be tagged.
+    FORCEINLINE TADDR GetValueMaybeTagged() const
+    {
+        LIMITED_METHOD_DAC_CONTRACT;
+        return m_ptr;
+    }
+
+    // Returns value of the encoded pointer. Assumes that the pointer is not NULL. 
+    // Allows the value to be tagged.
+    FORCEINLINE TADDR GetValueMaybeTagged(TADDR base) const
+    {
+        LIMITED_METHOD_DAC_CONTRACT;
+        return m_ptr;
+    }
+
     // Returns whether pointer is indirect. Assumes that the value is not NULL.
     bool IsIndirectPtr(TADDR base) const
     {
         LIMITED_METHOD_DAC_CONTRACT;
-
-        return (m_ptr & FIXUP_POINTER_INDIRECTION) != 0;
+        return FALSE;
     }
 
 #ifndef DACCESS_COMPILE
@@ -669,7 +678,7 @@ public:
     bool IsIndirectPtr() const
     {
         LIMITED_METHOD_CONTRACT;
-        return IsIndirectPtr((TADDR)this);
+        return FALSE;
     }
 #endif
 
@@ -677,8 +686,7 @@ public:
     bool IsIndirectPtrMaybeNull(TADDR base) const
     {
         LIMITED_METHOD_DAC_CONTRACT;
-
-        return IsIndirectPtr(base);
+        return FALSE;
     }
 
 #ifndef DACCESS_COMPILE
@@ -687,7 +695,7 @@ public:
     bool IsIndirectPtrMaybeNull() const
     {
         LIMITED_METHOD_CONTRACT;
-        return IsIndirectPtrMaybeNull((TADDR)this);
+        return FALSE;
     }
 #endif
 
index 92e5393..83f9d9a 100644 (file)
@@ -71,12 +71,14 @@ public:
     STDMETHODIMP SetOptimizeAccessForSpeed(
         BOOL fOptSpeed)
     {
+#ifdef FEATURE_PREJIT
         // The metadata cache of hot items is an optional working-set optimization 
         // that has a large speed cost relative to direct table lookup
         if (fOptSpeed)
         {   // We want to disable usage of hot data (e.g. in ngen compilation process)
             m_LiteWeightStgdb.m_MiniMd.DisableHotDataUsage();
         }
+#endif
         return S_OK;
     }
 
index cc983d2..9090ba4 100644 (file)
@@ -185,10 +185,12 @@ class WinMDImport : public IMetaDataImport2
                     _ASSERTE(!"WinMDImport::QueryInterface(IID_IMDInternalEmit) returning E_NOINTERFACE");
                 else if (riid == IID_IMetaDataEmitHelper)
                     _ASSERTE(!"WinMDImport::QueryInterface(IID_IMetaDataEmitHelper) returning E_NOINTERFACE");
+#ifdef FEATURE_PREJIT
                 else if (riid == IID_IMetaDataCorProfileData)
                     _ASSERTE(!"WinMDImport::QueryInterface(IID_IMetaDataCorProfileData) returning E_NOINTERFACE");
                 else if (riid == IID_IMDInternalMetadataReorderingOptions)
                     _ASSERTE(!"WinMDImport::QueryInterface(IID_IMDInternalMetadataReorderingOptions) returning E_NOINTERFACE");
+#endif
                 else
                     _ASSERTE(!"WinMDImport::QueryInterface() returning E_NOINTERFACE");
             }
index d8a278e..91da7b3 100644 (file)
@@ -73,15 +73,14 @@ class Pending;
 class MethodTable;
 class AppDomain;
 class DynamicMethodTable;
-struct CerPrepInfo;
+class CodeVersionManager;
+class CallCounter;
+class TieredCompilationManager;
 #ifdef FEATURE_PREJIT
 class CerNgenRootTable;
 struct MethodContextElement;
 class TypeHandleList;
 class ProfileEmitter;
-class CodeVersionManager;
-class CallCounter;
-class TieredCompilationManager;
 class TrackingMap;
 struct MethodInModule;
 class PersistentInlineTrackingMapNGen;
@@ -508,6 +507,7 @@ typedef DPTR(class MemberRef) PTR_MemberRef;
 #define IS_FIELD_MEMBER_REF ((TADDR)0x00000002)
 
 
+#ifdef FEATURE_PREJIT
 //
 // NGen image layout information that we need to quickly access at runtime
 //
@@ -557,6 +557,8 @@ struct NGenLayoutInfo
     PCODE                   m_pExternalMethodFixupJumpStub;
     DWORD                   m_rvaFilterPersonalityRoutine;
 };
+#endif // FEATURE_PREJIT
+
 
 //
 // VASigCookies are allocated to encapsulate a varargs call signature.
@@ -1622,13 +1624,15 @@ public:
         return (m_dwPersistedFlags & COLLECTIBLE_MODULE) != 0;
     }
 
+#ifdef FEATURE_READYTORUN
+private:
+    PTR_ReadyToRunInfo      m_pReadyToRunInfo;
+#endif
+
 #ifdef FEATURE_PREJIT
 
 private:
     PTR_NGenLayoutInfo      m_pNGenLayoutInfo;
-#ifdef FEATURE_READYTORUN
-    PTR_ReadyToRunInfo      m_pReadyToRunInfo;
-#endif
 
     PTR_ProfilingBlobTable  m_pProfilingBlobTable;   // While performing IBC instrumenting this hashtable is populated with the External defs
     CorProfileData *        m_pProfileData;          // While ngen-ing with IBC optimizations this contains a link to the IBC data for the assembly
@@ -2946,25 +2950,6 @@ public:
         return m_pNGenLayoutInfo->m_VirtualMethodThunks.IsInRange(code);
     }
 
-    BOOL IsReadyToRun()
-    {
-        LIMITED_METHOD_DAC_CONTRACT;
-
-#ifdef FEATURE_READYTORUN
-        return m_pReadyToRunInfo != NULL;
-#else
-        return FALSE;
-#endif
-    }
-
-#ifdef FEATURE_READYTORUN
-    PTR_ReadyToRunInfo GetReadyToRunInfo()
-    {
-        LIMITED_METHOD_DAC_CONTRACT;
-        return m_pReadyToRunInfo;
-    }
-#endif
-
     ICorJitInfo::ProfileBuffer * AllocateProfileBuffer(mdToken _token, DWORD _size, DWORD _ILSize);
     HANDLE OpenMethodProfileDataLogFile(GUID mvid);
     static void ProfileDataAllocateTokenLists(ProfileEmitter * pEmitter, TokenProfileData* pTokenProfileData);
@@ -3005,6 +2990,25 @@ public:
 
 #endif  // FEATURE_PREJIT
 
+    BOOL IsReadyToRun()
+    {
+        LIMITED_METHOD_DAC_CONTRACT;
+
+#ifdef FEATURE_READYTORUN
+        return m_pReadyToRunInfo != NULL;
+#else
+        return FALSE;
+#endif
+    }
+
+#ifdef FEATURE_READYTORUN
+    PTR_ReadyToRunInfo GetReadyToRunInfo()
+    {
+        LIMITED_METHOD_DAC_CONTRACT;
+        return m_pReadyToRunInfo;
+    }
+#endif
+
 #ifdef _DEBUG
     //Similar to the ExpandAll we use for NGen, this forces jitting of all methods in a module.  This is
     //used for debug purposes though.
index 3afef73..2c48265 100644 (file)
@@ -269,10 +269,12 @@ void LookupMap<TYPE>::EnsureElementCanBeStored(Module * pModule, DWORD rid)
     }
     CONTRACTL_END;
 
+#ifdef FEATURE_PREJIT
     // don't attempt to call GetElementPtr for rids inside the compressed portion of
     // a multi-node map
     if (MapIsCompressed() && rid < dwCount)
         return;
+#endif
     PTR_TADDR pElement = GetElementPtr(rid);
     if (pElement == NULL)
         GrowMap(pModule, rid);
index e30b633..ebf92e4 100644 (file)
@@ -68,6 +68,7 @@ Abstract:
 #include "shash.h"
 #include "pedecoder.h"
 #include "gcinfo.h"
+#include "eexcp.h"
 
 #if defined(WIN64EXCEPTIONS) && !defined(USE_INDIRECT_CODEHEADER)
 #error "WIN64EXCEPTIONS requires USE_INDIRECT_CODEHEADER"
@@ -1742,7 +1743,9 @@ public:
 class EECodeInfo
 {
     friend BOOL EEJitManager::JitCodeToMethodInfo(RangeSection * pRangeSection, PCODE currentPC, MethodDesc** ppMethodDesc, EECodeInfo * pCodeInfo);
+#ifdef FEATURE_PREJIT
     friend BOOL NativeImageJitManager::JitCodeToMethodInfo(RangeSection * pRangeSection, PCODE currentPC, MethodDesc** ppMethodDesc, EECodeInfo * pCodeInfo);
+#endif
 #ifdef FEATURE_READYTORUN
     friend BOOL ReadyToRunJitManager::JitCodeToMethodInfo(RangeSection * pRangeSection, PCODE currentPC, MethodDesc** ppMethodDesc, EECodeInfo * pCodeInfo);
 #endif
index 12d3f3c..ded1e57 100644 (file)
@@ -748,8 +748,7 @@ void DomainFile::VerifyNativeImageDependencies(bool verifyOnly)
         CORCOMPILE_VERSION_INFO * pDependencyNativeVersion =
                 pDependencyNativeLayout->GetNativeVersionInfo();
 
-        LoggablePEAssembly logAsm(pDependencyFile);
-        if (!RuntimeVerifyNativeImageDependency(pDependency, pDependencyNativeVersion, &logAsm))
+        if (!RuntimeVerifyNativeImageDependency(pDependency, pDependencyNativeVersion, pDependencyFile))
             goto NativeImageRejected;
     }
     LOG((LF_ZAP, LL_INFO100, "ZAP: Native image dependencies for %S OK.\n",
index 27981e6..b678387 100644 (file)
 
 #ifdef WIN64EXCEPTIONS
 
+#include "eexcp.h"
+#include "exstatecommon.h"
+
 #if defined(_TARGET_ARM_) || defined(_TARGET_X86_)
 #define USE_PER_FRAME_PINVOKE_INIT
 #endif // _TARGET_ARM_ || _TARGET_X86_
 
-
 // This address lies in the NULL pointer partition of the process memory.
 // Accessing it will result in AV.
 #define INVALID_RESUME_ADDRESS 0x000000000000bad0
 
-#include "exstatecommon.h"
-
 EXTERN_C EXCEPTION_DISPOSITION
 ProcessCLRException(IN     PEXCEPTION_RECORD     pExceptionRecord
           WIN64_ARG(IN     ULONG64               MemoryStackFp)
index 2cfb35b..976a0e7 100644 (file)
@@ -37,6 +37,8 @@
 class MethodDesc;
 typedef DPTR(class MethodDesc)          PTR_MethodDesc;
 
+class ZapHeap;
+
 struct MethodInModule
 {
     Module *m_module;
index 24afdf7..8bf5842 100644 (file)
@@ -3907,6 +3907,7 @@ BOOL MethodNeedsForwardComStub(MethodDesc *pMD, DataImage *pImage)
     return FALSE;
 }
 
+#ifdef FEATURE_PREJIT
 //---------------------------------------------------------------------------
 // Determines if a method is visible from COM in a way that requires a marshaling
 // stub, i.e. it allows early binding.
@@ -3992,6 +3993,7 @@ BOOL MethodNeedsReverseComStub(MethodDesc *pMD)
 
     return IsMethodVisibleFromCom(pMD);
 }
+#endif // FEATURE_PREJIT
 
 
 #ifndef CROSSGEN_COMPILE
index 7674f5e..5ed6869 100644 (file)
@@ -45,6 +45,7 @@ class DynamicMethodDesc;
 class ReJitManager;
 class CodeVersionManager;
 class PrepareCodeConfig;
+class CallCounter;
 
 typedef DPTR(FCallMethodDesc)        PTR_FCallMethodDesc;
 typedef DPTR(ArrayMethodDesc)        PTR_ArrayMethodDesc;
index 5739831..56397ca 100644 (file)
@@ -6516,6 +6516,7 @@ VOID MethodTableBuilder::PlaceInterfaceDeclarationOnClass(
         pDecl->GetSlotIndex(), 
         pImpl);
 
+#ifdef FEATURE_PREJIT
     if (IsCompilationProcess())
     {
         //
@@ -6527,6 +6528,7 @@ VOID MethodTableBuilder::PlaceInterfaceDeclarationOnClass(
             pDeclMT->GetWriteableDataForWrite()->SetIsOverridingInterface();
         }
     }
+#endif
     
 #ifdef _DEBUG
     if (bmtInterface->dbg_fShouldInjectInterfaceDuplicates)
index d417545..69dd4d0 100644 (file)
@@ -1034,7 +1034,7 @@ extern DWORD g_dwLogLevel;
 //===========================================================================================================
 // Encapsulates CLR and Fusion logging for runtime verification of native images.
 //===========================================================================================================
-static void RuntimeVerifyVLog(DWORD level, LoggableAssembly *pLogAsm, const WCHAR *fmt, va_list args)
+static void RuntimeVerifyVLog(DWORD level, PEAssembly *pLogAsm, const WCHAR *fmt, va_list args)
 {
     STANDARD_VM_CONTRACT;
 
@@ -1046,7 +1046,7 @@ static void RuntimeVerifyVLog(DWORD level, LoggableAssembly *pLogAsm, const WCHA
 
     if (fOutputToLogging)
     {
-        SString displayString = pLogAsm->DisplayString();
+        SString displayString = pLogAsm->GetPath();
         LOG((LF_ZAP, level, "%s: \"%S\"\n", "ZAP", displayString.GetUnicode()));
         LOG((LF_ZAP, level, "%S", message.GetUnicode()));
         LOG((LF_ZAP, level, "\n"));
@@ -1054,7 +1054,7 @@ static void RuntimeVerifyVLog(DWORD level, LoggableAssembly *pLogAsm, const WCHA
 
     if (fOutputToDebugger)
     {
-        SString displayString = pLogAsm->DisplayString();
+        SString displayString = pLogAsm->GetPath();
         WszOutputDebugString(W("CLR:("));
         WszOutputDebugString(displayString.GetUnicode());
         WszOutputDebugString(W(") "));
@@ -1068,7 +1068,7 @@ static void RuntimeVerifyVLog(DWORD level, LoggableAssembly *pLogAsm, const WCHA
 //===========================================================================================================
 // Encapsulates CLR and Fusion logging for runtime verification of native images.
 //===========================================================================================================
-static void RuntimeVerifyLog(DWORD level, LoggableAssembly *pLogAsm, const WCHAR *fmt, ...)
+static void RuntimeVerifyLog(DWORD level, PEAssembly *pLogAsm, const WCHAR *fmt, ...)
 {
     STANDARD_VM_CONTRACT;
 
@@ -1156,67 +1156,6 @@ extern HMODULE CorCompileGetRuntimeDll(CorCompileRuntimeDlls id)
 #endif // CROSSGEN_COMPILE
 
 //===========================================================================================================
-// Helper for RuntimeVerifyNativeImageVersion(). Compares the loaded clr.dll and clrjit.dll's against
-// the ones the native image was compiled against.
-//===========================================================================================================
-static BOOL RuntimeVerifyNativeImageTimestamps(const CORCOMPILE_VERSION_INFO *info, LoggableAssembly *pLogAsm)
-{
-    STANDARD_VM_CONTRACT;
-
-
-    return TRUE;
-}
-
-//===========================================================================================================
-// Validates that an NI matches the running CLR, OS, CPU, etc. This is the entrypoint used by the CLR loader.
-//
-//===========================================================================================================
-BOOL PEAssembly::CheckNativeImageVersion(PEImage *peimage)
-{
-    STANDARD_VM_CONTRACT;
-
-    //
-    // Get the zap version header. Note that modules will not have version
-    // headers - they add no additional versioning constraints from their
-    // assemblies.
-    //
-    PEImageLayoutHolder image=peimage->GetLayout(PEImageLayout::LAYOUT_ANY,PEImage::LAYOUT_CREATEIFNEEDED);
-
-    if (!image->HasNativeHeader())
-        return FALSE;
-
-    if (!image->CheckNativeHeaderVersion())
-    {
-        // Wrong native image version is fatal error on CoreCLR
-        ThrowHR(COR_E_NI_AND_RUNTIME_VERSION_MISMATCH);
-    }
-
-    CORCOMPILE_VERSION_INFO *info = image->GetNativeVersionInfo();
-    if (info == NULL)
-        return FALSE;
-
-    LoggablePEAssembly logAsm(this);
-    if (!RuntimeVerifyNativeImageVersion(info, &logAsm))
-    {
-        // Wrong native image version is fatal error on CoreCLR
-        ThrowHR(COR_E_NI_AND_RUNTIME_VERSION_MISMATCH);
-    }
-
-    CorCompileConfigFlags configFlags = PEFile::GetNativeImageConfigFlagsWithOverrides();
-
-    // Otherwise, match regardless of the instrumentation flags
-    configFlags = (CorCompileConfigFlags) (configFlags & ~(CORCOMPILE_CONFIG_INSTRUMENTATION_NONE | CORCOMPILE_CONFIG_INSTRUMENTATION));
-
-    if ((info->wConfigFlags & configFlags) != configFlags)
-    {
-        return FALSE;
-    }
-
-    return TRUE;
-}
-
-
-//===========================================================================================================
 // Validates that an NI matches the running CLR, OS, CPU, etc.
 //
 // For historial reasons, some versions of the runtime perform this check at native bind time (preferrred),
@@ -1225,13 +1164,10 @@ BOOL PEAssembly::CheckNativeImageVersion(PEImage *peimage)
 // This is the common funnel for both versions and is agnostic to whether the "assembly" is represented
 // by a CLR object or Fusion object.
 //===========================================================================================================
-BOOL RuntimeVerifyNativeImageVersion(const CORCOMPILE_VERSION_INFO *info, LoggableAssembly *pLogAsm)
+BOOL RuntimeVerifyNativeImageVersion(const CORCOMPILE_VERSION_INFO *info, PEAssembly *pLogAsm)
 {
     STANDARD_VM_CONTRACT;
 
-    if (!RuntimeVerifyNativeImageTimestamps(info, pLogAsm))
-        return FALSE;
-
     //
     // Check that the EE version numbers are the same.
     //
@@ -1295,6 +1231,53 @@ BOOL RuntimeVerifyNativeImageVersion(const CORCOMPILE_VERSION_INFO *info, Loggab
     return TRUE;
 }
 
+//===========================================================================================================
+// Validates that an NI matches the running CLR, OS, CPU, etc. This is the entrypoint used by the CLR loader.
+//
+//===========================================================================================================
+BOOL PEAssembly::CheckNativeImageVersion(PEImage *peimage)
+{
+    STANDARD_VM_CONTRACT;
+
+    //
+    // Get the zap version header. Note that modules will not have version
+    // headers - they add no additional versioning constraints from their
+    // assemblies.
+    //
+    PEImageLayoutHolder image = peimage->GetLayout(PEImageLayout::LAYOUT_ANY, PEImage::LAYOUT_CREATEIFNEEDED);
+
+    if (!image->HasNativeHeader())
+        return FALSE;
+
+    if (!image->CheckNativeHeaderVersion())
+    {
+        // Wrong native image version is fatal error on CoreCLR
+        ThrowHR(COR_E_NI_AND_RUNTIME_VERSION_MISMATCH);
+    }
+
+    CORCOMPILE_VERSION_INFO *info = image->GetNativeVersionInfo();
+    if (info == NULL)
+        return FALSE;
+
+    if (!RuntimeVerifyNativeImageVersion(info, this))
+    {
+        // Wrong native image version is fatal error on CoreCLR
+        ThrowHR(COR_E_NI_AND_RUNTIME_VERSION_MISMATCH);
+    }
+
+    CorCompileConfigFlags configFlags = PEFile::GetNativeImageConfigFlagsWithOverrides();
+
+    // Otherwise, match regardless of the instrumentation flags
+    configFlags = (CorCompileConfigFlags)(configFlags & ~(CORCOMPILE_CONFIG_INSTRUMENTATION_NONE | CORCOMPILE_CONFIG_INSTRUMENTATION));
+
+    if ((info->wConfigFlags & configFlags) != configFlags)
+    {
+        return FALSE;
+    }
+
+    return TRUE;
+}
+
 #endif // !DACCESS_COMPILE
 
 /* static */
@@ -1401,14 +1384,14 @@ CorCompileConfigFlags PEFile::GetNativeImageConfigFlagsWithOverrides()
 //===========================================================================================================
 BOOL RuntimeVerifyNativeImageDependency(const CORCOMPILE_NGEN_SIGNATURE &ngenSigExpected,
                                         const CORCOMPILE_VERSION_INFO *pActual,
-                                        LoggableAssembly              *pLogAsm)
+                                        PEAssembly                    *pLogAsm)
 {
     STANDARD_VM_CONTRACT;
 
     if (ngenSigExpected != pActual->signature)
     {
         // Signature did not match
-        SString displayString = pLogAsm->DisplayString();
+        SString displayString = pLogAsm->GetPath();
         RuntimeVerifyLog(LL_ERROR,
                          pLogAsm,
                          W("Rejecting native image because native image dependency %s ")
@@ -1422,7 +1405,7 @@ BOOL RuntimeVerifyNativeImageDependency(const CORCOMPILE_NGEN_SIGNATURE &ngenSig
 // Wrapper function for use by parts of the runtime that actually have a CORCOMPILE_DEPENDENCY to work with.
 BOOL RuntimeVerifyNativeImageDependency(const CORCOMPILE_DEPENDENCY   *pExpected,
                                         const CORCOMPILE_VERSION_INFO *pActual,
-                                        LoggableAssembly              *pLogAsm)
+                                        PEAssembly                    *pLogAsm)
 {
     WRAPPER_NO_CONTRACT;
 
index e79c94c..699b4e4 100644 (file)
@@ -814,43 +814,9 @@ typedef ReleaseHolder<PEFile> PEFileHolder;
 
 typedef ReleaseHolder<PEAssembly> PEAssemblyHolder;
 
-
-
-// A small shim around PEAssemblies/IBindResult that allow us to write Fusion/CLR-agnostic
-// for logging native bind failures to the Fusion log/CLR log.
-//
-// These structures are stack-based, non-thread-safe and created for the duration of a single RuntimeVerify call.
-// The methods are expected to compute their data lazily as they are only used in bind failures or in checked builds.
-class LoggablePEAssembly : public LoggableAssembly
-{
-  public:
-    virtual SString DisplayString()
-    {
-        STANDARD_VM_CONTRACT;
-
-        return m_peAssembly->GetPath();
-    }
-
-
-    LoggablePEAssembly(PEAssembly *peAssembly)
-    {
-        LIMITED_METHOD_CONTRACT;
-
-        m_peAssembly = peAssembly;
-        peAssembly->AddRef();
-    }
-
-    ~LoggablePEAssembly()
-    {
-        LIMITED_METHOD_CONTRACT;
-
-        m_peAssembly->Release();
-    }
-
-  private:
-    PEAssembly  *m_peAssembly;
-};
-
+BOOL RuntimeVerifyNativeImageDependency(const CORCOMPILE_DEPENDENCY   *pExpected,
+    const CORCOMPILE_VERSION_INFO *pActual,
+    PEAssembly                    *pLogAsm);
 
 // ================================================================================
 // Inline definitions
index 57f5400..8a9c96c 100644 (file)
@@ -376,6 +376,7 @@ inline const BOOL PEImage::HasStrongNameSignature()
 
 inline BOOL PEImage::IsIbcOptimized()   
 {
+#ifdef FEATURE_PREJIT 
     WRAPPER_NO_CONTRACT;
     if (HasLoadedLayout())
         return GetLoadedLayout()->GetNativeILIsIbcOptimized();
@@ -384,6 +385,9 @@ inline BOOL PEImage::IsIbcOptimized()
         PEImageLayoutHolder pLayout(GetLayout(PEImageLayout::LAYOUT_ANY,LAYOUT_CREATEIFNEEDED));
         return pLayout->GetNativeILIsIbcOptimized();
     }
+#else
+    return false;
+#endif
 }
 
 #ifdef FEATURE_PREJIT 
index 210399f..fea5b33 100644 (file)
 
 typedef DPTR(struct READYTORUN_SECTION) PTR_READYTORUN_SECTION;
 
+#ifndef FEATURE_PREJIT
+typedef DPTR(struct READYTORUN_IMPORT_SECTION) PTR_CORCOMPILE_IMPORT_SECTION;
+#endif
+
 class PrepareCodeConfig;
 
 typedef DPTR(class ReadyToRunInfo) PTR_ReadyToRunInfo;
index 2a36908..58c0fa3 100644 (file)
@@ -1522,6 +1522,7 @@ BOOL RangeSectionStubManager::DoTraceStub(PCODE stubStartAddress, TraceDestinati
     case STUB_CODE_BLOCK_STUBLINK:
         return StubLinkStubManager::g_pManager->DoTraceStub(stubStartAddress, trace);
 
+#ifdef FEATURE_PREJIT
     case STUB_CODE_BLOCK_VIRTUAL_METHOD_THUNK:
         {
             PCODE pTarget = GetMethodThunkTarget(stubStartAddress);
@@ -1540,6 +1541,7 @@ BOOL RangeSectionStubManager::DoTraceStub(PCODE stubStartAddress, TraceDestinati
             }
             return TRUE;
         }
+#endif
 
     case STUB_CODE_BLOCK_EXTERNAL_METHOD_THUNK:
         {
index 258e821..69be660 100644 (file)
 
 #include "common.h"
 
-//define function pointer type: EncodeModuleCallback
-//
+typedef DWORD(*ENCODEMODULE_CALLBACK)(LPVOID pModuleContext, CORINFO_MODULE_HANDLE moduleHandle);
 typedef DWORD (*EncodeModuleCallback)(void* pModuleContext, Module *pReferencedModule);
 enum {
     // return value when EncodeModule fails
     ENCODE_MODULE_FAILED         = 0xffffffff,
 };
 
-//define function pointer type: TokenDefinitionCallback
-//
+typedef void(*DEFINETOKEN_CALLBACK)(LPVOID pModuleContext, CORINFO_MODULE_HANDLE moduleHandle, DWORD index, mdTypeRef* token);
 typedef void (*TokenDefinitionCallback)(void* pModuleContext, Module *pReferencedModule, DWORD index, mdToken* refToken);
 
 class ZapSig