Module Name: src Committed By: pooka Date: Thu Sep 24 21:21:34 UTC 2009
Modified Files: src/include: dlfcn.h src/lib/libc/dlfcn: dlfcn_elf.c src/libexec/ld.elf_so: reloc.c rtld.c rtld.h symbol.c Log Message: Add Solarisa-like dlinfo() interface to the ELF dynamic linker. Implement RTLD_DI_LINKMAP which returns a pointer to the linkmap chain at the given object. Other Solaris queries are currently unimplemented. To generate a diff of this commit: cvs rdiff -u -r1.19 -r1.20 src/include/dlfcn.h cvs rdiff -u -r1.5 -r1.6 src/lib/libc/dlfcn/dlfcn_elf.c cvs rdiff -u -r1.96 -r1.97 src/libexec/ld.elf_so/reloc.c cvs rdiff -u -r1.124 -r1.125 src/libexec/ld.elf_so/rtld.c cvs rdiff -u -r1.80 -r1.81 src/libexec/ld.elf_so/rtld.h cvs rdiff -u -r1.47 -r1.48 src/libexec/ld.elf_so/symbol.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
Modified files: Index: src/include/dlfcn.h diff -u src/include/dlfcn.h:1.19 src/include/dlfcn.h:1.20 --- src/include/dlfcn.h:1.19 Mon Apr 28 20:22:54 2008 +++ src/include/dlfcn.h Thu Sep 24 21:21:33 2009 @@ -1,4 +1,4 @@ -/* $NetBSD: dlfcn.h,v 1.19 2008/04/28 20:22:54 martin Exp $ */ +/* $NetBSD: dlfcn.h,v 1.20 2009/09/24 21:21:33 pooka Exp $ */ /*- * Copyright (c) 1998 The NetBSD Foundation, Inc. @@ -54,6 +54,7 @@ #if defined(_NETBSD_SOURCE) int dladdr(const void * __restrict, Dl_info * __restrict); int dlctl(void *, int, void *); +int dlinfo(void *, int, void *); #endif __aconst char *dlerror(void); __END_DECLS @@ -88,4 +89,23 @@ #endif /* 0 */ #endif /* defined(_NETBSD_SOURCE) */ +/* + * dlinfo() commands + * + * From Solarisa: http://docs.sun.com/app/docs/doc/816-5168/dlinfo-3c?a=view + */ +#if defined(_NETBSD_SOURCE) +#define RTLD_DI_LINKMAP 3 +#if 0 +#define RTLD_DI_ARGSINFO 1 +#define RTLD_DI_CONFIGADDR 2 +#define RTLD_DI_LMID 4 +#define RTLD_DI_SERINFO 5 +#define RTLD_DI_SERINFOSIZE 6 +#define RTLD_DI_ORIGIN 7 +#define RTLD_DI_GETSIGNAL 8 +#define RTLD_DI_SETSIGNAL 9 +#endif +#endif /* _NETBSD_SOURCE */ + #endif /* !defined(_DLFCN_H_) */ Index: src/lib/libc/dlfcn/dlfcn_elf.c diff -u src/lib/libc/dlfcn/dlfcn_elf.c:1.5 src/lib/libc/dlfcn/dlfcn_elf.c:1.6 --- src/lib/libc/dlfcn/dlfcn_elf.c:1.5 Sun Jul 18 17:26:19 2004 +++ src/lib/libc/dlfcn/dlfcn_elf.c Thu Sep 24 21:21:33 2009 @@ -1,4 +1,4 @@ -/* $NetBSD: dlfcn_elf.c,v 1.5 2004/07/18 17:26:19 thorpej Exp $ */ +/* $NetBSD: dlfcn_elf.c,v 1.6 2009/09/24 21:21:33 pooka Exp $ */ /* * Copyright (c) 2000 Takuya SHIOZAKI @@ -27,7 +27,7 @@ #include <sys/cdefs.h> #if defined(LIBC_SCCS) && !defined(lint) -__RCSID("$NetBSD: dlfcn_elf.c,v 1.5 2004/07/18 17:26:19 thorpej Exp $"); +__RCSID("$NetBSD: dlfcn_elf.c,v 1.6 2009/09/24 21:21:33 pooka Exp $"); #endif /* LIBC_SCCS and not lint */ #include "namespace.h" @@ -37,12 +37,14 @@ #undef dlsym #undef dlerror #undef dladdr +#undef dfinfo #define dlopen ___dlopen #define dlclose ___dlclose #define dlsym ___dlsym #define dlerror ___dlerror #define dladdr ___dladdr +#define dlinfo ___dlinfo #define ELFSIZE ARCH_ELFSIZE #include "rtld.h" @@ -53,12 +55,14 @@ __weak_alias(dlsym,___dlsym) __weak_alias(dlerror,___dlerror) __weak_alias(dladdr,___dladdr) +__weak_alias(dlinfo,___dlinfo) __weak_alias(__dlopen,___dlopen) __weak_alias(__dlclose,___dlclose) __weak_alias(__dlsym,___dlsym) __weak_alias(__dlerror,___dlerror) __weak_alias(__dladdr,___dladdr) +__weak_alias(__dlinfo,___dlinfo) #endif /* @@ -112,3 +116,11 @@ return 0; } + +/*ARGSUSED*/ +int +dlinfo(void *handle, int req, void *v) +{ + + return -1; +} Index: src/libexec/ld.elf_so/reloc.c diff -u src/libexec/ld.elf_so/reloc.c:1.96 src/libexec/ld.elf_so/reloc.c:1.97 --- src/libexec/ld.elf_so/reloc.c:1.96 Tue Jul 29 16:27:01 2008 +++ src/libexec/ld.elf_so/reloc.c Thu Sep 24 21:21:34 2009 @@ -1,4 +1,4 @@ -/* $NetBSD: reloc.c,v 1.96 2008/07/29 16:27:01 matt Exp $ */ +/* $NetBSD: reloc.c,v 1.97 2009/09/24 21:21:34 pooka Exp $ */ /* * Copyright 1996 John D. Polstra. @@ -39,7 +39,7 @@ #include <sys/cdefs.h> #ifndef lint -__RCSID("$NetBSD: reloc.c,v 1.96 2008/07/29 16:27:01 matt Exp $"); +__RCSID("$NetBSD: reloc.c,v 1.97 2009/09/24 21:21:34 pooka Exp $"); #endif /* not lint */ #include <err.h> @@ -210,6 +210,7 @@ obj->dlerror = dlerror; obj->dlclose = dlclose; obj->dladdr = dladdr; + obj->dlinfo = dlinfo; dbg(("fixing up PLTGOT")); /* Set the special PLTGOT entries. */ Index: src/libexec/ld.elf_so/rtld.c diff -u src/libexec/ld.elf_so/rtld.c:1.124 src/libexec/ld.elf_so/rtld.c:1.125 --- src/libexec/ld.elf_so/rtld.c:1.124 Tue May 19 20:44:52 2009 +++ src/libexec/ld.elf_so/rtld.c Thu Sep 24 21:21:34 2009 @@ -1,4 +1,4 @@ -/* $NetBSD: rtld.c,v 1.124 2009/05/19 20:44:52 christos Exp $ */ +/* $NetBSD: rtld.c,v 1.125 2009/09/24 21:21:34 pooka Exp $ */ /* * Copyright 1996 John D. Polstra. @@ -40,7 +40,7 @@ #include <sys/cdefs.h> #ifndef lint -__RCSID("$NetBSD: rtld.c,v 1.124 2009/05/19 20:44:52 christos Exp $"); +__RCSID("$NetBSD: rtld.c,v 1.125 2009/09/24 21:21:34 pooka Exp $"); #endif /* not lint */ #include <err.h> @@ -985,6 +985,47 @@ return 1; } +__strong_alias(__dlinfo,dlinfo) +int +dlinfo(void *handle, int req, void *v) +{ + const Obj_Entry *obj; + void *retaddr; + + if (handle == RTLD_SELF) { +#ifdef __powerpc__ + retaddr = hackish_return_address(); +#else + retaddr = __builtin_return_address(0); +#endif + if ((obj = _rtld_obj_from_addr(retaddr)) == NULL) { + _rtld_error("Cannot determine caller's shared object"); + return -1; + } + } else { + if ((obj = _rtld_dlcheck(handle)) == NULL) { + _rtld_error("Invalid handle"); + return -1; + } + } + + switch (req) { + case RTLD_DI_LINKMAP: + { + const struct link_map **map = v; + + *map = &obj->linkmap; + break; + } + + default: + _rtld_error("Invalid request"); + return -1; + } + + return 0; +} + /* * Error reporting function. Use it like printf. If formats the message * into a buffer, and sets things up so that the next call to dlerror() Index: src/libexec/ld.elf_so/rtld.h diff -u src/libexec/ld.elf_so/rtld.h:1.80 src/libexec/ld.elf_so/rtld.h:1.81 --- src/libexec/ld.elf_so/rtld.h:1.80 Tue May 19 20:44:52 2009 +++ src/libexec/ld.elf_so/rtld.h Thu Sep 24 21:21:34 2009 @@ -1,4 +1,4 @@ -/* $NetBSD: rtld.h,v 1.80 2009/05/19 20:44:52 christos Exp $ */ +/* $NetBSD: rtld.h,v 1.81 2009/09/24 21:21:34 pooka Exp $ */ /* * Copyright 1996 John D. Polstra. @@ -168,6 +168,7 @@ char *(*dlerror)(void); int (*dlclose)(void *); int (*dladdr)(const void *, Dl_info *); + int (*dlinfo)(void *, int, void *); u_int32_t mainprog:1, /* True if this is the main program */ rtld:1, /* True if this is the dynamic linker */ @@ -222,6 +223,7 @@ void *dlsym(void *, const char *); int dlclose(void *); int dladdr(const void *, Dl_info *); +int dlinfo(void *, int, void *); void _rtld_error(const char *, ...) __attribute__((__format__(__printf__,1,2))); Index: src/libexec/ld.elf_so/symbol.c diff -u src/libexec/ld.elf_so/symbol.c:1.47 src/libexec/ld.elf_so/symbol.c:1.48 --- src/libexec/ld.elf_so/symbol.c:1.47 Sat Oct 4 09:37:12 2008 +++ src/libexec/ld.elf_so/symbol.c Thu Sep 24 21:21:34 2009 @@ -1,4 +1,4 @@ -/* $NetBSD: symbol.c,v 1.47 2008/10/04 09:37:12 skrll Exp $ */ +/* $NetBSD: symbol.c,v 1.48 2009/09/24 21:21:34 pooka Exp $ */ /* * Copyright 1996 John D. Polstra. @@ -40,7 +40,7 @@ #include <sys/cdefs.h> #ifndef lint -__RCSID("$NetBSD: symbol.c,v 1.47 2008/10/04 09:37:12 skrll Exp $"); +__RCSID("$NetBSD: symbol.c,v 1.48 2009/09/24 21:21:34 pooka Exp $"); #endif /* not lint */ #include <err.h> @@ -69,6 +69,7 @@ (fptr_t)dlsym, (fptr_t)dlerror, (fptr_t)dladdr, + (fptr_t)dlinfo, NULL }; int i;