-
Notifications
You must be signed in to change notification settings - Fork 14.5k
[libc] Update libc_errno to work correctly in both overlay and full build modes. #80177
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
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,40 +1,48 @@ | ||
//===-- Implementation of errno -------------------------------------------===// | ||
//===-- Implementation of libc_errno --------------------------------------===// | ||
// | ||
// 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 | ||
// | ||
//===----------------------------------------------------------------------===// | ||
|
||
#include "src/__support/macros/attributes.h" | ||
#include "src/__support/macros/properties/architectures.h" | ||
|
||
namespace LIBC_NAMESPACE { | ||
#include "libc_errno.h" | ||
|
||
#ifdef LIBC_TARGET_ARCH_IS_GPU | ||
struct ErrnoConsumer { | ||
void operator=(int) {} | ||
}; | ||
#endif | ||
// LIBC_THREAD_LOCAL on GPU currently does nothing. So essentially this is just | ||
// a global errno for gpu to use for now. | ||
extern "C" { | ||
LIBC_THREAD_LOCAL int __llvmlibc_gpu_errno; | ||
} | ||
|
||
void LIBC_NAMESPACE::Errno::operator=(int a) { __llvmlibc_gpu_errno = a; } | ||
LIBC_NAMESPACE::Errno::operator int() { return __llvmlibc_gpu_errno; } | ||
|
||
#elif !defined(LIBC_COPT_PUBLIC_PACKAGING) | ||
// This mode is for unit testing. We just use our internal errno. | ||
LIBC_THREAD_LOCAL int __llvmlibc_internal_errno; | ||
|
||
void LIBC_NAMESPACE::Errno::operator=(int a) { __llvmlibc_internal_errno = a; } | ||
LIBC_NAMESPACE::Errno::operator int() { return __llvmlibc_internal_errno; } | ||
|
||
#elif defined(LIBC_FULL_BUILD) | ||
// This mode is for public libc archive, hermetic, and integration tests. | ||
// In full build mode, we provide the errno storage ourselves. | ||
extern "C" { | ||
#ifdef LIBC_COPT_PUBLIC_PACKAGING | ||
// TODO: Declare __llvmlibc_errno only under LIBC_COPT_PUBLIC_PACKAGING and | ||
// __llvmlibc_internal_errno otherwise. | ||
// In overlay mode, this will be an unused thread local variable as libc_errno | ||
// will resolve to errno from the system libc's errno.h. In full build mode | ||
// however, libc_errno will resolve to this thread local variable via the errno | ||
// macro defined in LLVM libc's public errno.h header file. | ||
// TODO: Use a macro to distinguish full build and overlay build which can be | ||
// used to exclude __llvmlibc_errno under overlay build. | ||
#ifdef LIBC_TARGET_ARCH_IS_GPU | ||
ErrnoConsumer __llvmlibc_errno; | ||
#else | ||
LIBC_THREAD_LOCAL int __llvmlibc_errno; | ||
#endif // LIBC_TARGET_ARCH_IS_GPU | ||
} | ||
|
||
void LIBC_NAMESPACE::Errno::operator=(int a) { __llvmlibc_errno = a; } | ||
LIBC_NAMESPACE::Errno::operator int() { return __llvmlibc_errno; } | ||
|
||
#else | ||
LIBC_THREAD_LOCAL int __llvmlibc_internal_errno; | ||
#endif | ||
} // extern "C" | ||
// In overlay mode, we simply use the system errno. | ||
#include <errno.h> | ||
|
||
void LIBC_NAMESPACE::Errno::operator=(int a) { errno = a; } | ||
LIBC_NAMESPACE::Errno::operator int() { return errno; } | ||
|
||
#endif // LIBC_FULL_BUILD | ||
|
||
} // namespace LIBC_NAMESPACE | ||
// Define the global `libc_errno` instance. | ||
LIBC_NAMESPACE::Errno libc_errno; |
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
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.