Skip to content

[libc++] Provide flag for RUNTIMES_USE_LIBC=llvm-libc#174967

Merged
vhscampos merged 1 commit intollvm:mainfrom
voltur01:add_libcxx_llvmlibc_flag
Jan 15, 2026
Merged

[libc++] Provide flag for RUNTIMES_USE_LIBC=llvm-libc#174967
vhscampos merged 1 commit intollvm:mainfrom
voltur01:add_libcxx_llvmlibc_flag

Conversation

@voltur01
Copy link
Contributor

@voltur01 voltur01 commented Jan 8, 2026

There was no flag added for llvm-libc when picolibc and newlib were provided in #147956 - the missing flag breaks libc++ iostream support now because this check

_LIBCPP_HAS_MUSL_LIBC || defined(__OpenBSD__) || defined(__LLVM_LIBC__)
fails unless an LLVM libc header is included.

There was no flag added for llvm-libc when picolibc and newlib were provided in llvm#147956 - the missing flag breaks libc++ iostream support now because this check https://github.com/llvm/llvm-project/blob/9a8421fa6191d2e1047e3dc8c72a22fa810f9aee/libcxx/include/__config#L719 fails unless an LLVM libc header is included.
@voltur01 voltur01 requested a review from a team as a code owner January 8, 2026 12:43
@llvmbot llvmbot added the libc++ libc++ C++ Standard Library. Not GNU libstdc++. Not libc++abi. label Jan 8, 2026
@llvmbot
Copy link
Member

llvmbot commented Jan 8, 2026

@llvm/pr-subscribers-libcxx

Author: Volodymyr Turanskyy (voltur01)

Changes

There was no flag added for llvm-libc when picolibc and newlib were provided in #147956 - the missing flag breaks libc++ iostream support now because this check

_LIBCPP_HAS_MUSL_LIBC || defined(__OpenBSD__) || defined(__LLVM_LIBC__)
fails unless an LLVM libc header is included.


Full diff: https://github.com/llvm/llvm-project/pull/174967.diff

7 Files Affected:

  • (modified) libcxx/CMakeLists.txt (+2)
  • (modified) libcxx/include/__config (+1-1)
  • (modified) libcxx/include/__config_site.in (+1)
  • (modified) libcxx/include/__random/binomial_distribution.h (+1-1)
  • (modified) libcxx/src/chrono.cpp (+1-1)
  • (modified) libcxx/src/filesystem/filesystem_clock.cpp (+1-1)
  • (modified) libcxx/src/include/config_elast.h (+1-1)
diff --git a/libcxx/CMakeLists.txt b/libcxx/CMakeLists.txt
index 8b4cd2636fd4d..9f75f65d54af2 100644
--- a/libcxx/CMakeLists.txt
+++ b/libcxx/CMakeLists.txt
@@ -773,6 +773,8 @@ if (RUNTIMES_USE_LIBC STREQUAL "picolibc")
   config_define(1 _LIBCPP_LIBC_NEWLIB)
 elseif (RUNTIMES_USE_LIBC STREQUAL "newlib")
   config_define(1 _LIBCPP_LIBC_NEWLIB)
+elseif (RUNTIMES_USE_LIBC STREQUAL "llvm-libc")
+  config_define(1 _LIBCPP_LIBC_LLVM_LIBC)
 endif()
 
 # TODO: Remove in LLVM 21. We're leaving an error to make this fail explicitly.
diff --git a/libcxx/include/__config b/libcxx/include/__config
index b4db39472ce31..2cadce967d689 100644
--- a/libcxx/include/__config
+++ b/libcxx/include/__config
@@ -716,7 +716,7 @@ typedef __char32_t char32_t;
 #  endif
 
 #  if defined(__BIONIC__) || defined(__NuttX__) || defined(__Fuchsia__) || defined(__wasi__) ||                        \
