diff options
author | sobomax <sobomax@FreeBSD.org> | 2002-02-04 10:33:48 +0000 |
---|---|---|
committer | sobomax <sobomax@FreeBSD.org> | 2002-02-04 10:33:48 +0000 |
commit | 0a68f500fad520bd9e947259f71f0704362cde51 (patch) | |
tree | 0f41fb802fc9270b46740b35eb965449205e46a9 /usr.bin/ldd/ldd.c | |
parent | c61b7216e49401a2e8eb5f81218c1fa5a181abbf (diff) | |
download | FreeBSD-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/ldd.c')
-rw-r--r-- | usr.bin/ldd/ldd.c | 14 |
1 files changed, 12 insertions, 2 deletions
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); } } |