Cross-bitness in ZapRelocs (#18665)
authorEgor Chesakov <Egor.Chesakov@microsoft.com>
Wed, 27 Jun 2018 23:50:15 +0000 (16:50 -0700)
committerJan Kotas <jkotas@microsoft.com>
Wed, 27 Jun 2018 23:50:15 +0000 (16:50 -0700)
* Cast to UINT32 to avoid warnings on Windows in ZapBaseRelocs::WriteReloc in src/zap/zaprelocs.cpp

* Replace TADDR with DWORD in ZapInfo::recordRelocation IMAGE_REL_BASED_PTR in src/zap/zapinfo.cpp

* Replace sizeof(cell) with TARGET_POINTER_SIZE in src/zap/zapimport.cpp

* Replace TADDR with DWORD in ZapBaseRelocs::WriteReloc IMAGE_REL_BASED_PTR in src/zap/zaprelocs.cpp

* Define target_size_t type

* Replace TADDR with target_size_t in ZapInfo::recordRelocation in src/zap/zapinfo.cpp

* Replace SIZE_T PVOID with target_size_t in src/zap/zapimport.cpp

* Replace TADDR with target_size_t in src/zap/zaprelocs.cpp

* Rename target_size_t to TARGET_POINTER_TYPE

src/zap/common.h
src/zap/zapimport.cpp
src/zap/zapinfo.cpp
src/zap/zaprelocs.cpp

index 3db0b84..c4397c2 100644 (file)
 #endif
 #endif // !_TARGET_X86_ || FEATURE_PAL
 
+#ifdef _TARGET_64BIT_
+typedef unsigned __int64 TARGET_POINTER_TYPE;
+#else
+typedef unsigned int TARGET_POINTER_TYPE;
+#endif
+
 #include "utilcode.h"
 #include "corjit.h"
 #include "jithost.h"
index 49ec137..e35d0b9 100644 (file)
@@ -362,12 +362,12 @@ void ZapImport::Save(ZapWriter * pZapWriter)
 {
     if (IsReadyToRunCompilation())
     {
-        SIZE_T value = 0;
+        TARGET_POINTER_TYPE value = 0;
         pZapWriter->Write(&value, sizeof(value));
         return;
     }
 
-    SIZE_T token = CORCOMPILE_TAG_TOKEN(GetBlob()->GetRVA());
+    TARGET_POINTER_TYPE token = CORCOMPILE_TAG_TOKEN(GetBlob()->GetRVA());
     pZapWriter->Write(&token, sizeof(token));
 }
 
@@ -639,7 +639,7 @@ public:
     {
         ZapImage * pImage = ZapImage::GetImage(pZapWriter);
 
-        PVOID cell;
+        TARGET_POINTER_TYPE cell;
         pImage->WriteReloc(&cell, 0, m_pDelayLoadHelper, 0, IMAGE_REL_BASED_PTR);
         pZapWriter->Write(&cell, sizeof(cell));
     }
@@ -745,7 +745,7 @@ public:
     {
         ZapImage * pImage = ZapImage::GetImage(pZapWriter);
 
-        PVOID cell;
+        TARGET_POINTER_TYPE cell;
         pImage->WriteReloc(&cell, 0, m_pDelayLoadHelper, 0, IMAGE_REL_BASED_PTR);
         pZapWriter->Write(&cell, sizeof(cell));
     }
@@ -1725,7 +1725,7 @@ public:
     {
         ZapImage * pImage = ZapImage::GetImage(pZapWriter);
 
-        PVOID cell;
+        TARGET_POINTER_TYPE cell;
         pImage->WriteReloc(&cell, 0, m_pDelayLoadHelper, 0, IMAGE_REL_BASED_PTR);
         pZapWriter->Write(&cell, sizeof(cell));
     }
index 634a63e..40ab579 100644 (file)
@@ -2574,7 +2574,7 @@ void ZapInfo::recordRelocation(void *location, void *target,
         break;
 
     case IMAGE_REL_BASED_PTR:
-        *(UNALIGNED TADDR *)location = (TADDR)targetOffset;
+        *(UNALIGNED TARGET_POINTER_TYPE *)location = (TARGET_POINTER_TYPE)targetOffset;
         break;
 
 #if defined(_TARGET_X86_) || defined(_TARGET_AMD64_)
index 3718f2c..abfa76b 100644 (file)
@@ -48,7 +48,7 @@ void ZapBaseRelocs::WriteReloc(PVOID pSrc, int offset, ZapNode * pTarget, int ta
         // Misaligned relocs disable ASLR on ARM. We should never ever emit them.
         _ASSERTE(IS_ALIGNED(rva, TARGET_POINTER_SIZE));
 #endif
-        *(UNALIGNED TADDR *)pLocation = pActualTarget;
+        *(UNALIGNED TARGET_POINTER_TYPE *)pLocation = (TARGET_POINTER_TYPE)pActualTarget;
         break;
 
     case IMAGE_REL_BASED_RELPTR:
@@ -92,7 +92,7 @@ void ZapBaseRelocs::WriteReloc(PVOID pSrc, int offset, ZapNode * pTarget, int ta
             // description of IMAGE_REL_BASED_REL_THUMB_MOV32_PCREL
             const UINT32 offsetCorrection = 12;
 
-            UINT32 imm32 = pActualTarget - (pSite + offsetCorrection);
+            UINT32 imm32 = UINT32(pActualTarget - (pSite + offsetCorrection));
 
             PutThumb2Mov32((UINT16 *)pLocation, imm32);
 
@@ -122,7 +122,7 @@ void ZapBaseRelocs::WriteReloc(PVOID pSrc, int offset, ZapNode * pTarget, int ta
         }
         // IMAGE_REL_BASED_THUMB_BRANCH24 does not need base reloc entry
         return;
-#endif
+#endif // defined(_TARGET_ARM_)
 #if defined(_TARGET_ARM64_)
     case IMAGE_REL_ARM64_BRANCH26:
         {