v-zhangxiaomeng5 opened a new pull request, #21828:
URL: https://github.com/apache/nuttx/pull/21828

   ## Summary
   
   Upgrade the in-tree LLVM libc++ and libc++abi from 17.0.6 to 21.1.8.
   
   The 17.0.6 patches do not apply to 21.1.8, and 21.1.8 declares support
   for GCC 14 and later only, while NuttX CI builds libc++ with GCC 12
   (sim), GCC 13.2 (Arm) and GCC 14 (RISC-V, Xtensa). The PR therefore
   also carries the changes that 21.1.8 needs on NuttX and on these
   compilers.
   
   The PR has six commits. The first five do not depend on the libc++
   version and each builds on master with 17.0.6. The last one switches
   the version, and has to change the build and the patches together:
   21.1.8 does not build without its patches, and the patches do not
   apply to 17.0.6.
   
   1. `tls: add dedicated fields for tls per-thread and per-group data`
      Adds `tl_eh_globals` to `struct tls_info_s` and
      `ta_thread_local_data` to `struct task_info_s`, freed when the thread
      or the task group exits. libc++abi keeps the exception state of a
      thread there, and libc++ the `__thread_local_data` of a task group.
      Both used a single pthread key created once, while NuttX allocates
      pthread keys per task group, so a second task group got EINVAL from
      `pthread_setspecific()`. The fields are only present with
      `CONFIG_CXX_EXCEPTION` or `CONFIG_LIBCXX`.
   2. `compiler.h: define __has_feature/__has_extension/__has_keyword as
      0 for GCC < 14`
      libc++ 17 defined these when the compiler lacks them, 21 does not,
      and GCC only has them since 14.
   3. `arch/arm: mark arm_read_tp used to survive LTO`
      It is only referenced from the inline assembly of
      `__aeabi_read_tp()`, so LTO drops it.
   4. `libcxx: add supporting header file for libcxx
      from_chars_floating_point.h`
      21.1.8 includes llvm-libc headers that the libcxx tarball does not
      contain. `from_chars_support.h` provides the same interface on top
      of `strtof()`/`strtod()`.
   5. `libcxxabi/cmake: compile cxa_noexception.cpp ... when exception is
      disabled`
      As upstream libc++abi does. Without it, a build without exceptions
      lacks `__cxa_uncaught_exceptions` and friends.
   6. `libxx: upgrade libcxx and libcxxabi from llvm 17.0.6 to 21.1.8`
      Kconfig default version, `__config_site` in the 21 format, the source
      lists, `__assertion_handler`, and the patch series below. The patches
      are now kept in git format and every `*.patch` in the directory is
      applied in name order with `patch -p1` by both CMake and Make, so a
      new patch needs no build change. The CMake build of libcxxabi applied
      none of its patches before.
   
   libcxx patches (`libs/libxx/libcxx/`):
   
   | Patch | Why |
   |---|---|
   | 0001 keep the host headers out of the sim build | sim only uses 
`-nostdinc++`; glibc's `mbstate_t` and the 4-argument `_IOC` of 
`linux/random.h` win over NuttX |
   | 0002 `__fwd/ios.h` streamoff | `_NEWLIB_VERSION` leaks in from the 
toolchain `math.h`, so translation units disagree on `streamoff` and the link 
fails (`basic_streambuf::seekoff`) |
   | 0003 `from_chars_floating_point.h` | use `from_chars_support.h` (commit 4) 
|
   | 0004 what GCC 12 lacks from GCC 13 | `__remove_reference`, 
`__remove_cvref`, `__is_convertible`, `__is_nothrow_convertible`, 
`__reference_binds_to_temporary`, dependent `static_assert` |
   | 0005 what GCC 12 and 13 lack from GCC 14 and 15 | type trait, bit and 
`__type_pack_element` builtins; selected by `__has_builtin` where GCC 14 also 
lacks them |
   | 0006 compiler version warning | lowered to GCC 12; `-Werror` builds 
