[libc-commits] [libc] [libc] Use global errno for baremetal (PR #98130)

via libc-commits libc-commits at lists.llvm.org
Tue Jul 9 01:37:27 PDT 2024


llvmbot wrote:


<!--LLVM PR SUMMARY COMMENT-->

@llvm/pr-subscribers-libc

Author: Petr Hosek (petrhosek)

<details>
<summary>Changes</summary>

We want to avoid thread local variables on baremetal since the TLS support may not be universally available in those environments.

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


2 Files Affected:

- (modified) libc/include/errno.h.def (+2-1) 
- (modified) libc/src/errno/libc_errno.cpp (+2-1) 


``````````diff
diff --git a/libc/include/errno.h.def b/libc/include/errno.h.def
index 1f7120e63bfc9..db43f083d49ab 100644
--- a/libc/include/errno.h.def
+++ b/libc/include/errno.h.def
@@ -25,7 +25,8 @@
 #include "llvm-libc-macros/generic-error-number-macros.h"
 #endif
 
-#if defined(__AMDGPU__) || defined(__NVPTX__)
+#if defined(__AMDGPU__) || defined(__NVPTX__) || \
+  (defined(__ELF__) && !defined(__linux__) && defined(__Fuchsia__))
 extern int __llvmlibc_errno; // Not thread_local!
 #else
 #ifdef __cplusplus
diff --git a/libc/src/errno/libc_errno.cpp b/libc/src/errno/libc_errno.cpp
index bd1438c226143..b8d4bfb0c8e33 100644
--- a/libc/src/errno/libc_errno.cpp
+++ b/libc/src/errno/libc_errno.cpp
@@ -9,7 +9,8 @@
 #include "libc_errno.h"
 #include "src/__support/CPP/atomic.h"
 
-#ifdef LIBC_TARGET_ARCH_IS_GPU
+#if defined(LIBC_TARGET_ARCH_IS_GPU) || \
+  (defined(__ELF__) && !defined(__linux__) && defined(__Fuchsia__))
 // LIBC_THREAD_LOCAL on GPU currently does nothing. So essentially this is just
 // a global errno for gpu to use for now.
 extern "C" {

``````````

</details>


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


More information about the libc-commits mailing list