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
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion libc/include/errno.h.def
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
9 changes: 9 additions & 0 deletions libc/src/errno/libc_errno.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,15 @@ LIBC_NAMESPACE::Errno::operator int() {
return __llvmlibc_errno.load(cpp::MemoryOrder::RELAXED);
}

#elif defined(__ELF__) && !defined(__linux__) && !defined(__Fuchsia__)
// This is the baremetal case which currently uses a global errno.
extern "C" {
int __llvmlibc_errno;
}

void LIBC_NAMESPACE::Errno::operator=(int a) { __llvmlibc_errno = a; }
LIBC_NAMESPACE::Errno::operator int() { return __llvmlibc_errno; }

#elif !defined(LIBC_COPT_PUBLIC_PACKAGING)
// This mode is for unit testing. We just use our internal errno.
LIBC_THREAD_LOCAL int __llvmlibc_internal_errno;
Expand Down
Loading