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

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

Open
andrewrk opened this issue Mar 12, 2020 · 2 comments
Labels
arch-arm 32-bit ARM arch-csky arch-m68k Motorola 68000 series arch-mips 32-bit and 64-bit MIPS arch-powerpc 32-bit and 64-bit Power ISA arch-sparc 32-bit and 64-bit SPARC arch-x86 32-bit x86 contributor friendly This issue is limited in scope and/or knowledge of Zig internals. enhancement Solving this issue will likely involve adding new logic or components to the codebase. os-linux standard library This issue involves writing Zig code for the standard library.
Milestone

Comments

@andrewrk
Copy link
Member

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.

@andrewrk andrewrk added enhancement Solving this issue will likely involve adding new logic or components to the codebase. contributor friendly This issue is limited in scope and/or knowledge of Zig internals. standard library This issue involves writing Zig code for the standard library. os-linux arch-x86 32-bit x86 arch-arm 32-bit ARM arch-mips 32-bit and 64-bit MIPS labels Mar 12, 2020
@andrewrk andrewrk added this to the 0.7.0 milestone Mar 12, 2020
@andrewrk andrewrk modified the milestones: 0.7.0, 0.8.0 Oct 13, 2020
@andrewrk andrewrk modified the milestones: 0.8.0, 0.9.0 Nov 6, 2020
@andrewrk andrewrk modified the milestones: 0.9.0, 0.10.0 May 19, 2021
@alexrp
Copy link
Member

alexrp commented Jun 26, 2024

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?

alexrp added a commit to alexrp/zig that referenced this issue Jun 26, 2024
This is kind of a hack because the timespec in UAPI headers is actually still
32-bit while __kernel_timespec is 64-bit. But, importantly, all the syscalls
take __kernel_timespec from the get-go (because riscv32 support is so recent).

Defining our timespec this way will allow all the syscall wrappers in
std.os.linux to do the right thing for riscv32. For other 32-bit architectures,
we have to use the 64-bit time syscalls explicitly to solve the Y2038 problem.
See issue ziglang#4726 for that.
alexrp added a commit to alexrp/zig that referenced this issue Jul 3, 2024
This is kind of a hack because the timespec in UAPI headers is actually still
32-bit while __kernel_timespec is 64-bit. But, importantly, all the syscalls
take __kernel_timespec from the get-go (because riscv32 support is so recent).

Defining our timespec this way will allow all the syscall wrappers in
std.os.linux to do the right thing for riscv32. For other 32-bit architectures,
we have to use the 64-bit time syscalls explicitly to solve the Y2038 problem.
See issue ziglang#4726 for that.
alexrp added a commit to alexrp/zig that referenced this issue Jul 7, 2024
This is kind of a hack because the timespec in UAPI headers is actually still
32-bit while __kernel_timespec is 64-bit. But, importantly, all the syscalls
take __kernel_timespec from the get-go (because riscv32 support is so recent).

Defining our timespec this way will allow all the syscall wrappers in
std.os.linux to do the right thing for riscv32. For other 32-bit architectures,
we have to use the 64-bit time syscalls explicitly to solve the Y2038 problem.
See issue ziglang#4726 for that.
@perklet
Copy link

perklet commented Jul 9, 2024

Any updates on this? I'm getting ld.lld: error: undefined symbol: __time64 error when building curl with x86-linux-musl target.

alexrp added a commit to alexrp/zig that referenced this issue Jul 9, 2024
This is kind of a hack because the timespec in UAPI headers is actually still
32-bit while __kernel_timespec is 64-bit. But, importantly, all the syscalls
take __kernel_timespec from the get-go (because riscv32 support is so recent).

Defining our timespec this way will allow all the syscall wrappers in
std.os.linux to do the right thing for riscv32. For other 32-bit architectures,
we have to use the 64-bit time syscalls explicitly to solve the Y2038 problem.
See issue ziglang#4726 for that.
alexrp added a commit to alexrp/zig that referenced this issue Jul 20, 2024
This is kind of a hack because the timespec in UAPI headers is actually still
32-bit while __kernel_timespec is 64-bit. But, importantly, all the syscalls
take __kernel_timespec from the get-go (because riscv32 support is so recent).

Defining our timespec this way will allow all the syscall wrappers in
std.os.linux to do the right thing for riscv32. For other 32-bit architectures,
we have to use the 64-bit time syscalls explicitly to solve the Y2038 problem.
See issue ziglang#4726 for that.
alexrp added a commit to alexrp/zig that referenced this issue Jul 20, 2024
This is kind of a hack because the timespec in UAPI headers is actually still
32-bit while __kernel_timespec is 64-bit. But, importantly, all the syscalls
take __kernel_timespec from the get-go (because riscv32 support is so recent).

