[v2,00/10] Y2038 preparation: use clock_[gs]ettime to implement the other time-getting and -setting functions.

Message ID 20190828153236.18229-1-zackw@panix.com
Headers show
Series
  • Y2038 preparation: use clock_[gs]ettime to implement the other time-getting and -setting functions.
Related show

Message

Zack Weinberg Aug. 28, 2019, 3:32 p.m.
This patchset aims to make the Y2038 project a little easier by
implementing the other time-getting and time-setting functions
(time, ftime, stime, gettimeofday, and settimeofday) in terms of
clock_gettime and clock_settime.  Internal uses of (__)gettimeofday
are also all changed to __clock_gettime.  Internal uses of time() are
mostly left alone, since time() is easier and clearer when you don't
care about sub-second resolution and don't need a struct timespec for
some other reason.

The user-visible consequences of this patchset are:

 - The obsolete functions ftime and stime are no longer available to
   new binaries.  The header <sys/timeb.h> is no longer installed.
 - gettimeofday and ftime now always report a crude time zone
   corresponding to UTC.
 - settimeofday will fail with EINVAL when both of its arguments are
   non-null.
 - Programs that call gettimeofday with a non-null tzp argument will
   receive compile-time warnings (with GCC and when optimizing).
 - On Linux, the (v)syscalls time and gettimeofday are no longer used
   under any circumstances.

See the final patch in the series for edits to NEWS describing these
changes in more detail.

This patchset also includes a partial revision of manual/time.tex.i
clock_gettime and clock_settime are now documented, and the
obsolescent status of stime, settimeofday, and gettimeofday is
clearer.  I only documented CLOCK_REALTIME and CLOCK_MONOTONIC,
because most of the other clock constants are either extremely
Linux-specific or they have to do with measuring CPU time, and I
didn't touch the measuring-CPU-time part of time.texi.  (That part
also deserves a rewrite, but I don't know enough about the topic and
this patchset is already long enough.)

This patchset has a structural dependency on the patch "Linux/Alpha:
don't use timeval32 system calls."  I think that patch needs to be
reviewed and discussed separately since it has implications for how we
implement 32-bit time_t compatibility in general.  Some but not all of
the patches in this set could be re-done to avoid the dependency, but
I don't think there's much point.

Each individual patch in this series has been tested with
build-many-glibcs targeting alpha-linux-gnu, i686-gnu, and
x86_64-linux-gnu-enable-obsolete.  The complete patch series has been
tested with a full build-many-glibcs run and a full "make xcheck" run
in the x86_64-linux-gnu-enable-obsolete configuration.

Changes since v1:

 - Demote ftime and stime to compat symbols.
 - Also use clock_gettime to implement timespec_get.
 - Better implementation of warnings for gettimeofday with non-null
   tzp argument.
 - Patch series reorganized for ease of review and to ensure all
   intermediate stages work correctly on all supported platforms.
   In particular, gettimeofday and settimeofday have fully operational
   implementations on the Hurd at all stages of the series.
 - I believe all previous review comments have been addressed.

