155 Commits

Author SHA1 Message Date
Petr Hosek
b8daa45a56
[libc] Implement timespec_get (#116102)
`timespec_get` is C standard counterpart to POSIX `clock_gettime`. On
Linux we simply use `clock_gettime`. On baremetal we introduce a new
external API `__llvm_libc_timespec_get_utc` that should be implemented
by the vendor.
2024-12-02 14:29:49 -08:00
lntue
88a0a318e8
[libc] Use relative inclusion for public headers. (#114324)
We are finalizing the header inclusion policy, and for our public
headers in the `libc/include` folder, they must use relative path in
`"..."` when including each other.

This PR does the cleanup making sure that all the public header
inclusions in `libc/include` folder use relative paths.

---------

Co-authored-by: Nick Desaulniers <nickdesaulniers@users.noreply.github.com>
2024-11-01 14:33:30 -04:00
Michael Jones
e241964b93
[libc] Fix macro definition hermeticity (#114467)
Previously shm_test was including <asm-generic/fcntl.h> for the macro
FD_CLOEXEC. This patch adds that macro to the list we have defined, and
redirects the test to use the correct proxy header.
2024-10-31 14:42:50 -07:00
Nick Desaulniers
dc1ff883ca
[libc][i386] define MINSIGSTKSZ & SIGSTKSZ (#114249)
Link: #93709
2024-10-30 11:56:41 -07:00
Shourya Goel
f4ba6a654d
[libc][complex] Set up headers and add documentation for complex.h. (#111659)
Refer: 7.3.1 from [ISO
SPEC](https://www.open-std.org/jtc1/sc22/wg14/www/docs/n3220.pdf)

I have added complex variants of F16 and F128 in libc doc but have
omitted support for them since we will have to first investigate how
their support matrix for clang and gcc looks like, and then add header
guards for them accordingly. Planning to add them in follow up PRs once
this gets landed.
2024-10-14 13:35:04 -04:00
Shourya Goel
4e33afee5a
[libc][math] Implement issignaling and iscanonical macro. (#111403)
#109201
2024-10-09 10:25:49 -07:00
Job Henandez Lara
46944b0cbc
[libc] remove errno.h includes (#110934) 2024-10-05 19:31:36 -04:00
Fabio D'Urso
2396c46999
[libc] Add malloc.h header defining mallopt (#110908)
This patch adds the malloc.h header, declaring Scudo's mallopt
entrypoint when built LLVM_LIBC_INCLUDE_SCUDO, as well as two
constants that can be passed to it (M_PURGE and M_PURGE_ALL).

Due to limitations of the current build system, only the declaration
of mallopt is gated by LLVM_LIBC_INCLUDE_SCUDO, and the two new
constants are defined irrespectively of it. We may need to refine
this in the future.

Note that some allocators other than Scudo may offer a mallopt
implementation too (e.g. man 3 mallopt), albeit with different
supported input values. This patch only supports the specific case of
LLVM_LIBC_INCLUDE_SCUDO.
2024-10-03 18:45:23 +02:00
lntue
c63112a911
[libc][stdio] Use proxy headers of stdio.h in src and test folders. (#110067)
https://github.com/llvm/llvm-project/issues/60481
2024-10-01 11:48:07 -04:00
Shourya Goel
b935d312f1
[libc][math] Reapply and fix issignaling macro. (#110011)
reapply #109615
2024-09-25 15:39:55 -04:00
lntue
808c498f52
Revert "[libc][math] Implement issignaling macro." (#109992)
Reverts llvm/llvm-project#109615
2024-09-25 10:58:08 -04:00
Shourya Goel
ac802a3148
[libc][math] Implement issignaling macro. (#109615)
#109201
2024-09-25 10:35:20 -04:00
Shourya Goel
ba5e195809
[libc][math] Implement issubnormal macro. (#109572)
#109201
2024-09-23 00:50:46 -04:00
Shourya Goel
aaa637d8d0
[libc][math] Implement isnormal macro. (#109547)
#109201
2024-09-21 22:26:56 -04:00
Shourya Goel
56124feeb8
[libc][math] Implement fpclassify macro. (#109519)
#109201
2024-09-21 11:49:23 -04:00
Shourya Goel
739ede400b
[libc][[math] Implement IsZero Macro (#109336)
#109201
2024-09-20 13:00:01 -04:00
Sirui Mu
ded080152a
[libc] Add osutils for Windows and make libc and its tests build on Windows target (#104676)
This PR first adds osutils for Windows, and changes some libc code to
make libc and its tests build on the Windows target. It then temporarily
disables some libc tests that are currently problematic on Windows.

Specifically, the changes besides the addition of osutils include:

- Macro `LIBC_TYPES_HAS_FLOAT16` is disabled on Windows. `clang-cl`
generates calls to functions in `compiler-rt` to handle float16
arithmetic and these functions are currently not linked in on Windows.
- Macro `LIBC_TYPES_HAS_INT128` is disabled on Windows.
- The invocation to `::aligned_malloc` is changed to an invocation to
`::_aligned_malloc`.
- The following unit tests are temporarily disabled because they
currently fail on Windows:
  - `test.src.__support.big_int_test`
  - `test.src.__support.arg_list_test`
  - `test.src.fenv.getenv_and_setenv_test`
- Tests involving `__m128i`, `__m256i`, and `__m512i` in
`test.src.string.memory_utils.op_tests.cpp`
- `test_range_errors` in `libc/test/src/math/smoke/AddTest.h` and
`libc/test/src/math/smoke/SubTest.h`
2024-09-11 23:41:32 -04:00
Joseph Huber
a87105121d
[libc] Implement locale variants for 'stdlib.h' functions (#105718)
Summary:
This provides the `_l` variants for the `stdlib.h` functions. These are
just copies of the same entrypoint and don't do anything with the locale
information.
2024-08-29 14:18:37 -05:00
Joseph Huber
78d8ab2ab9
[libc] Initial support for 'locale.h' in the LLVM libc (#102689)
Summary:
This patch adds the macros and entrypoints associated with the
`locale.h` entrypoints.  These are mostly stubs, as we (for now and the
forseeable future) only expect to support the C and maybe C.UTF-8
locales in the LLVM libc.
2024-08-22 12:58:46 -05:00
Joseph Huber
2f4232db0b Revert " [libc] Add ctype.h locale variants (#102711)"
This reverts commit 8f005f8306dc52577b3b9482d271fb463f0152a5.
2024-08-22 12:45:16 -05:00
Joseph Huber
8f005f8306
[libc] Add ctype.h locale variants (#102711)
Summary:
This patch adds all the libc ctype variants. These ignore the locale
ingormation completely, so they're pretty much just stubs. Because these
use locale information, which is system scope, we do not enable building
them outisde of full build mode.
2024-08-22 12:41:20 -05:00
Joseph Huber
6cd37eb5de
[libc] Fix INFINITY being defined as a double (#103445)
Summary:
If the implementation supports floating-point infinities, the macro
INFINITY expands to constant expression of type float which evaluates to
positive or unsigned infinity.

Currently this is a double, this makes it a float.
2024-08-13 16:02:18 -05:00
Schrodinger ZHU Yifan
4371c79d45
[libc] Reapply ELF/LINK header changes (#102765)
This is based on @izaakschroeder previous patch but I only select macro
definitions for now. We need these definitions for VDSO work, which has
been delayed for a very long time.

Co-authored-by: Izaak Schroeder <izaak.schroeder@gmail.com>
2024-08-13 08:20:37 -07:00
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