Commit Graph

1832 Commits

Author SHA1 Message Date
Krishna Pandey
6f750cfb96 [libc][unistd] Implement setsid (#125704)
https://man7.org/linux/man-pages/man2/setsid.2.html

closes #124632
2025-02-05 10:08:16 -08:00
Roland McGrath
66ce716676 Revert "[libc] Make LlvmLibcStackChkFail.Smash test compatible with asan, hwasan" (#125785)
Reverts llvm/llvm-project#125763

This causes failures in asan. More thought is needed.
2025-02-04 16:06:21 -08:00
Roland McGrath
1e7624ca4f [libc] Make LlvmLibcStackChkFail.Smash test compatible with asan, hwasan (#125763)
Previously this test was entirely disabled under asan, but not
hwasan.  Instead of disabling the test, make the test compatible
with both asan and hwasan by disabling sanitizers only on the
subroutine that does the stack-smashing.
2025-02-04 13:42:23 -08:00
Simon Tatham
b53da77c50 [libc] Alternative algorithm for decimal FP printf (#123643)
The existing options for bin→dec float conversion are all based on the
Ryū algorithm, which generates 9 output digits at a time using a table
lookup. For users who can't afford the space cost of the table, the
table-lookup subroutine is replaced with one that computes the needed
table entry on demand, but the algorithm is otherwise unmodified.

The performance problem with computing table entries on demand is that
now you need to calculate a power of 10 for each 9 digits you output.
But if you're calculating a custom power of 10 anyway, it's easier to
just compute one, and multiply the _whole_ mantissa by it.

This patch adds a header file alongside `float_dec_converter.h`, which
replaces the whole Ryū system instead of just the table-lookup routine,
implementing this alternative simpler algorithm. The result is accurate
enough to satisfy (minimally) the accuracy demands of IEEE 754-2019 even
in 128-bit long double. The new float128 test cases demonstrate this by
testing the cases closest to the 39-digit rounding boundary.

In my tests of generating 39 output digits (the maximum number supported
by this algorithm) this code is also both faster and smaller than the
USE_DYADIC_FLOAT version of the existing Ryū code.
2025-02-04 08:57:54 +00:00
Simon Tatham
c06d0ff806 [libc] Optimize BigInt→decimal in IntegerToString (#123580)
When IntegerToString converts a BigInt into decimal, it determines each
digit by computing `n % 10` and then resets n to `n / 10`, until the
number becomes zero. The div and mod operations are done using
`BigInt::divide_unsigned`, which uses the simplest possible bit-by-bit
iteration, which is a slow algorithm in general, but especially so if
the divisor 10 must first be promoted to a BigInt the same size as the
dividend. The effect is to make each division take quadratic time, so
that the overall decimal conversion is cubic – and the division is
quadratic in the number of _bits_, so the constant of proportionality is
also large.

In this patch I've provided custom code to extract decimal digits much
faster, based on knowing that the divisor is always 10, and processing a
word at a time. So each digit extraction is linear-time with a much
smaller constant of proportionality.

Full comments are in the code. The general strategy is to do the
reduction mod 10 first to determine the output digit; then subtract it
off, so that what's left is guaranteed to be an exact multiple of 10;
and finally divide by 10 using modular-arithmetic techniques rather than
reciprocal-approximation-based ordinary integer division.

I didn't find any existing tests of IntegerToString on a BigInt, so I've
added one.
2025-02-04 08:57:41 +00:00
Roland McGrath
648981f913 [libc] Build with -Wdeprecated, fix some warnings (#125373)
While GCC's -Wdeprecated is on by default and doesn't do much,
Clang's -Wdeprecated enables many more things.  More apply in
C++20, so switch a test file that tickled one to using that.  In
future, C++20 should probably be made the baseline for compiling
all the libc code.
2025-02-01 18:22:18 -08:00
lntue
c47a57393c [libc] Fix conversion warnings for float16 tests. (#124830)
Fixes https://github.com/llvm/llvm-project/issues/124801.
2025-01-28 16:00:05 -05:00
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
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
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
Joseph Huber
db6b7a84e6 [libc][NFC] Strip all training whitespace and missing newlines (#124163) 2025-01-23 12:02:54 -06: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
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
Roland McGrath
421fc04748 [libc] Fix deprecated operator"" syntax (#123259) 2025-01-16 19:21:17 -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
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
Jay Foad
e87f94a6a8 [llvm-project] Fix typos mutli and mutliple. NFC. (#122880) 2025-01-14 11:59:41 +00:00
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
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
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
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
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
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
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
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
Nick Desaulniers
1d06157b9e [libc] fix -Wgcc-compat (#120303)
I don't quite recall why I added those in the first place. These tests build
without diagnostics for both clang and GCC with this fix.

Fixes: #114653
2024-12-17 13:30:20 -08:00
Shourya Goel
c98e79d856 [libc][complex] Implement different flavors of the cproj function (#119722)
Refer section 7.3.9.5 of ISO/IEC 9899:2023
2024-12-18 02:04:50 +05:30
Tristan Ross
7477b61b24 [libc] Add unistd overlay (#119312)
Reverts the revert #119295 of #118882 by expanding #118882 with
additional fixes which made CI unhappy.
2024-12-17 10:40:22 -08:00
Petr Hosek
51a0919412 [libc] Exclude FreeListHeap test and fuzzer on GPU (#120137)
FreeListHeap uses the _end symbol which conflicts with the _end symbol
defined by GPU start.cpp files so for now we exclude the test and the
fuzzer on GPU.
2024-12-16 13:28:42 -08:00
Petr Hosek
7bf3137c39 [libc] Breakup freelist_malloc into separate files (#119806)
This better matches the structure we use for the rest of libc.
2024-12-16 10:30:27 -08:00
Schrodinger ZHU Yifan
f75c84674c [libc] fix atomic and apply an explicit check on unique object representations (#119715) 2024-12-16 12:04:52 -05:00
wldfngrs
6a865b6d3d [libc][math][c23] Add cosf16 function (#118785) 2024-12-15 18:58:54 +01:00
lntue
4eec286b51 [libc] Add MPFR testing infra for float128. (#119499) 2024-12-13 09:32:38 -05:00
Petr Hosek
379cc44f56 Revert "[libc] Breakup freelist_malloc into separate files" (#119749)
Reverts llvm/llvm-project#98784 which broke libc builders.
2024-12-12 13:28:30 -08:00
Petr Hosek
4e2a9e50f6 [libc] Breakup freelist_malloc into separate files (#98784)
This better matches the structure we use for the rest of libc.
2024-12-12 11:24:36 -08:00