aboutsummaryrefslogtreecommitdiff
path: root/sysdeps/unix/sysv
diff options
context:
space:
mode:
authorAdhemerval Zanella <adhemerval.zanella@linaro.org>2019-10-24 19:19:33 +0000
committerAdhemerval Zanella <adhemerval.zanella@linaro.org>2019-10-30 17:11:10 -0300
commit5e46749c64d51f50f8511ed99c1266d7c13e182b (patch)
treee3fd42d4cb28b3863daff8585588d0c69d27b3cd /sysdeps/unix/sysv
parent40a36935fff4eac83b9676b04048990ccb3c4754 (diff)
downloadglibc-5e46749c64d51f50f8511ed99c1266d7c13e182b.tar
glibc-5e46749c64d51f50f8511ed99c1266d7c13e182b.tar.gz
glibc-5e46749c64d51f50f8511ed99c1266d7c13e182b.tar.bz2
glibc-5e46749c64d51f50f8511ed99c1266d7c13e182b.zip
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 <zackw@panix.com> Reviewed-by: Lukasz Majewski <lukma@denx.de>
Diffstat (limited to 'sysdeps/unix/sysv')
-rw-r--r--sysdeps/unix/sysv/linux/aarch64/gettimeofday.c34
-rw-r--r--sysdeps/unix/sysv/linux/alpha/gettimeofday.c (renamed from sysdeps/unix/sysv/linux/i386/gettimeofday.c)25
-rw-r--r--sysdeps/unix/sysv/linux/alpha/osf_gettimeofday.c11
-rw-r--r--sysdeps/unix/sysv/linux/alpha/tv32-compat.h6
-rw-r--r--sysdeps/unix/sysv/linux/gettimeofday.c49
-rw-r--r--sysdeps/unix/sysv/linux/powerpc/gettimeofday.c69
-rw-r--r--sysdeps/unix/sysv/linux/x86/gettimeofday.c43
-rw-r--r--sysdeps/unix/sysv/linux/x86_64/x32/gettimeofday.c1
-rw-r--r--sysdeps/unix/sysv/linux/x86_64/x32/syscalls.list1
9 files changed, 74 insertions, 165 deletions
diff --git a/sysdeps/unix/sysv/linux/aarch64/gettimeofday.c b/sysdeps/unix/sysv/linux/aarch64/gettimeofday.c
index 4ff74fa285..075af3d0d3 100644
--- a/sysdeps/unix/sysv/linux/aarch64/gettimeofday.c
+++ b/sysdeps/unix/sysv/linux/aarch64/gettimeofday.c
@@ -20,39 +20,39 @@
putting it into *tv and *tz. If tz is null, *tz is not filled.
Returns 0 on success, -1 on errors. */
-#include <sys/time.h>
+#include <time.h>
+#include <sysdep.h>
-#ifdef SHARED
-
-# include <dl-vdso.h>
-# include <sysdep-vdso.h>
+#ifdef HAVE_GETTIMEOFDAY_VSYSCALL
+# define HAVE_VSYSCALL
+#endif
+#include <sysdep-vdso.h>
/* Used as a fallback in the ifunc resolver if VDSO is not available
and for libc.so internal __gettimeofday calls. */
-
static int
__gettimeofday_vsyscall (struct timeval *tv, struct timezone *tz)
{
+ if (__glibc_unlikely (tz != 0))
+ memset (tz, 0, sizeof *tz);
+
return INLINE_VSYSCALL (gettimeofday, 2, tv, tz);
}
+#ifdef SHARED
+# include <dl-vdso.h>
+# include <sysdep-vdso.h>
+
# define INIT_ARCH()
-libc_ifunc_hidden (__gettimeofday, __gettimeofday,
- (get_vdso_symbol (HAVE_GETTIMEOFDAY_VSYSCALL)
- ?: __gettimeofday_vsyscall))
-libc_hidden_def (__gettimeofday)
+libc_ifunc (__gettimeofday,
+ (get_vdso_symbol (HAVE_GETTIMEOFDAY_VSYSCALL)
+ ?: __gettimeofday_vsyscall))
#else
-
-# include <sysdep.h>
int
__gettimeofday (struct timeval *tv, struct timezone *tz)
{
- return INLINE_SYSCALL (gettimeofday, 2, tv, tz);
+ return __gettimeofday_vsyscall (tv, tz);
}
-libc_hidden_def (__gettimeofday)
-
#endif
-
weak_alias (__gettimeofday, gettimeofday)
-libc_hidden_weak (gettimeofday)
diff --git a/sysdeps/unix/sysv/linux/i386/gettimeofday.c b/sysdeps/unix/sysv/linux/alpha/gettimeofday.c
index f6faecb21e..262a3c2352 100644
--- a/sysdeps/unix/sysv/linux/i386/gettimeofday.c
+++ b/sysdeps/unix/sysv/linux/alpha/gettimeofday.c
@@ -1,5 +1,5 @@
-/* gettimeofday - get the time. Linux/i386 version.
- Copyright (C) 2015-2019 Free Software Foundation, Inc.
+/* gettimeofday -- Get the current time of day. Linux/Alpha/tv64 version.
+ Copyright (C) 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
@@ -16,20 +16,7 @@
License along with the GNU C Library; if not, see
<https://www.gnu.org/licenses/>. */
-#ifdef SHARED
-# define __gettimeofday __redirect___gettimeofday
-#endif
-
-#include <sys/time.h>
-
-#ifdef SHARED
-# undef __gettimeofday
-# define __gettimeofday_type __redirect___gettimeofday
-
-# undef libc_hidden_def
-# define libc_hidden_def(name) \
- __hidden_ver1 (__gettimeofday_syscall, __GI___gettimeofday, \
- __gettimeofday_syscall);
-#endif
-
-#include <sysdeps/unix/sysv/linux/x86/gettimeofday.c>
+/* We can use the generic implementation, but we have to override its
+ default symbol version. */
+#define VERSION_gettimeofday GLIBC_2.1
+#include <time/gettimeofday.c>
diff --git a/sysdeps/unix/sysv/linux/alpha/osf_gettimeofday.c b/sysdeps/unix/sysv/linux/alpha/osf_gettimeofday.c
index 59fc614523..4698c8a5db 100644
--- a/sysdeps/unix/sysv/linux/alpha/osf_gettimeofday.c
+++ b/sysdeps/unix/sysv/linux/alpha/osf_gettimeofday.c
@@ -20,6 +20,8 @@
#if SHLIB_COMPAT (libc, GLIBC_2_0, GLIBC_2_1)
+#include <string.h>
+#include <time.h>
#include <sys/time.h>
#include <tv32-compat.h>
@@ -30,10 +32,13 @@ int
attribute_compat_text_section
__gettimeofday_tv32 (struct timeval32 *restrict tv32, void *restrict tz)
{
- struct timeval tv;
- __gettimeofday (&tv, tz);
+ if (__glibc_unlikely (tz != 0))
+ memset (tz, 0, sizeof (struct timezone));
- *tv32 = valid_timeval64_to_timeval (tv);
+ struct timespec ts;
+ __clock_gettime (CLOCK_REALTIME, &ts);
+
+ *tv32 = valid_timespec_to_timeval32 (ts);
return 0;
}
diff --git a/sysdeps/unix/sysv/linux/alpha/tv32-compat.h b/sysdeps/unix/sysv/linux/alpha/tv32-compat.h
index 5f86e66e08..0fbf284bb5 100644
--- a/sysdeps/unix/sysv/linux/alpha/tv32-compat.h
+++ b/sysdeps/unix/sysv/linux/alpha/tv32-compat.h
@@ -89,6 +89,12 @@ valid_timeval32_to_timespec (const struct timeval32 tv)
return (struct timespec) { tv.tv_sec, tv.tv_usec * 1000 };
}
+static inline struct timeval32
+valid_timespec_to_timeval32 (const struct timespec ts)
+{
+ return (struct timeval32) { (time_t) ts.tv_sec, ts.tv_nsec / 1000 };
+}
+
static inline void
rusage64_to_rusage32 (struct rusage32 *restrict r32,
const struct rusage *restrict r64)
diff --git a/sysdeps/unix/sysv/linux/gettimeofday.c b/sysdeps/unix/sysv/linux/gettimeofday.c
deleted file mode 100644
index c9597d6405..0000000000
--- a/sysdeps/unix/sysv/linux/gettimeofday.c
+++ /dev/null
@@ -1,49 +0,0 @@
-/* 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
- <https://www.gnu.org/licenses/>. */
-
-#include <errno.h>
-#include <sys/time.h>
-
-#undef __gettimeofday
-
-#ifdef HAVE_GETTIMEOFDAY_VSYSCALL
-# define HAVE_VSYSCALL
-#endif
-#include <sysdep-vdso.h>
-
-/* Get the current time of day and timezone information,
- putting it into *tv and *tz. If tz is null, *tz is not filled.
- Returns 0 on success, -1 on errors. */
-int
-___gettimeofday (struct timeval *tv, struct timezone *tz)
-{
- return INLINE_VSYSCALL (gettimeofday, 2, tv, tz);
-}
-
-#ifdef VERSION_gettimeofday
-weak_alias (___gettimeofday, __wgettimeofday);
-default_symbol_version (___gettimeofday, __gettimeofday, VERSION_gettimeofday);
-default_symbol_version (__wgettimeofday, gettimeofday, VERSION_gettimeofday);
-libc_hidden_ver (___gettimeofday, __gettimeofday);
-libc_hidden_ver (___gettimeofday, gettimeofday);
-#else
-strong_alias (___gettimeofday, __gettimeofday)
-weak_alias (___gettimeofday, gettimeofday)
-libc_hidden_def (__gettimeofday)
-libc_hidden_weak (gettimeofday)
-#endif
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
<https://www.gnu.org/licenses/>. */
-#if defined SHARED && !defined __powerpc64__
-# define __gettimeofday __redirect___gettimeofday
-#else
-# define __redirect___gettimeofday __gettimeofday
-#endif
-
-#include <sys/time.h>
-
-#ifdef SHARED
-
-# include <dl-vdso.h>
-# include <libc-vdso.h>
-# include <dl-machine.h>
-# include <sysdep.h>
-
-# 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 <time.h>
+#include <sysdep.h>
-# endif /* !__powerpc64__ */
+#ifdef HAVE_GETTIMEOFDAY_VSYSCALL
+# define HAVE_VSYSCALL
+#endif
+#include <sysdep-vdso.h>
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 <dl-vdso.h>
+# include <libc-vdso.h>
+
# 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 <sysdep.h>
-# include <errno.h>
-
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)
diff --git a/sysdeps/unix/sysv/linux/x86/gettimeofday.c b/sysdeps/unix/sysv/linux/x86/gettimeofday.c
index 2d9248ee26..cb20e358d8 100644
--- a/sysdeps/unix/sysv/linux/x86/gettimeofday.c
+++ b/sysdeps/unix/sysv/linux/x86/gettimeofday.c
@@ -16,47 +16,38 @@
License along with the GNU C Library; if not, see
<https://www.gnu.org/licenses/>. */
-#include <sys/time.h>
+#include <time.h>
+#include <sysdep.h>
-#ifdef SHARED
-
-# include <dl-vdso.h>
-# include <errno.h>
-# include <sysdep-vdso.h>
-# include <sysdep-vdso.h>
+#ifdef HAVE_GETTIMEOFDAY_VSYSCALL
+# define HAVE_VSYSCALL
+#endif
+#include <sysdep-vdso.h>
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);
}
-# ifndef __gettimeofday_type
-/* The i386 gettimeofday.c includes this file with a defined
- __gettimeofday_type macro. For x86_64 we have to define it to __gettimeofday
- as the internal symbol is the ifunc'ed one. */
-# define __gettimeofday_type __gettimeofday
-# endif
+#ifdef SHARED
+# include <dl-vdso.h>
+# include <libc-vdso.h>
# define INIT_ARCH()
/* If the vDSO is not available we fall back to syscall. */
-libc_ifunc_hidden (__gettimeofday_type, __gettimeofday,
- (get_vdso_symbol ("__vdso_gettimeofday")
- ?: __gettimeofday_syscall));
-libc_hidden_def (__gettimeofday)
+libc_ifunc (__gettimeofday,
+ (get_vdso_symbol (HAVE_GETTIMEOFDAY_VSYSCALL)
+ ?: __gettimeofday_syscall));
#else
-
-# include <sysdep.h>
-# include <errno.h>
-
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)
diff --git a/sysdeps/unix/sysv/linux/x86_64/x32/gettimeofday.c b/sysdeps/unix/sysv/linux/x86_64/x32/gettimeofday.c
new file mode 100644
index 0000000000..cd342f33ad
--- /dev/null
+++ b/sysdeps/unix/sysv/linux/x86_64/x32/gettimeofday.c
@@ -0,0 +1 @@
+#include <sysdeps/unix/sysv/linux/x86/gettimeofday.c>
diff --git a/sysdeps/unix/sysv/linux/x86_64/x32/syscalls.list b/sysdeps/unix/sysv/linux/x86_64/x32/syscalls.list
index b44f6f99e9..786c884232 100644
--- a/sysdeps/unix/sysv/linux/x86_64/x32/syscalls.list
+++ b/sysdeps/unix/sysv/linux/x86_64/x32/syscalls.list
@@ -1,6 +1,5 @@
# File name Caller Syscall name # args Strong name Weak names
-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