Commit Graph

869 Commits

Author SHA1 Message Date
Michael Jones
3d9e646c7c [libc][obvious] fix missing stdio dependency
Differential Revision: https://reviews.llvm.org/D146482
2023-03-20 17:37:09 -07:00
Michael Jones
46b5087227 [libc] add basic wide char functions
This patch adds the wchar header, as well as the functions to convert to
and from wide chars. The header also sets up the definitions for wint
and wchar.

Reviewed By: lntue

Differential Revision: https://reviews.llvm.org/D145995
2023-03-20 16:36:21 -07:00
Michael Jones
99047c0501 [libc][bazel] add targets for sprintf
The bazel build is currently overlay mode only, so the FILE functions
are still out of reach for it, but sprintf only uses strings. This adds
targets for sprintf, snprintf, and all the interal printf pieces, as
well as tests.

Reviewed By: sivachandra, lntue

Differential Revision: https://reviews.llvm.org/D146100
2023-03-20 15:09:20 -07:00
Joseph Huber
ae30ae23aa [libc][NFC] Add some missing comments to the RPC implementation
Summary:
These comments were accidentally dropped from the committed version. Add
them back in.
2023-03-20 09:30:12 -05:00
Joseph Huber
8e4f9b1fcb [libc] Add initial support for an RPC mechanism for the GPU
This patch adds initial support for an RPC client / server architecture.
The GPU is unable to perform several system utilities on its own, so in
order to implement features like printing or memory allocation we need
to be able to communicate with the executing process. This is done via a
buffer of "sharable" memory. That is, a buffer with a unified pointer
that both the client and server can use to communicate.

The implementation here is based off of Jon Chesterfields minimal RPC
example in his work. We use an `inbox` and `outbox` to communicate
between if there is an RPC request and to signify when work is done.
We use a fixed-size buffer for the communication channel. This is fixed
size so that we can ensure that there is enough space for all
compute-units on the GPU to issue work to any of the ports. Right now
the implementation is single threaded so there is only a single buffer
that is not shared.

This implementation still has several features missing to be complete.
Such as multi-threaded support and asynchrnonous calls.

Depends on D145912

Reviewed By: sivachandra

Differential Revision: https://reviews.llvm.org/D145913
2023-03-17 12:55:31 -05:00
Mikhail R. Gadelha
1990ce74dc [libc] Enable __llvm_libc_syscall and fork
This patch enables the remaining calls from unistd.

The test cases had to be updated to:
1. Use SYS_symlinkat if SYS_symlink is not available
2. Use SYS_readlinkat if SYS_readlink is not available
3. Use SYS_unlinkat if SYS_unlink is not available
4. Use SYS_openat if SYS_open is not available

We also abort compilation if neither of the syscalls mentioned above are
available.

Differential Revision: https://reviews.llvm.org/D146161
2023-03-16 06:16:14 -03:00
Mikhail R. Gadelha
fe99de31d9 [libc] Enable spawn lib in riscv
In this patch we add support for the spawn lib in riscv.

Only small changes were required, the biggest one was to use of dup3
instead of dup2, if the latter is not available. This follows our
implementation of dup2.

Differential Revision: https://reviews.llvm.org/D146145
2023-03-16 06:16:14 -03:00
Tue Ly
e35c71493b [libc][NFC] Clean up clang-tidy warnings for src/__support and src/math.
Clean up some warnings from running libc-lint for these folders.

Reviewed By: michaelrj, sivachandra

Differential Revision: https://reviews.llvm.org/D146048
2023-03-15 18:47:31 -04:00
Guillaume Chatelet
a49118a3f4 [reland][libc][NFC] Move memcmp implementations in subfolders 2023-03-14 13:03:47 +00:00
Guillaume Chatelet
00c5233139 Revert "[libc][NFC] Move memcmp implementations in subfolders"
this broke arm32 build bots
This reverts commit 7f20e2a8d2.
2023-03-14 13:00:40 +00:00
Guillaume Chatelet
7f20e2a8d2 [libc][NFC] Move memcmp implementations in subfolders 2023-03-14 12:47:24 +00:00
Siva Chandra Reddy
547e345666 [libc] Make libc_errno point to internal errno for non-public builds.
The macro llvmlibc_errno has also been removed. This change completes
the switch to using a hermetic errno for unit tests.

