Skip to content

Commit 321b040

Browse files
committed
[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 #167962.
1 parent 76d614b commit 321b040

File tree

3 files changed

+4
-1
lines changed

3 files changed

+4
-1
lines changed

libcxx/CMakeLists.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -298,6 +298,7 @@ endif()
298298

299299
# Feature options -------------------------------------------------------------
300300
option(LIBCXX_HAS_MUSL_LIBC "Build libc++ with support for the Musl C library" OFF)
301+
option(LIBCXX_HAS_NEWLIB_LIBC "Build libc++ with support for the Newlib C library" OFF)
301302
option(LIBCXX_HAS_PTHREAD_API "Ignore auto-detection and force use of pthread API" OFF)
302303
option(LIBCXX_HAS_WIN32_THREAD_API "Ignore auto-detection and force use of win32 thread API" OFF)
303304
option(LIBCXX_HAS_EXTERNAL_THREAD_API
@@ -754,6 +755,7 @@ config_define(${LIBCXX_HAS_PTHREAD_API} _LIBCPP_HAS_THREAD_API_PTHREAD)
754755
config_define(${LIBCXX_HAS_EXTERNAL_THREAD_API} _LIBCPP_HAS_THREAD_API_EXTERNAL)
755756
config_define(${LIBCXX_HAS_WIN32_THREAD_API} _LIBCPP_HAS_THREAD_API_WIN32)
756757
config_define(${LIBCXX_HAS_MUSL_LIBC} _LIBCPP_HAS_MUSL_LIBC)
758+
config_define(${LIBCXX_HAS_NEWLIB_LIBC} _LIBCPP_HAS_NEWLIB_LIBC)
757759
config_define_if(LIBCXX_NO_VCRUNTIME _LIBCPP_NO_VCRUNTIME)
758760
config_define(${LIBCXX_ENABLE_FILESYSTEM} _LIBCPP_HAS_FILESYSTEM)
759761
config_define(${LIBCXX_ENABLE_RANDOM_DEVICE} _LIBCPP_HAS_RANDOM_DEVICE)

libcxx/include/__config_site.in

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
#cmakedefine01 _LIBCPP_HAS_MONOTONIC_CLOCK
1818
#cmakedefine01 _LIBCPP_HAS_TERMINAL
1919
#cmakedefine01 _LIBCPP_HAS_MUSL_LIBC
20+
#cmakedefine01 _LIBCPP_HAS_NEWLIB_LIBC
2021
#cmakedefine01 _LIBCPP_HAS_THREAD_API_PTHREAD
2122
#cmakedefine01 _LIBCPP_HAS_THREAD_API_EXTERNAL
2223
#cmakedefine01 _LIBCPP_HAS_THREAD_API_WIN32

libcxx/include/__fwd/ios.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ using wios = basic_ios<wchar_t>;
3131
template <class _CharT, class _Traits>
3232
class _LIBCPP_PREFERRED_NAME(ios) _LIBCPP_IF_WIDE_CHARACTERS(_LIBCPP_PREFERRED_NAME(wios)) basic_ios;
3333

34-
#if defined(_NEWLIB_VERSION)
34+
#if _LIBCPP_HAS_NEWLIB_LIBC
3535
// On newlib, off_t is 'long int'
3636
using streamoff = long int; // for char_traits in <string>
3737
#else

0 commit comments

Comments
 (0)