Skip to content

libcxx: fixups for __BIONIC__ - #219591

Merged
nickdesaulniers merged 1 commit into
llvm:mainfrom
nickdesaulniers:libcxx_arc4random
Sep 1, 2026
Merged

nickdesaulniers merged 1 commit into
llvm:mainfrom
nickdesaulniers:libcxx_arc4random

Conversation

@nickdesaulniers
nickdesaulniers requested a review from a team as a code owner August 28, 2026 22:34
@llvmorg-github-actions llvmorg-github-actions Bot added the libc++ libc++ C++ Standard Library. Not GNU libstdc++. Not libc++abi. label Aug 28, 2026
@nickdesaulniers

Copy link
Copy Markdown
Member Author

cc @llvm/android-maintainers

@llvmorg-github-actions

Copy link
Copy Markdown

@llvm/pr-subscribers-libcxx

Author: Nick Desaulniers (nickdesaulniers)

Changes

A few header guards seem to check various libc's, but not Android's libc
(Bionic).

Bionic supports:

  • arc4random
  • copy_file_range
  • getcwd() extension

Link: https://android-review.git.corp.google.com/c/platform/bionic/+/41445
Link: https://android.googlesource.com/platform/bionic/+/refs/heads/main/libc/SYSCALLS.TXT
Link: https://android.googlesource.com/platform/bionic/+/refs/heads/main/libc/upstream-openbsd/lib/libc/crypt/arc4random.c


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

3 Files Affected:

  • (modified) libcxx/include/__config (+2-2)
  • (modified) libcxx/include/__cxx03/__config (+2-2)
  • (modified) libcxx/src/filesystem/operations.cpp (+4-3)
diff --git a/libcxx/include/__config b/libcxx/include/__config
index 31c573ba5dca3..2ac003149f2da 100644
--- a/libcxx/include/__config
+++ b/libcxx/include/__config
@@ -82,8 +82,8 @@
 //      Use rand_s(), for use on Windows.
 //      When this option is used, the token passed to `std::random_device`'s
 //      constructor *must* be "/dev/urandom" -- anything else is an error.
-#  if defined(__APPLE__) || defined(__FreeBSD__) || defined(__NetBSD__) || defined(__OpenBSD__) ||                     \
-      defined(__DragonFly__)
+#  if defined(__APPLE__) || defined(__FreeBSD__) || defined(__NetBSD__) ||  \
+      defined(__OpenBSD__) || defined(__DragonFly__) || defined(__BIONIC__) \
 #    define _LIBCPP_USING_ARC4_RANDOM
 #  elif defined(__wasi__) || defined(__EMSCRIPTEN__)
 #    define _LIBCPP_USING_GETENTROPY
diff --git a/libcxx/include/__cxx03/__config b/libcxx/include/__cxx03/__config
index 6679494a1f936..76b1cd452b2c0 100644
--- a/libcxx/include/__cxx03/__config
+++ b/libcxx/include/__cxx03/__config
@@ -269,8 +269,8 @@ _LIBCPP_HARDENING_MODE_DEBUG
 //      Use rand_s(), for use on Windows.
 //      When this option is used, the token passed to `std::random_device`'s
 //      constructor *must* be "/dev/urandom" -- anything else is an error.
-#  if defined(__APPLE__) || defined(__FreeBSD__) || defined(__NetBSD__) || defined(__OpenBSD__) ||                     \
-      defined(__DragonFly__)
+#  if defined(__APPLE__) || defined(__FreeBSD__) || defined(__NetBSD__) ||  \
+      defined(__OpenBSD__) || defined(__DragonFly__) || defined(__BIONIC__) \
 #    define _LIBCPP_USING_ARC4_RANDOM
 #  elif defined(__wasi__) || defined(__EMSCRIPTEN__)
 #    define _LIBCPP_USING_GETENTROPY
diff --git a/libcxx/src/filesystem/operations.cpp b/libcxx/src/filesystem/operations.cpp
index 3ff62c102d0ad..af12cbd2e24ea 100644
--- a/libcxx/src/filesystem/operations.cpp
+++ b/libcxx/src/filesystem/operations.cpp
@@ -40,8 +40,9 @@
 #include <fcntl.h> /* values for fchmodat */
 #include <time.h>
 
-// since Linux 4.5 and FreeBSD 13, but the Linux libc wrapper is only provided by glibc >= 2.27 and musl
-#if _LIBCPP_GLIBC_PREREQ(2, 27) || _LIBCPP_HAS_MUSL_LIBC || defined(__FreeBSD__)
+// Since Linux 4.5 and FreeBSD 13, but the Linux libc wrapper is only provided
+// by glibc >= 2.27, musl, and Bionic.
+#if _LIBCPP_GLIBC_PREREQ(2, 27) || _LIBCPP_HAS_MUSL_LIBC || defined(__FreeBSD__) || defined(__BIONIC__)
 #  define _LIBCPP_FILESYSTEM_USE_COPY_FILE_RANGE
 #endif
 
@@ -564,7 +565,7 @@ void __create_symlink(path const& from, path const& to, error_code* ec) {
 path __current_path(error_code* ec) {
   ErrorHandler<path> err("current_path", ec);
 
-#if defined(_WIN32) || defined(__GLIBC__) || defined(__APPLE__)
+#if defined(_WIN32) || defined(__GLIBC__) || defined(__APPLE__) || defined(__BIONIC__)
   // Common extension outside of POSIX getcwd() spec, without needing to
   // preallocate a buffer. Also supported by a number of other POSIX libcs.
   int size              = 0;

@github-actions

github-actions Bot commented Aug 28, 2026 •

Copy link
Copy Markdown

✅ With the latest revision this PR passed the C/C++ code formatter.

Comment thread libcxx/src/filesystem/operations.cpp Resolved

@enh-google enh-google left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

(otherwise lgtm)

Comment thread libcxx/include/__cxx03/__config Resolved
Comment thread libcxx/include/__config Resolved
Comment thread libcxx/src/filesystem/operations.cpp Resolved
@nickdesaulniers
nickdesaulniers marked this pull request as ready for review August 31, 2026 20:18

@enh-google enh-google left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

yes, this version matches bionic's reality :-)

@nickdesaulniers
nickdesaulniers merged commit b0829c5 into llvm:main Sep 1, 2026
71 checks passed
@nickdesaulniers
nickdesaulniers deleted the libcxx_arc4random branch September 1, 2026 16:46
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.

3 participants