182 Commits

Author SHA1 Message Date
Joseph Huber
3c391a640d
[libc] Add *_HAS_SUBNORM to float.h (#102182)
Summary:
These should be defined, since we provide `float.h` it will override the
Clang resource dir and not provide it.
2024-08-07 08:00:43 -05:00
Joseph Huber
b209eda621
[libc] Define MB_LEN_MAX in limits.h (#102246)
Summary:
This is supposed to define the maximum bytes required to store a char in
any locale. There's some question about what this should be set to. I
believe because the proposed solution for `locale.h` is to only support
the default locale, we should do what `musl` does and set it to `4`
which covers up to UTF-32.

Fixes https://github.com/llvm/llvm-project/issues/79358
2024-08-07 07:59:44 -05:00
Joseph Huber
bde51232ba
[libc] Provide 'signal.h' header for the GPU (#101996)
Summary:
This header is practically useless, but we provide it mostly for the
macros so that applications can compile. I'm only doing this for the
`libc++` unittests that want it, and it is part of the C standard
technically. I just made an RPC call to do `raise`. Anything more isn't
going to work since it'd be way too annoying to make the CPU call into
some signal handler the GPU registered.
2024-08-05 14:52:14 -05: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
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
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
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
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
0eb9e021b1
[libc][math][c23] Add fabsf16 C23 math function (#93567)
cc @lntue
2024-05-30 15:37:15 -04: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
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
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
aniplcc
11bd19a7a2
[libc][assert] define __STDC_VERSION_ASSERT_H__ (#87592)
Fixes #87561
2024-04-24 13:01:16 -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
Michael Jones
5264c22ef1
[libc] Temporary math macros fix (#87681)
Downstream's having some issues due to math-macros.h issues. These will
be fixed properly soon.

See https://github.com/llvm/llvm-project/issues/87683 for tracking this
tech debt.
2024-04-04 14:28:56 -07:00
Michael Jones
d5f06342a3
[libc] add flag for FP_*LOGB0/NAN values (#86723)
These values vary by system, this flag allows you to toggle their value.
2024-03-27 15:09:57 -07:00
OverMighty
b282259711
[libc][math][c23] Add {,u}fromfp{,x}{,f,l,f128} functions (#86003)
Fixes #85279.

cc @lntue
2024-03-25 10:26:22 -04:00
Nick Desaulniers
cdbec7baf1
[libc] fix up the use of angle includes in include/ (#86027)
Performed en-masse via:

    $ grep -rn "#include <ll" libc/include -l | \
      xargs perl -pi -e 's/#include <ll(.*)>/#include "ll$1"/'
    $ grep -rn "#include <__" libc/include -l | \
      xargs perl -pi -e 's/#include <__(.*)>/#include "__$1"/'

Link: #83463
Link: #83210
2024-03-22 08:24:08 -07:00
Roland McGrath
c56211b243
[libc] Make math-macros.h C++-friendly (#86206)
The isfinite, isnan, and isinf "functions" are specified by C99..C23 to
be macros that act as type-generic functions. Defining them as their
__builtin_* counterparts works fine for this. However, in C++ the
identifiers need to be usable in different contexts, such as being
declared inside a C++ namespace. So define inline constexpr template
functions for them under `#ifdef __cplusplus`.
2024-03-21 18:11:31 -04:00
Petr Hosek
d6722bcbd6
[libc] Move EOF macro to stdio-macros.h (#85159)
libc++ char_traits.h assumes EOF is always available

See #85158 for more details.
2024-03-15 10:56:39 -07:00
Petr Hosek
bb5921e2a2
[libc] Include FP_* macros in math.h (#84996)
These are used unconditionally by libc++ math.h.

This is related to issue #84879.
2024-03-12 17:01:29 -07:00
Nick Desaulniers
f0c0ddae45
[libc] implement the final macros for stdbit.h support (#84798)
Relevant sections of n3096:
- 7.18.1p1
- 7.18.2
2024-03-12 08:39:17 -07:00
Michael Flanders
75b0d384fb
[libc][stdbit][c23] adds implementation of stdc_bit_ceil functions (#84657)
Closes #84652.

Based on #84233.
2024-03-10 12:53:28 -04:00
Michael Flanders
35b784379e
[libc][stdbit][c23] fixes typos in bit_width, bit_floor C type-generic macros (#84659)
Fixes #84658.

Assuming these were typos in the first place.

I am unsure of the best way to ensure that both sides of the
preprocessor condition in
`libc/include/llvm-libc-macros/stdbit-macros.h` are tested. Could
someone point me in the right direction for adding test coverage to the
non `__cplusplus` branch? Or maybe it is being tested and I've missed
it.
2024-03-10 01:46:39 -05:00
Schrodinger ZHU Yifan
29afd64615
[libc][c23] make inttypes.h compat with c23 (#84493) 2024-03-08 10:36:22 -05:00
Nick Desaulniers
101a13df71
[libc][stdbit] implement stdc_bit_floor (C23) (#84233) 2024-03-07 08:38:04 -08:00
Nick Desaulniers
041638c429
[libc][stdbit] implement stdc_bit_width (C23) (#83892) 2024-03-05 09:49:41 -08:00
Joseph Huber
c996023f9a
[libc] Provide an implementation of the 'stdint.h' header (#83353)
Summary:
I've noticed one problem is that the user includes `stdint.h` the
compiler will do `#include_next <stdint.h>` potentially into a
conflicting implementation on systems with multiple headers installed.
The `clang` header is standards compliant and works with `clang` and
`gcc` which are both of our targets, so I simply copied it here. This
has the effect of including `stdint.h` on clang / LLVM libc behaving the
same as `-ffreestanding`.
2024-03-04 12:23:11 -06:00
lntue
cf68c0427d
[libc] Ignore -Winclude-next-absolute-path warning in float-macros.h (#83513) 2024-02-29 21:08:17 -05:00