434 Commits

Author SHA1 Message Date
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
Joseph Huber
4c0d805a54
[libc] Do not redefine wchar_t when compiling in C++ (#110769)
Summary:
This is a fundamental type in C++, so we can't redefine it.
2024-10-01 17:28:42 -07: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
Joseph Huber
fe6a3d46aa
[libc] Implement the 'rename' function on the GPU (#109814)
Summary:
Straightforward implementation like the other `stdio.h` functions.
2024-09-24 09:32:42 -07:00
Joseph Huber
16d11e26f3
[libc] Add GPU support for the 'system' function (#109687)
Summary:
This function can easily be implemented by forwarding it to the host
process. This shows up in a few places that we might want to test the
GPU so it should be provided. Also, I find the idea of the GPU
offloading work to the CPU via `system` very funny.
2024-09-23 14:04:28 -07: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
lntue
95d4c97a20
[libc][wchar] Move wchar's types to proxy headers. (#109334)
Also protect against extern inline function definitions added when
building with gcc: https://github.com/llvm/llvm-project/issues/60481.
2024-09-19 22:23:51 -04:00
Michael Jones
13dd2fd1e0
[libc] Put bind back, fix gcc build (#109341)
Fixes #106467.
Bind was accidentally removed while trying to clean up functions that
didn't end up being needed. The GCC issue was just a warning treated as
an error.
2024-09-19 15:10:56 -07:00
Michael Jones
f6b4c34d4f
[libc] Add functions to send/recv messages (#106467)
This patch adds the necessary functions to send and receive messages
over a socket. Those functions are: recv, recvfrom, recvmsg, send,
sendto, sendmsg, and socketpair for testing.
2024-09-19 14:43:00 -07: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
Schrodinger ZHU Yifan
ce9f987295
[libc] fix locale dependency for stdlib (#108042)
Address the following issue:
```
❯ ninja libc.test.src.__support.OSUtil.linux.vdso_test.__unit__
[91/127] Building CXX object libc/test/src/__support/OSUtil/linux/CMakeFiles/libc.test.src.__support.OSUtil.linux.vdso_test.__unit__.__build__.dir/vdso_test.cpp.o
FAILED: libc/test/src/__support/OSUtil/linux/CMakeFiles/libc.test.src.__support.OSUtil.linux.vdso_test.__unit__.__build__.dir/vdso_test.cpp.o 
sccache /usr/bin/clang++ -DLIBC_NAMESPACE=__llvm_libc_20_0_0_git -D_DEBUG -I/home/schrodingerzy/Documents/llvm-project/libc -isystem /home/schrodingerzy/Documents/llvm-project/build/libc/include -fvisibility-inlines-hidden -Werror=date-time -Werror=unguarded-availability-new -Wall -Wextra -Wno-unused-parameter -Wwrite-strings -Wcast-qual -Wmissing-field-initializers -Wimplicit-fallthrough -Wcovered-switch-default -Wno-noexcept-type -Wnon-virtual-dtor -Wdelete-non-virtual-dtor -Wsuggest-override -Wstring-conversion -Wmisleading-indentation -Wctad-maybe-unsupported -fdiagnostics-color -g -std=gnu++17 -fpie -DLIBC_FULL_BUILD -ffreestanding -fno-exceptions -fno-unwind-tables -fno-asynchronous-unwind-tables -fno-rtti -MD -MT libc/test/src/__support/OSUtil/linux/CMakeFiles/libc.test.src.__support.OSUtil.linux.vdso_test.__unit__.__build__.dir/vdso_test.cpp.o -MF libc/test/src/__support/OSUtil/linux/CMakeFiles/libc.test.src.__support.OSUtil.linux.vdso_test.__unit__.__build__.dir/vdso_test.cpp.o.d -o libc/test/src/__support/OSUtil/linux/CMakeFiles/libc.test.src.__support.OSUtil.linux.vdso_test.__unit__.__build__.dir/vdso_test.cpp.o -c /home/schrodingerzy/Documents/llvm-project/libc/test/src/__support/OSUtil/linux/vdso_test.cpp
In file included from /home/schrodingerzy/Documents/llvm-project/libc/test/src/__support/OSUtil/linux/vdso_test.cpp:21:
In file included from /home/schrodingerzy/Documents/llvm-project/libc/test/UnitTest/ErrnoSetterMatcher.h:13:
In file included from /home/schrodingerzy/Documents/llvm-project/libc/src/__support/FPUtil/fpbits_str.h:12:
In file included from /home/schrodingerzy/Documents/llvm-project/libc/src/__support/CPP/string.h:20:
/home/schrodingerzy/Documents/llvm-project/build/libc/include/stdlib.h:13:10: fatal error: 'llvm-libc-types/locale_t.h' file not found
   13 | #include "llvm-libc-types/locale_t.h"
      |          ^~~~~~~~~~~~~~~~~~~~~~~~~~~~
1 error generated.
[123/127] Building CXX object libc/test/UnitTest/CMakeFiles/LibcTest.unit.dir/LibcTestMain.cpp.o
ninja: build stopped: subcommand failed.
```
2024-09-10 13:04:19 -04:00
Joseph Huber
5c019bdb7a
[libc] Add support for 'string.h' locale variants (#105719)
Summary:
This adds the locale variants of the string functions. As previously,
these do not use the locale information at all and simply copy the
non-locale version which expects the "C" locale.
2024-08-29 14:20:15 -05: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
856dadb33c [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 13:51:54 -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
Michael Jones
845461093c
[libc] Fix generated header definitions in cmake (#104628)
Some new headers were not being properly built with
new headergen, since they were using the old "add_gen_header" instead of
the new "add_header_macro". This patch fixes the issue.
2024-08-16 11:52:37 -07:00
Michael Jones
97919864ec
Revert "[libc] Disable old headergen checks unless enabled" (#104627)
Reverts llvm/llvm-project#104522

Caused crashes on Fuchsia
2024-08-16 11:22:33 -07:00
Michael Jones
f668708796
[libc] Disable old headergen checks unless enabled (#104522)
Old Headergen needed extra build rules to ensure that it worked in
runtimes mode. This patch disables those checks if new headergen is
enabled. Also some new headers were not being properly built with
new headergen, and that's also fixed.
2024-08-16 09:51:29 -07:00
Joseph Huber
101acff2e5
[libc] Define 'size_t' in time.h and uchar.h (#103441)
Summary:
The standard says the following: The <time.h> header shall define the
clock_t, size_t, time_t, types as described in <sys/types.h>. I couldn't
find one for `uchar.h` but it needs it once we define things like
`mbrtoc8`.
2024-08-13 16:02:43 -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
Simon Tatham
722c066c59
[libc] Make use of 32-bit time_t a config option (#102012)
The 32-bit Arm builds of libc define time_t to be `__INTPTR_TYPE__`,
i.e. a 32-bit integer. This is commented in the commit introducing it
(75398f28ebdb600) as being for compatibility with glibc. But in the near
future not even every AArch32 build of glibc will have a 32-bit time_t:
Debian is planning that their next release (trixie) will have switched
to 64-bit. And non-Linux builds of this libc (e.g. baremetal) have no
reason to need glibc compatibility in the first place – and every reason
_not_ to want to start using a 32-bit time_t in 2024 or later.

So I've replaced the `#ifdef` in `llvm-libc-types/time_t.h` with two
versions of the header file, chosen in `CMakeLists.txt` via a new
configuration option. This involved adding an extra parameter to the
cmake `add_header` function to specify different names for the header
file in the source and destination directories.
2024-08-08 16:36:05 +01: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
Schrodinger ZHU Yifan
03841e7ab8
[libc] add spin lock family functions (#100509)
This PR:
- add entrypoints for `pthread_spin_*`
- additionally, the fixes a typo that has been disabling lock related
tests
2024-08-06 21:02:54 -07: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
Simon Tatham
2a6268d8f9
[libc][AArch64] Add an AArch64 setjmp/longjmp. (#101177)
Previously, building libc for AArch64 in `LLVM_LIBC_FULL_BUILD` mode
would fail because no implementation of setjmp/longjmp was available.
This was the only obstacle, so now a full AArch64 build of libc is
possible.

This implementation automatically supports PAC and BTI if compiled with
the appropriate options. I would have liked to do the same for MTE stack
tagging, but as far as I can see there's currently no predefined macro
that allows detection of `-fsanitize=memtag-stack`, so I've left that
one as a TODO.

AAPCS64 delegates the x18 register to individual platform ABIs, and
allows them to choose what it's used for, which may or may not require
setjmp and longjmp to save and restore it. To accommodate this, I've
introduced a libc configuration option. The default is on, because the
only use of x18 I've so far encountered uses it to store information
specific to the current stack frame (so longjmp does need to restore
it), and this is also safe behavior in the default situation where the
platform ABI specifies no use of x18 and it becomes a temporary register
(restoring it to its previous value is no worse than any _other_ way for
a function call to clobber it). But if a platform ABI needs to use x18
in a way that requires longjmp to leave it alone, they can turn the
option off.
2024-07-31 09:09:52 -07:00
Mikhail R. Gadelha
7ddcf7acf2
[libc] Change fsfilcnt_t and fsblkcnt_t to be 64-bits long (#99876)
In 32-bit systems with 64-bit offsets, both fsfilcnt_t and fsblkcnt_t are 64-bit long, just like 64-bit systems. This patch changes both types to be 64-bit long for all platforms and follows the reasoning used to change off_t: the standard only requires it to be an unsigned int, so making it 64-bit long doesn't violate this property.

It should be NFC for 64-bit systems.
2024-07-22 12:06:03 -03:00
Petr Hosek
d386a5582b
[libc] Make static_assert available even if NDEBUG is set (#99742)
This addresses an issue introduced in #98826 where static_assert was
made defined only when NDEBUG is not set which is different from all
other C libraries and breaks any code that uses static_assert and
doesn't guard it with NDEBUG.
2024-07-20 00:56:52 -07:00
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