This is the mail archive of the
libc-alpha@sources.redhat.com
mailing list for the glibc project.
[PATCH] ppc vdso, gettimeofday part II
- From: Steve Munroe <sjmunroe at us dot ibm dot com>
- To: libc-alpha at sources dot redhat dot com, Roland McGrath <roland at redhat dot com>
- Date: Wed, 04 May 2005 16:49:35 -0500
- Subject: [PATCH] ppc vdso, gettimeofday part II
- Reply-to: sjmunroe at vnet dot ibm dot com
Reworked patch ber comments.
2005-05-04 Steven Munroe <sjmunroe@us.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.
diff -urN libc24-cvstip-20050427/elf/rtld.c libc24/elf/rtld.c
--- libc24-cvstip-20050427/elf/rtld.c 2005-04-07 15:56:48.000000000 -0500
+++ libc24/elf/rtld.c 2005-04-27 15:52:25.000000000 -0500
@@ -1274,6 +1274,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 -urN libc24-cvstip-20050427/sysdeps/powerpc/elf/libc-start.c libc24/sysdeps/powerpc/elf/libc-start.c
--- libc24-cvstip-20050427/sysdeps/powerpc/elf/libc-start.c Sat Apr 03 19:06:07 2004
+++ libc24/sysdeps/powerpc/elf/libc-start.c Wed Dec 31 18:00:00 1969
@@ -1,100 +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
-#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);
-};
-
-
-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 -urN libc24-cvstip-20050427/sysdeps/unix/sysv/linux/powerpc/Makefile libc24/sysdeps/unix/sysv/linux/powerpc/Makefile
--- libc24-cvstip-20050427/sysdeps/unix/sysv/linux/powerpc/Makefile 2004-04-19 01:18:35.000000000 -0500
+++ libc24/sysdeps/unix/sysv/linux/powerpc/Makefile 2005-05-04 13:44:40.000000000 -0500
@@ -2,3 +2,8 @@
ifeq ($(subdir),rt)
librt-routines += rt-sysdep
endif
+
+ifeq ($(subdir),misc)
+routines += dl-vdso
+endif
+
diff -urN libc24-cvstip-20050427/sysdeps/unix/sysv/linux/powerpc/bits/libc-vdso.h libc24/sysdeps/unix/sysv/linux/powerpc/bits/libc-vdso.h
--- libc24-cvstip-20050427/sysdeps/unix/sysv/linux/powerpc/bits/libc-vdso.h Wed Dec 31 18:00:00 1969
+++ libc24/sysdeps/unix/sysv/linux/powerpc/bits/libc-vdso.h Fri Apr 29 14:17:48 2005
@@ -0,0 +1,30 @@
+/* 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;
+
+#endif
+
+#endif /* _LIBC_VDSO_H */
diff -urN libc24-cvstip-20050427/sysdeps/unix/sysv/linux/powerpc/dl-vdso.c libc24/sysdeps/unix/sysv/linux/powerpc/dl-vdso.c
--- libc24-cvstip-20050427/sysdeps/unix/sysv/linux/powerpc/dl-vdso.c Wed Dec 31 18:00:00 1969
+++ libc24/sysdeps/unix/sysv/linux/powerpc/dl-vdso.c Mon May 02 09:57:02 2005
@@ -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 -urN libc24-cvstip-20050427/sysdeps/unix/sysv/linux/powerpc/dl-vdso.h libc24/sysdeps/unix/sysv/linux/powerpc/dl-vdso.h
--- libc24-cvstip-20050427/sysdeps/unix/sysv/linux/powerpc/dl-vdso.h Wed Dec 31 18:00:00 1969
+++ libc24/sysdeps/unix/sysv/linux/powerpc/dl-vdso.h Mon May 02 13:52:14 2005
@@ -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 -urN libc24-cvstip-20050427/sysdeps/unix/sysv/linux/powerpc/gettimeofday.c libc24/sysdeps/unix/sysv/linux/powerpc/gettimeofday.c
--- libc24-cvstip-20050427/sysdeps/unix/sysv/linux/powerpc/gettimeofday.c Wed Dec 31 18:00:00 1969
+++ libc24/sysdeps/unix/sysv/linux/powerpc/gettimeofday.c Wed May 04 16:21:01 2005
@@ -0,0 +1,47 @@
+/* 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>
+
+#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 -urN libc24-cvstip-20050427/sysdeps/unix/sysv/linux/powerpc/libc-start.c libc24/sysdeps/unix/sysv/linux/powerpc/libc-start.c
--- libc24-cvstip-20050427/sysdeps/unix/sysv/linux/powerpc/libc-start.c Wed Dec 31 18:00:00 1969
+++ libc24/sysdeps/unix/sysv/linux/powerpc/libc-start.c Wed May 04 10:59:16 2005
@@ -0,0 +1,149 @@
+/* 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
+#include <bits/libc-vdso.h>
+
+__typeof (__gettimeofday) *__vdso_gettimeofday attribute_hidden;
+
+#if __WORDSIZE == 64
+typedef struct
+ {
+ void *func;
+ void *toc_ptr;
+ void *extra;
+ } _ppc_func_desciptor;
+
+static struct
+ {
+ _ppc_func_desciptor fd_gettimeofday;
+ } __vdso_descriptor;
+#endif
+
+static inline void
+_libc_vdso_platform_setup(void)
+{
+ void *vdso_ref = NULL;
+
+ __vdso_gettimeofday = 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
+}
+#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);
+}