This is the mail archive of the libc-alpha@sourceware.org mailing list for the glibc project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: PATCH: Add x32 time


On Thu, May 17, 2012 at 5:25 PM, H.J. Lu <hjl.tools@gmail.com> wrote:
> On Thu, May 17, 2012 at 3:06 PM, Roland McGrath <roland@hack.frob.com> wrote:
>> OK, this clinches it for me that we really should be doing this and
>> gettimeofday with syscalls.list enhancements instead.
>>
>>
>
> Those are in C. ?If you compare gettimeofday.c and time.c, excluding
> copyright, there are more codes which are different than common. We
> can define libc_ifunc_vdso in include/libc-symbols.h to cover
>
> # include <dl-vdso.h>
>
> void *time_ifunc (void) __asm__ ("__GI_time");
>
> void *
> time_ifunc (void)
> {
> ?PREPARE_VERSION (linux26, "LINUX_2.6", 61765110);
>
> ?return _dl_vdso_vsym ("__vdso_time", &linux26);
> }
> __asm (".type __GI_time, %gnu_indirect_function");
>
> It should cover most if not all common code.
>

Here is a patch to add libc_ifunc_vdso and libc_ifunc_vdso_hidden.
As it is shown,  there is not much in common between
time.c and gettimeofday.c.  It will take more much time to
update syscalls.list approach to support this.  OK to install?

Thanks,


-- 
H.J.
---
	* include/libc-symbols.h (libc_ifunc_vdso1): New macro.
	(libc_ifunc_vdso): Likewise.
	(libc_ifunc_vdso_hidden): Likewise.
	* sysdeps/unix/sysv/linux/x86_64/x32/gettimeofday.c: New file.
	* sysdeps/unix/sysv/linux/x86_64/x32/time.c: Likewise.

diff --git a/include/libc-symbols.h b/include/libc-symbols.h
index 12b3639..1d08ab5 100644
--- a/include/libc-symbols.h
+++ b/include/libc-symbols.h
@@ -772,6 +772,23 @@ for linking")
   }									\
   __asm__ (".type " #name ", %gnu_indirect_function");

+#define libc_ifunc_vdso1(name, vdsoname)				\
+  extern void *name##_ifunc (void) __asm__ (#name);			\
+  void *name##_ifunc (void)						\
+  {									\
+    PREPARE_VERSION (linux26, "LINUX_2.6", 61765110);			\
+    return _dl_vdso_vsym (#vdsoname, &linux26);				\
+  }									\
+  __asm__ (".type " #name ", %gnu_indirect_function");
+
+/* Macro used for indirection function symbols with vDSO.  */
+#define libc_ifunc_vdso(name, vdsoname)					\
+  libc_ifunc_vdso1 (name, vdsoname)
+
+/* Macro used for hidden indirection function symbols with vDSO.  */
+#define libc_ifunc_vdso_hidden(name, vdsoname)				\
+  libc_ifunc_vdso1 (__GI_##name, vdsoname)
+
 /* The body of the function is supposed to use __get_cpu_features
    which will, if necessary, initialize the data first.  */
 #define libm_ifunc(name, expr)						\
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 0000000..994567f
--- /dev/null
+++ b/sysdeps/unix/sysv/linux/x86_64/x32/gettimeofday.c
@@ -0,0 +1,35 @@
+/* The gettimeofday system call.  Linux/x32 version.
+   Copyright (C) 2012 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
+# include <dl-vdso.h>
+libc_ifunc_vdso (__gettimeofday, __vdso_gettimeofday)
+#else
+# include <errno.h>
+# include <sysdep.h>
+# include <sys/time.h>
+
+int
+__gettimeofday (struct timeval *tv, struct timezone *tz)
+{
+  return INLINE_SYSCALL (gettimeofday, 2, tv, tz);
+}
+#endif
+
+weak_alias (__gettimeofday, gettimeofday)
+strong_alias (__gettimeofday, __gettimeofday_internal)
diff --git a/sysdeps/unix/sysv/linux/x86_64/x32/time.c
b/sysdeps/unix/sysv/linux/x86_64/x32/time.c
new file mode 100644
index 0000000..059cecd
--- /dev/null
+++ b/sysdeps/unix/sysv/linux/x86_64/x32/time.c
@@ -0,0 +1,61 @@
+/* The time system call.  Linux/x32 version.
+   Copyright (C) 2012 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 <errno.h>
+#include <sysdep.h>
+#include <time.h>
+
+# undef INLINE_SYSCALL
+# define INLINE_SYSCALL(name, nr, args...) \
+  ({									      \
+    unsigned long long int resultvar = INTERNAL_SYSCALL (name, , nr, args);   \
+    if (__builtin_expect (INTERNAL_SYSCALL_ERROR_P (resultvar, ), 0))	      \
+      {									      \
+	__set_errno (INTERNAL_SYSCALL_ERRNO (resultvar, ));		      \
+	resultvar = (unsigned long long int) -1LL;			      \
+      }									      \
+    (long long int) resultvar; })
+
+# undef INTERNAL_SYSCALL_NCS
+# define INTERNAL_SYSCALL_NCS(name, err, nr, args...) \
+  ({									      \
+    unsigned long long int resultvar;					      \
+    LOAD_ARGS_##nr (args)						      \
+    LOAD_REGS_##nr							      \
+    asm volatile (							      \
+    "syscall\n\t"							      \
+    : "=a" (resultvar)							      \
+    : "0" (name) ASM_ARGS_##nr : "memory", "cc", "r11", "cx");		      \
+    (long long int) resultvar; })
+
+# undef INTERNAL_SYSCALL_ERROR_P
+# define INTERNAL_SYSCALL_ERROR_P(val, err) \
+  ((unsigned long long int) (long long int) (val) >= -4095LL)
+
+#ifdef SHARED
+# include <dl-vdso.h>
+libc_ifunc_vdso_hidden (time, __vdso_time)
+#else
+time_t
+time (time_t *t)
+{
+  return INLINE_SYSCALL (time, 1, t);
+}
+#endif
+
+libc_hidden_def (time)


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]