Fixes #61037

Reviewed By: lntue

Differential Revision: https://reviews.llvm.org/D146005
2023-03-14 04:21:56 +00:00
Siva Chandra Reddy
55612b8ec4 [libc] Switch sys/stat implementations over to libc_errno.
Reviewed By: lntue

Differential Revision: https://reviews.llvm.org/D146004
2023-03-14 04:02:45 +00:00
Siva Chandra Reddy
7e6462d90c [libc][NFC] Switch nanosleep_test and getcwd_test to libc_errno. 2023-03-14 01:25:47 +00:00
Siva Chandra Reddy
bb03705726 [libc] Switch termios implementations to libc_errno. 2023-03-14 01:00:58 +00:00
Siva Chandra Reddy
adff2b291c [libc][NFC] Switch all uses of errno in math and math tests to libc_errno. 2023-03-13 22:22:00 +00:00
Siva Chandra
c1bb7108a2 [libc] Special case sniffing of thread start args for riscv. 2023-03-13 07:29:35 +00:00
Siva Chandra
cf90633cf2 [libc] Extend the linux thread implementation for riscv64.
Also, added riscv64 startup code for static linking which is used
by the integration tests. Functions from the C standard threads
library have been enabled.

Reviewed By: mikhail.ramalho

Differential Revision: https://reviews.llvm.org/D145670
2023-03-09 16:58:48 +00:00
Joseph Huber
fdd710e69c [libc] Add missing header for LIBC_INLINE macro
Summray:
Forgot to do this in the last patch
2023-03-09 06:45:50 -06:00
Joseph Huber
a9cb298b39 [libc] Add intrinsic for thread fence to the atomic support
This function mimics the std::atomic_thread_fence function from
<atomic>. This has no uses in source currently, but this will be used by
the proposed RPC client for the GPU mode support. There is varying
support for direct memory ordering for the GPU atomics on shared memory
resources. So the implementation will use relaxed atomics and explicit
memory fences.

Some additional work may need to be done to map this to `NVPTX` system
level fences.

Reviewed By: sivachandra

Differential Revision: https://reviews.llvm.org/D145608
2023-03-09 06:36:54 -06:00
Siva Chandra Reddy
b32acff7b7 [libc][Obvious] Fix bad include and type in threads/tss_get.h. 2023-03-09 08:38:32 +00:00
Mikhail R. Gadelha
e9be85da8b [libc] Add fenv_t and signal macros in riscv
This patch now enables full build.

Reviewed By: sivachandra

Differential Revision: https://reviews.llvm.org/D145594
2023-03-08 17:31:58 -03:00
Mikhail R. Gadelha
f1f052f9b0 [libc] Add support for sqrt in riscv
Reviewed By: lntue

Differential Revision: https://reviews.llvm.org/D145593
2023-03-08 16:20:37 -03:00
Mikhail R. Gadelha
ac763b9fdf [libc] Add support for fma in riscv
Reviewed By: lntue

Differential Revision: https://reviews.llvm.org/D145592
2023-03-08 16:15:24 -03:00
Siva Chandra
6f8dfeee06 [libc] Add riscv64 fenv implementation and enable the fenv.h functions.
Reviewed By: mikhail.ramalho

Differential Revision: https://reviews.llvm.org/D145560
2023-03-08 10:49:24 -03:00
Mikhail R. Gadelha
0ffea21893 [libc] Small improvements to libc cmake
This patch includes:
1. Better error message when cmake finds incompatible triple
2. Added missing header dependencies libc/include/CMakeLists.txt as per
   app.td
3. Removed unused $LLVM_LIBC_INCLUDE_DIRS cmake variable

Reviewed By: sivachandra

