annotate sources/toys/readelf.c @ 1719:78050a31d1ee draft

Sigh. Checked in the wrong version of the patch (typo fix).
author Rob Landley <rob@landley.net>
date Tue, 06 Jan 2015 13:15:33 -0600
parents d29edba5582f
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
874
d29edba5582f Quick and dirty port of uClibc's readelf.c to build against glibc as well. Not used at the moment, just "so I have a copy when it goes away".
Rob Landley <rob@landley.net>
parents:
diff changeset
1 /* vi: set sw=4 ts=4: */
d29edba5582f Quick and dirty port of uClibc's readelf.c to build against glibc as well. Not used at the moment, just "so I have a copy when it goes away".
Rob Landley <rob@landley.net>
parents:
diff changeset
2 /*
d29edba5582f Quick and dirty port of uClibc's readelf.c to build against glibc as well. Not used at the moment, just "so I have a copy when it goes away".
Rob Landley <rob@landley.net>
parents:
diff changeset
3 * A small little readelf implementation for uClibc
d29edba5582f Quick and dirty port of uClibc's readelf.c to build against glibc as well. Not used at the moment, just "so I have a copy when it goes away".
Rob Landley <rob@landley.net>
parents:
diff changeset
4 *
d29edba5582f Quick and dirty port of uClibc's readelf.c to build against glibc as well. Not used at the moment, just "so I have a copy when it goes away".
Rob Landley <rob@landley.net>
parents:
diff changeset
5 * Copyright (C) 2000-2006 Erik Andersen <andersen@uclibc.org>
d29edba5582f Quick and dirty port of uClibc's readelf.c to build against glibc as well. Not used at the moment, just "so I have a copy when it goes away".
Rob Landley <rob@landley.net>
parents:
diff changeset
6 * Copyright (C) 2009 Rob Landley <rob@landley.net>
d29edba5582f Quick and dirty port of uClibc's readelf.c to build against glibc as well. Not used at the moment, just "so I have a copy when it goes away".
Rob Landley <rob@landley.net>
parents:
diff changeset
7 *
d29edba5582f Quick and dirty port of uClibc's readelf.c to build against glibc as well. Not used at the moment, just "so I have a copy when it goes away".
Rob Landley <rob@landley.net>
parents:
diff changeset
8 * Several functions in this file (specifically, elf_find_section_type(),
d29edba5582f Quick and dirty port of uClibc's readelf.c to build against glibc as well. Not used at the moment, just "so I have a copy when it goes away".
Rob Landley <rob@landley.net>
parents:
diff changeset
9 * elf_find_phdr_type(), and elf_find_dynamic(), were stolen from elflib.c from
d29edba5582f Quick and dirty port of uClibc's readelf.c to build against glibc as well. Not used at the moment, just "so I have a copy when it goes away".
Rob Landley <rob@landley.net>
parents:
diff changeset
10 * elfvector (http://www.BitWagon.com/elfvector.html) by John F. Reiser
d29edba5582f Quick and dirty port of uClibc's readelf.c to build against glibc as well. Not used at the moment, just "so I have a copy when it goes away".
Rob Landley <rob@landley.net>
parents:
diff changeset
11 * <jreiser@BitWagon.com>, which is copyright 2000 BitWagon Software LLC
d29edba5582f Quick and dirty port of uClibc's readelf.c to build against glibc as well. Not used at the moment, just "so I have a copy when it goes away".
Rob Landley <rob@landley.net>
parents:
diff changeset
12 * (GPL2).
d29edba5582f Quick and dirty port of uClibc's readelf.c to build against glibc as well. Not used at the moment, just "so I have a copy when it goes away".
Rob Landley <rob@landley.net>
parents:
diff changeset
13 *
d29edba5582f Quick and dirty port of uClibc's readelf.c to build against glibc as well. Not used at the moment, just "so I have a copy when it goes away".
Rob Landley <rob@landley.net>
parents:
diff changeset
14 * Licensed under GPLv2
d29edba5582f Quick and dirty port of uClibc's readelf.c to build against glibc as well. Not used at the moment, just "so I have a copy when it goes away".
Rob Landley <rob@landley.net>
parents:
diff changeset
15 */
d29edba5582f Quick and dirty port of uClibc's readelf.c to build against glibc as well. Not used at the moment, just "so I have a copy when it goes away".
Rob Landley <rob@landley.net>
parents:
diff changeset
16
d29edba5582f Quick and dirty port of uClibc's readelf.c to build against glibc as well. Not used at the moment, just "so I have a copy when it goes away".
Rob Landley <rob@landley.net>
parents:
diff changeset
17
d29edba5582f Quick and dirty port of uClibc's readelf.c to build against glibc as well. Not used at the moment, just "so I have a copy when it goes away".
Rob Landley <rob@landley.net>
parents:
diff changeset
18 #include <fcntl.h>
d29edba5582f Quick and dirty port of uClibc's readelf.c to build against glibc as well. Not used at the moment, just "so I have a copy when it goes away".
Rob Landley <rob@landley.net>
parents:
diff changeset
19 #include <stdio.h>
d29edba5582f Quick and dirty port of uClibc's readelf.c to build against glibc as well. Not used at the moment, just "so I have a copy when it goes away".
Rob Landley <rob@landley.net>
parents:
diff changeset
20 #include <stdlib.h>
d29edba5582f Quick and dirty port of uClibc's readelf.c to build against glibc as well. Not used at the moment, just "so I have a copy when it goes away".
Rob Landley <rob@landley.net>
parents:
diff changeset
21 #include <string.h>
d29edba5582f Quick and dirty port of uClibc's readelf.c to build against glibc as well. Not used at the moment, just "so I have a copy when it goes away".
Rob Landley <rob@landley.net>
parents:
diff changeset
22 #include <unistd.h>
d29edba5582f Quick and dirty port of uClibc's readelf.c to build against glibc as well. Not used at the moment, just "so I have a copy when it goes away".
Rob Landley <rob@landley.net>
parents:
diff changeset
23 #include <sys/mman.h>
d29edba5582f Quick and dirty port of uClibc's readelf.c to build against glibc as well. Not used at the moment, just "so I have a copy when it goes away".
Rob Landley <rob@landley.net>
parents:
diff changeset
24 #include <sys/stat.h>
d29edba5582f Quick and dirty port of uClibc's readelf.c to build against glibc as well. Not used at the moment, just "so I have a copy when it goes away".
Rob Landley <rob@landley.net>
parents:
diff changeset
25 #include <sys/types.h>
d29edba5582f Quick and dirty port of uClibc's readelf.c to build against glibc as well. Not used at the moment, just "so I have a copy when it goes away".
Rob Landley <rob@landley.net>
parents:
diff changeset
26
d29edba5582f Quick and dirty port of uClibc's readelf.c to build against glibc as well. Not used at the moment, just "so I have a copy when it goes away".
Rob Landley <rob@landley.net>
parents:
diff changeset
27 #include <endian.h>
d29edba5582f Quick and dirty port of uClibc's readelf.c to build against glibc as well. Not used at the moment, just "so I have a copy when it goes away".
Rob Landley <rob@landley.net>
parents:
diff changeset
28 #include <byteswap.h>
d29edba5582f Quick and dirty port of uClibc's readelf.c to build against glibc as well. Not used at the moment, just "so I have a copy when it goes away".
Rob Landley <rob@landley.net>
parents:
diff changeset
29 #include <elf.h>
d29edba5582f Quick and dirty port of uClibc's readelf.c to build against glibc as well. Not used at the moment, just "so I have a copy when it goes away".
Rob Landley <rob@landley.net>
parents:
diff changeset
30 #include <link.h>
d29edba5582f Quick and dirty port of uClibc's readelf.c to build against glibc as well. Not used at the moment, just "so I have a copy when it goes away".
Rob Landley <rob@landley.net>
parents:
diff changeset
31
d29edba5582f Quick and dirty port of uClibc's readelf.c to build against glibc as well. Not used at the moment, just "so I have a copy when it goes away".
Rob Landley <rob@landley.net>
parents:
diff changeset
32 static int byteswap;
d29edba5582f Quick and dirty port of uClibc's readelf.c to build against glibc as well. Not used at the moment, just "so I have a copy when it goes away".
Rob Landley <rob@landley.net>
parents:
diff changeset
33 static __inline__ uint32_t byteswap32_to_host(uint32_t value)
d29edba5582f Quick and dirty port of uClibc's readelf.c to build against glibc as well. Not used at the moment, just "so I have a copy when it goes away".
Rob Landley <rob@landley.net>
parents:
diff changeset
34 {
d29edba5582f Quick and dirty port of uClibc's readelf.c to build against glibc as well. Not used at the moment, just "so I have a copy when it goes away".
Rob Landley <rob@landley.net>
parents:
diff changeset
35 return byteswap ? bswap_32(value) : value;
d29edba5582f Quick and dirty port of uClibc's readelf.c to build against glibc as well. Not used at the moment, just "so I have a copy when it goes away".
Rob Landley <rob@landley.net>
parents:
diff changeset
36 }
d29edba5582f Quick and dirty port of uClibc's readelf.c to build against glibc as well. Not used at the moment, just "so I have a copy when it goes away".
Rob Landley <rob@landley.net>
parents:
diff changeset
37 static __inline__ uint64_t byteswap64_to_host(uint64_t value)
d29edba5582f Quick and dirty port of uClibc's readelf.c to build against glibc as well. Not used at the moment, just "so I have a copy when it goes away".
Rob Landley <rob@landley.net>
parents:
diff changeset
38 {
d29edba5582f Quick and dirty port of uClibc's readelf.c to build against glibc as well. Not used at the moment, just "so I have a copy when it goes away".
Rob Landley <rob@landley.net>
parents:
diff changeset
39 return byteswap ? bswap_64(value) : value;
d29edba5582f Quick and dirty port of uClibc's readelf.c to build against glibc as well. Not used at the moment, just "so I have a copy when it goes away".
Rob Landley <rob@landley.net>
parents:
diff changeset
40 }
d29edba5582f Quick and dirty port of uClibc's readelf.c to build against glibc as well. Not used at the moment, just "so I have a copy when it goes away".
Rob Landley <rob@landley.net>
parents:
diff changeset
41 #if __WORDSIZE == 64
d29edba5582f Quick and dirty port of uClibc's readelf.c to build against glibc as well. Not used at the moment, just "so I have a copy when it goes away".
Rob Landley <rob@landley.net>
parents:
diff changeset
42 # define byteswap_to_host(x) byteswap64_to_host(x)
d29edba5582f Quick and dirty port of uClibc's readelf.c to build against glibc as well. Not used at the moment, just "so I have a copy when it goes away".
Rob Landley <rob@landley.net>
parents:
diff changeset
43 #else
d29edba5582f Quick and dirty port of uClibc's readelf.c to build against glibc as well. Not used at the moment, just "so I have a copy when it goes away".
Rob Landley <rob@landley.net>
parents:
diff changeset
44 # define byteswap_to_host(x) byteswap32_to_host(x)
d29edba5582f Quick and dirty port of uClibc's readelf.c to build against glibc as well. Not used at the moment, just "so I have a copy when it goes away".
Rob Landley <rob@landley.net>
parents:
diff changeset
45 #endif
d29edba5582f Quick and dirty port of uClibc's readelf.c to build against glibc as well. Not used at the moment, just "so I have a copy when it goes away".
Rob Landley <rob@landley.net>
parents:
diff changeset
46
d29edba5582f Quick and dirty port of uClibc's readelf.c to build against glibc as well. Not used at the moment, just "so I have a copy when it goes away".
Rob Landley <rob@landley.net>
parents:
diff changeset
47 static ElfW(Shdr) * elf_find_section_type( uint32_t key, ElfW(Ehdr) *ehdr)
d29edba5582f Quick and dirty port of uClibc's readelf.c to build against glibc as well. Not used at the moment, just "so I have a copy when it goes away".
Rob Landley <rob@landley.net>
parents:
diff changeset
48 {
d29edba5582f Quick and dirty port of uClibc's readelf.c to build against glibc as well. Not used at the moment, just "so I have a copy when it goes away".
Rob Landley <rob@landley.net>
parents:
diff changeset
49 int j;
d29edba5582f Quick and dirty port of uClibc's readelf.c to build against glibc as well. Not used at the moment, just "so I have a copy when it goes away".
Rob Landley <rob@landley.net>
parents:
diff changeset
50 ElfW(Shdr) *shdr = (ElfW(Shdr) *)(ehdr->e_shoff + (char *)ehdr);
d29edba5582f Quick and dirty port of uClibc's readelf.c to build against glibc as well. Not used at the moment, just "so I have a copy when it goes away".
Rob Landley <rob@landley.net>
parents:
diff changeset
51 for (j = ehdr->e_shnum; --j>=0; ++shdr) {
d29edba5582f Quick and dirty port of uClibc's readelf.c to build against glibc as well. Not used at the moment, just "so I have a copy when it goes away".
Rob Landley <rob@landley.net>
parents:
diff changeset
52 if (key==byteswap32_to_host(shdr->sh_type)) {
d29edba5582f Quick and dirty port of uClibc's readelf.c to build against glibc as well. Not used at the moment, just "so I have a copy when it goes away".
Rob Landley <rob@landley.net>
parents:
diff changeset
53 return shdr;
d29edba5582f Quick and dirty port of uClibc's readelf.c to build against glibc as well. Not used at the moment, just "so I have a copy when it goes away".
Rob Landley <rob@landley.net>
parents:
diff changeset
54 }
d29edba5582f Quick and dirty port of uClibc's readelf.c to build against glibc as well. Not used at the moment, just "so I have a copy when it goes away".
Rob Landley <rob@landley.net>
parents:
diff changeset
55 }
d29edba5582f Quick and dirty port of uClibc's readelf.c to build against glibc as well. Not used at the moment, just "so I have a copy when it goes away".
Rob Landley <rob@landley.net>
parents:
diff changeset
56 return NULL;
d29edba5582f Quick and dirty port of uClibc's readelf.c to build against glibc as well. Not used at the moment, just "so I have a copy when it goes away".
Rob Landley <rob@landley.net>
parents:
diff changeset
57 }
d29edba5582f Quick and dirty port of uClibc's readelf.c to build against glibc as well. Not used at the moment, just "so I have a copy when it goes away".
Rob Landley <rob@landley.net>
parents:
diff changeset
58
d29edba5582f Quick and dirty port of uClibc's readelf.c to build against glibc as well. Not used at the moment, just "so I have a copy when it goes away".
Rob Landley <rob@landley.net>
parents:
diff changeset
59 static ElfW(Phdr) * elf_find_phdr_type( uint32_t type, ElfW(Ehdr) *ehdr)
d29edba5582f Quick and dirty port of uClibc's readelf.c to build against glibc as well. Not used at the moment, just "so I have a copy when it goes away".
Rob Landley <rob@landley.net>
parents:
diff changeset
60 {
d29edba5582f Quick and dirty port of uClibc's readelf.c to build against glibc as well. Not used at the moment, just "so I have a copy when it goes away".
Rob Landley <rob@landley.net>
parents:
diff changeset
61 int j;
d29edba5582f Quick and dirty port of uClibc's readelf.c to build against glibc as well. Not used at the moment, just "so I have a copy when it goes away".
Rob Landley <rob@landley.net>
parents:
diff changeset
62 ElfW(Phdr) *phdr = (ElfW(Phdr) *)(ehdr->e_phoff + (char *)ehdr);
d29edba5582f Quick and dirty port of uClibc's readelf.c to build against glibc as well. Not used at the moment, just "so I have a copy when it goes away".
Rob Landley <rob@landley.net>
parents:
diff changeset
63 for (j = ehdr->e_phnum; --j>=0; ++phdr) {
d29edba5582f Quick and dirty port of uClibc's readelf.c to build against glibc as well. Not used at the moment, just "so I have a copy when it goes away".
Rob Landley <rob@landley.net>
parents:
diff changeset
64 if (type==byteswap32_to_host(phdr->p_type)) {
d29edba5582f Quick and dirty port of uClibc's readelf.c to build against glibc as well. Not used at the moment, just "so I have a copy when it goes away".
Rob Landley <rob@landley.net>
parents:
diff changeset
65 return phdr;
d29edba5582f Quick and dirty port of uClibc's readelf.c to build against glibc as well. Not used at the moment, just "so I have a copy when it goes away".
Rob Landley <rob@landley.net>
parents:
diff changeset
66 }
d29edba5582f Quick and dirty port of uClibc's readelf.c to build against glibc as well. Not used at the moment, just "so I have a copy when it goes away".
Rob Landley <rob@landley.net>
parents:
diff changeset
67 }
d29edba5582f Quick and dirty port of uClibc's readelf.c to build against glibc as well. Not used at the moment, just "so I have a copy when it goes away".
Rob Landley <rob@landley.net>
parents:
diff changeset
68 return NULL;
d29edba5582f Quick and dirty port of uClibc's readelf.c to build against glibc as well. Not used at the moment, just "so I have a copy when it goes away".
Rob Landley <rob@landley.net>
parents:
diff changeset
69 }
d29edba5582f Quick and dirty port of uClibc's readelf.c to build against glibc as well. Not used at the moment, just "so I have a copy when it goes away".
Rob Landley <rob@landley.net>
parents:
diff changeset
70
d29edba5582f Quick and dirty port of uClibc's readelf.c to build against glibc as well. Not used at the moment, just "so I have a copy when it goes away".
Rob Landley <rob@landley.net>
parents:
diff changeset
71 /* Returns value if return_val==1, ptr otherwise */
d29edba5582f Quick and dirty port of uClibc's readelf.c to build against glibc as well. Not used at the moment, just "so I have a copy when it goes away".
Rob Landley <rob@landley.net>
parents:
diff changeset
72 static void * elf_find_dynamic( int64_t const key, ElfW(Dyn) *dynp,
d29edba5582f Quick and dirty port of uClibc's readelf.c to build against glibc as well. Not used at the moment, just "so I have a copy when it goes away".
Rob Landley <rob@landley.net>
parents:
diff changeset
73 ElfW(Ehdr) *ehdr, int return_val)
d29edba5582f Quick and dirty port of uClibc's readelf.c to build against glibc as well. Not used at the moment, just "so I have a copy when it goes away".
Rob Landley <rob@landley.net>
parents:
diff changeset
74 {
d29edba5582f Quick and dirty port of uClibc's readelf.c to build against glibc as well. Not used at the moment, just "so I have a copy when it goes away".
Rob Landley <rob@landley.net>
parents:
diff changeset
75 ElfW(Phdr) *pt_text = elf_find_phdr_type(PT_LOAD, ehdr);
d29edba5582f Quick and dirty port of uClibc's readelf.c to build against glibc as well. Not used at the moment, just "so I have a copy when it goes away".
Rob Landley <rob@landley.net>
parents:
diff changeset
76 ElfW(Addr) tx_reloc = byteswap_to_host(pt_text->p_vaddr) - byteswap_to_host(pt_text->p_offset);
d29edba5582f Quick and dirty port of uClibc's readelf.c to build against glibc as well. Not used at the moment, just "so I have a copy when it goes away".
Rob Landley <rob@landley.net>
parents:
diff changeset
77 for (; DT_NULL!=byteswap_to_host(dynp->d_tag); ++dynp) {
d29edba5582f Quick and dirty port of uClibc's readelf.c to build against glibc as well. Not used at the moment, just "so I have a copy when it goes away".
Rob Landley <rob@landley.net>
parents:
diff changeset
78 if (key == byteswap_to_host(dynp->d_tag)) {
d29edba5582f Quick and dirty port of uClibc's readelf.c to build against glibc as well. Not used at the moment, just "so I have a copy when it goes away".
Rob Landley <rob@landley.net>
parents:
diff changeset
79 if (return_val == 1)
d29edba5582f Quick and dirty port of uClibc's readelf.c to build against glibc as well. Not used at the moment, just "so I have a copy when it goes away".
Rob Landley <rob@landley.net>
parents:
diff changeset
80 return (void *)byteswap_to_host(dynp->d_un.d_val);
d29edba5582f Quick and dirty port of uClibc's readelf.c to build against glibc as well. Not used at the moment, just "so I have a copy when it goes away".
Rob Landley <rob@landley.net>
parents:
diff changeset
81 else
d29edba5582f Quick and dirty port of uClibc's readelf.c to build against glibc as well. Not used at the moment, just "so I have a copy when it goes away".
Rob Landley <rob@landley.net>
parents:
diff changeset
82 return (void *)(byteswap_to_host(dynp->d_un.d_val) - tx_reloc + (char *)ehdr );
d29edba5582f Quick and dirty port of uClibc's readelf.c to build against glibc as well. Not used at the moment, just "so I have a copy when it goes away".
Rob Landley <rob@landley.net>
parents:
diff changeset
83 }
d29edba5582f Quick and dirty port of uClibc's readelf.c to build against glibc as well. Not used at the moment, just "so I have a copy when it goes away".
Rob Landley <rob@landley.net>
parents:
diff changeset
84 }
d29edba5582f Quick and dirty port of uClibc's readelf.c to build against glibc as well. Not used at the moment, just "so I have a copy when it goes away".
Rob Landley <rob@landley.net>
parents:
diff changeset
85 return NULL;
d29edba5582f Quick and dirty port of uClibc's readelf.c to build against glibc as well. Not used at the moment, just "so I have a copy when it goes away".
Rob Landley <rob@landley.net>
parents:
diff changeset
86 }
d29edba5582f Quick and dirty port of uClibc's readelf.c to build against glibc as well. Not used at the moment, just "so I have a copy when it goes away".
Rob Landley <rob@landley.net>
parents:
diff changeset
87
d29edba5582f Quick and dirty port of uClibc's readelf.c to build against glibc as well. Not used at the moment, just "so I have a copy when it goes away".
Rob Landley <rob@landley.net>
parents:
diff changeset
88 static int check_elf_header(ElfW(Ehdr) *const ehdr)
d29edba5582f Quick and dirty port of uClibc's readelf.c to build against glibc as well. Not used at the moment, just "so I have a copy when it goes away".
Rob Landley <rob@landley.net>
parents:
diff changeset
89 {
d29edba5582f Quick and dirty port of uClibc's readelf.c to build against glibc as well. Not used at the moment, just "so I have a copy when it goes away".
Rob Landley <rob@landley.net>
parents:
diff changeset
90 if (! ehdr || strncmp((void *)ehdr, ELFMAG, SELFMAG) != 0 ||
d29edba5582f Quick and dirty port of uClibc's readelf.c to build against glibc as well. Not used at the moment, just "so I have a copy when it goes away".
Rob Landley <rob@landley.net>
parents:
diff changeset
91 (ehdr->e_ident[EI_CLASS] != ELFCLASS32 &&
d29edba5582f Quick and dirty port of uClibc's readelf.c to build against glibc as well. Not used at the moment, just "so I have a copy when it goes away".
Rob Landley <rob@landley.net>
parents:
diff changeset
92 ehdr->e_ident[EI_CLASS] != ELFCLASS64) ||
d29edba5582f Quick and dirty port of uClibc's readelf.c to build against glibc as well. Not used at the moment, just "so I have a copy when it goes away".
Rob Landley <rob@landley.net>
parents:
diff changeset
93 ehdr->e_ident[EI_VERSION] != EV_CURRENT)
d29edba5582f Quick and dirty port of uClibc's readelf.c to build against glibc as well. Not used at the moment, just "so I have a copy when it goes away".
Rob Landley <rob@landley.net>
parents:
diff changeset
94 {
d29edba5582f Quick and dirty port of uClibc's readelf.c to build against glibc as well. Not used at the moment, just "so I have a copy when it goes away".
Rob Landley <rob@landley.net>
parents:
diff changeset
95 return 1;
d29edba5582f Quick and dirty port of uClibc's readelf.c to build against glibc as well. Not used at the moment, just "so I have a copy when it goes away".
Rob Landley <rob@landley.net>
parents:
diff changeset
96 }
d29edba5582f Quick and dirty port of uClibc's readelf.c to build against glibc as well. Not used at the moment, just "so I have a copy when it goes away".
Rob Landley <rob@landley.net>
parents:
diff changeset
97
d29edba5582f Quick and dirty port of uClibc's readelf.c to build against glibc as well. Not used at the moment, just "so I have a copy when it goes away".
Rob Landley <rob@landley.net>
parents:
diff changeset
98 /* Check if the target endianness matches the host's endianness */
d29edba5582f Quick and dirty port of uClibc's readelf.c to build against glibc as well. Not used at the moment, just "so I have a copy when it goes away".
Rob Landley <rob@landley.net>
parents:
diff changeset
99 byteswap = 0;
d29edba5582f Quick and dirty port of uClibc's readelf.c to build against glibc as well. Not used at the moment, just "so I have a copy when it goes away".
Rob Landley <rob@landley.net>
parents:
diff changeset
100 #if __BYTE_ORDER == __LITTLE_ENDIAN
d29edba5582f Quick and dirty port of uClibc's readelf.c to build against glibc as well. Not used at the moment, just "so I have a copy when it goes away".
Rob Landley <rob@landley.net>
parents:
diff changeset
101 if (ehdr->e_ident[5] == ELFDATA2MSB) {
d29edba5582f Quick and dirty port of uClibc's readelf.c to build against glibc as well. Not used at the moment, just "so I have a copy when it goes away".
Rob Landley <rob@landley.net>
parents:
diff changeset
102 /* Ick -- we will have to byte-swap everything */
d29edba5582f Quick and dirty port of uClibc's readelf.c to build against glibc as well. Not used at the moment, just "so I have a copy when it goes away".
Rob Landley <rob@landley.net>
parents:
diff changeset
103 byteswap = 1;
d29edba5582f Quick and dirty port of uClibc's readelf.c to build against glibc as well. Not used at the moment, just "so I have a copy when it goes away".
Rob Landley <rob@landley.net>
parents:
diff changeset
104 }
d29edba5582f Quick and dirty port of uClibc's readelf.c to build against glibc as well. Not used at the moment, just "so I have a copy when it goes away".
Rob Landley <rob@landley.net>
parents:
diff changeset
105 #elif __BYTE_ORDER == __BIG_ENDIAN
d29edba5582f Quick and dirty port of uClibc's readelf.c to build against glibc as well. Not used at the moment, just "so I have a copy when it goes away".
Rob Landley <rob@landley.net>
parents:
diff changeset
106 if (ehdr->e_ident[5] == ELFDATA2LSB) {
d29edba5582f Quick and dirty port of uClibc's readelf.c to build against glibc as well. Not used at the moment, just "so I have a copy when it goes away".
Rob Landley <rob@landley.net>
parents:
diff changeset
107 byteswap = 1;
d29edba5582f Quick and dirty port of uClibc's readelf.c to build against glibc as well. Not used at the moment, just "so I have a copy when it goes away".
Rob Landley <rob@landley.net>
parents:
diff changeset
108 }
d29edba5582f Quick and dirty port of uClibc's readelf.c to build against glibc as well. Not used at the moment, just "so I have a copy when it goes away".
Rob Landley <rob@landley.net>
parents:
diff changeset
109 #else
d29edba5582f Quick and dirty port of uClibc's readelf.c to build against glibc as well. Not used at the moment, just "so I have a copy when it goes away".
Rob Landley <rob@landley.net>
parents:
diff changeset
110 #error Unknown host byte order!
d29edba5582f Quick and dirty port of uClibc's readelf.c to build against glibc as well. Not used at the moment, just "so I have a copy when it goes away".
Rob Landley <rob@landley.net>
parents:
diff changeset
111 #endif
d29edba5582f Quick and dirty port of uClibc's readelf.c to build against glibc as well. Not used at the moment, just "so I have a copy when it goes away".
Rob Landley <rob@landley.net>
parents:
diff changeset
112 /* Be vary lazy, and only byteswap the stuff we use */
d29edba5582f Quick and dirty port of uClibc's readelf.c to build against glibc as well. Not used at the moment, just "so I have a copy when it goes away".
Rob Landley <rob@landley.net>
parents:
diff changeset
113 if (byteswap==1) {
d29edba5582f Quick and dirty port of uClibc's readelf.c to build against glibc as well. Not used at the moment, just "so I have a copy when it goes away".
Rob Landley <rob@landley.net>
parents:
diff changeset
114 ehdr->e_type=bswap_16(ehdr->e_type);
d29edba5582f Quick and dirty port of uClibc's readelf.c to build against glibc as well. Not used at the moment, just "so I have a copy when it goes away".
Rob Landley <rob@landley.net>
parents:
diff changeset
115 ehdr->e_machine=bswap_16(ehdr->e_machine);
d29edba5582f Quick and dirty port of uClibc's readelf.c to build against glibc as well. Not used at the moment, just "so I have a copy when it goes away".
Rob Landley <rob@landley.net>
parents:
diff changeset
116 ehdr->e_phoff=byteswap_to_host(ehdr->e_phoff);
d29edba5582f Quick and dirty port of uClibc's readelf.c to build against glibc as well. Not used at the moment, just "so I have a copy when it goes away".
Rob Landley <rob@landley.net>
parents:
diff changeset
117 ehdr->e_shoff=byteswap_to_host(ehdr->e_shoff);
d29edba5582f Quick and dirty port of uClibc's readelf.c to build against glibc as well. Not used at the moment, just "so I have a copy when it goes away".
Rob Landley <rob@landley.net>
parents:
diff changeset
118 ehdr->e_phnum=bswap_16(ehdr->e_phnum);
d29edba5582f Quick and dirty port of uClibc's readelf.c to build against glibc as well. Not used at the moment, just "so I have a copy when it goes away".
Rob Landley <rob@landley.net>
parents:
diff changeset
119 ehdr->e_shnum=bswap_16(ehdr->e_shnum);
d29edba5582f Quick and dirty port of uClibc's readelf.c to build against glibc as well. Not used at the moment, just "so I have a copy when it goes away".
Rob Landley <rob@landley.net>
parents:
diff changeset
120 }
d29edba5582f Quick and dirty port of uClibc's readelf.c to build against glibc as well. Not used at the moment, just "so I have a copy when it goes away".
Rob Landley <rob@landley.net>
parents:
diff changeset
121 return 0;
d29edba5582f Quick and dirty port of uClibc's readelf.c to build against glibc as well. Not used at the moment, just "so I have a copy when it goes away".
Rob Landley <rob@landley.net>
parents:
diff changeset
122 }
d29edba5582f Quick and dirty port of uClibc's readelf.c to build against glibc as well. Not used at the moment, just "so I have a copy when it goes away".
Rob Landley <rob@landley.net>
parents:
diff changeset
123
d29edba5582f Quick and dirty port of uClibc's readelf.c to build against glibc as well. Not used at the moment, just "so I have a copy when it goes away".
Rob Landley <rob@landley.net>
parents:
diff changeset
124
d29edba5582f Quick and dirty port of uClibc's readelf.c to build against glibc as well. Not used at the moment, just "so I have a copy when it goes away".
Rob Landley <rob@landley.net>
parents:
diff changeset
125 static void describe_elf_hdr(ElfW(Ehdr)* ehdr)
d29edba5582f Quick and dirty port of uClibc's readelf.c to build against glibc as well. Not used at the moment, just "so I have a copy when it goes away".
Rob Landley <rob@landley.net>
parents:
diff changeset
126 {
d29edba5582f Quick and dirty port of uClibc's readelf.c to build against glibc as well. Not used at the moment, just "so I have a copy when it goes away".
Rob Landley <rob@landley.net>
parents:
diff changeset
127 char *tmp, *tmp1;
d29edba5582f Quick and dirty port of uClibc's readelf.c to build against glibc as well. Not used at the moment, just "so I have a copy when it goes away".
Rob Landley <rob@landley.net>
parents:
diff changeset
128
d29edba5582f Quick and dirty port of uClibc's readelf.c to build against glibc as well. Not used at the moment, just "so I have a copy when it goes away".
Rob Landley <rob@landley.net>
parents:
diff changeset
129 switch (ehdr->e_type) {
d29edba5582f Quick and dirty port of uClibc's readelf.c to build against glibc as well. Not used at the moment, just "so I have a copy when it goes away".
Rob Landley <rob@landley.net>
parents:
diff changeset
130 case ET_NONE: tmp = "None"; tmp1 = "NONE"; break;
d29edba5582f Quick and dirty port of uClibc's readelf.c to build against glibc as well. Not used at the moment, just "so I have a copy when it goes away".
Rob Landley <rob@landley.net>
parents:
diff changeset
131 case ET_REL: tmp = "Relocatable File"; tmp1 = "REL"; break;
d29edba5582f Quick and dirty port of uClibc's readelf.c to build against glibc as well. Not used at the moment, just "so I have a copy when it goes away".
Rob Landley <rob@landley.net>
parents:
diff changeset
132 case ET_EXEC: tmp = "Executable file"; tmp1 = "EXEC"; break;
d29edba5582f Quick and dirty port of uClibc's readelf.c to build against glibc as well. Not used at the moment, just "so I have a copy when it goes away".
Rob Landley <rob@landley.net>
parents:
diff changeset
133 case ET_DYN: tmp = "Shared object file"; tmp1 = "DYN"; break;
d29edba5582f Quick and dirty port of uClibc's readelf.c to build against glibc as well. Not used at the moment, just "so I have a copy when it goes away".
Rob Landley <rob@landley.net>
parents:
diff changeset
134 case ET_CORE: tmp = "Core file"; tmp1 = "CORE"; break;
d29edba5582f Quick and dirty port of uClibc's readelf.c to build against glibc as well. Not used at the moment, just "so I have a copy when it goes away".
Rob Landley <rob@landley.net>
parents:
diff changeset
135 default:
d29edba5582f Quick and dirty port of uClibc's readelf.c to build against glibc as well. Not used at the moment, just "so I have a copy when it goes away".
Rob Landley <rob@landley.net>
parents:
diff changeset
136 tmp = tmp1 = "Unknown";
d29edba5582f Quick and dirty port of uClibc's readelf.c to build against glibc as well. Not used at the moment, just "so I have a copy when it goes away".
Rob Landley <rob@landley.net>
parents:
diff changeset
137 }
d29edba5582f Quick and dirty port of uClibc's readelf.c to build against glibc as well. Not used at the moment, just "so I have a copy when it goes away".
Rob Landley <rob@landley.net>
parents:
diff changeset
138 printf( "Type:\t\t%s (%s)\n", tmp1, tmp);
d29edba5582f Quick and dirty port of uClibc's readelf.c to build against glibc as well. Not used at the moment, just "so I have a copy when it goes away".
Rob Landley <rob@landley.net>
parents:
diff changeset
139
d29edba5582f Quick and dirty port of uClibc's readelf.c to build against glibc as well. Not used at the moment, just "so I have a copy when it goes away".
Rob Landley <rob@landley.net>
parents:
diff changeset
140 switch (ehdr->e_machine) {
d29edba5582f Quick and dirty port of uClibc's readelf.c to build against glibc as well. Not used at the moment, just "so I have a copy when it goes away".
Rob Landley <rob@landley.net>
parents:
diff changeset
141 case EM_NONE: tmp="No machine"; break;
d29edba5582f Quick and dirty port of uClibc's readelf.c to build against glibc as well. Not used at the moment, just "so I have a copy when it goes away".
Rob Landley <rob@landley.net>
parents:
diff changeset
142 case EM_M32: tmp="AT&T WE 32100"; break;
d29edba5582f Quick and dirty port of uClibc's readelf.c to build against glibc as well. Not used at the moment, just "so I have a copy when it goes away".
Rob Landley <rob@landley.net>
parents:
diff changeset
143 case EM_SPARC: tmp="SUN SPARC"; break;
d29edba5582f Quick and dirty port of uClibc's readelf.c to build against glibc as well. Not used at the moment, just "so I have a copy when it goes away".
Rob Landley <rob@landley.net>
parents:
diff changeset
144 case EM_386: tmp="Intel 80386"; break;
d29edba5582f Quick and dirty port of uClibc's readelf.c to build against glibc as well. Not used at the moment, just "so I have a copy when it goes away".
Rob Landley <rob@landley.net>
parents:
diff changeset
145 case EM_68K: tmp="Motorola m68k family"; break;
d29edba5582f Quick and dirty port of uClibc's readelf.c to build against glibc as well. Not used at the moment, just "so I have a copy when it goes away".
Rob Landley <rob@landley.net>
parents:
diff changeset
146 case EM_88K: tmp="Motorola m88k family"; break;
d29edba5582f Quick and dirty port of uClibc's readelf.c to build against glibc as well. Not used at the moment, just "so I have a copy when it goes away".
Rob Landley <rob@landley.net>
parents:
diff changeset
147 // case EM_486: tmp="Intel 80486"; break;
d29edba5582f Quick and dirty port of uClibc's readelf.c to build against glibc as well. Not used at the moment, just "so I have a copy when it goes away".
Rob Landley <rob@landley.net>
parents:
diff changeset
148 case EM_860: tmp="Intel 80860"; break;
d29edba5582f Quick and dirty port of uClibc's readelf.c to build against glibc as well. Not used at the moment, just "so I have a copy when it goes away".
Rob Landley <rob@landley.net>
parents:
diff changeset
149 case EM_MIPS: tmp="MIPS R3000 big-endian"; break;
d29edba5582f Quick and dirty port of uClibc's readelf.c to build against glibc as well. Not used at the moment, just "so I have a copy when it goes away".
Rob Landley <rob@landley.net>
parents:
diff changeset
150 case EM_S370: tmp="IBM System/370"; break;
d29edba5582f Quick and dirty port of uClibc's readelf.c to build against glibc as well. Not used at the moment, just "so I have a copy when it goes away".
Rob Landley <rob@landley.net>
parents:
diff changeset
151 case EM_MIPS_RS3_LE: tmp="MIPS R3000 little-endian"; break;
d29edba5582f Quick and dirty port of uClibc's readelf.c to build against glibc as well. Not used at the moment, just "so I have a copy when it goes away".
Rob Landley <rob@landley.net>
parents:
diff changeset
152 // case EM_OLD_SPARCV9: tmp="Sparc v9 (old)"; break;
d29edba5582f Quick and dirty port of uClibc's readelf.c to build against glibc as well. Not used at the moment, just "so I have a copy when it goes away".
Rob Landley <rob@landley.net>
parents:
diff changeset
153 case EM_PARISC: tmp="HPPA"; break;
d29edba5582f Quick and dirty port of uClibc's readelf.c to build against glibc as well. Not used at the moment, just "so I have a copy when it goes away".
Rob Landley <rob@landley.net>
parents:
diff changeset
154 /*case EM_PPC_OLD: tmp="Power PC (old)"; break; conflicts with EM_VPP500 */
d29edba5582f Quick and dirty port of uClibc's readelf.c to build against glibc as well. Not used at the moment, just "so I have a copy when it goes away".
Rob Landley <rob@landley.net>
parents:
diff changeset
155 case EM_SPARC32PLUS: tmp="Sun's v8plus"; break;
d29edba5582f Quick and dirty port of uClibc's readelf.c to build against glibc as well. Not used at the moment, just "so I have a copy when it goes away".
Rob Landley <rob@landley.net>
parents:
diff changeset
156 case EM_960: tmp="Intel 80960"; break;
d29edba5582f Quick and dirty port of uClibc's readelf.c to build against glibc as well. Not used at the moment, just "so I have a copy when it goes away".
Rob Landley <rob@landley.net>
parents:
diff changeset
157 case EM_PPC: tmp="PowerPC"; break;
d29edba5582f Quick and dirty port of uClibc's readelf.c to build against glibc as well. Not used at the moment, just "so I have a copy when it goes away".
Rob Landley <rob@landley.net>
parents:
diff changeset
158 case EM_PPC64: tmp="PowerPC 64-bit"; break;
d29edba5582f Quick and dirty port of uClibc's readelf.c to build against glibc as well. Not used at the moment, just "so I have a copy when it goes away".
Rob Landley <rob@landley.net>
parents:
diff changeset
159 case EM_V800: tmp="NEC V800 series"; break;
d29edba5582f Quick and dirty port of uClibc's readelf.c to build against glibc as well. Not used at the moment, just "so I have a copy when it goes away".
Rob Landley <rob@landley.net>
parents:
diff changeset
160 case EM_FR20: tmp="Fujitsu FR20"; break;
d29edba5582f Quick and dirty port of uClibc's readelf.c to build against glibc as well. Not used at the moment, just "so I have a copy when it goes away".
Rob Landley <rob@landley.net>
parents:
diff changeset
161 case EM_RH32: tmp="TRW RH-32"; break;
d29edba5582f Quick and dirty port of uClibc's readelf.c to build against glibc as well. Not used at the moment, just "so I have a copy when it goes away".
Rob Landley <rob@landley.net>
parents:
diff changeset
162 // case EM_MCORE: tmp="MCORE"; break;
d29edba5582f Quick and dirty port of uClibc's readelf.c to build against glibc as well. Not used at the moment, just "so I have a copy when it goes away".
Rob Landley <rob@landley.net>
parents:
diff changeset
163 case EM_ARM: tmp="ARM"; break;
d29edba5582f Quick and dirty port of uClibc's readelf.c to build against glibc as well. Not used at the moment, just "so I have a copy when it goes away".
Rob Landley <rob@landley.net>
parents:
diff changeset
164 case EM_FAKE_ALPHA: tmp="Digital Alpha"; break;
d29edba5582f Quick and dirty port of uClibc's readelf.c to build against glibc as well. Not used at the moment, just "so I have a copy when it goes away".
Rob Landley <rob@landley.net>
parents:
diff changeset
165 case EM_SH: tmp="Renesas SH"; break;
d29edba5582f Quick and dirty port of uClibc's readelf.c to build against glibc as well. Not used at the moment, just "so I have a copy when it goes away".
Rob Landley <rob@landley.net>
parents:
diff changeset
166 case EM_SPARCV9: tmp="SPARC v9 64-bit"; break;
d29edba5582f Quick and dirty port of uClibc's readelf.c to build against glibc as well. Not used at the moment, just "so I have a copy when it goes away".
Rob Landley <rob@landley.net>
parents:
diff changeset
167 case EM_TRICORE: tmp="Siemens Tricore"; break;
d29edba5582f Quick and dirty port of uClibc's readelf.c to build against glibc as well. Not used at the moment, just "so I have a copy when it goes away".
Rob Landley <rob@landley.net>
parents:
diff changeset
168 case EM_ARC: tmp="Argonaut RISC Core"; break;
d29edba5582f Quick and dirty port of uClibc's readelf.c to build against glibc as well. Not used at the moment, just "so I have a copy when it goes away".
Rob Landley <rob@landley.net>
parents:
diff changeset
169 case EM_H8_300: tmp="Renesas H8/300"; break;
d29edba5582f Quick and dirty port of uClibc's readelf.c to build against glibc as well. Not used at the moment, just "so I have a copy when it goes away".
Rob Landley <rob@landley.net>
parents:
diff changeset
170 case EM_H8_300H: tmp="Renesas H8/300H"; break;
d29edba5582f Quick and dirty port of uClibc's readelf.c to build against glibc as well. Not used at the moment, just "so I have a copy when it goes away".
Rob Landley <rob@landley.net>
parents:
diff changeset
171 case EM_H8S: tmp="Renesas H8S"; break;
d29edba5582f Quick and dirty port of uClibc's readelf.c to build against glibc as well. Not used at the moment, just "so I have a copy when it goes away".
Rob Landley <rob@landley.net>
parents:
diff changeset
172 case EM_H8_500: tmp="Renesas H8/500"; break;
d29edba5582f Quick and dirty port of uClibc's readelf.c to build against glibc as well. Not used at the moment, just "so I have a copy when it goes away".
Rob Landley <rob@landley.net>
parents:
diff changeset
173 case EM_IA_64: tmp="Intel Merced"; break;
d29edba5582f Quick and dirty port of uClibc's readelf.c to build against glibc as well. Not used at the moment, just "so I have a copy when it goes away".
Rob Landley <rob@landley.net>
parents:
diff changeset
174 case EM_MIPS_X: tmp="Stanford MIPS-X"; break;
d29edba5582f Quick and dirty port of uClibc's readelf.c to build against glibc as well. Not used at the moment, just "so I have a copy when it goes away".
Rob Landley <rob@landley.net>
parents:
diff changeset
175 case EM_COLDFIRE: tmp="Motorola Coldfire"; break;
d29edba5582f Quick and dirty port of uClibc's readelf.c to build against glibc as well. Not used at the moment, just "so I have a copy when it goes away".
Rob Landley <rob@landley.net>
parents:
diff changeset
176 case EM_68HC12: tmp="Motorola M68HC12"; break;
d29edba5582f Quick and dirty port of uClibc's readelf.c to build against glibc as well. Not used at the moment, just "so I have a copy when it goes away".
Rob Landley <rob@landley.net>
parents:
diff changeset
177 case EM_ALPHA: tmp="Alpha"; break;
d29edba5582f Quick and dirty port of uClibc's readelf.c to build against glibc as well. Not used at the moment, just "so I have a copy when it goes away".
Rob Landley <rob@landley.net>
parents:
diff changeset
178 // case EM_CYGNUS_D10V:
d29edba5582f Quick and dirty port of uClibc's readelf.c to build against glibc as well. Not used at the moment, just "so I have a copy when it goes away".
Rob Landley <rob@landley.net>
parents:
diff changeset
179 case EM_D10V: tmp="Mitsubishi D10V"; break;
d29edba5582f Quick and dirty port of uClibc's readelf.c to build against glibc as well. Not used at the moment, just "so I have a copy when it goes away".
Rob Landley <rob@landley.net>
parents:
diff changeset
180 // case EM_CYGNUS_D30V:
d29edba5582f Quick and dirty port of uClibc's readelf.c to build against glibc as well. Not used at the moment, just "so I have a copy when it goes away".
Rob Landley <rob@landley.net>
parents:
diff changeset
181 case EM_D30V: tmp="Mitsubishi D30V"; break;
d29edba5582f Quick and dirty port of uClibc's readelf.c to build against glibc as well. Not used at the moment, just "so I have a copy when it goes away".
Rob Landley <rob@landley.net>
parents:
diff changeset
182 // case EM_CYGNUS_M32R:
d29edba5582f Quick and dirty port of uClibc's readelf.c to build against glibc as well. Not used at the moment, just "so I have a copy when it goes away".
Rob Landley <rob@landley.net>
parents:
diff changeset
183 case EM_M32R: tmp="Renesas M32R (formerly Mitsubishi M32r)"; break;
d29edba5582f Quick and dirty port of uClibc's readelf.c to build against glibc as well. Not used at the moment, just "so I have a copy when it goes away".
Rob Landley <rob@landley.net>
parents:
diff changeset
184 // case EM_CYGNUS_V850:
d29edba5582f Quick and dirty port of uClibc's readelf.c to build against glibc as well. Not used at the moment, just "so I have a copy when it goes away".
Rob Landley <rob@landley.net>
parents:
diff changeset
185 case EM_V850: tmp="NEC v850"; break;
d29edba5582f Quick and dirty port of uClibc's readelf.c to build against glibc as well. Not used at the moment, just "so I have a copy when it goes away".
Rob Landley <rob@landley.net>
parents:
diff changeset
186 // case EM_CYGNUS_MN10300:
d29edba5582f Quick and dirty port of uClibc's readelf.c to build against glibc as well. Not used at the moment, just "so I have a copy when it goes away".
Rob Landley <rob@landley.net>
parents:
diff changeset
187 case EM_MN10300: tmp="Matsushita MN10300"; break;
d29edba5582f Quick and dirty port of uClibc's readelf.c to build against glibc as well. Not used at the moment, just "so I have a copy when it goes away".
Rob Landley <rob@landley.net>
parents:
diff changeset
188 // case EM_CYGNUS_MN10200:
d29edba5582f Quick and dirty port of uClibc's readelf.c to build against glibc as well. Not used at the moment, just "so I have a copy when it goes away".
Rob Landley <rob@landley.net>
parents:
diff changeset
189 case EM_MN10200: tmp="Matsushita MN10200"; break;
d29edba5582f Quick and dirty port of uClibc's readelf.c to build against glibc as well. Not used at the moment, just "so I have a copy when it goes away".
Rob Landley <rob@landley.net>
parents:
diff changeset
190 // case EM_CYGNUS_FR30:
d29edba5582f Quick and dirty port of uClibc's readelf.c to build against glibc as well. Not used at the moment, just "so I have a copy when it goes away".
Rob Landley <rob@landley.net>
parents:
diff changeset
191 case EM_FR30: tmp="Fujitsu FR30"; break;
d29edba5582f Quick and dirty port of uClibc's readelf.c to build against glibc as well. Not used at the moment, just "so I have a copy when it goes away".
Rob Landley <rob@landley.net>
parents:
diff changeset
192 // case EM_CYGNUS_FRV:
d29edba5582f Quick and dirty port of uClibc's readelf.c to build against glibc as well. Not used at the moment, just "so I have a copy when it goes away".
Rob Landley <rob@landley.net>
parents:
diff changeset
193 // case EM_PJ_OLD:
d29edba5582f Quick and dirty port of uClibc's readelf.c to build against glibc as well. Not used at the moment, just "so I have a copy when it goes away".
Rob Landley <rob@landley.net>
parents:
diff changeset
194 case EM_PJ: tmp="picoJava"; break;
d29edba5582f Quick and dirty port of uClibc's readelf.c to build against glibc as well. Not used at the moment, just "so I have a copy when it goes away".
Rob Landley <rob@landley.net>
parents:
diff changeset
195 case EM_MMA: tmp="Fujitsu MMA Multimedia Accelerator"; break;
d29edba5582f Quick and dirty port of uClibc's readelf.c to build against glibc as well. Not used at the moment, just "so I have a copy when it goes away".
Rob Landley <rob@landley.net>
parents:
diff changeset
196 case EM_PCP: tmp="Siemens PCP"; break;
d29edba5582f Quick and dirty port of uClibc's readelf.c to build against glibc as well. Not used at the moment, just "so I have a copy when it goes away".
Rob Landley <rob@landley.net>
parents:
diff changeset
197 case EM_NCPU: tmp="Sony nCPU embeeded RISC"; break;
d29edba5582f Quick and dirty port of uClibc's readelf.c to build against glibc as well. Not used at the moment, just "so I have a copy when it goes away".
Rob Landley <rob@landley.net>
parents:
diff changeset
198 case EM_NDR1: tmp="Denso NDR1 microprocessor"; break;
d29edba5582f Quick and dirty port of uClibc's readelf.c to build against glibc as well. Not used at the moment, just "so I have a copy when it goes away".
Rob Landley <rob@landley.net>
parents:
diff changeset
199 case EM_STARCORE: tmp="Motorola Start*Core processor"; break;
d29edba5582f Quick and dirty port of uClibc's readelf.c to build against glibc as well. Not used at the moment, just "so I have a copy when it goes away".
Rob Landley <rob@landley.net>
parents:
diff changeset
200 case EM_ME16: tmp="Toyota ME16 processor"; break;
d29edba5582f Quick and dirty port of uClibc's readelf.c to build against glibc as well. Not used at the moment, just "so I have a copy when it goes away".
Rob Landley <rob@landley.net>
parents:
diff changeset
201 case EM_ST100: tmp="STMicroelectronic ST100 processor"; break;
d29edba5582f Quick and dirty port of uClibc's readelf.c to build against glibc as well. Not used at the moment, just "so I have a copy when it goes away".
Rob Landley <rob@landley.net>
parents:
diff changeset
202 case EM_TINYJ: tmp="Advanced Logic Corp. Tinyj emb.fam"; break;
d29edba5582f Quick and dirty port of uClibc's readelf.c to build against glibc as well. Not used at the moment, just "so I have a copy when it goes away".
Rob Landley <rob@landley.net>
parents:
diff changeset
203 case EM_FX66: tmp="Siemens FX66 microcontroller"; break;
d29edba5582f Quick and dirty port of uClibc's readelf.c to build against glibc as well. Not used at the moment, just "so I have a copy when it goes away".
Rob Landley <rob@landley.net>
parents:
diff changeset
204 case EM_ST9PLUS: tmp="STMicroelectronics ST9+ 8/16 mc"; break;
d29edba5582f Quick and dirty port of uClibc's readelf.c to build against glibc as well. Not used at the moment, just "so I have a copy when it goes away".
Rob Landley <rob@landley.net>
parents:
diff changeset
205 case EM_ST7: tmp="STmicroelectronics ST7 8 bit mc"; break;
d29edba5582f Quick and dirty port of uClibc's readelf.c to build against glibc as well. Not used at the moment, just "so I have a copy when it goes away".
Rob Landley <rob@landley.net>
parents:
diff changeset
206 case EM_68HC16: tmp="Motorola MC68HC16 microcontroller"; break;
d29edba5582f Quick and dirty port of uClibc's readelf.c to build against glibc as well. Not used at the moment, just "so I have a copy when it goes away".
Rob Landley <rob@landley.net>
parents:
diff changeset
207 case EM_68HC11: tmp="Motorola MC68HC11 microcontroller"; break;
d29edba5582f Quick and dirty port of uClibc's readelf.c to build against glibc as well. Not used at the moment, just "so I have a copy when it goes away".
Rob Landley <rob@landley.net>
parents:
diff changeset
208 case EM_68HC08: tmp="Motorola MC68HC08 microcontroller"; break;
d29edba5582f Quick and dirty port of uClibc's readelf.c to build against glibc as well. Not used at the moment, just "so I have a copy when it goes away".
Rob Landley <rob@landley.net>
parents:
diff changeset
209 case EM_68HC05: tmp="Motorola MC68HC05 microcontroller"; break;
d29edba5582f Quick and dirty port of uClibc's readelf.c to build against glibc as well. Not used at the moment, just "so I have a copy when it goes away".
Rob Landley <rob@landley.net>
parents:
diff changeset
210 case EM_SVX: tmp="Silicon Graphics SVx"; break;
d29edba5582f Quick and dirty port of uClibc's readelf.c to build against glibc as well. Not used at the moment, just "so I have a copy when it goes away".
Rob Landley <rob@landley.net>
parents:
diff changeset
211 case EM_ST19: tmp="STMicroelectronics ST19 8 bit mc"; break;
d29edba5582f Quick and dirty port of uClibc's readelf.c to build against glibc as well. Not used at the moment, just "so I have a copy when it goes away".
Rob Landley <rob@landley.net>
parents:
diff changeset
212 case EM_VAX: tmp="Digital VAX"; break;
d29edba5582f Quick and dirty port of uClibc's readelf.c to build against glibc as well. Not used at the moment, just "so I have a copy when it goes away".
Rob Landley <rob@landley.net>
parents:
diff changeset
213 // case EM_AVR_OLD:
d29edba5582f Quick and dirty port of uClibc's readelf.c to build against glibc as well. Not used at the moment, just "so I have a copy when it goes away".
Rob Landley <rob@landley.net>
parents:
diff changeset
214 case EM_AVR: tmp="Atmel AVR 8-bit microcontroller"; break;
d29edba5582f Quick and dirty port of uClibc's readelf.c to build against glibc as well. Not used at the moment, just "so I have a copy when it goes away".
Rob Landley <rob@landley.net>
parents:
diff changeset
215 case EM_CRIS: tmp="Axis Communications 32-bit embedded processor"; break;
d29edba5582f Quick and dirty port of uClibc's readelf.c to build against glibc as well. Not used at the moment, just "so I have a copy when it goes away".
Rob Landley <rob@landley.net>
parents:
diff changeset
216 case EM_JAVELIN: tmp="Infineon Technologies 32-bit embedded processor"; break;
d29edba5582f Quick and dirty port of uClibc's readelf.c to build against glibc as well. Not used at the moment, just "so I have a copy when it goes away".
Rob Landley <rob@landley.net>
parents:
diff changeset
217 case EM_FIREPATH: tmp="Element 14 64-bit DSP Processor"; break;
d29edba5582f Quick and dirty port of uClibc's readelf.c to build against glibc as well. Not used at the moment, just "so I have a copy when it goes away".
Rob Landley <rob@landley.net>
parents:
diff changeset
218 case EM_ZSP: tmp="LSI Logic 16-bit DSP Processor"; break;
d29edba5582f Quick and dirty port of uClibc's readelf.c to build against glibc as well. Not used at the moment, just "so I have a copy when it goes away".
Rob Landley <rob@landley.net>
parents:
diff changeset
219 case EM_MMIX: tmp="Donald Knuth's educational 64-bit processor"; break;
d29edba5582f Quick and dirty port of uClibc's readelf.c to build against glibc as well. Not used at the moment, just "so I have a copy when it goes away".
Rob Landley <rob@landley.net>
parents:
diff changeset
220 case EM_HUANY: tmp="Harvard University machine-independent object files"; break;
d29edba5582f Quick and dirty port of uClibc's readelf.c to build against glibc as well. Not used at the moment, just "so I have a copy when it goes away".
Rob Landley <rob@landley.net>
parents:
diff changeset
221 case EM_PRISM: tmp="SiTera Prism"; break;
d29edba5582f Quick and dirty port of uClibc's readelf.c to build against glibc as well. Not used at the moment, just "so I have a copy when it goes away".
Rob Landley <rob@landley.net>
parents:
diff changeset
222 case EM_X86_64: tmp="AMD x86-64 architecture"; break;
d29edba5582f Quick and dirty port of uClibc's readelf.c to build against glibc as well. Not used at the moment, just "so I have a copy when it goes away".
Rob Landley <rob@landley.net>
parents:
diff changeset
223 // case EM_S390_OLD:
d29edba5582f Quick and dirty port of uClibc's readelf.c to build against glibc as well. Not used at the moment, just "so I have a copy when it goes away".
Rob Landley <rob@landley.net>
parents:
diff changeset
224 case EM_S390: tmp="IBM S390"; break;
d29edba5582f Quick and dirty port of uClibc's readelf.c to build against glibc as well. Not used at the moment, just "so I have a copy when it goes away".
Rob Landley <rob@landley.net>
parents:
diff changeset
225 // case EM_XSTORMY16: tmp="Sanyo Xstormy16 CPU core"; break;
d29edba5582f Quick and dirty port of uClibc's readelf.c to build against glibc as well. Not used at the moment, just "so I have a copy when it goes away".
Rob Landley <rob@landley.net>
parents:
diff changeset
226 case EM_OPENRISC:
d29edba5582f Quick and dirty port of uClibc's readelf.c to build against glibc as well. Not used at the moment, just "so I have a copy when it goes away".
Rob Landley <rob@landley.net>
parents:
diff changeset
227 // case EM_OR32: tmp="OpenRISC"; break;
d29edba5582f Quick and dirty port of uClibc's readelf.c to build against glibc as well. Not used at the moment, just "so I have a copy when it goes away".
Rob Landley <rob@landley.net>
parents:
diff changeset
228 // case EM_CRX: tmp="National Semiconductor CRX microprocessor"; break;
d29edba5582f Quick and dirty port of uClibc's readelf.c to build against glibc as well. Not used at the moment, just "so I have a copy when it goes away".
Rob Landley <rob@landley.net>
parents:
diff changeset
229 // case EM_DLX: tmp="OpenDLX"; break;
d29edba5582f Quick and dirty port of uClibc's readelf.c to build against glibc as well. Not used at the moment, just "so I have a copy when it goes away".
Rob Landley <rob@landley.net>
parents:
diff changeset
230 // case EM_IP2K_OLD:
d29edba5582f Quick and dirty port of uClibc's readelf.c to build against glibc as well. Not used at the moment, just "so I have a copy when it goes away".
Rob Landley <rob@landley.net>
parents:
diff changeset
231 // case EM_IP2K: tmp="Ubicom IP2xxx 8-bit microcontrollers"; break;
d29edba5582f Quick and dirty port of uClibc's readelf.c to build against glibc as well. Not used at the moment, just "so I have a copy when it goes away".
Rob Landley <rob@landley.net>
parents:
diff changeset
232 // case EM_IQ2000: tmp="Vitesse IQ2000"; break;
d29edba5582f Quick and dirty port of uClibc's readelf.c to build against glibc as well. Not used at the moment, just "so I have a copy when it goes away".
Rob Landley <rob@landley.net>
parents:
diff changeset
233 // case EM_XTENSA_OLD:
d29edba5582f Quick and dirty port of uClibc's readelf.c to build against glibc as well. Not used at the moment, just "so I have a copy when it goes away".
Rob Landley <rob@landley.net>
parents:
diff changeset
234 case EM_XTENSA: tmp="Tensilica Xtensa Processor"; break;
d29edba5582f Quick and dirty port of uClibc's readelf.c to build against glibc as well. Not used at the moment, just "so I have a copy when it goes away".
Rob Landley <rob@landley.net>
parents:
diff changeset
235 // case EM_M32C: tmp="Renesas M32c"; break;
d29edba5582f Quick and dirty port of uClibc's readelf.c to build against glibc as well. Not used at the moment, just "so I have a copy when it goes away".
Rob Landley <rob@landley.net>
parents:
diff changeset
236 // case EM_MT: tmp="Morpho Techologies MT processor"; break;
d29edba5582f Quick and dirty port of uClibc's readelf.c to build against glibc as well. Not used at the moment, just "so I have a copy when it goes away".
Rob Landley <rob@landley.net>
parents:
diff changeset
237 // case EM_BLACKFIN: tmp="Analog Devices Blackfin"; break;
d29edba5582f Quick and dirty port of uClibc's readelf.c to build against glibc as well. Not used at the moment, just "so I have a copy when it goes away".
Rob Landley <rob@landley.net>
parents:
diff changeset
238 // case EM_NIOS32: tmp="Altera Nios 32"; break;
d29edba5582f Quick and dirty port of uClibc's readelf.c to build against glibc as well. Not used at the moment, just "so I have a copy when it goes away".
Rob Landley <rob@landley.net>
parents:
diff changeset
239 // case EM_ALTERA_NIOS2: tmp="Altera Nios II"; break;
d29edba5582f Quick and dirty port of uClibc's readelf.c to build against glibc as well. Not used at the moment, just "so I have a copy when it goes away".
Rob Landley <rob@landley.net>
parents:
diff changeset
240 case EM_VPP500: tmp="Fujitsu VPP500"; break;
d29edba5582f Quick and dirty port of uClibc's readelf.c to build against glibc as well. Not used at the moment, just "so I have a copy when it goes away".
Rob Landley <rob@landley.net>
parents:
diff changeset
241 case EM_PDSP: tmp="Sony DSP Processor"; break;
d29edba5582f Quick and dirty port of uClibc's readelf.c to build against glibc as well. Not used at the moment, just "so I have a copy when it goes away".
Rob Landley <rob@landley.net>
parents:
diff changeset
242 default: tmp="unknown";
d29edba5582f Quick and dirty port of uClibc's readelf.c to build against glibc as well. Not used at the moment, just "so I have a copy when it goes away".
Rob Landley <rob@landley.net>
parents:
diff changeset
243 }
d29edba5582f Quick and dirty port of uClibc's readelf.c to build against glibc as well. Not used at the moment, just "so I have a copy when it goes away".
Rob Landley <rob@landley.net>
parents:
diff changeset
244 printf( "Machine:\t%s\n", tmp);
d29edba5582f Quick and dirty port of uClibc's readelf.c to build against glibc as well. Not used at the moment, just "so I have a copy when it goes away".
Rob Landley <rob@landley.net>
parents:
diff changeset
245
d29edba5582f Quick and dirty port of uClibc's readelf.c to build against glibc as well. Not used at the moment, just "so I have a copy when it goes away".
Rob Landley <rob@landley.net>
parents:
diff changeset
246 switch (ehdr->e_ident[EI_CLASS]) {
d29edba5582f Quick and dirty port of uClibc's readelf.c to build against glibc as well. Not used at the moment, just "so I have a copy when it goes away".
Rob Landley <rob@landley.net>
parents:
diff changeset
247 case ELFCLASSNONE: tmp = "Invalid class"; break;
d29edba5582f Quick and dirty port of uClibc's readelf.c to build against glibc as well. Not used at the moment, just "so I have a copy when it goes away".
Rob Landley <rob@landley.net>
parents:
diff changeset
248 case ELFCLASS32: tmp = "ELF32"; break;
d29edba5582f Quick and dirty port of uClibc's readelf.c to build against glibc as well. Not used at the moment, just "so I have a copy when it goes away".
Rob Landley <rob@landley.net>
parents:
diff changeset
249 case ELFCLASS64: tmp = "ELF64"; break;
d29edba5582f Quick and dirty port of uClibc's readelf.c to build against glibc as well. Not used at the moment, just "so I have a copy when it goes away".
Rob Landley <rob@landley.net>
parents:
diff changeset
250 default: tmp = "Unknown";
d29edba5582f Quick and dirty port of uClibc's readelf.c to build against glibc as well. Not used at the moment, just "so I have a copy when it goes away".
Rob Landley <rob@landley.net>
parents:
diff changeset
251 }
d29edba5582f Quick and dirty port of uClibc's readelf.c to build against glibc as well. Not used at the moment, just "so I have a copy when it goes away".
Rob Landley <rob@landley.net>
parents:
diff changeset
252 printf( "Class:\t\t%s\n", tmp);
d29edba5582f Quick and dirty port of uClibc's readelf.c to build against glibc as well. Not used at the moment, just "so I have a copy when it goes away".
Rob Landley <rob@landley.net>
parents:
diff changeset
253
d29edba5582f Quick and dirty port of uClibc's readelf.c to build against glibc as well. Not used at the moment, just "so I have a copy when it goes away".
Rob Landley <rob@landley.net>
parents:
diff changeset
254 switch (ehdr->e_ident[EI_DATA]) {
d29edba5582f Quick and dirty port of uClibc's readelf.c to build against glibc as well. Not used at the moment, just "so I have a copy when it goes away".
Rob Landley <rob@landley.net>
parents:
diff changeset
255 case ELFDATANONE: tmp = "Invalid data encoding"; break;
d29edba5582f Quick and dirty port of uClibc's readelf.c to build against glibc as well. Not used at the moment, just "so I have a copy when it goes away".
Rob Landley <rob@landley.net>
parents:
diff changeset
256 case ELFDATA2LSB: tmp = "2's complement, little endian"; break;
d29edba5582f Quick and dirty port of uClibc's readelf.c to build against glibc as well. Not used at the moment, just "so I have a copy when it goes away".
Rob Landley <rob@landley.net>
parents:
diff changeset
257 case ELFDATA2MSB: tmp = "2's complement, big endian"; break;
d29edba5582f Quick and dirty port of uClibc's readelf.c to build against glibc as well. Not used at the moment, just "so I have a copy when it goes away".
Rob Landley <rob@landley.net>
parents:
diff changeset
258 default: tmp = "Unknown";
d29edba5582f Quick and dirty port of uClibc's readelf.c to build against glibc as well. Not used at the moment, just "so I have a copy when it goes away".
Rob Landley <rob@landley.net>
parents:
diff changeset
259 }
d29edba5582f Quick and dirty port of uClibc's readelf.c to build against glibc as well. Not used at the moment, just "so I have a copy when it goes away".
Rob Landley <rob@landley.net>
parents:
diff changeset
260 printf( "Data:\t\t%s\n", tmp);
d29edba5582f Quick and dirty port of uClibc's readelf.c to build against glibc as well. Not used at the moment, just "so I have a copy when it goes away".
Rob Landley <rob@landley.net>
parents:
diff changeset
261
d29edba5582f Quick and dirty port of uClibc's readelf.c to build against glibc as well. Not used at the moment, just "so I have a copy when it goes away".
Rob Landley <rob@landley.net>
parents:
diff changeset
262 printf( "Version:\t%d %s\n", ehdr->e_ident[EI_VERSION],
d29edba5582f Quick and dirty port of uClibc's readelf.c to build against glibc as well. Not used at the moment, just "so I have a copy when it goes away".
Rob Landley <rob@landley.net>
parents:
diff changeset
263 (ehdr->e_ident[EI_VERSION]==EV_CURRENT)?
d29edba5582f Quick and dirty port of uClibc's readelf.c to build against glibc as well. Not used at the moment, just "so I have a copy when it goes away".
Rob Landley <rob@landley.net>
parents:
diff changeset
264 "(current)" : "(unknown: %lx)");
d29edba5582f Quick and dirty port of uClibc's readelf.c to build against glibc as well. Not used at the moment, just "so I have a copy when it goes away".
Rob Landley <rob@landley.net>
parents:
diff changeset
265
d29edba5582f Quick and dirty port of uClibc's readelf.c to build against glibc as well. Not used at the moment, just "so I have a copy when it goes away".
Rob Landley <rob@landley.net>
parents:
diff changeset
266 switch (ehdr->e_ident[EI_OSABI]) {
d29edba5582f Quick and dirty port of uClibc's readelf.c to build against glibc as well. Not used at the moment, just "so I have a copy when it goes away".
Rob Landley <rob@landley.net>
parents:
diff changeset
267 case ELFOSABI_SYSV: tmp ="UNIX - System V"; break;
d29edba5582f Quick and dirty port of uClibc's readelf.c to build against glibc as well. Not used at the moment, just "so I have a copy when it goes away".
Rob Landley <rob@landley.net>
parents:
diff changeset
268 case ELFOSABI_HPUX: tmp ="UNIX - HP-UX"; break;
d29edba5582f Quick and dirty port of uClibc's readelf.c to build against glibc as well. Not used at the moment, just "so I have a copy when it goes away".
Rob Landley <rob@landley.net>
parents:
diff changeset
269 case ELFOSABI_NETBSD: tmp ="UNIX - NetBSD"; break;
d29edba5582f Quick and dirty port of uClibc's readelf.c to build against glibc as well. Not used at the moment, just "so I have a copy when it goes away".
Rob Landley <rob@landley.net>
parents:
diff changeset
270 case ELFOSABI_LINUX: tmp ="UNIX - Linux"; break;
d29edba5582f Quick and dirty port of uClibc's readelf.c to build against glibc as well. Not used at the moment, just "so I have a copy when it goes away".
Rob Landley <rob@landley.net>
parents:
diff changeset
271 // case ELFOSABI_HURD: tmp ="GNU/Hurd"; break;
d29edba5582f Quick and dirty port of uClibc's readelf.c to build against glibc as well. Not used at the moment, just "so I have a copy when it goes away".
Rob Landley <rob@landley.net>
parents:
diff changeset
272 case ELFOSABI_SOLARIS: tmp ="UNIX - Solaris"; break;
d29edba5582f Quick and dirty port of uClibc's readelf.c to build against glibc as well. Not used at the moment, just "so I have a copy when it goes away".
Rob Landley <rob@landley.net>
parents:
diff changeset
273 case ELFOSABI_AIX: tmp ="UNIX - AIX"; break;
d29edba5582f Quick and dirty port of uClibc's readelf.c to build against glibc as well. Not used at the moment, just "so I have a copy when it goes away".
Rob Landley <rob@landley.net>
parents:
diff changeset
274 case ELFOSABI_IRIX: tmp ="UNIX - IRIX"; break;
d29edba5582f Quick and dirty port of uClibc's readelf.c to build against glibc as well. Not used at the moment, just "so I have a copy when it goes away".
Rob Landley <rob@landley.net>
parents:
diff changeset
275 case ELFOSABI_FREEBSD: tmp ="UNIX - FreeBSD"; break;
d29edba5582f Quick and dirty port of uClibc's readelf.c to build against glibc as well. Not used at the moment, just "so I have a copy when it goes away".
Rob Landley <rob@landley.net>
parents:
diff changeset
276 case ELFOSABI_TRU64: tmp ="UNIX - TRU64"; break;
d29edba5582f Quick and dirty port of uClibc's readelf.c to build against glibc as well. Not used at the moment, just "so I have a copy when it goes away".
Rob Landley <rob@landley.net>
parents:
diff changeset
277 case ELFOSABI_MODESTO: tmp ="Novell - Modesto"; break;
d29edba5582f Quick and dirty port of uClibc's readelf.c to build against glibc as well. Not used at the moment, just "so I have a copy when it goes away".
Rob Landley <rob@landley.net>
parents:
diff changeset
278 case ELFOSABI_OPENBSD: tmp ="UNIX - OpenBSD"; break;
d29edba5582f Quick and dirty port of uClibc's readelf.c to build against glibc as well. Not used at the moment, just "so I have a copy when it goes away".
Rob Landley <rob@landley.net>
parents:
diff changeset
279 case ELFOSABI_STANDALONE: tmp ="Standalone App"; break;
d29edba5582f Quick and dirty port of uClibc's readelf.c to build against glibc as well. Not used at the moment, just "so I have a copy when it goes away".
Rob Landley <rob@landley.net>
parents:
diff changeset
280 case ELFOSABI_ARM: tmp ="ARM"; break;
d29edba5582f Quick and dirty port of uClibc's readelf.c to build against glibc as well. Not used at the moment, just "so I have a copy when it goes away".
Rob Landley <rob@landley.net>
parents:
diff changeset
281 default: tmp = "Unknown";
d29edba5582f Quick and dirty port of uClibc's readelf.c to build against glibc as well. Not used at the moment, just "so I have a copy when it goes away".
Rob Landley <rob@landley.net>
parents:
diff changeset
282 }
d29edba5582f Quick and dirty port of uClibc's readelf.c to build against glibc as well. Not used at the moment, just "so I have a copy when it goes away".
Rob Landley <rob@landley.net>
parents:
diff changeset
283 printf( "OS/ABI:\t\t%s\n", tmp);
d29edba5582f Quick and dirty port of uClibc's readelf.c to build against glibc as well. Not used at the moment, just "so I have a copy when it goes away".
Rob Landley <rob@landley.net>
parents:
diff changeset
284
d29edba5582f Quick and dirty port of uClibc's readelf.c to build against glibc as well. Not used at the moment, just "so I have a copy when it goes away".
Rob Landley <rob@landley.net>
parents:
diff changeset
285 printf( "ABI Version:\t%d\n", ehdr->e_ident[EI_ABIVERSION]);
d29edba5582f Quick and dirty port of uClibc's readelf.c to build against glibc as well. Not used at the moment, just "so I have a copy when it goes away".
Rob Landley <rob@landley.net>
parents:
diff changeset
286 }
d29edba5582f Quick and dirty port of uClibc's readelf.c to build against glibc as well. Not used at the moment, just "so I have a copy when it goes away".
Rob Landley <rob@landley.net>
parents:
diff changeset
287
d29edba5582f Quick and dirty port of uClibc's readelf.c to build against glibc as well. Not used at the moment, just "so I have a copy when it goes away".
Rob Landley <rob@landley.net>
parents:
diff changeset
288 static void list_needed_libraries(ElfW(Dyn)* dynamic, char *strtab)
d29edba5582f Quick and dirty port of uClibc's readelf.c to build against glibc as well. Not used at the moment, just "so I have a copy when it goes away".
Rob Landley <rob@landley.net>
parents:
diff changeset
289 {
d29edba5582f Quick and dirty port of uClibc's readelf.c to build against glibc as well. Not used at the moment, just "so I have a copy when it goes away".
Rob Landley <rob@landley.net>
parents:
diff changeset
290 ElfW(Dyn) *dyns;
d29edba5582f Quick and dirty port of uClibc's readelf.c to build against glibc as well. Not used at the moment, just "so I have a copy when it goes away".
Rob Landley <rob@landley.net>
parents:
diff changeset
291
d29edba5582f Quick and dirty port of uClibc's readelf.c to build against glibc as well. Not used at the moment, just "so I have a copy when it goes away".
Rob Landley <rob@landley.net>
parents:
diff changeset
292 printf("Dependancies:\n");
d29edba5582f Quick and dirty port of uClibc's readelf.c to build against glibc as well. Not used at the moment, just "so I have a copy when it goes away".
Rob Landley <rob@landley.net>
parents:
diff changeset
293 for (dyns=dynamic; byteswap_to_host(dyns->d_tag)!=DT_NULL; ++dyns) {
d29edba5582f Quick and dirty port of uClibc's readelf.c to build against glibc as well. Not used at the moment, just "so I have a copy when it goes away".
Rob Landley <rob@landley.net>
parents:
diff changeset
294 if (dyns->d_tag == DT_NEEDED) {
d29edba5582f Quick and dirty port of uClibc's readelf.c to build against glibc as well. Not used at the moment, just "so I have a copy when it goes away".
Rob Landley <rob@landley.net>
parents:
diff changeset
295 printf("\t%s\n", (char*)strtab + byteswap_to_host(dyns->d_un.d_val));
d29edba5582f Quick and dirty port of uClibc's readelf.c to build against glibc as well. Not used at the moment, just "so I have a copy when it goes away".
Rob Landley <rob@landley.net>
parents:
diff changeset
296 }
d29edba5582f Quick and dirty port of uClibc's readelf.c to build against glibc as well. Not used at the moment, just "so I have a copy when it goes away".
Rob Landley <rob@landley.net>
parents:
diff changeset
297 }
d29edba5582f Quick and dirty port of uClibc's readelf.c to build against glibc as well. Not used at the moment, just "so I have a copy when it goes away".
Rob Landley <rob@landley.net>
parents:
diff changeset
298 }
d29edba5582f Quick and dirty port of uClibc's readelf.c to build against glibc as well. Not used at the moment, just "so I have a copy when it goes away".
Rob Landley <rob@landley.net>
parents:
diff changeset
299
d29edba5582f Quick and dirty port of uClibc's readelf.c to build against glibc as well. Not used at the moment, just "so I have a copy when it goes away".
Rob Landley <rob@landley.net>
parents:
diff changeset
300 static void describe_elf_interpreter(ElfW(Ehdr)* ehdr)
d29edba5582f Quick and dirty port of uClibc's readelf.c to build against glibc as well. Not used at the moment, just "so I have a copy when it goes away".
Rob Landley <rob@landley.net>
parents:
diff changeset
301 {
d29edba5582f Quick and dirty port of uClibc's readelf.c to build against glibc as well. Not used at the moment, just "so I have a copy when it goes away".
Rob Landley <rob@landley.net>
parents:
diff changeset
302 ElfW(Phdr) *phdr;
d29edba5582f Quick and dirty port of uClibc's readelf.c to build against glibc as well. Not used at the moment, just "so I have a copy when it goes away".
Rob Landley <rob@landley.net>
parents:
diff changeset
303 phdr = elf_find_phdr_type(PT_INTERP, ehdr);
d29edba5582f Quick and dirty port of uClibc's readelf.c to build against glibc as well. Not used at the moment, just "so I have a copy when it goes away".
Rob Landley <rob@landley.net>
parents:
diff changeset
304 if (phdr) {
d29edba5582f Quick and dirty port of uClibc's readelf.c to build against glibc as well. Not used at the moment, just "so I have a copy when it goes away".
Rob Landley <rob@landley.net>
parents:
diff changeset
305 printf("Interpreter:\t%s\n", (char*)ehdr + byteswap_to_host(phdr->p_offset));
d29edba5582f Quick and dirty port of uClibc's readelf.c to build against glibc as well. Not used at the moment, just "so I have a copy when it goes away".
Rob Landley <rob@landley.net>
parents:
diff changeset
306 }
d29edba5582f Quick and dirty port of uClibc's readelf.c to build against glibc as well. Not used at the moment, just "so I have a copy when it goes away".
Rob Landley <rob@landley.net>
parents:
diff changeset
307 }
d29edba5582f Quick and dirty port of uClibc's readelf.c to build against glibc as well. Not used at the moment, just "so I have a copy when it goes away".
Rob Landley <rob@landley.net>
parents:
diff changeset
308
d29edba5582f Quick and dirty port of uClibc's readelf.c to build against glibc as well. Not used at the moment, just "so I have a copy when it goes away".
Rob Landley <rob@landley.net>
parents:
diff changeset
309 int main( int argc, char** argv)
d29edba5582f Quick and dirty port of uClibc's readelf.c to build against glibc as well. Not used at the moment, just "so I have a copy when it goes away".
Rob Landley <rob@landley.net>
parents:
diff changeset
310 {
d29edba5582f Quick and dirty port of uClibc's readelf.c to build against glibc as well. Not used at the moment, just "so I have a copy when it goes away".
Rob Landley <rob@landley.net>
parents:
diff changeset
311 /* map the .so, and locate interesting pieces */
d29edba5582f Quick and dirty port of uClibc's readelf.c to build against glibc as well. Not used at the moment, just "so I have a copy when it goes away".
Rob Landley <rob@landley.net>
parents:
diff changeset
312 char *dynstr;
d29edba5582f Quick and dirty port of uClibc's readelf.c to build against glibc as well. Not used at the moment, just "so I have a copy when it goes away".
Rob Landley <rob@landley.net>
parents:
diff changeset
313 char *thefilename = argv[1];
d29edba5582f Quick and dirty port of uClibc's readelf.c to build against glibc as well. Not used at the moment, just "so I have a copy when it goes away".
Rob Landley <rob@landley.net>
parents:
diff changeset
314 FILE *thefile;
d29edba5582f Quick and dirty port of uClibc's readelf.c to build against glibc as well. Not used at the moment, just "so I have a copy when it goes away".
Rob Landley <rob@landley.net>
parents:
diff changeset
315 struct stat statbuf;
d29edba5582f Quick and dirty port of uClibc's readelf.c to build against glibc as well. Not used at the moment, just "so I have a copy when it goes away".
Rob Landley <rob@landley.net>
parents:
diff changeset
316 ElfW(Ehdr) *ehdr = 0;
d29edba5582f Quick and dirty port of uClibc's readelf.c to build against glibc as well. Not used at the moment, just "so I have a copy when it goes away".
Rob Landley <rob@landley.net>
parents:
diff changeset
317 ElfW(Shdr) *dynsec;
d29edba5582f Quick and dirty port of uClibc's readelf.c to build against glibc as well. Not used at the moment, just "so I have a copy when it goes away".
Rob Landley <rob@landley.net>
parents:
diff changeset
318 ElfW(Dyn) *dynamic;
d29edba5582f Quick and dirty port of uClibc's readelf.c to build against glibc as well. Not used at the moment, just "so I have a copy when it goes away".
Rob Landley <rob@landley.net>
parents:
diff changeset
319
d29edba5582f Quick and dirty port of uClibc's readelf.c to build against glibc as well. Not used at the moment, just "so I have a copy when it goes away".
Rob Landley <rob@landley.net>
parents:
diff changeset
320 if (!thefilename) {
d29edba5582f Quick and dirty port of uClibc's readelf.c to build against glibc as well. Not used at the moment, just "so I have a copy when it goes away".
Rob Landley <rob@landley.net>
parents:
diff changeset
321 fprintf(stderr, "Usage: readelf FILENAME\n");
d29edba5582f Quick and dirty port of uClibc's readelf.c to build against glibc as well. Not used at the moment, just "so I have a copy when it goes away".
Rob Landley <rob@landley.net>
parents:
diff changeset
322 exit(1);
d29edba5582f Quick and dirty port of uClibc's readelf.c to build against glibc as well. Not used at the moment, just "so I have a copy when it goes away".
Rob Landley <rob@landley.net>
parents:
diff changeset
323 }
d29edba5582f Quick and dirty port of uClibc's readelf.c to build against glibc as well. Not used at the moment, just "so I have a copy when it goes away".
Rob Landley <rob@landley.net>
parents:
diff changeset
324 if (!(thefile = fopen(thefilename, "r"))) {
d29edba5582f Quick and dirty port of uClibc's readelf.c to build against glibc as well. Not used at the moment, just "so I have a copy when it goes away".
Rob Landley <rob@landley.net>
parents:
diff changeset
325 perror(thefilename);
d29edba5582f Quick and dirty port of uClibc's readelf.c to build against glibc as well. Not used at the moment, just "so I have a copy when it goes away".
Rob Landley <rob@landley.net>
parents:
diff changeset
326 exit(1);
d29edba5582f Quick and dirty port of uClibc's readelf.c to build against glibc as well. Not used at the moment, just "so I have a copy when it goes away".
Rob Landley <rob@landley.net>
parents:
diff changeset
327 }
d29edba5582f Quick and dirty port of uClibc's readelf.c to build against glibc as well. Not used at the moment, just "so I have a copy when it goes away".
Rob Landley <rob@landley.net>
parents:
diff changeset
328 if (fstat(fileno(thefile), &statbuf) < 0) {
d29edba5582f Quick and dirty port of uClibc's readelf.c to build against glibc as well. Not used at the moment, just "so I have a copy when it goes away".
Rob Landley <rob@landley.net>
parents:
diff changeset
329 perror(thefilename);
d29edba5582f Quick and dirty port of uClibc's readelf.c to build against glibc as well. Not used at the moment, just "so I have a copy when it goes away".
Rob Landley <rob@landley.net>
parents:
diff changeset
330 exit(EXIT_FAILURE);
d29edba5582f Quick and dirty port of uClibc's readelf.c to build against glibc as well. Not used at the moment, just "so I have a copy when it goes away".
Rob Landley <rob@landley.net>
parents:
diff changeset
331 }
d29edba5582f Quick and dirty port of uClibc's readelf.c to build against glibc as well. Not used at the moment, just "so I have a copy when it goes away".
Rob Landley <rob@landley.net>
parents:
diff changeset
332
d29edba5582f Quick and dirty port of uClibc's readelf.c to build against glibc as well. Not used at the moment, just "so I have a copy when it goes away".
Rob Landley <rob@landley.net>
parents:
diff changeset
333 if ((size_t)statbuf.st_size < sizeof(ElfW(Ehdr)))
d29edba5582f Quick and dirty port of uClibc's readelf.c to build against glibc as well. Not used at the moment, just "so I have a copy when it goes away".
Rob Landley <rob@landley.net>
parents:
diff changeset
334 goto foo;
d29edba5582f Quick and dirty port of uClibc's readelf.c to build against glibc as well. Not used at the moment, just "so I have a copy when it goes away".
Rob Landley <rob@landley.net>
parents:
diff changeset
335
d29edba5582f Quick and dirty port of uClibc's readelf.c to build against glibc as well. Not used at the moment, just "so I have a copy when it goes away".
Rob Landley <rob@landley.net>
parents:
diff changeset
336 /* mmap the file to make reading stuff from it effortless */
d29edba5582f Quick and dirty port of uClibc's readelf.c to build against glibc as well. Not used at the moment, just "so I have a copy when it goes away".
Rob Landley <rob@landley.net>
parents:
diff changeset
337 ehdr = (ElfW(Ehdr) *)mmap(0, statbuf.st_size,
d29edba5582f Quick and dirty port of uClibc's readelf.c to build against glibc as well. Not used at the moment, just "so I have a copy when it goes away".
Rob Landley <rob@landley.net>
parents:
diff changeset
338 PROT_READ|PROT_WRITE, MAP_PRIVATE, fileno(thefile), 0);
d29edba5582f Quick and dirty port of uClibc's readelf.c to build against glibc as well. Not used at the moment, just "so I have a copy when it goes away".
Rob Landley <rob@landley.net>
parents:
diff changeset
339
d29edba5582f Quick and dirty port of uClibc's readelf.c to build against glibc as well. Not used at the moment, just "so I have a copy when it goes away".
Rob Landley <rob@landley.net>
parents:
diff changeset
340 foo:
d29edba5582f Quick and dirty port of uClibc's readelf.c to build against glibc as well. Not used at the moment, just "so I have a copy when it goes away".
Rob Landley <rob@landley.net>
parents:
diff changeset
341 /* Check if this looks legit */
d29edba5582f Quick and dirty port of uClibc's readelf.c to build against glibc as well. Not used at the moment, just "so I have a copy when it goes away".
Rob Landley <rob@landley.net>
parents:
diff changeset
342 if (check_elf_header(ehdr)) {
d29edba5582f Quick and dirty port of uClibc's readelf.c to build against glibc as well. Not used at the moment, just "so I have a copy when it goes away".
Rob Landley <rob@landley.net>
parents:
diff changeset
343 fprintf(stderr, "This does not appear to be an ELF file.\n");
d29edba5582f Quick and dirty port of uClibc's readelf.c to build against glibc as well. Not used at the moment, just "so I have a copy when it goes away".
Rob Landley <rob@landley.net>
parents:
diff changeset
344 exit(EXIT_FAILURE);
d29edba5582f Quick and dirty port of uClibc's readelf.c to build against glibc as well. Not used at the moment, just "so I have a copy when it goes away".
Rob Landley <rob@landley.net>
parents:
diff changeset
345 }
d29edba5582f Quick and dirty port of uClibc's readelf.c to build against glibc as well. Not used at the moment, just "so I have a copy when it goes away".
Rob Landley <rob@landley.net>
parents:
diff changeset
346 describe_elf_hdr(ehdr);
d29edba5582f Quick and dirty port of uClibc's readelf.c to build against glibc as well. Not used at the moment, just "so I have a copy when it goes away".
Rob Landley <rob@landley.net>
parents:
diff changeset
347 describe_elf_interpreter(ehdr);
d29edba5582f Quick and dirty port of uClibc's readelf.c to build against glibc as well. Not used at the moment, just "so I have a copy when it goes away".
Rob Landley <rob@landley.net>
parents:
diff changeset
348
d29edba5582f Quick and dirty port of uClibc's readelf.c to build against glibc as well. Not used at the moment, just "so I have a copy when it goes away".
Rob Landley <rob@landley.net>
parents:
diff changeset
349 dynsec = elf_find_section_type(SHT_DYNAMIC, ehdr);
d29edba5582f Quick and dirty port of uClibc's readelf.c to build against glibc as well. Not used at the moment, just "so I have a copy when it goes away".
Rob Landley <rob@landley.net>
parents:
diff changeset
350 if (dynsec) {
d29edba5582f Quick and dirty port of uClibc's readelf.c to build against glibc as well. Not used at the moment, just "so I have a copy when it goes away".
Rob Landley <rob@landley.net>
parents:
diff changeset
351 dynamic = (ElfW(Dyn)*)(byteswap_to_host(dynsec->sh_offset) + (char *)ehdr);
d29edba5582f Quick and dirty port of uClibc's readelf.c to build against glibc as well. Not used at the moment, just "so I have a copy when it goes away".
Rob Landley <rob@landley.net>
parents:
diff changeset
352 dynstr = (char *)elf_find_dynamic(DT_STRTAB, dynamic, ehdr, 0);
d29edba5582f Quick and dirty port of uClibc's readelf.c to build against glibc as well. Not used at the moment, just "so I have a copy when it goes away".
Rob Landley <rob@landley.net>
parents:
diff changeset
353 list_needed_libraries(dynamic, dynstr);
d29edba5582f Quick and dirty port of uClibc's readelf.c to build against glibc as well. Not used at the moment, just "so I have a copy when it goes away".
Rob Landley <rob@landley.net>
parents:
diff changeset
354 }
d29edba5582f Quick and dirty port of uClibc's readelf.c to build against glibc as well. Not used at the moment, just "so I have a copy when it goes away".
Rob Landley <rob@landley.net>
parents:
diff changeset
355
d29edba5582f Quick and dirty port of uClibc's readelf.c to build against glibc as well. Not used at the moment, just "so I have a copy when it goes away".
Rob Landley <rob@landley.net>
parents:
diff changeset
356 return 0;
d29edba5582f Quick and dirty port of uClibc's readelf.c to build against glibc as well. Not used at the moment, just "so I have a copy when it goes away".
Rob Landley <rob@landley.net>
parents:
diff changeset
357 }