This is an automated email from the ASF dual-hosted git repository.

xiaoxiang781216 pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/nuttx.git

commit c803668d6c763c823b3286df1cc40c528abadf3e
Author: v-zhangxiaomeng5 <[email protected]>
AuthorDate: Sun Apr 5 14:18:20 2026 +0800

    libxx: upgrade libcxx and libcxxabi from llvm 17.0.6 to 21.1.8
    
    Kconfig:
    - Update LIBCXX and LIBCXXABI default version to 21.1.8
    
    __config_site:
    - Switch from llvm-17 _HAS_NO_ negated macros to llvm-21 0/1 positive macros
    - Guard _LIBCPP_HAS_THREADS and _LIBCPP_HAS_THREAD_API_PTHREAD with 
CONFIG_DISABLE_PTHREAD
    - Hardcode _LIBCPP_HAS_TIME_ZONE_DATABASE=0 (experimental/tzdb excluded)
    - Add #ifndef guard for _LIBCPP_DISABLE_DEPRECATION_WARNINGS to avoid 
redefinition
    - Add _LIBCPP_HARDENING_MODE_DEFAULT (required by llvm-21 __config)
    
    libcxx cmake/makefile:
    - Copy __assertion_handler from vendor template at configure time
    - Define constinit as __attribute__((__require_constant_initialization__)) 
for C++17
    - Suppress -Wno-c++20-compat for C++17 builds (constinit macro triggers 
keyword warning)
    - Exclude source files by C++ standard version: expected.cpp (C++23), 
barrier.cpp/atomic.cpp (C++20)
    - Exclude ostream.cpp/fstream.cpp when CXX_NO_LOCALIZATION is set
    - Exclude experimental directory to reduce code size
    
    libcxxabi cmake/makefile:
    - Map C++20 keyword constinit to compiler attribute for CXX_STANDARD < 20
    
    Patches:
    - The patches for 17.0.6 do not apply to 21.1.8. Replace them with the
      ones 21.1.8 needs, kept in git format, and apply every *.patch in the
      directory in name order with patch -p1, in both the CMake and the Make
      build. libcxxabi's CMake build applied none of its patches before.
    - Of the patches for 17.0.6, mbstate_t is carried over and the libcxxabi
      _Unwind_State fix is kept in an equivalent form. llvm 21 already
      contains the GCC 14 remove_pointer change, libcxxabi links
      cxa_noexception.cpp when exceptions are off, which replaces the ld
      errors patch, the code the __GLIBC__ patch avoided is no longer
      reached on NuttX, and the build does not need the others.
    - The new libcxx patches adapt libc++ to NuttX and to GCC 12 to 14,
      silence GCC false positives that user code hits, fix a few bugs, and
      add a stack size for std::thread and the mini localization. The new
      libcxxabi patches keep the exception state per thread and guard the
      ASan interface.
    - .codespell-ignore-lines accepts the patch lines that name
      include/__bit/countr.h, a libc++ file name that codespell takes for a
      typo.
    
    Assisted-by: Claude:claude-opus-5.5
    Signed-off-by: v-zhangxiaomeng5 <[email protected]>
---
 .codespell-ignore-lines                            |   4 +
 libs/libxx/Kconfig                                 |   4 +-
 libs/libxx/__config_site                           |  81 ++-
 .../0001-Fix-build-error-about-__GLIBC__.patch     |  17 -
 .../0001-libc-Fix-failures-with-GCC-14-92663.patch |  35 -
 libs/libxx/libcxx/0001-libcxx-fix-ld-errors.patch  |  28 -
 ...eep-the-host-headers-out-of-the-sim-build.patch |  58 ++
 .../libcxx/0001-libcxx-remove-mach-time-h.patch    |  13 -
 .../libcxx/0001_fix_stdatomic_h_miss_typedef.patch |  11 -
 ...d-ios.h-fix-streamoff-type-mismatch-by-re.patch |  31 +
 ...floating_point.h-replace-llvm-libc-shared.patch |  50 ++
 ...cxx-provide-what-GCC-12-lacks-from-GCC-13.patch | 314 ++++++++
 ...ide-what-GCC-12-and-13-lack-from-GCC-14-a.patch | 801 +++++++++++++++++++++
 ...r-unsupported-compiler-warning-threshold-.patch |  29 +
 ...-null-deref-after-realloc-failure-in-ios_.patch |  36 +
 ...ition_variable-fix-EINVAL-abort-when-syst.patch |  33 +
 ...ard-empty-range-relocate-to-avoid-null-me.patch |  33 +
 ...ing-remove-constexpr-from-basic_string-fo.patch |  29 +
 ..._functions.h-suppress-GCC-15-false-positi.patch |  30 +
 ...e-initialize-__chash-to-fix-GCC-15-Werror.patch |  26 +
 ...ar_traits.h-suppress-GCC-15-false-positiv.patch | 128 ++++
 ...use-task_info_s.ta_thread_local_data-for-.patch |  69 ++
 ...5-libcxx-let-std-thread-take-a-stack-size.patch | 123 ++++
 ...n-introduce-mini-localization-to-reduce-c.patch | 381 ++++++++++
 ...C-20-features-in-source-files-for-C-17-co.patch | 195 +++++
 libs/libxx/libcxx/CMakeLists.txt                   |  71 +-
 libs/libxx/libcxx/Make.defs                        |  34 +-
 libs/libxx/libcxx/mbstate_t.patch                  |  17 -
 ...on.cpp-guard-ASAN-interfaces-with-__has_i.patch |  26 +
 ...ix-build-warnings-generated-by-CMake-comp.patch |  38 -
 ...lity.cpp-fix-_Unwind_State-bitwise-operat.patch |  26 +
 .../0002-libcxxabi-fix-compilation-errors.patch    |  32 -
 ...on_storage.cpp-use-tls_info_s.tl_eh_globa.patch |  60 ++
 libs/libxx/libcxxabi/CMakeLists.txt                |  28 +-
 libs/libxx/libcxxabi/Make.defs                     |  11 +-
 35 files changed, 2642 insertions(+), 260 deletions(-)

