summaryrefslogtreecommitdiff
path: root/libc/include
AgeCommit message (Collapse)Author
2025-11-20[libc] Add missing dependencies for arpa/inet.h header. (#168951)Alexey Samsonov
Add dependency on headers with `in_addr` and `in_addr_t` type definitions to ensure that these headers will be properly installed by "install-libc" CMake target.
2025-11-18[libc] Implement pkey_alloc/free/get/set/mprotect for x86_64 linux (#162362)Jackson Stogel
This patch provides definitions for `pkey_*` functions for linux x86_64. `pkey_alloc`, `pkey_free`, and `pkey_mprotect` are simple syscall wrappers. `pkey_set` and `pkey_get` modify architecture-specific registers. The logic for these live in architecture specific directories: * `libc/src/sys/mman/linux/x86_64/pkey_common.h` has a real implementation * `libc/src/sys/mman/linux/generic/pkey_common.h` contains stubs that just return `ENOSYS`.
2025-11-18[libc] implement inet_addr (#167708)Connector Switch
This patch adds the posix function `inet_addr`. Since most of the parsing logic is delegated to `inet_aton`, I have only included some basic smoke tests for testing purposes.
2025-11-17[libc] Move mbtowc, mbstowcs and inverse functions to stdlib.h (#168455)Alexey Samsonov
These functions should be declared in `stdlib.h`, not `wchar.h`, as confusing as it is. Move them to the proper header file and matching directories in src/ and test/ trees. This was discovered while testing libc++ build against llvm-libc, which re-declares functions like mbtowc in std-namespace in `<cstdlib>` header, and then uses those functions in its locale implementation.
2025-11-17[libc] Implement wcstod and wcstold. (#168020)Alexey Samsonov
These are simply implemented as specializations of strtofloatingpoint for double / long double and for wchar_t. The unit tests are copied from the strtod / strtold ones.
2025-11-14Revert "[libc][test] split exit tests into two separate tests" (#168102)Schrodinger ZHU Yifan
Reverts llvm/llvm-project#166355
2025-11-14[libc][test] split exit tests into two separate tests (#166355)Shreeyash Pandey
_Exit(3) is a fairly simple syscall wrapper whereas exit(3) calls atexit-registered functions + whole lot of stuff that require support for sync primitives. Splitting the tests allows testing the former easily (especially for new port projects) --------- Signed-off-by: Shreeyash Pandey <shreeyash335@gmail.com>
2025-11-13[libc] Templatize strtofloatingpoint and implement wcstof. (#167755)Alexey Samsonov
This change follows the pattern of 315dfe5865962d8a3d60e21d1fffce5214fe54ef by making strtofloat also accept wchar_t* strings (in addition to regular char*). It uses overloads from wctype_utils or specialized functions to ensure comparison with literal characters (or literal strings) pick char or wchar_t variants based on the argument type. The wcstof implementation is added, with unit test cases copied from strtof test suite.
2025-11-11[libc][POSIX] Add clock_settime() function for Linux (#161729)Anton Shepelev
Closes #161461 - This is my first time contributing to libc's POSIX, so for reference I used `clock_gettime` implementation for Linux. For convenience, here is the description of `clock_settime` function [behavior](https://www.man7.org/linux/man-pages/man3/clock_settime.3.html)
2025-11-11[libc] Implement fchown (#167286)Anshul Nigham
Implements fchown fixes: #166856
2025-11-08[libc] add various macros relate to *ADDR* (#164830)Connector Switch
This patch adds 4 macros in the `netinet/in.h` header, as specified by POSIX standards.
2025-11-05[libc][math] Refactor the `math_errhandling` macro definition (#166350)Victor Campos
This patch refactors the logic to define each component of the `math_errhandling` macro. It assumes that math error handling is supported by the target and the C library unless otherwise disabled in the preprocessor logic. In addition to the refactoring, the support for error handling via exceptions is explicitly disabled for Arm targets with no FPU, that is, where `__ARM_FP` is not defined. This is because LLVM libc does not provide a floating-point environment for Arm no-FP configurations (or at least one with support for FP exceptions).
2025-11-04[libc] Add chown and getgid implementations (#166434)Shubh Pachchigar
Implements chown and getgid per the POSIX specification and adds corresponding unit tests. getgid is added as it is required by the chown unit tests. This PR will address #165785 Co-authored-by: shubh@DOE <shubhp@mbm3a24.local>
2025-10-30[libc] Add "struct tm" declaration to <wchar.h> (#165795)Alexey Samsonov
`<wchar.h>` should at least include the forward declaration of `struct tm`, since it's needed for the `wcsftime` declaration (also, see https://man7.org/linux/man-pages/man0/wchar.h.0p.html). Even though we don't yet have `wcsftime`, some downstream users (notably - libcxx) expects to see `struct tm` declaration there, to re-declare it under `std` namespace: https://github.com/llvm/llvm-project/blob/c46bfed1a484d30cd251a9a225649d74e3bf0af5/libcxx/include/cwchar#L135 So, add this type declaration to llvm-libc version of `wchar.h` now.
2025-10-30Add <stdbool.h> to llvm-libc-types headers that need it. (#165798)Alexey Samsonov
We need `<stdbool.h>` to support having "bool" members inside pthread structs that may get included through `<pthread.h>` from C code prior to C23.
2025-10-30[libc][hdrgen] Sort identifiers with leading underscores specially (#165745)Roland McGrath
This makes the sorting behavior more uniform: functions and macros are always sorted (separately), not only when merging. This changes the sort order used for functions and other things sorted by their symbol names. Symbols are sorted alphabetically without regard to leading underscores, and then for identifiers that differ only in the number of leading underscores, the fewer underscores the earlier in the sort order. For the functions declared in a generated header, adjacent names with and without underscores will be grouped together without blank lines. This is implemented by factoring the name field, equality, and sorting support out of the various entity classes into a new common superclass (hdrgen.Symbol). This uncovered YAML's requirement to quote the string "NULL" to avoid pyyaml parsing it as None (equivalent to Javascript null) rather than a string.
2025-10-25[libc] add SIG_HOLD for linux/gpu (#165007)Connector Switch
2025-10-24[libc] add missing headers in stdfix (#162078)Shreeyash Pandey
Fixes https://github.com/llvm/llvm-project/issues/129361 @michaelrj-google @PiJoules --------- Signed-off-by: Shreeyash Pandey <shreeyash335@gmail.com> Co-authored-by: Michael Jones <michaelrj@google.com>
2025-10-22[libc][annex_k] Add Annex K support macros. (#163100)Muhammad Bassiouni
RFC https://discourse.llvm.org/t/rfc-bounds-checking-interfaces-for-llvm-libc/87685 Add internal support macros required by Annex K interface in LLVM libc.
2025-10-22[libc] Fix a couple issues in <wchar.h> header (#164666)Alexey Samsonov
* Add FILE type declaration, as it should be presented in `<wchar.h>`, as well as in `<stdio.h>` * Fix argument type in `wcsrtombs` / `wcsnrtombs` function - it should be restrict pointer to `mbstate_t`. Add restrict qualifier to internal implementation as well. This brings us closer to being able to build libcxx with wide-character support against llvm-libc headers.
2025-10-22[libc] Add macros definitions for <nl_types.h> (#164474)Alexey Samsonov
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 12abe8aed6dc724546cf93c94d7ff6abe864f28b, together with stub definitions of the three required functions.
2025-10-21[libc] Stub out message catalog functions from <nl_types.h> (#164360)Alexey Samsonov
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[libc] implement `inet_aton` (#162651)Connector Switch
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[libc] Add llvm-libc-types header deps for <complex.h>. (#164422)Simon Tatham
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-17[libc] add IPV6 related macros (#162219)Connector Switch
2025-10-15[libc] Update generated libc header to include missing functions/files. ↵Alexey Samsonov
(#163658) * Add a missing dependency to install struct_itimerval.h * Add fseeko/ftello declarations to stdio.h
2025-10-08[libc][math][c23] Add rsqrtf() function (#159615)Anton Shepelev
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[libc][stdfix] Implement fxdivi functions (rdivi) (#154914)Shreeyash Pandey
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[libc] add `in_addr{, _t}` type (#162452)Connector Switch
These types will be used in `arpa/inet.h` and `netinet/in.h`.
2025-10-06[libc] add IPPROTO related macros (#161855)Connector Switch
2025-10-02[libc] Implement faccessat (#161065)Marcell Leleszi
#160404 - Implement POSIX function "faccessat" - Remove redundant param in facessat syscall in access implementation, faccessat syscall does not take a flags arg
2025-09-23[libc][POSIX][unistd] Implement gethostname (#128142)Zaky Hermawan
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-22[libc] Remove separate RPC test handling (#160206)Joseph Huber
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-17[libc][math][c23] Add rsqrtf16() function (#137545)Anton Shepelev
Addresses #132818 Part of #95250
2025-09-05[libc] Fix CMPLXF128 macro definition for aarch64. (#157157)lntue
2025-09-05[libc] Implement `CMPLX` for clang < 12 (#157096)Connector Switch
Fixes https://github.com/llvm/llvm-project/pull/156344#issuecomment-3256837826
2025-09-05[NFC] Fix a comment for cfloat128.h (#157093)Connector Switch
2025-09-05[libc] Workaround for GCC on `typedef` for `_Complex __float128` (#157010)A. Jiang
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[libc] Implement CMPLX related macros (#156344)Connector Switch
2025-09-04[libc] Remove unused _Thread_local define from headers. (#156967)Alexey Samsonov
It was added in dd33f9cdef9f6209aa34713e1417f4a2e24e5ca6 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-03[libc] implement template functions for localtime (#110363)Zishan Mirza
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-02[libc] Add CMake Target for Dl_info.h Header (#156195)Aiden Grossman
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[libc] Add missing and correct some existing C23 functions to math.h (#156512)Alexey Samsonov
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[libc][math][c23] Implement C23 math function atanpif16 (#150400)Mohamed Emad
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-08-22[libc] Add half-precision math functions to the math header (#155060)Leandro Lacerda
This patch adds the `exp10f16`, `exp2f16`, `expf16`, and `expm1f16` math functions to the `math.h` header.
2025-08-22[libc] Enable double math functions on the GPU (#154857)Leandro Lacerda
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-19[libc] Add _Returns_twice to C++ code (#153602)William Huynh
Fixes issue with `<csetjmp>` which requires `_Returns_twice` but in C++ mode
2025-08-18Reland "[libc][math][c23] Implement C23 math function asinpif16" (#152690)Mohamed Emad
#146226 with fixing asinpi MPFR number function and make it work when mpfr < `4.2.0`
2025-08-17[libc] Setup hdrgen for ioctl (#153976)Aiden Grossman
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-16[libc] Correct standard for getcpu (#153982)Aiden Grossman