Defining our timespec this way will allow all the syscall wrappers in
std.os.linux to do the right thing for riscv32. For other 32-bit architectures,
we have to use the 64-bit time syscalls explicitly to solve the Y2038 problem.
See issue ziglang#4726 for that.
alexrp added a commit to alexrp/zig that referenced this issue Jul 20, 2024
This is kind of a hack because the timespec in UAPI headers is actually still
32-bit while __kernel_timespec is 64-bit. But, importantly, all the syscalls
take __kernel_timespec from the get-go (because riscv32 support is so recent).

Defining our timespec this way will allow all the syscall wrappers in
std.os.linux to do the right thing for riscv32. For other 32-bit architectures,
we have to use the 64-bit time syscalls explicitly to solve the Y2038 problem.
See issue ziglang#4726 for that.
The-King-of-Toasters added a commit to The-King-of-Toasters/zig that referenced this issue Sep 17, 2024
The generic syscall table has different names for syscalls that take a
timespec64 on 32-bit targets, in that it adds the `_time64` suffix.
Similarly, the `_time32` suffix has been removed.

I'm not sure if the existing logic for determining the proper timespec
struct to use was subtly broken, but it should be a good chance to
finish ziglang#4726 - we only have 14 years after all...

In other news:

- x86_64 gets `uretprobe`, a syscall to speed up returning BPF probes.
- Hexagon gets `clone3`, but don't be fooled: it just returns ENOSYS.
The-King-of-Toasters added a commit to The-King-of-Toasters/zig that referenced this issue Sep 29, 2024
The generic syscall table has different names for syscalls that take a
timespec64 on 32-bit targets, in that it adds the `_time64` suffix.
Similarly, the `_time32` suffix has been removed.

I'm not sure if the existing logic for determining the proper timespec
struct to use was subtly broken, but it should be a good chance to
finish ziglang#4726 - we only have 14 years after all...

In other news:

- x86_64 gets `uretprobe`, a syscall to speed up returning BPF probes.
- Hexagon gets `clone3`, but don't be fooled: it just returns ENOSYS.
The-King-of-Toasters added a commit to The-King-of-Toasters/zig that referenced this issue Sep 29, 2024
The generic syscall table has different names for syscalls that take a
timespec64 on 32-bit targets, in that it adds the `_time64` suffix.
Similarly, the `_time32` suffix has been removed.

I'm not sure if the existing logic for determining the proper timespec
struct to use was subtly broken, but it should be a good chance to
finish ziglang#4726 - we only have 14 years after all...

In other news:

- x86_64 gets `uretprobe`, a syscall to speed up returning BPF probes.
- Hexagon gets `clone3`, but don't be fooled: it just returns ENOSYS.
@alexrp alexrp added arch-csky arch-m68k Motorola 68000 series labels Oct 18, 2024
@alexrp alexrp added arch-powerpc 32-bit and 64-bit Power ISA arch-sparc 32-bit and 64-bit SPARC labels Oct 18, 2024
The-King-of-Toasters added a commit to The-King-of-Toasters/zig that referenced this issue Oct 28, 2024
The generic syscall table has different names for syscalls that take a
timespec64 on 32-bit targets, in that it adds the `_time64` suffix.
Similarly, the `_time32` suffix has been removed.

I'm not sure if the existing logic for determining the proper timespec
struct to use was subtly broken, but it should be a good chance to
finish ziglang#4726 - we only have 14 years after all...

In other news:

- x86_64 gets `uretprobe`, a syscall to speed up returning BPF probes.
- Hexagon gets `clone3`, but don't be fooled: it just returns ENOSYS.
The-King-of-Toasters added a commit to The-King-of-Toasters/zig that referenced this issue Oct 29, 2024
The generic syscall table has different names for syscalls that take a
timespec64 on 32-bit targets, in that it adds the `_time64` suffix.
Similarly, the `_time32` suffix has been removed.

I'm not sure if the existing logic for determining the proper timespec
struct to use was subtly broken, but it should be a good chance to
finish ziglang#4726 - we only have 14 years after all...

In other news:

- x86_64 gets `uretprobe`, a syscall to speed up returning BPF probes.
- Hexagon gets `clone3`, but don't be fooled: it just returns ENOSYS.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
arch-arm 32-bit ARM arch-csky arch-m68k Motorola 68000 series arch-mips 32-bit and 64-bit MIPS arch-powerpc 32-bit and 64-bit Power ISA arch-sparc 32-bit and 64-bit SPARC arch-x86 32-bit x86 contributor friendly This issue is limited in scope and/or knowledge of Zig internals. enhancement Solving this issue will likely involve adding new logic or components to the codebase. os-linux standard library This issue involves writing Zig code for the standard library.
Projects
None yet
Development

No branches or pull requests

3 participants