4063 Commits

Author SHA1 Message Date
Tristan Ross
4e841d7d63
[libc] add uefi docs (#131426)
Adds documentation for the UEFI target since #131246 was merged.
2025-03-16 10:21:19 -07:00
Tristan Ross
bb694998d2
[libc] init uefi (#131246)
Initial UEFI OS target support after the headers. This just defines
enough that stuff might try and compile. Test with:
```
$ cmake -S llvm -B build -G Ninja -DLLVM_RUNTIME_TARGETS=x86_64-unknown-uefi-llvm -DRUNTIMES_x86_64-unknown-uefi-llvm_LLVM_ENABLE_RUNTIMES=libc -DRUNTIMES_x86_64-unknown-uefi-llvm_LLVM_LIBC_FULL_BUILD=true -DCMAKE_C_COMPILER_WORKS=true -DCMAKE_CXX_COMPILER_WORKS=true -DLLVM_ENABLE_PROJECTS="clang;lld" -DCMAKE_BUILD_TYPE=Debug -DLLVM_ENABLE_LIBCXX=true -DLLVM_HOST_TRIPLE=aarch64-unknown-linux-gnu -DLLVM_DEFAULT_TARGET_TRIPLE=x86_64-unknown-uefi-llvm -DCMAKE_INSTALL_LIBDIR=build/target/lib
$ ninja -C build
```
2025-03-14 20:15:24 -07:00
lntue
d0a0de50f7
[libc] Fix implicit conversion warnings in tests. (#131362) 2025-03-14 14:24:11 -04:00
Joseph Huber
fdb4b89bc0 [libc] Fix memmove macros for unreocognized targets 2025-03-14 10:25:42 -05:00
Joseph Huber
e8117026a9
[libc] Default to byte_per_byte instead of erroring (#131340)
Summary:
Right now a lot of the memory functions error if we don't have specific
handling for them. This is weird because we have a generic
implementation that should just be used whenever someone hasn't written
a more optimized version. This allows us to use the `libc` headers with
more architectures from the `shared/` directory without worrying about
it breaking.
2025-03-14 10:10:53 -05:00
Simon Tatham
80079c9c2f
[libc] Fix new warning in DyadicFloat::as_mantissa_type_rounded (#131148)
The affected line of code converts a float's exponent from `int` to
`size_t`, negating it in the process. Following clang commit
773e88f9d61399c, this provokes a warning, presumably because the
conversion goes wrong if `size_t` is wider than `int` and the input
value is `INT_MIN`: negating it within the `int` type is undefined
behavior, with the likely (though not guaranteed) effect of leaving it
still at `INT_MIN` and then sign-extending that on promotion to
`size_t`.

This fix adds a cast so that the promotion to `size_t` happens _before_
the negation, so that the negative input value will _always_ be
sign-extended, and then the negation will make it positive again.

(I don't believe this case will actually come up. `DyadicFloat` is a
helper system used in processing ordinary float formats, so nothing is
expected to generate an exponent with even a 16-bit absolute value, let
alone 31. But it's as easy to fix it to be robust as it is to just
suppress the warning!)
2025-03-14 11:57:25 +00:00
Connector Switch
bde2636fb5
[libc][NFC] Add the missing angle bracket in wchar.h (#131161) 2025-03-14 11:14:52 +08:00
Joseph Huber
8437b7f558
[libc] Make RPC server handling header only (#131205)
Summary:
This patch moves the RPC server handling to be a header only utility
stored in the `shared/` directory. This is intended to be shared within
LLVM for the loaders and `offload/` handling.

Generally, this makes it easier to share code without weird
cross-project binaries being plucked out of the build system. It also
allows us to soon move the loader interface out of the `libc` project so
that we don't need to bootstrap those and can build them in LLVM.
2025-03-13 19:23:21 -05:00
PiJoules
662bd4ca47
[stdio][baremetal] Fix templating for print functions (#131232)
This addresses build errors from https://github.com/llvm/llvm-project/pull/111559.
2025-03-13 15:30:45 -07:00
Simon Tatham
6fea340023
[libc] Fix non-templated uses of printf_core::Writer (#131149)
Commit 598e882ee88a1e3 turned `Writer` into a template, and updated most
of the call sites that use it. But not all. The alternative FP printf
system in `float_dec_converter_limited.h` wasn't updated, and neither
was `baremetal/printf.cpp` or `baremetal/vprintf.cpp`.

This patch updates `float_dec_converter_limited.h` in the same way that
the previous commit updated `float_dec_converter.h`: propagate the
templatedness through everything in the header, so that anything using a
`Writer` at all has a `write_mode` template parameter to pass on to it.

`printf.cpp` and `vprintf.cpp` are updated in the same way that the
previous commit updated `printf_core/vfprintf_internal.h`: the
`WriteBuffer` has parameter `WriteMode::FLUSH_TO_STREAM`, and `Writer`
picks it up implicitly from that.
2025-03-13 13:37:18 -05:00
Joseph Huber
e8e267ec42
[libc] Remove use of C++ STL features from rpc_server.cpp (#131169)
Summary:
This is done in preparation for making this header only so we can use it
without an object library. This will be a transient interface that
internal LLVM stuff with use. External people can use it too if they go
through the LLVM libc interface for shared stuff but there's no backward
compatibility guarantees.

Patch just cleans it up prior to the move.
2025-03-13 13:24:42 -05:00
Tejas Vipin
b910610eea
[libc][math] Fix Sollya command (#131091)
Fix a minor syntax error in the Sollya command in the comments of
asinhf.
2025-03-13 07:36:06 -04:00
Connector Switch
f291ec692e
[libc] Use proxy header in the locale implementation. (#130982)
Address review comments in
https://github.com/llvm/llvm-project/pull/130621#pullrequestreview-2671843932.

Some unused headers are also removed.
2025-03-13 11:35:41 +08:00
Joseph Huber
598e882ee8
[libc] Template the writing mode for the writer class (#111559)
Summary:
Currently we dispatch the writing mode off of a runtime enum passed in
by the constructor. This causes very unfortunate codegen for the GPU
targets where we get worst-case codegen because of the unused function
pointer for `sprintf`. Instead, this patch moves all of this to a
template so it can be masked out. This results in no dynamic stack and
uses 60 VGPRs instead of 117. It also compiles about 5x as fast.
2025-03-12 13:51:44 -05:00
Connector Switch
ab22f652a4
[libc] implement strings/str{n}casecmp_l (#130407)
ref:
https://pubs.opengroup.org/onlinepubs/9799919799/functions/strcasecmp_l.html

This patch introduces the `strcasecmp_l` function. At present, the
locale parameter is ignored, making it a stub implementation. This is
consistent with how other locale-related functions, such as `islower_l`,
are treated in our codebase as well as in
[musl](https://github.com/bminor/musl/blob/master/src/string/strcasecmp.c)
and
[bionic](https://cs.android.com/android/platform/superproject/main/+/main:bionic/libc/bionic/strings_l.cpp).

---------

Co-authored-by: Michael Jones <michaelrj@google.com>
2025-03-12 10:49:04 +08:00
lntue
d578148b7d
[libc][math] Skip checking for exceptional values when LIBC_MATH_SKIP_ACCURATE_PASS is set. (#130811) 2025-03-11 17:13:46 -04:00
PiJoules
313e2ef93e
[libc] Mark fixed point type generic macros as complete (#130805)
These were added in https://github.com/llvm/llvm-project/pull/129371.
2025-03-11 11:03:51 -07:00
lntue
5038e2f814
[libc] Provide more fine-grained control of FMA instruction for ARM targets. (#130700) 2025-03-11 10:17:34 -04:00
Connector Switch
426caf1182
[libc] add locale proxy header (#130621)
Address review comments in #130407.

This patch is already covered by existing locale test cases.
2025-03-11 08:46:29 +08:00
lntue
7e292772ad
[libc] Fix implicit conversion warnings. (#130635) 2025-03-10 12:51:38 -04:00
Vinay Deshmukh
257e483715
[libc] Add -Wno-sign-conversion & re-attempt -Wconversion (#129811)
Relates to
https://github.com/llvm/llvm-project/issues/119281#issuecomment-2699470459
2025-03-10 11:57:09 -04:00
Ishaan Verma
735afc8ceb
[libc] Added type-generic macros for fixed-point functions (#129371)
Adds macros `absfx`, `countlsfx` and `roundfx` .
ref:  #129111
2025-03-09 00:11:34 -05:00
Connector Switch
a5588b6d20
[libc] implement strings/ffs (#129892)
This patch adds the `strings/ffs` function.
ref: https://pubs.opengroup.org/onlinepubs/9799919799/functions/ffs.html
Closes: #122054.
2025-03-08 09:31:18 +08:00
Alexey Samsonov
d90423e310
[libc][bazel] Minor cleanup to remove unused dependencies. (#130348)
* strcpy doesn't need to depend on memcpy
* qsort_test_helper has been generalized and doesn't need to depend on
qsort.

This is a small cleanup to unblock the work outlined in #130327.
2025-03-07 13:31:18 -08:00
Connector Switch
dd9a2f0677
[libc] first_trailing_one(0) should be 0. (#130155)
Fix this minor bug. See more context at #129892.
2025-03-08 00:11:43 +08:00
Ajay Raj
9a65dc9513
Add sysexits.h header with BSD exit codes (total-18) (#126112)
This pull request adds a new header file, SysExits.h, to the LLVM
project. The header includes 18 BSD exit code.
2025-03-06 16:25:14 -08:00
Aiden Grossman
eac734aab6
[libc][docs] Fix libc docs build post #129138 (#130184)
The docs build action was failing with libc due to checks.rst not
existing in the expected path. This patch adjusts the path to the actual
path which seems to make everything happy. It seems like this did not
show up before as stdfix.rst was not included in a place that actually
caused it to get picked up by sphinx.
2025-03-06 14:07:44 -08:00
PiJoules
1a09adae9f
[libc] Add link to stdfix.h on headers page (#129138)
Co-authored-by: Petr Hosek <phosek@google.com>
2025-03-06 10:31:26 -08:00
lntue
f2bebdc688
[libc][math] Add skip accurate pass option for exp*, log*, and powf functions. (#129831) 2025-03-05 19:18:25 -05:00
Joseph Huber
77363f7518
[libc] Allow building the GPU targets that don't have CRT (#129945)
Summary:
If there's no subdirectory we can't make an alias. This allows it to at
least continue.
2025-03-05 16:39:35 -06:00
Augie Fackler
da61b0ddc5 Revert "[libc] Enable -Wconversion for tests. (#127523)"
This reverts commit 1e6e845d49a336e9da7ca6c576ec45c0b419b5f6 because it
changed the 1st parameter of adjust() to be unsigned, but libc itself
calls adjust() with a negative argument in align_backward() in
op_generic.h.
2025-03-05 16:42:40 -05:00
Michael Jones
ed5cd8d464
[libc] Fix casts for arm32 after Wconversion (#129771)
Followup to #127523

There were some test failures on arm32 after enabling Wconversion. There
were some tests that were failing due to missing casts. Also I changed
BigInt's `safe_get_at` back to being signed since it needed the ability
to be negative.
2025-03-04 14:32:36 -08:00
Jorge Gorbe Moya
f9a6ea4489
[libc][bazel] Add BUILD targets for complex functions and tests. (#129618)
This involved a little bit of yak shaving because one of the new tests
depends on MPC, and we didn't have targets for it yet, so I ended up
needing to add a similar setup to what we have for MPFR.
2025-03-04 11:05:01 -08:00
Vinay Deshmukh
1e6e845d49
[libc] Enable -Wconversion for tests. (#127523)
Relates to: #119281
2025-03-04 10:24:35 -05:00
Dmitri Gribenko
9084d2a0a1 [libc] Add a missing include
This is a fixup for
da6d5fa79a.
2025-03-04 08:54:46 +01:00
OverMighty
d9ac5d0be6
[libc][docs] Add links to Peter Smith's FOSDEM 2025 talk (#129555) 2025-03-03 19:15:21 +01:00
Lukas Bergdoll
da6d5fa79a
Add missing LIBC_INLINE to qsort_pivot.h (#126249)
Fixes #111495
2025-03-03 10:33:02 -05:00
Jorge Gorbe Moya
620953328d
[libc] Fix warning in libc/utils/MPCWrapper/MPCUtils.h (#129349)
`cpp::is_complex_type_same<T1, T2>` is a function, so we need
parentheses in order to call it. Otherwise the expression is treated
like a function pointer which is always true in this boolean context.
2025-02-28 22:40:43 -05:00
Tristan Ross
9b6d0d7660
[libc] Add UEFI headers (#127126)
Originated from #120687

This PR simply adds the necessary headers for UEFI which defines all the
necessary types. This PR unlocks the ability to work on other PR's for
UEFI support.
2025-02-28 11:43:33 -05:00
PiJoules
7842954b9d
[stdfix] Update function names (#129129)
The remaining math functions are `mulifx` (int * fx = int), `divifx`
(int / fx = int), `fxdivi` (int / int = fx), and `idivfx` (fx / fx =
int).
2025-02-27 13:51:37 -08:00
Michael Jones
64ae0a102f
[libc] implement l64a (#129099)
Adds l64a, which generates the base 64 string expected by a64l.
2025-02-27 12:48:39 -08:00
PiJoules
9a32af25b4
[stdfix] Check fxbits as complete (#129107)
These were added in https://github.com/llvm/llvm-project/pull/114912 by
@smallp-o-p.
2025-02-27 12:04:06 -08:00
lntue
4fd762caa6
[libc] Fix sqrtf128 smoke test for riscv32. (#129094) 2025-02-27 13:55:22 -05:00
Krishna Pandey
f6bfa33cdb
[libc][stdfix] Implement fixed point bitsfx functions in llvm libc (#128413)
Fixes #113359

---------

Signed-off-by: krishna2803 <kpandey81930@gmail.com>
2025-02-27 13:05:27 -05:00
Alexey Samsonov
829e2a5526
[libc][hdrgen] Allow to treat hdrgen Python code as a Python module. (#128955)
Move the hdrgen code under a subdirectory to treat it as a Python
module.

This mimics the structure used by llvm/utils/lit and
llvm/utils/mlgo-utils and simplifies integration of hdrgen to the build
system which rely on Python modules. In addition to that, it clarifies
which imports are coming from the hdrgen-specific helpers (e.g. "from
type import ..." becomes "from hdrgen.type import ...".

Leave the entrypoints (top-level main.py and yaml_to_classes.py) as-is:
they can keep being referred by the CMake build system w/o any changes.
2025-02-26 15:41:30 -08:00
Michael Jones
8beec9fc48
[libc] implement a64l (#128758)
Implement the posix function a64l.
Standard:
https://pubs.opengroup.org/onlinepubs/9799919799/functions/a64l.html
2025-02-25 13:57:13 -08:00
Michael Jones
f4a80180f1
[libc] Move fileno and fdopen to fullbuild only (#128762)
Both fileno and fdopen require interfacing with the opaque FILE struct,
so they shouldn't be enabled in overlay mode. This patch moves both into
fullbuild only on all platforms.

Fixes #128643
2025-02-25 13:56:20 -08:00
Alexey Samsonov
ab0e6fcaad
[libc][cmake] Clean up dead code in add_gen_header (#128753)
DATA_FILES CMake argument never existed in the new YAML-based hdrgen
version of add_gen_header function, and thus its uses added in
b1fd6f0996a9d6e6ebfa0cc3df0fe499c5ccdf65 were always dead code.

Remove them to clean up the function implementation.

Co-authored-by: Alexey Samsonov <samsonov@google.com>
2025-02-25 10:58:44 -08:00
Joseph Huber
089f988f46 [libc] Fix defaulting the full build
Summary:
This was missing the architecture macros as they were defined just
below.
2025-02-25 07:27:23 -06:00
Joseph Huber
eabe2eb933
[libc] Remove special full build handling for GPU (#128572)
Summary:
Currently we default to non-fullbuild for all targets, but realistically
we should do this depending on the target OS. Some OS's like the GPU or
upcoming UEFI have no existing hosted system, so they cannot be built
with an overlay build. These are already errors so there's no reason to
complicate things and require passing it in through the runtimes build.
2025-02-24 15:49:17 -06:00