ziglang / zig

General-purpose programming language and toolchain for maintaining robust, optimal, and reusable software.
https://ziglang.org
MIT License
32.16k stars 2.35k forks source link

update 32-bit architectures in the std lib to use 64-bit time to prepare for year 2038 #4726

Open andrewrk opened 4 years ago

andrewrk commented 4 years ago

Now that #4538 is done, it's zig std lib's turn to update. This task is to change time_t and related structs to be 64-bits and to call the 64-bit syscalls rather than the 32-bit ones. Here's a nice list of libc functions that have 64 bit versions:

andy@ark ~/D/musl> ls compat/time32/
adjtime32.c               gmtime32_r.c                         setitimer_time32.c
adjtimex_time32.c         localtime32.c                        settimeofday_time32.c
aio_suspend_time32.c      localtime32_r.c                      sigtimedwait_time32.c
clock_adjtime32.c         lstat_time32.c                       stat_time32.c
clock_getres_time32.c     lutimes_time32.c                     stime32.c
clock_gettime32.c         mktime32.c                           thrd_sleep_time32.c
clock_nanosleep_time32.c  mq_timedreceive_time32.c             time32.c
clock_settime32.c         mq_timedsend_time32.c                time32gm.c
cnd_timedwait_time32.c    mtx_timedlock_time32.c               time32.h
ctime32.c                 nanosleep_time32.c                   timerfd_gettime32.c
ctime32_r.c               ppoll_time32.c                       timerfd_settime32.c
difftime32.c              pselect_time32.c                     timer_gettime32.c
fstatat_time32.c          pthread_cond_timedwait_time32.c      timer_settime32.c
fstat_time32.c            pthread_mutex_timedlock_time32.c     timespec_get_time32.c
ftime32.c                 pthread_rwlock_timedrdlock_time32.c  utimensat_time32.c
futimens_time32.c         pthread_rwlock_timedwrlock_time32.c  utimes_time32.c
futimesat_time32.c        pthread_timedjoin_np_time32.c        utime_time32.c
futimes_time32.c          recvmmsg_time32.c                    wait3_time32.c
getitimer_time32.c        sched_rr_get_interval_time32.c       wait4_time32.c
getrusage_time32.c        select_time32.c                      __xstat.c
gettimeofday_time32.c     semtimedop_time32.c
gmtime32.c                sem_timedwait_time32.c

Any of these that match syscalls (or libc calls) that the zig std lib uses, should be upgraded.

alexrp commented 1 week ago

I ran into this as part of #20389. riscv32 is unusual in that all the classic syscalls like ppoll, clock_gettime, etc operate with 64-bit time values, whereas on older 32-bit architectures, you have to call ppoll_time64, clock_gettime64, etc if you want 64-bit time. I think arc is also like riscv32 in this regard. In other words, on riscv32/arc, you must use a __kernel_timespec (always 64-bit) to call ppoll, but on e.g. x86, you use a timespec (32-bit/64-bit depending on word size).

(I'm hacking around this for now by defining std.os.linux.timespec as equal to kernel_timespec on riscv32 only, which allows the time-related syscall wrappers to work. This is obviously less than ideal, but one thing at a time...)

Should our strategy for std.os.linux just be to have the syscall wrappers take kernel_timespec instead of timespec and only fall back to truncating to timespec if a 64-bit time version of the syscall is unavailable?