434 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
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
Roland McGrath
4010e0c45b
[libc] Use __attribute__((__noreturn__)) for _Noreturn in C < 11 (#121252)
When in modes like C99, the _Noreturn keyword is not available in
C.  But GNU-compatible compilers have a `noreturn` attribute with
the same effect on function declarations.
2025-01-02 16:57:31 -08:00
Roland McGrath
62cd050b63
[libc] Move hdrgen yaml files into include/ (#121443)
The .yaml files should live next to the corresponding .h.def
files in libc/include/, rather than next to the implementation of
the tool in libc/utils/hdrgen/.  As with the .h.def files, there
is no need for a yaml/ subdirectory under include/.  This simpler
layout is more natural for maintenance and also simplifies build
integration outside the LLVM CMake build.
2025-01-01 17:03:35 -08:00
Roland McGrath
9abcca5e25
[libc] Move hdrgen into utils/ subdirectory (#121256) 2024-12-30 15:36:53 -08:00
Joseph Huber
3bbd53ce97
[libc] Remove old RPC host call extension for GPU (#120800)
Summary:
This was originally a hacked together function that served to just
implement some features for OpenMP. That has been moved into OpenMP
itself now that we have exported RPC properly. This can now be deleted.
2024-12-20 19:34:05 -06:00
Roland McGrath
0b91d77bf4
[libc] Use __attribute__((__nothrow__)) for __NOEXCEPT in C (#114653)
Consistent with glibc headers, where `noexcept` is used in C++
(or `throw()` in older C++ which llvm-libc doesn't support) in
the public function declarations, `__attribute__((__nothrow__))` is
used in C for compilers that support it.
2024-12-17 12:18:37 -08:00
Nick Desaulniers
8a25398615
[libc] move pthread macros to dedicated header (#119286)
so that docgen can find our definitions.

Also eliminate the enums. POSIX is careful to call these "symbolic constants"
rather than specifically whether they are preprocessor macro defines or not.
Enums are useful to expressing mutual exclusion when the enum values are in
distinct enums which can improve type safety. Our enum values weren't using
that pattern though; they were all in one big anonymous enum.

Link:
https://pubs.opengroup.org/onlinepubs/9799919799/basedefs/pthread.h.html
Fixes: #88997
2024-12-10 09:00:06 -08:00
Shourya Goel
52da2db489
[libc][complex] check that cfloat128 is not defined as _Complex long double (#119324)
Fix buildbot errors in #118671
2024-12-10 11:18:29 +05:30
Schrodinger ZHU Yifan
e6cf5d2863
Reapply "[libc][windows] start time API implementation (#117775)" (#118886) 2024-12-05 18:21:03 -05:00
Joseph Huber
9fd052a122 Revert "[libc][windows] start time API implementation (#117775)"
This reverts commit 0adff0af20c7d9bae8bd8bdf402506c10369ead1.

Breaks the GPU build
2024-12-05 14:43:06 -06:00
Schrodinger ZHU Yifan
0adff0af20
[libc][windows] start time API implementation (#117775)
Add a `clock_gettime` emulation layer and use it to implement the `time`
entrypoint.

For windows, the monotonic clock is emulated using `QPC`.
The realtime clock is emulated using `GetSystemTimePreciseAsFileTime`.
2024-12-05 14:08:27 -05:00
Schrodinger ZHU Yifan
245f26a3d3
[libc] revert all process_mrelease changes (#118650)
Revert as its test is unstable.
https://github.com/llvm/llvm-project/issues/118057
2024-12-05 11:58:37 -05:00
Nick Desaulniers
06c831d7fb
[libc] rename newhdrgen to just hdrgen (#118545)
Link: #117208
Fixes: #117254
2024-12-04 08:48:12 -08:00
Nick Desaulniers
e0ae7793fc
[libc] delete hdrgen (#117220)
Thanks to the effort of @RoseZhang03 and @aaryanshukla under the
guidance of
@michaelrj-google and @amykhuang, we now have newhdrgen and no longer
have a
dependency on TableGen and thus LLVM in order to start bootstrapping a
full
build.

This PR removes:
- LIBC_HDRGEN_EXE; the in tree newhdrgen is the only hdrgen that can be
used.
- LIBC_USE_NEW_HEADER_GEN; newhdrgen is the default and only option.
- LIBC_HDRGEN_ONLY; there is no need to have a distinct build step for
old
  hdrgen.
- libc-api-test and libc-api-test-tidy build targets.
- Deletes all .td files.

It does not rename newhdrgen to just hdrgen. Will follow up with a
distinct PR
for that.

Link: #117209
Link: #117254
Fixes: #117208
2024-12-03 12:34:26 -08:00
Petr Hosek
b8daa45a56
[libc] Implement timespec_get (#116102)
`timespec_get` is C standard counterpart to POSIX `clock_gettime`. On
Linux we simply use `clock_gettime`. On baremetal we introduce a new
external API `__llvm_libc_timespec_get_utc` that should be implemented
by the vendor.
2024-12-02 14:29:49 -08:00
Omar Hossam
d2b482b0ef
[libc] (reland #117503) Implement process_mrelease (#117851)
This PR implements process_mrelease.
A previous PR was merged #117503, but failed on merge due to an issue in
the tests. Namely the failing tests were comparing against return type
as opposed to errno. This is fixed in this PR.
2024-11-27 20:15:17 -05:00
lntue
3372303188
Revert "[libc] Implement process_mrelease." (#117807)
Reverts llvm/llvm-project#117503
2024-11-26 18:07:30 -05:00
Omar Hossam
36a46d85e7
[libc] Implement process_mrelease. (#117503)
This PR addresses #110124.
2024-11-26 17:40:06 -05:00
Joseph Huber
d7c20a6f0c [libc][NFC] Move RPC opcodes to the 'shared/' directory as well 2024-11-25 12:04:10 -06:00
Joseph Huber
27d25d1c12
[libc] Increase RPC opcode to 32-bit and use a class byte (#116905)
Summary:
Currently, the RPC interface uses a basic opcode to communicate with the
server. This currently is 16 bits. There's no reason for this to be 16
bits, because on the GPU a 32-bit write is the same as a 16-bit write
performance wise.

Additionally, I am now making all the `libc` based opcodes qualified
with the 'c' type, mimiciing how Linux handles `ioctls` all coming from
the same driver. This will make it easier to extend the interface when
it's exported directly.
2024-11-19 21:56:10 -06:00
William Tran-Viet
13ced90b00
[libc] {u}lkbits broken on riscv32 (#115799)
- Re-enabled ulkbits and lkbits for Risc-V
- Bumped `int_lk_t` to a `signed long long` and a `uint_ulk_t` to an
`unsigned long long` to guarantee they both fit in 8 bytes, which `long
_Accum` and `unsigned long _Accum` are defaulted to on 32bit
architectures.

This is probably inconvenient on systems that have a word size larger
than 64 bits?

#115778
2024-11-12 10:38:08 -08:00
William Tran-Viet
c11b6e80b6
[libc][stdfix] Implement fixed point fxbits functions in llvm-libc (#114912) 2024-11-11 12:54:16 -05:00
Duncan
396ed9c2a1
[libc][search] implement posix lfind function (#114692)
# Changes
- Implement the POSIX
[`lfind`](https://man7.org/linux/man-pages/man3/lsearch.3.html)
function.

- Put a checkmark in the [posix support table
docs](https://libc.llvm.org/libc_search.html) next to `lfind`.
2024-11-11 09:53:20 -08:00
Roland McGrath
1c602c5fe5
[libc] Define away __restrict in C++ without GNU extensions (#114655)
The C99 restrict keyword is spelled __restrict in the libc
headers so it can be parsed by C++ compilers with GNU extensions
that recognize it.  When GNU extensions are not available in C++
2024-11-04 11:23:27 -08:00
lntue
88a0a318e8
[libc] Use relative inclusion for public headers. (#114324)
We are finalizing the header inclusion policy, and for our public
headers in the `libc/include` folder, they must use relative path in
`"..."` when including each other.

This PR does the cleanup making sure that all the public header
inclusions in `libc/include` folder use relative paths.

---------

Co-authored-by: Nick Desaulniers <nickdesaulniers@users.noreply.github.com>
2024-11-01 14:33:30 -04:00
Michael Jones
e241964b93
[libc] Fix macro definition hermeticity (#114467)
Previously shm_test was including <asm-generic/fcntl.h> for the macro
FD_CLOEXEC. This patch adds that macro to the list we have defined, and
redirects the test to use the correct proxy header.
2024-10-31 14:42:50 -07:00
Nick Desaulniers
b1320d3633
[libc][i386] setjmp/longjmp (#112437)
Link: #93709
2024-10-30 12:59:59 -07:00
Nick Desaulniers
dc1ff883ca
[libc][i386] define MINSIGSTKSZ & SIGSTKSZ (#114249)
Link: #93709
2024-10-30 11:56:41 -07:00
Roland McGrath
0c8e12fc64
[libc] Fix fexcept_t type to match canonical ABI and API (#113666)
In glibc and musl, fexcept_t is unsigned short int on x86 and
unsigned int on other machines that llvm-libc supports.  Match
that ABI (only different from before on x86) and API (different
everywhere as it was previously signed).
2024-10-30 10:09:34 -07:00
Shourya Goel
d508701249
[libc][complex] add additonal header guards for CFP16 and CFP128 (#112879)
Fixes build errors due to #112594
2024-10-18 16:29:07 +05:30
Shourya Goel
7be4ab0a86
[libc][complex] Added support for CFP16 and CFP128 (#112594)
Fixes: #112217
2024-10-18 11:55:57 +05:30