Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src Add Solarisa-like dlinfo() interface to the ELF dynamic linker.



details:   https://anonhg.NetBSD.org/src/rev/088b8fe55cac
branches:  trunk
changeset: 747621:088b8fe55cac
user:      pooka <pooka%NetBSD.org@localhost>
date:      Thu Sep 24 21:21:33 2009 +0000

description:
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.

diffstat:

 include/dlfcn.h            |  22 +++++++++++++++++++++-
 lib/libc/dlfcn/dlfcn_elf.c |  16 ++++++++++++++--
 libexec/ld.elf_so/reloc.c  |   5 +++--
 libexec/ld.elf_so/rtld.c   |  45 +++++++++++++++++++++++++++++++++++++++++++--
 libexec/ld.elf_so/rtld.h   |   4 +++-
 libexec/ld.elf_so/symbol.c |   5 +++--
 6 files changed, 87 insertions(+), 10 deletions(-)

diffs (244 lines):

diff -r 61932a5407eb -r 088b8fe55cac include/dlfcn.h
--- a/include/dlfcn.h   Thu Sep 24 21:04:45 2009 +0000
+++ b/include/dlfcn.h   Thu Sep 24 21:21:33 2009 +0000
@@ -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_) */
diff -r 61932a5407eb -r 088b8fe55cac lib/libc/dlfcn/dlfcn_elf.c
--- a/lib/libc/dlfcn/dlfcn_elf.c        Thu Sep 24 21:04:45 2009 +0000
+++ b/lib/libc/dlfcn/dlfcn_elf.c        Thu Sep 24 21:21:33 2009 +0000
@@ -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;
+}
diff -r 61932a5407eb -r 088b8fe55cac libexec/ld.elf_so/reloc.c
--- a/libexec/ld.elf_so/reloc.c Thu Sep 24 21:04:45 2009 +0000
+++ b/libexec/ld.elf_so/reloc.c Thu Sep 24 21:21:33 2009 +0000
@@ -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. */
diff -r 61932a5407eb -r 088b8fe55cac libexec/ld.elf_so/rtld.c
--- a/libexec/ld.elf_so/rtld.c  Thu Sep 24 21:04:45 2009 +0000
+++ b/libexec/ld.elf_so/rtld.c  Thu Sep 24 21:21:33 2009 +0000
@@ -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()
diff -r 61932a5407eb -r 088b8fe55cac libexec/ld.elf_so/rtld.h
--- a/libexec/ld.elf_so/rtld.h  Thu Sep 24 21:04:45 2009 +0000
+++ b/libexec/ld.elf_so/rtld.h  Thu Sep 24 21:21:33 2009 +0000
@@ -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)));
diff -r 61932a5407eb -r 088b8fe55cac libexec/ld.elf_so/symbol.c
--- a/libexec/ld.elf_so/symbol.c        Thu Sep 24 21:04:45 2009 +0000
+++ b/libexec/ld.elf_so/symbol.c        Thu Sep 24 21:21:33 2009 +0000
@@ -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;



Home | Main Index | Thread Index | Old Index