From 0eb47540816a37324403ed3fee64977c1fe04496 Mon Sep 17 00:00:00 2001 From: Josh Carp Date: Mon, 5 Jan 2026 16:17:21 +0000 Subject: [PATCH 1/3] Add illumos support to libc++ and LLVM. libc++ changes: - Add __sun to pthread platforms and rune table providers. - Add illumos ctype mask definitions with non-overlapping __regex_word. - Use musl locale shim for missing *_l functions. - Skip overloads already defined in illumos stdlib. - Fix conflicting __sentinel, _E1-_E24 macros. LLVM changes: - Fix conflicting FS, CS/CE macros. - Use std::fabs instead of std::abs for float in SampleProfileProbe. Part of #23777. --- libcxx/include/__config | 3 +- libcxx/include/__locale | 15 ++++++++ libcxx/include/__locale_dir/locale_base_api.h | 2 +- libcxx/include/__math/abs.h | 22 +++++------- libcxx/include/__math/exponential_functions.h | 34 +++++++----------- .../__math/inverse_trigonometric_functions.h | 30 +++++++--------- libcxx/include/__math/logarithms.h | 16 ++++----- libcxx/include/__math/modulo.h | 18 ++++------ libcxx/include/__math/roots.h | 10 +++--- libcxx/include/__math/rounding_functions.h | 20 +++++------ .../include/__math/trigonometric_functions.h | 22 ++++++------ libcxx/include/__ranges/zip_view.h | 1 - libcxx/include/__undef_macros | 36 +++++++++++++++++++ libcxx/include/stdlib.h | 4 +-- llvm/include/llvm/ADT/SmallVector.h | 6 ++-- llvm/include/llvm/Support/CommandLine.h | 6 ++++ llvm/include/llvm/Support/PGOOptions.h | 6 ++++ llvm/include/llvm/Target/TargetMachine.h | 6 ++++ .../lib/Transforms/IPO/SampleProfileProbe.cpp | 3 +- 19 files changed, 151 insertions(+), 109 deletions(-) diff --git a/libcxx/include/__config b/libcxx/include/__config index 982fa6e04288d..bc6e6ea024078 100644 --- a/libcxx/include/__config +++ b/libcxx/include/__config @@ -842,6 +842,7 @@ typedef __char32_t char32_t; defined(__APPLE__) || \ defined(__MVS__) || \ defined(_AIX) || \ + defined(__sun) || \ defined(__EMSCRIPTEN__) // clang-format on # undef _LIBCPP_HAS_THREAD_API_PTHREAD @@ -925,7 +926,7 @@ typedef __char32_t char32_t; # endif # if defined(__BIONIC__) || defined(__NuttX__) || defined(__Fuchsia__) || defined(__wasi__) || \ - _LIBCPP_HAS_MUSL_LIBC || defined(__OpenBSD__) || defined(__LLVM_LIBC__) + _LIBCPP_HAS_MUSL_LIBC || defined(__OpenBSD__) || defined(__LLVM_LIBC__) || defined(__sun) # define _LIBCPP_PROVIDES_DEFAULT_RUNE_TABLE # endif diff --git a/libcxx/include/__locale b/libcxx/include/__locale index 757a53951f66e..987b6b6b7d631 100644 --- a/libcxx/include/__locale +++ b/libcxx/include/__locale @@ -389,6 +389,21 @@ public: static const mask xdigit = _ISXDIGIT; static const mask blank = _ISBLANK; static const mask __regex_word = 0x8000; +# elif defined(__sun) + // illumos/Solaris ctype masks. Note: _ISPRINT is 0x8000, so we use + // 0x10000 for __regex_word to avoid overlap. + typedef unsigned int mask; + static const mask space = _ISSPACE; + static const mask print = _ISPRINT; + static const mask cntrl = _ISCNTRL; + static const mask upper = _ISUPPER; + static const mask lower = _ISLOWER; + static const mask alpha = _ISALPHA; + static const mask digit = _ISDIGIT; + static const mask punct = _ISPUNCT; + static const mask xdigit = _ISXDIGIT; + static const mask blank = _ISBLANK; + static const mask __regex_word = 0x10000; # elif defined(_NEWLIB_VERSION) // Same type as Newlib's _ctype_ array in newlib/libc/include/ctype.h. typedef char mask; diff --git a/libcxx/include/__locale_dir/locale_base_api.h b/libcxx/include/__locale_dir/locale_base_api.h index 8dbc28e839839..4d1063b4123cd 100644 --- a/libcxx/include/__locale_dir/locale_base_api.h +++ b/libcxx/include/__locale_dir/locale_base_api.h @@ -133,7 +133,7 @@ # include <__locale_dir/locale_base_api/android.h> # elif defined(__OpenBSD__) # include <__locale_dir/locale_base_api/openbsd.h> -# elif defined(__wasi__) || _LIBCPP_HAS_MUSL_LIBC +# elif defined(__wasi__) || _LIBCPP_HAS_MUSL_LIBC || defined(__sun) # include <__locale_dir/locale_base_api/musl.h> # endif diff --git a/libcxx/include/__math/abs.h b/libcxx/include/__math/abs.h index b780159f11ebf..aefe587404b9b 100644 --- a/libcxx/include/__math/abs.h +++ b/libcxx/include/__math/abs.h @@ -23,17 +23,11 @@ namespace __math { // fabs -[[__nodiscard__]] inline _LIBCPP_HIDE_FROM_ABI float fabs(float __x) _NOEXCEPT { return __builtin_fabsf(__x); } - template [[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI double fabs(double __x) _NOEXCEPT { return __builtin_fabs(__x); } -[[__nodiscard__]] inline _LIBCPP_HIDE_FROM_ABI long double fabs(long double __x) _NOEXCEPT { - return __builtin_fabsl(__x); -} - template ::value, int> = 0> [[__nodiscard__]] inline _LIBCPP_HIDE_FROM_ABI double fabs(_A1 __x) _NOEXCEPT { return __builtin_fabs((double)__x); @@ -41,13 +35,6 @@ template ::value, int> = 0> // abs -[[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI inline float abs(float __x) _NOEXCEPT { return __builtin_fabsf(__x); } -[[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI inline double abs(double __x) _NOEXCEPT { return __builtin_fabs(__x); } - -[[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI inline long double abs(long double __x) _NOEXCEPT { - return __builtin_fabsl(__x); -} - template [[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI inline int abs(int __x) _NOEXCEPT { return __builtin_abs(__x); @@ -63,6 +50,15 @@ template return __builtin_llabs(__x); } +// illumos already provides float/long double overloads +#ifndef __sun +[[__nodiscard__]] inline _LIBCPP_HIDE_FROM_ABI float fabs(float __x) _NOEXCEPT { return __builtin_fabsf(__x); } +[[__nodiscard__]] inline _LIBCPP_HIDE_FROM_ABI long double fabs(long double __x) _NOEXCEPT { return __builtin_fabsl(__x); } +[[__nodiscard__]] inline _LIBCPP_HIDE_FROM_ABI float abs(float __x) _NOEXCEPT { return __builtin_fabsf(__x); } +[[__nodiscard__]] inline _LIBCPP_HIDE_FROM_ABI double abs(double __x) _NOEXCEPT { return __builtin_fabs(__x); } +[[__nodiscard__]] inline _LIBCPP_HIDE_FROM_ABI long double abs(long double __x) _NOEXCEPT { return __builtin_fabsl(__x); } +#endif + } // namespace __math _LIBCPP_END_NAMESPACE_STD diff --git a/libcxx/include/__math/exponential_functions.h b/libcxx/include/__math/exponential_functions.h index 09930b7819e23..000cbf247c0bc 100644 --- a/libcxx/include/__math/exponential_functions.h +++ b/libcxx/include/__math/exponential_functions.h @@ -26,15 +26,11 @@ namespace __math { // exp -inline _LIBCPP_HIDE_FROM_ABI float exp(float __x) _NOEXCEPT { return __builtin_expf(__x); } - template _LIBCPP_HIDE_FROM_ABI double exp(double __x) _NOEXCEPT { return __builtin_exp(__x); } -inline _LIBCPP_HIDE_FROM_ABI long double exp(long double __x) _NOEXCEPT { return __builtin_expl(__x); } - template ::value, int> = 0> inline _LIBCPP_HIDE_FROM_ABI double exp(_A1 __x) _NOEXCEPT { return __builtin_exp((double)__x); @@ -42,17 +38,11 @@ inline _LIBCPP_HIDE_FROM_ABI double exp(_A1 __x) _NOEXCEPT { // frexp -inline _LIBCPP_HIDE_FROM_ABI float frexp(float __x, int* __e) _NOEXCEPT { return __builtin_frexpf(__x, __e); } - template _LIBCPP_HIDE_FROM_ABI double frexp(double __x, int* __e) _NOEXCEPT { return __builtin_frexp(__x, __e); } -inline _LIBCPP_HIDE_FROM_ABI long double frexp(long double __x, int* __e) _NOEXCEPT { - return __builtin_frexpl(__x, __e); -} - template ::value, int> = 0> inline _LIBCPP_HIDE_FROM_ABI double frexp(_A1 __x, int* __e) _NOEXCEPT { return __builtin_frexp((double)__x, __e); @@ -60,17 +50,11 @@ inline _LIBCPP_HIDE_FROM_ABI double frexp(_A1 __x, int* __e) _NOEXCEPT { // ldexp -inline _LIBCPP_HIDE_FROM_ABI float ldexp(float __x, int __e) _NOEXCEPT { return __builtin_ldexpf(__x, __e); } - template _LIBCPP_HIDE_FROM_ABI double ldexp(double __x, int __e) _NOEXCEPT { return __builtin_ldexp(__x, __e); } -inline _LIBCPP_HIDE_FROM_ABI long double ldexp(long double __x, int __e) _NOEXCEPT { - return __builtin_ldexpl(__x, __e); -} - template ::value, int> = 0> inline _LIBCPP_HIDE_FROM_ABI double ldexp(_A1 __x, int __e) _NOEXCEPT { return __builtin_ldexp((double)__x, __e); @@ -146,17 +130,11 @@ inline _LIBCPP_HIDE_FROM_ABI double scalbn(_A1 __x, int __y) _NOEXCEPT { // pow -inline _LIBCPP_HIDE_FROM_ABI float pow(float __x, float __y) _NOEXCEPT { return __builtin_powf(__x, __y); } - template _LIBCPP_HIDE_FROM_ABI double pow(double __x, double __y) _NOEXCEPT { return __builtin_pow(__x, __y); } -inline _LIBCPP_HIDE_FROM_ABI long double pow(long double __x, long double __y) _NOEXCEPT { - return __builtin_powl(__x, __y); -} - template ::value && is_arithmetic<_A2>::value, int> = 0> inline _LIBCPP_HIDE_FROM_ABI __promote_t<_A1, _A2> pow(_A1 __x, _A2 __y) _NOEXCEPT { using __result_type = __promote_t<_A1, _A2>; @@ -164,6 +142,18 @@ inline _LIBCPP_HIDE_FROM_ABI __promote_t<_A1, _A2> pow(_A1 __x, _A2 __y) _NOEXCE return __math::pow((__result_type)__x, (__result_type)__y); } +// illumos already provides float/long double overloads +#ifndef __sun +inline _LIBCPP_HIDE_FROM_ABI float exp(float __x) _NOEXCEPT { return __builtin_expf(__x); } +inline _LIBCPP_HIDE_FROM_ABI long double exp(long double __x) _NOEXCEPT { return __builtin_expl(__x); } +inline _LIBCPP_HIDE_FROM_ABI float frexp(float __x, int* __e) _NOEXCEPT { return __builtin_frexpf(__x, __e); } +inline _LIBCPP_HIDE_FROM_ABI long double frexp(long double __x, int* __e) _NOEXCEPT { return __builtin_frexpl(__x, __e); } +inline _LIBCPP_HIDE_FROM_ABI float ldexp(float __x, int __e) _NOEXCEPT { return __builtin_ldexpf(__x, __e); } +inline _LIBCPP_HIDE_FROM_ABI long double ldexp(long double __x, int __e) _NOEXCEPT { return __builtin_ldexpl(__x, __e); } +inline _LIBCPP_HIDE_FROM_ABI float pow(float __x, float __y) _NOEXCEPT { return __builtin_powf(__x, __y); } +inline _LIBCPP_HIDE_FROM_ABI long double pow(long double __x, long double __y) _NOEXCEPT { return __builtin_powl(__x, __y); } +#endif + } // namespace __math _LIBCPP_END_NAMESPACE_STD diff --git a/libcxx/include/__math/inverse_trigonometric_functions.h b/libcxx/include/__math/inverse_trigonometric_functions.h index 409500278e7a9..1dddd789ba41d 100644 --- a/libcxx/include/__math/inverse_trigonometric_functions.h +++ b/libcxx/include/__math/inverse_trigonometric_functions.h @@ -26,15 +26,11 @@ namespace __math { // acos -inline _LIBCPP_HIDE_FROM_ABI float acos(float __x) _NOEXCEPT { return __builtin_acosf(__x); } - template _LIBCPP_HIDE_FROM_ABI double acos(double __x) _NOEXCEPT { return __builtin_acos(__x); } -inline _LIBCPP_HIDE_FROM_ABI long double acos(long double __x) _NOEXCEPT { return __builtin_acosl(__x); } - template ::value, int> = 0> inline _LIBCPP_HIDE_FROM_ABI double acos(_A1 __x) _NOEXCEPT { return __builtin_acos((double)__x); @@ -42,15 +38,11 @@ inline _LIBCPP_HIDE_FROM_ABI double acos(_A1 __x) _NOEXCEPT { // asin -inline _LIBCPP_HIDE_FROM_ABI float asin(float __x) _NOEXCEPT { return __builtin_asinf(__x); } - template _LIBCPP_HIDE_FROM_ABI double asin(double __x) _NOEXCEPT { return __builtin_asin(__x); } -inline _LIBCPP_HIDE_FROM_ABI long double asin(long double __x) _NOEXCEPT { return __builtin_asinl(__x); } - template ::value, int> = 0> inline _LIBCPP_HIDE_FROM_ABI double asin(_A1 __x) _NOEXCEPT { return __builtin_asin((double)__x); @@ -58,15 +50,11 @@ inline _LIBCPP_HIDE_FROM_ABI double asin(_A1 __x) _NOEXCEPT { // atan -inline _LIBCPP_HIDE_FROM_ABI float atan(float __x) _NOEXCEPT { return __builtin_atanf(__x); } - template _LIBCPP_HIDE_FROM_ABI double atan(double __x) _NOEXCEPT { return __builtin_atan(__x); } -inline _LIBCPP_HIDE_FROM_ABI long double atan(long double __x) _NOEXCEPT { return __builtin_atanl(__x); } - template ::value, int> = 0> inline _LIBCPP_HIDE_FROM_ABI double atan(_A1 __x) _NOEXCEPT { return __builtin_atan((double)__x); @@ -74,17 +62,11 @@ inline _LIBCPP_HIDE_FROM_ABI double atan(_A1 __x) _NOEXCEPT { // atan2 -inline _LIBCPP_HIDE_FROM_ABI float atan2(float __y, float __x) _NOEXCEPT { return __builtin_atan2f(__y, __x); } - template _LIBCPP_HIDE_FROM_ABI double atan2(double __x, double __y) _NOEXCEPT { return __builtin_atan2(__x, __y); } -inline _LIBCPP_HIDE_FROM_ABI long double atan2(long double __y, long double __x) _NOEXCEPT { - return __builtin_atan2l(__y, __x); -} - template ::value && is_arithmetic<_A2>::value, int> = 0> inline _LIBCPP_HIDE_FROM_ABI __promote_t<_A1, _A2> atan2(_A1 __y, _A2 __x) _NOEXCEPT { using __result_type = __promote_t<_A1, _A2>; @@ -92,6 +74,18 @@ inline _LIBCPP_HIDE_FROM_ABI __promote_t<_A1, _A2> atan2(_A1 __y, _A2 __x) _NOEX return __math::atan2((__result_type)__y, (__result_type)__x); } +// illumos already provides float/long double overloads +#ifndef __sun +inline _LIBCPP_HIDE_FROM_ABI float acos(float __x) _NOEXCEPT { return __builtin_acosf(__x); } +inline _LIBCPP_HIDE_FROM_ABI long double acos(long double __x) _NOEXCEPT { return __builtin_acosl(__x); } +inline _LIBCPP_HIDE_FROM_ABI float asin(float __x) _NOEXCEPT { return __builtin_asinf(__x); } +inline _LIBCPP_HIDE_FROM_ABI long double asin(long double __x) _NOEXCEPT { return __builtin_asinl(__x); } +inline _LIBCPP_HIDE_FROM_ABI float atan(float __x) _NOEXCEPT { return __builtin_atanf(__x); } +inline _LIBCPP_HIDE_FROM_ABI long double atan(long double __x) _NOEXCEPT { return __builtin_atanl(__x); } +inline _LIBCPP_HIDE_FROM_ABI float atan2(float __y, float __x) _NOEXCEPT { return __builtin_atan2f(__y, __x); } +inline _LIBCPP_HIDE_FROM_ABI long double atan2(long double __y, long double __x) _NOEXCEPT { return __builtin_atan2l(__y, __x); } +#endif + } // namespace __math _LIBCPP_END_NAMESPACE_STD diff --git a/libcxx/include/__math/logarithms.h b/libcxx/include/__math/logarithms.h index 5f5f943977a50..f5d2ab7298a39 100644 --- a/libcxx/include/__math/logarithms.h +++ b/libcxx/include/__math/logarithms.h @@ -23,15 +23,11 @@ namespace __math { // log -inline _LIBCPP_HIDE_FROM_ABI float log(float __x) _NOEXCEPT { return __builtin_logf(__x); } - template _LIBCPP_HIDE_FROM_ABI double log(double __x) _NOEXCEPT { return __builtin_log(__x); } -inline _LIBCPP_HIDE_FROM_ABI long double log(long double __x) _NOEXCEPT { return __builtin_logl(__x); } - template ::value, int> = 0> inline _LIBCPP_HIDE_FROM_ABI double log(_A1 __x) _NOEXCEPT { return __builtin_log((double)__x); @@ -39,20 +35,24 @@ inline _LIBCPP_HIDE_FROM_ABI double log(_A1 __x) _NOEXCEPT { // log10 -inline _LIBCPP_HIDE_FROM_ABI float log10(float __x) _NOEXCEPT { return __builtin_log10f(__x); } - template _LIBCPP_HIDE_FROM_ABI double log10(double __x) _NOEXCEPT { return __builtin_log10(__x); } -inline _LIBCPP_HIDE_FROM_ABI long double log10(long double __x) _NOEXCEPT { return __builtin_log10l(__x); } - template ::value, int> = 0> inline _LIBCPP_HIDE_FROM_ABI double log10(_A1 __x) _NOEXCEPT { return __builtin_log10((double)__x); } +// illumos already provides float/long double overloads +#ifndef __sun +inline _LIBCPP_HIDE_FROM_ABI float log(float __x) _NOEXCEPT { return __builtin_logf(__x); } +inline _LIBCPP_HIDE_FROM_ABI long double log(long double __x) _NOEXCEPT { return __builtin_logl(__x); } +inline _LIBCPP_HIDE_FROM_ABI float log10(float __x) _NOEXCEPT { return __builtin_log10f(__x); } +inline _LIBCPP_HIDE_FROM_ABI long double log10(long double __x) _NOEXCEPT { return __builtin_log10l(__x); } +#endif + // ilogb inline _LIBCPP_HIDE_FROM_ABI int ilogb(float __x) _NOEXCEPT { return __builtin_ilogbf(__x); } diff --git a/libcxx/include/__math/modulo.h b/libcxx/include/__math/modulo.h index 71405abb6b9b8..8f77e2cb11df8 100644 --- a/libcxx/include/__math/modulo.h +++ b/libcxx/include/__math/modulo.h @@ -25,17 +25,11 @@ namespace __math { // fmod -inline _LIBCPP_HIDE_FROM_ABI float fmod(float __x, float __y) _NOEXCEPT { return __builtin_fmodf(__x, __y); } - template _LIBCPP_HIDE_FROM_ABI double fmod(double __x, double __y) _NOEXCEPT { return __builtin_fmod(__x, __y); } -inline _LIBCPP_HIDE_FROM_ABI long double fmod(long double __x, long double __y) _NOEXCEPT { - return __builtin_fmodl(__x, __y); -} - template ::value && is_arithmetic<_A2>::value, int> = 0> inline _LIBCPP_HIDE_FROM_ABI __promote_t<_A1, _A2> fmod(_A1 __x, _A2 __y) _NOEXCEPT { using __result_type = __promote_t<_A1, _A2>; @@ -45,16 +39,18 @@ inline _LIBCPP_HIDE_FROM_ABI __promote_t<_A1, _A2> fmod(_A1 __x, _A2 __y) _NOEXC // modf -inline _LIBCPP_HIDE_FROM_ABI float modf(float __x, float* __y) _NOEXCEPT { return __builtin_modff(__x, __y); } - template _LIBCPP_HIDE_FROM_ABI double modf(double __x, double* __y) _NOEXCEPT { return __builtin_modf(__x, __y); } -inline _LIBCPP_HIDE_FROM_ABI long double modf(long double __x, long double* __y) _NOEXCEPT { - return __builtin_modfl(__x, __y); -} +// illumos already provides float/long double overloads +#ifndef __sun +inline _LIBCPP_HIDE_FROM_ABI float fmod(float __x, float __y) _NOEXCEPT { return __builtin_fmodf(__x, __y); } +inline _LIBCPP_HIDE_FROM_ABI long double fmod(long double __x, long double __y) _NOEXCEPT { return __builtin_fmodl(__x, __y); } +inline _LIBCPP_HIDE_FROM_ABI float modf(float __x, float* __y) _NOEXCEPT { return __builtin_modff(__x, __y); } +inline _LIBCPP_HIDE_FROM_ABI long double modf(long double __x, long double* __y) _NOEXCEPT { return __builtin_modfl(__x, __y); } +#endif } // namespace __math diff --git a/libcxx/include/__math/roots.h b/libcxx/include/__math/roots.h index cef376fb008cf..bffaa4afc6549 100644 --- a/libcxx/include/__math/roots.h +++ b/libcxx/include/__math/roots.h @@ -23,20 +23,22 @@ namespace __math { // sqrt -inline _LIBCPP_HIDE_FROM_ABI float sqrt(float __x) _NOEXCEPT { return __builtin_sqrtf(__x); } - template _LIBCPP_HIDE_FROM_ABI double sqrt(double __x) _NOEXCEPT { return __builtin_sqrt(__x); } -inline _LIBCPP_HIDE_FROM_ABI long double sqrt(long double __x) _NOEXCEPT { return __builtin_sqrtl(__x); } - template ::value, int> = 0> inline _LIBCPP_HIDE_FROM_ABI double sqrt(_A1 __x) _NOEXCEPT { return __builtin_sqrt((double)__x); } +// illumos already provides float/long double overloads +#ifndef __sun +inline _LIBCPP_HIDE_FROM_ABI float sqrt(float __x) _NOEXCEPT { return __builtin_sqrtf(__x); } +inline _LIBCPP_HIDE_FROM_ABI long double sqrt(long double __x) _NOEXCEPT { return __builtin_sqrtl(__x); } +#endif + // cbrt [[__nodiscard__]] inline _LIBCPP_HIDE_FROM_ABI float cbrt(float __x) _NOEXCEPT { return __builtin_cbrtf(__x); } diff --git a/libcxx/include/__math/rounding_functions.h b/libcxx/include/__math/rounding_functions.h index aadeb395fa2eb..a9baaa102e869 100644 --- a/libcxx/include/__math/rounding_functions.h +++ b/libcxx/include/__math/rounding_functions.h @@ -26,17 +26,11 @@ namespace __math { // ceil -[[__nodiscard__]] inline _LIBCPP_HIDE_FROM_ABI float ceil(float __x) _NOEXCEPT { return __builtin_ceilf(__x); } - template [[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI double ceil(double __x) _NOEXCEPT { return __builtin_ceil(__x); } -[[__nodiscard__]] inline _LIBCPP_HIDE_FROM_ABI long double ceil(long double __x) _NOEXCEPT { - return __builtin_ceill(__x); -} - template ::value, int> = 0> [[__nodiscard__]] inline _LIBCPP_HIDE_FROM_ABI double ceil(_A1 __x) _NOEXCEPT { return __builtin_ceil((double)__x); @@ -44,22 +38,24 @@ template ::value, int> = 0> // floor -[[__nodiscard__]] inline _LIBCPP_HIDE_FROM_ABI float floor(float __x) _NOEXCEPT { return __builtin_floorf(__x); } - template [[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI double floor(double __x) _NOEXCEPT { return __builtin_floor(__x); } -[[__nodiscard__]] inline _LIBCPP_HIDE_FROM_ABI long double floor(long double __x) _NOEXCEPT { - return __builtin_floorl(__x); -} - template ::value, int> = 0> [[__nodiscard__]] inline _LIBCPP_HIDE_FROM_ABI double floor(_A1 __x) _NOEXCEPT { return __builtin_floor((double)__x); } +// illumos already provides float/long double overloads +#ifndef __sun +[[__nodiscard__]] inline _LIBCPP_HIDE_FROM_ABI float ceil(float __x) _NOEXCEPT { return __builtin_ceilf(__x); } +[[__nodiscard__]] inline _LIBCPP_HIDE_FROM_ABI long double ceil(long double __x) _NOEXCEPT { return __builtin_ceill(__x); } +[[__nodiscard__]] inline _LIBCPP_HIDE_FROM_ABI float floor(float __x) _NOEXCEPT { return __builtin_floorf(__x); } +[[__nodiscard__]] inline _LIBCPP_HIDE_FROM_ABI long double floor(long double __x) _NOEXCEPT { return __builtin_floorl(__x); } +#endif + // llrint inline _LIBCPP_HIDE_FROM_ABI long long llrint(float __x) _NOEXCEPT { return __builtin_llrintf(__x); } diff --git a/libcxx/include/__math/trigonometric_functions.h b/libcxx/include/__math/trigonometric_functions.h index 0ad91c7631609..b145a2d53c8f1 100644 --- a/libcxx/include/__math/trigonometric_functions.h +++ b/libcxx/include/__math/trigonometric_functions.h @@ -23,15 +23,11 @@ namespace __math { // cos -inline _LIBCPP_HIDE_FROM_ABI float cos(float __x) _NOEXCEPT { return __builtin_cosf(__x); } - template _LIBCPP_HIDE_FROM_ABI double cos(double __x) _NOEXCEPT { return __builtin_cos(__x); } -inline _LIBCPP_HIDE_FROM_ABI long double cos(long double __x) _NOEXCEPT { return __builtin_cosl(__x); } - template ::value, int> = 0> inline _LIBCPP_HIDE_FROM_ABI double cos(_A1 __x) _NOEXCEPT { return __builtin_cos((double)__x); @@ -39,15 +35,11 @@ inline _LIBCPP_HIDE_FROM_ABI double cos(_A1 __x) _NOEXCEPT { // sin -inline _LIBCPP_HIDE_FROM_ABI float sin(float __x) _NOEXCEPT { return __builtin_sinf(__x); } - template _LIBCPP_HIDE_FROM_ABI double sin(double __x) _NOEXCEPT { return __builtin_sin(__x); } -inline _LIBCPP_HIDE_FROM_ABI long double sin(long double __x) _NOEXCEPT { return __builtin_sinl(__x); } - template ::value, int> = 0> inline _LIBCPP_HIDE_FROM_ABI double sin(_A1 __x) _NOEXCEPT { return __builtin_sin((double)__x); @@ -55,20 +47,26 @@ inline _LIBCPP_HIDE_FROM_ABI double sin(_A1 __x) _NOEXCEPT { // tan -inline _LIBCPP_HIDE_FROM_ABI float tan(float __x) _NOEXCEPT { return __builtin_tanf(__x); } - template _LIBCPP_HIDE_FROM_ABI double tan(double __x) _NOEXCEPT { return __builtin_tan(__x); } -inline _LIBCPP_HIDE_FROM_ABI long double tan(long double __x) _NOEXCEPT { return __builtin_tanl(__x); } - template ::value, int> = 0> inline _LIBCPP_HIDE_FROM_ABI double tan(_A1 __x) _NOEXCEPT { return __builtin_tan((double)__x); } +// illumos already provides float/long double overloads +#ifndef __sun +inline _LIBCPP_HIDE_FROM_ABI float cos(float __x) _NOEXCEPT { return __builtin_cosf(__x); } +inline _LIBCPP_HIDE_FROM_ABI long double cos(long double __x) _NOEXCEPT { return __builtin_cosl(__x); } +inline _LIBCPP_HIDE_FROM_ABI float sin(float __x) _NOEXCEPT { return __builtin_sinf(__x); } +inline _LIBCPP_HIDE_FROM_ABI long double sin(long double __x) _NOEXCEPT { return __builtin_sinl(__x); } +inline _LIBCPP_HIDE_FROM_ABI float tan(float __x) _NOEXCEPT { return __builtin_tanf(__x); } +inline _LIBCPP_HIDE_FROM_ABI long double tan(long double __x) _NOEXCEPT { return __builtin_tanl(__x); } +#endif + } // namespace __math _LIBCPP_END_NAMESPACE_STD diff --git a/libcxx/include/__ranges/zip_view.h b/libcxx/include/__ranges/zip_view.h index e2a194efcfb4c..73129be2d3a9e 100644 --- a/libcxx/include/__ranges/zip_view.h +++ b/libcxx/include/__ranges/zip_view.h @@ -11,7 +11,6 @@ #define _LIBCPP___RANGES_ZIP_VIEW_H #include <__config> - #include <__algorithm/ranges_min.h> #include <__compare/three_way_comparable.h> #include <__concepts/convertible_to.h> diff --git a/libcxx/include/__undef_macros b/libcxx/include/__undef_macros index 29ab327e1c375..24a7dac92578b 100644 --- a/libcxx/include/__undef_macros +++ b/libcxx/include/__undef_macros @@ -26,3 +26,39 @@ #ifdef erase # undef erase #endif + +// illumos: sys/ccompile.h defines __sentinel as a macro for GCC's sentinel +// attribute, which conflicts with libc++ using __sentinel as an identifier +#ifdef __sun +# undef __sentinel +#endif + +// illumos: wctype_iso.h defines _E1-_E24 as character class constants +// which pollute libc++ template parameters like _E2 +// Note: _B and _C are kept because they're needed by __locale for ctype_base +#ifdef __sun +# undef _E1 +# undef _E2 +# undef _E3 +# undef _E4 +# undef _E5 +# undef _E6 +# undef _E7 +# undef _E8 +# undef _E9 +# undef _E10 +# undef _E11 +# undef _E12 +# undef _E13 +# undef _E14 +# undef _E15 +# undef _E16 +# undef _E17 +# undef _E18 +# undef _E19 +# undef _E20 +# undef _E21 +# undef _E22 +# undef _E23 +# undef _E24 +#endif diff --git a/libcxx/include/stdlib.h b/libcxx/include/stdlib.h index 8dfdfa416f088..5e4417026cd64 100644 --- a/libcxx/include/stdlib.h +++ b/libcxx/include/stdlib.h @@ -121,8 +121,8 @@ using std::__math::abs; # undef lldiv # endif -// MSVCRT already has the correct prototype in if __cplusplus is defined -# if !defined(_LIBCPP_MSVCRT) +// MSVCRT and illumos already have the correct prototype in if __cplusplus is defined +# if !defined(_LIBCPP_MSVCRT) && !defined(__sun) inline _LIBCPP_HIDE_FROM_ABI ldiv_t div(long __x, long __y) _NOEXCEPT { return ::ldiv(__x, __y); } # if !(defined(__FreeBSD__) && !defined(__LONG_LONG_SUPPORTED)) inline _LIBCPP_HIDE_FROM_ABI lldiv_t div(long long __x, long long __y) _NOEXCEPT { return ::lldiv(__x, __y); } diff --git a/llvm/include/llvm/ADT/SmallVector.h b/llvm/include/llvm/ADT/SmallVector.h index 80f7734b86907..4dbe366a19af1 100644 --- a/llvm/include/llvm/ADT/SmallVector.h +++ b/llvm/include/llvm/ADT/SmallVector.h @@ -749,10 +749,10 @@ class SmallVectorImpl : public SmallVectorTemplateBase { return(N); } - iterator erase(const_iterator CS, const_iterator CE) { + iterator erase(const_iterator CCS, const_iterator CCE) { // Just cast away constness because this is a non-const member function. - iterator S = const_cast(CS); - iterator E = const_cast(CE); + iterator S = const_cast(CCS); + iterator E = const_cast(CCE); assert(this->isRangeInStorage(S, E) && "Range to erase is out of bounds."); diff --git a/llvm/include/llvm/Support/CommandLine.h b/llvm/include/llvm/Support/CommandLine.h index adaa75cc6c348..00ff7f94740e1 100644 --- a/llvm/include/llvm/Support/CommandLine.h +++ b/llvm/include/llvm/Support/CommandLine.h @@ -19,6 +19,12 @@ #ifndef LLVM_SUPPORT_COMMANDLINE_H #define LLVM_SUPPORT_COMMANDLINE_H +// illumos: sys/regset.h defines FS as a macro for segment register (value 1) +// which conflicts with the FS parameter/member names in this file +#ifdef __sun +# undef FS +#endif + #include "llvm/ADT/ArrayRef.h" #include "llvm/ADT/STLExtras.h" #include "llvm/ADT/SmallPtrSet.h" diff --git a/llvm/include/llvm/Support/PGOOptions.h b/llvm/include/llvm/Support/PGOOptions.h index 6527a18258bf8..173b572742cfe 100644 --- a/llvm/include/llvm/Support/PGOOptions.h +++ b/llvm/include/llvm/Support/PGOOptions.h @@ -14,6 +14,12 @@ #ifndef LLVM_SUPPORT_PGOOPTIONS_H #define LLVM_SUPPORT_PGOOPTIONS_H +// illumos: sys/regset.h defines FS as a macro for segment register (value 1) +// which conflicts with the FS parameter/member names in this file +#ifdef __sun +# undef FS +#endif + #include "llvm/ADT/IntrusiveRefCntPtr.h" #include "llvm/Support/Compiler.h" #include "llvm/Support/Error.h" diff --git a/llvm/include/llvm/Target/TargetMachine.h b/llvm/include/llvm/Target/TargetMachine.h index bf4e490554723..57d35f10185ae 100644 --- a/llvm/include/llvm/Target/TargetMachine.h +++ b/llvm/include/llvm/Target/TargetMachine.h @@ -13,6 +13,12 @@ #ifndef LLVM_TARGET_TARGETMACHINE_H #define LLVM_TARGET_TARGETMACHINE_H +// illumos: sys/regset.h defines FS as a macro for segment register (value 1) +// which conflicts with the FS parameter/member names in this file +#ifdef __sun +# undef FS +#endif + #include "llvm/ADT/StringRef.h" #include "llvm/IR/DataLayout.h" #include "llvm/IR/PassManager.h" diff --git a/llvm/lib/Transforms/IPO/SampleProfileProbe.cpp b/llvm/lib/Transforms/IPO/SampleProfileProbe.cpp index 7fd7d4d4f750b..b5ba4ecfb3094 100644 --- a/llvm/lib/Transforms/IPO/SampleProfileProbe.cpp +++ b/llvm/lib/Transforms/IPO/SampleProfileProbe.cpp @@ -28,6 +28,7 @@ #include "llvm/Support/CRC.h" #include "llvm/Support/CommandLine.h" #include "llvm/Target/TargetMachine.h" +#include #include "llvm/Transforms/Utils/Instrumentation.h" #include "llvm/Transforms/Utils/ModuleUtils.h" #include @@ -151,7 +152,7 @@ void PseudoProbeVerifier::verifyProbeFactors( auto [It, Inserted] = PrevProbeFactors.try_emplace(I.first); if (!Inserted) { float PrevProbeFactor = It->second; - if (std::abs(CurProbeFactor - PrevProbeFactor) > + if (std::fabs(CurProbeFactor - PrevProbeFactor) > DistributionFactorVariance) { if (!BannerPrinted) { dbgs() << "Function " << F->getName() << ":\n"; From 8a6ca3b1574e36f687fbaaa0502ac9339ad5a5ba Mon Sep 17 00:00:00 2001 From: Josh Carp Date: Tue, 6 Jan 2026 21:41:23 +0000 Subject: [PATCH 2/3] [libunwind] Fix EH frame handling on illumos. Illumos uses PT_SUNW_EH_FRAME and PT_SUNW_UNWIND program header types instead of PT_GNU_EH_FRAME for exception handling frames. This patch checks if the illumos headers are defined, and checks the appropriate fields in the ELF header if so. Based on https://github.com/oxidecomputer/garbage-compactor/blob/master/clickhouse/patches/0020-Use-libunwind-on-illumos.patch. Part of https://github.com/ClickHouse/ClickHouse/issues/23777. Note: we'll submit this to upstream llvm as well. --- libunwind/src/AddressSpace.hpp | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/libunwind/src/AddressSpace.hpp b/libunwind/src/AddressSpace.hpp index b49b2c2ea3b9a..487ed61e848cb 100644 --- a/libunwind/src/AddressSpace.hpp +++ b/libunwind/src/AddressSpace.hpp @@ -408,7 +408,12 @@ static bool checkAddrInSegment(const Elf_Phdr *phdr, size_t image_base, static bool checkForUnwindInfoSegment(const Elf_Phdr *phdr, size_t image_base, dl_iterate_cb_data *cbdata) { #if defined(_LIBUNWIND_SUPPORT_DWARF_INDEX) +#if defined(PT_SUNW_UNWIND) + // illumos/Solaris use PT_SUNW_EH_FRAME and PT_SUNW_UNWIND instead of PT_GNU_EH_FRAME + if (phdr->p_type == PT_SUNW_EH_FRAME || phdr->p_type == PT_SUNW_UNWIND) { +#else if (phdr->p_type == PT_GNU_EH_FRAME) { +#endif EHHeaderParser::EHHeaderInfo hdrInfo; uintptr_t eh_frame_hdr_start = image_base + phdr->p_vaddr; cbdata->sects->dwarf_index_section = eh_frame_hdr_start; From d9f0847eb472841b2cb0cde5eb9f43b53e87d539 Mon Sep 17 00:00:00 2001 From: Josh Carp Date: Fri, 9 Jan 2026 18:45:00 +0000 Subject: [PATCH 3/3] [libunwind] Fix a freebsd regression introduced in #63. In #63, we checked for illumos-specific EH headers and used them if defined. But freebsd also defines some of these headers (but not all) for compatibility. This patch caused clickhouse builds to break on freebsd. This patch fixes the regression by checking for both EH headers, so that we fall through to the default case on freebsd. --- libunwind/src/AddressSpace.hpp | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/libunwind/src/AddressSpace.hpp b/libunwind/src/AddressSpace.hpp index 487ed61e848cb..cced4d7ff0ef2 100644 --- a/libunwind/src/AddressSpace.hpp +++ b/libunwind/src/AddressSpace.hpp @@ -408,8 +408,9 @@ static bool checkAddrInSegment(const Elf_Phdr *phdr, size_t image_base, static bool checkForUnwindInfoSegment(const Elf_Phdr *phdr, size_t image_base, dl_iterate_cb_data *cbdata) { #if defined(_LIBUNWIND_SUPPORT_DWARF_INDEX) -#if defined(PT_SUNW_UNWIND) - // illumos/Solaris use PT_SUNW_EH_FRAME and PT_SUNW_UNWIND instead of PT_GNU_EH_FRAME +#if defined(PT_SUNW_EH_FRAME) && defined(PT_SUNW_UNWIND) + // illumos/Solaris use PT_SUNW_EH_FRAME and PT_SUNW_UNWIND instead of PT_GNU_EH_FRAME. + // FreeBSD defines PT_SUNW_UNWIND but not PT_SUNW_EH_FRAME, so check for both. if (phdr->p_type == PT_SUNW_EH_FRAME || phdr->p_type == PT_SUNW_UNWIND) { #else if (phdr->p_type == PT_GNU_EH_FRAME) {