From 5e46749c64d51f50f8511ed99c1266d7c13e182b Mon Sep 17 00:00:00 2001 From: Adhemerval Zanella Date: Thu, 24 Oct 2019 19:19:33 +0000 Subject: Use clock_gettime to implement gettimeofday. Consolidate generic gettimeofday implementation to use clock_gettime. Linux ports that still provide gettimeofday through vDSO are not changed. Remove sysdeps/unix/clock_gettime.c, which implemented clock_gettime using gettimeofday; new OS ports must provide a real implementation of clock_gettime. Rename sysdeps/mach/gettimeofday.c to sysdeps/mach/clock_gettime.c and convert into an implementation of clock_gettime. It only supports CLOCK_REALTIME; Mach does not appear to have any support for monotonic clocks. It uses __host_get_time, which provides at best microsecond resolution. Hurd is currently using sysdeps/posix/clock_getres.c for clock_getres; its output for CLOCK_REALTIME is based on sysconf (_SC_CLK_TCK), and I do not know whether that gives the correct result. Unlike settimeofday, there are no known uses of gettimeofday's vestigial "get time zone" feature that are not bugs. (The per-process timezone support in localtime and friends is unrelated, and the programs that set the kernel's offset between the hardware clock and UTC do not need to read it back.) Therefore, this feature is dummied out. Henceforth, if gettimeofday's "struct timezone" argument is not NULL, it will write zeroes to both fields. Any program that is actually looking at this data will thus think it is running in UTC, which is probably more correct than whatever it was doing before. [__]gettimeofday no longer has any internal callers, so we can now remove its internal prototype and PLT bypass aliases. The __gettimeofday@GLIBC_2.0 export remains, in case it is used by any third-party code. It also allows to simplify the arch-specific implementation on x86 and powerpc to remove the hack to disable the internal route to non iFUNC variant for internal symbol. This patch also fixes a missing optimization on aarch64, powerpc, and x86 where the code used on static build do not use the vDSO. Checked on x86_64-linux-gnu, i686-linux-gnu, powerpc64le-linux-gnu, powerpc64-linux-gnu, powerpc-linux-gnu, and aarch64-linux-gnu. Co-authored-by: Zack Weinberg Reviewed-by: Lukasz Majewski --- sysdeps/unix/sysv/linux/powerpc/gettimeofday.c | 69 +++++++------------------- 1 file changed, 19 insertions(+), 50 deletions(-) (limited to 'sysdeps/unix/sysv/linux/powerpc') diff --git a/sysdeps/unix/sysv/linux/powerpc/gettimeofday.c b/sysdeps/unix/sysv/linux/powerpc/gettimeofday.c index 13a1fd292a..02486dee3a 100644 --- a/sysdeps/unix/sysv/linux/powerpc/gettimeofday.c +++ b/sysdeps/unix/sysv/linux/powerpc/gettimeofday.c @@ -15,71 +15,40 @@ License along with the GNU C Library; if not, see . */ -#if defined SHARED && !defined __powerpc64__ -# define __gettimeofday __redirect___gettimeofday -#else -# define __redirect___gettimeofday __gettimeofday -#endif - -#include - -#ifdef SHARED - -# include -# include -# include -# include - -# ifndef __powerpc64__ -# undef __gettimeofday - -int -__gettimeofday_vsyscall (struct timeval *tv, struct timezone *tz) -{ - return INLINE_VSYSCALL (gettimeofday, 2, tv, tz); -} - -/* __GI___gettimeofday 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 (__gettimeofday_vsyscall, __GI___gettimeofday, \ - __gettimeofday_vsyscall); +#include +#include -# endif /* !__powerpc64__ */ +#ifdef HAVE_GETTIMEOFDAY_VSYSCALL +# define HAVE_VSYSCALL +#endif +#include static int __gettimeofday_syscall (struct timeval *tv, struct timezone *tz) { - return INLINE_SYSCALL (gettimeofday, 2, tv, tz); + if (__glibc_unlikely (tz != 0)) + memset (tz, 0, sizeof *tz); + + return INLINE_VSYSCALL (gettimeofday, 2, tv, tz); } +#ifdef SHARED +# include +# include + # define INIT_ARCH() \ void *vdso_gettimeofday = get_vdso_symbol (HAVE_GETTIMEOFDAY_VSYSCALL) /* If the vDSO is not available we fall back syscall. */ -libc_ifunc_hidden (__redirect___gettimeofday, __gettimeofday, - vdso_gettimeofday - ? VDSO_IFUNC_RET (vdso_gettimeofday) - : (void *) __gettimeofday_syscall); -libc_hidden_def (__gettimeofday) - +libc_ifunc (__gettimeofday, + vdso_gettimeofday + ? VDSO_IFUNC_RET (vdso_gettimeofday) + : (void *) __gettimeofday_syscall); #else - -# include -# include - int __gettimeofday (struct timeval *tv, struct timezone *tz) { - return INLINE_SYSCALL (gettimeofday, 2, tv, tz); + return __gettimeofday_syscall (tv, tz); } -libc_hidden_def (__gettimeofday) - #endif weak_alias (__gettimeofday, gettimeofday) -libc_hidden_weak (gettimeofday) -- cgit 1.4.1