[libc-commits] [PATCH] D152015: [libc] Implement 'errno' on the GPU as a global integer internally

Joseph Huber via Phabricator via libc-commits libc-commits at lists.llvm.org
Fri Jun 2 10:52:27 PDT 2023


jhuber6 created this revision.
jhuber6 added reviewers: tra, jdoerfert, tianshilei1992, JonChesterfield, sivachandra, lntue, michaelrj.
Herald added subscribers: libc-commits, tschuett.
Herald added projects: libc-project, All.
jhuber6 requested review of this revision.

The C standard asserts that the `errno` value is an l-value thread local
integer. We cannot provide a generic thread local integer on the GPU
currently without some workarounds. Previously, we worked around this by
implementing the `errno` value as a special consumer class that made all
the writes disappear. However, this is problematic for internal tests.
Currently there are build failures because of this handling and it's
only likely to cause more problems the more we do this.

This patch instead makes the internal target used for testing export the
`errno` value as a simple global integer. This allows us to use and test
the `errno` interface correctly assuming we run with a single thread.
Because this is only used for the non-exported target we still do not
provide this feature in the version that users will use so we do not
need to worrk about it being incorrect in general.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D152015

Files:
  libc/src/errno/libc_errno.cpp
  libc/src/errno/libc_errno.h


Index: libc/src/errno/libc_errno.h
===================================================================
--- libc/src/errno/libc_errno.h
+++ libc/src/errno/libc_errno.h
@@ -39,13 +39,10 @@
 #else
 namespace __llvm_libc {
 
-#ifdef LIBC_TARGET_ARCH_IS_GPU
-extern "C" ErrnoConsumer __llvmlibc_internal_errno;
-#else // LIBC_TARGET_ARCH_IS_GPU
-extern "C" {
-extern LIBC_THREAD_LOCAL int __llvmlibc_internal_errno;
-} // extern "C"
-#endif
+// TODO: On the GPU build this will be mapped to a single global value. We need
+// to ensure that tests are not run with multiple threads that depend on errno
+// until we have true 'thread_local' support on the GPU.
+extern "C" LIBC_THREAD_LOCAL int __llvmlibc_internal_errno;
 
 // TODO: After all of libc/src and libc/test are switched over to use
 // libc_errno, this header file will be "shipped" via an add_entrypoint_object
Index: libc/src/errno/libc_errno.cpp
===================================================================
--- libc/src/errno/libc_errno.cpp
+++ libc/src/errno/libc_errno.cpp
@@ -33,11 +33,7 @@
 LIBC_THREAD_LOCAL int __llvmlibc_errno;
 #endif // LIBC_TARGET_ARCH_IS_GPU
 #else
-#ifdef LIBC_TARGET_ARCH_IS_GPU
-ErrnoConsumer __llvmlibc_internal_errno;
-#else
 LIBC_THREAD_LOCAL int __llvmlibc_internal_errno;
-#endif // LIBC_TARGET_ARCH_IS_GPU
 #endif
 } // extern "C"
 


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D152015.527910.patch
Type: text/x-patch
Size: 1337 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/libc-commits/attachments/20230602/3aa30027/attachment.bin>


More information about the libc-commits mailing list