From 3242a1a204ce2173027e1b7d36d28fedf63205c3 Mon Sep 17 00:00:00 2001 From: Sergey Fedorov Date: Sun, 16 Aug 2026 04:26:52 +0000 Subject: [PATCH] [llvm] Don't require on pre-10.10 Darwin hosts and the pthread QoS API (pthread_set_qos_class_self_np, QOS_CLASS_*) first shipped in macOS 10.10. On PowerPC hosts (macOS 10.5/10.6) the header does not exist in any SDK, so Unix/Threading.inc fails to compile before anything else does. Gate the include and the QoS branch of llvm::set_thread_priority() on __ENVIRONMENT_MAC_OS_X_VERSION_MIN_REQUIRED__ >= 101000. The deployment target is the right predicate rather than __has_include: when cross-building against a modern SDK with -mmacosx-version-min=10.5/10.6 the header exists but the functions are still absent from the target's libSystem, and an unguarded strong reference would fail at load time. Every Darwin compiler (Apple GCC 4.x, FSF GCC, clang) defines the macro, with 10.5 -> 1050 and 10.10 -> 101000, so the comparison is well-formed on both numbering schemes. With the QoS branch compiled out, set_thread_priority() falls through to the existing 'return SetThreadPriorityResult::FAILURE' tail, which is exactly what upstream returns on platforms without priority support; callers (ThreadPool background threads) treat it as advisory. The other Apple dependencies in this file are fine on 10.5: mach_thread_self and hw.physicalcpu sysctl exist there, and pthread_setname_np (10.6+) is already behind the HAVE_PTHREAD_SETNAME_NP configure check, which fails cleanly on 10.5. Co-Authored-By: Claude Fable 5 Claude-Session: https://claude.ai/code/session_01AN7qpyGgKic6UMdej1TVJd --- src/llvm/lib/Support/Unix/Threading.inc | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/llvm/lib/Support/Unix/Threading.inc b/src/llvm/lib/Support/Unix/Threading.inc index ab82327..2747684 100644 --- a/src/llvm/lib/Support/Unix/Threading.inc +++ b/src/llvm/lib/Support/Unix/Threading.inc @@ -22,7 +22,14 @@ #if defined(__APPLE__) #include #include +// The pthread QoS API first shipped in macOS 10.10: does not +// exist in earlier SDKs and the functions are absent from earlier libSystem, +// so gate on the deployment target rather than on header presence. +#if defined(__ENVIRONMENT_MAC_OS_X_VERSION_MIN_REQUIRED__) && \ + __ENVIRONMENT_MAC_OS_X_VERSION_MIN_REQUIRED__ >= 101000 #include +#define LLVM_APPLE_HAVE_PTHREAD_QOS 1 +#endif #include #include #endif @@ -267,7 +274,7 @@ SetThreadPriorityResult llvm::set_thread_priority(ThreadPriority Priority) { &priority) ? SetThreadPriorityResult::SUCCESS : SetThreadPriorityResult::FAILURE; -#elif defined(__APPLE__) +#elif defined(__APPLE__) && defined(LLVM_APPLE_HAVE_PTHREAD_QOS) // https://developer.apple.com/documentation/apple-silicon/tuning-your-code-s-performance-for-apple-silicon // // Background - Applies to work that isn’t visible to the user and may take -- 2.43.0