Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add new cfg gnu_file_offset_bits64 corresponding to _FILE_OFFSET_BITS=64 #4345

Open
wants to merge 21 commits into
base: main
Choose a base branch
from

Conversation

snogge
Copy link
Contributor

@snogge snogge commented Mar 20, 2025

Description

Add a new cfg gnu_file_offset_bits64 corresponding to
-D_FILE_OFFSET_BITS=64.
The cfg can also be enabled by setting the environment variable
RUST_LIBC_UNSTABLE_GNU_FILE_OFFSET_BITS64=1.

This is the second part of what was #3175 .

Sources

  1. off_t
    1. https://sourceware.org/git/?p=glibc.git;a=blob;f=posix/sys/types.h;h=ab3037a9dab25fdbbe4eccb3875b2a3305c7f342;hb=HEAD#l83
  2. ino_t
    1. https://sourceware.org/git/?p=glibc.git;a=blob;f=posix/sys/types.h;h=ab3037a9dab25fdbbe4eccb3875b2a3305c7f342;hb=HEAD#l45
  3. blkcnt_t
    1. https://sourceware.org/git/?p=glibc.git;a=blob;f=posix/sys/types.h;h=ab3037a9dab25fdbbe4eccb3875b2a3305c7f342;hb=HEAD#l191
  4. fsblkcnt_t
    1. https://sourceware.org/git?p=glibc.git;a=blob;f=posix/sys/types.h;h=ab3037a9dab25fdbbe4eccb3875b2a3305c7f342;hb=HEAD#l208
  5. fsfilcnt_t
    1. https://sourceware.org/git?p=glibc.git;a=blob;f=posix/sys/types.h;h=ab3037a9dab25fdbbe4eccb3875b2a3305c7f342;hb=HEAD#l213
  6. rlim_t
    1. https://sourceware.org/git/?p=glibc.git;a=blob;f=sysdeps/unix/sysv/linux/bits/resource.h;h=51c07da01933a696853e17b4c32e2c5f8e10acf5;hb=HEAD#l130
    2. https://sourceware.org/git/?p=glibc.git;a=blob;f=sysdeps/unix/sysv/linux/mips/bits/resource.h;h=05f8e6ad353a471b347af2b750c30d8c160da08d;hb=HEAD#l138
    3. https://sourceware.org/git?p=glibc.git;a=blob;f=sysdeps/unix/sysv/linux/sparc/bits/resource.h;h=05f8e6ad353a471b347af2b750c30d8c160da08d;hb=HEAD#l138
  7. F_GETLK
    1. https://github.com/torvalds/linux/blob/4701f33a10702d5fc577c32434eb62adde0a1ae1/include/uapi/asm-generic/fcntl.h#L104
    2. https://github.com/torvalds/linux/blob/4701f33a10702d5fc577c32434eb62adde0a1ae1/include/uapi/asm-generic/fcntl.h#L119
    3. https://github.com/torvalds/linux/blob/4701f33a10702d5fc577c32434eb62adde0a1ae1/arch/mips/include/uapi/asm/fcntl.h#L40
    4. https://github.com/torvalds/linux/blob/4701f33a10702d5fc577c32434eb62adde0a1ae1/arch/mips/include/uapi/asm/fcntl.h#L48
  8. F_SETLK and F_SETLKW
    1. https://github.com/torvalds/linux/blob/4701f33a10702d5fc577c32434eb62adde0a1ae1/include/uapi/asm-generic/fcntl.h#L105
    2. https://github.com/torvalds/linux/blob/4701f33a10702d5fc577c32434eb62adde0a1ae1/include/uapi/asm-generic/fcntl.h#L106
    3. https://github.com/torvalds/linux/blob/4701f33a10702d5fc577c32434eb62adde0a1ae1/include/uapi/asm-generic/fcntl.h#L120
    4. https://github.com/torvalds/linux/blob/4701f33a10702d5fc577c32434eb62adde0a1ae1/include/uapi/asm-generic/fcntl.h#L121
    5. https://github.com/torvalds/linux/blob/4701f33a10702d5fc577c32434eb62adde0a1ae1/arch/mips/include/uapi/asm/fcntl.h#L41
    6. https://github.com/torvalds/linux/blob/4701f33a10702d5fc577c32434eb62adde0a1ae1/arch/mips/include/uapi/asm/fcntl.h#L42
    7. https://github.com/torvalds/linux/blob/4701f33a10702d5fc577c32434eb62adde0a1ae1/arch/mips/include/uapi/asm/fcntl.h#L49
    8. https://github.com/torvalds/linux/blob/4701f33a10702d5fc577c32434eb62adde0a1ae1/arch/mips/include/uapi/asm/fcntl.h#L50
    9. https://github.com/torvalds/linux/blob/4701f33a10702d5fc577c32434eb62adde0a1ae1/arch/sparc/include/uapi/asm/fcntl.h#L44
    10. https://github.com/torvalds/linux/blob/4701f33a10702d5fc577c32434eb62adde0a1ae1/arch/sparc/include/uapi/asm/fcntl.h#L45
  9. RLIM_INFINITY
    1. https://github.com/torvalds/linux/blob/master/include/uapi/asm-generic/resource.h#L58
  10. getrlimit, setrlimit, prlimit
    1. https://github.com/bminor/glibc/blob/bfb2f2f481147da54237ade3266f2586a51d43c9/resource/sys/resource.h#L49
    2. https://github.com/bminor/glibc/blob/bfb2f2f481147da54237ade3266f2586a51d43c9/resource/sys/resource.h#L61
    3. https://github.com/bminor/glibc/blob/bfb2f2f481147da54237ade3266f2586a51d43c9/sysdeps/unix/sysv/linux/bits/resource.h#L202
  11. pread, pwrite, preadv2, pwritev2
    1. https://github.com/bminor/glibc/blob/bfb2f2f481147da54237ade3266f2586a51d43c9/misc/sys/uio.h#L57
    2. https://github.com/bminor/glibc/blob/bfb2f2f481147da54237ade3266f2586a51d43c9/misc/sys/uio.h#L131
  12. aio_read, aio_write, aio_error, aio_return, aio_cancel, lio_listio
    1. https://github.com/bminor/glibc/blob/bfb2f2f481147da54237ade3266f2586a51d43c9/rt/aio.h#L141
  13. fallocate, posix_fallocate, posix_fadvise, open, creat, fcntl,
    lockf, openat
    1. https://github.com/bminor/glibc/blob/bfb2f2f481147da54237ade3266f2586a51d43c9/sysdeps/unix/sysv/linux/bits/fcntl-linux.h#L427
    2. https://github.com/bminor/glibc/blob/bfb2f2f481147da54237ade3266f2586a51d43c9/io/fcntl.h#L322
    3. https://github.com/bminor/glibc/blob/bfb2f2f481147da54237ade3266f2586a51d43c9/io/fcntl.h#L297
    4. https://github.com/bminor/glibc/blob/bfb2f2f481147da54237ade3266f2586a51d43c9/io/fcntl.h#L208
    5. https://github.com/bminor/glibc/blob/bfb2f2f481147da54237ade3266f2586a51d43c9/io/fcntl.h#L254
    6. https://github.com/bminor/glibc/blob/bfb2f2f481147da54237ade3266f2586a51d43c9/io/fcntl.h#L176
    7. https://github.com/bminor/glibc/blob/bfb2f2f481147da54237ade3266f2586a51d43c9/io/fcntl.h#L283
    8. https://github.com/bminor/glibc/blob/bfb2f2f481147da54237ade3266f2586a51d43c9/io/fcntl.h#L232
  14. glob, globfree
    1. https://github.com/bminor/glibc/blob/bfb2f2f481147da54237ade3266f2586a51d43c9/posix/glob.h#L145
  15. mkstemps, mkostemp, mkostemps, mkstemp
    1. https://github.com/bminor/glibc/blob/bfb2f2f481147da54237ade3266f2586a51d43c9/stdlib/stdlib.h#L826
    2. https://github.com/bminor/glibc/blob/bfb2f2f481147da54237ade3266f2586a51d43c9/stdlib/stdlib.h#L880
    3. https://github.com/bminor/glibc/blob/bfb2f2f481147da54237ade3266f2586a51d43c9/stdlib/stdlib.h#L900
    4. https://github.com/bminor/glibc/blob/bfb2f2f481147da54237ade3266f2586a51d43c9/stdlib/stdlib.h#L826
  16. sendfile
    1. https://github.com/bminor/glibc/blob/bfb2f2f481147da54237ade3266f2586a51d43c9/io/sys/sendfile.h#L32
  17. statfs, fstatfs
    1. https://github.com/bminor/glibc/blob/bfb2f2f481147da54237ade3266f2586a51d43c9/io/sys/statfs.h#L30
    2. https://github.com/bminor/glibc/blob/bfb2f2f481147da54237ade3266f2586a51d43c9/io/sys/statfs.h#L49
  18. fopen, freopen, tmpfile, fgetpos, fsetpos, fseeko, ftello
    1. https://github.com/bminor/glibc/blob/bfb2f2f481147da54237ade3266f2586a51d43c9/libio/stdio.h#L259
    2. https://github.com/bminor/glibc/blob/bfb2f2f481147da54237ade3266f2586a51d43c9/libio/stdio.h#L193
    3. https://github.com/bminor/glibc/blob/bfb2f2f481147da54237ade3266f2586a51d43c9/libio/stdio.h#L811
    4. https://github.com/bminor/glibc/blob/bfb2f2f481147da54237ade3266f2586a51d43c9/libio/stdio.h#L785
  19. stat, fstat, fstatat, lstat
    1. https://github.com/bminor/glibc/blob/bfb2f2f481147da54237ade3266f2586a51d43c9/io/sys/stat.h#L203
    2. https://github.com/bminor/glibc/blob/bfb2f2f481147da54237ade3266f2586a51d43c9/io/sys/stat.h#L310
  20. statfs, fstatfs
    1. https://github.com/bminor/glibc/blob/bfb2f2f481147da54237ade3266f2586a51d43c9/io/sys/statfs.h
  21. readdir, readdir_r
    1. https://github.com/bminor/glibc/blob/bfb2f2f481147da54237ade3266f2586a51d43c9/dirent/dirent.h#L163
    2. https://github.com/bminor/glibc/blob/bfb2f2f481147da54237ade3266f2586a51d43c9/dirent/dirent.h#L184
  22. lseek, pread, pwrite, truncate, ftruncate
    1. https://github.com/bminor/glibc/blob/bfb2f2f481147da54237ade3266f2586a51d43c9/posix/unistd.h#L338
    2. https://github.com/bminor/glibc/blob/bfb2f2f481147da54237ade3266f2586a51d43c9/posix/unistd.h#L382
    3. https://github.com/bminor/glibc/blob/bfb2f2f481147da54237ade3266f2586a51d43c9/posix/unistd.h#L1025
    4. https://github.com/bminor/glibc/blob/bfb2f2f481147da54237ade3266f2586a51d43c9/posix/unistd.h#L1048
  23. mmap
    1. https://github.com/bminor/glibc/blob/bfb2f2f481147da54237ade3266f2586a51d43c9/misc/sys/mman.h#L56
  24. struct statvfs, struct fstatvfs
    1. https://github.com/bminor/glibc/blob/bfb2f2f481147da54237ade3266f2586a51d43c9/io/sys/statvfs.h
  25. struct stat, struct stat64
    1. https://github.com/bminor/glibc/blob/bfb2f2f481147da54237ade3266f2586a51d43c9/sysdeps/unix/sysv/linux/bits/struct_stat.h
    2. https://github.com/bminor/glibc/blob/bfb2f2f481147da54237ade3266f2586a51d43c9/sysdeps/unix/sysv/linux/mips/bits/struct_stat.h
    3. https://github.com/bminor/glibc/blob/bfb2f2f481147da54237ade3266f2586a51d43c9/sysdeps/unix/sysv/linux/powerpc/bits/struct_stat.h
    4. https://github.com/bminor/glibc/blob/bfb2f2f481147da54237ade3266f2586a51d43c9/sysdeps/unix/sysv/linux/sparc/bits/struct_stat.h
  26. struct statfs, struct statfs64
    1. https://github.com/bminor/glibc/blob/bfb2f2f481147da54237ade3266f2586a51d43c9/sysdeps/unix/sysv/linux/bits/statfs.h
    2. https://github.com/bminor/glibc/blob/bfb2f2f481147da54237ade3266f2586a51d43c9/sysdeps/unix/sysv/linux/mips/bits/statfs.h
  27. struct fpos_t, struct fpos64_t
    1. https://github.com/bminor/glibc/blob/c5113a838b28a8894da19794ca7a69c5ace959a3/libio/bits/types/__fpos_t.h#L10
    2. https://github.com/bminor/glibc/blob/c5113a838b28a8894da19794ca7a69c5ace959a3/libio/bits/types/__fpos64_t.h#L10
  28. struct aiocb
    1. https://github.com/bminor/glibc/blob/c5113a838b28a8894da19794ca7a69c5ace959a3/rt/aio.h#L50
  29. struct flock
    1. https://github.com/bminor/glibc/blob/c5113a838b28a8894da19794ca7a69c5ace959a3/sysdeps/unix/sysv/linux/mips/bits/fcntl.h#L67

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

