diff --git a/libcxx/src/chrono.cpp b/libcxx/src/chrono.cpp --- a/libcxx/src/chrono.cpp +++ b/libcxx/src/chrono.cpp @@ -74,11 +74,17 @@ static _LIBCPP_CONSTEXPR const seconds nt_to_unix_epoch{11644473600}; FILETIME ft; -#if _WIN32_WINNT >= _WIN32_WINNT_WIN8 && WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_DESKTOP) - GetSystemTimePreciseAsFileTime(&ft); -#else - GetSystemTimeAsFileTime(&ft); -#endif + typedef void (*GetSysTime_t)(LPFILETIME); + static GetSysTime_t getSysTime_p; + + GetSysTime_t getSysTime_f = getSysTime_p; + if (nullptr == getSysTime_f) { + getSysTime_f = (GetSysTime_t)GetProcAddress(GetModuleHandleA("kernel32.dll"), "GetSystemTimePreciseAsFileTime"); + if (nullptr == getSysTime_f) + getSysTime_f = GetSystemTimeAsFileTime; + getSysTime_p = getSysTime_f; + } + getSysTime_f(&ft); filetime_duration d{(static_cast<__int64>(ft.dwHighDateTime) << 32) | static_cast<__int64>(ft.dwLowDateTime)};