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

via libc-commits libc-commits at lists.llvm.org
Wed Jul 10 08:02:57 PDT 2024


================
@@ -9,44 +9,100 @@
 #include "libc_errno.h"
 #include "src/__support/CPP/atomic.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.
+#define LIBC_ERRNO_MODE_NONE 0x01
+#define LIBC_ERRNO_MODE_INTERNAL 0x02
+#define LIBC_ERRNO_MODE_EXTERNAL 0x04
+#define LIBC_ERRNO_MODE_THREAD_LOCAL 0x08
+#define LIBC_ERRNO_MODE_GLOBAL 0x10
+#define LIBC_ERRNO_MODE_LOCATION 0x20
+
+#ifndef LIBC_ERRNO_MODE
+#error LIBC_ERRNO_MODE is not defined
----------------
lntue wrote:

This is a new flag, so I think we should provide the default value for `LIBC_ERRNO_MODE` which matches the current behavior instead of errors to not break downstream users.
```
#ifndef LIBC_ERRNO_MODE
#ifndef LIBC_COPT_PUBLIC_PACKAGING
// This mode is for unit testing. We just use our internal errno.
#define LIBC_ERRNO_MODE LIBC_ERRNO_MODE_INTERNAL
#elif defined(LIBC_FULL_BUILD)
// In full build mode, we provide the errno storage ourselves.
#define LIBC_ERRNO_MODE LIBC_ERRNO_MODE_THREAD_LOCAL
#else
#define LIBC_ERRNO_MODE LIBC_ERRNO_MODE_EXTERNAL
#endif
#endif // LIBC_ERRNO_MODE
```
Then you can remove the default setting in the `CMakeLists.txt`.

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


More information about the libc-commits mailing list