Skip to content

Gnu time bits 64 #4433

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

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

Gnu time bits 64 #4433

wants to merge 13 commits into from

Conversation

snogge
Copy link
Contributor

@snogge snogge commented Apr 28, 2025

Description

Add a new cfg gnu_time_bits64 corresponding to
-D_TIME_BITS=64.
The cfg can also be enabled by setting the environment variable
RUST_LIBC_UNSTABLE_GNU_TIME_BITS64=1.

This is the third part of what was #3175 .

Sources

Sources are listed listed in each commit message.

struct stat64:
ARM:
https://github.com/bminor/glibc/blob/77930e0447e0b37a129db0e13c6c6f5e60a3019e/sysdeps/unix/sysv/linux/arm/bits/struct_stat.h
MIPS:
https://github.com/bminor/glibc/blob/77930e0447e0b37a129db0e13c6c6f5e60a3019e/sysdeps/unix/sysv/linux/mips/bits/struct_stat.h
POWERPC:
https://github.com/bminor/glibc/blob/77930e0447e0b37a129db0e13c6c6f5e60a3019e/sysdeps/unix/sysv/linux/powerpc/bits/struct_stat.h
SPARC:
https://github.com/bminor/glibc/blob/77930e0447e0b37a129db0e13c6c6f5e60a3019e/sysdeps/unix/sysv/linux/sparc/bits/struct_stat.h
x86:
https://github.com/bminor/glibc/blob/77930e0447e0b37a129db0e13c6c6f5e60a3019e/sysdeps/unix/sysv/linux/x86/bits/struct_stat.h
Common definition for _TIME_BITS=64
https://github.com/bminor/glibc/blob/77930e0447e0b37a129db0e13c6c6f5e60a3019e/sysdeps/unix/sysv/linux/bits/struct_stat_time64_helper.h

struct stat:
ARM:
https://github.com/bminor/glibc/blob/77930e0447e0b37a129db0e13c6c6f5e60a3019e/sysdeps/unix/sysv/linux/arm/bits/struct_stat.h
MIPS:
https://github.com/bminor/glibc/blob/77930e0447e0b37a129db0e13c6c6f5e60a3019e/sysdeps/unix/sysv/linux/mips/bits/struct_stat.h
POWERPC:
https://github.com/bminor/glibc/blob/77930e0447e0b37a129db0e13c6c6f5e60a3019e/sysdeps/unix/sysv/linux/powerpc/bits/struct_stat.h
SPARC:
https://github.com/bminor/glibc/blob/77930e0447e0b37a129db0e13c6c6f5e60a3019e/sysdeps/unix/sysv/linux/sparc/bits/struct_stat.h
x86:
https://github.com/bminor/glibc/blob/77930e0447e0b37a129db0e13c6c6f5e60a3019e/sysdeps/unix/sysv/linux/x86/bits/struct_stat.h
Common definition for _TIME_BITS=64
https://github.com/bminor/glibc/blob/77930e0447e0b37a129db0e13c6c6f5e60a3019e/sysdeps/unix/sysv/linux/bits/struct_stat_time64_helper.h

struct timeval
https://github.com/bminor/glibc/blob/e78caeb4ff812ae19d24d65f4d4d48508154277b/time/bits/types/struct_timeval.h

struct timex:
https://github.com/bminor/glibc/blob/e78caeb4ff812ae19d24d65f4d4d48508154277b/sysdeps/unix/sysv/linux/bits/timex.h

struct timespec
https://github.com/bminor/glibc/blob/e78caeb4ff812ae19d24d65f4d4d48508154277b/time/bits/types/struct_timespec.h

struct semid_ds:
Common definition for _TIME_BITS=64
https://github.com/bminor/glibc/blob/e78caeb4ff812ae19d24d65f4d4d48508154277b/sysdeps/unix/sysv/linux/bits/types/struct_semid64_ds_helper.h
Generic implementation used by arm:
https://github.com/bminor/glibc/blob/e78caeb4ff812ae19d24d65f4d4d48508154277b/sysdeps/unix/sysv/linux/bits/types/struct_semid_ds.h
x86:
https://github.com/bminor/glibc/blob/e78caeb4ff812ae19d24d65f4d4d48508154277b/sysdeps/unix/sysv/linux/x86/bits/types/struct_semid_ds.h
PowerPC:
https://github.com/bminor/glibc/blob/e78caeb4ff812ae19d24d65f4d4d48508154277b/sysdeps/unix/sysv/linux/powerpc/bits/types/struct_semid_ds.h
MIPS:
https://github.com/bminor/glibc/blob/e78caeb4ff812ae19d24d65f4d4d48508154277b/sysdeps/unix/sysv/linux/mips/bits/types/struct_semid_ds.h
SPARC:
https://github.com/bminor/glibc/blob/e78caeb4ff812ae19d24d65f4d4d48508154277b/sysdeps/unix/sysv/linux/sparc/bits/types/struct_semid_ds.h