Zack Weinberg (10):
  Change most internal uses of __gettimeofday to __clock_gettime.
  Finish move of clock_* functions to libc.
  Use clock_settime to implement stime; withdraw stime.
  Use clock_settime to implement settimeofday.
  Use clock_gettime to implement time.
  Use clock_gettime to implement ftime; withdraw ftime.
  Use clock_gettime to implement timespec_get.
  Use clock_gettime to implement gettimeofday.
  Warn when gettimeofday is called with non-null tzp argument.
  Revise the documentation of simple calendar time.

 NEWS                                          |   62 +-
 conform/Makefile                              |    9 +
 debug/warning-nop.c                           |    9 +
 include/sys/time.h                            |    7 +-
 include/time.h                                |    4 +-
 inet/deadline.c                               |    8 +-
 login/logout.c                                |    9 +-
 login/logwtmp.c                               |    7 +-
 manual/filesys.texi                           |    2 +-
 manual/llio.texi                              |   10 +-
 manual/threads.texi                           |    2 +-
 manual/time.texi                              | 1071 ++++++++++-------
 nis/nis_call.c                                |    4 +-
 nptl/pthread_join_common.c                    |    7 +-
 nptl/pthread_mutex_timedlock.c                |    7 +-
 nscd/nscd_helper.c                            |   24 +-
 resolv/gai_misc.c                             |    6 +-
 resolv/gai_suspend.c                          |    6 +-
 resolv/res_send.c                             |    7 +-
 rt/Makefile                                   |   15 +-
 rt/Versions                                   |   16 -
 rt/clock-compat.c                             |   63 -
 sunrpc/auth_des.c                             |   19 +-
 sunrpc/auth_unix.c                            |    9 +-
 sunrpc/create_xid.c                           |    6 +-
 sunrpc/svcauth_des.c                          |    7 +-
 support/support_test_main.c                   |   23 +-
 sysdeps/generic/memusage.h                    |   16 +-
 sysdeps/mach/clock_gettime.c                  |   51 +
 sysdeps/mach/gettimeofday.c                   |   43 -
 .../hurd/{settimeofday.c => clock_settime.c}  |   36 +-
 sysdeps/mach/hurd/getitimer.c                 |    6 +-
 sysdeps/mach/hurd/i386/libc.abilist           |    5 +
 sysdeps/mach/hurd/i386/librt.abilist          |    5 -
 sysdeps/mach/hurd/setitimer.c                 |    8 +-
 sysdeps/mach/hurd/times.c                     |    7 +-
 sysdeps/mach/nanosleep.c                      |   36 +-
 sysdeps/mach/usleep.c                         |    5 -
 sysdeps/posix/clock_getres.c                  |   11 +-
 sysdeps/posix/gettimeofday.c                  |   67 --
 sysdeps/posix/tempname.c                      |    9 +-
 sysdeps/posix/time.c                          |   40 -
 sysdeps/posix/timespec_get.c                  |   38 -
 sysdeps/pthread/aio_misc.c                    |    6 +-
 sysdeps/pthread/aio_suspend.c                 |    6 +-
 sysdeps/unix/bsd/ftime.c                      |   40 -
 sysdeps/unix/clock_gettime.c                  |   64 -
 sysdeps/unix/clock_nanosleep.c                |   10 +-
 sysdeps/unix/clock_settime.c                  |   54 -
 sysdeps/unix/make-syscalls.sh                 |    2 +-
 sysdeps/unix/syscalls.list                    |    2 -
 .../unix/sysv/linux/aarch64/gettimeofday.c    |   71 --
 sysdeps/unix/sysv/linux/aarch64/init-first.c  |    7 +-
 sysdeps/unix/sysv/linux/aarch64/libc-vdso.h   |    2 -
 .../linux/{time.c => alpha/gettimeofday.c}    |   31 +-
 sysdeps/unix/sysv/linux/alpha/libc.abilist    |    5 +
 sysdeps/unix/sysv/linux/alpha/librt.abilist   |    5 -
 .../unix/sysv/linux/alpha/osf_gettimeofday.c  |   11 +-
 .../unix/sysv/linux/alpha/osf_settimeofday.c  |   16 +-
 sysdeps/unix/sysv/linux/alpha/settimeofday.c  |   22 +
 sysdeps/unix/sysv/linux/alpha/syscalls.list   |    2 -
 sysdeps/unix/sysv/linux/arm/init-first.c      |    7 +-
 sysdeps/unix/sysv/linux/arm/libc-vdso.h       |    2 -
 sysdeps/unix/sysv/linux/arm/libc.abilist      |    5 +
 sysdeps/unix/sysv/linux/arm/librt.abilist     |    5 -
 sysdeps/unix/sysv/linux/clock_getcpuclockid.c |   10 +-
 sysdeps/unix/sysv/linux/clock_getres.c        |   11 +-
 sysdeps/unix/sysv/linux/clock_gettime.c       |   11 +-
 sysdeps/unix/sysv/linux/clock_nanosleep.c     |   10 +-
 sysdeps/unix/sysv/linux/clock_settime.c       |   11 +-
 sysdeps/unix/sysv/linux/ftime.c               |    3 -
 sysdeps/unix/sysv/linux/gettimeofday.c        |   49 -
 sysdeps/unix/sysv/linux/hppa/libc.abilist     |    5 +
 sysdeps/unix/sysv/linux/hppa/librt.abilist    |    5 -
 sysdeps/unix/sysv/linux/i386/gettimeofday.c   |   35 -
 sysdeps/unix/sysv/linux/i386/libc.abilist     |    5 +
 sysdeps/unix/sysv/linux/i386/librt.abilist    |    5 -
 sysdeps/unix/sysv/linux/i386/time.c           |   34 -
 sysdeps/unix/sysv/linux/ia64/libc.abilist     |    5 +
 sysdeps/unix/sysv/linux/ia64/librt.abilist    |    5 -
 .../sysv/linux/m68k/coldfire/libc.abilist     |    5 +
 .../sysv/linux/m68k/coldfire/librt.abilist    |    5 -
 .../unix/sysv/linux/m68k/m680x0/libc.abilist  |    5 +
 .../unix/sysv/linux/m68k/m680x0/librt.abilist |    5 -
 .../unix/sysv/linux/microblaze/librt.abilist  |    5 -
 sysdeps/unix/sysv/linux/mips/init-first.c     |    7 +-
 sysdeps/unix/sysv/linux/mips/libc-vdso.h      |    2 -
 .../sysv/linux/mips/mips32/fpu/libc.abilist   |    5 +
 .../unix/sysv/linux/mips/mips32/librt.abilist |    5 -
 .../sysv/linux/mips/mips32/nofpu/libc.abilist |    5 +
 .../unix/sysv/linux/mips/mips64/librt.abilist |    5 -
 .../sysv/linux/mips/mips64/n32/libc.abilist   |    5 +
 .../sysv/linux/mips/mips64/n64/libc.abilist   |    5 +
 sysdeps/unix/sysv/linux/powerpc/Versions      |    1 -
 .../unix/sysv/linux/powerpc/gettimeofday.c    |   85 --
 sysdeps/unix/sysv/linux/powerpc/init-first.c  |   13 +-
 sysdeps/unix/sysv/linux/powerpc/libc-vdso.h   |    2 -
 .../linux/powerpc/powerpc32/fpu/libc.abilist  |    5 +
 .../linux/powerpc/powerpc32/librt.abilist     |    5 -
 .../powerpc/powerpc32/nofpu/libc.abilist      |    5 +
 .../linux/powerpc/powerpc64/be/libc.abilist   |    5 +
 .../linux/powerpc/powerpc64/be/librt.abilist  |    5 -
 sysdeps/unix/sysv/linux/powerpc/time.c        |   84 --
 sysdeps/unix/sysv/linux/riscv/init-first.c    |   10 +-
 sysdeps/unix/sysv/linux/riscv/libc-vdso.h     |    2 -
 sysdeps/unix/sysv/linux/s390/init-first.c     |    9 +-
 sysdeps/unix/sysv/linux/s390/libc-vdso.h      |    3 -
 .../unix/sysv/linux/s390/s390-32/libc.abilist |    5 +
 .../sysv/linux/s390/s390-32/librt.abilist     |    5 -
 .../unix/sysv/linux/s390/s390-64/libc.abilist |    5 +
 .../sysv/linux/s390/s390-64/librt.abilist     |    5 -
 .../{stime.c => sysv/linux/settimezone.c}     |   30 +-
 sysdeps/unix/sysv/linux/sh/libc.abilist       |    5 +
 sysdeps/unix/sysv/linux/sh/librt.abilist      |    5 -
 sysdeps/unix/sysv/linux/sparc/init-first.c    |    8 +-
 sysdeps/unix/sysv/linux/sparc/libc-vdso.h     |    2 -
 .../sysv/linux/sparc/sparc32/libc.abilist     |    5 +
 .../sysv/linux/sparc/sparc32/librt.abilist    |    5 -
 .../sysv/linux/sparc/sparc64/libc.abilist     |    5 +
 .../sysv/linux/sparc/sparc64/librt.abilist    |    5 -
 sysdeps/unix/sysv/linux/sparc/sparc64/time.c  |    1 -
 sysdeps/unix/sysv/linux/syscalls.list         |    1 -
 sysdeps/unix/sysv/linux/timespec_get.c        |   46 -
 sysdeps/unix/sysv/linux/x86/gettimeofday.c    |   61 -
 sysdeps/unix/sysv/linux/x86/time.c            |   59 -
 .../unix/sysv/linux/x86_64/64/libc.abilist    |    5 +
 .../unix/sysv/linux/x86_64/64/librt.abilist   |    5 -
 .../unix/sysv/linux/x86_64/x32/libc.abilist   |    5 +
 .../unix/sysv/linux/x86_64/x32/librt.abilist  |    5 -
 .../unix/sysv/linux/x86_64/x32/syscalls.list  |    2 -
 time/Makefile                                 |   20 +-
 time/Versions                                 |   13 +
 {rt => time}/clock_getcpuclockid.c            |    9 +-
 time/clock_getres.c                           |   39 +
 {rt => time}/clock_gettime.c                  |   11 +-
 {rt => time}/clock_nanosleep.c                |   11 +-
 {rt => time}/clock_settime.c                  |   12 +-
 time/ftime.c                                  |   40 +-
 time/gettimeofday.c                           |   32 +-
 time/settimeofday.c                           |   24 +-
 rt/clock_getres.c => time/settimezone.c       |   12 +-
 time/stime.c                                  |   25 +-
 time/sys/time.h                               |   47 +-
 time/sys/timeb.h                              |   43 -
 time/time.c                                   |   12 +-
 time/time.h                                   |    6 -
 time/timespec_get.c                           |   14 +-
 {rt => time}/tst-clock.c                      |    0
 {rt => time}/tst-clock2.c                     |    0
 {rt => time}/tst-clock_nanosleep.c            |    0
 {rt => time}/tst-cpuclock1.c                  |    0
 time/tst-ftime.c                              |   58 -
 time/{tst-ftime_l.c => tst-strftime_l.c}      |    0
 153 files changed, 1376 insertions(+), 2011 deletions(-)
 delete mode 100644 rt/clock-compat.c
 create mode 100644 sysdeps/mach/clock_gettime.c
 delete mode 100644 sysdeps/mach/gettimeofday.c
 rename sysdeps/mach/hurd/{settimeofday.c => clock_settime.c} (60%)
 delete mode 100644 sysdeps/posix/gettimeofday.c
 delete mode 100644 sysdeps/posix/time.c
 delete mode 100644 sysdeps/posix/timespec_get.c
 delete mode 100644 sysdeps/unix/bsd/ftime.c
 delete mode 100644 sysdeps/unix/clock_gettime.c
 delete mode 100644 sysdeps/unix/clock_settime.c
 delete mode 100644 sysdeps/unix/sysv/linux/aarch64/gettimeofday.c
 rename sysdeps/unix/sysv/linux/{time.c => alpha/gettimeofday.c} (64%)
 create mode 100644 sysdeps/unix/sysv/linux/alpha/settimeofday.c
 delete mode 100644 sysdeps/unix/sysv/linux/ftime.c
 delete mode 100644 sysdeps/unix/sysv/linux/gettimeofday.c
 delete mode 100644 sysdeps/unix/sysv/linux/i386/gettimeofday.c
 delete mode 100644 sysdeps/unix/sysv/linux/i386/time.c
 delete mode 100644 sysdeps/unix/sysv/linux/powerpc/gettimeofday.c
 delete mode 100644 sysdeps/unix/sysv/linux/powerpc/time.c
 rename sysdeps/unix/{stime.c => sysv/linux/settimezone.c} (64%)
 delete mode 100644 sysdeps/unix/sysv/linux/sparc/sparc64/time.c
 delete mode 100644 sysdeps/unix/sysv/linux/timespec_get.c
 delete mode 100644 sysdeps/unix/sysv/linux/x86/gettimeofday.c
 delete mode 100644 sysdeps/unix/sysv/linux/x86/time.c
 rename {rt => time}/clock_getcpuclockid.c (75%)
 create mode 100644 time/clock_getres.c
 rename {rt => time}/clock_gettime.c (74%)
 rename {rt => time}/clock_nanosleep.c (76%)
 rename {rt => time}/clock_settime.c (71%)
 rename rt/clock_getres.c => time/settimezone.c (73%)
 delete mode 100644 time/sys/timeb.h
 rename {rt => time}/tst-clock.c (100%)
 rename {rt => time}/tst-clock2.c (100%)
 rename {rt => time}/tst-clock_nanosleep.c (100%)
 rename {rt => time}/tst-cpuclock1.c (100%)
 delete mode 100644 time/tst-ftime.c
 rename time/{tst-ftime_l.c => tst-strftime_l.c} (100%)