-      _LIBCPP_HAS_MUSL_LIBC || defined(__OpenBSD__) || defined(__LLVM_LIBC__)
+      _LIBCPP_HAS_MUSL_LIBC || defined(__OpenBSD__) || _LIBCPP_LIBC_LLVM_LIBC
 #    define _LIBCPP_PROVIDES_DEFAULT_RUNE_TABLE
 #  endif
 
diff --git a/libcxx/include/__config_site.in b/libcxx/include/__config_site.in
index b09ca807ee812..a1cc1208aeff3 100644
--- a/libcxx/include/__config_site.in
+++ b/libcxx/include/__config_site.in
@@ -45,6 +45,7 @@
 // C libraries
 #cmakedefine01 _LIBCPP_LIBC_PICOLIBC
 #cmakedefine01 _LIBCPP_LIBC_NEWLIB
+#cmakedefine01 _LIBCPP_LIBC_LLVM_LIBC
 
 // __USE_MINGW_ANSI_STDIO gets redefined on MinGW
 #ifdef __clang__
diff --git a/libcxx/include/__random/binomial_distribution.h b/libcxx/include/__random/binomial_distribution.h
index 0712e4ef4a4f6..6d07ff3c7df04 100644
--- a/libcxx/include/__random/binomial_distribution.h
+++ b/libcxx/include/__random/binomial_distribution.h
@@ -98,7 +98,7 @@ class binomial_distribution {
 };
 
 // Some libc declares the math functions to be `noexcept`.
-#if _LIBCPP_GLIBC_PREREQ(2, 8) || defined(__LLVM_LIBC__)
+#if _LIBCPP_GLIBC_PREREQ(2, 8) || _LIBCPP_LIBC_LLVM_LIBC
 #  define _LIBCPP_LGAMMA_R_NOEXCEPT _NOEXCEPT
 #else
 #  define _LIBCPP_LGAMMA_R_NOEXCEPT
diff --git a/libcxx/src/chrono.cpp b/libcxx/src/chrono.cpp
index 20387ea76124b..a27efc5a42b5d 100644
--- a/libcxx/src/chrono.cpp
+++ b/libcxx/src/chrono.cpp
@@ -31,7 +31,7 @@
 #  include <sys/time.h> // for gettimeofday and timeval
 #endif
 
-#if defined(__LLVM_LIBC__)
+#if _LIBCPP_LIBC_LLVM_LIBC
 #  define _LIBCPP_HAS_TIMESPEC_GET
 #endif
 
diff --git a/libcxx/src/filesystem/filesystem_clock.cpp b/libcxx/src/filesystem/filesystem_clock.cpp
index 49f65efb5a53a..865a1018871f2 100644
--- a/libcxx/src/filesystem/filesystem_clock.cpp
+++ b/libcxx/src/filesystem/filesystem_clock.cpp
@@ -32,7 +32,7 @@
 #  include <sys/time.h> // for gettimeofday and timeval
 #endif
 
-#if defined(__LLVM_LIBC__)
+#if _LIBCPP_LIBC_LLVM_LIBC
 #  define _LIBCPP_HAS_TIMESPEC_GET
 #endif
 
diff --git a/libcxx/src/include/config_elast.h b/libcxx/src/include/config_elast.h
index be665a97bf91b..daec2429de8eb 100644
--- a/libcxx/src/include/config_elast.h
+++ b/libcxx/src/include/config_elast.h
@@ -21,7 +21,7 @@
 // where strerror/strerror_r can't handle out-of-range errno values.
 #if defined(ELAST)
 #  define _LIBCPP_ELAST ELAST
-#elif defined(__LLVM_LIBC__)
+#elif _LIBCPP_LIBC_LLVM_LIBC
 // No _LIBCPP_ELAST needed for LLVM libc
 #elif _LIBCPP_LIBC_NEWLIB
 #  define _LIBCPP_ELAST __ELASTERROR

@voltur01
Copy link
Contributor Author

voltur01 commented Jan 8, 2026

I made this change consistent with other C library flags (picolibc and newlib), however I can imagine that the defined(__LLVM_LIBC__) checks did work because of some implicit definition of __LLVM_LIBC__, for example, via libc header files.

