[libc-commits] [libc] [libc] Support configurable errno modes (PR #98287)

Petr Hosek via libc-commits libc-commits at lists.llvm.org
Thu Jul 11 21:15:29 PDT 2024


================
@@ -7,46 +7,81 @@
 //===----------------------------------------------------------------------===//
 
 #include "libc_errno.h"
-#include "src/__support/CPP/atomic.h"
+#include "src/errno/errno.h"
 
-#ifdef LIBC_TARGET_ARCH_IS_GPU
-// LIBC_THREAD_LOCAL on GPU currently does nothing. So essentially this is just
-// a global errno for gpu to use for now.
-extern "C" {
-LIBC_THREAD_LOCAL LIBC_NAMESPACE::cpp::Atomic<int> __llvmlibc_errno;
-}
+#define LIBC_ERRNO_MODE_UNDEFINED 1
+#define LIBC_ERRNO_MODE_THREAD_LOCAL 2
+#define LIBC_ERRNO_MODE_SHARED 3
+#define LIBC_ERRNO_MODE_EXTERNAL 4
+#define LIBC_ERRNO_MODE_SYSTEM 5
+
+#ifndef LIBC_ERRNO_MODE
+#if defined(LIBC_FULL_BUILD) || !defined(LIBC_COPT_PUBLIC_PACKAGING)
+#define LIBC_ERRNO_MODE LIBC_ERRNO_MODE_THREAD_LOCAL
+#else
+#define LIBC_ERRNO_MODE LIBC_ERRNO_MODE_SYSTEM
+#endif
+#endif // LIBC_ERRNO_MODE
+
+#if LIBC_ERRNO_MODE != LIBC_ERRNO_MODE_UNDEFINED &&                            \
----------------
petrhosek wrote:

The current implementation doesn't require it and would fallback to either `LIBC_ERRNO_MODE_THREAD_LOCAL` or `LIBC_ERRNO_MODE_SYSTEM` depending on whether we're doing full build or overlay.

https://github.com/llvm/llvm-project/pull/98287


More information about the libc-commits mailing list