-- 
2.23.0

Comments

Joseph Myers Aug. 28, 2019, 5:15 p.m. | #1
On Wed, 28 Aug 2019, Zack Weinberg wrote:

>  - The obsolete functions ftime and stime are no longer available to

>    new binaries.  The header <sys/timeb.h> is no longer installed.


It might be advisable to see if this affects the build of libsanitizer, 
and alert sanitizer maintainers if so.  (There appear to be sanitizer 
interceptors for ftime and stime, and an include of <sys/timeb.h>.)

After comments at last year's Cauldron about glibc API changes breaking 
sanitizers and language libraries such as libgo, I added a --full-gcc 
option to build-many-glibcs.py with the hope that the people raising such 
issues would set up bots to monitor for them, but I don't think anyone has 
set up such a bot (and there were a series of pre-existing build issues 
using that option, as well as the need to have a new-enough native Ada 
compiler in the PATH when using it).

-- 
Joseph S. Myers
joseph@codesourcery.com
Zack Weinberg Sept. 3, 2019, 2:43 p.m. | #2
On Wed, Aug 28, 2019 at 1:15 PM Joseph Myers <joseph@codesourcery.com> wrote:
>

> On Wed, 28 Aug 2019, Zack Weinberg wrote:

>

> >  - The obsolete functions ftime and stime are no longer available to

