[libcxx-commits] [libcxx] [libc++] Fix Newlib check in __fwd/ios.h (PR #168952)
via libcxx-commits
libcxx-commits at lists.llvm.org
Thu Nov 20 14:00:34 PST 2025
llvmbot wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-libcxx
Author: Chenguang Wang (wecing)
<details>
<summary>Changes</summary>
_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.
---
Full diff: https://github.com/llvm/llvm-project/pull/168952.diff
3 Files Affected:
- (modified) libcxx/CMakeLists.txt (+2)
- (modified) libcxx/include/__config_site.in (+1)
- (modified) libcxx/include/__fwd/ios.h (+1-1)
``````````diff
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<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)
+#if _LIBCPP_HAS_NEWLIB_LIBC
// On newlib, off_t is 'long int'
using streamoff = long int; // for char_traits in <string>
#else
``````````
</details>
https://github.com/llvm/llvm-project/pull/168952
More information about the libcxx-commits
mailing list