372 Commits

Author SHA1 Message Date
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
3bbe0f90f3
[libc] Add 'strings.h' header on the GPU (#109661)
Summary:
These are GNU extensions but still show up, the entrypoints were enabled
but we weren't emitting the header so they couldn't be used.
2024-09-23 14:19:33 -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
Michael Jones
f009f72df5
[libc] Add printf strerror conversion (%m) (#105891)
This patch adds the %m conversion to printf, which prints the
strerror(errno). Explanation of why is below, this patch also updates
the docs, tests, and build system to accomodate this.

The standard for syslog in posix specifies it uses the same format as
printf, but adds %m which prints the error message string for the
current value of errno. For ease of implementation, it's standard
practice for libc implementers to just add %m to printf instead of
creating a separate parser for syslog.
2024-09-19 10:48:08 -07:00
Зишан Мирза
b9e13045ab
[libc] add ctime and ctime_r to date_and_time documentation (#108665)
closes #108664
2024-09-17 09:50:07 -07:00
lntue
1896ee3889
[libc] Fix undefined behavior for nan functions. (#106468)
Currently the nan* functions use nullptr dereferencing to crash with
SIGSEGV if the input is nullptr. Both `nan(nullptr)` and `nullptr`
dereferencing are undefined behaviors according to the C standard.
Employing `nullptr` dereference in the `nan` function implementation is
ok if users only linked against the pre-built library, but it might be
completely removed by the compilers' optimizations if it is built from
source together with the users' code.

See for instance:  https://godbolt.org/z/fd8KcM9bx

This PR uses volatile load to prevent the undefined behavior if libc is
built without sanitizers, and leave the current undefined behavior if
libc is built with sanitizers, so that the undefined behavior can be
caught for users' codes.
2024-09-11 14:13:31 -04:00
Joseph Huber
6b98a72365
[libc] Add scanf support to the GPU build (#104812)
Summary:
The `scanf` function has a "system file" configuration, which is pretty
much what the GPU implementation does at this point. So we should be
able to use it in much the same way.
2024-08-21 18:02:04 -05:00
Michael Jones
b89fef8f67
[libc][docs] Update docs to reflect new headergen (#102381)
Since new headergen is now the default for building LLVM-libc, the docs
need to be updated to reflect that. While I was editing those docs, I
took a quick pass at updating other out-of-date pages.
2024-08-21 10:50:39 -07:00
OverMighty
560ed8ce3d
[libc][math][c23] Add expm1f16 C23 math function (#102387)
Part of #95250.
2024-08-13 16:48:28 +02:00
aaryanshukla
b6cbd014b9
[libc][newhdrgen]sorted function names in yaml (#102544) 2024-08-09 11:27:36 -07:00
Job Henandez Lara
ff1cc5b97c
[libc][math][c23] Add totalorderl function. (#102564) 2024-08-09 10:18:00 -04:00
aaryanshukla
d0fe470fd2
[libc][math] Add scalbln{,f,l,f128} math functions (#102219)
Co-authored-by: OverMighty <its.overmighty@gmail.com>
2024-08-08 14:33:50 -07:00
lntue
eddfd504f8
[libc][math][c23] Add ddivl C23 math function. (#102468) 2024-08-08 11:41:17 -04: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
Job Henandez Lara
aae7c38827
[libc][math][c23] Add entrypoints and tests for setpayloadsig{,f,l,f128} and setpayloadl. (#102413) 2024-08-08 00:17:20 -04:00
aaryanshukla
2c74237c0f
[libc][math][c23] Add fsub{,l,f128} and remainderf128 C23 math functions (#101576)
Co-authored-by: OverMighty <its.overmighty@gmail.com>
2024-08-07 13:03:58 -07:00
OverMighty
59338ad8c5
[libc][math][c23] Add exp10f16 C23 math function (#101588)
Part of #95250.
2024-08-07 15:54:06 +02:00
Job Henandez Lara
e3778a5d0e
[libc][math] Add getpayloadl function. (#102214) 2024-08-07 08:27:45 -04: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
aaryanshukla
0395bf7636
[libc][math][c23] Add ffma{,l,f128} and fdiv{,l,f128} C23 math functions #101089 (#101253)
- added all variations of ffma and fdiv 
- will add all new headers into yaml  for next patch 
- only fsub is left then all basic operations for float is complete

---------

Co-authored-by: OverMighty <its.overmighty@gmail.com>
2024-08-06 10:19:54 -07:00
Sirui Mu
2f28378317
[libc] Fix builds on Windows (#102162)
This PR changes several places in the CMake scripts to make libc build
on Windows. It adds the `errno` entrypoint to the Windows target.

A mistake in the overlay build doc is also fixed.

Tests still cannot be built on Windows because of the lack of osutils.
2024-08-06 08:38:05 -07:00
OverMighty
936515c7a5
[libc][math][c23] Add exp2f16 C23 math function (#101217)
Part of #95250.
2024-08-06 14:44:01 +02:00
lntue
9f6b440adf
[libc][math] Implement fast pass for double precision pow function with up to 1ULP error. (#101926) 2024-08-05 13:08:59 -04:00
Michael Jones
a21fc4c0a6
[libc] Fix printf handling of INT_MIN width (#101729)
Prevously, if INT_MIN was passed as a wildcard width to a printf
conversion the parser would attempt to negate it to get the positive
width (and set the left justify flag), but it would underflow and the
width would be treated as 0. This patch corrects the issue by instead
treating a width of INT_MIN as identical to -INT_MAX.

Also includes docs changes to explain this behavior and adding b to the
list of int conversions.
2024-08-02 13:45:54 -07:00
aaryanshukla
8f33f1d829
[libc][math][c23] Add dadd{l,f128} and ddiv{l,f128} C23 math functions (#100456)
- fadd removed because I need to add for different input types
- finishing rest of basic operations
- noticed duplicates will remove

---------

Co-authored-by: OverMighty <its.overmighty@gmail.com>
2024-08-01 13:36:50 -07:00
Job Henandez Lara
ed12f80ff0
[libc][math][c23] add entrypoints and tests for getpayload{,f,f128} (#101285) 2024-07-31 23:16:42 -04:00
aaryanshukla
30b5d4a763
[libc][math][c23] Add dfma{l,f128} and dsub{l,f128} C23 math functions (#101089)
Co-authored-by: OverMighty <its.overmighty@gmail.com>
2024-07-31 13:07:03 -07: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
Job Henandez Lara
546e4a210c
[libc][math][c23] Add entrypoints and tests for setpayload{,f,f128} (#101122) 2024-07-30 19:52:47 -04:00
Job Henandez Lara
0813260aa8
[libc][math][c23] Add entrypoints and tests for totalorder{,f,f128} (#100593) 2024-07-30 18:58:44 +02:00
OverMighty
971a1ac445
[libc][math][c23] Add expf16 C23 math function (#100632)
Part of #95250.
2024-07-30 18:38:03 +02:00
Eric977
44df89cc30
[libc] add pthread_rwlock_clockrdlock and pthread_rwlock_clockwrlock … (#100543) 2024-07-28 11:58:09 -07:00
Schrodinger ZHU Yifan
3db5c1eeb0
revert all tid changes (#100915) 2024-07-27 22:29:21 -07:00
RoseZhang03
134b4484d8
[libc] Updated GettingStarted.rst with PyYAML version (#100649)
New Headergen requires PyYAML version 5.1 or newer in order to generate
header files .
2024-07-26 18:31:00 +00:00
lntue
ca8b14de51
[libc][math] Implement fast pass for double precision atan2 with 1 ULP errors. (#100648) 2024-07-26 09:56:46 -04:00
Daniel Thornburgh
0c10bdc05f
[libc] Lazily initialize freelist malloc using symbols (#99254)
This requires the user to set the upper bounds of the heap by defining
the symbol `__libc_heap_limit`. The heap begins at `_end` and ends
`__libc_heap_limit` bytes afterwards. This prevents a completely unused
heap from requiring any space, and it prevents the heap from being
zeroed at initialization time as part of BSS. It also allows users to
customize the available heap location without recompiling libc.
    
I'd think this should eventually be replaced with an implemenation based
on a morecore() library. This would allow the same implementation to use
sbrk() on POSIX, `_end` and `__libc_heap_limit` on embedded, and a
buffer in tests. It would also provide better "wilderness" behavior that
tends to decrease heap fragementation (see Wilson et al.)

See #98096
2024-07-25 13:38:06 -07:00
Mikhail R. Gadelha
88fb56ebf2 [libc] Fix broken table introduced by PR #100578 2024-07-25 19:57:06 +02:00
Mikhail R. Gadelha
e90d552c77
[libc][NFC] Update riscv documentation (#100578)
This adds linux-riscv32 to the documentation and fixes riscv's
entrypoint broken link.
2024-07-25 13:25:09 -03:00
Job Henandez Lara
7b51777ed8
[libc][math][c23] add entrypoints and tests for totalordermag{f,l,f128} (#100159)
Fixes https://github.com/llvm/llvm-project/issues/100139
2024-07-24 19:53:23 -04:00
aaryanshukla
8b094c9df3
[libc][newheadergen]: PyYaml Version Update (#100463)
- a lot of builds had an issue using new headergen because they do not
have PyYaml installed.
2024-07-24 15:04:05 -07:00
Joseph Huber
2e3ee31d29 [libc] Enable 'sscanf' on the GPU #100211
Summary:
We can enable the sscanf function on the GPU now. This required adding
the configs to the scanf list so that the GPU build didn't do float
conversions.
2024-07-24 14:16:57 -05:00
Joseph Huber
8d8fa01a66 Reapply "[libc] Remove 'packaged' GPU build support (#100208)"
This reverts commit 550b83d658755664a7f0f93b36242e885743a91b.
2024-07-24 10:24:53 -05:00
Joseph Huber
550b83d658 Revert "[libc] Remove 'packaged' GPU build support (#100208)"
Summary:
I forgot that the OpenMP tests still look for this, reverting for now
until I can make a fix.

This reverts commit c1c6ed83e9ac13c511961e5f5791034a63168e7e.
2024-07-24 07:51:47 -05:00
Joseph Huber
9914609468 Revert "[libc] Enable 'sscanf' on the GPU (#100211)"
Summary:
This fails tests in some situations, revert until it can be fixed.
This reverts commit 445bb35f954ecd5c60ced71523f6b32fc306d557.
2024-07-24 07:46:39 -05:00
Joseph Huber
445bb35f95
[libc] Enable 'sscanf' on the GPU (#100211)
Summary:
We can enable the `sscanf` function on the GPU now.
2024-07-24 07:41:32 -05:00
Joseph Huber
c1c6ed83e9
[libc] Remove 'packaged' GPU build support (#100208)
Summary:
Previously, the GPU built the `libc` in a fat binary version that was
used to pass this to the link job in offloading languages like CUDA or
OpenMP. This was mostly required because NVIDIA couldn't consume the
standard static library version. Recent patches have now created the
`clang-nvlink-wrapper` which lets us do that. Now, the C library is just
included implicitly by the toolchain (or passed with -Xoffload-linker
-lc).

This code can be fully removed, which will heavily simplify the build
(and removed some bugs and garbage files I've encoutnered).
2024-07-24 07:22:49 -05:00
Joseph Huber
0420d2f97e [libc] Fix leftover debug commandline argument
Summary:
Fixes https://github.com/llvm/llvm-project/issues/100289
2024-07-23 21:35:42 -05:00
RoseZhang03
8972979c37
[libc] Updated header_generation.rst (#99712)
Added new headergen documentation.
2024-07-22 20:15:26 +00:00
Job Henandez Lara
c1562374c8
[libc][math][c23] Add entrypoints and tests for dsqrt{l,f128} (#99815) 2024-07-21 15:55:11 -04:00
Job Henandez Lara
af0f58cf14
[libc][math][c23] Add entrypoints and tests for fsqrt{,l,f128} (#99669) 2024-07-21 11:17:41 -04:00