This is the mail archive of the
libc-alpha@sources.redhat.com
mailing list for the glibc project.
[PATCH] ppc vdso, A working gettimeofday
- From: Steve Munroe <sjmunroe at us dot ibm dot com>
- To: Roland McGrath <roland at redhat dot com>, libc-alpha at sources dot redhat dot com
- Date: Fri, 29 Apr 2005 16:37:57 -0500
- Subject: [PATCH] ppc vdso, A working gettimeofday
- Reply-to: sjmunroe at vnet dot ibm dot com
This is the working kludge for binding to vdso functions from libc. In
this case userland gettimeofday for powerpc32/powerpc64. Tested with and
without (2.6.12 vs earlier kernels for powerpc) vdso and both modes
(32-/64-bit of powerpc.
2005-04-29 Steven Munroe <sjmunroe@us.ibm.com>
* elf/Versions: Export _dl_vdso_sym and _dl_vdso_vsym.
* elf/dl-vdso.c: New file.
* elf/rtld.c (dl_main): Initialize l_local_scope for sysinfo_map.
* sysdeps/powerpc/elf/libc-start.c: Include <sys/time.h>
[SHARED]: Include <bits/libc-vdso.h>.
[SHARED]: Declare *__vdso_gettimeofday, _libc_vdso_platform_setup.
[__WORDSIZE == 64]: Add static struct __vdso_descriptor.
[SHARED] (libc_start_main): Call _libc_vdso_platform_setup.
* sysdeps/unix/sysv/linux/Makefile [elf]: Add routines += dl-vdso.
* sysdeps/unix/sysv/linux/ldsodefs.h: Declare _dl_vdso_sym and
_dl_vdso_vsym.
* sysdeps/unix/sysv/linux/powerpc/bits/libc-vdso.h: New file.
* sysdeps/unix/sysv/linux/powerpc/gettimeofday.c: New file.
diff -urN libc24-cvstip-20050427/elf/Versions libc24/elf/Versions
--- libc24-cvstip-20050427/elf/Versions 2005-01-06 16:40:26.000000000 -0600
+++ libc24/elf/Versions 2005-04-27 15:52:25.000000000 -0500
@@ -21,6 +21,7 @@
# functions used in other libraries
_dl_addr;
_dl_sym; _dl_vsym;
+ _dl_vdso_sym; _dl_vdso_vsym;
_dl_open_hook;
__libc_dlopen_mode; __libc_dlsym; __libc_dlclose;
}
diff -urN libc24-cvstip-20050427/elf/dl-vdso.c libc24/elf/dl-vdso.c
--- libc24-cvstip-20050427/elf/dl-vdso.c Wed Dec 31 18:00:00 1969
+++ libc24/elf/dl-vdso.c Thu Apr 28 17:26:43 2005
@@ -0,0 +1,85 @@
+/* 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>
+
+
+//#ifdef SHARED
+#if 1
+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;
+}
+#endif
+
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 2004-04-03 19:06:07.000000000 -0600
+++ libc24/sysdeps/powerpc/elf/libc-start.c 2005-04-29 15:48:44.000000000 -0500
@@ -18,6 +18,7 @@
#include <stdlib.h>
#include <unistd.h>
+#include <sys/time.h>
#include <ldsodefs.h>
#include <bp-start.h>
#include <bp-sym.h>
@@ -33,7 +34,6 @@
#define INIT_MAIN_ARGS
#include <sysdeps/generic/libc-start.c>
-
struct startup_info
{
void *__unbounded sda_base;
@@ -42,6 +42,51 @@
void (*fini) (void);
};
+#ifdef SHARED
+#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
@@ -94,6 +139,10 @@
break;
}
+#ifdef SHARED
+ /* Initialize the VDSO call vector. */
+ _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 -urN libc24-cvstip-20050427/sysdeps/unix/sysv/linux/Makefile libc24/sysdeps/unix/sysv/linux/Makefile
--- libc24-cvstip-20050427/sysdeps/unix/sysv/linux/Makefile 2004-10-04 18:29:06.000000000 -0500
+++ libc24/sysdeps/unix/sysv/linux/Makefile 2005-04-28 16:32:00.000000000 -0500
@@ -142,6 +142,7 @@
ifeq ($(subdir),elf)
sysdep-rtld-routines += dl-brk dl-sbrk
+routines += dl-vdso
CPPFLAGS-lddlibc4 += -DNOT_IN_libc
endif
diff -urN libc24-cvstip-20050427/sysdeps/unix/sysv/linux/ldsodefs.h libc24/sysdeps/unix/sysv/linux/ldsodefs.h
--- libc24-cvstip-20050427/sysdeps/unix/sysv/linux/ldsodefs.h 2003-06-26 14:54:28.000000000 -0500
+++ libc24/sysdeps/unix/sysv/linux/ldsodefs.h 2005-04-27 15:52:25.000000000 -0500
@@ -1,5 +1,5 @@
/* Run-time dynamic linker data structures for loaded ELF shared objects.
- Copyright (C) 2001, 2002, 2003 Free Software Foundation, Inc.
+ Copyright (C) 2001, 2002, 2003, 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
@@ -53,4 +53,11 @@
# define HAVE_AUX_PAGESIZE
#endif
+/* 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/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/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 Fri Apr 29 15:27:24 2005
@@ -0,0 +1,50 @@
+/* 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)