Differential Revision: https://reviews.llvm.org/D145496
2023-03-08 09:02:02 -03:00
Siva Chandra
9ca2fb8217 [libc] Add riscv64 syscall implementation.
All syscall wrapper functions which have unit tests have been enabled.

Reviewed By: kito-cheng

Differential Revision: https://reviews.llvm.org/D145452
2023-03-07 21:47:58 -03:00
Tue Ly
31c39439a8 [libc][math] Switch math functions to use libc_errno and fix some errno and floating point exceptions.
Switch math functions to use libc_errno and fix some errno and
floating point exceptions

Reviewed By: sivachandra

Differential Revision: https://reviews.llvm.org/D145349
2023-03-07 00:51:16 -05:00
Siva Chandra
f7e91f2b82 [libc] Add riscv64 config.
Memory functions get the basic implementation. They can be tuned
as a follow up.

Reviewed By: michaelrj, lntue

Differential Revision: https://reviews.llvm.org/D145433
2023-03-06 23:03:43 +00:00
Siva Chandra Reddy
d49b993f0d [libc][NFC] Switch dirent, fcntl, inttypes and sched to use libc_errno.
Reviewed By: michaelrj

Differential Revision: https://reviews.llvm.org/D145222
2023-03-06 22:24:51 +00:00
Siva Chandra Reddy
772e37f893 [libc] Add ALIAS option to add_object_library rule.
This ALIAS option is now used with threads/callonce target.

Reviewed By: lntue

Differential Revision: https://reviews.llvm.org/D145409
2023-03-06 22:11:33 +00:00
Siva Chandra Reddy
ae8e1b8fc3 [libc] Add arm 32 FEnvImpl.
Reviewed By: lntue

Differential Revision: https://reviews.llvm.org/D145347
2023-03-06 15:57:37 +00:00
Siva Chandra Reddy
7abf6c2524 [libc] Switch signal and termios to libc_errno.
Reviewed By: michaelrj

Differential Revision: https://reviews.llvm.org/D145274
2023-03-05 03:58:54 +00:00
Siva Chandra Reddy
ab07fd9ffa [libc][Obvious] Add the LIBC_INLINE tag to a function define in a.h file. 2023-03-05 02:58:45 +00:00
Alex Brachet
96ff21243e [libc] Fix strspn 2023-03-03 19:51:46 +00:00
Michael Jones
04a9c62554 [libc] move stdlib and stdio to new errno pattern
Fixes https://github.com/llvm/llvm-project/issues/61071

Reviewed By: sivachandra

Differential Revision: https://reviews.llvm.org/D145191
2023-03-03 11:15:36 -08:00
Siva Chandra Reddy
4052bc8674 [libc] Make errno an entrypoint.
The entrypoint has been added to the various entrypoint lists. The libc
code style doc has been updated with information on how errno should be
set from the libc runtime code.

Reviewed By: lntue

Differential Revision: https://reviews.llvm.org/D145179
2023-03-03 06:59:19 +00:00
Raman Tenneti
b98c1906d6 [libc][NFC] Switch use of errno in src/time and test/src/time to libc_errno.
Switch use of errno in src/time and test/src/time to libc_errno.

Reviewed By: sivachandra

Differential Revision: https://reviews.llvm.org/D145192
2023-03-02 14:41:19 -08:00
Michael Jones
803437db15 [libc][obvious] Fix errno includes in unistd
Minor typo swapped quotes for angle brackets. This patch moves
everything to quotes.

Differential Revision: https://reviews.llvm.org/D145188
2023-03-02 14:04:53 -08:00
Siva Chandra Reddy
204587a3cb [libc][NFC] Switch use of errno in src/unistd and src/sys to libc_errno.
Reviewed By: lntue

Differential Revision: https://reviews.llvm.org/D145096
2023-03-02 17:15:10 +00:00
Michael Jones
effd56b0a0 [libc] add basic Intel MacOS configuration
The config is based on the ARM MacOS config, but with fenv and math
functions disabled.

This should unblock this bug: https://github.com/llvm/llvm-project/issues/60910

