[libcxx-commits] [libcxx] libcxx: fixups for __BIONIC__ (PR #219591)
Nick Desaulniers via libcxx-commits
libcxx-commits at lists.llvm.org
Mon Aug 31 12:58:04 PDT 2026
https://github.com/nickdesaulniers updated https://github.com/llvm/llvm-project/pull/219591
>From 22844ed811fcbbaa5e3b1b0bb58dffba4fd80ba2 Mon Sep 17 00:00:00 2001
From: Nick Desaulniers <ndesaulniers at google.com>
Date: Fri, 28 Aug 2026 15:23:00 -0700
Subject: [PATCH 1/2] libcxx: fixups for __BIONIC__
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
---
libcxx/include/__config | 5 +++--
libcxx/include/__cxx03/__config | 5 +++--
libcxx/src/filesystem/operations.cpp | 7 ++++---
3 files changed, 10 insertions(+), 7 deletions(-)
diff --git a/libcxx/include/__config b/libcxx/include/__config
index 31c573ba5dca3..2a5aa31335390 100644
--- a/libcxx/include/__config
+++ b/libcxx/include/__config
@@ -82,8 +82,9 @@
// 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__) && __ANDROID_API__ >= 34)
# 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 9845b7aa8742e..3d6601e7f4f60 100644
--- a/libcxx/include/__cxx03/__config
+++ b/libcxx/include/__cxx03/__config
@@ -262,8 +262,9 @@ _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__) && __ANDROID_API__ >= 34)
# 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;
>From 22ed439fda4a047fdbb634ecdf625e7f9e0a359f Mon Sep 17 00:00:00 2001
From: Nick Desaulniers <ndesaulniers at google.com>
Date: Mon, 31 Aug 2026 12:57:48 -0700
Subject: [PATCH 2/2] reformat
---
libcxx/include/__config | 5 ++---
libcxx/include/__cxx03/__config | 5 ++---
2 files changed, 4 insertions(+), 6 deletions(-)
diff --git a/libcxx/include/__config b/libcxx/include/__config
index 2a5aa31335390..44c9c5cbf51a3 100644
--- a/libcxx/include/__config
+++ b/libcxx/include/__config
@@ -82,9 +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__) || \
- (defined(__BIONIC__) && __ANDROID_API__ >= 34)
+# if defined(__APPLE__) || defined(__FreeBSD__) || defined(__NetBSD__) || defined(__OpenBSD__) || \
+ defined(__DragonFly__) || (defined(__BIONIC__) && __ANDROID_API__ >= 34)
# 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 3d6601e7f4f60..0e8f267d03858 100644
--- a/libcxx/include/__cxx03/__config
+++ b/libcxx/include/__cxx03/__config
@@ -262,9 +262,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__) || \
- (defined(__BIONIC__) && __ANDROID_API__ >= 34)
+# if defined(__APPLE__) || defined(__FreeBSD__) || defined(__NetBSD__) || defined(__OpenBSD__) || \
+ defined(__DragonFly__) || (defined(__BIONIC__) && __ANDROID_API__ >= 34)
# define _LIBCPP_USING_ARC4_RANDOM
# elif defined(__wasi__) || defined(__EMSCRIPTEN__)
# define _LIBCPP_USING_GETENTROPY
More information about the libcxx-commits
mailing list