Skip to content

refactor: fix definition of LFS64-related types in emscripten#5142

Open
dybucc wants to merge 1 commit into
rust-lang:mainfrom
dybucc:emscripten-largefile64-patch
Open

refactor: fix definition of LFS64-related types in emscripten#5142
dybucc wants to merge 1 commit into
rust-lang:mainfrom
dybucc:emscripten-largefile64-patch

Conversation

@dybucc
Copy link
Copy Markdown
Contributor

@dybucc dybucc commented Jun 4, 2026

Description

This PR addresses bit-width representation issues under emscripten concerned with the LFS64 "spec."
The current interface we expose unconditionally makes the symbols available, even though the
upstream musl fork for emscripten does define the _GNU_SOURCE feature test macro by default. This
has been patched by conditionally compiling whenever it is that the gnu_file_offset_bits64 cfg
option is detected at build time.

All of the routines concerned with LFS64 were already in a module of their own but were always
exposed even though they are not always available in emscripten. According to [1], the
_LARGEFILE64_SOURCE feature test macro is considered "deprecated" and the gated functionality
should instead be provided by setting _FILE_OFFSET_BITS=64. At present, the libc crate aleady
has a cfg for that. Still, the definition in emscripten (and in upstream musl) also requires the
_GNU_SOURCE feature test macro to be enabled. This symbol is not made available by default in
Linux unless either explicitly defined in source code or as part of the compilation pipeline, and
makes available a number of GNU extensions. The libc crate does not have at the time of writing
any cfgs gating this functionality, but this PR does not introduce it. Further discussion on this
may be necessary.

This patch deprecates all such symbols (both suffixed routines and types) unless the cfg option is
set. These changes, though, may prove to be useless. That's why no greater effort has been made into
fixing the exposed interface, unless further confirmation from somebody else is provided. Tests
don't pass with the module availability changes as there's overlapping definitions between parent
modules to the emscripten module, and those in the emscripten module itself. This is caused by
the modified link names of a few routines when running under gnu_file_offset_bits64. Were this PR
to be viable, further changes will be made to fully fix this.

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
Copy link
Copy Markdown
Contributor Author

dybucc commented Jun 4, 2026

Style check fails for reasons outside the changes introduced in this PR. The formatting checks seem
to run on a post-macro expanded crate output. When annotating the item produced by the extern_ty
macro with an attribute, this expands with a wrongly indented function block, even though the actual
source code is correctly indented. The output log of the CI job shows this.

The definitions for types that were made available under the LFS64 spec
were being exposed even when the right feature test macro for that is
now `FILE_OFFSET_BITS64`.

This has been patched by deprecating the current definition when
building without the existing `gnu_file_offset_bits64` `cfg` option.
Even though the definitions are exposed when both the afore mentioned
macro and the `_GNU_SOURCE` macro are defined, no `cfg` has been added
for the latter.
@dybucc dybucc force-pushed the emscripten-largefile64-patch branch from 21a8c5d to 9cdfb82 Compare June 4, 2026 14:46
@rustbot
Copy link
Copy Markdown
Collaborator

rustbot commented Jun 4, 2026

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants