[v3] y2038: Replace __clock_gettime with __clock_gettime64

Message ID 20200505181605.22346-1-lukma@denx.de
State Committed
Commit e9698175b0b60407db1e89bcf29437ab224bca0b
Headers
Series [v3] y2038: Replace __clock_gettime with __clock_gettime64 |

Commit Message

Lukasz Majewski May 5, 2020, 6:16 p.m. UTC
  The __clock_gettime internal function is not supporting 64 bit time on
architectures with __WORDSIZE == 32 and __TIMESIZE != 64 (like e.g. ARM 32
bit).

The __clock_gettime64 function shall be used instead in the glibc itself as
it supports 64 bit time on those systems.
This patch does not bring any changes to systems with __WORDSIZE == 64 as
for them the __clock_gettime64 is aliased to __clock_gettime (in
./include/time.h).

---
Changes for v3:
- Fix the commit message (add missing "function" after __clock_gettime64)
- Refactor __nisfind_server() function to support 64 bit time
  with struct timespec instead of struct timeval
- Change expires to __time64_t

Changes for v2:
- Use only TIMESPEC_TO_TIMEVAL instead of valid_timespec64_to_timeval in
  logout.c and logwtmp.c as it is generic enough to also support struct
  __timespec64 conversion to struct timeval
---
 benchtests/bench-timing.h                        |  2 +-
 include/random-bits.h                            |  4 ++--
 login/logout.c                                   |  4 ++--
 login/logwtmp.c                                  |  5 +++--
 nis/nis_call.c                                   | 16 +++++++---------
 sysdeps/generic/hp-timing.h                      |  4 ++--
 sysdeps/generic/memusage.h                       |  4 ++--
 sysdeps/unix/sysv/linux/alpha/osf_gettimeofday.c |  4 ++--
 sysdeps/unix/sysv/linux/clock.c                  |  7 ++-----
 9 files changed, 23 insertions(+), 27 deletions(-)
  

Comments

Lukasz Majewski May 19, 2020, 7:51 p.m. UTC | #1
Dear All,

> The __clock_gettime internal function is not supporting 64 bit time on
> architectures with __WORDSIZE == 32 and __TIMESIZE != 64 (like e.g.
> ARM 32 bit).
> 
> The __clock_gettime64 function shall be used instead in the glibc
> itself as it supports 64 bit time on those systems.
> This patch does not bring any changes to systems with __WORDSIZE ==
> 64 as for them the __clock_gettime64 is aliased to __clock_gettime (in
> ./include/time.h).

Gentle ping on this patch. It has been on the glibc-alpha for 2 weeks
now ...

Is it OK to pull?