(matter's GN build) fail on it |
   | 0007 `ios.cpp` | null dereference after `realloc()` fails in 
`register_callback()` |
   | 0008 `condition_variable` | negative timeout before the clock is set makes 
`pthread_cond_timedwait()` return EINVAL, which aborts |
   | 0009 `uninitialized_algorithms.h` | `memcpy()` with null pointers for an 
empty range (UBSan) |
   | 0010 `~basic_string()` | Arm GCC does not emit the out-of-line `constexpr` 
destructor, undefined reference at link |
   | 0011, 0012, 0013 GCC false positives | 
`-Wstringop-overflow`/`-Warray-bounds` (`constexpr_c_functions.h`, 
`char_traits`) and `-Wmaybe-uninitialized` (`__hash_table`) in user code; seen 
with GCC 12 to 15
   at `-O2`/`-O3`, and for `__hash_table` at every level on Arm and RISC-V. 
`char_traits` also gets back the generic base template that LLVM 18 removed |
   | 0014 `thread.cpp` | use `ta_thread_local_data` (commit 1) |
   | 0015 `std::thread` stack size | `thread::attributes` with `stack_size()` |
   | 0016 mini localization | implements `CONFIG_CXX_MINI_LOCALIZATION`, which 
Kconfig already offers |
   | 0017 C++17 | the library sources use C++20; lets 
`CONFIG_CXX_STANDARD="gnu++17"` build |
   
   libcxxabi patches (`libs/libxx/libcxxabi/`):
   
   | Patch | Why |
   |---|---|
   | 0001 `cxa_exception.cpp` | guard the ASan interface with `__has_include`, 
KASan builds have no `sanitizer/asan_interface.h` |
   | 0002 `cxa_personality.cpp` | `_Unwind_State` conversion on Arm EHABI, same 
fix as the old patch |
   | 0003 `cxa_exception_storage.cpp` | use `tl_eh_globals` (commit 1) |
   
   Dropped 17.0.6 patches: `remove_pointer` (GCC 14) is in LLVM 21;
   `fix-ld-errors` is replaced by commit 5; `stdatomic.h`, `mach_time`,
   `__GLIBC__` and the libcxxabi `ttypeIndex` warning fix are not needed
   by 21.1.8 on NuttX.
   
   ## Impact
   
   * The default `CONFIG_LIBCXX_VERSION` and `CONFIG_LIBCXXABI_VERSION`
     become 21.1.8. No defconfig in the tree sets them.
   * A tree that already has the 17.0.6 sources extracted under
     `libs/libxx/libcxx/libcxx` or `libs/libxx/libcxxabi/libcxxabi` keeps
     using them; run `make distclean` or remove these directories once.
     This is the same as for earlier libc++ upgrades.
   * Compilers: GCC 12, 13 and 14 are tested here. GCC before 12 gets the
     "Libc++ only supports GCC 12 and later" warning; no board in CI uses
     libc++ with such a compiler.
   * `struct tls_info_s` and `struct task_info_s` grow by two pointers when
     `CONFIG_CXX_EXCEPTION` or `CONFIG_LIBCXX` is set.
   * New: `std::thread` stack size, `CONFIG_CXX_MINI_LOCALIZATION`
     implementation, C++17 builds of the library.
   * No change for configurations without libc++.
   
   ## Testing
   
   Host: Ubuntu 22.04 x86_64. Toolchains as in CI: host GCC 12.3 (sim),
   Arm GNU 13.2.Rel1, xPack RISC-V GCC 14.2.0-3, Espressif Xtensa 14.2.0.
   Base: master 562db43781f, nuttx-apps ab105e659.
   
   Every CI entry that enables libc++ or libc++abi, built from a clean
   tree with the tarballs downloaded and patched by the build, Make builds
   with `EXTRAFLAGS="-Wno-cpp -Werror"`:
   
   | dat | Configuration | Build | Result |
   |---|---|---|---|
   | sim-01 | sim:citest | Make | OK |
   | sim-02 | sim:libcxxtest | Make | OK |
   | sim-02 | sim:matter | CMake | OK |
   | sim-03 | sim:tflm | CMake | OK |
   | arm-imx | sabre-6quad:libcxx, imxrt1050/1060/1064/1170-evk:libcxxtest, 
verdin-mx8mp:nsh | Make | OK |
   | arm-other | qemu-armv7a:full | CMake | OK |
   | arm-stm32f4-2 | stm32f4discovery:testlibcxx | Make | OK |
   | risc-v-02 | esp32c3-legacy-devkit:cxx | Make | OK |
   | risc-v-04 | icicle:knsh | Make | OK |
   | risc-v-05 | rv-virt:citest | Make | OK |
   | risc-v-06 | rv-virt:libcxx, rv-virt:libcxx64 | Make | OK |
   | xtensa-01/02/03 | esp32-devkitc:cxx, esp32s2-saola-1:cxx, 
esp32s3-devkit:cxx | Make | OK |
   
   Each of the first five commits alone on master (17.0.6), and the five
   together: sim:libcxxtest, sabre-6quad:libcxx, qemu-armv7a:full,
   rv-virt:libcxx, rv-virt:libcxx64, esp32-devkitc:cxx build.
   
   Runtime:
   
   * NTFC (ntfc 0.0.3, nuttx-ntfc-testing release-0.0.2), as in CI:
   
     | Configuration | master | this PR |
     |---|---|---|
     | sim:citest | 1217 passed, 298 skipped | 1217 passed, 298 skipped |
     | rv-virt:citest (QEMU) | 1080 passed, 292 skipped | 1080 passed, 292 
skipped |
   
   * sim:libcxxtest, `cxxtest` run twice (two task groups) and `helloxx`:
     iostream, vector, map, filesystem, RTTI and exceptions pass, also with
     `CONFIG_CXX_STANDARD="gnu++17"` and with
     `CONFIG_CXX_MINI_LOCALIZATION`. `CONFIG_CXX_NO_LOCALIZATION` builds.
   * rv-virt:libcxx on QEMU: `cxxtest` passes.
   
   Real hardware: these changes have run for months in Xiaomi Vela products,
   on Arm and other architectures, built with GCC 13, GCC 15 and clang.
   The testing for this PR itself was done on sim and QEMU as listed above.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to