Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src/usr.bin/ldd Make sure stuff using Obj_Entry is compiled corr...
details: https://anonhg.NetBSD.org/src/rev/3a26cb06a65a
branches: trunk
changeset: 780028:3a26cb06a65a
user: matt <matt%NetBSD.org@localhost>
date: Sun Jul 08 00:53:44 2012 +0000
description:
Make sure stuff using Obj_Entry is compiled correctly for ELF32 or ELF64.
diffstat:
usr.bin/ldd/ldd.c | 113 ++---------------------------------------------
usr.bin/ldd/ldd.h | 5 +-
usr.bin/ldd/ldd_elfxx.c | 112 ++++++++++++++++++++++++++++++++++++++++++++++-
3 files changed, 117 insertions(+), 113 deletions(-)
diffs (296 lines):
diff -r 55765979dd16 -r 3a26cb06a65a usr.bin/ldd/ldd.c
--- a/usr.bin/ldd/ldd.c Sun Jul 08 00:53:01 2012 +0000
+++ b/usr.bin/ldd/ldd.c Sun Jul 08 00:53:44 2012 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: ldd.c,v 1.19 2011/05/24 12:27:29 joerg Exp $ */
+/* $NetBSD: ldd.c,v 1.20 2012/07/08 00:53:44 matt Exp $ */
/*-
* Copyright (c) 1998, 2000 The NetBSD Foundation, Inc.
@@ -62,7 +62,7 @@
#include <sys/cdefs.h>
#ifndef lint
-__RCSID("$NetBSD: ldd.c,v 1.19 2011/05/24 12:27:29 joerg Exp $");
+__RCSID("$NetBSD: ldd.c,v 1.20 2012/07/08 00:53:44 matt Exp $");
#endif /* not lint */
#include <sys/types.h>
@@ -89,6 +89,10 @@
*/
static char *error_message; /* Message for dlopen(), or NULL */
bool _rtld_trust; /* False for setuid and setgid programs */
+/*
+ * This may be ELF64 or ELF32 but since they are used opaquely it doesn't
+ * really matter.
+ */
Obj_Entry *_rtld_objlist; /* Head of linked list of shared objects */
Obj_Entry **_rtld_objtail = &_rtld_objlist;
/* Link field of last object in list */
@@ -200,111 +204,6 @@
}
void
-fmtprint(const char *libname, Obj_Entry *obj, const char *fmt1,
- const char *fmt2)
-{
- const char *libpath = obj ? obj->path : "not found";
- char libnamebuf[200];
- char *libmajor = NULL;
- const char *fmt;
- char *cp;
- int c;
-
- if (strncmp(libname, "lib", 3) == 0 &&
- (cp = strstr(libname, ".so")) != NULL) {
- size_t i = cp - (libname + 3);
-
- if (i >= sizeof(libnamebuf))
- i = sizeof(libnamebuf) - 1;
- (void)memcpy(libnamebuf, libname + 3, i);
- libnamebuf[i] = '\0';
- if (cp[3] && isdigit((unsigned char)cp[4]))
- libmajor = &cp[4];
- libname = libnamebuf;
- }
-
- if (fmt1 == NULL)
- fmt1 = libmajor != NULL ?
- "\t-l%o.%m => %p\n" :
- "\t-l%o => %p\n";
- if (fmt2 == NULL)
- fmt2 = "\t%o => %p\n";
-
- fmt = libname == libnamebuf ? fmt1 : fmt2;
- while ((c = *fmt++) != '\0') {
- switch (c) {
- default:
- putchar(c);
- continue;
- case '\\':
- switch (c = *fmt) {
- case '\0':
- continue;
- case 'n':
- putchar('\n');
- break;
- case 't':
- putchar('\t');
- break;
- }
- break;
- case '%':
- switch (c = *fmt) {
- case '\0':
- continue;
- case '%':
- default:
- putchar(c);
- break;
- case 'A':
- printf("%s", main_local);
- break;
- case 'a':
- printf("%s", main_progname);
- break;
- case 'o':
- printf("%s", libname);
- break;
- case 'm':
- printf("%s", libmajor);
- break;
- case 'n':
- /* XXX: not supported for elf */
- break;
- case 'p':
- printf("%s", libpath);
- break;
- case 'x':
- printf("%p", obj ? obj->mapbase : 0);
- break;
- }
- break;
- }
- ++fmt;
- }
-}
-
-void
-print_needed(Obj_Entry *obj, const char *fmt1, const char *fmt2)
-{
- const Needed_Entry *needed;
-
- for (needed = obj->needed; needed != NULL; needed = needed->next) {
- const char *libname = obj->strtab + needed->name;
-
- if (needed->obj != NULL) {
- if (!needed->obj->printed) {
- fmtprint(libname, needed->obj, fmt1, fmt2);
- needed->obj->printed = 1;
- print_needed(needed->obj, fmt1, fmt2);
- }
- } else {
- fmtprint(libname, needed->obj, fmt1, fmt2);
- }
- }
-}
-
-void
_rtld_die(void)
{
const char *msg = dlerror();
diff -r 55765979dd16 -r 3a26cb06a65a usr.bin/ldd/ldd.h
--- a/usr.bin/ldd/ldd.h Sun Jul 08 00:53:01 2012 +0000
+++ b/usr.bin/ldd/ldd.h Sun Jul 08 00:53:44 2012 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: ldd.h,v 1.6 2009/12/15 04:06:43 mrg Exp $ */
+/* $NetBSD: ldd.h,v 1.7 2012/07/08 00:53:44 matt Exp $ */
/*
* Copyright (c) 2008 Matthew R. Green
@@ -43,8 +43,5 @@
#define elf_ldd elf32_ldd
#endif
-void fmtprint(const char *, Obj_Entry *, const char *, const char *);
-void print_needed(Obj_Entry *, const char *, const char *);
-
extern char *main_local;
extern char *main_progname;
diff -r 55765979dd16 -r 3a26cb06a65a usr.bin/ldd/ldd_elfxx.c
--- a/usr.bin/ldd/ldd_elfxx.c Sun Jul 08 00:53:01 2012 +0000
+++ b/usr.bin/ldd/ldd_elfxx.c Sun Jul 08 00:53:44 2012 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: ldd_elfxx.c,v 1.5 2011/06/30 20:09:41 wiz Exp $ */
+/* $NetBSD: ldd_elfxx.c,v 1.6 2012/07/08 00:53:44 matt Exp $ */
/*-
* Copyright (c) 1998, 2000 The NetBSD Foundation, Inc.
@@ -62,7 +62,7 @@
#include <sys/cdefs.h>
#ifndef lint
-__RCSID("$NetBSD: ldd_elfxx.c,v 1.5 2011/06/30 20:09:41 wiz Exp $");
+__RCSID("$NetBSD: ldd_elfxx.c,v 1.6 2012/07/08 00:53:44 matt Exp $");
#endif /* not lint */
#include <sys/types.h>
@@ -84,6 +84,9 @@
#include "rtld.h"
#include "ldd.h"
+static void print_needed(Obj_Entry *, const char *, const char *);
+static void fmtprint(const char *, Obj_Entry *, const char *, const char *);
+
/*
* elfxx_ldd() - bit-size independent ELF ldd implementation.
* returns 0 on success and -1 on failure.
@@ -158,3 +161,108 @@
return 0;
}
+
+void
+fmtprint(const char *libname, Obj_Entry *obj, const char *fmt1,
+ const char *fmt2)
+{
+ const char *libpath = obj ? obj->path : "not found";
+ char libnamebuf[200];
+ char *libmajor = NULL;
+ const char *fmt;
+ char *cp;
+ int c;
+
+ if (strncmp(libname, "lib", 3) == 0 &&
+ (cp = strstr(libname, ".so")) != NULL) {
+ size_t i = cp - (libname + 3);
+
+ if (i >= sizeof(libnamebuf))
+ i = sizeof(libnamebuf) - 1;
+ (void)memcpy(libnamebuf, libname + 3, i);
+ libnamebuf[i] = '\0';
+ if (cp[3] && isdigit((unsigned char)cp[4]))
+ libmajor = &cp[4];
+ libname = libnamebuf;
+ }
+
+ if (fmt1 == NULL)
+ fmt1 = libmajor != NULL ?
+ "\t-l%o.%m => %p\n" :
+ "\t-l%o => %p\n";
+ if (fmt2 == NULL)
+ fmt2 = "\t%o => %p\n";
+
+ fmt = libname == libnamebuf ? fmt1 : fmt2;
+ while ((c = *fmt++) != '\0') {
+ switch (c) {
+ default:
+ putchar(c);
+ continue;
+ case '\\':
+ switch (c = *fmt) {
+ case '\0':
+ continue;
+ case 'n':
+ putchar('\n');
+ break;
+ case 't':
+ putchar('\t');
+ break;
+ }
+ break;
+ case '%':
+ switch (c = *fmt) {
+ case '\0':
+ continue;
+ case '%':
+ default:
+ putchar(c);
+ break;
+ case 'A':
+ printf("%s", main_local);
+ break;
+ case 'a':
+ printf("%s", main_progname);
+ break;
+ case 'o':
+ printf("%s", libname);
+ break;
+ case 'm':
+ printf("%s", libmajor);
+ break;
+ case 'n':
+ /* XXX: not supported for elf */
+ break;
+ case 'p':
+ printf("%s", libpath);
+ break;
+ case 'x':
+ printf("%p", obj ? obj->mapbase : 0);
+ break;
+ }
+ break;
+ }
+ ++fmt;
+ }
+}
+
+void
+print_needed(Obj_Entry *obj, const char *fmt1, const char *fmt2)
+{
+ const Needed_Entry *needed;
+
+ for (needed = obj->needed; needed != NULL; needed = needed->next) {
+ const char *libname = obj->strtab + needed->name;
+
+ if (needed->obj != NULL) {
+ if (!needed->obj->printed) {
+ fmtprint(libname, needed->obj, fmt1, fmt2);
+ needed->obj->printed = 1;
+ print_needed(needed->obj, fmt1, fmt2);
+ }
+ } else {
+ fmtprint(libname, needed->obj, fmt1, fmt2);
+ }
+ }
+}
Home |
Main Index |
Thread Index |
Old Index