Skip to content

Commit

Permalink
Always define __USE_TIME_BITS64 when 64 bit time_t is used
Browse files Browse the repository at this point in the history
It was raised on libc-help [1] that some Linux kernel interfaces expect
the libc to define __USE_TIME_BITS64 to indicate the time_t size for the
kABI.  Different than defined by the initial y2038 design document [2],
the __USE_TIME_BITS64 is only defined for ABIs that support more than
one time_t size (by defining the _TIME_BITS for each module).

The 64 bit time_t redirects are now enabled using a different internal
define (__USE_TIME64_REDIRECTS). There is no expected change in semantic
or code generation.

Checked on x86_64-linux-gnu, i686-linux-gnu, aarch64-linux-gnu, and
arm-linux-gnueabi

[1] https://sourceware.org/pipermail/libc-help/2024-January/006557.html
[2] https://sourceware.org/glibc/wiki/Y2038ProofnessDesign

Reviewed-by: DJ Delorie <dj@redhat.com>
  • Loading branch information
zatrazz committed Apr 2, 2024
1 parent a0698a5 commit a4ed047
Show file tree
Hide file tree
Showing 75 changed files with 178 additions and 182 deletions.
2 changes: 1 addition & 1 deletion io/bits/poll2.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ poll (__fortify_clang_overload_arg (struct pollfd *, ,__fds), nfds_t __nfds,


#ifdef __USE_GNU
# ifdef __USE_TIME_BITS64
# ifdef __USE_TIME64_REDIRECTS
extern int __REDIRECT (__ppoll64_alias, (struct pollfd *__fds, nfds_t __nfds,
const struct timespec *__timeout,
const __sigset_t *__ss), __ppoll64);
Expand Down
4 changes: 2 additions & 2 deletions io/fcntl.h
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ typedef __pid_t pid_t;
This function is a cancellation point and therefore not marked with
__THROW. */
#ifndef __USE_TIME_BITS64
#ifndef __USE_TIME64_REDIRECTS
# ifndef __USE_FILE_OFFSET64
extern int fcntl (int __fd, int __cmd, ...);
# else
Expand All @@ -185,7 +185,7 @@ extern int __REDIRECT (fcntl, (int __fd, int __cmd, ...), fcntl64);
# ifdef __USE_LARGEFILE64
extern int fcntl64 (int __fd, int __cmd, ...);
# endif
#else /* __USE_TIME_BITS64 */
#else /* __USE_TIME64_REDIRECTS */
# ifdef __REDIRECT
extern int __REDIRECT_NTH (fcntl, (int __fd, int __request, ...),
__fcntl_time64);
Expand Down
6 changes: 3 additions & 3 deletions io/fts.h
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@ FTSENT *fts_read (FTS *);
int fts_set (FTS *, FTSENT *, int) __THROW;
#else
# ifdef __REDIRECT
# ifndef __USE_TIME_BITS64
# ifndef __USE_TIME64_REDIRECTS
FTSENT *__REDIRECT (fts_children, (FTS *, int), fts64_children);
int __REDIRECT (fts_close, (FTS *), fts64_close);
FTS *__REDIRECT (fts_open, (char * const *, int,
Expand All @@ -206,7 +206,7 @@ int __REDIRECT_NTH (fts_set, (FTS *, FTSENT *, int),
__fts64_set_time64);
# endif
# else
# ifndef __USE_TIME_BITS64
# ifndef __USE_TIME64_REDIRECTS
# define fts_children fts64_children
# define fts_close fts64_close
# define fts_open fts64_open
Expand All @@ -217,7 +217,7 @@ int __REDIRECT_NTH (fts_set, (FTS *, FTSENT *, int),
# endif
#endif
#ifdef __USE_LARGEFILE64
# ifndef __USE_TIME_BITS64
# ifndef __USE_TIME64_REDIRECTS
FTSENT64 *fts64_children (FTS64 *, int);
int fts64_close (FTS64 *);
FTS64 *fts64_open (char * const *, int,
Expand Down
12 changes: 6 additions & 6 deletions io/ftw.h
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ extern int ftw (const char *__dir, __ftw_func_t __func, int __descriptors)
__nonnull ((1, 2));
#else
# ifdef __REDIRECT
# ifndef __USE_TIME_BITS64
# ifndef __USE_TIME64_REDIRECTS
extern int __REDIRECT (ftw, (const char *__dir, __ftw_func_t __func,
int __descriptors), ftw64) __nonnull ((1, 2));
# else
Expand All @@ -146,15 +146,15 @@ extern int __REDIRECT (ftw, (const char *__dir, __ftw_func_t __func,
__nonnull ((1, 2));
# endif
# else
# ifndef __USE_TIME_BITS64
# ifndef __USE_TIME64_REDIRECTS
# define ftw ftw64
# else
# define ftw __ftw64_time64
# endif
# endif
#endif
#ifdef __USE_LARGEFILE64
# ifndef __USE_TIME_BITS64
# ifndef __USE_TIME64_REDIRECTS
extern int ftw64 (const char *__dir, __ftw64_func_t __func,
int __descriptors) __nonnull ((1, 2));
# else
Expand All @@ -180,7 +180,7 @@ extern int nftw (const char *__dir, __nftw_func_t __func, int __descriptors,
int __flag) __nonnull ((1, 2));
# else
# ifdef __REDIRECT
# ifndef __USE_TIME_BITS64
# ifndef __USE_TIME64_REDIRECTS
extern int __REDIRECT (nftw, (const char *__dir, __nftw_func_t __func,
int __descriptors, int __flag), nftw64)
__nonnull ((1, 2));
Expand All @@ -190,15 +190,15 @@ extern int __REDIRECT (nftw, (const char *__dir, __nftw_func_t __func,
__nonnull ((1, 2));
# endif
# else
# ifndef __USE_TIME_BITS64
# ifndef __USE_TIME64_REDIRECTS
# define nftw nftw64
# else
# define nftw __nftw64_time64
# endif
# endif
# endif
# ifdef __USE_LARGEFILE64
# ifndef __USE_TIME_BITS64
# ifndef __USE_TIME64_REDIRECTS
extern int nftw64 (const char *__dir, __nftw64_func_t __func,
int __descriptors, int __flag) __nonnull ((1, 2));
# else
Expand Down
2 changes: 1 addition & 1 deletion io/sys/poll.h
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ extern int ppoll (struct pollfd *__fds, nfds_t __nfds,
const __sigset_t *__ss)
__fortified_attr_access (__write_only__, 1, 2);

# ifdef __USE_TIME_BITS64
# ifdef __USE_TIME64_REDIRECTS
# ifdef __REDIRECT
extern int __REDIRECT (ppoll, (struct pollfd *__fds, nfds_t __nfds,
const struct timespec *__timeout,
Expand Down
16 changes: 8 additions & 8 deletions io/sys/stat.h
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,7 @@ extern int stat (const char *__restrict __file,
that file descriptor FD is open on and put them in BUF. */
extern int fstat (int __fd, struct stat *__buf) __THROW __nonnull ((2));
#else
# ifdef __USE_TIME_BITS64
# ifdef __USE_TIME64_REDIRECTS
# ifdef __REDIRECT_NTH
extern int __REDIRECT_NTH (stat, (const char *__restrict __file,
struct stat *__restrict __buf),
Expand All @@ -236,7 +236,7 @@ extern int __REDIRECT_NTH (fstat, (int __fd, struct stat *__buf), fstat64)
# endif
#endif
#ifdef __USE_LARGEFILE64
# ifndef __USE_TIME_BITS64
# ifndef __USE_TIME64_REDIRECTS
extern int stat64 (const char *__restrict __file,
struct stat64 *__restrict __buf) __THROW __nonnull ((1, 2));
extern int fstat64 (int __fd, struct stat64 *__buf) __THROW __nonnull ((2));
Expand Down Expand Up @@ -265,7 +265,7 @@ extern int fstatat (int __fd, const char *__restrict __file,
struct stat *__restrict __buf, int __flag)
__THROW __nonnull ((2, 3));
# else
# ifdef __USE_TIME_BITS64
# ifdef __USE_TIME64_REDIRECTS
# ifdef __REDIRECT_NTH
extern int __REDIRECT_NTH (fstatat, (int __fd, const char *__restrict __file,
struct stat *__restrict __buf,
Expand All @@ -287,7 +287,7 @@ extern int __REDIRECT_NTH (fstatat, (int __fd, const char *__restrict __file,
# endif

# ifdef __USE_LARGEFILE64
# ifndef __USE_TIME_BITS64
# ifndef __USE_TIME64_REDIRECTS
extern int fstatat64 (int __fd, const char *__restrict __file,
struct stat64 *__restrict __buf, int __flag)
__THROW __nonnull ((2, 3));
Expand All @@ -313,7 +313,7 @@ extern int __REDIRECT_NTH (fstatat64, (int __fd,
extern int lstat (const char *__restrict __file,
struct stat *__restrict __buf) __THROW __nonnull ((1, 2));
# else
# ifdef __USE_TIME_BITS64
# ifdef __USE_TIME64_REDIRECTS
# ifdef __REDIRECT_NTH
extern int __REDIRECT_NTH (lstat,
(const char *__restrict __file,
Expand All @@ -334,7 +334,7 @@ extern int __REDIRECT_NTH (lstat,
# endif
# endif
# ifdef __USE_LARGEFILE64
# ifndef __USE_TIME_BITS64
# ifndef __USE_TIME64_REDIRECTS
extern int lstat64 (const char *__restrict __file,
struct stat64 *__restrict __buf)
__THROW __nonnull ((1, 2));
Expand Down Expand Up @@ -427,7 +427,7 @@ extern int mkfifoat (int __fd, const char *__path, __mode_t __mode)
#endif

#ifdef __USE_ATFILE
# ifndef __USE_TIME_BITS64
# ifndef __USE_TIME64_REDIRECTS
/* Set file access and modification times relative to directory file
descriptor. */
extern int utimensat (int __fd, const char *__path,
Expand All @@ -447,7 +447,7 @@ extern int __REDIRECT_NTH (utimensat, (int fd, const char *__path,
#endif

#ifdef __USE_XOPEN2K8
# ifndef __USE_TIME_BITS64
# ifndef __USE_TIME64_REDIRECTS
/* Set file access and modification times of the file associated with FD. */
extern int futimens (int __fd, const struct timespec __times[2]) __THROW;

Expand Down
4 changes: 2 additions & 2 deletions io/utime.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ __BEGIN_DECLS
/* Structure describing file times. */
struct utimbuf
{
#ifdef __USE_TIME_BITS64
#ifdef __USE_TIME64_REDIRECTS
__time64_t actime; /* Access time. */
__time64_t modtime; /* Modification time. */
#else
Expand All @@ -46,7 +46,7 @@ struct utimbuf

/* Set the access and modification times of FILE to those given in
*FILE_TIMES. If FILE_TIMES is NULL, set them to the current time. */
#ifndef __USE_TIME_BITS64
#ifndef __USE_TIME64_REDIRECTS
extern int utime (const char *__file,
const struct utimbuf *__file_times)
__THROW __nonnull ((1));
Expand Down
6 changes: 6 additions & 0 deletions manual/creature.texi
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,12 @@ Linux kernel version on which the system is running. For Linux kernel
version above @b{5.1} syscalls supporting 64-bit time are used. Otherwise,
a fallback code is used with legacy (i.e. 32-bit) syscalls.

On such platforms, @theglibc{} will also define @code{__USE_TIME64_REDIRECTS}
to indicate whether the declarations are expanded to different ones
(either by redefiniding the symbol name or using symbol aliais).
For instance, if the symbol @code{clock_gettime} expands to
@code{__glock_gettime64}.

@item
If @code{_TIME_BITS} is defined to be 32, @code{time_t} is defined to
be a 32-bit integer where that is supported. This is not recommended,
Expand Down
4 changes: 4 additions & 0 deletions manual/maint.texi
Original file line number Diff line number Diff line change
Expand Up @@ -491,6 +491,10 @@ derived as in the dual-time configuration case, and which expands to
the symbol's name. For instance, the macro @code{__clock_gettime64}
expands to @code{clock_gettime}.

When @code{__TIMESIZE} is set to 64, @theglibc{} will also define
the@code{__USE_TIME_BITS64} macro. It is used by the Linux kernel ABI
to set the expected @code{time_t} size used on some syscalls.

These macros are purely internal to @theglibc{} and exist only so that
a single definition of the 64-bit time functions can be used on both
single-time and dual-time configurations, and so that glibc code can
Expand Down
2 changes: 1 addition & 1 deletion misc/sys/ioctl.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ __BEGIN_DECLS
/* Perform the I/O control operation specified by REQUEST on FD.
One argument may follow; its presence and type depend on REQUEST.
Return value depends on REQUEST. Usually -1 indicates error. */
#ifndef __USE_TIME_BITS64
#ifndef __USE_TIME64_REDIRECTS
extern int ioctl (int __fd, unsigned long int __request, ...) __THROW;
#else
# ifdef __REDIRECT
Expand Down
4 changes: 2 additions & 2 deletions misc/sys/select.h
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ __BEGIN_DECLS
This function is a cancellation point and therefore not marked with
__THROW. */
#ifndef __USE_TIME_BITS64
#ifndef __USE_TIME64_REDIRECTS
extern int select (int __nfds, fd_set *__restrict __readfds,
fd_set *__restrict __writefds,
fd_set *__restrict __exceptfds,
Expand All @@ -123,7 +123,7 @@ extern int __REDIRECT (select,
This function is a cancellation point and therefore not marked with
__THROW. */
# ifndef __USE_TIME_BITS64
# ifndef __USE_TIME64_REDIRECTS
extern int pselect (int __nfds, fd_set *__restrict __readfds,
fd_set *__restrict __writefds,
fd_set *__restrict __exceptfds,
Expand Down
4 changes: 2 additions & 2 deletions posix/glob.h
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ extern int glob (const char *__restrict __pattern, int __flags,
/* Free storage allocated in PGLOB by a previous `glob' call. */
extern void globfree (glob_t *__pglob) __THROW;
#else
# ifdef __USE_TIME_BITS64
# ifdef __USE_TIME64_REDIRECTS
extern int __REDIRECT_NTHNL (glob, (const char *__restrict __pattern,
int __flags,
int (*__errfunc) (const char *, int),
Expand All @@ -170,7 +170,7 @@ extern void __REDIRECT_NTH (globfree, (glob_t *__pglob), globfree64);
#endif

#ifdef __USE_LARGEFILE64
# ifdef __USE_TIME_BITS64
# ifdef __USE_TIME64_REDIRECTS
extern int __REDIRECT_NTHNL (glob64, (const char *__restrict __pattern,
int __flags,
int (*__errfunc) (const char *, int),
Expand Down
2 changes: 1 addition & 1 deletion posix/sched.h
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ extern int sched_get_priority_max (int __algorithm) __THROW;
extern int sched_get_priority_min (int __algorithm) __THROW;

/* Get the SCHED_RR interval for the named process. */
#ifndef __USE_TIME_BITS64
#ifndef __USE_TIME64_REDIRECTS
extern int sched_rr_get_interval (__pid_t __pid, struct timespec *__t) __THROW;
#else
# ifdef __REDIRECT_NTH
Expand Down
4 changes: 2 additions & 2 deletions posix/sys/wait.h
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ struct rusage;
nil, store information about the child's resource usage there. If the
WUNTRACED bit is set in OPTIONS, return status for stopped children;
otherwise don't. */
# ifndef __USE_TIME_BITS64
# ifndef __USE_TIME64_REDIRECTS
extern __pid_t wait3 (int *__stat_loc, int __options,
struct rusage * __usage) __THROWNL;
# else
Expand All @@ -154,7 +154,7 @@ extern __pid_t __REDIRECT_NTHNL (wait3, (int *__stat_loc, int __options,
#endif

#ifdef __USE_MISC
# ifndef __USE_TIME_BITS64
# ifndef __USE_TIME64_REDIRECTS
/* PID is like waitpid. Other args are like wait3. */
extern __pid_t wait4 (__pid_t __pid, int *__stat_loc, int __options,
struct rusage *__usage) __THROWNL;
Expand Down
2 changes: 1 addition & 1 deletion resolv/netdb.h
Original file line number Diff line number Diff line change
Expand Up @@ -701,7 +701,7 @@ extern int getaddrinfo_a (int __mode, struct gaicb *__list[__restrict_arr],
extern int gai_suspend (const struct gaicb *const __list[], int __ent,
const struct timespec *__timeout);

# ifdef __USE_TIME_BITS64
# ifdef __USE_TIME64_REDIRECTS
# if defined(__REDIRECT)
extern int __REDIRECT (gai_suspend, (const struct gaicb *const __list[],
int __ent,
Expand Down
2 changes: 1 addition & 1 deletion resource/sys/resource.h
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ extern int setrlimit64 (__rlimit_resource_t __resource,
and put it in *USAGE. Returns 0 for success, -1 for failure. */
extern int getrusage (__rusage_who_t __who, struct rusage *__usage) __THROW;

#ifdef __USE_TIME_BITS64
#ifdef __USE_TIME64_REDIRECTS
# if defined(__REDIRECT_NTH)
extern int __REDIRECT_NTH (getrusage, (__rusage_who_t __who,
struct rusage *__usage),
Expand Down
4 changes: 2 additions & 2 deletions rt/aio.h
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,7 @@ extern __ssize_t __REDIRECT_NTH (aio_return, (struct aiocb *__aiocbp),
extern int __REDIRECT_NTH (aio_cancel,
(int __fildes, struct aiocb *__aiocbp),
aio_cancel64);
# ifdef __USE_TIME_BITS64
# ifdef __USE_TIME64_REDIRECTS
extern int __REDIRECT_NTH (aio_suspend,
(const struct aiocb *const __list[], int __nent,
const struct timespec *__restrict __timeout),
Expand All @@ -215,7 +215,7 @@ extern int __REDIRECT_NTH (aio_fsync,
# define aio_error aio_error64
# define aio_return aio_return64
# define aio_cancel aio_cancel64
# ifdef __USE_TIME_BITS64
# ifdef __USE_TIME64_REDIRECTS
# define aio_suspend __aio_suspend_time64
# else
# define aio_suspend aio_suspend64
Expand Down
2 changes: 1 addition & 1 deletion rt/mqueue.h
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ extern int mq_send (mqd_t __mqdes, const char *__msg_ptr, size_t __msg_len,
unsigned int __msg_prio) __nonnull ((2));

#ifdef __USE_XOPEN2K
# ifndef __USE_TIME_BITS64
# ifndef __USE_TIME64_REDIRECTS
/* Receive the oldest from highest priority messages in message queue
MQDES, stop waiting if ABS_TIMEOUT expires. */
extern ssize_t mq_timedreceive (mqd_t __mqdes, char *__restrict __msg_ptr,
Expand Down
2 changes: 1 addition & 1 deletion signal/signal.h
Original file line number Diff line number Diff line change
Expand Up @@ -269,7 +269,7 @@ extern int sigwaitinfo (const sigset_t *__restrict __set,
This function is a cancellation point and therefore not marked with
__THROW. */
# ifndef __USE_TIME_BITS64
# ifndef __USE_TIME64_REDIRECTS
extern int sigtimedwait (const sigset_t *__restrict __set,
siginfo_t *__restrict __info,
const struct timespec *__restrict __timeout)
Expand Down
Loading

0 comments on commit a4ed047

Please sign in to comment.