struct msqid_ds:
Common definition for _TIME_BITS=64
https://github.com/bminor/glibc/blob/e78caeb4ff812ae19d24d65f4d4d48508154277b/sysdeps/unix/sysv/linux/bits/types/struct_msqid64_ds_helper.h
Generic implementation used by x86 and arm:
https://github.com/bminor/glibc/blob/e78caeb4ff812ae19d24d65f4d4d48508154277b/sysdeps/unix/sysv/linux/bits/types/struct_msqid_ds.h
PowerPC:
https://github.com/bminor/glibc/blob/e78caeb4ff812ae19d24d65f4d4d48508154277b/sysdeps/unix/sysv/linux/powerpc/bits/types/struct_msqid_ds.h
MIPS:
https://github.com/bminor/glibc/blob/e78caeb4ff812ae19d24d65f4d4d48508154277b/sysdeps/unix/sysv/linux/mips/bits/types/struct_msqid_ds.h
SPARC:
https://github.com/bminor/glibc/blob/e78caeb4ff812ae19d24d65f4d4d48508154277b/sysdeps/unix/sysv/linux/sparc/bits/types/struct_msqid_ds.h

struct shmid_ds:
Common definition for _TIME_BITS=64
https://github.com/bminor/glibc/blob/e78caeb4ff812ae19d24d65f4d4d48508154277b/sysdeps/unix/sysv/linux/bits/types/struct_shmid64_ds_helper.h
Generic implementation used by x86 and arm:
https://github.com/bminor/glibc/blob/e78caeb4ff812ae19d24d65f4d4d48508154277b/sysdeps/unix/sysv/linux/bits/types/struct_shmid_ds.h
PowerPC:
https://github.com/bminor/glibc/blob/e78caeb4ff812ae19d24d65f4d4d48508154277b/sysdeps/unix/sysv/linux/powerpc/bits/types/struct_shmid_ds.h
MIPS: (no changes required)
https://github.com/bminor/glibc/blob/e78caeb4ff812ae19d24d65f4d4d48508154277b/sysdeps/unix/sysv/linux/mips/bits/types/struct_shmid_ds.h
SPARC:
https://github.com/bminor/glibc/blob/e78caeb4ff812ae19d24d65f4d4d48508154277b/sysdeps/unix/sysv/linux/sparc/bits/types/struct_shmid_ds.h

