Commit Graph

549 Commits

Author SHA1 Message Date
Alexey Samsonov
57a8228f40 [libc] Add macros definitions for <nl_types.h> (#164474)
This PR adds required macro definitions to `<nl_types.h>` header, so
that they're available to the code including it.

The header itself was added in 12abe8aed6,
together with stub definitions of the three required functions.
2025-10-22 09:41:03 -07:00
Alexey Samsonov
12abe8aed6 [libc] Stub out message catalog functions from <nl_types.h> (#164360)
Create a POSIX `<nl_types.h>` header with `catopen`, `catclose`, and
`catgets` function declarations.
Provide the stub/placeholder implementations which always return error.
This is consistent with the way
locales are currently (un-)implemented in llvm-libc.

Notably, providing `<nl_types.h>` fixes the last remaining issue with
building libc++ against llvm-libc
(on certain configuration of x86_64 Linux) after disabling threads and
wide-characters in libc++.
2025-10-21 10:34:35 -07:00
Connector Switch
5b3416caf9 [libc] implement inet_aton (#162651)
This patch adds the implementation for `inet_aton` function. Since this
function is not explicitly included in POSIX, I have marked it with
`llvm_libc_ext`. It is widely available and commonly used, and can also
be used to implement `inet_addr`, which is included in POSIX.
2025-10-21 23:47:38 +08:00
Simon Tatham
48a99ad1fa [libc] Add llvm-libc-types header deps for <complex.h>. (#164422)
complex.yaml declares types cfloat16, cfloat128 and float128 in its
'types' section, causing the output complex.h to #include three headers
with names of the form "llvm-libc-types/cfloat16.h". But
include/CMakeLists.txt doesn't mention those types as dependencies in
the `add_header_macro` call for complex.h. As a result, cfloat16.h and
cfloat128.h are not installed by the 'install' target, but complex.h
still tries to to include them.

The third type header, float128.h, doesn't have this problem because the
`add_header_macro` math.h does mention it as a dependency. So I've added
all three headers as dependencies in complex.h, following the same
pattern, and now the install target installs the missing two headers.
2025-10-21 15:47:54 +01:00
Connector Switch
c4ceb8d7e5 [libc] add IPV6 related macros (#162219) 2025-10-17 23:41:52 +08:00
Alexey Samsonov
36f7f3442c [libc] Update generated libc header to include missing functions/files. (#163658)
* Add a missing dependency to install struct_itimerval.h
* Add fseeko/ftello declarations to stdio.h
2025-10-15 18:06:13 -07:00
Anton Shepelev
1244fd24d9 [libc][math][c23] Add rsqrtf() function (#159615)
Closes #159614

**Changes:**
- Initial implementation of rsqrt for single precision float

**Some small unrelated style changes to this PR (that I missed in my
rsqrtf16 PR):**
- Added extra - to the top comments to make it look nicer in
libc/shared/math/rsqrtf16.h
- Put rsqrtf16 inside of libc/src/__support/math/CMakeLists.txt in
sorted order
- Rearanged libc_math_function rsqrtf16 in Bazel to match alphabetical
order
2025-10-08 23:37:01 -04:00
Shreeyash Pandey
c57796dcb2 [libc][stdfix] Implement fxdivi functions (rdivi) (#154914)
This PR includes only one of the fxdivi functions (rdivi). It uses a
polynomial function for initial approximation followed by 4
newton-raphson iterations to calculate the reciprocal and finally
multiplies the numerator with it to get the result.


---------

Signed-off-by: Shreeyash Pandey <shreeyash335@gmail.com>
2025-10-08 15:17:31 -04:00
Connector Switch
be301a6a3d [libc] add in_addr{, _t} type (#162452)
These types will be used in `arpa/inet.h` and `netinet/in.h`.
2025-10-08 22:08:22 +08:00
Connector Switch
6b1604ac30 [libc] add IPPROTO related macros (#161855) 2025-10-06 11:46:45 +08:00
Marcell Leleszi
44d471e706 [libc] Implement faccessat (#161065)
#160404

- Implement POSIX function "faccessat"
- Remove redundant param in facessat syscall in access implementation,
faccessat syscall does not take a flags arg
2025-10-02 12:33:21 -07:00
Zaky Hermawan
5ad347d1a1 [libc][POSIX][unistd] Implement gethostname (#128142)
The implementation is based on the specifications from:
https://man7.org/linux/man-pages/man2/gethostname.2.html

Closes https://github.com/llvm/llvm-project/issues/126602

---------

Signed-off-by: ZakyHermawan <zaky.hermawan9615@gmail.com>
2025-09-23 09:54:35 -04:00
Joseph Huber
0b9d816b3e [libc] Remove separate RPC test handling (#160206)
Summary:
This was originally kept separate so it didn't pollute the name space,
but now I'm thinking it's just easier to bundle it in with the default
interface. This means that we'll have a bit of extra code for people
using the server.h file to handle libc opcodes, but it's minimal (3
functions) and it simplifies this.

I'm doing this because I'm hoping to move the GPU tester binary to
liboffload which handles `libc` opcodes internally except these. This is
the easier option compared to adding a hook to register custom handlers
there.
2025-09-22 19:44:41 -05:00
Anton Shepelev
80f9c72a1e [libc][math][c23] Add rsqrtf16() function (#137545)
Addresses #132818 
Part of #95250
2025-09-17 10:19:20 -04:00
lntue
719b92dfb1 [libc] Fix CMPLXF128 macro definition for aarch64. (#157157) 2025-09-05 16:14:07 -04:00
Connector Switch
caf5fb1c40 [libc] Implement CMPLX for clang < 12 (#157096)
Fixes
https://github.com/llvm/llvm-project/pull/156344#issuecomment-3256837826
2025-09-05 10:46:38 -04:00
Connector Switch
8e4457baa2 [NFC] Fix a comment for cfloat128.h (#157093) 2025-09-05 21:16:03 +08:00
A. Jiang
33a583d377 [libc] Workaround for GCC on typedef for _Complex __float128 (#157010)
Currently, GCC can't parse `typedef _Complex __float128 cfloat128;`,
although `__typeof__` can be used as a workaround. Reported
https://gcc.gnu.org/PR121799 which was later considered as duplicate of
https://gcc.gnu.org/PR32187.

Some recent changes exposed it to GCC and then caused CI failure for
libc++. This patch adds a workaround for GCC.
2025-09-05 13:50:35 +08:00
Connector Switch
78579b9157 [libc] Implement CMPLX related macros (#156344) 2025-09-05 10:08:04 +08:00
Alexey Samsonov
369b2a783d [libc] Remove unused _Thread_local define from headers. (#156967)
It was added in dd33f9cdef to describe
thread-local errno, but is no longer used in the codebase (with the
exception of a single integration test, but the llvm-libc-provided
`#define _Thread_local thread_local` is not needed there anyway, since
`_Thread_local` is a keyword from C11 onwards.
2025-09-04 14:02:43 -07:00
Zishan Mirza
17bddd1224 [libc] implement template functions for localtime (#110363)
This is an implementation for template functions of localtime.

Update for this pull request: Implementation as been removed from this
pull request and will be added to a new one. This is because this pull
request is getting big. This pull request will only contain template
functions in order to implement localtime.

Update: The implementation is available in
https://github.com/zimirza/llvm-project/tree/localtime_implementation.

---------

Co-authored-by: Зишан Мирза <zmirza@tutanota.de>
Co-authored-by: Zishan Mirza <zmirza@posteo.de>
2025-09-03 14:55:02 -07:00
Aiden Grossman
e95355c3f7 [libc] Add CMake Target for Dl_info.h Header (#156195)
Otherwise when installing the dlfcn.h header, there is a missing
reference to Dl_info.h, which causes compilation failures in some cases,
notably libunwind.
2025-09-02 16:22:11 -07:00
Alexey Samsonov
2429a8f71f [libc] Add missing and correct some existing C23 functions to math.h (#156512)
This change fixes and closes some gaps in the YAML template for
producing the math.h header.

It adds some missing declarations (dadd/dsub function variants), correct
arguments and/or return type for other functions from this family (dsqrt
and ddiv), and add a missing fminimum_numl variant.
2025-09-02 13:42:48 -07:00
Mohamed Emad
c1d1e0e32f [libc][math][c23] Implement C23 math function atanpif16 (#150400)
This PR implements `atanpif16(x)` which computes
$\frac{\arctan(x)}{\pi}$ for half-precision floating-point numbers using
polynomial approximation with domain reduction.

## Mathematical Implementation

The implementation uses a 15th-degree Taylor polynomial expansion of
$\frac{\arctan(x)}{\pi}$ that's computed using
[`python-sympy`](https://www.sympy.org/en/index.html) and it's accurate
in $|x| \in [0, 0.5)$:

$$
g(x) = \frac{\arctan(x)}{\pi} \approx 
\begin{aligned}[t]
    & 0.318309886183791x \\
    & - 0.106103295394597x^3 \\
    & + 0.0636619772367581x^5 \\
    & - 0.0454728408833987x^7 \\
    & + 0.0353677651315323x^9 \\
    & - 0.0289372623803446x^{11} \\
    & + 0.0244853758602916x^{13} \\
    & - 0.0212206590789194x^{15} + O(x^{17})
\end{aligned}
$$


--- 

To ensure accuracy across all real inputs, the domain is divided into
three cases with appropriate transformations:

**Case 1: $|x| \leq 0.5$**  
Direct polynomial evaluation: 

$$\text{atanpi}(x) = \text{sign}(x) \cdot g(|x|)$$

**Case 2: $0.5 < |x| \leq 1$**  
Double-angle reduction using:

$$\arctan(x) = 2\arctan\left(\frac{x}{1 + \sqrt{1 + x^2}}\right)$$

$$\text{atanpi}(x) = \text{sign}(x) \cdot 2g\left(\frac{|x|}{1 + \sqrt{1
+ x^2}}\right)$$

**Case 3: $|x| > 1$**  
Reciprocal transformation using 

$$\arctan(x) = \frac{\pi}{2} - \arctan\left(\frac{1}{x}\right) \
\text{for} \ x \gt 0$$

$$\text{atanpi}(x) = \text{sign}(x) \cdot \left(\frac{1}{2} -
g\left(\frac{1}{|x|}\right)\right)$$


Closes #132212
2025-09-02 22:50:50 +03:00
Leandro Lacerda
9dc66a631e [libc] Add half-precision math functions to the math header (#155060)
This patch adds the `exp10f16`, `exp2f16`, `expf16`, and `expm1f16` math
functions to the `math.h` header.
2025-08-22 22:06:12 -05:00
Leandro Lacerda
15a192cde5 [libc] Enable double math functions on the GPU (#154857)
This patch adds the `acos` math function to the NVPTX build. It also
adds the `sincos` math function to the `math.h` header.
2025-08-22 06:52:13 -05:00
William Huynh
0c622d72fc [libc] Add _Returns_twice to C++ code (#153602)
Fixes issue with `<csetjmp>` which requires `_Returns_twice` but in C++
mode
2025-08-19 09:28:23 +01:00
Mohamed Emad
40833eea21 Reland "[libc][math][c23] Implement C23 math function asinpif16" (#152690)
#146226 with fixing asinpi MPFR number function and make it work when
mpfr < `4.2.0`
2025-08-18 00:04:47 +03:00
Aiden Grossman
71925a90c8 [libc] Setup hdrgen for ioctl (#153976)
This patch adds some hdrgen yaml for ioctl(). Otherwise the function
never actually ends up being available in a full build. This is the last
thing that is needed to enable turning on LIBCXX_ENABLE_RANDOM_DEVICE.
2025-08-17 08:52:29 -07:00
Aiden Grossman
29d49c8a37 [libc] Correct standard for getcpu (#153982) 2025-08-16 16:05:45 -07:00
Caslyn Tonelli
b8195e3a8e [libc] Fix typo and amend restrict qualifier (#152410)
This removes an extraneous ',' in the generated dlfcn header.

This also adds `__restrict` to `dladdr`'s declaration per POSIX. Another
fix is made: the C standard `restrict` keyword is removed from
dlinfo.cpp/dlinfo.h (but note that dlfcn.yaml still annotates
`__restrict` for dlinfo's decl).
2025-08-07 16:45:14 -07:00
Caslyn Tonelli
5a076e3b4d [libc] Add dladdr to dlfcn.h (#149872)
A initial commit for #97929, this adds a stub implementation for
`dladdr` and includes the definition for the `DL_info` type used as one
of its arguments.

While the `dladdr` implementation relies on dynamic linker support, this
patch will add its prototype in the generated `dlfcn.h` header so that
it can be used by downstream platforms that have their own `dladdr`
implementation.
2025-08-05 15:06:08 -07:00
Caslyn Tonelli
cfd1ee781f [libc] Add dlinfo + RTLD_DI_* macros to dlfcn.h (#149938)
An initial commit for #149911, this adds a stub implementation for
dlinfo and the enums list of `RTLD_DI_*` values.

While the dlinfo implementation relies on dynamic linker support, this
patch will add its prototype in the generated dlfcn.h header so that it
can be used by downstream platforms that have their own dlinfo
implementation.
2025-08-05 13:34:30 -07:00
Caslyn Tonelli
b5bf100046 [libc] Add RTLD_NEXT + RTLD_DEFAULT (#149909)
Related to #97920, this patch adds `dlsym` macros `RTLD_NEXT` AND
`RTLD_DEFAULT` to dlfcn.h.
2025-08-05 10:51:28 -07:00
Leandro Lacerda
cd19fbad09 [libc] Enable float math functions on the GPU (#151841)
This patch adds the `tanpif` math functions to the GPU build. It also
adds the `cospif` and `sinpif` math functions to the `math.h` header.
2025-08-02 22:13:04 -05:00
Aiden Grossman
fc5976118d [libc] Add implementation of getcpu syscall wrapper (#150871)
This patch adds the getcpu syscall wrapper. This has been supported in
glibc since v2.29.
2025-07-30 09:45:19 -07:00
Uzair Nawaz
a1aba84c2b [libc] Reland #148948 "Implement barriers for pthreads" (#151021)
Fixed build dependencies for pthread_barrier_t (add __barrier_type to
cmake dependencies)
2025-07-29 16:39:40 +00:00
sribee8
a653934b58 [libc] Reland wchar string conversion mb to wc (#151048)
Added crash on nullptr to mbstowcs

---------

Co-authored-by: Sriya Pratipati <sriyap@google.com>
2025-07-29 16:34:10 +00:00
sribee8
1381ad497b Revert "[libc] Reland #149423 "wchar string conversion functions mb to wc"" (#151016)
Reverts llvm/llvm-project#150667
2025-07-28 18:39:41 +00:00
Uzair Nawaz
a4a0832899 Revert "[libc] Implement barriers for pthreads" (#151014)
Reverts llvm/llvm-project#148948
2025-07-28 11:37:23 -07:00
Uzair Nawaz
7ca23754c4 [libc] Implement barriers for pthreads (#148948)
Implemented barrier synchronization for pthreads
- Uses condition variables internally for platform independence
(platform-specific work is handled by the condition variable
implementation)
- Does NOT currently handle barrierattr pshared, this is a goal for a
future patch
2025-07-28 11:22:38 -07:00
sribee8
741df45bc3 [libc] Reland #149423 "wchar string conversion functions mb to wc" (#150667)
Added missing includes in the test files for null check

---------

Co-authored-by: Sriya Pratipati <sriyap@google.com>
2025-07-28 17:40:10 +00:00
OverMighty
6a85f7cef3 Revert "[libc][math][c23] Implement C23 math function asinpif16" (#150756)
Reverts llvm/llvm-project#146226

The MPFR test uses `mpfr_asinpi` which requires MPFR 4.2.0 or later, but
the Buildbots are running an older version of MPFR.

See https://lab.llvm.org/buildbot/#/builders/104/builds/27743 for
example.

I said I was going to revert the PR until we have a workaround for older
versions of MPFR, but then I forgot and I just disabled the entrypoints
which doesn't fix the Buildbot builds.
2025-07-26 15:39:43 +03:00
Mohamed Emad
eed9b4e058 [libc][math][c23] Implement C23 math function asinpif16 (#146226)
The function is implemented using the following Taylor series that's
generated using [python-sympy](https://www.sympy.org/en/index.html), and
it is very accurate for |x| $$\in [0, 0.5]$$ and has been verified using
Geogebra. The range reduction is used for the rest range (0.5, 1].

$$
\frac{\arcsin(x)}{\pi} \approx 
\begin{aligned}[t]
    &  0.318309886183791x  \\
    & + 0.0530516476972984x^3 \\
    & + 0.0238732414637843x^5 \\
    & + 0.0142102627760621x^7 \\
    & + 0.00967087327815336x^9 \\
    & + 0.00712127941391293x^{11} \\
    & + 0.00552355646848375x^{13} \\
    & + 0.00444514782463692x^{15} \\
    & + 0.00367705242846804x^{17} \\
    & + 0.00310721681820837x^{19} + O(x^{21})
\end{aligned}
$$

## Geogebra graph

![28-06-2025-1913-eDP-1](https://github.com/user-attachments/assets/f70818e1-1b34-406e-962a-a30fdc909f18)

Closes #132210
2025-07-26 14:02:18 +03:00
Uzair Nawaz
3f3d779ff8 [libc] Implement mbsinit (#150654)
Implemented public libc function to check if an mbstate describes an
empty state
2025-07-25 12:45:24 -07:00
sribee8
42b101d844 Revert "[libc] wchar string conversion functions mb to wc" (#150549)
Reverts llvm/llvm-project#149423

Failing nullptr crash when using sanitizer
2025-07-24 23:39:16 +00:00
sribee8
af98a245f8 [libc] wchar string conversion functions mb to wc (#149423)
Implemented an internal multi-byte to wide character string conversion
function, public functions, and tests

---------

Co-authored-by: Sriya Pratipati <sriyap@google.com>
2025-07-24 23:10:32 +00:00
Uzair Nawaz
7884c077ff [libc] Implement wcs to mbs family of functions (#149421)
Implemented internal wcs to mbs internal function + tests
Impelemented wcs to mbs public functions
2025-07-24 13:15:52 -07:00
William Huynh
becde6d62e [libc] Fix issue with sigjmp_buf.h not being found (#150439)
When trying to use <setjmp.h>, it will try to include
llvm-libc-types/sigjmp_buf.h due to the way that headergen works. This
commit creates a dummy file, as the real implementation is found in
llvm-libc-types/jmp_buf.h.
2025-07-24 19:50:50 +01:00
Uzair Nawaz
f26c0d00df [libc] Implemented wcsdup libc function (#150453)
Implemented wcsdup by templating internal strdup function
2025-07-24 11:29:40 -07:00