Skip to content

linux(uclibc): add cfg for LFS bindings - #5315

Open
dybucc wants to merge 3 commits into
rust-lang:mainfrom
dybucc:uclibc-lfs-support
Open

linux(uclibc): add cfg for LFS bindings#5315
dybucc wants to merge 3 commits into
rust-lang:mainfrom
dybucc:uclibc-lfs-support

Conversation

@dybucc

@dybucc dybucc commented Jul 22, 2026

Copy link
Copy Markdown
Contributor

Description

This PR adds a new cfg for file offset types in uClibc to ensure target
triples with a 32-bit machine word size can also have 64-bit unsuffixed file
offset types. None of these changes affect 64-bit platforms.

The LFS types continue being exposed by default in all platforms, but when the
cfg option is issued, they will have equivalent definitions to the unsuffixed
types.

Would like to ask @operutka, @lancethepants, @skrap and @japaric whether you
think it's worth it to add this cfg, you folks being or having been
maintainers for targets using uClibc. It was originally part of #5165, but got
split because our need to customize rust-lang/libc to fit upstream build options
wasn't entirely clear.

Sources

Checklist

  • Relevant tests in libc-test/semver have been updated
  • Commit messages permalink to headers for added or changed API
  • Placeholder or unstable values like *LAST or *MAX have the standard
    doc comment
  • Tested locally (cargo test -p libc-test --target mytarget); especially
    relevant for platforms that may not be checked in CI

@rustbot label +stable-nominated

@rustbot

This comment has been minimized.

@tgross35

tgross35 commented Aug 2, 2026

Copy link
Copy Markdown
Member

Seems reasonable to me from a quick skim, but we need the maintainers to weigh whether this is needed.

@rustbot label +S-waiting-on-maintainer

@rustbot

This comment has been minimized.

@tgross35

Copy link
Copy Markdown
Member

@skrap any thoughts here? Pretty much up to you for whether or not this is worth it.

Comment thread libc-test/build.rs Outdated

if uclibc
&& pointer_width == 32
&& env::var("CARGO_CFG_LIBC_UNSTABLE_UCLIBC_FILE_OFFSET_BITS").is_ok()

@tgross35 tgross35 Aug 31, 2026

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One note without looking at the rest is this should check the value, CARGO_CFG_LIBC_UNSTABLE_UCLIBC_FILE_OFFSET_BITS=1 shouldn't work. But a binary flag like libc_unstable_uclib_off64 is likely better, I kind of regret accepting multiple values for the glibc flag.

View changes since the review

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

@dybucc
dybucc force-pushed the uclibc-lfs-support branch from 729cebc to cb19b6e Compare August 31, 2026 10:10
@rustbot

rustbot commented Aug 31, 2026

Copy link
Copy Markdown
Collaborator

This PR was rebased onto a different main commit. Here's a range-diff highlighting what actually changed.

Rebasing is a normal part of keeping PRs up to date, so no action is needed—this note is just to help reviewers.

dybucc added 3 commits August 31, 2026 12:12
Add a `cfg` to enable LFS bindings under 32-bit targets. This does not
apply to 64-bit targets. Their suffixed types are equivalent to their
unsuffixed types. They unconditionally get both suffixed and unsuffixed
types.

This `cfg` replicates a build option upstream.

Sources follow.

- Upstream uclibc-ng sources showing `ino_t` defined in terms of its
  64-bit variant, and the definition for the 64-bit variant. There's a
  "chain" of types that leads to the final type with which `ino64_t` is
  defined. This chain is made most obvious by the final type alias,
  which appends a `_TYPE` and prepends two underscores to the type
  identifier in question. Notice how the `__uquad_t` type is always
  defined as a 64-bit type, even on systems where that requires using a
  record type with a two-element array (32-bit per element).

  <https://github.com/wbx-github/uclibc-ng/blob/50c470ef4e688e6eea6fd1eff13083e4fd7b7c95/libc/sysdeps/linux/common/bits/typesizes.h#L33>
  <https://github.com/wbx-github/uclibc-ng/blob/50c470ef4e688e6eea6fd1eff13083e4fd7b7c95/libc/sysdeps/linux/common/bits/types.h#L55-L70>

