Skip to content

refactor: change file off bindings in linux uclibc#5165

Draft
dybucc wants to merge 1 commit into
rust-lang:mainfrom
dybucc:uclibc-file-offset-transition
Draft

refactor: change file off bindings in linux uclibc#5165
dybucc wants to merge 1 commit into
rust-lang:mainfrom
dybucc:uclibc-file-offset-transition

Conversation

@dybucc

@dybucc dybucc commented Jun 13, 2026

Copy link
Copy Markdown
Contributor

Description

This PR transitions the default types in uClibc from their 32-bit (non-LFS) variants to their 64-bit variants. Currently, the default build config when running the make scripts in upstream uclibc-ng will add support for LFS. This is configurable, but the libc crate has no configuration option for it. Thus, this patch decides to expose the default behavior.

The changes include a few modifications of the definitions for types involved in LFS64, such as ino_t and whole records like dirent. A few routines are also affected.

Because the libc crate is actively attempting to provide a single unsuffixed variant that is solely 64-bits wide, multiple types that mirrored other types such as 64-bit off_t, were deprecated. This patch does not target a stable release, as public fields of exposed records were altogether removed and sometimes reordered.

This also means that the unsuffixed "variants", such as off_t, now use their off64_t upstream definition by default. As a general rule, whenever a header file upstream checks for __USE_LARGEFILE64 or __USE_FILE_OFFSET64, this patch defines the unsuffixed type in terms of the suffixed type.

The only exceptions to this were records that are specifically not aliased in terms of their 64-bit "variants," but are rather both exposed in upstream uclibc-ng. Examples of this include stat and statfs.

There's one record I'm particularily doubtful of. In libc we choose to expose ever so slightly different definition for the statvfs structure depending on the target's endianness. This only affects whether a field appears before or after some padding, the latter of which depends on the target's word size. Other modules under the uclibc module do not seem to use this endian-dependent field ordering, so that has been removed as there's neither any indication in the upstream definition of there being need for that. Still, this is very much a change prone to reversion, if I'm, indeed, missing something. Input here is very much welcome.

There were also some changes related to records that were straight up conflicting between builds for each of the supported target triples under linux/uclibc. Among these, dirent had to be altogether removed from the uClibc interface because there were collisions while resolving items across the top-level linux and linux_l4re_shared modules. Though the types of its fields still refer to the corresponding types in the uclibc child module.

Finally, it must be noted that there were quite a few architecture-specific definitions in upstream uclibc-ng that were not included in the exposed bindings. More specifically, no ISAs beyond those already present under the uclibc module have been added. This means the libc crate currently exposes the correct definitions for the header files common to all architectures, and those specific to MIPS32, MIPS64, x86_64 and 32-bit arm. Other architectures such as OpenRISC, Alpha, SPARC or i686 have not been included in this patch, even though they have specialized upstream types/routines. The policy here for the libc crate is unknown. Should support be provided solely for targets for which there's some tiered support level in upstream rustc, or should the provided bindings be as wide-ranging as possible? It must be noted that we support the x86_64 module in linux/uclibc even though there is only one tiered Rust target that uses uClibc on x86_64. That one uses L4Re and not Linux.

Tests are pending on MIPS targets. This is a WIP.

Sources

Checklist

  • Relevant tests in libc-test/semver have been updated
  • No placeholder or unstable values like *LAST or *MAX are included (see #3131)
  • Tested locally (cd libc-test && cargo test --target mytarget); especially relevant for platforms that may not be checked in CI

@dybucc dybucc marked this pull request as draft June 13, 2026 09:12
The currently exposed bindings to file offset types and routines are
often found to be either lacking or incorrect in the current worktree.
This has been fixed by means of changing multiple type definitions
across child modules of the uClibc module under Linux, such that a more
cohesive interface is exposed.

Among those changes, the patch also switches the default definition of
types with LFS64 "variants," such that they use that definition by
default. This affects types such as `off_t` and `ino_t`, for which
support varied between platforms to either the regular definition
upstream or the LFS64 definition.

Beyond that, a few LFS64-specific routines have been deprecated in favor
of their unsuffixed variants. Much in the same vein as the prior
changes, this follows the trend towards supporting a single unsuffixed
type whose bitwidth is 64-bits. It has been assumed that this extends as
well to routines making use of such types.

Lastly, it must be noted that all changes submitted in this patch match
the definition of upstream uclibc-ng, but not necessarily of the
original uClibc (now unmaintained.) This was done by performing a regex
search through all header files under `**/{platform}/bits/*.h`, where
`{platform}` is replaced by one of: `common`, `common-generic`, `arm`,
`x86_64` or `mips`. The search term in question included any uses of the
`__USE_FILE_OFFSET64` or `__USE_LARGEFILE64` feature test macros. The
latter gates functionality that exposes 64-bit types, while the former
ensures the unsuffixed variants are defined in terms of the suffixed
types/routines. By default, upstream builds of uclibc-ng will have LFS
support added by default lest otherwise configured. This is shown in the
make configuration script generated by running make defconfig in the
root worktree.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants