This is the mail archive of the
libc-alpha@sources.redhat.com
mailing list for the glibc project.
[PATCH] Enable vdso symbol resolve
- 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>, Dwayne McConnell <dgm69 at us dot ibm dot com>
- Date: Mon, 25 Apr 2005 18:21:58 -0500
- Subject: [PATCH] Enable vdso symbol resolve
- Organization: IBM LTC
- Reply-to: sjmunroe at vnet dot ibm dot com
This is my first attempt at enabling generalized symbol resolve for
vdso. Hopefully this general enough to meet general requirements in
addition to powerpc needs.
If this general approach is acceptable I will follow up with the vdso
gettimeofday etc patches for powerpc.
2005-04-25 Steven Munroe <sjmunroe@us.ibm.com>
* elf/Versions: Export _dl_vdso_sym and _dl_vdso_vsym.
* elf/rtld.c (dl_main): Initialize l_local_scope for sysinfo_map.
* sysdeps/unix/sysv/linux/Makefile [elf]: Add routines += dl-vdso.
* sysdeps/unix/sysv/linux/dl-vdso.c: New file.
* sysdeps/unix/sysv/linux/ldsodefs.h: Declare _dl_vdso_sym and
_dl_vdso_vsym.
* sysdeps/unix/sysv/linux/powerpc/dl-sysdep.h: New File
diff -urN libc24-cvstip-20050408/elf/Versions libc24/elf/Versions
--- libc24-cvstip-20050408/elf/Versions 2005-01-06 16:40:26.000000000 -0600
+++ libc24/elf/Versions 2005-04-25 17:32:08.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-20050408/elf/rtld.c libc24/elf/rtld.c
--- libc24-cvstip-20050408/elf/rtld.c 2005-04-07 15:56:48.000000000 -0500
+++ libc24/elf/rtld.c 2005-04-22 16:25:34.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-20050408/sysdeps/unix/sysv/linux/Makefile libc24/sysdeps/unix/sysv/linux/Makefile
--- libc24-cvstip-20050408/sysdeps/unix/sysv/linux/Makefile 2004-10-04 18:29:06.000000000 -0500
+++ libc24/sysdeps/unix/sysv/linux/Makefile 2005-04-25 16:45:44.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-20050408/sysdeps/unix/sysv/linux/dl-vdso.c libc24/sysdeps/unix/sysv/linux/dl-vdso.c
--- libc24-cvstip-20050408/sysdeps/unix/sysv/linux/dl-vdso.c Wed Dec 31 18:00:00 1969
+++ libc24/sysdeps/unix/sysv/linux/dl-vdso.c Mon Apr 25 17:44:52 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
+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)
+ {
+ void *value;
+ value = DL_SYMBOL_ADDRESS (result, ref);
+
+ }
+ }
+ return value;
+}
+#endif
+
diff -urN libc24-cvstip-20050408/sysdeps/unix/sysv/linux/ldsodefs.h libc24/sysdeps/unix/sysv/linux/ldsodefs.h
--- libc24-cvstip-20050408/sysdeps/unix/sysv/linux/ldsodefs.h 2003-06-26 14:54:28.000000000 -0500
+++ libc24/sysdeps/unix/sysv/linux/ldsodefs.h 2005-04-25 16:30:23.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-20050408/sysdeps/unix/sysv/linux/powerpc/dl-sysdep.h libc24/sysdeps/unix/sysv/linux/powerpc/dl-sysdep.h
--- libc24-cvstip-20050408/sysdeps/unix/sysv/linux/powerpc/dl-sysdep.h Wed Dec 31 18:00:00 1969
+++ libc24/sysdeps/unix/sysv/linux/powerpc/dl-sysdep.h Mon Apr 11 10:17:18 2005
@@ -0,0 +1,55 @@
+/* System-specific settings for dynamic linker code. powerpc version.
+ 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_SYSDEP_H
+#define _DL_SYSDEP_H 1
+
+/* This macro must be defined to either 0 or 1.
+
+ If 1, then an errno global variable hidden in ld.so will work right with
+ all the errno-using libc code compiled for ld.so, and there is never a
+ need to share the errno location with libc. This is appropriate only if
+ all the libc functions that ld.so uses are called without PLT and always
+ get the versions linked into ld.so rather than the libc ones. */
+
+#ifdef IS_IN_rtld
+# define RTLD_PRIVATE_ERRNO 1
+#else
+# define RTLD_PRIVATE_ERRNO 0
+#endif
+
+/* Traditionally system calls have been used to access kernel services.
+ For some of these services the system call overhead is a significant
+ part of the total service time and Kernel privilege is not
+ required. Or the kernel knows detail of the processor implementation
+ that allow for critical optimizations not possible in generalized
+ libraries. Or the kernel needs to insert a fragment of code into
+ the application, like a signal trampoline.
+
+ All of this can be served by a mechanism that allows the kernel to
+ provide a DSO library without requiring explicit linking. Such a
+ is virtual (VDSO) because it may be wholly manufactured by the
+ kernel. To signal the presence of a VDSO library, the kernel passes
+ an AT_SYSINFO_EHDR value in the auxiliary vector to the
+ application. This allows symbols from the VDSO library to be
+ merged with the applications symbols. */
+
+#define NEED_DL_SYSINFO_DSO 1
+
+#endif /* dl-sysdep.h */