diff --git a/libc/config/gpu/entrypoints.txt b/libc/config/gpu/entrypoints.txt --- a/libc/config/gpu/entrypoints.txt +++ b/libc/config/gpu/entrypoints.txt @@ -53,6 +53,9 @@ libc.src.string.strstr libc.src.string.strtok libc.src.string.strtok_r + + # stdlib.h entrypoints + libc.src.stdlib.atoi ) set(TARGET_LLVMLIBC_ENTRYPOINTS diff --git a/libc/config/gpu/headers.txt b/libc/config/gpu/headers.txt --- a/libc/config/gpu/headers.txt +++ b/libc/config/gpu/headers.txt @@ -1,4 +1,5 @@ set(TARGET_PUBLIC_HEADERS libc.include.ctype libc.include.string + libc.include.stdlib ) diff --git a/libc/include/errno.h.def b/libc/include/errno.h.def --- a/libc/include/errno.h.def +++ b/libc/include/errno.h.def @@ -43,7 +43,9 @@ #include #endif +#if !defined(__AMDGPU__) && !defined(__NVPTX__) extern _Thread_local int __llvmlibc_errno; #define errno __llvmlibc_errno +#endif #endif // LLVM_LIBC_ERRNO_H diff --git a/libc/src/errno/libc_errno.h b/libc/src/errno/libc_errno.h --- a/libc/src/errno/libc_errno.h +++ b/libc/src/errno/libc_errno.h @@ -9,11 +9,26 @@ #ifndef LLVM_LIBC_SRC_ERRNO_LLVMLIBC_ERRNO_H #define LLVM_LIBC_SRC_ERRNO_LLVMLIBC_ERRNO_H +#include "src/__support/macros/properties/architectures.h" + #include +// If we are targeting the GPU we currently don't support 'errno'. We simply +// consume it. +#ifdef LIBC_TARGET_ARCH_IS_GPU +namespace __llvm_libc { +struct ErrnoConsumer { + void operator=(int) {} +}; +} // namespace __llvm_libc +#endif + // All of the libc runtime and test code should use the "libc_errno" macro. They // should not refer to the "errno" macro directly. -#ifdef LIBC_COPT_PUBLIC_PACKAGING +#if defined(LIBC_COPT_PUBLIC_PACKAGING) && defined(LIBC_TARGET_ARCH_IS_GPU) +extern "C" __llvm_libc::ErrnoConsumer __llvmlibc_errno; +#define libc_errno __llvmlibc_errno +#elif defined(LIBC_COPT_PUBLIC_PACKAGING) // This macro will resolve to errno from the errno.h file included above. Under // full build, this will be LLVM libc's errno. In overlay build, it will be // system libc's errno. @@ -21,9 +36,13 @@ #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 thread_local int __llvmlibc_internal_errno; } // extern "C" +#endif // 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 diff --git a/libc/src/errno/libc_errno.cpp b/libc/src/errno/libc_errno.cpp --- a/libc/src/errno/libc_errno.cpp +++ b/libc/src/errno/libc_errno.cpp @@ -6,6 +6,8 @@ // //===----------------------------------------------------------------------===// +#include "src/__support/macros/properties/architectures.h" + namespace __llvm_libc { extern "C" { @@ -18,9 +20,17 @@ // macro defined in LLVM libc's public errno.h header file. // TODO: Use a macro to distinguish full build and overlay build which can be // used to exclude __llvmlibc_errno under overlay build. +#ifdef LIBC_TARGET_ARCH_IS_GPU +ErrnoConsumer __llvmlibc_errno; +#else thread_local int __llvmlibc_errno; +#endif // LIBC_TARGET_ARCH_IS_GPU +#else +#ifdef LIBC_TARGET_ARCH_IS_GPU +ErrnoConsumer __llvmlibc_internal_errno; #else thread_local int __llvmlibc_internal_errno; +#endif // LIBC_TARGET_ARCH_IS_GPU #endif } // extern "C"