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

Petr Hosek via libc-commits libc-commits at lists.llvm.org
Tue Jul 9 02:06:06 PDT 2024


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

>From bc3298e69acfb8f4d747b50886cc57cd87ee270e Mon Sep 17 00:00:00 2001
From: Petr Hosek <phosek at google.com>
Date: Tue, 9 Jul 2024 01:33:56 -0700
Subject: [PATCH] [libc] Use global errno for baremetal

We want to avoid thread local variables on baremetal since the TLS
support may not be universally available in those environments.
---
 libc/include/errno.h.def      | 3 ++-
 libc/src/errno/libc_errno.cpp | 3 ++-
 2 files changed, 4 insertions(+), 2 deletions(-)

diff --git a/libc/include/errno.h.def b/libc/include/errno.h.def
index 1f7120e63bfc9..91d59d02cc5d3 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..c370b30a82576 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" {



More information about the libc-commits mailing list