I've tested this as widely as possible, but I have not been able to
run the sparc tests. mips and powerpc tests have been run on rust
1.85 using the yocto project, but it's not a fully compatible
environment for some reason.

snogge added 3 commits March 12, 2025 23:03
Less commands makes for a cleaner `set -x` log.  And it is more
efficient.
Variables set with `env` in the matrix never propagated into the
environment.  Add a step in test_tier1 and test_tier2 that reads the
env context from the matrix and adds the variables to the environment
used by later steps.
The `Create I artifacts` step is always run, whether earlier steps
succeeds or not.  But the upload step would only run if all preceeding
steps wer successfull.  Add a conditional to always run except if
artifact creation failed.
@rustbot
Copy link
Collaborator

rustbot commented Mar 20, 2025

r? @tgross35

rustbot has assigned @tgross35.
They will have a look at your PR within the next two weeks and either review your PR or reassign to another reviewer.

Use r? to explicitly pick a reviewer

Copy link
Contributor

@tgross35 tgross35 left a comment

Choose a reason for hiding this comment

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

I haven't checked the type changes in detail but this looks pretty good to me. Left a handful of comments mostly related to configuration.

Thank you so much for working on this!

build.rs Outdated
Comment on lines 93 to 96
let target_env = env::var("CARGO_CFG_TARGET_ENV").unwrap();
let target_os = env::var("CARGO_CFG_TARGET_OS").unwrap();
let target_ptr_width = env::var("CARGO_CFG_TARGET_POINTER_WIDTH").unwrap();
let target_arch = env::var("CARGO_CFG_TARGET_ARCH").unwrap();
Copy link
Contributor