glibc symbols:
https://github.com/bminor/glibc/blob/e78caeb4ff812ae19d24d65f4d4d48508154277b/io/fcntl.h
fcntl on line 190
https://github.com/bminor/glibc/blob/e78caeb4ff812ae19d24d65f4d4d48508154277b/io/sys/poll.h
ppoll on line 71
https://github.com/bminor/glibc/blob/e78caeb4ff812ae19d24d65f4d4d48508154277b/io/sys/stat.h
difftime on line 86
fstat on line 218
fstat64 on line 249
fstatat on line 270
fstatat64 on line 296
futimens on line 456
gmtime on line 140
gmtime_r on line 163
localtime on line 141
localtime_r on line 167
lstat on line 318
lstat64 on line 318
mktime on line 88
stat on line 214
stat64 on line 214
time on line 85
timegm on line 249
utimensat on line 439
https://github.com/bminor/glibc/blob/e78caeb4ff812ae19d24d65f4d4d48508154277b/io/utime.h
utime on line 56
https://github.com/bminor/glibc/blob/e78caeb4ff812ae19d24d65f4d4d48508154277b/misc/sys/ioctl.h
ioctl on line 45
https://github.com/bminor/glibc/blob/e78caeb4ff812ae19d24d65f4d4d48508154277b/misc/sys/select.h
pselect on line 134
select on line 108
https://github.com/bminor/glibc/blob/e78caeb4ff812ae19d24d65f4d4d48508154277b/posix/glob.h
glob on line 154
glob64 on line 174
globfree on line 160
globfree64 on line 180
https://github.com/bminor/glibc/blob/e78caeb4ff812ae19d24d65f4d4d48508154277b/posix/sched.h
sched_rr_get_interval on line 81
https://github.com/bminor/glibc/blob/e78caeb4ff812ae19d24d65f4d4d48508154277b/posix/sys/wait.h
wait4 on line 163
https://github.com/bminor/glibc/blob/e78caeb4ff812ae19d24d65f4d4d48508154277b/resource/sys/resource.h
getrusage on line 93
https://github.com/bminor/glibc/blob/e78caeb4ff812ae19d24d65f4d4d48508154277b/rt/aio.h
aio_suspend on line 197
https://github.com/bminor/glibc/blob/e78caeb4ff812ae19d24d65f4d4d48508154277b/rt/mqueue.h
mq_timedreceive on line 91
mq_timedsend on line 99
https://github.com/bminor/glibc/blob/e78caeb4ff812ae19d24d65f4d4d48508154277b/signal/signal.h
sigtimedwait on line 279
https://github.com/bminor/glibc/blob/e78caeb4ff812ae19d24d65f4d4d48508154277b/socket/sys/socket.h
getsockopt on line 260
recvmmsg on line 219
recvmsg on line 219
sendmmsg on line 199
sendmsg on line 178
setsockopt on line 281
https://github.com/bminor/glibc/blob/e78caeb4ff812ae19d24d65f4d4d48508154277b/sysdeps/nptl/pthread.h
pthread_cond_timedwait on line 1151
pthread_mutex_timedlock on line 805
https://github.com/bminor/glibc/blob/e78caeb4ff812ae19d24d65f4d4d48508154277b/sysdeps/pthread/semaphore.h
sem_timedwait on line 68
https://github.com/bminor/glibc/blob/e78caeb4ff812ae19d24d65f4d4d48508154277b/sysdeps/unix/sysv/linux/bits/time.h
clock_adjtime on line 82
https://github.com/bminor/glibc/blob/e78caeb4ff812ae19d24d65f4d4d48508154277b/sysdeps/unix/sysv/linux/sys/epoll.h
epoll_pwait2 on line 146
https://github.com/bminor/glibc/blob/e78caeb4ff812ae19d24d65f4d4d48508154277b/sysdeps/unix/sysv/linux/sys/prctl.h
prctl on line 45
https://github.com/bminor/glibc/blob/e78caeb4ff812ae19d24d65f4d4d48508154277b/sysdeps/unix/sysv/linux/sys/timerfd.h
timerfd_gettime on line 67
timerfd_settime on line 52
https://github.com/bminor/glibc/blob/e78caeb4ff812ae19d24d65f4d4d48508154277b/sysdeps/unix/sysv/linux/sys/timex.h
adjtimex on line 70
ntp_adjtime on line 76
ntp_gettime on line 72
https://github.com/bminor/glibc/blob/e78caeb4ff812ae19d24d65f4d4d48508154277b/sysvipc/sys/msg.h
msgctl on line 65
https://github.com/bminor/glibc/blob/e78caeb4ff812ae19d24d65f4d4d48508154277b/sysvipc/sys/sem.h
semctl on line 55
https://github.com/bminor/glibc/blob/e78caeb4ff812ae19d24d65f4d4d48508154277b/sysvipc/sys/shm.h
shmctl on line 53
https://github.com/bminor/glibc/blob/e78caeb4ff812ae19d24d65f4d4d48508154277b/time/sys/time.h
adjtime on line 102
futimes on line 200
gettimeofday on line 71
lutimes on line 196
settimeofday on line 98
utimes on line 176
https://github.com/bminor/glibc/blob/e78caeb4ff812ae19d24d65f4d4d48508154277b/time/time.h
clock_getres on line 299
clock_gettime on line 302
clock_nanosleep on line 328
clock_settime on line 305
ctime_r on line 206
nanosleep on line 328
timer_gettime on line 366
timer_settime on line 361