> >    new binaries.  The header <sys/timeb.h> is no longer installed.

>

> It might be advisable to see if this affects the build of libsanitizer,

> and alert sanitizer maintainers if so.  (There appear to be sanitizer

> interceptors for ftime and stime, and an include of <sys/timeb.h>.)


I may not have time to do anything about this for at least a couple
weeks, but I can confirm that the absence of sys/timeb.h does break
the build of libsanitizer.  Adhemerval's suggestion of keeping ftime
and <sys/timeb.h> around for at least another release, but issuing
warnings if ftime is actually used (attribute((deprecated)) maybe?)
seems reasonable to me.

zw
Adhemerval Zanella Sept. 10, 2019, 5:32 p.m. | #3
On 03/09/2019 11:43, Zack Weinberg wrote:
> On Wed, Aug 28, 2019 at 1:15 PM Joseph Myers <joseph@codesourcery.com> wrote:

>>

>> On Wed, 28 Aug 2019, Zack Weinberg wrote:

>>

>>>  - The obsolete functions ftime and stime are no longer available to

>>>    new binaries.  The header <sys/timeb.h> is no longer installed.

>>

>> It might be advisable to see if this affects the build of libsanitizer,

>> and alert sanitizer maintainers if so.  (There appear to be sanitizer

>> interceptors for ftime and stime, and an include of <sys/timeb.h>.)

