Skip to content

Commit

Permalink
[libc] Fix missing default value for errno config (#100175)
Browse files Browse the repository at this point in the history
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 `:`.
  • Loading branch information
jhuber6 authored Jul 23, 2024
1 parent bb60dd3 commit 14e20ee
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 5 deletions.
2 changes: 1 addition & 1 deletion libc/cmake/modules/LibcConfig.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
4 changes: 2 additions & 2 deletions libc/config/config.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
{
"errno": {
"LIBC_CONF_ERRNO_MODE": {
"value": "",
"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."
"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, and LIBC_ERRNO_MODE_SYSTEM."
}
},
"printf": {
Expand Down
9 changes: 7 additions & 2 deletions libc/src/errno/libc_errno.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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).
Expand All @@ -23,20 +25,23 @@
// 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
#define LIBC_ERRNO_MODE LIBC_ERRNO_MODE_SYSTEM
#endif
#endif // LIBC_ERRNO_MODE

#if LIBC_ERRNO_MODE != LIBC_ERRNO_MODE_UNDEFINED && \
#if LIBC_ERRNO_MODE != LIBC_ERRNO_MODE_DEFAULT && \
LIBC_ERRNO_MODE != LIBC_ERRNO_MODE_UNDEFINED && \
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
#error LIBC_ERRNO_MODE must be one of the following values: \
LIBC_ERRNO_MODE_DEFAULT, \
LIBC_ERRNO_MODE_UNDEFINED, \
LIBC_ERRNO_MODE_THREAD_LOCAL, \
LIBC_ERRNO_MODE_SHARED, \
Expand Down

0 comments on commit 14e20ee

Please sign in to comment.