Commit Graph

294 Commits

Author SHA1 Message Date
Joseph Huber
7e37d02102 [libc] Fix headers for statvfs implementation
Summry:
@lntue
2024-07-19 09:26:55 -05:00
Michael Jones
f1a8db1a1f [libc][newhdrgen] Remove redundant yaml prefixes (#99581)
Since the yaml files are already organized into folders, the name of the
file doesn't also need to be prefixed by what folder it's in.
2024-07-18 15:32:32 -07:00
aaryanshukla
b1fd6f0996 [libc] newheadergen: cmake config newhdrgen (#99543)
- revert to revert for patch
https://github.com/llvm/llvm-project/pull/98828
- revert to revert https://github.com/llvm/llvm-project/pull/99410
- revert to revert https://github.com/llvm/llvm-project/pull/99413
2024-07-18 13:16:00 -07:00
aaryanshukla
58d4ca06bd Revert "[libc] newheadergen: configured cmake" (#99414)
Reverts llvm/llvm-project#98828
2024-07-17 17:17:05 -07:00
aaryanshukla
ad4da8304c Revert "[libc] newheadergen: cmakelist file changes" (#99413)
Reverts llvm/llvm-project#99404
2024-07-17 17:16:33 -07:00
aaryanshukla
d5fe73515a Revert "[libc] newheadergen: quick fix to fuchsia build" (#99412)
Reverts llvm/llvm-project#99410
2024-07-17 17:15:18 -07:00
aaryanshukla
ab142c635e [libc] newheadergen: quick fix to fuchsia build (#99410) 2024-07-17 17:00:58 -07:00
aaryanshukla
ad023a844a [libc] newheadergen: cmakelist file changes (#99404) 2024-07-17 16:43:57 -07:00
aaryanshukla
83fbd79319 [libc] newheadergen: configured cmake (#98828)
- all headers in the build system are generated by newheadergen
- tested on gpu-build

---------

Co-authored-by: Rose Zhang <rosezhang@google.com>
2024-07-17 16:23:15 -07:00
Joseph Huber
8393ea5d1d [libc] Implement clock_gettime for the monotonic clock on the GPU (#99067)
Summary:
This patch implements `clock_gettime` using the monotonic clock. This
allows users to get time elapsed at nanosecond resolution. This is
primarily to facilitate compiling the `chrono` library from `libc++`.
For this reason we provide both `CLOCK_MONOTONIC`, which we can
implement
with the GPU's global fixed-frequency clock, and `CLOCK_REALTIME` which
we cannot. The latter is provided just to make people who use this
header happy and it will always return failure.
2024-07-16 16:17:34 -05:00
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 ea3fd020f4.
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