Skip to content

[libc] Use global errno for baremetal #98130

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from

Conversation

petrhosek
Copy link
Member

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

@llvmbot llvmbot added the libc label Jul 9, 2024
@llvmbot
Copy link
Member

llvmbot commented Jul 9, 2024

@llvm/pr-subscribers-libc

Author: Petr Hosek (petrhosek)

Changes

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 --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" {

Copy link

github-actions bot commented Jul 9, 2024

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

@petrhosek petrhosek force-pushed the libc-baremetal-errno branch from 047964a to bc3298e Compare July 9, 2024 09:06
We want to avoid thread local variables on baremetal since the TLS
support may not be universally available in those environments.
@petrhosek petrhosek force-pushed the libc-baremetal-errno branch from bc3298e to 626ce67 Compare July 9, 2024 09:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants