[libc-commits] [libc] [libc] Fix missing default value for errno config (PR #100175)

Joseph Huber via libc-commits libc-commits at lists.llvm.org
Tue Jul 23 12:34:55 PDT 2024


https://github.com/jhuber6 updated https://github.com/llvm/llvm-project/pull/100175

>From 3d3696cf501d7e9bcbd4490f12ee70f7d06543ec Mon Sep 17 00:00:00 2001
From: Joseph Huber <huberjn at outlook.com>
Date: Tue, 23 Jul 2024 13:19:01 -0500
Subject: [PATCH 1/2] [libc] Fix missing default value for errno config

Summary:
The configs all need default values which targets then override. This
one was an empty string which made the logic report an error. The only
reason it wasn't a build failure was because of a stray `:`.
---
 libc/cmake/modules/LibcConfig.cmake | 2 +-
 libc/config/config.json             | 2 +-
 libc/src/errno/libc_errno.cpp       | 5 ++++-
 3 files changed, 6 insertions(+), 3 deletions(-)

diff --git a/libc/cmake/modules/LibcConfig.cmake b/libc/cmake/modules/LibcConfig.cmake
index 7a3e6066b3cc0..da166dd6cc3fc 100644
--- a/libc/cmake/modules/LibcConfig.cmake
+++ b/libc/cmake/modules/LibcConfig.cmake
@@ -113,7 +113,7 @@ function(load_libc_config config_file)
       message(FATAL_ERROR ${json_error})
     endif()
     if(NOT DEFINED ${opt_name})
-      message(FATAL_ERROR: " Option ${opt_name} defined in ${config_file} is invalid.")
+      message(FATAL_ERROR " Option ${opt_name} defined in ${config_file} is invalid.")
     endif()
     if(ARGN)
       list(FIND ARGN ${opt_name} optname_exists)
diff --git a/libc/config/config.json b/libc/config/config.json
index 2005f4297bfc1..4ff98524a3926 100644
--- a/libc/config/config.json
+++ b/libc/config/config.json
@@ -1,7 +1,7 @@
 {
   "errno": {
     "LIBC_CONF_ERRNO_MODE": {
-      "value": "",
+      "value": "LIBC_ERRNO_MODE_DEFAULT",
       "doc": "The implementation used for errno, acceptable values are LIBC_ERRNO_MODE_UNDEFINED, LIBC_ERRNO_MODE_THREAD_LOCAL, LIBC_ERRNO_MODE_SHARED, LIBC_ERRNO_MODE_EXTERNAL, and LIBC_ERRNO_MODE_SYSTEM."
     }
   },
diff --git a/libc/src/errno/libc_errno.cpp b/libc/src/errno/libc_errno.cpp
index 7a17a5a8217c7..0ae9fe486e8ea 100644
--- a/libc/src/errno/libc_errno.cpp
+++ b/libc/src/errno/libc_errno.cpp
@@ -9,6 +9,8 @@
 #include "libc_errno.h"
 #include "src/__support/macros/config.h"
 
+// libc uses a fallback default value, either system or thread local.
+#define LIBC_ERRNO_MODE_DEFAULT 0
 // libc never stores a value; `errno` macro uses get link-time failure.
 #define LIBC_ERRNO_MODE_UNDEFINED 1
 // libc maintains per-thread state (requires C++ `thread_local` support).
@@ -23,7 +25,8 @@
 // fullbuild mode, effectively the same as `LIBC_ERRNO_MODE_EXTERNAL`.
 #define LIBC_ERRNO_MODE_SYSTEM 5
 
-#ifndef LIBC_ERRNO_MODE
+#if !defined(LIBC_ERRNO_MODE) || LIBC_ERRNO_MODE == LIBC_ERRNO_MODE_DEFAULT
+#undef LIBC_ERRNO_MODE
 #if defined(LIBC_FULL_BUILD) || !defined(LIBC_COPT_PUBLIC_PACKAGING)
 #define LIBC_ERRNO_MODE LIBC_ERRNO_MODE_THREAD_LOCAL
 #else

>From 7fa8553dee6718ac1f5be234f5bb28e811cca068 Mon Sep 17 00:00:00 2001
From: Joseph Huber <huberjn at outlook.com>
Date: Tue, 23 Jul 2024 14:34:48 -0500
Subject: [PATCH 2/2] Update libc/config/config.json

---
 libc/config/config.json | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/libc/config/config.json b/libc/config/config.json
index 4ff98524a3926..4b0fcc87fafa5 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_UNDEFINED, LIBC_ERRNO_MODE_THREAD_LOCAL, LIBC_ERRNO_MODE_SHARED, LIBC_ERRNO_MODE_EXTERNAL, and LIBC_ERRNO_MODE_SYSTEM."
+      "doc": "The implementation used for errno, acceptable values are LIBC_ERRNO_DEFAULT, LIBC_ERRNO_MODE_UNDEFINED, LIBC_ERRNO_MODE_THREAD_LOCAL, LIBC_ERRNO_MODE_SHARED, LIBC_ERRNO_MODE_EXTERNAL, and LIBC_ERRNO_MODE_SYSTEM."
     }
   },
   "printf": {



More information about the libc-commits mailing list