public inbox for glibc-cvs@sourceware.org help / color / mirror / Atom feed
From: Zack Weinberg <zack@sourceware.org> To: glibc-cvs@sourceware.org Subject: [glibc/zack/y2038-preliminaries] Use clock_gettime to implement time. Date: Wed, 28 Aug 2019 13:04:00 -0000 [thread overview] Message-ID: <20190828130453.18740.qmail@sourceware.org> (raw) https://sourceware.org/git/gitweb.cgi?p=glibc.git;h=f4e5cd6bbe38b3454bf683453d080b073ecec3ca commit f4e5cd6bbe38b3454bf683453d080b073ecec3ca Author: Zack Weinberg <zackw@panix.com> Date: Fri Aug 16 14:22:42 2019 -0400 Use clock_gettime to implement time. Most ports were using gettimeofday to implement time, or they were making a direct (v)syscall. Unconditionally switch to using clock_gettime instead. All sysdeps implementations of time are removed. * time/time.c (time): No longer a stub implementation. Call __clock_gettime. * sysdeps/unix/sysv/linux/powerpc/Versions (GLIBC_PRIVATE): Remove __vdso_time. * sysdeps/unix/sysv/linux/powerpc/init-first.c (__vdso_time): Delete. (_libc_vdso_platform_setup): Don't initialize __vdso_time. * sysdeps/unix/sysv/linux/x86_64/x32/syscalls.list: Remove entry for time. * sysdeps/posix/time.c * sysdeps/unix/sysv/linux/time.c * sysdeps/unix/sysv/linux/i386/time.c * sysdeps/unix/sysv/linux/powerpc/time.c * sysdeps/unix/sysv/linux/sparc/sparc64/time.c * sysdeps/unix/sysv/linux/x86/time.c: Delete file. Diff: --- sysdeps/posix/time.c | 40 ----------- sysdeps/unix/sysv/linux/i386/time.c | 34 ---------- sysdeps/unix/sysv/linux/powerpc/Versions | 1 - sysdeps/unix/sysv/linux/powerpc/init-first.c | 5 -- sysdeps/unix/sysv/linux/powerpc/time.c | 84 ------------------------ sysdeps/unix/sysv/linux/sparc/sparc64/time.c | 1 - sysdeps/unix/sysv/linux/time.c | 41 ------------ sysdeps/unix/sysv/linux/x86/time.c | 59 ----------------- sysdeps/unix/sysv/linux/x86_64/x32/syscalls.list | 1 - time/time.c | 12 ++-- 10 files changed, 5 insertions(+), 273 deletions(-) diff --git a/sysdeps/posix/time.c b/sysdeps/posix/time.c deleted file mode 100644 index e1b3bc8..0000000 --- a/sysdeps/posix/time.c +++ /dev/null @@ -1,40 +0,0 @@ -/* Copyright (C) 1991-2019 Free Software Foundation, Inc. - This file is part of the GNU C Library. - - The GNU C Library is free software; you can redistribute it and/or - modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 2.1 of the License, or (at your option) any later version. - - The GNU C Library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with the GNU C Library; if not, see - <http://www.gnu.org/licenses/>. */ - -#include <stddef.h> /* For NULL. */ -#include <time.h> -#include <sys/time.h> - - -/* Return the current time as a `time_t' and also put it in *T if T is - not NULL. Time is represented as seconds from Jan 1 00:00:00 1970. */ -time_t -time (time_t *t) -{ - struct timeval tv; - time_t result; - - if (__gettimeofday (&tv, (struct timezone *) NULL)) - result = (time_t) -1; - else - result = (time_t) tv.tv_sec; - - if (t != NULL) - *t = result; - return result; -} -libc_hidden_def (time) diff --git a/sysdeps/unix/sysv/linux/i386/time.c b/sysdeps/unix/sysv/linux/i386/time.c deleted file mode 100644 index 440e3e6..0000000 --- a/sysdeps/unix/sysv/linux/i386/time.c +++ /dev/null @@ -1,34 +0,0 @@ -/* time -- Get number of seconds since Epoch. Linux/i386 version. - Copyright (C) 2015-2019 Free Software Foundation, Inc. - This file is part of the GNU C Library. - - The GNU C Library is free software; you can redistribute it and/or - modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 2.1 of the License, or (at your option) any later version. - - The GNU C Library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with the GNU C Library; if not, see - <http://www.gnu.org/licenses/>. */ - -#ifdef SHARED -# define time __redirect_time -#endif - -#include <time.h> - -#ifdef SHARED -# undef time -# define time_type __redirect_time - -# undef libc_hidden_def -# define libc_hidden_def(name) \ - __hidden_ver1 (__time_syscall, __GI_time, __time_syscall); -#endif - -#include <sysdeps/unix/sysv/linux/x86/time.c> diff --git a/sysdeps/unix/sysv/linux/powerpc/Versions b/sysdeps/unix/sysv/linux/powerpc/Versions index 8ebeea1..859e0d7 100644 --- a/sysdeps/unix/sysv/linux/powerpc/Versions +++ b/sysdeps/unix/sysv/linux/powerpc/Versions @@ -10,7 +10,6 @@ libc { __vdso_clock_gettime; __vdso_clock_getres; __vdso_getcpu; - __vdso_time; } } libm { diff --git a/sysdeps/unix/sysv/linux/powerpc/init-first.c b/sysdeps/unix/sysv/linux/powerpc/init-first.c index 831f910..4f12b59 100644 --- a/sysdeps/unix/sysv/linux/powerpc/init-first.c +++ b/sysdeps/unix/sysv/linux/powerpc/init-first.c @@ -25,7 +25,6 @@ int (*VDSO_SYMBOL(clock_gettime)) (clockid_t, struct timespec *); int (*VDSO_SYMBOL(clock_getres)) (clockid_t, struct timespec *); unsigned long long (*VDSO_SYMBOL(get_tbfreq)) (void); int (*VDSO_SYMBOL(getcpu)) (unsigned *, unsigned *); -time_t (*VDSO_SYMBOL(time)) (time_t *); #if defined(__PPC64__) || defined(__powerpc64__) void *VDSO_SYMBOL(sigtramp_rt64); @@ -59,10 +58,6 @@ _libc_vdso_platform_setup (void) PTR_MANGLE (p); VDSO_SYMBOL (getcpu) = p; - p = _dl_vdso_vsym ("__kernel_time", &linux2615); - PTR_MANGLE (p); - VDSO_SYMBOL (time) = p; - /* PPC64 uses only one signal trampoline symbol, while PPC32 will use two depending if SA_SIGINFO is used (__kernel_sigtramp_rt32) or not (__kernel_sigtramp32). diff --git a/sysdeps/unix/sysv/linux/powerpc/time.c b/sysdeps/unix/sysv/linux/powerpc/time.c deleted file mode 100644 index cb3e8b9..0000000 --- a/sysdeps/unix/sysv/linux/powerpc/time.c +++ /dev/null @@ -1,84 +0,0 @@ -/* time system call for Linux/PowerPC. - Copyright (C) 2013-2019 Free Software Foundation, Inc. - This file is part of the GNU C Library. - - The GNU C Library is free software; you can redistribute it and/or - modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 2.1 of the License, or (at your option) any later version. - - The GNU C Library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with the GNU C Library; if not, see - <http://www.gnu.org/licenses/>. */ - -#ifdef SHARED -# ifndef __powerpc64__ -# define time __redirect_time -# else -# define __redirect_time time -# endif - -# include <time.h> -# include <sysdep.h> -# include <dl-vdso.h> -# include <libc-vdso.h> -# include <dl-machine.h> - -# ifndef __powerpc64__ -# undef time - -time_t -__time_vsyscall (time_t *t) -{ - return INLINE_VSYSCALL (time, 1, t); -} - -/* __GI_time is defined as hidden and for ppc32 it enables the - compiler make a local call (symbol@local) for internal GLIBC usage. It - means the PLT won't be used and the ifunc resolver will be called directly. - For ppc64 a call to a function in another translation unit might use a - different toc pointer thus disallowing direct branchess and making internal - ifuncs calls safe. */ -# undef libc_hidden_def -# define libc_hidden_def(name) \ - __hidden_ver1 (__time_vsyscall, __GI_time, __time_vsyscall); - -# endif /* !__powerpc64__ */ - -static time_t -time_syscall (time_t *t) -{ - struct timeval tv; - time_t result; - - if (INLINE_VSYSCALL (gettimeofday, 2, &tv, NULL) < 0) - result = (time_t) -1; - else - result = (time_t) tv.tv_sec; - - if (t != NULL) - *t = result; - return result; -} - -# define INIT_ARCH() \ - PREPARE_VERSION_KNOWN (linux2615, LINUX_2_6_15); \ - void *vdso_time = _dl_vdso_vsym ("__kernel_time", &linux2615); - -/* If the vDSO is not available we fall back to the syscall. */ -libc_ifunc_hidden (__redirect_time, time, - vdso_time - ? VDSO_IFUNC_RET (vdso_time) - : (void *) time_syscall); -libc_hidden_def (time) - -#else - -#include <sysdeps/posix/time.c> - -#endif /* !SHARED */ diff --git a/sysdeps/unix/sysv/linux/sparc/sparc64/time.c b/sysdeps/unix/sysv/linux/sparc/sparc64/time.c deleted file mode 100644 index 509b580..0000000 --- a/sysdeps/unix/sysv/linux/sparc/sparc64/time.c +++ /dev/null @@ -1 +0,0 @@ -#include <sysdeps/posix/time.c> diff --git a/sysdeps/unix/sysv/linux/time.c b/sysdeps/unix/sysv/linux/time.c deleted file mode 100644 index 1978f6d..0000000 --- a/sysdeps/unix/sysv/linux/time.c +++ /dev/null @@ -1,41 +0,0 @@ -/* Copyright (C) 2005-2019 Free Software Foundation, Inc. - This file is part of the GNU C Library. - - The GNU C Library is free software; you can redistribute it and/or - modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 2.1 of the License, or (at your option) any later version. - - The GNU C Library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with the GNU C Library; if not, see - <http://www.gnu.org/licenses/>. */ - -#include <stddef.h> -#include <time.h> - -#include <sysdep.h> - -#ifdef __NR_time - -time_t -time (time_t *t) -{ - INTERNAL_SYSCALL_DECL (err); - time_t res = INTERNAL_SYSCALL (time, err, 1, NULL); - /* There cannot be any error. */ - if (t != NULL) - *t = res; - return res; -} -libc_hidden_def (time) - -#else - -# include <sysdeps/posix/time.c> - -#endif diff --git a/sysdeps/unix/sysv/linux/x86/time.c b/sysdeps/unix/sysv/linux/x86/time.c deleted file mode 100644 index 3d72488..0000000 --- a/sysdeps/unix/sysv/linux/x86/time.c +++ /dev/null @@ -1,59 +0,0 @@ -/* time -- Get number of seconds since Epoch. Linux/x86 version. - Copyright (C) 2015-2019 Free Software Foundation, Inc. - This file is part of the GNU C Library. - - The GNU C Library is free software; you can redistribute it and/or - modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 2.1 of the License, or (at your option) any later version. - - The GNU C Library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with the GNU C Library; if not, see - <http://www.gnu.org/licenses/>. */ - -#include <time.h> - -#ifdef SHARED - -#include <dl-vdso.h> -#include <errno.h> - -static time_t -__time_syscall (time_t *t) -{ - INTERNAL_SYSCALL_DECL (err); - return INTERNAL_SYSCALL (time, err, 1, t); -} - -# ifndef time_type -/* The i386 time.c includes this file with a defined time_type macro. - For x86_64 we have to define it to time as the internal symbol is the - ifunc'ed one. */ -# define time_type time -# endif - -#undef INIT_ARCH -#define INIT_ARCH() PREPARE_VERSION_KNOWN (linux26, LINUX_2_6); -/* If the vDSO is not available we fall back on the syscall. */ -libc_ifunc_hidden (time_type, time, - (_dl_vdso_vsym ("__vdso_time", &linux26) - ?: &__time_syscall)) -libc_hidden_def (time) - -#else - -# include <sysdep.h> - -time_t -time (time_t *t) -{ - INTERNAL_SYSCALL_DECL (err); - return INTERNAL_SYSCALL (time, err, 1, t); -} - -#endif diff --git a/sysdeps/unix/sysv/linux/x86_64/x32/syscalls.list b/sysdeps/unix/sysv/linux/x86_64/x32/syscalls.list index b44f6f9..c0cfa7b 100644 --- a/sysdeps/unix/sysv/linux/x86_64/x32/syscalls.list +++ b/sysdeps/unix/sysv/linux/x86_64/x32/syscalls.list @@ -3,4 +3,3 @@ gettimeofday - gettimeofday:__vdso_gettimeofday@LINUX_2.6 i:pP __gettimeofday gettimeofday personality EXTRA personality Ei:i __personality personality posix_fadvise64 - fadvise64 Vi:iiii posix_fadvise posix_fadvise64 -time - time:__vdso_time@LINUX_2.6 Ei:P time diff --git a/time/time.c b/time/time.c index 88612d6..bae0fd1 100644 --- a/time/time.c +++ b/time/time.c @@ -15,19 +15,17 @@ License along with the GNU C Library; if not, see <http://www.gnu.org/licenses/>. */ -#include <errno.h> #include <time.h> /* Return the time now, and store it in *TIMER if not NULL. */ time_t time (time_t *timer) { - __set_errno (ENOSYS); + struct timespec ts; + __clock_gettime (CLOCK_REALTIME, &ts); - if (timer != NULL) - *timer = (time_t) -1; - return (time_t) -1; + if (timer) + *timer = ts.tv_sec; + return ts.tv_sec; } libc_hidden_def (time) - -stub_warning (time)
next reply other threads:[~2019-08-28 13:04 UTC|newest] Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top 2019-08-28 13:04 Zack Weinberg [this message] -- strict thread matches above, loose matches on Subject: below -- 2019-08-22 23:03 Zack Weinberg 2019-08-21 12:28 Zack Weinberg 2019-08-20 13:25 Zack Weinberg 2019-08-20 12:08 Zack Weinberg 2019-08-19 18:31 Zack Weinberg 2019-08-17 1:17 Zack Weinberg
Reply instructions: You may reply publicly to this message via plain-text email using any one of the following methods: * Save the following mbox file, import it into your mail client, and reply-to-all from there: mbox Avoid top-posting and favor interleaved quoting: https://en.wikipedia.org/wiki/Posting_style#Interleaved_style * Reply using the --to, --cc, and --in-reply-to switches of git-send-email(1): git send-email \ --in-reply-to=20190828130453.18740.qmail@sourceware.org \ --to=zack@sourceware.org \ --cc=glibc-cvs@sourceware.org \ /path/to/YOUR_REPLY https://kernel.org/pub/software/scm/git/docs/git-send-email.html * If your mail client supports setting the In-Reply-To header via mailto: links, try the mailto: linkBe sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox; as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).