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

Joseph Huber via libc-commits libc-commits at lists.llvm.org
Fri Jun 2 12:16:33 PDT 2023


Author: Joseph Huber
Date: 2023-06-02T14:16:24-05:00
New Revision: cfde5f2d8969040611d24075a571d485ab62cb27

URL: https://github.com/llvm/llvm-project/commit/cfde5f2d8969040611d24075a571d485ab62cb27
DIFF: https://github.com/llvm/llvm-project/commit/cfde5f2d8969040611d24075a571d485ab62cb27.diff

LOG: [libc] Implement 'errno' on the GPU as a global integer internally

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.

Reviewed By: lntue

Differential Revision: https://reviews.llvm.org/D152015

Added: 
    

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

Removed: 
    


################################################################################
diff  --git a/libc/src/errno/libc_errno.cpp b/libc/src/errno/libc_errno.cpp
index 005d9a9317791..0489e11a1e894 100644
--- a/libc/src/errno/libc_errno.cpp
+++ b/libc/src/errno/libc_errno.cpp
@@ -33,11 +33,7 @@ ErrnoConsumer __llvmlibc_errno;
 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"
 

diff  --git a/libc/src/errno/libc_errno.h b/libc/src/errno/libc_errno.h
index 0c473a5909c55..8007f0dea58b1 100644
--- a/libc/src/errno/libc_errno.h
+++ b/libc/src/errno/libc_errno.h
@@ -39,13 +39,10 @@ extern "C" __llvm_libc::ErrnoConsumer __llvmlibc_errno;
 #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


        


More information about the libc-commits mailing list