-
Notifications
You must be signed in to change notification settings - Fork 14.3k
[libc] Add strerror
and strerror_k
to the GPU
#99083
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
Conversation
@llvm/pr-subscribers-libc Author: Joseph Huber (jhuber6) ChangesSummary: Full diff: https://github.com/llvm/llvm-project/pull/99083.diff 2 Files Affected:
diff --git a/libc/config/gpu/entrypoints.txt b/libc/config/gpu/entrypoints.txt
index 63228216c85ec..36c5b8c808528 100644
--- a/libc/config/gpu/entrypoints.txt
+++ b/libc/config/gpu/entrypoints.txt
@@ -47,6 +47,8 @@ set(TARGET_LIBC_ENTRYPOINTS
libc.src.string.strcpy
libc.src.string.strcspn
libc.src.string.strdup
+ libc.src.string.strerror
+ libc.src.string.strerror_r
libc.src.string.strlcat
libc.src.string.strlcpy
libc.src.string.strlen
diff --git a/libc/test/src/string/strerror_test.cpp b/libc/test/src/string/strerror_test.cpp
index cfc79481699bc..6c59c709df24b 100644
--- a/libc/test/src/string/strerror_test.cpp
+++ b/libc/test/src/string/strerror_test.cpp
@@ -6,153 +6,16 @@
//
//===----------------------------------------------------------------------===//
+#include "src/__support/StringUtil/platform_errors.h"
+#include "src/__support/macros/properties/architectures.h"
#include "src/string/strerror.h"
#include "test/UnitTest/Test.h"
TEST(LlvmLibcStrErrorTest, KnownErrors) {
ASSERT_STREQ(LIBC_NAMESPACE::strerror(0), "Success");
- const char *message_array[] = {
- "Success",
- "Operation not permitted",
- "No such file or directory",
- "No such process",
- "Interrupted system call",
- "Input/output error",
- "No such device or address",
- "Argument list too long",
- "Exec format error",
- "Bad file descriptor",
- "No child processes",
- "Resource temporarily unavailable",
- "Cannot allocate memory",
- "Permission denied",
- "Bad address",
- "Block device required",
- "Device or resource busy",
- "File exists",
- "Invalid cross-device link",
- "No such device",
- "Not a directory",
- "Is a directory",
- "Invalid argument",
- "Too many open files in system",
- "Too many open files",
- "Inappropriate ioctl for device",
- "Text file busy",
- "File too large",
- "No space left on device",
- "Illegal seek",
- "Read-only file system",
- "Too many links",
- "Broken pipe",
- "Numerical argument out of domain",
- "Numerical result out of range",
- "Resource deadlock avoided",
- "File name too long",
- "No locks available",
- "Function not implemented",
- "Directory not empty",
- "Too many levels of symbolic links",
- "Unknown error 41", // Unknown
- "No message of desired type",
- "Identifier removed",
- "Channel number out of range",
- "Level 2 not synchronized",
- "Level 3 halted",
- "Level 3 reset",
- "Link number out of range",
- "Protocol driver not attached",
- "No CSI structure available",
- "Level 2 halted",
- "Invalid exchange",
- "Invalid request descriptor",
- "Exchange full",
- "No anode",
- "Invalid request code",
- "Invalid slot",
- "Unknown error 58", // Unknown
- "Bad font file format",
- "Device not a stream",
- "No data available",
- "Timer expired",
- "Out of streams resources",
- "Machine is not on the network",
- "Package not installed",
- "Object is remote",
- "Link has been severed",
- "Advertise error",
- "Srmount error",
- "Communication error on send",
- "Protocol error",
- "Multihop attempted",
- "RFS specific error",
- "Bad message",
- "Value too large for defined data type",
- "Name not unique on network",
- "File descriptor in bad state",
- "Remote address changed",
- "Can not access a needed shared library",
- "Accessing a corrupted shared library",
- ".lib section in a.out corrupted",
- "Attempting to link in too many shared libraries",
- "Cannot exec a shared library directly",
- "Unknown error 84", // Unknown
- "Interrupted system call should be restarted",
- "Streams pipe error",
- "Too many users",
- "Socket operation on non-socket",
- "Destination address required",
- "Message too long",
- "Protocol wrong type for socket",
- "Protocol not available",
- "Protocol not supported",
- "Socket type not supported",
- "Operation not supported",
- "Protocol family not supported",
- "Address family not supported by protocol",
- "Address already in use",
- "Cannot assign requested address",
- "Network is down",
- "Network is unreachable",
- "Network dropped connection on reset",
- "Software caused connection abort",
- "Connection reset by peer",
- "No buffer space available",
- "Transport endpoint is already connected",
- "Transport endpoint is not connected",
- "Cannot send after transport endpoint shutdown",
- "Too many references: cannot splice",
- "Connection timed out",
- "Connection refused",
- "Host is down",
- "No route to host",
- "Operation already in progress",
- "Operation now in progress",
- "Stale file handle",
- "Structure needs cleaning",
- "Not a XENIX named type file",
- "No XENIX semaphores available",
- "Is a named type file",
- "Remote I/O error",
- "Disk quota exceeded",
- "No medium found",
- "Wrong medium type",
- "Operation canceled",
- "Required key not available",
- "Key has expired",
- "Key has been revoked",
- "Key was rejected by service",
- "Owner died",
- "State not recoverable",
- "Operation not possible due to RF-kill",
- "Memory page has hardware error",
- };
-
- for (size_t i = 0; i < (sizeof(message_array) / sizeof(char *)); ++i) {
- EXPECT_STREQ(LIBC_NAMESPACE::strerror(static_cast<int>(i)),
- message_array[i]);
- }
+ for (auto [i, msg] : LIBC_NAMESPACE::PLATFORM_ERRORS)
+ EXPECT_STREQ(LIBC_NAMESPACE::strerror(static_cast<int>(i)), msg.begin());
}
TEST(LlvmLibcStrErrorTest, UnknownErrors) {
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
While you're doing this, could you also readd EILSEQ
? It's a C standard error so we do need to provide it.
It just needs to be added to libc/include/llvm-libc-macros/generic-error-number-macros.h
and added back to the list of error strings (see jplehr@aea35ab).
message_array[i]); | ||
} | ||
for (auto [i, msg] : LIBC_NAMESPACE::PLATFORM_ERRORS) | ||
EXPECT_STREQ(LIBC_NAMESPACE::strerror(static_cast<int>(i)), msg.begin()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm somewhat hesitant to do it this way, since it's effectively comparing the values against themselves, but I can't think of a better solution.
Summary: The GPU ignores `errno` primarily, but targets want these functions to be defined for certain C standard interfaces. This patch enables them and makes the test function on non-Linux targets.
Summary: The GPU ignores `errno` primarily, but targets want these functions to be defined for certain C standard interfaces. This patch enables them and makes the test function on non-Linux targets. Test Plan: Reviewers: Subscribers: Tasks: Tags: Differential Revision: https://phabricator.intern.facebook.com/D60251599
Summary:
The GPU ignores
errno
primarily, but targets want these functions tobe defined for certain C standard interfaces. This patch enables them
and makes the test function on non-Linux targets.