> 
> ---
> Changes for v3:
> - Fix the commit message (add missing "function" after
> __clock_gettime64)
> - Refactor __nisfind_server() function to support 64 bit time
>   with struct timespec instead of struct timeval
> - Change expires to __time64_t
> 
> Changes for v2:
> - Use only TIMESPEC_TO_TIMEVAL instead of valid_timespec64_to_timeval
> in logout.c and logwtmp.c as it is generic enough to also support
> struct __timespec64 conversion to struct timeval
> ---
>  benchtests/bench-timing.h                        |  2 +-
>  include/random-bits.h                            |  4 ++--
>  login/logout.c                                   |  4 ++--
>  login/logwtmp.c                                  |  5 +++--
>  nis/nis_call.c                                   | 16
> +++++++--------- sysdeps/generic/hp-timing.h                      |
> 4 ++-- sysdeps/generic/memusage.h                       |  4 ++--
>  sysdeps/unix/sysv/linux/alpha/osf_gettimeofday.c |  4 ++--
>  sysdeps/unix/sysv/linux/clock.c                  |  7 ++-----
>  9 files changed, 23 insertions(+), 27 deletions(-)
> 
> diff --git a/benchtests/bench-timing.h b/benchtests/bench-timing.h
> index 5b9a8384bb..a0d6f82465 100644
> --- a/benchtests/bench-timing.h
> +++ b/benchtests/bench-timing.h
> @@ -18,7 +18,7 @@
>  
>  #undef attribute_hidden
>  #define attribute_hidden
> -#define __clock_gettime clock_gettime
> +#define __clock_gettime __clock_gettime64
>  #include <hp-timing.h>
>  #include <stdint.h>
>  
> diff --git a/include/random-bits.h b/include/random-bits.h
> index fd3fa01f9b..7561e55ca6 100644
> --- a/include/random-bits.h
> +++ b/include/random-bits.h
> @@ -30,8 +30,8 @@
>  static inline uint32_t
>  random_bits (void)
>  {
> -  struct timespec tv;
> -  __clock_gettime (CLOCK_MONOTONIC, &tv);
> +  struct __timespec64 tv;
> +  __clock_gettime64 (CLOCK_MONOTONIC, &tv);
>    /* Shuffle the lower bits to minimize the clock bias.  */
>    uint32_t ret = tv.tv_nsec ^ tv.tv_sec;
>    ret ^= (ret << 24) | (ret >> 8);
> diff --git a/login/logout.c b/login/logout.c
> index 7653fe8886..091312eb1d 100644
> --- a/login/logout.c
> +++ b/login/logout.c
> @@ -47,8 +47,8 @@ logout (const char *line)
>        memset (ut->ut_name, '\0', sizeof ut->ut_name);
>        memset (ut->ut_host, '\0', sizeof ut->ut_host);
>  
> -      struct timespec ts;
> -      __clock_gettime (CLOCK_REALTIME, &ts);
> +      struct __timespec64 ts;
> +      __clock_gettime64 (CLOCK_REALTIME, &ts);
>        TIMESPEC_TO_TIMEVAL (&ut->ut_tv, &ts);
>        ut->ut_type = DEAD_PROCESS;
>  
> diff --git a/login/logwtmp.c b/login/logwtmp.c
> index 90406acc3d..050219c153 100644
> --- a/login/logwtmp.c
> +++ b/login/logwtmp.c
> @@ -21,6 +21,7 @@
>  #include <time.h>
>  #include <unistd.h>
>  #include <utmp.h>
> +#include <struct___timespec64.h>
>  
>  
>  void
> @@ -36,8 +37,8 @@ logwtmp (const char *line, const char *name, const
> char *host) strncpy (ut.ut_name, name, sizeof ut.ut_name);
>    strncpy (ut.ut_host, host, sizeof ut.ut_host);
>  
> -  struct timespec ts;
> -  __clock_gettime (CLOCK_REALTIME, &ts);
> +  struct __timespec64 ts;
> +  __clock_gettime64 (CLOCK_REALTIME, &ts);
>    TIMESPEC_TO_TIMEVAL (&ut.ut_tv, &ts);
>  
>    updwtmp (_PATH_WTMP, &ut);
> diff --git a/nis/nis_call.c b/nis/nis_call.c
> index 92c70e97aa..da4c52bdcd 100644
> --- a/nis/nis_call.c
> +++ b/nis/nis_call.c
> @@ -575,7 +575,7 @@ static struct nis_server_cache
>    unsigned int size;
>    unsigned int server_used;
>    unsigned int current_ep;
> -  time_t expires;
> +  __time64_t expires;
>    char name[];
>  } *nis_server_cache[16];
>  static time_t nis_cold_start_mtime;
> @@ -584,7 +584,7 @@ __libc_lock_define_initialized (static,
> nis_server_cache_lock) static directory_obj *
>  nis_server_cache_search (const_nis_name name, int search_parent,
>  			 unsigned int *server_used, unsigned int
> *current_ep,
> -			 struct timeval *now)
> +			 struct __timespec64 *now)
>  {
>    directory_obj *ret = NULL;
>    int i;
> @@ -642,7 +642,7 @@ nis_server_cache_search (const_nis_name name, int
> search_parent, static void
>  nis_server_cache_add (const_nis_name name, int search_parent,
>  		      directory_obj *dir, unsigned int server_used,
> -		      unsigned int current_ep, struct timeval *now)
> +		      unsigned int current_ep, struct __timespec64
> *now) {
>    struct nis_server_cache **loc;
>    struct nis_server_cache *new;
> @@ -708,8 +708,7 @@ __nisfind_server (const_nis_name name, int
> search_parent, nis_error result = NIS_SUCCESS;
>    nis_error status;
>    directory_obj *obj;
> -  struct timeval now;
> -  struct timespec ts;
> +  struct __timespec64 ts;
>    unsigned int server_used = ~0;
>    unsigned int current_ep = ~0;
>  
> @@ -719,12 +718,11 @@ __nisfind_server (const_nis_name name, int
> search_parent, if (*dir != NULL)
>      return NIS_SUCCESS;
>  
> -  __clock_gettime (CLOCK_REALTIME, &ts);
> -  TIMESPEC_TO_TIMEVAL (&now, &ts);
> +  __clock_gettime64 (CLOCK_REALTIME, &ts);
>  
>    if ((flags & NO_CACHE) == 0)
>      *dir = nis_server_cache_search (name, search_parent,
> &server_used,
> -				    &current_ep, &now);
> +				    &current_ep, &ts);
>    if (*dir != NULL)
>      {
>        unsigned int server_len = (*dir)->do_servers.do_servers_len;
> @@ -783,7 +781,7 @@ __nisfind_server (const_nis_name name, int
> search_parent, }
>  	  if ((flags & NO_CACHE) == 0)
>  	    nis_server_cache_add (name, search_parent, obj,
> -				  server_used, current_ep, &now);
> +				  server_used, current_ep, &ts);
>  	}
>        else
>  	{
> diff --git a/sysdeps/generic/hp-timing.h b/sysdeps/generic/hp-timing.h
> index e2d7447212..af9d92f7f7 100644
> --- a/sysdeps/generic/hp-timing.h
> +++ b/sysdeps/generic/hp-timing.h
> @@ -34,8 +34,8 @@ typedef uint64_t hp_timing_t;
>     vDSO symbol.  */
>  #define HP_TIMING_NOW(var) \
>  ({								\
> -  struct timespec tv;
> \
> -  __clock_gettime (CLOCK_MONOTONIC, &tv);			\
> +  struct __timespec64 tv;
> 	\
> +  __clock_gettime64 (CLOCK_MONOTONIC, &tv);			\
>    (var) = (tv.tv_nsec + UINT64_C(1000000000) * tv.tv_sec);	\
>  })
>  
> diff --git a/sysdeps/generic/memusage.h b/sysdeps/generic/memusage.h
> index a111864b0b..91e56d24de 100644
> --- a/sysdeps/generic/memusage.h
> +++ b/sysdeps/generic/memusage.h
> @@ -28,9 +28,9 @@
>  #ifndef GETTIME
>  # define GETTIME(low,high)
> 	   \ {
> 		   \
> -    struct timespec now;
> 	   \
> +    struct __timespec64 now;
> 	   \ uint64_t usecs;
> 		   \
> -    clock_gettime (CLOCK_REALTIME, &now);
> 	   \
> +    __clock_gettime64 (CLOCK_REALTIME, &now);
> 	   \ usecs = (uint64_t)now.tv_nsec / 1000 +
> (uint64_t)now.tv_sec * 1000000; \ low = usecs & 0xffffffff;
> 					   \ high = usecs >>
> 32;							   \ diff
> --git a/sysdeps/unix/sysv/linux/alpha/osf_gettimeofday.c
> b/sysdeps/unix/sysv/linux/alpha/osf_gettimeofday.c index
> 8cf5d303f9..5075ae0444 100644 ---
> a/sysdeps/unix/sysv/linux/alpha/osf_gettimeofday.c +++
> b/sysdeps/unix/sysv/linux/alpha/osf_gettimeofday.c @@ -35,8 +35,8 @@
> __gettimeofday_tv32 (struct __timeval32 *restrict tv32, void
> *restrict tz) if (__glibc_unlikely (tz != 0)) memset (tz, 0, sizeof
> (struct timezone)); 
> -  struct timespec ts;
> -  __clock_gettime (CLOCK_REALTIME, &ts);
> +  struct __timespec64 ts;
> +  __clock_gettime64 (CLOCK_REALTIME, &ts);
>  
>    *tv32 = valid_timespec_to_timeval32 (ts);
>    return 0;
> diff --git a/sysdeps/unix/sysv/linux/clock.c
> b/sysdeps/unix/sysv/linux/clock.c index 24a8df0cf5..157ae8eb3f 100644
> --- a/sysdeps/unix/sysv/linux/clock.c
> +++ b/sysdeps/unix/sysv/linux/clock.c
> @@ -23,15 +23,12 @@
>  clock_t
>  clock (void)
>  {
> -  struct timespec ts;
> +  struct __timespec64 ts;
>  
>    _Static_assert (CLOCKS_PER_SEC == 1000000,
>  		  "CLOCKS_PER_SEC should be 1000000");
>  
> -  /* clock_gettime shouldn't fail here since
> CLOCK_PROCESS_CPUTIME_ID is
> -     supported since 2.6.12.  Check the return value anyway in case
> the kernel
> -     barfs on us for some reason.  */
> -  if (__glibc_unlikely (__clock_gettime (CLOCK_PROCESS_CPUTIME_ID,
> &ts) != 0))
> +  if (__glibc_unlikely (__clock_gettime64 (CLOCK_PROCESS_CPUTIME_ID,
> &ts) != 0)) return (clock_t) -1;
>  
>    return (ts.tv_sec * CLOCKS_PER_SEC




Best regards,

Lukasz Majewski

--

DENX Software Engineering GmbH,      Managing Director: Wolfgang Denk
HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany
Phone: (+49)-8142-66989-59 Fax: (+49)-8142-66989-80 Email: lukma@denx.de
  
Andreas Schwab May 20, 2020, 10:29 a.m. UTC | #2
On Mai 05 2020, Lukasz Majewski wrote:

> The __clock_gettime internal function is not supporting 64 bit time on
> architectures with __WORDSIZE == 32 and __TIMESIZE != 64 (like e.g. ARM 32
> bit).
>
> The __clock_gettime64 function shall be used instead in the glibc itself as
> it supports 64 bit time on those systems.
> This patch does not bring any changes to systems with __WORDSIZE == 64 as
> for them the __clock_gettime64 is aliased to __clock_gettime (in
> ./include/time.h).

Ok.

> diff --git a/nis/nis_call.c b/nis/nis_call.c
> index 92c70e97aa..da4c52bdcd 100644
> --- a/nis/nis_call.c
> +++ b/nis/nis_call.c
> @@ -575,7 +575,7 @@ static struct nis_server_cache
>    unsigned int size;
>    unsigned int server_used;
>    unsigned int current_ep;
> -  time_t expires;
> +  __time64_t expires;
>    char name[];
>  } *nis_server_cache[16];
>  static time_t nis_cold_start_mtime;

This will need to be promoted to __time64_t eventually (but not in this
patch).

Andreas.
  
H.J. Lu May 21, 2020, 1:09 a.m. UTC | #3
On Tue, May 5, 2020 at 11:21 AM Lukasz Majewski <lukma@denx.de> wrote:
>
> The __clock_gettime internal function is not supporting 64 bit time on
> architectures with __WORDSIZE == 32 and __TIMESIZE != 64 (like e.g. ARM 32
> bit).
>
> The __clock_gettime64 function shall be used instead in the glibc itself as
> it supports 64 bit time on those systems.
> This patch does not bring any changes to systems with __WORDSIZE == 64 as
> for them the __clock_gettime64 is aliased to __clock_gettime (in
> ./include/time.h).
>
> ---
> Changes for v3:
> - Fix the commit message (add missing "function" after __clock_gettime64)
> - Refactor __nisfind_server() function to support 64 bit time
>   with struct timespec instead of struct timeval
> - Change expires to __time64_t
>
> Changes for v2:
> - Use only TIMESPEC_TO_TIMEVAL instead of valid_timespec64_to_timeval in
>   logout.c and logwtmp.c as it is generic enough to also support struct
>   __timespec64 conversion to struct timeval
> ---
>  benchtests/bench-timing.h                        |  2 +-
>  include/random-bits.h                            |  4 ++--
>  login/logout.c                                   |  4 ++--
>  login/logwtmp.c                                  |  5 +++--
>  nis/nis_call.c                                   | 16 +++++++---------
>  sysdeps/generic/hp-timing.h                      |  4 ++--
>  sysdeps/generic/memusage.h                       |  4 ++--
>  sysdeps/unix/sysv/linux/alpha/osf_gettimeofday.c |  4 ++--
>  sysdeps/unix/sysv/linux/clock.c                  |  7 ++-----
>  9 files changed, 23 insertions(+), 27 deletions(-)
>

Does this patch work with "make bench" when sysdeps/generic/hp-timing.h is used,
like on arm?  I got
In file included from ./bench-timing.h:23,
                 from ./bench-skeleton.c:25,
                 from
/export/build/gnu/tools-build/glibc-gitlab/build-x86_64-linux/benchtests/bench-rint.c:45:
./bench-skeleton.c: In function ‘main’:
../sysdeps/generic/hp-timing.h:37:23: error: storage size of ‘tv’ isn’t known
   37 |   struct __timespec64 tv;      \
      |                       ^~
./bench-timing.h:35:25: note: in expansion of macro ‘HP_TIMING_NOW’
   35 | #define TIMING_NOW(var) HP_TIMING_NOW (var)
      |                         ^~~~~~~~~~~~~
./bench-skeleton.c:82:8: note: in expansion of macro ‘TIMING_NOW’
   82 |        TIMING_NOW (start);
      |        ^~~~~~~~~~
../sysdeps/generic/hp-timing.h:38:3: error: implicit declaration of
function ‘__clock_gettime64’; did you mean ‘clock_gettime’?
[-Werror=implicit-function-declaration]
   38 |   __clock_gettime64 (CLOCK_MONOTONIC, &tv);   \
      |   ^~~~~~~~~~~~~~~~~
./bench-timing.h:35:25: note: in expansion of macro ‘HP_TIMING_NOW’
   35 | #define TIMING_NOW(var) HP_TIMING_NOW (var)
      |                         ^~~~~~~~~~~~~
./bench-skeleton.c:82:8: note: in expansion of macro ‘TIMING_NOW’
   82 |        TIMING_NOW (start);
      |        ^~~~~~~~~~
../sysdeps/generic/hp-timing.h:37:23: error: unused variable ‘tv’
[-Werror=unused-variable]
   37 |   struct __timespec64 tv;      \
      |                       ^~
./bench-timing.h:35:25: note: in expansion of macro ‘HP_TIMING_NOW’
   35 | #define TIMING_NOW(var) HP_TIMING_NOW (var)
      |                         ^~~~~~~~~~~~~
./bench-skeleton.c:82:8: note: in expansion of macro ‘TIMING_NOW’
   82 |        TIMING_NOW (start);
      |        ^~~~~~~~~~
../sysdeps/generic/hp-timing.h:37:23: error: storage size of ‘tv’ isn’t known
   37 |   struct __timespec64 tv;      \
      |                       ^~
./bench-timing.h:35:25: note: in expansion of macro ‘HP_TIMING_NOW’
   35 | #define TIMING_NOW(var) HP_TIMING_NOW (var)
      |                         ^~~~~~~~~~~~~
./bench-skeleton.c:86:8: note: in expansion of macro ‘TIMING_NOW’
   86 |        TIMING_NOW (end);
      |        ^~~~~~~~~~
../sysdeps/generic/hp-timing.h:37:23: error: unused variable ‘tv’
[-Werror=unused-variable]
   37 |   struct __timespec64 tv;      \
      |                       ^~
./bench-timing.h:35:25: note: in expansion of macro ‘HP_TIMING_NOW’
   35 | #define TIMING_NOW(var) HP_TIMING_NOW (var)
      |                         ^~~~~~~~~~~~~
./bench-skeleton.c:86:8: note: in expansion of macro ‘TIMING_NOW’
   86 |        TIMING_NOW (end);
      |        ^~~~~~~~~~
../sysdeps/generic/hp-timing.h:37:23: error: storage size of ‘tv’ isn’t known
   37 |   struct __timespec64 tv;      \
      |                       ^~
./bench-timing.h:35:25: note: in expansion of macro ‘HP_TIMING_NOW’
   35 | #define TIMING_NOW(var) HP_TIMING_NOW (var)
      |                         ^~~~~~~~~~~~~
./bench-skeleton.c:90:8: note: in expansion of macro ‘TIMING_NOW’
   90 |        TIMING_NOW (start);
      |        ^~~~~~~~~~
../sysdeps/generic/hp-timing.h:37:23: error: unused variable ‘tv’
[-Werror=unused-variable]
   37 |   struct __timespec64 tv;      \
      |                       ^~
./bench-timing.h:35:25: note: in expansion of macro ‘HP_TIMING_NOW’
   35 | #define TIMING_NOW(var) HP_TIMING_NOW (var)
      |                         ^~~~~~~~~~~~~
./bench-skeleton.c:90:8: note: in expansion of macro ‘TIMING_NOW’
   90 |        TIMING_NOW (start);
      |        ^~~~~~~~~~
../sysdeps/generic/hp-timing.h:37:23: error: storage size of ‘tv’ isn’t known
   37 |   struct __timespec64 tv;      \
      |                       ^~
./bench-timing.h:35:25: note: in expansion of macro ‘HP_TIMING_NOW’
   35 | #define TIMING_NOW(var) HP_TIMING_NOW (var)
      |                         ^~~~~~~~~~~~~
./bench-skeleton.c:94:8: note: in expansion of macro ‘TIMING_NOW’
   94 |        TIMING_NOW (end);
      |        ^~~~~~~~~~
../sysdeps/generic/hp-timing.h:37:23: error: unused variable ‘tv’
[-Werror=unused-variable]
   37 |   struct __timespec64 tv;      \
      |                       ^~
./bench-timing.h:35:25: note: in expansion of macro ‘HP_TIMING_NOW’
   35 | #define TIMING_NOW(var) HP_TIMING_NOW (var)
      |                         ^~~~~~~~~~~~~
./bench-skeleton.c:94:8: note: in expansion of macro ‘TIMING_NOW’
   94 |        TIMING_NOW (end);
      |        ^~~~~~~~~~
../sysdeps/generic/hp-timing.h:37:23: error: storage size of ‘tv’ isn’t known
   37 |   struct __timespec64 tv;      \
      |                       ^~
./bench-timing.h:35:25: note: in expansion of macro ‘HP_TIMING_NOW’
   35 | #define TIMING_NOW(var) HP_TIMING_NOW (var)
      |                         ^~~~~~~~~~~~~
./bench-skeleton.c:103:3: note: in expansion of macro ‘TIMING_NOW’
  103 |   TIMING_NOW (start);
      |   ^~~~~~~~~~
../sysdeps/generic/hp-timing.h:37:23: error: unused variable ‘tv’
[-Werror=unused-variable]
   37 |   struct __timespec64 tv;      \
      |                       ^~
./bench-timing.h:35:25: note: in expansion of macro ‘HP_TIMING_NOW’
   35 | #define TIMING_NOW(var) HP_TIMING_NOW (var)
      |                         ^~~~~~~~~~~~~
./bench-skeleton.c:103:3: note: in expansion of macro ‘TIMING_NOW’
  103 |   TIMING_NOW (start);
      |   ^~~~~~~~~~
../sysdeps/generic/hp-timing.h:37:23: error: storage size of ‘tv’ isn’t known
   37 |   struct __timespec64 tv;      \
      |                       ^~
./bench-timing.h:35:25: note: in expansion of macro ‘HP_TIMING_NOW’
   35 | #define TIMING_NOW(var) HP_TIMING_NOW (var)
      |                         ^~~~~~~~~~~~~
./bench-skeleton.c:106:3: note: in expansion of macro ‘TIMING_NOW’
  106 |   TIMING_NOW (end);
      |   ^~~~~~~~~~
../sysdeps/generic/hp-timing.h:37:23: error: unused variable ‘tv’
[-Werror=unused-variable]
   37 |   struct __timespec64 tv;      \
      |                       ^~
./bench-timing.h:35:25: note: in expansion of macro ‘HP_TIMING_NOW’
   35 | #define TIMING_NOW(var) HP_TIMING_NOW (var)
      |                         ^~~~~~~~~~~~~
./bench-skeleton.c:106:3: note: in expansion of macro ‘TIMING_NOW’
  106 |   TIMING_NOW (end);
      |   ^~~~~~~~~~
cc1: all warnings being treated as errors
  
Lukasz Majewski May 21, 2020, 10:24 a.m. UTC | #4
Hi "H.J. Lu",

> On Tue, May 5, 2020 at 11:21 AM Lukasz Majewski <lukma@denx.de> wrote:
> >
> > The __clock_gettime internal function is not supporting 64 bit time
> > on architectures with __WORDSIZE == 32 and __TIMESIZE != 64 (like
> > e.g. ARM 32 bit).
> >
> > The __clock_gettime64 function shall be used instead in the glibc
> > itself as it supports 64 bit time on those systems.
> > This patch does not bring any changes to systems with __WORDSIZE ==
> > 64 as for them the __clock_gettime64 is aliased to __clock_gettime
> > (in ./include/time.h).
> >
> > ---
> > Changes for v3:
> > - Fix the commit message (add missing "function" after
> > __clock_gettime64)
> > - Refactor __nisfind_server() function to support 64 bit time
> >   with struct timespec instead of struct timeval
> > - Change expires to __time64_t
> >
> > Changes for v2:
> > - Use only TIMESPEC_TO_TIMEVAL instead of
> > valid_timespec64_to_timeval in logout.c and logwtmp.c as it is
> > generic enough to also support struct __timespec64 conversion to
> > struct timeval ---
> >  benchtests/bench-timing.h                        |  2 +-
> >  include/random-bits.h                            |  4 ++--
> >  login/logout.c                                   |  4 ++--
> >  login/logwtmp.c                                  |  5 +++--
> >  nis/nis_call.c                                   | 16
> > +++++++--------- sysdeps/generic/hp-timing.h                      |
> >  4 ++-- sysdeps/generic/memusage.h                       |  4 ++--
> >  sysdeps/unix/sysv/linux/alpha/osf_gettimeofday.c |  4 ++--
> >  sysdeps/unix/sysv/linux/clock.c                  |  7 ++-----
> >  9 files changed, 23 insertions(+), 27 deletions(-)
> >  
> 
> Does this patch work with "make bench" when
> sysdeps/generic/hp-timing.h is used, like on arm?  I got
> In file included from ./bench-timing.h:23,
>                  from ./bench-skeleton.c:25,
>                  from
> /export/build/gnu/tools-build/glibc-gitlab/build-x86_64-linux/benchtests/bench-rint.c:45:
> ./bench-skeleton.c: In function ‘main’:
> ../sysdeps/generic/hp-timing.h:37:23: error: storage size of ‘tv’
> isn’t known 37 |   struct __timespec64 tv;      \
>       |                       ^~
> ./bench-timing.h:35:25: note: in expansion of macro ‘HP_TIMING_NOW’
>    35 | #define TIMING_NOW(var) HP_TIMING_NOW (var)
>       |                         ^~~~~~~~~~~~~
> ./bench-skeleton.c:82:8: note: in expansion of macro ‘TIMING_NOW’
>    82 |        TIMING_NOW (start);
>       |        ^~~~~~~~~~
> ../sysdeps/generic/hp-timing.h:38:3: error: implicit declaration of
> function ‘__clock_gettime64’; did you mean ‘clock_gettime’?
> [-Werror=implicit-function-declaration]
>    38 |   __clock_gettime64 (CLOCK_MONOTONIC, &tv);   \
>       |   ^~~~~~~~~~~~~~~~~
> ./bench-timing.h:35:25: note: in expansion of macro ‘HP_TIMING_NOW’
>    35 | #define TIMING_NOW(var) HP_TIMING_NOW (var)
>       |                         ^~~~~~~~~~~~~
> ./bench-skeleton.c:82:8: note: in expansion of macro ‘TIMING_NOW’
>    82 |        TIMING_NOW (start);
>       |        ^~~~~~~~~~
> ../sysdeps/generic/hp-timing.h:37:23: error: unused variable ‘tv’
> [-Werror=unused-variable]
>    37 |   struct __timespec64 tv;      \
>       |                       ^~
> ./bench-timing.h:35:25: note: in expansion of macro ‘HP_TIMING_NOW’
>    35 | #define TIMING_NOW(var) HP_TIMING_NOW (var)
>       |                         ^~~~~~~~~~~~~
> ./bench-skeleton.c:82:8: note: in expansion of macro ‘TIMING_NOW’
>    82 |        TIMING_NOW (start);
>       |        ^~~~~~~~~~
> ../sysdeps/generic/hp-timing.h:37:23: error: storage size of ‘tv’
> isn’t known 37 |   struct __timespec64 tv;      \
>       |                       ^~
> ./bench-timing.h:35:25: note: in expansion of macro ‘HP_TIMING_NOW’
>    35 | #define TIMING_NOW(var) HP_TIMING_NOW (var)
>       |                         ^~~~~~~~~~~~~
> ./bench-skeleton.c:86:8: note: in expansion of macro ‘TIMING_NOW’
>    86 |        TIMING_NOW (end);
>       |        ^~~~~~~~~~
> ../sysdeps/generic/hp-timing.h:37:23: error: unused variable ‘tv’
> [-Werror=unused-variable]
>    37 |   struct __timespec64 tv;      \
>       |                       ^~
> ./bench-timing.h:35:25: note: in expansion of macro ‘HP_TIMING_NOW’
>    35 | #define TIMING_NOW(var) HP_TIMING_NOW (var)
>       |                         ^~~~~~~~~~~~~
> ./bench-skeleton.c:86:8: note: in expansion of macro ‘TIMING_NOW’
>    86 |        TIMING_NOW (end);
>       |        ^~~~~~~~~~
> ../sysdeps/generic/hp-timing.h:37:23: error: storage size of ‘tv’
> isn’t known 37 |   struct __timespec64 tv;      \
>       |                       ^~
> ./bench-timing.h:35:25: note: in expansion of macro ‘HP_TIMING_NOW’
>    35 | #define TIMING_NOW(var) HP_TIMING_NOW (var)
>       |                         ^~~~~~~~~~~~~
> ./bench-skeleton.c:90:8: note: in expansion of macro ‘TIMING_NOW’
>    90 |        TIMING_NOW (start);
>       |        ^~~~~~~~~~
> ../sysdeps/generic/hp-timing.h:37:23: error: unused variable ‘tv’
> [-Werror=unused-variable]
>    37 |   struct __timespec64 tv;      \
>       |                       ^~
> ./bench-timing.h:35:25: note: in expansion of macro ‘HP_TIMING_NOW’
>    35 | #define TIMING_NOW(var) HP_TIMING_NOW (var)
>       |                         ^~~~~~~~~~~~~
> ./bench-skeleton.c:90:8: note: in expansion of macro ‘TIMING_NOW’
>    90 |        TIMING_NOW (start);
>       |        ^~~~~~~~~~
> ../sysdeps/generic/hp-timing.h:37:23: error: storage size of ‘tv’
> isn’t known 37 |   struct __timespec64 tv;      \
>       |                       ^~
> ./bench-timing.h:35:25: note: in expansion of macro ‘HP_TIMING_NOW’
>    35 | #define TIMING_NOW(var) HP_TIMING_NOW (var)
>       |                         ^~~~~~~~~~~~~
> ./bench-skeleton.c:94:8: note: in expansion of macro ‘TIMING_NOW’
>    94 |        TIMING_NOW (end);
>       |        ^~~~~~~~~~
> ../sysdeps/generic/hp-timing.h:37:23: error: unused variable ‘tv’
> [-Werror=unused-variable]
>    37 |   struct __timespec64 tv;      \
>       |                       ^~
> ./bench-timing.h:35:25: note: in expansion of macro ‘HP_TIMING_NOW’
>    35 | #define TIMING_NOW(var) HP_TIMING_NOW (var)
>       |                         ^~~~~~~~~~~~~
> ./bench-skeleton.c:94:8: note: in expansion of macro ‘TIMING_NOW’
>    94 |        TIMING_NOW (end);
>       |        ^~~~~~~~~~
> ../sysdeps/generic/hp-timing.h:37:23: error: storage size of ‘tv’
> isn’t known 37 |   struct __timespec64 tv;      \
>       |                       ^~
> ./bench-timing.h:35:25: note: in expansion of macro ‘HP_TIMING_NOW’
>    35 | #define TIMING_NOW(var) HP_TIMING_NOW (var)
>       |                         ^~~~~~~~~~~~~
> ./bench-skeleton.c:103:3: note: in expansion of macro ‘TIMING_NOW’
>   103 |   TIMING_NOW (start);
>       |   ^~~~~~~~~~
> ../sysdeps/generic/hp-timing.h:37:23: error: unused variable ‘tv’
> [-Werror=unused-variable]
>    37 |   struct __timespec64 tv;      \
>       |                       ^~
> ./bench-timing.h:35:25: note: in expansion of macro ‘HP_TIMING_NOW’
>    35 | #define TIMING_NOW(var) HP_TIMING_NOW (var)
>       |                         ^~~~~~~~~~~~~
> ./bench-skeleton.c:103:3: note: in expansion of macro ‘TIMING_NOW’
>   103 |   TIMING_NOW (start);
>       |   ^~~~~~~~~~
> ../sysdeps/generic/hp-timing.h:37:23: error: storage size of ‘tv’
> isn’t known 37 |   struct __timespec64 tv;      \
>       |                       ^~
> ./bench-timing.h:35:25: note: in expansion of macro ‘HP_TIMING_NOW’
>    35 | #define TIMING_NOW(var) HP_TIMING_NOW (var)
>       |                         ^~~~~~~~~~~~~
> ./bench-skeleton.c:106:3: note: in expansion of macro ‘TIMING_NOW’
>   106 |   TIMING_NOW (end);
>       |   ^~~~~~~~~~
> ../sysdeps/generic/hp-timing.h:37:23: error: unused variable ‘tv’
> [-Werror=unused-variable]
>    37 |   struct __timespec64 tv;      \
>       |                       ^~
> ./bench-timing.h:35:25: note: in expansion of macro ‘HP_TIMING_NOW’
>    35 | #define TIMING_NOW(var) HP_TIMING_NOW (var)
>       |                         ^~~~~~~~~~~~~
> ./bench-skeleton.c:106:3: note: in expansion of macro ‘TIMING_NOW’
>   106 |   TIMING_NOW (end);
>       |   ^~~~~~~~~~
> cc1: all warnings being treated as errors

How shall I reproduce this error?

Was it supposed to be catch with build-many-glibc.py ?


Best regards,

Lukasz Majewski

--

DENX Software Engineering GmbH,      Managing Director: Wolfgang Denk
HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany
Phone: (+49)-8142-66989-59 Fax: (+49)-8142-66989-80 Email: lukma@denx.de
  
H.J. Lu May 21, 2020, 11:11 a.m. UTC | #5
On Thu, May 21, 2020 at 3:24 AM Lukasz Majewski <lukma@denx.de> wrote:
>
> Hi "H.J. Lu",
>
> > On Tue, May 5, 2020 at 11:21 AM Lukasz Majewski <lukma@denx.de> wrote:
> > >
> > > The __clock_gettime internal function is not supporting 64 bit time
> > > on architectures with __WORDSIZE == 32 and __TIMESIZE != 64 (like
> > > e.g. ARM 32 bit).
> > >
> > > The __clock_gettime64 function shall be used instead in the glibc
> > > itself as it supports 64 bit time on those systems.
> > > This patch does not bring any changes to systems with __WORDSIZE ==
> > > 64 as for them the __clock_gettime64 is aliased to __clock_gettime
> > > (in ./include/time.h).
> > >
> > > ---
> > > Changes for v3:
> > > - Fix the commit message (add missing "function" after
> > > __clock_gettime64)
> > > - Refactor __nisfind_server() function to support 64 bit time
> > >   with struct timespec instead of struct timeval
> > > - Change expires to __time64_t
> > >
> > > Changes for v2:
> > > - Use only TIMESPEC_TO_TIMEVAL instead of
> > > valid_timespec64_to_timeval in logout.c and logwtmp.c as it is
> > > generic enough to also support struct __timespec64 conversion to
> > > struct timeval ---
> > >  benchtests/bench-timing.h                        |  2 +-
> > >  include/random-bits.h                            |  4 ++--
> > >  login/logout.c                                   |  4 ++--
> > >  login/logwtmp.c                                  |  5 +++--
> > >  nis/nis_call.c                                   | 16
> > > +++++++--------- sysdeps/generic/hp-timing.h                      |
> > >  4 ++-- sysdeps/generic/memusage.h                       |  4 ++--
> > >  sysdeps/unix/sysv/linux/alpha/osf_gettimeofday.c |  4 ++--
> > >  sysdeps/unix/sysv/linux/clock.c                  |  7 ++-----
> > >  9 files changed, 23 insertions(+), 27 deletions(-)
> > >
> >
> > Does this patch work with "make bench" when
> > sysdeps/generic/hp-timing.h is used, like on arm?  I got
> > In file included from ./bench-timing.h:23,
> >                  from ./bench-skeleton.c:25,
> >                  from
> > /export/build/gnu/tools-build/glibc-gitlab/build-x86_64-linux/benchtests/bench-rint.c:45:
> > ./bench-skeleton.c: In function ‘main’:
> > ../sysdeps/generic/hp-timing.h:37:23: error: storage size of ‘tv’
> > isn’t known 37 |   struct __timespec64 tv;      \
> >       |                       ^~
> > ./bench-timing.h:35:25: note: in expansion of macro ‘HP_TIMING_NOW’
> >    35 | #define TIMING_NOW(var) HP_TIMING_NOW (var)
> >       |                         ^~~~~~~~~~~~~
> > ./bench-skeleton.c:82:8: note: in expansion of macro ‘TIMING_NOW’
> >    82 |        TIMING_NOW (start);
> >       |        ^~~~~~~~~~
> > ../sysdeps/generic/hp-timing.h:38:3: error: implicit declaration of
> > function ‘__clock_gettime64’; did you mean ‘clock_gettime’?
> > [-Werror=implicit-function-declaration]
> >    38 |   __clock_gettime64 (CLOCK_MONOTONIC, &tv);   \
> >       |   ^~~~~~~~~~~~~~~~~
> > ./bench-timing.h:35:25: note: in expansion of macro ‘HP_TIMING_NOW’
> >    35 | #define TIMING_NOW(var) HP_TIMING_NOW (var)
> >       |                         ^~~~~~~~~~~~~
> > ./bench-skeleton.c:82:8: note: in expansion of macro ‘TIMING_NOW’
> >    82 |        TIMING_NOW (start);
> >       |        ^~~~~~~~~~
> > ../sysdeps/generic/hp-timing.h:37:23: error: unused variable ‘tv’
> > [-Werror=unused-variable]
> >    37 |   struct __timespec64 tv;      \
> >       |                       ^~
> > ./bench-timing.h:35:25: note: in expansion of macro ‘HP_TIMING_NOW’
> >    35 | #define TIMING_NOW(var) HP_TIMING_NOW (var)
> >       |                         ^~~~~~~~~~~~~
> > ./bench-skeleton.c:82:8: note: in expansion of macro ‘TIMING_NOW’
> >    82 |        TIMING_NOW (start);
> >       |        ^~~~~~~~~~
> > ../sysdeps/generic/hp-timing.h:37:23: error: storage size of ‘tv’
> > isn’t known 37 |   struct __timespec64 tv;      \
> >       |                       ^~
> > ./bench-timing.h:35:25: note: in expansion of macro ‘HP_TIMING_NOW’
> >    35 | #define TIMING_NOW(var) HP_TIMING_NOW (var)
> >       |                         ^~~~~~~~~~~~~
> > ./bench-skeleton.c:86:8: note: in expansion of macro ‘TIMING_NOW’
> >    86 |        TIMING_NOW (end);
> >       |        ^~~~~~~~~~
> > ../sysdeps/generic/hp-timing.h:37:23: error: unused variable ‘tv’
> > [-Werror=unused-variable]
> >    37 |   struct __timespec64 tv;      \
> >       |                       ^~
> > ./bench-timing.h:35:25: note: in expansion of macro ‘HP_TIMING_NOW’
> >    35 | #define TIMING_NOW(var) HP_TIMING_NOW (var)
> >       |                         ^~~~~~~~~~~~~
> > ./bench-skeleton.c:86:8: note: in expansion of macro ‘TIMING_NOW’
> >    86 |        TIMING_NOW (end);
> >       |        ^~~~~~~~~~
> > ../sysdeps/generic/hp-timing.h:37:23: error: storage size of ‘tv’
> > isn’t known 37 |   struct __timespec64 tv;      \
> >       |                       ^~
> > ./bench-timing.h:35:25: note: in expansion of macro ‘HP_TIMING_NOW’
> >    35 | #define TIMING_NOW(var) HP_TIMING_NOW (var)
> >       |                         ^~~~~~~~~~~~~
> > ./bench-skeleton.c:90:8: note: in expansion of macro ‘TIMING_NOW’
> >    90 |        TIMING_NOW (start);
> >       |        ^~~~~~~~~~
> > ../sysdeps/generic/hp-timing.h:37:23: error: unused variable ‘tv’
> > [-Werror=unused-variable]
> >    37 |   struct __timespec64 tv;      \
> >       |                       ^~
> > ./bench-timing.h:35:25: note: in expansion of macro ‘HP_TIMING_NOW’
> >    35 | #define TIMING_NOW(var) HP_TIMING_NOW (var)
> >       |                         ^~~~~~~~~~~~~
> > ./bench-skeleton.c:90:8: note: in expansion of macro ‘TIMING_NOW’
> >    90 |        TIMING_NOW (start);
> >       |        ^~~~~~~~~~
> > ../sysdeps/generic/hp-timing.h:37:23: error: storage size of ‘tv’
> > isn’t known 37 |   struct __timespec64 tv;      \
> >       |                       ^~
> > ./bench-timing.h:35:25: note: in expansion of macro ‘HP_TIMING_NOW’
> >    35 | #define TIMING_NOW(var) HP_TIMING_NOW (var)
> >       |                         ^~~~~~~~~~~~~
> > ./bench-skeleton.c:94:8: note: in expansion of macro ‘TIMING_NOW’
> >    94 |        TIMING_NOW (end);
> >       |        ^~~~~~~~~~
> > ../sysdeps/generic/hp-timing.h:37:23: error: unused variable ‘tv’
> > [-Werror=unused-variable]
> >    37 |   struct __timespec64 tv;      \
> >       |                       ^~
> > ./bench-timing.h:35:25: note: in expansion of macro ‘HP_TIMING_NOW’
> >    35 | #define TIMING_NOW(var) HP_TIMING_NOW (var)
> >       |                         ^~~~~~~~~~~~~
> > ./bench-skeleton.c:94:8: note: in expansion of macro ‘TIMING_NOW’
> >    94 |        TIMING_NOW (end);
> >       |        ^~~~~~~~~~
> > ../sysdeps/generic/hp-timing.h:37:23: error: storage size of ‘tv’
> > isn’t known 37 |   struct __timespec64 tv;      \
> >       |                       ^~
> > ./bench-timing.h:35:25: note: in expansion of macro ‘HP_TIMING_NOW’
> >    35 | #define TIMING_NOW(var) HP_TIMING_NOW (var)
> >       |                         ^~~~~~~~~~~~~
> > ./bench-skeleton.c:103:3: note: in expansion of macro ‘TIMING_NOW’
> >   103 |   TIMING_NOW (start);
> >       |   ^~~~~~~~~~
> > ../sysdeps/generic/hp-timing.h:37:23: error: unused variable ‘tv’
> > [-Werror=unused-variable]
> >    37 |   struct __timespec64 tv;      \
> >       |                       ^~
> > ./bench-timing.h:35:25: note: in expansion of macro ‘HP_TIMING_NOW’
> >    35 | #define TIMING_NOW(var) HP_TIMING_NOW (var)
> >       |                         ^~~~~~~~~~~~~
> > ./bench-skeleton.c:103:3: note: in expansion of macro ‘TIMING_NOW’
> >   103 |   TIMING_NOW (start);
> >       |   ^~~~~~~~~~
> > ../sysdeps/generic/hp-timing.h:37:23: error: storage size of ‘tv’
> > isn’t known 37 |   struct __timespec64 tv;      \
> >       |                       ^~
> > ./bench-timing.h:35:25: note: in expansion of macro ‘HP_TIMING_NOW’
> >    35 | #define TIMING_NOW(var) HP_TIMING_NOW (var)
> >       |                         ^~~~~~~~~~~~~
> > ./bench-skeleton.c:106:3: note: in expansion of macro ‘TIMING_NOW’
> >   106 |   TIMING_NOW (end);
> >       |   ^~~~~~~~~~
> > ../sysdeps/generic/hp-timing.h:37:23: error: unused variable ‘tv’
> > [-Werror=unused-variable]
> >    37 |   struct __timespec64 tv;      \
> >       |                       ^~
> > ./bench-timing.h:35:25: note: in expansion of macro ‘HP_TIMING_NOW’
> >    35 | #define TIMING_NOW(var) HP_TIMING_NOW (var)
> >       |                         ^~~~~~~~~~~~~
> > ./bench-skeleton.c:106:3: note: in expansion of macro ‘TIMING_NOW’
> >   106 |   TIMING_NOW (end);
> >       |   ^~~~~~~~~~
> > cc1: all warnings being treated as errors
>
> How shall I reproduce this error?

Apply the enclosed patch and do

$ make USE_CLOCK_GETTIME=1 bench

> Was it supposed to be catch with build-many-glibc.py ?
>

No, "make bench" isn't tested by build-many-glibc.py.
  
Andreas Schwab May 25, 2020, 10:57 a.m. UTC | #6
I don't think it make sense for benchtests to define _ISMAC if it uses
glibc internal interfaces.

Andreas.
  
Florian Weimer May 27, 2020, 12:44 p.m. UTC | #7
* Andreas Schwab:

> I don't think it make sense for benchtests to define _ISMAC if it uses
> glibc internal interfaces.

We have some internal interfaces that are available for !_ISOMAC,
e.g. pretty much the entire support/ directory.

I assume this is about <hp-timing.h>?  We could decide that it should be
in this category as well.

Thanks,
Florian
  
H.J. Lu May 27, 2020, 12:47 p.m. UTC | #8
On Wed, May 27, 2020 at 5:44 AM Florian Weimer <fweimer@redhat.com> wrote:
>
> * Andreas Schwab:
>
> > I don't think it make sense for benchtests to define _ISMAC if it uses
> > glibc internal interfaces.
>
> We have some internal interfaces that are available for !_ISOMAC,
> e.g. pretty much the entire support/ directory.
>
> I assume this is about <hp-timing.h>?  We could decide that it should be
> in this category as well.

To be precise, it is sysdeps/generic/hp-timing.h:

#define HP_TIMING_NOW(var) \
({ \
  struct __timespec64 tv; \
  __clock_gettime64 (CLOCK_MONOTONIC, &tv); \
  (var) = (tv.tv_nsec + UINT64_C(1000000000) * tv.tv_sec); \
})
  
Florian Weimer May 27, 2020, 12:50 p.m. UTC | #9
* H. J. Lu:

> On Wed, May 27, 2020 at 5:44 AM Florian Weimer <fweimer@redhat.com> wrote:
>>
>> * Andreas Schwab:
>>
>> > I don't think it make sense for benchtests to define _ISMAC if it uses
>> > glibc internal interfaces.
>>
>> We have some internal interfaces that are available for !_ISOMAC,
>> e.g. pretty much the entire support/ directory.
>>
>> I assume this is about <hp-timing.h>?  We could decide that it should be
>> in this category as well.
>
> To be precise, it is sysdeps/generic/hp-timing.h:
>
> #define HP_TIMING_NOW(var) \
> ({ \
>   struct __timespec64 tv; \
>   __clock_gettime64 (CLOCK_MONOTONIC, &tv); \
>   (var) = (tv.tv_nsec + UINT64_C(1000000000) * tv.tv_sec); \
> })

Okay, then we could add an #ifdef _ISOMAC and use clock_gettime outside
glibc.  Temporarily, until we have clock_gettime64 available outside
glibc, too.

Or would that be too awkward?

Thanks,
Florian
  
H.J. Lu May 28, 2020, 12:28 p.m. UTC | #10
On Wed, May 27, 2020 at 5:50 AM Florian Weimer <fweimer@redhat.com> wrote:
>
> * H. J. Lu:
>
> > On Wed, May 27, 2020 at 5:44 AM Florian Weimer <fweimer@redhat.com> wrote:
> >>
> >> * Andreas Schwab:
> >>
> >> > I don't think it make sense for benchtests to define _ISMAC if it uses
> >> > glibc internal interfaces.
> >>
> >> We have some internal interfaces that are available for !_ISOMAC,
> >> e.g. pretty much the entire support/ directory.
> >>
> >> I assume this is about <hp-timing.h>?  We could decide that it should be
> >> in this category as well.
> >
> > To be precise, it is sysdeps/generic/hp-timing.h:
> >
> > #define HP_TIMING_NOW(var) \
> > ({ \
> >   struct __timespec64 tv; \
> >   __clock_gettime64 (CLOCK_MONOTONIC, &tv); \
> >   (var) = (tv.tv_nsec + UINT64_C(1000000000) * tv.tv_sec); \
> > })
>
> Okay, then we could add an #ifdef _ISOMAC and use clock_gettime outside
> glibc.  Temporarily, until we have clock_gettime64 available outside
> glibc, too.
>

Like this?
  
Florian Weimer May 28, 2020, 12:58 p.m. UTC | #11
* H. J. Lu via Libc-alpha:

> diff --git a/sysdeps/generic/hp-timing.h b/sysdeps/generic/hp-timing.h
> index af9d92f7f7..99b12995f1 100644
> --- a/sysdeps/generic/hp-timing.h
> +++ b/sysdeps/generic/hp-timing.h
> @@ -24,6 +24,11 @@
>  #include <stdint.h>
>  #include <hp-timing-common.h>
>  
> +#ifdef _ISOMAC
> +# define __timespec64 timespec
> +# define __clock_gettime64 clock_gettime
> +#endif
> +
>  /* It should not be used for ld.so.  */
>  #define HP_TIMING_INLINE	(0)

To be honest, I would have expected different definitions of the timing
macros.  This redirection looks a bit iffy for me for _ISOMAC.

Thanks,
Florian
  
H.J. Lu May 28, 2020, 1:07 p.m. UTC | #12
On Thu, May 28, 2020 at 5:58 AM Florian Weimer <fweimer@redhat.com> wrote:
>
> * H. J. Lu via Libc-alpha:
>
> > diff --git a/sysdeps/generic/hp-timing.h b/sysdeps/generic/hp-timing.h
> > index af9d92f7f7..99b12995f1 100644
> > --- a/sysdeps/generic/hp-timing.h
> > +++ b/sysdeps/generic/hp-timing.h
> > @@ -24,6 +24,11 @@
> >  #include <stdint.h>
> >  #include <hp-timing-common.h>
> >
> > +#ifdef _ISOMAC
> > +# define __timespec64 timespec
> > +# define __clock_gettime64 clock_gettime
> > +#endif
> > +
> >  /* It should not be used for ld.so.  */
> >  #define HP_TIMING_INLINE     (0)
>
> To be honest, I would have expected different definitions of the timing
> macros.  This redirection looks a bit iffy for me for _ISOMAC.

What do you have in mind?
  
Florian Weimer May 28, 2020, 2:28 p.m. UTC | #13
* H. J. Lu:

> On Thu, May 28, 2020 at 5:58 AM Florian Weimer <fweimer@redhat.com> wrote:
>>
>> * H. J. Lu via Libc-alpha:
>>
>> > diff --git a/sysdeps/generic/hp-timing.h b/sysdeps/generic/hp-timing.h
>> > index af9d92f7f7..99b12995f1 100644
>> > --- a/sysdeps/generic/hp-timing.h
>> > +++ b/sysdeps/generic/hp-timing.h
>> > @@ -24,6 +24,11 @@
>> >  #include <stdint.h>
>> >  #include <hp-timing-common.h>
>> >
>> > +#ifdef _ISOMAC
>> > +# define __timespec64 timespec
>> > +# define __clock_gettime64 clock_gettime
>> > +#endif
>> > +
>> >  /* It should not be used for ld.so.  */
>> >  #define HP_TIMING_INLINE     (0)
>>
>> To be honest, I would have expected different definitions of the timing
>> macros.  This redirection looks a bit iffy for me for _ISOMAC.
>
> What do you have in mind?

Something like this:

/* The clock_gettime (CLOCK_MONOTONIC) has unspecified starting time,
   nano-second accuracy, and for some architectues is implemented as
   vDSO symbol.  */
#ifdef _ISOMAC
# define HP_TIMING_NOW(var) \
({								\
  struct timespec tv;						\
  clock_gettime (CLOCK_MONOTONIC, &tv);				\
  (var) = (tv.tv_nsec + UINT64_C(1000000000) * tv.tv_sec);	\
})
#else
# define HP_TIMING_NOW(var) \
({								\
  struct __timespec64 tv;					\
  __clock_gettime64 (CLOCK_MONOTONIC, &tv);			\
  (var) = (tv.tv_nsec + UINT64_C(1000000000) * tv.tv_sec);	\
})
#endif

in sysdeps/generic/hp-timing.h.

Thanks,
Florian
  

Patch

diff --git a/benchtests/bench-timing.h b/benchtests/bench-timing.h
index 5b9a8384bb..a0d6f82465 100644
--- a/benchtests/bench-timing.h
+++ b/benchtests/bench-timing.h
@@ -18,7 +18,7 @@ 
 
 #undef attribute_hidden
 #define attribute_hidden
-#define __clock_gettime clock_gettime
+#define __clock_gettime __clock_gettime64
 #include <hp-timing.h>
 #include <stdint.h>
 
diff --git a/include/random-bits.h b/include/random-bits.h
index fd3fa01f9b..7561e55ca6 100644
--- a/include/random-bits.h
+++ b/include/random-bits.h
@@ -30,8 +30,8 @@ 
 static inline uint32_t
 random_bits (void)
 {
-  struct timespec tv;
-  __clock_gettime (CLOCK_MONOTONIC, &tv);
+  struct __timespec64 tv;
+  __clock_gettime64 (CLOCK_MONOTONIC, &tv);
   /* Shuffle the lower bits to minimize the clock bias.  */
   uint32_t ret = tv.tv_nsec ^ tv.tv_sec;
   ret ^= (ret << 24) | (ret >> 8);
diff --git a/login/logout.c b/login/logout.c
index 7653fe8886..091312eb1d 100644
--- a/login/logout.c
+++ b/login/logout.c
@@ -47,8 +47,8 @@  logout (const char *line)
       memset (ut->ut_name, '\0', sizeof ut->ut_name);
       memset (ut->ut_host, '\0', sizeof ut->ut_host);
 
-      struct timespec ts;
-      __clock_gettime (CLOCK_REALTIME, &ts);
+      struct __timespec64 ts;
+      __clock_gettime64 (CLOCK_REALTIME, &ts);
       TIMESPEC_TO_TIMEVAL (&ut->ut_tv, &ts);
       ut->ut_type = DEAD_PROCESS;
 
diff --git a/login/logwtmp.c b/login/logwtmp.c
index 90406acc3d..050219c153 100644
--- a/login/logwtmp.c
+++ b/login/logwtmp.c
@@ -21,6 +21,7 @@ 
 #include <time.h>
 #include <unistd.h>
 #include <utmp.h>
+#include <struct___timespec64.h>
 
 
 void
@@ -36,8 +37,8 @@  logwtmp (const char *line, const char *name, const char *host)
   strncpy (ut.ut_name, name, sizeof ut.ut_name);
   strncpy (ut.ut_host, host, sizeof ut.ut_host);
 
-  struct timespec ts;
-  __clock_gettime (CLOCK_REALTIME, &ts);
+  struct __timespec64 ts;
+  __clock_gettime64 (CLOCK_REALTIME, &ts);
   TIMESPEC_TO_TIMEVAL (&ut.ut_tv, &ts);
 
   updwtmp (_PATH_WTMP, &ut);
diff --git a/nis/nis_call.c b/nis/nis_call.c
index 92c70e97aa..da4c52bdcd 100644
--- a/nis/nis_call.c
+++ b/nis/nis_call.c
@@ -575,7 +575,7 @@  static struct nis_server_cache
   unsigned int size;
   unsigned int server_used;
   unsigned int current_ep;
-  time_t expires;
+  __time64_t expires;
   char name[];
 } *nis_server_cache[16];
 static time_t nis_cold_start_mtime;
@@ -584,7 +584,7 @@  __libc_lock_define_initialized (static, nis_server_cache_lock)
 static directory_obj *
 nis_server_cache_search (const_nis_name name, int search_parent,
 			 unsigned int *server_used, unsigned int *current_ep,
-			 struct timeval *now)
+			 struct __timespec64 *now)
 {
   directory_obj *ret = NULL;
   int i;
@@ -642,7 +642,7 @@  nis_server_cache_search (const_nis_name name, int search_parent,
 static void
 nis_server_cache_add (const_nis_name name, int search_parent,
 		      directory_obj *dir, unsigned int server_used,
-		      unsigned int current_ep, struct timeval *now)
+		      unsigned int current_ep, struct __timespec64 *now)
 {
   struct nis_server_cache **loc;
   struct nis_server_cache *new;
@@ -708,8 +708,7 @@  __nisfind_server (const_nis_name name, int search_parent,
   nis_error result = NIS_SUCCESS;
   nis_error status;
   directory_obj *obj;
-  struct timeval now;
-  struct timespec ts;
+  struct __timespec64 ts;
   unsigned int server_used = ~0;
   unsigned int current_ep = ~0;
 
@@ -719,12 +718,11 @@  __nisfind_server (const_nis_name name, int search_parent,
   if (*dir != NULL)
     return NIS_SUCCESS;
 
-  __clock_gettime (CLOCK_REALTIME, &ts);
-  TIMESPEC_TO_TIMEVAL (&now, &ts);
+  __clock_gettime64 (CLOCK_REALTIME, &ts);
 
   if ((flags & NO_CACHE) == 0)
     *dir = nis_server_cache_search (name, search_parent, &server_used,
-				    &current_ep, &now);
+				    &current_ep, &ts);
   if (*dir != NULL)
     {
       unsigned int server_len = (*dir)->do_servers.do_servers_len;
@@ -783,7 +781,7 @@  __nisfind_server (const_nis_name name, int search_parent,
 	    }
 	  if ((flags & NO_CACHE) == 0)
 	    nis_server_cache_add (name, search_parent, obj,
-				  server_used, current_ep, &now);
+				  server_used, current_ep, &ts);
 	}
       else
 	{
diff --git a/sysdeps/generic/hp-timing.h b/sysdeps/generic/hp-timing.h
index e2d7447212..af9d92f7f7 100644
--- a/sysdeps/generic/hp-timing.h
+++ b/sysdeps/generic/hp-timing.h
@@ -34,8 +34,8 @@  typedef uint64_t hp_timing_t;
    vDSO symbol.  */
 #define HP_TIMING_NOW(var) \
 ({								\
-  struct timespec tv;						\
-  __clock_gettime (CLOCK_MONOTONIC, &tv);			\
+  struct __timespec64 tv;						\
+  __clock_gettime64 (CLOCK_MONOTONIC, &tv);			\
   (var) = (tv.tv_nsec + UINT64_C(1000000000) * tv.tv_sec);	\
 })
 
diff --git a/sysdeps/generic/memusage.h b/sysdeps/generic/memusage.h
index a111864b0b..91e56d24de 100644
--- a/sysdeps/generic/memusage.h
+++ b/sysdeps/generic/memusage.h
@@ -28,9 +28,9 @@ 
 #ifndef GETTIME
 # define GETTIME(low,high)						   \
   {									   \
-    struct timespec now;						   \
+    struct __timespec64 now;						   \
     uint64_t usecs;							   \
-    clock_gettime (CLOCK_REALTIME, &now);				   \
+    __clock_gettime64 (CLOCK_REALTIME, &now);				   \
     usecs = (uint64_t)now.tv_nsec / 1000 + (uint64_t)now.tv_sec * 1000000; \
     low = usecs & 0xffffffff;						   \
     high = usecs >> 32;							   \
diff --git a/sysdeps/unix/sysv/linux/alpha/osf_gettimeofday.c b/sysdeps/unix/sysv/linux/alpha/osf_gettimeofday.c
index 8cf5d303f9..5075ae0444 100644
--- a/sysdeps/unix/sysv/linux/alpha/osf_gettimeofday.c
+++ b/sysdeps/unix/sysv/linux/alpha/osf_gettimeofday.c
@@ -35,8 +35,8 @@  __gettimeofday_tv32 (struct __timeval32 *restrict tv32, void *restrict tz)
   if (__glibc_unlikely (tz != 0))
     memset (tz, 0, sizeof (struct timezone));
 
-  struct timespec ts;
-  __clock_gettime (CLOCK_REALTIME, &ts);
+  struct __timespec64 ts;
+  __clock_gettime64 (CLOCK_REALTIME, &ts);
 
   *tv32 = valid_timespec_to_timeval32 (ts);
   return 0;
diff --git a/sysdeps/unix/sysv/linux/clock.c b/sysdeps/unix/sysv/linux/clock.c
index 24a8df0cf5..157ae8eb3f 100644
--- a/sysdeps/unix/sysv/linux/clock.c
+++ b/sysdeps/unix/sysv/linux/clock.c
@@ -23,15 +23,12 @@ 
 clock_t
 clock (void)
 {
-  struct timespec ts;
+  struct __timespec64 ts;
 
   _Static_assert (CLOCKS_PER_SEC == 1000000,
 		  "CLOCKS_PER_SEC should be 1000000");
 
-  /* clock_gettime shouldn't fail here since CLOCK_PROCESS_CPUTIME_ID is
-     supported since 2.6.12.  Check the return value anyway in case the kernel
-     barfs on us for some reason.  */
-  if (__glibc_unlikely (__clock_gettime (CLOCK_PROCESS_CPUTIME_ID, &ts) != 0))
+  if (__glibc_unlikely (__clock_gettime64 (CLOCK_PROCESS_CPUTIME_ID, &ts) != 0))
     return (clock_t) -1;
 
   return (ts.tv_sec * CLOCKS_PER_SEC