1 /* readelf.c -- display contents of an ELF format file
2 Copyright 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005
3 Free Software Foundation, Inc.
5 Originally developed by Eric Youngdale <eric@andante.jic.com>
6 Modifications by Nick Clifton <nickc@redhat.com>
8 This file is part of GNU Binutils.
10 This program is free software; you can redistribute it and/or modify
11 it under the terms of the GNU General Public License as published by
12 the Free Software Foundation; either version 2 of the License, or
13 (at your option) any later version.
15 This program is distributed in the hope that it will be useful,
16 but WITHOUT ANY WARRANTY; without even the implied warranty of
17 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 GNU General Public License for more details.
20 You should have received a copy of the GNU General Public License
21 along with this program; if not, write to the Free Software
22 Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA
25 /* The difference between readelf and objdump:
27 Both programs are capable of displaying the contents of ELF format files,
28 so why does the binutils project have two file dumpers ?
30 The reason is that objdump sees an ELF file through a BFD filter of the
31 world; if BFD has a bug where, say, it disagrees about a machine constant
32 in e_flags, then the odds are good that it will remain internally
33 consistent. The linker sees it the BFD way, objdump sees it the BFD way,
34 GAS sees it the BFD way. There was need for a tool to go find out what
35 the file actually says.
37 This is why the readelf program does not link against the BFD library - it
38 exists as an independent program to help verify the correct working of BFD.
40 There is also the case that readelf can provide more information about an
41 ELF file than is provided by objdump. In particular it can display DWARF
42 debugging information which (at the moment) objdump cannot. */
45 #include <sys/types.h>
51 /* Define BFD64 here, even if our default architecture is 32 bit ELF
52 as this will allow us to read in and parse 64bit and 32bit ELF files.
53 Only do this if we believe that the compiler can support a 64 bit
54 data type. For now we only rely on GCC being able to do this. */
60 #include "elf/common.h"
61 #include "elf/external.h"
62 #include "elf/internal.h"
64 /* The following headers use the elf/reloc-macros.h file to
65 automatically generate relocation recognition functions
66 such as elf_mips_reloc_type() */
68 #define RELOC_MACROS_GEN_FUNC
70 #include "elf/alpha.h"
91 #include "elf/m68hc11.h"
92 #include "elf/mcore.h"
95 #include "elf/mn10200.h"
96 #include "elf/mn10300.h"
98 #include "elf/msp430.h"
102 #include "elf/ppc64.h"
103 #include "elf/s390.h"
105 #include "elf/sparc.h"
106 #include "elf/v850.h"
108 #include "elf/x86-64.h"
109 #include "elf/xstormy16.h"
111 #include "elf/iq2000.h"
112 #include "elf/xtensa.h"
118 #include "libiberty.h"
120 char *program_name = "readelf";
121 static long archive_file_offset;
122 static unsigned long archive_file_size;
123 static unsigned long dynamic_addr;
124 static bfd_size_type dynamic_size;
125 static unsigned int dynamic_nent;
126 static char *dynamic_strings;
127 static unsigned long dynamic_strings_length;
128 static char *string_table;
129 static unsigned long string_table_length;
130 static unsigned long num_dynamic_syms;
131 static Elf_Internal_Sym *dynamic_symbols;
132 static Elf_Internal_Syminfo *dynamic_syminfo;
133 static unsigned long dynamic_syminfo_offset;
134 static unsigned int dynamic_syminfo_nent;
135 static char program_interpreter[64];
136 static bfd_vma dynamic_info[DT_JMPREL + 1];
137 static bfd_vma version_info[16];
138 static Elf_Internal_Ehdr elf_header;
139 static Elf_Internal_Shdr *section_headers;
140 static Elf_Internal_Phdr *program_headers;
141 static Elf_Internal_Dyn *dynamic_section;
142 static Elf_Internal_Shdr *symtab_shndx_hdr;
143 static int show_name;
144 static int do_dynamic;
147 static int do_sections;
148 static int do_section_groups;
149 static int do_section_details;
150 static int do_segments;
151 static int do_unwind;
152 static int do_using_dynamic;
153 static int do_header;
155 static int do_version;
157 static int do_histogram;
158 static int do_debugging;
161 static int is_32bit_elf;
165 struct group_list *next;
166 unsigned int section_index;
171 struct group_list *root;
172 unsigned int group_index;
175 static size_t group_count;
176 static struct group *section_groups;
177 static struct group **section_headers_groups;
179 /* A dynamic array of flags indicating for which sections a hex dump
180 has been requested (via the -x switch) and/or a disassembly dump
181 (via the -i switch). */
182 char *cmdline_dump_sects = NULL;
183 unsigned num_cmdline_dump_sects = 0;
185 /* A dynamic array of flags indicating for which sections a dump of
186 some kind has been requested. It is reset on a per-object file
187 basis and then initialised from the cmdline_dump_sects array and
188 the results of interpreting the -w switch. */
189 char *dump_sects = NULL;
190 unsigned int num_dump_sects = 0;
192 #define HEX_DUMP (1 << 0)
193 #define DISASS_DUMP (1 << 1)
194 #define DEBUG_DUMP (1 << 2)
196 /* How to print a vma value. */
197 typedef enum print_mode
209 static void (*byte_put) (unsigned char *, bfd_vma, int);
213 #define SECTION_NAME(X) ((X) == NULL ? "<none>" : \
214 ((X)->sh_name >= string_table_length \
215 ? "<corrupt>" : string_table + (X)->sh_name))
217 /* Given st_shndx I, map to section_headers index. */
218 #define SECTION_HEADER_INDEX(I) \
219 ((I) < SHN_LORESERVE \
221 : ((I) <= SHN_HIRESERVE \
223 : (I) - (SHN_HIRESERVE + 1 - SHN_LORESERVE)))
225 /* Reverse of the above. */
226 #define SECTION_HEADER_NUM(N) \
227 ((N) < SHN_LORESERVE \
229 : (N) + (SHN_HIRESERVE + 1 - SHN_LORESERVE))
231 #define SECTION_HEADER(I) (section_headers + SECTION_HEADER_INDEX (I))
233 #define DT_VERSIONTAGIDX(tag) (DT_VERNEEDNUM - (tag)) /* Reverse order! */
235 #define BYTE_GET(field) byte_get (field, sizeof (field))
237 #define NUM_ELEM(array) (sizeof (array) / sizeof ((array)[0]))
239 #define GET_ELF_SYMBOLS(file, section) \
240 (is_32bit_elf ? get_32bit_elf_symbols (file, section) \
241 : get_64bit_elf_symbols (file, section))
243 #define VALID_DYNAMIC_NAME(offset) ((dynamic_strings != NULL) && (offset < dynamic_strings_length))
244 /* GET_DYNAMIC_NAME asssumes that VALID_DYNAMIC_NAME has
245 already been called and verified that the string exists. */
246 #define GET_DYNAMIC_NAME(offset) (dynamic_strings + offset)
248 /* This is just a bit of syntatic sugar. */
249 #define streq(a,b) (strcmp ((a), (b)) == 0)
250 #define strneq(a,b,n) (strncmp ((a), (b), (n)) == 0)
253 get_data (void *var, FILE *file, long offset, size_t size, size_t nmemb,
258 if (size == 0 || nmemb == 0)
261 if (fseek (file, archive_file_offset + offset, SEEK_SET))
263 error (_("Unable to seek to 0x%lx for %s\n"),
264 archive_file_offset + offset, reason);
271 /* Check for overflow. */
272 if (nmemb < (~(size_t) 0 - 1) / size)
273 /* + 1 so that we can '\0' terminate invalid string table sections. */
274 mvar = malloc (size * nmemb + 1);
278 error (_("Out of memory allocating 0x%lx bytes for %s\n"),
279 (unsigned long)(size * nmemb), reason);
283 ((char *) mvar)[size * nmemb] = '\0';
286 if (fread (mvar, size, nmemb, file) != nmemb)
288 error (_("Unable to read in 0x%lx bytes of %s\n"),
289 (unsigned long)(size * nmemb), reason);
299 byte_put_little_endian (unsigned char *field, bfd_vma value, int size)
304 field[7] = (((value >> 24) >> 24) >> 8) & 0xff;
305 field[6] = ((value >> 24) >> 24) & 0xff;
306 field[5] = ((value >> 24) >> 16) & 0xff;
307 field[4] = ((value >> 24) >> 8) & 0xff;
310 field[3] = (value >> 24) & 0xff;
311 field[2] = (value >> 16) & 0xff;
314 field[1] = (value >> 8) & 0xff;
317 field[0] = value & 0xff;
321 error (_("Unhandled data length: %d\n"), size);
326 #if defined BFD64 && !BFD_HOST_64BIT_LONG
328 print_dec_vma (bfd_vma vma, int is_signed)
334 if (is_signed && (bfd_signed_vma) vma < 0)
343 *bufp++ = '0' + vma % 10;
355 print_hex_vma (bfd_vma vma)
363 char digit = '0' + (vma & 0x0f);
365 digit += 'a' - '0' - 10;
378 /* Print a VMA value. */
380 print_vma (bfd_vma vma, print_mode mode)
389 return printf ("0x%8.8lx", (unsigned long) vma);
392 return printf ("%8.8lx", (unsigned long) vma);
396 return printf ("%5ld", (long) vma);
400 return printf ("0x%lx", (unsigned long) vma);
403 return printf ("%lx", (unsigned long) vma);
406 return printf ("%ld", (unsigned long) vma);
409 return printf ("%lu", (unsigned long) vma);
432 #if BFD_HOST_64BIT_LONG
433 return nc + printf ("%lx", vma);
435 return nc + print_hex_vma (vma);
439 #if BFD_HOST_64BIT_LONG
440 return printf ("%ld", vma);
442 return print_dec_vma (vma, 1);
446 #if BFD_HOST_64BIT_LONG
448 return printf ("%5ld", vma);
450 return printf ("%#lx", vma);
453 return printf ("%5ld", _bfd_int64_low (vma));
455 return print_hex_vma (vma);
459 #if BFD_HOST_64BIT_LONG
460 return printf ("%lu", vma);
462 return print_dec_vma (vma, 0);
470 /* Display a symbol on stdout. If do_wide is not true then
471 format the symbol to be at most WIDTH characters,
472 truncating as necessary. If WIDTH is negative then
473 format the string to be exactly - WIDTH characters,
474 truncating or padding as necessary. */
477 print_symbol (int width, const char *symbol)
480 printf ("%s", symbol);
482 printf ("%-*.*s", width, width, symbol);
484 printf ("%-.*s", width, symbol);
488 byte_put_big_endian (unsigned char *field, bfd_vma value, int size)
493 field[7] = value & 0xff;
494 field[6] = (value >> 8) & 0xff;
495 field[5] = (value >> 16) & 0xff;
496 field[4] = (value >> 24) & 0xff;
501 field[3] = value & 0xff;
502 field[2] = (value >> 8) & 0xff;
506 field[1] = value & 0xff;
510 field[0] = value & 0xff;
514 error (_("Unhandled data length: %d\n"), size);
519 /* Return a pointer to section NAME, or NULL if no such section exists. */
521 static Elf_Internal_Shdr *
522 find_section (const char *name)
526 for (i = 0; i < elf_header.e_shnum; i++)
527 if (streq (SECTION_NAME (section_headers + i), name))
528 return section_headers + i;
533 /* Guess the relocation size commonly used by the specific machines. */
536 guess_is_rela (unsigned long e_machine)
540 /* Targets that use REL relocations. */
555 /* Targets that use RELA relocations. */
570 case EM_CYGNUS_MN10200:
572 case EM_CYGNUS_MN10300:
621 warn (_("Don't know about relocations on this machine architecture\n"));
627 slurp_rela_relocs (FILE *file,
628 unsigned long rel_offset,
629 unsigned long rel_size,
630 Elf_Internal_Rela **relasp,
631 unsigned long *nrelasp)
633 Elf_Internal_Rela *relas;
634 unsigned long nrelas;
639 Elf32_External_Rela *erelas;
641 erelas = get_data (NULL, file, rel_offset, 1, rel_size, _("relocs"));
645 nrelas = rel_size / sizeof (Elf32_External_Rela);
647 relas = cmalloc (nrelas, sizeof (Elf_Internal_Rela));
652 error (_("out of memory parsing relocs"));
656 for (i = 0; i < nrelas; i++)
658 relas[i].r_offset = BYTE_GET (erelas[i].r_offset);
659 relas[i].r_info = BYTE_GET (erelas[i].r_info);
660 relas[i].r_addend = BYTE_GET (erelas[i].r_addend);
667 Elf64_External_Rela *erelas;
669 erelas = get_data (NULL, file, rel_offset, 1, rel_size, _("relocs"));
673 nrelas = rel_size / sizeof (Elf64_External_Rela);
675 relas = cmalloc (nrelas, sizeof (Elf_Internal_Rela));
680 error (_("out of memory parsing relocs"));
684 for (i = 0; i < nrelas; i++)
686 relas[i].r_offset = BYTE_GET (erelas[i].r_offset);
687 relas[i].r_info = BYTE_GET (erelas[i].r_info);
688 relas[i].r_addend = BYTE_GET (erelas[i].r_addend);
699 slurp_rel_relocs (FILE *file,
700 unsigned long rel_offset,
701 unsigned long rel_size,
702 Elf_Internal_Rela **relsp,
703 unsigned long *nrelsp)
705 Elf_Internal_Rela *rels;
711 Elf32_External_Rel *erels;
713 erels = get_data (NULL, file, rel_offset, 1, rel_size, _("relocs"));
717 nrels = rel_size / sizeof (Elf32_External_Rel);
719 rels = cmalloc (nrels, sizeof (Elf_Internal_Rela));
724 error (_("out of memory parsing relocs"));
728 for (i = 0; i < nrels; i++)
730 rels[i].r_offset = BYTE_GET (erels[i].r_offset);
731 rels[i].r_info = BYTE_GET (erels[i].r_info);
732 rels[i].r_addend = 0;
739 Elf64_External_Rel *erels;
741 erels = get_data (NULL, file, rel_offset, 1, rel_size, _("relocs"));
745 nrels = rel_size / sizeof (Elf64_External_Rel);
747 rels = cmalloc (nrels, sizeof (Elf_Internal_Rela));
752 error (_("out of memory parsing relocs"));
756 for (i = 0; i < nrels; i++)
758 rels[i].r_offset = BYTE_GET (erels[i].r_offset);
759 rels[i].r_info = BYTE_GET (erels[i].r_info);
760 rels[i].r_addend = 0;
770 /* Display the contents of the relocation data found at the specified
774 dump_relocations (FILE *file,
775 unsigned long rel_offset,
776 unsigned long rel_size,
777 Elf_Internal_Sym *symtab,
780 unsigned long strtablen,
784 Elf_Internal_Rela *rels;
787 if (is_rela == UNKNOWN)
788 is_rela = guess_is_rela (elf_header.e_machine);
792 if (!slurp_rela_relocs (file, rel_offset, rel_size, &rels, &rel_size))
797 if (!slurp_rel_relocs (file, rel_offset, rel_size, &rels, &rel_size))
806 printf (_(" Offset Info Type Sym. Value Symbol's Name + Addend\n"));
808 printf (_(" Offset Info Type Sym.Value Sym. Name + Addend\n"));
813 printf (_(" Offset Info Type Sym. Value Symbol's Name\n"));
815 printf (_(" Offset Info Type Sym.Value Sym. Name\n"));
823 printf (_(" Offset Info Type Symbol's Value Symbol's Name + Addend\n"));
825 printf (_(" Offset Info Type Sym. Value Sym. Name + Addend\n"));
830 printf (_(" Offset Info Type Symbol's Value Symbol's Name\n"));
832 printf (_(" Offset Info Type Sym. Value Sym. Name\n"));
836 for (i = 0; i < rel_size; i++)
839 const char *rtype2 = NULL;
840 const char *rtype3 = NULL;
843 bfd_vma symtab_index;
848 offset = rels[i].r_offset;
849 info = rels[i].r_info;
853 type = ELF32_R_TYPE (info);
854 symtab_index = ELF32_R_SYM (info);
858 /* The #ifdef BFD64 below is to prevent a compile time warning.
859 We know that if we do not have a 64 bit data type that we
860 will never execute this code anyway. */
862 if (elf_header.e_machine == EM_MIPS)
864 /* In little-endian objects, r_info isn't really a 64-bit
865 little-endian value: it has a 32-bit little-endian
866 symbol index followed by four individual byte fields.
867 Reorder INFO accordingly. */
868 if (elf_header.e_ident[EI_DATA] != ELFDATA2MSB)
869 info = (((info & 0xffffffff) << 32)
870 | ((info >> 56) & 0xff)
871 | ((info >> 40) & 0xff00)
872 | ((info >> 24) & 0xff0000)
873 | ((info >> 8) & 0xff000000));
874 type = ELF64_MIPS_R_TYPE (info);
875 type2 = ELF64_MIPS_R_TYPE2 (info);
876 type3 = ELF64_MIPS_R_TYPE3 (info);
878 else if (elf_header.e_machine == EM_SPARCV9)
879 type = ELF64_R_TYPE_ID (info);
881 type = ELF64_R_TYPE (info);
883 symtab_index = ELF64_R_SYM (info);
889 #ifdef _bfd_int64_low
890 printf ("%8.8lx %8.8lx ", _bfd_int64_low (offset), _bfd_int64_low (info));
892 printf ("%8.8lx %8.8lx ", offset, info);
897 #ifdef _bfd_int64_low
899 ? "%8.8lx%8.8lx %8.8lx%8.8lx "
900 : "%4.4lx%8.8lx %4.4lx%8.8lx ",
901 _bfd_int64_high (offset),
902 _bfd_int64_low (offset),
903 _bfd_int64_high (info),
904 _bfd_int64_low (info));
907 ? "%16.16lx %16.16lx "
908 : "%12.12lx %12.12lx ",
913 switch (elf_header.e_machine)
921 rtype = elf_m32r_reloc_type (type);
926 rtype = elf_i386_reloc_type (type);
931 rtype = elf_m68hc11_reloc_type (type);
935 rtype = elf_m68k_reloc_type (type);
939 rtype = elf_i960_reloc_type (type);
944 rtype = elf_avr_reloc_type (type);
951 rtype = elf_sparc_reloc_type (type);
956 rtype = v850_reloc_type (type);
961 rtype = elf_d10v_reloc_type (type);
966 rtype = elf_d30v_reloc_type (type);
970 rtype = elf_dlx_reloc_type (type);
974 rtype = elf_sh_reloc_type (type);
978 case EM_CYGNUS_MN10300:
979 rtype = elf_mn10300_reloc_type (type);
983 case EM_CYGNUS_MN10200:
984 rtype = elf_mn10200_reloc_type (type);
989 rtype = elf_fr30_reloc_type (type);
993 rtype = elf_frv_reloc_type (type);
997 rtype = elf_mcore_reloc_type (type);
1001 rtype = elf_mmix_reloc_type (type);
1006 rtype = elf_msp430_reloc_type (type);
1010 rtype = elf_ppc_reloc_type (type);
1014 rtype = elf_ppc64_reloc_type (type);
1018 case EM_MIPS_RS3_LE:
1019 rtype = elf_mips_reloc_type (type);
1022 rtype2 = elf_mips_reloc_type (type2);
1023 rtype3 = elf_mips_reloc_type (type3);
1028 rtype = elf_alpha_reloc_type (type);
1032 rtype = elf_arm_reloc_type (type);
1036 rtype = elf_arc_reloc_type (type);
1040 rtype = elf_hppa_reloc_type (type);
1046 rtype = elf_h8_reloc_type (type);
1051 rtype = elf_or32_reloc_type (type);
1056 rtype = elf_pj_reloc_type (type);
1059 rtype = elf_ia64_reloc_type (type);
1063 rtype = elf_cris_reloc_type (type);
1067 rtype = elf_i860_reloc_type (type);
1071 rtype = elf_x86_64_reloc_type (type);
1075 rtype = i370_reloc_type (type);
1080 rtype = elf_s390_reloc_type (type);
1084 rtype = elf_xstormy16_reloc_type (type);
1088 rtype = elf_crx_reloc_type (type);
1092 rtype = elf_vax_reloc_type (type);
1097 rtype = elf_ip2k_reloc_type (type);
1101 rtype = elf_iq2000_reloc_type (type);
1106 rtype = elf_xtensa_reloc_type (type);
1110 rtype = elf_m32c_reloc_type (type);
1114 rtype = elf_ms1_reloc_type (type);
1119 #ifdef _bfd_int64_low
1120 printf (_("unrecognized: %-7lx"), _bfd_int64_low (type));
1122 printf (_("unrecognized: %-7lx"), type);
1125 printf (do_wide ? "%-22.22s" : "%-17.17s", rtype);
1127 if (elf_header.e_machine == EM_ALPHA
1128 && streq (rtype, "R_ALPHA_LITUSE")
1131 switch (rels[i].r_addend)
1133 case LITUSE_ALPHA_ADDR: rtype = "ADDR"; break;
1134 case LITUSE_ALPHA_BASE: rtype = "BASE"; break;
1135 case LITUSE_ALPHA_BYTOFF: rtype = "BYTOFF"; break;
1136 case LITUSE_ALPHA_JSR: rtype = "JSR"; break;
1137 case LITUSE_ALPHA_TLSGD: rtype = "TLSGD"; break;
1138 case LITUSE_ALPHA_TLSLDM: rtype = "TLSLDM"; break;
1139 case LITUSE_ALPHA_JSRDIRECT: rtype = "JSRDIRECT"; break;
1140 default: rtype = NULL;
1143 printf (" (%s)", rtype);
1147 printf (_("<unknown addend: %lx>"),
1148 (unsigned long) rels[i].r_addend);
1151 else if (symtab_index)
1153 if (symtab == NULL || symtab_index >= nsyms)
1154 printf (" bad symbol index: %08lx", (unsigned long) symtab_index);
1157 Elf_Internal_Sym *psym;
1159 psym = symtab + symtab_index;
1162 print_vma (psym->st_value, LONG_HEX);
1163 printf (is_32bit_elf ? " " : " ");
1165 if (psym->st_name == 0)
1167 const char *sec_name = "<null>";
1170 if (ELF_ST_TYPE (psym->st_info) == STT_SECTION)
1172 bfd_vma sec_index = (bfd_vma) -1;
1174 if (psym->st_shndx < SHN_LORESERVE)
1175 sec_index = psym->st_shndx;
1176 else if (psym->st_shndx > SHN_HIRESERVE)
1177 sec_index = psym->st_shndx - (SHN_HIRESERVE + 1
1180 if (sec_index != (bfd_vma) -1)
1181 sec_name = SECTION_NAME (section_headers + sec_index);
1182 else if (psym->st_shndx == SHN_ABS)
1184 else if (psym->st_shndx == SHN_COMMON)
1185 sec_name = "COMMON";
1186 else if (elf_header.e_machine == EM_X86_64
1187 && psym->st_shndx == SHN_X86_64_LCOMMON)
1188 sec_name = "LARGE_COMMON";
1189 else if (elf_header.e_machine == EM_IA_64
1190 && elf_header.e_ident[EI_OSABI] == ELFOSABI_HPUX
1191 && psym->st_shndx == SHN_IA_64_ANSI_COMMON)
1192 sec_name = "ANSI_COM";
1195 sprintf (name_buf, "<section 0x%x>",
1196 (unsigned int) psym->st_shndx);
1197 sec_name = name_buf;
1200 print_symbol (22, sec_name);
1202 else if (strtab == NULL)
1203 printf (_("<string table index: %3ld>"), psym->st_name);
1204 else if (psym->st_name >= strtablen)
1205 printf (_("<corrupt string table index: %3ld>"), psym->st_name);
1207 print_symbol (22, strtab + psym->st_name);
1210 printf (" + %lx", (unsigned long) rels[i].r_addend);
1215 printf ("%*c", is_32bit_elf ?
1216 (do_wide ? 34 : 28) : (do_wide ? 26 : 20), ' ');
1217 print_vma (rels[i].r_addend, LONG_HEX);
1220 if (elf_header.e_machine == EM_SPARCV9 && streq (rtype, "R_SPARC_OLO10"))
1221 printf (" + %lx", (unsigned long) ELF64_R_TYPE_DATA (info));
1225 if (! is_32bit_elf && elf_header.e_machine == EM_MIPS)
1227 printf (" Type2: ");
1230 #ifdef _bfd_int64_low
1231 printf (_("unrecognized: %-7lx"), _bfd_int64_low (type2));
1233 printf (_("unrecognized: %-7lx"), type2);
1236 printf ("%-17.17s", rtype2);
1238 printf ("\n Type3: ");
1241 #ifdef _bfd_int64_low
1242 printf (_("unrecognized: %-7lx"), _bfd_int64_low (type3));
1244 printf (_("unrecognized: %-7lx"), type3);
1247 printf ("%-17.17s", rtype3);
1259 get_mips_dynamic_type (unsigned long type)
1263 case DT_MIPS_RLD_VERSION: return "MIPS_RLD_VERSION";
1264 case DT_MIPS_TIME_STAMP: return "MIPS_TIME_STAMP";
1265 case DT_MIPS_ICHECKSUM: return "MIPS_ICHECKSUM";
1266 case DT_MIPS_IVERSION: return "MIPS_IVERSION";
1267 case DT_MIPS_FLAGS: return "MIPS_FLAGS";
1268 case DT_MIPS_BASE_ADDRESS: return "MIPS_BASE_ADDRESS";
1269 case DT_MIPS_MSYM: return "MIPS_MSYM";
1270 case DT_MIPS_CONFLICT: return "MIPS_CONFLICT";
1271 case DT_MIPS_LIBLIST: return "MIPS_LIBLIST";
1272 case DT_MIPS_LOCAL_GOTNO: return "MIPS_LOCAL_GOTNO";
1273 case DT_MIPS_CONFLICTNO: return "MIPS_CONFLICTNO";
1274 case DT_MIPS_LIBLISTNO: return "MIPS_LIBLISTNO";
1275 case DT_MIPS_SYMTABNO: return "MIPS_SYMTABNO";
1276 case DT_MIPS_UNREFEXTNO: return "MIPS_UNREFEXTNO";
1277 case DT_MIPS_GOTSYM: return "MIPS_GOTSYM";
1278 case DT_MIPS_HIPAGENO: return "MIPS_HIPAGENO";
1279 case DT_MIPS_RLD_MAP: return "MIPS_RLD_MAP";
1280 case DT_MIPS_DELTA_CLASS: return "MIPS_DELTA_CLASS";
1281 case DT_MIPS_DELTA_CLASS_NO: return "MIPS_DELTA_CLASS_NO";
1282 case DT_MIPS_DELTA_INSTANCE: return "MIPS_DELTA_INSTANCE";
1283 case DT_MIPS_DELTA_INSTANCE_NO: return "MIPS_DELTA_INSTANCE_NO";
1284 case DT_MIPS_DELTA_RELOC: return "MIPS_DELTA_RELOC";
1285 case DT_MIPS_DELTA_RELOC_NO: return "MIPS_DELTA_RELOC_NO";
1286 case DT_MIPS_DELTA_SYM: return "MIPS_DELTA_SYM";
1287 case DT_MIPS_DELTA_SYM_NO: return "MIPS_DELTA_SYM_NO";
1288 case DT_MIPS_DELTA_CLASSSYM: return "MIPS_DELTA_CLASSSYM";
1289 case DT_MIPS_DELTA_CLASSSYM_NO: return "MIPS_DELTA_CLASSSYM_NO";
1290 case DT_MIPS_CXX_FLAGS: return "MIPS_CXX_FLAGS";
1291 case DT_MIPS_PIXIE_INIT: return "MIPS_PIXIE_INIT";
1292 case DT_MIPS_SYMBOL_LIB: return "MIPS_SYMBOL_LIB";
1293 case DT_MIPS_LOCALPAGE_GOTIDX: return "MIPS_LOCALPAGE_GOTIDX";
1294 case DT_MIPS_LOCAL_GOTIDX: return "MIPS_LOCAL_GOTIDX";
1295 case DT_MIPS_HIDDEN_GOTIDX: return "MIPS_HIDDEN_GOTIDX";
1296 case DT_MIPS_PROTECTED_GOTIDX: return "MIPS_PROTECTED_GOTIDX";
1297 case DT_MIPS_OPTIONS: return "MIPS_OPTIONS";
1298 case DT_MIPS_INTERFACE: return "MIPS_INTERFACE";
1299 case DT_MIPS_DYNSTR_ALIGN: return "MIPS_DYNSTR_ALIGN";
1300 case DT_MIPS_INTERFACE_SIZE: return "MIPS_INTERFACE_SIZE";
1301 case DT_MIPS_RLD_TEXT_RESOLVE_ADDR: return "MIPS_RLD_TEXT_RESOLVE_ADDR";
1302 case DT_MIPS_PERF_SUFFIX: return "MIPS_PERF_SUFFIX";
1303 case DT_MIPS_COMPACT_SIZE: return "MIPS_COMPACT_SIZE";
1304 case DT_MIPS_GP_VALUE: return "MIPS_GP_VALUE";
1305 case DT_MIPS_AUX_DYNAMIC: return "MIPS_AUX_DYNAMIC";
1312 get_sparc64_dynamic_type (unsigned long type)
1316 case DT_SPARC_REGISTER: return "SPARC_REGISTER";
1323 get_ppc_dynamic_type (unsigned long type)
1327 case DT_PPC_GOT: return "PPC_GOT";
1334 get_ppc64_dynamic_type (unsigned long type)
1338 case DT_PPC64_GLINK: return "PPC64_GLINK";
1339 case DT_PPC64_OPD: return "PPC64_OPD";
1340 case DT_PPC64_OPDSZ: return "PPC64_OPDSZ";
1347 get_parisc_dynamic_type (unsigned long type)
1351 case DT_HP_LOAD_MAP: return "HP_LOAD_MAP";
1352 case DT_HP_DLD_FLAGS: return "HP_DLD_FLAGS";
1353 case DT_HP_DLD_HOOK: return "HP_DLD_HOOK";
1354 case DT_HP_UX10_INIT: return "HP_UX10_INIT";
1355 case DT_HP_UX10_INITSZ: return "HP_UX10_INITSZ";
1356 case DT_HP_PREINIT: return "HP_PREINIT";
1357 case DT_HP_PREINITSZ: return "HP_PREINITSZ";
1358 case DT_HP_NEEDED: return "HP_NEEDED";
1359 case DT_HP_TIME_STAMP: return "HP_TIME_STAMP";
1360 case DT_HP_CHECKSUM: return "HP_CHECKSUM";
1361 case DT_HP_GST_SIZE: return "HP_GST_SIZE";
1362 case DT_HP_GST_VERSION: return "HP_GST_VERSION";
1363 case DT_HP_GST_HASHVAL: return "HP_GST_HASHVAL";
1364 case DT_HP_EPLTREL: return "HP_GST_EPLTREL";
1365 case DT_HP_EPLTRELSZ: return "HP_GST_EPLTRELSZ";
1366 case DT_HP_FILTERED: return "HP_FILTERED";
1367 case DT_HP_FILTER_TLS: return "HP_FILTER_TLS";
1368 case DT_HP_COMPAT_FILTERED: return "HP_COMPAT_FILTERED";
1369 case DT_HP_LAZYLOAD: return "HP_LAZYLOAD";
1370 case DT_HP_BIND_NOW_COUNT: return "HP_BIND_NOW_COUNT";
1371 case DT_PLT: return "PLT";
1372 case DT_PLT_SIZE: return "PLT_SIZE";
1373 case DT_DLT: return "DLT";
1374 case DT_DLT_SIZE: return "DLT_SIZE";
1381 get_ia64_dynamic_type (unsigned long type)
1385 case DT_IA_64_PLT_RESERVE: return "IA_64_PLT_RESERVE";
1392 get_alpha_dynamic_type (unsigned long type)
1396 case DT_ALPHA_PLTRO: return "ALPHA_PLTRO";
1403 get_dynamic_type (unsigned long type)
1405 static char buff[64];
1409 case DT_NULL: return "NULL";
1410 case DT_NEEDED: return "NEEDED";
1411 case DT_PLTRELSZ: return "PLTRELSZ";
1412 case DT_PLTGOT: return "PLTGOT";
1413 case DT_HASH: return "HASH";
1414 case DT_STRTAB: return "STRTAB";
1415 case DT_SYMTAB: return "SYMTAB";
1416 case DT_RELA: return "RELA";
1417 case DT_RELASZ: return "RELASZ";
1418 case DT_RELAENT: return "RELAENT";
1419 case DT_STRSZ: return "STRSZ";
1420 case DT_SYMENT: return "SYMENT";
1421 case DT_INIT: return "INIT";
1422 case DT_FINI: return "FINI";
1423 case DT_SONAME: return "SONAME";
1424 case DT_RPATH: return "RPATH";
1425 case DT_SYMBOLIC: return "SYMBOLIC";
1426 case DT_REL: return "REL";
1427 case DT_RELSZ: return "RELSZ";
1428 case DT_RELENT: return "RELENT";
1429 case DT_PLTREL: return "PLTREL";
1430 case DT_DEBUG: return "DEBUG";
1431 case DT_TEXTREL: return "TEXTREL";
1432 case DT_JMPREL: return "JMPREL";
1433 case DT_BIND_NOW: return "BIND_NOW";
1434 case DT_INIT_ARRAY: return "INIT_ARRAY";
1435 case DT_FINI_ARRAY: return "FINI_ARRAY";
1436 case DT_INIT_ARRAYSZ: return "INIT_ARRAYSZ";
1437 case DT_FINI_ARRAYSZ: return "FINI_ARRAYSZ";
1438 case DT_RUNPATH: return "RUNPATH";
1439 case DT_FLAGS: return "FLAGS";
1441 case DT_PREINIT_ARRAY: return "PREINIT_ARRAY";
1442 case DT_PREINIT_ARRAYSZ: return "PREINIT_ARRAYSZ";
1444 case DT_CHECKSUM: return "CHECKSUM";
1445 case DT_PLTPADSZ: return "PLTPADSZ";
1446 case DT_MOVEENT: return "MOVEENT";
1447 case DT_MOVESZ: return "MOVESZ";
1448 case DT_FEATURE: return "FEATURE";
1449 case DT_POSFLAG_1: return "POSFLAG_1";
1450 case DT_SYMINSZ: return "SYMINSZ";
1451 case DT_SYMINENT: return "SYMINENT"; /* aka VALRNGHI */
1453 case DT_ADDRRNGLO: return "ADDRRNGLO";
1454 case DT_CONFIG: return "CONFIG";
1455 case DT_DEPAUDIT: return "DEPAUDIT";
1456 case DT_AUDIT: return "AUDIT";
1457 case DT_PLTPAD: return "PLTPAD";
1458 case DT_MOVETAB: return "MOVETAB";
1459 case DT_SYMINFO: return "SYMINFO"; /* aka ADDRRNGHI */
1461 case DT_VERSYM: return "VERSYM";
1463 case DT_RELACOUNT: return "RELACOUNT";
1464 case DT_RELCOUNT: return "RELCOUNT";
1465 case DT_FLAGS_1: return "FLAGS_1";
1466 case DT_VERDEF: return "VERDEF";
1467 case DT_VERDEFNUM: return "VERDEFNUM";
1468 case DT_VERNEED: return "VERNEED";
1469 case DT_VERNEEDNUM: return "VERNEEDNUM";
1471 case DT_AUXILIARY: return "AUXILIARY";
1472 case DT_USED: return "USED";
1473 case DT_FILTER: return "FILTER";
1475 case DT_GNU_PRELINKED: return "GNU_PRELINKED";
1476 case DT_GNU_CONFLICT: return "GNU_CONFLICT";
1477 case DT_GNU_CONFLICTSZ: return "GNU_CONFLICTSZ";
1478 case DT_GNU_LIBLIST: return "GNU_LIBLIST";
1479 case DT_GNU_LIBLISTSZ: return "GNU_LIBLISTSZ";
1482 if ((type >= DT_LOPROC) && (type <= DT_HIPROC))
1486 switch (elf_header.e_machine)
1489 case EM_MIPS_RS3_LE:
1490 result = get_mips_dynamic_type (type);
1493 result = get_sparc64_dynamic_type (type);
1496 result = get_ppc_dynamic_type (type);
1499 result = get_ppc64_dynamic_type (type);
1502 result = get_ia64_dynamic_type (type);
1505 result = get_alpha_dynamic_type (type);
1515 snprintf (buff, sizeof (buff), _("Processor Specific: %lx"), type);
1517 else if (((type >= DT_LOOS) && (type <= DT_HIOS))
1518 || (elf_header.e_machine == EM_PARISC
1519 && (type >= OLD_DT_LOOS) && (type <= OLD_DT_HIOS)))
1523 switch (elf_header.e_machine)
1526 result = get_parisc_dynamic_type (type);
1536 snprintf (buff, sizeof (buff), _("Operating System specific: %lx"),
1540 snprintf (buff, sizeof (buff), _("<unknown>: %lx"), type);
1547 get_file_type (unsigned e_type)
1549 static char buff[32];
1553 case ET_NONE: return _("NONE (None)");
1554 case ET_REL: return _("REL (Relocatable file)");
1555 case ET_EXEC: return _("EXEC (Executable file)");
1556 case ET_DYN: return _("DYN (Shared object file)");
1557 case ET_CORE: return _("CORE (Core file)");
1560 if ((e_type >= ET_LOPROC) && (e_type <= ET_HIPROC))
1561 snprintf (buff, sizeof (buff), _("Processor Specific: (%x)"), e_type);
1562 else if ((e_type >= ET_LOOS) && (e_type <= ET_HIOS))
1563 snprintf (buff, sizeof (buff), _("OS Specific: (%x)"), e_type);
1565 snprintf (buff, sizeof (buff), _("<unknown>: %x"), e_type);
1571 get_machine_name (unsigned e_machine)
1573 static char buff[64]; /* XXX */
1577 case EM_NONE: return _("None");
1578 case EM_M32: return "WE32100";
1579 case EM_SPARC: return "Sparc";
1580 case EM_386: return "Intel 80386";
1581 case EM_68K: return "MC68000";
1582 case EM_88K: return "MC88000";
1583 case EM_486: return "Intel 80486";
1584 case EM_860: return "Intel 80860";
1585 case EM_MIPS: return "MIPS R3000";
1586 case EM_S370: return "IBM System/370";
1587 case EM_MIPS_RS3_LE: return "MIPS R4000 big-endian";
1588 case EM_OLD_SPARCV9: return "Sparc v9 (old)";
1589 case EM_PARISC: return "HPPA";
1590 case EM_PPC_OLD: return "Power PC (old)";
1591 case EM_SPARC32PLUS: return "Sparc v8+" ;
1592 case EM_960: return "Intel 90860";
1593 case EM_PPC: return "PowerPC";
1594 case EM_PPC64: return "PowerPC64";
1595 case EM_V800: return "NEC V800";
1596 case EM_FR20: return "Fujitsu FR20";
1597 case EM_RH32: return "TRW RH32";
1598 case EM_MCORE: return "MCORE";
1599 case EM_ARM: return "ARM";
1600 case EM_OLD_ALPHA: return "Digital Alpha (old)";
1601 case EM_SH: return "Renesas / SuperH SH";
1602 case EM_SPARCV9: return "Sparc v9";
1603 case EM_TRICORE: return "Siemens Tricore";
1604 case EM_ARC: return "ARC";
1605 case EM_H8_300: return "Renesas H8/300";
1606 case EM_H8_300H: return "Renesas H8/300H";
1607 case EM_H8S: return "Renesas H8S";
1608 case EM_H8_500: return "Renesas H8/500";
1609 case EM_IA_64: return "Intel IA-64";
1610 case EM_MIPS_X: return "Stanford MIPS-X";
1611 case EM_COLDFIRE: return "Motorola Coldfire";
1612 case EM_68HC12: return "Motorola M68HC12";
1613 case EM_ALPHA: return "Alpha";
1614 case EM_CYGNUS_D10V:
1615 case EM_D10V: return "d10v";
1616 case EM_CYGNUS_D30V:
1617 case EM_D30V: return "d30v";
1618 case EM_CYGNUS_M32R:
1619 case EM_M32R: return "Renesas M32R (formerly Mitsubishi M32r)";
1620 case EM_CYGNUS_V850:
1621 case EM_V850: return "NEC v850";
1622 case EM_CYGNUS_MN10300:
1623 case EM_MN10300: return "mn10300";
1624 case EM_CYGNUS_MN10200:
1625 case EM_MN10200: return "mn10200";
1626 case EM_CYGNUS_FR30:
1627 case EM_FR30: return "Fujitsu FR30";
1628 case EM_CYGNUS_FRV: return "Fujitsu FR-V";
1630 case EM_PJ: return "picoJava";
1631 case EM_MMA: return "Fujitsu Multimedia Accelerator";
1632 case EM_PCP: return "Siemens PCP";
1633 case EM_NCPU: return "Sony nCPU embedded RISC processor";
1634 case EM_NDR1: return "Denso NDR1 microprocesspr";
1635 case EM_STARCORE: return "Motorola Star*Core processor";
1636 case EM_ME16: return "Toyota ME16 processor";
1637 case EM_ST100: return "STMicroelectronics ST100 processor";
1638 case EM_TINYJ: return "Advanced Logic Corp. TinyJ embedded processor";
1639 case EM_FX66: return "Siemens FX66 microcontroller";
1640 case EM_ST9PLUS: return "STMicroelectronics ST9+ 8/16 bit microcontroller";
1641 case EM_ST7: return "STMicroelectronics ST7 8-bit microcontroller";
1642 case EM_68HC16: return "Motorola MC68HC16 Microcontroller";
1643 case EM_68HC11: return "Motorola MC68HC11 Microcontroller";
1644 case EM_68HC08: return "Motorola MC68HC08 Microcontroller";
1645 case EM_68HC05: return "Motorola MC68HC05 Microcontroller";
1646 case EM_SVX: return "Silicon Graphics SVx";
1647 case EM_ST19: return "STMicroelectronics ST19 8-bit microcontroller";
1648 case EM_VAX: return "Digital VAX";
1650 case EM_AVR: return "Atmel AVR 8-bit microcontroller";
1651 case EM_CRIS: return "Axis Communications 32-bit embedded processor";
1652 case EM_JAVELIN: return "Infineon Technologies 32-bit embedded cpu";
1653 case EM_FIREPATH: return "Element 14 64-bit DSP processor";
1654 case EM_ZSP: return "LSI Logic's 16-bit DSP processor";
1655 case EM_MMIX: return "Donald Knuth's educational 64-bit processor";
1656 case EM_HUANY: return "Harvard Universitys's machine-independent object format";
1657 case EM_PRISM: return "Vitesse Prism";
1658 case EM_X86_64: return "Advanced Micro Devices X86-64";
1660 case EM_S390: return "IBM S/390";
1661 case EM_XSTORMY16: return "Sanyo Xstormy16 CPU core";
1663 case EM_OR32: return "OpenRISC";
1664 case EM_CRX: return "National Semiconductor CRX microprocessor";
1665 case EM_DLX: return "OpenDLX";
1667 case EM_IP2K: return "Ubicom IP2xxx 8-bit microcontrollers";
1668 case EM_IQ2000: return "Vitesse IQ2000";
1670 case EM_XTENSA: return "Tensilica Xtensa Processor";
1671 case EM_M32C: return "Renesas M32c";
1672 case EM_MS1: return "Morpho Techologies MS1 processor";
1674 snprintf (buff, sizeof (buff), _("<unknown>: %x"), e_machine);
1680 decode_ARM_machine_flags (unsigned e_flags, char buf[])
1685 eabi = EF_ARM_EABI_VERSION (e_flags);
1686 e_flags &= ~ EF_ARM_EABIMASK;
1688 /* Handle "generic" ARM flags. */
1689 if (e_flags & EF_ARM_RELEXEC)
1691 strcat (buf, ", relocatable executable");
1692 e_flags &= ~ EF_ARM_RELEXEC;
1695 if (e_flags & EF_ARM_HASENTRY)
1697 strcat (buf, ", has entry point");
1698 e_flags &= ~ EF_ARM_HASENTRY;
1701 /* Now handle EABI specific flags. */
1705 strcat (buf, ", <unrecognized EABI>");
1710 case EF_ARM_EABI_VER1:
1711 strcat (buf, ", Version1 EABI");
1716 /* Process flags one bit at a time. */
1717 flag = e_flags & - e_flags;
1722 case EF_ARM_SYMSARESORTED: /* Conflicts with EF_ARM_INTERWORK. */
1723 strcat (buf, ", sorted symbol tables");
1733 case EF_ARM_EABI_VER2:
1734 strcat (buf, ", Version2 EABI");
1739 /* Process flags one bit at a time. */
1740 flag = e_flags & - e_flags;
1745 case EF_ARM_SYMSARESORTED: /* Conflicts with EF_ARM_INTERWORK. */
1746 strcat (buf, ", sorted symbol tables");
1749 case EF_ARM_DYNSYMSUSESEGIDX:
1750 strcat (buf, ", dynamic symbols use segment index");
1753 case EF_ARM_MAPSYMSFIRST:
1754 strcat (buf, ", mapping symbols precede others");
1764 case EF_ARM_EABI_VER3:
1765 strcat (buf, ", Version3 EABI");
1768 case EF_ARM_EABI_VER4:
1769 strcat (buf, ", Version4 EABI");
1774 /* Process flags one bit at a time. */
1775 flag = e_flags & - e_flags;
1781 strcat (buf, ", BE8");
1785 strcat (buf, ", LE8");
1795 case EF_ARM_EABI_UNKNOWN:
1796 strcat (buf, ", GNU EABI");
1801 /* Process flags one bit at a time. */
1802 flag = e_flags & - e_flags;
1807 case EF_ARM_INTERWORK:
1808 strcat (buf, ", interworking enabled");
1811 case EF_ARM_APCS_26:
1812 strcat (buf, ", uses APCS/26");
1815 case EF_ARM_APCS_FLOAT:
1816 strcat (buf, ", uses APCS/float");
1820 strcat (buf, ", position independent");
1824 strcat (buf, ", 8 bit structure alignment");
1827 case EF_ARM_NEW_ABI:
1828 strcat (buf, ", uses new ABI");
1831 case EF_ARM_OLD_ABI:
1832 strcat (buf, ", uses old ABI");
1835 case EF_ARM_SOFT_FLOAT:
1836 strcat (buf, ", software FP");
1839 case EF_ARM_VFP_FLOAT:
1840 strcat (buf, ", VFP");
1843 case EF_ARM_MAVERICK_FLOAT:
1844 strcat (buf, ", Maverick FP");
1855 strcat (buf,", <unknown>");
1859 get_machine_flags (unsigned e_flags, unsigned e_machine)
1861 static char buf[1024];
1873 decode_ARM_machine_flags (e_flags, buf);
1877 switch (e_flags & EF_FRV_CPU_MASK)
1879 case EF_FRV_CPU_GENERIC:
1883 strcat (buf, ", fr???");
1886 case EF_FRV_CPU_FR300:
1887 strcat (buf, ", fr300");
1890 case EF_FRV_CPU_FR400:
1891 strcat (buf, ", fr400");
1893 case EF_FRV_CPU_FR405:
1894 strcat (buf, ", fr405");
1897 case EF_FRV_CPU_FR450:
1898 strcat (buf, ", fr450");
1901 case EF_FRV_CPU_FR500:
1902 strcat (buf, ", fr500");
1904 case EF_FRV_CPU_FR550:
1905 strcat (buf, ", fr550");
1908 case EF_FRV_CPU_SIMPLE:
1909 strcat (buf, ", simple");
1911 case EF_FRV_CPU_TOMCAT:
1912 strcat (buf, ", tomcat");
1918 if (e_flags & EF_CPU32)
1919 strcat (buf, ", cpu32");
1920 if (e_flags & EF_M68000)
1921 strcat (buf, ", m68000");
1925 if (e_flags & EF_PPC_EMB)
1926 strcat (buf, ", emb");
1928 if (e_flags & EF_PPC_RELOCATABLE)
1929 strcat (buf, ", relocatable");
1931 if (e_flags & EF_PPC_RELOCATABLE_LIB)
1932 strcat (buf, ", relocatable-lib");
1936 case EM_CYGNUS_V850:
1937 switch (e_flags & EF_V850_ARCH)
1940 strcat (buf, ", v850e1");
1943 strcat (buf, ", v850e");
1946 strcat (buf, ", v850");
1949 strcat (buf, ", unknown v850 architecture variant");
1955 case EM_CYGNUS_M32R:
1956 if ((e_flags & EF_M32R_ARCH) == E_M32R_ARCH)
1957 strcat (buf, ", m32r");
1962 case EM_MIPS_RS3_LE:
1963 if (e_flags & EF_MIPS_NOREORDER)
1964 strcat (buf, ", noreorder");
1966 if (e_flags & EF_MIPS_PIC)
1967 strcat (buf, ", pic");
1969 if (e_flags & EF_MIPS_CPIC)
1970 strcat (buf, ", cpic");
1972 if (e_flags & EF_MIPS_UCODE)
1973 strcat (buf, ", ugen_reserved");
1975 if (e_flags & EF_MIPS_ABI2)
1976 strcat (buf, ", abi2");
1978 if (e_flags & EF_MIPS_OPTIONS_FIRST)
1979 strcat (buf, ", odk first");
1981 if (e_flags & EF_MIPS_32BITMODE)
1982 strcat (buf, ", 32bitmode");
1984 switch ((e_flags & EF_MIPS_MACH))
1986 case E_MIPS_MACH_3900: strcat (buf, ", 3900"); break;
1987 case E_MIPS_MACH_4010: strcat (buf, ", 4010"); break;
1988 case E_MIPS_MACH_4100: strcat (buf, ", 4100"); break;
1989 case E_MIPS_MACH_4111: strcat (buf, ", 4111"); break;
1990 case E_MIPS_MACH_4120: strcat (buf, ", 4120"); break;
1991 case E_MIPS_MACH_4650: strcat (buf, ", 4650"); break;
1992 case E_MIPS_MACH_5400: strcat (buf, ", 5400"); break;
1993 case E_MIPS_MACH_5500: strcat (buf, ", 5500"); break;
1994 case E_MIPS_MACH_SB1: strcat (buf, ", sb1"); break;
1995 case E_MIPS_MACH_9000: strcat (buf, ", 9000"); break;
1997 /* We simply ignore the field in this case to avoid confusion:
1998 MIPS ELF does not specify EF_MIPS_MACH, it is a GNU
2001 default: strcat (buf, ", unknown CPU"); break;
2004 switch ((e_flags & EF_MIPS_ABI))
2006 case E_MIPS_ABI_O32: strcat (buf, ", o32"); break;
2007 case E_MIPS_ABI_O64: strcat (buf, ", o64"); break;
2008 case E_MIPS_ABI_EABI32: strcat (buf, ", eabi32"); break;
2009 case E_MIPS_ABI_EABI64: strcat (buf, ", eabi64"); break;
2011 /* We simply ignore the field in this case to avoid confusion:
2012 MIPS ELF does not specify EF_MIPS_ABI, it is a GNU extension.
2013 This means it is likely to be an o32 file, but not for
2016 default: strcat (buf, ", unknown ABI"); break;
2019 if (e_flags & EF_MIPS_ARCH_ASE_MDMX)
2020 strcat (buf, ", mdmx");
2022 if (e_flags & EF_MIPS_ARCH_ASE_M16)
2023 strcat (buf, ", mips16");
2025 switch ((e_flags & EF_MIPS_ARCH))
2027 case E_MIPS_ARCH_1: strcat (buf, ", mips1"); break;
2028 case E_MIPS_ARCH_2: strcat (buf, ", mips2"); break;
2029 case E_MIPS_ARCH_3: strcat (buf, ", mips3"); break;
2030 case E_MIPS_ARCH_4: strcat (buf, ", mips4"); break;
2031 case E_MIPS_ARCH_5: strcat (buf, ", mips5"); break;
2032 case E_MIPS_ARCH_32: strcat (buf, ", mips32"); break;
2033 case E_MIPS_ARCH_32R2: strcat (buf, ", mips32r2"); break;
2034 case E_MIPS_ARCH_64: strcat (buf, ", mips64"); break;
2035 case E_MIPS_ARCH_64R2: strcat (buf, ", mips64r2"); break;
2036 default: strcat (buf, ", unknown ISA"); break;
2042 switch ((e_flags & EF_SH_MACH_MASK))
2044 case EF_SH1: strcat (buf, ", sh1"); break;
2045 case EF_SH2: strcat (buf, ", sh2"); break;
2046 case EF_SH3: strcat (buf, ", sh3"); break;
2047 case EF_SH_DSP: strcat (buf, ", sh-dsp"); break;
2048 case EF_SH3_DSP: strcat (buf, ", sh3-dsp"); break;
2049 case EF_SH4AL_DSP: strcat (buf, ", sh4al-dsp"); break;
2050 case EF_SH3E: strcat (buf, ", sh3e"); break;
2051 case EF_SH4: strcat (buf, ", sh4"); break;
2052 case EF_SH5: strcat (buf, ", sh5"); break;
2053 case EF_SH2E: strcat (buf, ", sh2e"); break;
2054 case EF_SH4A: strcat (buf, ", sh4a"); break;
2055 case EF_SH2A: strcat (buf, ", sh2a"); break;
2056 case EF_SH4_NOFPU: strcat (buf, ", sh4-nofpu"); break;
2057 case EF_SH4A_NOFPU: strcat (buf, ", sh4a-nofpu"); break;
2058 case EF_SH2A_NOFPU: strcat (buf, ", sh2a-nofpu"); break;
2059 default: strcat (buf, ", unknown ISA"); break;
2065 if (e_flags & EF_SPARC_32PLUS)
2066 strcat (buf, ", v8+");
2068 if (e_flags & EF_SPARC_SUN_US1)
2069 strcat (buf, ", ultrasparcI");
2071 if (e_flags & EF_SPARC_SUN_US3)
2072 strcat (buf, ", ultrasparcIII");
2074 if (e_flags & EF_SPARC_HAL_R1)
2075 strcat (buf, ", halr1");
2077 if (e_flags & EF_SPARC_LEDATA)
2078 strcat (buf, ", ledata");
2080 if ((e_flags & EF_SPARCV9_MM) == EF_SPARCV9_TSO)
2081 strcat (buf, ", tso");
2083 if ((e_flags & EF_SPARCV9_MM) == EF_SPARCV9_PSO)
2084 strcat (buf, ", pso");
2086 if ((e_flags & EF_SPARCV9_MM) == EF_SPARCV9_RMO)
2087 strcat (buf, ", rmo");
2091 switch (e_flags & EF_PARISC_ARCH)
2093 case EFA_PARISC_1_0:
2094 strcpy (buf, ", PA-RISC 1.0");
2096 case EFA_PARISC_1_1:
2097 strcpy (buf, ", PA-RISC 1.1");
2099 case EFA_PARISC_2_0:
2100 strcpy (buf, ", PA-RISC 2.0");
2105 if (e_flags & EF_PARISC_TRAPNIL)
2106 strcat (buf, ", trapnil");
2107 if (e_flags & EF_PARISC_EXT)
2108 strcat (buf, ", ext");
2109 if (e_flags & EF_PARISC_LSB)
2110 strcat (buf, ", lsb");
2111 if (e_flags & EF_PARISC_WIDE)
2112 strcat (buf, ", wide");
2113 if (e_flags & EF_PARISC_NO_KABP)
2114 strcat (buf, ", no kabp");
2115 if (e_flags & EF_PARISC_LAZYSWAP)
2116 strcat (buf, ", lazyswap");
2121 if ((e_flags & EF_PICOJAVA_NEWCALLS) == EF_PICOJAVA_NEWCALLS)
2122 strcat (buf, ", new calling convention");
2124 if ((e_flags & EF_PICOJAVA_GNUCALLS) == EF_PICOJAVA_GNUCALLS)
2125 strcat (buf, ", gnu calling convention");
2129 if ((e_flags & EF_IA_64_ABI64))
2130 strcat (buf, ", 64-bit");
2132 strcat (buf, ", 32-bit");
2133 if ((e_flags & EF_IA_64_REDUCEDFP))
2134 strcat (buf, ", reduced fp model");
2135 if ((e_flags & EF_IA_64_NOFUNCDESC_CONS_GP))
2136 strcat (buf, ", no function descriptors, constant gp");
2137 else if ((e_flags & EF_IA_64_CONS_GP))
2138 strcat (buf, ", constant gp");
2139 if ((e_flags & EF_IA_64_ABSOLUTE))
2140 strcat (buf, ", absolute");
2144 if ((e_flags & EF_VAX_NONPIC))
2145 strcat (buf, ", non-PIC");
2146 if ((e_flags & EF_VAX_DFLOAT))
2147 strcat (buf, ", D-Float");
2148 if ((e_flags & EF_VAX_GFLOAT))
2149 strcat (buf, ", G-Float");
2158 get_osabi_name (unsigned int osabi)
2160 static char buff[32];
2164 case ELFOSABI_NONE: return "UNIX - System V";
2165 case ELFOSABI_HPUX: return "UNIX - HP-UX";
2166 case ELFOSABI_NETBSD: return "UNIX - NetBSD";
2167 case ELFOSABI_LINUX: return "UNIX - Linux";
2168 case ELFOSABI_HURD: return "GNU/Hurd";
2169 case ELFOSABI_SOLARIS: return "UNIX - Solaris";
2170 case ELFOSABI_AIX: return "UNIX - AIX";
2171 case ELFOSABI_IRIX: return "UNIX - IRIX";
2172 case ELFOSABI_FREEBSD: return "UNIX - FreeBSD";
2173 case ELFOSABI_TRU64: return "UNIX - TRU64";
2174 case ELFOSABI_MODESTO: return "Novell - Modesto";
2175 case ELFOSABI_OPENBSD: return "UNIX - OpenBSD";
2176 case ELFOSABI_OPENVMS: return "VMS - OpenVMS";
2177 case ELFOSABI_NSK: return "HP - Non-Stop Kernel";
2178 case ELFOSABI_AROS: return "Amiga Research OS";
2179 case ELFOSABI_STANDALONE: return _("Standalone App");
2180 case ELFOSABI_ARM: return "ARM";
2182 snprintf (buff, sizeof (buff), _("<unknown: %x>"), osabi);
2188 get_arm_segment_type (unsigned long type)
2202 get_mips_segment_type (unsigned long type)
2206 case PT_MIPS_REGINFO:
2208 case PT_MIPS_RTPROC:
2210 case PT_MIPS_OPTIONS:
2220 get_parisc_segment_type (unsigned long type)
2224 case PT_HP_TLS: return "HP_TLS";
2225 case PT_HP_CORE_NONE: return "HP_CORE_NONE";
2226 case PT_HP_CORE_VERSION: return "HP_CORE_VERSION";
2227 case PT_HP_CORE_KERNEL: return "HP_CORE_KERNEL";
2228 case PT_HP_CORE_COMM: return "HP_CORE_COMM";
2229 case PT_HP_CORE_PROC: return "HP_CORE_PROC";
2230 case PT_HP_CORE_LOADABLE: return "HP_CORE_LOADABLE";
2231 case PT_HP_CORE_STACK: return "HP_CORE_STACK";
2232 case PT_HP_CORE_SHM: return "HP_CORE_SHM";
2233 case PT_HP_CORE_MMF: return "HP_CORE_MMF";
2234 case PT_HP_PARALLEL: return "HP_PARALLEL";
2235 case PT_HP_FASTBIND: return "HP_FASTBIND";
2236 case PT_HP_OPT_ANNOT: return "HP_OPT_ANNOT";
2237 case PT_HP_HSL_ANNOT: return "HP_HSL_ANNOT";
2238 case PT_HP_STACK: return "HP_STACK";
2239 case PT_HP_CORE_UTSNAME: return "HP_CORE_UTSNAME";
2240 case PT_PARISC_ARCHEXT: return "PARISC_ARCHEXT";
2241 case PT_PARISC_UNWIND: return "PARISC_UNWIND";
2242 case PT_PARISC_WEAKORDER: return "PARISC_WEAKORDER";
2251 get_ia64_segment_type (unsigned long type)
2255 case PT_IA_64_ARCHEXT: return "IA_64_ARCHEXT";
2256 case PT_IA_64_UNWIND: return "IA_64_UNWIND";
2257 case PT_HP_TLS: return "HP_TLS";
2258 case PT_IA_64_HP_OPT_ANOT: return "HP_OPT_ANNOT";
2259 case PT_IA_64_HP_HSL_ANOT: return "HP_HSL_ANNOT";
2260 case PT_IA_64_HP_STACK: return "HP_STACK";
2269 get_segment_type (unsigned long p_type)
2271 static char buff[32];
2275 case PT_NULL: return "NULL";
2276 case PT_LOAD: return "LOAD";
2277 case PT_DYNAMIC: return "DYNAMIC";
2278 case PT_INTERP: return "INTERP";
2279 case PT_NOTE: return "NOTE";
2280 case PT_SHLIB: return "SHLIB";
2281 case PT_PHDR: return "PHDR";
2282 case PT_TLS: return "TLS";
2284 case PT_GNU_EH_FRAME:
2285 return "GNU_EH_FRAME";
2286 case PT_GNU_STACK: return "GNU_STACK";
2287 case PT_GNU_RELRO: return "GNU_RELRO";
2290 if ((p_type >= PT_LOPROC) && (p_type <= PT_HIPROC))
2294 switch (elf_header.e_machine)
2297 result = get_arm_segment_type (p_type);
2300 case EM_MIPS_RS3_LE:
2301 result = get_mips_segment_type (p_type);
2304 result = get_parisc_segment_type (p_type);
2307 result = get_ia64_segment_type (p_type);
2317 sprintf (buff, "LOPROC+%lx", p_type - PT_LOPROC);
2319 else if ((p_type >= PT_LOOS) && (p_type <= PT_HIOS))
2323 switch (elf_header.e_machine)
2326 result = get_parisc_segment_type (p_type);
2329 result = get_ia64_segment_type (p_type);
2339 sprintf (buff, "LOOS+%lx", p_type - PT_LOOS);
2342 snprintf (buff, sizeof (buff), _("<unknown>: %lx"), p_type);
2349 get_mips_section_type_name (unsigned int sh_type)
2353 case SHT_MIPS_LIBLIST: return "MIPS_LIBLIST";
2354 case SHT_MIPS_MSYM: return "MIPS_MSYM";
2355 case SHT_MIPS_CONFLICT: return "MIPS_CONFLICT";
2356 case SHT_MIPS_GPTAB: return "MIPS_GPTAB";
2357 case SHT_MIPS_UCODE: return "MIPS_UCODE";
2358 case SHT_MIPS_DEBUG: return "MIPS_DEBUG";
2359 case SHT_MIPS_REGINFO: return "MIPS_REGINFO";
2360 case SHT_MIPS_PACKAGE: return "MIPS_PACKAGE";
2361 case SHT_MIPS_PACKSYM: return "MIPS_PACKSYM";
2362 case SHT_MIPS_RELD: return "MIPS_RELD";
2363 case SHT_MIPS_IFACE: return "MIPS_IFACE";
2364 case SHT_MIPS_CONTENT: return "MIPS_CONTENT";
2365 case SHT_MIPS_OPTIONS: return "MIPS_OPTIONS";
2366 case SHT_MIPS_SHDR: return "MIPS_SHDR";
2367 case SHT_MIPS_FDESC: return "MIPS_FDESC";
2368 case SHT_MIPS_EXTSYM: return "MIPS_EXTSYM";
2369 case SHT_MIPS_DENSE: return "MIPS_DENSE";
2370 case SHT_MIPS_PDESC: return "MIPS_PDESC";
2371 case SHT_MIPS_LOCSYM: return "MIPS_LOCSYM";
2372 case SHT_MIPS_AUXSYM: return "MIPS_AUXSYM";
2373 case SHT_MIPS_OPTSYM: return "MIPS_OPTSYM";
2374 case SHT_MIPS_LOCSTR: return "MIPS_LOCSTR";
2375 case SHT_MIPS_LINE: return "MIPS_LINE";
2376 case SHT_MIPS_RFDESC: return "MIPS_RFDESC";
2377 case SHT_MIPS_DELTASYM: return "MIPS_DELTASYM";
2378 case SHT_MIPS_DELTAINST: return "MIPS_DELTAINST";
2379 case SHT_MIPS_DELTACLASS: return "MIPS_DELTACLASS";
2380 case SHT_MIPS_DWARF: return "MIPS_DWARF";
2381 case SHT_MIPS_DELTADECL: return "MIPS_DELTADECL";
2382 case SHT_MIPS_SYMBOL_LIB: return "MIPS_SYMBOL_LIB";
2383 case SHT_MIPS_EVENTS: return "MIPS_EVENTS";
2384 case SHT_MIPS_TRANSLATE: return "MIPS_TRANSLATE";
2385 case SHT_MIPS_PIXIE: return "MIPS_PIXIE";
2386 case SHT_MIPS_XLATE: return "MIPS_XLATE";
2387 case SHT_MIPS_XLATE_DEBUG: return "MIPS_XLATE_DEBUG";
2388 case SHT_MIPS_WHIRL: return "MIPS_WHIRL";
2389 case SHT_MIPS_EH_REGION: return "MIPS_EH_REGION";
2390 case SHT_MIPS_XLATE_OLD: return "MIPS_XLATE_OLD";
2391 case SHT_MIPS_PDR_EXCEPTION: return "MIPS_PDR_EXCEPTION";
2399 get_parisc_section_type_name (unsigned int sh_type)
2403 case SHT_PARISC_EXT: return "PARISC_EXT";
2404 case SHT_PARISC_UNWIND: return "PARISC_UNWIND";
2405 case SHT_PARISC_DOC: return "PARISC_DOC";
2406 case SHT_PARISC_ANNOT: return "PARISC_ANNOT";
2407 case SHT_PARISC_SYMEXTN: return "PARISC_SYMEXTN";
2408 case SHT_PARISC_STUBS: return "PARISC_STUBS";
2409 case SHT_PARISC_DLKM: return "PARISC_DLKM";
2417 get_ia64_section_type_name (unsigned int sh_type)
2419 /* If the top 8 bits are 0x78 the next 8 are the os/abi ID. */
2420 if ((sh_type & 0xFF000000) == SHT_IA_64_LOPSREG)
2421 return get_osabi_name ((sh_type & 0x00FF0000) >> 16);
2425 case SHT_IA_64_EXT: return "IA_64_EXT";
2426 case SHT_IA_64_UNWIND: return "IA_64_UNWIND";
2427 case SHT_IA_64_PRIORITY_INIT: return "IA_64_PRIORITY_INIT";
2435 get_x86_64_section_type_name (unsigned int sh_type)
2439 case SHT_X86_64_UNWIND: return "X86_64_UNWIND";
2447 get_arm_section_type_name (unsigned int sh_type)
2453 case SHT_ARM_PREEMPTMAP:
2454 return "ARM_PREEMPTMAP";
2455 case SHT_ARM_ATTRIBUTES:
2456 return "ARM_ATTRIBUTES";
2464 get_section_type_name (unsigned int sh_type)
2466 static char buff[32];
2470 case SHT_NULL: return "NULL";
2471 case SHT_PROGBITS: return "PROGBITS";
2472 case SHT_SYMTAB: return "SYMTAB";
2473 case SHT_STRTAB: return "STRTAB";
2474 case SHT_RELA: return "RELA";
2475 case SHT_HASH: return "HASH";
2476 case SHT_DYNAMIC: return "DYNAMIC";
2477 case SHT_NOTE: return "NOTE";
2478 case SHT_NOBITS: return "NOBITS";
2479 case SHT_REL: return "REL";
2480 case SHT_SHLIB: return "SHLIB";
2481 case SHT_DYNSYM: return "DYNSYM";
2482 case SHT_INIT_ARRAY: return "INIT_ARRAY";
2483 case SHT_FINI_ARRAY: return "FINI_ARRAY";
2484 case SHT_PREINIT_ARRAY: return "PREINIT_ARRAY";
2485 case SHT_GROUP: return "GROUP";
2486 case SHT_SYMTAB_SHNDX: return "SYMTAB SECTION INDICIES";
2487 case SHT_GNU_verdef: return "VERDEF";
2488 case SHT_GNU_verneed: return "VERNEED";
2489 case SHT_GNU_versym: return "VERSYM";
2490 case 0x6ffffff0: return "VERSYM";
2491 case 0x6ffffffc: return "VERDEF";
2492 case 0x7ffffffd: return "AUXILIARY";
2493 case 0x7fffffff: return "FILTER";
2494 case SHT_GNU_LIBLIST: return "GNU_LIBLIST";
2497 if ((sh_type >= SHT_LOPROC) && (sh_type <= SHT_HIPROC))
2501 switch (elf_header.e_machine)
2504 case EM_MIPS_RS3_LE:
2505 result = get_mips_section_type_name (sh_type);
2508 result = get_parisc_section_type_name (sh_type);
2511 result = get_ia64_section_type_name (sh_type);
2514 result = get_x86_64_section_type_name (sh_type);
2517 result = get_arm_section_type_name (sh_type);
2527 sprintf (buff, "LOPROC+%x", sh_type - SHT_LOPROC);
2529 else if ((sh_type >= SHT_LOOS) && (sh_type <= SHT_HIOS))
2530 sprintf (buff, "LOOS+%x", sh_type - SHT_LOOS);
2531 else if ((sh_type >= SHT_LOUSER) && (sh_type <= SHT_HIUSER))
2532 sprintf (buff, "LOUSER+%x", sh_type - SHT_LOUSER);
2534 snprintf (buff, sizeof (buff), _("<unknown>: %x"), sh_type);
2540 #define OPTION_DEBUG_DUMP 512
2542 static struct option options[] =
2544 {"all", no_argument, 0, 'a'},
2545 {"file-header", no_argument, 0, 'h'},
2546 {"program-headers", no_argument, 0, 'l'},
2547 {"headers", no_argument, 0, 'e'},
2548 {"histogram", no_argument, 0, 'I'},
2549 {"segments", no_argument, 0, 'l'},
2550 {"sections", no_argument, 0, 'S'},
2551 {"section-headers", no_argument, 0, 'S'},
2552 {"section-groups", no_argument, 0, 'g'},
2553 {"section-details", no_argument, 0, 't'},
2554 {"full-section-name",no_argument, 0, 'N'},
2555 {"symbols", no_argument, 0, 's'},
2556 {"syms", no_argument, 0, 's'},
2557 {"relocs", no_argument, 0, 'r'},
2558 {"notes", no_argument, 0, 'n'},
2559 {"dynamic", no_argument, 0, 'd'},
2560 {"arch-specific", no_argument, 0, 'A'},
2561 {"version-info", no_argument, 0, 'V'},
2562 {"use-dynamic", no_argument, 0, 'D'},
2563 {"hex-dump", required_argument, 0, 'x'},
2564 {"debug-dump", optional_argument, 0, OPTION_DEBUG_DUMP},
2565 {"unwind", no_argument, 0, 'u'},
2566 #ifdef SUPPORT_DISASSEMBLY
2567 {"instruction-dump", required_argument, 0, 'i'},
2570 {"version", no_argument, 0, 'v'},
2571 {"wide", no_argument, 0, 'W'},
2572 {"help", no_argument, 0, 'H'},
2573 {0, no_argument, 0, 0}
2579 fprintf (stdout, _("Usage: readelf <option(s)> elf-file(s)\n"));
2580 fprintf (stdout, _(" Display information about the contents of ELF format files\n"));
2581 fprintf (stdout, _(" Options are:\n\
2582 -a --all Equivalent to: -h -l -S -s -r -d -V -A -I\n\
2583 -h --file-header Display the ELF file header\n\
2584 -l --program-headers Display the program headers\n\
2585 --segments An alias for --program-headers\n\
2586 -S --section-headers Display the sections' header\n\
2587 --sections An alias for --section-headers\n\
2588 -g --section-groups Display the section groups\n\
2589 -t --section-details Display the section details\n\
2590 -e --headers Equivalent to: -h -l -S\n\
2591 -s --syms Display the symbol table\n\
2592 --symbols An alias for --syms\n\
2593 -n --notes Display the core notes (if present)\n\
2594 -r --relocs Display the relocations (if present)\n\
2595 -u --unwind Display the unwind info (if present)\n\
2596 -d --dynamic Display the dynamic section (if present)\n\
2597 -V --version-info Display the version sections (if present)\n\
2598 -A --arch-specific Display architecture specific information (if any).\n\
2599 -D --use-dynamic Use the dynamic section info when displaying symbols\n\
2600 -x --hex-dump=<number> Dump the contents of section <number>\n\
2601 -w[liaprmfFsoR] or\n\
2602 --debug-dump[=line,=info,=abbrev,=pubnames,=aranges,=macro,=frames,=str,=loc,=Ranges]\n\
2603 Display the contents of DWARF2 debug sections\n"));
2604 #ifdef SUPPORT_DISASSEMBLY
2605 fprintf (stdout, _("\
2606 -i --instruction-dump=<number>\n\
2607 Disassemble the contents of section <number>\n"));
2609 fprintf (stdout, _("\
2610 -I --histogram Display histogram of bucket list lengths\n\
2611 -W --wide Allow output width to exceed 80 characters\n\
2612 -H --help Display this information\n\
2613 -v --version Display the version number of readelf\n"));
2614 fprintf (stdout, _("Report bugs to %s\n"), REPORT_BUGS_TO);
2619 /* Record the fact that the user wants the contents of section number
2620 SECTION to be displayed using the method(s) encoded as flags bits
2621 in TYPE. Note, TYPE can be zero if we are creating the array for
2625 request_dump (unsigned int section, int type)
2627 if (section >= num_dump_sects)
2629 char *new_dump_sects;
2631 new_dump_sects = calloc (section + 1, 1);
2633 if (new_dump_sects == NULL)
2634 error (_("Out of memory allocating dump request table."));
2637 /* Copy current flag settings. */
2638 memcpy (new_dump_sects, dump_sects, num_dump_sects);
2642 dump_sects = new_dump_sects;
2643 num_dump_sects = section + 1;
2648 dump_sects[section] |= type;
2654 parse_args (int argc, char **argv)
2661 while ((c = getopt_long
2662 (argc, argv, "ersuahnldSDAINtgw::x:i:vVWH", options, NULL)) != EOF)
2683 do_section_groups++;
2691 do_section_groups++;
2696 do_section_details++;
2738 section = strtoul (optarg, & cp, 0);
2739 if (! *cp && section >= 0)
2741 request_dump (section, HEX_DUMP);
2751 unsigned int index = 0;
2755 while (optarg[index])
2756 switch (optarg[index++])
2765 do_debug_abbrevs = 1;
2775 do_debug_pubnames = 1;
2779 do_debug_aranges = 1;
2783 do_debug_ranges = 1;
2787 do_debug_frames_interp = 1;
2789 do_debug_frames = 1;
2794 do_debug_macinfo = 1;
2808 warn (_("Unrecognized debug option '%s'\n"), optarg);
2813 case OPTION_DEBUG_DUMP:
2821 const char * option;
2824 debug_dump_long_opts;
2826 debug_dump_long_opts opts_table [] =
2828 /* Please keep this table alpha- sorted. */
2829 { "Ranges", & do_debug_ranges },
2830 { "abbrev", & do_debug_abbrevs },
2831 { "aranges", & do_debug_aranges },
2832 { "frames", & do_debug_frames },
2833 { "frames-interp", & do_debug_frames_interp },
2834 { "info", & do_debug_info },
2835 { "line", & do_debug_lines },
2836 { "loc", & do_debug_loc },
2837 { "macro", & do_debug_macinfo },
2838 { "pubnames", & do_debug_pubnames },
2839 /* This entry is for compatability
2840 with earlier versions of readelf. */
2841 { "ranges", & do_debug_aranges },
2842 { "str", & do_debug_str },
2853 debug_dump_long_opts * entry;
2855 for (entry = opts_table; entry->option; entry++)
2857 size_t len = strlen (entry->option);
2859 if (strneq (p, entry->option, len)
2860 && (p[len] == ',' || p[len] == '\0'))
2862 * entry->variable = 1;
2864 /* The --debug-dump=frames-interp option also
2865 enables the --debug-dump=frames option. */
2866 if (do_debug_frames_interp)
2867 do_debug_frames = 1;
2874 if (entry->option == NULL)
2876 warn (_("Unrecognized debug option '%s'\n"), p);
2877 p = strchr (p, ',');
2887 #ifdef SUPPORT_DISASSEMBLY
2890 section = strtoul (optarg, & cp, 0);
2891 if (! *cp && section >= 0)
2893 request_dump (section, DISASS_DUMP);
2899 print_version (program_name);
2909 /* xgettext:c-format */
2910 error (_("Invalid option '-%c'\n"), c);
2917 if (!do_dynamic && !do_syms && !do_reloc && !do_unwind && !do_sections
2918 && !do_segments && !do_header && !do_dump && !do_version
2919 && !do_histogram && !do_debugging && !do_arch && !do_notes
2920 && !do_section_groups)
2924 warn (_("Nothing to do.\n"));
2930 get_elf_class (unsigned int elf_class)
2932 static char buff[32];
2936 case ELFCLASSNONE: return _("none");
2937 case ELFCLASS32: return "ELF32";
2938 case ELFCLASS64: return "ELF64";
2940 snprintf (buff, sizeof (buff), _("<unknown: %x>"), elf_class);
2946 get_data_encoding (unsigned int encoding)
2948 static char buff[32];
2952 case ELFDATANONE: return _("none");
2953 case ELFDATA2LSB: return _("2's complement, little endian");
2954 case ELFDATA2MSB: return _("2's complement, big endian");
2956 snprintf (buff, sizeof (buff), _("<unknown: %x>"), encoding);
2961 /* Decode the data held in 'elf_header'. */
2964 process_file_header (void)
2966 if ( elf_header.e_ident[EI_MAG0] != ELFMAG0
2967 || elf_header.e_ident[EI_MAG1] != ELFMAG1
2968 || elf_header.e_ident[EI_MAG2] != ELFMAG2
2969 || elf_header.e_ident[EI_MAG3] != ELFMAG3)
2972 (_("Not an ELF file - it has the wrong magic bytes at the start\n"));
2980 printf (_("ELF Header:\n"));
2981 printf (_(" Magic: "));
2982 for (i = 0; i < EI_NIDENT; i++)
2983 printf ("%2.2x ", elf_header.e_ident[i]);
2985 printf (_(" Class: %s\n"),
2986 get_elf_class (elf_header.e_ident[EI_CLASS]));
2987 printf (_(" Data: %s\n"),
2988 get_data_encoding (elf_header.e_ident[EI_DATA]));
2989 printf (_(" Version: %d %s\n"),
2990 elf_header.e_ident[EI_VERSION],
2991 (elf_header.e_ident[EI_VERSION] == EV_CURRENT
2993 : (elf_header.e_ident[EI_VERSION] != EV_NONE
2996 printf (_(" OS/ABI: %s\n"),
2997 get_osabi_name (elf_header.e_ident[EI_OSABI]));
2998 printf (_(" ABI Version: %d\n"),
2999 elf_header.e_ident[EI_ABIVERSION]);
3000 printf (_(" Type: %s\n"),
3001 get_file_type (elf_header.e_type));
3002 printf (_(" Machine: %s\n"),
3003 get_machine_name (elf_header.e_machine));
3004 printf (_(" Version: 0x%lx\n"),
3005 (unsigned long) elf_header.e_version);
3007 printf (_(" Entry point address: "));
3008 print_vma ((bfd_vma) elf_header.e_entry, PREFIX_HEX);
3009 printf (_("\n Start of program headers: "));
3010 print_vma ((bfd_vma) elf_header.e_phoff, DEC);
3011 printf (_(" (bytes into file)\n Start of section headers: "));
3012 print_vma ((bfd_vma) elf_header.e_shoff, DEC);
3013 printf (_(" (bytes into file)\n"));
3015 printf (_(" Flags: 0x%lx%s\n"),
3016 (unsigned long) elf_header.e_flags,
3017 get_machine_flags (elf_header.e_flags, elf_header.e_machine));
3018 printf (_(" Size of this header: %ld (bytes)\n"),
3019 (long) elf_header.e_ehsize);
3020 printf (_(" Size of program headers: %ld (bytes)\n"),
3021 (long) elf_header.e_phentsize);
3022 printf (_(" Number of program headers: %ld\n"),
3023 (long) elf_header.e_phnum);
3024 printf (_(" Size of section headers: %ld (bytes)\n"),
3025 (long) elf_header.e_shentsize);
3026 printf (_(" Number of section headers: %ld"),
3027 (long) elf_header.e_shnum);
3028 if (section_headers != NULL && elf_header.e_shnum == 0)
3029 printf (" (%ld)", (long) section_headers[0].sh_size);
3030 putc ('\n', stdout);
3031 printf (_(" Section header string table index: %ld"),
3032 (long) elf_header.e_shstrndx);
3033 if (section_headers != NULL && elf_header.e_shstrndx == SHN_XINDEX)
3034 printf (" (%ld)", (long) section_headers[0].sh_link);
3035 putc ('\n', stdout);
3038 if (section_headers != NULL)
3040 if (elf_header.e_shnum == 0)
3041 elf_header.e_shnum = section_headers[0].sh_size;
3042 if (elf_header.e_shstrndx == SHN_XINDEX)
3043 elf_header.e_shstrndx = section_headers[0].sh_link;
3044 free (section_headers);
3045 section_headers = NULL;
3053 get_32bit_program_headers (FILE *file, Elf_Internal_Phdr *program_headers)
3055 Elf32_External_Phdr *phdrs;
3056 Elf32_External_Phdr *external;
3057 Elf_Internal_Phdr *internal;
3060 phdrs = get_data (NULL, file, elf_header.e_phoff,
3061 elf_header.e_phentsize, elf_header.e_phnum,
3062 _("program headers"));
3066 for (i = 0, internal = program_headers, external = phdrs;
3067 i < elf_header.e_phnum;
3068 i++, internal++, external++)
3070 internal->p_type = BYTE_GET (external->p_type);
3071 internal->p_offset = BYTE_GET (external->p_offset);
3072 internal->p_vaddr = BYTE_GET (external->p_vaddr);
3073 internal->p_paddr = BYTE_GET (external->p_paddr);
3074 internal->p_filesz = BYTE_GET (external->p_filesz);
3075 internal->p_memsz = BYTE_GET (external->p_memsz);
3076 internal->p_flags = BYTE_GET (external->p_flags);
3077 internal->p_align = BYTE_GET (external->p_align);
3086 get_64bit_program_headers (FILE *file, Elf_Internal_Phdr *program_headers)
3088 Elf64_External_Phdr *phdrs;
3089 Elf64_External_Phdr *external;
3090 Elf_Internal_Phdr *internal;
3093 phdrs = get_data (NULL, file, elf_header.e_phoff,
3094 elf_header.e_phentsize, elf_header.e_phnum,
3095 _("program headers"));
3099 for (i = 0, internal = program_headers, external = phdrs;
3100 i < elf_header.e_phnum;
3101 i++, internal++, external++)
3103 internal->p_type = BYTE_GET (external->p_type);
3104 internal->p_flags = BYTE_GET (external->p_flags);
3105 internal->p_offset = BYTE_GET (external->p_offset);
3106 internal->p_vaddr = BYTE_GET (external->p_vaddr);
3107 internal->p_paddr = BYTE_GET (external->p_paddr);
3108 internal->p_filesz = BYTE_GET (external->p_filesz);
3109 internal->p_memsz = BYTE_GET (external->p_memsz);
3110 internal->p_align = BYTE_GET (external->p_align);
3118 /* Returns 1 if the program headers were read into `program_headers'. */
3121 get_program_headers (FILE *file)
3123 Elf_Internal_Phdr *phdrs;
3125 /* Check cache of prior read. */
3126 if (program_headers != NULL)
3129 phdrs = cmalloc (elf_header.e_phnum, sizeof (Elf_Internal_Phdr));
3133 error (_("Out of memory\n"));
3138 ? get_32bit_program_headers (file, phdrs)
3139 : get_64bit_program_headers (file, phdrs))
3141 program_headers = phdrs;
3149 /* Returns 1 if the program headers were loaded. */
3152 process_program_headers (FILE *file)
3154 Elf_Internal_Phdr *segment;
3157 if (elf_header.e_phnum == 0)
3160 printf (_("\nThere are no program headers in this file.\n"));
3164 if (do_segments && !do_header)
3166 printf (_("\nElf file type is %s\n"), get_file_type (elf_header.e_type));
3167 printf (_("Entry point "));
3168 print_vma ((bfd_vma) elf_header.e_entry, PREFIX_HEX);
3169 printf (_("\nThere are %d program headers, starting at offset "),
3170 elf_header.e_phnum);
3171 print_vma ((bfd_vma) elf_header.e_phoff, DEC);
3175 if (! get_program_headers (file))
3180 if (elf_header.e_phnum > 1)
3181 printf (_("\nProgram Headers:\n"));
3183 printf (_("\nProgram Headers:\n"));
3187 (_(" Type Offset VirtAddr PhysAddr FileSiz MemSiz Flg Align\n"));
3190 (_(" Type Offset VirtAddr PhysAddr FileSiz MemSiz Flg Align\n"));
3194 (_(" Type Offset VirtAddr PhysAddr\n"));
3196 (_(" FileSiz MemSiz Flags Align\n"));
3203 for (i = 0, segment = program_headers;
3204 i < elf_header.e_phnum;
3209 printf (" %-14.14s ", get_segment_type (segment->p_type));
3213 printf ("0x%6.6lx ", (unsigned long) segment->p_offset);
3214 printf ("0x%8.8lx ", (unsigned long) segment->p_vaddr);
3215 printf ("0x%8.8lx ", (unsigned long) segment->p_paddr);
3216 printf ("0x%5.5lx ", (unsigned long) segment->p_filesz);
3217 printf ("0x%5.5lx ", (unsigned long) segment->p_memsz);
3219 (segment->p_flags & PF_R ? 'R' : ' '),
3220 (segment->p_flags & PF_W ? 'W' : ' '),
3221 (segment->p_flags & PF_X ? 'E' : ' '));
3222 printf ("%#lx", (unsigned long) segment->p_align);
3226 if ((unsigned long) segment->p_offset == segment->p_offset)
3227 printf ("0x%6.6lx ", (unsigned long) segment->p_offset);
3230 print_vma (segment->p_offset, FULL_HEX);
3234 print_vma (segment->p_vaddr, FULL_HEX);
3236 print_vma (segment->p_paddr, FULL_HEX);
3239 if ((unsigned long) segment->p_filesz == segment->p_filesz)
3240 printf ("0x%6.6lx ", (unsigned long) segment->p_filesz);
3243 print_vma (segment->p_filesz, FULL_HEX);
3247 if ((unsigned long) segment->p_memsz == segment->p_memsz)
3248 printf ("0x%6.6lx", (unsigned long) segment->p_memsz);
3251 print_vma (segment->p_offset, FULL_HEX);
3255 (segment->p_flags & PF_R ? 'R' : ' '),
3256 (segment->p_flags & PF_W ? 'W' : ' '),
3257 (segment->p_flags & PF_X ? 'E' : ' '));
3259 if ((unsigned long) segment->p_align == segment->p_align)
3260 printf ("%#lx", (unsigned long) segment->p_align);
3263 print_vma (segment->p_align, PREFIX_HEX);
3268 print_vma (segment->p_offset, FULL_HEX);
3270 print_vma (segment->p_vaddr, FULL_HEX);
3272 print_vma (segment->p_paddr, FULL_HEX);
3274 print_vma (segment->p_filesz, FULL_HEX);
3276 print_vma (segment->p_memsz, FULL_HEX);
3278 (segment->p_flags & PF_R ? 'R' : ' '),
3279 (segment->p_flags & PF_W ? 'W' : ' '),
3280 (segment->p_flags & PF_X ? 'E' : ' '));
3281 print_vma (segment->p_align, HEX);
3285 switch (segment->p_type)
3289 error (_("more than one dynamic segment\n"));
3291 /* Try to locate the .dynamic section. If there is
3292 a section header table, we can easily locate it. */
3293 if (section_headers != NULL)
3295 Elf_Internal_Shdr *sec;
3297 sec = find_section (".dynamic");
3298 if (sec == NULL || sec->sh_size == 0)
3300 error (_("no .dynamic section in the dynamic segment"));
3304 dynamic_addr = sec->sh_offset;
3305 dynamic_size = sec->sh_size;
3307 if (dynamic_addr < segment->p_offset
3308 || dynamic_addr > segment->p_offset + segment->p_filesz)
3309 warn (_("the .dynamic section is not contained within the dynamic segment"));
3310 else if (dynamic_addr > segment->p_offset)
3311 warn (_("the .dynamic section is not the first section in the dynamic segment."));
3315 /* Otherwise, we can only assume that the .dynamic
3316 section is the first section in the DYNAMIC segment. */
3317 dynamic_addr = segment->p_offset;
3318 dynamic_size = segment->p_filesz;
3323 if (fseek (file, archive_file_offset + (long) segment->p_offset,
3325 error (_("Unable to find program interpreter name\n"));
3328 program_interpreter[0] = 0;
3329 fscanf (file, "%63s", program_interpreter);
3332 printf (_("\n [Requesting program interpreter: %s]"),
3333 program_interpreter);
3339 putc ('\n', stdout);
3342 if (do_segments && section_headers != NULL && string_table != NULL)
3344 printf (_("\n Section to Segment mapping:\n"));
3345 printf (_(" Segment Sections...\n"));
3347 for (i = 0; i < elf_header.e_phnum; i++)
3350 Elf_Internal_Shdr *section;
3352 segment = program_headers + i;
3353 section = section_headers;
3355 printf (" %2.2d ", i);
3357 for (j = 1; j < elf_header.e_shnum; j++, section++)
3359 if (section->sh_size > 0
3360 /* Compare allocated sections by VMA, unallocated
3361 sections by file offset. */
3362 && (section->sh_flags & SHF_ALLOC
3363 ? (section->sh_addr >= segment->p_vaddr
3364 && section->sh_addr + section->sh_size
3365 <= segment->p_vaddr + segment->p_memsz)
3366 : ((bfd_vma) section->sh_offset >= segment->p_offset
3367 && (section->sh_offset + section->sh_size
3368 <= segment->p_offset + segment->p_filesz)))
3369 /* .tbss is special. It doesn't contribute memory space
3370 to normal segments. */
3371 && (!((section->sh_flags & SHF_TLS) != 0
3372 && section->sh_type == SHT_NOBITS)
3373 || segment->p_type == PT_TLS))
3374 printf ("%s ", SECTION_NAME (section));
3385 /* Find the file offset corresponding to VMA by using the program headers. */
3388 offset_from_vma (FILE *file, bfd_vma vma, bfd_size_type size)
3390 Elf_Internal_Phdr *seg;
3392 if (! get_program_headers (file))
3394 warn (_("Cannot interpret virtual addresses without program headers.\n"));
3398 for (seg = program_headers;
3399 seg < program_headers + elf_header.e_phnum;
3402 if (seg->p_type != PT_LOAD)
3405 if (vma >= (seg->p_vaddr & -seg->p_align)
3406 && vma + size <= seg->p_vaddr + seg->p_filesz)
3407 return vma - seg->p_vaddr + seg->p_offset;
3410 warn (_("Virtual address 0x%lx not located in any PT_LOAD segment.\n"),
3417 get_32bit_section_headers (FILE *file, unsigned int num)
3419 Elf32_External_Shdr *shdrs;
3420 Elf_Internal_Shdr *internal;
3423 shdrs = get_data (NULL, file, elf_header.e_shoff,
3424 elf_header.e_shentsize, num, _("section headers"));
3428 section_headers = cmalloc (num, sizeof (Elf_Internal_Shdr));
3430 if (section_headers == NULL)
3432 error (_("Out of memory\n"));
3436 for (i = 0, internal = section_headers;
3440 internal->sh_name = BYTE_GET (shdrs[i].sh_name);
3441 internal->sh_type = BYTE_GET (shdrs[i].sh_type);
3442 internal->sh_flags = BYTE_GET (shdrs[i].sh_flags);
3443 internal->sh_addr = BYTE_GET (shdrs[i].sh_addr);
3444 internal->sh_offset = BYTE_GET (shdrs[i].sh_offset);
3445 internal->sh_size = BYTE_GET (shdrs[i].sh_size);
3446 internal->sh_link = BYTE_GET (shdrs[i].sh_link);
3447 internal->sh_info = BYTE_GET (shdrs[i].sh_info);
3448 internal->sh_addralign = BYTE_GET (shdrs[i].sh_addralign);
3449 internal->sh_entsize = BYTE_GET (shdrs[i].sh_entsize);
3458 get_64bit_section_headers (FILE *file, unsigned int num)
3460 Elf64_External_Shdr *shdrs;
3461 Elf_Internal_Shdr *internal;
3464 shdrs = get_data (NULL, file, elf_header.e_shoff,
3465 elf_header.e_shentsize, num, _("section headers"));
3469 section_headers = cmalloc (num, sizeof (Elf_Internal_Shdr));
3471 if (section_headers == NULL)
3473 error (_("Out of memory\n"));
3477 for (i = 0, internal = section_headers;
3481 internal->sh_name = BYTE_GET (shdrs[i].sh_name);
3482 internal->sh_type = BYTE_GET (shdrs[i].sh_type);
3483 internal->sh_flags = BYTE_GET (shdrs[i].sh_flags);
3484 internal->sh_addr = BYTE_GET (shdrs[i].sh_addr);
3485 internal->sh_size = BYTE_GET (shdrs[i].sh_size);
3486 internal->sh_entsize = BYTE_GET (shdrs[i].sh_entsize);
3487 internal->sh_link = BYTE_GET (shdrs[i].sh_link);
3488 internal->sh_info = BYTE_GET (shdrs[i].sh_info);
3489 internal->sh_offset = BYTE_GET (shdrs[i].sh_offset);
3490 internal->sh_addralign = BYTE_GET (shdrs[i].sh_addralign);
3498 static Elf_Internal_Sym *
3499 get_32bit_elf_symbols (FILE *file, Elf_Internal_Shdr *section)
3501 unsigned long number;
3502 Elf32_External_Sym *esyms;
3503 Elf_External_Sym_Shndx *shndx;
3504 Elf_Internal_Sym *isyms;
3505 Elf_Internal_Sym *psym;
3508 esyms = get_data (NULL, file, section->sh_offset, 1, section->sh_size,
3514 if (symtab_shndx_hdr != NULL
3515 && (symtab_shndx_hdr->sh_link
3516 == (unsigned long) SECTION_HEADER_NUM (section - section_headers)))
3518 shndx = get_data (NULL, file, symtab_shndx_hdr->sh_offset,
3519 1, symtab_shndx_hdr->sh_size, _("symtab shndx"));
3527 number = section->sh_size / section->sh_entsize;
3528 isyms = cmalloc (number, sizeof (Elf_Internal_Sym));
3532 error (_("Out of memory\n"));
3539 for (j = 0, psym = isyms;
3543 psym->st_name = BYTE_GET (esyms[j].st_name);
3544 psym->st_value = BYTE_GET (esyms[j].st_value);
3545 psym->st_size = BYTE_GET (esyms[j].st_size);
3546 psym->st_shndx = BYTE_GET (esyms[j].st_shndx);
3547 if (psym->st_shndx == SHN_XINDEX && shndx != NULL)
3549 = byte_get ((unsigned char *) &shndx[j], sizeof (shndx[j]));
3550 psym->st_info = BYTE_GET (esyms[j].st_info);
3551 psym->st_other = BYTE_GET (esyms[j].st_other);
3561 static Elf_Internal_Sym *
3562 get_64bit_elf_symbols (FILE *file, Elf_Internal_Shdr *section)
3564 unsigned long number;
3565 Elf64_External_Sym *esyms;
3566 Elf_External_Sym_Shndx *shndx;
3567 Elf_Internal_Sym *isyms;
3568 Elf_Internal_Sym *psym;
3571 esyms = get_data (NULL, file, section->sh_offset, 1, section->sh_size,
3577 if (symtab_shndx_hdr != NULL
3578 && (symtab_shndx_hdr->sh_link
3579 == (unsigned long) SECTION_HEADER_NUM (section - section_headers)))
3581 shndx = get_data (NULL, file, symtab_shndx_hdr->sh_offset,
3582 1, symtab_shndx_hdr->sh_size, _("symtab shndx"));
3590 number = section->sh_size / section->sh_entsize;
3591 isyms = cmalloc (number, sizeof (Elf_Internal_Sym));
3595 error (_("Out of memory\n"));
3602 for (j = 0, psym = isyms;
3606 psym->st_name = BYTE_GET (esyms[j].st_name);
3607 psym->st_info = BYTE_GET (esyms[j].st_info);
3608 psym->st_other = BYTE_GET (esyms[j].st_other);
3609 psym->st_shndx = BYTE_GET (esyms[j].st_shndx);
3610 if (psym->st_shndx == SHN_XINDEX && shndx != NULL)
3612 = byte_get ((unsigned char *) &shndx[j], sizeof (shndx[j]));
3613 psym->st_value = BYTE_GET (esyms[j].st_value);
3614 psym->st_size = BYTE_GET (esyms[j].st_size);
3625 get_elf_section_flags (bfd_vma sh_flags)
3627 static char buff[1024];
3629 int field_size = is_32bit_elf ? 8 : 16;
3630 int index, size = sizeof (buff) - (field_size + 4 + 1);
3631 bfd_vma os_flags = 0;
3632 bfd_vma proc_flags = 0;
3633 bfd_vma unknown_flags = 0;
3647 { "LINK ORDER", 10 },
3648 { "OS NONCONF", 10 },
3653 if (do_section_details)
3655 sprintf (buff, "[%*.*lx]: ",
3656 field_size, field_size, (unsigned long) sh_flags);
3657 p += field_size + 4;
3664 flag = sh_flags & - sh_flags;
3667 if (do_section_details)
3671 case SHF_WRITE: index = 0; break;
3672 case SHF_ALLOC: index = 1; break;
3673 case SHF_EXECINSTR: index = 2; break;
3674 case SHF_MERGE: index = 3; break;
3675 case SHF_STRINGS: index = 4; break;
3676 case SHF_INFO_LINK: index = 5; break;
3677 case SHF_LINK_ORDER: index = 6; break;
3678 case SHF_OS_NONCONFORMING: index = 7; break;
3679 case SHF_GROUP: index = 8; break;
3680 case SHF_TLS: index = 9; break;
3689 if (p != buff + field_size + 4)
3691 if (size < (10 + 2))
3698 size -= flags [index].len;
3699 p = stpcpy (p, flags [index].str);
3701 else if (flag & SHF_MASKOS)
3703 else if (flag & SHF_MASKPROC)
3706 unknown_flags |= flag;
3712 case SHF_WRITE: *p = 'W'; break;
3713 case SHF_ALLOC: *p = 'A'; break;
3714 case SHF_EXECINSTR: *p = 'X'; break;
3715 case SHF_MERGE: *p = 'M'; break;
3716 case SHF_STRINGS: *p = 'S'; break;
3717 case SHF_INFO_LINK: *p = 'I'; break;
3718 case SHF_LINK_ORDER: *p = 'L'; break;
3719 case SHF_OS_NONCONFORMING: *p = 'O'; break;
3720 case SHF_GROUP: *p = 'G'; break;
3721 case SHF_TLS: *p = 'T'; break;
3724 if (elf_header.e_machine == EM_X86_64
3725 && flag == SHF_X86_64_LARGE)
3727 else if (flag & SHF_MASKOS)
3730 sh_flags &= ~ SHF_MASKOS;
3732 else if (flag & SHF_MASKPROC)
3735 sh_flags &= ~ SHF_MASKPROC;
3745 if (do_section_details)
3749 size -= 5 + field_size;
3750 if (p != buff + field_size + 4)
3758 sprintf (p, "OS (%*.*lx)", field_size, field_size,
3759 (unsigned long) os_flags);
3760 p += 5 + field_size;
3764 size -= 7 + field_size;
3765 if (p != buff + field_size + 4)
3773 sprintf (p, "PROC (%*.*lx)", field_size, field_size,
3774 (unsigned long) proc_flags);
3775 p += 7 + field_size;
3779 size -= 10 + field_size;
3780 if (p != buff + field_size + 4)
3788 sprintf (p, "UNKNOWN (%*.*lx)", field_size, field_size,
3789 (unsigned long) unknown_flags);
3790 p += 10 + field_size;
3799 process_section_headers (FILE *file)
3801 Elf_Internal_Shdr *section;
3804 section_headers = NULL;
3806 if (elf_header.e_shnum == 0)
3809 printf (_("\nThere are no sections in this file.\n"));
3814 if (do_sections && !do_header)
3815 printf (_("There are %d section headers, starting at offset 0x%lx:\n"),
3816 elf_header.e_shnum, (unsigned long) elf_header.e_shoff);
3820 if (! get_32bit_section_headers (file, elf_header.e_shnum))
3823 else if (! get_64bit_section_headers (file, elf_header.e_shnum))
3826 /* Read in the string table, so that we have names to display. */
3827 if (SECTION_HEADER_INDEX (elf_header.e_shstrndx) < elf_header.e_shnum)
3829 section = SECTION_HEADER (elf_header.e_shstrndx);
3831 if (section->sh_size != 0)
3833 string_table = get_data (NULL, file, section->sh_offset,
3834 1, section->sh_size, _("string table"));
3836 string_table_length = string_table != NULL ? section->sh_size : 0;
3840 /* Scan the sections for the dynamic symbol table
3841 and dynamic string table and debug sections. */
3842 dynamic_symbols = NULL;
3843 dynamic_strings = NULL;
3844 dynamic_syminfo = NULL;
3845 symtab_shndx_hdr = NULL;
3847 eh_addr_size = is_32bit_elf ? 4 : 8;
3848 switch (elf_header.e_machine)
3851 case EM_MIPS_RS3_LE:
3852 /* The 64-bit MIPS EABI uses a combination of 32-bit ELF and 64-bit
3853 FDE addresses. However, the ABI also has a semi-official ILP32
3854 variant for which the normal FDE address size rules apply.
3856 GCC 4.0 marks EABI64 objects with a dummy .gcc_compiled_longXX
3857 section, where XX is the size of longs in bits. Unfortunately,
3858 earlier compilers provided no way of distinguishing ILP32 objects
3859 from LP64 objects, so if there's any doubt, we should assume that
3860 the official LP64 form is being used. */
3861 if ((elf_header.e_flags & EF_MIPS_ABI) == E_MIPS_ABI_EABI64
3862 && find_section (".gcc_compiled_long32") == NULL)
3867 #define CHECK_ENTSIZE_VALUES(section, i, size32, size64) \
3870 size_t expected_entsize \
3871 = is_32bit_elf ? size32 : size64; \
3872 if (section->sh_entsize != expected_entsize) \
3873 error (_("Section %d has invalid sh_entsize %lx (expected %lx)\n"), \
3874 i, (unsigned long int) section->sh_entsize, \
3875 (unsigned long int) expected_entsize); \
3876 section->sh_entsize = expected_entsize; \
3879 #define CHECK_ENTSIZE(section, i, type) \
3880 CHECK_ENTSIZE_VALUES (section, i, sizeof (Elf32_External_##type), \
3881 sizeof (Elf64_External_##type))
3883 for (i = 0, section = section_headers;
3884 i < elf_header.e_shnum;
3887 char *name = SECTION_NAME (section);
3889 if (section->sh_type == SHT_DYNSYM)
3891 if (dynamic_symbols != NULL)
3893 error (_("File contains multiple dynamic symbol tables\n"));
3897 CHECK_ENTSIZE (section, i, Sym);
3898 num_dynamic_syms = section->sh_size / section->sh_entsize;
3899 dynamic_symbols = GET_ELF_SYMBOLS (file, section);
3901 else if (section->sh_type == SHT_STRTAB
3902 && streq (name, ".dynstr"))
3904 if (dynamic_strings != NULL)
3906 error (_("File contains multiple dynamic string tables\n"));
3910 dynamic_strings = get_data (NULL, file, section->sh_offset,
3911 1, section->sh_size, _("dynamic strings"));
3912 dynamic_strings_length = section->sh_size;
3914 else if (section->sh_type == SHT_SYMTAB_SHNDX)
3916 if (symtab_shndx_hdr != NULL)
3918 error (_("File contains multiple symtab shndx tables\n"));
3921 symtab_shndx_hdr = section;
3923 else if (section->sh_type == SHT_SYMTAB)
3924 CHECK_ENTSIZE (section, i, Sym);
3925 else if (section->sh_type == SHT_GROUP)
3926 CHECK_ENTSIZE_VALUES (section, i, GRP_ENTRY_SIZE, GRP_ENTRY_SIZE);
3927 else if (section->sh_type == SHT_REL)
3928 CHECK_ENTSIZE (section, i, Rel);
3929 else if (section->sh_type == SHT_RELA)
3930 CHECK_ENTSIZE (section, i, Rela);
3931 else if ((do_debugging || do_debug_info || do_debug_abbrevs
3932 || do_debug_lines || do_debug_pubnames || do_debug_aranges
3933 || do_debug_frames || do_debug_macinfo || do_debug_str
3934 || do_debug_loc || do_debug_ranges)
3935 && strneq (name, ".debug_", 7))
3940 || (do_debug_info && streq (name, "info"))
3941 || (do_debug_abbrevs && streq (name, "abbrev"))
3942 || (do_debug_lines && streq (name, "line"))
3943 || (do_debug_pubnames && streq (name, "pubnames"))
3944 || (do_debug_aranges && streq (name, "aranges"))
3945 || (do_debug_ranges && streq (name, "ranges"))
3946 || (do_debug_frames && streq (name, "frame"))
3947 || (do_debug_macinfo && streq (name, "macinfo"))
3948 || (do_debug_str && streq (name, "str"))
3949 || (do_debug_loc && streq (name, "loc"))
3951 request_dump (i, DEBUG_DUMP);
3953 /* linkonce section to be combined with .debug_info at link time. */
3954 else if ((do_debugging || do_debug_info)
3955 && strneq (name, ".gnu.linkonce.wi.", 17))
3956 request_dump (i, DEBUG_DUMP);
3957 else if (do_debug_frames && streq (name, ".eh_frame"))
3958 request_dump (i, DEBUG_DUMP);
3964 if (elf_header.e_shnum > 1)
3965 printf (_("\nSection Headers:\n"));
3967 printf (_("\nSection Header:\n"));
3971 if (do_section_details)
3973 printf (_(" [Nr] Name\n"));
3974 printf (_(" Type Addr Off Size ES Lk Inf Al\n"));
3978 (_(" [Nr] Name Type Addr Off Size ES Flg Lk Inf Al\n"));
3982 if (do_section_details)
3984 printf (_(" [Nr] Name\n"));
3985 printf (_(" Type Address Off Size ES Lk Inf Al\n"));
3989 (_(" [Nr] Name Type Address Off Size ES Flg Lk Inf Al\n"));
3993 if (do_section_details)
3995 printf (_(" [Nr] Name\n"));
3996 printf (_(" Type Address Offset Link\n"));
3997 printf (_(" Size EntSize Info Align\n"));
4001 printf (_(" [Nr] Name Type Address Offset\n"));
4002 printf (_(" Size EntSize Flags Link Info Align\n"));
4006 if (do_section_details)
4007 printf (_(" Flags\n"));
4009 for (i = 0, section = section_headers;
4010 i < elf_header.e_shnum;
4013 if (do_section_details)
4015 printf (" [%2u] %s\n",
4016 SECTION_HEADER_NUM (i),
4017 SECTION_NAME (section));
4018 if (is_32bit_elf || do_wide)
4019 printf (" %-15.15s ",
4020 get_section_type_name (section->sh_type));
4023 printf (" [%2u] %-17.17s %-15.15s ",
4024 SECTION_HEADER_NUM (i),
4025 SECTION_NAME (section),
4026 get_section_type_name (section->sh_type));
4030 print_vma (section->sh_addr, LONG_HEX);
4032 printf ( " %6.6lx %6.6lx %2.2lx",
4033 (unsigned long) section->sh_offset,
4034 (unsigned long) section->sh_size,
4035 (unsigned long) section->sh_entsize);
4037 if (do_section_details)
4038 fputs (" ", stdout);
4040 printf (" %3s ", get_elf_section_flags (section->sh_flags));
4042 printf ("%2ld %3lu %2ld\n",
4043 (unsigned long) section->sh_link,
4044 (unsigned long) section->sh_info,
4045 (unsigned long) section->sh_addralign);
4049 print_vma (section->sh_addr, LONG_HEX);
4051 if ((long) section->sh_offset == section->sh_offset)
4052 printf (" %6.6lx", (unsigned long) section->sh_offset);
4056 print_vma (section->sh_offset, LONG_HEX);
4059 if ((unsigned long) section->sh_size == section->sh_size)
4060 printf (" %6.6lx", (unsigned long) section->sh_size);
4064 print_vma (section->sh_size, LONG_HEX);
4067 if ((unsigned long) section->sh_entsize == section->sh_entsize)
4068 printf (" %2.2lx", (unsigned long) section->sh_entsize);
4072 print_vma (section->sh_entsize, LONG_HEX);
4075 if (do_section_details)
4076 fputs (" ", stdout);
4078 printf (" %3s ", get_elf_section_flags (section->sh_flags));
4080 printf ("%2ld %3lu ",
4081 (unsigned long) section->sh_link,
4082 (unsigned long) section->sh_info);
4084 if ((unsigned long) section->sh_addralign == section->sh_addralign)
4085 printf ("%2ld\n", (unsigned long) section->sh_addralign);
4088 print_vma (section->sh_addralign, DEC);
4092 else if (do_section_details)
4094 printf (" %-15.15s ",
4095 get_section_type_name (section->sh_type));
4096 print_vma (section->sh_addr, LONG_HEX);
4097 if ((long) section->sh_offset == section->sh_offset)
4098 printf (" %16.16lx", (unsigned long) section->sh_offset);
4102 print_vma (section->sh_offset, LONG_HEX);
4104 printf (" %ld\n ", (unsigned long) section->sh_link);
4105 print_vma (section->sh_size, LONG_HEX);
4107 print_vma (section->sh_entsize, LONG_HEX);
4109 printf (" %-16lu %ld\n",
4110 (unsigned long) section->sh_info,
4111 (unsigned long) section->sh_addralign);
4116 print_vma (section->sh_addr, LONG_HEX);
4117 if ((long) section->sh_offset == section->sh_offset)
4118 printf (" %8.8lx", (unsigned long) section->sh_offset);
4122 print_vma (section->sh_offset, LONG_HEX);
4125 print_vma (section->sh_size, LONG_HEX);
4127 print_vma (section->sh_entsize, LONG_HEX);
4129 printf (" %3s ", get_elf_section_flags (section->sh_flags));
4131 printf (" %2ld %3lu %ld\n",
4132 (unsigned long) section->sh_link,
4133 (unsigned long) section->sh_info,
4134 (unsigned long) section->sh_addralign);
4137 if (do_section_details)
4138 printf (" %s\n", get_elf_section_flags (section->sh_flags));
4141 if (!do_section_details)
4142 printf (_("Key to Flags:\n\
4143 W (write), A (alloc), X (execute), M (merge), S (strings)\n\
4144 I (info), L (link order), G (group), x (unknown)\n\
4145 O (extra OS processing required) o (OS specific), p (processor specific)\n"));
4151 get_group_flags (unsigned int flags)
4153 static char buff[32];
4160 snprintf (buff, sizeof (buff), _("[<unknown>: 0x%x]"), flags);
4167 process_section_groups (FILE *file)
4169 Elf_Internal_Shdr *section;
4171 struct group *group;
4172 Elf_Internal_Shdr *symtab_sec, *strtab_sec;
4173 Elf_Internal_Sym *symtab;
4177 /* Don't process section groups unless needed. */
4178 if (!do_unwind && !do_section_groups)
4181 if (elf_header.e_shnum == 0)
4183 if (do_section_groups)
4184 printf (_("\nThere are no sections in this file.\n"));
4189 if (section_headers == NULL)
4191 error (_("Section headers are not available!\n"));
4195 section_headers_groups = calloc (elf_header.e_shnum,
4196 sizeof (struct group *));
4198 if (section_headers_groups == NULL)
4200 error (_("Out of memory\n"));
4204 /* Scan the sections for the group section. */
4206 for (i = 0, section = section_headers;
4207 i < elf_header.e_shnum;
4209 if (section->sh_type == SHT_GROUP)
4212 if (group_count == 0)
4214 if (do_section_groups)
4215 printf (_("\nThere are no section groups in this file.\n"));
4220 section_groups = calloc (group_count, sizeof (struct group));
4222 if (section_groups == NULL)
4224 error (_("Out of memory\n"));
4233 for (i = 0, section = section_headers, group = section_groups;
4234 i < elf_header.e_shnum;
4237 if (section->sh_type == SHT_GROUP)
4239 char *name = SECTION_NAME (section);
4241 unsigned char *start, *indices;
4242 unsigned int entry, j, size;
4243 Elf_Internal_Shdr *sec;
4244 Elf_Internal_Sym *sym;
4246 /* Get the symbol table. */
4247 if (SECTION_HEADER_INDEX (section->sh_link) >= elf_header.e_shnum
4248 || ((sec = SECTION_HEADER (section->sh_link))->sh_type
4251 error (_("Bad sh_link in group section `%s'\n"), name);
4255 if (symtab_sec != sec)
4260 symtab = GET_ELF_SYMBOLS (file, symtab_sec);
4263 sym = symtab + section->sh_info;
4265 if (ELF_ST_TYPE (sym->st_info) == STT_SECTION)
4267 bfd_vma sec_index = SECTION_HEADER_INDEX (sym->st_shndx);
4270 error (_("Bad sh_info in group section `%s'\n"), name);
4274 group_name = SECTION_NAME (section_headers + sec_index);
4283 /* Get the string table. */
4284 if (SECTION_HEADER_INDEX (symtab_sec->sh_link)
4285 >= elf_header.e_shnum)
4294 != (sec = SECTION_HEADER (symtab_sec->sh_link)))
4299 strtab = get_data (NULL, file, strtab_sec->sh_offset,
4300 1, strtab_sec->sh_size,
4302 strtab_size = strtab != NULL ? strtab_sec->sh_size : 0;
4304 group_name = sym->st_name < strtab_size
4305 ? strtab + sym->st_name : "<corrupt>";
4308 start = get_data (NULL, file, section->sh_offset,
4309 1, section->sh_size, _("section data"));
4312 size = (section->sh_size / section->sh_entsize) - 1;
4313 entry = byte_get (indices, 4);
4316 if (do_section_groups)
4318 printf ("\n%s group section [%5u] `%s' [%s] contains %u sections:\n",
4319 get_group_flags (entry), i, name, group_name, size);
4321 printf (_(" [Index] Name\n"));
4324 group->group_index = i;
4326 for (j = 0; j < size; j++)
4328 struct group_list *g;
4330 entry = byte_get (indices, 4);
4333 if (SECTION_HEADER_INDEX (entry) >= elf_header.e_shnum)
4335 error (_("section [%5u] in group section [%5u] > maximum section [%5u]\n"),
4336 entry, i, elf_header.e_shnum - 1);
4339 else if (entry >= SHN_LORESERVE && entry <= SHN_HIRESERVE)
4341 error (_("invalid section [%5u] in group section [%5u]\n"),
4346 if (section_headers_groups [SECTION_HEADER_INDEX (entry)]
4351 error (_("section [%5u] in group section [%5u] already in group section [%5u]\n"),
4353 section_headers_groups [SECTION_HEADER_INDEX (entry)]->group_index);
4358 /* Intel C/C++ compiler may put section 0 in a
4359 section group. We just warn it the first time
4360 and ignore it afterwards. */
4361 static int warned = 0;
4364 error (_("section 0 in group section [%5u]\n"),
4365 section_headers_groups [SECTION_HEADER_INDEX (entry)]->group_index);
4371 section_headers_groups [SECTION_HEADER_INDEX (entry)]
4374 if (do_section_groups)
4376 sec = SECTION_HEADER (entry);
4377 printf (" [%5u] %s\n", entry, SECTION_NAME (sec));
4380 g = xmalloc (sizeof (struct group_list));
4381 g->section_index = entry;
4382 g->next = group->root;
4406 } dynamic_relocations [] =
4408 { "REL", DT_REL, DT_RELSZ, FALSE },
4409 { "RELA", DT_RELA, DT_RELASZ, TRUE },
4410 { "PLT", DT_JMPREL, DT_PLTRELSZ, UNKNOWN }
4413 /* Process the reloc section. */
4416 process_relocs (FILE *file)
4418 unsigned long rel_size;
4419 unsigned long rel_offset;
4425 if (do_using_dynamic)
4429 int has_dynamic_reloc;
4432 has_dynamic_reloc = 0;
4434 for (i = 0; i < ARRAY_SIZE (dynamic_relocations); i++)
4436 is_rela = dynamic_relocations [i].rela;
4437 name = dynamic_relocations [i].name;
4438 rel_size = dynamic_info [dynamic_relocations [i].size];
4439 rel_offset = dynamic_info [dynamic_relocations [i].reloc];
4441 has_dynamic_reloc |= rel_size;
4443 if (is_rela == UNKNOWN)
4445 if (dynamic_relocations [i].reloc == DT_JMPREL)
4446 switch (dynamic_info[DT_PLTREL])
4460 (_("\n'%s' relocation section at offset 0x%lx contains %ld bytes:\n"),
4461 name, rel_offset, rel_size);
4463 dump_relocations (file,
4464 offset_from_vma (file, rel_offset, rel_size),
4466 dynamic_symbols, num_dynamic_syms,
4467 dynamic_strings, dynamic_strings_length, is_rela);
4471 if (! has_dynamic_reloc)
4472 printf (_("\nThere are no dynamic relocations in this file.\n"));
4476 Elf_Internal_Shdr *section;
4480 for (i = 0, section = section_headers;
4481 i < elf_header.e_shnum;
4484 if ( section->sh_type != SHT_RELA
4485 && section->sh_type != SHT_REL)
4488 rel_offset = section->sh_offset;
4489 rel_size = section->sh_size;
4493 Elf_Internal_Shdr *strsec;
4496 printf (_("\nRelocation section "));
4498 if (string_table == NULL)
4499 printf ("%d", section->sh_name);
4501 printf (_("'%s'"), SECTION_NAME (section));
4503 printf (_(" at offset 0x%lx contains %lu entries:\n"),
4504 rel_offset, (unsigned long) (rel_size / section->sh_entsize));
4506 is_rela = section->sh_type == SHT_RELA;
4508 if (section->sh_link
4509 && SECTION_HEADER_INDEX (section->sh_link)
4510 < elf_header.e_shnum)
4512 Elf_Internal_Shdr *symsec;
4513 Elf_Internal_Sym *symtab;
4514 unsigned long nsyms;
4515 unsigned long strtablen = 0;
4516 char *strtab = NULL;
4518 symsec = SECTION_HEADER (section->sh_link);
4519 if (symsec->sh_type != SHT_SYMTAB
4520 && symsec->sh_type != SHT_DYNSYM)
4523 nsyms = symsec->sh_size / symsec->sh_entsize;
4524 symtab = GET_ELF_SYMBOLS (file, symsec);
4529 if (SECTION_HEADER_INDEX (symsec->sh_link)
4530 < elf_header.e_shnum)
4532 strsec = SECTION_HEADER (symsec->sh_link);
4534 strtab = get_data (NULL, file, strsec->sh_offset,
4537 strtablen = strtab == NULL ? 0 : strsec->sh_size;
4540 dump_relocations (file, rel_offset, rel_size,
4541 symtab, nsyms, strtab, strtablen, is_rela);
4547 dump_relocations (file, rel_offset, rel_size,
4548 NULL, 0, NULL, 0, is_rela);
4555 printf (_("\nThere are no relocations in this file.\n"));
4561 /* Process the unwind section. */
4563 #include "unwind-ia64.h"
4565 /* An absolute address consists of a section and an offset. If the
4566 section is NULL, the offset itself is the address, otherwise, the
4567 address equals to LOAD_ADDRESS(section) + offset. */
4571 unsigned short section;
4575 struct ia64_unw_aux_info
4577 struct ia64_unw_table_entry
4579 struct absaddr start;
4581 struct absaddr info;
4583 *table; /* Unwind table. */
4584 unsigned long table_len; /* Length of unwind table. */
4585 unsigned char *info; /* Unwind info. */
4586 unsigned long info_size; /* Size of unwind info. */
4587 bfd_vma info_addr; /* starting address of unwind info. */
4588 bfd_vma seg_base; /* Starting address of segment. */
4589 Elf_Internal_Sym *symtab; /* The symbol table. */
4590 unsigned long nsyms; /* Number of symbols. */
4591 char *strtab; /* The string table. */
4592 unsigned long strtab_size; /* Size of string table. */
4596 find_symbol_for_address (Elf_Internal_Sym *symtab,
4597 unsigned long nsyms,
4599 unsigned long strtab_size,
4600 struct absaddr addr,
4601 const char **symname,
4604 bfd_vma dist = 0x100000;
4605 Elf_Internal_Sym *sym, *best = NULL;
4608 for (i = 0, sym = symtab; i < nsyms; ++i, ++sym)
4610 if (ELF_ST_TYPE (sym->st_info) == STT_FUNC
4611 && sym->st_name != 0
4612 && (addr.section == SHN_UNDEF || addr.section == sym->st_shndx)
4613 && addr.offset >= sym->st_value
4614 && addr.offset - sym->st_value < dist)
4617 dist = addr.offset - sym->st_value;
4624 *symname = (best->st_name >= strtab_size
4625 ? "<corrupt>" : strtab + best->st_name);
4630 *offset = addr.offset;
4634 dump_ia64_unwind (struct ia64_unw_aux_info *aux)
4636 struct ia64_unw_table_entry *tp;
4639 for (tp = aux->table; tp < aux->table + aux->table_len; ++tp)
4643 const unsigned char *dp;
4644 const unsigned char *head;
4645 const char *procname;
4647 find_symbol_for_address (aux->symtab, aux->nsyms, aux->strtab,
4648 aux->strtab_size, tp->start, &procname, &offset);
4650 fputs ("\n<", stdout);
4654 fputs (procname, stdout);
4657 printf ("+%lx", (unsigned long) offset);
4660 fputs (">: [", stdout);
4661 print_vma (tp->start.offset, PREFIX_HEX);
4662 fputc ('-', stdout);
4663 print_vma (tp->end.offset, PREFIX_HEX);
4664 printf ("], info at +0x%lx\n",
4665 (unsigned long) (tp->info.offset - aux->seg_base));
4667 head = aux->info + (tp->info.offset - aux->info_addr);
4668 stamp = byte_get ((unsigned char *) head, sizeof (stamp));
4670 printf (" v%u, flags=0x%lx (%s%s), len=%lu bytes\n",
4671 (unsigned) UNW_VER (stamp),
4672 (unsigned long) ((stamp & UNW_FLAG_MASK) >> 32),
4673 UNW_FLAG_EHANDLER (stamp) ? " ehandler" : "",
4674 UNW_FLAG_UHANDLER (stamp) ? " uhandler" : "",
4675 (unsigned long) (eh_addr_size * UNW_LENGTH (stamp)));
4677 if (UNW_VER (stamp) != 1)
4679 printf ("\tUnknown version.\n");
4684 for (dp = head + 8; dp < head + 8 + eh_addr_size * UNW_LENGTH (stamp);)
4685 dp = unw_decode (dp, in_body, & in_body);
4690 slurp_ia64_unwind_table (FILE *file,
4691 struct ia64_unw_aux_info *aux,
4692 Elf_Internal_Shdr *sec)
4694 unsigned long size, nrelas, i;
4695 Elf_Internal_Phdr *seg;
4696 struct ia64_unw_table_entry *tep;
4697 Elf_Internal_Shdr *relsec;
4698 Elf_Internal_Rela *rela, *rp;
4699 unsigned char *table, *tp;
4700 Elf_Internal_Sym *sym;
4701 const char *relname;
4703 /* First, find the starting address of the segment that includes
4706 if (elf_header.e_phnum)
4708 if (! get_program_headers (file))
4711 for (seg = program_headers;
4712 seg < program_headers + elf_header.e_phnum;
4715 if (seg->p_type != PT_LOAD)
4718 if (sec->sh_addr >= seg->p_vaddr
4719 && (sec->sh_addr + sec->sh_size <= seg->p_vaddr + seg->p_memsz))
4721 aux->seg_base = seg->p_vaddr;
4727 /* Second, build the unwind table from the contents of the unwind section: */
4728 size = sec->sh_size;
4729 table = get_data (NULL, file, sec->sh_offset, 1, size, _("unwind table"));
4733 aux->table = xcmalloc (size / (3 * eh_addr_size), sizeof (aux->table[0]));
4735 for (tp = table; tp < table + size; tp += 3 * eh_addr_size, ++tep)
4737 tep->start.section = SHN_UNDEF;
4738 tep->end.section = SHN_UNDEF;
4739 tep->info.section = SHN_UNDEF;
4742 tep->start.offset = byte_get ((unsigned char *) tp + 0, 4);
4743 tep->end.offset = byte_get ((unsigned char *) tp + 4, 4);
4744 tep->info.offset = byte_get ((unsigned char *) tp + 8, 4);
4748 tep->start.offset = BYTE_GET ((unsigned char *) tp + 0);
4749 tep->end.offset = BYTE_GET ((unsigned char *) tp + 8);
4750 tep->info.offset = BYTE_GET ((unsigned char *) tp + 16);
4752 tep->start.offset += aux->seg_base;
4753 tep->end.offset += aux->seg_base;
4754 tep->info.offset += aux->seg_base;
4758 /* Third, apply any relocations to the unwind table: */
4760 for (relsec = section_headers;
4761 relsec < section_headers + elf_header.e_shnum;
4764 if (relsec->sh_type != SHT_RELA
4765 || SECTION_HEADER_INDEX (relsec->sh_info) >= elf_header.e_shnum
4766 || SECTION_HEADER (relsec->sh_info) != sec)
4769 if (!slurp_rela_relocs (file, relsec->sh_offset, relsec->sh_size,
4773 for (rp = rela; rp < rela + nrelas; ++rp)
4777 relname = elf_ia64_reloc_type (ELF32_R_TYPE (rp->r_info));
4778 sym = aux->symtab + ELF32_R_SYM (rp->r_info);
4782 relname = elf_ia64_reloc_type (ELF64_R_TYPE (rp->r_info));
4783 sym = aux->symtab + ELF64_R_SYM (rp->r_info);
4786 if (! strneq (relname, "R_IA64_SEGREL", 13))
4788 warn (_("Skipping unexpected relocation type %s\n"), relname);
4792 i = rp->r_offset / (3 * eh_addr_size);
4794 switch (rp->r_offset/eh_addr_size % 3)
4797 aux->table[i].start.section = sym->st_shndx;
4798 aux->table[i].start.offset += rp->r_addend + sym->st_value;
4801 aux->table[i].end.section = sym->st_shndx;
4802 aux->table[i].end.offset += rp->r_addend + sym->st_value;
4805 aux->table[i].info.section = sym->st_shndx;
4806 aux->table[i].info.offset += rp->r_addend + sym->st_value;
4816 aux->table_len = size / (3 * eh_addr_size);
4821 ia64_process_unwind (FILE *file)
4823 Elf_Internal_Shdr *sec, *unwsec = NULL, *strsec;
4824 unsigned long i, unwcount = 0, unwstart = 0;
4825 struct ia64_unw_aux_info aux;
4827 memset (& aux, 0, sizeof (aux));
4829 for (i = 0, sec = section_headers; i < elf_header.e_shnum; ++i, ++sec)
4831 if (sec->sh_type == SHT_SYMTAB
4832 && SECTION_HEADER_INDEX (sec->sh_link) < elf_header.e_shnum)
4834 aux.nsyms = sec->sh_size / sec->sh_entsize;
4835 aux.symtab = GET_ELF_SYMBOLS (file, sec);
4837 strsec = SECTION_HEADER (sec->sh_link);
4838 aux.strtab = get_data (NULL, file, strsec->sh_offset,
4839 1, strsec->sh_size, _("string table"));
4840 aux.strtab_size = aux.strtab != NULL ? strsec->sh_size : 0;
4842 else if (sec->sh_type == SHT_IA_64_UNWIND)
4847 printf (_("\nThere are no unwind sections in this file.\n"));
4849 while (unwcount-- > 0)
4854 for (i = unwstart, sec = section_headers + unwstart;
4855 i < elf_header.e_shnum; ++i, ++sec)
4856 if (sec->sh_type == SHT_IA_64_UNWIND)
4863 len = sizeof (ELF_STRING_ia64_unwind_once) - 1;
4865 if ((unwsec->sh_flags & SHF_GROUP) != 0)
4867 /* We need to find which section group it is in. */
4868 struct group_list *g = section_headers_groups [i]->root;
4870 for (; g != NULL; g = g->next)
4872 sec = SECTION_HEADER (g->section_index);
4874 if (streq (SECTION_NAME (sec), ELF_STRING_ia64_unwind_info))
4879 i = elf_header.e_shnum;
4881 else if (strneq (SECTION_NAME (unwsec), ELF_STRING_ia64_unwind_once, len))
4883 /* .gnu.linkonce.ia64unw.FOO -> .gnu.linkonce.ia64unwi.FOO. */
4884 len2 = sizeof (ELF_STRING_ia64_unwind_info_once) - 1;
4885 suffix = SECTION_NAME (unwsec) + len;
4886 for (i = 0, sec = section_headers; i < elf_header.e_shnum;
4888 if (strneq (SECTION_NAME (sec), ELF_STRING_ia64_unwind_info_once, len2)
4889 && streq (SECTION_NAME (sec) + len2, suffix))
4894 /* .IA_64.unwindFOO -> .IA_64.unwind_infoFOO
4895 .IA_64.unwind or BAR -> .IA_64.unwind_info. */
4896 len = sizeof (ELF_STRING_ia64_unwind) - 1;
4897 len2 = sizeof (ELF_STRING_ia64_unwind_info) - 1;
4899 if (strneq (SECTION_NAME (unwsec), ELF_STRING_ia64_unwind, len))
4900 suffix = SECTION_NAME (unwsec) + len;
4901 for (i = 0, sec = section_headers; i < elf_header.e_shnum;
4903 if (strneq (SECTION_NAME (sec), ELF_STRING_ia64_unwind_info, len2)
4904 && streq (SECTION_NAME (sec) + len2, suffix))
4908 if (i == elf_header.e_shnum)
4910 printf (_("\nCould not find unwind info section for "));
4912 if (string_table == NULL)
4913 printf ("%d", unwsec->sh_name);
4915 printf (_("'%s'"), SECTION_NAME (unwsec));
4919 aux.info_size = sec->sh_size;
4920 aux.info_addr = sec->sh_addr;
4921 aux.info = get_data (NULL, file, sec->sh_offset, 1, aux.info_size,
4924 printf (_("\nUnwind section "));
4926 if (string_table == NULL)
4927 printf ("%d", unwsec->sh_name);
4929 printf (_("'%s'"), SECTION_NAME (unwsec));
4931 printf (_(" at offset 0x%lx contains %lu entries:\n"),
4932 (unsigned long) unwsec->sh_offset,
4933 (unsigned long) (unwsec->sh_size / (3 * eh_addr_size)));
4935 (void) slurp_ia64_unwind_table (file, & aux, unwsec);
4937 if (aux.table_len > 0)
4938 dump_ia64_unwind (& aux);
4941 free ((char *) aux.table);
4943 free ((char *) aux.info);
4952 free ((char *) aux.strtab);
4957 struct hppa_unw_aux_info
4959 struct hppa_unw_table_entry
4961 struct absaddr start;
4963 unsigned int Cannot_unwind:1; /* 0 */
4964 unsigned int Millicode:1; /* 1 */
4965 unsigned int Millicode_save_sr0:1; /* 2 */
4966 unsigned int Region_description:2; /* 3..4 */
4967 unsigned int reserved1:1; /* 5 */
4968 unsigned int Entry_SR:1; /* 6 */
4969 unsigned int Entry_FR:4; /* number saved */ /* 7..10 */
4970 unsigned int Entry_GR:5; /* number saved */ /* 11..15 */
4971 unsigned int Args_stored:1; /* 16 */
4972 unsigned int Variable_Frame:1; /* 17 */
4973 unsigned int Separate_Package_Body:1; /* 18 */
4974 unsigned int Frame_Extension_Millicode:1; /* 19 */
4975 unsigned int Stack_Overflow_Check:1; /* 20 */
4976 unsigned int Two_Instruction_SP_Increment:1; /* 21 */
4977 unsigned int Ada_Region:1; /* 22 */
4978 unsigned int cxx_info:1; /* 23 */
4979 unsigned int cxx_try_catch:1; /* 24 */
4980 unsigned int sched_entry_seq:1; /* 25 */
4981 unsigned int reserved2:1; /* 26 */
4982 unsigned int Save_SP:1; /* 27 */
4983 unsigned int Save_RP:1; /* 28 */
4984 unsigned int Save_MRP_in_frame:1; /* 29 */
4985 unsigned int extn_ptr_defined:1; /* 30 */
4986 unsigned int Cleanup_defined:1; /* 31 */
4988 unsigned int MPE_XL_interrupt_marker:1; /* 0 */
4989 unsigned int HP_UX_interrupt_marker:1; /* 1 */
4990 unsigned int Large_frame:1; /* 2 */
4991 unsigned int Pseudo_SP_Set:1; /* 3 */
4992 unsigned int reserved4:1; /* 4 */
4993 unsigned int Total_frame_size:27; /* 5..31 */
4995 *table; /* Unwind table. */
4996 unsigned long table_len; /* Length of unwind table. */
4997 bfd_vma seg_base; /* Starting address of segment. */
4998 Elf_Internal_Sym *symtab; /* The symbol table. */
4999 unsigned long nsyms; /* Number of symbols. */
5000 char *strtab; /* The string table. */
5001 unsigned long strtab_size; /* Size of string table. */
5005 dump_hppa_unwind (struct hppa_unw_aux_info *aux)
5007 struct hppa_unw_table_entry *tp;
5009 for (tp = aux->table; tp < aux->table + aux->table_len; ++tp)
5012 const char *procname;
5014 find_symbol_for_address (aux->symtab, aux->nsyms, aux->strtab,
5015 aux->strtab_size, tp->start, &procname,
5018 fputs ("\n<", stdout);
5022 fputs (procname, stdout);
5025 printf ("+%lx", (unsigned long) offset);
5028 fputs (">: [", stdout);
5029 print_vma (tp->start.offset, PREFIX_HEX);
5030 fputc ('-', stdout);
5031 print_vma (tp->end.offset, PREFIX_HEX);
5034 #define PF(_m) if (tp->_m) printf (#_m " ");
5035 #define PV(_m) if (tp->_m) printf (#_m "=%d ", tp->_m);
5038 PF(Millicode_save_sr0);
5039 /* PV(Region_description); */
5045 PF(Separate_Package_Body);
5046 PF(Frame_Extension_Millicode);
5047 PF(Stack_Overflow_Check);
5048 PF(Two_Instruction_SP_Increment);
5052 PF(sched_entry_seq);
5055 PF(Save_MRP_in_frame);
5056 PF(extn_ptr_defined);
5057 PF(Cleanup_defined);
5058 PF(MPE_XL_interrupt_marker);
5059 PF(HP_UX_interrupt_marker);
5062 PV(Total_frame_size);
5071 slurp_hppa_unwind_table (FILE *file,
5072 struct hppa_unw_aux_info *aux,
5073 Elf_Internal_Shdr *sec)
5075 unsigned long size, unw_ent_size, nentries, nrelas, i;
5076 Elf_Internal_Phdr *seg;
5077 struct hppa_unw_table_entry *tep;
5078 Elf_Internal_Shdr *relsec;
5079 Elf_Internal_Rela *rela, *rp;
5080 unsigned char *table, *tp;
5081 Elf_Internal_Sym *sym;
5082 const char *relname;
5084 /* First, find the starting address of the segment that includes
5087 if (elf_header.e_phnum)
5089 if (! get_program_headers (file))
5092 for (seg = program_headers;
5093 seg < program_headers + elf_header.e_phnum;
5096 if (seg->p_type != PT_LOAD)
5099 if (sec->sh_addr >= seg->p_vaddr
5100 && (sec->sh_addr + sec->sh_size <= seg->p_vaddr + seg->p_memsz))
5102 aux->seg_base = seg->p_vaddr;
5108 /* Second, build the unwind table from the contents of the unwind
5110 size = sec->sh_size;
5111 table = get_data (NULL, file, sec->sh_offset, 1, size, _("unwind table"));
5116 nentries = size / unw_ent_size;
5117 size = unw_ent_size * nentries;
5119 tep = aux->table = xcmalloc (nentries, sizeof (aux->table[0]));
5121 for (tp = table; tp < table + size; tp += unw_ent_size, ++tep)
5123 unsigned int tmp1, tmp2;
5125 tep->start.section = SHN_UNDEF;
5126 tep->end.section = SHN_UNDEF;
5128 tep->start.offset = byte_get ((unsigned char *) tp + 0, 4);
5129 tep->end.offset = byte_get ((unsigned char *) tp + 4, 4);
5130 tmp1 = byte_get ((unsigned char *) tp + 8, 4);
5131 tmp2 = byte_get ((unsigned char *) tp + 12, 4);
5133 tep->start.offset += aux->seg_base;
5134 tep->end.offset += aux->seg_base;
5136 tep->Cannot_unwind = (tmp1 >> 31) & 0x1;
5137 tep->Millicode = (tmp1 >> 30) & 0x1;
5138 tep->Millicode_save_sr0 = (tmp1 >> 29) & 0x1;
5139 tep->Region_description = (tmp1 >> 27) & 0x3;
5140 tep->reserved1 = (tmp1 >> 26) & 0x1;
5141 tep->Entry_SR = (tmp1 >> 25) & 0x1;
5142 tep->Entry_FR = (tmp1 >> 21) & 0xf;
5143 tep->Entry_GR = (tmp1 >> 16) & 0x1f;
5144 tep->Args_stored = (tmp1 >> 15) & 0x1;
5145 tep->Variable_Frame = (tmp1 >> 14) & 0x1;
5146 tep->Separate_Package_Body = (tmp1 >> 13) & 0x1;
5147 tep->Frame_Extension_Millicode = (tmp1 >> 12) & 0x1;
5148 tep->Stack_Overflow_Check = (tmp1 >> 11) & 0x1;
5149 tep->Two_Instruction_SP_Increment = (tmp1 >> 10) & 0x1;
5150 tep->Ada_Region = (tmp1 >> 9) & 0x1;
5151 tep->cxx_info = (tmp1 >> 8) & 0x1;
5152 tep->cxx_try_catch = (tmp1 >> 7) & 0x1;
5153 tep->sched_entry_seq = (tmp1 >> 6) & 0x1;
5154 tep->reserved2 = (tmp1 >> 5) & 0x1;
5155 tep->Save_SP = (tmp1 >> 4) & 0x1;
5156 tep->Save_RP = (tmp1 >> 3) & 0x1;
5157 tep->Save_MRP_in_frame = (tmp1 >> 2) & 0x1;
5158 tep->extn_ptr_defined = (tmp1 >> 1) & 0x1;
5159 tep->Cleanup_defined = tmp1 & 0x1;
5161 tep->MPE_XL_interrupt_marker = (tmp2 >> 31) & 0x1;
5162 tep->HP_UX_interrupt_marker = (tmp2 >> 30) & 0x1;
5163 tep->Large_frame = (tmp2 >> 29) & 0x1;
5164 tep->Pseudo_SP_Set = (tmp2 >> 28) & 0x1;
5165 tep->reserved4 = (tmp2 >> 27) & 0x1;
5166 tep->Total_frame_size = tmp2 & 0x7ffffff;
5170 /* Third, apply any relocations to the unwind table. */
5172 for (relsec = section_headers;
5173 relsec < section_headers + elf_header.e_shnum;
5176 if (relsec->sh_type != SHT_RELA
5177 || SECTION_HEADER_INDEX (relsec->sh_info) >= elf_header.e_shnum
5178 || SECTION_HEADER (relsec->sh_info) != sec)
5181 if (!slurp_rela_relocs (file, relsec->sh_offset, relsec->sh_size,
5185 for (rp = rela; rp < rela + nrelas; ++rp)
5189 relname = elf_hppa_reloc_type (ELF32_R_TYPE (rp->r_info));
5190 sym = aux->symtab + ELF32_R_SYM (rp->r_info);
5194 relname = elf_hppa_reloc_type (ELF64_R_TYPE (rp->r_info));
5195 sym = aux->symtab + ELF64_R_SYM (rp->r_info);
5198 /* R_PARISC_SEGREL32 or R_PARISC_SEGREL64. */
5199 if (strncmp (relname, "R_PARISC_SEGREL", 15) != 0)
5201 warn (_("Skipping unexpected relocation type %s\n"), relname);
5205 i = rp->r_offset / unw_ent_size;
5207 switch ((rp->r_offset % unw_ent_size) / eh_addr_size)
5210 aux->table[i].start.section = sym->st_shndx;
5211 aux->table[i].start.offset += sym->st_value + rp->r_addend;
5214 aux->table[i].end.section = sym->st_shndx;
5215 aux->table[i].end.offset += sym->st_value + rp->r_addend;
5225 aux->table_len = nentries;
5231 hppa_process_unwind (FILE *file)
5233 struct hppa_unw_aux_info aux;
5234 Elf_Internal_Shdr *unwsec = NULL;
5235 Elf_Internal_Shdr *strsec;
5236 Elf_Internal_Shdr *sec;
5239 memset (& aux, 0, sizeof (aux));
5241 if (string_table == NULL)
5244 for (i = 0, sec = section_headers; i < elf_header.e_shnum; ++i, ++sec)
5246 if (sec->sh_type == SHT_SYMTAB
5247 && SECTION_HEADER_INDEX (sec->sh_link) < elf_header.e_shnum)
5249 aux.nsyms = sec->sh_size / sec->sh_entsize;
5250 aux.symtab = GET_ELF_SYMBOLS (file, sec);
5252 strsec = SECTION_HEADER (sec->sh_link);
5253 aux.strtab = get_data (NULL, file, strsec->sh_offset,
5254 1, strsec->sh_size, _("string table"));
5255 aux.strtab_size = aux.strtab != NULL ? strsec->sh_size : 0;
5257 else if (streq (SECTION_NAME (sec), ".PARISC.unwind"))
5262 printf (_("\nThere are no unwind sections in this file.\n"));
5264 for (i = 0, sec = section_headers; i < elf_header.e_shnum; ++i, ++sec)
5266 if (streq (SECTION_NAME (sec), ".PARISC.unwind"))
5268 printf (_("\nUnwind section "));
5269 printf (_("'%s'"), SECTION_NAME (sec));
5271 printf (_(" at offset 0x%lx contains %lu entries:\n"),
5272 (unsigned long) sec->sh_offset,
5273 (unsigned long) (sec->sh_size / (2 * eh_addr_size + 8)));
5275 slurp_hppa_unwind_table (file, &aux, sec);
5276 if (aux.table_len > 0)
5277 dump_hppa_unwind (&aux);
5280 free ((char *) aux.table);
5288 free ((char *) aux.strtab);
5294 process_unwind (FILE *file)
5296 struct unwind_handler {
5298 int (*handler)(FILE *file);
5300 { EM_IA_64, ia64_process_unwind },
5301 { EM_PARISC, hppa_process_unwind },
5309 for (i = 0; handlers[i].handler != NULL; i++)
5310 if (elf_header.e_machine == handlers[i].machtype)
5311 return handlers[i].handler (file);
5313 printf (_("\nThere are no unwind sections in this file.\n"));
5318 dynamic_section_mips_val (Elf_Internal_Dyn *entry)
5320 switch (entry->d_tag)
5323 if (entry->d_un.d_val == 0)
5327 static const char * opts[] =
5329 "QUICKSTART", "NOTPOT", "NO_LIBRARY_REPLACEMENT",
5330 "NO_MOVE", "SGI_ONLY", "GUARANTEE_INIT", "DELTA_C_PLUS_PLUS",
5331 "GUARANTEE_START_INIT", "PIXIE", "DEFAULT_DELAY_LOAD",
5332 "REQUICKSTART", "REQUICKSTARTED", "CORD", "NO_UNRES_UNDEF",
5337 for (cnt = 0; cnt < NUM_ELEM (opts); ++cnt)
5338 if (entry->d_un.d_val & (1 << cnt))
5340 printf ("%s%s", first ? "" : " ", opts[cnt]);
5347 case DT_MIPS_IVERSION:
5348 if (VALID_DYNAMIC_NAME (entry->d_un.d_val))
5349 printf ("Interface Version: %s\n", GET_DYNAMIC_NAME (entry->d_un.d_val));
5351 printf ("<corrupt: %ld>\n", (long) entry->d_un.d_ptr);
5354 case DT_MIPS_TIME_STAMP:
5359 time_t time = entry->d_un.d_val;
5360 tmp = gmtime (&time);
5361 snprintf (timebuf, sizeof (timebuf), "%04u-%02u-%02uT%02u:%02u:%02u",
5362 tmp->tm_year + 1900, tmp->tm_mon + 1, tmp->tm_mday,
5363 tmp->tm_hour, tmp->tm_min, tmp->tm_sec);
5364 printf ("Time Stamp: %s\n", timebuf);
5368 case DT_MIPS_RLD_VERSION:
5369 case DT_MIPS_LOCAL_GOTNO:
5370 case DT_MIPS_CONFLICTNO:
5371 case DT_MIPS_LIBLISTNO:
5372 case DT_MIPS_SYMTABNO:
5373 case DT_MIPS_UNREFEXTNO:
5374 case DT_MIPS_HIPAGENO:
5375 case DT_MIPS_DELTA_CLASS_NO:
5376 case DT_MIPS_DELTA_INSTANCE_NO:
5377 case DT_MIPS_DELTA_RELOC_NO:
5378 case DT_MIPS_DELTA_SYM_NO:
5379 case DT_MIPS_DELTA_CLASSSYM_NO:
5380 case DT_MIPS_COMPACT_SIZE:
5381 printf ("%ld\n", (long) entry->d_un.d_ptr);
5385 printf ("%#lx\n", (long) entry->d_un.d_ptr);
5391 dynamic_section_parisc_val (Elf_Internal_Dyn *entry)
5393 switch (entry->d_tag)
5395 case DT_HP_DLD_FLAGS:
5404 { DT_HP_DEBUG_PRIVATE, "HP_DEBUG_PRIVATE" },
5405 { DT_HP_DEBUG_CALLBACK, "HP_DEBUG_CALLBACK" },
5406 { DT_HP_DEBUG_CALLBACK_BOR, "HP_DEBUG_CALLBACK_BOR" },
5407 { DT_HP_NO_ENVVAR, "HP_NO_ENVVAR" },
5408 { DT_HP_BIND_NOW, "HP_BIND_NOW" },
5409 { DT_HP_BIND_NONFATAL, "HP_BIND_NONFATAL" },
5410 { DT_HP_BIND_VERBOSE, "HP_BIND_VERBOSE" },
5411 { DT_HP_BIND_RESTRICTED, "HP_BIND_RESTRICTED" },
5412 { DT_HP_BIND_SYMBOLIC, "HP_BIND_SYMBOLIC" },
5413 { DT_HP_RPATH_FIRST, "HP_RPATH_FIRST" },
5414 { DT_HP_BIND_DEPTH_FIRST, "HP_BIND_DEPTH_FIRST" },
5415 { DT_HP_GST, "HP_GST" },
5416 { DT_HP_SHLIB_FIXED, "HP_SHLIB_FIXED" },
5417 { DT_HP_MERGE_SHLIB_SEG, "HP_MERGE_SHLIB_SEG" },
5418 { DT_HP_NODELETE, "HP_NODELETE" },
5419 { DT_HP_GROUP, "HP_GROUP" },
5420 { DT_HP_PROTECT_LINKAGE_TABLE, "HP_PROTECT_LINKAGE_TABLE" }
5424 bfd_vma val = entry->d_un.d_val;
5426 for (cnt = 0; cnt < sizeof (flags) / sizeof (flags[0]); ++cnt)
5427 if (val & flags[cnt].bit)
5431 fputs (flags[cnt].str, stdout);
5433 val ^= flags[cnt].bit;
5436 if (val != 0 || first)
5440 print_vma (val, HEX);
5446 print_vma (entry->d_un.d_ptr, PREFIX_HEX);
5453 dynamic_section_ia64_val (Elf_Internal_Dyn *entry)
5455 switch (entry->d_tag)
5457 case DT_IA_64_PLT_RESERVE:
5458 /* First 3 slots reserved. */
5459 print_vma (entry->d_un.d_ptr, PREFIX_HEX);
5461 print_vma (entry->d_un.d_ptr + (3 * 8), PREFIX_HEX);
5465 print_vma (entry->d_un.d_ptr, PREFIX_HEX);
5472 get_32bit_dynamic_section (FILE *file)
5474 Elf32_External_Dyn *edyn, *ext;
5475 Elf_Internal_Dyn *entry;
5477 edyn = get_data (NULL, file, dynamic_addr, 1, dynamic_size,
5478 _("dynamic section"));
5482 /* SGI's ELF has more than one section in the DYNAMIC segment, and we
5483 might not have the luxury of section headers. Look for the DT_NULL
5484 terminator to determine the number of entries. */
5485 for (ext = edyn, dynamic_nent = 0;
5486 (char *) ext < (char *) edyn + dynamic_size;
5490 if (BYTE_GET (ext->d_tag) == DT_NULL)
5494 dynamic_section = cmalloc (dynamic_nent, sizeof (*entry));
5495 if (dynamic_section == NULL)
5497 error (_("Out of memory\n"));
5502 for (ext = edyn, entry = dynamic_section;
5503 entry < dynamic_section + dynamic_nent;
5506 entry->d_tag = BYTE_GET (ext->d_tag);
5507 entry->d_un.d_val = BYTE_GET (ext->d_un.d_val);
5516 get_64bit_dynamic_section (FILE *file)
5518 Elf64_External_Dyn *edyn, *ext;
5519 Elf_Internal_Dyn *entry;
5521 edyn = get_data (NULL, file, dynamic_addr, 1, dynamic_size,
5522 _("dynamic section"));
5526 /* SGI's ELF has more than one section in the DYNAMIC segment, and we
5527 might not have the luxury of section headers. Look for the DT_NULL
5528 terminator to determine the number of entries. */
5529 for (ext = edyn, dynamic_nent = 0;
5530 (char *) ext < (char *) edyn + dynamic_size;
5534 if (BYTE_GET (ext->d_tag) == DT_NULL)
5538 dynamic_section = cmalloc (dynamic_nent, sizeof (*entry));
5539 if (dynamic_section == NULL)
5541 error (_("Out of memory\n"));
5546 for (ext = edyn, entry = dynamic_section;
5547 entry < dynamic_section + dynamic_nent;
5550 entry->d_tag = BYTE_GET (ext->d_tag);
5551 entry->d_un.d_val = BYTE_GET (ext->d_un.d_val);
5560 print_dynamic_flags (bfd_vma flags)
5568 flag = flags & - flags;
5578 case DF_ORIGIN: fputs ("ORIGIN", stdout); break;
5579 case DF_SYMBOLIC: fputs ("SYMBOLIC", stdout); break;
5580 case DF_TEXTREL: fputs ("TEXTREL", stdout); break;
5581 case DF_BIND_NOW: fputs ("BIND_NOW", stdout); break;
5582 case DF_STATIC_TLS: fputs ("STATIC_TLS", stdout); break;
5583 default: fputs ("unknown", stdout); break;
5589 /* Parse and display the contents of the dynamic section. */
5592 process_dynamic_section (FILE *file)
5594 Elf_Internal_Dyn *entry;
5596 if (dynamic_size == 0)
5599 printf (_("\nThere is no dynamic section in this file.\n"));
5606 if (! get_32bit_dynamic_section (file))
5609 else if (! get_64bit_dynamic_section (file))
5612 /* Find the appropriate symbol table. */
5613 if (dynamic_symbols == NULL)
5615 for (entry = dynamic_section;
5616 entry < dynamic_section + dynamic_nent;
5619 Elf_Internal_Shdr section;
5621 if (entry->d_tag != DT_SYMTAB)
5624 dynamic_info[DT_SYMTAB] = entry->d_un.d_val;
5626 /* Since we do not know how big the symbol table is,
5627 we default to reading in the entire file (!) and
5628 processing that. This is overkill, I know, but it
5630 section.sh_offset = offset_from_vma (file, entry->d_un.d_val, 0);
5632 if (archive_file_offset != 0)
5633 section.sh_size = archive_file_size - section.sh_offset;
5636 if (fseek (file, 0, SEEK_END))
5637 error (_("Unable to seek to end of file!"));
5639 section.sh_size = ftell (file) - section.sh_offset;
5643 section.sh_entsize = sizeof (Elf32_External_Sym);
5645 section.sh_entsize = sizeof (Elf64_External_Sym);
5647 num_dynamic_syms = section.sh_size / section.sh_entsize;
5648 if (num_dynamic_syms < 1)
5650 error (_("Unable to determine the number of symbols to load\n"));
5654 dynamic_symbols = GET_ELF_SYMBOLS (file, §ion);
5658 /* Similarly find a string table. */
5659 if (dynamic_strings == NULL)
5661 for (entry = dynamic_section;
5662 entry < dynamic_section + dynamic_nent;
5665 unsigned long offset;
5668 if (entry->d_tag != DT_STRTAB)
5671 dynamic_info[DT_STRTAB] = entry->d_un.d_val;
5673 /* Since we do not know how big the string table is,
5674 we default to reading in the entire file (!) and
5675 processing that. This is overkill, I know, but it
5678 offset = offset_from_vma (file, entry->d_un.d_val, 0);
5680 if (archive_file_offset != 0)
5681 str_tab_len = archive_file_size - offset;
5684 if (fseek (file, 0, SEEK_END))
5685 error (_("Unable to seek to end of file\n"));
5686 str_tab_len = ftell (file) - offset;
5689 if (str_tab_len < 1)
5692 (_("Unable to determine the length of the dynamic string table\n"));
5696 dynamic_strings = get_data (NULL, file, offset, 1, str_tab_len,
5697 _("dynamic string table"));
5698 dynamic_strings_length = str_tab_len;
5703 /* And find the syminfo section if available. */
5704 if (dynamic_syminfo == NULL)
5706 unsigned long syminsz = 0;
5708 for (entry = dynamic_section;
5709 entry < dynamic_section + dynamic_nent;
5712 if (entry->d_tag == DT_SYMINENT)
5714 /* Note: these braces are necessary to avoid a syntax
5715 error from the SunOS4 C compiler. */
5716 assert (sizeof (Elf_External_Syminfo) == entry->d_un.d_val);
5718 else if (entry->d_tag == DT_SYMINSZ)
5719 syminsz = entry->d_un.d_val;
5720 else if (entry->d_tag == DT_SYMINFO)
5721 dynamic_syminfo_offset = offset_from_vma (file, entry->d_un.d_val,
5725 if (dynamic_syminfo_offset != 0 && syminsz != 0)
5727 Elf_External_Syminfo *extsyminfo, *extsym;
5728 Elf_Internal_Syminfo *syminfo;
5730 /* There is a syminfo section. Read the data. */
5731 extsyminfo = get_data (NULL, file, dynamic_syminfo_offset, 1,
5732 syminsz, _("symbol information"));
5736 dynamic_syminfo = malloc (syminsz);
5737 if (dynamic_syminfo == NULL)
5739 error (_("Out of memory\n"));
5743 dynamic_syminfo_nent = syminsz / sizeof (Elf_External_Syminfo);
5744 for (syminfo = dynamic_syminfo, extsym = extsyminfo;
5745 syminfo < dynamic_syminfo + dynamic_syminfo_nent;
5746 ++syminfo, ++extsym)
5748 syminfo->si_boundto = BYTE_GET (extsym->si_boundto);
5749 syminfo->si_flags = BYTE_GET (extsym->si_flags);
5756 if (do_dynamic && dynamic_addr)
5757 printf (_("\nDynamic section at offset 0x%lx contains %u entries:\n"),
5758 dynamic_addr, dynamic_nent);
5760 printf (_(" Tag Type Name/Value\n"));
5762 for (entry = dynamic_section;
5763 entry < dynamic_section + dynamic_nent;
5771 print_vma (entry->d_tag, FULL_HEX);
5772 dtype = get_dynamic_type (entry->d_tag);
5773 printf (" (%s)%*s", dtype,
5774 ((is_32bit_elf ? 27 : 19)
5775 - (int) strlen (dtype)),
5779 switch (entry->d_tag)
5783 print_dynamic_flags (entry->d_un.d_val);
5793 switch (entry->d_tag)
5796 printf (_("Auxiliary library"));
5800 printf (_("Filter library"));
5804 printf (_("Configuration file"));
5808 printf (_("Dependency audit library"));
5812 printf (_("Audit library"));
5816 if (VALID_DYNAMIC_NAME (entry->d_un.d_val))
5817 printf (": [%s]\n", GET_DYNAMIC_NAME (entry->d_un.d_val));
5821 print_vma (entry->d_un.d_val, PREFIX_HEX);
5830 printf (_("Flags:"));
5832 if (entry->d_un.d_val == 0)
5833 printf (_(" None\n"));
5836 unsigned long int val = entry->d_un.d_val;
5838 if (val & DTF_1_PARINIT)
5840 printf (" PARINIT");
5841 val ^= DTF_1_PARINIT;
5843 if (val & DTF_1_CONFEXP)
5845 printf (" CONFEXP");
5846 val ^= DTF_1_CONFEXP;
5849 printf (" %lx", val);
5858 printf (_("Flags:"));
5860 if (entry->d_un.d_val == 0)
5861 printf (_(" None\n"));
5864 unsigned long int val = entry->d_un.d_val;
5866 if (val & DF_P1_LAZYLOAD)
5868 printf (" LAZYLOAD");
5869 val ^= DF_P1_LAZYLOAD;
5871 if (val & DF_P1_GROUPPERM)
5873 printf (" GROUPPERM");
5874 val ^= DF_P1_GROUPPERM;
5877 printf (" %lx", val);
5886 printf (_("Flags:"));
5887 if (entry->d_un.d_val == 0)
5888 printf (_(" None\n"));
5891 unsigned long int val = entry->d_un.d_val;
5898 if (val & DF_1_GLOBAL)
5903 if (val & DF_1_GROUP)
5908 if (val & DF_1_NODELETE)
5910 printf (" NODELETE");
5911 val ^= DF_1_NODELETE;
5913 if (val & DF_1_LOADFLTR)
5915 printf (" LOADFLTR");
5916 val ^= DF_1_LOADFLTR;
5918 if (val & DF_1_INITFIRST)
5920 printf (" INITFIRST");
5921 val ^= DF_1_INITFIRST;
5923 if (val & DF_1_NOOPEN)
5928 if (val & DF_1_ORIGIN)
5933 if (val & DF_1_DIRECT)
5938 if (val & DF_1_TRANS)
5943 if (val & DF_1_INTERPOSE)
5945 printf (" INTERPOSE");
5946 val ^= DF_1_INTERPOSE;
5948 if (val & DF_1_NODEFLIB)
5950 printf (" NODEFLIB");
5951 val ^= DF_1_NODEFLIB;
5953 if (val & DF_1_NODUMP)
5958 if (val & DF_1_CONLFAT)
5960 printf (" CONLFAT");
5961 val ^= DF_1_CONLFAT;
5964 printf (" %lx", val);
5971 dynamic_info[entry->d_tag] = entry->d_un.d_val;
5973 puts (get_dynamic_type (entry->d_un.d_val));
5993 dynamic_info[entry->d_tag] = entry->d_un.d_val;
5999 if (VALID_DYNAMIC_NAME (entry->d_un.d_val))
6000 name = GET_DYNAMIC_NAME (entry->d_un.d_val);
6006 switch (entry->d_tag)
6009 printf (_("Shared library: [%s]"), name);
6011 if (streq (name, program_interpreter))
6012 printf (_(" program interpreter"));
6016 printf (_("Library soname: [%s]"), name);
6020 printf (_("Library rpath: [%s]"), name);
6024 printf (_("Library runpath: [%s]"), name);
6028 print_vma (entry->d_un.d_val, PREFIX_HEX);
6033 print_vma (entry->d_un.d_val, PREFIX_HEX);
6046 dynamic_info[entry->d_tag] = entry->d_un.d_val;
6050 case DT_INIT_ARRAYSZ:
6051 case DT_FINI_ARRAYSZ:
6052 case DT_GNU_CONFLICTSZ:
6053 case DT_GNU_LIBLISTSZ:
6056 print_vma (entry->d_un.d_val, UNSIGNED);
6057 printf (" (bytes)\n");
6067 print_vma (entry->d_un.d_val, UNSIGNED);
6080 if (entry->d_tag == DT_USED
6081 && VALID_DYNAMIC_NAME (entry->d_un.d_val))
6083 char *name = GET_DYNAMIC_NAME (entry->d_un.d_val);
6087 printf (_("Not needed object: [%s]\n"), name);
6092 print_vma (entry->d_un.d_val, PREFIX_HEX);
6098 /* The value of this entry is ignored. */
6103 case DT_GNU_PRELINKED:
6107 time_t time = entry->d_un.d_val;
6109 tmp = gmtime (&time);
6110 printf ("%04u-%02u-%02uT%02u:%02u:%02u\n",
6111 tmp->tm_year + 1900, tmp->tm_mon + 1, tmp->tm_mday,
6112 tmp->tm_hour, tmp->tm_min, tmp->tm_sec);
6118 if ((entry->d_tag >= DT_VERSYM) && (entry->d_tag <= DT_VERNEEDNUM))
6119 version_info[DT_VERSIONTAGIDX (entry->d_tag)] =
6124 switch (elf_header.e_machine)
6127 case EM_MIPS_RS3_LE:
6128 dynamic_section_mips_val (entry);
6131 dynamic_section_parisc_val (entry);
6134 dynamic_section_ia64_val (entry);
6137 print_vma (entry->d_un.d_val, PREFIX_HEX);
6149 get_ver_flags (unsigned int flags)
6151 static char buff[32];
6158 if (flags & VER_FLG_BASE)
6159 strcat (buff, "BASE ");
6161 if (flags & VER_FLG_WEAK)
6163 if (flags & VER_FLG_BASE)
6164 strcat (buff, "| ");
6166 strcat (buff, "WEAK ");
6169 if (flags & ~(VER_FLG_BASE | VER_FLG_WEAK))
6170 strcat (buff, "| <unknown>");
6175 /* Display the contents of the version sections. */
6177 process_version_sections (FILE *file)
6179 Elf_Internal_Shdr *section;
6186 for (i = 0, section = section_headers;
6187 i < elf_header.e_shnum;
6190 switch (section->sh_type)
6192 case SHT_GNU_verdef:
6194 Elf_External_Verdef *edefs;
6201 (_("\nVersion definition section '%s' contains %ld entries:\n"),
6202 SECTION_NAME (section), section->sh_info);
6204 printf (_(" Addr: 0x"));
6205 printf_vma (section->sh_addr);
6206 printf (_(" Offset: %#08lx Link: %lx (%s)\n"),
6207 (unsigned long) section->sh_offset, section->sh_link,
6208 SECTION_HEADER_INDEX (section->sh_link)
6209 < elf_header.e_shnum
6210 ? SECTION_NAME (SECTION_HEADER (section->sh_link))
6213 edefs = get_data (NULL, file, section->sh_offset, 1,
6215 _("version definition section"));
6219 for (idx = cnt = 0; cnt < section->sh_info; ++cnt)
6222 Elf_External_Verdef *edef;
6223 Elf_Internal_Verdef ent;
6224 Elf_External_Verdaux *eaux;
6225 Elf_Internal_Verdaux aux;
6229 vstart = ((char *) edefs) + idx;
6231 edef = (Elf_External_Verdef *) vstart;
6233 ent.vd_version = BYTE_GET (edef->vd_version);
6234 ent.vd_flags = BYTE_GET (edef->vd_flags);
6235 ent.vd_ndx = BYTE_GET (edef->vd_ndx);
6236 ent.vd_cnt = BYTE_GET (edef->vd_cnt);
6237 ent.vd_hash = BYTE_GET (edef->vd_hash);
6238 ent.vd_aux = BYTE_GET (edef->vd_aux);
6239 ent.vd_next = BYTE_GET (edef->vd_next);
6241 printf (_(" %#06x: Rev: %d Flags: %s"),
6242 idx, ent.vd_version, get_ver_flags (ent.vd_flags));
6244 printf (_(" Index: %d Cnt: %d "),
6245 ent.vd_ndx, ent.vd_cnt);
6247 vstart += ent.vd_aux;
6249 eaux = (Elf_External_Verdaux *) vstart;
6251 aux.vda_name = BYTE_GET (eaux->vda_name);
6252 aux.vda_next = BYTE_GET (eaux->vda_next);
6254 if (VALID_DYNAMIC_NAME (aux.vda_name))
6255 printf (_("Name: %s\n"), GET_DYNAMIC_NAME (aux.vda_name));
6257 printf (_("Name index: %ld\n"), aux.vda_name);
6259 isum = idx + ent.vd_aux;
6261 for (j = 1; j < ent.vd_cnt; j++)
6263 isum += aux.vda_next;
6264 vstart += aux.vda_next;
6266 eaux = (Elf_External_Verdaux *) vstart;
6268 aux.vda_name = BYTE_GET (eaux->vda_name);
6269 aux.vda_next = BYTE_GET (eaux->vda_next);
6271 if (VALID_DYNAMIC_NAME (aux.vda_name))
6272 printf (_(" %#06x: Parent %d: %s\n"),
6273 isum, j, GET_DYNAMIC_NAME (aux.vda_name));
6275 printf (_(" %#06x: Parent %d, name index: %ld\n"),
6276 isum, j, aux.vda_name);
6286 case SHT_GNU_verneed:
6288 Elf_External_Verneed *eneed;
6294 printf (_("\nVersion needs section '%s' contains %ld entries:\n"),
6295 SECTION_NAME (section), section->sh_info);
6297 printf (_(" Addr: 0x"));
6298 printf_vma (section->sh_addr);
6299 printf (_(" Offset: %#08lx Link to section: %ld (%s)\n"),
6300 (unsigned long) section->sh_offset, section->sh_link,
6301 SECTION_HEADER_INDEX (section->sh_link)
6302 < elf_header.e_shnum
6303 ? SECTION_NAME (SECTION_HEADER (section->sh_link))
6306 eneed = get_data (NULL, file, section->sh_offset, 1,
6308 _("version need section"));
6312 for (idx = cnt = 0; cnt < section->sh_info; ++cnt)
6314 Elf_External_Verneed *entry;
6315 Elf_Internal_Verneed ent;
6320 vstart = ((char *) eneed) + idx;
6322 entry = (Elf_External_Verneed *) vstart;
6324 ent.vn_version = BYTE_GET (entry->vn_version);
6325 ent.vn_cnt = BYTE_GET (entry->vn_cnt);
6326 ent.vn_file = BYTE_GET (entry->vn_file);
6327 ent.vn_aux = BYTE_GET (entry->vn_aux);
6328 ent.vn_next = BYTE_GET (entry->vn_next);
6330 printf (_(" %#06x: Version: %d"), idx, ent.vn_version);
6332 if (VALID_DYNAMIC_NAME (ent.vn_file))
6333 printf (_(" File: %s"), GET_DYNAMIC_NAME (ent.vn_file));
6335 printf (_(" File: %lx"), ent.vn_file);
6337 printf (_(" Cnt: %d\n"), ent.vn_cnt);
6339 vstart += ent.vn_aux;
6341 for (j = 0, isum = idx + ent.vn_aux; j < ent.vn_cnt; ++j)
6343 Elf_External_Vernaux *eaux;
6344 Elf_Internal_Vernaux aux;
6346 eaux = (Elf_External_Vernaux *) vstart;
6348 aux.vna_hash = BYTE_GET (eaux->vna_hash);
6349 aux.vna_flags = BYTE_GET (eaux->vna_flags);
6350 aux.vna_other = BYTE_GET (eaux->vna_other);
6351 aux.vna_name = BYTE_GET (eaux->vna_name);
6352 aux.vna_next = BYTE_GET (eaux->vna_next);
6354 if (VALID_DYNAMIC_NAME (aux.vna_name))
6355 printf (_(" %#06x: Name: %s"),
6356 isum, GET_DYNAMIC_NAME (aux.vna_name));
6358 printf (_(" %#06x: Name index: %lx"),
6359 isum, aux.vna_name);
6361 printf (_(" Flags: %s Version: %d\n"),
6362 get_ver_flags (aux.vna_flags), aux.vna_other);
6364 isum += aux.vna_next;
6365 vstart += aux.vna_next;
6375 case SHT_GNU_versym:
6377 Elf_Internal_Shdr *link_section;
6380 unsigned char *edata;
6381 unsigned short *data;
6383 Elf_Internal_Sym *symbols;
6384 Elf_Internal_Shdr *string_sec;
6387 if (SECTION_HEADER_INDEX (section->sh_link) >= elf_header.e_shnum)
6390 link_section = SECTION_HEADER (section->sh_link);
6391 total = section->sh_size / sizeof (Elf_External_Versym);
6393 if (SECTION_HEADER_INDEX (link_section->sh_link)
6394 >= elf_header.e_shnum)
6399 symbols = GET_ELF_SYMBOLS (file, link_section);
6401 string_sec = SECTION_HEADER (link_section->sh_link);
6403 strtab = get_data (NULL, file, string_sec->sh_offset, 1,
6404 string_sec->sh_size, _("version string table"));
6408 printf (_("\nVersion symbols section '%s' contains %d entries:\n"),
6409 SECTION_NAME (section), total);
6411 printf (_(" Addr: "));
6412 printf_vma (section->sh_addr);
6413 printf (_(" Offset: %#08lx Link: %lx (%s)\n"),
6414 (unsigned long) section->sh_offset, section->sh_link,
6415 SECTION_NAME (link_section));
6417 off = offset_from_vma (file,
6418 version_info[DT_VERSIONTAGIDX (DT_VERSYM)],
6419 total * sizeof (short));
6420 edata = get_data (NULL, file, off, total, sizeof (short),
6421 _("version symbol data"));
6428 data = cmalloc (total, sizeof (short));
6430 for (cnt = total; cnt --;)
6431 data[cnt] = byte_get (edata + cnt * sizeof (short),
6436 for (cnt = 0; cnt < total; cnt += 4)
6439 int check_def, check_need;
6442 printf (" %03x:", cnt);
6444 for (j = 0; (j < 4) && (cnt + j) < total; ++j)
6445 switch (data[cnt + j])
6448 fputs (_(" 0 (*local*) "), stdout);
6452 fputs (_(" 1 (*global*) "), stdout);
6456 nn = printf ("%4x%c", data[cnt + j] & 0x7fff,
6457 data[cnt + j] & 0x8000 ? 'h' : ' ');
6461 if (SECTION_HEADER_INDEX (symbols[cnt + j].st_shndx)
6462 >= elf_header.e_shnum
6463 || SECTION_HEADER (symbols[cnt + j].st_shndx)->sh_type
6466 if (symbols[cnt + j].st_shndx == SHN_UNDEF)
6473 && version_info[DT_VERSIONTAGIDX (DT_VERNEED)])
6475 Elf_Internal_Verneed ivn;
6476 unsigned long offset;
6478 offset = offset_from_vma
6479 (file, version_info[DT_VERSIONTAGIDX (DT_VERNEED)],
6480 sizeof (Elf_External_Verneed));
6484 Elf_Internal_Vernaux ivna;
6485 Elf_External_Verneed evn;
6486 Elf_External_Vernaux evna;
6487 unsigned long a_off;
6489 get_data (&evn, file, offset, sizeof (evn), 1,
6492 ivn.vn_aux = BYTE_GET (evn.vn_aux);
6493 ivn.vn_next = BYTE_GET (evn.vn_next);
6495 a_off = offset + ivn.vn_aux;
6499 get_data (&evna, file, a_off, sizeof (evna),
6500 1, _("version need aux (2)"));
6502 ivna.vna_next = BYTE_GET (evna.vna_next);
6503 ivna.vna_other = BYTE_GET (evna.vna_other);
6505 a_off += ivna.vna_next;
6507 while (ivna.vna_other != data[cnt + j]
6508 && ivna.vna_next != 0);
6510 if (ivna.vna_other == data[cnt + j])
6512 ivna.vna_name = BYTE_GET (evna.vna_name);
6514 name = strtab + ivna.vna_name;
6515 nn += printf ("(%s%-*s",
6517 12 - (int) strlen (name),
6523 offset += ivn.vn_next;
6525 while (ivn.vn_next);
6528 if (check_def && data[cnt + j] != 0x8001
6529 && version_info[DT_VERSIONTAGIDX (DT_VERDEF)])
6531 Elf_Internal_Verdef ivd;
6532 Elf_External_Verdef evd;
6533 unsigned long offset;
6535 offset = offset_from_vma
6536 (file, version_info[DT_VERSIONTAGIDX (DT_VERDEF)],
6541 get_data (&evd, file, offset, sizeof (evd), 1,
6544 ivd.vd_next = BYTE_GET (evd.vd_next);
6545 ivd.vd_ndx = BYTE_GET (evd.vd_ndx);
6547 offset += ivd.vd_next;
6549 while (ivd.vd_ndx != (data[cnt + j] & 0x7fff)
6550 && ivd.vd_next != 0);
6552 if (ivd.vd_ndx == (data[cnt + j] & 0x7fff))
6554 Elf_External_Verdaux evda;
6555 Elf_Internal_Verdaux ivda;
6557 ivd.vd_aux = BYTE_GET (evd.vd_aux);
6559 get_data (&evda, file,
6560 offset - ivd.vd_next + ivd.vd_aux,
6562 _("version def aux"));
6564 ivda.vda_name = BYTE_GET (evda.vda_name);
6566 name = strtab + ivda.vda_name;
6567 nn += printf ("(%s%-*s",
6569 12 - (int) strlen (name),
6575 printf ("%*c", 18 - nn, ' ');
6593 printf (_("\nNo version information found in this file.\n"));
6599 get_symbol_binding (unsigned int binding)
6601 static char buff[32];
6605 case STB_LOCAL: return "LOCAL";
6606 case STB_GLOBAL: return "GLOBAL";
6607 case STB_WEAK: return "WEAK";
6609 if (binding >= STB_LOPROC && binding <= STB_HIPROC)
6610 snprintf (buff, sizeof (buff), _("<processor specific>: %d"),
6612 else if (binding >= STB_LOOS && binding <= STB_HIOS)
6613 snprintf (buff, sizeof (buff), _("<OS specific>: %d"), binding);
6615 snprintf (buff, sizeof (buff), _("<unknown>: %d"), binding);
6621 get_symbol_type (unsigned int type)
6623 static char buff[32];
6627 case STT_NOTYPE: return "NOTYPE";
6628 case STT_OBJECT: return "OBJECT";
6629 case STT_FUNC: return "FUNC";
6630 case STT_SECTION: return "SECTION";
6631 case STT_FILE: return "FILE";
6632 case STT_COMMON: return "COMMON";
6633 case STT_TLS: return "TLS";
6635 if (type >= STT_LOPROC && type <= STT_HIPROC)
6637 if (elf_header.e_machine == EM_ARM && type == STT_ARM_TFUNC)
6638 return "THUMB_FUNC";
6640 if (elf_header.e_machine == EM_SPARCV9 && type == STT_REGISTER)
6643 if (elf_header.e_machine == EM_PARISC && type == STT_PARISC_MILLI)
6644 return "PARISC_MILLI";
6646 snprintf (buff, sizeof (buff), _("<processor specific>: %d"), type);
6648 else if (type >= STT_LOOS && type <= STT_HIOS)
6650 if (elf_header.e_machine == EM_PARISC)
6652 if (type == STT_HP_OPAQUE)
6654 if (type == STT_HP_STUB)
6658 snprintf (buff, sizeof (buff), _("<OS specific>: %d"), type);
6661 snprintf (buff, sizeof (buff), _("<unknown>: %d"), type);
6667 get_symbol_visibility (unsigned int visibility)
6671 case STV_DEFAULT: return "DEFAULT";
6672 case STV_INTERNAL: return "INTERNAL";
6673 case STV_HIDDEN: return "HIDDEN";
6674 case STV_PROTECTED: return "PROTECTED";
6680 get_symbol_index_type (unsigned int type)
6682 static char buff[32];
6686 case SHN_UNDEF: return "UND";
6687 case SHN_ABS: return "ABS";
6688 case SHN_COMMON: return "COM";
6690 if (type == SHN_IA_64_ANSI_COMMON
6691 && elf_header.e_machine == EM_IA_64
6692 && elf_header.e_ident[EI_OSABI] == ELFOSABI_HPUX)
6694 else if (elf_header.e_machine == EM_X86_64
6695 && type == SHN_X86_64_LCOMMON)
6697 else if (type >= SHN_LOPROC && type <= SHN_HIPROC)
6698 sprintf (buff, "PRC[0x%04x]", type);
6699 else if (type >= SHN_LOOS && type <= SHN_HIOS)
6700 sprintf (buff, "OS [0x%04x]", type);
6701 else if (type >= SHN_LORESERVE && type <= SHN_HIRESERVE)
6702 sprintf (buff, "RSV[0x%04x]", type);
6704 sprintf (buff, "%3d", type);
6712 get_dynamic_data (FILE *file, unsigned int number, unsigned int ent_size)
6714 unsigned char *e_data;
6717 e_data = cmalloc (number, ent_size);
6721 error (_("Out of memory\n"));
6725 if (fread (e_data, ent_size, number, file) != number)
6727 error (_("Unable to read in dynamic data\n"));
6731 i_data = cmalloc (number, sizeof (*i_data));
6735 error (_("Out of memory\n"));
6741 i_data[number] = byte_get (e_data + number * ent_size, ent_size);
6748 /* Dump the symbol table. */
6750 process_symbol_table (FILE *file)
6752 Elf_Internal_Shdr *section;
6753 bfd_vma nbuckets = 0;
6754 bfd_vma nchains = 0;
6755 bfd_vma *buckets = NULL;
6756 bfd_vma *chains = NULL;
6758 if (! do_syms && !do_histogram)
6761 if (dynamic_info[DT_HASH] && ((do_using_dynamic && dynamic_strings != NULL)
6764 unsigned char nb[8];
6765 unsigned char nc[8];
6766 int hash_ent_size = 4;
6768 if ((elf_header.e_machine == EM_ALPHA
6769 || elf_header.e_machine == EM_S390
6770 || elf_header.e_machine == EM_S390_OLD)
6771 && elf_header.e_ident[EI_CLASS] == ELFCLASS64)
6775 (archive_file_offset
6776 + offset_from_vma (file, dynamic_info[DT_HASH],
6777 sizeof nb + sizeof nc)),
6780 error (_("Unable to seek to start of dynamic information"));
6784 if (fread (nb, hash_ent_size, 1, file) != 1)
6786 error (_("Failed to read in number of buckets\n"));
6790 if (fread (nc, hash_ent_size, 1, file) != 1)
6792 error (_("Failed to read in number of chains\n"));
6796 nbuckets = byte_get (nb, hash_ent_size);
6797 nchains = byte_get (nc, hash_ent_size);
6799 buckets = get_dynamic_data (file, nbuckets, hash_ent_size);
6800 chains = get_dynamic_data (file, nchains, hash_ent_size);
6802 if (buckets == NULL || chains == NULL)
6807 && dynamic_info[DT_HASH] && do_using_dynamic && dynamic_strings != NULL)
6812 printf (_("\nSymbol table for image:\n"));
6814 printf (_(" Num Buc: Value Size Type Bind Vis Ndx Name\n"));
6816 printf (_(" Num Buc: Value Size Type Bind Vis Ndx Name\n"));
6818 for (hn = 0; hn < nbuckets; hn++)
6823 for (si = buckets[hn]; si < nchains && si > 0; si = chains[si])
6825 Elf_Internal_Sym *psym;
6828 psym = dynamic_symbols + si;
6830 n = print_vma (si, DEC_5);
6832 fputs (" " + n, stdout);
6833 printf (" %3lu: ", hn);
6834 print_vma (psym->st_value, LONG_HEX);
6836 print_vma (psym->st_size, DEC_5);
6838 printf (" %6s", get_symbol_type (ELF_ST_TYPE (psym->st_info)));
6839 printf (" %6s", get_symbol_binding (ELF_ST_BIND (psym->st_info)));
6840 printf (" %3s", get_symbol_visibility (ELF_ST_VISIBILITY (psym->st_other)));
6841 printf (" %3.3s ", get_symbol_index_type (psym->st_shndx));
6842 if (VALID_DYNAMIC_NAME (psym->st_name))
6843 print_symbol (25, GET_DYNAMIC_NAME (psym->st_name));
6845 printf (" <corrupt: %14ld>", psym->st_name);
6850 else if (do_syms && !do_using_dynamic)
6854 for (i = 0, section = section_headers;
6855 i < elf_header.e_shnum;
6859 char *strtab = NULL;
6860 unsigned long int strtab_size = 0;
6861 Elf_Internal_Sym *symtab;
6862 Elf_Internal_Sym *psym;
6865 if ( section->sh_type != SHT_SYMTAB
6866 && section->sh_type != SHT_DYNSYM)
6869 printf (_("\nSymbol table '%s' contains %lu entries:\n"),
6870 SECTION_NAME (section),
6871 (unsigned long) (section->sh_size / section->sh_entsize));
6873 printf (_(" Num: Value Size Type Bind Vis Ndx Name\n"));
6875 printf (_(" Num: Value Size Type Bind Vis Ndx Name\n"));
6877 symtab = GET_ELF_SYMBOLS (file, section);
6881 if (section->sh_link == elf_header.e_shstrndx)
6883 strtab = string_table;
6884 strtab_size = string_table_length;
6886 else if (SECTION_HEADER_INDEX (section->sh_link) < elf_header.e_shnum)
6888 Elf_Internal_Shdr *string_sec;
6890 string_sec = SECTION_HEADER (section->sh_link);
6892 strtab = get_data (NULL, file, string_sec->sh_offset,
6893 1, string_sec->sh_size, _("string table"));
6894 strtab_size = strtab != NULL ? string_sec->sh_size : 0;
6897 for (si = 0, psym = symtab;
6898 si < section->sh_size / section->sh_entsize;
6901 printf ("%6d: ", si);
6902 print_vma (psym->st_value, LONG_HEX);
6904 print_vma (psym->st_size, DEC_5);
6905 printf (" %-7s", get_symbol_type (ELF_ST_TYPE (psym->st_info)));
6906 printf (" %-6s", get_symbol_binding (ELF_ST_BIND (psym->st_info)));
6907 printf (" %-3s", get_symbol_visibility (ELF_ST_VISIBILITY (psym->st_other)));
6908 printf (" %4s ", get_symbol_index_type (psym->st_shndx));
6909 print_symbol (25, psym->st_name < strtab_size
6910 ? strtab + psym->st_name : "<corrupt>");
6912 if (section->sh_type == SHT_DYNSYM &&
6913 version_info[DT_VERSIONTAGIDX (DT_VERSYM)] != 0)
6915 unsigned char data[2];
6916 unsigned short vers_data;
6917 unsigned long offset;
6921 offset = offset_from_vma
6922 (file, version_info[DT_VERSIONTAGIDX (DT_VERSYM)],
6923 sizeof data + si * sizeof (vers_data));
6925 get_data (&data, file, offset + si * sizeof (vers_data),
6926 sizeof (data), 1, _("version data"));
6928 vers_data = byte_get (data, 2);
6930 is_nobits = (SECTION_HEADER_INDEX (psym->st_shndx)
6931 < elf_header.e_shnum
6932 && SECTION_HEADER (psym->st_shndx)->sh_type
6935 check_def = (psym->st_shndx != SHN_UNDEF);
6937 if ((vers_data & 0x8000) || vers_data > 1)
6939 if (version_info[DT_VERSIONTAGIDX (DT_VERNEED)]
6940 && (is_nobits || ! check_def))
6942 Elf_External_Verneed evn;
6943 Elf_Internal_Verneed ivn;
6944 Elf_Internal_Vernaux ivna;
6946 /* We must test both. */
6947 offset = offset_from_vma
6948 (file, version_info[DT_VERSIONTAGIDX (DT_VERNEED)],
6953 unsigned long vna_off;
6955 get_data (&evn, file, offset, sizeof (evn), 1,
6958 ivn.vn_aux = BYTE_GET (evn.vn_aux);
6959 ivn.vn_next = BYTE_GET (evn.vn_next);
6961 vna_off = offset + ivn.vn_aux;
6965 Elf_External_Vernaux evna;
6967 get_data (&evna, file, vna_off,
6969 _("version need aux (3)"));
6971 ivna.vna_other = BYTE_GET (evna.vna_other);
6972 ivna.vna_next = BYTE_GET (evna.vna_next);
6973 ivna.vna_name = BYTE_GET (evna.vna_name);
6975 vna_off += ivna.vna_next;
6977 while (ivna.vna_other != vers_data
6978 && ivna.vna_next != 0);
6980 if (ivna.vna_other == vers_data)
6983 offset += ivn.vn_next;
6985 while (ivn.vn_next != 0);
6987 if (ivna.vna_other == vers_data)
6990 ivna.vna_name < strtab_size
6991 ? strtab + ivna.vna_name : "<corrupt>",
6995 else if (! is_nobits)
6996 error (_("bad dynamic symbol"));
7003 if (vers_data != 0x8001
7004 && version_info[DT_VERSIONTAGIDX (DT_VERDEF)])
7006 Elf_Internal_Verdef ivd;
7007 Elf_Internal_Verdaux ivda;
7008 Elf_External_Verdaux evda;
7009 unsigned long offset;
7011 offset = offset_from_vma
7013 version_info[DT_VERSIONTAGIDX (DT_VERDEF)],
7014 sizeof (Elf_External_Verdef));
7018 Elf_External_Verdef evd;
7020 get_data (&evd, file, offset, sizeof (evd),
7021 1, _("version def"));
7023 ivd.vd_ndx = BYTE_GET (evd.vd_ndx);
7024 ivd.vd_aux = BYTE_GET (evd.vd_aux);
7025 ivd.vd_next = BYTE_GET (evd.vd_next);
7027 offset += ivd.vd_next;
7029 while (ivd.vd_ndx != (vers_data & 0x7fff)
7030 && ivd.vd_next != 0);
7032 offset -= ivd.vd_next;
7033 offset += ivd.vd_aux;
7035 get_data (&evda, file, offset, sizeof (evda),
7036 1, _("version def aux"));
7038 ivda.vda_name = BYTE_GET (evda.vda_name);
7040 if (psym->st_name != ivda.vda_name)
7041 printf ((vers_data & 0x8000)
7043 ivda.vda_name < strtab_size
7044 ? strtab + ivda.vda_name : "<corrupt>");
7054 if (strtab != string_table)
7060 (_("\nDynamic symbol information is not available for displaying symbols.\n"));
7062 if (do_histogram && buckets != NULL)
7064 unsigned long *lengths;
7065 unsigned long *counts;
7068 unsigned long maxlength = 0;
7069 unsigned long nzero_counts = 0;
7070 unsigned long nsyms = 0;
7072 printf (_("\nHistogram for bucket list length (total of %lu buckets):\n"),
7073 (unsigned long) nbuckets);
7074 printf (_(" Length Number %% of total Coverage\n"));
7076 lengths = calloc (nbuckets, sizeof (*lengths));
7077 if (lengths == NULL)
7079 error (_("Out of memory"));
7082 for (hn = 0; hn < nbuckets; ++hn)
7084 for (si = buckets[hn]; si > 0 && si < nchains; si = chains[si])
7087 if (maxlength < ++lengths[hn])
7092 counts = calloc (maxlength + 1, sizeof (*counts));
7095 error (_("Out of memory"));
7099 for (hn = 0; hn < nbuckets; ++hn)
7100 ++counts[lengths[hn]];
7105 printf (" 0 %-10lu (%5.1f%%)\n",
7106 counts[0], (counts[0] * 100.0) / nbuckets);
7107 for (i = 1; i <= maxlength; ++i)
7109 nzero_counts += counts[i] * i;
7110 printf ("%7lu %-10lu (%5.1f%%) %5.1f%%\n",
7111 i, counts[i], (counts[i] * 100.0) / nbuckets,
7112 (nzero_counts * 100.0) / nsyms);
7120 if (buckets != NULL)
7130 process_syminfo (FILE *file ATTRIBUTE_UNUSED)
7134 if (dynamic_syminfo == NULL
7136 /* No syminfo, this is ok. */
7139 /* There better should be a dynamic symbol section. */
7140 if (dynamic_symbols == NULL || dynamic_strings == NULL)
7144 printf (_("\nDynamic info segment at offset 0x%lx contains %d entries:\n"),
7145 dynamic_syminfo_offset, dynamic_syminfo_nent);
7147 printf (_(" Num: Name BoundTo Flags\n"));
7148 for (i = 0; i < dynamic_syminfo_nent; ++i)
7150 unsigned short int flags = dynamic_syminfo[i].si_flags;
7152 printf ("%4d: ", i);
7153 if (VALID_DYNAMIC_NAME (dynamic_symbols[i].st_name))
7154 print_symbol (30, GET_DYNAMIC_NAME (dynamic_symbols[i].st_name));
7156 printf ("<corrupt: %19ld>", dynamic_symbols[i].st_name);
7159 switch (dynamic_syminfo[i].si_boundto)
7161 case SYMINFO_BT_SELF:
7162 fputs ("SELF ", stdout);
7164 case SYMINFO_BT_PARENT:
7165 fputs ("PARENT ", stdout);
7168 if (dynamic_syminfo[i].si_boundto > 0
7169 && dynamic_syminfo[i].si_boundto < dynamic_nent
7170 && VALID_DYNAMIC_NAME (dynamic_section[dynamic_syminfo[i].si_boundto].d_un.d_val))
7172 print_symbol (10, GET_DYNAMIC_NAME (dynamic_section[dynamic_syminfo[i].si_boundto].d_un.d_val));
7176 printf ("%-10d ", dynamic_syminfo[i].si_boundto);
7180 if (flags & SYMINFO_FLG_DIRECT)
7182 if (flags & SYMINFO_FLG_PASSTHRU)
7183 printf (" PASSTHRU");
7184 if (flags & SYMINFO_FLG_COPY)
7186 if (flags & SYMINFO_FLG_LAZYLOAD)
7187 printf (" LAZYLOAD");
7195 #ifdef SUPPORT_DISASSEMBLY
7197 disassemble_section (Elf_Internal_Shdr *section, FILE *file)
7199 printf (_("\nAssembly dump of section %s\n"),
7200 SECTION_NAME (section));
7202 /* XXX -- to be done --- XXX */
7209 dump_section (Elf_Internal_Shdr *section, FILE *file)
7211 bfd_size_type bytes;
7213 unsigned char *data;
7214 unsigned char *start;
7216 bytes = section->sh_size;
7218 if (bytes == 0 || section->sh_type == SHT_NOBITS)
7220 printf (_("\nSection '%s' has no data to dump.\n"),
7221 SECTION_NAME (section));
7225 printf (_("\nHex dump of section '%s':\n"), SECTION_NAME (section));
7227 addr = section->sh_addr;
7229 start = get_data (NULL, file, section->sh_offset, 1, bytes,
7242 lbytes = (bytes > 16 ? 16 : bytes);
7244 printf (" 0x%8.8lx ", (unsigned long) addr);
7246 switch (elf_header.e_ident[EI_DATA])
7250 for (j = 15; j >= 0; j --)
7253 printf ("%2.2x", data[j]);
7263 for (j = 0; j < 16; j++)
7266 printf ("%2.2x", data[j]);
7276 for (j = 0; j < lbytes; j++)
7279 if (k >= ' ' && k < 0x7f)
7297 /* Apply addends of RELA relocations. */
7300 debug_apply_rela_addends (void *file,
7301 Elf_Internal_Shdr *section,
7302 unsigned char *start)
7304 Elf_Internal_Shdr *relsec;
7305 unsigned char *end = start + section->sh_size;
7306 /* FIXME: The relocation field size is relocation type dependent. */
7307 unsigned int reloc_size = 4;
7309 if (!is_relocatable)
7312 if (section->sh_size < reloc_size)
7315 for (relsec = section_headers;
7316 relsec < section_headers + elf_header.e_shnum;
7319 unsigned long nrelas;
7320 Elf_Internal_Rela *rela, *rp;
7321 Elf_Internal_Shdr *symsec;
7322 Elf_Internal_Sym *symtab;
7323 Elf_Internal_Sym *sym;
7325 if (relsec->sh_type != SHT_RELA
7326 || SECTION_HEADER_INDEX (relsec->sh_info) >= elf_header.e_shnum
7327 || SECTION_HEADER (relsec->sh_info) != section
7328 || relsec->sh_size == 0
7329 || SECTION_HEADER_INDEX (relsec->sh_link) >= elf_header.e_shnum)
7332 if (!slurp_rela_relocs (file, relsec->sh_offset, relsec->sh_size,
7336 symsec = SECTION_HEADER (relsec->sh_link);
7337 symtab = GET_ELF_SYMBOLS (file, symsec);
7339 for (rp = rela; rp < rela + nrelas; ++rp)
7343 loc = start + rp->r_offset;
7344 if ((loc + reloc_size) > end)
7346 warn (_("skipping invalid relocation offset 0x%lx in section %s\n"),
7347 (unsigned long) rp->r_offset,
7348 SECTION_NAME (section));
7354 sym = symtab + ELF32_R_SYM (rp->r_info);
7356 if (ELF32_R_SYM (rp->r_info) != 0
7357 && ELF32_ST_TYPE (sym->st_info) != STT_SECTION
7358 /* Relocations against object symbols can happen,
7359 eg when referencing a global array. For an
7360 example of this see the _clz.o binary in libgcc.a. */
7361 && ELF32_ST_TYPE (sym->st_info) != STT_OBJECT)
7363 warn (_("skipping unexpected symbol type %s in relocation in section .rela%s\n"),
7364 get_symbol_type (ELF32_ST_TYPE (sym->st_info)),
7365 SECTION_NAME (section));
7371 /* In MIPS little-endian objects, r_info isn't really a
7372 64-bit little-endian value: it has a 32-bit little-endian
7373 symbol index followed by four individual byte fields.
7374 Reorder INFO accordingly. */
7375 if (elf_header.e_machine == EM_MIPS
7376 && elf_header.e_ident[EI_DATA] != ELFDATA2MSB)
7377 rp->r_info = (((rp->r_info & 0xffffffff) << 32)
7378 | ((rp->r_info >> 56) & 0xff)
7379 | ((rp->r_info >> 40) & 0xff00)
7380 | ((rp->r_info >> 24) & 0xff0000)
7381 | ((rp->r_info >> 8) & 0xff000000));
7383 sym = symtab + ELF64_R_SYM (rp->r_info);
7385 if (ELF64_R_SYM (rp->r_info) != 0
7386 && ELF64_ST_TYPE (sym->st_info) != STT_SECTION
7387 && ELF64_ST_TYPE (sym->st_info) != STT_OBJECT)
7389 warn (_("skipping unexpected symbol type %s in relocation in section .rela.%s\n"),
7390 get_symbol_type (ELF64_ST_TYPE (sym->st_info)),
7391 SECTION_NAME (section));
7396 byte_put (loc, rp->r_addend, reloc_size);
7407 load_debug_section (enum dwarf_section_display_enum debug, void *file)
7409 struct dwarf_section *section = &debug_displays [debug].section;
7410 Elf_Internal_Shdr *sec;
7413 /* If it is already loaded, do nothing. */
7414 if (section->start != NULL)
7417 /* Locate the debug section. */
7418 sec = find_section (section->name);
7422 snprintf (buf, sizeof (buf), _("%s section data"), section->name);
7423 section->address = sec->sh_addr;
7424 section->size = sec->sh_size;
7425 section->start = get_data (NULL, file, sec->sh_offset, 1,
7428 if (debug_displays [debug].relocate)
7429 debug_apply_rela_addends (file, sec, section->start);
7431 return section->start != NULL;
7435 free_debug_section (enum dwarf_section_display_enum debug)
7437 struct dwarf_section *section = &debug_displays [debug].section;
7439 if (section->start == NULL)
7442 free ((char *) section->start);
7443 section->start = NULL;
7444 section->address = 0;
7449 display_debug_section (Elf_Internal_Shdr *section, FILE *file)
7451 char *name = SECTION_NAME (section);
7452 bfd_size_type length;
7454 enum dwarf_section_display_enum i;
7456 length = section->sh_size;
7459 printf (_("\nSection '%s' has no debugging data.\n"), name);
7463 if (strneq (name, ".gnu.linkonce.wi.", 17))
7464 name = ".debug_info";
7466 /* See if we know how to display the contents of this section. */
7467 for (i = 0; i < max; i++)
7468 if (streq (debug_displays[i].section.name, name))
7470 struct dwarf_section *sec = &debug_displays [i].section;
7472 if (load_debug_section (i, file))
7474 result &= debug_displays[i].display (sec, file);
7476 if (i != info && i != abbrev)
7477 free_debug_section (i);
7485 printf (_("Unrecognized debug section: %s\n"), name);
7493 process_section_contents (FILE *file)
7495 Elf_Internal_Shdr *section;
7501 for (i = 0, section = section_headers;
7502 i < elf_header.e_shnum && i < num_dump_sects;
7505 #ifdef SUPPORT_DISASSEMBLY
7506 if (dump_sects[i] & DISASS_DUMP)
7507 disassemble_section (section, file);
7509 if (dump_sects[i] & HEX_DUMP)
7510 dump_section (section, file);
7512 if (dump_sects[i] & DEBUG_DUMP)
7513 display_debug_section (section, file);
7516 /* Check to see if the user requested a
7517 dump of a section that does not exist. */
7518 while (i++ < num_dump_sects)
7520 warn (_("Section %d was not dumped because it does not exist!\n"), i);
7524 process_mips_fpe_exception (int mask)
7529 if (mask & OEX_FPU_INEX)
7530 fputs ("INEX", stdout), first = 0;
7531 if (mask & OEX_FPU_UFLO)
7532 printf ("%sUFLO", first ? "" : "|"), first = 0;
7533 if (mask & OEX_FPU_OFLO)
7534 printf ("%sOFLO", first ? "" : "|"), first = 0;
7535 if (mask & OEX_FPU_DIV0)
7536 printf ("%sDIV0", first ? "" : "|"), first = 0;
7537 if (mask & OEX_FPU_INVAL)
7538 printf ("%sINVAL", first ? "" : "|");
7541 fputs ("0", stdout);
7545 process_mips_specific (FILE *file)
7547 Elf_Internal_Dyn *entry;
7548 size_t liblist_offset = 0;
7549 size_t liblistno = 0;
7550 size_t conflictsno = 0;
7551 size_t options_offset = 0;
7552 size_t conflicts_offset = 0;
7554 /* We have a lot of special sections. Thanks SGI! */
7555 if (dynamic_section == NULL)
7556 /* No information available. */
7559 for (entry = dynamic_section; entry->d_tag != DT_NULL; ++entry)
7560 switch (entry->d_tag)
7562 case DT_MIPS_LIBLIST:
7564 = offset_from_vma (file, entry->d_un.d_val,
7565 liblistno * sizeof (Elf32_External_Lib));
7567 case DT_MIPS_LIBLISTNO:
7568 liblistno = entry->d_un.d_val;
7570 case DT_MIPS_OPTIONS:
7571 options_offset = offset_from_vma (file, entry->d_un.d_val, 0);
7573 case DT_MIPS_CONFLICT:
7575 = offset_from_vma (file, entry->d_un.d_val,
7576 conflictsno * sizeof (Elf32_External_Conflict));
7578 case DT_MIPS_CONFLICTNO:
7579 conflictsno = entry->d_un.d_val;
7585 if (liblist_offset != 0 && liblistno != 0 && do_dynamic)
7587 Elf32_External_Lib *elib;
7590 elib = get_data (NULL, file, liblist_offset,
7591 liblistno, sizeof (Elf32_External_Lib),
7595 printf ("\nSection '.liblist' contains %lu entries:\n",
7596 (unsigned long) liblistno);
7597 fputs (" Library Time Stamp Checksum Version Flags\n",
7600 for (cnt = 0; cnt < liblistno; ++cnt)
7607 liblist.l_name = BYTE_GET (elib[cnt].l_name);
7608 time = BYTE_GET (elib[cnt].l_time_stamp);
7609 liblist.l_checksum = BYTE_GET (elib[cnt].l_checksum);
7610 liblist.l_version = BYTE_GET (elib[cnt].l_version);
7611 liblist.l_flags = BYTE_GET (elib[cnt].l_flags);
7613 tmp = gmtime (&time);
7614 snprintf (timebuf, sizeof (timebuf),
7615 "%04u-%02u-%02uT%02u:%02u:%02u",
7616 tmp->tm_year + 1900, tmp->tm_mon + 1, tmp->tm_mday,
7617 tmp->tm_hour, tmp->tm_min, tmp->tm_sec);
7619 printf ("%3lu: ", (unsigned long) cnt);
7620 if (VALID_DYNAMIC_NAME (liblist.l_name))
7621 print_symbol (20, GET_DYNAMIC_NAME (liblist.l_name));
7623 printf ("<corrupt: %9ld>", liblist.l_name);
7624 printf (" %s %#10lx %-7ld", timebuf, liblist.l_checksum,
7627 if (liblist.l_flags == 0)
7638 { " EXACT_MATCH", LL_EXACT_MATCH },
7639 { " IGNORE_INT_VER", LL_IGNORE_INT_VER },
7640 { " REQUIRE_MINOR", LL_REQUIRE_MINOR },
7641 { " EXPORTS", LL_EXPORTS },
7642 { " DELAY_LOAD", LL_DELAY_LOAD },
7643 { " DELTA", LL_DELTA }
7645 int flags = liblist.l_flags;
7649 fcnt < sizeof (l_flags_vals) / sizeof (l_flags_vals[0]);
7651 if ((flags & l_flags_vals[fcnt].bit) != 0)
7653 fputs (l_flags_vals[fcnt].name, stdout);
7654 flags ^= l_flags_vals[fcnt].bit;
7657 printf (" %#x", (unsigned int) flags);
7667 if (options_offset != 0)
7669 Elf_External_Options *eopt;
7670 Elf_Internal_Shdr *sect = section_headers;
7671 Elf_Internal_Options *iopt;
7672 Elf_Internal_Options *option;
7676 /* Find the section header so that we get the size. */
7677 while (sect->sh_type != SHT_MIPS_OPTIONS)
7680 eopt = get_data (NULL, file, options_offset, 1, sect->sh_size,
7684 iopt = cmalloc ((sect->sh_size / sizeof (eopt)), sizeof (*iopt));
7687 error (_("Out of memory"));
7694 while (offset < sect->sh_size)
7696 Elf_External_Options *eoption;
7698 eoption = (Elf_External_Options *) ((char *) eopt + offset);
7700 option->kind = BYTE_GET (eoption->kind);
7701 option->size = BYTE_GET (eoption->size);
7702 option->section = BYTE_GET (eoption->section);
7703 option->info = BYTE_GET (eoption->info);
7705 offset += option->size;
7711 printf (_("\nSection '%s' contains %d entries:\n"),
7712 SECTION_NAME (sect), cnt);
7720 switch (option->kind)
7723 /* This shouldn't happen. */
7724 printf (" NULL %d %lx", option->section, option->info);
7727 printf (" REGINFO ");
7728 if (elf_header.e_machine == EM_MIPS)
7731 Elf32_External_RegInfo *ereg;
7732 Elf32_RegInfo reginfo;
7734 ereg = (Elf32_External_RegInfo *) (option + 1);
7735 reginfo.ri_gprmask = BYTE_GET (ereg->ri_gprmask);
7736 reginfo.ri_cprmask[0] = BYTE_GET (ereg->ri_cprmask[0]);
7737 reginfo.ri_cprmask[1] = BYTE_GET (ereg->ri_cprmask[1]);
7738 reginfo.ri_cprmask[2] = BYTE_GET (ereg->ri_cprmask[2]);
7739 reginfo.ri_cprmask[3] = BYTE_GET (ereg->ri_cprmask[3]);
7740 reginfo.ri_gp_value = BYTE_GET (ereg->ri_gp_value);
7742 printf ("GPR %08lx GP 0x%lx\n",
7744 (unsigned long) reginfo.ri_gp_value);
7745 printf (" CPR0 %08lx CPR1 %08lx CPR2 %08lx CPR3 %08lx\n",
7746 reginfo.ri_cprmask[0], reginfo.ri_cprmask[1],
7747 reginfo.ri_cprmask[2], reginfo.ri_cprmask[3]);
7752 Elf64_External_RegInfo *ereg;
7753 Elf64_Internal_RegInfo reginfo;
7755 ereg = (Elf64_External_RegInfo *) (option + 1);
7756 reginfo.ri_gprmask = BYTE_GET (ereg->ri_gprmask);
7757 reginfo.ri_cprmask[0] = BYTE_GET (ereg->ri_cprmask[0]);
7758 reginfo.ri_cprmask[1] = BYTE_GET (ereg->ri_cprmask[1]);
7759 reginfo.ri_cprmask[2] = BYTE_GET (ereg->ri_cprmask[2]);
7760 reginfo.ri_cprmask[3] = BYTE_GET (ereg->ri_cprmask[3]);
7761 reginfo.ri_gp_value = BYTE_GET (ereg->ri_gp_value);
7763 printf ("GPR %08lx GP 0x",
7764 reginfo.ri_gprmask);
7765 printf_vma (reginfo.ri_gp_value);
7768 printf (" CPR0 %08lx CPR1 %08lx CPR2 %08lx CPR3 %08lx\n",
7769 reginfo.ri_cprmask[0], reginfo.ri_cprmask[1],
7770 reginfo.ri_cprmask[2], reginfo.ri_cprmask[3]);
7774 case ODK_EXCEPTIONS:
7775 fputs (" EXCEPTIONS fpe_min(", stdout);
7776 process_mips_fpe_exception (option->info & OEX_FPU_MIN);
7777 fputs (") fpe_max(", stdout);
7778 process_mips_fpe_exception ((option->info & OEX_FPU_MAX) >> 8);
7779 fputs (")", stdout);
7781 if (option->info & OEX_PAGE0)
7782 fputs (" PAGE0", stdout);
7783 if (option->info & OEX_SMM)
7784 fputs (" SMM", stdout);
7785 if (option->info & OEX_FPDBUG)
7786 fputs (" FPDBUG", stdout);
7787 if (option->info & OEX_DISMISS)
7788 fputs (" DISMISS", stdout);
7791 fputs (" PAD ", stdout);
7792 if (option->info & OPAD_PREFIX)
7793 fputs (" PREFIX", stdout);
7794 if (option->info & OPAD_POSTFIX)
7795 fputs (" POSTFIX", stdout);
7796 if (option->info & OPAD_SYMBOL)
7797 fputs (" SYMBOL", stdout);
7800 fputs (" HWPATCH ", stdout);
7801 if (option->info & OHW_R4KEOP)
7802 fputs (" R4KEOP", stdout);
7803 if (option->info & OHW_R8KPFETCH)
7804 fputs (" R8KPFETCH", stdout);
7805 if (option->info & OHW_R5KEOP)
7806 fputs (" R5KEOP", stdout);
7807 if (option->info & OHW_R5KCVTL)
7808 fputs (" R5KCVTL", stdout);
7811 fputs (" FILL ", stdout);
7812 /* XXX Print content of info word? */
7815 fputs (" TAGS ", stdout);
7816 /* XXX Print content of info word? */
7819 fputs (" HWAND ", stdout);
7820 if (option->info & OHWA0_R4KEOP_CHECKED)
7821 fputs (" R4KEOP_CHECKED", stdout);
7822 if (option->info & OHWA0_R4KEOP_CLEAN)
7823 fputs (" R4KEOP_CLEAN", stdout);
7826 fputs (" HWOR ", stdout);
7827 if (option->info & OHWA0_R4KEOP_CHECKED)
7828 fputs (" R4KEOP_CHECKED", stdout);
7829 if (option->info & OHWA0_R4KEOP_CLEAN)
7830 fputs (" R4KEOP_CLEAN", stdout);
7833 printf (" GP_GROUP %#06lx self-contained %#06lx",
7834 option->info & OGP_GROUP,
7835 (option->info & OGP_SELF) >> 16);
7838 printf (" IDENT %#06lx self-contained %#06lx",
7839 option->info & OGP_GROUP,
7840 (option->info & OGP_SELF) >> 16);
7843 /* This shouldn't happen. */
7844 printf (" %3d ??? %d %lx",
7845 option->kind, option->section, option->info);
7849 len = sizeof (*eopt);
7850 while (len < option->size)
7851 if (((char *) option)[len] >= ' '
7852 && ((char *) option)[len] < 0x7f)
7853 printf ("%c", ((char *) option)[len++]);
7855 printf ("\\%03o", ((char *) option)[len++]);
7857 fputs ("\n", stdout);
7865 if (conflicts_offset != 0 && conflictsno != 0)
7867 Elf32_Conflict *iconf;
7870 if (dynamic_symbols == NULL)
7872 error (_("conflict list found without a dynamic symbol table"));
7876 iconf = cmalloc (conflictsno, sizeof (*iconf));
7879 error (_("Out of memory"));
7885 Elf32_External_Conflict *econf32;
7887 econf32 = get_data (NULL, file, conflicts_offset,
7888 conflictsno, sizeof (*econf32), _("conflict"));
7892 for (cnt = 0; cnt < conflictsno; ++cnt)
7893 iconf[cnt] = BYTE_GET (econf32[cnt]);
7899 Elf64_External_Conflict *econf64;
7901 econf64 = get_data (NULL, file, conflicts_offset,
7902 conflictsno, sizeof (*econf64), _("conflict"));
7906 for (cnt = 0; cnt < conflictsno; ++cnt)
7907 iconf[cnt] = BYTE_GET (econf64[cnt]);
7912 printf (_("\nSection '.conflict' contains %lu entries:\n"),
7913 (unsigned long) conflictsno);
7914 puts (_(" Num: Index Value Name"));
7916 for (cnt = 0; cnt < conflictsno; ++cnt)
7918 Elf_Internal_Sym *psym = & dynamic_symbols[iconf[cnt]];
7920 printf ("%5lu: %8lu ", (unsigned long) cnt, iconf[cnt]);
7921 print_vma (psym->st_value, FULL_HEX);
7923 if (VALID_DYNAMIC_NAME (psym->st_name))
7924 print_symbol (25, GET_DYNAMIC_NAME (psym->st_name));
7926 printf ("<corrupt: %14ld>", psym->st_name);
7937 process_gnu_liblist (FILE *file)
7939 Elf_Internal_Shdr *section, *string_sec;
7940 Elf32_External_Lib *elib;
7949 for (i = 0, section = section_headers;
7950 i < elf_header.e_shnum;
7953 switch (section->sh_type)
7955 case SHT_GNU_LIBLIST:
7956 if (SECTION_HEADER_INDEX (section->sh_link) >= elf_header.e_shnum)
7959 elib = get_data (NULL, file, section->sh_offset, 1, section->sh_size,
7964 string_sec = SECTION_HEADER (section->sh_link);
7966 strtab = get_data (NULL, file, string_sec->sh_offset, 1,
7967 string_sec->sh_size, _("liblist string table"));
7968 strtab_size = string_sec->sh_size;
7971 || section->sh_entsize != sizeof (Elf32_External_Lib))
7977 printf (_("\nLibrary list section '%s' contains %lu entries:\n"),
7978 SECTION_NAME (section),
7979 (long) (section->sh_size / sizeof (Elf32_External_Lib)));
7981 puts (" Library Time Stamp Checksum Version Flags");
7983 for (cnt = 0; cnt < section->sh_size / sizeof (Elf32_External_Lib);
7991 liblist.l_name = BYTE_GET (elib[cnt].l_name);
7992 time = BYTE_GET (elib[cnt].l_time_stamp);
7993 liblist.l_checksum = BYTE_GET (elib[cnt].l_checksum);
7994 liblist.l_version = BYTE_GET (elib[cnt].l_version);
7995 liblist.l_flags = BYTE_GET (elib[cnt].l_flags);
7997 tmp = gmtime (&time);
7998 snprintf (timebuf, sizeof (timebuf),
7999 "%04u-%02u-%02uT%02u:%02u:%02u",
8000 tmp->tm_year + 1900, tmp->tm_mon + 1, tmp->tm_mday,
8001 tmp->tm_hour, tmp->tm_min, tmp->tm_sec);
8003 printf ("%3lu: ", (unsigned long) cnt);
8005 printf ("%-20s", liblist.l_name < strtab_size
8006 ? strtab + liblist.l_name : "<corrupt>");
8008 printf ("%-20.20s", liblist.l_name < strtab_size
8009 ? strtab + liblist.l_name : "<corrupt>");
8010 printf (" %s %#010lx %-7ld %-7ld\n", timebuf, liblist.l_checksum,
8011 liblist.l_version, liblist.l_flags);
8022 get_note_type (unsigned e_type)
8024 static char buff[64];
8026 if (elf_header.e_type == ET_CORE)
8030 return _("NT_AUXV (auxiliary vector)");
8032 return _("NT_PRSTATUS (prstatus structure)");
8034 return _("NT_FPREGSET (floating point registers)");
8036 return _("NT_PRPSINFO (prpsinfo structure)");
8038 return _("NT_TASKSTRUCT (task structure)");
8040 return _("NT_PRXFPREG (user_xfpregs structure)");
8042 return _("NT_PSTATUS (pstatus structure)");
8044 return _("NT_FPREGS (floating point registers)");
8046 return _("NT_PSINFO (psinfo structure)");
8048 return _("NT_LWPSTATUS (lwpstatus_t structure)");
8050 return _("NT_LWPSINFO (lwpsinfo_t structure)");
8051 case NT_WIN32PSTATUS:
8052 return _("NT_WIN32PSTATUS (win32_pstatus structure)");
8060 return _("NT_VERSION (version)");
8062 return _("NT_ARCH (architecture)");
8067 snprintf (buff, sizeof (buff), _("Unknown note type: (0x%08x)"), e_type);
8072 get_netbsd_elfcore_note_type (unsigned e_type)
8074 static char buff[64];
8076 if (e_type == NT_NETBSDCORE_PROCINFO)
8078 /* NetBSD core "procinfo" structure. */
8079 return _("NetBSD procinfo structure");
8082 /* As of Jan 2002 there are no other machine-independent notes
8083 defined for NetBSD core files. If the note type is less
8084 than the start of the machine-dependent note types, we don't
8087 if (e_type < NT_NETBSDCORE_FIRSTMACH)
8089 snprintf (buff, sizeof (buff), _("Unknown note type: (0x%08x)"), e_type);
8093 switch (elf_header.e_machine)
8095 /* On the Alpha, SPARC (32-bit and 64-bit), PT_GETREGS == mach+0
8096 and PT_GETFPREGS == mach+2. */
8101 case EM_SPARC32PLUS:
8105 case NT_NETBSDCORE_FIRSTMACH+0:
8106 return _("PT_GETREGS (reg structure)");
8107 case NT_NETBSDCORE_FIRSTMACH+2:
8108 return _("PT_GETFPREGS (fpreg structure)");
8114 /* On all other arch's, PT_GETREGS == mach+1 and
8115 PT_GETFPREGS == mach+3. */
8119 case NT_NETBSDCORE_FIRSTMACH+1:
8120 return _("PT_GETREGS (reg structure)");
8121 case NT_NETBSDCORE_FIRSTMACH+3:
8122 return _("PT_GETFPREGS (fpreg structure)");
8128 snprintf (buff, sizeof (buff), _("PT_FIRSTMACH+%d"),
8129 e_type - NT_NETBSDCORE_FIRSTMACH);
8133 /* Note that by the ELF standard, the name field is already null byte
8134 terminated, and namesz includes the terminating null byte.
8135 I.E. the value of namesz for the name "FSF" is 4.
8137 If the value of namesz is zero, there is no name present. */
8139 process_note (Elf_Internal_Note *pnote)
8143 if (pnote->namesz == 0)
8144 /* If there is no note name, then use the default set of
8145 note type strings. */
8146 nt = get_note_type (pnote->type);
8148 else if (strneq (pnote->namedata, "NetBSD-CORE", 11))
8149 /* NetBSD-specific core file notes. */
8150 nt = get_netbsd_elfcore_note_type (pnote->type);
8153 /* Don't recognize this note name; just use the default set of
8154 note type strings. */
8155 nt = get_note_type (pnote->type);
8157 printf (" %s\t\t0x%08lx\t%s\n",
8158 pnote->namesz ? pnote->namedata : "(NONE)",
8165 process_corefile_note_segment (FILE *file, bfd_vma offset, bfd_vma length)
8167 Elf_External_Note *pnotes;
8168 Elf_External_Note *external;
8174 pnotes = get_data (NULL, file, offset, 1, length, _("notes"));
8180 printf (_("\nNotes at offset 0x%08lx with length 0x%08lx:\n"),
8181 (unsigned long) offset, (unsigned long) length);
8182 printf (_(" Owner\t\tData size\tDescription\n"));
8184 while (external < (Elf_External_Note *)((char *) pnotes + length))
8186 Elf_External_Note *next;
8187 Elf_Internal_Note inote;
8190 inote.type = BYTE_GET (external->type);
8191 inote.namesz = BYTE_GET (external->namesz);
8192 inote.namedata = external->name;
8193 inote.descsz = BYTE_GET (external->descsz);
8194 inote.descdata = inote.namedata + align_power (inote.namesz, 2);
8195 inote.descpos = offset + (inote.descdata - (char *) pnotes);
8197 next = (Elf_External_Note *)(inote.descdata + align_power (inote.descsz, 2));
8199 if (((char *) next) > (((char *) pnotes) + length))
8201 warn (_("corrupt note found at offset %lx into core notes\n"),
8202 (long)((char *)external - (char *)pnotes));
8203 warn (_(" type: %lx, namesize: %08lx, descsize: %08lx\n"),
8204 inote.type, inote.namesz, inote.descsz);
8210 /* Verify that name is null terminated. It appears that at least
8211 one version of Linux (RedHat 6.0) generates corefiles that don't
8212 comply with the ELF spec by failing to include the null byte in
8214 if (inote.namedata[inote.namesz] != '\0')
8216 temp = malloc (inote.namesz + 1);
8220 error (_("Out of memory\n"));
8225 strncpy (temp, inote.namedata, inote.namesz);
8226 temp[inote.namesz] = 0;
8228 /* warn (_("'%s' NOTE name not properly null terminated\n"), temp); */
8229 inote.namedata = temp;
8232 res &= process_note (& inote);
8247 process_corefile_note_segments (FILE *file)
8249 Elf_Internal_Phdr *segment;
8253 if (! get_program_headers (file))
8256 for (i = 0, segment = program_headers;
8257 i < elf_header.e_phnum;
8260 if (segment->p_type == PT_NOTE)
8261 res &= process_corefile_note_segment (file,
8262 (bfd_vma) segment->p_offset,
8263 (bfd_vma) segment->p_filesz);
8270 process_note_sections (FILE *file)
8272 Elf_Internal_Shdr *section;
8276 for (i = 0, section = section_headers;
8277 i < elf_header.e_shnum;
8279 if (section->sh_type == SHT_NOTE)
8280 res &= process_corefile_note_segment (file,
8281 (bfd_vma) section->sh_offset,
8282 (bfd_vma) section->sh_size);
8288 process_notes (FILE *file)
8290 /* If we have not been asked to display the notes then do nothing. */
8294 if (elf_header.e_type != ET_CORE)
8295 return process_note_sections (file);
8297 /* No program headers means no NOTE segment. */
8298 if (elf_header.e_phnum > 0)
8299 return process_corefile_note_segments (file);
8301 printf (_("No note segments present in the core file.\n"));
8306 process_arch_specific (FILE *file)
8311 switch (elf_header.e_machine)
8314 case EM_MIPS_RS3_LE:
8315 return process_mips_specific (file);
8324 get_file_header (FILE *file)
8326 /* Read in the identity array. */
8327 if (fread (elf_header.e_ident, EI_NIDENT, 1, file) != 1)
8330 /* Determine how to read the rest of the header. */
8331 switch (elf_header.e_ident[EI_DATA])
8333 default: /* fall through */
8334 case ELFDATANONE: /* fall through */
8336 byte_get = byte_get_little_endian;
8337 byte_put = byte_put_little_endian;
8340 byte_get = byte_get_big_endian;
8341 byte_put = byte_put_big_endian;
8345 /* For now we only support 32 bit and 64 bit ELF files. */
8346 is_32bit_elf = (elf_header.e_ident[EI_CLASS] != ELFCLASS64);
8348 /* Read in the rest of the header. */
8351 Elf32_External_Ehdr ehdr32;
8353 if (fread (ehdr32.e_type, sizeof (ehdr32) - EI_NIDENT, 1, file) != 1)
8356 elf_header.e_type = BYTE_GET (ehdr32.e_type);
8357 elf_header.e_machine = BYTE_GET (ehdr32.e_machine);
8358 elf_header.e_version = BYTE_GET (ehdr32.e_version);
8359 elf_header.e_entry = BYTE_GET (ehdr32.e_entry);
8360 elf_header.e_phoff = BYTE_GET (ehdr32.e_phoff);
8361 elf_header.e_shoff = BYTE_GET (ehdr32.e_shoff);
8362 elf_header.e_flags = BYTE_GET (ehdr32.e_flags);
8363 elf_header.e_ehsize = BYTE_GET (ehdr32.e_ehsize);
8364 elf_header.e_phentsize = BYTE_GET (ehdr32.e_phentsize);
8365 elf_header.e_phnum = BYTE_GET (ehdr32.e_phnum);
8366 elf_header.e_shentsize = BYTE_GET (ehdr32.e_shentsize);
8367 elf_header.e_shnum = BYTE_GET (ehdr32.e_shnum);
8368 elf_header.e_shstrndx = BYTE_GET (ehdr32.e_shstrndx);
8372 Elf64_External_Ehdr ehdr64;
8374 /* If we have been compiled with sizeof (bfd_vma) == 4, then
8375 we will not be able to cope with the 64bit data found in
8376 64 ELF files. Detect this now and abort before we start
8377 overwriting things. */
8378 if (sizeof (bfd_vma) < 8)
8380 error (_("This instance of readelf has been built without support for a\n\
8381 64 bit data type and so it cannot read 64 bit ELF files.\n"));
8385 if (fread (ehdr64.e_type, sizeof (ehdr64) - EI_NIDENT, 1, file) != 1)
8388 elf_header.e_type = BYTE_GET (ehdr64.e_type);
8389 elf_header.e_machine = BYTE_GET (ehdr64.e_machine);
8390 elf_header.e_version = BYTE_GET (ehdr64.e_version);
8391 elf_header.e_entry = BYTE_GET (ehdr64.e_entry);
8392 elf_header.e_phoff = BYTE_GET (ehdr64.e_phoff);
8393 elf_header.e_shoff = BYTE_GET (ehdr64.e_shoff);
8394 elf_header.e_flags = BYTE_GET (ehdr64.e_flags);
8395 elf_header.e_ehsize = BYTE_GET (ehdr64.e_ehsize);
8396 elf_header.e_phentsize = BYTE_GET (ehdr64.e_phentsize);
8397 elf_header.e_phnum = BYTE_GET (ehdr64.e_phnum);
8398 elf_header.e_shentsize = BYTE_GET (ehdr64.e_shentsize);
8399 elf_header.e_shnum = BYTE_GET (ehdr64.e_shnum);
8400 elf_header.e_shstrndx = BYTE_GET (ehdr64.e_shstrndx);
8403 if (elf_header.e_shoff)
8405 /* There may be some extensions in the first section header. Don't
8406 bomb if we can't read it. */
8408 get_32bit_section_headers (file, 1);
8410 get_64bit_section_headers (file, 1);
8413 is_relocatable = elf_header.e_type == ET_REL;
8418 /* Process one ELF object file according to the command line options.
8419 This file may actually be stored in an archive. The file is
8420 positioned at the start of the ELF object. */
8423 process_object (char *file_name, FILE *file)
8427 if (! get_file_header (file))
8429 error (_("%s: Failed to read file header\n"), file_name);
8433 /* Initialise per file variables. */
8434 for (i = NUM_ELEM (version_info); i--;)
8435 version_info[i] = 0;
8437 for (i = NUM_ELEM (dynamic_info); i--;)
8438 dynamic_info[i] = 0;
8440 /* Process the file. */
8442 printf (_("\nFile: %s\n"), file_name);
8444 /* Initialise the dump_sects array from the cmdline_dump_sects array.
8445 Note we do this even if cmdline_dump_sects is empty because we
8446 must make sure that the dump_sets array is zeroed out before each
8447 object file is processed. */
8448 if (num_dump_sects > num_cmdline_dump_sects)
8449 memset (dump_sects, 0, num_dump_sects);
8451 if (num_cmdline_dump_sects > 0)
8453 if (num_dump_sects == 0)
8454 /* A sneaky way of allocating the dump_sects array. */
8455 request_dump (num_cmdline_dump_sects, 0);
8457 assert (num_dump_sects >= num_cmdline_dump_sects);
8458 memcpy (dump_sects, cmdline_dump_sects, num_cmdline_dump_sects);
8461 if (! process_file_header ())
8464 if (! process_section_headers (file))
8466 /* Without loaded section headers we cannot process lots of
8468 do_unwind = do_version = do_dump = do_arch = 0;
8470 if (! do_using_dynamic)
8471 do_syms = do_reloc = 0;
8474 if (! process_section_groups (file))
8476 /* Without loaded section groups we cannot process unwind. */
8480 if (process_program_headers (file))
8481 process_dynamic_section (file);
8483 process_relocs (file);
8485 process_unwind (file);
8487 process_symbol_table (file);
8489 process_syminfo (file);
8491 process_version_sections (file);
8493 process_section_contents (file);
8495 process_notes (file);
8497 process_gnu_liblist (file);
8499 process_arch_specific (file);
8501 if (program_headers)
8503 free (program_headers);
8504 program_headers = NULL;
8507 if (section_headers)
8509 free (section_headers);
8510 section_headers = NULL;
8515 free (string_table);
8516 string_table = NULL;
8517 string_table_length = 0;
8520 if (dynamic_strings)
8522 free (dynamic_strings);
8523 dynamic_strings = NULL;
8524 dynamic_strings_length = 0;
8527 if (dynamic_symbols)
8529 free (dynamic_symbols);
8530 dynamic_symbols = NULL;
8531 num_dynamic_syms = 0;
8534 if (dynamic_syminfo)
8536 free (dynamic_syminfo);
8537 dynamic_syminfo = NULL;
8540 if (section_headers_groups)
8542 free (section_headers_groups);
8543 section_headers_groups = NULL;
8548 struct group_list *g, *next;
8550 for (i = 0; i < group_count; i++)
8552 for (g = section_groups [i].root; g != NULL; g = next)
8559 free (section_groups);
8560 section_groups = NULL;
8563 free_debug_memory ();
8568 /* Process an ELF archive. The file is positioned just after the
8572 process_archive (char *file_name, FILE *file)
8574 struct ar_hdr arhdr;
8577 char *longnames = NULL;
8578 unsigned long longnames_size = 0;
8579 size_t file_name_size;
8584 got = fread (&arhdr, 1, sizeof arhdr, file);
8585 if (got != sizeof arhdr)
8590 error (_("%s: failed to read archive header\n"), file_name);
8594 if (memcmp (arhdr.ar_name, "/ ", 16) == 0)
8596 /* This is the archive symbol table. Skip it.
8597 FIXME: We should have an option to dump it. */
8598 size = strtoul (arhdr.ar_size, NULL, 10);
8599 if (fseek (file, size + (size & 1), SEEK_CUR) != 0)
8601 error (_("%s: failed to skip archive symbol table\n"), file_name);
8605 got = fread (&arhdr, 1, sizeof arhdr, file);
8606 if (got != sizeof arhdr)
8611 error (_("%s: failed to read archive header\n"), file_name);
8616 if (memcmp (arhdr.ar_name, "// ", 16) == 0)
8618 /* This is the archive string table holding long member
8621 longnames_size = strtoul (arhdr.ar_size, NULL, 10);
8623 longnames = malloc (longnames_size);
8624 if (longnames == NULL)
8626 error (_("Out of memory\n"));
8630 if (fread (longnames, longnames_size, 1, file) != 1)
8633 error (_("%s: failed to read string table\n"), file_name);
8637 if ((longnames_size & 1) != 0)
8640 got = fread (&arhdr, 1, sizeof arhdr, file);
8641 if (got != sizeof arhdr)
8648 error (_("%s: failed to read archive header\n"), file_name);
8653 file_name_size = strlen (file_name);
8662 if (arhdr.ar_name[0] == '/')
8666 off = strtoul (arhdr.ar_name + 1, NULL, 10);
8667 if (off >= longnames_size)
8669 error (_("%s: invalid archive string table offset %lu\n"), file_name, off);
8674 name = longnames + off;
8675 nameend = memchr (name, '/', longnames_size - off);
8679 name = arhdr.ar_name;
8680 nameend = memchr (name, '/', 16);
8683 if (nameend == NULL)
8685 error (_("%s: bad archive file name\n"), file_name);
8690 namealc = malloc (file_name_size + (nameend - name) + 3);
8691 if (namealc == NULL)
8693 error (_("Out of memory\n"));
8698 memcpy (namealc, file_name, file_name_size);
8699 namealc[file_name_size] = '(';
8700 memcpy (namealc + file_name_size + 1, name, nameend - name);
8701 namealc[file_name_size + 1 + (nameend - name)] = ')';
8702 namealc[file_name_size + 2 + (nameend - name)] = '\0';
8704 archive_file_offset = ftell (file);
8705 archive_file_size = strtoul (arhdr.ar_size, NULL, 10);
8707 ret |= process_object (namealc, file);
8712 (archive_file_offset
8714 + (archive_file_size & 1)),
8717 error (_("%s: failed to seek to next archive header\n"), file_name);
8722 got = fread (&arhdr, 1, sizeof arhdr, file);
8723 if (got != sizeof arhdr)
8728 error (_("%s: failed to read archive header\n"), file_name);
8741 process_file (char *file_name)
8744 struct stat statbuf;
8748 if (stat (file_name, &statbuf) < 0)
8750 if (errno == ENOENT)
8751 error (_("'%s': No such file\n"), file_name);
8753 error (_("Could not locate '%s'. System error message: %s\n"),
8754 file_name, strerror (errno));
8758 if (! S_ISREG (statbuf.st_mode))
8760 error (_("'%s' is not an ordinary file\n"), file_name);
8764 file = fopen (file_name, "rb");
8767 error (_("Input file '%s' is not readable.\n"), file_name);
8771 if (fread (armag, SARMAG, 1, file) != 1)
8773 error (_("%s: Failed to read file header\n"), file_name);
8778 if (memcmp (armag, ARMAG, SARMAG) == 0)
8779 ret = process_archive (file_name, file);
8783 archive_file_size = archive_file_offset = 0;
8784 ret = process_object (file_name, file);
8792 #ifdef SUPPORT_DISASSEMBLY
8793 /* Needed by the i386 disassembler. For extra credit, someone could
8794 fix this so that we insert symbolic addresses here, esp for GOT/PLT
8798 print_address (unsigned int addr, FILE *outfile)
8800 fprintf (outfile,"0x%8.8x", addr);
8803 /* Needed by the i386 disassembler. */
8805 db_task_printsym (unsigned int addr)
8807 print_address (addr, stderr);
8812 main (int argc, char **argv)
8816 #if defined (HAVE_SETLOCALE) && defined (HAVE_LC_MESSAGES)
8817 setlocale (LC_MESSAGES, "");
8819 #if defined (HAVE_SETLOCALE)
8820 setlocale (LC_CTYPE, "");
8822 bindtextdomain (PACKAGE, LOCALEDIR);
8823 textdomain (PACKAGE);
8825 parse_args (argc, argv);
8827 if (num_dump_sects > 0)
8829 /* Make a copy of the dump_sects array. */
8830 cmdline_dump_sects = malloc (num_dump_sects);
8831 if (cmdline_dump_sects == NULL)
8832 error (_("Out of memory allocating dump request table."));
8835 memcpy (cmdline_dump_sects, dump_sects, num_dump_sects);
8836 num_cmdline_dump_sects = num_dump_sects;
8840 if (optind < (argc - 1))
8844 while (optind < argc)
8845 err |= process_file (argv[optind++]);
8847 if (dump_sects != NULL)
8849 if (cmdline_dump_sects != NULL)
8850 free (cmdline_dump_sects);