- Upstream uclibc-ng sources showing `off_t` defined in terms of its
  64-bit variant when LFS64 support and `__USE_FILE_OFFSET64` are
  enabled. Much like the above, there's a "chain" of types leading to
  the type whose bitwidth is made clear. The chain is shortened to the
  last few types.

  <https://github.com/wbx-github/uclibc-ng/blob/50c470ef4e688e6eea6fd1eff13083e4fd7b7c95/libc/sysdeps/linux/common/bits/typesizes.h#L37>
  <https://github.com/wbx-github/uclibc-ng/blob/50c470ef4e688e6eea6fd1eff13083e4fd7b7c95/libc/sysdeps/linux/common/bits/types.h#L109-L121>
  <https://github.com/wbx-github/uclibc-ng/blob/50c470ef4e688e6eea6fd1eff13083e4fd7b7c95/libc/sysdeps/linux/common/bits/types.h#L55-L70>

- Upstream uclibc-ng sources showing `rlim_t` defined in terms of its
  64-bit variant when LFS64 support and `__USE_FILE_OFFSET64` are
  enabled. This follows the same reasoning as the above.

  <https://github.com/wbx-github/uclibc-ng/blob/50c470ef4e688e6eea6fd1eff13083e4fd7b7c95/libc/sysdeps/linux/common/bits/resource.h#L131-L138>
  <https://github.com/wbx-github/uclibc-ng/blob/50c470ef4e688e6eea6fd1eff13083e4fd7b7c95/libc/sysdeps/linux/common/bits/types.h#L149-L150>
  <https://github.com/wbx-github/uclibc-ng/blob/50c470ef4e688e6eea6fd1eff13083e4fd7b7c95/libc/sysdeps/linux/common/bits/typesizes.h#L39-L40>
  <https://github.com/wbx-github/uclibc-ng/blob/50c470ef4e688e6eea6fd1eff13083e4fd7b7c95/libc/sysdeps/linux/common/bits/types.h#L107>
  <https://github.com/wbx-github/uclibc-ng/blob/50c470ef4e688e6eea6fd1eff13083e4fd7b7c95/libc/sysdeps/linux/common/bits/types.h#L110-L122>
  <https://github.com/wbx-github/uclibc-ng/blob/50c470ef4e688e6eea6fd1eff13083e4fd7b7c95/libc/sysdeps/linux/common/bits/types.h#L55-L70>

- Upstream uclibc-ng sources showing `blkcnt_t` defined in terms of its
  64-bit variant. This follows the same reasoning as the above.

  <https://github.com/wbx-github/uclibc-ng/blob/50c470ef4e688e6eea6fd1eff13083e4fd7b7c95/include/sys/stat.h#L89-L96>
  <https://github.com/wbx-github/uclibc-ng/blob/50c470ef4e688e6eea6fd1eff13083e4fd7b7c95/libc/sysdeps/linux/common/bits/types.h#L172-L173>
  <https://github.com/wbx-github/uclibc-ng/blob/50c470ef4e688e6eea6fd1eff13083e4fd7b7c95/libc/sysdeps/linux/common/bits/typesizes.h#L41-L42>
  <https://github.com/wbx-github/uclibc-ng/blob/50c470ef4e688e6eea6fd1eff13083e4fd7b7c95/libc/sysdeps/linux/common/bits/types.h#L109-L121>
  <https://github.com/wbx-github/uclibc-ng/blob/50c470ef4e688e6eea6fd1eff13083e4fd7b7c95/libc/sysdeps/linux/common/bits/types.h#L55-L70>

- Upstream uclibc-ng sources showing `fsblckcnt_t` and `fsfilcnt_t`
  defined in terms of their 64-bit variants. This first of the below
  sources also includes references to the above types.

  <https://github.com/wbx-github/uclibc-ng/blob/50c470ef4e688e6eea6fd1eff13083e4fd7b7c95/include/sys/types.h#L233-L265>
  <https://github.com/wbx-github/uclibc-ng/blob/50c470ef4e688e6eea6fd1eff13083e4fd7b7c95/libc/sysdeps/linux/common/bits/typesizes.h#L43-L44>
  <https://github.com/wbx-github/uclibc-ng/blob/50c470ef4e688e6eea6fd1eff13083e4fd7b7c95/libc/sysdeps/linux/common/bits/typesizes.h#L45-L46>
  <https://github.com/wbx-github/uclibc-ng/blob/50c470ef4e688e6eea6fd1eff13083e4fd7b7c95/libc/sysdeps/linux/common/bits/types.h#L110-L122>
  <https://github.com/wbx-github/uclibc-ng/blob/50c470ef4e688e6eea6fd1eff13083e4fd7b7c95/libc/sysdeps/linux/common/bits/types.h#L55-L70>
Fixe the definitions of:

- `stat`.
- `statfs`.
- `statvfs`.

The analogous 64-bit types were also tweaked. They are equivalent on
some target architectures. They only needed to be aliased.

Sources follow.

- Upstream uclibc-ng sources showing how `statvfs` and `statvfs64` are
  independent, but like the above, have equivalent definitions when
  `__USE_FILE_OFFSET64` is defined. This also shows how there does not
  seem to be a need for the fields to be reordered depending on the
  system's endianness.

  <https://github.com/wbx-github/uclibc-ng/blob/50c470ef4e688e6eea6fd1eff13083e4fd7b7c95/libc/sysdeps/linux/common/bits/statvfs.h#L28-L75>

- Upstream uclibc-ng sources showing how `statfs` and `statfs64` are
  independent, but like the above, have equivalent definitions when
  `__USE_FILE_OFFSET64` is defined. A bunch of field types were changed
  to both accurately reflect the upstream types used, and to add missing
  fields. The former has not been documented in full in the below
  sources because the types involved are already part of the sources
  cited in other list items. Some required special-casing in MIPS
  platforms has been necessary, as there were fields that had altogether
  different types. These were only ever so slightly tweaked for the same
  reasons as above. `statfs` in MIPS got unified as the definitions for
  both the o32 and N64/N32 ABIs are equivalent under
  `__USE_FILE_OFFSET64`.

  <https://github.com/wbx-github/uclibc-ng/blob/50c470ef4e688e6eea6fd1eff13083e4fd7b7c95/libc/sysdeps/linux/common/bits/statfs.h#L24-L64>
  <https://github.com/wbx-github/uclibc-ng/blob/50c470ef4e688e6eea6fd1eff13083e4fd7b7c95/libc/sysdeps/linux/mips/bits/statfs.h#L24-L70>

- Upstream uclibc-ng sources showing the same as the above but for
  `stat` and `stat64`. There was also some special casing required in
  MIPS platforms, though the definitions for both x86_64 and arm
  converged. These have been kept in their corresponding modules because
  there's need for MIPS to have their own and it was decided against a
  top-level, field-specific `cfg`.

  <https://github.com/wbx-github/uclibc-ng/blob/50c470ef4e688e6eea6fd1eff13083e4fd7b7c95/libc/sysdeps/linux/common/bits/stat.h#L35-L130>
  <https://github.com/wbx-github/uclibc-ng/blob/50c470ef4e688e6eea6fd1eff13083e4fd7b7c95/libc/sysdeps/linux/mips/bits/stat.h#L38-L214>
Replace existing definitions. They were not correct under MIPS. This
target needed some special casing.

Sources follow.

- Upstream uclibc-ng sources showing how `flock` and `flock64` are
  independent, but when defined with `__USE_FILE_OFFSET64`, will end up
  having the same record layout. The second source shows how this
  definition can actually be unified across all child modules to the
  `uclibc` module because the fields that are conditionally compiled
  under MIPS will never be any different if `__USE_FILE_OFFSET64` is
  defined.

  <https://github.com/wbx-github/uclibc-ng/blob/50c470ef4e688e6eea6fd1eff13083e4fd7b7c95/libc/sysdeps/linux/x86_64/bits/fcntl.h#L166-L189>
  <https://github.com/wbx-github/uclibc-ng/blob/50c470ef4e688e6eea6fd1eff13083e4fd7b7c95/libc/sysdeps/linux/mips/bits/fcntl.h#L164-L198>
  <https://github.com/wbx-github/uclibc-ng/blob/50c470ef4e688e6eea6fd1eff13083e4fd7b7c95/libc/sysdeps/linux/arm/bits/fcntl.h#L152-L175>
@dybucc
dybucc force-pushed the uclibc-lfs-support branch from cb19b6e to e1f4a8c Compare August 31, 2026 10:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants