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]

[PATCH] Draft vDSO Submission for ppc/ppc64


Greetings,

I've taken a little time to extend the vDSO implementation on ppc/ppc64 to 
include a couple more functions. (Ben is going to supply the kernel 
implementation) So in this enclosed patch there are use of vDSOs now for 
gettimeofday, clock_gettime and clock_getres if the kernel has them 
available. Patch builds, make check pases.

comments welcome (and expected :-).

2005-05-04  Steven Munroe  <sjmunroe@us.ibm.com>
2005-10-31 Tom Gall <tom_gall@vnet.ibm.com>

        * elf/rtld.c (dl_main): Initialize l_local_scope for sysinfo_map.
        * sysdeps/powerpc/elf/libc-start.c: Move this.
        * sysdeps/unix/sysv/linux/powerpc/libc-start.c: To here.
        * sysdeps/unix/sysv/linux/powerpc/Makefile: Add routines += dl-vdso.
        * sysdeps/unix/sysv/linux/powerpc/bits/libc-vdso.h: New file.
        * sysdeps/unix/sysv/linux/powerpc/dl-vdso.c: New file.
        * sysdeps/unix/sysv/linux/powerpc/dl-vdso.h: New file.
        * sysdeps/unix/sysv/linux/powerpc/gettimeofday.c: New file.
        * sysdeps/unix/sysv/linux/powerpc/clock_gettime.c: New file.
        * sysdeps/unix/sysv/linux/powerpc/clock_getres.c: New file.

diff -uNr libc-10-27-orig/elf/rtld.c libc/elf/rtld.c
--- libc-10-27-orig/elf/rtld.c	2005-10-27 11:57:22.319292248 -0400
+++ libc/elf/rtld.c	2005-10-27 15:08:57.196321848 -0400
@@ -1296,6 +1296,13 @@
 	  elf_get_dynamic_info (l, dyn_temp);
 	  _dl_setup_hash (l);
 	  l->l_relocated = 1;
+	  /* Initialize l_local_scope to contain just this map. This allows 
+	     the use of dl_lookup_symbol_x to resolve symbols within the vdso.
+	     So we create a single entry list pointing to l_real as its only
+	     element */
+	  
+	  l->l_local_scope[0]->r_nlist = 1;
+	  l->l_local_scope[0]->r_list = &l->l_real;
 
 	  /* Now that we have the info handy, use the DSO image's soname
 	     so this object can be looked up by name.  Note that we do not
diff -uNr libc-10-27-orig/sysdeps/powerpc/elf/libc-start.c libc/sysdeps/powerpc/elf/libc-start.c
--- libc-10-27-orig/sysdeps/powerpc/elf/libc-start.c	2005-10-27 11:57:23.455380728 -0400
+++ libc/sysdeps/powerpc/elf/libc-start.c	1969-12-31 19:00:00.000000000 -0500
@@ -1,99 +0,0 @@
-/* Copyright (C) 1998,2000,2001,2002,2003,2004 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, write to the Free
-   Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
-   02111-1307 USA.  */
-
-#include <stdlib.h>
-#include <unistd.h>
-#include <ldsodefs.h>
-#include <bp-start.h>
-#include <bp-sym.h>
-
-extern int __cache_line_size;
-weak_extern (__cache_line_size)
-
-/* The main work is done in the generic function.  */
-#define LIBC_START_MAIN generic_start_main
-#define LIBC_START_DISABLE_INLINE
-#define LIBC_START_MAIN_AUXVEC_ARG
-#define MAIN_AUXVEC_ARG
-#include <sysdeps/generic/libc-start.c>
-
-
-struct startup_info
-{
-  void *__unbounded sda_base;
-  int (*main) (int, char **, char **, void *);
-  int (*init) (int, char **, char **, void *);
-  void (*fini) (void);
-};
-
-
-int
-/* GKM FIXME: GCC: this should get __BP_ prefix by virtue of the
-   BPs in the arglist of startup_info.main and startup_info.init. */
-BP_SYM (__libc_start_main) (int argc, char *__unbounded *__unbounded ubp_av,
-			    char *__unbounded *__unbounded ubp_ev,
-			    ElfW(auxv_t) *__unbounded auxvec,
-			    void (*rtld_fini) (void),
-			    struct startup_info *__unbounded stinfo,
-			    char *__unbounded *__unbounded stack_on_entry)
-{
-#if __BOUNDED_POINTERS__
-  char **argv;
-#else
-# define argv ubp_av
-#endif
-
-  /* the PPC SVR4 ABI says that the top thing on the stack will
-     be a NULL pointer, so if not we assume that we're being called
-     as a statically-linked program by Linux...	 */
-  if (*stack_on_entry != NULL)
-    {
-      char *__unbounded *__unbounded temp;
-      /* ...in which case, we have argc as the top thing on the
-	 stack, followed by argv (NULL-terminated), envp (likewise),
-	 and the auxilary vector.  */
-      /* 32/64-bit agnostic load from stack */
-      argc = *(long int *__unbounded) stack_on_entry;
-      ubp_av = stack_on_entry + 1;
-      ubp_ev = ubp_av + argc + 1;
-#ifdef HAVE_AUX_VECTOR
-      temp = ubp_ev;
-      while (*temp != NULL)
-        ++temp;
-      auxvec = (ElfW(auxv_t) *)++temp;
-#endif
-      rtld_fini = NULL;
-    }
-
-  /* Initialize the __cache_line_size variable from the aux vector.  */
-  for (ElfW(auxv_t) *av = auxvec; av->a_type != AT_NULL; ++av)
-    switch (av->a_type)
-      {
-      case AT_DCACHEBSIZE:
-        {
-          int *cls = & __cache_line_size;
-          if (cls != NULL)
-            *cls = av->a_un.a_val;
-        }
-        break;
-      }
-
-  return generic_start_main (stinfo->main, argc, ubp_av, auxvec,
-			     stinfo->init, stinfo->fini, rtld_fini,
-			     stack_on_entry);
-}
diff -uNr libc-10-27-orig/sysdeps/unix/sysv/linux/powerpc/bits/libc-vdso.h libc/sysdeps/unix/sysv/linux/powerpc/bits/libc-vdso.h
--- libc-10-27-orig/sysdeps/unix/sysv/linux/powerpc/bits/libc-vdso.h	1969-12-31 19:00:00.000000000 -0500
+++ libc/sysdeps/unix/sysv/linux/powerpc/bits/libc-vdso.h	2005-10-27 21:23:37.972294520 -0400
@@ -0,0 +1,38 @@
+/* Resolved function pointers to VDSO functions.
+   Copyright (C) 2005 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, write to the Free
+   Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+   02111-1307 USA.  */
+
+
+#ifndef _LIBC_VDSO_H
+#define _LIBC_VDSO_H
+
+#ifdef SHARED
+extern
+__typeof (__gettimeofday) *__vdso_gettimeofday attribute_hidden;
+/* extern
+__typeof (clock_gettime) *__vdso_clock_gettime attribute_hidden;
+extern
+__typeof (clock_getres) *__vdso_clock_getres attribute_hidden; */
+
+typedef int (* __vdso_clock_gettime_t)(clockid_t, struct timespec *) attribute_hidden;
+
+typedef  int(* __vdso_clock_getres_t)(struct timeval*, void*) attribute_hidden;
+
+#endif
+
+#endif /* _LIBC_VDSO_H */
diff -uNr libc-10-27-orig/sysdeps/unix/sysv/linux/powerpc/clock_getres.c libc/sysdeps/unix/sysv/linux/powerpc/clock_getres.c
--- libc-10-27-orig/sysdeps/unix/sysv/linux/powerpc/clock_getres.c	1969-12-31 19:00:00.000000000 -0500
+++ libc/sysdeps/unix/sysv/linux/powerpc/clock_getres.c	2005-10-27 16:48:11.034302784 -0400
@@ -0,0 +1,197 @@
+/* clock_getres -- Get the resolution of a POSIX clockid_t.  Linux version.
+   Copyright (C) 2003, 2004 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, write to the Free
+   Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+   02111-1307 USA.  */
+
+#include <sysdep.h>
+#include <errno.h>
+#include <time.h>
+#include <sysdeps/unix/sysv/linux/kernel-posix-cpu-timers.h>
+#include <sysdeps/unix/sysv/linux/kernel-features.h>
+
+#undef __clock_getres
+#include <bits/libc-vdso.h>
+
+
+#define SYSCALL_GETRES_MONOTONIC \
+#ifdef SHARED                    \
+  if (__vdso_clock_getres== NULL)\
+    retval = INLINE_SYSCALL (clock_getres, 2, clock_id, res); \
+  else \
+    return (__vdso_clock_getres) (clock_id, tp); \
+  break
+
+#define SYSCALL_GETRES_REALTIME \
+  retval = INLINE_SYSCALL (clock_getres, 2, clock_id, res); \
+  break
+
+#ifdef __ASSUME_POSIX_TIMERS
+
+/* This means the REALTIME and MONOTONIC clock are definitely
+   supported in the kernel.  */
+# define SYSDEP_GETRES							      \
+  SYSDEP_GETRES_CPUTIME						      \
+  case CLOCK_REALTIME:							      \
+    SYSCALL_GETRES_REALTIME                                                   \
+  case CLOCK_MONOTONIC:						      \
+    SYSCALL_GETRES_MONOTONIC
+
+# define __libc_missing_posix_timers 0
+#elif defined __NR_clock_getres
+/* Is the syscall known to exist?  */
+extern int __libc_missing_posix_timers attribute_hidden;
+
+static inline int
+maybe_syscall_getres (clockid_t clock_id, struct timespec *res)
+{
+  int e = EINVAL;
+
+  if (!__libc_missing_posix_timers)
+    {
+      INTERNAL_SYSCALL_DECL (err);
+      int r = INTERNAL_SYSCALL (clock_getres, err, 2, clock_id, res);
+      if (!INTERNAL_SYSCALL_ERROR_P (r, err))
+	return 0;
+
+      e = INTERNAL_SYSCALL_ERRNO (r, err);
+      if (e == ENOSYS)
+	{
+	  __libc_missing_posix_timers = 1;
+	  e = EINVAL;
+	}
+    }
+
+  return e;
+}
+
+/* The REALTIME and MONOTONIC clock might be available.  Try the
+   syscall first.  */
+# define SYSDEP_GETRES							      \
+  SYSDEP_GETRES_CPUTIME						      \
+  case CLOCK_REALTIME:							      \
+  case CLOCK_MONOTONIC:						      \
+    retval = maybe_syscall_getres (clock_id, res);			      \
+    if (retval == 0)							      \
+      break;								      \
+    /* Fallback code.  */						      \
+    if (retval == EINVAL && clock_id == CLOCK_REALTIME)			      \
+      retval = realtime_getres (res);					      \
+    else								      \
+      {									      \
+	__set_errno (retval);						      \
+	retval = -1;							      \
+      }									      \
+    break;
+#endif
+
+#ifdef __NR_clock_getres
+/* We handled the REALTIME clock here.  */
+# define HANDLED_REALTIME	1
+# define HANDLED_CPUTIME	1
+
+# if __ASSUME_POSIX_CPU_TIMERS > 0
+
+#  define SYSDEP_GETRES_CPU SYSCALL_GETRES
+#  define SYSDEP_GETRES_CPUTIME	/* Default catches them too.  */
+
+# else
+
+extern int __libc_missing_posix_cpu_timers attribute_hidden;
+
+static int
+maybe_syscall_getres_cpu (clockid_t clock_id, struct timespec *res)
+{
+  int e = EINVAL;
+
+  if (!__libc_missing_posix_cpu_timers)
+    {
+      INTERNAL_SYSCALL_DECL (err);
+      int r = INTERNAL_SYSCALL (clock_getres, err, 2, clock_id, res);
+      if (!INTERNAL_SYSCALL_ERROR_P (r, err))
+	return 0;
+
+      e = INTERNAL_SYSCALL_ERRNO (r, err);
+# ifndef __ASSUME_POSIX_TIMERS
+      if (e == ENOSYS)
+	{
+	  __libc_missing_posix_timers = 1;
+	  __libc_missing_posix_cpu_timers = 1;
+	  e = EINVAL;
+	}
+      else
+# endif
+	{
+	  if (e == EINVAL)
+	    {
+	      /* Check whether the kernel supports CPU clocks at all.
+		 If not, record it for the future.  */
+	      r = INTERNAL_SYSCALL (clock_getres, err, 2,
+				    MAKE_PROCESS_CPUCLOCK (0, CPUCLOCK_SCHED),
+				    NULL);
+	      if (INTERNAL_SYSCALL_ERROR_P (r, err))
+		__libc_missing_posix_cpu_timers = 1;
+	    }
+	}
+    }
+
+  return e;
+}
+
+#  define SYSDEP_GETRES_CPU						      \
+  retval = maybe_syscall_getres_cpu (clock_id, res);			      \
+  if (retval == 0)							      \
+    break;								      \
+  if (retval != EINVAL || !__libc_missing_posix_cpu_timers)		      \
+    {									      \
+      __set_errno (retval);						      \
+      retval = -1;							      \
+      break;								      \
+    }									      \
+  retval = -1 /* Otherwise continue on to the HP_TIMING version.  */;
+
+static inline int
+maybe_syscall_getres_cputime (clockid_t clock_id, struct timespec *res)
+{
+  return maybe_syscall_getres_cpu
+    (clock_id == CLOCK_THREAD_CPUTIME_ID
+     ? MAKE_THREAD_CPUCLOCK (0, CPUCLOCK_SCHED)
+     : MAKE_PROCESS_CPUCLOCK (0, CPUCLOCK_SCHED),
+     res);
+}
+
+#  define SYSDEP_GETRES_CPUTIME						      \
+    case CLOCK_PROCESS_CPUTIME_ID:					      \
+    case CLOCK_THREAD_CPUTIME_ID:					      \
+      retval = maybe_syscall_getres_cputime (clock_id, res);		      \
+      if (retval == 0)							      \
+	break;								      \
+      if (retval != EINVAL || !__libc_missing_posix_cpu_timers)		      \
+	{								      \
+	  __set_errno (retval);						      \
+	  retval = -1;							      \
+	  break;							      \
+	}								      \
+      retval = hp_timing_getres (res);					      \
+      break;
+#  if !HP_TIMING_AVAIL
+#   define hp_timing_getres(res) (__set_errno (EINVAL), -1)
+#  endif
+
+# endif
+#endif
+
+#include <sysdeps/posix/clock_getres.c>
diff -uNr libc-10-27-orig/sysdeps/unix/sysv/linux/powerpc/clock_gettime.c libc/sysdeps/unix/sysv/linux/powerpc/clock_gettime.c
--- libc-10-27-orig/sysdeps/unix/sysv/linux/powerpc/clock_gettime.c	1969-12-31 19:00:00.000000000 -0500
+++ libc/sysdeps/unix/sysv/linux/powerpc/clock_gettime.c	2005-10-27 16:47:25.676276640 -0400
@@ -0,0 +1,196 @@
+/* clock_gettime -- Get current time from a POSIX clockid_t.  Linux version.
+   Copyright (C) 2003, 2004 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, write to the Free
+   Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+   02111-1307 USA.  */
+
+#include <sysdep.h>
+#include <errno.h>
+#include <time.h>
+#include <sysdeps/unix/sysv/linux/kernel-posix-cpu-timers.h>
+#include <sysdeps/unix/sysv/linux/kernel-features.h>
+
+#undef __clock_gettime
+#include <bits/libc-vdso.h>
+
+#define SYSCALL_GETTIME_CLOCK_MONOTONIC \
+#ifdef SHARED                           \
+  if (__vdso_clock_gettime== NULL)      \
+    retval = INLINE_SYSCALL (clock_gettime, 2, clock_id, tp); \
+  else \
+    return (__vdso_clock_gettime) (clock_id, tp); \
+  break
+
+#define SYSCALL_GETTIME_CLOCK_REALTIME \
+  retval = INLINE_SYSCALL (clock_gettime, 2, clock_id, tp); \
+  break
+
+#ifdef __ASSUME_POSIX_TIMERS
+
+/* This means the REALTIME and MONOTONIC clock are definitely
+   supported in the kernel.  */
+# define SYSDEP_GETTIME							      \
+  SYSDEP_GETTIME_CPUTIME						      \
+  case CLOCK_REALTIME:							      \
+    SYSCALL_GETTIME_CLOCK_REALTIME                                            \
+  case CLOCK_MONOTONIC:							      \
+    SYSCALL_GETTIME_CLOCK_MONOTONIC
+
+# define __libc_missing_posix_timers 0
+#elif defined __NR_clock_gettime
+/* Is the syscall known to exist?  */
+int __libc_missing_posix_timers attribute_hidden;
+
+static inline int
+maybe_syscall_gettime (clockid_t clock_id, struct timespec *tp)
+{
+  int e = EINVAL;
+
+  if (!__libc_missing_posix_timers)
+    {
+      INTERNAL_SYSCALL_DECL (err);
+      int r = INTERNAL_SYSCALL (clock_gettime, err, 2, clock_id, tp);
+      if (!INTERNAL_SYSCALL_ERROR_P (r, err))
+	return 0;
+
+      e = INTERNAL_SYSCALL_ERRNO (r, err);
+      if (e == ENOSYS)
+	{
+	  __libc_missing_posix_timers = 1;
+	  e = EINVAL;
+	}
+    }
+
+  return e;
+}
+
+/* The REALTIME and MONOTONIC clock might be available.  Try the
+   syscall first.  */
+# define SYSDEP_GETTIME							      \
+  SYSDEP_GETTIME_CPUTIME						      \
+  case CLOCK_REALTIME:							      \
+  case CLOCK_MONOTONIC:							      \
+    retval = maybe_syscall_gettime (clock_id, tp);			      \
+    if (retval == 0)							      \
+      break;								      \
+    /* Fallback code.  */						      \
+    if (retval == EINVAL && clock_id == CLOCK_REALTIME)			      \
+      retval = realtime_gettime (tp);					      \
+    else 								      \
+      {									      \
+	__set_errno (retval);						      \
+	retval = -1;							      \
+      }									      \
+    break;
+#endif
+
+#ifdef __NR_clock_gettime
+/* We handled the REALTIME clock here.  */
+# define HANDLED_REALTIME	1
+# define HANDLED_CPUTIME	1
+
+# if __ASSUME_POSIX_CPU_TIMERS > 0
+
+#  define SYSDEP_GETTIME_CPU SYSCALL_GETTIME
+#  define SYSDEP_GETTIME_CPUTIME	/* Default catches them too.  */
+
+# else
+
+int __libc_missing_posix_cpu_timers attribute_hidden;
+
+static int
+maybe_syscall_gettime_cpu (clockid_t clock_id, struct timespec *tp)
+{
+  int e = EINVAL;
+
+  if (!__libc_missing_posix_cpu_timers)
+    {
+      INTERNAL_SYSCALL_DECL (err);
+      int r = INTERNAL_SYSCALL (clock_gettime, err, 2, clock_id, tp);
+      if (!INTERNAL_SYSCALL_ERROR_P (r, err))
+	return 0;
+
+      e = INTERNAL_SYSCALL_ERRNO (r, err);
+# ifndef __ASSUME_POSIX_TIMERS
+      if (e == ENOSYS)
+	{
+	  __libc_missing_posix_timers = 1;
+	  __libc_missing_posix_cpu_timers = 1;
+	  e = EINVAL;
+	}
+      else
+# endif
+	{
+	  if (e == EINVAL)
+	    {
+	      /* Check whether the kernel supports CPU clocks at all.
+		 If not, record it for the future.  */
+	      r = INTERNAL_SYSCALL (clock_getres, err, 2,
+				    MAKE_PROCESS_CPUCLOCK (0, CPUCLOCK_SCHED),
+				    NULL);
+	      if (INTERNAL_SYSCALL_ERROR_P (r, err))
+		__libc_missing_posix_cpu_timers = 1;
+	    }
+	}
+    }
+
+  return e;
+}
+
+#  define SYSDEP_GETTIME_CPU						      \
+  retval = maybe_syscall_gettime_cpu (clock_id, tp);			      \
+  if (retval == 0)							      \
+    break;								      \
+  if (retval != EINVAL || !__libc_missing_posix_cpu_timers)		      \
+    {									      \
+      __set_errno (retval);						      \
+      retval = -1;							      \
+      break;								      \
+    }									      \
+  retval = -1 /* Otherwise continue on to the HP_TIMING version.  */;
+
+static inline int
+maybe_syscall_gettime_cputime (clockid_t clock_id, struct timespec *tp)
+{
+  return maybe_syscall_gettime_cpu
+    (clock_id == CLOCK_THREAD_CPUTIME_ID
+     ? MAKE_THREAD_CPUCLOCK (0, CPUCLOCK_SCHED)
+     : MAKE_PROCESS_CPUCLOCK (0, CPUCLOCK_SCHED),
+     tp);
+}
+
+#  define SYSDEP_GETTIME_CPUTIME					      \
+    case CLOCK_PROCESS_CPUTIME_ID:					      \
+    case CLOCK_THREAD_CPUTIME_ID:					      \
+      retval = maybe_syscall_gettime_cputime (clock_id, tp);		      \
+      if (retval == 0)							      \
+	break;								      \
+      if (retval != EINVAL || !__libc_missing_posix_cpu_timers)		      \
+	{								      \
+	  __set_errno (retval);						      \
+	  retval = -1;							      \
+	  break;							      \
+	}								      \
+      retval = hp_timing_gettime (clock_id, tp);			      \
+      break;
+#  if !HP_TIMING_AVAIL
+#   define hp_timing_gettime(clock_id, tp) (__set_errno (EINVAL), -1)
+#  endif
+
+# endif
+#endif
+
+#include <sysdeps/unix/clock_gettime.c>
diff -uNr libc-10-27-orig/sysdeps/unix/sysv/linux/powerpc/dl-vdso.c libc/sysdeps/unix/sysv/linux/powerpc/dl-vdso.c
--- libc-10-27-orig/sysdeps/unix/sysv/linux/powerpc/dl-vdso.c	1969-12-31 19:00:00.000000000 -0500
+++ libc/sysdeps/unix/sysv/linux/powerpc/dl-vdso.c	2005-10-27 15:08:57.198321544 -0400
@@ -0,0 +1,78 @@
+/* VDSO symbol handling in the ELF dynamic linker.
+   Copyright (C) 2005 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, write to the Free
+   Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+   02111-1307 USA.  */
+
+#include "config.h"
+#include <dl-hash.h>
+#include <ldsodefs.h>
+
+void *internal_function
+_dl_vdso_sym (const char *name)
+{
+  const ElfW (Sym) * ref = NULL;
+  struct link_map *map = GLRO (dl_sysinfo_map);
+  void *value = NULL;
+  lookup_t result;
+
+  if (map != NULL)
+    {
+      /* Search the scope of the given vdso map.  */
+      result = GLRO (dl_lookup_symbol_x) (name, map, &ref,
+					  map->l_local_scope,
+					  NULL, 0, 0, NULL);
+
+      if (ref != NULL)
+	{
+	  value = DL_SYMBOL_ADDRESS (result, ref);
+	}
+    }
+
+  return value;
+}
+
+void *internal_function
+_dl_vdso_vsym (const char *name, const char *version)
+{
+  const ElfW (Sym) * ref = NULL;
+  struct link_map *map = GLRO (dl_sysinfo_map);
+  void *value = NULL;
+  struct r_found_version vers;
+  lookup_t result;
+
+  if (map != NULL)
+    {
+      /* Compute hash value to the version string.  */
+      vers.name = version;
+      vers.hidden = 1;
+      vers.hash = _dl_elf_hash (version);
+      /* We don't have a specific file where the symbol can be found.  */
+      vers.filename = NULL;
+
+      /* Search the scope of the vdso map.  */
+      result = GLRO (dl_lookup_symbol_x) (name, map, &ref,
+					  map->l_local_scope,
+					  &vers, 0, 0, NULL);
+
+      if (ref != NULL)
+	{
+	  value = DL_SYMBOL_ADDRESS (result, ref);
+
+	}
+    }
+  return value;
+}
diff -uNr libc-10-27-orig/sysdeps/unix/sysv/linux/powerpc/dl-vdso.h libc/sysdeps/unix/sysv/linux/powerpc/dl-vdso.h
--- libc-10-27-orig/sysdeps/unix/sysv/linux/powerpc/dl-vdso.h	1969-12-31 19:00:00.000000000 -0500
+++ libc/sysdeps/unix/sysv/linux/powerpc/dl-vdso.h	2005-10-27 15:08:57.199321392 -0400
@@ -0,0 +1,30 @@
+/* Run-time dynamic linker data structures for loaded ELF shared objects.
+   Copyright (C) 2005 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, write to the Free
+   Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+   02111-1307 USA.  */
+
+#ifndef	_DL_VDSO_H
+#define _DL_VDSO_H
+
+/* Functions for resolving symbols in the VDSO link map.  */
+extern void* _dl_vdso_sym(const char *name)
+     internal_function attribute_hidden;
+
+extern void* _dl_vdso_vsym(const char *name, const char *version)
+     internal_function attribute_hidden;
+
+#endif /* ldsodefs.h */
diff -uNr libc-10-27-orig/sysdeps/unix/sysv/linux/powerpc/gettimeofday.c libc/sysdeps/unix/sysv/linux/powerpc/gettimeofday.c
--- libc-10-27-orig/sysdeps/unix/sysv/linux/powerpc/gettimeofday.c	1969-12-31 19:00:00.000000000 -0500
+++ libc/sysdeps/unix/sysv/linux/powerpc/gettimeofday.c	2005-10-27 22:02:21.529309368 -0400
@@ -0,0 +1,48 @@
+/* Copyright (C) 2005 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, write to the Free
+   Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+   02111-1307 USA.  */
+
+#include <sysdep.h>
+#include <bp-checks.h>
+#include <stddef.h>
+#include <sys/time.h>
+#include <time.h>
+
+#undef __gettimeofday
+#include <bits/libc-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 (tv, tz)
+     struct timeval *tv;
+     struct timezone *tz;
+{
+#ifdef SHARED
+  if (__vdso_gettimeofday == NULL)
+#endif
+    return INLINE_SYSCALL (gettimeofday, 2, CHECK_1 (tv), CHECK_1 (tz));
+#ifdef SHARED
+  else
+    { 
+      return (*__vdso_gettimeofday) (tv, tz);
+    }
+#endif
+}
+
+INTDEF (__gettimeofday) weak_alias (__gettimeofday, gettimeofday)
diff -uNr libc-10-27-orig/sysdeps/unix/sysv/linux/powerpc/libc-start.c libc/sysdeps/unix/sysv/linux/powerpc/libc-start.c
--- libc-10-27-orig/sysdeps/unix/sysv/linux/powerpc/libc-start.c	1969-12-31 19:00:00.000000000 -0500
+++ libc/sysdeps/unix/sysv/linux/powerpc/libc-start.c	2005-10-28 14:24:04.591377024 -0400
@@ -0,0 +1,188 @@
+/* Copyright (C) 1998,2000,2001,2002,2003,2004,2005 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, write to the Free
+   Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+   02111-1307 USA.  */
+
+#include <stdlib.h>
+#include <unistd.h>
+#include <ldsodefs.h>
+#include <bp-start.h>
+#include <bp-sym.h>
+
+extern int __cache_line_size;
+weak_extern (__cache_line_size)
+
+/* The main work is done in the generic function.  */
+#define LIBC_START_MAIN generic_start_main
+#define LIBC_START_DISABLE_INLINE
+#define LIBC_START_MAIN_AUXVEC_ARG
+#define MAIN_AUXVEC_ARG
+#define INIT_MAIN_ARGS
+#include <sysdeps/generic/libc-start.c>
+
+
+struct startup_info
+{
+  void *__unbounded sda_base;
+  int (*main) (int, char **, char **, void *);
+  int (*init) (int, char **, char **, void *);
+  void (*fini) (void);
+};
+
+
+#ifdef SHARED
+#include <sys/time.h>
+#include <dl-vdso.h>
+#undef __gettimeofday
+#undef __clock_gettime
+#undef __clock_getres
+#include <bits/libc-vdso.h>
+
+__typeof (__gettimeofday) *__vdso_gettimeofday attribute_hidden;
+
+__vdso_clock_gettime_t __vdso_clock_gettime;
+__vdso_clock_getres_t __vdso_clock_getres;
+
+#if __WORDSIZE == 64
+typedef struct
+  {
+    void	*func;
+    void	*toc_ptr;
+    void	*extra;
+  } _ppc_func_desciptor;
+	
+static struct
+  {
+    _ppc_func_desciptor	fd_gettimeofday;
+    _ppc_func_desciptor	fd_clock_gettime;
+    _ppc_func_desciptor	fd_clock_getres;
+  } __vdso_descriptor;
+#endif
+
+static inline void 
+_libc_vdso_platform_setup(void)
+{
+  void	*vdso_ref = NULL;
+	
+  __vdso_gettimeofday = NULL;
+  __vdso_clock_gettime = NULL;
+  __vdso_clock_getres = NULL;
+
+  vdso_ref = _dl_vdso_sym("__kernel_gettimeofday");
+			    
+#if __WORDSIZE == 64
+  if ( vdso_ref != NULL)
+  {
+     __vdso_descriptor.fd_gettimeofday.func = vdso_ref;
+     __vdso_descriptor.fd_gettimeofday.toc_ptr = NULL;
+     __vdso_descriptor.fd_gettimeofday.extra = NULL;
+     __vdso_gettimeofday = (int(*) (struct timeval*, void*))
+                             &__vdso_descriptor.fd_gettimeofday;
+  }
+#else
+  __vdso_gettimeofday = (int(*)(struct timeval*, void*))vdso_ref;
+#endif
+
+  vdso_ref = _dl_vdso_sym("__kernel_clock_gettime");
+
+#if __WORDSIZE == 64
+  if ( vdso_ref != NULL)
+  {
+     __vdso_descriptor.fd_clock_gettime.func = vdso_ref;
+     __vdso_descriptor.fd_clock_gettime.toc_ptr = NULL;
+     __vdso_descriptor.fd_clock_gettime.extra = NULL;
+     __vdso_clock_gettime = (int(*) (clockid_t, struct timespec*))
+                             &__vdso_descriptor.fd_clock_gettime;
+  }
+#else
+  __vdso_clock_gettime = (int(*)(clockid_t, struct timespec*))vdso_ref;
+#endif
+
+  vdso_ref = _dl_vdso_sym("__kernel_clock_getres");
+
+#if __WORDSIZE == 64
+  if ( vdso_ref != NULL)
+  {
+     __vdso_descriptor.fd_clock_getres.func = vdso_ref;
+     __vdso_descriptor.fd_clock_getres.toc_ptr = NULL;
+     __vdso_descriptor.fd_clock_getres.extra = NULL;
+     __vdso_clock_getres= (int(*) (struct timeval*, void*))
+                             &__vdso_descriptor.fd_clock_getres;
+  }
+#else
+  __vdso_clock_getres = (int(*)(struct timeval*, void*))vdso_ref;
+#endif
+}
+#endif
+
+int
+/* GKM FIXME: GCC: this should get __BP_ prefix by virtue of the
+   BPs in the arglist of startup_info.main and startup_info.init. */
+BP_SYM (__libc_start_main) (int argc, char *__unbounded *__unbounded ubp_av,
+			    char *__unbounded *__unbounded ubp_ev,
+			    ElfW(auxv_t) *__unbounded auxvec,
+			    void (*rtld_fini) (void),
+			    struct startup_info *__unbounded stinfo,
+			    char *__unbounded *__unbounded stack_on_entry)
+{
+#if __BOUNDED_POINTERS__
+  char **argv;
+#else
+# define argv ubp_av
+#endif
+
+  /* the PPC SVR4 ABI says that the top thing on the stack will
+     be a NULL pointer, so if not we assume that we're being called
+     as a statically-linked program by Linux...	 */
+  if (*stack_on_entry != NULL)
+    {
+      char *__unbounded *__unbounded temp;
+      /* ...in which case, we have argc as the top thing on the
+	 stack, followed by argv (NULL-terminated), envp (likewise),
+	 and the auxilary vector.  */
+      /* 32/64-bit agnostic load from stack */
+      argc = *(long int *__unbounded) stack_on_entry;
+      ubp_av = stack_on_entry + 1;
+      ubp_ev = ubp_av + argc + 1;
+#ifdef HAVE_AUX_VECTOR
+      temp = ubp_ev;
+      while (*temp != NULL)
+        ++temp;
+      auxvec = (ElfW(auxv_t) *)++temp;
+#endif
+      rtld_fini = NULL;
+    }
+
+  /* Initialize the __cache_line_size variable from the aux vector.  */
+  for (ElfW(auxv_t) *av = auxvec; av->a_type != AT_NULL; ++av)
+    switch (av->a_type)
+      {
+      case AT_DCACHEBSIZE:
+        {
+          int *cls = & __cache_line_size;
+          if (cls != NULL)
+            *cls = av->a_un.a_val;
+        }
+        break;
+      }
+#ifdef SHARED
+  /* Resolve and initialize function pointers for VDSO functions.  */
+  _libc_vdso_platform_setup();
+#endif
+  return generic_start_main (stinfo->main, argc, ubp_av, auxvec,
+			     stinfo->init, stinfo->fini, rtld_fini,
+			     stack_on_entry);
+}
diff -uNr libc-10-27-orig/sysdeps/unix/sysv/linux/powerpc/Makefile libc/sysdeps/unix/sysv/linux/powerpc/Makefile
--- libc-10-27-orig/sysdeps/unix/sysv/linux/powerpc/Makefile	2005-10-27 11:57:24.278389632 -0400
+++ libc/sysdeps/unix/sysv/linux/powerpc/Makefile	2005-10-27 15:08:57.197321696 -0400
@@ -2,3 +2,8 @@
 ifeq ($(subdir),rt)
 librt-routines += rt-sysdep
 endif
+
+ifeq ($(subdir),misc)
+routines += dl-vdso
+endif
+


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