diff --git a/.codespell-ignore-lines b/.codespell-ignore-lines
index 68ff6e8ca69..847c6a8af78 100644
--- a/.codespell-ignore-lines
+++ b/.codespell-ignore-lines
@@ -193,3 +193,7 @@ next trough with no gap in counting, matching the reload 
behavior of
 `CVE Numbering Authority (CNA) <https://www.cve.org/ProgramOrganization/CNAs>`_
 * [#16969](https://github.com/apache/nuttx/pull/16969) Revert "codespellrc: 
add ans to ignore words"
 * [#16966](https://github.com/apache/nuttx/pull/16966) codespellrc: add ans to 
ignore words
+--- a/include/__bit/countr.h
++++ b/include/__bit/countr.h
+diff --git a/include/__bit/countr.h b/include/__bit/countr.h
+ include/__bit/countr.h                     | 11 +++++++
diff --git a/libs/libxx/Kconfig b/libs/libxx/Kconfig
index ea650b8f6eb..17aa3dbf4aa 100644
--- a/libs/libxx/Kconfig
+++ b/libs/libxx/Kconfig
@@ -100,7 +100,7 @@ config LIBCXXABI_VERSION
        string "Select libcxxabi version"
        depends on LIBCXXABI
        default LIBCXX_VERSION if LIBCXX
-       default "17.0.6" if !LIBCXX
+       default "21.1.8" if !LIBCXX
 
 config LIBSTDCXX_VERSION
        string "Select libstdcxx version"
@@ -152,7 +152,7 @@ endif
 config LIBCXX_VERSION
        string "Select libcxx version"
        depends on LIBCXX
-       default "17.0.6"
+       default "21.1.8"
 
 config LIBCXX_TEST
        bool "LLVM Libcxx Library Test"
diff --git a/libs/libxx/__config_site b/libs/libxx/__config_site
index f305d6ffd3e..69ec7ffcb80 100644
--- a/libs/libxx/__config_site
+++ b/libs/libxx/__config_site
@@ -10,60 +10,65 @@
 #define _LIBCPP___CONFIG_SITE
 
 #include <nuttx/config.h>
+#include <nuttx/compiler.h>
 
 #define _LIBCPP_ABI_VERSION 1
 #define _LIBCPP_ABI_NAMESPACE __1
+
 /* #undef _LIBCPP_ABI_FORCE_ITANIUM */
 /* #undef _LIBCPP_ABI_FORCE_MICROSOFT */
-/* #undef _LIBCPP_HAS_NO_THREADS */
-/* #undef _LIBCPP_HAS_NO_MONOTONIC_CLOCK */
-/* #undef _LIBCPP_HAS_MUSL_LIBC */
-#define _LIBCPP_HAS_THREAD_API_PTHREAD 1
-/* #undef _LIBCPP_HAS_THREAD_API_EXTERNAL */
-/* #undef _LIBCPP_HAS_THREAD_API_WIN32 */
-/* #undef _LIBCPP_DISABLE_VISIBILITY_ANNOTATIONS */
-#define _LIBCPP_HAS_NO_VENDOR_AVAILABILITY_ANNOTATIONS
-/* #undef _LIBCPP_NO_VCRUNTIME */
-/* #undef _LIBCPP_TYPEINFO_COMPARISON_IMPLEMENTATION */
-/* #undef _LIBCPP_HAS_NO_FILESYSTEM */
-/* #undef _LIBCPP_HAS_NO_RANDOM_DEVICE */
-#define _LIBCPP_HAS_NO_CONTENTION_TABLE
+#ifdef CONFIG_DISABLE_PTHREAD
+#  define _LIBCPP_HAS_THREADS 0
+#  define _LIBCPP_HAS_THREAD_API_PTHREAD 0
+#else
+#  define _LIBCPP_HAS_THREADS 1
+#  define _LIBCPP_HAS_THREAD_API_PTHREAD 1
+#endif
+#define _LIBCPP_HAS_MONOTONIC_CLOCK 1
+#define _LIBCPP_HAS_TERMINAL 0
+#define _LIBCPP_HAS_MUSL_LIBC 0
+#define _LIBCPP_HAS_THREAD_API_EXTERNAL 0
+#define _LIBCPP_HAS_THREAD_API_WIN32 0
+#define _LIBCPP_HAS_THREAD_API_C11 0
+#define _LIBCPP_HAS_VENDOR_AVAILABILITY_ANNOTATIONS 0
+#define _LIBCPP_HAS_FILESYSTEM 1
+#define _LIBCPP_HAS_RANDOM_DEVICE 1
+#define _LIBCPP_HAS_UNICODE 1
+#define _LIBCPP_HAS_NO_STD_MODULES
+#define _LIBCPP_HAS_TIME_ZONE_DATABASE 0
+#define _LIBCPP_INSTRUMENTED_WITH_ASAN 0
+#ifdef CONFIG_CXX_WCHAR
+#  define _LIBCPP_HAS_WIDE_CHARACTERS 1
+#else
+#  define _LIBCPP_HAS_WIDE_CHARACTERS 0
+#endif
 #if defined(CONFIG_CXX_NO_LOCALIZATION)
-#  define _LIBCPP_HAS_NO_LOCALIZATION
+#  define _LIBCPP_HAS_LOCALIZATION 0
 #elif defined(CONFIG_CXX_MINI_LOCALIZATION)
+#  define _LIBCPP_HAS_LOCALIZATION 1
 #  define _LIBCPP_HAS_MINI_LOCALIZATION
+#else
+#  define _LIBCPP_HAS_LOCALIZATION 1
 #endif
-#ifndef CONFIG_CXX_WCHAR
-#  define _LIBCPP_HAS_NO_WIDE_CHARACTERS
-#endif
-#define _LIBCPP_ENABLE_ASSERTIONS_DEFAULT 0
-
 // PSTL backends
-#define _LIBCPP_PSTL_CPU_BACKEND_SERIAL
-/* #undef _LIBCPP_PSTL_CPU_BACKEND_THREAD */
-/* #undef _LIBCPP_PSTL_CPU_BACKEND_LIBDISPATCH */
-
-// Hardening.
-#define _LIBCPP_ENABLE_HARDENED_MODE_DEFAULT 0
-#define _LIBCPP_ENABLE_DEBUG_MODE_DEFAULT 0
-
-#define _LIBCPP_DISABLE_DEPRECATION_WARNINGS 1
-#define _LIBCPP_AVAILABILITY_HAS_NO_VERBOSE_ABORT 1
+#define _LIBCPP_PSTL_BACKEND_SERIAL
+// Hardening
+#define _LIBCPP_HARDENING_MODE_DEFAULT _LIBCPP_HARDENING_MODE_NONE
 
-// __USE_MINGW_ANSI_STDIO gets redefined on MinGW
-#ifdef __clang__
-#  pragma clang diagnostic push
-#  pragma clang diagnostic ignored "-Wmacro-redefined"
-#endif
+/* #undef _LIBCPP_DISABLE_VISIBILITY_ANNOTATIONS */
+/* #undef _LIBCPP_NO_VCRUNTIME */
+/* #undef _LIBCPP_TYPEINFO_COMPARISON_IMPLEMENTATION */
 
-#ifdef __clang__
-#  pragma clang diagnostic pop
+// Guard: some libcxx source files pre-define this without a value before 
including headers.
+#ifndef _LIBCPP_DISABLE_DEPRECATION_WARNINGS
+#  define _LIBCPP_DISABLE_DEPRECATION_WARNINGS 1
 #endif
-
-#define _SYS_REENT_H_
+#define _LIBCPP_AVAILABILITY_HAS_NO_VERBOSE_ABORT 1
 
 #ifndef __ULong
 #define __ULong unsigned long
 #endif
 
+#define _SYS_REENT_H_
+
 #endif // _LIBCPP___CONFIG_SITE
diff --git a/libs/libxx/libcxx/0001-Fix-build-error-about-__GLIBC__.patch 
b/libs/libxx/libcxx/0001-Fix-build-error-about-__GLIBC__.patch
deleted file mode 100644
index 95d6ee09dff..00000000000
--- a/libs/libxx/libcxx/0001-Fix-build-error-about-__GLIBC__.patch
+++ /dev/null
@@ -1,17 +0,0 @@
-diff --git libcxx/src/locale.cpp libcxx/src/locale.cpp
---- libcxx/src/locale.cpp
-+++ libcxx/src/locale.cpp
-@@ -41,6 +41,10 @@
- #include "include/atomic_support.h"
- #include "include/sso_allocator.h"
-
-+#if defined(__NuttX__) && defined(__GLIBC__)
-+#   undef __GLIBC__
-+#endif
-+
- // On Linux, wint_t and wchar_t have different signed-ness, and this causes
- // lots of noise in the build log, but no bugs that I know of.
- _LIBCPP_CLANG_DIAGNOSTIC_IGNORED("-Wsign-conversion")
---
-2.34.1
-
diff --git a/libs/libxx/libcxx/0001-libc-Fix-failures-with-GCC-14-92663.patch 
b/libs/libxx/libcxx/0001-libc-Fix-failures-with-GCC-14-92663.patch
deleted file mode 100644
index 9687db50221..00000000000
--- a/libs/libxx/libcxx/0001-libc-Fix-failures-with-GCC-14-92663.patch
+++ /dev/null
@@ -1,35 +0,0 @@
-From cb7a03b41fff563c0cbb5145eed09f9b17edf9e2 Mon Sep 17 00:00:00 2001
-From: Nikolas Klauser <[email protected]>
-Date: Sat, 1 Jun 2024 12:20:41 +0200
-Subject: [PATCH]  [libc++] Fix failures with GCC 14 (#92663)
-
-Fixes #91831
-
-Signed-off-by: chao an <[email protected]>
-
----
- libcxx/include/__type_traits/remove_pointer.h                | 5 +++++
- 11 files changed, 22 insertions(+), 8 deletions(-)
-
-diff --git libcxx/include/__type_traits/remove_pointer.h 
b/libcxx/include/__type_traits/remove_pointer.h
-index 54390a1939f7..1048f67055a2 100644
---- libcxx/include/__type_traits/remove_pointer.h
-+++ libcxx/include/__type_traits/remove_pointer.h
-@@ -23,8 +23,13 @@ struct remove_pointer {
-   using type _LIBCPP_NODEBUG = __remove_pointer(_Tp);
- };
-
-+#  ifdef _LIBCPP_COMPILER_GCC
-+template <class _Tp>
-+using __remove_pointer_t = typename remove_pointer<_Tp>::type;
-+#  else
- template <class _Tp>
- using __remove_pointer_t = __remove_pointer(_Tp);
-+#  endif
- #else
- // clang-format off
- template <class _Tp> struct _LIBCPP_TEMPLATE_VIS remove_pointer               
       {typedef _LIBCPP_NODEBUG _Tp type;};
-
---
-2.43.0
-
diff --git a/libs/libxx/libcxx/0001-libcxx-fix-ld-errors.patch 
b/libs/libxx/libcxx/0001-libcxx-fix-ld-errors.patch
deleted file mode 100644
index 8bfbe4528c2..00000000000
--- a/libs/libxx/libcxx/0001-libcxx-fix-ld-errors.patch
+++ /dev/null
@@ -1,28 +0,0 @@
-diff --git libcxx/include/ostream libcxx/include/ostream
---- libcxx/include/ostream
-+++ libcxx/include/ostream
-@@ -320,7 +320,10 @@ template <class _CharT, class _Traits>
- basic_ostream<_CharT, _Traits>::sentry::~sentry()
- {
-     if (__os_.rdbuf() && __os_.good() && (__os_.flags() & ios_base::unitbuf)
--                      && !uncaught_exception())
-+#ifndef _LIBCPP_HAS_NO_EXCEPTIONS
-+                      && !uncaught_exception()
-+#endif
-+       ) 
-     {
- #ifndef _LIBCPP_HAS_NO_EXCEPTIONS
-         try
-diff --git libcxx/src/exception.cpp libcxx/src/exception.cpp
---- libcxx/src/exception.cpp
-+++ libcxx/src/exception.cpp
-@@ -19,6 +19,9 @@
- #if defined(_LIBCPP_ABI_MICROSOFT)
- #include "support/runtime/exception_msvc.ipp"
- #include "support/runtime/exception_pointer_msvc.ipp"
-+#elif defined(_LIBCPPABI_VERSION) && defined(_LIBCPP_HAS_NO_EXCEPTIONS)
-+#include "include/atomic_support.h"
-+#include "support/runtime/exception_pointer_unimplemented.ipp"
- #elif defined(_LIBCPPABI_VERSION)
- #include "support/runtime/exception_libcxxabi.ipp"
- #include "support/runtime/exception_pointer_cxxabi.ipp"
diff --git 
a/libs/libxx/libcxx/0001-libcxx-keep-the-host-headers-out-of-the-sim-build.patch
 
b/libs/libxx/libcxx/0001-libcxx-keep-the-host-headers-out-of-the-sim-build.patch
new file mode 100644
index 00000000000..1b263237db9
--- /dev/null
+++ 
b/libs/libxx/libcxx/0001-libcxx-keep-the-host-headers-out-of-the-sim-build.patch
@@ -0,0 +1,58 @@
+From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
+From: v-zhangxiaomeng5 <[email protected]>
+Date: Fri, 13 Nov 2026 12:11:38 +0800
+Subject: [PATCH] libcxx: keep the host headers out of the sim build
+
+The sim build only passes -nostdinc++, so the host C library headers
+stay visible to libc++ and win over the NuttX ones in two places.
+
+__mbstate_t.h picks glibc's bits/types/mbstate_t.h before NuttX's
+wchar.h, and the two mbstate_t definitions conflict. Try include_next
+<wchar.h> first.
+
+random.cpp includes linux/random.h and sys/ioctl.h whenever they can be
+found. The host copies use a four argument _IOC while NuttX defines it
+with two, so the build fails with
+
+  macro "_IOC" requires 4 arguments, but only 2 given
+
+Include them only when __linux__ is defined.
+
+Signed-off-by: v-zhangxiaomeng5 <[email protected]>
+---
+ include/__mbstate_t.h | 4 ++--
+ src/random.cpp        | 2 +-
+ 2 files changed, 3 insertions(+), 3 deletions(-)
+
+diff --git a/include/__mbstate_t.h b/include/__mbstate_t.h
+index c23ea7113c..18c6dc5e88 100644
+--- a/include/__mbstate_t.h
++++ b/include/__mbstate_t.h
+@@ -39,12 +39,12 @@
+ #  define __NEED_mbstate_t
+ #  include <bits/alltypes.h>
+ #  undef __NEED_mbstate_t
++#elif __has_include_next(<wchar.h>)
++#  include_next <wchar.h> // use the C standard provider of mbstate_t if 
present
+ #elif __has_include(<bits/types/mbstate_t.h>)
+ #  include <bits/types/mbstate_t.h> // works on most Unixes
+ #elif __has_include(<sys/_types/_mbstate_t.h>)
+ #  include <sys/_types/_mbstate_t.h> // works on Darwin
+-#elif __has_include_next(<wchar.h>)
+-#  include_next <wchar.h> // use the C standard provider of mbstate_t if 
present
+ #elif __has_include_next(<uchar.h>)
+ #  include_next <uchar.h> // Try <uchar.h> in absence of <wchar.h> for 
mbstate_t
+ #else
+diff --git a/src/random.cpp b/src/random.cpp
+index 5c6644811b..9fcc802208 100644
+--- a/src/random.cpp
++++ b/src/random.cpp
+@@ -27,7 +27,7 @@
+ #elif defined(_LIBCPP_USING_DEV_RANDOM)
+ #  include <fcntl.h>
+ #  include <unistd.h>
+-#  if __has_include(<sys/ioctl.h>) && __has_include(<linux/random.h>)
++#  if __has_include(<sys/ioctl.h>) && __has_include(<linux/random.h>) && 
defined(__linux__)
+ #    include <linux/random.h>
+ #    include <sys/ioctl.h>
+ #  endif
diff --git a/libs/libxx/libcxx/0001-libcxx-remove-mach-time-h.patch 
b/libs/libxx/libcxx/0001-libcxx-remove-mach-time-h.patch
deleted file mode 100644
index 7019bc6d563..00000000000
--- a/libs/libxx/libcxx/0001-libcxx-remove-mach-time-h.patch
+++ /dev/null
@@ -1,13 +0,0 @@
---- libcxx/src/chrono.cpp
-+++ libcxx/src/chrono.cpp
-@@ -48,10 +48,6 @@
- #  include <zircon/syscalls.h>
- #endif
- 
--#if __has_include(<mach/mach_time.h>)
--# include <mach/mach_time.h>
--#endif
--
- #if defined(__ELF__) && defined(_LIBCPP_LINK_RT_LIB)
- #  pragma comment(lib, "rt")
- #endif
diff --git a/libs/libxx/libcxx/0001_fix_stdatomic_h_miss_typedef.patch 
b/libs/libxx/libcxx/0001_fix_stdatomic_h_miss_typedef.patch
deleted file mode 100644
index 56ae62c4023..00000000000
--- a/libs/libxx/libcxx/0001_fix_stdatomic_h_miss_typedef.patch
+++ /dev/null
@@ -1,11 +0,0 @@
---- libcxx/include/stdatomic.h.old     2023-12-06 21:01:46.168049453 +0800
-+++ libcxx/include/stdatomic.h 2023-12-06 21:01:55.056057032 +0800
-@@ -220,7 +220,7 @@
- using std::atomic_signal_fence _LIBCPP_USING_IF_EXISTS;
- using std::atomic_thread_fence _LIBCPP_USING_IF_EXISTS;
- 
--#elif defined(_LIBCPP_COMPILER_CLANG_BASED)
-+#else
- 
- // Before C++23, we include the next <stdatomic.h> on the path to avoid 
hijacking
- // the header. We do this because Clang has historically shipped a 
<stdatomic.h>
diff --git 
a/libs/libxx/libcxx/0002-libcxx-__fwd-ios.h-fix-streamoff-type-mismatch-by-re.patch
 
b/libs/libxx/libcxx/0002-libcxx-__fwd-ios.h-fix-streamoff-type-mismatch-by-re.patch
new file mode 100644
index 00000000000..2ee9c8d8412
--- /dev/null
+++ 
b/libs/libxx/libcxx/0002-libcxx-__fwd-ios.h-fix-streamoff-type-mismatch-by-re.patch
@@ -0,0 +1,31 @@
+From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
+From: v-zhangxiaomeng5 <[email protected]>
+Date: Mon, 6 Apr 2026 15:58:53 +0800
+Subject: [PATCH] libcxx/__fwd/ios.h: fix streamoff type mismatch by removing
+ _NEWLIB_VERSION guard
+
+The original guard "#if defined(_NEWLIB_VERSION)" set streamoff to long int 
(matching newlib's off_t). However, _NEWLIB_VERSION leaks into NuttX builds 
through the toolchain's newlib headers via the include chain: libcxx/math.h -> 
toolchain math.h -> sys/reent.h -> sys/cdefs.h -> sys/features.h -> 
_newlib_version.h. This leak only affects source files that transitively 
include math.h, causing different libcxx .cpp files to see different streamoff 
types - iostream.cpp gets long int while  [...]
+NuttX uses its own libc (not newlib) with off_t = int64_t, so streamoff should 
always be long long. The upstream llvm is also moving away from _NEWLIB_VERSION 
detection toward an explicit _LIBCPP_LIBC_NEWLIB CMake-configured macro 
(targeting llvm-22+).
+
+Signed-off-by: v-zhangxiaomeng5 <[email protected]>
+---
+ include/__fwd/ios.h | 5 -----
+ 1 file changed, 5 deletions(-)
+
+diff --git a/include/__fwd/ios.h b/include/__fwd/ios.h
+index 831624f4b1..abcff9abd6 100644
+--- a/include/__fwd/ios.h
++++ b/include/__fwd/ios.h
+@@ -31,12 +31,7 @@ using wios = basic_ios<wchar_t>;
+ template <class _CharT, class _Traits>
+ class _LIBCPP_PREFERRED_NAME(ios) 
_LIBCPP_IF_WIDE_CHARACTERS(_LIBCPP_PREFERRED_NAME(wios)) basic_ios;
+ 
+-#if defined(_NEWLIB_VERSION)
+-// On newlib, off_t is 'long int'
+-using streamoff = long int; // for char_traits in <string>
+-#else
+ using streamoff = long long; // for char_traits in <string>
+-#endif
+ 
+ _LIBCPP_END_NAMESPACE_STD
+ 
diff --git 
a/libs/libxx/libcxx/0003-from_chars_floating_point.h-replace-llvm-libc-shared.patch
 
b/libs/libxx/libcxx/0003-from_chars_floating_point.h-replace-llvm-libc-shared.patch
new file mode 100644
index 00000000000..ab37ad18d35
--- /dev/null
+++ 
b/libs/libxx/libcxx/0003-from_chars_floating_point.h-replace-llvm-libc-shared.patch
@@ -0,0 +1,50 @@
+From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
+From: v-zhangxiaomeng5 <[email protected]>
+Date: Sun, 5 Apr 2026 23:59:04 +0800
+Subject: [PATCH] from_chars_floating_point.h: replace llvm-libc shared headers
+ with from_chars_support.h
+
+llvm-21's from_chars_floating_point.h implementation depends on 3 llvm-libc 
shared headers which pull in 146 internal header files. Add a self-contained 
from_chars_support.h(under nuttx repo) that delegates actual float parsing to 
nuttx strtof/strtod, replacing the 146-file dependency tree.
+Known limitations of from_chars_support.h:
+- Correctness depends on system strtod quality
+- Extremely long inputs (500+ digits) may lose precision due to mantissa 
truncation during the mantissa->string->strtod round-trip
+- Overflow boundary rounding may differ from IEEE 754 strict compliance
+
+Signed-off-by: v-zhangxiaomeng5 <[email protected]>
+---
+ src/include/from_chars_floating_point.h | 15 ++++++++++-----
+ 1 file changed, 10 insertions(+), 5 deletions(-)
+
+diff --git a/src/include/from_chars_floating_point.h 
b/src/include/from_chars_floating_point.h
+index 19eeeb28fb..9cbabcd106 100644
+--- a/src/include/from_chars_floating_point.h
++++ b/src/include/from_chars_floating_point.h
+@@ -9,11 +9,6 @@
+ #ifndef _LIBCPP_SRC_INCLUDE_FROM_CHARS_FLOATING_POINT_H
+ #define _LIBCPP_SRC_INCLUDE_FROM_CHARS_FLOATING_POINT_H
+ 
+-// These headers are in the shared LLVM-libc header library.
+-#include "shared/fp_bits.h"
+-#include "shared/str_to_float.h"
+-#include "shared/str_to_integer.h"
+-
+ #include <__assert>
+ #include <__config>
+ #include <cctype>
+@@ -24,6 +19,16 @@
+ // Included for the _Floating_type_traits class
+ #include "to_chars_floating_point.h"
+ 
++// Included if llvm-libc/shared/ presents,
++// otherwise include libxx/libcxx/from_chars_support.h
++#if __has_include("shared/fp_bits.h")
++#include "shared/fp_bits.h"
++#include "shared/str_to_float.h"
++#include "shared/str_to_integer.h"
++#else
++#include "from_chars_support.h"
++#endif
++
+ _LIBCPP_BEGIN_NAMESPACE_STD
+ 
+ // Parses an infinity string.
diff --git 
a/libs/libxx/libcxx/0004-libcxx-provide-what-GCC-12-lacks-from-GCC-13.patch 
b/libs/libxx/libcxx/0004-libcxx-provide-what-GCC-12-lacks-from-GCC-13.patch
new file mode 100644
index 00000000000..b1294123788
--- /dev/null
+++ b/libs/libxx/libcxx/0004-libcxx-provide-what-GCC-12-lacks-from-GCC-13.patch
@@ -0,0 +1,314 @@
+From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
+From: v-zhangxiaomeng5 <[email protected]>
+Date: Fri, 13 Nov 2026 12:11:38 +0800
+Subject: [PATCH] libcxx: provide what GCC 12 lacks from GCC 13
+
+llvm 21 relies on builtins and a language change that arrived in
+GCC 13, without a fallback. With GCC 12 the library fails to build:
+
+  remove_reference.h:37: #error "remove_reference not implemented!"
+  tuple:1547: 'remove_reference_t' was not declared in this scope
+  remove_cvref.h:23: expected type-specifier before '__remove_cvref'
+  is_convertible.h:35: '__is_convertible' was not declared in this scope
+  is_convertible.h:118: there are no arguments to
+    '__is_nothrow_convertible' that depend on a template parameter
+  reference_constructs_from_temporary.h:39: there are no arguments to
+    '__reference_binds_to_temporary' that depend on a template parameter
+  pointer_traits.h:57: static assertion failed: Cannot rebind pointer;
+    did you forget to add a rebind member to your pointer?
+
+remove_reference, remove_cvref, is_convertible and
+is_nothrow_convertible are built on __remove_reference, __remove_cvref,
+__is_convertible and __is_nothrow_convertible. Restore the portable
+implementations libc++ had before these builtins became mandatory,
+behind __has_builtin, so that a compiler providing them is unaffected.
+
+reference_constructs_from_temporary falls back to
+__reference_binds_to_temporary without checking for it. Detecting a
+temporary needs compiler support, so where neither builtin exists
+assume none is bound, which is what the only user of the trait, the
+dangling reference check of tuple, treated as the pass case before the
+trait existed.
+
+pointer_traits uses static_assert(false) inside a template, which GCC
+12 evaluates when parsing the template. Make the condition depend on
+the template parameter so that it is only evaluated on instantiation.
+
+Signed-off-by: v-zhangxiaomeng5 <[email protected]>
+---
+ include/__memory/pointer_traits.h             |   4 +-
+ include/__type_traits/is_convertible.h        | 119 +++++++++++++++++-
+ include/__type_traits/is_unqualified.h        |   3 +-
+ .../reference_constructs_from_temporary.h     |   7 +-
+ include/__type_traits/remove_cvref.h          |  16 ++-
+ include/__type_traits/remove_reference.h      |  10 +-
+ 6 files changed, 151 insertions(+), 8 deletions(-)
+
+diff --git a/include/__memory/pointer_traits.h 
b/include/__memory/pointer_traits.h
+index 8c7f8dff1b..435591fff7 100644
+--- a/include/__memory/pointer_traits.h
++++ b/include/__memory/pointer_traits.h
+@@ -54,7 +54,9 @@ struct __pointer_traits_element_type<_Ptr, __void_t<typename 
_Ptr::element_type>
+ 
+ template <class _Tp, class _Up>
+ struct __pointer_traits_rebind_impl {
+-  static_assert(false, "Cannot rebind pointer; did you forget to add a rebind 
member to your pointer?");
++  // The condition is made dependent on purpose: static_assert(false) inside a
++  // template is only well-formed since C++23.
++  static_assert(sizeof(_Tp*) == 0, "Cannot rebind pointer; did you forget to 
add a rebind member to your pointer?");
+ };
+ 
+ template <template <class, class...> class _Sp, class _Tp, class... _Args, 
class _Up>
+diff --git a/include/__type_traits/is_convertible.h 
b/include/__type_traits/is_convertible.h
+index f0a859f9cc..0678862283 100644
+--- a/include/__type_traits/is_convertible.h
++++ b/include/__type_traits/is_convertible.h
+@@ -12,28 +12,143 @@
+ #include <__config>
+ #include <__type_traits/integral_constant.h>
+ 
++#if !__has_builtin(__is_convertible)
++// No __is_convertible builtin; the headers below are needed by the fallback.
++#  include <__cstddef/size_t.h>
++#  include <__type_traits/is_array.h>
++#  include <__type_traits/is_function.h>
++#  include <__type_traits/is_void.h>
++#  include <__type_traits/remove_reference.h>
++#  include <__utility/declval.h>
++#endif
++
++#if _LIBCPP_STD_VER >= 20 && !__has_builtin(__is_nothrow_convertible)
++// No __is_nothrow_convertible builtin; the headers below are needed by the 
fallback.
++#  include <__type_traits/conjunction.h>
++#  include <__type_traits/disjunction.h>
++#  include <__type_traits/is_void.h>
++#  include <__type_traits/lazy.h>
++#  include <__utility/declval.h>
++#endif
++
+ #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
+ #  pragma GCC system_header
+ #endif
+ 
+ _LIBCPP_BEGIN_NAMESPACE_STD
+ 
++#if __has_builtin(__is_convertible)
+ template <class _T1, class _T2>
+ struct _LIBCPP_NO_SPECIALIZATIONS is_convertible : integral_constant<bool, 
__is_convertible(_T1, _T2)> {};
+ 
+-#if _LIBCPP_STD_VER >= 17
++#  if _LIBCPP_STD_VER >= 17
+ template <class _From, class _To>
+ _LIBCPP_NO_SPECIALIZATIONS inline constexpr bool is_convertible_v = 
__is_convertible(_From, _To);
+-#endif
++#  endif
++
++#else // !__has_builtin(__is_convertible)
++
++namespace __is_convertible_imp {
++template <class _Tp>
++void __test_convert(_Tp);
++
++template <class _From, class _To, class = void>
++struct __is_convertible_test : false_type {};
++
++template <class _From, class _To>
++struct __is_convertible_test<_From, _To, 
decltype(__is_convertible_imp::__test_convert<_To>(std::declval<_From>()))>
++    : true_type {};
++
++// clang-format off
++template <class _Tp,
++          bool _IsArray    = is_array<_Tp>::value,
++          bool _IsFunction = is_function<_Tp>::value,
++          bool _IsVoid     = is_void<_Tp>::value>
++                     struct __is_array_function_or_void                       
   { enum { value = 0 }; };
++template <class _Tp> struct __is_array_function_or_void<_Tp, true, false, 
false> { enum { value = 1 }; };
++template <class _Tp> struct __is_array_function_or_void<_Tp, false, true, 
false> { enum { value = 2 }; };
++template <class _Tp> struct __is_array_function_or_void<_Tp, false, false, 
true> { enum { value = 3 }; };
++// clang-format on
++} // namespace __is_convertible_imp
++
++template <class _Tp,
++          unsigned = 
__is_convertible_imp::__is_array_function_or_void<__libcpp_remove_reference_t<_Tp>
 >::value>
++struct __is_convertible_check {
++  static const size_t __v = 0;
++};
++
++template <class _Tp>
++struct __is_convertible_check<_Tp, 0> {
++  static const size_t __v = sizeof(_Tp);
++};
++
++// clang-format off
++template <class _T1,
++          class _T2,
++          unsigned _T1_is_array_function_or_void = 
__is_convertible_imp::__is_array_function_or_void<_T1>::value,
++          unsigned _T2_is_array_function_or_void = 
__is_convertible_imp::__is_array_function_or_void<_T2>::value>
++struct __is_convertible : integral_constant<bool, 
__is_convertible_imp::__is_convertible_test<_T1, _T2>::value> {};
++
++template <class _T1, class _T2> struct __is_convertible<_T1, _T2, 0, 1> : 
false_type {};
++template <class _T1, class _T2> struct __is_convertible<_T1, _T2, 1, 1> : 
false_type {};
++template <class _T1, class _T2> struct __is_convertible<_T1, _T2, 2, 1> : 
false_type {};
++template <class _T1, class _T2> struct __is_convertible<_T1, _T2, 3, 1> : 
false_type {};
++
++template <class _T1, class _T2> struct __is_convertible<_T1, _T2, 0, 2> : 
false_type {};
++template <class _T1, class _T2> struct __is_convertible<_T1, _T2, 1, 2> : 
false_type {};
++template <class _T1, class _T2> struct __is_convertible<_T1, _T2, 2, 2> : 
false_type {};
++template <class _T1, class _T2> struct __is_convertible<_T1, _T2, 3, 2> : 
false_type {};
++
++template <class _T1, class _T2> struct __is_convertible<_T1, _T2, 0, 3> : 
false_type {};
++template <class _T1, class _T2> struct __is_convertible<_T1, _T2, 1, 3> : 
false_type {};
++template <class _T1, class _T2> struct __is_convertible<_T1, _T2, 2, 3> : 
false_type {};
++template <class _T1, class _T2> struct __is_convertible<_T1, _T2, 3, 3> : 
true_type {};
++// clang-format on
++
++template <class _T1, class _T2>
++struct is_convertible : __is_convertible<_T1, _T2> {
++  static const size_t __complete_check1 = __is_convertible_check<_T1>::__v;
++  static const size_t __complete_check2 = __is_convertible_check<_T2>::__v;
++};
++
++#  if _LIBCPP_STD_VER >= 17
++template <class _From, class _To>
++inline constexpr bool is_convertible_v = is_convertible<_From, _To>::value;
++#  endif
++
++#endif // __has_builtin(__is_convertible)
+ 
+ #if _LIBCPP_STD_VER >= 20
+ 
++#  if __has_builtin(__is_nothrow_convertible)
++
+ template <class _Tp, class _Up>
+ struct _LIBCPP_NO_SPECIALIZATIONS is_nothrow_convertible : 
bool_constant<__is_nothrow_convertible(_Tp, _Up)> {};
+ 
+ template <class _Tp, class _Up>
+ _LIBCPP_NO_SPECIALIZATIONS inline constexpr bool is_nothrow_convertible_v = 
__is_nothrow_convertible(_Tp, _Up);
+ 
++#  else // __has_builtin(__is_nothrow_convertible)
++
++template <typename _Tp>
++void __test_noexcept(_Tp) noexcept;
++
++template <typename _Fm, typename _To>
++bool_constant<noexcept(std::__test_noexcept<_To>(std::declval<_Fm>()))> 
__is_nothrow_convertible_test();
++
++template <typename _Fm, typename _To>
++struct __is_nothrow_convertible_helper : 
decltype(std::__is_nothrow_convertible_test<_Fm, _To>()) {};
++
++template <typename _Fm, typename _To>
++struct is_nothrow_convertible
++    : _Or<_And<is_void<_To>, is_void<_Fm>>,
++          _Lazy<_And, is_convertible<_Fm, _To>, 
__is_nothrow_convertible_helper<_Fm, _To> > >::type {};
++
++template <typename _Fm, typename _To>
++inline constexpr bool is_nothrow_convertible_v = is_nothrow_convertible<_Fm, 
_To>::value;
++
++#  endif // __has_builtin(__is_nothrow_convertible)
++
+ #endif // _LIBCPP_STD_VER >= 20
+ 
+ _LIBCPP_END_NAMESPACE_STD
+diff --git a/include/__type_traits/is_unqualified.h 
b/include/__type_traits/is_unqualified.h
+index 7970b36116..617a9b072b 100644
+--- a/include/__type_traits/is_unqualified.h
++++ b/include/__type_traits/is_unqualified.h
+@@ -10,6 +10,7 @@
+ #define _LIBCPP___TYPE_TRAITS_IS_UNQUALIFIED_H
+ 
+ #include <__config>
++#include <__type_traits/remove_cvref.h> // for __remove_cvref_t
+ 
+ #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
+ #  pragma GCC system_header
+@@ -18,7 +19,7 @@
+ _LIBCPP_BEGIN_NAMESPACE_STD
+ 
+ template <class _Tp>
+-inline const bool __is_unqualified_v = __is_same(_Tp, __remove_cvref(_Tp));
++inline const bool __is_unqualified_v = __is_same(_Tp, __remove_cvref_t<_Tp>);
+ 
+ _LIBCPP_END_NAMESPACE_STD
+ 
+diff --git a/include/__type_traits/reference_constructs_from_temporary.h 
b/include/__type_traits/reference_constructs_from_temporary.h
+index 2ff549b4e1..61532a41d3 100644
+--- a/include/__type_traits/reference_constructs_from_temporary.h
++++ b/include/__type_traits/reference_constructs_from_temporary.h
+@@ -33,10 +33,15 @@ _LIBCPP_NO_SPECIALIZATIONS inline constexpr bool 
reference_constructs_from_tempo
+ #if __has_builtin(__reference_constructs_from_temporary)
+ template <class _Tp, class _Up>
+ inline const bool __reference_constructs_from_temporary_v = 
__reference_constructs_from_temporary(_Tp, _Up);
+-#else
++#elif __has_builtin(__reference_binds_to_temporary)
+ // TODO(LLVM 22): Remove this as all supported compilers should have 
__reference_constructs_from_temporary implemented.
+ template <class _Tp, class _Up>
+ inline const bool __reference_constructs_from_temporary_v = 
__reference_binds_to_temporary(_Tp, _Up);
++#else
++// Neither builtin is available, for example with the TASKING compiler. Only a
++// diagnostic is lost by assuming that no temporary is bound.
++template <class _Tp, class _Up>
++inline const bool __reference_constructs_from_temporary_v = false;
+ #endif
+ 
+ _LIBCPP_END_NAMESPACE_STD
+diff --git a/include/__type_traits/remove_cvref.h 
b/include/__type_traits/remove_cvref.h
+index c568e8df30..d99da622a1 100644
+--- a/include/__type_traits/remove_cvref.h
++++ b/include/__type_traits/remove_cvref.h
+@@ -11,13 +11,25 @@
+ 
+ #include <__config>
+ 
++#if !__has_builtin(__remove_cvref)
++// The trait is composed from __remove_cv and __remove_reference when the
++// builtin is absent.
++#  include <__type_traits/remove_cv.h>
++#  include <__type_traits/remove_reference.h>
++#endif
++
+ #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
+ #  pragma GCC system_header
+ #endif
+ 
+ _LIBCPP_BEGIN_NAMESPACE_STD
+ 
+-#if defined(_LIBCPP_COMPILER_GCC)
++#if !__has_builtin(__remove_cvref)
++// Neither TASKING nor GCC before 14 has the builtin; compose the trait from
++// __remove_cv and __remove_reference instead.
++template <class _Tp>
++using __remove_cvref_t _LIBCPP_NODEBUG = 
__remove_cv_t<__libcpp_remove_reference_t<_Tp> >;
++#elif defined(_LIBCPP_COMPILER_GCC)
+ template <class _Tp>
+ struct __remove_cvref_gcc {
+   using type = __remove_cvref(_Tp);
+@@ -33,7 +45,7 @@ using __remove_cvref_t _LIBCPP_NODEBUG = __remove_cvref(_Tp);
+ #if _LIBCPP_STD_VER >= 20
+ template <class _Tp>
+ struct _LIBCPP_NO_SPECIALIZATIONS remove_cvref {
+-  using type _LIBCPP_NODEBUG = __remove_cvref(_Tp);
++  using type _LIBCPP_NODEBUG = __remove_cvref_t<_Tp>;
+ };
+ 
+ template <class _Tp>
+diff --git a/include/__type_traits/remove_reference.h 
b/include/__type_traits/remove_reference.h
+index 7cc3ca1705..d66b2e8da2 100644
+--- a/include/__type_traits/remove_reference.h
++++ b/include/__type_traits/remove_reference.h
+@@ -34,7 +34,15 @@ struct remove_reference {
+ template <class _Tp>
+ using __libcpp_remove_reference_t = typename remove_reference<_Tp>::type;
+ #else
+-#  error "remove_reference not implemented!"
++// Neither builtin is available, for example with the TASKING compiler.
++// clang-format off
++template <class _Tp> struct remove_reference        {using type 
_LIBCPP_NODEBUG = _Tp;};
++template <class _Tp> struct remove_reference<_Tp&>  {using type 
_LIBCPP_NODEBUG = _Tp;};
++template <class _Tp> struct remove_reference<_Tp&&> {using type 
_LIBCPP_NODEBUG = _Tp;};
++// clang-format on
++
++template <class _Tp>
++using __libcpp_remove_reference_t _LIBCPP_NODEBUG = typename 
remove_reference<_Tp>::type;
+ #endif // __has_builtin(__remove_reference_t)
+ 
+ #if _LIBCPP_STD_VER >= 14
diff --git 
a/libs/libxx/libcxx/0005-libcxx-provide-what-GCC-12-and-13-lack-from-GCC-14-a.patch
 
b/libs/libxx/libcxx/0005-libcxx-provide-what-GCC-12-and-13-lack-from-GCC-14-a.patch
new file mode 100644
index 00000000000..331f3ff8c5e
--- /dev/null
+++ 
b/libs/libxx/libcxx/0005-libcxx-provide-what-GCC-12-and-13-lack-from-GCC-14-a.patch
@@ -0,0 +1,801 @@
+From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
+From: v-zhangxiaomeng5 <[email protected]>
+Date: Fri, 13 Nov 2026 12:11:38 +0800
+Subject: [PATCH] libcxx: provide what GCC 12 and 13 lack from GCC 14 and 15
+
+llvm 21 uses compiler builtins that GCC added in versions 14 and 15.
+Add fallbacks for them, keeping the original code for compilers that
+provide the builtins.
+
+The type trait builtins, such as __is_array, __is_const, __remove_cv
+and __decay, get template based implementations. The ones GCC added in
+14 are selected by _LIBCPP_GCC_VER < 1400. The ones it only added in
+15 are selected by __has_builtin, since GCC 14 lacks them as well.
+
+__builtin_clzg, __builtin_ctzg and __builtin_popcountg dispatch to the
+__builtin_clz, __builtin_ctz and __builtin_popcount variants.
+
+__type_pack_element gets a recursive template in tuple_element.h,
+make_tuple_types.h and variant.
+
+__builtin_operator_new and __builtin_operator_delete, which only Clang
+has, become ::operator new and ::operator delete.
+
+is_void.h and is_null_pointer.h use __remove_cv_t instead of calling
+the __remove_cv builtin.
+
+bitset silences a false -Wstringop-overflow in to_string() from GCC 13.
+
+Signed-off-by: v-zhangxiaomeng5 <[email protected]>
+---
+ include/__bit/countl.h                     | 11 +++++++
+ include/__bit/countr.h                     | 11 +++++++
+ include/__bit/popcount.h                   |  9 ++++++
+ include/__new/allocate.h                   | 17 ++++++++++
+ include/__tuple/make_tuple_types.h         |  5 +++
+ include/__tuple/tuple_element.h            | 12 ++++++++
+ include/__type_traits/add_pointer.h        |  4 +--
+ include/__type_traits/add_reference.h      | 12 ++++++++
+ include/__type_traits/decay.h              | 22 +++++++++++++
+ include/__type_traits/is_array.h           |  9 ++++++
+ include/__type_traits/is_bounded_array.h   | 12 ++++++++
+ include/__type_traits/is_const.h           |  9 ++++++
+ include/__type_traits/is_function.h        | 12 ++++++++
+ include/__type_traits/is_member_pointer.h  | 36 ++++++++++++++++++++++
+ include/__type_traits/is_null_pointer.h    |  6 ++++
+ include/__type_traits/is_object.h          | 13 ++++++++
+ include/__type_traits/is_pointer.h         | 11 +++++++
+ include/__type_traits/is_reference.h       | 10 ++++++
+ include/__type_traits/is_void.h            | 10 ++++++
+ include/__type_traits/is_volatile.h        |  9 ++++++
+ include/__type_traits/remove_all_extents.h |  6 ++++
+ include/__type_traits/remove_cv.h          |  7 +++++
+ include/__type_traits/remove_extent.h      |  6 ++++
+ include/bitset                             |  6 +++-
+ include/variant                            |  7 +++++
+ 25 files changed, 269 insertions(+), 3 deletions(-)
+
+diff --git a/include/__bit/countl.h b/include/__bit/countl.h
+index 0759140208..d5ccc30260 100644
+--- a/include/__bit/countl.h
++++ b/include/__bit/countl.h
+@@ -25,7 +25,18 @@ _LIBCPP_BEGIN_NAMESPACE_STD
+ template <class _Tp>
+ _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 int __countl_zero(_Tp 
__t) _NOEXCEPT {
+   static_assert(__is_unsigned_integer_v<_Tp>, "__countl_zero requires an 
unsigned integer type");
++#if defined(_LIBCPP_COMPILER_GCC) && _LIBCPP_GCC_VER < 1400
++  if (__t == 0)
++    return numeric_limits<_Tp>::digits;
++  if constexpr (sizeof(_Tp) <= sizeof(unsigned int))
++    return __builtin_clz(static_cast<unsigned int>(__t)) - 
(numeric_limits<unsigned int>::digits - numeric_limits<_Tp>::digits);
++  else if constexpr (sizeof(_Tp) <= sizeof(unsigned long))
++    return __builtin_clzl(static_cast<unsigned long>(__t)) - 
(numeric_limits<unsigned long>::digits - numeric_limits<_Tp>::digits);
++  else
++    return __builtin_clzll(static_cast<unsigned long long>(__t)) - 
(numeric_limits<unsigned long long>::digits - numeric_limits<_Tp>::digits);
++#else
+   return __builtin_clzg(__t, numeric_limits<_Tp>::digits);
++#endif
+ }
+ 
+ #if _LIBCPP_STD_VER >= 20
+diff --git a/include/__bit/countr.h b/include/__bit/countr.h
+index f6c98695d3..b5f1852a7c 100644
+--- a/include/__bit/countr.h
++++ b/include/__bit/countr.h
+@@ -25,7 +25,18 @@ _LIBCPP_BEGIN_NAMESPACE_STD
+ template <class _Tp>
+ [[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR int 
__countr_zero(_Tp __t) _NOEXCEPT {
+   static_assert(__is_unsigned_integer_v<_Tp>, "__countr_zero only works with 
unsigned types");
++#if defined(_LIBCPP_COMPILER_GCC) && _LIBCPP_GCC_VER < 1400
++  if (__t == 0)
++    return numeric_limits<_Tp>::digits;
++  if constexpr (sizeof(_Tp) <= sizeof(unsigned int))
++    return __builtin_ctz(static_cast<unsigned int>(__t));
++  else if constexpr (sizeof(_Tp) <= sizeof(unsigned long))
++    return __builtin_ctzl(static_cast<unsigned long>(__t));
++  else
++    return __builtin_ctzll(static_cast<unsigned long long>(__t));
++#else
+   return __builtin_ctzg(__t, numeric_limits<_Tp>::digits);
++#endif
+ }
+ 
+ #if _LIBCPP_STD_VER >= 20
+diff --git a/include/__bit/popcount.h b/include/__bit/popcount.h
+index 8d9ba09938..609dfd8365 100644
+--- a/include/__bit/popcount.h
++++ b/include/__bit/popcount.h
+@@ -24,7 +24,16 @@ _LIBCPP_BEGIN_NAMESPACE_STD
+ template <class _Tp>
+ [[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR int __popcount(_Tp 
__t) _NOEXCEPT {
+   static_assert(__is_unsigned_integer_v<_Tp>, "__popcount only works with 
unsigned types");
++#if defined(_LIBCPP_COMPILER_GCC) && _LIBCPP_GCC_VER < 1400
++  if constexpr (sizeof(_Tp) <= sizeof(unsigned int))
++    return __builtin_popcount(static_cast<unsigned int>(__t));
++  else if constexpr (sizeof(_Tp) <= sizeof(unsigned long))
++    return __builtin_popcountl(static_cast<unsigned long>(__t));
++  else
++    return __builtin_popcountll(static_cast<unsigned long long>(__t));
++#else
+   return __builtin_popcountg(__t);
++#endif
+ }
+ 
+ #if _LIBCPP_STD_VER >= 20
+diff --git a/include/__new/allocate.h b/include/__new/allocate.h
+index 9bfe19aedb..7541dbb504 100644
+--- a/include/__new/allocate.h
++++ b/include/__new/allocate.h
+@@ -37,10 +37,18 @@ __libcpp_allocate(__element_count __n, 
[[__maybe_unused__]] size_t __align = _LI
+   size_t __size = static_cast<size_t>(__n) * sizeof(_Tp);
+ #if _LIBCPP_HAS_ALIGNED_ALLOCATION
+   if (__is_overaligned_for_new(__align))
++#if defined(_LIBCPP_COMPILER_GCC)
++    return static_cast<_Tp*>(::operator new(__size, 
static_cast<align_val_t>(__align)));
++#else
+     return static_cast<_Tp*>(__builtin_operator_new(__size, 
static_cast<align_val_t>(__align)));
+ #endif
++#endif
+ 
++#if defined(_LIBCPP_COMPILER_GCC)
++  return static_cast<_Tp*>(::operator new(__size));
++#else
+   return static_cast<_Tp*>(__builtin_operator_new(__size));
++#endif
+ }
+ 
+ #if _LIBCPP_HAS_SIZED_DEALLOCATION
+@@ -57,10 +65,19 @@ __libcpp_deallocate(__type_identity_t<_Tp>* __ptr,
+   [[__maybe_unused__]] size_t __size = static_cast<size_t>(__n) * sizeof(_Tp);
+ #if _LIBCPP_HAS_ALIGNED_ALLOCATION
+   if (__is_overaligned_for_new(__align))
++#if defined(_LIBCPP_COMPILER_GCC)
++    return ::operator delete(
++        __ptr _LIBCPP_ONLY_IF_SIZED_DEALLOCATION(, __size), 
static_cast<align_val_t>(__align));
++#else
+     return __builtin_operator_delete(
+         __ptr _LIBCPP_ONLY_IF_SIZED_DEALLOCATION(, __size), 
static_cast<align_val_t>(__align));
+ #endif
++#endif
++#if defined(_LIBCPP_COMPILER_GCC)
++  return ::operator delete(__ptr _LIBCPP_ONLY_IF_SIZED_DEALLOCATION(, 
__size));
++#else
+   return __builtin_operator_delete(__ptr _LIBCPP_ONLY_IF_SIZED_DEALLOCATION(, 
__size));
++#endif
+ }
+ 
+ #undef _LIBCPP_ONLY_IF_SIZED_DEALLOCATION
+diff --git a/include/__tuple/make_tuple_types.h 
b/include/__tuple/make_tuple_types.h
+index a5c9bcf23a..758a58cfc7 100644
+--- a/include/__tuple/make_tuple_types.h
++++ b/include/__tuple/make_tuple_types.h
+@@ -41,7 +41,12 @@ template <template <class...> class _Tuple, class... 
_Types, size_t... _Idx>
+ struct __make_tuple_types_flat<_Tuple<_Types...>, __tuple_indices<_Idx...>> {
+   // Specialization for pair, tuple, and __tuple_types
+   template <class _Tp>
++#if defined(_LIBCPP_COMPILER_GCC) && _LIBCPP_GCC_VER < 1400
++  using __apply_quals _LIBCPP_NODEBUG =
++      __tuple_types<__copy_cvref_t<_Tp, typename 
__type_pack_element_fallback<_Idx, _Types...>::type>...>;
++#else
+   using __apply_quals _LIBCPP_NODEBUG = __tuple_types<__copy_cvref_t<_Tp, 
__type_pack_element<_Idx, _Types...>>...>;
++#endif
+ };
+ 
+ template <class _Vt, size_t _Np, size_t... _Idx>
+diff --git a/include/__tuple/tuple_element.h b/include/__tuple/tuple_element.h
+index f67c867464..9f461733be 100644
+--- a/include/__tuple/tuple_element.h
++++ b/include/__tuple/tuple_element.h
+@@ -40,10 +40,22 @@ struct tuple_element<_Ip, const volatile _Tp> {
+ 
+ #ifndef _LIBCPP_CXX03_LANG
+ 
++#if defined(_LIBCPP_COMPILER_GCC) && _LIBCPP_GCC_VER < 1400
++template <size_t _Ip, class... _Types> struct __type_pack_element_fallback;
++template <class _Head, class... _Tail>
++struct __type_pack_element_fallback<0, _Head, _Tail...> { using type = _Head; 
};
++template <size_t _Ip, class _Head, class... _Tail>
++struct __type_pack_element_fallback<_Ip, _Head, _Tail...> : 
__type_pack_element_fallback<_Ip - 1, _Tail...> {};
++#endif
++
+ template <size_t _Ip, class... _Types>
+ struct tuple_element<_Ip, __tuple_types<_Types...> > {
+   static_assert(_Ip < sizeof...(_Types), "tuple_element index out of range");
++#if defined(_LIBCPP_COMPILER_GCC) && _LIBCPP_GCC_VER < 1400
++  using type _LIBCPP_NODEBUG = typename __type_pack_element_fallback<_Ip, 
_Types...>::type;
++#else
+   using type _LIBCPP_NODEBUG = __type_pack_element<_Ip, _Types...>;
++#endif
+ };
+ 
+ #  if _LIBCPP_STD_VER >= 14
+diff --git a/include/__type_traits/add_pointer.h 
b/include/__type_traits/add_pointer.h
+index fa9376699a..c497f6c446 100644
+--- a/include/__type_traits/add_pointer.h
++++ b/include/__type_traits/add_pointer.h
+@@ -20,7 +20,7 @@
+ 
+ _LIBCPP_BEGIN_NAMESPACE_STD
+ 
+-#if !defined(_LIBCPP_WORKAROUND_OBJCXX_COMPILER_INTRINSICS)
++#if !defined(_LIBCPP_WORKAROUND_OBJCXX_COMPILER_INTRINSICS) && 
__has_builtin(__add_pointer)
+ 
+ template <class _Tp>
+ struct _LIBCPP_NO_SPECIALIZATIONS add_pointer {
+@@ -53,7 +53,7 @@ struct _LIBCPP_NO_SPECIALIZATIONS add_pointer {
+   using type _LIBCPP_NODEBUG = __add_pointer_t<_Tp>;
+ };
+ 
+-#endif // !defined(_LIBCPP_WORKAROUND_OBJCXX_COMPILER_INTRINSICS)
++#endif // !defined(_LIBCPP_WORKAROUND_OBJCXX_COMPILER_INTRINSICS) && 
__has_builtin(__add_pointer)
+ 
+ #if _LIBCPP_STD_VER >= 14
+ template <class _Tp>
+diff --git a/include/__type_traits/add_reference.h 
b/include/__type_traits/add_reference.h
+index c6f5d63d26..3014765803 100644
+--- a/include/__type_traits/add_reference.h
++++ b/include/__type_traits/add_reference.h
+@@ -17,10 +17,16 @@
+ 
+ _LIBCPP_BEGIN_NAMESPACE_STD
+ 
++#if !__has_builtin(__add_lvalue_reference)
++template <class _Tp, class = void> struct __add_lvalue_ref { using type = 
_Tp; };
++template <class _Tp> struct __add_lvalue_ref<_Tp, 
decltype(void(static_cast<_Tp&(*)()>(nullptr)))> { using type = _Tp&; };
++template <class _Tp> struct add_lvalue_reference : __add_lvalue_ref<_Tp> {};
++#else
+ template <class _Tp>
+ struct _LIBCPP_NO_SPECIALIZATIONS add_lvalue_reference {
+   using type _LIBCPP_NODEBUG = __add_lvalue_reference(_Tp);
+ };
++#endif // !__has_builtin(__add_lvalue_reference)
+ 
+ #ifdef _LIBCPP_COMPILER_GCC
+ template <class _Tp>
+@@ -35,10 +41,16 @@ template <class _Tp>
+ using add_lvalue_reference_t = __add_lvalue_reference_t<_Tp>;
+ #endif
+ 
++#if !__has_builtin(__add_rvalue_reference)
++template <class _Tp, class = void> struct __add_rvalue_ref { using type = 
_Tp; };
++template <class _Tp> struct __add_rvalue_ref<_Tp, 
decltype(void(static_cast<_Tp&&(*)()>(nullptr)))> { using type = _Tp&&; };
++template <class _Tp> struct add_rvalue_reference : __add_rvalue_ref<_Tp> {};
++#else
+ template <class _Tp>
+ struct _LIBCPP_NO_SPECIALIZATIONS add_rvalue_reference {
+   using type _LIBCPP_NODEBUG = __add_rvalue_reference(_Tp);
+ };
++#endif // !__has_builtin(__add_rvalue_reference)
+ 
+ #ifdef _LIBCPP_COMPILER_GCC
+ template <class _Tp>
+diff --git a/include/__type_traits/decay.h b/include/__type_traits/decay.h
+index 661fba53df..e12b5a73c6 100644
+--- a/include/__type_traits/decay.h
++++ b/include/__type_traits/decay.h
+@@ -10,6 +10,13 @@
+ #define _LIBCPP___TYPE_TRAITS_DECAY_H
+ 
+ #include <__config>
++#include <__type_traits/remove_reference.h>
++#include <__type_traits/remove_extent.h>
++#include <__type_traits/remove_cv.h>
++#include <__type_traits/is_function.h>
++#include <__type_traits/is_array.h>
++#include <__type_traits/conditional.h>
++#include <__type_traits/add_pointer.h>
+ 
+ #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
+ #  pragma GCC system_header
+@@ -17,10 +24,25 @@
+ 
+ _LIBCPP_BEGIN_NAMESPACE_STD
+ 
++#if !__has_builtin(__decay)
++template <class _Tp>
++struct decay {
++private:
++  using _Up _LIBCPP_NODEBUG = typename remove_reference<_Tp>::type;
++public:
++  using type _LIBCPP_NODEBUG =
++      __conditional_t<is_array<_Up>::value,
++                      __add_pointer_t<typename remove_extent<_Up>::type>,
++                      __conditional_t<is_function<_Up>::value,
++                                      __add_pointer_t<_Up>,
++                                      typename remove_cv<_Up>::type>>;
++};
++#else
+ template <class _Tp>
+ struct _LIBCPP_NO_SPECIALIZATIONS decay {
+   using type _LIBCPP_NODEBUG = __decay(_Tp);
+ };
++#endif // !__has_builtin(__decay)
+ 
+ #ifdef _LIBCPP_COMPILER_GCC
+ template <class _Tp>
+diff --git a/include/__type_traits/is_array.h 
b/include/__type_traits/is_array.h
+index e734d1a304..a92db971fd 100644
+--- a/include/__type_traits/is_array.h
++++ b/include/__type_traits/is_array.h
+@@ -18,6 +18,14 @@
+ 
+ _LIBCPP_BEGIN_NAMESPACE_STD
+ 
++#if defined(_LIBCPP_COMPILER_GCC) && _LIBCPP_GCC_VER < 1400
++template <class _Tp> struct is_array : false_type {};
++template <class _Tp> struct is_array<_Tp[]> : true_type {};
++template <class _Tp, __SIZE_TYPE__ _Np> struct is_array<_Tp[_Np]> : true_type 
{};
++#if _LIBCPP_STD_VER >= 17
++template <class _Tp> inline constexpr bool is_array_v = is_array<_Tp>::value;
++#endif
++#else // GCC >= 14 or Clang
+ template <class _Tp>
+ struct _LIBCPP_NO_SPECIALIZATIONS is_array : _BoolConstant<__is_array(_Tp)> 
{};
+ 
+@@ -25,6 +33,7 @@ struct _LIBCPP_NO_SPECIALIZATIONS is_array : 
_BoolConstant<__is_array(_Tp)> {};
+ template <class _Tp>
+ _LIBCPP_NO_SPECIALIZATIONS inline constexpr bool is_array_v = __is_array(_Tp);
+ #endif
++#endif // _LIBCPP_GCC_VER < 1400
+ 
+ _LIBCPP_END_NAMESPACE_STD
+ 
+diff --git a/include/__type_traits/is_bounded_array.h 
b/include/__type_traits/is_bounded_array.h
+index 8a41e07aa0..c7385e4a22 100644
+--- a/include/__type_traits/is_bounded_array.h
++++ b/include/__type_traits/is_bounded_array.h
+@@ -18,16 +18,28 @@
+ 
+ _LIBCPP_BEGIN_NAMESPACE_STD
+ 
++#if defined(_LIBCPP_COMPILER_GCC) && _LIBCPP_GCC_VER < 1400
++template <class _Tp> inline const bool __is_bounded_array_v = false;
++template <class _Tp, __SIZE_TYPE__ _Np> inline const bool 
__is_bounded_array_v<_Tp[_Np]> = true;
++#else // GCC >= 14 or Clang
+ template <class _Tp>
+ inline const bool __is_bounded_array_v = __is_bounded_array(_Tp);
++#endif // _LIBCPP_GCC_VER < 1400
+ 
+ #if _LIBCPP_STD_VER >= 20
+ 
++#if defined(_LIBCPP_COMPILER_GCC) && _LIBCPP_GCC_VER < 1400
++template <class _Tp> struct is_bounded_array : false_type {};
++template <class _Tp, __SIZE_TYPE__ _Np> struct is_bounded_array<_Tp[_Np]> : 
true_type {};
++template <class _Tp>
++inline constexpr bool is_bounded_array_v = is_bounded_array<_Tp>::value;
++#else // GCC >= 14 or Clang
+ template <class _Tp>
+ struct _LIBCPP_NO_SPECIALIZATIONS is_bounded_array : 
bool_constant<__is_bounded_array(_Tp)> {};
+ 
+ template <class _Tp>
+ _LIBCPP_NO_SPECIALIZATIONS inline constexpr bool is_bounded_array_v = 
__is_bounded_array(_Tp);
++#endif // _LIBCPP_GCC_VER < 1400
+ 
+ #endif
+ 
+diff --git a/include/__type_traits/is_const.h 
b/include/__type_traits/is_const.h
+index 85cc32bff1..7c717b0f90 100644
+--- a/include/__type_traits/is_const.h
++++ b/include/__type_traits/is_const.h
+@@ -18,6 +18,14 @@
+ 
+ _LIBCPP_BEGIN_NAMESPACE_STD
+ 
++#if !__has_builtin(__is_const)
++template <class _Tp> struct is_const : false_type {};
++template <class _Tp> struct is_const<_Tp const> : true_type {};
++#if _LIBCPP_STD_VER >= 17
++template <class _Tp> inline constexpr bool is_const_v = false;
++template <class _Tp> inline constexpr bool is_const_v<const _Tp> = true;
++#endif
++#else
+ template <class _Tp>
+ struct _LIBCPP_NO_SPECIALIZATIONS is_const : _BoolConstant<__is_const(_Tp)> 
{};
+ 
+@@ -25,6 +33,7 @@ struct _LIBCPP_NO_SPECIALIZATIONS is_const : 
_BoolConstant<__is_const(_Tp)> {};
+ template <class _Tp>
+ _LIBCPP_NO_SPECIALIZATIONS inline constexpr bool is_const_v = __is_const(_Tp);
+ #endif
++#endif // !__has_builtin(__is_const)
+ 
+ _LIBCPP_END_NAMESPACE_STD
+ 
+diff --git a/include/__type_traits/is_function.h 
b/include/__type_traits/is_function.h
+index 119892ee1a..afe801b226 100644
+--- a/include/__type_traits/is_function.h
++++ b/include/__type_traits/is_function.h
+@@ -11,6 +11,8 @@
+ 
+ #include <__config>
+ #include <__type_traits/integral_constant.h>
++#include <__type_traits/is_const.h>
++#include <__type_traits/is_reference.h>
+ 
+ #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
+ #  pragma GCC system_header
+@@ -18,6 +20,15 @@
+ 
+ _LIBCPP_BEGIN_NAMESPACE_STD
+ 
++#if defined(_LIBCPP_COMPILER_GCC) && _LIBCPP_GCC_VER < 1400
++template <class _Tp>
++struct is_function
++    : public integral_constant<bool, !(is_reference<_Tp>::value || 
is_const<const _Tp>::value)> {};
++#if _LIBCPP_STD_VER >= 17
++template <class _Tp>
++inline constexpr bool is_function_v = is_function<_Tp>::value;
++#endif
++#else // GCC >= 14 or Clang
+ template <class _Tp>
+ struct _LIBCPP_NO_SPECIALIZATIONS is_function : integral_constant<bool, 
__is_function(_Tp)> {};
+ 
+@@ -25,6 +36,7 @@ struct _LIBCPP_NO_SPECIALIZATIONS is_function : 
integral_constant<bool, __is_fun
+ template <class _Tp>
+ _LIBCPP_NO_SPECIALIZATIONS inline constexpr bool is_function_v = 
__is_function(_Tp);
+ #endif
++#endif // _LIBCPP_GCC_VER < 1400
+ 
+ _LIBCPP_END_NAMESPACE_STD
+ 
+diff --git a/include/__type_traits/is_member_pointer.h 
b/include/__type_traits/is_member_pointer.h
+index e4fd9e0f26..e46aa004bb 100644
+--- a/include/__type_traits/is_member_pointer.h
++++ b/include/__type_traits/is_member_pointer.h
+@@ -11,6 +11,7 @@
+ 
+ #include <__config>
+ #include <__type_traits/integral_constant.h>
++#include <__type_traits/remove_cv.h>
+ 
+ #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
+ #  pragma GCC system_header
+@@ -18,6 +19,39 @@
+ 
+ _LIBCPP_BEGIN_NAMESPACE_STD
+ 
++#if defined(_LIBCPP_COMPILER_GCC) && _LIBCPP_GCC_VER < 1400
++
++template <class _Tp> struct __libcpp_is_member_pointer : false_type {};
++template <class _Tp, class _Cl> struct __libcpp_is_member_pointer<_Tp _Cl::*> 
: true_type {};
++template <class _Tp> struct is_member_pointer : 
__libcpp_is_member_pointer<__remove_cv_t<_Tp>> {};
++
++template <class _Tp> struct __libcpp_is_member_fn_ptr : false_type {};
++template <class _Rp, class _Cl, class... _As> struct 
__libcpp_is_member_fn_ptr<_Rp (_Cl::*)(_As...)> : true_type {};
++template <class _Rp, class _Cl, class... _As> struct 
__libcpp_is_member_fn_ptr<_Rp (_Cl::*)(_As...) const> : true_type {};
++template <class _Rp, class _Cl, class... _As> struct 
__libcpp_is_member_fn_ptr<_Rp (_Cl::*)(_As...) volatile> : true_type {};
++template <class _Rp, class _Cl, class... _As> struct 
__libcpp_is_member_fn_ptr<_Rp (_Cl::*)(_As...) const volatile> : true_type {};
++template <class _Rp, class _Cl, class... _As> struct 
__libcpp_is_member_fn_ptr<_Rp (_Cl::*)(_As...)&> : true_type {};
++template <class _Rp, class _Cl, class... _As> struct 
__libcpp_is_member_fn_ptr<_Rp (_Cl::*)(_As...) const&> : true_type {};
++template <class _Rp, class _Cl, class... _As> struct 
__libcpp_is_member_fn_ptr<_Rp (_Cl::*)(_As...) volatile&> : true_type {};
++template <class _Rp, class _Cl, class... _As> struct 
__libcpp_is_member_fn_ptr<_Rp (_Cl::*)(_As...) const volatile&> : true_type {};
++template <class _Rp, class _Cl, class... _As> struct 
__libcpp_is_member_fn_ptr<_Rp (_Cl::*)(_As...)&&> : true_type {};
++template <class _Rp, class _Cl, class... _As> struct 
__libcpp_is_member_fn_ptr<_Rp (_Cl::*)(_As...) const&&> : true_type {};
++template <class _Rp, class _Cl, class... _As> struct 
__libcpp_is_member_fn_ptr<_Rp (_Cl::*)(_As...) volatile&&> : true_type {};
++template <class _Rp, class _Cl, class... _As> struct 
__libcpp_is_member_fn_ptr<_Rp (_Cl::*)(_As...) const volatile&&> : true_type {};
++template <class _Tp> struct is_member_function_pointer : 
__libcpp_is_member_fn_ptr<__remove_cv_t<_Tp>> {};
++
++template <class _Tp>
++struct is_member_object_pointer
++    : _BoolConstant<is_member_pointer<_Tp>::value && 
!is_member_function_pointer<_Tp>::value> {};
++
++#if _LIBCPP_STD_VER >= 17
++template <class _Tp> inline constexpr bool is_member_pointer_v = 
is_member_pointer<_Tp>::value;
++template <class _Tp> inline constexpr bool is_member_object_pointer_v = 
is_member_object_pointer<_Tp>::value;
++template <class _Tp> inline constexpr bool is_member_function_pointer_v = 
is_member_function_pointer<_Tp>::value;
++#endif
++
++#else // GCC >= 14 or Clang
++
+ template <class _Tp>
+ struct _LIBCPP_NO_SPECIALIZATIONS is_member_pointer : 
_BoolConstant<__is_member_pointer(_Tp)> {};
+ 
+@@ -38,6 +72,8 @@ template <class _Tp>
+ _LIBCPP_NO_SPECIALIZATIONS inline constexpr bool is_member_function_pointer_v 
= __is_member_function_pointer(_Tp);
+ #endif
+ 
++#endif // _LIBCPP_GCC_VER < 1400
++
+ _LIBCPP_END_NAMESPACE_STD
+ 
+ #endif // _LIBCPP___TYPE_TRAITS_IS_MEMBER_POINTER_H
+diff --git a/include/__type_traits/is_null_pointer.h 
b/include/__type_traits/is_null_pointer.h
+index 63bfb7d4da..54fe9aa33c 100644
+--- a/include/__type_traits/is_null_pointer.h
++++ b/include/__type_traits/is_null_pointer.h
+@@ -12,6 +12,7 @@
+ #include <__config>
+ #include <__cstddef/nullptr_t.h>
+ #include <__type_traits/integral_constant.h>
++#include <__type_traits/remove_cv.h>
+ 
+ #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
+ #  pragma GCC system_header
+@@ -19,8 +20,13 @@
+ 
+ _LIBCPP_BEGIN_NAMESPACE_STD
+ 
++#if defined(_LIBCPP_COMPILER_GCC) && _LIBCPP_GCC_VER < 1400
++template <class _Tp>
++inline const bool __is_null_pointer_v = __is_same(__remove_cv_t<_Tp>, 
nullptr_t);
++#else // GCC >= 14 or Clang
+ template <class _Tp>
+ inline const bool __is_null_pointer_v = __is_same(__remove_cv(_Tp), 
nullptr_t);
++#endif // _LIBCPP_GCC_VER < 1400
+ 
+ #if _LIBCPP_STD_VER >= 14
+ template <class _Tp>
+diff --git a/include/__type_traits/is_object.h 
b/include/__type_traits/is_object.h
+index 6532835961..4395817045 100644
+--- a/include/__type_traits/is_object.h
++++ b/include/__type_traits/is_object.h
+@@ -11,6 +11,9 @@
+ 
+ #include <__config>
+ #include <__type_traits/integral_constant.h>
++#include <__type_traits/is_function.h>
++#include <__type_traits/is_reference.h>
++#include <__type_traits/is_void.h>
+ 
+ #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
+ #  pragma GCC system_header
+@@ -18,6 +21,15 @@
+ 
+ _LIBCPP_BEGIN_NAMESPACE_STD
+ 
++#if defined(_LIBCPP_COMPILER_GCC) && _LIBCPP_GCC_VER < 1400
++template <class _Tp>
++struct is_object
++    : _BoolConstant<!is_reference<_Tp>::value && !is_void<_Tp>::value && 
!is_function<_Tp>::value> {};
++#if _LIBCPP_STD_VER >= 17
++template <class _Tp>
++inline constexpr bool is_object_v = is_object<_Tp>::value;
++#endif
++#else // GCC >= 14 or Clang
+ template <class _Tp>
+ struct _LIBCPP_NO_SPECIALIZATIONS is_object : _BoolConstant<__is_object(_Tp)> 
{};
+ 
+@@ -25,6 +37,7 @@ struct _LIBCPP_NO_SPECIALIZATIONS is_object : 
_BoolConstant<__is_object(_Tp)> {}
+ template <class _Tp>
+ _LIBCPP_NO_SPECIALIZATIONS inline constexpr bool is_object_v = 
__is_object(_Tp);
+ #endif
++#endif // _LIBCPP_GCC_VER < 1400
+ 
+ _LIBCPP_END_NAMESPACE_STD
+ 
+diff --git a/include/__type_traits/is_pointer.h 
b/include/__type_traits/is_pointer.h
+index 1c3a93d125..d929deb3fe 100644
+--- a/include/__type_traits/is_pointer.h
++++ b/include/__type_traits/is_pointer.h
+@@ -11,6 +11,7 @@
+ 
+ #include <__config>
+ #include <__type_traits/integral_constant.h>
++#include <__type_traits/remove_cv.h>
+ 
+ #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
+ #  pragma GCC system_header
+@@ -18,6 +19,15 @@
+ 
+ _LIBCPP_BEGIN_NAMESPACE_STD
+ 
++#if !__has_builtin(__is_pointer)
++template <class _Tp> struct __libcpp_is_pointer : false_type {};
++template <class _Tp> struct __libcpp_is_pointer<_Tp*> : true_type {};
++template <class _Tp> struct is_pointer : 
__libcpp_is_pointer<__remove_cv_t<_Tp>> {};
++#if _LIBCPP_STD_VER >= 17
++template <class _Tp>
++inline constexpr bool is_pointer_v = is_pointer<_Tp>::value;
++#endif
++#else
+ template <class _Tp>
+ struct _LIBCPP_NO_SPECIALIZATIONS is_pointer : 
_BoolConstant<__is_pointer(_Tp)> {};
+ 
+@@ -25,6 +35,7 @@ struct _LIBCPP_NO_SPECIALIZATIONS is_pointer : 
_BoolConstant<__is_pointer(_Tp)>
+ template <class _Tp>
+ _LIBCPP_NO_SPECIALIZATIONS inline constexpr bool is_pointer_v = 
__is_pointer(_Tp);
+ #  endif
++#endif // !__has_builtin(__is_pointer)
+ 
+ _LIBCPP_END_NAMESPACE_STD
+ 
+diff --git a/include/__type_traits/is_reference.h 
b/include/__type_traits/is_reference.h
+index 9c98c13fd1..9d1033ac12 100644
+--- a/include/__type_traits/is_reference.h
++++ b/include/__type_traits/is_reference.h
+@@ -18,6 +18,15 @@
+ 
+ _LIBCPP_BEGIN_NAMESPACE_STD
+ 
++#if defined(_LIBCPP_COMPILER_GCC) && _LIBCPP_GCC_VER < 1400
++template <class _Tp> struct is_reference : false_type {};
++template <class _Tp> struct is_reference<_Tp&> : true_type {};
++template <class _Tp> struct is_reference<_Tp&&> : true_type {};
++#if _LIBCPP_STD_VER >= 17
++template <class _Tp>
++inline constexpr bool is_reference_v = is_reference<_Tp>::value;
++#endif
++#else // GCC >= 14 or Clang
+ template <class _Tp>
+ struct _LIBCPP_NO_SPECIALIZATIONS is_reference : 
_BoolConstant<__is_reference(_Tp)> {};
+ 
+@@ -25,6 +34,7 @@ struct _LIBCPP_NO_SPECIALIZATIONS is_reference : 
_BoolConstant<__is_reference(_T
+ template <class _Tp>
+ _LIBCPP_NO_SPECIALIZATIONS inline constexpr bool is_reference_v = 
__is_reference(_Tp);
+ #endif
++#endif // _LIBCPP_GCC_VER < 1400
+ 
+ #if __has_builtin(__is_lvalue_reference) && 
__has_builtin(__is_rvalue_reference)
+ 
+diff --git a/include/__type_traits/is_void.h b/include/__type_traits/is_void.h
+index f3af756863..674a627e99 100644
+--- a/include/__type_traits/is_void.h
++++ b/include/__type_traits/is_void.h
+@@ -11,6 +11,7 @@
+ 
+ #include <__config>
+ #include <__type_traits/integral_constant.h>
++#include <__type_traits/remove_cv.h>
+ 
+ #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
+ #  pragma GCC system_header
+@@ -18,6 +19,14 @@
+ 
+ _LIBCPP_BEGIN_NAMESPACE_STD
+ 
++#if defined(_LIBCPP_COMPILER_GCC) && _LIBCPP_GCC_VER < 1400
++template <class _Tp>
++struct is_void : _BoolConstant<__is_same(__remove_cv_t<_Tp>, void)> {};
++#if _LIBCPP_STD_VER >= 17
++template <class _Tp>
++inline constexpr bool is_void_v = __is_same(__remove_cv_t<_Tp>, void);
++#endif
++#else // GCC >= 14 or Clang
+ template <class _Tp>
+ struct _LIBCPP_NO_SPECIALIZATIONS is_void : 
_BoolConstant<__is_same(__remove_cv(_Tp), void)> {};
+ 
+@@ -25,6 +34,7 @@ struct _LIBCPP_NO_SPECIALIZATIONS is_void : 
_BoolConstant<__is_same(__remove_cv(
+ template <class _Tp>
+ _LIBCPP_NO_SPECIALIZATIONS inline constexpr bool is_void_v = 
__is_same(__remove_cv(_Tp), void);
+ #endif
++#endif // _LIBCPP_GCC_VER < 1400
+ 
+ _LIBCPP_END_NAMESPACE_STD
+ 
+diff --git a/include/__type_traits/is_volatile.h 
b/include/__type_traits/is_volatile.h
+index c654ebba92..9eb61b74c4 100644
+--- a/include/__type_traits/is_volatile.h
++++ b/include/__type_traits/is_volatile.h
+@@ -18,6 +18,14 @@
+ 
+ _LIBCPP_BEGIN_NAMESPACE_STD
+ 
++#if !__has_builtin(__is_volatile)
++template <class _Tp> struct is_volatile : false_type {};
++template <class _Tp> struct is_volatile<volatile _Tp> : true_type {};
++#if _LIBCPP_STD_VER >= 17
++template <class _Tp> inline constexpr bool is_volatile_v = false;
++template <class _Tp> inline constexpr bool is_volatile_v<volatile _Tp> = true;
++#endif
++#else
+ template <class _Tp>
+ struct _LIBCPP_NO_SPECIALIZATIONS is_volatile : 
_BoolConstant<__is_volatile(_Tp)> {};
+ 
+@@ -25,6 +33,7 @@ struct _LIBCPP_NO_SPECIALIZATIONS is_volatile : 
_BoolConstant<__is_volatile(_Tp)
+ template <class _Tp>
+ _LIBCPP_NO_SPECIALIZATIONS inline constexpr bool is_volatile_v = 
__is_volatile(_Tp);
+ #endif
++#endif // !__has_builtin(__is_volatile)
+ 
+ _LIBCPP_END_NAMESPACE_STD
+ 
+diff --git a/include/__type_traits/remove_all_extents.h 
b/include/__type_traits/remove_all_extents.h
+index a9aaad4880..7e98369367 100644
+--- a/include/__type_traits/remove_all_extents.h
++++ b/include/__type_traits/remove_all_extents.h
+@@ -17,10 +17,16 @@
+ 
+ _LIBCPP_BEGIN_NAMESPACE_STD
+ 
++#if !__has_builtin(__remove_all_extents)
++template <class _Tp> struct remove_all_extents { using type _LIBCPP_NODEBUG = 
_Tp; };
++template <class _Tp> struct remove_all_extents<_Tp[]> : 
remove_all_extents<_Tp> {};
++template <class _Tp, __SIZE_TYPE__ _Np> struct remove_all_extents<_Tp[_Np]> : 
remove_all_extents<_Tp> {};
++#else
+ template <class _Tp>
+ struct _LIBCPP_NO_SPECIALIZATIONS remove_all_extents {
+   using type _LIBCPP_NODEBUG = __remove_all_extents(_Tp);
+ };
++#endif // !__has_builtin(__remove_all_extents)
+ 
+ #ifdef _LIBCPP_COMPILER_GCC
+ template <class _Tp>
+diff --git a/include/__type_traits/remove_cv.h 
b/include/__type_traits/remove_cv.h
+index 0beaf3367e..0231c30b44 100644
+--- a/include/__type_traits/remove_cv.h
++++ b/include/__type_traits/remove_cv.h
+@@ -17,10 +17,17 @@
+ 
+ _LIBCPP_BEGIN_NAMESPACE_STD
+ 
++#if defined(_LIBCPP_COMPILER_GCC) && _LIBCPP_GCC_VER < 1400
++template <class _Tp> struct remove_cv { using type _LIBCPP_NODEBUG = _Tp; };
++template <class _Tp> struct remove_cv<const _Tp> { using type _LIBCPP_NODEBUG 
= _Tp; };
++template <class _Tp> struct remove_cv<volatile _Tp> { using type 
_LIBCPP_NODEBUG = _Tp; };
++template <class _Tp> struct remove_cv<const volatile _Tp> { using type 
_LIBCPP_NODEBUG = _Tp; };
++#else // GCC >= 14 or Clang
+ template <class _Tp>
+ struct _LIBCPP_NO_SPECIALIZATIONS remove_cv {
+   using type _LIBCPP_NODEBUG = __remove_cv(_Tp);
+ };
++#endif // _LIBCPP_GCC_VER < 1400
+ 
+ #if defined(_LIBCPP_COMPILER_GCC)
+ template <class _Tp>
+diff --git a/include/__type_traits/remove_extent.h 
b/include/__type_traits/remove_extent.h
+index 108b867bd0..a26a7770ee 100644
+--- a/include/__type_traits/remove_extent.h
++++ b/include/__type_traits/remove_extent.h
+@@ -17,10 +17,16 @@
+ 
+ _LIBCPP_BEGIN_NAMESPACE_STD
+ 
++#if !__has_builtin(__remove_extent)
++template <class _Tp> struct remove_extent { using type _LIBCPP_NODEBUG = _Tp; 
};
++template <class _Tp> struct remove_extent<_Tp[]> { using type _LIBCPP_NODEBUG 
= _Tp; };
++template <class _Tp, __SIZE_TYPE__ _Np> struct remove_extent<_Tp[_Np]> { 
using type _LIBCPP_NODEBUG = _Tp; };
++#else
+ template <class _Tp>
+ struct _LIBCPP_NO_SPECIALIZATIONS remove_extent {
+   using type _LIBCPP_NODEBUG = __remove_extent(_Tp);
+ };
++#endif // !__has_builtin(__remove_extent)
+ 
+ #ifdef _LIBCPP_COMPILER_GCC
+ template <class _Tp>
+diff --git a/include/bitset b/include/bitset
+index d109f27af5..cfa4a3acdd 100644
+--- a/include/bitset
++++ b/include/bitset
+@@ -277,8 +277,12 @@ protected:
+       __storage_type __word = std::__invert_if<!_Sparse>(__first_[__i]);
+       if (__i == _N_words - 1 && _Size - __bits < __bits_per_word)
+         __word &= (__storage_type(1) << (_Size - __bits)) - 1;
+-      for (; __word; __word &= (__word - 1))
++      for (; __word; __word &= (__word - 1)) {
++        _LIBCPP_DIAGNOSTIC_PUSH
++        _LIBCPP_GCC_DIAGNOSTIC_IGNORED("-Wstringop-overflow")
+         __r[_Size - 1 - (__bits + std::__countr_zero(__word))] = _Sparse ? 
__one : __zero;
++        _LIBCPP_DIAGNOSTIC_POP
++      }
+     }
+ 
+     return __r;
+diff --git a/include/variant b/include/variant
+index ede9f486ec..4f5969cba1 100644
+--- a/include/variant
++++ b/include/variant
+@@ -220,6 +220,7 @@ namespace std {
+ #  include <__compare/ordering.h>
+ #  include <__compare/three_way_comparable.h>
+ #  include <__config>
++#  include <__tuple/tuple_element.h>
+ #  include <__exception/exception.h>
+ #  include <__functional/hash.h>
+ #  include <__functional/operations.h>
+@@ -339,10 +340,16 @@ struct variant_alternative<_Ip, volatile _Tp> : 
add_volatile<variant_alternative
+ template <size_t _Ip, class _Tp>
+ struct variant_alternative<_Ip, const volatile _Tp> : 
add_cv<variant_alternative_t<_Ip, _Tp>> {};
+ 
++
++
+ template <size_t _Ip, class... _Types>
+ struct variant_alternative<_Ip, variant<_Types...>> {
+   static_assert(_Ip < sizeof...(_Types), "Index out of bounds in 
std::variant_alternative<>");
++#if defined(_LIBCPP_COMPILER_GCC) && _LIBCPP_GCC_VER < 1400
++  using type _LIBCPP_NODEBUG = typename __type_pack_element_fallback<_Ip, 
_Types...>::type;
++#else
+   using type _LIBCPP_NODEBUG = __type_pack_element<_Ip, _Types...>;
++#endif
+ };
+ 
+ template <size_t _NumAlternatives>
diff --git 
a/libs/libxx/libcxx/0006-libcxx-lower-unsupported-compiler-warning-threshold-.patch
 
b/libs/libxx/libcxx/0006-libcxx-lower-unsupported-compiler-warning-threshold-.patch
new file mode 100644
index 00000000000..227ec69ffc3
--- /dev/null
+++ 
b/libs/libxx/libcxx/0006-libcxx-lower-unsupported-compiler-warning-threshold-.patch
@@ -0,0 +1,29 @@
+From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
+From: v-zhangxiaomeng5 <[email protected]>
+Date: Wed, 2 Sep 2026 14:42:31 +0800
+Subject: [PATCH] libcxx: lower unsupported-compiler warning threshold to GCC
+ 12
+
+llvm-21 libc++ emits #warning "Libc++ only supports GCC 14 and later"
+for GCC < 14, which -Werror=cpp turns into a build error.
+
+Signed-off-by: v-zhangxiaomeng5 <[email protected]>
+---
+ include/__configuration/compiler.h | 4 ++--
+ 1 file changed, 2 insertions(+), 2 deletions(-)
+
+diff --git a/include/__configuration/compiler.h 
b/include/__configuration/compiler.h
+index 4b6c6cad35..27c4256b61 100644
+--- a/include/__configuration/compiler.h
++++ b/include/__configuration/compiler.h
+@@ -41,8 +41,8 @@
+ #      warning "Libc++ only supports AppleClang 15 and later"
+ #    endif
+ #  elif defined(_LIBCPP_GCC_VER)
+-#    if _LIBCPP_GCC_VER < 1400
+-#      warning "Libc++ only supports GCC 14 and later"
++#    if _LIBCPP_GCC_VER < 1200
++#      warning "Libc++ only supports GCC 12 and later"
+ #    endif
+ #  endif
+ 
diff --git 
a/libs/libxx/libcxx/0007-ios.cpp-fix-null-deref-after-realloc-failure-in-ios_.patch
 
b/libs/libxx/libcxx/0007-ios.cpp-fix-null-deref-after-realloc-failure-in-ios_.patch
new file mode 100644
index 00000000000..90ad0015f34
--- /dev/null
+++ 
b/libs/libxx/libcxx/0007-ios.cpp-fix-null-deref-after-realloc-failure-in-ios_.patch
@@ -0,0 +1,36 @@
+From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
+From: v-zhangxiaomeng5 <[email protected]>
+Date: Tue, 7 Apr 2026 17:25:33 +0800
+Subject: [PATCH] ios.cpp: fix null deref after realloc failure in
+ ios_base::register_callback
+
+Add early return after setstate(badbit) when realloc fails in 
ios_base::register_callback(). Without the return, execution continues with 
__fn_ or __index_ set to null (from failed realloc), then __fn_[__event_size_] 
dereferences null causing a crash.
+
+Signed-off-by: v-zhangxiaomeng5 <[email protected]>
+---
+ src/ios.cpp | 8 ++++++--
+ 1 file changed, 6 insertions(+), 2 deletions(-)
+
+diff --git a/src/ios.cpp b/src/ios.cpp
+index 02ce484118..077389eafd 100644
+--- a/src/ios.cpp
++++ b/src/ios.cpp
+@@ -180,12 +180,16 @@ void ios_base::register_callback(event_callback fn, int 
index) {
+   if (req_size > __event_cap_) {
+     size_t newcap       = __ios_new_cap<event_callback>(req_size, 
__event_cap_);
+     event_callback* fns = static_cast<event_callback*>(realloc(__fn_, newcap 
* sizeof(event_callback)));
+-    if (fns == 0)
++    if (fns == 0) {
+       setstate(badbit);
++      return;
++    }
+     __fn_      = fns;
+     int* indxs = static_cast<int*>(realloc(__index_, newcap * sizeof(int)));
+-    if (indxs == 0)
++    if (indxs == 0) {
+       setstate(badbit);
++      return;
++    }
+     __index_     = indxs;
+     __event_cap_ = newcap;
+   }
diff --git 
a/libs/libxx/libcxx/0008-libcxx-condition_variable-fix-EINVAL-abort-when-syst.patch
 
b/libs/libxx/libcxx/0008-libcxx-condition_variable-fix-EINVAL-abort-when-syst.patch
new file mode 100644
index 00000000000..cafd2800896
--- /dev/null
+++ 
b/libs/libxx/libcxx/0008-libcxx-condition_variable-fix-EINVAL-abort-when-syst.patch
@@ -0,0 +1,33 @@
+From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
+From: v-zhangxiaomeng5 <[email protected]>
+Date: Mon, 15 Jun 2026 21:16:24 +0800
+Subject: [PATCH] libcxx/condition_variable: fix EINVAL abort when system clock
+ not synced
+
+When system_clock is not yet synchronized (e.g. device cold boot),
+condition_variable::wait_for() may compute a negative time_point.
+This causes NuttX pthread_cond_timedwait() to return EINVAL, and
+libc++ treats any error other than ETIMEDOUT as fatal, calling
+abort() and crashing the system.
+
+Fix by clamping the duration to zero when negative, right after
+the upper-bound check.
+
+Signed-off-by: v-zhangxiaomeng5 <[email protected]>
+---
+ src/condition_variable.cpp | 2 ++
+ 1 file changed, 2 insertions(+)
+
+diff --git a/src/condition_variable.cpp b/src/condition_variable.cpp
+index a87399d1b7..6bbc906ece 100644
+--- a/src/condition_variable.cpp
++++ b/src/condition_variable.cpp
+@@ -46,6 +46,8 @@ void condition_variable::__do_timed_wait(unique_lock<mutex>& 
lk,
+   nanoseconds d = tp.time_since_epoch();
+   if (d > nanoseconds(0x59682F000000E941))
+     d = nanoseconds(0x59682F000000E941);
++  else if (d < nanoseconds(0))
++    d = nanoseconds(0);
+   __libcpp_timespec_t ts;
+   seconds s = duration_cast<seconds>(d);
+   typedef decltype(ts.tv_sec) ts_sec;
diff --git 
a/libs/libxx/libcxx/0009-__memory-guard-empty-range-relocate-to-avoid-null-me.patch
 
b/libs/libxx/libcxx/0009-__memory-guard-empty-range-relocate-to-avoid-null-me.patch
new file mode 100644
index 00000000000..a8da26907b0
--- /dev/null
+++ 
b/libs/libxx/libcxx/0009-__memory-guard-empty-range-relocate-to-avoid-null-me.patch
@@ -0,0 +1,33 @@
+From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
+From: v-zhangxiaomeng5 <[email protected]>
+Date: Mon, 7 Sep 2026 11:58:43 +0800
+Subject: [PATCH] __memory: guard empty range relocate to avoid null memcpy
+ UBSan
+
+The trivially relocatable fast path in __uninitialized_allocator_relocate
+calls __builtin_memcpy unconditionally. When the source range is empty
+(for example growing an empty vector) the pointers can be null, and
+passing null to memcpy violates its nonnull argument attribute, which
+-fsanitize=undefined reports at runtime even though the copy size is
+zero. llvm17 used an element by element move loop that naturally did
+nothing for an empty range, so this only regressed after the llvm21
+upgrade. Skip the memcpy when the range is empty to match that behavior.
+
+Signed-off-by: v-zhangxiaomeng5 <[email protected]>
+---
+ include/__memory/uninitialized_algorithms.h | 2 +-
+ 1 file changed, 1 insertion(+), 1 deletion(-)
+
+diff --git a/include/__memory/uninitialized_algorithms.h 
b/include/__memory/uninitialized_algorithms.h
+index e802366400..1347cbedbd 100644
+--- a/include/__memory/uninitialized_algorithms.h
++++ b/include/__memory/uninitialized_algorithms.h
+@@ -633,7 +633,7 @@ _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 void 
__uninitialized_allocat
+     }
+     __guard.__complete();
+     std::__allocator_destroy(__alloc, __first, __last);
+-  } else {
++  } else if (__first != __last) {
+     // Casting to void* to suppress clang complaining that this is 
technically UB.
+     __builtin_memcpy(static_cast<void*>(std::__to_address(__result)),
+                      std::__to_address(__first),
diff --git 
a/libs/libxx/libcxx/0010-include-string-remove-constexpr-from-basic_string-fo.patch
 
b/libs/libxx/libcxx/0010-include-string-remove-constexpr-from-basic_string-fo.patch
new file mode 100644
index 00000000000..8a6923bb398
--- /dev/null
+++ 
b/libs/libxx/libcxx/0010-include-string-remove-constexpr-from-basic_string-fo.patch
@@ -0,0 +1,29 @@
+From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
+From: v-zhangxiaomeng5 <[email protected]>
+Date: Thu, 9 Apr 2026 12:22:30 +0800
+Subject: [PATCH] include/string: remove constexpr from ~basic_string() for ARM
+ GCC
+
+ARM GCC does not emit an out-of-line definition for ~basic_string() when the 
destructor is marked constexpr, even through explicit template instantiation in 
string.cpp. This causes undefined reference errors at link time for locale.cpp 
and prebuilt libraries compiled at -O0.
+
+Signed-off-by: v-zhangxiaomeng5 <[email protected]>
+---
+ include/string | 4 ++++
+ 1 file changed, 4 insertions(+)
+
+diff --git a/include/string b/include/string
+index d282071abf..39c26e99f3 100644
+--- a/include/string
++++ b/include/string
+@@ -1201,7 +1201,11 @@ public:
+   }
+ #  endif // _LIBCPP_CXX03_LANG
+ 
++#if defined(__arm__) && !defined(__clang__)
++  inline ~basic_string() {
++#else
+   inline _LIBCPP_CONSTEXPR_SINCE_CXX20 ~basic_string() {
++#endif
+     __annotate_delete();
+     if (__is_long())
+       __alloc_traits::deallocate(__alloc_, __get_long_pointer(), 
__get_long_cap());
diff --git 
a/libs/libxx/libcxx/0011-constexpr_c_functions.h-suppress-GCC-15-false-positi.patch
 
b/libs/libxx/libcxx/0011-constexpr_c_functions.h-suppress-GCC-15-false-positi.patch
new file mode 100644
index 00000000000..e9a7f130172
--- /dev/null
+++ 
b/libs/libxx/libcxx/0011-constexpr_c_functions.h-suppress-GCC-15-false-positi.patch
@@ -0,0 +1,30 @@
+From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
+From: v-zhangxiaomeng5 <[email protected]>
+Date: Fri, 10 Apr 2026 17:04:42 +0800
+Subject: [PATCH] constexpr_c_functions.h: suppress GCC 15 false positives
+
+GCC 15 reports -Wstringop-overflow, -Wrestrict, and -Warray-bounds on the 
__builtin_memmove call in __constexpr_memmove when inlined into string 
operations at -O1+. These options are useful in applications that can not be 
suppressed.
+
+Signed-off-by: v-zhangxiaomeng5 <[email protected]>
+---
+ include/__string/constexpr_c_functions.h | 6 ++++++
+ 1 file changed, 6 insertions(+)
+
+diff --git a/include/__string/constexpr_c_functions.h 
b/include/__string/constexpr_c_functions.h
+index 119669e16b..f40b61c6b4 100644
+--- a/include/__string/constexpr_c_functions.h
++++ b/include/__string/constexpr_c_functions.h
+@@ -226,7 +226,13 @@ __constexpr_memmove(_Tp* __dest, _Up* __src, 
__element_count __n) {
+       }
+     }
+   } else if (__count > 0) {
++    // Suppress GCC 15 false positive when inlined into string operations at 
-O1+
++    _LIBCPP_DIAGNOSTIC_PUSH
++    _LIBCPP_GCC_DIAGNOSTIC_IGNORED("-Wstringop-overflow")
++    _LIBCPP_GCC_DIAGNOSTIC_IGNORED("-Wrestrict")
++    _LIBCPP_GCC_DIAGNOSTIC_IGNORED("-Warray-bounds")
+     ::__builtin_memmove(__dest, __src, (__count - 1) * sizeof(_Tp) + 
__datasizeof_v<_Tp>);
++    _LIBCPP_DIAGNOSTIC_POP
+   }
+   return __dest;
+ }
diff --git 
a/libs/libxx/libcxx/0012-__hash_table-initialize-__chash-to-fix-GCC-15-Werror.patch
 
b/libs/libxx/libcxx/0012-__hash_table-initialize-__chash-to-fix-GCC-15-Werror.patch
new file mode 100644
index 00000000000..e9829705018
--- /dev/null
+++ 
b/libs/libxx/libcxx/0012-__hash_table-initialize-__chash-to-fix-GCC-15-Werror.patch
@@ -0,0 +1,26 @@
+From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
+From: v-zhangxiaomeng5 <[email protected]>
+Date: Fri, 10 Apr 2026 16:46:53 +0800
+Subject: [PATCH] __hash_table: initialize __chash to fix GCC 15
+ -Werror=maybe-uninitialized
+
+GCC 15 reports __chash may be used uninitialized in 
__hash_table::__emplace_unique_key_args when inlined into 
unordered_map::operator[]. This is a false positive from GCC's value range 
analysis after deep.
+
+Signed-off-by: v-zhangxiaomeng5 <[email protected]>
+---
+ include/__hash_table | 2 +-
+ 1 file changed, 1 insertion(+), 1 deletion(-)
+
+diff --git a/include/__hash_table b/include/__hash_table
+index 78f2f3bfd2..29de91a488 100644
+--- a/include/__hash_table
++++ b/include/__hash_table
+@@ -1569,7 +1569,7 @@ __hash_table<_Tp, _Hash, _Equal, 
_Alloc>::__emplace_unique_key_args(_Key const&
+   size_type __bc  = bucket_count();
+   bool __inserted = false;
+   __next_pointer __nd;
+-  size_t __chash;
++  size_t __chash = 0;
+   if (__bc != 0) {
+     __chash = std::__constrain_hash(__hash, __bc);
+     __nd    = __bucket_list_[__chash];
diff --git 
a/libs/libxx/libcxx/0013-__string-char_traits.h-suppress-GCC-15-false-positiv.patch
 
b/libs/libxx/libcxx/0013-__string-char_traits.h-suppress-GCC-15-false-positiv.patch
new file mode 100644
index 00000000000..62774f6d73c
--- /dev/null
+++ 
b/libs/libxx/libcxx/0013-__string-char_traits.h-suppress-GCC-15-false-positiv.patch
@@ -0,0 +1,128 @@
+From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
+From: v-zhangxiaomeng5 <[email protected]>
+Date: Sun, 19 Apr 2026 01:01:12 +0800
+Subject: [PATCH] __string/char_traits.h: suppress GCC 15 false positive and
+ add generic base template
+
+Changes:
+- GCC 15 reports false -Warray-bounds and -Wstringop-overflow warnings when 
char_traits::assign is inlined into string operations (getline, append, etc.) 
at -O1+. Suppress with diagnostic pragmas around the assignment. Affects all 
architectures with GCC 15.
+- Restore the generic char_traits<_CharT> base template removed since llvm-18, 
this breaks code using basic_string_view or basic_string with non-standard char 
types like unsigned char / uint8_t. Then android libcppbor, keymaster, 
ethercat, abseil-cpp etc. code don't need to change.
+
+Signed-off-by: v-zhangxiaomeng5 <[email protected]>
+---
+ include/__string/char_traits.h | 92 +++++++++++++++++++++++-----------
+ 1 file changed, 62 insertions(+), 30 deletions(-)
+
+diff --git a/include/__string/char_traits.h b/include/__string/char_traits.h
+index 86c92477cb..b13625a16b 100644
+--- a/include/__string/char_traits.h
++++ b/include/__string/char_traits.h
+@@ -42,38 +42,65 @@ _LIBCPP_PUSH_MACROS
+ 
+ _LIBCPP_BEGIN_NAMESPACE_STD
+ 
++// Generic base template for non-standard char types (e.g. unsigned char).
++// llvm-21 removed this; provide it for backward compatibility with code
++// that uses basic_string_view<unsigned char> or similar.
++
+ template <class _CharT>
+-struct char_traits;
+-/*
+-The Standard does not define the base template for char_traits because it is 
impossible to provide
+-a correct definition for arbitrary character types. Instead, it requires 
implementations to provide
+-specializations for predefined character types like `char`, `wchar_t` and 
others. We provide this as
+-exposition-only to document what members a char_traits specialization should 
provide:
+-{
+-    using char_type  = _CharT;
+-    using int_type   = ...;
+-    using off_type   = ...;
+-    using pos_type   = ...;
+-    using state_type = ...;
+-
+-    static void assign(char_type&, const char_type&);
+-    static bool eq(char_type, char_type);
+-    static bool lt(char_type, char_type);
+-
+-    static int              compare(const char_type*, const char_type*, 
size_t);
+-    static size_t           length(const char_type*);
+-    static const char_type* find(const char_type*, size_t, const char_type&);
+-    static char_type*       move(char_type*, const char_type*, size_t);
+-    static char_type*       copy(char_type*, const char_type*, size_t);
+-    static char_type*       assign(char_type*, size_t, char_type);
+-
+-    static int_type  not_eof(int_type);
+-    static char_type to_char_type(int_type);
+-    static int_type  to_int_type(char_type);
+-    static bool      eq_int_type(int_type, int_type);
+-    static int_type  eof();
++struct char_traits {
++  using char_type  = _CharT;
++  using int_type   = int;
++  using off_type   = streamoff;
++  using pos_type   = streampos;
++  using state_type = mbstate_t;
++
++  static inline void assign(char_type& __c1, const char_type& __c2) _NOEXCEPT 
{ __c1 = __c2; }
++  static inline _LIBCPP_CONSTEXPR bool eq(char_type __c1, char_type __c2) 
_NOEXCEPT { return __c1 == __c2; }
++  static inline _LIBCPP_CONSTEXPR bool lt(char_type __c1, char_type __c2) 
_NOEXCEPT { return __c1 < __c2; }
++
++  static int compare(const char_type* __s1, const char_type* __s2, size_t 
__n) {
++    for (size_t __i = 0; __i < __n; ++__i) {
++      if (lt(__s1[__i], __s2[__i])) return -1;
++      if (lt(__s2[__i], __s1[__i])) return 1;
++    }
++    return 0;
++  }
++
++  static size_t length(const char_type* __s) {
++    size_t __len = 0;
++    for (; !eq(__s[__len], char_type()); ++__len) {}
++    return __len;
++  }
++
++  static const char_type* find(const char_type* __s, size_t __n, const 
char_type& __a) {
++    for (size_t __i = 0; __i < __n; ++__i)
++      if (eq(__s[__i], __a)) return __s + __i;
++    return nullptr;
++  }
++
++  static char_type* move(char_type* __s1, const char_type* __s2, size_t __n) {
++    if (__n == 0) return __s1;
++    if (__s1 < __s2) { for (size_t __i = 0; __i < __n; ++__i) 
assign(__s1[__i], __s2[__i]); }
++    else { for (size_t __i = __n; __i > 0; --__i) assign(__s1[__i-1], 
__s2[__i-1]); }
++    return __s1;
++  }
++
++  static char_type* copy(char_type* __s1, const char_type* __s2, size_t __n) {
++    for (size_t __i = 0; __i < __n; ++__i) assign(__s1[__i], __s2[__i]);
++    return __s1;
++  }
++
++  static char_type* assign(char_type* __s, size_t __n, char_type __a) {
++    for (size_t __i = 0; __i < __n; ++__i) assign(__s[__i], __a);
++    return __s;
++  }
++
++  static inline _LIBCPP_CONSTEXPR int_type not_eof(int_type __c) _NOEXCEPT { 
return eq_int_type(__c, eof()) ? ~eof() : __c; }
++  static inline _LIBCPP_CONSTEXPR char_type to_char_type(int_type __c) 
_NOEXCEPT { return char_type(__c); }
++  static inline _LIBCPP_CONSTEXPR int_type to_int_type(char_type __c) 
_NOEXCEPT { return int_type(__c); }
++  static inline _LIBCPP_CONSTEXPR bool eq_int_type(int_type __c1, int_type 
__c2) _NOEXCEPT { return __c1 == __c2; }
++  static inline _LIBCPP_CONSTEXPR int_type eof() _NOEXCEPT { return 
int_type(EOF); }
+ };
+-*/
+ 
+ // char_traits<char>
+ 
+@@ -90,7 +117,12 @@ struct char_traits<char> {
+ 
+   static inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX17 void
+   assign(char_type& __c1, const char_type& __c2) _NOEXCEPT {
++    // Suppress GCC 15 false positive when inlined into string operations at 
-O1+
++    _LIBCPP_DIAGNOSTIC_PUSH
++    _LIBCPP_GCC_DIAGNOSTIC_IGNORED("-Warray-bounds")
++    _LIBCPP_GCC_DIAGNOSTIC_IGNORED("-Wstringop-overflow")
+     __c1 = __c2;
++    _LIBCPP_DIAGNOSTIC_POP
+   }
+ 
+   // TODO: Make this _LIBCPP_HIDE_FROM_ABI
diff --git 
a/libs/libxx/libcxx/0014-thread.cpp-use-task_info_s.ta_thread_local_data-for-.patch
 
b/libs/libxx/libcxx/0014-thread.cpp-use-task_info_s.ta_thread_local_data-for-.patch
new file mode 100644
index 00000000000..62fbfb8ba4d
--- /dev/null
+++ 
b/libs/libxx/libcxx/0014-thread.cpp-use-task_info_s.ta_thread_local_data-for-.patch
@@ -0,0 +1,69 @@
+From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
+From: v-zhangxiaomeng5 <[email protected]>
+Date: Tue, 7 Apr 2026 15:11:55 +0800
+Subject: [PATCH] thread.cpp: use task_info_s.ta_thread_local_data for
+ per-group __thread_local_data
+
+In NuttX flat build, the default __thread_local_data() uses a global static 
shared across all task groups, causing data corruption. Store 
__thread_specific_ptr in task_info_s.ta_thread_local_data for per-task-group 
isolation. Destructor registered for cleanup on task group exit.
+
+Signed-off-by: v-zhangxiaomeng5 <[email protected]>
+---
+ src/thread.cpp | 31 +++++++++++++++++++++++++++++++
+ 1 file changed, 31 insertions(+)
+
+diff --git a/src/thread.cpp b/src/thread.cpp
+index 028d36e3bf..29f5f64e93 100644
+--- a/src/thread.cpp
++++ b/src/thread.cpp
+@@ -24,6 +24,10 @@
+ #  pragma weak pthread_create // Do not create libpthread dependency
+ #endif
+ 
++#if defined(__NuttX__) && !defined(CONFIG_BUILD_KERNEL)
++#  include <nuttx/tls.h>
++#endif
++
+ #if defined(_LIBCPP_WIN32API)
+ #  include <windows.h>
+ #endif
+@@ -99,6 +103,31 @@ void sleep_for(const chrono::nanoseconds& ns) {
+ 
+ } // namespace this_thread
+ 
++#if defined(__NuttX__) && !defined(CONFIG_BUILD_KERNEL)
++
++#include <nuttx/tls.h>
++
++static void __free_thread_local_data(void* data) {
++  __thread_specific_ptr<__thread_struct>* __p = 
static_cast<__thread_specific_ptr<__thread_struct>*>(data);
++  delete __p;
++}
++
++__thread_specific_ptr<__thread_struct>& __thread_local_data() {
++  FAR struct task_info_s *info = task_get_info();
++  __thread_specific_ptr<__thread_struct>* __p =
++      
static_cast<__thread_specific_ptr<__thread_struct>*>(info->ta_thread_local_data);
++  if (__p == NULL) {
++    __p = new __thread_specific_ptr<__thread_struct>();
++    if (__p == NULL)
++      abort();
++    info->ta_thread_local_data = __p;
++    info->ta_thread_local_dtor = __free_thread_local_data;
++  }
++  return *__p;
++}
++
++#else
++
+ __thread_specific_ptr<__thread_struct>& __thread_local_data() {
+   // Even though __thread_specific_ptr's destructor doesn't actually destroy
+   // anything (see comments there), we can't call it at all because threads 
may
+@@ -109,6 +138,8 @@ __thread_specific_ptr<__thread_struct>& 
__thread_local_data() {
+   return *__p;
+ }
+ 
++#endif
++
+ // __thread_struct_imp
+ 
+ template <class T>
diff --git 
a/libs/libxx/libcxx/0015-libcxx-let-std-thread-take-a-stack-size.patch 
b/libs/libxx/libcxx/0015-libcxx-let-std-thread-take-a-stack-size.patch
new file mode 100644
index 00000000000..f31bc550a2c
--- /dev/null
+++ b/libs/libxx/libcxx/0015-libcxx-let-std-thread-take-a-stack-size.patch
@@ -0,0 +1,123 @@
+From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
+From: v-zhangxiaomeng5 <[email protected]>
+Date: Fri, 13 Nov 2026 12:11:39 +0800
+Subject: [PATCH] libcxx: let std::thread take a stack size
+
+NuttX tasks often need a stack size other than the default, which
+std::thread has no way to express. Add thread::attributes with a
+stack_size() setter, and a thread constructor that takes it.
+
+  __thread/support/pthread.h wraps pthread_attr_t and adds a
+  pthread_create overload that accepts it.
+  __thread/thread.h defines thread::attributes in the class, which Clang
+  needs, and keeps it out of the callable template through enable_if.
+  __type_traits/nat.h drops ~__nat() = delete. GCC instantiates the
+  template bodies during overload resolution, and the new constructor
+  makes it reach the destructor of __nat:
+
+    thread.h:159:16: error: use of deleted function
+    'std::__1::__nat::~__nat()'
+
+Signed-off-by: v-zhangxiaomeng5 <[email protected]>
+---
+ include/__thread/support/pthread.h | 21 +++++++++++++++++++++
+ include/__thread/thread.h          | 27 ++++++++++++++++++++++++++-
+ include/__type_traits/nat.h        |  2 +-
+ 3 files changed, 48 insertions(+), 2 deletions(-)
+
+diff --git a/include/__thread/support/pthread.h 
b/include/__thread/support/pthread.h
+index 14e92079da..0d1967476b 100644
+--- a/include/__thread/support/pthread.h
++++ b/include/__thread/support/pthread.h
+@@ -182,6 +182,27 @@ inline _LIBCPP_HIDE_FROM_ABI int 
__libcpp_thread_create(__libcpp_thread_t* __t,
+   return pthread_create(__t, nullptr, __func, __arg);
+ }
+ 
++// Thread attributes for controlling stack size etc.
++typedef pthread_attr_t __libcpp_thread_attr;
++
++inline _LIBCPP_HIDE_FROM_ABI void 
__libcpp_thread_attr_init(__libcpp_thread_attr* __attr) {
++  pthread_attr_init(__attr);
++}
++
++inline _LIBCPP_HIDE_FROM_ABI void 
__libcpp_thread_attr_destroy(__libcpp_thread_attr* __attr) {
++  pthread_attr_destroy(__attr);
++}
++
++inline _LIBCPP_HIDE_FROM_ABI void 
__libcpp_thread_attr_stack_size(__libcpp_thread_attr* __attr, size_t __size) {
++  pthread_attr_setstacksize(__attr, __size);
++}
++
++inline _LIBCPP_HIDE_FROM_ABI int
++__libcpp_thread_create(__libcpp_thread_t* __t, const __libcpp_thread_attr* 
__attr,
++                       void* (*__func)(void*), void* __arg) {
++  return pthread_create(__t, __attr, __func, __arg);
++}
++
+ inline _LIBCPP_HIDE_FROM_ABI __libcpp_thread_id 
__libcpp_thread_get_current_id() {
+   const __libcpp_thread_t __current_thread = pthread_self();
+   return __libcpp_thread_get_id(&__current_thread);
+diff --git a/include/__thread/thread.h b/include/__thread/thread.h
+index 1b51571ce3..954b7f2c8e 100644
+--- a/include/__thread/thread.h
++++ b/include/__thread/thread.h
+@@ -198,13 +198,25 @@ class _LIBCPP_EXPORTED_FROM_ABI thread {
+   thread& operator=(const thread&);
+ 
+ public:
++  class attributes {
++  public:
++    _LIBCPP_HIDE_FROM_ABI attributes() _NOEXCEPT { 
__libcpp_thread_attr_init(&__attr_); }
++    _LIBCPP_HIDE_FROM_ABI ~attributes() { 
__libcpp_thread_attr_destroy(&__attr_); }
++    _LIBCPP_HIDE_FROM_ABI attributes& stack_size(size_t __size) _NOEXCEPT {
++      __libcpp_thread_attr_stack_size(&__attr_, __size);
++      return *this;
++    }
++    __libcpp_thread_attr __attr_;
++  };
+   typedef __thread_id id;
+   typedef __libcpp_thread_t native_handle_type;
+ 
+   _LIBCPP_HIDE_FROM_ABI thread() _NOEXCEPT : __t_(_LIBCPP_NULL_THREAD) {}
+ 
+ #  ifndef _LIBCPP_CXX03_LANG
+-  template <class _Fp, class... _Args, 
__enable_if_t<!is_same<__remove_cvref_t<_Fp>, thread>::value, int> = 0>
++  template <class _Fp, class... _Args,
++            __enable_if_t<!is_same<__remove_cvref_t<_Fp>, thread>::value &&
++                          !is_same<__remove_cvref_t<_Fp>, attributes>::value, 
int> = 0>
+   _LIBCPP_HIDE_FROM_ABI explicit thread(_Fp&& __f, _Args&&... __args) {
+     typedef unique_ptr<__thread_struct> _TSPtr;
+     _TSPtr __tsp(new __thread_struct);
+@@ -216,6 +228,19 @@ public:
+     else
+       __throw_system_error(__ec, "thread constructor failed");
+   }
++
++  template <class _Fp, class... _Args, 
__enable_if_t<!is_same<__remove_cvref_t<_Fp>, thread>::value, int> = 0>
++  _LIBCPP_HIDE_FROM_ABI thread(const attributes& __attrs, _Fp&& __f, 
_Args&&... __args) {
++    typedef unique_ptr<__thread_struct> _TSPtr;
++    _TSPtr __tsp(new __thread_struct);
++    typedef tuple<_TSPtr, __decay_t<_Fp>, __decay_t<_Args>...> _Gp;
++    unique_ptr<_Gp> __p(new _Gp(std::move(__tsp), std::forward<_Fp>(__f), 
std::forward<_Args>(__args)...));
++    int __ec = std::__libcpp_thread_create(&__t_, &__attrs.__attr_, 
std::addressof(__thread_proxy<_Gp>), __p.get());
++    if (__ec == 0)
++      __p.release();
++    else
++      __throw_system_error(__ec, "thread constructor failed");
++  }
+ #  else // _LIBCPP_CXX03_LANG
+   template <class _Fp>
+   _LIBCPP_HIDE_FROM_ABI explicit thread(_Fp __f) {
+diff --git a/include/__type_traits/nat.h b/include/__type_traits/nat.h
+index 9f39b80681..b71bd9d06c 100644
+--- a/include/__type_traits/nat.h
++++ b/include/__type_traits/nat.h
+@@ -22,7 +22,7 @@ struct __nat {
+   __nat()                        = delete;
+   __nat(const __nat&)            = delete;
+   __nat& operator=(const __nat&) = delete;
+-  ~__nat()                       = delete;
++  // ~__nat()                       = delete;
+ #endif
+ };
+ 
diff --git 
a/libs/libxx/libcxx/0016-localization-introduce-mini-localization-to-reduce-c.patch
 
b/libs/libxx/libcxx/0016-localization-introduce-mini-localization-to-reduce-c.patch
new file mode 100644
index 00000000000..5e4fba7d64a
--- /dev/null
+++ 
b/libs/libxx/libcxx/0016-localization-introduce-mini-localization-to-reduce-c.patch
@@ -0,0 +1,381 @@
+From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
+From: v-zhangxiaomeng5 <[email protected]>
+Date: Wed, 8 Apr 2026 14:51:07 +0800
+Subject: [PATCH] localization: introduce mini localization to reduce code size
+
+When CXX_MINI_LOCALIZATION is enabled, strip dead locale code that is
+unreachable with only the classic "C" locale:
+- Guard *_byname facet implementations (collate, ctype, numpunct)
+- Guard functional facets (time_get/put, money_get/put, moneypunct, messages)
+- Guard explicit template instantiations for the above
+- Guard checked_string_to_* helper functions (LLVM 21 only)
+- Guard __install_ctor declaration to match its guarded definition
+- Provide no-op __locale namespace stubs and __locale_guard when
+  LIBC_LOCALE is disabled (LLVM 21 NuttX integration)
+
+Signed-off-by: v-zhangxiaomeng5 <[email protected]>
+---
+ include/__locale                              | 10 ++++++
+ include/__locale_dir/locale_base_api.h        | 11 ++++++
+ .../locale_base_api/bsd_locale_fallbacks.h    |  4 +++
+ src/locale.cpp                                | 36 +++++++++++++++++++
+ 4 files changed, 61 insertions(+)
+
+diff --git a/include/__locale b/include/__locale
+index 757a53951f..2d659756b7 100644
+--- a/include/__locale
++++ b/include/__locale
+@@ -65,6 +65,7 @@ public:
+   class _LIBCPP_EXPORTED_FROM_ABI facet;
+   class _LIBCPP_EXPORTED_FROM_ABI id;
+ 
++#ifndef _LIBCPP_HAS_MINI_LOCALIZATION
+   typedef int category;
+ 
+   static const category // values assigned here are for exposition only
+@@ -72,10 +73,12 @@ public:
+       collate = _LIBCPP_COLLATE_MASK, ctype = _LIBCPP_CTYPE_MASK, monetary = 
_LIBCPP_MONETARY_MASK,
+       numeric = _LIBCPP_NUMERIC_MASK, time = _LIBCPP_TIME_MASK, messages = 
_LIBCPP_MESSAGES_MASK,
+       all = collate | ctype | monetary | numeric | time | messages;
++#endif
+ 
+   // construct/copy/destroy:
+   locale() _NOEXCEPT;
+   locale(const locale&) _NOEXCEPT;
++#ifndef _LIBCPP_HAS_MINI_LOCALIZATION
+   explicit locale(const char*);
+   explicit locale(const string&);
+   locale(const locale&, const char*, category);
+@@ -83,11 +86,13 @@ public:
+   template <class _Facet>
+   _LIBCPP_HIDE_FROM_ABI locale(const locale&, _Facet*);
+   locale(const locale&, const locale&, category);
++#endif
+ 
+   ~locale();
+ 
+   const locale& operator=(const locale&) _NOEXCEPT;
+ 
++#ifndef _LIBCPP_HAS_MINI_LOCALIZATION
+   template <class _Facet>
+   _LIBCPP_HIDE_FROM_ABI locale combine(const locale& __other) const {
+     if (!std::has_facet<_Facet>(__other))
+@@ -95,6 +100,7 @@ public:
+ 
+     return locale(*this, 
std::addressof(const_cast<_Facet&>(std::use_facet<_Facet>(__other))));
+   }
++#endif
+ 
+   // locale operations:
+   string name() const;
+@@ -121,7 +127,9 @@ private:
+   friend struct __no_destroy;
+   _LIBCPP_HIDE_FROM_ABI explicit locale(__private_constructor_tag, __imp* 
__loc) : __locale_(__loc) {}
+ 
++#ifndef _LIBCPP_HAS_MINI_LOCALIZATION
+   void __install_ctor(const locale&, facet*, long);
++#endif
+   static locale& __global();
+   bool has_facet(id&) const;
+   const facet* use_facet(id&) const;
+@@ -163,10 +171,12 @@ public: // only needed for tests
+   friend class locale::__imp;
+ };
+ 
++#ifndef _LIBCPP_HAS_MINI_LOCALIZATION
+ template <class _Facet>
+ inline _LIBCPP_HIDE_FROM_ABI locale::locale(const locale& __other, _Facet* 
__f) {
+   __install_ctor(__other, __f, __f ? __f->id.__get() : 0);
+ }
++#endif
+ 
+ template <class _Facet>
+ inline _LIBCPP_HIDE_FROM_ABI bool has_facet(const locale& __l) _NOEXCEPT {
+diff --git a/include/__locale_dir/locale_base_api.h 
b/include/__locale_dir/locale_base_api.h
+index 8dbc28e839..5f6d1a4947 100644
+--- a/include/__locale_dir/locale_base_api.h
++++ b/include/__locale_dir/locale_base_api.h
+@@ -137,6 +137,10 @@
+ #      include <__locale_dir/locale_base_api/musl.h>
+ #    endif
+ 
++#    if defined(_LIBCPP_HAS_MINI_LOCALIZATION)
++#      include <locale.h>
++#    endif
++
+ #    include <__locale_dir/locale_base_api/bsd_locale_fallbacks.h>
+ 
+ #    include <__cstddef/size_t.h>
+@@ -166,6 +170,12 @@ using __locale_t _LIBCPP_NODEBUG = locale_t;
+ #    if defined(_LIBCPP_BUILDING_LIBRARY)
+ using __lconv_t _LIBCPP_NODEBUG = lconv;
+ 
++#      if defined(_LIBCPP_HAS_MINI_LOCALIZATION)
++inline _LIBCPP_HIDE_FROM_ABI __locale_t __newlocale(int, const char*, 
__locale_t) { return 0; }
++inline _LIBCPP_HIDE_FROM_ABI char* __setlocale(int, char const*) { return 
const_cast<char*>("C"); }
++inline _LIBCPP_HIDE_FROM_ABI void __freelocale(__locale_t) {}
++inline _LIBCPP_HIDE_FROM_ABI __lconv_t* __localeconv(__locale_t&) { return 0; 
}
++#      else
+ inline _LIBCPP_HIDE_FROM_ABI __locale_t __newlocale(int __category_mask, 
const char* __name, __locale_t __loc) {
+   return newlocale(__category_mask, __name, __loc);
+ }
+@@ -177,6 +187,7 @@ inline _LIBCPP_HIDE_FROM_ABI char* __setlocale(int 
__category, char const* __loc
+ inline _LIBCPP_HIDE_FROM_ABI void __freelocale(__locale_t __loc) { 
freelocale(__loc); }
+ 
+ inline _LIBCPP_HIDE_FROM_ABI __lconv_t* __localeconv(__locale_t& __loc) { 
return __libcpp_localeconv_l(__loc); }
++#      endif // _LIBCPP_HAS_MINI_LOCALIZATION
+ #    endif // _LIBCPP_BUILDING_LIBRARY
+ 
+ //
+diff --git a/include/__locale_dir/locale_base_api/bsd_locale_fallbacks.h 
b/include/__locale_dir/locale_base_api/bsd_locale_fallbacks.h
+index b62a1b737e..a9a7891b02 100644
+--- a/include/__locale_dir/locale_base_api/bsd_locale_fallbacks.h
++++ b/include/__locale_dir/locale_base_api/bsd_locale_fallbacks.h
+@@ -29,6 +29,9 @@
+ _LIBCPP_BEGIN_NAMESPACE_STD
+ 
+ struct __locale_guard {
++#ifdef _LIBCPP_HAS_MINI_LOCALIZATION
++  _LIBCPP_HIDE_FROM_ABI __locale_guard(locale_t&) {}
++#else
+   _LIBCPP_HIDE_FROM_ABI __locale_guard(locale_t& __loc) : 
__old_loc_(::uselocale(__loc)) {}
+ 
+   _LIBCPP_HIDE_FROM_ABI ~__locale_guard() {
+@@ -37,6 +40,7 @@ struct __locale_guard {
+   }
+ 
+   locale_t __old_loc_;
++#endif
+ 
+   __locale_guard(__locale_guard const&)            = delete;
+   __locale_guard& operator=(__locale_guard const&) = delete;
+diff --git a/src/locale.cpp b/src/locale.cpp
+index da735865c3..624a2775bc 100644
+--- a/src/locale.cpp
++++ b/src/locale.cpp
+@@ -98,6 +98,7 @@ inline constexpr size_t countof(const T* const begin, const 
T* const end) {
+   return static_cast<size_t>(end - begin);
+ }
+ 
++#ifndef _LIBCPP_HAS_MINI_LOCALIZATION
+ string build_name(const string& other, const string& one, locale::category c) 
{
+   if (other == "*" || one == "*")
+     return "*";
+@@ -108,9 +109,11 @@ string build_name(const string& other, const string& one, 
locale::category c) {
+   // different names for different categories.
+   return "*";
+ }
++#endif
+ 
+ } // namespace
+ 
++#ifndef _LIBCPP_HAS_MINI_LOCALIZATION
+ const locale::category locale::none;
+ const locale::category locale::collate;
+ const locale::category locale::ctype;
+@@ -119,6 +122,7 @@ const locale::category locale::numeric;
+ const locale::category locale::time;
+ const locale::category locale::messages;
+ const locale::category locale::all;
++#endif // _LIBCPP_HAS_MINI_LOCALIZATION
+ 
+ class _LIBCPP_HIDDEN locale::__imp : public facet {
+   enum { N = 30 };
+@@ -127,11 +131,15 @@ class _LIBCPP_HIDDEN locale::__imp : public facet {
+ 
+ public:
+   explicit __imp(size_t refs = 0);
++#ifndef _LIBCPP_HAS_MINI_LOCALIZATION
+   explicit __imp(const string& name, size_t refs = 0);
++#endif
+   __imp(const __imp&);
++#ifndef _LIBCPP_HAS_MINI_LOCALIZATION
+   __imp(const __imp&, const string&, locale::category c);
+   __imp(const __imp& other, const __imp& one, locale::category c);
+   __imp(const __imp&, facet* f, long id);
++#endif
+   ~__imp();
+ 
+   const string& name() const { return name_; }
+@@ -148,8 +156,10 @@ private:
+   void install(F* f) {
+     install(f, f->id.__get());
+   }
++#ifndef _LIBCPP_HAS_MINI_LOCALIZATION
+   template <class F>
+   void install_from(const __imp& other);
++#endif
+ };
+ 
+ locale::__imp::__imp(size_t refs) : facet(refs), facets_(N), name_("C") {
+@@ -186,6 +196,7 @@ locale::__imp::__imp(size_t refs) : facet(refs), 
facets_(N), name_("C") {
+ #if _LIBCPP_HAS_WIDE_CHARACTERS
+   install(&make<num_put<wchar_t> >(1u));
+ #endif
++#ifndef _LIBCPP_HAS_MINI_LOCALIZATION
+   install(&make<moneypunct<char, false> >(1u));
+   install(&make<moneypunct<char, true> >(1u));
+ #if _LIBCPP_HAS_WIDE_CHARACTERS
+@@ -212,8 +223,10 @@ locale::__imp::__imp(size_t refs) : facet(refs), 
facets_(N), name_("C") {
+ #if _LIBCPP_HAS_WIDE_CHARACTERS
+   install(&make<std::messages<wchar_t> >(1u));
+ #endif
++#endif // _LIBCPP_HAS_MINI_LOCALIZATION
+ }
+ 
++#ifndef _LIBCPP_HAS_MINI_LOCALIZATION
+ locale::__imp::__imp(const string& name, size_t refs) : facet(refs), 
facets_(N), name_(name) {
+ #if _LIBCPP_HAS_EXCEPTIONS
+   try {
+@@ -273,6 +286,7 @@ locale::__imp::__imp(const string& name, size_t refs) : 
facet(refs), facets_(N),
+   }
+ #endif // _LIBCPP_HAS_EXCEPTIONS
+ }
++#endif // _LIBCPP_HAS_MINI_LOCALIZATION
+ 
+ locale::__imp::__imp(const __imp& other) : facets_(max<size_t>(N, 
other.facets_.size())), name_(other.name_) {
+   facets_ = other.facets_;
+@@ -281,6 +295,7 @@ locale::__imp::__imp(const __imp& other) : 
facets_(max<size_t>(N, other.facets_.
+       facets_[i]->__add_shared();
+ }
+ 
++#ifndef _LIBCPP_HAS_MINI_LOCALIZATION
+ locale::__imp::__imp(const __imp& other, const string& name, locale::category 
c)
+     : facets_(N), name_(build_name(other.name_, name, c)) {
+   facets_ = other.facets_;
+@@ -459,6 +474,7 @@ locale::__imp::__imp(const __imp& other, facet* f, long id)
+       facets_[i]->__add_shared();
+   install(hold.get(), id);
+ }
++#endif // _LIBCPP_HAS_MINI_LOCALIZATION
+ 
+ locale::__imp::~__imp() {
+   for (unsigned i = 0; i < facets_.size(); ++i)
+@@ -529,6 +545,7 @@ const locale& locale::operator=(const locale& other) 
noexcept {
+   return *this;
+ }
+ 
++#ifndef _LIBCPP_HAS_MINI_LOCALIZATION
+ locale::locale(const char* name)
+     : __locale_(name ? new __imp(name) : (__throw_runtime_error("locale 
constructed with null"), nullptr)) {
+   __locale_->acquire();
+@@ -550,9 +567,11 @@ locale::locale(const locale& other, const locale& one, 
category c)
+     : __locale_(new __imp(*other.__locale_, *one.__locale_, c)) {
+   __locale_->acquire();
+ }
++#endif // _LIBCPP_HAS_MINI_LOCALIZATION
+ 
+ string locale::name() const { return __locale_->name(); }
+ 
++#ifndef _LIBCPP_HAS_MINI_LOCALIZATION
+ void locale::__install_ctor(const locale& other, facet* f, long facet_id) {
+   if (f)
+     __locale_ = new __imp(*other.__locale_, f, facet_id);
+@@ -560,6 +579,7 @@ void locale::__install_ctor(const locale& other, facet* f, 
long facet_id) {
+     __locale_ = other.__locale_;
+   __locale_->acquire();
+ }
++#endif // _LIBCPP_HAS_MINI_LOCALIZATION
+ 
+ locale locale::global(const locale& loc) {
+   locale& g = __global();
+@@ -593,6 +613,8 @@ long locale::id::__get() {
+   return __id_ - 1;
+ }
+ 
++#ifndef _LIBCPP_HAS_MINI_LOCALIZATION
++
+ // template <> class collate_byname<char>
+ 
+ collate_byname<char>::collate_byname(const char* n, size_t refs)
+@@ -681,6 +703,7 @@ collate_byname<wchar_t>::do_transform(const char_type* lo, 
const char_type* hi)
+   return out;
+ }
+ #endif // _LIBCPP_HAS_WIDE_CHARACTERS
++#endif // _LIBCPP_HAS_MINI_LOCALIZATION
+ 
+ const ctype_base::mask ctype_base::space;
+ const ctype_base::mask ctype_base::print;
+@@ -955,6 +978,8 @@ const ctype<char>::mask* ctype<char>::classic_table() 
noexcept {
+ }
+ #endif
+ 
++#ifndef _LIBCPP_HAS_MINI_LOCALIZATION
++
+ // template <> class ctype_byname<char>
+ 
+ ctype_byname<char>::ctype_byname(const char* name, size_t refs)
+@@ -1195,6 +1220,7 @@ ctype_byname<wchar_t>::do_narrow(const char_type* low, 
const char_type* high, ch
+   return low;
+ }
+ #endif // _LIBCPP_HAS_WIDE_CHARACTERS
++#endif // _LIBCPP_HAS_MINI_LOCALIZATION
+ 
+ // template <> class codecvt<char, char, mbstate_t>
+ 
+@@ -3846,6 +3872,7 @@ __widen_from_utf8<16>::~__widen_from_utf8() {}
+ 
+ __widen_from_utf8<32>::~__widen_from_utf8() {}
+ 
++#ifndef _LIBCPP_HAS_MINI_LOCALIZATION
+ #if _LIBCPP_HAS_WIDE_CHARACTERS
+ static bool checked_string_to_wchar_convert(wchar_t& dest, const char* ptr, 
__locale::__locale_t loc) {
+   if (*ptr == '\0')
+@@ -3914,6 +3941,7 @@ static bool checked_string_to_char_convert(char& dest, 
const char* ptr, __locale
+ #endif // _LIBCPP_HAS_WIDE_CHARACTERS
+   __libcpp_unreachable();
+ }
++#endif // _LIBCPP_HAS_MINI_LOCALIZATION
+ 
+ // numpunct<char> && numpunct<wchar_t>
+ 
+@@ -3959,6 +3987,8 @@ string numpunct< char >::do_falsename() const { return 
"false"; }
+ wstring numpunct<wchar_t>::do_falsename() const { return L"false"; }
+ #endif
+ 
++#ifndef _LIBCPP_HAS_MINI_LOCALIZATION
++
+ // numpunct_byname<char>
+ 
+ numpunct_byname<char>::numpunct_byname(const char* nm, size_t refs) : 
numpunct<char>(refs) { __init(nm); }
+@@ -4017,6 +4047,7 @@ void numpunct_byname<wchar_t>::__init(const char* nm) {
+   }
+ }
+ #endif // _LIBCPP_HAS_WIDE_CHARACTERS
++#endif // _LIBCPP_HAS_MINI_LOCALIZATION
+ 
+ // num_get helpers
+ 
+@@ -4135,6 +4166,8 @@ char* __num_put_base::__identify_padding(char* __nb, 
char* __ne, const ios_base&
+   return __nb;
+ }
+ 
++#ifndef _LIBCPP_HAS_MINI_LOCALIZATION
++
+ // time_get
+ 
+ static string* init_weeks() {
+@@ -5558,6 +5591,7 @@ void moneypunct_byname<wchar_t, true>::init(const char* 
nm) {
+ #  endif // !_LIBCPP_MSVCRT
+ }
+ #endif // _LIBCPP_HAS_WIDE_CHARACTERS
++#endif // _LIBCPP_HAS_MINI_LOCALIZATION
+ 
+ void __do_nothing(void*) {}
+ 
+@@ -5586,6 +5620,7 @@ _LIBCPP_IF_WIDE_CHARACTERS(template class 
_LIBCPP_CLASS_TEMPLATE_INSTANTIATION_V
+ template struct _LIBCPP_CLASS_TEMPLATE_INSTANTIATION_VIS __num_put<char>;
+ _LIBCPP_IF_WIDE_CHARACTERS(template struct 
_LIBCPP_CLASS_TEMPLATE_INSTANTIATION_VIS __num_put<wchar_t>;)
+ 
++#ifndef _LIBCPP_HAS_MINI_LOCALIZATION
+ template class _LIBCPP_CLASS_TEMPLATE_INSTANTIATION_VIS time_get<char>;
+ _LIBCPP_IF_WIDE_CHARACTERS(template class 
_LIBCPP_CLASS_TEMPLATE_INSTANTIATION_VIS time_get<wchar_t>;)
+ 
+@@ -5637,6 +5672,7 @@ template class _LIBCPP_DEPRECATED_IN_CXX20 
_LIBCPP_CLASS_TEMPLATE_INSTANTIATION_
+ template class _LIBCPP_CLASS_TEMPLATE_INSTANTIATION_VIS 
codecvt_byname<char16_t, char8_t, mbstate_t>;
+ template class _LIBCPP_CLASS_TEMPLATE_INSTANTIATION_VIS 
codecvt_byname<char32_t, char8_t, mbstate_t>;
+ #endif
++#endif // _LIBCPP_HAS_MINI_LOCALIZATION
+ 
+ _LIBCPP_END_NAMESPACE_STD
+ 
diff --git 
a/libs/libxx/libcxx/0017-libcxx-fix-C-20-features-in-source-files-for-C-17-co.patch
 
b/libs/libxx/libcxx/0017-libcxx-fix-C-20-features-in-source-files-for-C-17-co.patch
new file mode 100644
index 00000000000..37a191a65dc
--- /dev/null
+++ 
b/libs/libxx/libcxx/0017-libcxx-fix-C-20-features-in-source-files-for-C-17-co.patch
@@ -0,0 +1,195 @@
+From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
+From: v-zhangxiaomeng5 <[email protected]>
+Date: Wed, 8 Apr 2026 14:58:59 +0800
+Subject: [PATCH] libcxx: fix C++20 features in source files for C++17
+ compatibility
+
+Upstream always builds the library with C++23, but NuttX needs to support 
C++17, 4 files are updated:
+- src/algorithm.cpp: replace ranges::less (C++20) with __less<> for C++17, 
guarded by _LIBCPP_STD_VER
+- src/include/from_chars_floating_point.h: replace floating_point concept 
(C++20) with class template parameter for C++17, guarded by _LIBCPP_STD_VER
+- src/include/to_chars_floating_point.h: replace std::bit_cast (C++20) with 
__bit_cast (internal, all standards), add __bit/bit_cast.h include
+- src/iostream.cpp: guard constexpr destructor (C++20) and replace 
std::construct_at (C++20) with placement new for C++17
+
+The CMake layer also adds -D"constinit=..." for C++17 and excludes 
barrier.cpp/atomic.cpp (C++20-only files).
+
+Signed-off-by: v-zhangxiaomeng5 <[email protected]>
+---
+ src/algorithm.cpp                       |  7 +++++++
+ src/include/from_chars_floating_point.h | 20 ++++++++++++++++++++
+ src/include/to_chars_floating_point.h   | 11 ++++++-----
+ src/iostream.cpp                        | 10 +++++++++-
+ 4 files changed, 42 insertions(+), 6 deletions(-)
+
+diff --git a/src/algorithm.cpp b/src/algorithm.cpp
+index 8157be6f74..16807b94c1 100644
+--- a/src/algorithm.cpp
++++ b/src/algorithm.cpp
+@@ -21,10 +21,17 @@ void __sort(RandomAccessIterator first, 
RandomAccessIterator last, Comp comp) {
+   // Only use bitset partitioning for arithmetic types.  We should also check
+   // that the default comparator is in use so that we are sure that there are 
no
+   // branches in the comparator.
++#if _LIBCPP_STD_VER >= 20
+   std::__introsort<_ClassicAlgPolicy,
+                    ranges::less,
+                    RandomAccessIterator,
+                    __use_branchless_sort<ranges::less, 
RandomAccessIterator>>(first, last, ranges::less{}, depth_limit);
++#else
++  std::__introsort<_ClassicAlgPolicy,
++                   __less<>,
++                   RandomAccessIterator,
++                   __use_branchless_sort<__less<>, 
RandomAccessIterator>>(first, last, __less<>{}, depth_limit);
++#endif
+ }
+ 
+ // clang-format off
+diff --git a/src/include/from_chars_floating_point.h 
b/src/include/from_chars_floating_point.h
+index 9cbabcd106..313c7ea66d 100644
+--- a/src/include/from_chars_floating_point.h
++++ b/src/include/from_chars_floating_point.h
+@@ -41,7 +41,11 @@ _LIBCPP_BEGIN_NAMESPACE_STD
+ // - __ptr is the current position is the input string. This is points beyond
+ //   the initial I character.
+ // - __negative whether a valid string represents -inf or +inf.
++#if _LIBCPP_STD_VER >= 20
+ template <floating_point _Fp>
++#else
++template <class _Fp>
++#endif
+ __from_chars_result<_Fp>
+ __from_chars_floating_point_inf(const char* const __first, const char* 
__last, const char* __ptr, bool __negative) {
+   if (__last - __ptr < 2) [[unlikely]]
+@@ -85,7 +89,11 @@ __from_chars_floating_point_inf(const char* const __first, 
const char* __last, c
+ // - __ptr is the current position is the input string. This is points beyond
+ //   the initial N character.
+ // - __negative whether a valid string represents -nan or +nan.
++#if _LIBCPP_STD_VER >= 20
+ template <floating_point _Fp>
++#else
++template <class _Fp>
++#endif
+ __from_chars_result<_Fp>
+ __from_chars_floating_point_nan(const char* const __first, const char* 
__last, const char* __ptr, bool __negative) {
+   if (__last - __ptr < 2) [[unlikely]]
+@@ -279,7 +287,11 @@ __calculate_result(_Tp __mantissa, int __exponent, bool 
__negative, __from_chars
+ // This function and __from_chars_floating_point_decimal are similar. However
+ // the similar parts are all in helper functions. So the amount of code
+ // duplication is minimal.
++#if _LIBCPP_STD_VER >= 20
+ template <floating_point _Fp>
++#else
++template <class _Fp>
++#endif
+ __from_chars_result<_Fp>
+ __from_chars_floating_point_hex(const char* const __first, const char* 
__last, const char* __ptr, bool __negative) {
+   size_t __n         = __last - __first;
+@@ -358,7 +370,11 @@ __parse_fractional_decimal_constant(const char* __input, 
ptrdiff_t __n, ptrdiff_
+ // __fmt forwarded from from_chars
+ // __ptr the start of the buffer to parse. This is after the optional sign 
character.
+ // __negative should __value be set to a negative value?
++#if _LIBCPP_STD_VER >= 20
+ template <floating_point _Fp>
++#else
++template <class _Fp>
++#endif
+ __from_chars_result<_Fp> __from_chars_floating_point_decimal(
+     const char* const __first, const char* __last, chars_format __fmt, const 
char* __ptr, bool __negative) {
+   ptrdiff_t __n      = __last - __first;
+@@ -412,7 +428,11 @@ __from_chars_result<_Fp> 
__from_chars_floating_point_decimal(
+   return std::__calculate_result(__expanded_float.mantissa, 
__expanded_float.exponent, __negative, __result);
+ }
+ 
++#if _LIBCPP_STD_VER >= 20
+ template <floating_point _Fp>
++#else
++template <class _Fp>
++#endif
+ __from_chars_result<_Fp>
+ __from_chars_floating_point_impl(const char* const __first, const char* 
__last, chars_format __fmt) {
+   if (__first == __last) [[unlikely]]
+diff --git a/src/include/to_chars_floating_point.h 
b/src/include/to_chars_floating_point.h
+index 01c2618169..db87ddd241 100644
+--- a/src/include/to_chars_floating_point.h
++++ b/src/include/to_chars_floating_point.h
+@@ -21,6 +21,7 @@
+ #include <__algorithm/find_if.h>
+ #include <__algorithm/lower_bound.h>
+ #include <__algorithm/min.h>
++#include <__bit/bit_cast.h>
+ #include <__assert>
+ #include <__config>
+ #include <__functional/operations.h>
+@@ -119,7 +120,7 @@ to_chars_result _Floating_to_chars_hex_precision(
+     using _Traits    = _Floating_type_traits<_Floating>;
+     using _Uint_type = typename _Traits::_Uint_type;
+ 
+-    const _Uint_type _Uint_value    = std::bit_cast<_Uint_type>(_Value);
++    const _Uint_type _Uint_value    = __bit_cast<_Uint_type>(_Value);
+     const _Uint_type _Ieee_mantissa = _Uint_value & 
_Traits::_Denormal_mantissa_mask;
+     const int32_t _Ieee_exponent    = static_cast<int32_t>(_Uint_value >> 
_Traits::_Exponent_shift);
+ 
+@@ -347,7 +348,7 @@ to_chars_result _Floating_to_chars_hex_shortest(
+     using _Traits    = _Floating_type_traits<_Floating>;
+     using _Uint_type = typename _Traits::_Uint_type;
+ 
+-    const _Uint_type _Uint_value = std::bit_cast<_Uint_type>(_Value);
++    const _Uint_type _Uint_value = __bit_cast<_Uint_type>(_Value);
+ 
+     if (_Uint_value == 0) { // zero detected; write "0p+0" and return
+         // C11 7.21.6.1 "The fprintf function"/8: "If the value is zero, the 
exponent is zero."
+@@ -839,7 +840,7 @@ to_chars_result _Floating_to_chars_general_precision(
+     using _Traits    = _Floating_type_traits<_Floating>;
+     using _Uint_type = typename _Traits::_Uint_type;
+ 
+-    const _Uint_type _Uint_value = std::bit_cast<_Uint_type>(_Value);
++    const _Uint_type _Uint_value = __bit_cast<_Uint_type>(_Value);
+ 
+     if (_Uint_value == 0) { // zero detected; write "0" and return; 
_Precision is irrelevant due to zero-trimming
+         if (_First == _Last) {
+@@ -1002,7 +1003,7 @@ to_chars_result _Floating_to_chars(
+     using _Traits    = _Floating_type_traits<_Floating>;
+     using _Uint_type = typename _Traits::_Uint_type;
+ 
+-    _Uint_type _Uint_value = std::bit_cast<_Uint_type>(_Value);
++    _Uint_type _Uint_value = __bit_cast<_Uint_type>(_Value);
+ 
+     const bool _Was_negative = (_Uint_value & _Traits::_Shifted_sign_mask) != 
0;
+ 
+@@ -1014,7 +1015,7 @@ to_chars_result _Floating_to_chars(
+         *_First++ = '-';
+ 
+         _Uint_value &= ~_Traits::_Shifted_sign_mask;
+-        _Value = std::bit_cast<_Floating>(_Uint_value);
++        _Value = __bit_cast<_Floating>(_Uint_value);
+     }
+ 
+     if ((_Uint_value & _Traits::_Shifted_exponent_mask) == 
_Traits::_Shifted_exponent_mask) {
+diff --git a/src/iostream.cpp b/src/iostream.cpp
+index 416725235c..8ec0db24a5 100644
+--- a/src/iostream.cpp
++++ b/src/iostream.cpp
+@@ -19,7 +19,10 @@ _LIBCPP_BEGIN_NAMESPACE_STD
+ template <class StreamT, class BufferT>
+ union stream_data {
+   constexpr stream_data() {}
+-  constexpr ~stream_data() {}
++#if _LIBCPP_STD_VER >= 20
++  constexpr
++#endif
++  ~stream_data() {}
+   struct {
+     // The stream has to be the first element, since that's referenced by the 
stream declarations in <iostream>
+     StreamT stream;
+@@ -29,8 +32,13 @@ union stream_data {
+ 
+   void init(FILE* stdstream) {
+     mb = {};
++#if _LIBCPP_STD_VER >= 20
+     std::construct_at(&buffer, stdstream, &mb);
+     std::construct_at(&stream, &buffer);
++#else
++    ::new (static_cast<void*>(&buffer)) BufferT(stdstream, &mb);
++    ::new (static_cast<void*>(&stream)) StreamT(&buffer);
++#endif
+   }
+ };
+ 
diff --git a/libs/libxx/libcxx/CMakeLists.txt b/libs/libxx/libcxx/CMakeLists.txt
index ccf09068a40..6f970391ec5 100644
--- a/libs/libxx/libcxx/CMakeLists.txt
+++ b/libs/libxx/libcxx/CMakeLists.txt
@@ -25,6 +25,23 @@ if(CONFIG_LIBCXX)
 
     set(LIBCXX_VERSION ${CONFIG_LIBCXX_VERSION})
 
+    file(GLOB LIBCXX_PATCHES ${CMAKE_CURRENT_LIST_DIR}/*.patch)
+    list(SORT LIBCXX_PATCHES)
+    set(LIBCXX_PATCH_COMMAND)
+    foreach(patch ${LIBCXX_PATCHES})
+      list(
+        APPEND
+        LIBCXX_PATCH_COMMAND
+        COMMAND
+        patch
+        -p1
+        -d
+        ${CMAKE_CURRENT_LIST_DIR}/libcxx
+        <
+        ${patch})
+    endforeach()
+    list(REMOVE_AT LIBCXX_PATCH_COMMAND 0)
+
     FetchContent_Declare(
       libcxx
       DOWNLOAD_NAME "libcxx-${LIBCXX_VERSION}.src.tar.xz"
@@ -42,19 +59,7 @@ if(CONFIG_LIBCXX)
           ""
           TEST_COMMAND
           ""
-      PATCH_COMMAND
-        patch -p1 -d ${CMAKE_CURRENT_LIST_DIR}/libcxx <
-        ${CMAKE_CURRENT_LIST_DIR}/0001_fix_stdatomic_h_miss_typedef.patch &&
-        patch -p3 -d ${CMAKE_CURRENT_LIST_DIR}/libcxx <
-        ${CMAKE_CURRENT_LIST_DIR}/mbstate_t.patch && patch -p1 -d
-        ${CMAKE_CURRENT_LIST_DIR}/libcxx <
-        ${CMAKE_CURRENT_LIST_DIR}/0001-libcxx-remove-mach-time-h.patch && patch
-        -p1 -d ${CMAKE_CURRENT_LIST_DIR}/libcxx <
-        ${CMAKE_CURRENT_LIST_DIR}/0001-libcxx-fix-ld-errors.patch && patch -p1
-        -d ${CMAKE_CURRENT_LIST_DIR}/libcxx <
-        ${CMAKE_CURRENT_LIST_DIR}/0001-Fix-build-error-about-__GLIBC__.patch &&
-        patch -p1 -d ${CMAKE_CURRENT_LIST_DIR}/libcxx <
-        
${CMAKE_CURRENT_LIST_DIR}/0001-libc-Fix-failures-with-GCC-14-92663.patch
+      PATCH_COMMAND ${LIBCXX_PATCH_COMMAND}
       DOWNLOAD_NO_PROGRESS true
       TIMEOUT 30)
 
@@ -81,7 +86,16 @@ if(CONFIG_LIBCXX)
              ${CMAKE_CURRENT_LIST_DIR}/libcxx/test/support
              ${CMAKE_CURRENT_LIST_DIR}/libcxx/src)
 
+  # llvm-21+ requires __assertion_handler
+  if(EXISTS
+     ${CMAKE_CURRENT_LIST_DIR}/libcxx/vendor/llvm/default_assertion_handler.in)
+    configure_file(
+      ${CMAKE_CURRENT_LIST_DIR}/libcxx/vendor/llvm/default_assertion_handler.in
+      ${NUTTX_BINARY_DIR}/include/libcxx_config/__assertion_handler COPYONLY)
+  endif()
+
   add_compile_definitions(_LIBCPP_BUILDING_LIBRARY)
+
   if(CONFIG_LIBSUPCXX_TOOLCHAIN)
     add_compile_definitions(__GLIBCXX__)
   endif()
@@ -97,9 +111,17 @@ if(CONFIG_LIBCXX)
   file(GLOB SRCS ${CMAKE_CURRENT_LIST_DIR}/libcxx/src/*.cpp)
 
   string(REGEX MATCH "[0-9]+$" CPP_STD_VER "${CONFIG_CXX_STANDARD}")
-  if(${CPP_STD_VER} GREATER_EQUAL 20)
-    file(GLOB SRCSTMP ${CMAKE_CURRENT_LIST_DIR}/libcxx/src/experimental/*.cpp)
-    list(APPEND SRCS ${SRCSTMP})
+
+  if(${CPP_STD_VER} LESS 23)
+    list(REMOVE_ITEM SRCS ${CMAKE_CURRENT_LIST_DIR}/libcxx/src/expected.cpp)
+  endif()
+
+  if(${CPP_STD_VER} LESS 20)
+    list(REMOVE_ITEM SRCS ${CMAKE_CURRENT_LIST_DIR}/libcxx/src/barrier.cpp
+         ${CMAKE_CURRENT_LIST_DIR}/libcxx/src/atomic.cpp)
+  endif()
+
+  if(${CPP_STD_VER} GREATER_EQUAL 17)
     file(GLOB SRCSTMP ${CMAKE_CURRENT_LIST_DIR}/libcxx/src/filesystem/*.cpp)
     list(APPEND SRCS ${SRCSTMP})
     file(GLOB SRCSTMP ${CMAKE_CURRENT_LIST_DIR}/libcxx/src/ryu/*.cpp)
@@ -128,7 +150,9 @@ if(CONFIG_LIBCXX)
       ${CMAKE_CURRENT_LIST_DIR}/libcxx/src/iostream.cpp
       ${CMAKE_CURRENT_LIST_DIR}/libcxx/src/locale.cpp
       ${CMAKE_CURRENT_LIST_DIR}/libcxx/src/regex.cpp
-      ${CMAKE_CURRENT_LIST_DIR}/libcxx/src/strstream.cpp)
+      ${CMAKE_CURRENT_LIST_DIR}/libcxx/src/strstream.cpp
+      ${CMAKE_CURRENT_LIST_DIR}/libcxx/src/ostream.cpp
+      ${CMAKE_CURRENT_LIST_DIR}/libcxx/src/fstream.cpp)
     list(REMOVE_ITEM SRCS ${SRCSTMP})
   endif()
 
@@ -141,13 +165,26 @@ if(CONFIG_LIBCXX)
     list(APPEND FLAGS -Wno-maybe-uninitialized -Wno-alloc-size-larger-than)
   endif()
 
+  # Suppress C++20 keyword(e.g. constinit macro) for -std=c++17
+  if(${CPP_STD_VER} LESS 20)
+    list(APPEND FLAGS -Wno-c++20-compat)
+  endif()
+
   nuttx_add_system_library(libcxx)
   target_sources(libcxx PRIVATE ${SRCS})
+
   target_compile_options(libcxx PRIVATE ${FLAGS})
   target_include_directories(
     libcxx BEFORE PRIVATE ${CMAKE_CURRENT_LIST_DIR}/libcxx/src
                           ${CMAKE_CURRENT_LIST_DIR})
 
+  # Map C++20 keyword constinit to compiler attribute for C++17 builds
+  if(${CPP_STD_VER} LESS 20)
+    target_compile_definitions(
+      libcxx
+      PRIVATE "constinit=__attribute__((__require_constant_initialization__))")
+  endif()
+
   if(CONFIG_LIBCXX_TEST)
     list(
       APPEND
diff --git a/libs/libxx/libcxx/Make.defs b/libs/libxx/libcxx/Make.defs
index 24af401e6ac..7f542422afe 100644
--- a/libs/libxx/libcxx/Make.defs
+++ b/libs/libxx/libcxx/Make.defs
@@ -31,20 +31,17 @@ libcxx/libcxx: libcxx-$(LIBCXX_VERSION).src.tar.xz
        $(Q) tar -xf $< \
                 --exclude libcxx-$(LIBCXX_VERSION).src/test/std/pstl
        $(Q) mv libcxx-$(LIBCXX_VERSION).src $@
-       $(Q) patch -p0 < libcxx/0001_fix_stdatomic_h_miss_typedef.patch -d 
libcxx
-       $(Q) patch -p2 < libcxx/mbstate_t.patch -d libcxx
-       $(Q) patch -p0 < libcxx/0001-libcxx-remove-mach-time-h.patch -d libcxx
-       $(Q) patch -p0 < libcxx/0001-libcxx-fix-ld-errors.patch -d libcxx
-       $(Q) patch -p0 < libcxx/0001-Fix-build-error-about-__GLIBC__.patch -d 
libcxx
-       $(Q) patch -p0 < libcxx/0001-libc-Fix-failures-with-GCC-14-92663.patch 
-d libcxx
+       $(Q) $(foreach PATCH_FILE,$(sort $(wildcard libcxx/*.patch)), \
+              patch -p1 -d $@ < $(PATCH_FILE) &&) true
 
 endif
 
 $(TOPDIR)/include/libcxx: libcxx/libcxx
        $(Q) $(DIRLINK) $(CURDIR)/$</include $(TOPDIR)/include/libcxx
-       $(Q) cp $(CURDIR)/__config_site $(TOPDIR)/include/libcxx/__config_site
 
 context:: $(TOPDIR)/include/libcxx
+       $(Q) cp $(CURDIR)/__config_site $(TOPDIR)/include/libcxx/__config_site
+       $(Q) cp 
$(CURDIR)/libcxx/libcxx/vendor/llvm/default_assertion_handler.in 
$(TOPDIR)/include/libcxx/__assertion_handler
 
 distclean::
        $(Q) $(DIRUNLINK) $(TOPDIR)/include/libcxx
@@ -74,12 +71,23 @@ endif
 
 CPPSRCS += $(wildcard libcxx/libcxx/src/*.cpp)
 CPP_STD_VER := $(shell echo $(CONFIG_CXX_STANDARD) | sed -E 
's/.*\+\+([0-9]+)$$/\1/')
-ifeq ($(shell [ $(CPP_STD_VER) -ge 20 ] && echo true),true)
-  CPPSRCS += $(wildcard libcxx/libcxx/src/experimental/*.cpp)
+
+# Filesystem and ryu sources for C++17+
+ifeq ($(shell [ $(CPP_STD_VER) -ge 17 ] && echo true),true)
   CPPSRCS += $(wildcard libcxx/libcxx/src/filesystem/*.cpp)
   CPPSRCS += $(wildcard libcxx/libcxx/src/ryu/*.cpp)
 endif
 
+# Exclude barrier.cpp/atomic.cpp for C++ < 20
+ifeq ($(shell [ $(CPP_STD_VER) -lt 20 ] && echo true),true)
+  CPPSRCS := $(filter-out libcxx/libcxx/src/barrier.cpp 
libcxx/libcxx/src/atomic.cpp, $(CPPSRCS))
+endif
+
+# Exclude expected.cpp for C++ < 23
+ifeq ($(shell [ $(CPP_STD_VER) -lt 23 ] && echo true),true)
+  CPPSRCS := $(filter-out libcxx/libcxx/src/expected.cpp, $(CPPSRCS))
+endif
+
 ifeq ($(shell [ $(CPP_STD_VER) -le 14 ] && echo true),true)
   EXCLUDE_CPP := libcxx/libcxx/src/any.cpp
   EXCLUDE_CPP += libcxx/libcxx/src/variant.cpp
@@ -97,5 +105,13 @@ ifeq ($(CONFIG_CXX_NO_LOCALIZATION),y)
   LOCALE_CPPSRCS += libcxx/libcxx/src/locale.cpp
   LOCALE_CPPSRCS += libcxx/libcxx/src/regex.cpp
   LOCALE_CPPSRCS += libcxx/libcxx/src/strstream.cpp
+  LOCALE_CPPSRCS += libcxx/libcxx/src/ostream.cpp
+  LOCALE_CPPSRCS += libcxx/libcxx/src/fstream.cpp
   CPPSRCS := $(filter-out $(LOCALE_CPPSRCS), $(CPPSRCS))
 endif
+
+# Map C++20 keyword constinit to compiler attribute for C++17 builds
+ifeq ($(shell [ $(CPP_STD_VER) -lt 20 ] && echo true),true)
+  CXXFLAGS += 
${DEFINE_PREFIX}constinit=__attribute__\(\(__require_constant_initialization__\)\)
+  CXXFLAGS += -Wno-c++20-compat
+endif
diff --git a/libs/libxx/libcxx/mbstate_t.patch 
b/libs/libxx/libcxx/mbstate_t.patch
deleted file mode 100644
index 1aee59bde04..00000000000
--- a/libs/libxx/libcxx/mbstate_t.patch
+++ /dev/null
@@ -1,17 +0,0 @@
---- libs/libxx/libcxx/include/__mbstate_t.h    2023-11-28 09:52:28.000000000 
+0100
-+++ libs/libxx/libcxx/include/__mbstate_t.h    2023-12-05 16:14:46.523689408 
+0100
-@@ -39,12 +39,12 @@
- #   define __NEED_mbstate_t
- #   include <bits/alltypes.h>
- #   undef __NEED_mbstate_t
-+#elif !defined(_LIBCPP_HAS_NO_WIDE_CHARACTERS) && 
__has_include_next(<wchar.h>)
-+#   include_next <wchar.h> // fall back to the C standard provider of 
mbstate_t
- #elif __has_include(<bits/types/mbstate_t.h>)
- #   include <bits/types/mbstate_t.h> // works on most Unixes
- #elif __has_include(<sys/_types/_mbstate_t.h>)
- #   include <sys/_types/_mbstate_t.h> // works on Darwin
--#elif !defined(_LIBCPP_HAS_NO_WIDE_CHARACTERS) && 
__has_include_next(<wchar.h>)
--#   include_next <wchar.h> // fall back to the C standard provider of 
mbstate_t
- #elif __has_include_next(<uchar.h>)
- #   include_next <uchar.h> // <uchar.h> is also required to make mbstate_t 
visible
- #else
diff --git 
a/libs/libxx/libcxxabi/0001-cxa_exception.cpp-guard-ASAN-interfaces-with-__has_i.patch
 
b/libs/libxx/libcxxabi/0001-cxa_exception.cpp-guard-ASAN-interfaces-with-__has_i.patch
new file mode 100644
index 00000000000..94ccac00795
--- /dev/null
+++ 
b/libs/libxx/libcxxabi/0001-cxa_exception.cpp-guard-ASAN-interfaces-with-__has_i.patch
@@ -0,0 +1,26 @@
+From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
+From: v-zhangxiaomeng5 <[email protected]>
+Date: Fri, 10 Apr 2026 17:06:56 +0800
+Subject: [PATCH] cxa_exception.cpp: guard ASAN interfaces with __has_include
+ for bare-metal
+
+GCC 15 added __has_feature() support, causing __has_feature(address_sanitizer) 
to return true when NuttX KASAN (-fsanitize=kernel-address) is enabled. This 
triggers includes of sanitizer/asan_interface.h.
+
+Signed-off-by: v-zhangxiaomeng5 <[email protected]>
+---
+ src/cxa_exception.cpp | 2 +-
+ 1 file changed, 1 insertion(+), 1 deletion(-)
+
+diff --git a/src/cxa_exception.cpp b/src/cxa_exception.cpp
+index 92901a8..cfc443e 100644
+--- a/src/cxa_exception.cpp
++++ b/src/cxa_exception.cpp
+@@ -284,7 +284,7 @@ __cxa_throw(void *thrown_object, std::type_info *tinfo, 
void (_LIBCXXABI_DTOR_FU
+   __cxa_exception* exception_header = 
__cxa_init_primary_exception(thrown_object, tinfo, dest);
+   exception_header->referenceCount = 1; // This is a newly allocated 
exception, no need for thread safety.
+ 
+-#if __has_feature(address_sanitizer)
++#if __has_feature(address_sanitizer) && 
__has_include(<sanitizer/asan_interface.h>)
+   // Inform the ASan runtime that now might be a good time to clean stuff up.
+   __asan_handle_no_return();
+ #endif
diff --git 
a/libs/libxx/libcxxabi/0001-libcxxabi-Fix-build-warnings-generated-by-CMake-comp.patch
 
b/libs/libxx/libcxxabi/0001-libcxxabi-Fix-build-warnings-generated-by-CMake-comp.patch
deleted file mode 100644
index f07e83d8c93..00000000000
--- 
a/libs/libxx/libcxxabi/0001-libcxxabi-Fix-build-warnings-generated-by-CMake-comp.patch
+++ /dev/null
@@ -1,38 +0,0 @@
-From df7ad61eb3ce52ebf864f30ec3ad1a6ccea74730 Mon Sep 17 00:00:00 2001
-From: cuiziwei <[email protected]>
-Date: Thu, 23 May 2024 11:11:30 +0800
-libcxxabi:Fix build warnings generated by CMake
- compilation.
-MIME-Version: 1.0
-Content-Type: text/plain; charset=UTF-8
-Content-Transfer-Encoding: 8bit
-
-nuttx/libs/libxx/libcxxabi/src/cxa_personality.cpp: In function ‘void 
__cxxabiv1::__cxa_call_unexpected(void*)’:
-nuttx/libs/libxx/libcxxabi/src/cxa_personality.cpp:1250:46: warning: 
‘ttypeIndex’ may be used uninitialized [-Wmaybe-uninitialized]
- 1250 |                 if (!exception_spec_can_catch(ttypeIndex, classInfo, 
ttypeEncoding,
-      |                      
~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
- 1251 |                                               excpType, adjustedPtr,
-      |                                               ~~~~~~~~~~~~~~~~~~~~~~
- 1252 |                                               unwind_exception, base))
-
-Signed-off-by: cuiziwei <[email protected]>
----
- src/cxa_personality.cpp | 2 +-
- 1 file changed, 1 insertion(+), 1 deletion(-)
-
-diff --git libcxxabi/src/cxa_personality.cpp libcxxabi/src/cxa_personality.cpp
-index b28c58d..5b58037 100644
---- libcxxabi/src/cxa_personality.cpp
-+++ libcxxabi/src/cxa_personality.cpp
-@@ -1174,7 +1174,7 @@ __cxa_call_unexpected(void* arg)
-     std::unexpected_handler u_handler;
-     std::terminate_handler t_handler;
-     __cxa_exception* old_exception_header = 0;
--    int64_t ttypeIndex;
-+    int64_t ttypeIndex = 0;
-     const uint8_t* lsda;
-     uintptr_t base = 0;
- 
--- 
-2.34.1
-
diff --git 
a/libs/libxx/libcxxabi/0002-cxa_personality.cpp-fix-_Unwind_State-bitwise-operat.patch
 
b/libs/libxx/libcxxabi/0002-cxa_personality.cpp-fix-_Unwind_State-bitwise-operat.patch
new file mode 100644
index 00000000000..b60b283b96f
--- /dev/null
+++ 
b/libs/libxx/libcxxabi/0002-cxa_personality.cpp-fix-_Unwind_State-bitwise-operat.patch
@@ -0,0 +1,26 @@
+From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
+From: v-zhangxiaomeng5 <[email protected]>
+Date: Mon, 13 Apr 2026 15:28:45 +0800
+Subject: [PATCH] cxa_personality.cpp: fix _Unwind_State bitwise operation
+ error on ARM GCC
+
+On ARM, the C++ exception ABI (EHABI) defines _Unwind_State as an enum type. 
GCC 15 with -Werror rejects the implicit conversion from int back to 
_Unwind_State after a bitwise &= operation. Add static_cast to make the 
conversion explicit. This code is inside the _LIBCXXABI_ARM_EHABI branch and 
only affects ARM targets. Other architectures use the Itanium ABI where the 
equivalent parameter is int, so they are unaffected.
+
+Signed-off-by: v-zhangxiaomeng5 <[email protected]>
+---
+ src/cxa_personality.cpp | 2 +-
+ 1 file changed, 1 insertion(+), 1 deletion(-)
+
+diff --git a/src/cxa_personality.cpp b/src/cxa_personality.cpp
+index 5f6e75c..d72d3ef 100644
+--- a/src/cxa_personality.cpp
++++ b/src/cxa_personality.cpp
+@@ -1074,7 +1074,7 @@ __gxx_personality_v0(_Unwind_State state,
+ 
+     // Check the undocumented force unwinding behavior
+     bool is_force_unwinding = state & _US_FORCE_UNWIND;
+-    state &= ~_US_FORCE_UNWIND;
++    state = static_cast<_Unwind_State>(state & ~_US_FORCE_UNWIND);
+ 
+     scan_results results;
+     switch (state) {
diff --git a/libs/libxx/libcxxabi/0002-libcxxabi-fix-compilation-errors.patch 
b/libs/libxx/libcxxabi/0002-libcxxabi-fix-compilation-errors.patch
deleted file mode 100644
index 6881e77804c..00000000000
--- a/libs/libxx/libcxxabi/0002-libcxxabi-fix-compilation-errors.patch
+++ /dev/null
@@ -1,32 +0,0 @@
-From b84bcf890c949d248ade97a5e1fbcf2a8e3efcd7 Mon Sep 17 00:00:00 2001
-From: yinshengkai <[email protected]>
-Date: Fri, 5 Jul 2024 16:59:49 +0800
-libcxxabi: fix compilation errors
-
-error: invalid conversion from 'int' to '_Unwind_State' [-fpermissive]
- 1073 |     state &= ~_US_FORCE_UNWIND;
-      |     ~~~~~~^~~~~~~~~~~~~~~~~~~~
-      |           |
-      |           int
-
-Signed-off-by: yinshengkai <[email protected]>
----
- src/cxa_personality.cpp | 2 +-
- 1 file changed, 1 insertion(+), 1 deletion(-)
-
-diff --git libcxxabi/src/cxa_personality.cpp libcxxabi/src/cxa_personality.cpp
-index 5b58037..3e1fd83 100644
---- libcxxabi/src/cxa_personality.cpp
-+++ libcxxabi/src/cxa_personality.cpp
-@@ -1070,7 +1070,7 @@ __gxx_personality_v0(_Unwind_State state,
- 
-     // Check the undocumented force unwinding behavior
-     bool is_force_unwinding = state & _US_FORCE_UNWIND;
--    state &= ~_US_FORCE_UNWIND;
-+    state = (_Unwind_State)(state & ~_US_FORCE_UNWIND);
- 
-     scan_results results;
-     switch (state) {
--- 
-2.34.1
-
diff --git 
a/libs/libxx/libcxxabi/0003-cxa_exception_storage.cpp-use-tls_info_s.tl_eh_globa.patch
 
b/libs/libxx/libcxxabi/0003-cxa_exception_storage.cpp-use-tls_info_s.tl_eh_globa.patch
new file mode 100644
index 00000000000..a7c7e21edc3
--- /dev/null
+++ 
b/libs/libxx/libcxxabi/0003-cxa_exception_storage.cpp-use-tls_info_s.tl_eh_globa.patch
@@ -0,0 +1,60 @@
+From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
+From: v-zhangxiaomeng5 <[email protected]>
+Date: Tue, 14 Apr 2026 20:12:47 +0800
+Subject: [PATCH] cxa_exception_storage.cpp: use tls_info_s.tl_eh_globals for
+ per-thread exception storage on NuttX
+
+Store __cxa_eh_globals pointer directly in tls_info_s for per-thread isolation 
without depending on CONFIG_TLS_TASK_NELEM or pthread_key. Lazy-allocate on 
first access via __calloc_with_fallback, with destructor registered for cleanup 
on thread exit.
+
+Signed-off-by: v-zhangxiaomeng5 <[email protected]>
+---
+ src/cxa_exception_storage.cpp | 36 +++++++++++++++++++++++++++++++++++
+ 1 file changed, 36 insertions(+)
+
+diff --git a/src/cxa_exception_storage.cpp b/src/cxa_exception_storage.cpp
+index 05da6a4..8215160 100644
+--- a/src/cxa_exception_storage.cpp
++++ b/src/cxa_exception_storage.cpp
+@@ -24,6 +24,42 @@ extern "C" {
+ } // extern "C"
+ } // namespace __cxxabiv1
+ 
++#elif defined(__NuttX__) && defined(CONFIG_CXX_EXCEPTION) \
++      && !defined(CONFIG_SCHED_THREAD_LOCAL)
++
++// Use the dedicated tl_eh_globals field in tls_info_s for per-thread
++// exception storage. No dependency on CONFIG_TLS_TASK_NELEM.
++
++#include "abort_message.h"
++#include "fallback_malloc.h"
++
++#include <nuttx/tls.h>
++
++namespace __cxxabiv1 {
++extern "C" {
++    __cxa_eh_globals *__cxa_get_globals() {
++        FAR struct tls_info_s *tls = tls_get_info();
++        __cxa_eh_globals *retVal =
++            static_cast<__cxa_eh_globals *>(tls->tl_eh_globals);
++
++        if (NULL == retVal) {
++            retVal = static_cast<__cxa_eh_globals *>(
++                __calloc_with_fallback(1, sizeof(__cxa_eh_globals)));
++            if (NULL == retVal)
++                __abort_message("cannot allocate __cxa_eh_globals");
++            tls->tl_eh_globals = retVal;
++            tls->tl_eh_free = __free_with_fallback;
++        }
++        return retVal;
++    }
++
++    __cxa_eh_globals *__cxa_get_globals_fast() {
++        FAR struct tls_info_s *tls = tls_get_info();
++        return static_cast<__cxa_eh_globals *>(tls->tl_eh_globals);
++    }
++} // extern "C"
++} // namespace __cxxabiv1
++
+ #elif __has_feature(cxx_thread_local)
+ 
+ namespace __cxxabiv1 {
diff --git a/libs/libxx/libcxxabi/CMakeLists.txt 
b/libs/libxx/libcxxabi/CMakeLists.txt
index 748ef060ae0..80b7b8f0383 100644
--- a/libs/libxx/libcxxabi/CMakeLists.txt
+++ b/libs/libxx/libcxxabi/CMakeLists.txt
@@ -24,6 +24,23 @@ if(CONFIG_LIBCXXABI)
 
     set(LIBCXXABI_VERSION ${CONFIG_LIBCXXABI_VERSION})
 
+    file(GLOB LIBCXXABI_PATCHES ${CMAKE_CURRENT_LIST_DIR}/*.patch)
+    list(SORT LIBCXXABI_PATCHES)
+    set(LIBCXXABI_PATCH_COMMAND)
+    foreach(patch ${LIBCXXABI_PATCHES})
+      list(
+        APPEND
+        LIBCXXABI_PATCH_COMMAND
+        COMMAND
+        patch
+        -p1
+        -d
+        ${CMAKE_CURRENT_LIST_DIR}/libcxxabi
+        <
+        ${patch})
+    endforeach()
+    list(REMOVE_AT LIBCXXABI_PATCH_COMMAND 0)
+
     FetchContent_Declare(
       libcxxabi
       DOWNLOAD_NAME "libcxxabi-${LIBCXXABI_VERSION}.src.tar.xz"
@@ -41,7 +58,7 @@ if(CONFIG_LIBCXXABI)
           ""
           TEST_COMMAND
           ""
-      PATCH_COMMAND ""
+      PATCH_COMMAND ${LIBCXXABI_PATCH_COMMAND}
       DOWNLOAD_NO_PROGRESS true
       TIMEOUT 30)
 
@@ -122,6 +139,15 @@ if(CONFIG_LIBCXXABI)
   target_compile_definitions(libcxxabi
                              PRIVATE LIBCXXABI_NON_DEMANGLING_TERMINATE)
 
+  # Map C++20 keyword constinit to compiler attribute(works for gcc&clang)
+  string(REGEX MATCH "[0-9]+$" CPP_STD_VER_ABI "${CONFIG_CXX_STANDARD}")
+  if(CPP_STD_VER_ABI LESS 20)
+    target_compile_definitions(
+      libcxxabi
+      PRIVATE "constinit=__attribute__((__require_constant_initialization__))")
+    target_compile_options(libcxxabi PRIVATE -Wno-c++20-compat)
+  endif()
+
   target_sources(libcxxabi PRIVATE ${TARGET_SRCS})
   target_include_directories(
     libcxxabi BEFORE PRIVATE ${NUTTX_DIR}/libs/libxx/libcxx/libcxx/src
diff --git a/libs/libxx/libcxxabi/Make.defs b/libs/libxx/libcxxabi/Make.defs
index 80ca2e8be41..6f84e590e9a 100644
--- a/libs/libxx/libcxxabi/Make.defs
+++ b/libs/libxx/libcxxabi/Make.defs
@@ -30,8 +30,8 @@ libcxxabi-$(LIBCXXABI_VERSION).src.tar.xz:
 libcxxabi/libcxxabi: libcxxabi-$(LIBCXXABI_VERSION).src.tar.xz
        $(Q) tar -xf $<
        $(Q) mv libcxxabi-$(LIBCXXABI_VERSION).src $@
-       $(Q) patch -p0 < 
libcxxabi/0001-libcxxabi-Fix-build-warnings-generated-by-CMake-comp.patch -d 
libcxxabi
-       $(Q) patch -p0 < libcxxabi/0002-libcxxabi-fix-compilation-errors.patch 
-d libcxxabi
+       $(Q) $(foreach PATCH_FILE,$(sort $(wildcard libcxxabi/*.patch)), \
+              patch -p1 -d $@ < $(PATCH_FILE) &&) true
 endif
 
 $(TOPDIR)/include/libcxxabi: libcxxabi/libcxxabi
@@ -90,5 +90,12 @@ endif
 CXXFLAGS += -DLIBCXXABI_NON_DEMANGLING_TERMINATE
 CXXFLAGS += -DLIBCXXABI_BAREMETAL
 
+# Map C++20 keyword constinit to compiler attribute for C++17 builds
+CPP_STD_VER_ABI := $(shell echo $(CONFIG_CXX_STANDARD) | sed -E 
's/.*\+\+([0-9]+)$$/\1/')
+ifeq ($(shell [ $(CPP_STD_VER_ABI) -lt 20 ] && echo true),true)
+  CXXFLAGS += 
${DEFINE_PREFIX}constinit=__attribute__\(\(__require_constant_initialization__\)\)
+  CXXFLAGS += -Wno-c++20-compat
+endif
+
 DEPPATH += --dep-path libcxxabi/libcxxabi/src
 VPATH += libcxxabi/libcxxabi/src

Reply via email to