-
Notifications
You must be signed in to change notification settings - Fork 15.6k
[libc] Move libc_errno.h to libc/src/__support and make LIBC_ERRNO_MODE_SYSTEM to be header-only. #143187
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
[libc] Move libc_errno.h to libc/src/__support and make LIBC_ERRNO_MODE_SYSTEM to be header-only. #143187
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
3c81e1f
[libc] Move libc_errno.h to libc/src/__support and make LIBC_ERRNO_MO…
lntue fdee7eb
Use LIBC_ERRNO_MODE_SYSTEM for libc/shared folder.
lntue c5ce70a
Mass update "src/errno/libc_errno.h" -> "src/__support/libc_errno.h" …
lntue 9af1e56
Add LIBC_ERRNO_MODE_SYSTEM_INLINE and use that as the default for lib…
lntue d010519
Update `libcxx_shared_headers` in Bazel build.
lntue 453200e
Error out when `LIBC_ERRNO_MODE` is set to something different from L…
lntue 03a20b9
Add TODO about deprecating LIBC_ERRNO_MODE_SYSTEM.
lntue 73c2e1d
Update comments.
lntue File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,26 @@ | ||
| //===-- Common defines for sharing LLVM libc with LLVM projects -*- C++ -*-===// | ||
lntue marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| // | ||
| // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. | ||
| // See https://llvm.org/LICENSE.txt for license information. | ||
| // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception | ||
| // | ||
| //===----------------------------------------------------------------------===// | ||
|
|
||
| #ifndef LLVM_LIBC_SHARED_LIBC_COMMON_H | ||
| #define LLVM_LIBC_SHARED_LIBC_COMMON_H | ||
|
|
||
| // Use system errno. | ||
| #ifdef LIBC_ERRNO_MODE | ||
| #if LIBC_ERRNO_MODE != LIBC_ERRNO_MODE_SYSTEM_INLINE | ||
| #error \ | ||
| "LIBC_ERRNO_MODE was set to something different from LIBC_ERRNO_MODE_SYSTEM_INLINE." | ||
| #endif // LIBC_ERRNO_MODE != LIBC_ERRNO_MODE_SYSTEM_INLINE | ||
| #else | ||
| #define LIBC_ERRNO_MODE LIBC_ERRNO_MODE_SYSTEM_INLINE | ||
| #endif // LIBC_ERRNO_MODE | ||
|
|
||
| #ifndef LIBC_NAMESPACE | ||
vonosmas marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| #define LIBC_NAMESPACE __llvm_libc | ||
| #endif // LIBC_NAMESPACE | ||
|
|
||
| #endif // LLVM_LIBC_SHARED_LIBC_COMMON_H | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,108 @@ | ||
| //===-- Implementation header for libc_errno --------------------*- C++ -*-===// | ||
| // | ||
| // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. | ||
| // See https://llvm.org/LICENSE.txt for license information. | ||
| // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception | ||
| // | ||
| //===----------------------------------------------------------------------===// | ||
|
|
||
| #ifndef LLVM_LIBC_SRC___SUPPORT_LIBC_ERRNO_H | ||
| #define LLVM_LIBC_SRC___SUPPORT_LIBC_ERRNO_H | ||
|
|
||
| // This header is to be consumed by internal implementations, in which all of | ||
| // them should refer to `libc_errno` instead of using `errno` directly from | ||
| // <errno.h> header. | ||
|
|
||
| // Unit and hermetic tests should: | ||
| // - #include "src/__support/libc_errno.h" | ||
| // - NOT #include <errno.h> | ||
| // - Only use `libc_errno` in the code | ||
| // - Depend on libc.src.errno.errno | ||
|
|
||
| // Integration tests should: | ||
| // - NOT #include "src/__support/libc_errno.h" | ||
| // - #include <errno.h> | ||
| // - Use regular `errno` in the code | ||
| // - Still depend on libc.src.errno.errno | ||
|
|
||
| // 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). | ||
| #define LIBC_ERRNO_MODE_THREAD_LOCAL 2 | ||
| // libc maintains shared state used by all threads, contrary to standard C | ||
| // semantics unless always single-threaded; nothing prevents data races. | ||
| #define LIBC_ERRNO_MODE_SHARED 3 | ||
| // 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 | ||
| // 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. | ||
| #define LIBC_ERRNO_MODE_SYSTEM_INLINE 6 | ||
|
|
||
| #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_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 && \ | ||
| LIBC_ERRNO_MODE != LIBC_ERRNO_MODE_SYSTEM_INLINE | ||
| #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, \ | ||
| LIBC_ERRNO_MODE_EXTERNAL, \ | ||
| LIBC_ERRNO_MODE_SYSTEM, \ | ||
| LIBC_ERRNO_MODE_SYSTEM_INLINE. | ||
| #endif | ||
|
|
||
| #if LIBC_ERRNO_MODE == LIBC_ERRNO_MODE_SYSTEM_INLINE | ||
|
|
||
| #include <errno.h> | ||
|
|
||
| #define libc_errno errno | ||
|
|
||
| #else // !LIBC_ERRNO_MODE_SYSTEM_INLINE | ||
|
|
||
| #include "hdr/errno_macros.h" | ||
| #include "src/__support/macros/config.h" | ||
|
|
||
| namespace LIBC_NAMESPACE_DECL { | ||
|
|
||
| extern "C" int *__llvm_libc_errno() noexcept; | ||
|
|
||
| struct Errno { | ||
| void operator=(int); | ||
| operator int(); | ||
| }; | ||
|
|
||
| extern Errno libc_errno; | ||
|
|
||
| } // namespace LIBC_NAMESPACE_DECL | ||
|
|
||
| using LIBC_NAMESPACE::libc_errno; | ||
|
|
||
| #endif // LIBC_ERRNO_MODE_SYSTEM_INLINE | ||
|
|
||
| #endif // LLVM_LIBC_SRC___SUPPORT_LIBC_ERRNO_H |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,28 +1,16 @@ | ||
| # If we are in full build mode, we will provide the errno definition ourselves, | ||
| # and if we are in overlay mode, we will just re-use the system's errno. | ||
| # We are passing LIBC_FULL_BUILD flag in full build mode so that the | ||
| # implementation of libc_errno will know if we are in full build mode or not. | ||
|
|
||
| # TODO: Move LIBC_FULL_BUILD flag to _get_common_compile_options. | ||
| set(full_build_flag "") | ||
| if(LLVM_LIBC_FULL_BUILD) | ||
| set(full_build_flag "-DLIBC_FULL_BUILD") | ||
| endif() | ||
|
|
||
| if(LIBC_CONF_ERRNO_MODE) | ||
| set(errno_config_copts "-DLIBC_ERRNO_MODE=${LIBC_CONF_ERRNO_MODE}") | ||
| endif() | ||
|
|
||
| add_entrypoint_object( | ||
| errno | ||
| SRCS | ||
| libc_errno.cpp | ||
| HDRS | ||
| libc_errno.h # Include this | ||
| COMPILE_OPTIONS | ||
| ${full_build_flag} | ||
| ${errno_config_copts} | ||
| ../__support/libc_errno.h | ||
| DEPENDS | ||
| libc.hdr.errno_macros | ||
| libc.src.__support.common | ||
| libc.src.__support.libc_errno | ||
| libc.src.__support.macros.attributes | ||
| libc.src.__support.macros.config | ||
| ) |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.