Skip to content

Conversation

vonosmas
Copy link
Contributor

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 5ccc734. 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.

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
5ccc734. 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 llvm#143454.
@vonosmas vonosmas requested a review from lntue August 11, 2025 20:00
@llvmbot llvmbot added the libc label Aug 11, 2025
@llvmbot
Copy link
Member

llvmbot commented Aug 11, 2025

@llvm/pr-subscribers-libc

Author: Alexey Samsonov (vonosmas)

Changes

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 5ccc734. 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.


Full diff: https://github.com/llvm/llvm-project/pull/153077.diff

4 Files Affected:

  • (modified) libc/config/config.json (+1-1)
  • (modified) libc/docs/configure.rst (+1-1)
  • (modified) libc/src/__support/libc_errno.h (+4-13)
  • (modified) libc/src/errno/libc_errno.cpp (-5)
diff --git a/libc/config/config.json b/libc/config/config.json
index 1b0546980e6ba..cfbe9a43948ea 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 95c51b8517e64..e23fc824ce7c8 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 ab5f6a9c4b9d9..3720cdebd5d2a 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.h>` `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 <errno.h>.  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 8ff1eec1b1035..e8960fcd89500 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.

@vonosmas vonosmas merged commit 04081ca into llvm:main Aug 13, 2025
22 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants