Skip to content

Commit d87eea3

Browse files
authored
[libc] Move libc_errno.h to libc/src/__support and make LIBC_ERRNO_MODE_SYSTEM to be header-only. (#143187)
This is the first step in preparation for: https://discourse.llvm.org/t/rfc-make-clang-builtin-math-functions-constexpr-with-llvm-libc-to-support-c-23-constexpr-math-functions/86450
1 parent fb761aa commit d87eea3

File tree

397 files changed

+829
-783
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

397 files changed

+829
-783
lines changed

libc/cmake/modules/LLVMLibCCompileOptionRules.cmake

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,10 @@ function(_get_compile_options_from_config output_var)
106106
list(APPEND config_options "-DLIBC_MATH=${LIBC_CONF_MATH_OPTIMIZATIONS}")
107107
endif()
108108

109+
if(LIBC_CONF_ERRNO_MODE)
110+
set(APPEND config_options "-DLIBC_ERRNO_MODE=${LIBC_CONF_ERRNO_MODE}")
111+
endif()
112+
109113
set(${output_var} ${config_options} PARENT_SCOPE)
110114
endfunction(_get_compile_options_from_config)
111115

libc/config/config.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"errno": {
33
"LIBC_CONF_ERRNO_MODE": {
44
"value": "LIBC_ERRNO_MODE_DEFAULT",
5-
"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."
5+
"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."
66
}
77
},
88
"printf": {

libc/docs/dev/code_style.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ test infrastructure itself can be affected. To avoid perturbing the unit test
101101
infrastructure around the setting of ``errno``, the following rules are to be
102102
followed:
103103

104-
#. A special macro named ``libc_errno`` defined in ``src/errno/libc_errno.h``
104+
#. A special macro named ``libc_errno`` defined in ``src/__support/libc_errno.h``
105105
should be used when setting ``errno`` from libc runtime code. For example,
106106
code to set ``errno`` to ``EINVAL`` should be:
107107

@@ -117,7 +117,7 @@ followed:
117117
`ErrorOr <https://github.com/llvm/llvm-project/blob/main/libc/src/__support/error_or.h>`_
118118
to return error values.
119119

120-
#. The header file ``src/errno/libc_errno.h`` is shipped as part of the target
120+
#. The header file ``src/__support/libc_errno.h`` is shipped as part of the target
121121
corresponding to the ``errno`` entrypoint ``libc.src.errno.errno``. We do
122122
not in general allow dependencies between entrypoints. However, the ``errno``
123123
entrypoint is the only exceptional entrypoint on which other entrypoints

libc/shared/fp_bits.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
#ifndef LLVM_LIBC_SHARED_FP_BITS_H
1010
#define LLVM_LIBC_SHARED_FP_BITS_H
1111

12+
#include "libc_common.h"
1213
#include "src/__support/FPUtil/FPBits.h"
1314

1415
namespace LIBC_NAMESPACE_DECL {

libc/shared/libc_common.h

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
//===-- Common defines for sharing LLVM libc with LLVM projects -*- C++ -*-===//
2+
//
3+
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4+
// See https://llvm.org/LICENSE.txt for license information.
5+
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6+
//
7+
//===----------------------------------------------------------------------===//
8+
9+
#ifndef LLVM_LIBC_SHARED_LIBC_COMMON_H
10+
#define LLVM_LIBC_SHARED_LIBC_COMMON_H
11+
12+
// Use system errno.
13+
#ifdef LIBC_ERRNO_MODE
14+
#if LIBC_ERRNO_MODE != LIBC_ERRNO_MODE_SYSTEM_INLINE
15+
#error \
16+
"LIBC_ERRNO_MODE was set to something different from LIBC_ERRNO_MODE_SYSTEM_INLINE."
17+
#endif // LIBC_ERRNO_MODE != LIBC_ERRNO_MODE_SYSTEM_INLINE
18+
#else
19+
#define LIBC_ERRNO_MODE LIBC_ERRNO_MODE_SYSTEM_INLINE
20+
#endif // LIBC_ERRNO_MODE
21+
22+
#ifndef LIBC_NAMESPACE
23+
#define LIBC_NAMESPACE __llvm_libc
24+
#endif // LIBC_NAMESPACE
25+
26+
#endif // LLVM_LIBC_SHARED_LIBC_COMMON_H

libc/shared/rpc_server.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
#ifndef LLVM_LIBC_SHARED_RPC_SERVER_H
1010
#define LLVM_LIBC_SHARED_RPC_SERVER_H
1111

12+
#include "libc_common.h"
1213
#include "src/__support/RPC/rpc_server.h"
1314

1415
namespace LIBC_NAMESPACE_DECL {

libc/shared/str_to_float.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
#ifndef LLVM_LIBC_SHARED_STR_TO_FLOAT_H
1010
#define LLVM_LIBC_SHARED_STR_TO_FLOAT_H
1111

12+
#include "libc_common.h"
1213
#include "src/__support/str_to_float.h"
1314

1415
namespace LIBC_NAMESPACE_DECL {

libc/shared/str_to_integer.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
#ifndef LLVM_LIBC_SHARED_STR_TO_INTEGER_H
1010
#define LLVM_LIBC_SHARED_STR_TO_INTEGER_H
1111

12+
#include "libc_common.h"
1213
#include "src/__support/str_to_integer.h"
1314

1415
namespace LIBC_NAMESPACE_DECL {

libc/src/__support/CMakeLists.txt

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,15 @@
11
add_subdirectory(CPP)
22
add_subdirectory(macros)
33

4+
add_header_library(
5+
libc_errno
6+
HDRS
7+
libc_errno.h
8+
DEPENDS
9+
libc.hdr.errno_macros
10+
libc.src.__support.macros.config
11+
)
12+
413
add_header_library(
514
block
615
HDRS

libc/src/__support/FPUtil/FEnvImpl.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,10 @@
1212
#include "hdr/fenv_macros.h"
1313
#include "hdr/math_macros.h"
1414
#include "hdr/types/fenv_t.h"
15+
#include "src/__support/libc_errno.h"
1516
#include "src/__support/macros/attributes.h" // LIBC_INLINE
1617
#include "src/__support/macros/config.h"
1718
#include "src/__support/macros/properties/architectures.h"
18-
#include "src/errno/libc_errno.h"
1919

2020
#if defined(LIBC_TARGET_ARCH_IS_AARCH64) && defined(__ARM_FP)
2121
#if defined(__APPLE__)

0 commit comments

Comments
 (0)