diff --git a/libc/config/linux/aarch64/entrypoints.txt b/libc/config/linux/aarch64/entrypoints.txt --- a/libc/config/linux/aarch64/entrypoints.txt +++ b/libc/config/linux/aarch64/entrypoints.txt @@ -17,9 +17,6 @@ libc.src.ctype.tolower libc.src.ctype.toupper - # errno.h entrypoints - libc.src.errno.__errno_location - # fcntl.h entrypoints libc.src.fcntl.creat libc.src.fcntl.open diff --git a/libc/config/linux/api.td b/libc/config/linux/api.td --- a/libc/config/linux/api.td +++ b/libc/config/linux/api.td @@ -44,11 +44,8 @@ def ErrnoMacro : MacroDef<"errno"> { let Defn = [{ - #ifdef __cplusplus - extern "C" - #endif - int *__errno_location(); - #define errno (*__errno_location()) + extern _Thread_local int __llvmlibc_errno; + #define errno __llvmlibc_errno }]; } diff --git a/libc/config/linux/x86_64/entrypoints.txt b/libc/config/linux/x86_64/entrypoints.txt --- a/libc/config/linux/x86_64/entrypoints.txt +++ b/libc/config/linux/x86_64/entrypoints.txt @@ -17,9 +17,6 @@ libc.src.ctype.tolower libc.src.ctype.toupper - # errno.h entrypoints - libc.src.errno.__errno_location - # fcntl.h entrypoints libc.src.fcntl.creat libc.src.fcntl.open diff --git a/libc/include/__llvm-libc-common.h b/libc/include/__llvm-libc-common.h --- a/libc/include/__llvm-libc-common.h +++ b/libc/include/__llvm-libc-common.h @@ -29,6 +29,9 @@ #undef _Alignof #define _Alignof alignof +#undef _Thread_local +#define _Thread_local thread_local + #else // not __cplusplus #undef __BEGIN_C_DECLS diff --git a/libc/spec/llvm_libc_ext.td b/libc/spec/llvm_libc_ext.td --- a/libc/spec/llvm_libc_ext.td +++ b/libc/spec/llvm_libc_ext.td @@ -33,24 +33,8 @@ ] >; - HeaderSpec Errno = HeaderSpec< - "errno.h", - [], // Macros - [], // Types - [], // Enumerations - [ - FunctionSpec< - "__errno_location", - RetValSpec, - [ArgSpec] - - >, - ] - >; - let Headers = [ String, Assert, - Errno, ]; } diff --git a/libc/src/__support/CMakeLists.txt b/libc/src/__support/CMakeLists.txt --- a/libc/src/__support/CMakeLists.txt +++ b/libc/src/__support/CMakeLists.txt @@ -22,7 +22,7 @@ DEPENDS .ctype_utils libc.include.errno - libc.src.errno.__errno_location + libc.src.errno.errno libc.src.__support.CPP.standalone_cpp ) @@ -43,7 +43,7 @@ .ctype_utils .high_precision_decimal libc.include.errno - libc.src.errno.__errno_location + libc.src.errno.errno libc.src.__support.CPP.standalone_cpp libc.src.__support.FPUtil.fputil ) diff --git a/libc/src/__support/FPUtil/CMakeLists.txt b/libc/src/__support/FPUtil/CMakeLists.txt --- a/libc/src/__support/FPUtil/CMakeLists.txt +++ b/libc/src/__support/FPUtil/CMakeLists.txt @@ -21,7 +21,7 @@ libc.include.fenv libc.src.__support.common libc.src.__support.CPP.standalone_cpp - libc.src.errno.__errno_location + libc.src.errno.errno ) add_header_library( diff --git a/libc/src/__support/File/CMakeLists.txt b/libc/src/__support/File/CMakeLists.txt --- a/libc/src/__support/File/CMakeLists.txt +++ b/libc/src/__support/File/CMakeLists.txt @@ -5,5 +5,6 @@ HDRS file.h DEPENDS - libc.src.errno.__errno_location + libc.include.errno + libc.src.errno.errno ) diff --git a/libc/src/errno/CMakeLists.txt b/libc/src/errno/CMakeLists.txt --- a/libc/src/errno/CMakeLists.txt +++ b/libc/src/errno/CMakeLists.txt @@ -1,15 +1,14 @@ if (LLVM_LIBC_FULL_BUILD) -add_entrypoint_object( - __errno_location +add_object_library( + errno SRCS - __errno_location.cpp + errno.cpp HDRS - __errno_location.h llvmlibc_errno.h ) else() -add_entrypoint_object( - __errno_location +add_object_library( + errno SRCS dummy_errno.cpp HDRS diff --git a/libc/src/errno/__errno_location.h b/libc/src/errno/__errno_location.h deleted file mode 100644 --- a/libc/src/errno/__errno_location.h +++ /dev/null @@ -1,18 +0,0 @@ -//===-- Implementation header for __errno_location --------------*- C++ -*-===// -// -// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. -// See https://llvm.org/LICENSE.txt for license information. -// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -// -//===----------------------------------------------------------------------===// - -#ifndef LLVM_LIBC_SRC_ERRNO_ERRNO_LOCATION_H -#define LLVM_LIBC_SRC_ERRNO_ERRNO_LOCATION_H - -namespace __llvm_libc { - -int *__errno_location(); - -} // namespace __llvm_libc - -#endif // LLVM_LIBC_SRC_ERRNO_ERRNO_LOCATION_H diff --git a/libc/src/errno/__errno_location.cpp b/libc/src/errno/__errno_location.cpp deleted file mode 100644 --- a/libc/src/errno/__errno_location.cpp +++ /dev/null @@ -1,22 +0,0 @@ -//===-- Implementation of __errno_location --------------------------------===// -// -// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. -// See https://llvm.org/LICENSE.txt for license information. -// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -// -//===----------------------------------------------------------------------===// - -#include "src/errno/__errno_location.h" - -#include "src/__support/common.h" - -namespace __llvm_libc { - -static thread_local int errno = 0; - -// __errno_location is not really an entry point but we still want it to behave -// like an entry point because the errno macro resolves to the C symbol -// "__errno_location". -LLVM_LIBC_FUNCTION(int *, __errno_location, ()) { return &errno; } - -} // namespace __llvm_libc diff --git a/libc/src/errno/errno.cpp b/libc/src/errno/errno.cpp new file mode 100644 --- /dev/null +++ b/libc/src/errno/errno.cpp @@ -0,0 +1,9 @@ +//===-- Implementation of __errno_location --------------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +thread_local int __llvmlibc_errno = 0; diff --git a/libc/src/errno/llvmlibc_errno.h b/libc/src/errno/llvmlibc_errno.h --- a/libc/src/errno/llvmlibc_errno.h +++ b/libc/src/errno/llvmlibc_errno.h @@ -6,13 +6,12 @@ // //===----------------------------------------------------------------------===// -#include "src/errno/__errno_location.h" - #ifndef LLVM_LIBC_SRC_ERRNO_LLVMLIBC_ERRNO_H #define LLVM_LIBC_SRC_ERRNO_LLVMLIBC_ERRNO_H // Internal code should use this and not use the errno macro from the // public header. -#define llvmlibc_errno (*__llvm_libc::__errno_location()) +extern thread_local int __llvmlibc_errno; +#define llvmlibc_errno __llvmlibc_errno #endif // LLVM_LIBC_SRC_ERRNO_LLVMLIBC_ERRNO_H diff --git a/libc/src/fcntl/linux/CMakeLists.txt b/libc/src/fcntl/linux/CMakeLists.txt --- a/libc/src/fcntl/linux/CMakeLists.txt +++ b/libc/src/fcntl/linux/CMakeLists.txt @@ -8,7 +8,7 @@ libc.include.errno libc.include.fcntl libc.src.__support.OSUtil.osutil - libc.src.errno.__errno_location + libc.src.errno.errno ) add_entrypoint_object( @@ -21,7 +21,7 @@ libc.include.errno libc.include.fcntl libc.src.__support.OSUtil.osutil - libc.src.errno.__errno_location + libc.src.errno.errno ) add_entrypoint_object( @@ -34,5 +34,5 @@ libc.include.errno libc.include.fcntl libc.src.__support.OSUtil.osutil - libc.src.errno.__errno_location + libc.src.errno.errno ) diff --git a/libc/src/math/generic/CMakeLists.txt b/libc/src/math/generic/CMakeLists.txt --- a/libc/src/math/generic/CMakeLists.txt +++ b/libc/src/math/generic/CMakeLists.txt @@ -43,7 +43,7 @@ DEPENDS libc.include.errno libc.include.math - libc.src.errno.__errno_location + libc.src.errno.errno ) add_object_library( @@ -65,7 +65,7 @@ DEPENDS .sincosf_utils libc.include.math - libc.src.errno.__errno_location + libc.src.errno.errno COMPILE_OPTIONS -O3 ) @@ -79,7 +79,7 @@ DEPENDS .sincosf_utils libc.include.math - libc.src.errno.__errno_location + libc.src.errno.errno libc.src.__support.FPUtil.fputil COMPILE_OPTIONS -O3 @@ -94,7 +94,7 @@ DEPENDS .sincosf_utils libc.include.math - libc.src.errno.__errno_location + libc.src.errno.errno COMPILE_OPTIONS -O3 ) diff --git a/libc/src/signal/linux/CMakeLists.txt b/libc/src/signal/linux/CMakeLists.txt --- a/libc/src/signal/linux/CMakeLists.txt +++ b/libc/src/signal/linux/CMakeLists.txt @@ -41,7 +41,7 @@ libc.include.signal libc.include.sys_syscall libc.src.__support.OSUtil.osutil - libc.src.errno.__errno_location + libc.src.errno.errno ) add_entrypoint_object( @@ -55,7 +55,7 @@ libc.include.signal libc.include.sys_syscall libc.src.__support.OSUtil.osutil - libc.src.errno.__errno_location + libc.src.errno.errno ) add_entrypoint_object( @@ -68,7 +68,7 @@ DEPENDS libc.include.errno libc.include.signal - libc.src.errno.__errno_location + libc.src.errno.errno ) add_entrypoint_object( @@ -81,7 +81,7 @@ DEPENDS libc.include.errno libc.include.signal - libc.src.errno.__errno_location + libc.src.errno.errno ) add_entrypoint_object( @@ -106,7 +106,7 @@ DEPENDS libc.include.errno libc.include.signal - libc.src.errno.__errno_location + libc.src.errno.errno ) add_entrypoint_object( @@ -119,5 +119,5 @@ DEPENDS libc.include.errno libc.include.signal - libc.src.errno.__errno_location + libc.src.errno.errno ) diff --git a/libc/src/sys/mman/linux/CMakeLists.txt b/libc/src/sys/mman/linux/CMakeLists.txt --- a/libc/src/sys/mman/linux/CMakeLists.txt +++ b/libc/src/sys/mman/linux/CMakeLists.txt @@ -8,7 +8,7 @@ libc.include.sys_mman libc.include.sys_syscall libc.src.__support.OSUtil.osutil - libc.src.errno.__errno_location + libc.src.errno.errno ) add_entrypoint_object( @@ -21,5 +21,5 @@ libc.include.sys_mman libc.include.sys_syscall libc.src.__support.OSUtil.osutil - libc.src.errno.__errno_location + libc.src.errno.errno ) diff --git a/libc/src/sys/stat/linux/CMakeLists.txt b/libc/src/sys/stat/linux/CMakeLists.txt --- a/libc/src/sys/stat/linux/CMakeLists.txt +++ b/libc/src/sys/stat/linux/CMakeLists.txt @@ -9,7 +9,7 @@ libc.include.sys_stat libc.include.sys_syscall libc.src.__support.OSUtil.osutil - libc.src.errno.__errno_location + libc.src.errno.errno ) add_entrypoint_object( @@ -22,5 +22,5 @@ libc.include.sys_stat libc.include.sys_syscall libc.src.__support.OSUtil.osutil - libc.src.errno.__errno_location + libc.src.errno.errno ) diff --git a/libc/src/threads/linux/CMakeLists.txt b/libc/src/threads/linux/CMakeLists.txt --- a/libc/src/threads/linux/CMakeLists.txt +++ b/libc/src/threads/linux/CMakeLists.txt @@ -50,7 +50,7 @@ libc.include.threads libc.src.__support.common libc.src.__support.OSUtil.osutil - libc.src.errno.__errno_location + libc.src.errno.errno libc.src.sys.mman.mmap COMPILE_OPTIONS -O3 diff --git a/libc/src/time/CMakeLists.txt b/libc/src/time/CMakeLists.txt --- a/libc/src/time/CMakeLists.txt +++ b/libc/src/time/CMakeLists.txt @@ -7,7 +7,7 @@ DEPENDS libc.include.errno libc.include.time - libc.src.errno.__errno_location + libc.src.errno.errno ) add_entrypoint_object( @@ -64,5 +64,5 @@ .time_utils libc.include.errno libc.include.time - libc.src.errno.__errno_location + libc.src.errno.errno ) diff --git a/libc/src/unistd/linux/CMakeLists.txt b/libc/src/unistd/linux/CMakeLists.txt --- a/libc/src/unistd/linux/CMakeLists.txt +++ b/libc/src/unistd/linux/CMakeLists.txt @@ -8,7 +8,7 @@ libc.include.unistd libc.include.sys_syscall libc.src.__support.OSUtil.osutil - libc.src.errno.__errno_location + libc.src.errno.errno ) add_entrypoint_object( @@ -21,7 +21,7 @@ libc.include.unistd libc.include.sys_syscall libc.src.__support.OSUtil.osutil - libc.src.errno.__errno_location + libc.src.errno.errno ) add_entrypoint_object( @@ -34,7 +34,7 @@ libc.include.unistd libc.include.sys_syscall libc.src.__support.OSUtil.osutil - libc.src.errno.__errno_location + libc.src.errno.errno ) add_entrypoint_object( @@ -48,7 +48,7 @@ libc.include.unistd libc.include.sys_syscall libc.src.__support.OSUtil.osutil - libc.src.errno.__errno_location + libc.src.errno.errno ) add_entrypoint_object( @@ -62,7 +62,7 @@ libc.include.unistd libc.include.sys_syscall libc.src.__support.OSUtil.osutil - libc.src.errno.__errno_location + libc.src.errno.errno ) add_entrypoint_object( @@ -76,7 +76,7 @@ libc.include.unistd libc.include.sys_syscall libc.src.__support.OSUtil.osutil - libc.src.errno.__errno_location + libc.src.errno.errno ) add_entrypoint_object( @@ -89,5 +89,5 @@ libc.include.unistd libc.include.sys_syscall libc.src.__support.OSUtil.osutil - libc.src.errno.__errno_location + libc.src.errno.errno ) diff --git a/libc/test/loader/linux/CMakeLists.txt b/libc/test/loader/linux/CMakeLists.txt --- a/libc/test/loader/linux/CMakeLists.txt +++ b/libc/test/loader/linux/CMakeLists.txt @@ -70,6 +70,6 @@ # libc.include.sys_mman # libc.loader.linux.crt1 # libc.src.assert.__assert_fail -# libc.src.errno.__errno_location +# libc.src.errno.errno # libc.src.sys.mman.mmap #) diff --git a/libc/test/src/__support/File/CMakeLists.txt b/libc/test/src/__support/File/CMakeLists.txt --- a/libc/test/src/__support/File/CMakeLists.txt +++ b/libc/test/src/__support/File/CMakeLists.txt @@ -6,6 +6,7 @@ SRCS file_test.cpp DEPENDS + libc.include.errno libc.include.stdio libc.include.stdlib libc.src.__support.File.file diff --git a/libc/test/src/errno/CMakeLists.txt b/libc/test/src/errno/CMakeLists.txt --- a/libc/test/src/errno/CMakeLists.txt +++ b/libc/test/src/errno/CMakeLists.txt @@ -11,5 +11,5 @@ SRCS errno_test.cpp DEPENDS - libc.src.errno.__errno_location + libc.src.errno.errno ) diff --git a/libc/test/src/math/CMakeLists.txt b/libc/test/src/math/CMakeLists.txt --- a/libc/test/src/math/CMakeLists.txt +++ b/libc/test/src/math/CMakeLists.txt @@ -309,7 +309,7 @@ DEPENDS libc.include.errno libc.include.math - libc.src.errno.__errno_location + libc.src.errno.errno libc.src.fenv.feclearexcept libc.src.fenv.feraiseexcept libc.src.fenv.fetestexcept @@ -329,7 +329,7 @@ DEPENDS libc.include.errno libc.include.math - libc.src.errno.__errno_location + libc.src.errno.errno libc.src.fenv.feclearexcept libc.src.fenv.feraiseexcept libc.src.fenv.fetestexcept @@ -349,7 +349,7 @@ DEPENDS libc.include.errno libc.include.math - libc.src.errno.__errno_location + libc.src.errno.errno libc.src.fenv.feclearexcept libc.src.fenv.feraiseexcept libc.src.fenv.fetestexcept @@ -369,7 +369,7 @@ DEPENDS libc.include.errno libc.include.math - libc.src.errno.__errno_location + libc.src.errno.errno libc.src.fenv.feclearexcept libc.src.fenv.feraiseexcept libc.src.fenv.fetestexcept @@ -389,7 +389,7 @@ DEPENDS libc.include.errno libc.include.math - libc.src.errno.__errno_location + libc.src.errno.errno libc.src.fenv.feclearexcept libc.src.fenv.feraiseexcept libc.src.fenv.fetestexcept @@ -409,7 +409,7 @@ DEPENDS libc.include.errno libc.include.math - libc.src.errno.__errno_location + libc.src.errno.errno libc.src.fenv.feclearexcept libc.src.fenv.feraiseexcept libc.src.fenv.fetestexcept diff --git a/libc/test/src/signal/CMakeLists.txt b/libc/test/src/signal/CMakeLists.txt --- a/libc/test/src/signal/CMakeLists.txt +++ b/libc/test/src/signal/CMakeLists.txt @@ -33,7 +33,7 @@ sigprocmask_test.cpp DEPENDS libc.include.errno - libc.src.errno.__errno_location + libc.src.errno.errno libc.src.signal.raise libc.src.signal.sigaddset libc.src.signal.sigemptyset @@ -63,7 +63,7 @@ DEPENDS libc.include.errno libc.include.signal - libc.src.errno.__errno_location + libc.src.errno.errno libc.src.signal.raise libc.src.signal.signal libc.test.errno_setter_matcher diff --git a/libc/test/src/sys/mman/linux/CMakeLists.txt b/libc/test/src/sys/mman/linux/CMakeLists.txt --- a/libc/test/src/sys/mman/linux/CMakeLists.txt +++ b/libc/test/src/sys/mman/linux/CMakeLists.txt @@ -9,7 +9,7 @@ DEPENDS libc.include.errno libc.include.sys_mman - libc.src.errno.__errno_location + libc.src.errno.errno libc.src.sys.mman.mmap libc.src.sys.mman.munmap libc.test.errno_setter_matcher diff --git a/libc/test/src/threads/CMakeLists.txt b/libc/test/src/threads/CMakeLists.txt --- a/libc/test/src/threads/CMakeLists.txt +++ b/libc/test/src/threads/CMakeLists.txt @@ -26,7 +26,7 @@ thrd_test.cpp DEPENDS libc.include.threads - libc.src.errno.__errno_location + libc.src.errno.errno libc.src.threads.thrd_create libc.src.threads.thrd_join ) @@ -39,7 +39,7 @@ mtx_test.cpp DEPENDS libc.include.threads - libc.src.errno.__errno_location + libc.src.errno.errno libc.src.threads.mtx_destroy libc.src.threads.mtx_init libc.src.threads.mtx_lock