Skip to content

Commit fda2fee

Browse files
authored
Modify __int64 definition in PAL to match the OS definition (#77056)
* Modify __int64 definition in PAL to match the OS definition This change modifies the definition of __int64 and thus of many other types defined on the basis of it to match the OS definitions. This ensures that we can use these types in interfaces between code in coreclr and various PALs that are compiled against OS headers. The key issue was that we were defining __int64 for 64 bit OSes as long while Unix defines it as long long. The size of those types is the same on Unix, but they are different and result in different mangling of C++ names. * Fix coreclr tests build * Fix comment on #endif in jit.h * Reflect PR feedback * Fix jit source formatting * Fix FreeBSD build
1 parent 570b373 commit fda2fee

File tree

21 files changed

+250
-202
lines changed

21 files changed

+250
-202
lines changed

src/coreclr/debug/createdump/crashinfounix.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -376,8 +376,8 @@ CrashInfo::VisitProgramHeader(uint64_t loadbias, uint64_t baseAddress, Phdr* phd
376376
TRACE("VisitProgramHeader: ehFrameHdrStart %016llx ehFrameHdrSize %08llx\n", ehFrameHdrStart, ehFrameHdrSize);
377377
InsertMemoryRegion(ehFrameHdrStart, ehFrameHdrSize);
378378

379-
uint64_t ehFrameStart;
380-
uint64_t ehFrameSize;
379+
ULONG64 ehFrameStart;
380+
ULONG64 ehFrameSize;
381381
if (PAL_GetUnwindInfoSize(baseAddress, ehFrameHdrStart, ReadMemoryAdapter, &ehFrameStart, &ehFrameSize))
382382
{
383383
TRACE("VisitProgramHeader: ehFrameStart %016llx ehFrameSize %08llx\n", ehFrameStart, ehFrameSize);

src/coreclr/debug/inc/dacdbistructures.inl

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -640,8 +640,6 @@ void FieldData::ClearFields()
640640
m_pFldStaticAddress = NULL;
641641
}
642642

643-
typedef ULONG_PTR SIZE_T;
644-
645643
inline
646644
BOOL FieldData::OkToGetOrSetInstanceOffset()
647645
{

src/coreclr/inc/check.inl

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -220,6 +220,14 @@ inline CHECK CheckOverflow(const void *address, UINT64 offset)
220220
CHECK_OK;
221221
}
222222

223+
#if defined(HOST_UNIX) && defined(HOST_64BIT)
224+
inline CHECK CheckOverflow(const void *address, SIZE_T offset)
225+
{
226+
CHECK((UINT64) address + offset >= (UINT64) address);
227+
228+
CHECK_OK;
229+
}
230+
#endif // HOST_UNIX && HOST_BIT64
223231

224232
inline CHECK CheckUnderflow(UINT value1, UINT value2)
225233
{

src/coreclr/inc/clrtypes.h

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -338,6 +338,15 @@ inline UINT64 AlignUp(UINT64 value, UINT alignment)
338338
return (value+alignment-1)&~(UINT64)(alignment-1);
339339
}
340340

341+
#if defined(HOST_UNIX) && defined(HOST_64BIT)
342+
inline SIZE_T AlignUp(SIZE_T value, UINT alignment)
343+
{
344+
STATIC_CONTRACT_LEAF;
345+
STATIC_CONTRACT_SUPPORTS_DAC;
346+
return (value+alignment-1)&~(SIZE_T)(alignment-1);
347+
}
348+
#endif // HOST_UNIX && HOST_BIT64
349+
341350
inline UINT AlignDown(UINT value, UINT alignment)
342351
{
343352
STATIC_CONTRACT_LEAF;
@@ -381,6 +390,14 @@ inline UINT AlignmentPad(UINT64 value, UINT alignment)
381390
return (UINT) (AlignUp(value, alignment) - value);
382391
}
383392

393+
#if defined(HOST_UNIX) && defined(HOST_64BIT)
394+
inline UINT AlignmentPad(SIZE_T value, UINT alignment)
395+
{
396+
STATIC_CONTRACT_WRAPPER;
397+
return (UINT) (AlignUp(value, alignment) - value);
398+
}
399+
#endif // HOST_UNIX && HOST_BIT64
400+
384401
inline UINT AlignmentTrim(UINT value, UINT alignment)
385402
{
386403
STATIC_CONTRACT_LEAF;
@@ -406,4 +423,13 @@ inline UINT AlignmentTrim(UINT64 value, UINT alignment)
406423
return ((UINT)value)&(alignment-1);
407424
}
408425

426+
#if defined(HOST_UNIX) && defined(HOST_64BIT)
427+
inline UINT AlignmentTrim(SIZE_T value, UINT alignment)
428+
{
429+
STATIC_CONTRACT_LEAF;
430+
STATIC_CONTRACT_SUPPORTS_DAC;
431+
return ((UINT)value)&(alignment-1);
432+
}
433+
#endif // HOST_UNIX && HOST_BIT64
434+
409435
#endif // CLRTYPES_H_

src/coreclr/inc/daccess.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1027,6 +1027,12 @@ class __DPtrBase : public __TPtrBase
10271027
{
10281028
return DPtrType(DacTAddrOffset(m_addr, val, sizeof(type)));
10291029
}
1030+
#if defined(HOST_UNIX) && defined(HOST_64BIT)
1031+
DPtrType operator+(unsigned long long val)
1032+
{
1033+
return DPtrType(DacTAddrOffset(m_addr, val, sizeof(type)));
1034+
}
1035+
#endif // HOST_UNIX && HOST_BIT64
10301036
DPtrType operator+(short val)
10311037
{
10321038
return DPtrType(m_addr + val * sizeof(type));

src/coreclr/inc/regdisp.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -561,7 +561,7 @@ inline size_t * getRegAddr (unsigned regNum, PTR_CONTEXT regs)
561561
return (PTR_size_t)(PTR_BYTE(regs) + OFFSET_OF_REGISTERS[regNum]);
562562
#elif defined(TARGET_AMD64)
563563
_ASSERTE(regNum < 16);
564-
return &regs->Rax + regNum;
564+
return (size_t *)&regs->Rax + regNum;
565565
#elif defined(TARGET_ARM)
566566
_ASSERTE(regNum < 16);
567567
return (size_t *)&regs->R0 + regNum;

src/coreclr/jit/compiler.hpp

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -233,6 +233,13 @@ inline unsigned genLog2(unsigned __int64 value)
233233
#endif
234234
}
235235

236+
#if defined(HOST_UNIX) && defined(HOST_64BIT)
237+
inline unsigned genLog2(size_t value)
238+
{
239+
return genLog2((unsigned __int64)value);
240+
}
241+
#endif // HOST_UNIX && HOST_BIT64
242+
236243
/*****************************************************************************
237244
*
238245
* Return the lowest bit that is set in the given register mask.
@@ -1536,7 +1543,8 @@ void GenTree::BashToConst(T value, var_types type /* = TYP_UNDEF */)
15361543
{
15371544
static_assert_no_msg((std::is_same<T, int32_t>::value || std::is_same<T, int64_t>::value ||
15381545
std::is_same<T, long long>::value || std::is_same<T, float>::value ||
1539-
std::is_same<T, double>::value));
1546+
std::is_same<T, ssize_t>::value || std::is_same<T, double>::value));
1547+
15401548
static_assert_no_msg(sizeof(int64_t) == sizeof(long long));
15411549