@petrhosek do you have more context in regards to existing checks for libc in libc++?

Alternative would be to define __LLVM_LIBC__ in __config_site to keep existing checks, however this does not look good long term.

Thanks!

Copy link
Contributor

@saturn691 saturn691 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, but I think someone from llvm/reviewers-libcxx should also have a look

Copy link
Contributor

@philnik777 philnik777 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM % nit.

Comment on lines +35 to 37
#if _LIBCPP_LIBC_LLVM_LIBC
# define _LIBCPP_HAS_TIMESPEC_GET
#endif
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
#if _LIBCPP_LIBC_LLVM_LIBC
# define _LIBCPP_HAS_TIMESPEC_GET
#endif
#define _LIBCPP_HAS_TIMESPEC_GET _LIBCPP_LIBC_LLVM_LIBC

Same below.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for the review and suggestion!

Just to confirm, _LIBCPP_LIBC_LLVM_LIBC will be always defined and set to either 0 or 1 depending on the C library in use. So current logic will define the other flag _LIBCPP_HAS_TIMESPEC_GET only if _LIBCPP_LIBC_LLVM_LIBC == 1.

However, in the suggested simplified definition of _LIBCPP_HAS_TIMESPEC_GET it will be always defined even if _LIBCPP_LIBC_LLVM_LIBC == 0 - taking into account that below in the file

#elif defined(_LIBCPP_HAS_TIMESPEC_GET)
the check is only whether _LIBCPP_HAS_TIMESPEC_GET is defined or not (regardless of its value) setting it to 0 when _LIBCPP_LIBC_LLVM_LIBC == 0 will change the behavior of the code. So the simplified definition is not equivalent to the current behavior, which, I believe, is undesired.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, I didn't realize that. It should always be defined and checked for #if _LIBCPP_HAS_TIMESPEC_GET instead, but that should be fixed in a separate PR. Feel free to ignore.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for the confirmation!

@vhscampos
Copy link
Member

Merging on behalf of @voltur01 as he doesn't have merging privileges.

@vhscampos vhscampos merged commit dc5e1d0 into llvm:main Jan 15, 2026
137 of 138 checks passed
voltur01 added a commit to voltur01/arm-toolchain that referenced this pull request Jan 15, 2026
After llvm/llvm-project#174967 RUNTIMES_USE_LIBC=llvm-libc option provides all necessary defines for libcxx to work with LLVM libc.
voltur01 added a commit to arm/arm-toolchain that referenced this pull request Jan 15, 2026
After llvm/llvm-project#174967
RUNTIMES_USE_LIBC=llvm-libc option provides all necessary defines for
libcxx to work with LLVM libc.
@llvm-ci
Copy link

llvm-ci commented Jan 16, 2026

LLVM Buildbot has detected a new failure on builder sanitizer-ppc64le-linux running on ppc64le-sanitizer while building libcxx at step 2 "annotate".

Full details are available at: https://lab.llvm.org/buildbot/#/builders/72/builds/16967