> 

> I may not have time to do anything about this for at least a couple

> weeks, but I can confirm that the absence of sys/timeb.h does break

> the build of libsanitizer.  Adhemerval's suggestion of keeping ftime

> and <sys/timeb.h> around for at least another release, but issuing

> warnings if ftime is actually used (attribute((deprecated)) maybe?)

> seems reasonable to me.

> 

> zw

> 


Hi Zack,

I just pushed a personal branch [1] based on your y2038-preliminaries
with the changes I have proposed in the review:

  * Change most internal uses of __gettimeofday to __clock_gettime.
    - Some tab/whitespace issues.
    - Hurd time_value_t to timespec strict issues.

  * Use clock_settime to implement settimeofday.
    - Simplify sysdeps/unix/sysv/linux/settimezone.c

  * Use clock_gettime to implement time.
    - Do not remove arch-specific time implementations.
    - Adjust powerpc time to use the new generic implementation.

  * Use clock_gettime to implement ftime; withdraw ftime.
    - Keep the sys/timeb.h header and deprecate ftime.

  * Use clock_gettime to implement gettimeofday.
    - Do not remove arch-specific gettimeofday implementations.

  * Warn when gettimeofday is called with non-null tzp argument.
    - Remove the __warndecl hack.
    - Change to "Make second argument of gettimeofday as 'void *'"
      and adjust the required implementations.

I don't like to clash with you proposal, since some changes remove
some suggestion from your first patchset.
  
[1] https://sourceware.org/git/?p=glibc.git;a=shortlog;h=refs/heads/azanella/y2038-preliminaries