Commit Graph

414 Commits

Author SHA1 Message Date
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
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
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
wldfngrs
3e284554a8 [libc][math][c23] Add acosf16() function (#127731)
- Implementation of acosf16 (inverse cosine) function for 16-bit inputs.
- Exhaustive tests across the 16-bit input range.
2025-02-23 19:46:46 +01:00
Petr Hosek
00637b7dfb [libc] Add strftime_l (#127767)
This is a (no-op) locale version of strftime.

Fixes: https://github.com/llvm/llvm-project/issues/106630
2025-02-21 10:50:32 -08:00
Alexey Samsonov
ad0c7da953 [libc] Add missing stdc_first_trailing_zero_ to stdbit.yaml (#128101)
These declarations were missing in the generated header. Make sure to
add them, otherwise <stdbit.h> inclusion fails, since the subsequently
included "stdbit-macros.h" expects these declarations to be present.

Co-authored-by: Alexey Samsonov <samsonov@google.com>
2025-02-21 08:24:59 -08:00
Zaky Hermawan
ef49760fa9 [libc][POSIX][unistd] implement getsid (#127341)
Fixes https://github.com/llvm/llvm-project/issues/126603

---------

Signed-off-by: ZakyHermawan <zaky.hermawan9615@gmail.com>
2025-02-19 14:26:18 -08:00
c8ef
826af1757c [libc] add LLVM_LIBC_CAST macro. (#127319)
related: #127238

This patch adds a macro called `LLVM_LIBC_CAST`, similar to
`__BIONIC_CAST`, for type conversion in `endian.h`.
2025-02-19 23:28:11 +08:00
Petr Hosek
a2b4d4e756 Revert "[libc] Add strftime_l" (#127766)
Reverts llvm/llvm-project#127708
2025-02-19 00:39:33 -08:00
Petr Hosek
9072ba71ca [libc] Add strftime_l (#127708)
This is a (no-op) locale version of strftime.
2025-02-18 23:54:45 -08:00
Roland McGrath
8fe290efa6 [libc] Canonicalize generated fenv.h (#127363)
This removes the custom template for fenv.h by declaring all the
standard-specified macros using macro_header.
2025-02-17 17:06:59 -08:00
Roland McGrath
2157aecfe4 [libc] Produce standard-compliant header guard macros in hdrgen (#127356)
Macros starting with alphabetic characters such as "LLVM" are in
the application name space and cannot be defined or used by a
conforming implementation's headers.  This fixes the headers that
are entirely generated, and the __llvm-libc-common.h header to
use a conforming macro name for the header guard.  That is, it
starts with "_LLVM_LIBC_" instead of "LLVM_LIBC_", as identifiers
starting with an underscore followed by a capital letter are in
the name space reserved for the implementation.

The remaining headers either will be fixed implicitly by removal
of their custom template files, or will need to be fixed by hand.
2025-02-15 17:36:44 -08:00
Roland McGrath
ed48398431 [libc] Fill out generated malloc.h and related stdlib.h extensions (#127293)
This updates the generated stdlib.h and malloc.h headers to
include the subsets of extenion functions declared by glibc that
are also supported by Scudo and that use only simple types.
Scudo's extensions not declared by glibc are omitted.  glibc's
extensions not implemented by Scudo are omitted.  The mallinfo
and mallinfo2 functions are omitted (at least for now) since they
need struct definitions for their return types.
2025-02-15 16:32:30 -08:00
Roland McGrath
625cb5a185 [libc] Share hdrgen declarations between stdlib.h and malloc.h (#127278)
This uses the new merge_yaml_files feature in hdrgen to share the
source of truth for the malloc suite of functions declared in
both stdlib.h and in malloc.h (without either header including
the other).  It also modernizes the malloc.yaml definition a bit,
including dropping the custom template malloc.h.def file in favor
of using the explicit macros list to generate the includes.
2025-02-14 16:46:56 -08:00
Michael Jones
398f865499 [libc] Implement strftime (#122556)
Implements the posix-specified strftime conversions for the default
locale, along with comprehensive unit tests. This reuses a lot of design
from printf, as well as the printf writer.

Roughly based on #111305, but with major rewrites.
2025-02-14 15:56:55 -08:00
Roland McGrath
303f241544 [libc] Make template_header optional for hdrgen (#127259)
This allows a YAML file to omit `template_header` and have no
`.h.def` file.  A default template is generated based purely on
the information in the YAML file.  This should handle most of the
cases.  For now, it's exercised (aside from the hdrgen tests)
only for one of the simplest cases: <ctype.h>.

This includes making the parser notice the "standards" YAML field
at the top (header) level, not just in "functions" lists.  The
standards listed for the header overall and for the individual
functions both feed into how a fully-generated header describes
itself in comments.  To go with this, files using the default
generated template must stick to a new uniform set of spellings
for the "standards" lists.  As more custom template files are
retired, the corresponding YAML files will need all their
standards lists normalized.  For now, ctype.yaml is updated
with correct attribution for the POSIX `_l` extensions.
2025-02-14 14:01:18 -08:00
Roland McGrath
6d3bfddb9d [libc] Make hdrgen support macro_header YAML field. (#123265)
A macro can specify macro_header instead of macro_value to
indicate that an llvm-libc-macros/ header file is supposed to
define this macro.  This is used for dlfcn.h, which previously
bogusly redefined the RTLD_* macros to empty.
2025-02-13 16:07:06 -08:00
Nick Desaulniers
3e02069afe [libc][pthread] fix -Wmissing-field-initializers (#126314)
Fixes:


llvm-project/libc/test/integration/src/pthread/pthread_rwlock_test.cpp:59:29:
    warning: missing field '__preference' initializer
    [-Wmissing-field-initializers]
       59 |   pthread_rwlock_t rwlock = PTHREAD_RWLOCK_INITIALIZER;
          |                             ^

Also, add a test that demonstrates the same issue for
PTHREAD_MUTEX_INITIALIZER, and fix that, too.

PTHREAD_ONCE_INIT does not have this issue and does have test coverage.
2025-02-12 14:28:29 -08:00
Petr Hosek
b0d7820805 [libc] Move __LLVM_LIBC__ define to __llvm-libc-common.h (#126877)
Relying on features.h is problematic since codebases are free to have
such a header on their search path, which breaks compilation. libc
should instead provide a more standard way of getting __LLVM_LIBC__.
Since __llvm-libc-common.h is included from all libc headers, defining
__LLVM_LIBC__ there ensures that this define is available whenever any
of the standard header is included.
2025-02-12 11:37:07 -08:00
Krishna Pandey
1f51038036 [libc][stdfix] Implement countlsfx functions in libc. (#126597)
fixes #113357

---------

Signed-off-by: krishna2803 <kpandey81930@gmail.com>
2025-02-12 14:12:44 -05:00
c8ef
6de4de8931 [libc] implement endian related macros (#126368)
Follow up of #125168.

This patch adds endian-related macros to `endian.h`. We utilize compiler
built-ins for byte swap functions, which are already included in our
minimal supported compiler version.
2025-02-12 10:17:09 +08:00
Michael Jones
a760e7faac [libc] create TimeReader to look at a struct tm (#126138)
In the process of adding strftime (#122556) I wrote this utility class
to simplify reading from a struct tm. It provides helper functions that
return basically everything needed by strftime. It's not tested
directly, but it is thoroughly exercised by the strftime tests.
2025-02-11 14:37:15 -08:00
wldfngrs
7ee56b9afc [libc][math][c23] Add asinf16() function (#124212)
Co-authored-by: OverMighty <its.overmighty@gmail.com>
2025-02-10 12:38:55 +01:00
Joseph Huber
7623d91784 Revert "[libc][stdfix] Fix buildbot failure because of a typo. (#126291)"
This reverts commit bada9220b8.

Revert "[libc][stdfix] Implement fixed point `countlsfx` functions in llvm-libc (#125356)"

This reverts commit f2a1103b32.
2025-02-07 14:34:40 -06:00
Krishna Pandey
f2a1103b32 [libc][stdfix] Implement fixed point countlsfx functions in llvm-libc (#125356)
fixes #113357
2025-02-07 13:53:17 -05:00
Nick Desaulniers
e566313a1f [libc][signal] clean up usage of sighandler_t (#125745)
`man 3 signal`'s declaration has a face _only a mother could love_.

sighandler_t and __sighandler_t are not defined in the C standard, or POSIX.

They are helpful typedefs provided by glibc and the Linux kernel UAPI headers
respectively since working with function pointers' syntax can be painful. But
we should not rely on them; in C++ we have `auto*` and `using` statements.

Remove the proxy header, and only include a typedef for sighandler_t when
targeting Linux, for compatibility with glibc.

Fixes: #125598
2025-02-07 10:43:56 -08:00
c8ef
6807164500 [libc] Add the <endian.h> header. (#125168)
Closes [#124631](https://github.com/llvm/llvm-project/issues/124631).
ref:
https://pubs.opengroup.org/onlinepubs/9799919799/basedefs/endian.h.html

This patch adds the implementation of `endian.h`, which includes the
header itself and three related macros. These macros in the header rely
on the compiler preprocessor, similar to how
https://github.com/llvm/llvm-project/blob/main/libc/src/__support/endian_internal.h
does. Hopefully this will meet the requirements for compiling llvm with
llvm-libc.
2025-02-07 09:20:18 +08: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
8e35b3d29b [libc][POSIX][poll.h] implement poll (#125118)
Simple syscall.

Fixes: #124647
2025-02-05 13:24:39 -08: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
Alex Prabhat Bara
9b52dbe0e0 [libc] added _POSIX_ARG_MAX in limits.h (#124954)
Fixes: #124947
2025-01-30 12:39:49 -08:00
Alex Prabhat Bara
a255da0c53 [libc] clean up duplicated includes in generated headers (#124524)
Fixes: #124149
2025-01-28 12:22:51 -08: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
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
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
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
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
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
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
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
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
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