diff options
author | Jan Vorlicek <janvorli@microsoft.com> | 2017-10-03 22:09:43 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-10-03 22:09:43 +0200 |
commit | 08d39ddf02c81c99bd49c19b808c855235cbabdc (patch) | |
tree | f1314991120946c183cd58490db9219cbce596ca | |
parent | 4cfd557c2d1e80123d5a37aaea00636ddcc7be49 (diff) | |
download | coreclr-08d39ddf02c81c99bd49c19b808c855235cbabdc.tar.gz coreclr-08d39ddf02c81c99bd49c19b808c855235cbabdc.tar.bz2 coreclr-08d39ddf02c81c99bd49c19b808c855235cbabdc.zip |
Fix build with latest Xcode on OSX (#14282)
* Fix build with latest Xcode on OSX
The latest Xcode 9 cannot successfully build CoreCLR PAL. There are
several issues. First, it complains that min / max macros cannot be defined
in C++ code, since they would collide with the std::min and std::max
functions. Second, some of the headers that PAL includes pull in declarations
of several template classes that we explicitly define in PAL and also
the new operator declaration.
To fix that, I have undefined the min and max macros for PAL and replaced
their usage by the std::min / max functions. I have also removed the manual
declaration of the colliding template classes and new operator and added
inclusion of the proper C++ headers instead.
The PAL was including non-pal safemath.h and to make this change compatible
with it, I have added definition of USE_STL that makes safemath.h include
type_trait from STL instead of our local trimmed copy.
I have also removed some dead code that I have discovered during the process.
Fixes #14279
* Fix build on ARM32 and very recent GLIBCXX
-rw-r--r-- | src/pal/CMakeLists.txt | 1 | ||||
-rw-r--r-- | src/pal/src/cruntime/mbstring.cpp | 3 | ||||
-rw-r--r-- | src/pal/src/cruntime/printf.cpp | 77 | ||||
-rw-r--r-- | src/pal/src/cruntime/printfcpp.cpp | 77 | ||||
-rw-r--r-- | src/pal/src/cruntime/wchar.cpp | 3 | ||||
-rw-r--r-- | src/pal/src/exception/seh.cpp | 32 | ||||
-rw-r--r-- | src/pal/src/include/pal/cruntime.h | 18 | ||||
-rw-r--r-- | src/pal/src/include/pal/malloc.hpp | 4 | ||||
-rw-r--r-- | src/pal/src/include/pal/palinternal.h | 8 | ||||
-rw-r--r-- | src/pal/src/init/pal.cpp | 4 | ||||
-rw-r--r-- | src/pal/src/misc/cgroup.cpp | 7 | ||||
-rw-r--r-- | src/pal/src/misc/sysinfo.cpp | 21 | ||||
-rw-r--r-- | src/pal/src/numa/numa.cpp | 6 | ||||
-rw-r--r-- | src/pal/src/synchmgr/synchmanager.cpp | 10 |
14 files changed, 44 insertions, 227 deletions
diff --git a/src/pal/CMakeLists.txt b/src/pal/CMakeLists.txt index c687d832df..a510d25081 100644 --- a/src/pal/CMakeLists.txt +++ b/src/pal/CMakeLists.txt @@ -9,6 +9,7 @@ include_directories(${COREPAL_SOURCE_DIR}/src) include_directories(${COREPAL_SOURCE_DIR}/../inc) add_compile_options(-fexceptions) +add_definitions(-DUSE_STL) add_subdirectory(src) diff --git a/src/pal/src/cruntime/mbstring.cpp b/src/pal/src/cruntime/mbstring.cpp index ace2aa56c6..828e4a3240 100644 --- a/src/pal/src/cruntime/mbstring.cpp +++ b/src/pal/src/cruntime/mbstring.cpp @@ -31,6 +31,7 @@ Implementation Notes: #include "pal/palinternal.h" #include "pal/dbgmsg.h" +#include <algorithm> SET_DEFAULT_DEBUG_CHANNEL(CRT); @@ -125,7 +126,7 @@ _mbsninc( ret = (unsigned char *) string; if (GetCPInfo(CP_ACP, &cpinfo) && cpinfo.MaxCharSize == 1) { - ret += min(count, strlen((const char*)string)); + ret += std::min(count, strlen((const char*)string)); } else { diff --git a/src/pal/src/cruntime/printf.cpp b/src/pal/src/cruntime/printf.cpp index 72c7e11bea..6ae6263b74 100644 --- a/src/pal/src/cruntime/printf.cpp +++ b/src/pal/src/cruntime/printf.cpp @@ -47,83 +47,6 @@ static int SscanfFloatCheckExponent(LPCSTR buff, LPCSTR floatFmt, /******************************************************************************* Function: - Internal_AddPaddingA - -Parameters: - Out - - buffer to place padding and given string (In) - Count - - maximum chars to be copied so as not to overrun given buffer - In - - string to place into (Out) accompanied with padding - Padding - - number of padding chars to add - Flags - - padding style flags (PRINTF_FORMAT_FLAGS) -*******************************************************************************/ -BOOL Internal_AddPaddingA(LPSTR *Out, INT Count, LPSTR In, - INT Padding, INT Flags) -{ - LPSTR OutOriginal = *Out; - INT PaddingOriginal = Padding; - INT LengthInStr; - LengthInStr = strlen(In); - - - if (Padding < 0) - { - /* this is used at the bottom to determine if the buffer ran out */ - PaddingOriginal = 0; - } - if (Flags & PFF_MINUS) /* pad on right */ - { - if (strncpy_s(*Out, Count, In, min(LengthInStr + 1, Count)) != SAFECRT_SUCCESS) - { - return FALSE; - } - - *Out += min(LengthInStr, Count); - } - if (Padding > 0) - { - if (Flags & PFF_ZERO) /* '0', pad with zeros */ - { - while (Padding-- && Count > *Out - OutOriginal) - { - *(*Out)++ = '0'; - } - } - else /* pad left with spaces */ - { - while (Padding-- && Count > *Out - OutOriginal) - { - *(*Out)++ = ' '; - } - } - } - if (!(Flags & PFF_MINUS)) /* put 'In' after padding */ - { - if (strncpy_s(*Out, Count, In, - min(LengthInStr + 1, Count - (*Out - OutOriginal))) != SAFECRT_SUCCESS) - { - return FALSE; - } - - *Out += min(LengthInStr, Count - (*Out - OutOriginal)); - } - - if (LengthInStr + PaddingOriginal > Count) - { - return FALSE; - } - else - { - return TRUE; - } -} - -/******************************************************************************* -Function: PAL_printf_arg_remover Parameters: diff --git a/src/pal/src/cruntime/printfcpp.cpp b/src/pal/src/cruntime/printfcpp.cpp index 0b9072102b..662561b87b 100644 --- a/src/pal/src/cruntime/printfcpp.cpp +++ b/src/pal/src/cruntime/printfcpp.cpp @@ -776,83 +776,6 @@ BOOL Internal_ExtractFormatW(CPalThread *pthrCurrent, LPCWSTR *Fmt, LPSTR Out, L /******************************************************************************* Function: - Internal_AddPaddingW - -Parameters: - Out - - buffer to place padding and given string (In) - Count - - maximum chars to be copied so as not to overrun given buffer - In - - string to place into (Out) accompanied with padding - Padding - - number of padding chars to add - Flags - - padding style flags (PRINTF_FORMAT_FLAGS) -*******************************************************************************/ - -BOOL Internal_AddPaddingW(LPWSTR *Out, INT Count, LPWSTR In, INT Padding, INT Flags) -{ - LPWSTR OutOriginal = *Out; - INT PaddingOriginal = Padding; - INT LengthInStr; - LengthInStr = PAL_wcslen(In); - - - if (Padding < 0) - { - /* this is used at the bottom to determine if the buffer ran out */ - PaddingOriginal = 0; - } - if (Flags & PFF_MINUS) /* pad on right */ - { - if (wcsncpy_s(*Out, Count, In, min(LengthInStr + 1, Count - 1)) != SAFECRT_SUCCESS) - { - return FALSE; - } - - *Out += min(LengthInStr, Count - 1); - } - if (Padding > 0) - { - if (Flags & PFF_ZERO) /* '0', pad with zeros */ - { - while (Padding-- && Count > *Out - OutOriginal) - { - *(*Out)++ = '0'; - } - } - else /* pad left with spaces */ - { - while (Padding-- && Count > *Out - OutOriginal) - { - *(*Out)++ = ' '; - } - } - } - if (!(Flags & PFF_MINUS)) /* put 'In' after padding */ - { - if (wcsncpy_s(*Out, Count - (*Out - OutOriginal), In, - min(LengthInStr, Count - (*Out - OutOriginal) - 1)) != SAFECRT_SUCCESS) - { - return FALSE; - } - - *Out += min(LengthInStr, Count - (*Out - OutOriginal) - 1); - } - - if (LengthInStr + PaddingOriginal > Count - 1) - { - return FALSE; - } - else - { - return TRUE; - } -} - -/******************************************************************************* -Function: Internal_AddPaddingVfprintf Parameters: diff --git a/src/pal/src/cruntime/wchar.cpp b/src/pal/src/cruntime/wchar.cpp index 5b466960a6..c93a3d5edf 100644 --- a/src/pal/src/cruntime/wchar.cpp +++ b/src/pal/src/cruntime/wchar.cpp @@ -41,6 +41,7 @@ Abstract: #endif #include <errno.h> +#include <algorithm> SET_DEFAULT_DEBUG_CHANNEL(CRT); @@ -1237,7 +1238,7 @@ PAL_wcsncpy( wchar_16 * strDest, const wchar_16 *strSource, size_t count ) strDest, strSource, strSource, (unsigned long) count); memset( strDest, 0, length ); - length = min( count, PAL_wcslen( strSource ) ) * sizeof( wchar_16 ); + length = std::min( count, PAL_wcslen( strSource ) ) * sizeof( wchar_16 ); memcpy( strDest, strSource, length ); LOGEXIT("wcsncpy returning (wchar_16*): %p\n", strDest); diff --git a/src/pal/src/exception/seh.cpp b/src/pal/src/exception/seh.cpp index 2d1c18218a..9f5f074f18 100644 --- a/src/pal/src/exception/seh.cpp +++ b/src/pal/src/exception/seh.cpp @@ -39,37 +39,7 @@ Abstract: #include <unistd.h> #include <pthread.h> #include <stdlib.h> - -// Define the std::move so that we don't have to include the <utility> header -// which on some platforms pulls in STL stuff that collides with PAL stuff. -// The std::move is needed to enable using move constructor and assignment operator -// for PAL_SEHException. -namespace std -{ - template<typename T> - struct remove_reference - { - typedef T type; - }; - - template<typename T> - struct remove_reference<T&> - { - typedef T type; - }; - - template<typename T> - struct remove_reference<T&&> - { - typedef T type; - }; - - template<class T> inline - typename remove_reference<T>::type&& move(T&& arg) - { // forward arg as movable - return ((typename remove_reference<T>::type&&)arg); - } -} +#include <utility> using namespace CorUnix; diff --git a/src/pal/src/include/pal/cruntime.h b/src/pal/src/include/pal/cruntime.h index 65bf33c952..3b3fa7b3f8 100644 --- a/src/pal/src/include/pal/cruntime.h +++ b/src/pal/src/include/pal/cruntime.h @@ -98,24 +98,6 @@ typedef enum /******************************************************************************* Function: - Internal_AddPaddingA - -Parameters: - Out - - buffer to place padding and given string (In) - Count - - maximum chars to be copied so as not to overrun given buffer - In - - string to place into (Out) accompanied with padding - Padding - - number of padding chars to add - Flags - - padding style flags (PRINTF_FORMAT_FLAGS) -*******************************************************************************/ -BOOL Internal_AddPaddingA(LPSTR *Out, INT Count, LPSTR In, INT Padding, INT Flags); - -/******************************************************************************* -Function: PAL_printf_arg_remover Parameters: diff --git a/src/pal/src/include/pal/malloc.hpp b/src/pal/src/include/pal/malloc.hpp index c7333419a7..9faf4273d9 100644 --- a/src/pal/src/include/pal/malloc.hpp +++ b/src/pal/src/include/pal/malloc.hpp @@ -25,6 +25,7 @@ Abstract: #include <stdarg.h> #include <stdlib.h> +#include <new> extern "C" { @@ -54,9 +55,6 @@ extern "C" ); } -inline void* operator new(size_t, void* p) throw () { return p; } -inline void* operator new[](size_t, void* p) throw () { return p; } - namespace CorUnix{ void * diff --git a/src/pal/src/include/pal/palinternal.h b/src/pal/src/include/pal/palinternal.h index 12312a3018..abebcb545e 100644 --- a/src/pal/src/include/pal/palinternal.h +++ b/src/pal/src/include/pal/palinternal.h @@ -153,6 +153,11 @@ function_name() to call the system's implementation #define _ENABLE_DEBUG_MESSAGES_ 0 #endif +/* Include type_traits before including the pal.h. On newer glibcxx versions, + the type_traits fail to compile if we redefine the wchar_t before including + the header */ +#include <type_traits> + #ifdef PAL_PERF #include "pal_perf.h" #endif @@ -534,6 +539,9 @@ function_name() to call the system's implementation #undef ctime +#undef min +#undef max + #undef SCHAR_MIN #undef SCHAR_MAX #undef UCHAR_MAX diff --git a/src/pal/src/init/pal.cpp b/src/pal/src/init/pal.cpp index 37c1677f38..996292e2c4 100644 --- a/src/pal/src/init/pal.cpp +++ b/src/pal/src/init/pal.cpp @@ -83,6 +83,8 @@ int CacheLineSize; #include <kvm.h> #endif +#include <algorithm> + using namespace CorUnix; // @@ -218,7 +220,7 @@ InitializeDefaultStackSize() if (errno == 0) { - g_defaultStackSize = max(size, PTHREAD_STACK_MIN); + g_defaultStackSize = std::max(size, (long int)PTHREAD_STACK_MIN); } } diff --git a/src/pal/src/misc/cgroup.cpp b/src/pal/src/misc/cgroup.cpp index ec0a0bd5fb..7a3a9261a1 100644 --- a/src/pal/src/misc/cgroup.cpp +++ b/src/pal/src/misc/cgroup.cpp @@ -17,6 +17,7 @@ SET_DEFAULT_DEBUG_CHANNEL(MISC); #include "pal/palinternal.h" #include <sys/resource.h> #include "pal/virtual.h" +#include <algorithm> #define PROC_MOUNTINFO_FILENAME "/proc/self/mountinfo" #define PROC_CGROUP_FILENAME "/proc/self/cgroup" @@ -362,7 +363,7 @@ PAL_GetRestrictedPhysicalMemoryLimit() { rlimit_soft_limit = curr_rlimit.rlim_cur; } - physical_memory_limit = min(physical_memory_limit, rlimit_soft_limit); + physical_memory_limit = std::min(physical_memory_limit, rlimit_soft_limit); // Ensure that limit is not greater than real memory size long pages = sysconf(_SC_PHYS_PAGES); @@ -371,8 +372,8 @@ PAL_GetRestrictedPhysicalMemoryLimit() long pageSize = sysconf(_SC_PAGE_SIZE); if (pageSize != -1) { - physical_memory_limit = min(physical_memory_limit, - (size_t)pages * pageSize); + physical_memory_limit = std::min(physical_memory_limit, + (size_t)(pages * pageSize)); } } diff --git a/src/pal/src/misc/sysinfo.cpp b/src/pal/src/misc/sysinfo.cpp index a06f4b75cb..cb5dda62a8 100644 --- a/src/pal/src/misc/sysinfo.cpp +++ b/src/pal/src/misc/sysinfo.cpp @@ -81,6 +81,7 @@ Revision History: #include "pal/dbgmsg.h" +#include <algorithm> SET_DEFAULT_DEBUG_CHANNEL(MISC); @@ -437,16 +438,16 @@ PAL_GetLogicalProcessorCacheSizeFromOS() size_t cacheSize = 0; #ifdef _SC_LEVEL1_DCACHE_SIZE - cacheSize = max(cacheSize, sysconf(_SC_LEVEL1_DCACHE_SIZE)); + cacheSize = std::max(cacheSize, (size_t)sysconf(_SC_LEVEL1_DCACHE_SIZE)); #endif #ifdef _SC_LEVEL2_CACHE_SIZE - cacheSize = max(cacheSize, sysconf(_SC_LEVEL2_CACHE_SIZE)); + cacheSize = std::max(cacheSize, (size_t)sysconf(_SC_LEVEL2_CACHE_SIZE)); #endif #ifdef _SC_LEVEL3_CACHE_SIZE - cacheSize = max(cacheSize, sysconf(_SC_LEVEL3_CACHE_SIZE)); + cacheSize = std::max(cacheSize, (size_t)sysconf(_SC_LEVEL3_CACHE_SIZE)); #endif #ifdef _SC_LEVEL4_CACHE_SIZE - cacheSize = max(cacheSize, sysconf(_SC_LEVEL4_CACHE_SIZE)); + cacheSize = std::max(cacheSize, (size_t)sysconf(_SC_LEVEL4_CACHE_SIZE)); #endif #if defined(_ARM64_) @@ -455,15 +456,15 @@ PAL_GetLogicalProcessorCacheSizeFromOS() size_t size; if(ReadMemoryValueFromFile("/sys/devices/system/cpu/cpu0/cache/index0/size", &size)) - cacheSize = max(cacheSize, size); + cacheSize = std::max(cacheSize, size); if(ReadMemoryValueFromFile("/sys/devices/system/cpu/cpu0/cache/index1/size", &size)) - cacheSize = max(cacheSize, size); + cacheSize = std::max(cacheSize, size); if(ReadMemoryValueFromFile("/sys/devices/system/cpu/cpu0/cache/index2/size", &size)) - cacheSize = max(cacheSize, size); + cacheSize = std::max(cacheSize, size); if(ReadMemoryValueFromFile("/sys/devices/system/cpu/cpu0/cache/index3/size", &size)) - cacheSize = max(cacheSize, size); + cacheSize = std::max(cacheSize, size); if(ReadMemoryValueFromFile("/sys/devices/system/cpu/cpu0/cache/index4/size", &size)) - cacheSize = max(cacheSize, size); + cacheSize = std::max(cacheSize, size); } if(cacheSize == 0) @@ -488,7 +489,7 @@ PAL_GetLogicalProcessorCacheSizeFromOS() // Assume L3$/CPU grows linearly from 256K to 1.5M/CPU as logicalCPUs grows from 2 to 12 CPUs DWORD logicalCPUs = PAL_GetLogicalCpuCountFromOS(); - cacheSize = logicalCPUs*min(1536, max(256, logicalCPUs*128))*1024; + cacheSize = logicalCPUs*std::min(1536, std::max(256, logicalCPUs*128))*1024; } #endif diff --git a/src/pal/src/numa/numa.cpp b/src/pal/src/numa/numa.cpp index 383fb0e3b0..6e4593d0b3 100644 --- a/src/pal/src/numa/numa.cpp +++ b/src/pal/src/numa/numa.cpp @@ -32,6 +32,8 @@ SET_DEFAULT_DEBUG_CHANNEL(NUMA); #include <pthread.h> #include <dlfcn.h> +#include <algorithm> + #include "numashim.h" using namespace CorUnix; @@ -630,7 +632,7 @@ SetThreadAffinityMask( if (st == 0) { - for (int i = 0; i < min(8 * sizeof(KAFFINITY), g_possibleCpuCount); i++) + for (int i = 0; i < std::min(8 * (int)sizeof(KAFFINITY), g_possibleCpuCount); i++) { if (CPU_ISSET(i, &prevCpuSet)) { @@ -978,4 +980,4 @@ SetThreadIdealProcessorEx( PERF_EXIT(SetThreadIdealProcessorEx); return success; -}
\ No newline at end of file +} diff --git a/src/pal/src/synchmgr/synchmanager.cpp b/src/pal/src/synchmgr/synchmanager.cpp index 048ea3ee7d..349b3de135 100644 --- a/src/pal/src/synchmgr/synchmanager.cpp +++ b/src/pal/src/synchmgr/synchmanager.cpp @@ -39,6 +39,10 @@ SET_DEFAULT_DEBUG_CHANNEL(SYNC); // some headers have code with asserts, so do t #include "pal/fakepoll.h" #endif // HAVE_POLL +#include <algorithm> + +const int CorUnix::CThreadSynchronizationInfo::PendingSignalingsArraySize; + // We use the synchronization manager's worker thread to handle // process termination requests. It does so by calling the // registered handler function. @@ -4146,7 +4150,7 @@ namespace CorUnix ERROR("Failed creating thread synchronization mutex [error=%d (%s)]\n", iRet, strerror(iRet)); if (EAGAIN == iRet && MaxUnavailableResourceRetries >= ++iEagains) { - poll(NULL, 0, min(100,10*iEagains)); + poll(NULL, 0, std::min(100,10*iEagains)); goto Mutex_retry; } else if (ENOMEM == iRet) @@ -4172,7 +4176,7 @@ namespace CorUnix "[error=%d (%s)]\n", iRet, strerror(iRet)); if (EAGAIN == iRet && MaxUnavailableResourceRetries >= ++iEagains) { - poll(NULL, 0, min(100,10*iEagains)); + poll(NULL, 0, std::min(100,10*iEagains)); goto Cond_retry; } else if (ENOMEM == iRet) @@ -4361,7 +4365,7 @@ namespace CorUnix if (0 < m_lPendingSignalingCount) { - LONG lArrayPendingSignalingCount = min(PendingSignalingsArraySize, m_lPendingSignalingCount); + LONG lArrayPendingSignalingCount = std::min(PendingSignalingsArraySize, m_lPendingSignalingCount); LONG lIdx = 0; PAL_ERROR palTempErr; |