From 04081caa09fc025fb6a8d8e52bfb083651adbcb5 Mon Sep 17 00:00:00 2001 From: Alexey Samsonov Date: Tue, 12 Aug 2025 19:52:40 -0700 Subject: [PATCH] [libc] Remove LIBC_ERRNO_MODE_SYSTEM mode. (#153077) Use LIBC_ERRNO_MODE_SYSTEM_INLINE instead as the default for the "public packaging" (i.e. release mode) of an overlay build. The Bazel build has already switched to use it by default in 5ccc734fa0355f971f8f515457a0bece33ab6642. This should be a safe change, as LIBC_ERRNO_MODE_SYSTEM_INLINE works a drop-in (but simpler) LIBC_ERRNO_MODE_SYSTEM replacement. Remove the associated code paths and config settings. Fixes issue #143454. --- libc/config/config.json | 2 +- libc/docs/configure.rst | 2 +- libc/src/__support/libc_errno.h | 17 ++++------------- libc/src/errno/libc_errno.cpp | 5 ----- 4 files changed, 6 insertions(+), 20 deletions(-) diff --git a/libc/config/config.json b/libc/config/config.json index 1b0546980e6b..cfbe9a43948e 100644 --- a/libc/config/config.json +++ b/libc/config/config.json @@ -2,7 +2,7 @@ "errno": { "LIBC_CONF_ERRNO_MODE": { "value": "LIBC_ERRNO_MODE_DEFAULT", - "doc": "The implementation used for errno, acceptable values are LIBC_ERRNO_MODE_DEFAULT, LIBC_ERRNO_MODE_UNDEFINED, LIBC_ERRNO_MODE_THREAD_LOCAL, LIBC_ERRNO_MODE_SHARED, LIBC_ERRNO_MODE_EXTERNAL, LIBC_ERRNO_MODE_SYSTEM, and LIBC_ERRNO_MODE_SYSTEM_INLINE." + "doc": "The implementation used for errno, acceptable values are LIBC_ERRNO_MODE_DEFAULT, LIBC_ERRNO_MODE_UNDEFINED, LIBC_ERRNO_MODE_THREAD_LOCAL, LIBC_ERRNO_MODE_SHARED, LIBC_ERRNO_MODE_EXTERNAL, and LIBC_ERRNO_MODE_SYSTEM_INLINE." } }, "threads": { diff --git a/libc/docs/configure.rst b/libc/docs/configure.rst index 95c51b8517e6..e23fc824ce7c 100644 --- a/libc/docs/configure.rst +++ b/libc/docs/configure.rst @@ -29,7 +29,7 @@ to learn about the defaults for your platform and target. - ``LIBC_CONF_ENABLE_STRONG_STACK_PROTECTOR``: Enable -fstack-protector-strong to defend against stack smashing attack. - ``LIBC_CONF_KEEP_FRAME_POINTER``: Keep frame pointer in functions for better debugging experience. * **"errno" options** - - ``LIBC_CONF_ERRNO_MODE``: The implementation used for errno, acceptable values are LIBC_ERRNO_MODE_DEFAULT, LIBC_ERRNO_MODE_UNDEFINED, LIBC_ERRNO_MODE_THREAD_LOCAL, LIBC_ERRNO_MODE_SHARED, LIBC_ERRNO_MODE_EXTERNAL, LIBC_ERRNO_MODE_SYSTEM, and LIBC_ERRNO_MODE_SYSTEM_INLINE. + - ``LIBC_CONF_ERRNO_MODE``: The implementation used for errno, acceptable values are LIBC_ERRNO_MODE_DEFAULT, LIBC_ERRNO_MODE_UNDEFINED, LIBC_ERRNO_MODE_THREAD_LOCAL, LIBC_ERRNO_MODE_SHARED, LIBC_ERRNO_MODE_EXTERNAL, and LIBC_ERRNO_MODE_SYSTEM_INLINE. * **"general" options** - ``LIBC_ADD_NULL_CHECKS``: Add nullptr checks in the library's implementations to some functions for which passing nullptr is undefined behavior. * **"math" options** diff --git a/libc/src/__support/libc_errno.h b/libc/src/__support/libc_errno.h index ab5f6a9c4b9d..3720cdebd5d2 100644 --- a/libc/src/__support/libc_errno.h +++ b/libc/src/__support/libc_errno.h @@ -37,18 +37,11 @@ // libc doesn't maintain any internal state, instead the embedder must define // `int *__llvm_libc_errno(void);` C function. #define LIBC_ERRNO_MODE_EXTERNAL 4 -// libc uses system `` `errno` macro directly in the overlay mode; in -// fullbuild mode, effectively the same as `LIBC_ERRNO_MODE_EXTERNAL`. -// In this mode, the public C++ symbol `LIBC_NAMESPACE::libc_errno ` is still -// exported and get redirected to the system `errno` inside its implementation. - -// TODO: Investigate deprecating LIBC_ERRNO_MODE_SYSTEM in favor of -// LIBC_ERRNO_MODE_SYSTEM_INLINE. -// https://github.com/llvm/llvm-project/issues/143454 -#define LIBC_ERRNO_MODE_SYSTEM 5 +// DEPRECATED: #define LIBC_ERRNO_MODE_SYSTEM 5 // In this mode, the libc_errno is simply a macro resolved to `errno` from the // system header . There is no need to link against the -// `libc.src.errno.errno` object. +// `libc.src.errno.errno` object, and public C++ symbol +// `LIBC_NAMESPACE::libc_errno` doesn't exist. #define LIBC_ERRNO_MODE_SYSTEM_INLINE 6 #if !defined(LIBC_ERRNO_MODE) || LIBC_ERRNO_MODE == LIBC_ERRNO_MODE_DEFAULT @@ -56,7 +49,7 @@ #if defined(LIBC_FULL_BUILD) || !defined(LIBC_COPT_PUBLIC_PACKAGING) #define LIBC_ERRNO_MODE LIBC_ERRNO_MODE_THREAD_LOCAL #else -#define LIBC_ERRNO_MODE LIBC_ERRNO_MODE_SYSTEM +#define LIBC_ERRNO_MODE LIBC_ERRNO_MODE_SYSTEM_INLINE #endif #endif // LIBC_ERRNO_MODE @@ -65,7 +58,6 @@ LIBC_ERRNO_MODE != LIBC_ERRNO_MODE_THREAD_LOCAL && \ LIBC_ERRNO_MODE != LIBC_ERRNO_MODE_SHARED && \ LIBC_ERRNO_MODE != LIBC_ERRNO_MODE_EXTERNAL && \ - LIBC_ERRNO_MODE != LIBC_ERRNO_MODE_SYSTEM && \ LIBC_ERRNO_MODE != LIBC_ERRNO_MODE_SYSTEM_INLINE #error LIBC_ERRNO_MODE must be one of the following values: \ LIBC_ERRNO_MODE_DEFAULT, \ @@ -73,7 +65,6 @@ LIBC_ERRNO_MODE_UNDEFINED, \ LIBC_ERRNO_MODE_THREAD_LOCAL, \ LIBC_ERRNO_MODE_SHARED, \ LIBC_ERRNO_MODE_EXTERNAL, \ -LIBC_ERRNO_MODE_SYSTEM, \ LIBC_ERRNO_MODE_SYSTEM_INLINE. #endif diff --git a/libc/src/errno/libc_errno.cpp b/libc/src/errno/libc_errno.cpp index 8ff1eec1b103..e8960fcd8950 100644 --- a/libc/src/errno/libc_errno.cpp +++ b/libc/src/errno/libc_errno.cpp @@ -46,11 +46,6 @@ Errno::operator int() { return shared_errno; } void Errno::operator=(int a) { *__llvm_libc_errno() = a; } Errno::operator int() { return *__llvm_libc_errno(); } -#elif LIBC_ERRNO_MODE == LIBC_ERRNO_MODE_SYSTEM - -void Errno::operator=(int a) { errno = a; } -Errno::operator int() { return errno; } - #endif // Define the global `libc_errno` instance.