Skip to content

Commit f7cee44

Browse files
authored
[libc] Add strerror and strerror_k to the GPU (#99083)
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.
1 parent 434c238 commit f7cee44

File tree

4 files changed

+9
-142
lines changed

4 files changed

+9
-142
lines changed

libc/config/gpu/entrypoints.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,8 @@ set(TARGET_LIBC_ENTRYPOINTS
4747
libc.src.string.strcpy
4848
libc.src.string.strcspn
4949
libc.src.string.strdup
50+
libc.src.string.strerror
51+
libc.src.string.strerror_r
5052
libc.src.string.strlcat
5153
libc.src.string.strlcpy
5254
libc.src.string.strlen

libc/include/llvm-libc-macros/generic-error-number-macros.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,5 +43,6 @@
4343
#define EPIPE 32
4444
#define EDOM 33
4545
#define ERANGE 34
46+
#define EILSEQ 84
4647

4748
#endif // LLVM_LIBC_MACROS_GENERIC_ERROR_NUMBER_MACROS_H

libc/src/__support/StringUtil/tables/stdc_errors.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,11 @@
1616

1717
namespace LIBC_NAMESPACE_DECL {
1818

19-
LIBC_INLINE_VAR constexpr const MsgTable<3> STDC_ERRORS = {
19+
LIBC_INLINE_VAR constexpr const MsgTable<4> STDC_ERRORS = {
2020
MsgMapping(0, "Success"),
2121
MsgMapping(EDOM, "Numerical argument out of domain"),
2222
MsgMapping(ERANGE, "Numerical result out of range"),
23+
MsgMapping(EILSEQ, "Invalid or incomplete multibyte or wide character"),
2324
};
2425

2526
} // namespace LIBC_NAMESPACE_DECL

libc/test/src/string/strerror_test.cpp

Lines changed: 4 additions & 141 deletions
Original file line numberDiff line numberDiff line change
@@ -6,153 +6,16 @@
66
//
77
//===----------------------------------------------------------------------===//
88

9+
#include "src/__support/StringUtil/platform_errors.h"
10+
#include "src/__support/macros/properties/architectures.h"
911
#include "src/string/strerror.h"
1012
#include "test/UnitTest/Test.h"
1113

1214
TEST(LlvmLibcStrErrorTest, KnownErrors) {
1315
ASSERT_STREQ(LIBC_NAMESPACE::strerror(0), "Success");
1416

15-
const char *message_array[] = {
16-
"Success",
17-
"Operation not permitted",
18-
"No such file or directory",
19-
"No such process",
20-
"Interrupted system call",
21-
"Input/output error",
22-
"No such device or address",
23-
"Argument list too long",
24-
"Exec format error",
25-
"Bad file descriptor",
26-
"No child processes",
27-
"Resource temporarily unavailable",
28-
"Cannot allocate memory",
29-
"Permission denied",
30-
"Bad address",
31-
"Block device required",
32-
"Device or resource busy",
33-
"File exists",
34-
"Invalid cross-device link",
35-
"No such device",
36-
"Not a directory",
37-
"Is a directory",
38-
"Invalid argument",
39-
"Too many open files in system",
40-
"Too many open files",
41-
"Inappropriate ioctl for device",
42-
"Text file busy",
43-
"File too large",
44-
"No space left on device",
45-
"Illegal seek",
46-
"Read-only file system",
47-
"Too many links",
48-
"Broken pipe",
49-
"Numerical argument out of domain",
50-
"Numerical result out of range",
51-
"Resource deadlock avoided",
52-
"File name too long",
53-
"No locks available",
54-
"Function not implemented",
55-
"Directory not empty",
56-
"Too many levels of symbolic links",
57-
"Unknown error 41", // Unknown
58-
"No message of desired type",
59-
"Identifier removed",
60-
"Channel number out of range",
61-
"Level 2 not synchronized",
62-
"Level 3 halted",
63-
"Level 3 reset",
64-
"Link number out of range",
65-
"Protocol driver not attached",
66-
"No CSI structure available",
67-
"Level 2 halted",
68-
"Invalid exchange",
69-
"Invalid request descriptor",
70-
"Exchange full",
71-
"No anode",
72-
"Invalid request code",
73-
"Invalid slot",
74-
"Unknown error 58", // Unknown
75-
"Bad font file format",
76-
"Device not a stream",
77-
"No data available",
78-
"Timer expired",
79-
"Out of streams resources",
80-
"Machine is not on the network",
81-
"Package not installed",
82-
"Object is remote",
83-
"Link has been severed",
84-
"Advertise error",
85-
"Srmount error",
86-
"Communication error on send",
87-
"Protocol error",
88-
"Multihop attempted",
89-
"RFS specific error",
90-
"Bad message",
91-
"Value too large for defined data type",
92-
"Name not unique on network",
93-
"File descriptor in bad state",
94-
"Remote address changed",
95-
"Can not access a needed shared library",
96-
"Accessing a corrupted shared library",
97-
".lib section in a.out corrupted",
98-
"Attempting to link in too many shared libraries",
99-
"Cannot exec a shared library directly",
100-
"Unknown error 84", // Unknown
101-
"Interrupted system call should be restarted",
102-
"Streams pipe error",
103-
"Too many users",
104-
"Socket operation on non-socket",
105-
"Destination address required",
106-
"Message too long",
107-
"Protocol wrong type for socket",
108-
"Protocol not available",
109-
"Protocol not supported",
110-
"Socket type not supported",
111-
"Operation not supported",
112-
"Protocol family not supported",
113-
"Address family not supported by protocol",
114-
"Address already in use",
115-
"Cannot assign requested address",
116-
"Network is down",
117-
"Network is unreachable",
118-
"Network dropped connection on reset",
119-
"Software caused connection abort",
120-
"Connection reset by peer",
121-
"No buffer space available",
122-
"Transport endpoint is already connected",
123-
"Transport endpoint is not connected",
124-
"Cannot send after transport endpoint shutdown",
125-
"Too many references: cannot splice",
126-
"Connection timed out",
127-
"Connection refused",
128-
"Host is down",
129-
"No route to host",
130-
"Operation already in progress",
131-
"Operation now in progress",
132-
"Stale file handle",
133-
"Structure needs cleaning",
134-
"Not a XENIX named type file",
135-
"No XENIX semaphores available",
136-
"Is a named type file",
137-
"Remote I/O error",
138-
"Disk quota exceeded",
139-
"No medium found",
140-
"Wrong medium type",
141-
"Operation canceled",
142-
"Required key not available",
143-
"Key has expired",
144-
"Key has been revoked",
145-
"Key was rejected by service",
146-
"Owner died",
147-
"State not recoverable",
148-
"Operation not possible due to RF-kill",
149-
"Memory page has hardware error",
150-
};
151-
152-
for (size_t i = 0; i < (sizeof(message_array) / sizeof(char *)); ++i) {
153-
EXPECT_STREQ(LIBC_NAMESPACE::strerror(static_cast<int>(i)),
154-
message_array[i]);
155-
}
17+
for (auto [i, msg] : LIBC_NAMESPACE::PLATFORM_ERRORS)
18+
EXPECT_STREQ(LIBC_NAMESPACE::strerror(static_cast<int>(i)), msg.begin());
15619
}
15720

15821
TEST(LlvmLibcStrErrorTest, UnknownErrors) {

0 commit comments

Comments
 (0)