path: root/src/pal/inc/pal.h
diff options
authorSinan Kaya <>2019-02-01 10:27:39 -0500
committerJan Vorlicek <>2019-02-01 16:27:39 +0100
commitfc7a8fbbc1754c8dd49f66f9b59c1ff12a5f842e (patch)
treeaebcfe9a9ea0f9381cf1c6ff184f3b96c852a65b /src/pal/inc/pal.h
parenta8a05e8c595ae0b9e12333134f38e19acf981be4 (diff)
Coreclr gnuport (#22129)
* 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));
Diffstat (limited to 'src/pal/inc/pal.h')
1 files changed, 36 insertions, 15 deletions
diff --git a/src/pal/inc/pal.h b/src/pal/inc/pal.h
index 76e04cdbdb..7bf34963fc 100644
--- a/src/pal/inc/pal.h
+++ b/src/pal/inc/pal.h
@@ -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
+#define THROW_DECL throw()
#ifndef _MSC_VER
#if defined(CORECLR)
@@ -156,7 +161,7 @@ typedef void * NATIVE_LIBRARY_HANDLE;
#if defined(_MSC_VER) || defined(__llvm__)
#define DECLSPEC_ALIGN(x) __declspec(align(x))
-#define DECLSPEC_ALIGN(x)
+#define DECLSPEC_ALIGN(x) __attribute__ ((aligned(x)))
@@ -176,6 +181,14 @@ typedef void * NATIVE_LIBRARY_HANDLE;
+#if defined(__llvm__)
+#define NOOPT_ATTRIBUTE optnone
+#define NOOPT_ATTRIBUTE optimize("O0")
#if __GNUC__
@@ -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);
return result;
@@ -3517,7 +3530,7 @@ InterlockedExchange64(
IN OUT LONGLONG volatile *Target,
- LONGLONG result = __sync_swap(Target, Value);
+ LONGLONG result = __atomic_exchange_n(Target, Value, __ATOMIC_ACQ_REL);
return result;
@@ -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);
@@ -4355,7 +4368,7 @@ PALIMPORT int __cdecl toupper(int);
#define _TRUNCATE ((size_t)-1)
-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 *);
@@ -4426,7 +4439,15 @@ inline WCHAR *PAL_wcsstr(WCHAR *_S, const WCHAR *_P)
-#if !__has_builtin(_rotl)
+#if defined(__llvm__)
+#define HAS_ROTL __has_builtin(_rotl)
+#define HAS_ROTR __has_builtin(_rotr)
+#define HAS_ROTL 0
+#define HAS_ROTR 0
+#if !HAS_ROTL
@@ -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
@@ -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
@@ -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);
@@ -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);