434 Commits

Author SHA1 Message Date
Joseph Huber
f7cee44ef2
[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.
2024-07-16 16:17:01 -05:00
Joseph Huber
94ed08d6b2
[libc] Enable 'wchar.h' for the GPU (#98973)
Summary:
This file is not really well populated, but is required for some targets
to configure. Enable it on the GPU for now.
2024-07-15 22:21:17 -05:00
aaryanshukla
34e06dc371
[libc] newheadergen: added assert.yaml (#98826)
- removed assert macro definitions in api.td
- included macro definitions in assert.h.def
- added assert.yaml
2024-07-15 16:52:32 -07:00
Akiel
3604c23dfc
[libc][math] implement signbit and math macro unit tests (#97791)
This PR resolves #96322 and implements the `signbit` macro under a new
header `generic-math-macros.h`. This also removed the `TODO` in
`math-macros.h` and moves `isfinite`, `isinf`, and `isnan` to the same
generic maths header. Finally, a test file
`generic-math-macros_test.cpp` that adds coverage to the above 4 macros.

Fixes #96322.
2024-07-13 23:01:36 -04:00
Petr Hosek
69258491d2
[libc] Support configurable errno modes (#98287)
Rather than selecting the errno implementation based on the platform
which doesn't provide the necessary flexibility, make it configurable.

The errno value location is returned by `int *__llvm_libc_errno()` which
is a common design used by other C libraries.
2024-07-13 10:52:42 -07:00
Joseph Huber
40effc7af5
[libc] Implement (v|f)printf on the GPU (#96369)
Summary:
This patch implements the `printf` family of functions on the GPU using
the new variadic support. This patch adapts the old handling in the
`rpc_fprintf` placeholder, but adds an extra RPC call to get the size of
the buffer to copy. This prevents the GPU from needing to parse the
string. While it's theoretically possible for the pass to know the size
of the struct, it's prohibitively difficult to do while maintaining ABI
compatibility with NVIDIA's varargs.

Depends on https://github.com/llvm/llvm-project/pull/96015.
2024-07-12 19:36:13 -05:00
Petr Hosek
6cbea4880e
[libc] Define HUGE_VALF in math.h (#98522)
This is analogous to `HUGE_VAL`.
2024-07-11 14:18:38 -07:00
Michael Jones
5aed6d67e3
Reland: [libc] Move off_t and stdio macros to proxy hdrs (#98384)
reland of https://github.com/llvm/llvm-project/pull/98215

Additionally adds proxy headers for FILE and the fopencookie types

The arm32 build has been failing due to redefinitions of the off_t type.
This patch fixes this by moving off_t to a proper proxy header. To do
this, it also moves stdio macros to a proxy header to hopefully avoid
including this proxy header alongside this public stdio.h.
2024-07-11 11:09:51 -07:00
Petr Hosek
b6e41c159b
[libc] Provide isnan, isnanf and isnanl functions (#96008)
While C99 defines type generic isnan macro, BSD provided isnan, isnanf
and isnanl in prior C standards and existing code still relies on these.
2024-07-09 21:28:51 -07:00
Michael Jones
3a744283f4
Revert "[libc] Move off_t and stdio macros to proxy hdrs" (#98242)
Reverts llvm/llvm-project#98215

Breaks linux bots
2024-07-09 16:22:38 -07:00
Michael Jones
240ec5a375
[libc] Move off_t and stdio macros to proxy hdrs (#98215)
The arm32 build has been failing due to redefinitions of the off_t type.
This patch fixes this by moving off_t to a proper proxy header. To do
this, it also moves stdio macros to a proxy header to hopefully avoid
including this proxy header alongside this public stdio.h.
2024-07-09 16:17:02 -07:00
Joseph Huber
d358151a4f Reapply "[libc] Make GPU libm use generic implementations" (#98061)
This reverts commit ea3fd020f4879d5b4261eabd9a56c24f30bc47f9.
2024-07-08 15:02:05 -05:00
Mehdi Amini
ea3fd020f4
Revert "[libc] Make GPU libm use generic implementations" (#98061)
Reverts llvm/llvm-project#98014

buildbot is broken.
2024-07-08 20:17:35 +02:00
Joseph Huber
5c40e561bb
[libc] Make GPU libm use generic implementations (#98014)
Summary:
This patch moves a lot of the old vendor implementations to the new
generic math functions. Previously a lot of these were done through the
vendor functions, but the long term goal is to completely phase these
out. In order to make the tests pass I had to disable exceptions so they
only perform functional tests.
2024-07-08 08:48:53 -05:00
Nhat Nguyen
7f3c40a661
[libc] implement pathconf/fpathconf (#87165) 2024-07-07 11:20:49 -07:00
Schrodinger ZHU Yifan
1acb08660a
Revert "[libc] Add link.h and elf.h headers" (#97931)
Reverts llvm/llvm-project#97924
2024-07-06 18:32:13 -07:00
Izaak Schroeder
ba255076a0
[libc] Add link.h and elf.h headers (#97924)
Headers for https://github.com/llvm/llvm-project/pull/97504
2024-07-06 18:17:34 -07:00
Izaak Schroeder
ccf357ff64
[libc] Add dlfcn.h headers (#97772) 2024-07-05 22:02:04 -07:00
Joseph Huber
3c64a98180
[libc] Partially implement 'errno' on the GPU (#97107)
Summary:
The `errno` variable is expected to be `thread_local` by the standard.
However, the GPU targets do not support `thread_local` and implementing
that would be a large endeavor. Because of that, we previously didn't
provide the `errno` symbol at all. However, to build some programs we at
least need to be able to link against `errno`. Many things that would
normally set `errno` completely ignore it currently (i.e. stdio) but
some programs still need to be able to link against correct C programs.

For this purpose this patch exports the `errno` symbol as a simple
global. Internally, this will be updated atomically so it's at least not
racy. Externally, this will be on the user. I've updated the
documentation to state as such. This is required to get `libc++` to
build.
2024-07-01 06:30:15 -05:00
Joseph Huber
ec0e6ef09b
[libc] Implement the 'remove' function on the GPU (#97096)
Summary:
Straightforward RPC implementation of the `remove` function for the GPU.
Copies over the string and calls `remove` on it, passing the result
back. This is required for building some `libc++` functionality.
2024-07-01 06:29:48 -05:00
Izaak Schroeder
74852bfa4c
[libc]: fix missing linux/error-number-macros.h (#97101)
The headers installation previously missed platform-specific number
macros, and this fixes that. From discussion on LLVM discord with
`michaelrj` – ccing @michaelrj-google who hopefully is the same person 😅

N.B. I have tested this manually in my Linux Dockerfile and it appears
to do the right thing; I haven't done much more than that.
2024-06-28 14:55:25 -05:00
Michael Jones
808e0f1c46
[libc] remove include_file headergen usage (#96970)
Previously headergen had a mechanism to copy the contents of one file
inot another. This wasn't ever used properly, and isn't supported by the
new headergen design. We will investigate better ways to support
different syscall definitions in future.
2024-06-28 10:27:32 -07:00
OverMighty
e34dbb127a
[libc][math][c23] Add f16fma{,l,f128} C23 math function (#96711)
Part of #93566.
2024-06-27 14:44:19 -04:00
Nick Desaulniers (paternity leave)
bea7f3d873
[libc][startup] create header for ElfW and use in startup (#96510)
This is necessary for 32b platforms such as ARM and i386.

Link: #94128
2024-06-24 14:37:50 -07:00
Nick Desaulniers (paternity leave)
f1ce6a465d
[libc][arm] implement a basic setjmp/longjmp (#93220)
Note: our baremetal arm configuration compiles this as
`--target=arm-none-eabi`, so this code is built in -marm mode. It could be
smaller with `--target=armv7-none-eabi -mthumb`. The assembler is valid ARMv5,
or THUMB2, but not THUMB(1).
2024-06-20 08:16:48 -07:00
Schrodinger ZHU Yifan
41fecca97b
[libc] add rwlock (#94156) 2024-06-14 13:34:28 -07:00
Joseph Huber
d6bbe2e20f
[libc] Fix definition of UINT_MAX in limits.h (#95279)
Summary:
Currently we use `(~0U)` for this definition, however the ~ operator
returns a different sign, meaning that preprocessor checks against this
value will fail. See https://godbolt.org/z/TrjaY1d8q where the
preprocessor thinks that it's not `0xffffffff` while the static
assertion thinks it is. This is because the latter does implicit
conversion but the preprocessor does not. This is now consistent with
other headers.
2024-06-12 15:29:10 -05:00
OverMighty
a9e5f42e2a
[libc][math][c23] Temporarily disable float16 on 32-bit Arm (#95027)
See Buildbot failure:
https://lab.llvm.org/buildbot/#/builders/229/builds/27009.
2024-06-10 15:30:18 -04:00
OverMighty
c5b68a9dce
[libc][math][c23] Temporarily disable float16 on RISC-V (#94984)
See Buildbot failures:

- https://lab.llvm.org/buildbot/#/builders/257/builds/13450
- https://lab.llvm.org/buildbot/#/builders/256/builds/14531
2024-06-10 10:18:53 -04:00
OverMighty
cb1a727dea
[libc][math][c23] Add nanf16 C23 math function (#94767)
Part of #93566.
2024-06-10 00:19:22 -04:00
Schrodinger ZHU Yifan
142afde0eb
[libc] rework mutex (#92168) 2024-05-31 18:57:18 -07:00
OverMighty
0eb9e021b1
[libc][math][c23] Add fabsf16 C23 math function (#93567)
cc @lntue
2024-05-30 15:37:15 -04:00
Hendrik Hübner
485f9f5895
Reland: [libc][POSIX][pthreads] implemented missing pthread_rwlockattr functions (#93622)
New pull request for https://github.com/llvm/llvm-project/issues/89443

The previous PR was reverted after breaking fullbuild due to a missing
struct declaration, which I forgot to commit.

Reverts revert and adds the missing pthread_rwlockattr_getkind_np /
pthread_rwlockattr_setkind_np functions and tests respecitvely.
2024-05-30 11:27:50 -07:00
lntue
4486fcba75
[libc] Add proxy header for float.h. (#93504)
This is the continuation of
https://github.com/llvm/llvm-project/pull/88674.

Fixes #88433, #90496.

---------

Co-authored-by: aniplcc <aniplccode@gmail.com>
2024-05-28 19:14:26 -04:00
Nick Desaulniers (paternity leave)
dce197ac92
[libc][errno] remove mips+sparc specific errnos (#92798)
These are untested and unsupported platforms. The pattern used makes sense for
platform specific error numbers, but these are platforms we do not support.
Excise this code.

Link: #91150
2024-05-20 14:15:24 -07:00
Robin Caloudis
0980f715cf
[libc][errno] Remove previously added errno numbers (#92163)
Introduced in https://github.com/llvm/llvm-project/pull/91150. Not
needed anymore as https://github.com/llvm/llvm-project/pull/92041 fixed
the root cause. `ENAMETOOLONG` and `EOVERFLOW` are well defined in
`<linux/errno.h>`.

Post mortem: Due to the previously missing inclusion of
`<linux/errno.h>` (fixed with
https://github.com/llvm/llvm-project/pull/92041), I misinterpreted an
undefined macro issue during the development of
https://github.com/llvm/llvm-project/pull/91150 as being caused by a
missing definition rather than by the missing inclusion of the linux
header. I realized too late that `ENAMETOOLONG` and `EOVERFLOW` were
correctly defined in `<linux/errno.h>` and that it was my missing
inclusion that caused the problem.
2024-05-15 01:26:23 -04:00
Robin Caloudis
a71e2b9d0f
[libc][errno] Remove non asm generic error number (#92172)
The following small thing caught my eye:

1) `EILSEQ` is not part of the generic asm error number macros. See the
[full list of generic asm errno
codes](4b95dc8736/include/uapi/asm-generic/errno-base.h).
AFAIK the generic asm errno numbers are common between different
operating systems and architectures. `EILSEQ` is not part of this common
set of errno's.

2) `EILSEQ`'s value is wrong. During the addition of `EILSEQ` in
https://reviews.llvm.org/D151129, the value `35` was probably chosen as
its the consecutive number. This is not correct. The actual values can
be looked up for example here:
* [For Linux
kernel](https://github.com/search?q=repo%3Atorvalds%2Flinux+EILSEQ&type=code&p=1):
`EILSEQ = 84` (uapi; i.e. x86_64), `EILSEQ = 88` (mips), `EILSEQ = 47`
(parisc)
* [For Darwin
kernel](https://github.com/apple-oss-distributions/xnu/blob/main/bsd/sys/errno.h#L237):
`EILSEQ = 92`
2024-05-15 00:02:46 -04:00
Robin Caloudis
561c42df57
[libc][errno] Use macro instead of system header (#91150)
## Why
Currently, the system header `errno.h` is included in `libc_errno.h`,
which is supposed to be consumed by internal implementations only. As
unit and hermetic tests should never use `#include <errno.h>` but
instead use `#include "src/errno/libc_errno.h"`, we do not want to
implicitly include `errno.h`. In order to have a clear seperation
between those two, we want to pull out the definitions of errno numbers
from `errno.h`.

## What
* Extract the definitions of errno numbers from
[include/errno.h.def](https://github.com/llvm/llvm-project/pull/91150/files#diff-ed38ed463ed50571b498a5b69039cab58dc9d145da7f751a24da9d77f07781cd)
and place it under
[include/llvm-libc-macros/linux/error-number-macros.h](https://github.com/llvm/llvm-project/pull/91150/files#diff-d6192866629690ebb7cefa1f0a90b6675073e9642f3279df08a04dcdb05fd892)
* Provide mips-specific errno numbers in
[include/llvm-libc-macros/linux/mips/error-number-macros.h](https://github.com/llvm/llvm-project/pull/91150/files#diff-3fd35a4c94e0cc359933e497b10311d857857b2e173e8afebc421b04b7527743)
* Find definition of mips errno numbers in glibc
[here](ea73eb5f58/sysdeps/unix/sysv/linux/mips/bits/errno.h (L32-L50))
(equally defined in the Linux kernel)
* Provide sparc-specific errno numbers in
[include/llvm-libc-macros/linux/sparc/error-number-macros.h](https://github.com/llvm/llvm-project/pull/91150/files#diff-5f16ffb2a51a6f72ebd4403aca7e1edea48289c99dd5978a1c84385bec4f226b)
* Find definition of sparc errno numbers in glibc
[here](ea73eb5f58/sysdeps/unix/sysv/linux/sparc/bits/errno.h (L33-L51))
(equally defined in the Linux kernel)
* Include proxy header `errno_macros.h` instead of the system header
`errno.h` in `libc_errno.h`/`libc_errno.cpp`

Closes https://github.com/llvm/llvm-project/issues/80172
2024-05-13 17:56:01 -04:00
Schrodinger ZHU Yifan
27595c4bef
Revert "[libc][POSIX][pthreads] implemented missing pthread_rwlockattr functions" (#91966)
Reverts llvm/llvm-project#90249

Fullbuild is broken:
https://lab.llvm.org/buildbot/#/builders/163/builds/56501
2024-05-13 09:43:14 -04:00
Hendrik Hübner
d2676a7333
[libc][POSIX][pthreads] implemented missing pthread_rwlockattr functions (#90249)
Closes #89443

I added the two missing functions and respective test cases. Let me know
if anything needs changing.
2024-05-13 09:35:17 -04:00
Joseph Huber
873431a68a
[libc] Add __FE_DENORM to the fenv macros (#91353)
Summary:
Some targets support denormals as floating point exceptions. This is
provided as an extension in the GNU headers as __FE_DENORM.

This provides it in our headers, however I'm unsure if we should make it
internal or external. I do not think it should be in all exception as it
doesn't represent an exceptional behavior as far as the standard is
concerned, but I'm not an expert.
2024-05-07 12:57:54 -05:00
Joseph Huber
1022636b0c
[libc] Fix assert dependency on macro header (#91036)
Summary:
This file was missing a dependency so it wasn't being installed.
2024-05-03 20:57:34 -05:00
Vinayak Dev
aca511734f
[libc] Implement fcntl() function (#89507)
Fixes #84968. 

Implements the `fcntl()` function defined in the `fcntl.h` header.
2024-05-01 11:18:44 -07:00
Fabian Keßler
cd7a7a56fc
Add basic char*_t support for libc (partial WG14 N2653) (#90360)
This PR implements a part of WG14 N2653:
 - Define C23 char8_t
 - Define C11 char16_t
 - Define C11 char32_t
 
 Missing goals are:
- The type of UTF-8 character literals is changed from unsigned char to
char8_t. (Since UTF-8 character literals already have type unsigned
char, this is not a semantic change).
- New mbrtoc8() and c8rtomb() functions declared in <uchar.h> enable
conversions between multibyte characters and UTF-8.
    - A new ATOMIC_CHAR8_T_LOCK_FREE macro.
    - A new atomic_char8_t typedef name.
2024-04-30 15:08:38 -07:00
aniplcc
11bd19a7a2
[libc][assert] define __STDC_VERSION_ASSERT_H__ (#87592)
Fixes #87561
2024-04-24 13:01:16 -07:00
Nick Desaulniers
dd7963239e
[libc][POSIX][pthreads] implement pthread_rwlockattr_t functions (#89322)
Implement:
- pthread_rwlockattr_destroy
- pthread_rwlockattr_getpshared
- pthread_rwlockattr_init
- pthread_rwlockattr_setpshared
2024-04-22 12:03:27 -07:00
Nick Desaulniers
06947b9f8d
[libc][POSIX][pthreads] implement pthread_condattr_t functions (#88987)
Implement:
- pthread_condattr_destroy
- pthread_condattr_getclock
- pthread_condattr_getpshared
- pthread_condattr_init
- pthread_condattr_setclock
- pthread_condattr_setpshared

Fixes: #88581
2024-04-17 09:31:29 -07:00
Michael Jones
5fb821560a
[libc] add remaining epoll functions, pipe (#84587)
The epoll_wait functions need the rest of the epoll functions (create,
ctl) to be available to actually test them, as well as pipe to create a
usable file descriptor. This patch adds epoll_create, epoll_create1,
epoll_ctl, and pipe. These have tests, and the tests for epoll_wait,
epoll_pwait, and epoll_pwait2 (currently disabled) are updated to use
these newly available functions.
2024-04-11 16:26:49 -07:00
lntue
22b1f1bc69
[libc] Remove #ifdef __cplusplus part from include/llvm-libc-macros/math-macros.h. (#87864)
Now with the proxy header `hdr/math_macros.h`, the header
`include/llvm-libc-macros/math-macros.h` will not be included in overlay
mode, and the extra definitions for `__cplusplus` mode is not needed any
more.
2024-04-08 19:26:12 -04:00
lntue
5748ad84e5
[libc] Add proxy header math_macros.h. (#87598)
Context: https://github.com/llvm/llvm-project/pull/87017

- Add proxy header `libc/hdr/math_macros.h` that will:
  - include `<math.h>` in overlay mode,
- include `"include/llvm-libc-macros/math-macros.h"` in full build mode.
- Its corresponding CMake target `libc.hdr.math_macros` will only depend
on `libc.include.math` and `libc.include.llvm-libc-macros.math_macros`
in full build mode.
- Replace all `#include "include/llvm-libc-macros/math-macros.h"` with
`#include "hdr/math_macros.h"`.
- Add dependency to `libc.hdr.math_macros` CMake target when using
`add_fp_unittest`.
- Update the remaining dependency.
- Update bazel overlay: add `libc:hdr_math_macros` target, and replacing
all dependency on `libc:llvm_libc_macros_math_macros` with
`libc:hdr_math_macros`.
2024-04-05 18:21:16 -04:00