diff options
author | dfr <dfr@FreeBSD.org> | 1998-05-01 08:40:11 +0000 |
---|---|---|
committer | dfr <dfr@FreeBSD.org> | 1998-05-01 08:40:11 +0000 |
commit | f28fdede6f2d2cb5aafec030913ea5ac7ad6eaed (patch) | |
tree | 2bf3b75648ce5b5bc8ca8eef5254d750a9052ae3 /gnu/usr.bin | |
parent | ac67dd4e68c1d174836e84ce2b9e319b1230f8ac (diff) | |
download | FreeBSD-src-f28fdede6f2d2cb5aafec030913ea5ac7ad6eaed.zip FreeBSD-src-f28fdede6f2d2cb5aafec030913ea5ac7ad6eaed.tar.gz |
Add ELF support.
Diffstat (limited to 'gnu/usr.bin')
-rw-r--r-- | gnu/usr.bin/ld/ldd/ldd.c | 61 | ||||
-rw-r--r-- | gnu/usr.bin/ld/ldd/sods.c | 12 |
2 files changed, 62 insertions, 11 deletions
diff --git a/gnu/usr.bin/ld/ldd/ldd.c b/gnu/usr.bin/ld/ldd/ldd.c index d940261..31a7a67 100644 --- a/gnu/usr.bin/ld/ldd/ldd.c +++ b/gnu/usr.bin/ld/ldd/ldd.c @@ -27,7 +27,7 @@ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * - * $Id: ldd.c,v 1.13 1997/02/22 15:46:43 peter Exp $ + * $Id: ldd.c,v 1.14 1997/09/02 21:54:39 jdp Exp $ */ #include <sys/types.h> @@ -37,6 +37,7 @@ #include <sys/resource.h> #include <sys/wait.h> #include <a.out.h> +#include <elf.h> #include <err.h> #include <fcntl.h> #include <stdio.h> @@ -118,19 +119,61 @@ char *argv[]; argv++; continue; } - if (read(fd, &hdr, sizeof hdr) != sizeof hdr - || (N_GETFLAG(hdr) & EX_DPMASK) != EX_DYNAMIC -#if 1 /* Compatibility */ - || hdr.a_entry < __LDPGSZ -#endif - ) { - - warnx("%s: not a dynamic executable", *argv); + if (read(fd, &hdr, sizeof hdr) != sizeof hdr) { + warnx("%s: can't read program header", *argv); (void)close(fd); rval |= 1; argv++; continue; } + + if (!N_BADMAG(hdr)) { + /* a.out file */ + if ((N_GETFLAG(hdr) & EX_DPMASK) != EX_DYNAMIC +#if 1 /* Compatibility */ + || hdr.a_entry < __LDPGSZ +#endif + ) { + warnx("%s: not a dynamic executable", *argv); + (void)close(fd); + rval |= 1; + argv++; + continue; + } + } else if (IS_ELF(*(Elf32_Ehdr*)&hdr)) { + Elf32_Ehdr ehdr; + Elf32_Phdr phdr; + int dynamic = 0, i; + + lseek(fd, 0, SEEK_SET); + if (read(fd, &ehdr, sizeof ehdr) != sizeof ehdr) { + warnx("%s: can't read program header", *argv); + (void)close(fd); + rval |= 1; + argv++; + continue; + } + lseek(fd, 0, ehdr.e_phoff); + for (i = 0; i < ehdr.e_phnum; i++) { + if (read(fd, &phdr, ehdr.e_phentsize) + != sizeof phdr) { + warnx("%s: can't read program header", *argv); + (void)close(fd); + rval |= 1; + argv++; + continue; + } + if (phdr.p_type == PT_DYNAMIC) + dynamic = 1; + } + if (!dynamic) { + warnx("%s: not a dynamic executable", *argv); + (void)close(fd); + rval |= 1; + argv++; + continue; + } + } (void)close(fd); setenv("LD_TRACE_LOADED_OBJECTS_PROGNAME", *argv, 1); diff --git a/gnu/usr.bin/ld/ldd/sods.c b/gnu/usr.bin/ld/ldd/sods.c index 3e28746..801cca0 100644 --- a/gnu/usr.bin/ld/ldd/sods.c +++ b/gnu/usr.bin/ld/ldd/sods.c @@ -22,7 +22,7 @@ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * - * $Id: sods.c,v 1.5 1997/09/02 21:54:39 jdp Exp $ + * $Id: sods.c,v 1.6 1997/11/28 19:34:27 jdp Exp $ */ #include <assert.h> @@ -39,6 +39,7 @@ #include <sys/stat.h> #include <a.out.h> +#include <elf.h> #include <link.h> #include <stab.h> @@ -173,6 +174,13 @@ dump_file(const char *fname) file_base = (const char *) objbase; /* Makes address arithmetic easier */ + if (IS_ELF(*(Elf32_Ehdr*) file_base)) { + error("%s: this is an ELF program; use objdump to examine.", fname); + munmap(objbase, sb.st_size); + close(fd); + return; + } + ex = (const struct exec *) file_base; printf("%s: a_midmag = 0x%lx\n", fname, ex->a_midmag); @@ -211,7 +219,7 @@ dump_file(const char *fname) } printf(" Entry = 0x%lx\n", ex->a_entry); - printf(" Text offset = %x, address = %x\n", N_TXTOFF(*ex), + printf(" Text offset = %x, address = %lx\n", N_TXTOFF(*ex), N_TXTADDR(*ex)); printf(" Data offset = %lx, address = %lx\n", N_DATOFF(*ex), N_DATADDR(*ex)); |