summaryrefslogtreecommitdiffstats
path: root/usr.bin/ldd
diff options
context:
space:
mode:
authorsobomax <sobomax@FreeBSD.org>2002-02-04 10:33:48 +0000
committersobomax <sobomax@FreeBSD.org>2002-02-04 10:33:48 +0000
commit0a68f500fad520bd9e947259f71f0704362cde51 (patch)
tree0f41fb802fc9270b46740b35eb965449205e46a9 /usr.bin/ldd
parentc61b7216e49401a2e8eb5f81218c1fa5a181abbf (diff)
downloadFreeBSD-src-0a68f500fad520bd9e947259f71f0704362cde51.zip
FreeBSD-src-0a68f500fad520bd9e947259f71f0704362cde51.tar.gz
Allow ldd(1) be used on shared libraries in addition to executables.
Diffstat (limited to 'usr.bin/ldd')
-rw-r--r--usr.bin/ldd/ldd.13
-rw-r--r--usr.bin/ldd/ldd.c14
2 files changed, 14 insertions, 3 deletions
diff --git a/usr.bin/ldd/ldd.1 b/usr.bin/ldd/ldd.1
index d784751..470fd42 100644
--- a/usr.bin/ldd/ldd.1
+++ b/usr.bin/ldd/ldd.1
@@ -13,7 +13,8 @@
.Ar program ...
.Sh DESCRIPTION
.Nm
-displays all shared objects that are needed to run the given program.
+displays all shared objects that are needed to run the given program or
+to load the given shared object.
Contrary to
.Xr nm 1 ,
the list includes
diff --git a/usr.bin/ldd/ldd.c b/usr.bin/ldd/ldd.c
index 22b4072..0d86e66 100644
--- a/usr.bin/ldd/ldd.c
+++ b/usr.bin/ldd/ldd.c
@@ -36,6 +36,7 @@ static const char rcsid[] =
#include <sys/wait.h>
#include <machine/elf.h>
#include <a.out.h>
+#include <dlfcn.h>
#include <err.h>
#include <fcntl.h>
#include <stdio.h>
@@ -116,6 +117,7 @@ char *argv[];
int n;
int status;
int file_ok;
+ int is_shlib;
if ((fd = open(*argv, O_RDONLY, 0)) < 0) {
warn("%s", *argv);
@@ -130,6 +132,7 @@ char *argv[];
}
file_ok = 1;
+ is_shlib = 0;
if (n >= sizeof hdr.aout && !N_BADMAG(hdr.aout)) {
/* a.out file */
if ((N_GETFLAG(hdr.aout) & EX_DPMASK) != EX_DYNAMIC
@@ -167,6 +170,8 @@ char *argv[];
if (!dynamic) {
warnx("%s: not a dynamic executable", *argv);
file_ok = 0;
+ } else if (hdr.elf.e_type == ET_DYN) {
+ is_shlib = 1;
}
} else {
warnx("%s: not a dynamic executable", *argv);
@@ -204,8 +209,13 @@ char *argv[];
}
break;
case 0:
- execl(*argv, *argv, (char *)NULL);
- warn("%s", *argv);
+ if (is_shlib == 0) {
+ execl(*argv, *argv, (char *)NULL);
+ warn("%s", *argv);
+ } else {
+ dlopen(*argv, RTLD_TRACE);
+ warnx("%s: %s", *argv, dlerror());
+ }
_exit(1);
}
}
OpenPOWER on IntegriCloud