* Abstract away NOINLINE statement
MSVC and GNU compilers use different attributes for noinline.
Abstract away compiler differences.
* Replace __sync_swap with __atomic_exchange_n
__sync_swap doesn't exist on GNU. Replacing with __atomic_exchange_n
which is universally available.
* Define CDECL for GNUC
__cdecl is not defined by default on GNU compilers.
* Define gcc version of __declspec(thread)
* Correct pointer casting
A pointer value is usually unsigned long on most platforms.
Casting it to integer causes signedness issues. Use size_t
to be efficient on all 32 and 64 bit architectures.
* Put quotes around the error string
Correct error statement. GNU G++ is picky about the string
following the error statement with ' character in it. It needs
to be enclosed with double quotes.
* Fix casting problem
Seeing these warnings with GNU G++ compiler
src/pal/src/sync/cs.cpp: In function ‘void CorUnix::InternalInitializeCriticalSectionAndSpinCount(PCRITICAL_SECTION, DWORD, bool)’:
src/pal/src/sync/cs.cpp:630:48: warning: converting to non-pointer type ‘SIZE_T {aka long unsigned int}’ from NULL [-Wconversion-null]
pPalCriticalSection->OwningThread = NULL;
^
src/pal/src/sync/cs.cpp: In function ‘void CorUnix::InternalLeaveCriticalSection(CorUnix::CPalThread*, _CRITICAL_SECTION*)’:
src/pal/src/sync/cs.cpp:880:43: warning: converting to non-pointer type ‘SIZE_T {aka long unsigned int}’ from NULL [-Wconversion-null]
pPalCriticalSection->OwningThread = NULL;
^
* Abstract optnone compiler attribute
GNU compiler doesn't support optnone attribute.
pal/src/exception/seh-unwind.cpp:449:77: warning: ‘optnone’ attribute directive ignored [-Wattributes]
* Set the aligned attribute for GNU compiler
* Make __rotl and __rotr functions portable
GNU compiler doesn't have an intrinsic for these. Open code them
using the provided implementation.
* Define deprecated attribute for gcc
* Add throw specifier for GCC
/usr/include/string.h:43:28: error: declaration of ‘void* memcpy(void*, const void*, size_t) throw ()’ has a different exception specifier
size_t __n) __THROW __nonnull ((1, 2));
Commit migrated from https://github.com/dotnet/coreclr/commit/
fc7a8fbbc1754c8dd49f66f9b59c1ff12a5f842e
#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.
#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.
{
struct ScanThrowMarkerStandard
{
- __declspec(noinline) ScanThrowMarkerStandard()
+ NOINLINE ScanThrowMarkerStandard()
{
METHOD_CANNOT_BE_FOLDED_DEBUG;
STATIC_CONTRACT_THROWS;
struct ScanThrowMarkerTerminal
{
- __declspec(noinline) ScanThrowMarkerTerminal()
+ NOINLINE ScanThrowMarkerTerminal()
{
METHOD_CANNOT_BE_FOLDED_DEBUG;
}
struct ScanThrowMarkerIgnore
{
- __declspec(noinline) ScanThrowMarkerIgnore()
+ NOINLINE ScanThrowMarkerIgnore()
{
METHOD_CANNOT_BE_FOLDED_DEBUG;
}
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;
// define the return value for success
#define SAFECRT_SUCCESS 0
+#if defined(_MSC_VER) || defined(__llvm__)
+#define THROW_DECL
+#else
+#define THROW_DECL throw()
+#endif
+
#ifdef __cplusplus
extern "C" {
#endif
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
#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)
#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
#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__
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;
}
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;
}
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);
#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 *);
}
#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
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:
return retval;
}
-#endif // !__has_builtin(_rotr)
+#endif // !HAS_ROTR
PALIMPORT int __cdecl abs(int);
// clang complains if this is declared with __int64
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);
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);
#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)
--*/
PAL_NORETURN
__attribute__((noinline))
-__attribute__((optnone))
+__attribute__((NOOPT_ATTRIBUTE))
static void
RtlpRaiseException(EXCEPTION_RECORD *ExceptionRecord, CONTEXT *ContextRecord)
{
--*/
-#ifdef __llvm__
-__thread
-#else // __llvm__
-__declspec(thread)
-#endif // !__llvm__
-static NativeExceptionHolderBase *t_nativeExceptionHolderHead = nullptr;
+#if defined(__GNUC__)
+static __thread
+#else // __GNUC__
+__declspec(thread) static
+#endif // !__GNUC__
+NativeExceptionHolderBase *t_nativeExceptionHolderHead = nullptr;
extern "C"
NativeExceptionHolderBase **
#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"
#endif
}
#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
}
#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
}
real life scenarios work.
--*/
-__attribute__((noinline,optnone))
+__attribute__((noinline,NOOPT_ATTRIBUTE))
void
EnsureStackSize(SIZE_T stackSize)
{
}
// get pSrc 2-byte aligned
- if (((int)pSrc & 0x1) != 0) {
+ if (((size_t)pSrc & 0x1) != 0) {
ch = *pSrc;
pSrc++;
if (ch > 0x7F) {
}
// 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;
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) {
}
// 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;
}
// get pSrc aligned
- if (((int)pSrc & 0x2) != 0) {
+ if (((size_t)pSrc & 0x2) != 0) {
ch = *pSrc;
pSrc++;
if (ch > 0x7F) // Not ASCII
size_t sizeInBytes,
const void * src,
size_t count
-)
+) THROW_DECL
{
if (count == 0)
{
pPalCriticalSection->LockCount = 0;
pPalCriticalSection->RecursionCount = 0;
pPalCriticalSection->SpinCount = dwSpinCount;
- pPalCriticalSection->OwningThread = NULL;
+ pPalCriticalSection->OwningThread = 0;
pPalCriticalSection->LockSemaphore = NULL;
pPalCriticalSection->fInternal = fInternal;
}
// Reset CS ownership
- pPalCriticalSection->OwningThread = NULL;
+ pPalCriticalSection->OwningThread = 0;
// Load the current LockCount value
lVal = pPalCriticalSection->LockCount;
ASSIGN_REG(X28)
#else
-#error Don't know how to assign registers on this architecture
+#error "Don't know how to assign registers on this architecture"
#endif
#define ASSIGN_ALL_REGS \
return PAL_InitializeDLL();
}
-__attribute__((noinline,optnone))
+__attribute__((noinline,NOOPT_ATTRIBUTE))
static void FailingFunction(volatile int *p)
{
if (p == NULL)
return PAL_InitializeDLL();
}
-__attribute__((noinline,optnone))
+__attribute__((noinline,NOOPT_ATTRIBUTE))
static void FailingFunction(volatile int *p)
{
if (p == NULL)