Reviewed By: sivachandra

Differential Revision: https://reviews.llvm.org/D145099
2023-03-01 15:33:16 -08:00
Alex Brachet
c891ef6ca0 [libc] Fix strcspn
Differential Revision: https://reviews.llvm.org/D144995
2023-03-01 18:57:53 +00:00
Michael Jones
b39f1e5c13 [libc] Fix printf %f rounding condition
When running the tbin2dec tests I found a rounding error in my code.
Upon inspection I realized it was due to a lack of parenthesis when
calculating the number of trailing digits. This patch fixes that mistake
and adds unit tests to catch regressions in future.

Reviewed By: lntue

Differential Revision: https://reviews.llvm.org/D145011
2023-03-01 10:57:26 -08:00
Siva Chandra Reddy
110ee16467 [libc][NFC] Refactor internal errno.
This is in preparation for the transition to a solution to make libc tests
hermetic with respect to their use of errno. The implementation of strdup
has been switched over to libc_errno as an example of what the code looks
like in the new way.

See #61037 for more information.

Reviewed By: lntue

Differential Revision: https://reviews.llvm.org/D144928
2023-02-28 20:40:42 +00:00
Michael Jones
cb3c41c285 [libc] Refactor string to float return values
The internal implementation of the string to float function previously
used pointer arguments for returning several values. Additionally it
set errno in several unexpected places. Now all of that goes through
return structs. For readability I also moved the function away from raw
pointer arithmetic towards proper indexing. I also added support for
rounding modes.

Reviewed By: sivachandra

Differential Revision: https://reviews.llvm.org/D144597
2023-02-28 10:50:43 -08:00
Michael Jones
8f0814f5dc [libc] Clarify printf percent conversion behavior.
Almost all printf conversions ending in '%' are undefined, but they're
traditionally treated as if the complete conversion specifier is "%%".
This patch modifies the parser to more closely match that behavior.

Reviewed By: sivachandra

Differential Revision: https://reviews.llvm.org/D144679
2023-02-24 13:29:30 -08:00
Tue Ly
0aa9593c2f [libc][math] Set floating point exceptions for exp*f, sinhf, and coshf.
Set FE_OVERFLOW and FE_UNDERFLOW for expf, exp2f, exp10f, expm1f, sinhf
and coshf.

Reviewed By: sivachandra, renyichen

Differential Revision: https://reviews.llvm.org/D144340
2023-02-24 12:56:39 -05:00
Michael Jones
bf279f903b [libc] Prevent printf index mode crashes
The posix standard defines an alternate mode for printf where the
conversions also have an index that describes which argument to select.
Due to how variadic arguments work in C, to reach the nth argument all
n-1 previous arguments must be read with their correct types. If the
format string does not specify the types for a continuous set of
arguments, then the arguments after the discontinuity cannot be safely
read. This patch causes all conversions requesting an argument that
comes after a gap be treated as raw (i.e. the conversion string is
printed literally).

Reviewed By: sivachandra

Differential Revision: https://reviews.llvm.org/D143782
2023-02-22 16:27:26 -08:00
Joseph Huber
f7b7c698eb [libc] Partially implement 'quick_exit' for the GPU
This patch adds a partial implementation of `quick_exit` for the GPU
target. This is mainly done to test object libraries for the GPU and
will be expanded later. This will simply cause the threads to terminate
on the GPU without returning an error code. This functionality will be
added later to facilitate unit tests.

Reviewed By: sivachandra

Differential Revision: https://reviews.llvm.org/D144421
2023-02-22 13:10:16 -06:00
Raman Tenneti
d0d6d78bbd [libc] Implement ntohl and ntohs
Per spec:

https://pubs.opengroup.org/onlinepubs/9699919799/functions/ntohl.html
https://pubs.opengroup.org/onlinepubs/9699919799/functions/ntohs.html

Co-authored-by: Jeff Bailey <jbailey@google.com>

Reviewed By: sivachandra

Differential Revision: https://reviews.llvm.org/D144506
2023-02-22 10:40:38 -08:00