4063 Commits

Author SHA1 Message Date
Shourya Goel
7f37b34d31
[libc][complex] Testing infra for MPC (#121261)
This PR aims to add the groundwork to test the precision of libc complex
functions against MPC. I took `cargf` as a test to verify that the infra
works fine.
2025-01-28 11:01:16 +05:30
Joseph Huber
7b1becd940
[libc] Add CMake cache file for the GPU build (#124589)
Summary:
This introduces libc cache files and adds one for building the GPU
support. The cache files will set defaults for these arguments which can
be overridden if the user needs to. They also serve as documentation for
how the builid is expected to look.
2025-01-27 11:46:35 -06:00
Petr Hosek
73b462321c
[libc] Include size_t type header in strings.h (#124352)
A number of functions in strings.h take size_t as an argument.
2025-01-24 13:39:20 -08:00
siya100
d398c0c97a
[libc][cpio] Add cpio.h header. (#123798)
[libc][docs] add cpio to documentation and include related functi… 
These changes ensure that the cpio header is documented properly
with respect to the issue
(https://github.com/llvm/llvm-project/issues/122006 ).

**Changes:**
1. **cpio.yaml**: Created a new YAML file for cpio with functions
and related macros.
2. **CMakeLists.txt**: Added cpio to the documentation
directories.
3. **index.rst**: Included `cpio` in the documentation index.

---------

Co-authored-by: siya <siya@Siya.com>
2025-01-24 12:32:51 -08:00
lntue
a976036a10
[libc][NFC] Remove extra ; in exhaustive_test.h. (#124216)
These cause warnings when running check-libc.
2025-01-24 11:57:43 -05:00
Joseph Huber
256f40d0e6
[libc] Use the NVIDIA device allocator for GPU malloc (#124277)
Summary:
This is a blocker on another patch in the OpenMP runtime. The problem is
that NVIDIA truly doesn't handle RPC-based allocations very well. It
cannot reliably update the MMU while a kernel is running and it will
usually deadlock if called from a separate thread due to internal use of
TLS.

This patch just removes the definition of `malloc` and `free` for NVPTX.
The result here is that they will be undefined, which is the cue for the
`nvlink` linker to define them for us. So, as far as `libc` is concerned
it still implements malloc.
2025-01-24 10:17:20 -06:00
lntue
b11529bfa2
[libc] Use -fno-math-errno to for __builtin_fma* to generate fma instructions. (#124200)
Fixes https://github.com/llvm/llvm-project/issues/123387
2025-01-23 20:38:53 -05:00
Nick Desaulniers
631a6e0004
[libc][wchar] implement wcslen (#124150)
Update string_utils' string_length to work with char* or wchar_t*, so that it
may be reusable when implementing wmemchr, wcspbrk, wcsrchr, wcsstr.

Link: #121183
Link: #124027

Co-authored-by: Nick Desaulniers <ndesaulniers@google.com>

---------

Co-authored-by: Tristan Ross <tristan.ross@midstall.com>
2025-01-23 13:33:04 -08:00
Prashanth
24b1373650
[libc][docs] Add Unistd header's page to the status of implementations doc (#123068)
These changes ensure that the unistd header is documented properly with
respect to the issue ( https://github.com/llvm/llvm-project/issues/122006 ) .
2025-01-23 11:30:01 -08:00
Alex Prabhat Bara
cb981cc540
[libc] added btowc to wchar.h generated header (#124168)
Fixes: #124152
2025-01-23 11:25:14 -08:00
Joseph Huber
db6b7a84e6
[libc][NFC] Strip all training whitespace and missing newlines (#124163) 2025-01-23 12:02:54 -06:00
Alex Prabhat Bara
6045146014
[libc] change return type of pthread_setspecific to int in generated header (#124072)
Fixes: #124032
2025-01-23 10:01:39 -08:00
Nick Desaulniers
8e79ade49d
[libc][LIBC_ADD_NULL_CHECKS] replace volatile deref with __builtin_trap (#123401)
Also, update the unit tests that were checking for SIGSEGV to not check for a
specific signal.

To further improve this check, it may be worth:
- renaming the configuration option/macro/docs to be clearer about intent.
- swap __builtin_trap for __builtin_unreachable, removing the preprocessor
  variants of LIBC_CRASH_ON_NULLPTR, then unconditionally using
  `-fsanitize=unreachable -fsanitize-trap=unreachable` in cmake flags when
  LIBC_ADD_NULL_CHECKS is enabled.
- building with `-fno-delete-null-pointer-checks` when LIBC_ADD_NULL_CHECKS (or
  when some larger yet to be added hardening config) is enabled.

Link: #111546
2025-01-22 09:34:59 -08:00
Nick Desaulniers
ddb8607fe8
[libc][docs] disable pthreads docs (#123824)
Having a target named pthreads is breaking when multiple runtimes are enabled.
Disable this target for now so that the builds go back to green (and sites get
updated).

Link: https://github.com/llvm/llvm-zorg/issues/359#issuecomment-2600285688
Link: #122006
Link: #122497
Link: #123821
2025-01-22 09:33:53 -08:00
Nick Desaulniers
f3c3a9b882
[libc][cmake] error if user disables sanitizers but wants scudo (#123834)
I found this out the hard way...though we don't suggest in our docs setting or
unsetting COMPILER_RT_BUILD_SANITIZERS, I had this explicitly disabled in a
cmake script I was using to setup an llvm-libc based sysroot. While the libc
compiled, hello world failed to link due to missing references to malloc at
link time. Though I had set the cmake variables to opt into using scudo,
apparently explicitly disabling sanitizers will still prevent scudo from being
built... Check for this at configure time and stop the build then.
2025-01-22 09:33:08 -08:00
Nick Desaulniers
e2d9e999a2
[libc] fix -Wextra-semi (#123783)
Found while trying to consolidate our command line flags between tests and
underlying object files.

    error: extra ';' after member function definition [-Werror,-Wextra-semi]

Link: #119281
2025-01-21 13:18:23 -08:00
Daniel Thornburgh
98067a3225 [libc] Outer size, not inner size 2025-01-17 13:15:53 -08:00
Daniel Thornburgh
a440c3ea89 [libc] Correct previous malloc fix 2025-01-17 13:14:03 -08:00
Daniel Thornburgh
5db28679da [libc] Fix malloc riscv32 test failures from #117815 2025-01-17 13:07:46 -08:00
Daniel Thornburgh
e237e37c62 [libc] Fix riscv32 Block assertion failure on #117815 2025-01-17 12:27:43 -08:00
Prashanth
f12e0c9c3a
[libc][docs] Add sys/stat page to the status of implementations docs (#122997)
These changes ensure that the sys/stat header is documented properly
with respect to the issue ( #122006 ) .
2025-01-17 10:19:22 -08:00
Prashanth
d54d8d7e5a
[libc][docs] Add termios page to the status of implementations docs (#123004)
These changes ensure that the termios header is documented properly with
respect to the issue ( https://github.com/llvm/llvm-project/issues/122006 ) .
2025-01-17 08:59:49 -08:00
Prashanth
9f627cf540
[libc][docs] Add sys/time page to the status of implementations docs (#123000)
These changes ensure that the sys/time header is documented properly
with respect to the issue ( #122006 ) .
2025-01-17 08:38:03 -08:00
Roland McGrath
771045377b
[libc] Fix sigset_t type definition (#123277)
The libc headers are C, not C++.
2025-01-16 22:32:23 -08:00
Roland McGrath
a4e87da963
[libc] Make headers compatible with C++ < 11 (#123260)
C++11 introduced `noexcept`, but `throw()` can be used in older
versions of the language.
2025-01-16 19:21:40 -08:00
Roland McGrath
421fc04748
[libc] Fix deprecated operator"" syntax (#123259) 2025-01-16 19:21:17 -08:00
Roland McGrath
906cbbbd3c
[libc] Fix hdrgen output for no-argument functions (#123245)
The hdrgen output is C, not C++.
2025-01-16 19:20:53 -08:00
Daniel Thornburgh
305639526a [NFC][libc] Delete dead BlockStatus enum type 2025-01-16 15:16:33 -08:00
Daniel Thornburgh
859b4f1938 [NFC][libc] Add Block::PREV_FIELD_SIZE for use in tests 2025-01-16 15:11:03 -08:00
Daniel Thornburgh
cd92aedf1b [NFC][libc] Remove Block::ALIGNMENT and Block::BLOCK_OVERHEAD 2025-01-16 14:25:02 -08:00
Daniel Thornburgh
99d40fe8f0 [libc] Fix freelist_heap_test.cpp warnings 2025-01-16 12:04:44 -08:00
Daniel Thornburgh
60de7dc886
[libc] Fix malloc Block alignment issue on riscv32 (#117815)
Aligning blocks to max_align_t is neither necessary nor sufficient to
ensure that the usable_space() is so aligned. Instead, we make this an
invariant of Block and maintain it in init() and split().

This allows targets like riscv32 with small pointers and large
max_align_t to maintain the property that all available blocks are
aligned for malloc(). This change adjusts the tests to match and also
updates them closer to llvm-libc style.
2025-01-16 11:56:46 -08:00
Prashanth
fadb0e9b52
[libc][docs] add sys/wait to documentation and include related functi… (#122598)
These changes ensure that the `sys/wait` header is documented properly
with respect to the issue (#122006 ).

**Changes:**
1. **wait.yaml**: Created a new YAML file for `sys/wait` with functions
(`wait`, `waitid`, `waitpid`) and related macros.
2. **CMakeLists.txt**: Added `sys/wait` to the documentation
directories.
3. **index.rst**: Included `sys/wait` in the documentation index.
2025-01-15 15:45:16 -08:00
Schrodinger ZHU Yifan
defd0d966d
[libc] implement unistd/getentropy (#122692)
Implement GNU extension getentropy. This function is used by many
programs to acquire entropy without handling the loop of getrandom.
2025-01-15 18:27:05 +08:00
Roland McGrath
1dbc98294a
[libc] Fix SPDX-License-Identifier file header comment typos (#122776) 2025-01-14 10:53:41 -08:00
Nick Desaulniers
692c77f2af
[libc][docs] reorder docs to be more beginner friendly (#122376)
This commit does a few things, with the intent to make it more straightforward
to potential future users how to get started with llvm-libc. Answers to "What's
the status and how do I use it?" are front and center, "above the fold."

This commit does a few things:
* reorganize the landing page's toctree: start with implementation status, arch
* support, platform support, and
    compiler support.
  * Then a (new) simple getting started page using full host builds. Then more
  * Advanced topics such as host vs cross builds, overlay mode,
    gpu builds and additional configuration options.
* Remove c23 status, the old fullbuild_mode landing page, and
  usage_modes landing pages. c23 status isn't as interesting as I originally
  thought it might.

We should point people at full host builds to start, then link to more info on
cross compilation, or overlay mode as more advanced topics. I assert most users
starting out won't care about those.
2025-01-14 09:38:15 -08:00
Nick Desaulniers
539b15b41a
[libc][docs] stub out pthread.h support (#122497)
Link: #122006
2025-01-14 08:48:38 -08:00
Prashanth
c2771ca284
[libc][docs] Add sys/resource header's implementation status (#122563)
### Add sys/resource header's implementation status ( #122006 )

#### Changes:
1. **CMakeLists.txt**: Added `sys/resource` to the list of documentation
directories.
2. **index.rst**: Included `sys/resource` in the documentation index.
3. **resource.yaml**: Created a new YAML file for `sys/resource` with
functions and macros which manages system resources.

This PR adds documentation support for the `sys/resource` header,
including functions and macros as per the latest POSIX standards.
2025-01-14 08:44:46 -08:00
Nick Desaulniers
091adb8807
[libc][cmake] move _get_{common|hermetic}_test_compile_options to LLVMLibCTestRules.cmake (#122549)
They're only used in that file, which is more appropriate than
LLVMLibCCompileOptionRules.cmake since they're strictly related to tests.

Remove unused flags param from _get_hermetic_test_compile_options, and flags
that were already set by a prior call to _get_common_test_compile_options.
2025-01-14 08:36:04 -08:00
Jay Foad
e87f94a6a8
[llvm-project] Fix typos mutli and mutliple. NFC. (#122880) 2025-01-14 11:59:41 +00:00
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