15421550
var_types typeOfValue = TYP_UNDEF;

src/coreclr/jit/gentree.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3287,7 +3287,8 @@ inline void GenTreeIntConCommon::SetIntegralValue(int64_t value)
32873287
template <typename T>
32883288
inline void GenTreeIntConCommon::SetValueTruncating(T value)
32893289
{
3290-
static_assert_no_msg((std::is_same<T, int32_t>::value || std::is_same<T, int64_t>::value));
3290+
static_assert_no_msg(
3291+
(std::is_same<T, int32_t>::value || std::is_same<T, int64_t>::value || std::is_same<T, ssize_t>::value));
32913292

32923293
if (TypeIs(TYP_LONG))
32933294
{

src/coreclr/jit/jit.h

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -219,6 +219,8 @@
219219
#error Unsupported or unset target architecture
220220
#endif
221221

222+
typedef ptrdiff_t ssize_t;
223+
222224
// Include the AMD64 unwind codes when appropriate.
223225
#if defined(TARGET_AMD64)
224226
#include "win64unwind.h"
@@ -349,8 +351,6 @@ typedef int NATIVE_OFFSET;
349351
// this is used for native code sizes.
350352
typedef unsigned UNATIVE_OFFSET;
351353

352-
typedef ptrdiff_t ssize_t;
353-
354354
// Type used for weights (e.g. block and edge weights)
355355
typedef double weight_t;
356356

@@ -630,9 +630,16 @@ inline unsigned int unsigned_abs(int x)
630630

631631
#ifdef TARGET_64BIT
632632
inline size_t unsigned_abs(ssize_t x)
633+
{
634+
return ((size_t)abs((__int64)x));
635+
}
636+
637+
#ifdef HOST_UNIX
638+
inline size_t unsigned_abs(__int64 x)
633639
{
634640
return ((size_t)abs(x));
635641
}
642+
#endif // HOST_UNIX
636643
#endif // TARGET_64BIT
637644

638645
/*****************************************************************************/

src/coreclr/jit/register.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,10 +68,10 @@ REGALIAS(EDI, RDI)
6868

6969
#ifdef TARGET_AMD64
7070
#define XMMBASE 16
71-
#define XMMMASK(x) (__int64(1) << ((x)+XMMBASE))
71+
#define XMMMASK(x) ((__int64)(1) << ((x)+XMMBASE))
7272
#else // !TARGET_AMD64
7373
#define XMMBASE 8
74-
#define XMMMASK(x) (__int32(1) << ((x)+XMMBASE))
74+
#define XMMMASK(x) ((__int32)(1) << ((x)+XMMBASE))
7575
#endif // !TARGET_AMD64
7676

7777
REGDEF(XMM0, 0+XMMBASE, XMMMASK(0), "mm0" )

0 commit comments

Comments
 (0)