summaryrefslogtreecommitdiff
path: root/src/pal/inc
diff options
context:
space:
mode:
authorSinan Kaya <41809318+franksinankaya@users.noreply.github.com>2019-02-01 10:27:39 -0500
committerJan Vorlicek <janvorli@microsoft.com>2019-02-01 16:27:39 +0100
commitfc7a8fbbc1754c8dd49f66f9b59c1ff12a5f842e (patch)
treeaebcfe9a9ea0f9381cf1c6ff184f3b96c852a65b /src/pal/inc
parenta8a05e8c595ae0b9e12333134f38e19acf981be4 (diff)
downloadcoreclr-fc7a8fbbc1754c8dd49f66f9b59c1ff12a5f842e.tar.gz
coreclr-fc7a8fbbc1754c8dd49f66f9b59c1ff12a5f842e.tar.bz2
coreclr-fc7a8fbbc1754c8dd49f66f9b59c1ff12a5f842e.zip
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')
-rw-r--r--src/pal/inc/mbusafecrt.h8
-rw-r--r--src/pal/inc/pal.h51
-rw-r--r--src/pal/inc/rt/safecrt.h4
3 files changed, 47 insertions, 16 deletions
diff --git a/src/pal/inc/mbusafecrt.h b/src/pal/inc/mbusafecrt.h
index f030b7ded2..9c516e032b 100644
--- a/src/pal/inc/mbusafecrt.h
+++ b/src/pal/inc/mbusafecrt.h
@@ -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()
+#endif
+
#ifdef __cplusplus
extern "C" {
#endif
@@ -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
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
+#else
+#define THROW_DECL throw()
+#endif
#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))
#else
-#define DECLSPEC_ALIGN(x)
+#define DECLSPEC_ALIGN(x) __attribute__ ((aligned(x)))
#endif
#define DECLSPEC_NORETURN PAL_NORETURN
@@ -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__
@@ -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;
}
@@ -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;
}
@@ -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)
#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 *);
@@ -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
@@ -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:
@@ -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);
diff --git a/src/pal/inc/rt/safecrt.h b/src/pal/inc/rt/safecrt.h
index 92366dfc38..9f9e15c244 100644
--- a/src/pal/inc/rt/safecrt.h
+++ b/src/pal/inc/rt/safecrt.h
@@ -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)