Skip to content
This repository was archived by the owner on Jan 23, 2023. It is now read-only.

Commit 1a24a27

Browse files
echesakovjkotas
authored andcommitted
Cross-bitness in ZapRelocs (#18665)
* 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
1 parent 634b609 commit 1a24a27

File tree

4 files changed

+15
-9
lines changed

4 files changed

+15
-9
lines changed

src/zap/common.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,12 @@
2727
#endif
2828
#endif // !_TARGET_X86_ || FEATURE_PAL
2929

30+
#ifdef _TARGET_64BIT_
31+
typedef unsigned __int64 TARGET_POINTER_TYPE;
32+
#else
33+
typedef unsigned int TARGET_POINTER_TYPE;
34+
#endif
35+
3036
#include "utilcode.h"
3137
#include "corjit.h"
3238
#include "jithost.h"

src/zap/zapimport.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -362,12 +362,12 @@ void ZapImport::Save(ZapWriter * pZapWriter)
362362
{
363363
if (IsReadyToRunCompilation())
364364
{
365-
SIZE_T value = 0;
365+
TARGET_POINTER_TYPE value = 0;
366366
pZapWriter->Write(&value, sizeof(value));
367367
return;
368368
}
369369

370-
SIZE_T token = CORCOMPILE_TAG_TOKEN(GetBlob()->GetRVA());
370+
TARGET_POINTER_TYPE token = CORCOMPILE_TAG_TOKEN(GetBlob()->GetRVA());
371371
pZapWriter->Write(&token, sizeof(token));
372372
}
373373

@@ -639,7 +639,7 @@ class ZapStubDispatchCell : public ZapImport
639639
{
640640
ZapImage * pImage = ZapImage::GetImage(pZapWriter);
641641

642-
PVOID cell;
642+
TARGET_POINTER_TYPE cell;
643643
pImage->WriteReloc(&cell, 0, m_pDelayLoadHelper, 0, IMAGE_REL_BASED_PTR);
644644
pZapWriter->Write(&cell, sizeof(cell));
645645
}
@@ -745,7 +745,7 @@ class ZapExternalMethodCell : public ZapImport
745745
{
746746
ZapImage * pImage = ZapImage::GetImage(pZapWriter);
747747

748-
PVOID cell;
748+
TARGET_POINTER_TYPE cell;
749749
pImage->WriteReloc(&cell, 0, m_pDelayLoadHelper, 0, IMAGE_REL_BASED_PTR);
750750
pZapWriter->Write(&cell, sizeof(cell));
751751
}
@@ -1725,7 +1725,7 @@ class ZapDynamicHelperCell : public ZapImport
17251725
{
17261726
ZapImage * pImage = ZapImage::GetImage(pZapWriter);
17271727

1728-
PVOID cell;
1728+
TARGET_POINTER_TYPE cell;
17291729
pImage->WriteReloc(&cell, 0, m_pDelayLoadHelper, 0, IMAGE_REL_BASED_PTR);
17301730
pZapWriter->Write(&cell, sizeof(cell));
17311731
}

src/zap/zapinfo.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2574,7 +2574,7 @@ void ZapInfo::recordRelocation(void *location, void *target,
25742574
break;
25752575

25762576
case IMAGE_REL_BASED_PTR:
2577-
*(UNALIGNED TADDR *)location = (TADDR)targetOffset;
2577+
*(UNALIGNED TARGET_POINTER_TYPE *)location = (TARGET_POINTER_TYPE)targetOffset;
25782578
break;
25792579

25802580
#if defined(_TARGET_X86_) || defined(_TARGET_AMD64_)

src/zap/zaprelocs.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ void ZapBaseRelocs::WriteReloc(PVOID pSrc, int offset, ZapNode * pTarget, int ta
4848
// Misaligned relocs disable ASLR on ARM. We should never ever emit them.
4949
_ASSERTE(IS_ALIGNED(rva, TARGET_POINTER_SIZE));
5050
#endif
51-
*(UNALIGNED TADDR *)pLocation = pActualTarget;
51+
*(UNALIGNED TARGET_POINTER_TYPE *)pLocation = (TARGET_POINTER_TYPE)pActualTarget;
5252
break;
5353

5454
case IMAGE_REL_BASED_RELPTR:
@@ -92,7 +92,7 @@ void ZapBaseRelocs::WriteReloc(PVOID pSrc, int offset, ZapNode * pTarget, int ta
9292
// description of IMAGE_REL_BASED_REL_THUMB_MOV32_PCREL
9393
const UINT32 offsetCorrection = 12;
9494

95-
UINT32 imm32 = pActualTarget - (pSite + offsetCorrection);
95+
UINT32 imm32 = UINT32(pActualTarget - (pSite + offsetCorrection));
9696

9797
PutThumb2Mov32((UINT16 *)pLocation, imm32);
9898

@@ -122,7 +122,7 @@ void ZapBaseRelocs::WriteReloc(PVOID pSrc, int offset, ZapNode * pTarget, int ta
122122
}
123123
// IMAGE_REL_BASED_THUMB_BRANCH24 does not need base reloc entry
124124
return;
125-
#endif
125+
#endif // defined(_TARGET_ARM_)
126126
#if defined(_TARGET_ARM64_)
127127
case IMAGE_REL_ARM64_BRANCH26:
128128
{

0 commit comments

Comments
 (0)