601 Commits

Author SHA1 Message Date
bkuhls
ea9f8b7746
[libc] Fix detection of cfloat128 (#185486)
Building compiler-rt with aarch64-buildroot-linux-gnu-gcc 15.2 causes a
build error:
```
compiler-rt-22.1.0/cmake/Modules/../../libc/src/__support/CPP/type_traits/is_complex.h:44:31:
 error: 'cfloat128' was not declared in this scope; did you mean 'float128'? [-Wtemplate-body]
```
According to
https://gcc.gnu.org/onlinedocs/gcc-15.2.0/gcc/Floating-Types.html
__float128 is not available on aarch64.

Analyzing the gcc defines for aarch64 seems to prove it:
```
$ aarch64-buildroot-linux-gnu-gcc -v
Target: aarch64-buildroot-linux-gnu
gcc version 15.2.0 (Buildroot 2026.02-114-gdadec9da56)

$ echo | aarch64-buildroot-linux-gnu-gcc -dM -E - | grep __GCC_IEC_559_COMPLEX
  #define __GCC_IEC_559_COMPLEX 2

$ echo | aarch64-buildroot-linux-gnu-gcc -dM -E - | grep __STDC_IEC_60559_COMPLEX__
  #define __STDC_IEC_60559_COMPLEX__ 201404L

$ echo | aarch64-buildroot-linux-gnu-gcc -dM -E - | grep -i float128
$
```
In contrast gcc for x86_64:
```
$ x86_64-buildroot-linux-gnu-gcc -v
Target: x86_64-buildroot-linux-gnu
gcc version 15.2.0 (Buildroot 2026.02-112-gd12ac02486)

$ echo | x86_64-buildroot-linux-gnu-gcc -dM -E - | grep __GCC_IEC_559_COMPLEX
  #define __GCC_IEC_559_COMPLEX 2

$ echo | x86_64-buildroot-linux-gnu-gcc -dM -E - | grep __STDC_IEC_60559_COMPLEX__
  #define __STDC_IEC_60559_COMPLEX__ 201404L

$ echo | x86_64-buildroot-linux-gnu-gcc -dM -E - | grep -i float128
  #define __SIZEOF_FLOAT128__ 16
```
This patch changes the or-condition to an and-condition for
    \_\_STDC_IEC_60559_COMPLEX\_\_ and \_\_SIZEOF_FLOAT128\_\_.

Signed-off-by: Bernd Kuhls <bernd@kuhls.net>
2026-03-11 10:12:23 -04:00
Jiří Filek
56e19de931
[libc] Implement iswspace entrypoint (#185269)
Implement entrypoint for iswspace function and related test
Part of #185136
2026-03-11 06:56:54 -07:00
Alexey Samsonov
bbb1c831d1
[libc] Add missing const qualifiers to a few functions in <time.h> (#185311)
`asctime_r`, `gmtime`, and `gmtime_r` were missing const-qualifiers for
a first function argument. Add them to fix generated `<time.h>` header.

Implementation headers / source files are declaring arguments correctly.
2026-03-10 10:08:55 -07:00
valium007
375357eeaf
[libc] implement iswcntrl entrypoint (#185273)
Implement iswcntrl entrypoint and test for #185136
2026-03-10 08:29:44 -07:00
albertbolt1
c79034abb6
[libc] 185136 - added iswlower entry point (#185221)
Changes include:
- Added iswlower entrypoint in wctype.yaml to expose the function
- Created iswlower.h header and iswlower.cpp implementation
- Added CMake entrypoint object for iswlower
- Created unit test in iswlower_test.cpp
- Added test entry to wctype CMakeLists.txt

this PR helps in exposing iswlower which internally calls islower on
wide character

built using :  ninja -C build libc 
tested using : ninja libc_wctype_unittests and all the 3 tests passed 

resolves issue #185136
2026-03-10 07:20:23 -07:00
Alexey Samsonov
6a6564cd14
[libc] Add more macro/type declarations to Elf headers. (#185348)
* Add several `AT_` macro values from `<sys/auxv.h>`. In particular,
this allows to make internal Linux auxv header parsing more hermetic by
removing one of Linux header includes.
* Add constants between `DT_ADDRNGLO` and `DT_ADDRNGHI`, in particular
`DT_GNU_HASH`, which is de-facto standard on many platforms.
* Add `Elf32_auxv_t` and `Elf64_auxv_t` types which define the auxv
entries and can be used by VDSO parsing code. Note that this PR doesn't
yet update libc's own Linux auxv header support (in
`src/__support/OSUtil/linux/auxv.h`).

This fixes some of the missing definitions when building code working
with Elf files, such as Abseil's debugging support in

https://github.com/abseil/abseil-cpp/tree/master/absl/debugging/internal.
2026-03-09 15:12:54 -07:00
Alexey Samsonov
3fb55b6872
[libc] Add <sys/un.h> header. (#182622)
`sockaddr_un` structure is supposed to be provided by the `<sys/un.h>`
header. Add this header to llvm-libc, and move the declaration of
`sockaddr_un` there from `<sys/socket.h>`. See
https://man7.org/linux/man-pages/man0/sys_un.h.0p.html

Add proxy headers for the `<sys/socket.h>` macro (like `AF_UNIX`) and
for the `struct sockaddr_un` so that the tests can be more hermetic and
avoid system header inclusion.
2026-03-08 06:22:36 +00:00
Pengxiang Huang
5b976c9301
[libc][sys] add header and functions for sys ipc (#182700)
Split from a larger change. This PR contains the base impl for sys ipc,
sys sem will come after this. @SchrodingerZhu

this PR implements for:
https://github.com/llvm/llvm-project/issues/182161

see the last PR for more detail:
https://github.com/llvm/llvm-project/pull/182683
2026-03-03 09:48:18 -05:00
Roland McGrath
5156147824
[libc] Declare reallocarray in stdlib.h / malloc.h (#184223)
Scudo now provides reallocarray, so declare it.
2026-03-02 13:47:43 -08:00
Muhammad Bassiouni
e3735ce4b3
[libc][math] Disable float16 on Clang 11 and older (#183574)
This also reverts
c5d6feb315
2026-02-26 20:47:29 +02:00
Alexey Samsonov
8cbbd5b561
[libc] Add backwards-compatibility macro to struct stat. (#182601)
Older code may use `st_atime` which recorded timestamps with one-second
precision, instead of `struct timespec st_atim` that is available in
later POSIX versions.

Add `#define st_atime` (& friends) to type declaration as suggested in
https://man7.org/linux/man-pages/man3/stat.3type.html
2026-02-24 22:28:30 +00:00
Jeff Bailey
d1e29a4bf1
[libc] Enable ifunc support in static startup (#182841)
Resolves ifunc targets before `main()` runs in static libc

This enables static binaries to use ifunc-based dispatch during early
process startup, so optimized implementations can be selected based on
CPU features. Without this relocation step in startup, those targets are
not ready when program code begins executing.

This change:
- adds IRELATIVE relocation handling for x86_64, AArch64, ARMv7 and RISC-V,
- reads `AT_HWCAP` / `AT_HWCAP2` from auxv and passes them to resolvers
where required (notably AArch64),
- runs IRELATIVE processing after base-address discovery and before TLS
setup,
- adds integration tests for both the ifunc path and the no-ifunc path,
- Changed the load bias type for ptrdiff_t to intptr_t to align with
IRELATIVE handling, which uses intptr_t for load bias calculations.
2026-02-24 21:03:05 +00:00
fineg74
ab3d742f6f
[libc] Add basic support for building SPIR-V libraries (#181049)
This is to add support to build libc for building with spirv backend,
for use with OpenMP kernels
2026-02-16 20:27:39 -06:00
Roland McGrath
73dc25c1b6
[libc] Add pthread_getattr_np declaration (#178549)
Add header declaration and implementation header for the GNU
extension function pthread_getattr_np.  An actual implementation
can come later.
2026-01-29 10:33:19 -08:00
Roland McGrath
dbce14f0d6
[libc] Clean up pthread.yaml (#178327)
Remove pthread.h.def and use pure generation.  Fix YAML records
for standards to correct syntax and remove redundancies.

Don't declare NULL, which is not specified for <pthread.h>.
Do declare PTHREAD_NULL.
2026-01-28 12:30:54 -08:00
Jakob Koschel
dc55e20483
[libc] Add Elf32_Xword type (#177915)
In a recent PR (https://github.com/llvm/llvm-project/pull/174772), we
introduced GnuPropertySection using ElfW(Xword). Since we are currently
missing Elf32_Xword, this is failing on 32bit architectures.

This commit adds the missing Elf32_Xword type that should always hold
64bit even on 32bit architectures.
2026-01-26 14:48:35 -08:00
Jakob Koschel
6574918875
[libc][linux] add support to parse PT_GNU_PROPERTY (#174772)
In order to add Control-flow Enforcement Technology (CET) Shadow Stack
(SHSTK) support, we need to parse the `PT_GNU_PROPERTY` program header
and the corresponding section to evaluate if the binary being started
was compiled with the necessary support.

PS: This is my first PR to llvm-libc, I might have made obvious styling
mistakes so I'd appreciate any feedback or suggestions to improve it.

I have a prototype branch using this change to enable SHSTK support:
https://github.com/jakos-sec/llvm-project/tree/add-shstk-support
2026-01-20 14:33:01 -08:00
Petr Hosek
9007f1dd45
[libc] Fix a typo in DT_BIND_NOW macro name (#175619)
This was accidentally introduced in #172766.
2026-01-12 19:18:34 +00:00
Petr Hosek
5db5782da1
[libc] Provide a minimal implementation of elf.h (#172766)
Some of the baremetal users of libc use elf.h to generate coredumps and
we would like to support this use case without needing Linux elf.h.
2026-01-12 10:56:49 -08:00
Roland McGrath
10d6a02016
[libc] Add stub pthread_attr_getschedparam / pthread_attr_setschedparam (#173440)
Add the boilerplate for declaring these POSIX functions and
providing implementations.  So far the only implementations are
just stubs that fail with ENOTSUP, and they are neither tested
nor included in any CMake entrypoints lists.  More work is still
required to add the actual fields to the pthread_attr_t and
implement the support in the Linux pthread_create et al, but that
is not done here.  It's not an especially large amount of work,
but more than just trivial.

The scaffolding here paves the way for that later work, but is
also immediately useful for filling out the subset of POSIX
pthread_attr_* functions that Fuchsia's libc already supports.
2025-12-23 19:55:18 -08:00
Connector Switch
12e5bd1e30
[libc] Add IN6_IS_ADDR_V4COMPAT (#172646)
This patch adds the `IN6_IS_ADDR_V4COMPAT` macro, which checks whether
an address is IPv4-compatible.
2025-12-18 23:13:54 +08:00
Connector Switch
e071e43589
[libc] Add IN6_IS_ADDR_V4MAPPED (#172645)
This patch adds the `IN6_IS_ADDR_V4MAPPED` macro, which checks whether
an address is IPv4 mapped address.
2025-12-18 23:12:49 +08:00
Connector Switch
12d4889a0a
[libc] Add IN6_IS_ADDR_MC* (#172643)
This patch adds the `IN6_IS_ADDR_MC*` macro, which checks whether an
address is multicast node-local address, multicast link-local address,
multicast site-local address, multicast organization-local address and
multicast global address.
2025-12-18 23:11:35 +08:00
Connector Switch
3f79d13aff
[libc] Add IN6_IS_ADDR_MULTICAST (#172498)
This patch adds the `IN6_IS_ADDR_MULTICAST` macro, which checks whether
an address is multicast address.
2025-12-18 23:10:33 +08:00
Connector Switch
ecd46d350a
[libc] Add IN6_IS_ADDR_LOOPBACK (#172312)
This patch adds the `IN6_IS_ADDR_LOOPBACK` macro, which checks whether
an address is loopback address.
2025-12-18 23:09:35 +08:00
Connector Switch
f904c2ad59
[libc] Add IN6_IS_ADDR_UNSPECIFIED (#172311)
This patch adds the `IN6_IS_ADDR_UNSPECIFIED` macro, which checks
whether an address is unspecified address.
2025-12-18 23:06:54 +08:00
Connector Switch
62ee2cf0f4
[libc] Add IN6_IS_ADDR_{LINK, SITE}LOCAL (#168207)
This patch introduces two macros in `netinet/in.h`. The redundant tests
for macro values in the testcases have been removed.
2025-12-13 10:57:38 +08:00
Sterling-Augustine
a50a7ea2e2
[libc] Add support for getpagesize. (#171713)
As in the description.
2025-12-11 14:27:50 -08:00
Shreeyash Pandey
2a5420ea51
[libc] move abs_timesout and monotonicity out of linux dir (#167719)
This patch moves abs_timeout and monotonicity out of the linux dir into
common. Both of these functions depend on clock_gettime which is the
actual os-dependent component. As other features in `__support/threads`
may want to use these, it's better to share it in common.
2025-12-08 22:14:12 +05:30
lntue
4c59219fc9
[libc][fenv] Refactor x86 fenv implementations to make it work for various fenv_t. (#165015) 2025-12-05 16:00:10 -05:00
Shreeyash Pandey
80e4a3f7a6
[libc] Add clock_gettime for Darwin (#167160)
This patch adds support for clock_gettime for Darwin. Darwin syscall
'gettimeofday' is used to query the time from the system.

Many headers in llvm-libc-types, namely clockid_t, struct_timespec,
struct_timeval, suseconds_t, time_t_32, time_t_64, are modified to
include
header guards as Darwin has its own implementation of primitive types.
2025-11-28 20:23:41 +05:30
Shreeyash Pandey
fb94261d88
[libc][darwin] add syscall numbers from macos sdk (#166354)
This PR adds support to include syscall.h from MacOS sdk by explicitly including the path to the sdk via `xcrun`.
2025-11-27 21:26:42 +05:30
Alexey Samsonov
1136239561
[libc] Add missing dependencies for arpa/inet.h header. (#168951)
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-20 22:04:05 +00:00
Jackson Stogel
db71cc58ec
[libc] Implement pkey_alloc/free/get/set/mprotect for x86_64 linux (#162362)
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 14:30:15 -08:00
Connector Switch
a5590a2aab
[libc] implement inet_addr (#167708)
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-18 10:17:19 +08:00
Alexey Samsonov
da61dd28c6
[libc] Move mbtowc, mbstowcs and inverse functions to stdlib.h (#168455)
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 15:43:42 -08:00
Alexey Samsonov
92c8c87c49
[libc] Implement wcstod and wcstold. (#168020)
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-17 13:42:12 -08:00
Schrodinger ZHU Yifan
5b798df8c4
Revert "[libc][test] split exit tests into two separate tests" (#168102)
Reverts llvm/llvm-project#166355
2025-11-14 13:36:05 -05:00
Shreeyash Pandey
e7db040b79
[libc][test] split exit tests into two separate tests (#166355)
_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-14 13:27:32 -05:00
Alexey Samsonov
e797ec6476
[libc] Templatize strtofloatingpoint and implement wcstof. (#167755)
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-13 11:38:33 -08:00
Anton Shepelev
79601cec33
[libc][POSIX] Add clock_settime() function for Linux (#161729)
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 09:54:34 -08:00
Anshul Nigham
497dc100c9
[libc] Implement fchown (#167286)
Implements fchown

fixes: #166856
2025-11-11 09:54:21 -08:00
Connector Switch
ffb5831fce
[libc] add various macros relate to *ADDR* (#164830)
This patch adds 4 macros in the `netinet/in.h` header, as specified by
POSIX standards.
2025-11-08 20:39:26 +08:00
Victor Campos
0b72899f6d
[libc][math] Refactor the math_errhandling macro definition (#166350)
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-05 16:59:55 +00:00
Shubh Pachchigar
0fd029858a
[libc] Add chown and getgid implementations (#166434)
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-11-04 16:18:53 -08:00
Alexey Samsonov
42a8ff877d
[libc] Add "struct tm" declaration to <wchar.h> (#165795)
`<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:
c46bfed1a4/libcxx/include/cwchar (L135)

So, add this type declaration to llvm-libc version of `wchar.h` now.
2025-10-30 20:30:49 -07:00
Alexey Samsonov
45b1a4bb8d
Add <stdbool.h> to llvm-libc-types headers that need it. (#165798)
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 16:37:00 -07:00
Roland McGrath
a24a7548b8
[libc][hdrgen] Sort identifiers with leading underscores specially (#165745)
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-30 11:49:22 -07:00
Connector Switch
30f9ce14b4
[libc] add SIG_HOLD for linux/gpu (#165007) 2025-10-25 12:34:03 +08:00
Shreeyash Pandey
a1dc546f7f
[libc] add missing headers in stdfix (#162078)
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-24 10:42:31 -07:00