[libc-commits] [libc] [libc] Define more headers and entrypoints on aarch64 Linux. (PR #241542)
Alexey Samsonov via libc-commits
libc-commits at lists.llvm.org
Wed Nov 11 13:52:44 PST 2026
vonosmas wrote:
Copying the LLM analysis on the feasibility of this change (human-verified) - it's helpful for Ctrl-F searching details about each particular function to confirm why it's OK to roll it out on arm64, or to look up particular concerns / arm64-specific considerations:
## 1. Public Headers Added ([headers.txt](file:///usr/local/google/home/samsonov/llvm-project/libc/config/linux/aarch64/headers.txt))
| Header Target | Public Header | Safety Rationale on Linux AArch64 |
| :--- | :--- | :--- |
| `libc.include.nl_types` | `<nl_types.h>` | Defines `nl_item` (`int`) and `nl_catd` (`void *`) plus `NL_SETD` / `NL_CAT_LOCALE` constants ([nl_types.yaml](file:///usr/local/google/home/samsonov/llvm-project/libc/include/nl_types.yaml)); completely architecture-independent. |
| `libc.include.sys_ipc` | `<sys/ipc.h>` | Exposes `struct ipc_perm` ([struct_ipc_perm.h](file:///usr/local/google/home/samsonov/llvm-project/libc/include/llvm-libc-types/struct_ipc_perm.h#L18-L29)), which was already used on AArch64 by `<sys/shm.h>` and matches Linux `asm-generic/ipcbuf.h` (`ipc64_perm`) and glibc on 64-bit `aarch64`. |
| `libc.include.sys_sem` | `<sys/sem.h>` | Exposes `struct sembuf`, `struct seminfo` ([struct_seminfo.h](file:///usr/local/google/home/samsonov/llvm-project/libc/include/llvm-libc-types/struct_seminfo.h#L13-L24)), and `struct semid_ds` ([struct_semid_ds.h](file:///usr/local/google/home/samsonov/llvm-project/libc/include/llvm-libc-types/struct_semid_ds.h#L16-L32)), which already omits `x86_64`-only padding fields (`#if defined(__x86_64__)`) to match `asm-generic/sembuf.h` on `aarch64` and `riscv64`. |
---
## 2. Unconditional `TARGET_LIBC_ENTRYPOINTS` (Overlay + Fullbuild)
### 2.1 Syscall & OS Wrappers (5 entrypoints)
| Header | Entrypoints | Implementation & AArch64 Safety Rationale |
| :--- | :--- | :--- |
| `sched.h` | `getcpu` | Calls `SYS_getcpu` (`168` in `asm-generic/unistd.h`) via [getcpu.cpp](file:///usr/local/google/home/samsonov/llvm-project/libc/src/sched/linux/getcpu.cpp). Uses the same kernel interface as `sched_getcpu`, which was already enabled on AArch64. |
| `sys/ipc.h` | `ftok` | Implemented in [ftok.cpp](file:///usr/local/google/home/samsonov/llvm-project/libc/src/sys/ipc/linux/ftok.cpp#L18-L37) via `SYS_statx` (`291` in `asm-generic/unistd.h`, already used by `stat` on AArch64) followed by standard POSIX bit-packing of `stx_ino`, `stx_dev_minor`, and `proj_id` into 32-bit `key_t`. |
| `sys/sem.h` | `semget`, `semctl`, `semop` | Wraps `SYS_semget` (`190`), `SYS_semctl` (`191`), and `SYS_semop` (`192`), all present in `asm-generic/unistd.h`. In [semctl.cpp](file:///usr/local/google/home/samsonov/llvm-project/libc/src/sys/sem/linux/semctl.cpp), variadic `union semun` extraction (`va_arg`) works identically under AAPCS64, and `IPC_64` (`0x0` on modern 64-bit generic UAPI / `0x100` ignored by 64-bit kernel `parse_ipccall_version`) plus `struct semid_ds` layout ([struct_semid_ds.h](file:///usr/local/google/home/samsonov/llvm-project/libc/include/llvm-libc-types/struct_semid_ds.h#L16-L32)) match both Linux `arm64` kernel `semid64_ds` and `aarch64-linux-gnu` glibc. |
| `sys/time.h` | `utimes` | Linux `arm64` does **not** have legacy `SYS_utimes`, and [utimes.cpp](file:///usr/local/google/home/samsonov/llvm-project/libc/src/sys/time/linux/utimes.cpp#L20-L62) does not use it: it converts `struct timeval[2]` to `struct timespec[2]` and invokes `SYS_utimensat` (`280` in `asm-generic/unistd.h`) with `AT_FDCWD`. Both `struct timeval` and `struct timespec` have identical `{int64_t, int64_t}` layouts in glibc and `llvm-libc` on LP64 AArch64. |
### 2.2 Wide-Character & Multibyte String/Conversion Functions (37 entrypoints)
| Header | Entrypoints | Implementation & AArch64 Safety Rationale |
| :--- | :--- | :--- |
| `wchar.h` | `btowc` | Pure single-byte ASCII-to-`wint_t` helper (`wctob` was already enabled on AArch64). Returns `WEOF` (`0xFFFFFFFFu`) when out of `[0, 0x7F]`, matching `wint_t` on AArch64. |
| `wchar.h` | `wcsnlen`, `wcscpy`, `wcsncpy`, `wcslcpy`, `wcpcpy`, `wcpncpy`, `wcscat`, `wcsncat`, `wcslcat`, `wcschr`, `wcsrchr`, `wcsstr`, `wcspbrk`, `wcsspn`, `wcscspn`, `wcstok`, `wcsdup`, `wcsxfrm`, `wmemcpy`, `wmempcpy`, `wmemmove`, `wmemset`, `wmemchr` | Pure C++ element-wise operations over `wchar_t` buffers (`wcsdup` uses `malloc` + `wmemcpy`, same allocator pattern as `strdup`). Independent of `wchar_t` signedness and architecture. |
| `wchar.h` | `wcscmp`, `wcsncmp`, `wcscoll`, `wmemcmp` | Pure C++ element comparisons ([wcscmp.cpp](file:///usr/local/google/home/samsonov/llvm-project/libc/src/wchar/wcscmp.cpp#L18-L26), [wmemcmp.cpp](file:///usr/local/google/home/samsonov/llvm-project/libc/src/wchar/wmemcmp.cpp#L19-L29)). Safe for all valid Unicode scalar values (`0 .. 0x10FFFF`); see the unsigned `wchar_t` note below regarding synthetic values `>= 0x80000000U`. |
| `wchar.h`, `inttypes.h` | `wcstol`, `wcstoll`, `wcstoul`, `wcstoull`, `wcstof`, `wcstod`, `wcstold`, `wcstoimax`, `wcstoumax` | Pure C++ numeric parsers in `src/__support/wcs_to_integer.h` and `src/__support/wcs_to_float.h`. Character classification checks explicit bounds (`>= L'0' && <= L'9'`, etc.) safely with unsigned `wchar_t`, and `wcstold` targets IEEE `binary128` `long double` via the same Eisel-Lemire / fast-path conversion infrastructure already used by `strtold` on AArch64. |
> [!NOTE]
> **Unsigned `wchar_t` edge case in `wcscmp` / `wcsncmp` / `wcscoll` / `wmemcmp`**: Because `wchar_t` is `uint32_t` under AAPCS64, expressions like `return (int)(s1[i] - s2[i]);` ([wmemcmp.cpp](file:///usr/local/google/home/samsonov/llvm-project/libc/src/wchar/wmemcmp.cpp#L25)) perform `uint32_t` wrap-around before converting to `int`. For all valid Unicode code points (`0 .. 0x10FFFF`), the difference lies in `[-0x10FFFF, +0x10FFFF]` and preserves the exact sign. Only synthetic non-Unicode `wchar_t` values with bit 31 set (e.g., comparing `0U` against `0x80000000U`) wrap to a positive `int`. Existing unit tests pass; if desired in a follow-up patch, changing those four returns to `(a > b) - (a < b)` makes them overflow-free across the entire `uint32_t` range.
### 2.3 `<stdlib.h>` & `<dlfcn.h>` Additions (4 entrypoints)
| Header | Entrypoints | Implementation & AArch64 Safety Rationale |
| :--- | :--- | :--- |
| `stdlib.h` | `a64l`, `l64a` | Pure C++ POSIX radix-64 converters ([a64l.cpp](file:///usr/local/google/home/samsonov/llvm-project/libc/src/stdlib/a64l.cpp#L43-L62), [l64a.cpp](file:///usr/local/google/home/samsonov/llvm-project/libc/src/stdlib/l64a.cpp#L46-L59)). Both explicitly operate on 32-bit `int32_t`/`uint32_t` intermediates and sign-extend to 64-bit `long` on LP64, as mandated by POSIX. `l64a` uses `LIBC_THREAD_LOCAL`, which is already supported and tested across AArch64 `libc`. |
| `stdlib.h` | `strfroml` | Previously commented out with a `clang-11` crash workaround (`# TODO: long double support is buggy with clang-11`). `llvm-libc` now requires a much newer Clang, and `strfromf128` (identical binary128 representation on AArch64) was already enabled. Cross-compiled and verified clean. |
| `dlfcn.h` | `dladdr` | Arch-independent stub returning `0` ([dladdr.cpp](file:///usr/local/google/home/samsonov/llvm-project/libc/src/dlfcn/dladdr.cpp#L22-L26)), using proxy header [dl_info.h](file:///usr/local/google/home/samsonov/llvm-project/libc/hdr/types/dl_info.h) for overlay/fullbuild compatibility. Matches `dlopen`, `dlsym`, `dlclose`, and `dlerror`, which are likewise stubs and were already enabled in `aarch64/entrypoints.txt`. |
### 2.4 Promoted from `LLVM_LIBC_FULL_BUILD` to Unconditional `TARGET_LIBC_ENTRYPOINTS` (17 entrypoints)
On `x86_64` and `riscv`, these 17 networking entrypoints are unconditionally in `TARGET_LIBC_ENTRYPOINTS`, whereas on `aarch64` they were previously left inside `if(LLVM_LIBC_FULL_BUILD)`:
- **`arpa/inet.h` (9)**: `htonl`, `htons`, `ntohl`, `ntohs`, `inet_addr`, `inet_aton`, `inet_ntoa`, `inet_ntop`, `inet_pton` — pure C++ byte-order / IP string parsing using compiler byte-swap builtins and `hdr/*` proxy headers; zero fullbuild-only dependencies and ABI-identical to glibc in overlay mode.
- **`netinet/ether.h` (4)**: `ether_aton`, `ether_aton_r`, `ether_ntoa`, `ether_ntoa_r` — pure C++ 6-byte MAC address formatting/parsing using `struct ether_addr` (`uint8_t[6]`).
- **`netinet/in.h` (2)**: `in6addr_any`, `in6addr_loopback` — constant 16-byte `struct in6_addr` globals (`::` and `::1`), layout-identical to glibc ([in6addr_any.cpp](file:///usr/local/google/home/samsonov/llvm-project/libc/src/netinet/in6addr_any.cpp)).
- **`net/if.h` (2)**: `if_indextoname`, `if_nametoindex` — implemented in [if_indextoname.cpp](file:///usr/local/google/home/samsonov/llvm-project/libc/src/net/if/linux/if_indextoname.cpp#L32-L69) via `socket(AF_UNIX, SOCK_DGRAM)` + `ioctl(SIOCGIFNAME / SIOCGIFINDEX)` on `struct ifreq` using `hdr/types/struct_ifreq.h` (which includes `<net/if.h>` in overlay mode). `SIOCGIFNAME` (`0x8910`) and `SIOCGIFINDEX` (`0x8933`) are architecture-independent Linux socket ioctl constants.
---
## 3. Math & Fixed-Point Entrypoints (`TARGET_LIBM_ENTRYPOINTS`)
| Guard / Section | Entrypoints | Implementation & AArch64 Safety Rationale |
| :--- | :--- | :--- |
| Unconditional `TARGET_LIBM_ENTRYPOINTS` (promoted from `LIBC_TYPES_HAS_FLOAT16`) | `fdiv`, `fdivl`, `ffma`, `ffmal` (4) | C23 narrowing `double`/`long double` -> `float` functions. They do not use `_Float16` at all and were misplaced inside `if(LIBC_TYPES_HAS_FLOAT16)` on AArch64; moved to unconditional `TARGET_LIBM_ENTRYPOINTS` to match `x86_64` and `riscv`. |
| `if(LIBC_TYPES_HAS_FLOAT16)` | 23 missing (`acosf16`, `acospif16`, `asinf16`, `asinhf16`, `atanf16`, `atanhf16`, `atanpif16`, `cosf16`, `coshf16`, `exp10f16`, `exp10m1f16`, `exp2f16`, `exp2m1f16`, `expm1f16`, `hypotf16`, `log10f16`, `log2f16`, `logf16`, `sinf16`, `sinhf16`, `tanf16`, `tanhf16`, `tanpif16`) + 9 uncommented (`f16addl`, `f16divl`, `f16fmal`, `f16mull`, `f16sqrtl`, `f16subl`, `fmodf16`, `modff16`, `nexttowardf16`) | Pure `FPUtil` C++ implementations evaluating in `float`/`double` or `DyadicFloat`. The commented-out `f16*l` and `nexttowardf16` entrypoints were only disabled for an ancient `clang-11` `_Float16 <-> long double` crash. `fputil::cast` performs `_Float16 <-> binary128` conversions in software bit-manipulation, emitting **zero** calls to `__extendhftf2` / `__trunctfhf2` (verified via `llvm-nm -u` across all compiled object files). |
| `if(LIBC_TYPES_HAS_FLOAT16)` + `if(LIBC_TYPES_HAS_NATIVE_FLOAT128)` | `f16addf128`, `f16divf128`, `f16fmaf128`, `f16mulf128`, `f16sqrtf128`, `f16subf128` (6 uncommented) | Same software `FPUtil` narrowing arithmetic over native 128-bit `float128` (`long double` on AArch64); verified zero external soft-fp helper dependencies beyond standard `compiler-rt` / `libgcc` quad routines already used by `daddf128`, etc. |
| `if(LIBC_TYPES_HAS_NATIVE_FLOAT128)` | `atan2l` (1) | [atan2l.cpp](file:///usr/local/google/home/samsonov/llvm-project/libc/src/math/generic/atan2l.cpp#L18-L26) delegates directly to `math::atan2f128`, which was already enabled right below it (`libc.src.math.atan2f128`) on AArch64. |
| `if(LIBC_COMPILER_HAS_FIXED_POINT)` | 97 `libc.src.stdfix.*` entrypoints (`sqrtulk` kept commented out matching `x86_64`/`riscv`) | Pure compiler fixed-point (`-ffixed-point`) and integer bit-manipulation arithmetic in `libc/src/stdfix/`. Already enabled on `baremetal/aarch64` and `darwin/aarch64`; verified all 97 entrypoints and unit tests compile cleanly for `aarch64-unknown-linux-gnu`. |
---
## 4. Fullbuild-Only `TARGET_LIBC_ENTRYPOINTS` (`if(LLVM_LIBC_FULL_BUILD)`)
Because all 52 entrypoints below are gated under `if(LLVM_LIBC_FULL_BUILD)`, they are **never** linked into overlay `libllvmlibc.a` and therefore cannot collide with glibc's opaque internal types (`locale_t`, `pthread_barrier_t`, `mbstate_t`, `nl_catd`).
| Header | Entrypoints | Implementation & AArch64 Safety Rationale |
| :--- | :--- | :--- |
| `locale.h` | `newlocale`, `freelocale`, `duplocale`, `setlocale`, `uselocale`, `localeconv` (6) | C-locale implementation in `libc/src/locale/` returning static `"C"` locale handles and standard `struct lconv`. 100% architecture-independent C++. |
| `ctype.h` | `isalnum_l`, `isalpha_l`, `isblank_l`, `iscntrl_l`, `isdigit_l`, `isgraph_l`, `islower_l`, `isprint_l`, `ispunct_l`, `isspace_l`, `isupper_l`, `isxdigit_l`, `tolower_l`, `toupper_l` (14) | Thin wrappers over ASCII `ctype_utils.h` (matching `strings.h`'s `strcasecmp_l` / `strncasecmp_l`, which were already enabled on AArch64). |
| `stdlib.h`, `string.h` | `strtod_l`, `strtof_l`, `strtold_l`, `strtol_l`, `strtoll_l`, `strtoul_l`, `strtoull_l`, `strcoll_l`, `strxfrm_l` (9) | Delegate to the already-enabled non-`_l` conversion/comparison cores (`strtold_l` uses AArch64 binary128 `strtold`). |
| `wchar.h`, `stdlib.h` | `mbrlen`, `mbsinit`, `mbrtowc`, `mbsrtowcs`, `mbsnrtowcs`, `wcrtomb`, `wcsrtombs`, `wcsnrtombs`, `mblen`, `mbtowc`, `wctomb`, `mbstowcs`, `wcstombs` (13) | Stateful/stateless UTF-8 <-> UTF-32 `CharacterConverter` in `libc/src/__support/wchar/`. Uses `char32_t` internally and converts cleanly to 32-bit `wchar_t` on AArch64; gated on `LLVM_LIBC_FULL_BUILD` because `mbstate_t` layout is `llvm-libc`-specific. |
| `time.h` | `localtime`, `localtime_r`, `strftime`, `strftime_l` (4) | `localtime` / `localtime_r` ([localtime_r.cpp](file:///usr/local/google/home/samsonov/llvm-project/libc/src/time/localtime_r.cpp#L18-L29)) share `time_utils.h` with already-enabled `gmtime` / `gmtime_r` / `mktime`. `strftime` / `strftime_l` use portable `strftime_core` formatting with zero arch-specific logic. |
| `nl_types.h` | `catopen`, `catgets`, `catclose` (3) | Minimal POSIX message catalog implementation (`catopen` fails with `ENOENT`/`EINVAL`, `catgets` returns the fallback message string, `catclose` returns `0`). 100% portable C++. |
| `pthread.h` | `pthread_barrier_init`, `pthread_barrier_wait`, `pthread_barrier_destroy` (3) | Implemented via generic C++ `Barrier` built on `Mutex` + `CndVar` (Linux `futex`, already enabled for `pthread_mutex_*` and `pthread_cond_*` on AArch64). [pthread_barrier_init.cpp](file:///usr/local/google/home/samsonov/llvm-project/libc/src/pthread/pthread_barrier_init.cpp) enforces compile-time `static_assert`s verifying `sizeof(Barrier) <= sizeof(pthread_barrier_t)` and `alignof(Barrier) <= alignof(pthread_barrier_t)` against [__barrier_type.h](file:///usr/local/google/home/samsonov/llvm-project/libc/include/llvm-libc-types/__barrier_type.h#L14-L21) (`80` bytes, 8-byte aligned on LP64 AArch64). |
https://github.com/llvm/llvm-project/pull/241542
More information about the libc-commits
mailing list