3945 Commits

Author SHA1 Message Date
PiJoules
ec7167bac7
[libc] Disable fixed point printing for baremetal (#126115)
This follows suite with disabling float printing.
2025-02-06 11:31:05 -08:00
Simon Tatham
7ef33e609c
[libc] Fix recently introduced integer-type warnings (#125864)
These warnings all come up in code modified by one of my two recent
commits c06d0ff806b72b1 and b53da77c505a2d3, and all relate to implicit
integer type conversion. In a build of ours with strict compile options
two of them became errors. Even without that problem, it's worth fixing
them to reduce noise that might hide a more serious warning.
2025-02-06 09:14:59 +00:00
c8ef
e1c63bbde5
[libc] implement sys/uio/readv (#124718)
Closes #124694.

This patch adds the `sys/uio/readv` function.
ref:
https://pubs.opengroup.org/onlinepubs/009696699/functions/readv.html
2025-02-06 09:28:20 +08:00
Alan Zhao
fd4c4ed712
[libc] Add returns_twice attribute to setjmp(3) (#124370)
This is to ensure that calls to `setjmp(3)` result in correct code
generation that respects `setjmp(3)`'s `returns_twice` behavior.
Otherwise, we might run into bugs (for example, Clang may perform
tail-call optimization on this function if `-fno-builtins` is set
(#122840)).

---------

Co-authored-by: Nick Desaulniers <nick.desaulniers@gmail.com>
2025-02-05 14:37:03 -08:00
Nick Desaulniers
72aa3889fb
[libc][poll] remove entrypoint for riscv (#125941)
riscv32 specifically doesn't provide EITHER SYS_poll or SYS_ppoll. We may be
able to reimplement poll in terms of syscalls to SYS_ppoll_time64, but will
leave that as a TODO for the future. (Such as when we want to be able to cross
compile for riscv32).

Link: #125940
Fixes: #125118
2025-02-05 13:56:30 -08:00
Nick Desaulniers
718b16a0fc
[libc][wait] add comment about __W_CONTINUED value (#125934) 2025-02-05 13:43:48 -08:00
Nick Desaulniers
8e35b3d29b
[libc][POSIX][poll.h] implement poll (#125118)
Simple syscall.

Fixes: #124647
2025-02-05 13:24:39 -08:00
Nick Desaulniers
b4d547ac82
[libc][wait] hard code __W_CONTINUED for SYS_waitid fallback (#125929)
riscv32 currently doesn't have SYS_wait4, so wait4 is implemented via fallback
to SYS_waitid. In #125572, I missed that we had one use of the removed
__W_CONTINUED value. Hard code it here.

Fixes: #125572
2025-02-05 13:10:53 -08:00
Roland McGrath
4eab219487
[libc] Remove LlvmLibcStackChkFail.Smash test (#125919)
This test was problematic, and also unnecessary.  It's not really
a test of the libc functionality or ABI.  That's already covered
by the LlvmLibcStackChkFail.Death test.  The Smash test was in
fact just testing that the compiler produces the call in the
expected situation.  That's a compiler test, not a libc test.

It's not really feasible to make a test like this both reliable
and safe.  Since it's not something libc needs to test, it's not
worth trying.
2025-02-05 12:34:19 -08:00
lntue
46c4845244
[libc][cmake] Do not overwrite SKIP_FLAG_EXPANSION_*. (#125762)
So that users can set these manually if needed.
2025-02-05 14:01:25 -05:00
Joseph Huber
2d8106cb5a
[Clang] Add width handling for <gpuintrin.h> shuffle helper (#125896)
Summary:
The CUDA impelementation has long supported the `width` argument on its
shuffle instrucitons, which makes it more difficult to replace those
uses with this helper. This patch just correctly implements that for
AMDGPU and NVPTX so it's equivalent to `__shfl_sync` in CUDA. This will
ease porting.

Fortunately these get optimized out correctly when passing in known
widths.
2025-02-05 12:38:48 -06:00
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
Nick Desaulniers
57614a340c
[libc][sys/wait][linux] add missing and clean up existing macros (#125572)
This patch does a few things:
- replace macro definitions with an inclusion of the linux/wait.h kernel
  header.
  - WNOHANG
  - WUNTRACED
  - WEXITED
  - WCONTINUED
  - WSTOPPED
  - P_ALL
  - P_PID
  - P_PGID
  - P_PIDFD
- Add missing macro definitions mandated by POSIX. Some are needed to
  build LLVM.
  - WCOREDUMP
  - WIFCONTINUED
  - WIFSIGNALELD
  - WIFSTOPPED
  - WSTOPSIG
- Remove glibc style __W* macros. Users should stick with the POSIX
  macros. We can re-add them if necessary.
  - __WEXITSTATUS
  - __WTERMSIG
  - __WIFEXITED
  - __WIFSIGNALED
  - __WIFSTOPPED
  - __WIFCONTINUED
  - __WCOREDUMP
  - __W_EXITCODE
  - __W_STOPCODE
  - __W_CONTINUED
  - __WCOREFLAG

Fixes: #124944
2025-02-05 10:01:50 -08:00
Krishna Pandey
19c3e2f7de
[libc] Fix all imports of src/string/memory_utils (#114939)
Fixed imports for all files *within* `libc/src/string/memory_utils`.
Note: This doesn't include **all** files that need to be fixed.

Fixes #86579
2025-02-05 09:24:44 -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
5afb31dbd6
[libc][float_dec_converter_limited] Add missing LIBC_INLINE (#125655)
This caused a build failure in check-libc introduced by commit
b53da77c505a2d3.
2025-02-04 09:20:36 +00: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
Joseph Huber
36d6b63f85 [libc][NFC] Silence C99 extension warnings on clang for RPC
Summary:
This only shows up during the build of the server, silence it.
2025-02-03 16:16:18 -06: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
Alex Prabhat Bara
9b52dbe0e0
[libc] added _POSIX_ARG_MAX in limits.h (#124954)
Fixes: #124947
2025-01-30 12:39:49 -08:00
lntue
bcf306e0eb
[libc] Update include directory for libcMPCWrapper target when LIBC_MPC_INSTALL_PATH is set. (#124810) 2025-01-29 15:19:25 -05:00
Joseph Huber
26f4e2a701 [libc][docs] Fix the RPC documentation leaking ports
Summary:
Forgot to close it, that'll make it deadlock after awhile.
2025-01-28 15:26:10 -06:00
lntue
ed199c8d76
[libc] Workaround for gcc complaining about implicit conversions with the ternary ?: operator. (#124820)
Fixes https://github.com/llvm/llvm-project/issues/120427,
https://github.com/llvm/llvm-project/issues/122745

This is caused by a -Wconversion false-positive bug in gcc:
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=101537
2025-01-28 16:04:57 -05: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
Alex Prabhat Bara
a255da0c53
[libc] clean up duplicated includes in generated headers (#124524)
Fixes: #124149
2025-01-28 12:22:51 -08:00
lntue
a080498c92
[libc] Update include directory for libcMPCommon target when LLVM_LIBC_MPFR_INSTALL_PATH is set. (#124765)
Fix the current riscv32 bot failures.
2025-01-28 11:54:55 -05:00
c8ef
648912582c
[libc] Add FILENO related macros to unistd.h. (#124688)
Closes #124637.

This is necessary to build LLVM with LLVM-libc and align the behavior
with other libc implementations.
ref: https://pubs.opengroup.org/onlinepubs/9799919799/basedefs/unistd.h.html
2025-01-29 00:45:01 +08:00
c8ef
5a8fe9e9a7
[libc] Revise the definition of {get, set}rlimit. (#124701)
Closes #124633.

Some parameter types in the definition of `{get, set}rlimit` currently
do not match the standard. This patch resolves the issue.
ref: https://man7.org/linux/man-pages/man2/getrlimit.2.html
2025-01-29 00:24:11 +08:00
c8ef
8ce0d05b88
[libc] Revise the definition of posix_spawn. (#124686)
Closes #124635.

Some parameter types in the definition of `posix_spawn` currently do not
match the standard. This patch resolves the issue.
ref: https://man7.org/linux/man-pages/man3/posix_spawn.3.html
2025-01-29 00:23:09 +08:00
Shourya Goel
839cdb58e7
[libc][complex] remove -ffreestanding flag from MPFRUtils compile options (#124702)
Fixes buildbot error in #121261
2025-01-28 11:19:15 +05:30
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