Commit Graph

3873 Commits

Author SHA1 Message Date
Shourya Goel
b861539196 [libc][complex] fix compiler support matrix for cfloat128 (#122593)
Before this patch, [godbolt](https://godbolt.org/z/6PPsvv9qd) failed to
compile `cfloat128` with `-ffreestanding` but with the patch, the
compilation succeeds, [godbolt](https://godbolt.org/z/4M8zzejss).

Fixes: #122500

cc: @nickdesaulniers
2025-01-13 11:23:36 +05:30
wldfngrs
ecf4f95c4f [libc][math][c23] Add tanf16 function (#121018)
- Implementation of tan for 16-bit floating point inputs.
- Exhaustive tests across the 16-bit input range
2025-01-12 23:46:53 -05:00
Roland McGrath
5e4b41c1d5 [libc] Add compile tests for each public header (#122527)
This adds a test that consists of compiling `#include <...>`,
pretty much alone, for each public header file in each different
language mode (`-std=...` compiler switch) with -Werror and many
warnings enabled.

There are several headers that have bugs when used alone, and
many more headers that have bugs in certain language modes.  So
for now, compiling the new tests is gated on the cmake switch
-DLLVM_LIBC_BUILD_HEADER_TESTS=ON.  When all the bugs are fixed,
the switch will be removed so future regressions don't land.
2025-01-11 17:24:37 -08:00
Nick Desaulniers
85711bdda3 [libc][docs] update docs on how to build linux kernel headers from src (#122381)
It's simpler than the directions we have; which are very very Debian specific.
2025-01-10 14:40:57 -08:00
Prashanth
0afee850de [libc][docs] Add net/if.h documentation by referring to POSIX standards (#122406)
This pull request introduces the following changes to the project with
reference to issue ( #122006 ):

1. **Documentation Update**:
- Added a new YAML file `if.yaml` under `net` to document network
interface functions and macros.
   - The `if.yaml` file includes the following functions and macros:
     - Functions:
       - `if_freenameindex`
       - `if_indextoname`
       - `if_nameindex`
       - `if_nametoindex`
     - Macros:
       - `IF_NAMESIZE`

2. **CMake Configuration Update**:
- Updated the `CMakeLists.txt` file to create the necessary directory
for the `net` headers.
- Included the `net/if` documentation in the Sphinx build configuration.

3. **Index Update**:
- Updated the `index.rst` file to include a reference to the newly added
`net/if` documentation.

**Purpose**:
- This pull request adds documentation for network interface functions
and macros, ensuring they are included in the project's documentation.
- Updates the CMake configuration to support the new documentation.

**Testing**:
- Verified that the new YAML file is correctly referenced in the
`index.rst`.
- Ensured that the documentation builds without errors and includes the
new network interface documentation.

Co-authored-by: Nick Desaulniers <ndesaulniers@google.com>
2025-01-10 09:27:40 -08:00
Prashanth
dff7ef2353 [libc][docs] Add netinet/in header documentation by referring to POSIX standards (#122411)
This pull request introduces the following changes to the project with
reference to ( #122006 ):

1. **Documentation Update**:
- Added a new YAML file `in.yaml` to document network protocol and
address macros.
   - The `in.yaml` file includes the following macros:
     - `IPPROTO_IP`
     - `IPPROTO_IPV6`
     - `IPPROTO_ICMP`
     - `IPPROTO_RAW`
     - `IPPROTO_TCP`
     - `IPPROTO_UDP`
     - `INADDR_ANY`
     - `INADDR_BROADCAST`
     - `INET_ADDRSTRLEN`
     - `IPV6_JOIN_GROUP`
     - `IPV6_LEAVE_GROUP`
     - `IPV6_MULTICAST_HOPS`
     - `IPV6_MULTICAST_IF`
     - `IPV6_MULTICAST_LOOP`
     - `IPV6_UNICAST_HOPS`
     - `IPV6_V6ONLY`
     - `IN6_IS_ADDR_UNSPECIFIED`
     - `IN6_IS_ADDR_LOOPBACK`
     - `IN6_IS_ADDR_MULTICAST`
     - `IN6_IS_ADDR_LINKLOCAL`
     - `IN6_IS_ADDR_SITELOCAL`
     - `IN6_IS_ADDR_V4MAPPED`
     - `IN6_IS_ADDR_V4COMPAT`
     - `IN6_IS_ADDR_MC_NODELOCAL`
     - `IN6_IS_ADDR_MC_LINKLOCAL`
     - `IN6_IS_ADDR_MC_SITELOCAL`
     - `IN6_IS_ADDR_MC_ORGLOCAL`
     - `IN6_IS_ADDR_MC_GLOBAL`

_I believe, all these macros are necessary and should be documented._

2. **CMake Configuration Update**:
- Updated the `CMakeLists.txt` file to create the necessary directory
for the `netinet` headers.
- Included the `netinet/in` documentation in the Sphinx build
configuration.

3. **Index Update**:
- Updated the `index.rst` file to include a reference to the newly added
`netinet/in` documentation.

**Purpose**:
- This pull request adds documentation for network protocol and address
macros in the `netinet/in` header.
- Updates the CMake configuration to support the new documentation.

**Testing**:
- Verified that the new YAML file is correctly referenced in the
`index.rst`.
- Ensured that the documentation builds without errors and includes the
new network interface documentation.

This pull request ensures that the `netinet/in` header macros are
documented and included in the project's documentation, and updates the
CMake configuration to support these changes.
2025-01-10 09:24:02 -08:00
Prashanth
20f0290af0 [docs][libc] Add AIO documentation refering POSIX and include in build (#122219)
With reference to #122006 , add a new header reference (aio.yaml) to doc
2025-01-10 09:23:42 -08:00
Schrodinger ZHU Yifan
73dd730fb9 [libc] implement sys/uio/writev (#122233)
implement sys/uio/writev according to POSIX standard. This vectorized IO
API is needed by many logging libraries to achieve atomic logging
multiple strings.
2025-01-10 12:49:00 +08:00
Nick Desaulniers
9426fdd4cb [libc][test] fix memory leak pt.2 (#122384)
These were created with operator new (see `Test::createCallable`), so operator
delete should be used instead of free().

Fixes: #122369
Fixes: #122378
2025-01-09 14:46:52 -08:00
Nick Desaulniers
3caa68a021 [libc][test] fix memory leak (#122378)
Looks like the smart pointer I removed was being used to free the underlying
object.

Fixes: #122369
2025-01-09 14:15:31 -08:00
Nick Desaulniers
0efb376c20 [libc][test] remove C++ stdlib includes (#122369)
These make cross compiling the test suite more difficult, as you need
the
sysroot to contain these headers and libraries cross compiled for your
target.
It's straightforward to stick with the corresponding C headers.
2025-01-09 13:40:54 -08:00
Joseph Huber
0acdba83ae [libc] Remove leftover 'gpu/' source directory (#122368)
Summary:
This isn't used anymore, I moved the GPU extensions into `offload/`.
2025-01-09 14:46:34 -06:00
Alexey Samsonov
b30f9d74d6 [libc] Fix return value of __cxa_thread_atexit_impl function. (#122171)
This has been added in 0071a79532 to
support TLS destructors. Return value of __cxa_thread_atexit is supposed
to be the same as std::atexit - zero on success, non-zero on failure.
Update the code to do just that (also be consistent with llvm-libc's
existing atexit / at_quick_exit implementations).
2025-01-08 21:47:58 -08:00
Jack Huang
c6b7bd42d5 [libc] Support _IONBF buffering for read_unlocked (#120677)
Support _IONBF buffering for read_unlocked. Add the functions
read_unlocked_nbf() and read_unlocked_fbf().

Fixes: #120155
2025-01-09 11:24:16 +08:00
Alexey Samsonov
508398021d [libc] Add hardening for FixedVector data structure and fix exposed bug. (#122159)
Add LIBC_ASSERT statements to FixedVector implementation, and zero out
the memory when the elements are removed to flag out-of-bound access and
dangling pointer/reference access.

This change unmasks the bug in one of FixedVector uses for atexit
handlers: dangling reference use, which was actually led to crashes in
the wild (with prod blockstore implementation). Fix it in this CL.
2025-01-08 13:03:59 -08:00
Michael Jones
f9c2377fb6 [libc][NFC] Cleanup time.h (#122027)
While working on strftime I noticed some constants were being defined in
unexpected places. One thing led to another, and I ended up doing a
major cleanup of the time functions.

What's included:
All uses of <time.h> in /src and /test removed (except for LibcTest.cpp)
The various time constants have been moved to time_constants.h, and the
`time_constants` namespace.
struct tm gets its own type indirection header now.
2025-01-08 12:28:50 -08:00
Roland McGrath
cdbba15c6c [libc] Add --write-if-changed switch to hdrgen/main.py (#122037)
This avoids touching the output file when it hasn't changed.  The
cmake build integration now uses this so that touching a .yaml or
.h.def file in ways that don't affect the generated header output
won't cause unnecessary recompilations.
2025-01-08 11:00:31 -08:00
Michael Jones
ca3fd63369 [libc] clean up the hdrgen docs a bit (#121974)
Since the files have been reorganized, the readme is out of date. This
patch updates it to be more accurate.
2025-01-07 16:29:01 -08:00
Roland McGrath
6ad0dcf67f [libc] Revamp hdrgen command line and build integration (#121522)
This adds a new main command-line entry point for hdrgen, in the
new main.py.  This new interface is used for generating a header.
The old ways of invoking yaml_to_classes.py for other purposes
are left there for now, but `--e` is renamed to `--entry-point`
for consistency with the new CLI.

The YAML schema is expanded with the `header_template` key where
the corresponding `.h.def` file's path is given relative to where
the YAML file is found.  The build integration no longer gives
the `.h.def` path on the command line.  Instead, the script now
emits a depfile that's used by the cmake rules to track that.
The output file is always explicit in the script command line
rather than sometimes being derived from a directory path.
2025-01-07 15:56:12 -08:00
Prabhuk
3b19e787fc [libc] Keep framepointers for baremetal (#121836)
Keep framepointers enabled by default for the default baremetal libc
builds.

Frame pointers help unwind the stack and unwinding without frame pointer
is complex and increaseis the code size. This code size increase is
potentially larger than the savings achieved by disabling frame
pointers. Retaining the original behavior of retaining frame pointers as
the default behavior.
2025-01-07 13:22:14 -08:00
Roland McGrath
ce33a48efd [libc] Keep headers compatible with -std=c89 mode (#121981)
C89 doesn't have the `restrict` keyword.  When in `-std=c89`
mode, GNU-compatible compilers require the `__restrict` spelling.
2025-01-07 12:13:24 -08:00
Joseph Huber
ac604b2fa6 [libc] Switch to using the generic <gpuintrin.h> implementations (#121810)
Summary:
This patch switches the GPU utility helpers to wrapping around the
gpuintrin.h ones with a C++ flavor.
2025-01-07 13:08:39 -06:00
Nick Desaulniers
0a58a1c9a2 [libc] update todo with bug link 2025-01-07 08:55:14 -08:00
Joseph Huber
f4bab06c97 [libc] Split AMDGPU and NVPTX configs into separate folders (#120153)
Summary:
This is a holdover from when these targets were merged. They're
basically the same but there's no reason they should be treated as
identical. I think we will live with a little duplication.
2025-01-06 13:49:19 -06:00
Nick Desaulniers
98b3191a34 [libc][docgen] regen docgen via cmake (#119628)
Now, `ninja docs-libc-html` will re-run docgen.

Previously, we would run docgen offline, and commit the result.

Now we no longer need to do that; docgen is invoked from the
dependencies of the `docs-libc-html` target on demand. This
commit removes the dynamically generated .rst files (keeping
the static ones that haven't been converted to docgen), and
fixes up some mistakes I failed to cleanup recently since I
didn't have such automation in place to catch such bugs.
2025-01-06 08:52:08 -08:00
Joseph Huber
7cb6e6bced [libc] Fix sort test failing on NVPTX
Summary:
This test uses too much stack and crashes, make the buffer `static` to
push it to `.bss`. This shouldn't change behavior because the tests are
all run single threaded.
2025-01-06 09:04:31 -06:00
JoelWee
f0247081fa Fix after #121482 (#121764) 2025-01-06 13:17:37 +00:00
Schrodinger ZHU Yifan
de7f531106 [libc][fuzz] workaround gcc's constexpr capture issue in sort fuzzer (#121684)
Fix the build problem at
https://lab.llvm.org/buildbot/#/builders/131/builds/13255
2025-01-05 09:12:18 -08:00
Lukas Bergdoll
a738d81cd2 [libc] Improve qsort (with build fix) (#121482) 2025-01-05 06:10:41 +08:00
Joseph Huber
f855ceeefc [libc][NFC] use __has_builtin instead of checking macros. 2025-01-04 15:36:08 -06:00
Alexey Samsonov
9a95c097d0 [libc] Remove some unused includes from headers under src/math/generic. (#121632)
These were indicated by Clang include-cleaner.
2025-01-04 10:02:48 -08:00
Mikhail R. Gadelha
82c0f68c04 [libc] Remove assert to fix rv32 buildbot 2025-01-03 22:03:30 -03:00
Roland McGrath
4010e0c45b [libc] Use __attribute__((__noreturn__)) for _Noreturn in C < 11 (#121252)
When in modes like C99, the _Noreturn keyword is not available in
C.  But GNU-compatible compilers have a `noreturn` attribute with
the same effect on function declarations.
2025-01-02 16:57:31 -08:00
Roland McGrath
508929d42a [libc] Make GpuHeaderFile a subclass (#121445)
Replace copy&paste from HeaderFile to GpuHeaderFile with
subclassing.  Only the __str__ method differs.
2025-01-01 18:16:32 -08:00
Roland McGrath
62cd050b63 [libc] Move hdrgen yaml files into include/ (#121443)
The .yaml files should live next to the corresponding .h.def
files in libc/include/, rather than next to the implementation of
the tool in libc/utils/hdrgen/.  As with the .h.def files, there
is no need for a yaml/ subdirectory under include/.  This simpler
layout is more natural for maintenance and also simplifies build
integration outside the LLVM CMake build.
2025-01-01 17:03:35 -08:00
Tristan Ross
1d0f40ba05 [libc] fix generic __stack_check_fail for fuchsia (#121401) 2024-12-31 19:36:24 -05:00
Tristan Ross
6f3d1d3018 [libc] add __stack_chk_guard to generic (#121121) 2024-12-31 02:34:16 -05:00
Roland McGrath
07e13b764d [libc] Remove unnecessary subdirectory layers in utils/hdrgen (#121363)
Two extra layers of subdirectory for a handful of single-symbol
Python source files did not improve anything, and it complicated
integration of the hdrgen Python outside the LLVM CMake build.
2024-12-30 17:28:59 -08:00
Roland McGrath
9abcca5e25 [libc] Move hdrgen into utils/ subdirectory (#121256) 2024-12-30 15:36:53 -08:00
Roland McGrath
70c9152f99 [libc] Fix non-calls to cpp::is_complex_type_same (#121257)
Some uses were not actually calls, just references to the name.
2024-12-30 14:35:31 -08:00
Schrodinger ZHU Yifan
0b96f1cf68 Revert "[libc] Improve qsort" (#121303)
Reverts llvm/llvm-project#120450
2024-12-29 16:03:53 -05:00
Lukas Bergdoll
d2e71c92b8 [libc] Improve qsort (#120450) 2024-12-29 14:55:44 -05:00
Prabhuk
7deaed975e [libc] Reduce binary size for baremetal targets (#121164)
For `math` functions we must choose size optimized implementations.
Removing framepointers will also help with binary size savings.
2024-12-26 15:55:39 -08:00
Shourya Goel
9f75b6664f [libc][complex] fix buildbot errors (#121141)
Fix buildbot errors due to #121140
2024-12-26 12:57:48 +05:30
Shourya Goel
abd9102344 [libc][complex] add cfloat16 and cfloat128 compiler flags (#121140)
Proper fix for the temporary fix in #114696
2024-12-26 12:50:07 +05:30
Shourya Goel
ff97daadcd Revert "[libc][complex] enable CFP128 entrypoints on X86_64 (#121111)" (#121113)
This reverts commit dd9c5c1182.
2024-12-25 20:56:13 +05:30
Shourya Goel
dd9c5c1182 [libc][complex] enable CFP128 entrypoints on X86_64 (#121111) 2024-12-25 20:45:32 +05:30
Joseph Huber
3bbd53ce97 [libc] Remove old RPC host call extension for GPU (#120800)
Summary:
This was originally a hacked together function that served to just
implement some features for OpenMP. That has been moved into OpenMP
itself now that we have exported RPC properly. This can now be deleted.
2024-12-20 19:34:05 -06:00
Alexey Samsonov
6ecedb05b0 [libc] Make a couple of math smoke tests more robust. (#120808)
Make sure to clear out all FE_ALL_EXCEPT bits both before and after
invoking function under test -- otherwise the very first check for the
exception bits in the unit test may fail due to bits set prior to test
invocation.
2024-12-20 16:06:20 -08:00
Michael Jones
0a94ee694f [libc] update host build docs (#120147)
Update the host build docs to better reflect the current recommended
process.
2024-12-19 13:13:55 -08:00