Commit graph

782 commits

Author SHA1 Message Date
Michael Jones
9001032630
[libc] Move generated elf header to include (#211428)
The fact that `hdr/elf_proxy.h` was generated with headergen was causing
dependency issues. This shouldn't be necessary, and this PR moves it out
into `include` to avoid needing headergen for an overlay build.

Assisted-by: Automated tooling, human reviewed.
2026-07-31 16:37:32 -07:00
Alexey Samsonov
6e4374e974
[libc] Add SIGPOLL si_code values. (#212873)
This is a follow-up to efc78d2029, which
adds `si_code` values for the `SIGPOLL` signal on Linux.
2026-07-31 09:13:24 -07:00
Alexey Samsonov
fd7993ea2d
[libc] Add <sys/statfs.h> header and entrypoints. (#213108)
Implement `statfs` and `fstatfs` functions on Linux.

We already have `struct statfs` and syscall wrappers defined (to
implement POSIX `<sys/statvfs.h>`). Use them to provide Linux-specific
functions as well.
2026-07-31 14:29:27 +00:00
Alexey Samsonov
7d5dd438b2
[libc] Add 'struct ucred' definition. (#213152)
This is a Linux extension that allows to obtain credentials of a peer
process connected to a socket, e.g. via passing `SO_PEERCRED` to
`getsockopt` function.
2026-07-31 07:15:02 -07:00
Alexey Samsonov
2f08dff513
[libc] Refactor statfs Linux syscalls and provide 'struct statfs' (#212930)
* Extract statfs/fstatfs Linux syscall wrappers to
`linux/syscall_wrappers` directory;
* Provide our own definition of `struct statfs` type and a corresponding
proxy header (to use system type in overlay mode);
* Migrate callers (e.g. statfs->statvfs translation) to use the new
syscall wrapper.

This would allow us to add Linux-specific (non-POSIX) `<sys/statfs.h>`
header as a next step.

Assisted by: Gemini, human-reviewed
2026-07-30 07:46:38 -07:00
Jeff Bailey
a853e6fcaf
[libc] Add struct passwd type, pwd.yaml, and pwd_utils parser (#212421)
Added struct passwd type definition, pwd.yaml header specification, and
parse_passwd_line utility returning ErrorOr<struct passwd> for
colon-separated
password file parsing with hermetic unit tests.

Note: Additional POSIX pwd.h functions (getpwuid, getpwnam, getpwuid_r,
getpwnam_r, fgetpwent) are omitted from this initial change and will be
added in follow-up PRs.

* Added libc/include/llvm-libc-types/struct_passwd.h and proxy header
* Added libc/include/pwd.yaml header specification
* Added pwd_utils.h and pwd_utils.cpp implementing ErrorOr<struct
passwd> parse_passwd_line
* Added pwd.h to target public headers for linux architectures
* Added unit tests in libc/test/src/pwd/pwd_utils_test.cpp

Assisted-by: Automated tooling, human reviewed.
2026-07-30 15:27:07 +01:00
Alexey Samsonov
e7b04c15e6
[libc] Modernize and extend dirent.h header. (#212902)
Extend the `<dirent.h>` header with macro and types specified in recent
POSIX.1-2024:
* Add `posix_dent` structure, which has more fields than `dirent`, that
are actually used in practice. This struct would be identical to
`dirent` that we have on Linux
* Add `reclen_t` type for `d_reclen` field.
* Add macro `DT_BLK` and friends

Also, extend the tests to verify the values of `d_type` field, now that
we have the proper macro defined.

Assisted by: Gemini, human-verified
2026-07-29 17:49:01 -07:00
Jeff Bailey
33d2c6ad8c
[libc] Add missing type dependencies to sys_types header target (#212601)
Add missing type dependencies to the sys_types header target in
libc/include/CMakeLists.txt for types defined in sys/types.yaml,
including __off_t, __off64_t, __uint64_t, off64_t, and BSD/System V
types added in commit 39df67d0ed.

Without these DEPENDS entries, CMake and Ninja do not copy the
corresponding type headers into the build and install directories,
causing missing header includes (e.g. __off64_t.h) when consuming
generated <sys/types.h>.

Assisted-by: Automated tooling, human reviewed.
2026-07-28 23:43:07 +01:00
Jeff Bailey
7cf62f99cd
[libc] Add POSIX redirection header specifications in YAML (#211859)
Add header YAML specifications for memory.h, sys/poll.h, sys/unistd.h,
sys/fcntl.h, and sys/signal.h using public_includes.

POSIX.1-2017 and historical X/Open System Interfaces (XSI) standards
define these headers as alternate or legacy header locations that
forward to string.h, poll.h, unistd.h, fcntl.h, and signal.h
respectively. The YAML header specs allow hdrgen to generate the public
headers automatically with proper license headers and guards.

Updated Linux target headers.txt configuration files to register the new
public header targets for installation.

Assisted-by: Automated tooling, human reviewed.
2026-07-28 15:37:12 +01:00
Jeff Bailey
e362f3c846
[libc][stdlib] Add putenv (#208339)
Added the POSIX putenv() function and its internal support.

Implemented EnvironmentManager::put() to insert caller-provided
"name=value" strings directly into the environment array, managing
ownership correctly (caller retains ownership).

Registered for x86_64, aarch64, and riscv. Integration tests cover basic
operations, ownership semantics, validation, and edge cases.

Assisted-by: Automated tooling, human reviewed.
2026-07-28 15:35:04 +01:00
Alex Strelnikov
39d3b9344f
[libc] Add stub implementation for strptime. (#211088)
This PR adds a stub for `strptime` under
`LLVM_LIBC_ENABLE_EXPERIMENTAL_ENTRYPOINTS` for x86_64 and aarch64 as a
first step in implementing the function.
2026-07-27 16:19:21 +01:00
Alexey Samsonov
efc78d2029
[libc] Add symbolic constants for si_code values. (#211945)
Extend SIGCHLD-specific `si_code` values, already available in
`signal-macros.h` with Linux values for the rest of the signal-specific
codes specified in the POSIX.1-2024.
2026-07-24 16:57:00 -07:00
Jeff Bailey
b545f9ff45
[libc] Add missing standard and Linux header macros (#211862)
Add missing header macro constants:

* endian-macros.h: __BYTE_ORDER, __LITTLE_ENDIAN, and __BIG_ENDIAN
* sys-stat-macros.h: S_IREAD, S_IWRITE, S_IEXEC, and ACCESSPERMS
* limits-macros.h: _POSIX_HOST_NAME_MAX and HOST_NAME_MAX
* unistd-macros.h: TEMP_FAILURE_RETRY

POSIX.1-2017 specifies _POSIX_HOST_NAME_MAX as 255. The Linux
gethostname(2) man page specifies HOST_NAME_MAX as 64. The
double-underscore byte order macros and TEMP_FAILURE_RETRY macro follow
the Linux and GNU C library conventions.

Assisted-by: Automated tooling, human reviewed.
2026-07-24 21:59:16 +01:00
Jeff Bailey
39df67d0ed
[libc] Add missing sys/types.h integer and BSD/System V type definitions (#211861)
Add missing type definitions to llvm-libc-types and sys/types.yaml:

* POSIX standard types: id_t, useconds_t
* BSD and System V compatibility typedefs: caddr_t, u_int, u_int8_t,
u_int16_t, u_long, u_short, ulong, ushort
* Large File Support (LFS) and Linux kernel internal types: ino64_t,
off64_t, __off_t, __off64_t, __uint64_t

POSIX.1-2017 defines id_t and useconds_t in sys/types.h. The BSD and
System V standards specify the legacy unsigned integer shorthand types,
and Linux kernel/glibc interfaces use the double-underscore prefix
offset and integer types.

Assisted-by: Automated tooling, human reviewed.
2026-07-24 21:49:38 +01:00
lntue
995e2af535
[libc][termios] Make termios hermetic and fix its compatibility with glibc 2.42 or after. (#211039)
Make termios hermetic and address its compatibility with glibc 2.42
breaking change
with baud rate definitions:

https://inbox.sourceware.org/libc-announce/5906001.DvuYhMxLoT@pinacolada/T/

Fixes include:
- Baud rate translation utilities.
- Add proxy headers for termios.h macros and types.
- Update tests.

Assisted-by: Gemini 3.5 Flash.
2026-07-24 13:31:41 -04:00
Jeff Bailey
8d4f2368a0
[libc] Implement pthread_setschedparam and getschedparam (#205770)
Implemented the pthread_setschedparam and pthread_getschedparam
functions.

Added Linux syscall wrappers:
* sched_setscheduler
* sched_getscheduler
* sched_getparam

Updated the Thread class to support getting and setting scheduling
parameters.

Added integration tests to verify the implementation.

Assisted-by: Automated tooling, human reviewed.
2026-07-23 17:59:56 +01:00
Jeff Bailey
6d0e88210c
[libc] Add langinfo.h header generation, macros, and types (#210941)
Add header generation support for langinfo.h, including nl_item type
definition, langinfo macros, and YAML header specification.

* libc/include/llvm-libc-types/nl_item.h: Define nl_item type
* libc/include/llvm-libc-macros/langinfo-macros.h: Define POSIX macros
* libc/include/langinfo.yaml: Define langinfo.h interface
* libc/include/langinfo.h.def: Header template
* libc/config/linux/*/headers.txt: Enable langinfo header for Linux

Assisted-by: Automated tooling, human reviewed.
2026-07-22 10:45:16 +00:00
Pavel Labath
375231d8ea
[libc] Add struct group_req, struct group_source_req, and related socket options (#210029)
Add definitions for struct group_req and struct group_source_req in
llvm-libc-types and wire them into <netinet/in.h>.

Also define the multicast socket options using these structs:
- MCAST_JOIN_GROUP
- MCAST_LEAVE_GROUP
- MCAST_BLOCK_SOURCE
- MCAST_UNBLOCK_SOURCE
- MCAST_JOIN_SOURCE_GROUP
- MCAST_LEAVE_SOURCE_GROUP

Add layout assertions for struct group_req and struct group_source_req
to the netinet/in.h unit test.

Assisted by Gemini.
2026-07-21 07:19:01 +02:00
Anonmiraj
f05a649741
[libc][math] Implement half precision lgamma function (#192834)
The implementation uses three distinct paths based on $|x|$:

- Small ($|x| < 0.66$): Fits a degree-12 Chebyshev for $h(t) =
\frac{\text{lgamma}(t) + \log(t)}{t}$, recovering $\text{lgamma}(t) = t
\cdot h - \log(t)$.

- Medium ($|x| \in [0.66, 3.37]$): Fits a degree-20 Chebyshev for $g(t)
= \frac{\text{lgamma}(t)}{(t-1)(t-2)}$
- Stirling ($|x| > 3.37$): Uses $(x-0.5) \cdot \log(x) - x +
\frac{\log(2\pi)}{2}$ plus 1/2/4/8-term Bernoulli corrections by
sub-range.


Special cases: NaN, +/-Inf -> +Inf, +/-0 pole, negative integer pole,
lgamma(1) = lgamma(2) = 0 exactly, overflow for large positive x.

Exhaustive tests pass in all 4 rounding modes.

-- CORE-MATH reciprocal throughput --
Ntrial = 20 ; Min = 391.348 + 77.447 clc/call; Median-Min = 68.093
clc/call; Max = 540.055 clc/call;
-- System LIBC reciprocal throughput --
Ntrial = 20 ; Min = 377.829 + 81.686 clc/call; Median-Min = 64.851
clc/call; Max = 532.888 clc/call;
2026-07-19 04:29:50 +03:00
Pavel Labath
c571b0bd73
[libc] Fix size of struct sockaddr_storage (#210037)
My cleverness with the union backfired as it introduced an
(architecture-specific) padding between before it. Drop the union to
avoid that.

This probably wouldn't break much as the structure exists just to
allocate space (and this made it larger), but we should fix it
nonetheless.
2026-07-17 08:45:51 +02:00
Alexey Samsonov
bd0395ebfe
[libc] Move gettimeofday to sys/time.h header. (#210185)
`gettimeofday` is supposed to be declared in the `<sys/time.h>` header,
not the `<time.h>` where we've had it previously. Move the declaration
to the correct header, and move the files with implementation and unit
tests accordingly.

Note that `gettimeofday` is removed removed from POSIX-2024, but let's
keep it available for now, since there's fair amount of existing code
that still uses it.
2026-07-16 15:03:47 -07:00
Jeff Bailey
fe616e4d87
[libc] Implement alloca.h header (#210150)
Implemented the alloca.h header for LLVM libc.

* libc/include/llvm-libc-macros/alloca-macros.h: Defined alloca macro
using __builtin_alloca.
* libc/include/alloca.yaml: Added header specification.
* libc/include/CMakeLists.txt,
libc/include/llvm-libc-macros/CMakeLists.txt: Registered the new header
and macro targets.
* libc/config/linux/*/headers.txt: Enabled the header for Linux targets
(x86_64, aarch64, arm, i386, riscv).
* libc/test/include/alloca_test.cpp, libc/test/include/CMakeLists.txt:
Added and registered functional unit tests.

Tested by running the new unit and hermetic tests.

Assisted-by: Automated tooling, human reviewed.
2026-07-16 21:43:12 +01:00
Pavel Labath
5a530a22fa
[libc] Reimplement IN6_IS_ADDR_* macros using statement expressions (#209772)
This patch fixes three issues with the previous implementation:
- the macro argument was being evaluated more than once
- casting to other types (uint32_t in particular) was an aliasing
violation
- it was casting to non-const pointers, resulting in compiler errors in
cases where the user passes a const ptr.

A statement expression fixes the first issue by using a temporary
variable. The second issue is fixed by using the appropriate members of
struct in6_addr. The last issue is fixed by dropping the cast
completely. This requires the user to pass a correctly types pointer (as
POSIX requires). Implementations keep it for compatibility with old code
passing void * and similar, but a quick survey shows that most modern
code passes the correct types. If this turns out to be an issue, we can
easily add the cast (to a const type) back.

Implementation notes:
- IN6_IS_ADDR_MULTICAST doesn't use the statement expression because the
argument is evaluated only once
- I use private helper macros (__IN6_IS_ADDR_UNSPECIFIED and
__IN6_IS_ADDR_LOOPBACK) so IN6_IS_ADDR_V4COMPAT does not nest statement
expressions
- I considered using private entrypoints (like we do with cpuset macros)
instead of statement expressions, but decided against it because these
macros are simpler and would thus result in a higher
boilerplate-to-useful-code ratio (particularly given our restriction on
calling other entrypoints)

Assisted by Gemini.
2026-07-16 08:35:53 +02:00
sohail
48607d2984
[libc][stdfix] Implement divifx functions in LLVM libc (#206115)
Fixes #129124
2026-07-16 09:54:19 +05:30
Pavel Labath
89fa7352a2
[libc] Implement inet_ntoa (#208702)
Implement inet_ntoa, reusing the internal net::ipv4_to_str helper that
backs inet_ntop.

The result is stored in a *thread-local* static buffer. A thread-local
buffer is not required for POSIX conformance, but there is some
precedent for that, both in llvm libc (e.g. `strsignal`) and in glibc
(whose `inet_ntoa` uses it). I'm doing the same for maximum
compatiblity.

Assisted by Gemini.
2026-07-15 07:08:26 +00:00
Pavel Labath
cf9a244fb2
[libc] Fix non-relative includes of __llvm-libc-common.h (#209412)
This seems to work, but I ran into this problem when trying to expand
hermetic tests.

The hdrgen-generated headers already use relative includes of this file.
2026-07-14 14:14:17 +02:00
Jeff Bailey
da99ce2fe0
[libc] Implement SA_NODEFER and SA_RESETHAND signal flags (#209429)
Defined SA_NODEFER and SA_RESETHAND in Linux signal-macros.h.

Added unit tests in sigaction_test.cpp to verify the behavior of the new
flags. Also added a test case for SA_SIGINFO.

Assisted-by: Automated tooling, human reviewed.
2026-07-14 12:23:00 +01:00
Jackson Stogel
2987984f1e
[libc] Define NAME_MAX in limits.h (#209296)
Defines the POSIX macro `NAME_MAX`. Will be used by `realpath` tests.
2026-07-13 14:05:56 -07:00
Pavel Labath
9a4ad0acce
[libc] Assorted improvements to [gs]etitimer (#206974)
This started out as a patch adding a syscall wrapper for the two
functions. It still does that, but along the way I (or rather AI)
discovered an edge case in the truncation of microsecond values, where
we could turn bogus values into seemingly valid ones by throwing away
the high-order bits.

Additionally, when writing a test case, I noticed that the (64-bit)
kernel returns EINVAL for these out-or-range values. Our check returns
EOVERFLOW in this case, so I also change our error code in order to
provide an uniform behavior for the test case.

Neither of these (the check and the EINVAL error code) are present in
glibc (which lets truncated usec values through and returns EOVERFLOW on
second truncation), but I think it's better to be consistent with the
64-bit behavior. The EOVERFLOW error also has no foundation in POSIX
whereas EINVAL is mentioned as an error for invalid microseconds.

While in there, I also define ITIMER_REAL, ITIMER_VIRTUAL, and
ITIMER_PROF in linux/sys-time-macros.h and update code to use them
instead of raw numbers.

Assisted by Gemini.
2026-07-10 10:46:26 +02:00
Jeff Bailey
21be7ef447
[libc] Implement BSD extensions in <err.h> (#199055)
Implemented the BSD-extension functions defined in <err.h>:

- err, errx, verr, verrx
- warn, warnx, vwarn, vwarnx

Added an internal reporting helper in src/__support/Err. The err family
functions call internal::exit directly to satisfy [[noreturn]]
requirements. Enabled these entrypoints for aarch64, riscv, and x86_64.

Assisted-by: Automated tooling, human reviewed.
2026-07-09 06:09:01 +01:00
Pavel Labath
12c36c7abb
[libc] Implement if_nametoindex and if_indextoname (#206082)
This patch implements if_nametoindex and if_indextoname for Linux.

Both functions work by creating a temporary AF_UNIX socket and issuing
ioctl calls (SIOCGIFINDEX and SIOCGIFNAME, respectively).

The main implementation details:
- for if_nametoindex, I check that the interface name fits within
IF_NAMESIZE before issuing the ioctl
- for if_indextoname, if the kernel returns ENODEV for an unknown index,
I map it to ENXIO to comply with POSIX requirements
- added the definition of struct ifreq to support these operations.
Similar to the other net structure definitions, I'm using an anonymous
union to avoid #defining members.

Assisted by Gemini.
2026-07-07 11:26:10 +00:00
Pavel Labath
4db63ee847
[libc] Add inet_ntop (#204143)
The function converts from IPv4/6 addresses to their string forms. The
complication comes from the v6 part due to address compression and
v4-mapping.

The traditional implementation of this is to sprintf the address into a
temporary buffer. We cannot do that here due to the ban on calling other
entry points. Using the lower-level constructs is possible, but a
straight forward application of IntegerToString does not result in
particularly impressive performance: 50%-100% slower than what's in this
patch (and slower than glibc). It also doesn't make the code much
smaller as the majority of it is dedicated to v6 compression.

The IPv6 implementation uses a temporary buffer, but it also has a
fast-path which skips the buffer if its size is guaranteed to be
sufficient. The IPv4 implementation also has a fast path, but the
fallback here is to compute the precise length of the string instead
(the buffer option was slower and IPv4 makes it easier to compute the
precise length).

The v6 compression code is unrolled to make it easier to optimize. While
it is possible to write a single printing loop that handles all cases,
its branchiness does not make it amenable for optimization.

The resulting function is faster than its glibc counterpart, though the
exact ratio varies depending on the input:
- random IPv4: 15% faster
- random IPv6: 6% faster
- "::": 50% faster
2026-07-07 11:15:35 +00:00
Jeff Bailey
5318bd4123
[libc] Add auxiliary vector and note macros to elf.h (#207914)
Added missing macros to elf.h:

* sys-auxv-macros.h: Added AT_RSEQ_FEATURE_SIZE and AT_RSEQ_ALIGN.
* elf.yaml: Added PT_AARCH64_MEMTAG_MTE, PN_XNUM, ELFCLASSNUM, EV_NUM,
and AT_* macros (via sys-auxv-macros.h). Also added NN_* and NT_* note
macros (including NT_FPREGSET and NT_SIGINFO) to match system headers.
* CMakeLists.txt: Added sys_auxv_macros dependency to elf target.

Assisted-by: Automated tooling, human reviewed.
2026-07-07 10:27:24 +01:00
Pavel Labath
831ad2ee6a
[libc] Add struct ipv6_mreq and IPv6 socket options (#206448)
This patch adds struct ipv6_mreq and defines various IPv6 socket option
macros in <netinet/in.h>. I've also moved the existing option
definitions to the yaml file.

Assisted by Gemini.
2026-07-06 11:27:11 +02:00
Pavel Labath
753ceecfdc
[libc] Implement sockatmark (#205400)
This patch implements sockatmark as a simple wrapper around
ioctl(SIOCATMARK).

I don't test it with actual out of band data, as that requires a TCP
connection, which is more complicated to set up.

Assisted by Gemini.
2026-07-06 08:43:49 +00:00
Pavel Labath
61679c3a29
[libc] Add protocol family constants (#206911)
These aren't in POSIX, but are in 4.2BSD and they're still widely used.
2026-07-06 10:06:59 +02:00
jinge90
774f8a0b86
[libc][complex] Enable cabs and cabsf in libc (#206677)
This PR adds basic implementation for cabs and cabsf in LLVM libc and
also extend current MPC infrastructure to support cabs operation.

---------

Signed-off-by: jinge90 <ge.jin@intel.com>
2026-07-06 10:55:08 +08:00
Jackson Stogel
88a3488c8a
[libc][realpath] Implement symbolic path resolution (#204467)
This PR contains an incremental implementation of `realpath` that just
simplifies path traversals (e.g. `"/a/./../b"` -> `"/b"`). The complete
implementation would perform `getcwd`/`statx`/`readlinkat` to actually
resolve symlinks, validate paths, etc. This PR aims to add as much
functionality/error handling as possible without making any syscalls.

This implementation lives in `libc/src/stdlib/linux/`, since follow-on
PRs will rely on linux-specific syscalls. For testing purposes, I've
added the entrypoint for x86-64 linux when
`LLVM_LIBC_ENABLE_EXPERIMENTAL_ENTRYPOINTS` is enabled.

Follow-on PRs to add: path validation (e.g.
paths must exist), support for cwd-relative paths, and symlink
resolution.
2026-07-01 15:58:08 -07:00
Pavel Labath
58203500b5
[libc] Migrate header .def files to public_includes (#206727)
Now that public_includes is supported in header yaml files, we don't
need custom .h.def templates just to include another header.

This patch removes link.h.def, string.h.def, and ucontext.h.def and
moves their inclusions directly into
their yaml definitions:
- link.yaml: add elf.h
- string.yaml: add strings.h
- sys/ucontext.yaml: add ucontext.h

Assisted by Gemini.
2026-07-01 09:00:54 +02:00
Pavel Labath
201b694dc4
[libc] Implement CPU_{AND,OR,XOR,EQUAL}(_S)? macros (#205412)
This patch implements CPU_AND, CPU_OR, CPU_XOR, and CPU_EQUAL macros
(along with their _S variants) from sched.h.

The implementation follows existing patterns by adding internal entry
points (__sched_andcpuset, __sched_orcpuset, __sched_xorcpuset, and
__sched_cpuequal) that perform bitwise operations on cpu_set_t. For
__sched_cpuequal, I use inline_memcmp instead of a manual loop.

Assisted by Gemini.
2026-06-30 11:00:15 +02:00
Pavel Labath
2bd8d73902
[libc] Add public_includes stanza to hdrgen and use it in socket headers (#205543)
This patch adds support for a public_includes stanza in header YAML
files, allowing generated public headers to include other public
headers.

I use this to make arpa/inet.h include netinet/in.h, and netinet/in.h
include sys/socket.h. While POSIX doesn't strictly require these headers
to include each other, it permits it, and many real-world applications
depend on this behavior.

To make this work, I also needed to reorder the header targets in
include/CMakeLists.txt so that targets sys_socket and netinet_in are
defined before targets declare dependencies on them.

There are a couple of other files that could use this feature (right now
they handle it through the header template), but I'll do that as a
separate patch.

Assisted by Gemini.
2026-06-29 08:13:17 +02:00
hulxv
c1be719788
[libc] introduce shared compiler-rt builtins (#200094)
Introduce shared compiler-rt builtins to libc and addtf3 builtin

Split from #197950

Part of #197824
2026-06-26 19:20:27 +03:00
Jeff Bailey
bef95e5467
[libc][stdlib] Add unsetenv (#202422)
Added the POSIX unsetenv() function and its internal support.

Implemented EnvironmentManager::unset() to remove a variable by name,
free the string if allocated, and compact the array.

Updated EnvironmentManager to synchronize the public global environ
pointer when transitioning to managed storage.

Registered for x86_64, aarch64, and riscv. Integration tests cover basic
operations and edge cases.

Assisted-by: Automated tooling, human reviewed.
2026-06-25 15:07:08 +01:00
jinge90
05daa3d135
[libc][complex] Add cargf and carg functions to libc complex math (#204087)
This PR adds carg and cargf function to libc complex and also add test
cases to cover some special inputs.

---------

Signed-off-by: jinge90 <ge.jin@intel.com>
2026-06-25 10:07:13 +08:00
Pavel Labath
a712923566
[libc] Add IPv4 socket options and related structs (#204787)
This patch adds struct ip_mreq, ip_mreq_source, ip_mreqn, ip_opts, and
ip_msfilter to <netinet/in.h>, along with IP level socket option macros
(IP_TOS, IP_TTL, IP_ADD_MEMBERSHIP, etc.).

I add basic unit tests verifying the size and member offsets of the new
structures against standard layout expectations, mainly to make sure
that the files are used /somewhere/.

Assisted by Gemini.
2026-06-24 11:17:03 +02:00
Jeff Bailey
0914d20f2f
[libc] Add loff_t type (#204641)
Added loff_t type definition. This is a Linux extension required for
large file offsets.

* llvm-libc-types/loff_t.h: Include linux/loff_t.h on Linux.
* llvm-libc-types/linux/loff_t.h: Added Linux definition using
__kernel_loff_t.
* llvm-libc-types/CMakeLists.txt: Include linux subdirectory and add
dependency for loff_t.
* llvm-libc-types/linux/CMakeLists.txt: Registered loff_t.
* sys/types.yaml: Added loff_t to sys/types.
* libc/include/CMakeLists.txt: Added dependency to sys_types target.

Assisted-by: Automated tooling, human reviewed.
2026-06-23 16:46:14 +00:00
Jeff Bailey
dc658f1f11
Reland "[libc] Implement basename and dirname in libgen.h #204554" (#205352)
Added the POSIX standard functions basename and dirname under a new libgen.h header. The implementations modify the input path in-place using cpp::string_view to determine boundaries safely.

Added find_last_not_of to cpp::string_view to support trailing slash removal.

Implemented:

libc/include/libgen.yaml, libgen.h.def: Public API definitions.
libc/src/libgen/basename.cpp, dirname.cpp: Generic implementations.
libc/test/src/libgen/: Unit and hermetic tests.
Registered the new entrypoints for all active Linux targets (x86_64, aarch64, arm, riscv) and added docgen configuration.

The tests are skipped when using ASan because death tests do not currently work with them.

Assisted-by: Automated tooling, human reviewed.
2026-06-23 15:59:59 +01:00
Pavel Labath
86d380e54f
[libc] Add CPU_CLR(_S) macros (#204590)
This patch implements CPU_CLR and CPU_CLR_S macros following the
existing CPU_SET pattern. The macro just forwards to an internal entry
point.

Assisted by Gemini.
2026-06-23 15:41:55 +02:00
Jeff Bailey
ae60782c82
Revert "[libc] Implement basename and dirname in libgen.h (#204554)" (#204856)
Reverted due to death tests failing with ASan on buildbots. Reverts
commit 29692c150f.
2026-06-19 17:39:37 +01:00
Jeff Bailey
29692c150f
[libc] Implement basename and dirname in libgen.h (#204554)
Added the POSIX standard functions basename and dirname under a new
libgen.h header. The implementations modify the input path in-place
using cpp::string_view to determine boundaries safely.

Added find_last_not_of to cpp::string_view to support trailing slash
removal.

Implemented:
* libc/include/libgen.yaml, libgen.h.def: Public API definitions.
* libc/src/libgen/basename.cpp, dirname.cpp: Generic implementations.
* libc/test/src/libgen/: Unit and hermetic tests.

Registered the new entrypoints for all active Linux targets (x86_64,
aarch64, arm, riscv) and added docgen configuration.

Assisted-by: Automated tooling, human reviewed.
2026-06-19 15:44:27 +00:00