Here is the relevant piece of the build log for the reference
Step 2 (annotate) failure: 'python ../sanitizer_buildbot/sanitizers/zorg/buildbot/builders/sanitizers/buildbot_selector.py' (failure) (timed out)
...
[105/114] Generating libmsan_loadable.powerpc64le-with-call.so
[106/114] Generating MSAN_INST_TEST_OBJECTS.msan_test_main.cpp.powerpc64le-with-call.o
[107/114] Generating MSAN_INST_TEST_OBJECTS.msan_test_main.cpp.powerpc64le.o
[108/114] Generating MSAN_INST_GTEST.gtest-all.cc.powerpc64le-with-call.o
[109/114] Generating MSAN_INST_GTEST.gtest-all.cc.powerpc64le.o
[110/114] Generating MSAN_INST_TEST_OBJECTS.msan_test.cpp.powerpc64le-with-call.o
[111/114] Generating Msan-powerpc64le-with-call-Test
[112/114] Generating MSAN_INST_TEST_OBJECTS.msan_test.cpp.powerpc64le.o
[113/114] Generating Msan-powerpc64le-Test
[113/114] Running compiler_rt regression tests
command timed out: 1800 seconds without output running [b'python', b'../sanitizer_buildbot/sanitizers/zorg/buildbot/builders/sanitizers/buildbot_selector.py'], attempting to kill
process killed by signal 9
program finished with exit code -1
elapsedTime=8057.509013
Step 14 (test standalone compiler-rt) failure: test standalone compiler-rt (failure)
...
-- Installing: /home/buildbots/llvm-external-buildbots/workers/ppc64le-sanitizer/sanitizer-ppc64le/build/compiler_rt_build/lib/msan/libcxx_msan_powerpc64le/share/libc++/v1/std/typeinfo.inc
-- Installing: /home/buildbots/llvm-external-buildbots/workers/ppc64le-sanitizer/sanitizer-ppc64le/build/compiler_rt_build/lib/msan/libcxx_msan_powerpc64le/share/libc++/v1/std/unordered_map.inc
-- Installing: /home/buildbots/llvm-external-buildbots/workers/ppc64le-sanitizer/sanitizer-ppc64le/build/compiler_rt_build/lib/msan/libcxx_msan_powerpc64le/share/libc++/v1/std/unordered_set.inc
-- Installing: /home/buildbots/llvm-external-buildbots/workers/ppc64le-sanitizer/sanitizer-ppc64le/build/compiler_rt_build/lib/msan/libcxx_msan_powerpc64le/share/libc++/v1/std/utility.inc
-- Installing: /home/buildbots/llvm-external-buildbots/workers/ppc64le-sanitizer/sanitizer-ppc64le/build/compiler_rt_build/lib/msan/libcxx_msan_powerpc64le/share/libc++/v1/std/valarray.inc
-- Installing: /home/buildbots/llvm-external-buildbots/workers/ppc64le-sanitizer/sanitizer-ppc64le/build/compiler_rt_build/lib/msan/libcxx_msan_powerpc64le/share/libc++/v1/std/variant.inc
-- Installing: /home/buildbots/llvm-external-buildbots/workers/ppc64le-sanitizer/sanitizer-ppc64le/build/compiler_rt_build/lib/msan/libcxx_msan_powerpc64le/share/libc++/v1/std/vector.inc
-- Installing: /home/buildbots/llvm-external-buildbots/workers/ppc64le-sanitizer/sanitizer-ppc64le/build/compiler_rt_build/lib/msan/libcxx_msan_powerpc64le/share/libc++/v1/std/version.inc
-- Installing: /home/buildbots/llvm-external-buildbots/workers/ppc64le-sanitizer/sanitizer-ppc64le/build/compiler_rt_build/lib/msan/libcxx_msan_powerpc64le/share/libc++/v1/std.compat/cassert.inc
-- Installing: /home/buildbots/llvm-external-buildbots/workers/ppc64le-sanitizer/sanitizer-ppc64le/build/compiler_rt_build/lib/msan/libcxx_msan_powerpc64le/share/libc++/v1/std.compat/cctype.inc
-- Installing: /home/buildbots/llvm-external-buildbots/workers/ppc64le-sanitizer/sanitizer-ppc64le/build/compiler_rt_build/lib/msan/libcxx_msan_powerpc64le/share/libc++/v1/std.compat/cerrno.inc
-- Installing: /home/buildbots/llvm-external-buildbots/workers/ppc64le-sanitizer/sanitizer-ppc64le/build/compiler_rt_build/lib/msan/libcxx_msan_powerpc64le/share/libc++/v1/std.compat/cfenv.inc
-- Installing: /home/buildbots/llvm-external-buildbots/workers/ppc64le-sanitizer/sanitizer-ppc64le/build/compiler_rt_build/lib/msan/libcxx_msan_powerpc64le/share/libc++/v1/std.compat/cfloat.inc
-- Installing: /home/buildbots/llvm-external-buildbots/workers/ppc64le-sanitizer/sanitizer-ppc64le/build/compiler_rt_build/lib/msan/libcxx_msan_powerpc64le/share/libc++/v1/std.compat/cinttypes.inc
-- Installing: /home/buildbots/llvm-external-buildbots/workers/ppc64le-sanitizer/sanitizer-ppc64le/build/compiler_rt_build/lib/msan/libcxx_msan_powerpc64le/share/libc++/v1/std.compat/climits.inc
-- Installing: /home/buildbots/llvm-external-buildbots/workers/ppc64le-sanitizer/sanitizer-ppc64le/build/compiler_rt_build/lib/msan/libcxx_msan_powerpc64le/share/libc++/v1/std.compat/clocale.inc
-- Installing: /home/buildbots/llvm-external-buildbots/workers/ppc64le-sanitizer/sanitizer-ppc64le/build/compiler_rt_build/lib/msan/libcxx_msan_powerpc64le/share/libc++/v1/std.compat/cmath.inc
-- Installing: /home/buildbots/llvm-external-buildbots/workers/ppc64le-sanitizer/sanitizer-ppc64le/build/compiler_rt_build/lib/msan/libcxx_msan_powerpc64le/share/libc++/v1/std.compat/csetjmp.inc
-- Installing: /home/buildbots/llvm-external-buildbots/workers/ppc64le-sanitizer/sanitizer-ppc64le/build/compiler_rt_build/lib/msan/libcxx_msan_powerpc64le/share/libc++/v1/std.compat/csignal.inc
-- Installing: /home/buildbots/llvm-external-buildbots/workers/ppc64le-sanitizer/sanitizer-ppc64le/build/compiler_rt_build/lib/msan/libcxx_msan_powerpc64le/share/libc++/v1/std.compat/cstdarg.inc
-- Installing: /home/buildbots/llvm-external-buildbots/workers/ppc64le-sanitizer/sanitizer-ppc64le/build/compiler_rt_build/lib/msan/libcxx_msan_powerpc64le/share/libc++/v1/std.compat/cstddef.inc
-- Installing: /home/buildbots/llvm-external-buildbots/workers/ppc64le-sanitizer/sanitizer-ppc64le/build/compiler_rt_build/lib/msan/libcxx_msan_powerpc64le/share/libc++/v1/std.compat/cstdint.inc
-- Installing: /home/buildbots/llvm-external-buildbots/workers/ppc64le-sanitizer/sanitizer-ppc64le/build/compiler_rt_build/lib/msan/libcxx_msan_powerpc64le/share/libc++/v1/std.compat/cstdio.inc
-- Installing: /home/buildbots/llvm-external-buildbots/workers/ppc64le-sanitizer/sanitizer-ppc64le/build/compiler_rt_build/lib/msan/libcxx_msan_powerpc64le/share/libc++/v1/std.compat/cstdlib.inc
-- Installing: /home/buildbots/llvm-external-buildbots/workers/ppc64le-sanitizer/sanitizer-ppc64le/build/compiler_rt_build/lib/msan/libcxx_msan_powerpc64le/share/libc++/v1/std.compat/cstring.inc
-- Installing: /home/buildbots/llvm-external-buildbots/workers/ppc64le-sanitizer/sanitizer-ppc64le/build/compiler_rt_build/lib/msan/libcxx_msan_powerpc64le/share/libc++/v1/std.compat/ctime.inc
-- Installing: /home/buildbots/llvm-external-buildbots/workers/ppc64le-sanitizer/sanitizer-ppc64le/build/compiler_rt_build/lib/msan/libcxx_msan_powerpc64le/share/libc++/v1/std.compat/cuchar.inc
-- Installing: /home/buildbots/llvm-external-buildbots/workers/ppc64le-sanitizer/sanitizer-ppc64le/build/compiler_rt_build/lib/msan/libcxx_msan_powerpc64le/share/libc++/v1/std.compat/cwchar.inc
-- Installing: /home/buildbots/llvm-external-buildbots/workers/ppc64le-sanitizer/sanitizer-ppc64le/build/compiler_rt_build/lib/msan/libcxx_msan_powerpc64le/share/libc++/v1/std.compat/cwctype.inc
-- Installing: /home/buildbots/llvm-external-buildbots/workers/ppc64le-sanitizer/sanitizer-ppc64le/build/compiler_rt_build/lib/msan/libcxx_msan_powerpc64le/share/libc++/v1/std.cppm
-- Installing: /home/buildbots/llvm-external-buildbots/workers/ppc64le-sanitizer/sanitizer-ppc64le/build/compiler_rt_build/lib/msan/libcxx_msan_powerpc64le/share/libc++/v1/std.compat.cppm
-- Installing: /home/buildbots/llvm-external-buildbots/workers/ppc64le-sanitizer/sanitizer-ppc64le/build/compiler_rt_build/lib/msan/libcxx_msan_powerpc64le/lib/libc++.modules.json
[102/114] Generating MSAN_INST_LOADABLE_OBJECTS.msan_loadable.cpp.powerpc64le.o
[103/114] Generating MSAN_INST_LOADABLE_OBJECTS.msan_loadable.cpp.powerpc64le-with-call.o
[104/114] Generating libmsan_loadable.powerpc64le.so
[105/114] Generating libmsan_loadable.powerpc64le-with-call.so
[106/114] Generating MSAN_INST_TEST_OBJECTS.msan_test_main.cpp.powerpc64le-with-call.o
[107/114] Generating MSAN_INST_TEST_OBJECTS.msan_test_main.cpp.powerpc64le.o
[108/114] Generating MSAN_INST_GTEST.gtest-all.cc.powerpc64le-with-call.o
[109/114] Generating MSAN_INST_GTEST.gtest-all.cc.powerpc64le.o
[110/114] Generating MSAN_INST_TEST_OBJECTS.msan_test.cpp.powerpc64le-with-call.o
[111/114] Generating Msan-powerpc64le-with-call-Test
[112/114] Generating MSAN_INST_TEST_OBJECTS.msan_test.cpp.powerpc64le.o
[113/114] Generating Msan-powerpc64le-Test
[113/114] Running compiler_rt regression tests

