From 321b040b04174354ef1a9b19e38db743672b8be0 Mon Sep 17 00:00:00 2001 From: Chenguang Wang Date: Fri, 21 Nov 2025 05:47:14 +0800 Subject: [PATCH 1/2] [libc++] Fix Newlib check in __fwd/ios.h _NEWLIB_VERSION is only visible when any libc header is included. I ran into a weird case where during libc++ compilation, __fwd/ios.h did not see _NEWLIB_VERSION and defined off_t as `long long`, but in the actual user program, _NEWLIB_VERSION was visible, so the program tried to use a `long int` instead of `long long` specialization of a template function that is provided by libc++.a, and caused linking failure. The new cmake option was also used in another PR that I created; see https://github.com/llvm/llvm-project/pull/167962. --- libcxx/CMakeLists.txt | 2 ++ libcxx/include/__config_site.in | 1 + libcxx/include/__fwd/ios.h | 2 +- 3 files changed, 4 insertions(+), 1 deletion(-) diff --git a/libcxx/CMakeLists.txt b/libcxx/CMakeLists.txt index 1423b6713fd35..fabfb126d06f3 100644 --- a/libcxx/CMakeLists.txt +++ b/libcxx/CMakeLists.txt @@ -298,6 +298,7 @@ endif() # Feature options ------------------------------------------------------------- option(LIBCXX_HAS_MUSL_LIBC "Build libc++ with support for the Musl C library" OFF) +option(LIBCXX_HAS_NEWLIB_LIBC "Build libc++ with support for the Newlib C library" OFF) option(LIBCXX_HAS_PTHREAD_API "Ignore auto-detection and force use of pthread API" OFF) option(LIBCXX_HAS_WIN32_THREAD_API "Ignore auto-detection and force use of win32 thread API" OFF) option(LIBCXX_HAS_EXTERNAL_THREAD_API @@ -754,6 +755,7 @@ config_define(${LIBCXX_HAS_PTHREAD_API} _LIBCPP_HAS_THREAD_API_PTHREAD) config_define(${LIBCXX_HAS_EXTERNAL_THREAD_API} _LIBCPP_HAS_THREAD_API_EXTERNAL) config_define(${LIBCXX_HAS_WIN32_THREAD_API} _LIBCPP_HAS_THREAD_API_WIN32) config_define(${LIBCXX_HAS_MUSL_LIBC} _LIBCPP_HAS_MUSL_LIBC) +config_define(${LIBCXX_HAS_NEWLIB_LIBC} _LIBCPP_HAS_NEWLIB_LIBC) config_define_if(LIBCXX_NO_VCRUNTIME _LIBCPP_NO_VCRUNTIME) config_define(${LIBCXX_ENABLE_FILESYSTEM} _LIBCPP_HAS_FILESYSTEM) config_define(${LIBCXX_ENABLE_RANDOM_DEVICE} _LIBCPP_HAS_RANDOM_DEVICE) diff --git a/libcxx/include/__config_site.in b/libcxx/include/__config_site.in index 6dcca1849a96c..6521cf7c51c96 100644 --- a/libcxx/include/__config_site.in +++ b/libcxx/include/__config_site.in @@ -17,6 +17,7 @@ #cmakedefine01 _LIBCPP_HAS_MONOTONIC_CLOCK #cmakedefine01 _LIBCPP_HAS_TERMINAL #cmakedefine01 _LIBCPP_HAS_MUSL_LIBC +#cmakedefine01 _LIBCPP_HAS_NEWLIB_LIBC #cmakedefine01 _LIBCPP_HAS_THREAD_API_PTHREAD #cmakedefine01 _LIBCPP_HAS_THREAD_API_EXTERNAL #cmakedefine01 _LIBCPP_HAS_THREAD_API_WIN32 diff --git a/libcxx/include/__fwd/ios.h b/libcxx/include/__fwd/ios.h index 831624f4b1c57..96505e615693c 100644 --- a/libcxx/include/__fwd/ios.h +++ b/libcxx/include/__fwd/ios.h @@ -31,7 +31,7 @@ using wios = basic_ios; template class _LIBCPP_PREFERRED_NAME(ios) _LIBCPP_IF_WIDE_CHARACTERS(_LIBCPP_PREFERRED_NAME(wios)) basic_ios; -#if defined(_NEWLIB_VERSION) +#if _LIBCPP_HAS_NEWLIB_LIBC // On newlib, off_t is 'long int' using streamoff = long int; // for char_traits in #else From ce171015d1a9b128672c7aaa55a70db91e0d64e6 Mon Sep 17 00:00:00 2001 From: Chenguang Wang Date: Sat, 22 Nov 2025 06:35:40 +0800 Subject: [PATCH 2/2] Use LIBCXX_HAS_NEWLIB_LIBC in CI tests. --- libcxx/utils/ci/run-buildbot | 1 + 1 file changed, 1 insertion(+) diff --git a/libcxx/utils/ci/run-buildbot b/libcxx/utils/ci/run-buildbot index 7442361627104..b04e3eed203f1 100755 --- a/libcxx/utils/ci/run-buildbot +++ b/libcxx/utils/ci/run-buildbot @@ -205,6 +205,7 @@ function test-armv7m-picolibc() { -DLIBUNWIND_TEST_CONFIG="armv7m-picolibc-libunwind.cfg.in" \ -DCMAKE_C_FLAGS="${flags}" \ -DCMAKE_CXX_FLAGS="${flags}" \ + -DLIBCXX_HAS_NEWLIB_LIBC=ON \ "${@}" step "Installing compiler-rt"