diff --git a/libcxx/docs/index.rst b/libcxx/docs/index.rst --- a/libcxx/docs/index.rst +++ b/libcxx/docs/index.rst @@ -85,25 +85,46 @@ Platform and Compiler Support ----------------------------- -libc++ is known to work on the following platforms, using gcc and -clang. -Note that functionality provided by ```` is only functional with clang -and GCC. +For using the libc++ headers +############################ +The libc++ headers are known to work on the following platforms, using GCC and +Clang. Note that functionality provided by ```` is only functional with +Clang and GCC. + +============ ==================== ============ +OS Arch Compilers +============ ==================== ============ +macOS 10.9+ i386, x86_64 Clang, GCC +FreeBSD 10+ i386, x86_64, ARM Clang, GCC +Linux i386, x86_64 Clang, GCC +============ ==================== ============ + +The following minimum compiler versions are required: + +* Clang 4.0 and above +* GCC 5.0 and above. + +The C++03 dialect is only supported with Clang. + +For building the libc++ library +############################### +Building the libc++ library (static or shared) requires some features from +the operating system. As such, it has its own set of (slightly different) +system requirements. ============ ==================== ============ ======================== OS Arch Compilers ABI Library ============ ==================== ============ ======================== -macOS i386, x86_64 Clang, GCC libc++abi +macOS 10.12+ i386, x86_64 Clang, GCC libc++abi FreeBSD 10+ i386, x86_64, ARM Clang, GCC libcxxrt, libc++abi Linux i386, x86_64 Clang, GCC libc++abi ============ ==================== ============ ======================== -The following minimum compiler versions are strongly recommended. +The following minimum compiler versions are required: * Clang 4.0 and above * GCC 5.0 and above. -The C++03 dialect is only supported for Clang compilers. C++ Dialect Support --------------------- diff --git a/libcxx/src/chrono.cpp b/libcxx/src/chrono.cpp --- a/libcxx/src/chrono.cpp +++ b/libcxx/src/chrono.cpp @@ -9,7 +9,7 @@ #include "chrono" #include "cerrno" // errno #include "system_error" // __throw_system_error -#include // clock_gettime, CLOCK_MONOTONIC and CLOCK_REALTIME +#include // clock_gettime and CLOCK_{MONOTONIC,REALTIME,MONOTONIC_RAW} #include "include/apple_availability.h" #if __has_include() @@ -21,28 +21,20 @@ #endif #if defined(_LIBCPP_WIN32API) -#define WIN32_LEAN_AND_MEAN -#define VC_EXTRA_LEAN -#include -#if _WIN32_WINNT >= _WIN32_WINNT_WIN8 -#include -#endif +# define WIN32_LEAN_AND_MEAN +# define VC_EXTRA_LEAN +# include +# if _WIN32_WINNT >= _WIN32_WINNT_WIN8 +# include +# endif #else -#if !defined(CLOCK_REALTIME) || !defined(_LIBCPP_USE_CLOCK_GETTIME) -#include // for gettimeofday and timeval -#endif +# if !defined(CLOCK_REALTIME) +# include // for gettimeofday and timeval +# endif // !defined(CLOCK_REALTIME) #endif // defined(_LIBCPP_WIN32API) -#if !defined(_LIBCPP_HAS_NO_MONOTONIC_CLOCK) -#if __APPLE__ -#include // mach_absolute_time, mach_timebase_info_data_t -#elif !defined(_LIBCPP_WIN32API) && !defined(CLOCK_MONOTONIC) -#error "Monotonic clock not implemented" -#endif -#endif - #if defined(__ELF__) && defined(_LIBCPP_LINK_RT_LIB) -#pragma comment(lib, "rt") +# pragma comment(lib, "rt") #endif _LIBCPP_BEGIN_NAMESPACE_STD @@ -82,7 +74,7 @@ static_cast<__int64>(ft.dwLowDateTime)}; return time_point(duration_cast(d - nt_to_unix_epoch)); #else -#if defined(_LIBCPP_USE_CLOCK_GETTIME) && defined(CLOCK_REALTIME) +#if defined(CLOCK_REALTIME) struct timespec tp; if (0 != clock_gettime(CLOCK_REALTIME, &tp)) __throw_system_error(errno, "clock_gettime(CLOCK_REALTIME) failed"); @@ -91,7 +83,7 @@ timeval tv; gettimeofday(&tv, 0); return time_point(seconds(tv.tv_sec) + microseconds(tv.tv_usec)); -#endif // _LIBCPP_USE_CLOCK_GETTIME && CLOCK_REALTIME +#endif // CLOCK_REALTIME #endif } @@ -118,8 +110,15 @@ #if defined(__APPLE__) -// Darwin libc versions >= 1133 provide ns precision via CLOCK_MONOTONIC_RAW -#if defined(_LIBCPP_USE_CLOCK_GETTIME) && defined(CLOCK_MONOTONIC_RAW) +#if !defined(CLOCK_MONOTONIC_RAW) +# error "Building libc++ on Apple platforms requires CLOCK_MONOTONIC_RAW" +#endif + +// On Apple platforms, only CLOCK_UPTIME_RAW, CLOCK_MONOTONIC_RAW or +// mach_absolute_time are able to time functions in the nanosecond range. +// Furthermore, only CLOCK_MONOTONIC_RAW is truly monotonic, because it +// also counts cycles when the system is asleep. Thus, it is the only +// acceptable implementation of steady_clock. steady_clock::time_point steady_clock::now() _NOEXCEPT { @@ -129,60 +128,6 @@ return time_point(seconds(tp.tv_sec) + nanoseconds(tp.tv_nsec)); } -#else -// mach_absolute_time() * MachInfo.numer / MachInfo.denom is the number of -// nanoseconds since the computer booted up. MachInfo.numer and MachInfo.denom -// are run time constants supplied by the OS. This clock has no relationship -// to the Gregorian calendar. It's main use is as a high resolution timer. - -// MachInfo.numer / MachInfo.denom is often 1 on the latest equipment. Specialize -// for that case as an optimization. - -static -steady_clock::rep -steady_simplified() -{ - return static_cast(mach_absolute_time()); -} - -static -double -compute_steady_factor() -{ - mach_timebase_info_data_t MachInfo; - mach_timebase_info(&MachInfo); - return static_cast(MachInfo.numer) / MachInfo.denom; -} - -static -steady_clock::rep -steady_full() -{ - static const double factor = compute_steady_factor(); - return static_cast(mach_absolute_time() * factor); -} - -typedef steady_clock::rep (*FP)(); - -static -FP -init_steady_clock() -{ - mach_timebase_info_data_t MachInfo; - mach_timebase_info(&MachInfo); - if (MachInfo.numer == MachInfo.denom) - return &steady_simplified; - return &steady_full; -} - -steady_clock::time_point -steady_clock::now() _NOEXCEPT -{ - static FP fp = init_steady_clock(); - return time_point(duration(fp())); -} -#endif // defined(_LIBCPP_USE_CLOCK_GETTIME) && defined(CLOCK_MONOTONIC_RAW) - #elif defined(_LIBCPP_WIN32API) // https://msdn.microsoft.com/en-us/library/windows/desktop/ms644905(v=vs.85).aspx says: @@ -210,13 +155,6 @@ #elif defined(CLOCK_MONOTONIC) -// On Apple platforms only CLOCK_UPTIME_RAW, CLOCK_MONOTONIC_RAW or -// mach_absolute_time are able to time functions in the nanosecond range. -// Thus, they are the only acceptable implementations of steady_clock. -#ifdef __APPLE__ -#error "Never use CLOCK_MONOTONIC for steady_clock::now on Apple platforms" -#endif - steady_clock::time_point steady_clock::now() _NOEXCEPT { @@ -227,7 +165,7 @@ } #else -#error "Monotonic clock not implemented" +# error "Monotonic clock not implemented" #endif #endif // !_LIBCPP_HAS_NO_MONOTONIC_CLOCK diff --git a/libcxx/src/filesystem/operations.cpp b/libcxx/src/filesystem/operations.cpp --- a/libcxx/src/filesystem/operations.cpp +++ b/libcxx/src/filesystem/operations.cpp @@ -36,13 +36,9 @@ #define _LIBCPP_USE_COPYFILE #endif -#if !defined(__APPLE__) && _POSIX_TIMERS > 0 -#define _LIBCPP_USE_CLOCK_GETTIME -#endif - -#if !defined(CLOCK_REALTIME) || !defined(_LIBCPP_USE_CLOCK_GETTIME) +#if !defined(CLOCK_REALTIME) #include // for gettimeofday and timeval -#endif // !defined(CLOCK_REALTIME) +#endif // !defined(CLOCK_REALTIME) #if defined(__ELF__) && defined(_LIBCPP_LINK_RT_LIB) #pragma comment(lib, "rt") @@ -490,7 +486,7 @@ _FilesystemClock::time_point _FilesystemClock::now() noexcept { typedef chrono::duration __secs; -#if defined(_LIBCPP_USE_CLOCK_GETTIME) && defined(CLOCK_REALTIME) +#if defined(CLOCK_REALTIME) typedef chrono::duration __nsecs; struct timespec tp; if (0 != clock_gettime(CLOCK_REALTIME, &tp)) @@ -502,7 +498,7 @@ timeval tv; gettimeofday(&tv, 0); return time_point(__secs(tv.tv_sec) + __microsecs(tv.tv_usec)); -#endif // _LIBCPP_USE_CLOCK_GETTIME && CLOCK_REALTIME +#endif // CLOCK_REALTIME } filesystem_error::~filesystem_error() {} diff --git a/libcxx/src/include/apple_availability.h b/libcxx/src/include/apple_availability.h --- a/libcxx/src/include/apple_availability.h +++ b/libcxx/src/include/apple_availability.h @@ -28,24 +28,6 @@ #endif #endif // __ENVIRONMENT_.*_VERSION_MIN_REQUIRED__ -#if defined(__ENVIRONMENT_MAC_OS_X_VERSION_MIN_REQUIRED__) -#if __ENVIRONMENT_MAC_OS_X_VERSION_MIN_REQUIRED__ >= 101200 -#define _LIBCPP_USE_CLOCK_GETTIME -#endif -#elif defined(__ENVIRONMENT_IPHONE_OS_VERSION_MIN_REQUIRED__) -#if __ENVIRONMENT_IPHONE_OS_VERSION_MIN_REQUIRED__ >= 100000 -#define _LIBCPP_USE_CLOCK_GETTIME -#endif -#elif defined(__ENVIRONMENT_TV_OS_VERSION_MIN_REQUIRED__) -#if __ENVIRONMENT_TV_OS_VERSION_MIN_REQUIRED__ >= 100000 -#define _LIBCPP_USE_CLOCK_GETTIME -#endif -#elif defined(__ENVIRONMENT_WATCH_OS_VERSION_MIN_REQUIRED__) -#if __ENVIRONMENT_WATCH_OS_VERSION_MIN_REQUIRED__ >= 30000 -#define _LIBCPP_USE_CLOCK_GETTIME -#endif -#endif // __ENVIRONMENT_.*_VERSION_MIN_REQUIRED__ - #if defined(__ENVIRONMENT_MAC_OS_X_VERSION_MIN_REQUIRED__) #if __ENVIRONMENT_MAC_OS_X_VERSION_MIN_REQUIRED__ >= 101500 #define _LIBCPP_USE_ULOCK