Checklist

  • Relevant tests in libc-test/semver have been updated
  • No placeholder or unstable values like *LAST or *MAX are
    included (see rust-lang/libc#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.83 using the yocto project, but it's not a fully compatible
environment for some reason.

@tgross35
Copy link
Contributor

It will take me a couple of days to go through everything but from a quick pass this looks great. Thank you for another extremely thorough PR.

@tgross35 tgross35 added the stable-nominated This PR should be considered for cherry-pick to libc's stable release branch label Apr 28, 2025
snogge added 12 commits April 29, 2025 15:17
Add new jobs for i686 in test_tier1 and arm and powerpc in test_tier2
where RUST_LIBC_UNSTABLE_GNU_TIME_BITS=64.

Use artifact-tag to avoid artifact name collisions.
Set the basic types correctly for
gnu_time_bits64 (_TIME_BITS=64 and _FILE_OFFSET_BITS=64).
Set the link names of relevant symbols to use be the same as when a C
program is built against GNU libc with -D_TIME_BITS=64 -- which also
requires -D_FILE_OFFSET_BITS=64.

References:

https://github.com/bminor/glibc/blob/e78caeb4ff812ae19d24d65f4d4d48508154277b/io/fcntl.h
 fcntl on line 190

https://github.com/bminor/glibc/blob/e78caeb4ff812ae19d24d65f4d4d48508154277b/io/sys/poll.h
 ppoll on line 71

https://github.com/bminor/glibc/blob/e78caeb4ff812ae19d24d65f4d4d48508154277b/io/sys/stat.h
 difftime on line 86
 fstat on line 218
 fstat64 on line 249
 fstatat on line 270
 fstatat64 on line 296
 futimens on line 456
 gmtime on line 140
 gmtime_r on line 163
 localtime on line 141
 localtime_r on line 167
 lstat on line 318
 lstat64 on line 318
 mktime on line 88
 stat on line 214
 stat64 on line 214
 time on line 85
 timegm on line 249
 utimensat on line 439

https://github.com/bminor/glibc/blob/e78caeb4ff812ae19d24d65f4d4d48508154277b/io/utime.h
 utime on line 56

https://github.com/bminor/glibc/blob/e78caeb4ff812ae19d24d65f4d4d48508154277b/misc/sys/ioctl.h
 ioctl on line 45

https://github.com/bminor/glibc/blob/e78caeb4ff812ae19d24d65f4d4d48508154277b/misc/sys/select.h
 pselect on line 134
 select on line 108

https://github.com/bminor/glibc/blob/e78caeb4ff812ae19d24d65f4d4d48508154277b/posix/glob.h
 glob on line 154
 glob64 on line 174
 globfree on line 160
 globfree64 on line 180

https://github.com/bminor/glibc/blob/e78caeb4ff812ae19d24d65f4d4d48508154277b/posix/sched.h
 sched_rr_get_interval on line 81

https://github.com/bminor/glibc/blob/e78caeb4ff812ae19d24d65f4d4d48508154277b/posix/sys/wait.h
 wait4 on line 163

https://github.com/bminor/glibc/blob/e78caeb4ff812ae19d24d65f4d4d48508154277b/resource/sys/resource.h
 getrusage on line 93

https://github.com/bminor/glibc/blob/e78caeb4ff812ae19d24d65f4d4d48508154277b/rt/aio.h
 aio_suspend on line 197

https://github.com/bminor/glibc/blob/e78caeb4ff812ae19d24d65f4d4d48508154277b/rt/mqueue.h
 mq_timedreceive on line 91
 mq_timedsend on line 99

https://github.com/bminor/glibc/blob/e78caeb4ff812ae19d24d65f4d4d48508154277b/signal/signal.h
 sigtimedwait on line 279

https://github.com/bminor/glibc/blob/e78caeb4ff812ae19d24d65f4d4d48508154277b/socket/sys/socket.h
 getsockopt on line 260
 recvmmsg on line 219
 recvmsg on line 219
 sendmmsg on line 199
 sendmsg on line 178
 setsockopt on line 281

https://github.com/bminor/glibc/blob/e78caeb4ff812ae19d24d65f4d4d48508154277b/sysdeps/nptl/pthread.h
 pthread_cond_timedwait on line 1151
 pthread_mutex_timedlock on line 805

https://github.com/bminor/glibc/blob/e78caeb4ff812ae19d24d65f4d4d48508154277b/sysdeps/pthread/semaphore.h
 sem_timedwait on line 68

https://github.com/bminor/glibc/blob/e78caeb4ff812ae19d24d65f4d4d48508154277b/sysdeps/unix/sysv/linux/bits/time.h
 clock_adjtime on line 82

https://github.com/bminor/glibc/blob/e78caeb4ff812ae19d24d65f4d4d48508154277b/sysdeps/unix/sysv/linux/sys/epoll.h
 epoll_pwait2 on line 146

https://github.com/bminor/glibc/blob/e78caeb4ff812ae19d24d65f4d4d48508154277b/sysdeps/unix/sysv/linux/sys/prctl.h
 prctl on line 45

https://github.com/bminor/glibc/blob/e78caeb4ff812ae19d24d65f4d4d48508154277b/sysdeps/unix/sysv/linux/sys/timerfd.h
 timerfd_gettime on line 67
 timerfd_settime on line 52

https://github.com/bminor/glibc/blob/e78caeb4ff812ae19d24d65f4d4d48508154277b/sysdeps/unix/sysv/linux/sys/timex.h
 adjtimex on line 70
 ntp_adjtime on line 76
 ntp_gettime on line 72

https://github.com/bminor/glibc/blob/e78caeb4ff812ae19d24d65f4d4d48508154277b/sysvipc/sys/msg.h
 msgctl on line 65

https://github.com/bminor/glibc/blob/e78caeb4ff812ae19d24d65f4d4d48508154277b/sysvipc/sys/sem.h
 semctl on line 55

https://github.com/bminor/glibc/blob/e78caeb4ff812ae19d24d65f4d4d48508154277b/sysvipc/sys/shm.h
 shmctl on line 53

https://github.com/bminor/glibc/blob/e78caeb4ff812ae19d24d65f4d4d48508154277b/time/sys/time.h
 adjtime on line 102
 futimes on line 200
 gettimeofday on line 71
 lutimes on line 196
 settimeofday on line 98
 utimes on line 176

https://github.com/bminor/glibc/blob/e78caeb4ff812ae19d24d65f4d4d48508154277b/time/time.h
 clock_getres on line 299
 clock_gettime on line 302
 clock_nanosleep on line 328
 clock_settime on line 305
 ctime_r on line 206
 nanosleep on line 328
 timer_gettime on line 366
 timer_settime on line 361
Big-endian platforms wants 32 bits of padding before tv_nsec,
little-endian after.

GNU libc always uses long for tv_nsec.

References:

https://github.com/bminor/glibc/blob/e78caeb4ff812ae19d24d65f4d4d48508154277b/time/bits/types/struct_timespec.h
Will make it easier to adapt for _TIME_BITS=64
For 64 bit time on 32 bit linux glibc timeval.tv_usec is actually
__suseconds64_t (64 bits) while suseconds_t is still 32 bits.

References:
https://github.com/bminor/glibc/blob/e78caeb4ff812ae19d24d65f4d4d48508154277b/time/bits/types/struct_timeval.h
@snogge snogge force-pushed the gnu-time-bits-64 branch from 78239f1 to 979222c Compare April 30, 2025 07:31
@tgross35 tgross35 mentioned this pull request May 2, 2025
3 tasks
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.

Everything looks pretty good to me! Mostly some style review.

@@ -77,7 +77,9 @@ test_target() {
case "$target" in
# Test with the equivalent of __FILE_OFFSET_BITS=64
Copy link
Contributor

Choose a reason for hiding this comment

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

This comment could use a small adjustment

@@ -66,10 +66,21 @@ s! {
// See https://sourceware.org/bugzilla/show_bug.cgi?id=16437
pub struct timespec {
Copy link
Contributor

Choose a reason for hiding this comment

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

This struct has some complicated config. Maybe it would be easiest to split? Config the current one non-gnu and move the rest to linux/gnu.

@@ -204,23 +204,74 @@ s! {

pub struct timex {
Copy link
Contributor

Choose a reason for hiding this comment

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

Maybe this should be split in two to avoid interleaving fields?

Comment on lines +63 to +66
// For 64 bit time on 32 bit linux glibc, suseconds_t is still
// a 32 bit type. Use i64 instead
#[cfg(gnu_time_bits64)]
pub tv_usec: i64,
Copy link
Contributor

Choose a reason for hiding this comment

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

For consistency, maybe suseconds64_t should be defined then used here?

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