command timed out: 1800 seconds without output running [b'python', b'../sanitizer_buildbot/sanitizers/zorg/buildbot/builders/sanitizers/buildbot_selector.py'], attempting to kill
process killed by signal 9
program finished with exit code -1
elapsedTime=8057.509013

Priyanshu3820 pushed a commit to Priyanshu3820/llvm-project that referenced this pull request Jan 18, 2026
There was no flag added for llvm-libc when picolibc and newlib were
provided in llvm#147956 - the
missing flag breaks libc++ iostream support now because this check
https://github.com/llvm/llvm-project/blob/9a8421fa6191d2e1047e3dc8c72a22fa810f9aee/libcxx/include/__config#L719
fails unless an LLVM libc header is included.
voltur01 added a commit to voltur01/arm-toolchain that referenced this pull request Jan 21, 2026
After llvm/llvm-project#174967 RUNTIMES_USE_LIBC=llvm-libc option provides all necessary defines for libcxx to work with LLVM libc.
voltur01 added a commit to voltur01/arm-toolchain that referenced this pull request Jan 21, 2026
After llvm/llvm-project#174967
RUNTIMES_USE_LIBC=llvm-libc option provides all necessary defines for
libcxx to work with LLVM libc.

(cherry picked from commit 227f790)
BStott6 pushed a commit to BStott6/llvm-project that referenced this pull request Jan 22, 2026
There was no flag added for llvm-libc when picolibc and newlib were
provided in llvm#147956 - the
missing flag breaks libc++ iostream support now because this check
https://github.com/llvm/llvm-project/blob/9a8421fa6191d2e1047e3dc8c72a22fa810f9aee/libcxx/include/__config#L719
fails unless an LLVM libc header is included.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

libc++ libc++ C++ Standard Library. Not GNU libstdc++. Not libc++abi.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants