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

Coreclr gnuport #22129

Merged
merged 12 commits into from Feb 1, 2019
6 changes: 6 additions & 0 deletions src/inc/palclr.h
Expand Up @@ -31,6 +31,12 @@
#define _DEBUG_IMPL 1
#endif

#if __GNUC__
#ifndef __cdecl
#define __cdecl __attribute__((__cdecl__))
#endif
#endif

//
// CPP_ASSERT() can be used within a class definition, to perform a
// compile-time assertion involving private names within the class.
Expand Down
20 changes: 14 additions & 6 deletions src/inc/staticcontract.h
Expand Up @@ -15,6 +15,14 @@
#define SCAN_WIDEN2(x) L ## x
#define SCAN_WIDEN(x) SCAN_WIDEN2(x)

#ifndef NOINLINE
#if __GNUC__
#define NOINLINE __attribute__((noinline))
#else
#define NOINLINE __declspec(noinline)
#endif
#endif

//
// PDB annotations for the static contract analysis tool. These are seperated
// from Contract.h to allow their inclusion in any part of the system.
Expand Down Expand Up @@ -236,7 +244,7 @@ namespace StaticContract
{
struct ScanThrowMarkerStandard
{
__declspec(noinline) ScanThrowMarkerStandard()
NOINLINE ScanThrowMarkerStandard()
{
METHOD_CANNOT_BE_FOLDED_DEBUG;
STATIC_CONTRACT_THROWS;
Expand All @@ -251,7 +259,7 @@ namespace StaticContract

struct ScanThrowMarkerTerminal
{
__declspec(noinline) ScanThrowMarkerTerminal()
NOINLINE ScanThrowMarkerTerminal()
{
METHOD_CANNOT_BE_FOLDED_DEBUG;
}
Expand All @@ -263,7 +271,7 @@ namespace StaticContract

struct ScanThrowMarkerIgnore
{
__declspec(noinline) ScanThrowMarkerIgnore()
NOINLINE ScanThrowMarkerIgnore()
{
METHOD_CANNOT_BE_FOLDED_DEBUG;
}
Expand Down Expand Up @@ -340,21 +348,21 @@ template <UINT COUNT>
class BlockMarker
{
public:
__declspec(noinline) void MarkBlock()
NOINLINE void MarkBlock()
{
ANNOTATION_MARK_BLOCK_ANNOTATION;
METHOD_CANNOT_BE_FOLDED_DEBUG;
return;
}

__declspec(noinline) void UseMarkedBlockAnnotation()
NOINLINE void UseMarkedBlockAnnotation()
{
ANNOTATION_USE_BLOCK_ANNOTATION;
METHOD_CANNOT_BE_FOLDED_DEBUG;
return;
}

__declspec(noinline) void EndUseMarkedBlockAnnotation()
NOINLINE void EndUseMarkedBlockAnnotation()
{
ANNOTATION_END_USE_BLOCK_ANNOTATION;
METHOD_CANNOT_BE_FOLDED_DEBUG;
Expand Down
8 changes: 7 additions & 1 deletion src/pal/inc/mbusafecrt.h
Expand Up @@ -31,6 +31,12 @@ typedef int errno_t;
// define the return value for success
#define SAFECRT_SUCCESS 0

#if defined(_MSC_VER) || defined(__llvm__)
#define THROW_DECL
#else
#define THROW_DECL throw()
janvorli marked this conversation as resolved.
Show resolved Hide resolved
#endif

#ifdef __cplusplus
extern "C" {
#endif
Expand Down Expand Up @@ -98,7 +104,7 @@ extern int swscanf_s( const WCHAR *string, const WCHAR *format, ... );
extern int _snscanf_s( const char *string, size_t count, const char *format, ... );
extern int _snwscanf_s( const WCHAR *string, size_t count, const WCHAR *format, ... );

extern errno_t memcpy_s( void * dst, size_t sizeInBytes, const void * src, size_t count );
extern errno_t memcpy_s( void * dst, size_t sizeInBytes, const void * src, size_t count ) THROW_DECL;
extern errno_t memmove_s( void * dst, size_t sizeInBytes, const void * src, size_t count );

#ifdef __cplusplus
Expand Down
51 changes: 36 additions & 15 deletions src/pal/inc/pal.h
Expand Up @@ -143,6 +143,11 @@ typedef void * NATIVE_LIBRARY_HANDLE;
#define LANG_THAI 0x1e

/******************* Compiler-specific glue *******************************/
#if defined(_MSC_VER) || defined(__llvm__)
#define THROW_DECL
#else
#define THROW_DECL throw()
#endif

#ifndef _MSC_VER
#if defined(CORECLR)
Expand All @@ -156,7 +161,7 @@ typedef void * NATIVE_LIBRARY_HANDLE;
#if defined(_MSC_VER) || defined(__llvm__)
#define DECLSPEC_ALIGN(x) __declspec(align(x))
#else
#define DECLSPEC_ALIGN(x)
#define DECLSPEC_ALIGN(x) __attribute__ ((aligned(x)))
#endif

#define DECLSPEC_NORETURN PAL_NORETURN
Expand All @@ -176,6 +181,14 @@ typedef void * NATIVE_LIBRARY_HANDLE;
#endif
#endif

#ifndef NOOPT_ATTRIBUTE
#if defined(__llvm__)
#define NOOPT_ATTRIBUTE optnone
#else
#define NOOPT_ATTRIBUTE optimize("O0")
#endif
#endif

#ifndef PAL_STDCPP_COMPAT

#if __GNUC__
Expand Down Expand Up @@ -3503,7 +3516,7 @@ InterlockedExchange(
IN OUT LONG volatile *Target,
IN LONG Value)
{
LONG result = __sync_swap(Target, Value);
LONG result = __atomic_exchange_n(Target, Value, __ATOMIC_ACQ_REL);
PAL_ArmInterlockedOperationBarrier();
return result;
}
Expand All @@ -3517,7 +3530,7 @@ InterlockedExchange64(
IN OUT LONGLONG volatile *Target,
IN LONGLONG Value)
{
LONGLONG result = __sync_swap(Target, Value);
LONGLONG result = __atomic_exchange_n(Target, Value, __ATOMIC_ACQ_REL);
PAL_ArmInterlockedOperationBarrier();
return result;
}
Expand Down Expand Up @@ -4316,7 +4329,7 @@ PALIMPORT int __cdecl memcmp(const void *, const void *, size_t);
PALIMPORT void * __cdecl memset(void *, int, size_t);
PALIMPORT void * __cdecl memmove(void *, const void *, size_t);
PALIMPORT void * __cdecl memchr(const void *, int, size_t);
PALIMPORT long long int __cdecl atoll(const char *);
PALIMPORT long long int __cdecl atoll(const char *) THROW_DECL;
PALIMPORT size_t __cdecl strlen(const char *);
PALIMPORT int __cdecl strcmp(const char*, const char *);
PALIMPORT int __cdecl strncmp(const char*, const char *, size_t);
Expand Down Expand Up @@ -4355,7 +4368,7 @@ PALIMPORT int __cdecl toupper(int);
#define _TRUNCATE ((size_t)-1)
#endif

PALIMPORT errno_t __cdecl memcpy_s(void *, size_t, const void *, size_t);
PALIMPORT errno_t __cdecl memcpy_s(void *, size_t, const void *, size_t) THROW_DECL;
PALIMPORT errno_t __cdecl memmove_s(void *, size_t, const void *, size_t);
PALIMPORT char * __cdecl _strlwr(char *);
PALIMPORT int __cdecl _stricmp(const char *, const char *);
Expand Down Expand Up @@ -4426,7 +4439,15 @@ inline WCHAR *PAL_wcsstr(WCHAR *_S, const WCHAR *_P)
}
#endif

#if !__has_builtin(_rotl)
#if defined(__llvm__)
#define HAS_ROTL __has_builtin(_rotl)
#define HAS_ROTR __has_builtin(_rotr)
#else
#define HAS_ROTL 0
#define HAS_ROTR 0
#endif

#if !HAS_ROTL
/*++
Function:
_rotl
Expand All @@ -4444,14 +4465,14 @@ unsigned int __cdecl _rotl(unsigned int value, int shift)
retval = (value << shift) | (value >> (sizeof(int) * CHAR_BIT - shift));
return retval;
}
#endif // !__has_builtin(_rotl)
#endif // !HAS_ROTL

// On 64 bit unix, make the long an int.
#ifdef BIT64
#define _lrotl _rotl
#endif // BIT64

#if !__has_builtin(_rotr)
#if !HAS_ROTR

/*++
Function:
Expand All @@ -4471,7 +4492,7 @@ unsigned int __cdecl _rotr(unsigned int value, int shift)
return retval;
}

#endif // !__has_builtin(_rotr)
#endif // !HAS_ROTR

PALIMPORT int __cdecl abs(int);
// clang complains if this is declared with __int64
Expand All @@ -4487,10 +4508,10 @@ PALIMPORT double __cdecl acos(double);
PALIMPORT double __cdecl acosh(double);
PALIMPORT double __cdecl asin(double);
PALIMPORT double __cdecl asinh(double);
PALIMPORT double __cdecl atan(double);
PALIMPORT double __cdecl atanh(double);
PALIMPORT double __cdecl atan(double) THROW_DECL;
PALIMPORT double __cdecl atanh(double) THROW_DECL;
PALIMPORT double __cdecl atan2(double, double);
PALIMPORT double __cdecl cbrt(double);
PALIMPORT double __cdecl cbrt(double) THROW_DECL;
PALIMPORT double __cdecl ceil(double);
PALIMPORT double __cdecl cos(double);
PALIMPORT double __cdecl cosh(double);
Expand Down Expand Up @@ -4520,10 +4541,10 @@ PALIMPORT float __cdecl acosf(float);
PALIMPORT float __cdecl acoshf(float);
PALIMPORT float __cdecl asinf(float);
PALIMPORT float __cdecl asinhf(float);
PALIMPORT float __cdecl atanf(float);
PALIMPORT float __cdecl atanhf(float);
PALIMPORT float __cdecl atanf(float) THROW_DECL;
PALIMPORT float __cdecl atanhf(float) THROW_DECL;
PALIMPORT float __cdecl atan2f(float, float);
PALIMPORT float __cdecl cbrtf(float);
PALIMPORT float __cdecl cbrtf(float) THROW_DECL;
PALIMPORT float __cdecl ceilf(float);
PALIMPORT float __cdecl cosf(float);
PALIMPORT float __cdecl coshf(float);
Expand Down
4 changes: 4 additions & 0 deletions src/pal/inc/rt/safecrt.h
Expand Up @@ -135,7 +135,11 @@ typedef _W64 unsigned int uintptr_t;
#define _UINTPTR_T_DEFINED
#endif

#ifdef __GNUC__
#define SAFECRT_DEPRECATED __attribute__((deprecated))
#else
#define SAFECRT_DEPRECATED __declspec(deprecated)
#endif

/* errno_t */
#if !defined(_ERRCODE_DEFINED)
Expand Down
2 changes: 1 addition & 1 deletion src/pal/src/exception/seh-unwind.cpp
Expand Up @@ -444,7 +444,7 @@ PAL_FreeExceptionRecords(IN EXCEPTION_RECORD *exceptionRecord, IN CONTEXT *conte
--*/
PAL_NORETURN
__attribute__((noinline))
__attribute__((optnone))
__attribute__((NOOPT_ATTRIBUTE))
static void
RtlpRaiseException(EXCEPTION_RECORD *ExceptionRecord, CONTEXT *ContextRecord)
{
Expand Down
12 changes: 6 additions & 6 deletions src/pal/src/exception/seh.cpp
Expand Up @@ -394,12 +394,12 @@ bool CatchHardwareExceptionHolder::IsEnabled()

--*/

#ifdef __llvm__
__thread
#else // __llvm__
__declspec(thread)
#endif // !__llvm__
static NativeExceptionHolderBase *t_nativeExceptionHolderHead = nullptr;
#if defined(__GNUC__)
static __thread
janvorli marked this conversation as resolved.
Show resolved Hide resolved
#else // __GNUC__
__declspec(thread) static
#endif // !__GNUC__
NativeExceptionHolderBase *t_nativeExceptionHolderHead = nullptr;

extern "C"
NativeExceptionHolderBase **
Expand Down
6 changes: 3 additions & 3 deletions src/pal/src/include/pal/context.h
Expand Up @@ -486,7 +486,7 @@ inline static DWORD64 CONTEXTGetPC(LPCONTEXT pContext)
#elif defined(_ARM64_) || defined(_ARM_)
return pContext->Pc;
#else
#error don't know how to get the program counter for this architecture
#error "don't know how to get the program counter for this architecture"
franksinankaya marked this conversation as resolved.
Show resolved Hide resolved
#endif
}

Expand All @@ -499,7 +499,7 @@ inline static void CONTEXTSetPC(LPCONTEXT pContext, DWORD64 pc)
#elif defined(_ARM64_) || defined(_ARM_)
pContext->Pc = pc;
#else
#error don't know how to set the program counter for this architecture
#error "don't know how to set the program counter for this architecture"
#endif
}

Expand All @@ -514,7 +514,7 @@ inline static DWORD64 CONTEXTGetFP(LPCONTEXT pContext)
#elif defined(_ARM64_)
return pContext->Fp;
#else
#error don't know how to get the frame pointer for this architecture
#error "don't know how to get the frame pointer for this architecture"
#endif
}

Expand Down
2 changes: 1 addition & 1 deletion src/pal/src/init/pal.cpp
Expand Up @@ -239,7 +239,7 @@ PAL_SetInitializeDLLFlags(
real life scenarios work.

--*/
__attribute__((noinline,optnone))
__attribute__((noinline,NOOPT_ATTRIBUTE))
void
EnsureStackSize(SIZE_T stackSize)
{
Expand Down
10 changes: 5 additions & 5 deletions src/pal/src/locale/utf8.cpp
Expand Up @@ -1463,7 +1463,7 @@ class UTF8Encoding
}

// get pSrc 2-byte aligned
if (((int)pSrc & 0x1) != 0) {
if (((size_t)pSrc & 0x1) != 0) {
ch = *pSrc;
pSrc++;
if (ch > 0x7F) {
Expand All @@ -1472,7 +1472,7 @@ class UTF8Encoding
}

// get pSrc 4-byte aligned
if (((int)pSrc & 0x2) != 0) {
if (((size_t)pSrc & 0x2) != 0) {
ch = *(USHORT*)pSrc;
if ((ch & 0x8080) != 0) {
goto LongCodeWithMask16;
Expand Down Expand Up @@ -1902,7 +1902,7 @@ class UTF8Encoding
pTarget++;

// get pSrc to be 2-byte aligned
if ((((int)pSrc) & 0x1) != 0) {
if ((((size_t)pSrc) & 0x1) != 0) {
ch = *pSrc;
pSrc++;
if (ch > 0x7F) {
Expand All @@ -1913,7 +1913,7 @@ class UTF8Encoding
}

// get pSrc to be 4-byte aligned
if ((((int)pSrc) & 0x2) != 0) {
if ((((size_t)pSrc) & 0x2) != 0) {
ch = *(USHORT*)pSrc;
if ((ch & 0x8080) != 0) {
goto LongCodeWithMask16;
Expand Down Expand Up @@ -2736,7 +2736,7 @@ class UTF8Encoding
}

// get pSrc aligned
if (((int)pSrc & 0x2) != 0) {
if (((size_t)pSrc & 0x2) != 0) {
ch = *pSrc;
pSrc++;
if (ch > 0x7F) // Not ASCII
Expand Down
2 changes: 1 addition & 1 deletion src/pal/src/safecrt/memcpy_s.cpp
Expand Up @@ -54,7 +54,7 @@ errno_t __cdecl memcpy_s(
size_t sizeInBytes,
const void * src,
size_t count
)
) THROW_DECL
{
if (count == 0)
{
Expand Down
4 changes: 2 additions & 2 deletions src/pal/src/sync/cs.cpp
Expand Up @@ -627,7 +627,7 @@ namespace CorUnix
pPalCriticalSection->LockCount = 0;
pPalCriticalSection->RecursionCount = 0;
pPalCriticalSection->SpinCount = dwSpinCount;
pPalCriticalSection->OwningThread = NULL;
pPalCriticalSection->OwningThread = 0;
pPalCriticalSection->LockSemaphore = NULL;
pPalCriticalSection->fInternal = fInternal;

Expand Down Expand Up @@ -877,7 +877,7 @@ namespace CorUnix
}

// Reset CS ownership
pPalCriticalSection->OwningThread = NULL;
pPalCriticalSection->OwningThread = 0;

// Load the current LockCount value
lVal = pPalCriticalSection->LockCount;
Expand Down