diff --git CMake/folly-deps.cmake CMake/folly-deps.cmake index 41a513a30..70f5b589d 100644 --- CMake/folly-deps.cmake +++ CMake/folly-deps.cmake @@ -246,7 +246,7 @@ check_cxx_source_compiles(" FOLLY_STDLIB_LIBCPP ) -if (APPLE) +if (APPLE AND FOLLY_STDLIB_LIBCXX) list (APPEND CMAKE_REQUIRED_LIBRARIES c++abi) list (APPEND FOLLY_LINK_LIBRARIES c++abi) endif () diff --git CMakeLists.txt CMakeLists.txt index 318a38316..9b54d5b1e 100644 --- CMakeLists.txt +++ CMakeLists.txt @@ -668,7 +668,7 @@ TEST compression_alias_fano_bit_vector_coding_test SOURCES BitVectorCodingTest.cpp TEST compression_alias_fano_elias_fano_test - SOURCES EliasFanoCodingTest.cpp + APPLE_DISABLED SOURCES EliasFanoCodingTest.cpp DIRECTORY container/test/ TEST container_access_test SOURCES AccessTest.cpp @@ -1057,7 +1057,7 @@ TEST atomic_hash_map_test HANGING SOURCES AtomicHashMapTest.cpp TEST atomic_linked_list_test SOURCES AtomicLinkedListTest.cpp - TEST atomic_unordered_map_test SOURCES AtomicUnorderedMapTest.cpp + TEST atomic_unordered_map_test APPLE_DISABLED SOURCES AtomicUnorderedMapTest.cpp TEST base64_test SOURCES base64_test.cpp TEST buffered_atomic_test SOURCES BufferedAtomicTest.cpp TEST cancellation_token_test SOURCES CancellationTokenTest.cpp @@ -1072,7 +1072,7 @@ TEST cpu_id_test SOURCES CpuIdTest.cpp TEST demangle_test SOURCES DemangleTest.cpp TEST deterministic_schedule_test SOURCES DeterministicScheduleTest.cpp - TEST discriminated_ptr_test SOURCES DiscriminatedPtrTest.cpp + TEST discriminated_ptr_test APPLE_DISABLED SOURCES DiscriminatedPtrTest.cpp TEST endian_test SOURCES EndianTest.cpp TEST exception_string_test BROKEN SOURCES ExceptionStringTest.cpp TEST exception_test SOURCES ExceptionTest.cpp diff --git folly/ConstexprMath.h folly/ConstexprMath.h index 3eb0fd76a..6a620aa65 100644 --- folly/ConstexprMath.h +++ folly/ConstexprMath.h @@ -44,15 +44,25 @@ using enable_if_floating_t = /// /// mimic: std::numbers::e_v, C++20 template +#if defined(__ppc__) || defined(__i386__) +inline constexpr T e_v = detail::enable_if_floating_t( + 2.71828182845904523536028747135266250); +#else inline constexpr T e_v = detail::enable_if_floating_t( 2.71828182845904523536028747135266249775724709369995L); +#endif /// ln2_v /// /// mimic: std::numbers::ln2_v, C++20 template +#if defined(__ppc__) || defined(__i386__) +inline constexpr T ln2_v = detail::enable_if_floating_t( + 0.693147180559945309417232121458176568); +#else inline constexpr T ln2_v = detail::enable_if_floating_t( 0.69314718055994530941723212145817656807550013436025L); +#endif /// e /// diff --git folly/DiscriminatedPtr.h folly/DiscriminatedPtr.h index be8a9d523..5985afb94 100644 --- folly/DiscriminatedPtr.h +++ folly/DiscriminatedPtr.h @@ -33,8 +33,8 @@ #include #include -#if !FOLLY_X64 && !FOLLY_AARCH64 && !FOLLY_PPC64 && !FOLLY_RISCV64 -#error "DiscriminatedPtr is x64, arm64, ppc64 and riscv64 specific code." +#if !FOLLY_X64 && !FOLLY_AARCH64 && !FOLLY_PPC && !FOLLY_PPC64 && !FOLLY_RISCV64 +#error "DiscriminatedPtr is x64, arm64, ppc, ppc64 and riscv64 specific code." #endif namespace folly { diff --git folly/File.cpp folly/File.cpp index b0ac777ce..38bd0882b 100644 --- folly/File.cpp +++ folly/File.cpp @@ -120,8 +120,10 @@ File File::dupCloseOnExec() const { int fd; #ifdef _WIN32 fd = ::dup(fd_); -#else +#elif defined(F_DUPFD_CLOEXEC) fd = ::fcntl(fd_, F_DUPFD_CLOEXEC, 0); +#else + fd = ::dup(fd_); #endif checkUnixError(fd, "dup() failed"); diff --git folly/Portability.h folly/Portability.h index 874de15ac..f157b1128 100644 --- folly/Portability.h +++ folly/Portability.h @@ -119,12 +119,18 @@ constexpr bool kHasUnalignedAccess = false; #define FOLLY_AARCH64 0 #endif -#if defined(__powerpc64__) +#if defined(__powerpc64__) || defined(__ppc64__) #define FOLLY_PPC64 1 #else #define FOLLY_PPC64 0 #endif +#if defined(__ppc__) +#define FOLLY_PPC 1 +#else +#define FOLLY_PPC 0 +#endif + #if defined(__s390x__) #define FOLLY_S390X 1 #else @@ -142,6 +148,7 @@ constexpr bool kIsArchArm = FOLLY_ARM == 1; constexpr bool kIsArchAmd64 = FOLLY_X64 == 1; constexpr bool kIsArchAArch64 = FOLLY_AARCH64 == 1; constexpr bool kIsArchPPC64 = FOLLY_PPC64 == 1; +constexpr bool kIsArchPPC = FOLLY_PPC == 1; constexpr bool kIsArchS390X = FOLLY_S390X == 1; constexpr bool kIsArchRISCV64 = FOLLY_RISCV64 == 1; } // namespace folly @@ -306,6 +313,9 @@ constexpr auto kIsLittleEndian = false; #else constexpr auto kIsLittleEndian = true; #endif +#elif defined(__APPLE__) && defined(__POWERPC__) +// Darwin ppc/ppc64 +constexpr auto kIsLittleEndian = false; #else constexpr auto kIsLittleEndian = __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__; #endif diff --git folly/Synchronized.h folly/Synchronized.h index 5bb2587be..5cb6e5f6f 100644 --- folly/Synchronized.h +++ folly/Synchronized.h @@ -1510,8 +1510,10 @@ class LockedPtr { SynchronizedType* parent() const { using simulacrum = typename SynchronizedType::Simulacrum; +#ifndef __ppc__ static_assert(sizeof(simulacrum) == sizeof(SynchronizedType), "mismatch"); static_assert(alignof(simulacrum) == alignof(SynchronizedType), "mismatch"); +#endif auto off = offsetof(simulacrum, mutex_); const auto raw = reinterpret_cast(lock_.mutex()); return reinterpret_cast(raw - (raw ? off : 0)); diff --git folly/io/async/AsyncUDPSocket.cpp folly/io/async/AsyncUDPSocket.cpp index 4db5e5ab0..0e2349e44 100644 --- folly/io/async/AsyncUDPSocket.cpp +++ folly/io/async/AsyncUDPSocket.cpp @@ -262,6 +262,7 @@ void AsyncUDPSocket::init(sa_family_t family, BindOptions bindOptions) { "failed to set IPV6_RECVTCLASS on the socket", errno); } + #ifdef IP_RECVTOS } else if (family == AF_INET) { if (netops::setsockopt( socket, IPPROTO_IP, IP_RECVTOS, &flag, sizeof(flag)) != 0) { @@ -270,6 +271,7 @@ void AsyncUDPSocket::init(sa_family_t family, BindOptions bindOptions) { "failed to set IP_RECVTOS on the socket", errno); } + #endif } } diff --git folly/io/async/fdsock/AsyncFdSocket.h folly/io/async/fdsock/AsyncFdSocket.h index d3d84bb58..8fbfbd9ba 100644 --- folly/io/async/fdsock/AsyncFdSocket.h +++ folly/io/async/fdsock/AsyncFdSocket.h @@ -19,6 +19,16 @@ #include #include +#ifdef __APPLE__ +#include +#if MAC_OS_X_VERSION_MIN_REQUIRED < 110000 +#ifdef __DARWIN_ALIGN32 +#undef __DARWIN_ALIGN32 +#define __DARWIN_ALIGN32(p) ((__darwin_size_t)((__darwin_size_t)(p) + __DARWIN_ALIGNBYTES32) &~ __DARWIN_ALIGNBYTES32) +#endif +#endif +#endif + namespace folly { // Including `gtest/gtest_prod.h` would make gtest/gmock a hard dep diff --git folly/net/NetOps.h folly/net/NetOps.h index 71c1883df..c7aecaecd 100644 --- folly/net/NetOps.h +++ folly/net/NetOps.h @@ -261,6 +261,16 @@ struct mmsghdr { #define F_COPY_CMSG_INT_DATA(cm, val, len) memcpy(CMSG_DATA(cm), val, len) #endif /* _WIN32 */ +#ifndef IPV6_TCLASS +#if defined(__APPLE__) +#define IPV6_TCLASS 36 +#endif +#endif + +#ifndef AI_NUMERICSERV +#define AI_NUMERICSERV 0 +#endif + namespace folly { namespace netops { // Poll descriptor is intended to be byte-for-byte identical to pollfd, diff --git folly/net/TcpInfoTypes.h folly/net/TcpInfoTypes.h index 09a8a9907..d3a6caac4 100644 --- folly/net/TcpInfoTypes.h +++ folly/net/TcpInfoTypes.h @@ -179,7 +179,7 @@ struct tcp_info_legacy { __u32 tcpi_total_retrans; }; -#elif defined(__APPLE__) +#elif defined(__APPLE__) && MAC_OS_X_VERSION_MIN_REQUIRED > 101003 #define FOLLY_HAVE_TCP_INFO 1 using tcp_info = ::tcp_connection_info; const int tcp_info_sock_opt = TCP_CONNECTION_INFO; diff --git folly/portability/Asm.h folly/portability/Asm.h index e71da91c7..2fdafe6cf 100644 --- folly/portability/Asm.h +++ folly/portability/Asm.h @@ -43,8 +43,12 @@ inline void asm_volatile_pause() { asm volatile("isb"); #elif (defined(__arm__) && !(__ARM_ARCH < 7)) asm volatile("yield"); -#elif FOLLY_PPC64 - asm volatile("or 27,27,27"); +#elif FOLLY_PPC || FOLLY_PPC64 + #ifdef __APPLE__ + __asm__ volatile ("or r27,r27,r27" ::: "memory"); + #else + asm volatile("or 27,27,27"); + #endif #endif } } // namespace folly diff --git folly/portability/Time.cpp folly/portability/Time.cpp index 4039ea814..cb4fda71c 100644 --- folly/portability/Time.cpp +++ folly/portability/Time.cpp @@ -37,11 +37,13 @@ static void duration_to_ts( #if !FOLLY_HAVE_CLOCK_GETTIME || FOLLY_FORCE_CLOCK_GETTIME_DEFINITION #if __MACH__ #include +#include #include // @manual #include // @manual #include // @manual #include // @manual #include // @manual +#include // for MacOS <= Lion #include // @manual #include // @manual @@ -64,6 +66,7 @@ static int clock_process_cputime(struct timespec* ts) { } // Get CPU usage for terminated threads. +#ifdef MACH_TASK_BASIC_INFO mach_task_basic_info task_basic_info; mach_msg_type_number_t task_basic_info_count = MACH_TASK_BASIC_INFO_COUNT; kern_result = task_info( @@ -74,6 +77,18 @@ static int clock_process_cputime(struct timespec* ts) { if (FOLLY_UNLIKELY(kern_result != KERN_SUCCESS)) { return -1; } +#else + task_basic_info task_basic_info; + mach_msg_type_number_t task_basic_info_count = TASK_BASIC_INFO_COUNT; + kern_result = task_info( + mach_task_self(), + TASK_BASIC_INFO, + (thread_info_t)&task_basic_info, + &task_basic_info_count); + if (FOLLY_UNLIKELY(kern_result != KERN_SUCCESS)) { + return -1; + } +#endif auto cputime = time_value_to_ns(thread_times_info.user_time) + time_value_to_ns(thread_times_info.system_time) + @@ -99,6 +114,7 @@ static int clock_thread_cputime(struct timespec* ts) { return 0; } +#if defined(__APPLE__) && MAC_OS_X_VERSION_MIN_REQUIRED > 101100 FOLLY_ATTR_WEAK int clock_gettime(clockid_t clk_id, struct timespec* ts) { switch (folly::to_underlying(clk_id)) { case CLOCK_REALTIME: { @@ -120,6 +136,7 @@ FOLLY_ATTR_WEAK int clock_gettime(clockid_t clk_id, struct timespec* ts) { return -1; } } +#endif int clock_getres(clockid_t clk_id, struct timespec* ts) { if (clk_id != CLOCK_MONOTONIC) { @@ -190,6 +207,7 @@ extern "C" int clock_getres(clockid_t clock_id, struct timespec* res) { res->tv_nsec = time_t(perSec * kNsPerSec); return 0; } +#if defined(__APPLE__) && MAC_OS_X_VERSION_MIN_REQUIRED > 101100 case CLOCK_PROCESS_CPUTIME_ID: case CLOCK_THREAD_CPUTIME_ID: { DWORD adj, timeIncrement; @@ -203,6 +221,7 @@ extern "C" int clock_getres(clockid_t clock_id, struct timespec* res) { res->tv_nsec = long(timeIncrement * 100); return 0; } +#endif default: errno = EINVAL; @@ -236,6 +255,7 @@ extern "C" int clock_gettime(clockid_t clock_id, struct timespec* tp) { duration_to_ts(now, tp); return 0; } +#if defined(__APPLE__) && MAC_OS_X_VERSION_MIN_REQUIRED > 101100 case CLOCK_PROCESS_CPUTIME_ID: { if (!GetProcessTimes( GetCurrentProcess(), @@ -268,6 +288,7 @@ extern "C" int clock_gettime(clockid_t clock_id, struct timespec* tp) { filetimeToUnsignedNanos(kernalTime) + filetimeToUnsignedNanos(userTime)); } +#endif default: errno = EINVAL; diff --git folly/synchronization/AtomicRef.h folly/synchronization/AtomicRef.h index b82c47155..7904a6c52 100644 --- folly/synchronization/AtomicRef.h +++ folly/synchronization/AtomicRef.h @@ -168,9 +168,11 @@ struct make_atomic_ref_t { typename T, std::enable_if_t< std::is_trivially_copyable_v && - sizeof(T) == sizeof(std::atomic) && - alignof(T) == alignof(std::atomic), - int> = 0> + sizeof(T) == sizeof(std::atomic) +#ifndef __ppc__ + && alignof(T) == alignof(std::atomic) +#endif + , int> = 0> atomic_ref operator()(T& ref) const { return atomic_ref{ref}; } diff --git folly/synchronization/NativeSemaphore.h folly/synchronization/NativeSemaphore.h index f894eed63..2d7c195af 100644 --- folly/synchronization/NativeSemaphore.h +++ folly/synchronization/NativeSemaphore.h @@ -20,13 +20,17 @@ #include #include +#if defined(__APPLE__) +#include +#endif + #include #include #include #if defined(_WIN32) -#elif defined(__APPLE__) +#elif defined(__APPLE__) && (MAC_OS_X_VERSION_MIN_REQUIRED > 1050) && !defined(__ppc__) #include // @manual @@ -94,7 +98,7 @@ class NativeSemaphore { HANDLE sem_{INVALID_HANDLE_VALUE}; }; -#elif defined(__APPLE__) +#elif defined(__APPLE__) && (MAC_OS_X_VERSION_MIN_REQUIRED > 1050) && !defined(__ppc__) class NativeSemaphore { public: diff --git folly/system/ThreadId.cpp folly/system/ThreadId.cpp index 12320cb19..d4bac0a87 100644 --- folly/system/ThreadId.cpp +++ folly/system/ThreadId.cpp @@ -40,9 +40,13 @@ uint64_t getOSThreadIDSlow() { #if defined(__APPLE__) - uint64_t tid; - pthread_threadid_np(nullptr, &tid); - return tid; + #ifndef __POWERPC__ + uint64_t tid; + pthread_threadid_np(nullptr, &tid); + return tid; + #else + return 0; + #endif #elif defined(_WIN32) return uint64_t(GetCurrentThreadId()); #elif defined(__FreeBSD__) diff --git folly/system/ThreadName.cpp folly/system/ThreadName.cpp index 52c4ddd64..4cddafe13 100644 --- folly/system/ThreadName.cpp +++ folly/system/ThreadName.cpp @@ -52,7 +52,7 @@ #define FOLLY_HAS_PTHREAD_SETNAME_NP_THREAD_NAME 0 #endif -#if defined(__APPLE__) +#if defined(__APPLE__) && !defined(__POWERPC__) && (MAC_OS_X_VERSION_MIN_REQUIRED >= 1060) #define FOLLY_HAS_PTHREAD_SETNAME_NP_NAME 1 #else #define FOLLY_HAS_PTHREAD_SETNAME_NP_NAME 0 diff --git folly/test/ConstexprMathTest.cpp folly/test/ConstexprMathTest.cpp index bc48de553..ca0577970 100644 --- folly/test/ConstexprMathTest.cpp +++ folly/test/ConstexprMathTest.cpp @@ -987,7 +987,7 @@ TEST_F(ConstexprMathTest, constexpr_exp_floating) { } { constexpr auto a = folly::constexpr_exp(471.L); -#if defined(__APPLE__) && defined(FOLLY_AARCH64) +#if defined(__APPLE__) && (FOLLY_AARCH64 || FOLLY_PPC) EXPECT_LT( // too inexact for expect-double-eq std::exp(471.L) / a - 1, 16 * lim::epsilon()); diff --git folly/test/IteratorsTest.cpp folly/test/IteratorsTest.cpp index 63195eced..21741776a 100644 --- folly/test/IteratorsTest.cpp +++ folly/test/IteratorsTest.cpp @@ -42,7 +42,9 @@ TEST(IteratorsTest, IterFacadeHasCorrectTraits) { static_assert( std::is_same::value, ""); +#if !FOLLY_PPC static_assert(std::is_same::value, ""); +#endif } TEST(IteratorsTest, SimpleIteratorFacade) { @@ -85,7 +87,9 @@ TEST(IteratorsTest, IterAdaptorHasCorrectTraits) { static_assert( std::is_same::value, ""); +#if !FOLLY_PPC static_assert(std::is_same::value, ""); +#endif } TEST(IteratorsTest, IterAdaptorWithPointer) { diff --git folly/test/MemsetBenchmark.cpp folly/test/MemsetBenchmark.cpp index 139987d0d..afe5af1aa 100644 --- folly/test/MemsetBenchmark.cpp +++ folly/test/MemsetBenchmark.cpp @@ -25,6 +25,10 @@ #include #include +#ifdef __APPLE__ +#include +#endif + DEFINE_uint32(min_size, 1, "Minimum size to benchmark"); DEFINE_uint32(max_size, 32768, "Maximum size to benchmark"); DEFINE_bool(linear, false, "Test all sizes [min_size, max_size]"); @@ -86,7 +90,11 @@ int main(int argc, char** argv) { assert(FLAGS_step > 0); size_t totalBufSize = (FLAGS_max_size + FLAGS_page_offset + 4095) & ~4095; +#if defined(__APPLE__) && (MAC_OS_X_VERSION_MIN_REQUIRED < 101500) + temp_buf = (uint8_t*)malloc(totalBufSize); +#else temp_buf = (uint8_t*)aligned_alloc(4096, totalBufSize); +#endif // Make sure all pages are allocated for (size_t i = 0; i < totalBufSize; i++) { temp_buf[i] = 0; diff --git folly/test/MemsetTest.cpp folly/test/MemsetTest.cpp index b1deaca05..254dafb42 100644 --- folly/test/MemsetTest.cpp +++ folly/test/MemsetTest.cpp @@ -21,6 +21,10 @@ #include +#ifdef __APPLE__ +#include +#endif + constexpr size_t kPageSize = 4096; constexpr uint8_t kBufEnd = 0xDB; @@ -45,8 +49,13 @@ void testMemsetImpl(uint8_t* buf, size_t maxLen) { TEST(MemsetAsmTest, alignedBuffer) { constexpr size_t kMaxSize = 2 * kPageSize; +#if defined(__APPLE__) && (MAC_OS_X_VERSION_MIN_REQUIRED < 101500) + uint8_t* buf = reinterpret_cast( + malloc(kMaxSize + 2 * kPageSize)); +#else uint8_t* buf = reinterpret_cast( aligned_alloc(kPageSize, kMaxSize + 2 * kPageSize)); +#endif // Get buffer aligned power of 2 from 16 all the way up to a page size for (size_t alignment = 16; alignment <= kPageSize; alignment <<= 1) { testMemsetImpl(buf + (alignment % kPageSize), kMaxSize); @@ -55,8 +64,13 @@ TEST(MemsetAsmTest, alignedBuffer) { } TEST(MemsetAsmTest, unalignedBuffer) { +#if defined(__APPLE__) && (MAC_OS_X_VERSION_MIN_REQUIRED < 101500) + uint8_t* buf = + reinterpret_cast(malloc(2 * kPageSize)); +#else uint8_t* buf = reinterpret_cast(aligned_alloc(kPageSize, 2 * kPageSize)); +#endif for (size_t alignment = 1; alignment <= 192; alignment++) { testMemsetImpl(buf + alignment, 256); } diff --git folly/test/OptionalTest.cpp folly/test/OptionalTest.cpp index 060b3bd76..941750aa8 100644 --- folly/test/OptionalTest.cpp +++ folly/test/OptionalTest.cpp @@ -74,9 +74,11 @@ struct NoDefault { } // namespace +#if !FOLLY_PPC static_assert(sizeof(Optional) == 2, ""); -static_assert(sizeof(Optional) == 8, ""); static_assert(sizeof(Optional) == 4, ""); +#endif +static_assert(sizeof(Optional) == 8, ""); static_assert(sizeof(Optional) == sizeof(std::optional), ""); static_assert(sizeof(Optional) == sizeof(std::optional), ""); static_assert(sizeof(Optional) == sizeof(std::optional), "");