Choose a reason for hiding this comment

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

Nit, could you move these out of this block and toward the top of main? Something else may want to use them.

unwrap_or_default() may be better too, I doubt anybody is building this without Cargo but it's probably good to be careful just in case.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done

build.rs Outdated
Comment on lines 91 to 92
Ok(val) => {
if val == "1" {
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
Ok(val) => {
if val == "1" {
Ok(val) => if val == "1" {

Nit to remove an indent level. The next arm needs to change to Ok(_v) | Err(_e).

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done

build.rs Outdated
Comment on lines 100 to 101
&& target_arch != "riscv32"
&& target_arch != "x86_64"
Copy link
Contributor

Choose a reason for hiding this comment

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

x86_64 won't ever get matched here since target_ptr_width is checked right? And then, what is special about riscv32?

It would probably be good to add a riscv32 test in CI since unfortunately we don't have one yet (not here of course)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

x86_64-unknown-linux-gnux32 have 32bit pointer but always 64 bit time_t.
riscv32 also always have 64-bit time_t.

RUST_LIBC_UNSTABLE_GNU_FILE_OFFSET_BITS64: 1
artifact-tag: offset-bits64
# - target: powerpc-unknown-linux-gnu
# - target: powerpc-unknown-linux-gnu
Copy link
Contributor

Choose a reason for hiding this comment

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

Could you keep the FIXME(ppc): SIGILL running tests ... note?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Oops, I meant to include that.

Comment on lines -50 to +52
--volume "$(pwd)":/checkout:ro \
--volume "$(pwd)"/target:/checkout/target \
--volume "$PWD":/checkout:ro \
--volume "$PWD"/target:/checkout/target \
Copy link
Contributor

Choose a reason for hiding this comment

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

Is this just style (fine if so) or did some platform not work with PWD?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Not just style, running the script under set -x will give prints for the execution of the $(pwd) subprocess.
At the moment I was having a hard time getting the CI to do what I wanted and the extra prints were annoying.

Comment on lines 3579 to 3581
Ok(val) => {
if val == "1" {
if target.contains("gnu")
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
Ok(val) => {
if val == "1" {
if target.contains("gnu")
Ok(val) if val == "1" && target.contains("gnu") && ...

Same nit as above

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done

target_env = "gnu",
gnu_file_offset_bits64
))] {
pub const RLIM_INFINITY: crate::rlim_t = !0;
Copy link
Contributor

Choose a reason for hiding this comment

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

Is this meant to be the same as the above block? If so, the conditions could be merged.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The conditions tend to be complicated, but I'll push an updated variant.

// #[cfg(not(gnu_file_offset_bits64))]
// __st_ino: crate::ino_t,
// #[cfg(gnu_file_offset_bits64)]
__st_ino: c_ulong,
Copy link
Contributor

Choose a reason for hiding this comment

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

What is the reason for this to be commented out?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This was included by mistake. I'll remove it.

build.rs Outdated
Comment on lines 89 to 90
println!("cargo:rerun-if-env-changed=RUST_LIBC_UNSTABLE_GNU_FILE_OFFSET_BITS64");
match env::var("RUST_LIBC_UNSTABLE_GNU_FILE_OFFSET_BITS64") {
Copy link
Contributor

Choose a reason for hiding this comment

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

I think we may want to use RUST_LIBC_UNSTABLE_GNU_FILE_OFFSET_BITS and then have it be set to =32 or =64. Reason being, I think in 1.0 we will default to 64-bit but need to provide an environment variable to use 32.

Copy link
Contributor

@tgross35 tgross35 Mar 22, 2025

Choose a reason for hiding this comment

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

Also, doesn't this need to set linux_time_bits64 as well? edit: nope, mixing my time and files

Comment on lines +542 to +547
if #[cfg(not(target_env = "gnu"))] {
missing! {
#[cfg_attr(feature = "extra_traits", derive(Debug))]
pub enum fpos_t {} // FIXME(unix): fill this out with a struct
}
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Is this not provided at all for glibc? Or only with 64-bit time.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It was only provided as an enum before, this PR provides it for gnu/glibc. The definition for glibc is in src/unix/linux_like/linux/gnu/mod.rs.
The fpos_t definition in src/unix/mod.rs and fpos64_t definition in src/unix/linux_like/linux/mod.rs are now only for non-gnu libcs.

@tgross35 tgross35 added the stable-nominated This PR should be considered for cherry-pick to libc's stable release branch label Mar 22, 2025
snogge added 11 commits March 24, 2025 14:23
Add new jobs for i686 in test_tier1 and arm and powerpc in test_tier2
where RUST_LIBC_UNSTABLE_GNU_FILE_OFFSET_BITS=64.

Use artifact-tag to avoid artifact name collisions.
Set the basic types correctly for
gnu_file_offset_bits64 (_FILE_OFFSET_BITS=64).
gnu_file_offset_bits64 means _FILE_OFFSET_BITS=64.
When _FILE_OFFSET_BITS=64, glibc redirects some function calls to 64
bit versions.  These symbols are sometimes the public LFS variants,
sometimes hidden variants.
Like mips, the stat struct will become different once support for
gnu_file_offset_bits64 is added.
Like mips and powerpc, the stat struct will become different once
support for gnu_file_offset_bits64 is added.
Change the __padX members in b32/mod.rs from short to uint even though
they are actually unsigned short in C.  Using unsigned int will give
the same alignment, and make the struct equivalent to stat64 when
gnu_file_offset_bits64 is set.
@snogge snogge force-pushed the gnu-file-offset-64 branch from aba1e20 to cf9c316 Compare March 24, 2025 13:24
@snogge
Copy link
Contributor Author

snogge commented Mar 24, 2025

@rustbot ready

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-CI Area: CI-related items O-arm O-gnu O-linux O-linux-like O-mips O-sparc O-unix O-x86 S-waiting-on-review stable-nominated This PR should be considered for cherry-pick to libc's stable release branch
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants