1 /* readelf.c -- display contents of an ELF format file
2 Copyright 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006
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"
92 #include "elf/m68hc11.h"
93 #include "elf/mcore.h"
96 #include "elf/mn10200.h"
97 #include "elf/mn10300.h"
99 #include "elf/msp430.h"
100 #include "elf/or32.h"
103 #include "elf/ppc64.h"
104 #include "elf/s390.h"
106 #include "elf/sparc.h"
107 #include "elf/v850.h"
109 #include "elf/x86-64.h"
110 #include "elf/xstormy16.h"
112 #include "elf/iq2000.h"
113 #include "elf/xtensa.h"
119 #include "libiberty.h"
121 char *program_name = "readelf";
122 static long archive_file_offset;
123 static unsigned long archive_file_size;
124 static unsigned long dynamic_addr;
125 static bfd_size_type dynamic_size;
126 static unsigned int dynamic_nent;
127 static char *dynamic_strings;
128 static unsigned long dynamic_strings_length;
129 static char *string_table;
130 static unsigned long string_table_length;
131 static unsigned long num_dynamic_syms;
132 static Elf_Internal_Sym *dynamic_symbols;
133 static Elf_Internal_Syminfo *dynamic_syminfo;
134 static unsigned long dynamic_syminfo_offset;
135 static unsigned int dynamic_syminfo_nent;
136 static char program_interpreter[64];
137 static bfd_vma dynamic_info[DT_JMPREL + 1];
138 static bfd_vma dynamic_info_DT_GNU_HASH;
139 static bfd_vma version_info[16];
140 static Elf_Internal_Ehdr elf_header;
141 static Elf_Internal_Shdr *section_headers;
142 static Elf_Internal_Phdr *program_headers;
143 static Elf_Internal_Dyn *dynamic_section;
144 static Elf_Internal_Shdr *symtab_shndx_hdr;
145 static int show_name;
146 static int do_dynamic;
149 static int do_sections;
150 static int do_section_groups;
151 static int do_section_details;
152 static int do_segments;
153 static int do_unwind;
154 static int do_using_dynamic;
155 static int do_header;
157 static int do_version;
159 static int do_histogram;
160 static int do_debugging;
163 static int is_32bit_elf;
167 struct group_list *next;
168 unsigned int section_index;
173 struct group_list *root;
174 unsigned int group_index;
177 static size_t group_count;
178 static struct group *section_groups;
179 static struct group **section_headers_groups;
181 /* A linked list of the section names for which dumps were requested
183 struct dump_list_entry
187 struct dump_list_entry *next;
189 static struct dump_list_entry *dump_sects_byname;
191 /* A dynamic array of flags indicating for which sections a hex dump
192 has been requested (via the -x switch) and/or a disassembly dump
193 (via the -i switch). */
194 char *cmdline_dump_sects = NULL;
195 unsigned num_cmdline_dump_sects = 0;
197 /* A dynamic array of flags indicating for which sections a dump of
198 some kind has been requested. It is reset on a per-object file
199 basis and then initialised from the cmdline_dump_sects array,
200 the results of interpreting the -w switch, and the
201 dump_sects_byname list. */
202 char *dump_sects = NULL;
203 unsigned int num_dump_sects = 0;
205 #define HEX_DUMP (1 << 0)
206 #define DISASS_DUMP (1 << 1)
207 #define DEBUG_DUMP (1 << 2)
209 /* How to print a vma value. */
210 typedef enum print_mode
222 static void (*byte_put) (unsigned char *, bfd_vma, int);
226 #define SECTION_NAME(X) \
227 ((X) == NULL ? "<none>" \
228 : string_table == NULL ? "<no-name>" \
229 : ((X)->sh_name >= string_table_length ? "<corrupt>" \
230 : string_table + (X)->sh_name))
232 /* Given st_shndx I, map to section_headers index. */
233 #define SECTION_HEADER_INDEX(I) \
234 ((I) < SHN_LORESERVE \
236 : ((I) <= SHN_HIRESERVE \
238 : (I) - (SHN_HIRESERVE + 1 - SHN_LORESERVE)))
240 /* Reverse of the above. */
241 #define SECTION_HEADER_NUM(N) \
242 ((N) < SHN_LORESERVE \
244 : (N) + (SHN_HIRESERVE + 1 - SHN_LORESERVE))
246 #define SECTION_HEADER(I) (section_headers + SECTION_HEADER_INDEX (I))
248 #define DT_VERSIONTAGIDX(tag) (DT_VERNEEDNUM - (tag)) /* Reverse order! */
250 #define BYTE_GET(field) byte_get (field, sizeof (field))
252 #define NUM_ELEM(array) (sizeof (array) / sizeof ((array)[0]))
254 #define GET_ELF_SYMBOLS(file, section) \
255 (is_32bit_elf ? get_32bit_elf_symbols (file, section) \
256 : get_64bit_elf_symbols (file, section))
258 #define VALID_DYNAMIC_NAME(offset) ((dynamic_strings != NULL) && (offset < dynamic_strings_length))
259 /* GET_DYNAMIC_NAME asssumes that VALID_DYNAMIC_NAME has
260 already been called and verified that the string exists. */
261 #define GET_DYNAMIC_NAME(offset) (dynamic_strings + offset)
263 /* This is just a bit of syntatic sugar. */
264 #define streq(a,b) (strcmp ((a), (b)) == 0)
265 #define strneq(a,b,n) (strncmp ((a), (b), (n)) == 0)
266 #define const_strneq(a,b) (strncmp ((a), (b), sizeof (b) - 1) == 0)
269 get_data (void *var, FILE *file, long offset, size_t size, size_t nmemb,
274 if (size == 0 || nmemb == 0)
277 if (fseek (file, archive_file_offset + offset, SEEK_SET))
279 error (_("Unable to seek to 0x%lx for %s\n"),
280 archive_file_offset + offset, reason);
287 /* Check for overflow. */
288 if (nmemb < (~(size_t) 0 - 1) / size)
289 /* + 1 so that we can '\0' terminate invalid string table sections. */
290 mvar = malloc (size * nmemb + 1);
294 error (_("Out of memory allocating 0x%lx bytes for %s\n"),
295 (unsigned long)(size * nmemb), reason);
299 ((char *) mvar)[size * nmemb] = '\0';
302 if (fread (mvar, size, nmemb, file) != nmemb)
304 error (_("Unable to read in 0x%lx bytes of %s\n"),
305 (unsigned long)(size * nmemb), reason);
315 byte_put_little_endian (unsigned char *field, bfd_vma value, int size)
320 field[7] = (((value >> 24) >> 24) >> 8) & 0xff;
321 field[6] = ((value >> 24) >> 24) & 0xff;
322 field[5] = ((value >> 24) >> 16) & 0xff;
323 field[4] = ((value >> 24) >> 8) & 0xff;
326 field[3] = (value >> 24) & 0xff;
327 field[2] = (value >> 16) & 0xff;
330 field[1] = (value >> 8) & 0xff;
333 field[0] = value & 0xff;
337 error (_("Unhandled data length: %d\n"), size);
342 #if defined BFD64 && !BFD_HOST_64BIT_LONG
344 print_dec_vma (bfd_vma vma, int is_signed)
350 if (is_signed && (bfd_signed_vma) vma < 0)
359 *bufp++ = '0' + vma % 10;
371 print_hex_vma (bfd_vma vma)
379 char digit = '0' + (vma & 0x0f);
381 digit += 'a' - '0' - 10;
394 /* Print a VMA value. */
396 print_vma (bfd_vma vma, print_mode mode)
405 return printf ("0x%8.8lx", (unsigned long) vma);
408 return printf ("%8.8lx", (unsigned long) vma);
412 return printf ("%5ld", (long) vma);
416 return printf ("0x%lx", (unsigned long) vma);
419 return printf ("%lx", (unsigned long) vma);
422 return printf ("%ld", (unsigned long) vma);
425 return printf ("%lu", (unsigned long) vma);
448 #if BFD_HOST_64BIT_LONG
449 return nc + printf ("%lx", vma);
451 return nc + print_hex_vma (vma);
455 #if BFD_HOST_64BIT_LONG
456 return printf ("%ld", vma);
458 return print_dec_vma (vma, 1);
462 #if BFD_HOST_64BIT_LONG
464 return printf ("%5ld", vma);
466 return printf ("%#lx", vma);
469 return printf ("%5ld", _bfd_int64_low (vma));
471 return print_hex_vma (vma);
475 #if BFD_HOST_64BIT_LONG
476 return printf ("%lu", vma);
478 return print_dec_vma (vma, 0);
486 /* Display a symbol on stdout. If do_wide is not true then
487 format the symbol to be at most WIDTH characters,
488 truncating as necessary. If WIDTH is negative then
489 format the string to be exactly - WIDTH characters,
490 truncating or padding as necessary. */
493 print_symbol (int width, const char *symbol)
496 printf ("%s", symbol);
498 printf ("%-*.*s", width, width, symbol);
500 printf ("%-.*s", width, symbol);
504 byte_put_big_endian (unsigned char *field, bfd_vma value, int size)
509 field[7] = value & 0xff;
510 field[6] = (value >> 8) & 0xff;
511 field[5] = (value >> 16) & 0xff;
512 field[4] = (value >> 24) & 0xff;
517 field[3] = value & 0xff;
518 field[2] = (value >> 8) & 0xff;
522 field[1] = value & 0xff;
526 field[0] = value & 0xff;
530 error (_("Unhandled data length: %d\n"), size);
535 /* Return a pointer to section NAME, or NULL if no such section exists. */
537 static Elf_Internal_Shdr *
538 find_section (const char *name)
542 for (i = 0; i < elf_header.e_shnum; i++)
543 if (streq (SECTION_NAME (section_headers + i), name))
544 return section_headers + i;
549 /* Guess the relocation size commonly used by the specific machines. */
552 guess_is_rela (unsigned long e_machine)
556 /* Targets that use REL relocations. */
571 /* Targets that use RELA relocations. */
586 case EM_CYGNUS_MN10200:
588 case EM_CYGNUS_MN10300:
619 case EM_ALTERA_NIOS2:
640 warn (_("Don't know about relocations on this machine architecture\n"));
646 slurp_rela_relocs (FILE *file,
647 unsigned long rel_offset,
648 unsigned long rel_size,
649 Elf_Internal_Rela **relasp,
650 unsigned long *nrelasp)
652 Elf_Internal_Rela *relas;
653 unsigned long nrelas;
658 Elf32_External_Rela *erelas;
660 erelas = get_data (NULL, file, rel_offset, 1, rel_size, _("relocs"));
664 nrelas = rel_size / sizeof (Elf32_External_Rela);
666 relas = cmalloc (nrelas, sizeof (Elf_Internal_Rela));
671 error (_("out of memory parsing relocs"));
675 for (i = 0; i < nrelas; i++)
677 relas[i].r_offset = BYTE_GET (erelas[i].r_offset);
678 relas[i].r_info = BYTE_GET (erelas[i].r_info);
679 relas[i].r_addend = BYTE_GET (erelas[i].r_addend);
686 Elf64_External_Rela *erelas;
688 erelas = get_data (NULL, file, rel_offset, 1, rel_size, _("relocs"));
692 nrelas = rel_size / sizeof (Elf64_External_Rela);
694 relas = cmalloc (nrelas, sizeof (Elf_Internal_Rela));
699 error (_("out of memory parsing relocs"));
703 for (i = 0; i < nrelas; i++)
705 relas[i].r_offset = BYTE_GET (erelas[i].r_offset);
706 relas[i].r_info = BYTE_GET (erelas[i].r_info);
707 relas[i].r_addend = BYTE_GET (erelas[i].r_addend);
718 slurp_rel_relocs (FILE *file,
719 unsigned long rel_offset,
720 unsigned long rel_size,
721 Elf_Internal_Rela **relsp,
722 unsigned long *nrelsp)
724 Elf_Internal_Rela *rels;
730 Elf32_External_Rel *erels;
732 erels = get_data (NULL, file, rel_offset, 1, rel_size, _("relocs"));
736 nrels = rel_size / sizeof (Elf32_External_Rel);
738 rels = cmalloc (nrels, sizeof (Elf_Internal_Rela));
743 error (_("out of memory parsing relocs"));
747 for (i = 0; i < nrels; i++)
749 rels[i].r_offset = BYTE_GET (erels[i].r_offset);
750 rels[i].r_info = BYTE_GET (erels[i].r_info);
751 rels[i].r_addend = 0;
758 Elf64_External_Rel *erels;
760 erels = get_data (NULL, file, rel_offset, 1, rel_size, _("relocs"));
764 nrels = rel_size / sizeof (Elf64_External_Rel);
766 rels = cmalloc (nrels, sizeof (Elf_Internal_Rela));
771 error (_("out of memory parsing relocs"));
775 for (i = 0; i < nrels; i++)
777 rels[i].r_offset = BYTE_GET (erels[i].r_offset);
778 rels[i].r_info = BYTE_GET (erels[i].r_info);
779 rels[i].r_addend = 0;
789 /* Display the contents of the relocation data found at the specified
793 dump_relocations (FILE *file,
794 unsigned long rel_offset,
795 unsigned long rel_size,
796 Elf_Internal_Sym *symtab,
799 unsigned long strtablen,
803 Elf_Internal_Rela *rels;
806 if (is_rela == UNKNOWN)
807 is_rela = guess_is_rela (elf_header.e_machine);
811 if (!slurp_rela_relocs (file, rel_offset, rel_size, &rels, &rel_size))
816 if (!slurp_rel_relocs (file, rel_offset, rel_size, &rels, &rel_size))
825 printf (_(" Offset Info Type Sym. Value Symbol's Name + Addend\n"));
827 printf (_(" Offset Info Type Sym.Value Sym. Name + Addend\n"));
832 printf (_(" Offset Info Type Sym. Value Symbol's Name\n"));
834 printf (_(" Offset Info Type Sym.Value Sym. Name\n"));
842 printf (_(" Offset Info Type Symbol's Value Symbol's Name + Addend\n"));
844 printf (_(" Offset Info Type Sym. Value Sym. Name + Addend\n"));
849 printf (_(" Offset Info Type Symbol's Value Symbol's Name\n"));
851 printf (_(" Offset Info Type Sym. Value Sym. Name\n"));
855 for (i = 0; i < rel_size; i++)
858 const char *rtype2 = NULL;
859 const char *rtype3 = NULL;
862 bfd_vma symtab_index;
867 offset = rels[i].r_offset;
868 info = rels[i].r_info;
872 type = ELF32_R_TYPE (info);
873 symtab_index = ELF32_R_SYM (info);
877 /* The #ifdef BFD64 below is to prevent a compile time warning.
878 We know that if we do not have a 64 bit data type that we
879 will never execute this code anyway. */
881 if (elf_header.e_machine == EM_MIPS)
883 /* In little-endian objects, r_info isn't really a 64-bit
884 little-endian value: it has a 32-bit little-endian
885 symbol index followed by four individual byte fields.
886 Reorder INFO accordingly. */
887 if (elf_header.e_ident[EI_DATA] != ELFDATA2MSB)
888 info = (((info & 0xffffffff) << 32)
889 | ((info >> 56) & 0xff)
890 | ((info >> 40) & 0xff00)
891 | ((info >> 24) & 0xff0000)
892 | ((info >> 8) & 0xff000000));
893 type = ELF64_MIPS_R_TYPE (info);
894 type2 = ELF64_MIPS_R_TYPE2 (info);
895 type3 = ELF64_MIPS_R_TYPE3 (info);
897 else if (elf_header.e_machine == EM_SPARCV9)
898 type = ELF64_R_TYPE_ID (info);
900 type = ELF64_R_TYPE (info);
902 symtab_index = ELF64_R_SYM (info);
908 #ifdef _bfd_int64_low
909 printf ("%8.8lx %8.8lx ", _bfd_int64_low (offset), _bfd_int64_low (info));
911 printf ("%8.8lx %8.8lx ", offset, info);
916 #ifdef _bfd_int64_low
918 ? "%8.8lx%8.8lx %8.8lx%8.8lx "
919 : "%4.4lx%8.8lx %4.4lx%8.8lx ",
920 _bfd_int64_high (offset),
921 _bfd_int64_low (offset),
922 _bfd_int64_high (info),
923 _bfd_int64_low (info));
926 ? "%16.16lx %16.16lx "
927 : "%12.12lx %12.12lx ",
932 switch (elf_header.e_machine)
940 rtype = elf_m32r_reloc_type (type);
945 rtype = elf_i386_reloc_type (type);
950 rtype = elf_m68hc11_reloc_type (type);
954 rtype = elf_m68k_reloc_type (type);
958 rtype = elf_i960_reloc_type (type);
963 rtype = elf_avr_reloc_type (type);
970 rtype = elf_sparc_reloc_type (type);
975 rtype = v850_reloc_type (type);
980 rtype = elf_d10v_reloc_type (type);
985 rtype = elf_d30v_reloc_type (type);
989 rtype = elf_dlx_reloc_type (type);
993 rtype = elf_sh_reloc_type (type);
997 case EM_CYGNUS_MN10300:
998 rtype = elf_mn10300_reloc_type (type);
1002 case EM_CYGNUS_MN10200:
1003 rtype = elf_mn10200_reloc_type (type);
1007 case EM_CYGNUS_FR30:
1008 rtype = elf_fr30_reloc_type (type);
1012 rtype = elf_frv_reloc_type (type);
1016 rtype = elf_mcore_reloc_type (type);
1020 rtype = elf_mmix_reloc_type (type);
1025 rtype = elf_msp430_reloc_type (type);
1029 rtype = elf_ppc_reloc_type (type);
1033 rtype = elf_ppc64_reloc_type (type);
1037 case EM_MIPS_RS3_LE:
1038 rtype = elf_mips_reloc_type (type);
1041 rtype2 = elf_mips_reloc_type (type2);
1042 rtype3 = elf_mips_reloc_type (type3);
1047 rtype = elf_alpha_reloc_type (type);
1051 rtype = elf_arm_reloc_type (type);
1055 rtype = elf_arc_reloc_type (type);
1059 rtype = elf_hppa_reloc_type (type);
1065 rtype = elf_h8_reloc_type (type);
1070 rtype = elf_or32_reloc_type (type);
1075 rtype = elf_pj_reloc_type (type);
1078 rtype = elf_ia64_reloc_type (type);
1082 rtype = elf_cris_reloc_type (type);
1086 rtype = elf_i860_reloc_type (type);
1090 rtype = elf_x86_64_reloc_type (type);
1094 rtype = i370_reloc_type (type);
1099 rtype = elf_s390_reloc_type (type);
1103 rtype = elf_xstormy16_reloc_type (type);
1107 rtype = elf_crx_reloc_type (type);
1111 rtype = elf_vax_reloc_type (type);
1116 rtype = elf_ip2k_reloc_type (type);
1120 rtype = elf_iq2000_reloc_type (type);
1125 rtype = elf_xtensa_reloc_type (type);
1129 rtype = elf_m32c_reloc_type (type);
1133 rtype = elf_mt_reloc_type (type);
1137 rtype = elf_bfin_reloc_type (type);
1142 #ifdef _bfd_int64_low
1143 printf (_("unrecognized: %-7lx"), _bfd_int64_low (type));
1145 printf (_("unrecognized: %-7lx"), type);
1148 printf (do_wide ? "%-22.22s" : "%-17.17s", rtype);
1150 if (elf_header.e_machine == EM_ALPHA
1152 && streq (rtype, "R_ALPHA_LITUSE")
1155 switch (rels[i].r_addend)
1157 case LITUSE_ALPHA_ADDR: rtype = "ADDR"; break;
1158 case LITUSE_ALPHA_BASE: rtype = "BASE"; break;
1159 case LITUSE_ALPHA_BYTOFF: rtype = "BYTOFF"; break;
1160 case LITUSE_ALPHA_JSR: rtype = "JSR"; break;
1161 case LITUSE_ALPHA_TLSGD: rtype = "TLSGD"; break;
1162 case LITUSE_ALPHA_TLSLDM: rtype = "TLSLDM"; break;
1163 case LITUSE_ALPHA_JSRDIRECT: rtype = "JSRDIRECT"; break;
1164 default: rtype = NULL;
1167 printf (" (%s)", rtype);
1171 printf (_("<unknown addend: %lx>"),
1172 (unsigned long) rels[i].r_addend);
1175 else if (symtab_index)
1177 if (symtab == NULL || symtab_index >= nsyms)
1178 printf (" bad symbol index: %08lx", (unsigned long) symtab_index);
1181 Elf_Internal_Sym *psym;
1183 psym = symtab + symtab_index;
1186 print_vma (psym->st_value, LONG_HEX);
1187 printf (is_32bit_elf ? " " : " ");
1189 if (psym->st_name == 0)
1191 const char *sec_name = "<null>";
1194 if (ELF_ST_TYPE (psym->st_info) == STT_SECTION)
1196 bfd_vma sec_index = (bfd_vma) -1;
1198 if (psym->st_shndx < SHN_LORESERVE)
1199 sec_index = psym->st_shndx;
1200 else if (psym->st_shndx > SHN_HIRESERVE)
1201 sec_index = psym->st_shndx - (SHN_HIRESERVE + 1
1204 if (sec_index != (bfd_vma) -1)
1205 sec_name = SECTION_NAME (section_headers + sec_index);
1206 else if (psym->st_shndx == SHN_ABS)
1208 else if (psym->st_shndx == SHN_COMMON)
1209 sec_name = "COMMON";
1210 else if (elf_header.e_machine == EM_MIPS
1211 && psym->st_shndx == SHN_MIPS_SCOMMON)
1212 sec_name = "SCOMMON";
1213 else if (elf_header.e_machine == EM_MIPS
1214 && psym->st_shndx == SHN_MIPS_SUNDEFINED)
1215 sec_name = "SUNDEF";
1216 else if (elf_header.e_machine == EM_X86_64
1217 && psym->st_shndx == SHN_X86_64_LCOMMON)
1218 sec_name = "LARGE_COMMON";
1219 else if (elf_header.e_machine == EM_IA_64
1220 && elf_header.e_ident[EI_OSABI] == ELFOSABI_HPUX
1221 && psym->st_shndx == SHN_IA_64_ANSI_COMMON)
1222 sec_name = "ANSI_COM";
1225 sprintf (name_buf, "<section 0x%x>",
1226 (unsigned int) psym->st_shndx);
1227 sec_name = name_buf;
1230 print_symbol (22, sec_name);
1232 else if (strtab == NULL)
1233 printf (_("<string table index: %3ld>"), psym->st_name);
1234 else if (psym->st_name >= strtablen)
1235 printf (_("<corrupt string table index: %3ld>"), psym->st_name);
1237 print_symbol (22, strtab + psym->st_name);
1240 printf (" + %lx", (unsigned long) rels[i].r_addend);
1245 printf ("%*c", is_32bit_elf ?
1246 (do_wide ? 34 : 28) : (do_wide ? 26 : 20), ' ');
1247 print_vma (rels[i].r_addend, LONG_HEX);
1250 if (elf_header.e_machine == EM_SPARCV9
1252 && streq (rtype, "R_SPARC_OLO10"))
1253 printf (" + %lx", (unsigned long) ELF64_R_TYPE_DATA (info));
1257 if (! is_32bit_elf && elf_header.e_machine == EM_MIPS)
1259 printf (" Type2: ");
1262 #ifdef _bfd_int64_low
1263 printf (_("unrecognized: %-7lx"), _bfd_int64_low (type2));
1265 printf (_("unrecognized: %-7lx"), type2);
1268 printf ("%-17.17s", rtype2);
1270 printf ("\n Type3: ");
1273 #ifdef _bfd_int64_low
1274 printf (_("unrecognized: %-7lx"), _bfd_int64_low (type3));
1276 printf (_("unrecognized: %-7lx"), type3);
1279 printf ("%-17.17s", rtype3);
1291 get_mips_dynamic_type (unsigned long type)
1295 case DT_MIPS_RLD_VERSION: return "MIPS_RLD_VERSION";
1296 case DT_MIPS_TIME_STAMP: return "MIPS_TIME_STAMP";
1297 case DT_MIPS_ICHECKSUM: return "MIPS_ICHECKSUM";
1298 case DT_MIPS_IVERSION: return "MIPS_IVERSION";
1299 case DT_MIPS_FLAGS: return "MIPS_FLAGS";
1300 case DT_MIPS_BASE_ADDRESS: return "MIPS_BASE_ADDRESS";
1301 case DT_MIPS_MSYM: return "MIPS_MSYM";
1302 case DT_MIPS_CONFLICT: return "MIPS_CONFLICT";
1303 case DT_MIPS_LIBLIST: return "MIPS_LIBLIST";
1304 case DT_MIPS_LOCAL_GOTNO: return "MIPS_LOCAL_GOTNO";
1305 case DT_MIPS_CONFLICTNO: return "MIPS_CONFLICTNO";
1306 case DT_MIPS_LIBLISTNO: return "MIPS_LIBLISTNO";
1307 case DT_MIPS_SYMTABNO: return "MIPS_SYMTABNO";
1308 case DT_MIPS_UNREFEXTNO: return "MIPS_UNREFEXTNO";
1309 case DT_MIPS_GOTSYM: return "MIPS_GOTSYM";
1310 case DT_MIPS_HIPAGENO: return "MIPS_HIPAGENO";
1311 case DT_MIPS_RLD_MAP: return "MIPS_RLD_MAP";
1312 case DT_MIPS_DELTA_CLASS: return "MIPS_DELTA_CLASS";
1313 case DT_MIPS_DELTA_CLASS_NO: return "MIPS_DELTA_CLASS_NO";
1314 case DT_MIPS_DELTA_INSTANCE: return "MIPS_DELTA_INSTANCE";
1315 case DT_MIPS_DELTA_INSTANCE_NO: return "MIPS_DELTA_INSTANCE_NO";
1316 case DT_MIPS_DELTA_RELOC: return "MIPS_DELTA_RELOC";
1317 case DT_MIPS_DELTA_RELOC_NO: return "MIPS_DELTA_RELOC_NO";
1318 case DT_MIPS_DELTA_SYM: return "MIPS_DELTA_SYM";
1319 case DT_MIPS_DELTA_SYM_NO: return "MIPS_DELTA_SYM_NO";
1320 case DT_MIPS_DELTA_CLASSSYM: return "MIPS_DELTA_CLASSSYM";
1321 case DT_MIPS_DELTA_CLASSSYM_NO: return "MIPS_DELTA_CLASSSYM_NO";
1322 case DT_MIPS_CXX_FLAGS: return "MIPS_CXX_FLAGS";
1323 case DT_MIPS_PIXIE_INIT: return "MIPS_PIXIE_INIT";
1324 case DT_MIPS_SYMBOL_LIB: return "MIPS_SYMBOL_LIB";
1325 case DT_MIPS_LOCALPAGE_GOTIDX: return "MIPS_LOCALPAGE_GOTIDX";
1326 case DT_MIPS_LOCAL_GOTIDX: return "MIPS_LOCAL_GOTIDX";
1327 case DT_MIPS_HIDDEN_GOTIDX: return "MIPS_HIDDEN_GOTIDX";
1328 case DT_MIPS_PROTECTED_GOTIDX: return "MIPS_PROTECTED_GOTIDX";
1329 case DT_MIPS_OPTIONS: return "MIPS_OPTIONS";
1330 case DT_MIPS_INTERFACE: return "MIPS_INTERFACE";
1331 case DT_MIPS_DYNSTR_ALIGN: return "MIPS_DYNSTR_ALIGN";
1332 case DT_MIPS_INTERFACE_SIZE: return "MIPS_INTERFACE_SIZE";
1333 case DT_MIPS_RLD_TEXT_RESOLVE_ADDR: return "MIPS_RLD_TEXT_RESOLVE_ADDR";
1334 case DT_MIPS_PERF_SUFFIX: return "MIPS_PERF_SUFFIX";
1335 case DT_MIPS_COMPACT_SIZE: return "MIPS_COMPACT_SIZE";
1336 case DT_MIPS_GP_VALUE: return "MIPS_GP_VALUE";
1337 case DT_MIPS_AUX_DYNAMIC: return "MIPS_AUX_DYNAMIC";
1344 get_sparc64_dynamic_type (unsigned long type)
1348 case DT_SPARC_REGISTER: return "SPARC_REGISTER";
1355 get_ppc_dynamic_type (unsigned long type)
1359 case DT_PPC_GOT: return "PPC_GOT";
1366 get_ppc64_dynamic_type (unsigned long type)
1370 case DT_PPC64_GLINK: return "PPC64_GLINK";
1371 case DT_PPC64_OPD: return "PPC64_OPD";
1372 case DT_PPC64_OPDSZ: return "PPC64_OPDSZ";
1379 get_parisc_dynamic_type (unsigned long type)
1383 case DT_HP_LOAD_MAP: return "HP_LOAD_MAP";
1384 case DT_HP_DLD_FLAGS: return "HP_DLD_FLAGS";
1385 case DT_HP_DLD_HOOK: return "HP_DLD_HOOK";
1386 case DT_HP_UX10_INIT: return "HP_UX10_INIT";
1387 case DT_HP_UX10_INITSZ: return "HP_UX10_INITSZ";
1388 case DT_HP_PREINIT: return "HP_PREINIT";
1389 case DT_HP_PREINITSZ: return "HP_PREINITSZ";
1390 case DT_HP_NEEDED: return "HP_NEEDED";
1391 case DT_HP_TIME_STAMP: return "HP_TIME_STAMP";
1392 case DT_HP_CHECKSUM: return "HP_CHECKSUM";
1393 case DT_HP_GST_SIZE: return "HP_GST_SIZE";
1394 case DT_HP_GST_VERSION: return "HP_GST_VERSION";
1395 case DT_HP_GST_HASHVAL: return "HP_GST_HASHVAL";
1396 case DT_HP_EPLTREL: return "HP_GST_EPLTREL";
1397 case DT_HP_EPLTRELSZ: return "HP_GST_EPLTRELSZ";
1398 case DT_HP_FILTERED: return "HP_FILTERED";
1399 case DT_HP_FILTER_TLS: return "HP_FILTER_TLS";
1400 case DT_HP_COMPAT_FILTERED: return "HP_COMPAT_FILTERED";
1401 case DT_HP_LAZYLOAD: return "HP_LAZYLOAD";
1402 case DT_HP_BIND_NOW_COUNT: return "HP_BIND_NOW_COUNT";
1403 case DT_PLT: return "PLT";
1404 case DT_PLT_SIZE: return "PLT_SIZE";
1405 case DT_DLT: return "DLT";
1406 case DT_DLT_SIZE: return "DLT_SIZE";
1413 get_ia64_dynamic_type (unsigned long type)
1417 case DT_IA_64_PLT_RESERVE: return "IA_64_PLT_RESERVE";
1424 get_alpha_dynamic_type (unsigned long type)
1428 case DT_ALPHA_PLTRO: return "ALPHA_PLTRO";
1435 get_dynamic_type (unsigned long type)
1437 static char buff[64];
1441 case DT_NULL: return "NULL";
1442 case DT_NEEDED: return "NEEDED";
1443 case DT_PLTRELSZ: return "PLTRELSZ";
1444 case DT_PLTGOT: return "PLTGOT";
1445 case DT_HASH: return "HASH";
1446 case DT_STRTAB: return "STRTAB";
1447 case DT_SYMTAB: return "SYMTAB";
1448 case DT_RELA: return "RELA";
1449 case DT_RELASZ: return "RELASZ";
1450 case DT_RELAENT: return "RELAENT";
1451 case DT_STRSZ: return "STRSZ";
1452 case DT_SYMENT: return "SYMENT";
1453 case DT_INIT: return "INIT";
1454 case DT_FINI: return "FINI";
1455 case DT_SONAME: return "SONAME";
1456 case DT_RPATH: return "RPATH";
1457 case DT_SYMBOLIC: return "SYMBOLIC";
1458 case DT_REL: return "REL";
1459 case DT_RELSZ: return "RELSZ";
1460 case DT_RELENT: return "RELENT";
1461 case DT_PLTREL: return "PLTREL";
1462 case DT_DEBUG: return "DEBUG";
1463 case DT_TEXTREL: return "TEXTREL";
1464 case DT_JMPREL: return "JMPREL";
1465 case DT_BIND_NOW: return "BIND_NOW";
1466 case DT_INIT_ARRAY: return "INIT_ARRAY";
1467 case DT_FINI_ARRAY: return "FINI_ARRAY";
1468 case DT_INIT_ARRAYSZ: return "INIT_ARRAYSZ";
1469 case DT_FINI_ARRAYSZ: return "FINI_ARRAYSZ";
1470 case DT_RUNPATH: return "RUNPATH";
1471 case DT_FLAGS: return "FLAGS";
1473 case DT_PREINIT_ARRAY: return "PREINIT_ARRAY";
1474 case DT_PREINIT_ARRAYSZ: return "PREINIT_ARRAYSZ";
1476 case DT_CHECKSUM: return "CHECKSUM";
1477 case DT_PLTPADSZ: return "PLTPADSZ";
1478 case DT_MOVEENT: return "MOVEENT";
1479 case DT_MOVESZ: return "MOVESZ";
1480 case DT_FEATURE: return "FEATURE";
1481 case DT_POSFLAG_1: return "POSFLAG_1";
1482 case DT_SYMINSZ: return "SYMINSZ";
1483 case DT_SYMINENT: return "SYMINENT"; /* aka VALRNGHI */
1485 case DT_ADDRRNGLO: return "ADDRRNGLO";
1486 case DT_CONFIG: return "CONFIG";
1487 case DT_DEPAUDIT: return "DEPAUDIT";
1488 case DT_AUDIT: return "AUDIT";
1489 case DT_PLTPAD: return "PLTPAD";
1490 case DT_MOVETAB: return "MOVETAB";
1491 case DT_SYMINFO: return "SYMINFO"; /* aka ADDRRNGHI */
1493 case DT_VERSYM: return "VERSYM";
1495 case DT_TLSDESC_GOT: return "TLSDESC_GOT";
1496 case DT_TLSDESC_PLT: return "TLSDESC_PLT";
1497 case DT_RELACOUNT: return "RELACOUNT";
1498 case DT_RELCOUNT: return "RELCOUNT";
1499 case DT_FLAGS_1: return "FLAGS_1";
1500 case DT_VERDEF: return "VERDEF";
1501 case DT_VERDEFNUM: return "VERDEFNUM";
1502 case DT_VERNEED: return "VERNEED";
1503 case DT_VERNEEDNUM: return "VERNEEDNUM";
1505 case DT_AUXILIARY: return "AUXILIARY";
1506 case DT_USED: return "USED";
1507 case DT_FILTER: return "FILTER";
1509 case DT_GNU_PRELINKED: return "GNU_PRELINKED";
1510 case DT_GNU_CONFLICT: return "GNU_CONFLICT";
1511 case DT_GNU_CONFLICTSZ: return "GNU_CONFLICTSZ";
1512 case DT_GNU_LIBLIST: return "GNU_LIBLIST";
1513 case DT_GNU_LIBLISTSZ: return "GNU_LIBLISTSZ";
1514 case DT_GNU_HASH: return "GNU_HASH";
1517 if ((type >= DT_LOPROC) && (type <= DT_HIPROC))
1521 switch (elf_header.e_machine)
1524 case EM_MIPS_RS3_LE:
1525 result = get_mips_dynamic_type (type);
1528 result = get_sparc64_dynamic_type (type);
1531 result = get_ppc_dynamic_type (type);
1534 result = get_ppc64_dynamic_type (type);
1537 result = get_ia64_dynamic_type (type);
1540 result = get_alpha_dynamic_type (type);
1550 snprintf (buff, sizeof (buff), _("Processor Specific: %lx"), type);
1552 else if (((type >= DT_LOOS) && (type <= DT_HIOS))
1553 || (elf_header.e_machine == EM_PARISC
1554 && (type >= OLD_DT_LOOS) && (type <= OLD_DT_HIOS)))
1558 switch (elf_header.e_machine)
1561 result = get_parisc_dynamic_type (type);
1571 snprintf (buff, sizeof (buff), _("Operating System specific: %lx"),
1575 snprintf (buff, sizeof (buff), _("<unknown>: %lx"), type);
1582 get_file_type (unsigned e_type)
1584 static char buff[32];
1588 case ET_NONE: return _("NONE (None)");
1589 case ET_REL: return _("REL (Relocatable file)");
1590 case ET_EXEC: return _("EXEC (Executable file)");
1591 case ET_DYN: return _("DYN (Shared object file)");
1592 case ET_CORE: return _("CORE (Core file)");
1595 if ((e_type >= ET_LOPROC) && (e_type <= ET_HIPROC))
1596 snprintf (buff, sizeof (buff), _("Processor Specific: (%x)"), e_type);
1597 else if ((e_type >= ET_LOOS) && (e_type <= ET_HIOS))
1598 snprintf (buff, sizeof (buff), _("OS Specific: (%x)"), e_type);
1600 snprintf (buff, sizeof (buff), _("<unknown>: %x"), e_type);
1606 get_machine_name (unsigned e_machine)
1608 static char buff[64]; /* XXX */
1612 case EM_NONE: return _("None");
1613 case EM_M32: return "WE32100";
1614 case EM_SPARC: return "Sparc";
1615 case EM_386: return "Intel 80386";
1616 case EM_68K: return "MC68000";
1617 case EM_88K: return "MC88000";
1618 case EM_486: return "Intel 80486";
1619 case EM_860: return "Intel 80860";
1620 case EM_MIPS: return "MIPS R3000";
1621 case EM_S370: return "IBM System/370";
1622 case EM_MIPS_RS3_LE: return "MIPS R4000 big-endian";
1623 case EM_OLD_SPARCV9: return "Sparc v9 (old)";
1624 case EM_PARISC: return "HPPA";
1625 case EM_PPC_OLD: return "Power PC (old)";
1626 case EM_SPARC32PLUS: return "Sparc v8+" ;
1627 case EM_960: return "Intel 90860";
1628 case EM_PPC: return "PowerPC";
1629 case EM_PPC64: return "PowerPC64";
1630 case EM_V800: return "NEC V800";
1631 case EM_FR20: return "Fujitsu FR20";
1632 case EM_RH32: return "TRW RH32";
1633 case EM_MCORE: return "MCORE";
1634 case EM_ARM: return "ARM";
1635 case EM_OLD_ALPHA: return "Digital Alpha (old)";
1636 case EM_SH: return "Renesas / SuperH SH";
1637 case EM_SPARCV9: return "Sparc v9";
1638 case EM_TRICORE: return "Siemens Tricore";
1639 case EM_ARC: return "ARC";
1640 case EM_H8_300: return "Renesas H8/300";
1641 case EM_H8_300H: return "Renesas H8/300H";
1642 case EM_H8S: return "Renesas H8S";
1643 case EM_H8_500: return "Renesas H8/500";
1644 case EM_IA_64: return "Intel IA-64";
1645 case EM_MIPS_X: return "Stanford MIPS-X";
1646 case EM_COLDFIRE: return "Motorola Coldfire";
1647 case EM_68HC12: return "Motorola M68HC12";
1648 case EM_ALPHA: return "Alpha";
1649 case EM_CYGNUS_D10V:
1650 case EM_D10V: return "d10v";
1651 case EM_CYGNUS_D30V:
1652 case EM_D30V: return "d30v";
1653 case EM_CYGNUS_M32R:
1654 case EM_M32R: return "Renesas M32R (formerly Mitsubishi M32r)";
1655 case EM_CYGNUS_V850:
1656 case EM_V850: return "NEC v850";
1657 case EM_CYGNUS_MN10300:
1658 case EM_MN10300: return "mn10300";
1659 case EM_CYGNUS_MN10200:
1660 case EM_MN10200: return "mn10200";
1661 case EM_CYGNUS_FR30:
1662 case EM_FR30: return "Fujitsu FR30";
1663 case EM_CYGNUS_FRV: return "Fujitsu FR-V";
1665 case EM_PJ: return "picoJava";
1666 case EM_MMA: return "Fujitsu Multimedia Accelerator";
1667 case EM_PCP: return "Siemens PCP";
1668 case EM_NCPU: return "Sony nCPU embedded RISC processor";
1669 case EM_NDR1: return "Denso NDR1 microprocesspr";
1670 case EM_STARCORE: return "Motorola Star*Core processor";
1671 case EM_ME16: return "Toyota ME16 processor";
1672 case EM_ST100: return "STMicroelectronics ST100 processor";
1673 case EM_TINYJ: return "Advanced Logic Corp. TinyJ embedded processor";
1674 case EM_FX66: return "Siemens FX66 microcontroller";
1675 case EM_ST9PLUS: return "STMicroelectronics ST9+ 8/16 bit microcontroller";
1676 case EM_ST7: return "STMicroelectronics ST7 8-bit microcontroller";
1677 case EM_68HC16: return "Motorola MC68HC16 Microcontroller";
1678 case EM_68HC11: return "Motorola MC68HC11 Microcontroller";
1679 case EM_68HC08: return "Motorola MC68HC08 Microcontroller";
1680 case EM_68HC05: return "Motorola MC68HC05 Microcontroller";
1681 case EM_SVX: return "Silicon Graphics SVx";
1682 case EM_ST19: return "STMicroelectronics ST19 8-bit microcontroller";
1683 case EM_VAX: return "Digital VAX";
1685 case EM_AVR: return "Atmel AVR 8-bit microcontroller";
1686 case EM_CRIS: return "Axis Communications 32-bit embedded processor";
1687 case EM_JAVELIN: return "Infineon Technologies 32-bit embedded cpu";
1688 case EM_FIREPATH: return "Element 14 64-bit DSP processor";
1689 case EM_ZSP: return "LSI Logic's 16-bit DSP processor";
1690 case EM_MMIX: return "Donald Knuth's educational 64-bit processor";
1691 case EM_HUANY: return "Harvard Universitys's machine-independent object format";
1692 case EM_PRISM: return "Vitesse Prism";
1693 case EM_X86_64: return "Advanced Micro Devices X86-64";
1695 case EM_S390: return "IBM S/390";
1696 case EM_XSTORMY16: return "Sanyo Xstormy16 CPU core";
1698 case EM_OR32: return "OpenRISC";
1699 case EM_CRX: return "National Semiconductor CRX microprocessor";
1700 case EM_DLX: return "OpenDLX";
1702 case EM_IP2K: return "Ubicom IP2xxx 8-bit microcontrollers";
1703 case EM_IQ2000: return "Vitesse IQ2000";
1705 case EM_XTENSA: return "Tensilica Xtensa Processor";
1706 case EM_M32C: return "Renesas M32c";
1707 case EM_MT: return "Morpho Techologies MT processor";
1708 case EM_BLACKFIN: return "Analog Devices Blackfin";
1709 case EM_NIOS32: return "Altera Nios";
1710 case EM_ALTERA_NIOS2: return "Altera Nios II";
1711 case EM_XC16X: return "Infineon Technologies xc16x";
1713 snprintf (buff, sizeof (buff), _("<unknown>: %x"), e_machine);
1719 decode_ARM_machine_flags (unsigned e_flags, char buf[])
1724 eabi = EF_ARM_EABI_VERSION (e_flags);
1725 e_flags &= ~ EF_ARM_EABIMASK;
1727 /* Handle "generic" ARM flags. */
1728 if (e_flags & EF_ARM_RELEXEC)
1730 strcat (buf, ", relocatable executable");
1731 e_flags &= ~ EF_ARM_RELEXEC;
1734 if (e_flags & EF_ARM_HASENTRY)
1736 strcat (buf, ", has entry point");
1737 e_flags &= ~ EF_ARM_HASENTRY;
1740 /* Now handle EABI specific flags. */
1744 strcat (buf, ", <unrecognized EABI>");
1749 case EF_ARM_EABI_VER1:
1750 strcat (buf, ", Version1 EABI");
1755 /* Process flags one bit at a time. */
1756 flag = e_flags & - e_flags;
1761 case EF_ARM_SYMSARESORTED: /* Conflicts with EF_ARM_INTERWORK. */
1762 strcat (buf, ", sorted symbol tables");
1772 case EF_ARM_EABI_VER2:
1773 strcat (buf, ", Version2 EABI");
1778 /* Process flags one bit at a time. */
1779 flag = e_flags & - e_flags;
1784 case EF_ARM_SYMSARESORTED: /* Conflicts with EF_ARM_INTERWORK. */
1785 strcat (buf, ", sorted symbol tables");
1788 case EF_ARM_DYNSYMSUSESEGIDX:
1789 strcat (buf, ", dynamic symbols use segment index");
1792 case EF_ARM_MAPSYMSFIRST:
1793 strcat (buf, ", mapping symbols precede others");
1803 case EF_ARM_EABI_VER3:
1804 strcat (buf, ", Version3 EABI");
1807 case EF_ARM_EABI_VER4:
1808 strcat (buf, ", Version4 EABI");
1811 case EF_ARM_EABI_VER5:
1812 strcat (buf, ", Version5 EABI");
1818 /* Process flags one bit at a time. */
1819 flag = e_flags & - e_flags;
1825 strcat (buf, ", BE8");
1829 strcat (buf, ", LE8");
1839 case EF_ARM_EABI_UNKNOWN:
1840 strcat (buf, ", GNU EABI");
1845 /* Process flags one bit at a time. */
1846 flag = e_flags & - e_flags;
1851 case EF_ARM_INTERWORK:
1852 strcat (buf, ", interworking enabled");
1855 case EF_ARM_APCS_26:
1856 strcat (buf, ", uses APCS/26");
1859 case EF_ARM_APCS_FLOAT:
1860 strcat (buf, ", uses APCS/float");
1864 strcat (buf, ", position independent");
1868 strcat (buf, ", 8 bit structure alignment");
1871 case EF_ARM_NEW_ABI:
1872 strcat (buf, ", uses new ABI");
1875 case EF_ARM_OLD_ABI:
1876 strcat (buf, ", uses old ABI");
1879 case EF_ARM_SOFT_FLOAT:
1880 strcat (buf, ", software FP");
1883 case EF_ARM_VFP_FLOAT:
1884 strcat (buf, ", VFP");
1887 case EF_ARM_MAVERICK_FLOAT:
1888 strcat (buf, ", Maverick FP");
1899 strcat (buf,", <unknown>");
1903 get_machine_flags (unsigned e_flags, unsigned e_machine)
1905 static char buf[1024];
1917 decode_ARM_machine_flags (e_flags, buf);
1921 switch (e_flags & EF_FRV_CPU_MASK)
1923 case EF_FRV_CPU_GENERIC:
1927 strcat (buf, ", fr???");
1930 case EF_FRV_CPU_FR300:
1931 strcat (buf, ", fr300");
1934 case EF_FRV_CPU_FR400:
1935 strcat (buf, ", fr400");
1937 case EF_FRV_CPU_FR405:
1938 strcat (buf, ", fr405");
1941 case EF_FRV_CPU_FR450:
1942 strcat (buf, ", fr450");
1945 case EF_FRV_CPU_FR500:
1946 strcat (buf, ", fr500");
1948 case EF_FRV_CPU_FR550:
1949 strcat (buf, ", fr550");
1952 case EF_FRV_CPU_SIMPLE:
1953 strcat (buf, ", simple");
1955 case EF_FRV_CPU_TOMCAT:
1956 strcat (buf, ", tomcat");
1962 if (e_flags & EF_M68K_CPU32)
1963 strcat (buf, ", cpu32");
1964 if (e_flags & EF_M68K_M68000)
1965 strcat (buf, ", m68000");
1966 if (e_flags & EF_M68K_ISA_MASK)
1968 char const *isa = _("unknown");
1969 char const *mac = _("unknown mac");
1970 char const *additional = NULL;
1972 switch (e_flags & EF_M68K_ISA_MASK)
1974 case EF_M68K_ISA_A_NODIV:
1976 additional = ", nodiv";
1981 case EF_M68K_ISA_A_PLUS:
1984 case EF_M68K_ISA_B_NOUSP:
1986 additional = ", nousp";
1992 strcat (buf, ", cf, isa ");
1995 strcat (buf, additional);
1996 if (e_flags & EF_M68K_FLOAT)
1997 strcat (buf, ", float");
1998 switch (e_flags & EF_M68K_MAC_MASK)
2019 if (e_flags & EF_PPC_EMB)
2020 strcat (buf, ", emb");
2022 if (e_flags & EF_PPC_RELOCATABLE)
2023 strcat (buf, ", relocatable");
2025 if (e_flags & EF_PPC_RELOCATABLE_LIB)
2026 strcat (buf, ", relocatable-lib");
2030 case EM_CYGNUS_V850:
2031 switch (e_flags & EF_V850_ARCH)
2034 strcat (buf, ", v850e1");
2037 strcat (buf, ", v850e");
2040 strcat (buf, ", v850");
2043 strcat (buf, ", unknown v850 architecture variant");
2049 case EM_CYGNUS_M32R:
2050 if ((e_flags & EF_M32R_ARCH) == E_M32R_ARCH)
2051 strcat (buf, ", m32r");
2055 case EM_MIPS_RS3_LE:
2056 if (e_flags & EF_MIPS_NOREORDER)
2057 strcat (buf, ", noreorder");
2059 if (e_flags & EF_MIPS_PIC)
2060 strcat (buf, ", pic");
2062 if (e_flags & EF_MIPS_CPIC)
2063 strcat (buf, ", cpic");
2065 if (e_flags & EF_MIPS_UCODE)
2066 strcat (buf, ", ugen_reserved");
2068 if (e_flags & EF_MIPS_ABI2)
2069 strcat (buf, ", abi2");
2071 if (e_flags & EF_MIPS_OPTIONS_FIRST)
2072 strcat (buf, ", odk first");
2074 if (e_flags & EF_MIPS_32BITMODE)
2075 strcat (buf, ", 32bitmode");
2077 switch ((e_flags & EF_MIPS_MACH))
2079 case E_MIPS_MACH_3900: strcat (buf, ", 3900"); break;
2080 case E_MIPS_MACH_4010: strcat (buf, ", 4010"); break;
2081 case E_MIPS_MACH_4100: strcat (buf, ", 4100"); break;
2082 case E_MIPS_MACH_4111: strcat (buf, ", 4111"); break;
2083 case E_MIPS_MACH_4120: strcat (buf, ", 4120"); break;
2084 case E_MIPS_MACH_4650: strcat (buf, ", 4650"); break;
2085 case E_MIPS_MACH_5400: strcat (buf, ", 5400"); break;
2086 case E_MIPS_MACH_5500: strcat (buf, ", 5500"); break;
2087 case E_MIPS_MACH_SB1: strcat (buf, ", sb1"); break;
2088 case E_MIPS_MACH_9000: strcat (buf, ", 9000"); break;
2090 /* We simply ignore the field in this case to avoid confusion:
2091 MIPS ELF does not specify EF_MIPS_MACH, it is a GNU
2094 default: strcat (buf, ", unknown CPU"); break;
2097 switch ((e_flags & EF_MIPS_ABI))
2099 case E_MIPS_ABI_O32: strcat (buf, ", o32"); break;
2100 case E_MIPS_ABI_O64: strcat (buf, ", o64"); break;
2101 case E_MIPS_ABI_EABI32: strcat (buf, ", eabi32"); break;
2102 case E_MIPS_ABI_EABI64: strcat (buf, ", eabi64"); break;
2104 /* We simply ignore the field in this case to avoid confusion:
2105 MIPS ELF does not specify EF_MIPS_ABI, it is a GNU extension.
2106 This means it is likely to be an o32 file, but not for
2109 default: strcat (buf, ", unknown ABI"); break;
2112 if (e_flags & EF_MIPS_ARCH_ASE_MDMX)
2113 strcat (buf, ", mdmx");
2115 if (e_flags & EF_MIPS_ARCH_ASE_M16)
2116 strcat (buf, ", mips16");
2118 switch ((e_flags & EF_MIPS_ARCH))
2120 case E_MIPS_ARCH_1: strcat (buf, ", mips1"); break;
2121 case E_MIPS_ARCH_2: strcat (buf, ", mips2"); break;
2122 case E_MIPS_ARCH_3: strcat (buf, ", mips3"); break;
2123 case E_MIPS_ARCH_4: strcat (buf, ", mips4"); break;
2124 case E_MIPS_ARCH_5: strcat (buf, ", mips5"); break;
2125 case E_MIPS_ARCH_32: strcat (buf, ", mips32"); break;
2126 case E_MIPS_ARCH_32R2: strcat (buf, ", mips32r2"); break;
2127 case E_MIPS_ARCH_64: strcat (buf, ", mips64"); break;
2128 case E_MIPS_ARCH_64R2: strcat (buf, ", mips64r2"); break;
2129 default: strcat (buf, ", unknown ISA"); break;
2135 switch ((e_flags & EF_SH_MACH_MASK))
2137 case EF_SH1: strcat (buf, ", sh1"); break;
2138 case EF_SH2: strcat (buf, ", sh2"); break;
2139 case EF_SH3: strcat (buf, ", sh3"); break;
2140 case EF_SH_DSP: strcat (buf, ", sh-dsp"); break;
2141 case EF_SH3_DSP: strcat (buf, ", sh3-dsp"); break;
2142 case EF_SH4AL_DSP: strcat (buf, ", sh4al-dsp"); break;
2143 case EF_SH3E: strcat (buf, ", sh3e"); break;
2144 case EF_SH4: strcat (buf, ", sh4"); break;
2145 case EF_SH5: strcat (buf, ", sh5"); break;
2146 case EF_SH2E: strcat (buf, ", sh2e"); break;
2147 case EF_SH4A: strcat (buf, ", sh4a"); break;
2148 case EF_SH2A: strcat (buf, ", sh2a"); break;
2149 case EF_SH4_NOFPU: strcat (buf, ", sh4-nofpu"); break;
2150 case EF_SH4A_NOFPU: strcat (buf, ", sh4a-nofpu"); break;
2151 case EF_SH2A_NOFPU: strcat (buf, ", sh2a-nofpu"); break;
2152 case EF_SH3_NOMMU: strcat (buf, ", sh3-nommu"); break;
2153 case EF_SH4_NOMMU_NOFPU: strcat (buf, ", sh4-nommu-nofpu"); break;
2154 case EF_SH2A_SH4_NOFPU: strcat (buf, ", sh2a-nofpu-or-sh4-nommu-nofpu"); break;
2155 case EF_SH2A_SH3_NOFPU: strcat (buf, ", sh2a-nofpu-or-sh3-nommu"); break;
2156 case EF_SH2A_SH4: strcat (buf, ", sh2a-or-sh4"); break;
2157 case EF_SH2A_SH3E: strcat (buf, ", sh2a-or-sh3e"); break;
2158 default: strcat (buf, ", unknown ISA"); break;
2164 if (e_flags & EF_SPARC_32PLUS)
2165 strcat (buf, ", v8+");
2167 if (e_flags & EF_SPARC_SUN_US1)
2168 strcat (buf, ", ultrasparcI");
2170 if (e_flags & EF_SPARC_SUN_US3)
2171 strcat (buf, ", ultrasparcIII");
2173 if (e_flags & EF_SPARC_HAL_R1)
2174 strcat (buf, ", halr1");
2176 if (e_flags & EF_SPARC_LEDATA)
2177 strcat (buf, ", ledata");
2179 if ((e_flags & EF_SPARCV9_MM) == EF_SPARCV9_TSO)
2180 strcat (buf, ", tso");
2182 if ((e_flags & EF_SPARCV9_MM) == EF_SPARCV9_PSO)
2183 strcat (buf, ", pso");
2185 if ((e_flags & EF_SPARCV9_MM) == EF_SPARCV9_RMO)
2186 strcat (buf, ", rmo");
2190 switch (e_flags & EF_PARISC_ARCH)
2192 case EFA_PARISC_1_0:
2193 strcpy (buf, ", PA-RISC 1.0");
2195 case EFA_PARISC_1_1:
2196 strcpy (buf, ", PA-RISC 1.1");
2198 case EFA_PARISC_2_0:
2199 strcpy (buf, ", PA-RISC 2.0");
2204 if (e_flags & EF_PARISC_TRAPNIL)
2205 strcat (buf, ", trapnil");
2206 if (e_flags & EF_PARISC_EXT)
2207 strcat (buf, ", ext");
2208 if (e_flags & EF_PARISC_LSB)
2209 strcat (buf, ", lsb");
2210 if (e_flags & EF_PARISC_WIDE)
2211 strcat (buf, ", wide");
2212 if (e_flags & EF_PARISC_NO_KABP)
2213 strcat (buf, ", no kabp");
2214 if (e_flags & EF_PARISC_LAZYSWAP)
2215 strcat (buf, ", lazyswap");
2220 if ((e_flags & EF_PICOJAVA_NEWCALLS) == EF_PICOJAVA_NEWCALLS)
2221 strcat (buf, ", new calling convention");
2223 if ((e_flags & EF_PICOJAVA_GNUCALLS) == EF_PICOJAVA_GNUCALLS)
2224 strcat (buf, ", gnu calling convention");
2228 if ((e_flags & EF_IA_64_ABI64))
2229 strcat (buf, ", 64-bit");
2231 strcat (buf, ", 32-bit");
2232 if ((e_flags & EF_IA_64_REDUCEDFP))
2233 strcat (buf, ", reduced fp model");
2234 if ((e_flags & EF_IA_64_NOFUNCDESC_CONS_GP))
2235 strcat (buf, ", no function descriptors, constant gp");
2236 else if ((e_flags & EF_IA_64_CONS_GP))
2237 strcat (buf, ", constant gp");
2238 if ((e_flags & EF_IA_64_ABSOLUTE))
2239 strcat (buf, ", absolute");
2243 if ((e_flags & EF_VAX_NONPIC))
2244 strcat (buf, ", non-PIC");
2245 if ((e_flags & EF_VAX_DFLOAT))
2246 strcat (buf, ", D-Float");
2247 if ((e_flags & EF_VAX_GFLOAT))
2248 strcat (buf, ", G-Float");
2257 get_osabi_name (unsigned int osabi)
2259 static char buff[32];
2263 case ELFOSABI_NONE: return "UNIX - System V";
2264 case ELFOSABI_HPUX: return "UNIX - HP-UX";
2265 case ELFOSABI_NETBSD: return "UNIX - NetBSD";
2266 case ELFOSABI_LINUX: return "UNIX - Linux";
2267 case ELFOSABI_HURD: return "GNU/Hurd";
2268 case ELFOSABI_SOLARIS: return "UNIX - Solaris";
2269 case ELFOSABI_AIX: return "UNIX - AIX";
2270 case ELFOSABI_IRIX: return "UNIX - IRIX";
2271 case ELFOSABI_FREEBSD: return "UNIX - FreeBSD";
2272 case ELFOSABI_TRU64: return "UNIX - TRU64";
2273 case ELFOSABI_MODESTO: return "Novell - Modesto";
2274 case ELFOSABI_OPENBSD: return "UNIX - OpenBSD";
2275 case ELFOSABI_OPENVMS: return "VMS - OpenVMS";
2276 case ELFOSABI_NSK: return "HP - Non-Stop Kernel";
2277 case ELFOSABI_AROS: return "Amiga Research OS";
2278 case ELFOSABI_STANDALONE: return _("Standalone App");
2279 case ELFOSABI_ARM: return "ARM";
2281 snprintf (buff, sizeof (buff), _("<unknown: %x>"), osabi);
2287 get_arm_segment_type (unsigned long type)
2301 get_mips_segment_type (unsigned long type)
2305 case PT_MIPS_REGINFO:
2307 case PT_MIPS_RTPROC:
2309 case PT_MIPS_OPTIONS:
2319 get_parisc_segment_type (unsigned long type)
2323 case PT_HP_TLS: return "HP_TLS";
2324 case PT_HP_CORE_NONE: return "HP_CORE_NONE";
2325 case PT_HP_CORE_VERSION: return "HP_CORE_VERSION";
2326 case PT_HP_CORE_KERNEL: return "HP_CORE_KERNEL";
2327 case PT_HP_CORE_COMM: return "HP_CORE_COMM";
2328 case PT_HP_CORE_PROC: return "HP_CORE_PROC";
2329 case PT_HP_CORE_LOADABLE: return "HP_CORE_LOADABLE";
2330 case PT_HP_CORE_STACK: return "HP_CORE_STACK";
2331 case PT_HP_CORE_SHM: return "HP_CORE_SHM";
2332 case PT_HP_CORE_MMF: return "HP_CORE_MMF";
2333 case PT_HP_PARALLEL: return "HP_PARALLEL";
2334 case PT_HP_FASTBIND: return "HP_FASTBIND";
2335 case PT_HP_OPT_ANNOT: return "HP_OPT_ANNOT";
2336 case PT_HP_HSL_ANNOT: return "HP_HSL_ANNOT";
2337 case PT_HP_STACK: return "HP_STACK";
2338 case PT_HP_CORE_UTSNAME: return "HP_CORE_UTSNAME";
2339 case PT_PARISC_ARCHEXT: return "PARISC_ARCHEXT";
2340 case PT_PARISC_UNWIND: return "PARISC_UNWIND";
2341 case PT_PARISC_WEAKORDER: return "PARISC_WEAKORDER";
2350 get_ia64_segment_type (unsigned long type)
2354 case PT_IA_64_ARCHEXT: return "IA_64_ARCHEXT";
2355 case PT_IA_64_UNWIND: return "IA_64_UNWIND";
2356 case PT_HP_TLS: return "HP_TLS";
2357 case PT_IA_64_HP_OPT_ANOT: return "HP_OPT_ANNOT";
2358 case PT_IA_64_HP_HSL_ANOT: return "HP_HSL_ANNOT";
2359 case PT_IA_64_HP_STACK: return "HP_STACK";
2368 get_segment_type (unsigned long p_type)
2370 static char buff[32];
2374 case PT_NULL: return "NULL";
2375 case PT_LOAD: return "LOAD";
2376 case PT_DYNAMIC: return "DYNAMIC";
2377 case PT_INTERP: return "INTERP";
2378 case PT_NOTE: return "NOTE";
2379 case PT_SHLIB: return "SHLIB";
2380 case PT_PHDR: return "PHDR";
2381 case PT_TLS: return "TLS";
2383 case PT_GNU_EH_FRAME:
2384 return "GNU_EH_FRAME";
2385 case PT_GNU_STACK: return "GNU_STACK";
2386 case PT_GNU_RELRO: return "GNU_RELRO";
2389 if ((p_type >= PT_LOPROC) && (p_type <= PT_HIPROC))
2393 switch (elf_header.e_machine)
2396 result = get_arm_segment_type (p_type);
2399 case EM_MIPS_RS3_LE:
2400 result = get_mips_segment_type (p_type);
2403 result = get_parisc_segment_type (p_type);
2406 result = get_ia64_segment_type (p_type);
2416 sprintf (buff, "LOPROC+%lx", p_type - PT_LOPROC);
2418 else if ((p_type >= PT_LOOS) && (p_type <= PT_HIOS))
2422 switch (elf_header.e_machine)
2425 result = get_parisc_segment_type (p_type);
2428 result = get_ia64_segment_type (p_type);
2438 sprintf (buff, "LOOS+%lx", p_type - PT_LOOS);
2441 snprintf (buff, sizeof (buff), _("<unknown>: %lx"), p_type);
2448 get_mips_section_type_name (unsigned int sh_type)
2452 case SHT_MIPS_LIBLIST: return "MIPS_LIBLIST";
2453 case SHT_MIPS_MSYM: return "MIPS_MSYM";
2454 case SHT_MIPS_CONFLICT: return "MIPS_CONFLICT";
2455 case SHT_MIPS_GPTAB: return "MIPS_GPTAB";
2456 case SHT_MIPS_UCODE: return "MIPS_UCODE";
2457 case SHT_MIPS_DEBUG: return "MIPS_DEBUG";
2458 case SHT_MIPS_REGINFO: return "MIPS_REGINFO";
2459 case SHT_MIPS_PACKAGE: return "MIPS_PACKAGE";
2460 case SHT_MIPS_PACKSYM: return "MIPS_PACKSYM";
2461 case SHT_MIPS_RELD: return "MIPS_RELD";
2462 case SHT_MIPS_IFACE: return "MIPS_IFACE";
2463 case SHT_MIPS_CONTENT: return "MIPS_CONTENT";
2464 case SHT_MIPS_OPTIONS: return "MIPS_OPTIONS";
2465 case SHT_MIPS_SHDR: return "MIPS_SHDR";
2466 case SHT_MIPS_FDESC: return "MIPS_FDESC";
2467 case SHT_MIPS_EXTSYM: return "MIPS_EXTSYM";
2468 case SHT_MIPS_DENSE: return "MIPS_DENSE";
2469 case SHT_MIPS_PDESC: return "MIPS_PDESC";
2470 case SHT_MIPS_LOCSYM: return "MIPS_LOCSYM";
2471 case SHT_MIPS_AUXSYM: return "MIPS_AUXSYM";
2472 case SHT_MIPS_OPTSYM: return "MIPS_OPTSYM";
2473 case SHT_MIPS_LOCSTR: return "MIPS_LOCSTR";
2474 case SHT_MIPS_LINE: return "MIPS_LINE";
2475 case SHT_MIPS_RFDESC: return "MIPS_RFDESC";
2476 case SHT_MIPS_DELTASYM: return "MIPS_DELTASYM";
2477 case SHT_MIPS_DELTAINST: return "MIPS_DELTAINST";
2478 case SHT_MIPS_DELTACLASS: return "MIPS_DELTACLASS";
2479 case SHT_MIPS_DWARF: return "MIPS_DWARF";
2480 case SHT_MIPS_DELTADECL: return "MIPS_DELTADECL";
2481 case SHT_MIPS_SYMBOL_LIB: return "MIPS_SYMBOL_LIB";
2482 case SHT_MIPS_EVENTS: return "MIPS_EVENTS";
2483 case SHT_MIPS_TRANSLATE: return "MIPS_TRANSLATE";
2484 case SHT_MIPS_PIXIE: return "MIPS_PIXIE";
2485 case SHT_MIPS_XLATE: return "MIPS_XLATE";
2486 case SHT_MIPS_XLATE_DEBUG: return "MIPS_XLATE_DEBUG";
2487 case SHT_MIPS_WHIRL: return "MIPS_WHIRL";
2488 case SHT_MIPS_EH_REGION: return "MIPS_EH_REGION";
2489 case SHT_MIPS_XLATE_OLD: return "MIPS_XLATE_OLD";
2490 case SHT_MIPS_PDR_EXCEPTION: return "MIPS_PDR_EXCEPTION";
2498 get_parisc_section_type_name (unsigned int sh_type)
2502 case SHT_PARISC_EXT: return "PARISC_EXT";
2503 case SHT_PARISC_UNWIND: return "PARISC_UNWIND";
2504 case SHT_PARISC_DOC: return "PARISC_DOC";
2505 case SHT_PARISC_ANNOT: return "PARISC_ANNOT";
2506 case SHT_PARISC_SYMEXTN: return "PARISC_SYMEXTN";
2507 case SHT_PARISC_STUBS: return "PARISC_STUBS";
2508 case SHT_PARISC_DLKM: return "PARISC_DLKM";
2516 get_ia64_section_type_name (unsigned int sh_type)
2518 /* If the top 8 bits are 0x78 the next 8 are the os/abi ID. */
2519 if ((sh_type & 0xFF000000) == SHT_IA_64_LOPSREG)
2520 return get_osabi_name ((sh_type & 0x00FF0000) >> 16);
2524 case SHT_IA_64_EXT: return "IA_64_EXT";
2525 case SHT_IA_64_UNWIND: return "IA_64_UNWIND";
2526 case SHT_IA_64_PRIORITY_INIT: return "IA_64_PRIORITY_INIT";
2534 get_x86_64_section_type_name (unsigned int sh_type)
2538 case SHT_X86_64_UNWIND: return "X86_64_UNWIND";
2546 get_arm_section_type_name (unsigned int sh_type)
2552 case SHT_ARM_PREEMPTMAP:
2553 return "ARM_PREEMPTMAP";
2554 case SHT_ARM_ATTRIBUTES:
2555 return "ARM_ATTRIBUTES";
2563 get_section_type_name (unsigned int sh_type)
2565 static char buff[32];
2569 case SHT_NULL: return "NULL";
2570 case SHT_PROGBITS: return "PROGBITS";
2571 case SHT_SYMTAB: return "SYMTAB";
2572 case SHT_STRTAB: return "STRTAB";
2573 case SHT_RELA: return "RELA";
2574 case SHT_HASH: return "HASH";
2575 case SHT_DYNAMIC: return "DYNAMIC";
2576 case SHT_NOTE: return "NOTE";
2577 case SHT_NOBITS: return "NOBITS";
2578 case SHT_REL: return "REL";
2579 case SHT_SHLIB: return "SHLIB";
2580 case SHT_DYNSYM: return "DYNSYM";
2581 case SHT_INIT_ARRAY: return "INIT_ARRAY";
2582 case SHT_FINI_ARRAY: return "FINI_ARRAY";
2583 case SHT_PREINIT_ARRAY: return "PREINIT_ARRAY";
2584 case SHT_GNU_HASH: return "GNU_HASH";
2585 case SHT_GROUP: return "GROUP";
2586 case SHT_SYMTAB_SHNDX: return "SYMTAB SECTION INDICIES";
2587 case SHT_GNU_verdef: return "VERDEF";
2588 case SHT_GNU_verneed: return "VERNEED";
2589 case SHT_GNU_versym: return "VERSYM";
2590 case 0x6ffffff0: return "VERSYM";
2591 case 0x6ffffffc: return "VERDEF";
2592 case 0x7ffffffd: return "AUXILIARY";
2593 case 0x7fffffff: return "FILTER";
2594 case SHT_GNU_LIBLIST: return "GNU_LIBLIST";
2597 if ((sh_type >= SHT_LOPROC) && (sh_type <= SHT_HIPROC))
2601 switch (elf_header.e_machine)
2604 case EM_MIPS_RS3_LE:
2605 result = get_mips_section_type_name (sh_type);
2608 result = get_parisc_section_type_name (sh_type);
2611 result = get_ia64_section_type_name (sh_type);
2614 result = get_x86_64_section_type_name (sh_type);
2617 result = get_arm_section_type_name (sh_type);
2627 sprintf (buff, "LOPROC+%x", sh_type - SHT_LOPROC);
2629 else if ((sh_type >= SHT_LOOS) && (sh_type <= SHT_HIOS))
2630 sprintf (buff, "LOOS+%x", sh_type - SHT_LOOS);
2631 else if ((sh_type >= SHT_LOUSER) && (sh_type <= SHT_HIUSER))
2632 sprintf (buff, "LOUSER+%x", sh_type - SHT_LOUSER);
2634 snprintf (buff, sizeof (buff), _("<unknown>: %x"), sh_type);
2640 #define OPTION_DEBUG_DUMP 512
2642 static struct option options[] =
2644 {"all", no_argument, 0, 'a'},
2645 {"file-header", no_argument, 0, 'h'},
2646 {"program-headers", no_argument, 0, 'l'},
2647 {"headers", no_argument, 0, 'e'},
2648 {"histogram", no_argument, 0, 'I'},
2649 {"segments", no_argument, 0, 'l'},
2650 {"sections", no_argument, 0, 'S'},
2651 {"section-headers", no_argument, 0, 'S'},
2652 {"section-groups", no_argument, 0, 'g'},
2653 {"section-details", no_argument, 0, 't'},
2654 {"full-section-name",no_argument, 0, 'N'},
2655 {"symbols", no_argument, 0, 's'},
2656 {"syms", no_argument, 0, 's'},
2657 {"relocs", no_argument, 0, 'r'},
2658 {"notes", no_argument, 0, 'n'},
2659 {"dynamic", no_argument, 0, 'd'},
2660 {"arch-specific", no_argument, 0, 'A'},
2661 {"version-info", no_argument, 0, 'V'},
2662 {"use-dynamic", no_argument, 0, 'D'},
2663 {"hex-dump", required_argument, 0, 'x'},
2664 {"debug-dump", optional_argument, 0, OPTION_DEBUG_DUMP},
2665 {"unwind", no_argument, 0, 'u'},
2666 #ifdef SUPPORT_DISASSEMBLY
2667 {"instruction-dump", required_argument, 0, 'i'},
2670 {"version", no_argument, 0, 'v'},
2671 {"wide", no_argument, 0, 'W'},
2672 {"help", no_argument, 0, 'H'},
2673 {0, no_argument, 0, 0}
2679 fprintf (stdout, _("Usage: readelf <option(s)> elf-file(s)\n"));
2680 fprintf (stdout, _(" Display information about the contents of ELF format files\n"));
2681 fprintf (stdout, _(" Options are:\n\
2682 -a --all Equivalent to: -h -l -S -s -r -d -V -A -I\n\
2683 -h --file-header Display the ELF file header\n\
2684 -l --program-headers Display the program headers\n\
2685 --segments An alias for --program-headers\n\
2686 -S --section-headers Display the sections' header\n\
2687 --sections An alias for --section-headers\n\
2688 -g --section-groups Display the section groups\n\
2689 -t --section-details Display the section details\n\
2690 -e --headers Equivalent to: -h -l -S\n\
2691 -s --syms Display the symbol table\n\
2692 --symbols An alias for --syms\n\
2693 -n --notes Display the core notes (if present)\n\
2694 -r --relocs Display the relocations (if present)\n\
2695 -u --unwind Display the unwind info (if present)\n\
2696 -d --dynamic Display the dynamic section (if present)\n\
2697 -V --version-info Display the version sections (if present)\n\
2698 -A --arch-specific Display architecture specific information (if any).\n\
2699 -D --use-dynamic Use the dynamic section info when displaying symbols\n\
2700 -x --hex-dump=<number> Dump the contents of section <number>\n\
2701 -w[liaprmfFsoR] or\n\
2702 --debug-dump[=line,=info,=abbrev,=pubnames,=aranges,=macro,=frames,=str,=loc,=Ranges]\n\
2703 Display the contents of DWARF2 debug sections\n"));
2704 #ifdef SUPPORT_DISASSEMBLY
2705 fprintf (stdout, _("\
2706 -i --instruction-dump=<number>\n\
2707 Disassemble the contents of section <number>\n"));
2709 fprintf (stdout, _("\
2710 -I --histogram Display histogram of bucket list lengths\n\
2711 -W --wide Allow output width to exceed 80 characters\n\
2712 @<file> Read options from <file>\n\
2713 -H --help Display this information\n\
2714 -v --version Display the version number of readelf\n"));
2715 fprintf (stdout, _("Report bugs to %s\n"), REPORT_BUGS_TO);
2720 /* Record the fact that the user wants the contents of section number
2721 SECTION to be displayed using the method(s) encoded as flags bits
2722 in TYPE. Note, TYPE can be zero if we are creating the array for
2726 request_dump (unsigned int section, int type)
2728 if (section >= num_dump_sects)
2730 char *new_dump_sects;
2732 new_dump_sects = calloc (section + 1, 1);
2734 if (new_dump_sects == NULL)
2735 error (_("Out of memory allocating dump request table."));
2738 /* Copy current flag settings. */
2739 memcpy (new_dump_sects, dump_sects, num_dump_sects);
2743 dump_sects = new_dump_sects;
2744 num_dump_sects = section + 1;
2749 dump_sects[section] |= type;
2754 /* Request a dump by section name. */
2757 request_dump_byname (const char *section, int type)
2759 struct dump_list_entry *new_request;
2761 new_request = malloc (sizeof (struct dump_list_entry));
2763 error (_("Out of memory allocating dump request table."));
2765 new_request->name = strdup (section);
2766 if (!new_request->name)
2767 error (_("Out of memory allocating dump request table."));
2769 new_request->type = type;
2771 new_request->next = dump_sects_byname;
2772 dump_sects_byname = new_request;
2776 parse_args (int argc, char **argv)
2783 while ((c = getopt_long
2784 (argc, argv, "ersuahnldSDAINtgw::x:i:vVWH", options, NULL)) != EOF)
2805 do_section_groups++;
2813 do_section_groups++;
2818 do_section_details++;
2860 section = strtoul (optarg, & cp, 0);
2861 if (! *cp && section >= 0)
2862 request_dump (section, HEX_DUMP);
2864 request_dump_byname (optarg, HEX_DUMP);
2872 unsigned int index = 0;
2876 while (optarg[index])
2877 switch (optarg[index++])
2886 do_debug_abbrevs = 1;
2896 do_debug_pubnames = 1;
2900 do_debug_aranges = 1;
2904 do_debug_ranges = 1;
2908 do_debug_frames_interp = 1;
2910 do_debug_frames = 1;
2915 do_debug_macinfo = 1;
2929 warn (_("Unrecognized debug option '%s'\n"), optarg);
2934 case OPTION_DEBUG_DUMP:
2942 const char * option;
2945 debug_dump_long_opts;
2947 debug_dump_long_opts opts_table [] =
2949 /* Please keep this table alpha- sorted. */
2950 { "Ranges", & do_debug_ranges },
2951 { "abbrev", & do_debug_abbrevs },
2952 { "aranges", & do_debug_aranges },
2953 { "frames", & do_debug_frames },
2954 { "frames-interp", & do_debug_frames_interp },
2955 { "info", & do_debug_info },
2956 { "line", & do_debug_lines },
2957 { "loc", & do_debug_loc },
2958 { "macro", & do_debug_macinfo },
2959 { "pubnames", & do_debug_pubnames },
2960 /* This entry is for compatability
2961 with earlier versions of readelf. */
2962 { "ranges", & do_debug_aranges },
2963 { "str", & do_debug_str },
2974 debug_dump_long_opts * entry;
2976 for (entry = opts_table; entry->option; entry++)
2978 size_t len = strlen (entry->option);
2980 if (strneq (p, entry->option, len)
2981 && (p[len] == ',' || p[len] == '\0'))
2983 * entry->variable = 1;
2985 /* The --debug-dump=frames-interp option also
2986 enables the --debug-dump=frames option. */
2987 if (do_debug_frames_interp)
2988 do_debug_frames = 1;
2995 if (entry->option == NULL)
2997 warn (_("Unrecognized debug option '%s'\n"), p);
2998 p = strchr (p, ',');
3008 #ifdef SUPPORT_DISASSEMBLY
3011 section = strtoul (optarg, & cp, 0);
3012 if (! *cp && section >= 0)
3014 request_dump (section, DISASS_DUMP);
3020 print_version (program_name);
3029 #ifdef SUPPORT_DISASSEMBLY
3032 /* xgettext:c-format */
3033 error (_("Invalid option '-%c'\n"), c);
3040 if (!do_dynamic && !do_syms && !do_reloc && !do_unwind && !do_sections
3041 && !do_segments && !do_header && !do_dump && !do_version
3042 && !do_histogram && !do_debugging && !do_arch && !do_notes
3043 && !do_section_groups)
3047 warn (_("Nothing to do.\n"));
3053 get_elf_class (unsigned int elf_class)
3055 static char buff[32];
3059 case ELFCLASSNONE: return _("none");
3060 case ELFCLASS32: return "ELF32";
3061 case ELFCLASS64: return "ELF64";
3063 snprintf (buff, sizeof (buff), _("<unknown: %x>"), elf_class);
3069 get_data_encoding (unsigned int encoding)
3071 static char buff[32];
3075 case ELFDATANONE: return _("none");
3076 case ELFDATA2LSB: return _("2's complement, little endian");
3077 case ELFDATA2MSB: return _("2's complement, big endian");
3079 snprintf (buff, sizeof (buff), _("<unknown: %x>"), encoding);
3084 /* Decode the data held in 'elf_header'. */
3087 process_file_header (void)
3089 if ( elf_header.e_ident[EI_MAG0] != ELFMAG0
3090 || elf_header.e_ident[EI_MAG1] != ELFMAG1
3091 || elf_header.e_ident[EI_MAG2] != ELFMAG2
3092 || elf_header.e_ident[EI_MAG3] != ELFMAG3)
3095 (_("Not an ELF file - it has the wrong magic bytes at the start\n"));
3103 printf (_("ELF Header:\n"));
3104 printf (_(" Magic: "));
3105 for (i = 0; i < EI_NIDENT; i++)
3106 printf ("%2.2x ", elf_header.e_ident[i]);
3108 printf (_(" Class: %s\n"),
3109 get_elf_class (elf_header.e_ident[EI_CLASS]));
3110 printf (_(" Data: %s\n"),
3111 get_data_encoding (elf_header.e_ident[EI_DATA]));
3112 printf (_(" Version: %d %s\n"),
3113 elf_header.e_ident[EI_VERSION],
3114 (elf_header.e_ident[EI_VERSION] == EV_CURRENT
3116 : (elf_header.e_ident[EI_VERSION] != EV_NONE
3119 printf (_(" OS/ABI: %s\n"),
3120 get_osabi_name (elf_header.e_ident[EI_OSABI]));
3121 printf (_(" ABI Version: %d\n"),
3122 elf_header.e_ident[EI_ABIVERSION]);
3123 printf (_(" Type: %s\n"),
3124 get_file_type (elf_header.e_type));
3125 printf (_(" Machine: %s\n"),
3126 get_machine_name (elf_header.e_machine));
3127 printf (_(" Version: 0x%lx\n"),
3128 (unsigned long) elf_header.e_version);
3130 printf (_(" Entry point address: "));
3131 print_vma ((bfd_vma) elf_header.e_entry, PREFIX_HEX);
3132 printf (_("\n Start of program headers: "));
3133 print_vma ((bfd_vma) elf_header.e_phoff, DEC);
3134 printf (_(" (bytes into file)\n Start of section headers: "));
3135 print_vma ((bfd_vma) elf_header.e_shoff, DEC);
3136 printf (_(" (bytes into file)\n"));
3138 printf (_(" Flags: 0x%lx%s\n"),
3139 (unsigned long) elf_header.e_flags,
3140 get_machine_flags (elf_header.e_flags, elf_header.e_machine));
3141 printf (_(" Size of this header: %ld (bytes)\n"),
3142 (long) elf_header.e_ehsize);
3143 printf (_(" Size of program headers: %ld (bytes)\n"),
3144 (long) elf_header.e_phentsize);
3145 printf (_(" Number of program headers: %ld\n"),
3146 (long) elf_header.e_phnum);
3147 printf (_(" Size of section headers: %ld (bytes)\n"),
3148 (long) elf_header.e_shentsize);
3149 printf (_(" Number of section headers: %ld"),
3150 (long) elf_header.e_shnum);
3151 if (section_headers != NULL && elf_header.e_shnum == 0)
3152 printf (" (%ld)", (long) section_headers[0].sh_size);
3153 putc ('\n', stdout);
3154 printf (_(" Section header string table index: %ld"),
3155 (long) elf_header.e_shstrndx);
3156 if (section_headers != NULL && elf_header.e_shstrndx == SHN_XINDEX)
3157 printf (" (%ld)", (long) section_headers[0].sh_link);
3158 else if (elf_header.e_shstrndx != SHN_UNDEF
3159 && (elf_header.e_shstrndx >= elf_header.e_shnum
3160 || (elf_header.e_shstrndx >= SHN_LORESERVE
3161 && elf_header.e_shstrndx <= SHN_HIRESERVE)))
3162 printf (" <corrupt: out of range>");
3163 putc ('\n', stdout);
3166 if (section_headers != NULL)
3168 if (elf_header.e_shnum == 0)
3169 elf_header.e_shnum = section_headers[0].sh_size;
3170 if (elf_header.e_shstrndx == SHN_XINDEX)
3171 elf_header.e_shstrndx = section_headers[0].sh_link;
3172 else if (elf_header.e_shstrndx != SHN_UNDEF
3173 && (elf_header.e_shstrndx >= elf_header.e_shnum
3174 || (elf_header.e_shstrndx >= SHN_LORESERVE
3175 && elf_header.e_shstrndx <= SHN_HIRESERVE)))
3176 elf_header.e_shstrndx = SHN_UNDEF;
3177 free (section_headers);
3178 section_headers = NULL;
3186 get_32bit_program_headers (FILE *file, Elf_Internal_Phdr *program_headers)
3188 Elf32_External_Phdr *phdrs;
3189 Elf32_External_Phdr *external;
3190 Elf_Internal_Phdr *internal;
3193 phdrs = get_data (NULL, file, elf_header.e_phoff,
3194 elf_header.e_phentsize, elf_header.e_phnum,
3195 _("program headers"));
3199 for (i = 0, internal = program_headers, external = phdrs;
3200 i < elf_header.e_phnum;
3201 i++, internal++, external++)
3203 internal->p_type = BYTE_GET (external->p_type);
3204 internal->p_offset = BYTE_GET (external->p_offset);
3205 internal->p_vaddr = BYTE_GET (external->p_vaddr);
3206 internal->p_paddr = BYTE_GET (external->p_paddr);
3207 internal->p_filesz = BYTE_GET (external->p_filesz);
3208 internal->p_memsz = BYTE_GET (external->p_memsz);
3209 internal->p_flags = BYTE_GET (external->p_flags);
3210 internal->p_align = BYTE_GET (external->p_align);
3219 get_64bit_program_headers (FILE *file, Elf_Internal_Phdr *program_headers)
3221 Elf64_External_Phdr *phdrs;
3222 Elf64_External_Phdr *external;
3223 Elf_Internal_Phdr *internal;
3226 phdrs = get_data (NULL, file, elf_header.e_phoff,
3227 elf_header.e_phentsize, elf_header.e_phnum,
3228 _("program headers"));
3232 for (i = 0, internal = program_headers, external = phdrs;
3233 i < elf_header.e_phnum;
3234 i++, internal++, external++)
3236 internal->p_type = BYTE_GET (external->p_type);
3237 internal->p_flags = BYTE_GET (external->p_flags);
3238 internal->p_offset = BYTE_GET (external->p_offset);
3239 internal->p_vaddr = BYTE_GET (external->p_vaddr);
3240 internal->p_paddr = BYTE_GET (external->p_paddr);
3241 internal->p_filesz = BYTE_GET (external->p_filesz);
3242 internal->p_memsz = BYTE_GET (external->p_memsz);
3243 internal->p_align = BYTE_GET (external->p_align);
3251 /* Returns 1 if the program headers were read into `program_headers'. */
3254 get_program_headers (FILE *file)
3256 Elf_Internal_Phdr *phdrs;
3258 /* Check cache of prior read. */
3259 if (program_headers != NULL)
3262 phdrs = cmalloc (elf_header.e_phnum, sizeof (Elf_Internal_Phdr));
3266 error (_("Out of memory\n"));
3271 ? get_32bit_program_headers (file, phdrs)
3272 : get_64bit_program_headers (file, phdrs))
3274 program_headers = phdrs;
3282 /* Returns 1 if the program headers were loaded. */
3285 process_program_headers (FILE *file)
3287 Elf_Internal_Phdr *segment;
3290 if (elf_header.e_phnum == 0)
3293 printf (_("\nThere are no program headers in this file.\n"));
3297 if (do_segments && !do_header)
3299 printf (_("\nElf file type is %s\n"), get_file_type (elf_header.e_type));
3300 printf (_("Entry point "));
3301 print_vma ((bfd_vma) elf_header.e_entry, PREFIX_HEX);
3302 printf (_("\nThere are %d program headers, starting at offset "),
3303 elf_header.e_phnum);
3304 print_vma ((bfd_vma) elf_header.e_phoff, DEC);
3308 if (! get_program_headers (file))
3313 if (elf_header.e_phnum > 1)
3314 printf (_("\nProgram Headers:\n"));
3316 printf (_("\nProgram Headers:\n"));
3320 (_(" Type Offset VirtAddr PhysAddr FileSiz MemSiz Flg Align\n"));
3323 (_(" Type Offset VirtAddr PhysAddr FileSiz MemSiz Flg Align\n"));
3327 (_(" Type Offset VirtAddr PhysAddr\n"));
3329 (_(" FileSiz MemSiz Flags Align\n"));
3336 for (i = 0, segment = program_headers;
3337 i < elf_header.e_phnum;
3342 printf (" %-14.14s ", get_segment_type (segment->p_type));
3346 printf ("0x%6.6lx ", (unsigned long) segment->p_offset);
3347 printf ("0x%8.8lx ", (unsigned long) segment->p_vaddr);
3348 printf ("0x%8.8lx ", (unsigned long) segment->p_paddr);
3349 printf ("0x%5.5lx ", (unsigned long) segment->p_filesz);
3350 printf ("0x%5.5lx ", (unsigned long) segment->p_memsz);
3352 (segment->p_flags & PF_R ? 'R' : ' '),
3353 (segment->p_flags & PF_W ? 'W' : ' '),
3354 (segment->p_flags & PF_X ? 'E' : ' '));
3355 printf ("%#lx", (unsigned long) segment->p_align);
3359 if ((unsigned long) segment->p_offset == segment->p_offset)
3360 printf ("0x%6.6lx ", (unsigned long) segment->p_offset);
3363 print_vma (segment->p_offset, FULL_HEX);
3367 print_vma (segment->p_vaddr, FULL_HEX);
3369 print_vma (segment->p_paddr, FULL_HEX);
3372 if ((unsigned long) segment->p_filesz == segment->p_filesz)
3373 printf ("0x%6.6lx ", (unsigned long) segment->p_filesz);
3376 print_vma (segment->p_filesz, FULL_HEX);
3380 if ((unsigned long) segment->p_memsz == segment->p_memsz)
3381 printf ("0x%6.6lx", (unsigned long) segment->p_memsz);
3384 print_vma (segment->p_offset, FULL_HEX);
3388 (segment->p_flags & PF_R ? 'R' : ' '),
3389 (segment->p_flags & PF_W ? 'W' : ' '),
3390 (segment->p_flags & PF_X ? 'E' : ' '));
3392 if ((unsigned long) segment->p_align == segment->p_align)
3393 printf ("%#lx", (unsigned long) segment->p_align);
3396 print_vma (segment->p_align, PREFIX_HEX);
3401 print_vma (segment->p_offset, FULL_HEX);
3403 print_vma (segment->p_vaddr, FULL_HEX);
3405 print_vma (segment->p_paddr, FULL_HEX);
3407 print_vma (segment->p_filesz, FULL_HEX);
3409 print_vma (segment->p_memsz, FULL_HEX);
3411 (segment->p_flags & PF_R ? 'R' : ' '),
3412 (segment->p_flags & PF_W ? 'W' : ' '),
3413 (segment->p_flags & PF_X ? 'E' : ' '));
3414 print_vma (segment->p_align, HEX);
3418 switch (segment->p_type)
3422 error (_("more than one dynamic segment\n"));
3424 /* Try to locate the .dynamic section. If there is
3425 a section header table, we can easily locate it. */
3426 if (section_headers != NULL)
3428 Elf_Internal_Shdr *sec;
3430 sec = find_section (".dynamic");
3431 if (sec == NULL || sec->sh_size == 0)
3433 error (_("no .dynamic section in the dynamic segment"));
3437 dynamic_addr = sec->sh_offset;
3438 dynamic_size = sec->sh_size;
3440 if (dynamic_addr < segment->p_offset
3441 || dynamic_addr > segment->p_offset + segment->p_filesz)
3442 warn (_("the .dynamic section is not contained within the dynamic segment"));
3443 else if (dynamic_addr > segment->p_offset)
3444 warn (_("the .dynamic section is not the first section in the dynamic segment."));
3448 /* Otherwise, we can only assume that the .dynamic
3449 section is the first section in the DYNAMIC segment. */
3450 dynamic_addr = segment->p_offset;
3451 dynamic_size = segment->p_filesz;
3456 if (fseek (file, archive_file_offset + (long) segment->p_offset,
3458 error (_("Unable to find program interpreter name\n"));
3461 program_interpreter[0] = 0;
3462 fscanf (file, "%63s", program_interpreter);
3465 printf (_("\n [Requesting program interpreter: %s]"),
3466 program_interpreter);
3472 putc ('\n', stdout);
3475 if (do_segments && section_headers != NULL && string_table != NULL)
3477 printf (_("\n Section to Segment mapping:\n"));
3478 printf (_(" Segment Sections...\n"));
3480 for (i = 0; i < elf_header.e_phnum; i++)
3483 Elf_Internal_Shdr *section;
3485 segment = program_headers + i;
3486 section = section_headers;
3488 printf (" %2.2d ", i);
3490 for (j = 1; j < elf_header.e_shnum; j++, section++)
3492 if (ELF_IS_SECTION_IN_SEGMENT_MEMORY(section, segment))
3493 printf ("%s ", SECTION_NAME (section));
3504 /* Find the file offset corresponding to VMA by using the program headers. */
3507 offset_from_vma (FILE *file, bfd_vma vma, bfd_size_type size)
3509 Elf_Internal_Phdr *seg;
3511 if (! get_program_headers (file))
3513 warn (_("Cannot interpret virtual addresses without program headers.\n"));
3517 for (seg = program_headers;
3518 seg < program_headers + elf_header.e_phnum;
3521 if (seg->p_type != PT_LOAD)
3524 if (vma >= (seg->p_vaddr & -seg->p_align)
3525 && vma + size <= seg->p_vaddr + seg->p_filesz)
3526 return vma - seg->p_vaddr + seg->p_offset;
3529 warn (_("Virtual address 0x%lx not located in any PT_LOAD segment.\n"),
3536 get_32bit_section_headers (FILE *file, unsigned int num)
3538 Elf32_External_Shdr *shdrs;
3539 Elf_Internal_Shdr *internal;
3542 shdrs = get_data (NULL, file, elf_header.e_shoff,
3543 elf_header.e_shentsize, num, _("section headers"));
3547 section_headers = cmalloc (num, sizeof (Elf_Internal_Shdr));
3549 if (section_headers == NULL)
3551 error (_("Out of memory\n"));
3555 for (i = 0, internal = section_headers;
3559 internal->sh_name = BYTE_GET (shdrs[i].sh_name);
3560 internal->sh_type = BYTE_GET (shdrs[i].sh_type);
3561 internal->sh_flags = BYTE_GET (shdrs[i].sh_flags);
3562 internal->sh_addr = BYTE_GET (shdrs[i].sh_addr);
3563 internal->sh_offset = BYTE_GET (shdrs[i].sh_offset);
3564 internal->sh_size = BYTE_GET (shdrs[i].sh_size);
3565 internal->sh_link = BYTE_GET (shdrs[i].sh_link);
3566 internal->sh_info = BYTE_GET (shdrs[i].sh_info);
3567 internal->sh_addralign = BYTE_GET (shdrs[i].sh_addralign);
3568 internal->sh_entsize = BYTE_GET (shdrs[i].sh_entsize);
3577 get_64bit_section_headers (FILE *file, unsigned int num)
3579 Elf64_External_Shdr *shdrs;
3580 Elf_Internal_Shdr *internal;
3583 shdrs = get_data (NULL, file, elf_header.e_shoff,
3584 elf_header.e_shentsize, num, _("section headers"));
3588 section_headers = cmalloc (num, sizeof (Elf_Internal_Shdr));
3590 if (section_headers == NULL)
3592 error (_("Out of memory\n"));
3596 for (i = 0, internal = section_headers;
3600 internal->sh_name = BYTE_GET (shdrs[i].sh_name);
3601 internal->sh_type = BYTE_GET (shdrs[i].sh_type);
3602 internal->sh_flags = BYTE_GET (shdrs[i].sh_flags);
3603 internal->sh_addr = BYTE_GET (shdrs[i].sh_addr);
3604 internal->sh_size = BYTE_GET (shdrs[i].sh_size);
3605 internal->sh_entsize = BYTE_GET (shdrs[i].sh_entsize);
3606 internal->sh_link = BYTE_GET (shdrs[i].sh_link);
3607 internal->sh_info = BYTE_GET (shdrs[i].sh_info);
3608 internal->sh_offset = BYTE_GET (shdrs[i].sh_offset);
3609 internal->sh_addralign = BYTE_GET (shdrs[i].sh_addralign);
3617 static Elf_Internal_Sym *
3618 get_32bit_elf_symbols (FILE *file, Elf_Internal_Shdr *section)
3620 unsigned long number;
3621 Elf32_External_Sym *esyms;
3622 Elf_External_Sym_Shndx *shndx;
3623 Elf_Internal_Sym *isyms;
3624 Elf_Internal_Sym *psym;
3627 esyms = get_data (NULL, file, section->sh_offset, 1, section->sh_size,
3633 if (symtab_shndx_hdr != NULL
3634 && (symtab_shndx_hdr->sh_link
3635 == (unsigned long) SECTION_HEADER_NUM (section - section_headers)))
3637 shndx = get_data (NULL, file, symtab_shndx_hdr->sh_offset,
3638 1, symtab_shndx_hdr->sh_size, _("symtab shndx"));
3646 number = section->sh_size / section->sh_entsize;
3647 isyms = cmalloc (number, sizeof (Elf_Internal_Sym));
3651 error (_("Out of memory\n"));
3658 for (j = 0, psym = isyms;
3662 psym->st_name = BYTE_GET (esyms[j].st_name);
3663 psym->st_value = BYTE_GET (esyms[j].st_value);
3664 psym->st_size = BYTE_GET (esyms[j].st_size);
3665 psym->st_shndx = BYTE_GET (esyms[j].st_shndx);
3666 if (psym->st_shndx == SHN_XINDEX && shndx != NULL)
3668 = byte_get ((unsigned char *) &shndx[j], sizeof (shndx[j]));
3669 psym->st_info = BYTE_GET (esyms[j].st_info);
3670 psym->st_other = BYTE_GET (esyms[j].st_other);
3680 static Elf_Internal_Sym *
3681 get_64bit_elf_symbols (FILE *file, Elf_Internal_Shdr *section)
3683 unsigned long number;
3684 Elf64_External_Sym *esyms;
3685 Elf_External_Sym_Shndx *shndx;
3686 Elf_Internal_Sym *isyms;
3687 Elf_Internal_Sym *psym;
3690 esyms = get_data (NULL, file, section->sh_offset, 1, section->sh_size,
3696 if (symtab_shndx_hdr != NULL
3697 && (symtab_shndx_hdr->sh_link
3698 == (unsigned long) SECTION_HEADER_NUM (section - section_headers)))
3700 shndx = get_data (NULL, file, symtab_shndx_hdr->sh_offset,
3701 1, symtab_shndx_hdr->sh_size, _("symtab shndx"));
3709 number = section->sh_size / section->sh_entsize;
3710 isyms = cmalloc (number, sizeof (Elf_Internal_Sym));
3714 error (_("Out of memory\n"));
3721 for (j = 0, psym = isyms;
3725 psym->st_name = BYTE_GET (esyms[j].st_name);
3726 psym->st_info = BYTE_GET (esyms[j].st_info);
3727 psym->st_other = BYTE_GET (esyms[j].st_other);
3728 psym->st_shndx = BYTE_GET (esyms[j].st_shndx);
3729 if (psym->st_shndx == SHN_XINDEX && shndx != NULL)
3731 = byte_get ((unsigned char *) &shndx[j], sizeof (shndx[j]));
3732 psym->st_value = BYTE_GET (esyms[j].st_value);
3733 psym->st_size = BYTE_GET (esyms[j].st_size);
3744 get_elf_section_flags (bfd_vma sh_flags)
3746 static char buff[1024];
3748 int field_size = is_32bit_elf ? 8 : 16;
3749 int index, size = sizeof (buff) - (field_size + 4 + 1);
3750 bfd_vma os_flags = 0;
3751 bfd_vma proc_flags = 0;
3752 bfd_vma unknown_flags = 0;
3766 { "LINK ORDER", 10 },
3767 { "OS NONCONF", 10 },
3772 if (do_section_details)
3774 sprintf (buff, "[%*.*lx]: ",
3775 field_size, field_size, (unsigned long) sh_flags);
3776 p += field_size + 4;
3783 flag = sh_flags & - sh_flags;
3786 if (do_section_details)
3790 case SHF_WRITE: index = 0; break;
3791 case SHF_ALLOC: index = 1; break;
3792 case SHF_EXECINSTR: index = 2; break;
3793 case SHF_MERGE: index = 3; break;
3794 case SHF_STRINGS: index = 4; break;
3795 case SHF_INFO_LINK: index = 5; break;
3796 case SHF_LINK_ORDER: index = 6; break;
3797 case SHF_OS_NONCONFORMING: index = 7; break;
3798 case SHF_GROUP: index = 8; break;
3799 case SHF_TLS: index = 9; break;
3808 if (p != buff + field_size + 4)
3810 if (size < (10 + 2))
3817 size -= flags [index].len;
3818 p = stpcpy (p, flags [index].str);
3820 else if (flag & SHF_MASKOS)
3822 else if (flag & SHF_MASKPROC)
3825 unknown_flags |= flag;
3831 case SHF_WRITE: *p = 'W'; break;
3832 case SHF_ALLOC: *p = 'A'; break;
3833 case SHF_EXECINSTR: *p = 'X'; break;
3834 case SHF_MERGE: *p = 'M'; break;
3835 case SHF_STRINGS: *p = 'S'; break;
3836 case SHF_INFO_LINK: *p = 'I'; break;
3837 case SHF_LINK_ORDER: *p = 'L'; break;
3838 case SHF_OS_NONCONFORMING: *p = 'O'; break;
3839 case SHF_GROUP: *p = 'G'; break;
3840 case SHF_TLS: *p = 'T'; break;
3843 if (elf_header.e_machine == EM_X86_64
3844 && flag == SHF_X86_64_LARGE)
3846 else if (flag & SHF_MASKOS)
3849 sh_flags &= ~ SHF_MASKOS;
3851 else if (flag & SHF_MASKPROC)
3854 sh_flags &= ~ SHF_MASKPROC;
3864 if (do_section_details)
3868 size -= 5 + field_size;
3869 if (p != buff + field_size + 4)
3877 sprintf (p, "OS (%*.*lx)", field_size, field_size,
3878 (unsigned long) os_flags);
3879 p += 5 + field_size;
3883 size -= 7 + field_size;
3884 if (p != buff + field_size + 4)
3892 sprintf (p, "PROC (%*.*lx)", field_size, field_size,
3893 (unsigned long) proc_flags);
3894 p += 7 + field_size;
3898 size -= 10 + field_size;
3899 if (p != buff + field_size + 4)
3907 sprintf (p, "UNKNOWN (%*.*lx)", field_size, field_size,
3908 (unsigned long) unknown_flags);
3909 p += 10 + field_size;
3918 process_section_headers (FILE *file)
3920 Elf_Internal_Shdr *section;
3923 section_headers = NULL;
3925 if (elf_header.e_shnum == 0)
3928 printf (_("\nThere are no sections in this file.\n"));
3933 if (do_sections && !do_header)
3934 printf (_("There are %d section headers, starting at offset 0x%lx:\n"),
3935 elf_header.e_shnum, (unsigned long) elf_header.e_shoff);
3939 if (! get_32bit_section_headers (file, elf_header.e_shnum))
3942 else if (! get_64bit_section_headers (file, elf_header.e_shnum))
3945 /* Read in the string table, so that we have names to display. */
3946 if (elf_header.e_shstrndx != SHN_UNDEF
3947 && SECTION_HEADER_INDEX (elf_header.e_shstrndx) < elf_header.e_shnum)
3949 section = SECTION_HEADER (elf_header.e_shstrndx);
3951 if (section->sh_size != 0)
3953 string_table = get_data (NULL, file, section->sh_offset,
3954 1, section->sh_size, _("string table"));
3956 string_table_length = string_table != NULL ? section->sh_size : 0;
3960 /* Scan the sections for the dynamic symbol table
3961 and dynamic string table and debug sections. */
3962 dynamic_symbols = NULL;
3963 dynamic_strings = NULL;
3964 dynamic_syminfo = NULL;
3965 symtab_shndx_hdr = NULL;
3967 eh_addr_size = is_32bit_elf ? 4 : 8;
3968 switch (elf_header.e_machine)
3971 case EM_MIPS_RS3_LE:
3972 /* The 64-bit MIPS EABI uses a combination of 32-bit ELF and 64-bit
3973 FDE addresses. However, the ABI also has a semi-official ILP32
3974 variant for which the normal FDE address size rules apply.
3976 GCC 4.0 marks EABI64 objects with a dummy .gcc_compiled_longXX
3977 section, where XX is the size of longs in bits. Unfortunately,
3978 earlier compilers provided no way of distinguishing ILP32 objects
3979 from LP64 objects, so if there's any doubt, we should assume that
3980 the official LP64 form is being used. */
3981 if ((elf_header.e_flags & EF_MIPS_ABI) == E_MIPS_ABI_EABI64
3982 && find_section (".gcc_compiled_long32") == NULL)
3988 switch (elf_header.e_flags & EF_H8_MACH)
3990 case E_H8_MACH_H8300:
3991 case E_H8_MACH_H8300HN:
3992 case E_H8_MACH_H8300SN:
3993 case E_H8_MACH_H8300SXN:
3996 case E_H8_MACH_H8300H:
3997 case E_H8_MACH_H8300S:
3998 case E_H8_MACH_H8300SX:
4004 #define CHECK_ENTSIZE_VALUES(section, i, size32, size64) \
4007 size_t expected_entsize \
4008 = is_32bit_elf ? size32 : size64; \
4009 if (section->sh_entsize != expected_entsize) \
4010 error (_("Section %d has invalid sh_entsize %lx (expected %lx)\n"), \
4011 i, (unsigned long int) section->sh_entsize, \
4012 (unsigned long int) expected_entsize); \
4013 section->sh_entsize = expected_entsize; \
4016 #define CHECK_ENTSIZE(section, i, type) \
4017 CHECK_ENTSIZE_VALUES (section, i, sizeof (Elf32_External_##type), \
4018 sizeof (Elf64_External_##type))
4020 for (i = 0, section = section_headers;
4021 i < elf_header.e_shnum;
4024 char *name = SECTION_NAME (section);
4026 if (section->sh_type == SHT_DYNSYM)
4028 if (dynamic_symbols != NULL)
4030 error (_("File contains multiple dynamic symbol tables\n"));
4034 CHECK_ENTSIZE (section, i, Sym);
4035 num_dynamic_syms = section->sh_size / section->sh_entsize;
4036 dynamic_symbols = GET_ELF_SYMBOLS (file, section);
4038 else if (section->sh_type == SHT_STRTAB
4039 && streq (name, ".dynstr"))
4041 if (dynamic_strings != NULL)
4043 error (_("File contains multiple dynamic string tables\n"));
4047 dynamic_strings = get_data (NULL, file, section->sh_offset,
4048 1, section->sh_size, _("dynamic strings"));
4049 dynamic_strings_length = section->sh_size;
4051 else if (section->sh_type == SHT_SYMTAB_SHNDX)
4053 if (symtab_shndx_hdr != NULL)
4055 error (_("File contains multiple symtab shndx tables\n"));
4058 symtab_shndx_hdr = section;
4060 else if (section->sh_type == SHT_SYMTAB)
4061 CHECK_ENTSIZE (section, i, Sym);
4062 else if (section->sh_type == SHT_GROUP)
4063 CHECK_ENTSIZE_VALUES (section, i, GRP_ENTRY_SIZE, GRP_ENTRY_SIZE);
4064 else if (section->sh_type == SHT_REL)
4065 CHECK_ENTSIZE (section, i, Rel);
4066 else if (section->sh_type == SHT_RELA)
4067 CHECK_ENTSIZE (section, i, Rela);
4068 else if ((do_debugging || do_debug_info || do_debug_abbrevs
4069 || do_debug_lines || do_debug_pubnames || do_debug_aranges
4070 || do_debug_frames || do_debug_macinfo || do_debug_str
4071 || do_debug_loc || do_debug_ranges)
4072 && const_strneq (name, ".debug_"))
4077 || (do_debug_info && streq (name, "info"))
4078 || (do_debug_abbrevs && streq (name, "abbrev"))
4079 || (do_debug_lines && streq (name, "line"))
4080 || (do_debug_pubnames && streq (name, "pubnames"))
4081 || (do_debug_aranges && streq (name, "aranges"))
4082 || (do_debug_ranges && streq (name, "ranges"))
4083 || (do_debug_frames && streq (name, "frame"))
4084 || (do_debug_macinfo && streq (name, "macinfo"))
4085 || (do_debug_str && streq (name, "str"))
4086 || (do_debug_loc && streq (name, "loc"))
4088 request_dump (i, DEBUG_DUMP);
4090 /* linkonce section to be combined with .debug_info at link time. */
4091 else if ((do_debugging || do_debug_info)
4092 && const_strneq (name, ".gnu.linkonce.wi."))
4093 request_dump (i, DEBUG_DUMP);
4094 else if (do_debug_frames && streq (name, ".eh_frame"))
4095 request_dump (i, DEBUG_DUMP);
4101 if (elf_header.e_shnum > 1)
4102 printf (_("\nSection Headers:\n"));
4104 printf (_("\nSection Header:\n"));
4108 if (do_section_details)
4110 printf (_(" [Nr] Name\n"));
4111 printf (_(" Type Addr Off Size ES Lk Inf Al\n"));
4115 (_(" [Nr] Name Type Addr Off Size ES Flg Lk Inf Al\n"));
4119 if (do_section_details)
4121 printf (_(" [Nr] Name\n"));
4122 printf (_(" Type Address Off Size ES Lk Inf Al\n"));
4126 (_(" [Nr] Name Type Address Off Size ES Flg Lk Inf Al\n"));
4130 if (do_section_details)
4132 printf (_(" [Nr] Name\n"));
4133 printf (_(" Type Address Offset Link\n"));
4134 printf (_(" Size EntSize Info Align\n"));
4138 printf (_(" [Nr] Name Type Address Offset\n"));
4139 printf (_(" Size EntSize Flags Link Info Align\n"));
4143 if (do_section_details)
4144 printf (_(" Flags\n"));
4146 for (i = 0, section = section_headers;
4147 i < elf_header.e_shnum;
4150 if (do_section_details)
4152 printf (" [%2u] %s\n",
4153 SECTION_HEADER_NUM (i),
4154 SECTION_NAME (section));
4155 if (is_32bit_elf || do_wide)
4156 printf (" %-15.15s ",
4157 get_section_type_name (section->sh_type));
4160 printf (" [%2u] %-17.17s %-15.15s ",
4161 SECTION_HEADER_NUM (i),
4162 SECTION_NAME (section),
4163 get_section_type_name (section->sh_type));
4167 print_vma (section->sh_addr, LONG_HEX);
4169 printf ( " %6.6lx %6.6lx %2.2lx",
4170 (unsigned long) section->sh_offset,
4171 (unsigned long) section->sh_size,
4172 (unsigned long) section->sh_entsize);
4174 if (do_section_details)
4175 fputs (" ", stdout);
4177 printf (" %3s ", get_elf_section_flags (section->sh_flags));
4179 printf ("%2ld %3lu %2ld\n",
4180 (unsigned long) section->sh_link,
4181 (unsigned long) section->sh_info,
4182 (unsigned long) section->sh_addralign);
4186 print_vma (section->sh_addr, LONG_HEX);
4188 if ((long) section->sh_offset == section->sh_offset)
4189 printf (" %6.6lx", (unsigned long) section->sh_offset);
4193 print_vma (section->sh_offset, LONG_HEX);
4196 if ((unsigned long) section->sh_size == section->sh_size)
4197 printf (" %6.6lx", (unsigned long) section->sh_size);
4201 print_vma (section->sh_size, LONG_HEX);
4204 if ((unsigned long) section->sh_entsize == section->sh_entsize)
4205 printf (" %2.2lx", (unsigned long) section->sh_entsize);
4209 print_vma (section->sh_entsize, LONG_HEX);
4212 if (do_section_details)
4213 fputs (" ", stdout);
4215 printf (" %3s ", get_elf_section_flags (section->sh_flags));
4217 printf ("%2ld %3lu ",
4218 (unsigned long) section->sh_link,
4219 (unsigned long) section->sh_info);
4221 if ((unsigned long) section->sh_addralign == section->sh_addralign)
4222 printf ("%2ld\n", (unsigned long) section->sh_addralign);
4225 print_vma (section->sh_addralign, DEC);
4229 else if (do_section_details)
4231 printf (" %-15.15s ",
4232 get_section_type_name (section->sh_type));
4233 print_vma (section->sh_addr, LONG_HEX);
4234 if ((long) section->sh_offset == section->sh_offset)
4235 printf (" %16.16lx", (unsigned long) section->sh_offset);
4239 print_vma (section->sh_offset, LONG_HEX);
4241 printf (" %ld\n ", (unsigned long) section->sh_link);
4242 print_vma (section->sh_size, LONG_HEX);
4244 print_vma (section->sh_entsize, LONG_HEX);
4246 printf (" %-16lu %ld\n",
4247 (unsigned long) section->sh_info,
4248 (unsigned long) section->sh_addralign);
4253 print_vma (section->sh_addr, LONG_HEX);
4254 if ((long) section->sh_offset == section->sh_offset)
4255 printf (" %8.8lx", (unsigned long) section->sh_offset);
4259 print_vma (section->sh_offset, LONG_HEX);
4262 print_vma (section->sh_size, LONG_HEX);
4264 print_vma (section->sh_entsize, LONG_HEX);
4266 printf (" %3s ", get_elf_section_flags (section->sh_flags));
4268 printf (" %2ld %3lu %ld\n",
4269 (unsigned long) section->sh_link,
4270 (unsigned long) section->sh_info,
4271 (unsigned long) section->sh_addralign);
4274 if (do_section_details)
4275 printf (" %s\n", get_elf_section_flags (section->sh_flags));
4278 if (!do_section_details)
4279 printf (_("Key to Flags:\n\
4280 W (write), A (alloc), X (execute), M (merge), S (strings)\n\
4281 I (info), L (link order), G (group), x (unknown)\n\
4282 O (extra OS processing required) o (OS specific), p (processor specific)\n"));
4288 get_group_flags (unsigned int flags)
4290 static char buff[32];
4297 snprintf (buff, sizeof (buff), _("[<unknown>: 0x%x]"), flags);
4304 process_section_groups (FILE *file)
4306 Elf_Internal_Shdr *section;
4308 struct group *group;
4309 Elf_Internal_Shdr *symtab_sec, *strtab_sec;
4310 Elf_Internal_Sym *symtab;
4314 /* Don't process section groups unless needed. */
4315 if (!do_unwind && !do_section_groups)
4318 if (elf_header.e_shnum == 0)
4320 if (do_section_groups)
4321 printf (_("\nThere are no sections in this file.\n"));
4326 if (section_headers == NULL)
4328 error (_("Section headers are not available!\n"));
4332 section_headers_groups = calloc (elf_header.e_shnum,
4333 sizeof (struct group *));
4335 if (section_headers_groups == NULL)
4337 error (_("Out of memory\n"));
4341 /* Scan the sections for the group section. */
4343 for (i = 0, section = section_headers;
4344 i < elf_header.e_shnum;
4346 if (section->sh_type == SHT_GROUP)
4349 if (group_count == 0)
4351 if (do_section_groups)
4352 printf (_("\nThere are no section groups in this file.\n"));
4357 section_groups = calloc (group_count, sizeof (struct group));
4359 if (section_groups == NULL)
4361 error (_("Out of memory\n"));
4370 for (i = 0, section = section_headers, group = section_groups;
4371 i < elf_header.e_shnum;
4374 if (section->sh_type == SHT_GROUP)
4376 char *name = SECTION_NAME (section);
4378 unsigned char *start, *indices;
4379 unsigned int entry, j, size;
4380 Elf_Internal_Shdr *sec;
4381 Elf_Internal_Sym *sym;
4383 /* Get the symbol table. */
4384 if (SECTION_HEADER_INDEX (section->sh_link) >= elf_header.e_shnum
4385 || ((sec = SECTION_HEADER (section->sh_link))->sh_type
4388 error (_("Bad sh_link in group section `%s'\n"), name);
4392 if (symtab_sec != sec)
4397 symtab = GET_ELF_SYMBOLS (file, symtab_sec);
4400 sym = symtab + section->sh_info;
4402 if (ELF_ST_TYPE (sym->st_info) == STT_SECTION)
4404 bfd_vma sec_index = SECTION_HEADER_INDEX (sym->st_shndx);
4407 error (_("Bad sh_info in group section `%s'\n"), name);
4411 group_name = SECTION_NAME (section_headers + sec_index);
4420 /* Get the string table. */
4421 if (SECTION_HEADER_INDEX (symtab_sec->sh_link)
4422 >= elf_header.e_shnum)
4431 != (sec = SECTION_HEADER (symtab_sec->sh_link)))
4436 strtab = get_data (NULL, file, strtab_sec->sh_offset,
4437 1, strtab_sec->sh_size,
4439 strtab_size = strtab != NULL ? strtab_sec->sh_size : 0;
4441 group_name = sym->st_name < strtab_size
4442 ? strtab + sym->st_name : "<corrupt>";
4445 start = get_data (NULL, file, section->sh_offset,
4446 1, section->sh_size, _("section data"));
4449 size = (section->sh_size / section->sh_entsize) - 1;
4450 entry = byte_get (indices, 4);
4453 if (do_section_groups)
4455 printf ("\n%s group section [%5u] `%s' [%s] contains %u sections:\n",
4456 get_group_flags (entry), i, name, group_name, size);
4458 printf (_(" [Index] Name\n"));
4461 group->group_index = i;
4463 for (j = 0; j < size; j++)
4465 struct group_list *g;
4467 entry = byte_get (indices, 4);
4470 if (SECTION_HEADER_INDEX (entry) >= elf_header.e_shnum)
4472 error (_("section [%5u] in group section [%5u] > maximum section [%5u]\n"),
4473 entry, i, elf_header.e_shnum - 1);
4476 else if (entry >= SHN_LORESERVE && entry <= SHN_HIRESERVE)
4478 error (_("invalid section [%5u] in group section [%5u]\n"),
4483 if (section_headers_groups [SECTION_HEADER_INDEX (entry)]
4488 error (_("section [%5u] in group section [%5u] already in group section [%5u]\n"),
4490 section_headers_groups [SECTION_HEADER_INDEX (entry)]->group_index);
4495 /* Intel C/C++ compiler may put section 0 in a
4496 section group. We just warn it the first time
4497 and ignore it afterwards. */
4498 static int warned = 0;
4501 error (_("section 0 in group section [%5u]\n"),
4502 section_headers_groups [SECTION_HEADER_INDEX (entry)]->group_index);
4508 section_headers_groups [SECTION_HEADER_INDEX (entry)]
4511 if (do_section_groups)
4513 sec = SECTION_HEADER (entry);
4514 printf (" [%5u] %s\n", entry, SECTION_NAME (sec));
4517 g = xmalloc (sizeof (struct group_list));
4518 g->section_index = entry;
4519 g->next = group->root;
4543 } dynamic_relocations [] =
4545 { "REL", DT_REL, DT_RELSZ, FALSE },
4546 { "RELA", DT_RELA, DT_RELASZ, TRUE },
4547 { "PLT", DT_JMPREL, DT_PLTRELSZ, UNKNOWN }
4550 /* Process the reloc section. */
4553 process_relocs (FILE *file)
4555 unsigned long rel_size;
4556 unsigned long rel_offset;
4562 if (do_using_dynamic)
4566 int has_dynamic_reloc;
4569 has_dynamic_reloc = 0;
4571 for (i = 0; i < ARRAY_SIZE (dynamic_relocations); i++)
4573 is_rela = dynamic_relocations [i].rela;
4574 name = dynamic_relocations [i].name;
4575 rel_size = dynamic_info [dynamic_relocations [i].size];
4576 rel_offset = dynamic_info [dynamic_relocations [i].reloc];
4578 has_dynamic_reloc |= rel_size;
4580 if (is_rela == UNKNOWN)
4582 if (dynamic_relocations [i].reloc == DT_JMPREL)
4583 switch (dynamic_info[DT_PLTREL])
4597 (_("\n'%s' relocation section at offset 0x%lx contains %ld bytes:\n"),
4598 name, rel_offset, rel_size);
4600 dump_relocations (file,
4601 offset_from_vma (file, rel_offset, rel_size),
4603 dynamic_symbols, num_dynamic_syms,
4604 dynamic_strings, dynamic_strings_length, is_rela);
4608 if (! has_dynamic_reloc)
4609 printf (_("\nThere are no dynamic relocations in this file.\n"));
4613 Elf_Internal_Shdr *section;
4617 for (i = 0, section = section_headers;
4618 i < elf_header.e_shnum;
4621 if ( section->sh_type != SHT_RELA
4622 && section->sh_type != SHT_REL)
4625 rel_offset = section->sh_offset;
4626 rel_size = section->sh_size;
4630 Elf_Internal_Shdr *strsec;
4633 printf (_("\nRelocation section "));
4635 if (string_table == NULL)
4636 printf ("%d", section->sh_name);
4638 printf (_("'%s'"), SECTION_NAME (section));
4640 printf (_(" at offset 0x%lx contains %lu entries:\n"),
4641 rel_offset, (unsigned long) (rel_size / section->sh_entsize));
4643 is_rela = section->sh_type == SHT_RELA;
4645 if (section->sh_link
4646 && SECTION_HEADER_INDEX (section->sh_link)
4647 < elf_header.e_shnum)
4649 Elf_Internal_Shdr *symsec;
4650 Elf_Internal_Sym *symtab;
4651 unsigned long nsyms;
4652 unsigned long strtablen = 0;
4653 char *strtab = NULL;
4655 symsec = SECTION_HEADER (section->sh_link);
4656 if (symsec->sh_type != SHT_SYMTAB
4657 && symsec->sh_type != SHT_DYNSYM)
4660 nsyms = symsec->sh_size / symsec->sh_entsize;
4661 symtab = GET_ELF_SYMBOLS (file, symsec);
4666 if (SECTION_HEADER_INDEX (symsec->sh_link)
4667 < elf_header.e_shnum)
4669 strsec = SECTION_HEADER (symsec->sh_link);
4671 strtab = get_data (NULL, file, strsec->sh_offset,
4674 strtablen = strtab == NULL ? 0 : strsec->sh_size;
4677 dump_relocations (file, rel_offset, rel_size,
4678 symtab, nsyms, strtab, strtablen, is_rela);
4684 dump_relocations (file, rel_offset, rel_size,
4685 NULL, 0, NULL, 0, is_rela);
4692 printf (_("\nThere are no relocations in this file.\n"));
4698 /* Process the unwind section. */
4700 #include "unwind-ia64.h"
4702 /* An absolute address consists of a section and an offset. If the
4703 section is NULL, the offset itself is the address, otherwise, the
4704 address equals to LOAD_ADDRESS(section) + offset. */
4708 unsigned short section;
4712 #define ABSADDR(a) \
4714 ? section_headers [(a).section].sh_addr + (a).offset \
4717 struct ia64_unw_aux_info
4719 struct ia64_unw_table_entry
4721 struct absaddr start;
4723 struct absaddr info;
4725 *table; /* Unwind table. */
4726 unsigned long table_len; /* Length of unwind table. */
4727 unsigned char *info; /* Unwind info. */
4728 unsigned long info_size; /* Size of unwind info. */
4729 bfd_vma info_addr; /* starting address of unwind info. */
4730 bfd_vma seg_base; /* Starting address of segment. */
4731 Elf_Internal_Sym *symtab; /* The symbol table. */
4732 unsigned long nsyms; /* Number of symbols. */
4733 char *strtab; /* The string table. */
4734 unsigned long strtab_size; /* Size of string table. */
4738 find_symbol_for_address (Elf_Internal_Sym *symtab,
4739 unsigned long nsyms,
4741 unsigned long strtab_size,
4742 struct absaddr addr,
4743 const char **symname,
4746 bfd_vma dist = 0x100000;
4747 Elf_Internal_Sym *sym, *best = NULL;
4750 for (i = 0, sym = symtab; i < nsyms; ++i, ++sym)
4752 if (ELF_ST_TYPE (sym->st_info) == STT_FUNC
4753 && sym->st_name != 0
4754 && (addr.section == SHN_UNDEF || addr.section == sym->st_shndx)
4755 && addr.offset >= sym->st_value
4756 && addr.offset - sym->st_value < dist)
4759 dist = addr.offset - sym->st_value;
4766 *symname = (best->st_name >= strtab_size
4767 ? "<corrupt>" : strtab + best->st_name);
4772 *offset = addr.offset;
4776 dump_ia64_unwind (struct ia64_unw_aux_info *aux)
4778 struct ia64_unw_table_entry *tp;
4781 for (tp = aux->table; tp < aux->table + aux->table_len; ++tp)
4785 const unsigned char *dp;
4786 const unsigned char *head;
4787 const char *procname;
4789 find_symbol_for_address (aux->symtab, aux->nsyms, aux->strtab,
4790 aux->strtab_size, tp->start, &procname, &offset);
4792 fputs ("\n<", stdout);
4796 fputs (procname, stdout);
4799 printf ("+%lx", (unsigned long) offset);
4802 fputs (">: [", stdout);
4803 print_vma (tp->start.offset, PREFIX_HEX);
4804 fputc ('-', stdout);
4805 print_vma (tp->end.offset, PREFIX_HEX);
4806 printf ("], info at +0x%lx\n",
4807 (unsigned long) (tp->info.offset - aux->seg_base));
4809 head = aux->info + (ABSADDR (tp->info) - aux->info_addr);
4810 stamp = byte_get ((unsigned char *) head, sizeof (stamp));
4812 printf (" v%u, flags=0x%lx (%s%s), len=%lu bytes\n",
4813 (unsigned) UNW_VER (stamp),
4814 (unsigned long) ((stamp & UNW_FLAG_MASK) >> 32),
4815 UNW_FLAG_EHANDLER (stamp) ? " ehandler" : "",
4816 UNW_FLAG_UHANDLER (stamp) ? " uhandler" : "",
4817 (unsigned long) (eh_addr_size * UNW_LENGTH (stamp)));
4819 if (UNW_VER (stamp) != 1)
4821 printf ("\tUnknown version.\n");
4826 for (dp = head + 8; dp < head + 8 + eh_addr_size * UNW_LENGTH (stamp);)
4827 dp = unw_decode (dp, in_body, & in_body);
4832 slurp_ia64_unwind_table (FILE *file,
4833 struct ia64_unw_aux_info *aux,
4834 Elf_Internal_Shdr *sec)
4836 unsigned long size, nrelas, i;
4837 Elf_Internal_Phdr *seg;
4838 struct ia64_unw_table_entry *tep;
4839 Elf_Internal_Shdr *relsec;
4840 Elf_Internal_Rela *rela, *rp;
4841 unsigned char *table, *tp;
4842 Elf_Internal_Sym *sym;
4843 const char *relname;
4845 /* First, find the starting address of the segment that includes
4848 if (elf_header.e_phnum)
4850 if (! get_program_headers (file))
4853 for (seg = program_headers;
4854 seg < program_headers + elf_header.e_phnum;
4857 if (seg->p_type != PT_LOAD)
4860 if (sec->sh_addr >= seg->p_vaddr
4861 && (sec->sh_addr + sec->sh_size <= seg->p_vaddr + seg->p_memsz))
4863 aux->seg_base = seg->p_vaddr;
4869 /* Second, build the unwind table from the contents of the unwind section: */
4870 size = sec->sh_size;
4871 table = get_data (NULL, file, sec->sh_offset, 1, size, _("unwind table"));
4875 aux->table = xcmalloc (size / (3 * eh_addr_size), sizeof (aux->table[0]));
4877 for (tp = table; tp < table + size; tp += 3 * eh_addr_size, ++tep)
4879 tep->start.section = SHN_UNDEF;
4880 tep->end.section = SHN_UNDEF;
4881 tep->info.section = SHN_UNDEF;
4884 tep->start.offset = byte_get ((unsigned char *) tp + 0, 4);
4885 tep->end.offset = byte_get ((unsigned char *) tp + 4, 4);
4886 tep->info.offset = byte_get ((unsigned char *) tp + 8, 4);
4890 tep->start.offset = BYTE_GET ((unsigned char *) tp + 0);
4891 tep->end.offset = BYTE_GET ((unsigned char *) tp + 8);
4892 tep->info.offset = BYTE_GET ((unsigned char *) tp + 16);
4894 tep->start.offset += aux->seg_base;
4895 tep->end.offset += aux->seg_base;
4896 tep->info.offset += aux->seg_base;
4900 /* Third, apply any relocations to the unwind table: */
4902 for (relsec = section_headers;
4903 relsec < section_headers + elf_header.e_shnum;
4906 if (relsec->sh_type != SHT_RELA
4907 || SECTION_HEADER_INDEX (relsec->sh_info) >= elf_header.e_shnum
4908 || SECTION_HEADER (relsec->sh_info) != sec)
4911 if (!slurp_rela_relocs (file, relsec->sh_offset, relsec->sh_size,
4915 for (rp = rela; rp < rela + nrelas; ++rp)
4919 relname = elf_ia64_reloc_type (ELF32_R_TYPE (rp->r_info));
4920 sym = aux->symtab + ELF32_R_SYM (rp->r_info);
4924 relname = elf_ia64_reloc_type (ELF64_R_TYPE (rp->r_info));
4925 sym = aux->symtab + ELF64_R_SYM (rp->r_info);
4928 if (! const_strneq (relname, "R_IA64_SEGREL"))
4930 warn (_("Skipping unexpected relocation type %s\n"), relname);
4934 i = rp->r_offset / (3 * eh_addr_size);
4936 switch (rp->r_offset/eh_addr_size % 3)
4939 aux->table[i].start.section = sym->st_shndx;
4940 aux->table[i].start.offset += rp->r_addend + sym->st_value;
4943 aux->table[i].end.section = sym->st_shndx;
4944 aux->table[i].end.offset += rp->r_addend + sym->st_value;
4947 aux->table[i].info.section = sym->st_shndx;
4948 aux->table[i].info.offset += rp->r_addend + sym->st_value;
4958 aux->table_len = size / (3 * eh_addr_size);
4963 ia64_process_unwind (FILE *file)
4965 Elf_Internal_Shdr *sec, *unwsec = NULL, *strsec;
4966 unsigned long i, unwcount = 0, unwstart = 0;
4967 struct ia64_unw_aux_info aux;
4969 memset (& aux, 0, sizeof (aux));
4971 for (i = 0, sec = section_headers; i < elf_header.e_shnum; ++i, ++sec)
4973 if (sec->sh_type == SHT_SYMTAB
4974 && SECTION_HEADER_INDEX (sec->sh_link) < elf_header.e_shnum)
4976 aux.nsyms = sec->sh_size / sec->sh_entsize;
4977 aux.symtab = GET_ELF_SYMBOLS (file, sec);
4979 strsec = SECTION_HEADER (sec->sh_link);
4980 aux.strtab = get_data (NULL, file, strsec->sh_offset,
4981 1, strsec->sh_size, _("string table"));
4982 aux.strtab_size = aux.strtab != NULL ? strsec->sh_size : 0;
4984 else if (sec->sh_type == SHT_IA_64_UNWIND)
4989 printf (_("\nThere are no unwind sections in this file.\n"));
4991 while (unwcount-- > 0)
4996 for (i = unwstart, sec = section_headers + unwstart;
4997 i < elf_header.e_shnum; ++i, ++sec)
4998 if (sec->sh_type == SHT_IA_64_UNWIND)
5005 len = sizeof (ELF_STRING_ia64_unwind_once) - 1;
5007 if ((unwsec->sh_flags & SHF_GROUP) != 0)
5009 /* We need to find which section group it is in. */
5010 struct group_list *g = section_headers_groups [i]->root;
5012 for (; g != NULL; g = g->next)
5014 sec = SECTION_HEADER (g->section_index);
5016 if (streq (SECTION_NAME (sec), ELF_STRING_ia64_unwind_info))
5021 i = elf_header.e_shnum;
5023 else if (strneq (SECTION_NAME (unwsec), ELF_STRING_ia64_unwind_once, len))
5025 /* .gnu.linkonce.ia64unw.FOO -> .gnu.linkonce.ia64unwi.FOO. */
5026 len2 = sizeof (ELF_STRING_ia64_unwind_info_once) - 1;
5027 suffix = SECTION_NAME (unwsec) + len;
5028 for (i = 0, sec = section_headers; i < elf_header.e_shnum;
5030 if (strneq (SECTION_NAME (sec), ELF_STRING_ia64_unwind_info_once, len2)
5031 && streq (SECTION_NAME (sec) + len2, suffix))
5036 /* .IA_64.unwindFOO -> .IA_64.unwind_infoFOO
5037 .IA_64.unwind or BAR -> .IA_64.unwind_info. */
5038 len = sizeof (ELF_STRING_ia64_unwind) - 1;
5039 len2 = sizeof (ELF_STRING_ia64_unwind_info) - 1;
5041 if (strneq (SECTION_NAME (unwsec), ELF_STRING_ia64_unwind, len))
5042 suffix = SECTION_NAME (unwsec) + len;
5043 for (i = 0, sec = section_headers; i < elf_header.e_shnum;
5045 if (strneq (SECTION_NAME (sec), ELF_STRING_ia64_unwind_info, len2)
5046 && streq (SECTION_NAME (sec) + len2, suffix))
5050 if (i == elf_header.e_shnum)
5052 printf (_("\nCould not find unwind info section for "));
5054 if (string_table == NULL)
5055 printf ("%d", unwsec->sh_name);
5057 printf (_("'%s'"), SECTION_NAME (unwsec));
5061 aux.info_size = sec->sh_size;
5062 aux.info_addr = sec->sh_addr;
5063 aux.info = get_data (NULL, file, sec->sh_offset, 1, aux.info_size,
5066 printf (_("\nUnwind section "));
5068 if (string_table == NULL)
5069 printf ("%d", unwsec->sh_name);
5071 printf (_("'%s'"), SECTION_NAME (unwsec));
5073 printf (_(" at offset 0x%lx contains %lu entries:\n"),
5074 (unsigned long) unwsec->sh_offset,
5075 (unsigned long) (unwsec->sh_size / (3 * eh_addr_size)));
5077 (void) slurp_ia64_unwind_table (file, & aux, unwsec);
5079 if (aux.table_len > 0)
5080 dump_ia64_unwind (& aux);
5083 free ((char *) aux.table);
5085 free ((char *) aux.info);
5094 free ((char *) aux.strtab);
5099 struct hppa_unw_aux_info
5101 struct hppa_unw_table_entry
5103 struct absaddr start;
5105 unsigned int Cannot_unwind:1; /* 0 */
5106 unsigned int Millicode:1; /* 1 */
5107 unsigned int Millicode_save_sr0:1; /* 2 */
5108 unsigned int Region_description:2; /* 3..4 */
5109 unsigned int reserved1:1; /* 5 */
5110 unsigned int Entry_SR:1; /* 6 */
5111 unsigned int Entry_FR:4; /* number saved */ /* 7..10 */
5112 unsigned int Entry_GR:5; /* number saved */ /* 11..15 */
5113 unsigned int Args_stored:1; /* 16 */
5114 unsigned int Variable_Frame:1; /* 17 */
5115 unsigned int Separate_Package_Body:1; /* 18 */
5116 unsigned int Frame_Extension_Millicode:1; /* 19 */
5117 unsigned int Stack_Overflow_Check:1; /* 20 */
5118 unsigned int Two_Instruction_SP_Increment:1; /* 21 */
5119 unsigned int Ada_Region:1; /* 22 */
5120 unsigned int cxx_info:1; /* 23 */
5121 unsigned int cxx_try_catch:1; /* 24 */
5122 unsigned int sched_entry_seq:1; /* 25 */
5123 unsigned int reserved2:1; /* 26 */
5124 unsigned int Save_SP:1; /* 27 */
5125 unsigned int Save_RP:1; /* 28 */
5126 unsigned int Save_MRP_in_frame:1; /* 29 */
5127 unsigned int extn_ptr_defined:1; /* 30 */
5128 unsigned int Cleanup_defined:1; /* 31 */
5130 unsigned int MPE_XL_interrupt_marker:1; /* 0 */
5131 unsigned int HP_UX_interrupt_marker:1; /* 1 */
5132 unsigned int Large_frame:1; /* 2 */
5133 unsigned int Pseudo_SP_Set:1; /* 3 */
5134 unsigned int reserved4:1; /* 4 */
5135 unsigned int Total_frame_size:27; /* 5..31 */
5137 *table; /* Unwind table. */
5138 unsigned long table_len; /* Length of unwind table. */
5139 bfd_vma seg_base; /* Starting address of segment. */
5140 Elf_Internal_Sym *symtab; /* The symbol table. */
5141 unsigned long nsyms; /* Number of symbols. */
5142 char *strtab; /* The string table. */
5143 unsigned long strtab_size; /* Size of string table. */
5147 dump_hppa_unwind (struct hppa_unw_aux_info *aux)
5149 struct hppa_unw_table_entry *tp;
5151 for (tp = aux->table; tp < aux->table + aux->table_len; ++tp)
5154 const char *procname;
5156 find_symbol_for_address (aux->symtab, aux->nsyms, aux->strtab,
5157 aux->strtab_size, tp->start, &procname,
5160 fputs ("\n<", stdout);
5164 fputs (procname, stdout);
5167 printf ("+%lx", (unsigned long) offset);
5170 fputs (">: [", stdout);
5171 print_vma (tp->start.offset, PREFIX_HEX);
5172 fputc ('-', stdout);
5173 print_vma (tp->end.offset, PREFIX_HEX);
5176 #define PF(_m) if (tp->_m) printf (#_m " ");
5177 #define PV(_m) if (tp->_m) printf (#_m "=%d ", tp->_m);
5180 PF(Millicode_save_sr0);
5181 /* PV(Region_description); */
5187 PF(Separate_Package_Body);
5188 PF(Frame_Extension_Millicode);
5189 PF(Stack_Overflow_Check);
5190 PF(Two_Instruction_SP_Increment);
5194 PF(sched_entry_seq);
5197 PF(Save_MRP_in_frame);
5198 PF(extn_ptr_defined);
5199 PF(Cleanup_defined);
5200 PF(MPE_XL_interrupt_marker);
5201 PF(HP_UX_interrupt_marker);
5204 PV(Total_frame_size);
5213 slurp_hppa_unwind_table (FILE *file,
5214 struct hppa_unw_aux_info *aux,
5215 Elf_Internal_Shdr *sec)
5217 unsigned long size, unw_ent_size, nentries, nrelas, i;
5218 Elf_Internal_Phdr *seg;
5219 struct hppa_unw_table_entry *tep;
5220 Elf_Internal_Shdr *relsec;
5221 Elf_Internal_Rela *rela, *rp;
5222 unsigned char *table, *tp;
5223 Elf_Internal_Sym *sym;
5224 const char *relname;
5226 /* First, find the starting address of the segment that includes
5229 if (elf_header.e_phnum)
5231 if (! get_program_headers (file))
5234 for (seg = program_headers;
5235 seg < program_headers + elf_header.e_phnum;
5238 if (seg->p_type != PT_LOAD)
5241 if (sec->sh_addr >= seg->p_vaddr
5242 && (sec->sh_addr + sec->sh_size <= seg->p_vaddr + seg->p_memsz))
5244 aux->seg_base = seg->p_vaddr;
5250 /* Second, build the unwind table from the contents of the unwind
5252 size = sec->sh_size;
5253 table = get_data (NULL, file, sec->sh_offset, 1, size, _("unwind table"));
5258 nentries = size / unw_ent_size;
5259 size = unw_ent_size * nentries;
5261 tep = aux->table = xcmalloc (nentries, sizeof (aux->table[0]));
5263 for (tp = table; tp < table + size; tp += unw_ent_size, ++tep)
5265 unsigned int tmp1, tmp2;
5267 tep->start.section = SHN_UNDEF;
5268 tep->end.section = SHN_UNDEF;
5270 tep->start.offset = byte_get ((unsigned char *) tp + 0, 4);
5271 tep->end.offset = byte_get ((unsigned char *) tp + 4, 4);
5272 tmp1 = byte_get ((unsigned char *) tp + 8, 4);
5273 tmp2 = byte_get ((unsigned char *) tp + 12, 4);
5275 tep->start.offset += aux->seg_base;
5276 tep->end.offset += aux->seg_base;
5278 tep->Cannot_unwind = (tmp1 >> 31) & 0x1;
5279 tep->Millicode = (tmp1 >> 30) & 0x1;
5280 tep->Millicode_save_sr0 = (tmp1 >> 29) & 0x1;
5281 tep->Region_description = (tmp1 >> 27) & 0x3;
5282 tep->reserved1 = (tmp1 >> 26) & 0x1;
5283 tep->Entry_SR = (tmp1 >> 25) & 0x1;
5284 tep->Entry_FR = (tmp1 >> 21) & 0xf;
5285 tep->Entry_GR = (tmp1 >> 16) & 0x1f;
5286 tep->Args_stored = (tmp1 >> 15) & 0x1;
5287 tep->Variable_Frame = (tmp1 >> 14) & 0x1;
5288 tep->Separate_Package_Body = (tmp1 >> 13) & 0x1;
5289 tep->Frame_Extension_Millicode = (tmp1 >> 12) & 0x1;
5290 tep->Stack_Overflow_Check = (tmp1 >> 11) & 0x1;
5291 tep->Two_Instruction_SP_Increment = (tmp1 >> 10) & 0x1;
5292 tep->Ada_Region = (tmp1 >> 9) & 0x1;
5293 tep->cxx_info = (tmp1 >> 8) & 0x1;
5294 tep->cxx_try_catch = (tmp1 >> 7) & 0x1;
5295 tep->sched_entry_seq = (tmp1 >> 6) & 0x1;
5296 tep->reserved2 = (tmp1 >> 5) & 0x1;
5297 tep->Save_SP = (tmp1 >> 4) & 0x1;
5298 tep->Save_RP = (tmp1 >> 3) & 0x1;
5299 tep->Save_MRP_in_frame = (tmp1 >> 2) & 0x1;
5300 tep->extn_ptr_defined = (tmp1 >> 1) & 0x1;
5301 tep->Cleanup_defined = tmp1 & 0x1;
5303 tep->MPE_XL_interrupt_marker = (tmp2 >> 31) & 0x1;
5304 tep->HP_UX_interrupt_marker = (tmp2 >> 30) & 0x1;
5305 tep->Large_frame = (tmp2 >> 29) & 0x1;
5306 tep->Pseudo_SP_Set = (tmp2 >> 28) & 0x1;
5307 tep->reserved4 = (tmp2 >> 27) & 0x1;
5308 tep->Total_frame_size = tmp2 & 0x7ffffff;
5312 /* Third, apply any relocations to the unwind table. */
5314 for (relsec = section_headers;
5315 relsec < section_headers + elf_header.e_shnum;
5318 if (relsec->sh_type != SHT_RELA
5319 || SECTION_HEADER_INDEX (relsec->sh_info) >= elf_header.e_shnum
5320 || SECTION_HEADER (relsec->sh_info) != sec)
5323 if (!slurp_rela_relocs (file, relsec->sh_offset, relsec->sh_size,
5327 for (rp = rela; rp < rela + nrelas; ++rp)
5331 relname = elf_hppa_reloc_type (ELF32_R_TYPE (rp->r_info));
5332 sym = aux->symtab + ELF32_R_SYM (rp->r_info);
5336 relname = elf_hppa_reloc_type (ELF64_R_TYPE (rp->r_info));
5337 sym = aux->symtab + ELF64_R_SYM (rp->r_info);
5340 /* R_PARISC_SEGREL32 or R_PARISC_SEGREL64. */
5341 if (! const_strneq (relname, "R_PARISC_SEGREL"))
5343 warn (_("Skipping unexpected relocation type %s\n"), relname);
5347 i = rp->r_offset / unw_ent_size;
5349 switch ((rp->r_offset % unw_ent_size) / eh_addr_size)
5352 aux->table[i].start.section = sym->st_shndx;
5353 aux->table[i].start.offset += sym->st_value + rp->r_addend;
5356 aux->table[i].end.section = sym->st_shndx;
5357 aux->table[i].end.offset += sym->st_value + rp->r_addend;
5367 aux->table_len = nentries;
5373 hppa_process_unwind (FILE *file)
5375 struct hppa_unw_aux_info aux;
5376 Elf_Internal_Shdr *unwsec = NULL;
5377 Elf_Internal_Shdr *strsec;
5378 Elf_Internal_Shdr *sec;
5381 memset (& aux, 0, sizeof (aux));
5383 if (string_table == NULL)
5386 for (i = 0, sec = section_headers; i < elf_header.e_shnum; ++i, ++sec)
5388 if (sec->sh_type == SHT_SYMTAB
5389 && SECTION_HEADER_INDEX (sec->sh_link) < elf_header.e_shnum)
5391 aux.nsyms = sec->sh_size / sec->sh_entsize;
5392 aux.symtab = GET_ELF_SYMBOLS (file, sec);
5394 strsec = SECTION_HEADER (sec->sh_link);
5395 aux.strtab = get_data (NULL, file, strsec->sh_offset,
5396 1, strsec->sh_size, _("string table"));
5397 aux.strtab_size = aux.strtab != NULL ? strsec->sh_size : 0;
5399 else if (streq (SECTION_NAME (sec), ".PARISC.unwind"))
5404 printf (_("\nThere are no unwind sections in this file.\n"));
5406 for (i = 0, sec = section_headers; i < elf_header.e_shnum; ++i, ++sec)
5408 if (streq (SECTION_NAME (sec), ".PARISC.unwind"))
5410 printf (_("\nUnwind section "));
5411 printf (_("'%s'"), SECTION_NAME (sec));
5413 printf (_(" at offset 0x%lx contains %lu entries:\n"),
5414 (unsigned long) sec->sh_offset,
5415 (unsigned long) (sec->sh_size / (2 * eh_addr_size + 8)));
5417 slurp_hppa_unwind_table (file, &aux, sec);
5418 if (aux.table_len > 0)
5419 dump_hppa_unwind (&aux);
5422 free ((char *) aux.table);
5430 free ((char *) aux.strtab);
5436 process_unwind (FILE *file)
5438 struct unwind_handler {
5440 int (*handler)(FILE *file);
5442 { EM_IA_64, ia64_process_unwind },
5443 { EM_PARISC, hppa_process_unwind },
5451 for (i = 0; handlers[i].handler != NULL; i++)
5452 if (elf_header.e_machine == handlers[i].machtype)
5453 return handlers[i].handler (file);
5455 printf (_("\nThere are no unwind sections in this file.\n"));
5460 dynamic_section_mips_val (Elf_Internal_Dyn *entry)
5462 switch (entry->d_tag)
5465 if (entry->d_un.d_val == 0)
5469 static const char * opts[] =
5471 "QUICKSTART", "NOTPOT", "NO_LIBRARY_REPLACEMENT",
5472 "NO_MOVE", "SGI_ONLY", "GUARANTEE_INIT", "DELTA_C_PLUS_PLUS",
5473 "GUARANTEE_START_INIT", "PIXIE", "DEFAULT_DELAY_LOAD",
5474 "REQUICKSTART", "REQUICKSTARTED", "CORD", "NO_UNRES_UNDEF",
5479 for (cnt = 0; cnt < NUM_ELEM (opts); ++cnt)
5480 if (entry->d_un.d_val & (1 << cnt))
5482 printf ("%s%s", first ? "" : " ", opts[cnt]);
5489 case DT_MIPS_IVERSION:
5490 if (VALID_DYNAMIC_NAME (entry->d_un.d_val))
5491 printf ("Interface Version: %s\n", GET_DYNAMIC_NAME (entry->d_un.d_val));
5493 printf ("<corrupt: %ld>\n", (long) entry->d_un.d_ptr);
5496 case DT_MIPS_TIME_STAMP:
5501 time_t time = entry->d_un.d_val;
5502 tmp = gmtime (&time);
5503 snprintf (timebuf, sizeof (timebuf), "%04u-%02u-%02uT%02u:%02u:%02u",
5504 tmp->tm_year + 1900, tmp->tm_mon + 1, tmp->tm_mday,
5505 tmp->tm_hour, tmp->tm_min, tmp->tm_sec);
5506 printf ("Time Stamp: %s\n", timebuf);
5510 case DT_MIPS_RLD_VERSION:
5511 case DT_MIPS_LOCAL_GOTNO:
5512 case DT_MIPS_CONFLICTNO:
5513 case DT_MIPS_LIBLISTNO:
5514 case DT_MIPS_SYMTABNO:
5515 case DT_MIPS_UNREFEXTNO:
5516 case DT_MIPS_HIPAGENO:
5517 case DT_MIPS_DELTA_CLASS_NO:
5518 case DT_MIPS_DELTA_INSTANCE_NO:
5519 case DT_MIPS_DELTA_RELOC_NO:
5520 case DT_MIPS_DELTA_SYM_NO:
5521 case DT_MIPS_DELTA_CLASSSYM_NO:
5522 case DT_MIPS_COMPACT_SIZE:
5523 printf ("%ld\n", (long) entry->d_un.d_ptr);
5527 printf ("%#lx\n", (long) entry->d_un.d_ptr);
5533 dynamic_section_parisc_val (Elf_Internal_Dyn *entry)
5535 switch (entry->d_tag)
5537 case DT_HP_DLD_FLAGS:
5546 { DT_HP_DEBUG_PRIVATE, "HP_DEBUG_PRIVATE" },
5547 { DT_HP_DEBUG_CALLBACK, "HP_DEBUG_CALLBACK" },
5548 { DT_HP_DEBUG_CALLBACK_BOR, "HP_DEBUG_CALLBACK_BOR" },
5549 { DT_HP_NO_ENVVAR, "HP_NO_ENVVAR" },
5550 { DT_HP_BIND_NOW, "HP_BIND_NOW" },
5551 { DT_HP_BIND_NONFATAL, "HP_BIND_NONFATAL" },
5552 { DT_HP_BIND_VERBOSE, "HP_BIND_VERBOSE" },
5553 { DT_HP_BIND_RESTRICTED, "HP_BIND_RESTRICTED" },
5554 { DT_HP_BIND_SYMBOLIC, "HP_BIND_SYMBOLIC" },
5555 { DT_HP_RPATH_FIRST, "HP_RPATH_FIRST" },
5556 { DT_HP_BIND_DEPTH_FIRST, "HP_BIND_DEPTH_FIRST" },
5557 { DT_HP_GST, "HP_GST" },
5558 { DT_HP_SHLIB_FIXED, "HP_SHLIB_FIXED" },
5559 { DT_HP_MERGE_SHLIB_SEG, "HP_MERGE_SHLIB_SEG" },
5560 { DT_HP_NODELETE, "HP_NODELETE" },
5561 { DT_HP_GROUP, "HP_GROUP" },
5562 { DT_HP_PROTECT_LINKAGE_TABLE, "HP_PROTECT_LINKAGE_TABLE" }
5566 bfd_vma val = entry->d_un.d_val;
5568 for (cnt = 0; cnt < sizeof (flags) / sizeof (flags[0]); ++cnt)
5569 if (val & flags[cnt].bit)
5573 fputs (flags[cnt].str, stdout);
5575 val ^= flags[cnt].bit;
5578 if (val != 0 || first)
5582 print_vma (val, HEX);
5588 print_vma (entry->d_un.d_ptr, PREFIX_HEX);
5595 dynamic_section_ia64_val (Elf_Internal_Dyn *entry)
5597 switch (entry->d_tag)
5599 case DT_IA_64_PLT_RESERVE:
5600 /* First 3 slots reserved. */
5601 print_vma (entry->d_un.d_ptr, PREFIX_HEX);
5603 print_vma (entry->d_un.d_ptr + (3 * 8), PREFIX_HEX);
5607 print_vma (entry->d_un.d_ptr, PREFIX_HEX);
5614 get_32bit_dynamic_section (FILE *file)
5616 Elf32_External_Dyn *edyn, *ext;
5617 Elf_Internal_Dyn *entry;
5619 edyn = get_data (NULL, file, dynamic_addr, 1, dynamic_size,
5620 _("dynamic section"));
5624 /* SGI's ELF has more than one section in the DYNAMIC segment, and we
5625 might not have the luxury of section headers. Look for the DT_NULL
5626 terminator to determine the number of entries. */
5627 for (ext = edyn, dynamic_nent = 0;
5628 (char *) ext < (char *) edyn + dynamic_size;
5632 if (BYTE_GET (ext->d_tag) == DT_NULL)
5636 dynamic_section = cmalloc (dynamic_nent, sizeof (*entry));
5637 if (dynamic_section == NULL)
5639 error (_("Out of memory\n"));
5644 for (ext = edyn, entry = dynamic_section;
5645 entry < dynamic_section + dynamic_nent;
5648 entry->d_tag = BYTE_GET (ext->d_tag);
5649 entry->d_un.d_val = BYTE_GET (ext->d_un.d_val);
5658 get_64bit_dynamic_section (FILE *file)
5660 Elf64_External_Dyn *edyn, *ext;
5661 Elf_Internal_Dyn *entry;
5663 edyn = get_data (NULL, file, dynamic_addr, 1, dynamic_size,
5664 _("dynamic section"));
5668 /* SGI's ELF has more than one section in the DYNAMIC segment, and we
5669 might not have the luxury of section headers. Look for the DT_NULL
5670 terminator to determine the number of entries. */
5671 for (ext = edyn, dynamic_nent = 0;
5672 (char *) ext < (char *) edyn + dynamic_size;
5676 if (BYTE_GET (ext->d_tag) == DT_NULL)
5680 dynamic_section = cmalloc (dynamic_nent, sizeof (*entry));
5681 if (dynamic_section == NULL)
5683 error (_("Out of memory\n"));
5688 for (ext = edyn, entry = dynamic_section;
5689 entry < dynamic_section + dynamic_nent;
5692 entry->d_tag = BYTE_GET (ext->d_tag);
5693 entry->d_un.d_val = BYTE_GET (ext->d_un.d_val);
5702 print_dynamic_flags (bfd_vma flags)
5710 flag = flags & - flags;
5720 case DF_ORIGIN: fputs ("ORIGIN", stdout); break;
5721 case DF_SYMBOLIC: fputs ("SYMBOLIC", stdout); break;
5722 case DF_TEXTREL: fputs ("TEXTREL", stdout); break;
5723 case DF_BIND_NOW: fputs ("BIND_NOW", stdout); break;
5724 case DF_STATIC_TLS: fputs ("STATIC_TLS", stdout); break;
5725 default: fputs ("unknown", stdout); break;
5731 /* Parse and display the contents of the dynamic section. */
5734 process_dynamic_section (FILE *file)
5736 Elf_Internal_Dyn *entry;
5738 if (dynamic_size == 0)
5741 printf (_("\nThere is no dynamic section in this file.\n"));
5748 if (! get_32bit_dynamic_section (file))
5751 else if (! get_64bit_dynamic_section (file))
5754 /* Find the appropriate symbol table. */
5755 if (dynamic_symbols == NULL)
5757 for (entry = dynamic_section;
5758 entry < dynamic_section + dynamic_nent;
5761 Elf_Internal_Shdr section;
5763 if (entry->d_tag != DT_SYMTAB)
5766 dynamic_info[DT_SYMTAB] = entry->d_un.d_val;
5768 /* Since we do not know how big the symbol table is,
5769 we default to reading in the entire file (!) and
5770 processing that. This is overkill, I know, but it
5772 section.sh_offset = offset_from_vma (file, entry->d_un.d_val, 0);
5774 if (archive_file_offset != 0)
5775 section.sh_size = archive_file_size - section.sh_offset;
5778 if (fseek (file, 0, SEEK_END))
5779 error (_("Unable to seek to end of file!"));
5781 section.sh_size = ftell (file) - section.sh_offset;
5785 section.sh_entsize = sizeof (Elf32_External_Sym);
5787 section.sh_entsize = sizeof (Elf64_External_Sym);
5789 num_dynamic_syms = section.sh_size / section.sh_entsize;
5790 if (num_dynamic_syms < 1)
5792 error (_("Unable to determine the number of symbols to load\n"));
5796 dynamic_symbols = GET_ELF_SYMBOLS (file, §ion);
5800 /* Similarly find a string table. */
5801 if (dynamic_strings == NULL)
5803 for (entry = dynamic_section;
5804 entry < dynamic_section + dynamic_nent;
5807 unsigned long offset;
5810 if (entry->d_tag != DT_STRTAB)
5813 dynamic_info[DT_STRTAB] = entry->d_un.d_val;
5815 /* Since we do not know how big the string table is,
5816 we default to reading in the entire file (!) and
5817 processing that. This is overkill, I know, but it
5820 offset = offset_from_vma (file, entry->d_un.d_val, 0);
5822 if (archive_file_offset != 0)
5823 str_tab_len = archive_file_size - offset;
5826 if (fseek (file, 0, SEEK_END))
5827 error (_("Unable to seek to end of file\n"));
5828 str_tab_len = ftell (file) - offset;
5831 if (str_tab_len < 1)
5834 (_("Unable to determine the length of the dynamic string table\n"));
5838 dynamic_strings = get_data (NULL, file, offset, 1, str_tab_len,
5839 _("dynamic string table"));
5840 dynamic_strings_length = str_tab_len;
5845 /* And find the syminfo section if available. */
5846 if (dynamic_syminfo == NULL)
5848 unsigned long syminsz = 0;
5850 for (entry = dynamic_section;
5851 entry < dynamic_section + dynamic_nent;
5854 if (entry->d_tag == DT_SYMINENT)
5856 /* Note: these braces are necessary to avoid a syntax
5857 error from the SunOS4 C compiler. */
5858 assert (sizeof (Elf_External_Syminfo) == entry->d_un.d_val);
5860 else if (entry->d_tag == DT_SYMINSZ)
5861 syminsz = entry->d_un.d_val;
5862 else if (entry->d_tag == DT_SYMINFO)
5863 dynamic_syminfo_offset = offset_from_vma (file, entry->d_un.d_val,
5867 if (dynamic_syminfo_offset != 0 && syminsz != 0)
5869 Elf_External_Syminfo *extsyminfo, *extsym;
5870 Elf_Internal_Syminfo *syminfo;
5872 /* There is a syminfo section. Read the data. */
5873 extsyminfo = get_data (NULL, file, dynamic_syminfo_offset, 1,
5874 syminsz, _("symbol information"));
5878 dynamic_syminfo = malloc (syminsz);
5879 if (dynamic_syminfo == NULL)
5881 error (_("Out of memory\n"));
5885 dynamic_syminfo_nent = syminsz / sizeof (Elf_External_Syminfo);
5886 for (syminfo = dynamic_syminfo, extsym = extsyminfo;
5887 syminfo < dynamic_syminfo + dynamic_syminfo_nent;
5888 ++syminfo, ++extsym)
5890 syminfo->si_boundto = BYTE_GET (extsym->si_boundto);
5891 syminfo->si_flags = BYTE_GET (extsym->si_flags);
5898 if (do_dynamic && dynamic_addr)
5899 printf (_("\nDynamic section at offset 0x%lx contains %u entries:\n"),
5900 dynamic_addr, dynamic_nent);
5902 printf (_(" Tag Type Name/Value\n"));
5904 for (entry = dynamic_section;
5905 entry < dynamic_section + dynamic_nent;
5913 print_vma (entry->d_tag, FULL_HEX);
5914 dtype = get_dynamic_type (entry->d_tag);
5915 printf (" (%s)%*s", dtype,
5916 ((is_32bit_elf ? 27 : 19)
5917 - (int) strlen (dtype)),
5921 switch (entry->d_tag)
5925 print_dynamic_flags (entry->d_un.d_val);
5935 switch (entry->d_tag)
5938 printf (_("Auxiliary library"));
5942 printf (_("Filter library"));
5946 printf (_("Configuration file"));
5950 printf (_("Dependency audit library"));
5954 printf (_("Audit library"));
5958 if (VALID_DYNAMIC_NAME (entry->d_un.d_val))
5959 printf (": [%s]\n", GET_DYNAMIC_NAME (entry->d_un.d_val));
5963 print_vma (entry->d_un.d_val, PREFIX_HEX);
5972 printf (_("Flags:"));
5974 if (entry->d_un.d_val == 0)
5975 printf (_(" None\n"));
5978 unsigned long int val = entry->d_un.d_val;
5980 if (val & DTF_1_PARINIT)
5982 printf (" PARINIT");
5983 val ^= DTF_1_PARINIT;
5985 if (val & DTF_1_CONFEXP)
5987 printf (" CONFEXP");
5988 val ^= DTF_1_CONFEXP;
5991 printf (" %lx", val);
6000 printf (_("Flags:"));
6002 if (entry->d_un.d_val == 0)
6003 printf (_(" None\n"));
6006 unsigned long int val = entry->d_un.d_val;
6008 if (val & DF_P1_LAZYLOAD)
6010 printf (" LAZYLOAD");
6011 val ^= DF_P1_LAZYLOAD;
6013 if (val & DF_P1_GROUPPERM)
6015 printf (" GROUPPERM");
6016 val ^= DF_P1_GROUPPERM;
6019 printf (" %lx", val);
6028 printf (_("Flags:"));
6029 if (entry->d_un.d_val == 0)
6030 printf (_(" None\n"));
6033 unsigned long int val = entry->d_un.d_val;
6040 if (val & DF_1_GLOBAL)
6045 if (val & DF_1_GROUP)
6050 if (val & DF_1_NODELETE)
6052 printf (" NODELETE");
6053 val ^= DF_1_NODELETE;
6055 if (val & DF_1_LOADFLTR)
6057 printf (" LOADFLTR");
6058 val ^= DF_1_LOADFLTR;
6060 if (val & DF_1_INITFIRST)
6062 printf (" INITFIRST");
6063 val ^= DF_1_INITFIRST;
6065 if (val & DF_1_NOOPEN)
6070 if (val & DF_1_ORIGIN)
6075 if (val & DF_1_DIRECT)
6080 if (val & DF_1_TRANS)
6085 if (val & DF_1_INTERPOSE)
6087 printf (" INTERPOSE");
6088 val ^= DF_1_INTERPOSE;
6090 if (val & DF_1_NODEFLIB)
6092 printf (" NODEFLIB");
6093 val ^= DF_1_NODEFLIB;
6095 if (val & DF_1_NODUMP)
6100 if (val & DF_1_CONLFAT)
6102 printf (" CONLFAT");
6103 val ^= DF_1_CONLFAT;
6106 printf (" %lx", val);
6113 dynamic_info[entry->d_tag] = entry->d_un.d_val;
6115 puts (get_dynamic_type (entry->d_un.d_val));
6135 dynamic_info[entry->d_tag] = entry->d_un.d_val;
6141 if (VALID_DYNAMIC_NAME (entry->d_un.d_val))
6142 name = GET_DYNAMIC_NAME (entry->d_un.d_val);
6148 switch (entry->d_tag)
6151 printf (_("Shared library: [%s]"), name);
6153 if (streq (name, program_interpreter))
6154 printf (_(" program interpreter"));
6158 printf (_("Library soname: [%s]"), name);
6162 printf (_("Library rpath: [%s]"), name);
6166 printf (_("Library runpath: [%s]"), name);
6170 print_vma (entry->d_un.d_val, PREFIX_HEX);
6175 print_vma (entry->d_un.d_val, PREFIX_HEX);
6188 dynamic_info[entry->d_tag] = entry->d_un.d_val;
6192 case DT_INIT_ARRAYSZ:
6193 case DT_FINI_ARRAYSZ:
6194 case DT_GNU_CONFLICTSZ:
6195 case DT_GNU_LIBLISTSZ:
6198 print_vma (entry->d_un.d_val, UNSIGNED);
6199 printf (" (bytes)\n");
6209 print_vma (entry->d_un.d_val, UNSIGNED);
6222 if (entry->d_tag == DT_USED
6223 && VALID_DYNAMIC_NAME (entry->d_un.d_val))
6225 char *name = GET_DYNAMIC_NAME (entry->d_un.d_val);
6229 printf (_("Not needed object: [%s]\n"), name);
6234 print_vma (entry->d_un.d_val, PREFIX_HEX);
6240 /* The value of this entry is ignored. */
6245 case DT_GNU_PRELINKED:
6249 time_t time = entry->d_un.d_val;
6251 tmp = gmtime (&time);
6252 printf ("%04u-%02u-%02uT%02u:%02u:%02u\n",
6253 tmp->tm_year + 1900, tmp->tm_mon + 1, tmp->tm_mday,
6254 tmp->tm_hour, tmp->tm_min, tmp->tm_sec);
6260 dynamic_info_DT_GNU_HASH = entry->d_un.d_val;
6263 print_vma (entry->d_un.d_val, PREFIX_HEX);
6269 if ((entry->d_tag >= DT_VERSYM) && (entry->d_tag <= DT_VERNEEDNUM))
6270 version_info[DT_VERSIONTAGIDX (entry->d_tag)] =
6275 switch (elf_header.e_machine)
6278 case EM_MIPS_RS3_LE:
6279 dynamic_section_mips_val (entry);
6282 dynamic_section_parisc_val (entry);
6285 dynamic_section_ia64_val (entry);
6288 print_vma (entry->d_un.d_val, PREFIX_HEX);
6300 get_ver_flags (unsigned int flags)
6302 static char buff[32];
6309 if (flags & VER_FLG_BASE)
6310 strcat (buff, "BASE ");
6312 if (flags & VER_FLG_WEAK)
6314 if (flags & VER_FLG_BASE)
6315 strcat (buff, "| ");
6317 strcat (buff, "WEAK ");
6320 if (flags & ~(VER_FLG_BASE | VER_FLG_WEAK))
6321 strcat (buff, "| <unknown>");
6326 /* Display the contents of the version sections. */
6328 process_version_sections (FILE *file)
6330 Elf_Internal_Shdr *section;
6337 for (i = 0, section = section_headers;
6338 i < elf_header.e_shnum;
6341 switch (section->sh_type)
6343 case SHT_GNU_verdef:
6345 Elf_External_Verdef *edefs;
6352 (_("\nVersion definition section '%s' contains %ld entries:\n"),
6353 SECTION_NAME (section), section->sh_info);
6355 printf (_(" Addr: 0x"));
6356 printf_vma (section->sh_addr);
6357 printf (_(" Offset: %#08lx Link: %lx (%s)\n"),
6358 (unsigned long) section->sh_offset, section->sh_link,
6359 SECTION_HEADER_INDEX (section->sh_link)
6360 < elf_header.e_shnum
6361 ? SECTION_NAME (SECTION_HEADER (section->sh_link))
6364 edefs = get_data (NULL, file, section->sh_offset, 1,
6366 _("version definition section"));
6370 for (idx = cnt = 0; cnt < section->sh_info; ++cnt)
6373 Elf_External_Verdef *edef;
6374 Elf_Internal_Verdef ent;
6375 Elf_External_Verdaux *eaux;
6376 Elf_Internal_Verdaux aux;
6380 vstart = ((char *) edefs) + idx;
6382 edef = (Elf_External_Verdef *) vstart;
6384 ent.vd_version = BYTE_GET (edef->vd_version);
6385 ent.vd_flags = BYTE_GET (edef->vd_flags);
6386 ent.vd_ndx = BYTE_GET (edef->vd_ndx);
6387 ent.vd_cnt = BYTE_GET (edef->vd_cnt);
6388 ent.vd_hash = BYTE_GET (edef->vd_hash);
6389 ent.vd_aux = BYTE_GET (edef->vd_aux);
6390 ent.vd_next = BYTE_GET (edef->vd_next);
6392 printf (_(" %#06x: Rev: %d Flags: %s"),
6393 idx, ent.vd_version, get_ver_flags (ent.vd_flags));
6395 printf (_(" Index: %d Cnt: %d "),
6396 ent.vd_ndx, ent.vd_cnt);
6398 vstart += ent.vd_aux;
6400 eaux = (Elf_External_Verdaux *) vstart;
6402 aux.vda_name = BYTE_GET (eaux->vda_name);
6403 aux.vda_next = BYTE_GET (eaux->vda_next);
6405 if (VALID_DYNAMIC_NAME (aux.vda_name))
6406 printf (_("Name: %s\n"), GET_DYNAMIC_NAME (aux.vda_name));
6408 printf (_("Name index: %ld\n"), aux.vda_name);
6410 isum = idx + ent.vd_aux;
6412 for (j = 1; j < ent.vd_cnt; j++)
6414 isum += aux.vda_next;
6415 vstart += aux.vda_next;
6417 eaux = (Elf_External_Verdaux *) vstart;
6419 aux.vda_name = BYTE_GET (eaux->vda_name);
6420 aux.vda_next = BYTE_GET (eaux->vda_next);
6422 if (VALID_DYNAMIC_NAME (aux.vda_name))
6423 printf (_(" %#06x: Parent %d: %s\n"),
6424 isum, j, GET_DYNAMIC_NAME (aux.vda_name));
6426 printf (_(" %#06x: Parent %d, name index: %ld\n"),
6427 isum, j, aux.vda_name);
6437 case SHT_GNU_verneed:
6439 Elf_External_Verneed *eneed;
6445 printf (_("\nVersion needs section '%s' contains %ld entries:\n"),
6446 SECTION_NAME (section), section->sh_info);
6448 printf (_(" Addr: 0x"));
6449 printf_vma (section->sh_addr);
6450 printf (_(" Offset: %#08lx Link to section: %ld (%s)\n"),
6451 (unsigned long) section->sh_offset, section->sh_link,
6452 SECTION_HEADER_INDEX (section->sh_link)
6453 < elf_header.e_shnum
6454 ? SECTION_NAME (SECTION_HEADER (section->sh_link))
6457 eneed = get_data (NULL, file, section->sh_offset, 1,
6459 _("version need section"));
6463 for (idx = cnt = 0; cnt < section->sh_info; ++cnt)
6465 Elf_External_Verneed *entry;
6466 Elf_Internal_Verneed ent;
6471 vstart = ((char *) eneed) + idx;
6473 entry = (Elf_External_Verneed *) vstart;
6475 ent.vn_version = BYTE_GET (entry->vn_version);
6476 ent.vn_cnt = BYTE_GET (entry->vn_cnt);
6477 ent.vn_file = BYTE_GET (entry->vn_file);
6478 ent.vn_aux = BYTE_GET (entry->vn_aux);
6479 ent.vn_next = BYTE_GET (entry->vn_next);
6481 printf (_(" %#06x: Version: %d"), idx, ent.vn_version);
6483 if (VALID_DYNAMIC_NAME (ent.vn_file))
6484 printf (_(" File: %s"), GET_DYNAMIC_NAME (ent.vn_file));
6486 printf (_(" File: %lx"), ent.vn_file);
6488 printf (_(" Cnt: %d\n"), ent.vn_cnt);
6490 vstart += ent.vn_aux;
6492 for (j = 0, isum = idx + ent.vn_aux; j < ent.vn_cnt; ++j)
6494 Elf_External_Vernaux *eaux;
6495 Elf_Internal_Vernaux aux;
6497 eaux = (Elf_External_Vernaux *) vstart;
6499 aux.vna_hash = BYTE_GET (eaux->vna_hash);
6500 aux.vna_flags = BYTE_GET (eaux->vna_flags);
6501 aux.vna_other = BYTE_GET (eaux->vna_other);
6502 aux.vna_name = BYTE_GET (eaux->vna_name);
6503 aux.vna_next = BYTE_GET (eaux->vna_next);
6505 if (VALID_DYNAMIC_NAME (aux.vna_name))
6506 printf (_(" %#06x: Name: %s"),
6507 isum, GET_DYNAMIC_NAME (aux.vna_name));
6509 printf (_(" %#06x: Name index: %lx"),
6510 isum, aux.vna_name);
6512 printf (_(" Flags: %s Version: %d\n"),
6513 get_ver_flags (aux.vna_flags), aux.vna_other);
6515 isum += aux.vna_next;
6516 vstart += aux.vna_next;
6526 case SHT_GNU_versym:
6528 Elf_Internal_Shdr *link_section;
6531 unsigned char *edata;
6532 unsigned short *data;
6534 Elf_Internal_Sym *symbols;
6535 Elf_Internal_Shdr *string_sec;
6538 if (SECTION_HEADER_INDEX (section->sh_link) >= elf_header.e_shnum)
6541 link_section = SECTION_HEADER (section->sh_link);
6542 total = section->sh_size / sizeof (Elf_External_Versym);
6544 if (SECTION_HEADER_INDEX (link_section->sh_link)
6545 >= elf_header.e_shnum)
6550 symbols = GET_ELF_SYMBOLS (file, link_section);
6552 string_sec = SECTION_HEADER (link_section->sh_link);
6554 strtab = get_data (NULL, file, string_sec->sh_offset, 1,
6555 string_sec->sh_size, _("version string table"));
6559 printf (_("\nVersion symbols section '%s' contains %d entries:\n"),
6560 SECTION_NAME (section), total);
6562 printf (_(" Addr: "));
6563 printf_vma (section->sh_addr);
6564 printf (_(" Offset: %#08lx Link: %lx (%s)\n"),
6565 (unsigned long) section->sh_offset, section->sh_link,
6566 SECTION_NAME (link_section));
6568 off = offset_from_vma (file,
6569 version_info[DT_VERSIONTAGIDX (DT_VERSYM)],
6570 total * sizeof (short));
6571 edata = get_data (NULL, file, off, total, sizeof (short),
6572 _("version symbol data"));
6579 data = cmalloc (total, sizeof (short));
6581 for (cnt = total; cnt --;)
6582 data[cnt] = byte_get (edata + cnt * sizeof (short),
6587 for (cnt = 0; cnt < total; cnt += 4)
6590 int check_def, check_need;
6593 printf (" %03x:", cnt);
6595 for (j = 0; (j < 4) && (cnt + j) < total; ++j)
6596 switch (data[cnt + j])
6599 fputs (_(" 0 (*local*) "), stdout);
6603 fputs (_(" 1 (*global*) "), stdout);
6607 nn = printf ("%4x%c", data[cnt + j] & 0x7fff,
6608 data[cnt + j] & 0x8000 ? 'h' : ' ');
6612 if (SECTION_HEADER_INDEX (symbols[cnt + j].st_shndx)
6613 >= elf_header.e_shnum
6614 || SECTION_HEADER (symbols[cnt + j].st_shndx)->sh_type
6617 if (symbols[cnt + j].st_shndx == SHN_UNDEF)
6624 && version_info[DT_VERSIONTAGIDX (DT_VERNEED)])
6626 Elf_Internal_Verneed ivn;
6627 unsigned long offset;
6629 offset = offset_from_vma
6630 (file, version_info[DT_VERSIONTAGIDX (DT_VERNEED)],
6631 sizeof (Elf_External_Verneed));
6635 Elf_Internal_Vernaux ivna;
6636 Elf_External_Verneed evn;
6637 Elf_External_Vernaux evna;
6638 unsigned long a_off;
6640 get_data (&evn, file, offset, sizeof (evn), 1,
6643 ivn.vn_aux = BYTE_GET (evn.vn_aux);
6644 ivn.vn_next = BYTE_GET (evn.vn_next);
6646 a_off = offset + ivn.vn_aux;
6650 get_data (&evna, file, a_off, sizeof (evna),
6651 1, _("version need aux (2)"));
6653 ivna.vna_next = BYTE_GET (evna.vna_next);
6654 ivna.vna_other = BYTE_GET (evna.vna_other);
6656 a_off += ivna.vna_next;
6658 while (ivna.vna_other != data[cnt + j]
6659 && ivna.vna_next != 0);
6661 if (ivna.vna_other == data[cnt + j])
6663 ivna.vna_name = BYTE_GET (evna.vna_name);
6665 name = strtab + ivna.vna_name;
6666 nn += printf ("(%s%-*s",
6668 12 - (int) strlen (name),
6674 offset += ivn.vn_next;
6676 while (ivn.vn_next);
6679 if (check_def && data[cnt + j] != 0x8001
6680 && version_info[DT_VERSIONTAGIDX (DT_VERDEF)])
6682 Elf_Internal_Verdef ivd;
6683 Elf_External_Verdef evd;
6684 unsigned long offset;
6686 offset = offset_from_vma
6687 (file, version_info[DT_VERSIONTAGIDX (DT_VERDEF)],
6692 get_data (&evd, file, offset, sizeof (evd), 1,
6695 ivd.vd_next = BYTE_GET (evd.vd_next);
6696 ivd.vd_ndx = BYTE_GET (evd.vd_ndx);
6698 offset += ivd.vd_next;
6700 while (ivd.vd_ndx != (data[cnt + j] & 0x7fff)
6701 && ivd.vd_next != 0);
6703 if (ivd.vd_ndx == (data[cnt + j] & 0x7fff))
6705 Elf_External_Verdaux evda;
6706 Elf_Internal_Verdaux ivda;
6708 ivd.vd_aux = BYTE_GET (evd.vd_aux);
6710 get_data (&evda, file,
6711 offset - ivd.vd_next + ivd.vd_aux,
6713 _("version def aux"));
6715 ivda.vda_name = BYTE_GET (evda.vda_name);
6717 name = strtab + ivda.vda_name;
6718 nn += printf ("(%s%-*s",
6720 12 - (int) strlen (name),
6726 printf ("%*c", 18 - nn, ' ');
6744 printf (_("\nNo version information found in this file.\n"));
6750 get_symbol_binding (unsigned int binding)
6752 static char buff[32];
6756 case STB_LOCAL: return "LOCAL";
6757 case STB_GLOBAL: return "GLOBAL";
6758 case STB_WEAK: return "WEAK";
6760 if (binding >= STB_LOPROC && binding <= STB_HIPROC)
6761 snprintf (buff, sizeof (buff), _("<processor specific>: %d"),
6763 else if (binding >= STB_LOOS && binding <= STB_HIOS)
6764 snprintf (buff, sizeof (buff), _("<OS specific>: %d"), binding);
6766 snprintf (buff, sizeof (buff), _("<unknown>: %d"), binding);
6772 get_symbol_type (unsigned int type)
6774 static char buff[32];
6778 case STT_NOTYPE: return "NOTYPE";
6779 case STT_OBJECT: return "OBJECT";
6780 case STT_FUNC: return "FUNC";
6781 case STT_SECTION: return "SECTION";
6782 case STT_FILE: return "FILE";
6783 case STT_COMMON: return "COMMON";
6784 case STT_TLS: return "TLS";
6786 if (type >= STT_LOPROC && type <= STT_HIPROC)
6788 if (elf_header.e_machine == EM_ARM && type == STT_ARM_TFUNC)
6789 return "THUMB_FUNC";
6791 if (elf_header.e_machine == EM_SPARCV9 && type == STT_REGISTER)
6794 if (elf_header.e_machine == EM_PARISC && type == STT_PARISC_MILLI)
6795 return "PARISC_MILLI";
6797 snprintf (buff, sizeof (buff), _("<processor specific>: %d"), type);
6799 else if (type >= STT_LOOS && type <= STT_HIOS)
6801 if (elf_header.e_machine == EM_PARISC)
6803 if (type == STT_HP_OPAQUE)
6805 if (type == STT_HP_STUB)
6809 snprintf (buff, sizeof (buff), _("<OS specific>: %d"), type);
6812 snprintf (buff, sizeof (buff), _("<unknown>: %d"), type);
6818 get_symbol_visibility (unsigned int visibility)
6822 case STV_DEFAULT: return "DEFAULT";
6823 case STV_INTERNAL: return "INTERNAL";
6824 case STV_HIDDEN: return "HIDDEN";
6825 case STV_PROTECTED: return "PROTECTED";
6831 get_mips_symbol_other (unsigned int other)
6835 case STO_OPTIONAL: return "OPTIONAL";
6836 case STO_MIPS16: return "MIPS16";
6837 default: return NULL;
6842 get_symbol_other (unsigned int other)
6844 const char * result = NULL;
6845 static char buff [32];
6850 switch (elf_header.e_machine)
6853 result = get_mips_symbol_other (other);
6861 snprintf (buff, sizeof buff, _("<other>: %x"), other);
6866 get_symbol_index_type (unsigned int type)
6868 static char buff[32];
6872 case SHN_UNDEF: return "UND";
6873 case SHN_ABS: return "ABS";
6874 case SHN_COMMON: return "COM";
6876 if (type == SHN_IA_64_ANSI_COMMON
6877 && elf_header.e_machine == EM_IA_64
6878 && elf_header.e_ident[EI_OSABI] == ELFOSABI_HPUX)
6880 else if (elf_header.e_machine == EM_X86_64
6881 && type == SHN_X86_64_LCOMMON)
6883 else if (type == SHN_MIPS_SCOMMON
6884 && elf_header.e_machine == EM_MIPS)
6886 else if (type == SHN_MIPS_SUNDEFINED
6887 && elf_header.e_machine == EM_MIPS)
6889 else if (type >= SHN_LOPROC && type <= SHN_HIPROC)
6890 sprintf (buff, "PRC[0x%04x]", type);
6891 else if (type >= SHN_LOOS && type <= SHN_HIOS)
6892 sprintf (buff, "OS [0x%04x]", type);
6893 else if (type >= SHN_LORESERVE && type <= SHN_HIRESERVE)
6894 sprintf (buff, "RSV[0x%04x]", type);
6896 sprintf (buff, "%3d", type);
6904 get_dynamic_data (FILE *file, unsigned int number, unsigned int ent_size)
6906 unsigned char *e_data;
6909 e_data = cmalloc (number, ent_size);
6913 error (_("Out of memory\n"));
6917 if (fread (e_data, ent_size, number, file) != number)
6919 error (_("Unable to read in dynamic data\n"));
6923 i_data = cmalloc (number, sizeof (*i_data));
6927 error (_("Out of memory\n"));
6933 i_data[number] = byte_get (e_data + number * ent_size, ent_size);
6940 /* Dump the symbol table. */
6942 process_symbol_table (FILE *file)
6944 Elf_Internal_Shdr *section;
6945 bfd_vma nbuckets = 0;
6946 bfd_vma nchains = 0;
6947 bfd_vma *buckets = NULL;
6948 bfd_vma *chains = NULL;
6949 bfd_vma ngnubuckets = 0;
6950 bfd_vma *gnubuckets = NULL;
6951 bfd_vma *gnuchains = NULL;
6953 if (! do_syms && !do_histogram)
6956 if (dynamic_info[DT_HASH] && ((do_using_dynamic && dynamic_strings != NULL)
6959 unsigned char nb[8];
6960 unsigned char nc[8];
6961 int hash_ent_size = 4;
6963 if ((elf_header.e_machine == EM_ALPHA
6964 || elf_header.e_machine == EM_S390
6965 || elf_header.e_machine == EM_S390_OLD)
6966 && elf_header.e_ident[EI_CLASS] == ELFCLASS64)
6970 (archive_file_offset
6971 + offset_from_vma (file, dynamic_info[DT_HASH],
6972 sizeof nb + sizeof nc)),
6975 error (_("Unable to seek to start of dynamic information"));
6979 if (fread (nb, hash_ent_size, 1, file) != 1)
6981 error (_("Failed to read in number of buckets\n"));
6985 if (fread (nc, hash_ent_size, 1, file) != 1)
6987 error (_("Failed to read in number of chains\n"));
6991 nbuckets = byte_get (nb, hash_ent_size);
6992 nchains = byte_get (nc, hash_ent_size);
6994 buckets = get_dynamic_data (file, nbuckets, hash_ent_size);
6995 chains = get_dynamic_data (file, nchains, hash_ent_size);
6997 if (buckets == NULL || chains == NULL)
7002 && dynamic_info[DT_HASH] && do_using_dynamic && dynamic_strings != NULL)
7007 printf (_("\nSymbol table for image:\n"));
7009 printf (_(" Num Buc: Value Size Type Bind Vis Ndx Name\n"));
7011 printf (_(" Num Buc: Value Size Type Bind Vis Ndx Name\n"));
7013 for (hn = 0; hn < nbuckets; hn++)
7018 for (si = buckets[hn]; si < nchains && si > 0; si = chains[si])
7020 Elf_Internal_Sym *psym;
7023 psym = dynamic_symbols + si;
7025 n = print_vma (si, DEC_5);
7027 fputs (" " + n, stdout);
7028 printf (" %3lu: ", hn);
7029 print_vma (psym->st_value, LONG_HEX);
7031 print_vma (psym->st_size, DEC_5);
7033 printf (" %6s", get_symbol_type (ELF_ST_TYPE (psym->st_info)));
7034 printf (" %6s", get_symbol_binding (ELF_ST_BIND (psym->st_info)));
7035 printf (" %3s", get_symbol_visibility (ELF_ST_VISIBILITY (psym->st_other)));
7036 /* Check to see if any other bits in the st_other field are set.
7037 Note - displaying this information disrupts the layout of the
7038 table being generated, but for the moment this case is very rare. */
7039 if (psym->st_other ^ ELF_ST_VISIBILITY (psym->st_other))
7040 printf (" [%s] ", get_symbol_other (psym->st_other ^ ELF_ST_VISIBILITY (psym->st_other)));
7041 printf (" %3.3s ", get_symbol_index_type (psym->st_shndx));
7042 if (VALID_DYNAMIC_NAME (psym->st_name))
7043 print_symbol (25, GET_DYNAMIC_NAME (psym->st_name));
7045 printf (" <corrupt: %14ld>", psym->st_name);
7050 else if (do_syms && !do_using_dynamic)
7054 for (i = 0, section = section_headers;
7055 i < elf_header.e_shnum;
7059 char *strtab = NULL;
7060 unsigned long int strtab_size = 0;
7061 Elf_Internal_Sym *symtab;
7062 Elf_Internal_Sym *psym;
7065 if ( section->sh_type != SHT_SYMTAB
7066 && section->sh_type != SHT_DYNSYM)
7069 printf (_("\nSymbol table '%s' contains %lu entries:\n"),
7070 SECTION_NAME (section),
7071 (unsigned long) (section->sh_size / section->sh_entsize));
7073 printf (_(" Num: Value Size Type Bind Vis Ndx Name\n"));
7075 printf (_(" Num: Value Size Type Bind Vis Ndx Name\n"));
7077 symtab = GET_ELF_SYMBOLS (file, section);
7081 if (section->sh_link == elf_header.e_shstrndx)
7083 strtab = string_table;
7084 strtab_size = string_table_length;
7086 else if (SECTION_HEADER_INDEX (section->sh_link) < elf_header.e_shnum)
7088 Elf_Internal_Shdr *string_sec;
7090 string_sec = SECTION_HEADER (section->sh_link);
7092 strtab = get_data (NULL, file, string_sec->sh_offset,
7093 1, string_sec->sh_size, _("string table"));
7094 strtab_size = strtab != NULL ? string_sec->sh_size : 0;
7097 for (si = 0, psym = symtab;
7098 si < section->sh_size / section->sh_entsize;
7101 printf ("%6d: ", si);
7102 print_vma (psym->st_value, LONG_HEX);
7104 print_vma (psym->st_size, DEC_5);
7105 printf (" %-7s", get_symbol_type (ELF_ST_TYPE (psym->st_info)));
7106 printf (" %-6s", get_symbol_binding (ELF_ST_BIND (psym->st_info)));
7107 printf (" %-3s", get_symbol_visibility (ELF_ST_VISIBILITY (psym->st_other)));
7108 /* Check to see if any other bits in the st_other field are set.
7109 Note - displaying this information disrupts the layout of the
7110 table being generated, but for the moment this case is very rare. */
7111 if (psym->st_other ^ ELF_ST_VISIBILITY (psym->st_other))
7112 printf (" [%s] ", get_symbol_other (psym->st_other ^ ELF_ST_VISIBILITY (psym->st_other)));
7113 printf (" %4s ", get_symbol_index_type (psym->st_shndx));
7114 print_symbol (25, psym->st_name < strtab_size
7115 ? strtab + psym->st_name : "<corrupt>");
7117 if (section->sh_type == SHT_DYNSYM &&
7118 version_info[DT_VERSIONTAGIDX (DT_VERSYM)] != 0)
7120 unsigned char data[2];
7121 unsigned short vers_data;
7122 unsigned long offset;
7126 offset = offset_from_vma
7127 (file, version_info[DT_VERSIONTAGIDX (DT_VERSYM)],
7128 sizeof data + si * sizeof (vers_data));
7130 get_data (&data, file, offset + si * sizeof (vers_data),
7131 sizeof (data), 1, _("version data"));
7133 vers_data = byte_get (data, 2);
7135 is_nobits = (SECTION_HEADER_INDEX (psym->st_shndx)
7136 < elf_header.e_shnum
7137 && SECTION_HEADER (psym->st_shndx)->sh_type
7140 check_def = (psym->st_shndx != SHN_UNDEF);
7142 if ((vers_data & 0x8000) || vers_data > 1)
7144 if (version_info[DT_VERSIONTAGIDX (DT_VERNEED)]
7145 && (is_nobits || ! check_def))
7147 Elf_External_Verneed evn;
7148 Elf_Internal_Verneed ivn;
7149 Elf_Internal_Vernaux ivna;
7151 /* We must test both. */
7152 offset = offset_from_vma
7153 (file, version_info[DT_VERSIONTAGIDX (DT_VERNEED)],
7158 unsigned long vna_off;
7160 get_data (&evn, file, offset, sizeof (evn), 1,
7163 ivn.vn_aux = BYTE_GET (evn.vn_aux);
7164 ivn.vn_next = BYTE_GET (evn.vn_next);
7166 vna_off = offset + ivn.vn_aux;
7170 Elf_External_Vernaux evna;
7172 get_data (&evna, file, vna_off,
7174 _("version need aux (3)"));
7176 ivna.vna_other = BYTE_GET (evna.vna_other);
7177 ivna.vna_next = BYTE_GET (evna.vna_next);
7178 ivna.vna_name = BYTE_GET (evna.vna_name);
7180 vna_off += ivna.vna_next;
7182 while (ivna.vna_other != vers_data
7183 && ivna.vna_next != 0);
7185 if (ivna.vna_other == vers_data)
7188 offset += ivn.vn_next;
7190 while (ivn.vn_next != 0);
7192 if (ivna.vna_other == vers_data)
7195 ivna.vna_name < strtab_size
7196 ? strtab + ivna.vna_name : "<corrupt>",
7200 else if (! is_nobits)
7201 error (_("bad dynamic symbol"));
7208 if (vers_data != 0x8001
7209 && version_info[DT_VERSIONTAGIDX (DT_VERDEF)])
7211 Elf_Internal_Verdef ivd;
7212 Elf_Internal_Verdaux ivda;
7213 Elf_External_Verdaux evda;
7214 unsigned long offset;
7216 offset = offset_from_vma
7218 version_info[DT_VERSIONTAGIDX (DT_VERDEF)],
7219 sizeof (Elf_External_Verdef));
7223 Elf_External_Verdef evd;
7225 get_data (&evd, file, offset, sizeof (evd),
7226 1, _("version def"));
7228 ivd.vd_ndx = BYTE_GET (evd.vd_ndx);
7229 ivd.vd_aux = BYTE_GET (evd.vd_aux);
7230 ivd.vd_next = BYTE_GET (evd.vd_next);
7232 offset += ivd.vd_next;
7234 while (ivd.vd_ndx != (vers_data & 0x7fff)
7235 && ivd.vd_next != 0);
7237 offset -= ivd.vd_next;
7238 offset += ivd.vd_aux;
7240 get_data (&evda, file, offset, sizeof (evda),
7241 1, _("version def aux"));
7243 ivda.vda_name = BYTE_GET (evda.vda_name);
7245 if (psym->st_name != ivda.vda_name)
7246 printf ((vers_data & 0x8000)
7248 ivda.vda_name < strtab_size
7249 ? strtab + ivda.vda_name : "<corrupt>");
7259 if (strtab != string_table)
7265 (_("\nDynamic symbol information is not available for displaying symbols.\n"));
7267 if (do_histogram && buckets != NULL)
7269 unsigned long *lengths;
7270 unsigned long *counts;
7273 unsigned long maxlength = 0;
7274 unsigned long nzero_counts = 0;
7275 unsigned long nsyms = 0;
7277 printf (_("\nHistogram for bucket list length (total of %lu buckets):\n"),
7278 (unsigned long) nbuckets);
7279 printf (_(" Length Number %% of total Coverage\n"));
7281 lengths = calloc (nbuckets, sizeof (*lengths));
7282 if (lengths == NULL)
7284 error (_("Out of memory"));
7287 for (hn = 0; hn < nbuckets; ++hn)
7289 for (si = buckets[hn]; si > 0 && si < nchains; si = chains[si])
7292 if (maxlength < ++lengths[hn])
7297 counts = calloc (maxlength + 1, sizeof (*counts));
7300 error (_("Out of memory"));
7304 for (hn = 0; hn < nbuckets; ++hn)
7305 ++counts[lengths[hn]];
7310 printf (" 0 %-10lu (%5.1f%%)\n",
7311 counts[0], (counts[0] * 100.0) / nbuckets);
7312 for (i = 1; i <= maxlength; ++i)
7314 nzero_counts += counts[i] * i;
7315 printf ("%7lu %-10lu (%5.1f%%) %5.1f%%\n",
7316 i, counts[i], (counts[i] * 100.0) / nbuckets,
7317 (nzero_counts * 100.0) / nsyms);
7325 if (buckets != NULL)
7331 if (do_histogram && dynamic_info_DT_GNU_HASH)
7333 unsigned char nb[16];
7334 bfd_vma i, maxchain = 0xffffffff, symidx, bitmaskwords;
7335 unsigned long *lengths;
7336 unsigned long *counts;
7338 unsigned long maxlength = 0;
7339 unsigned long nzero_counts = 0;
7340 unsigned long nsyms = 0;
7341 bfd_vma buckets_vma;
7344 (archive_file_offset
7345 + offset_from_vma (file, dynamic_info_DT_GNU_HASH,
7349 error (_("Unable to seek to start of dynamic information"));
7353 if (fread (nb, 16, 1, file) != 1)
7355 error (_("Failed to read in number of buckets\n"));
7359 ngnubuckets = byte_get (nb, 4);
7360 symidx = byte_get (nb + 4, 4);
7361 bitmaskwords = byte_get (nb + 8, 4);
7362 buckets_vma = dynamic_info_DT_GNU_HASH + 16;
7364 buckets_vma += bitmaskwords * 4;
7366 buckets_vma += bitmaskwords * 8;
7369 (archive_file_offset
7370 + offset_from_vma (file, buckets_vma, 4)),
7373 error (_("Unable to seek to start of dynamic information"));
7377 gnubuckets = get_dynamic_data (file, ngnubuckets, 4);
7379 if (gnubuckets == NULL)
7382 for (i = 0; i < ngnubuckets; i++)
7383 if (gnubuckets[i] != 0)
7385 if (gnubuckets[i] < symidx)
7388 if (maxchain == 0xffffffff || gnubuckets[i] > maxchain)
7389 maxchain = gnubuckets[i];
7392 if (maxchain == 0xffffffff)
7398 (archive_file_offset
7399 + offset_from_vma (file, buckets_vma
7400 + 4 * (ngnubuckets + maxchain), 4)),
7403 error (_("Unable to seek to start of dynamic information"));
7409 if (fread (nb, 4, 1, file) != 1)
7411 error (_("Failed to determine last chain length\n"));
7415 if (maxchain + 1 == 0)
7420 while ((byte_get (nb, 4) & 1) == 0);
7423 (archive_file_offset
7424 + offset_from_vma (file, buckets_vma + 4 * ngnubuckets, 4)),
7427 error (_("Unable to seek to start of dynamic information"));
7431 gnuchains = get_dynamic_data (file, maxchain, 4);
7433 if (gnuchains == NULL)
7436 lengths = calloc (ngnubuckets, sizeof (*lengths));
7437 if (lengths == NULL)
7439 error (_("Out of memory"));
7443 printf (_("\nHistogram for `.gnu.hash' bucket list length (total of %lu buckets):\n"),
7444 (unsigned long) ngnubuckets);
7445 printf (_(" Length Number %% of total Coverage\n"));
7447 for (hn = 0; hn < ngnubuckets; ++hn)
7448 if (gnubuckets[hn] != 0)
7450 bfd_vma off, length = 1;
7452 for (off = gnubuckets[hn] - symidx;
7453 (gnuchains[off] & 1) == 0; ++off)
7455 lengths[hn] = length;
7456 if (length > maxlength)
7461 counts = calloc (maxlength + 1, sizeof (*counts));
7464 error (_("Out of memory"));
7468 for (hn = 0; hn < ngnubuckets; ++hn)
7469 ++counts[lengths[hn]];
7471 if (ngnubuckets > 0)
7474 printf (" 0 %-10lu (%5.1f%%)\n",
7475 counts[0], (counts[0] * 100.0) / ngnubuckets);
7476 for (j = 1; j <= maxlength; ++j)
7478 nzero_counts += counts[j] * j;
7479 printf ("%7lu %-10lu (%5.1f%%) %5.1f%%\n",
7480 j, counts[j], (counts[j] * 100.0) / ngnubuckets,
7481 (nzero_counts * 100.0) / nsyms);
7495 process_syminfo (FILE *file ATTRIBUTE_UNUSED)
7499 if (dynamic_syminfo == NULL
7501 /* No syminfo, this is ok. */
7504 /* There better should be a dynamic symbol section. */
7505 if (dynamic_symbols == NULL || dynamic_strings == NULL)
7509 printf (_("\nDynamic info segment at offset 0x%lx contains %d entries:\n"),
7510 dynamic_syminfo_offset, dynamic_syminfo_nent);
7512 printf (_(" Num: Name BoundTo Flags\n"));
7513 for (i = 0; i < dynamic_syminfo_nent; ++i)
7515 unsigned short int flags = dynamic_syminfo[i].si_flags;
7517 printf ("%4d: ", i);
7518 if (VALID_DYNAMIC_NAME (dynamic_symbols[i].st_name))
7519 print_symbol (30, GET_DYNAMIC_NAME (dynamic_symbols[i].st_name));
7521 printf ("<corrupt: %19ld>", dynamic_symbols[i].st_name);
7524 switch (dynamic_syminfo[i].si_boundto)
7526 case SYMINFO_BT_SELF:
7527 fputs ("SELF ", stdout);
7529 case SYMINFO_BT_PARENT:
7530 fputs ("PARENT ", stdout);
7533 if (dynamic_syminfo[i].si_boundto > 0
7534 && dynamic_syminfo[i].si_boundto < dynamic_nent
7535 && VALID_DYNAMIC_NAME (dynamic_section[dynamic_syminfo[i].si_boundto].d_un.d_val))
7537 print_symbol (10, GET_DYNAMIC_NAME (dynamic_section[dynamic_syminfo[i].si_boundto].d_un.d_val));
7541 printf ("%-10d ", dynamic_syminfo[i].si_boundto);
7545 if (flags & SYMINFO_FLG_DIRECT)
7547 if (flags & SYMINFO_FLG_PASSTHRU)
7548 printf (" PASSTHRU");
7549 if (flags & SYMINFO_FLG_COPY)
7551 if (flags & SYMINFO_FLG_LAZYLOAD)
7552 printf (" LAZYLOAD");
7560 #ifdef SUPPORT_DISASSEMBLY
7562 disassemble_section (Elf_Internal_Shdr *section, FILE *file)
7564 printf (_("\nAssembly dump of section %s\n"),
7565 SECTION_NAME (section));
7567 /* XXX -- to be done --- XXX */
7574 dump_section (Elf_Internal_Shdr *section, FILE *file)
7576 bfd_size_type bytes;
7578 unsigned char *data;
7579 unsigned char *start;
7581 bytes = section->sh_size;
7583 if (bytes == 0 || section->sh_type == SHT_NOBITS)
7585 printf (_("\nSection '%s' has no data to dump.\n"),
7586 SECTION_NAME (section));
7590 printf (_("\nHex dump of section '%s':\n"), SECTION_NAME (section));
7592 addr = section->sh_addr;
7594 start = get_data (NULL, file, section->sh_offset, 1, bytes,
7607 lbytes = (bytes > 16 ? 16 : bytes);
7609 printf (" 0x%8.8lx ", (unsigned long) addr);
7611 switch (elf_header.e_ident[EI_DATA])
7615 for (j = 15; j >= 0; j --)
7618 printf ("%2.2x", data[j]);
7628 for (j = 0; j < 16; j++)
7631 printf ("%2.2x", data[j]);
7641 for (j = 0; j < lbytes; j++)
7644 if (k >= ' ' && k < 0x7f)
7662 /* Apply addends of RELA relocations. */
7665 debug_apply_rela_addends (void *file,
7666 Elf_Internal_Shdr *section,
7667 unsigned char *start)
7669 Elf_Internal_Shdr *relsec;
7670 unsigned char *end = start + section->sh_size;
7671 /* FIXME: The relocation field size is relocation type dependent. */
7672 unsigned int reloc_size = 4;
7674 if (!is_relocatable)
7677 if (section->sh_size < reloc_size)
7680 for (relsec = section_headers;
7681 relsec < section_headers + elf_header.e_shnum;
7684 unsigned long nrelas;
7685 Elf_Internal_Rela *rela, *rp;
7686 Elf_Internal_Shdr *symsec;
7687 Elf_Internal_Sym *symtab;
7688 Elf_Internal_Sym *sym;
7690 if (relsec->sh_type != SHT_RELA
7691 || SECTION_HEADER_INDEX (relsec->sh_info) >= elf_header.e_shnum
7692 || SECTION_HEADER (relsec->sh_info) != section
7693 || relsec->sh_size == 0
7694 || SECTION_HEADER_INDEX (relsec->sh_link) >= elf_header.e_shnum)
7697 if (!slurp_rela_relocs (file, relsec->sh_offset, relsec->sh_size,
7701 symsec = SECTION_HEADER (relsec->sh_link);
7702 symtab = GET_ELF_SYMBOLS (file, symsec);
7704 for (rp = rela; rp < rela + nrelas; ++rp)
7708 loc = start + rp->r_offset;
7709 if ((loc + reloc_size) > end)
7711 warn (_("skipping invalid relocation offset 0x%lx in section %s\n"),
7712 (unsigned long) rp->r_offset,
7713 SECTION_NAME (section));
7719 sym = symtab + ELF32_R_SYM (rp->r_info);
7721 if (ELF32_R_SYM (rp->r_info) != 0
7722 && ELF32_ST_TYPE (sym->st_info) != STT_SECTION
7723 /* Relocations against object symbols can happen,
7724 eg when referencing a global array. For an
7725 example of this see the _clz.o binary in libgcc.a. */
7726 && ELF32_ST_TYPE (sym->st_info) != STT_OBJECT)
7728 warn (_("skipping unexpected symbol type %s in relocation in section .rela%s\n"),
7729 get_symbol_type (ELF32_ST_TYPE (sym->st_info)),
7730 SECTION_NAME (section));
7736 /* In MIPS little-endian objects, r_info isn't really a
7737 64-bit little-endian value: it has a 32-bit little-endian
7738 symbol index followed by four individual byte fields.
7739 Reorder INFO accordingly. */
7740 if (elf_header.e_machine == EM_MIPS
7741 && elf_header.e_ident[EI_DATA] != ELFDATA2MSB)
7742 rp->r_info = (((rp->r_info & 0xffffffff) << 32)
7743 | ((rp->r_info >> 56) & 0xff)
7744 | ((rp->r_info >> 40) & 0xff00)
7745 | ((rp->r_info >> 24) & 0xff0000)
7746 | ((rp->r_info >> 8) & 0xff000000));
7748 sym = symtab + ELF64_R_SYM (rp->r_info);
7750 if (ELF64_R_SYM (rp->r_info) != 0
7751 && ELF64_ST_TYPE (sym->st_info) != STT_SECTION
7752 && ELF64_ST_TYPE (sym->st_info) != STT_OBJECT)
7754 warn (_("skipping unexpected symbol type %s in relocation in section .rela.%s\n"),
7755 get_symbol_type (ELF64_ST_TYPE (sym->st_info)),
7756 SECTION_NAME (section));
7761 byte_put (loc, rp->r_addend, reloc_size);
7772 load_debug_section (enum dwarf_section_display_enum debug, void *file)
7774 struct dwarf_section *section = &debug_displays [debug].section;
7775 Elf_Internal_Shdr *sec;
7778 /* If it is already loaded, do nothing. */
7779 if (section->start != NULL)
7782 /* Locate the debug section. */
7783 sec = find_section (section->name);
7787 snprintf (buf, sizeof (buf), _("%s section data"), section->name);
7788 section->address = sec->sh_addr;
7789 section->size = sec->sh_size;
7790 section->start = get_data (NULL, file, sec->sh_offset, 1,
7793 if (debug_displays [debug].relocate)
7794 debug_apply_rela_addends (file, sec, section->start);
7796 return section->start != NULL;
7800 free_debug_section (enum dwarf_section_display_enum debug)
7802 struct dwarf_section *section = &debug_displays [debug].section;
7804 if (section->start == NULL)
7807 free ((char *) section->start);
7808 section->start = NULL;
7809 section->address = 0;
7814 display_debug_section (Elf_Internal_Shdr *section, FILE *file)
7816 char *name = SECTION_NAME (section);
7817 bfd_size_type length;
7819 enum dwarf_section_display_enum i;
7821 length = section->sh_size;
7824 printf (_("\nSection '%s' has no debugging data.\n"), name);
7828 if (const_strneq (name, ".gnu.linkonce.wi."))
7829 name = ".debug_info";
7831 /* See if we know how to display the contents of this section. */
7832 for (i = 0; i < max; i++)
7833 if (streq (debug_displays[i].section.name, name))
7835 struct dwarf_section *sec = &debug_displays [i].section;
7837 if (load_debug_section (i, file))
7839 result &= debug_displays[i].display (sec, file);
7841 if (i != info && i != abbrev)
7842 free_debug_section (i);
7850 printf (_("Unrecognized debug section: %s\n"), name);
7857 /* Set DUMP_SECTS for all sections where dumps were requested
7858 based on section name. */
7861 initialise_dumps_byname (void)
7863 struct dump_list_entry *cur;
7865 for (cur = dump_sects_byname; cur; cur = cur->next)
7870 for (i = 0, any = 0; i < elf_header.e_shnum; i++)
7871 if (streq (SECTION_NAME (section_headers + i), cur->name))
7873 request_dump (i, cur->type);
7878 warn (_("Section '%s' was not dumped because it does not exist!\n"),
7884 process_section_contents (FILE *file)
7886 Elf_Internal_Shdr *section;
7892 initialise_dumps_byname ();
7894 for (i = 0, section = section_headers;
7895 i < elf_header.e_shnum && i < num_dump_sects;
7898 #ifdef SUPPORT_DISASSEMBLY
7899 if (dump_sects[i] & DISASS_DUMP)
7900 disassemble_section (section, file);
7902 if (dump_sects[i] & HEX_DUMP)
7903 dump_section (section, file);
7905 if (dump_sects[i] & DEBUG_DUMP)
7906 display_debug_section (section, file);
7909 /* Check to see if the user requested a
7910 dump of a section that does not exist. */
7911 while (i++ < num_dump_sects)
7913 warn (_("Section %d was not dumped because it does not exist!\n"), i);
7917 process_mips_fpe_exception (int mask)
7922 if (mask & OEX_FPU_INEX)
7923 fputs ("INEX", stdout), first = 0;
7924 if (mask & OEX_FPU_UFLO)
7925 printf ("%sUFLO", first ? "" : "|"), first = 0;
7926 if (mask & OEX_FPU_OFLO)
7927 printf ("%sOFLO", first ? "" : "|"), first = 0;
7928 if (mask & OEX_FPU_DIV0)
7929 printf ("%sDIV0", first ? "" : "|"), first = 0;
7930 if (mask & OEX_FPU_INVAL)
7931 printf ("%sINVAL", first ? "" : "|");
7934 fputs ("0", stdout);
7937 /* ARM EABI attributes section. */
7942 /* 0 = special, 1 = string, 2 = uleb123, > 0x80 == table lookup. */
7945 } arm_attr_public_tag;
7947 static const char *arm_attr_tag_CPU_arch[] =
7948 {"Pre-v4", "v4", "v4T", "v5T", "v5TE", "v5TEJ", "v6", "v6KZ", "v6T2",
7950 static const char *arm_attr_tag_ARM_ISA_use[] = {"No", "Yes"};
7951 static const char *arm_attr_tag_THUMB_ISA_use[] =
7952 {"No", "Thumb-1", "Thumb-2"};
7953 /* FIXME: VFPv3 encoding was extrapolated! */
7954 static const char *arm_attr_tag_VFP_arch[] = {"No", "VFPv1", "VFPv2", "VFPv3"};
7955 static const char *arm_attr_tag_WMMX_arch[] = {"No", "WMMXv1"};
7956 static const char *arm_attr_tag_NEON_arch[] = {"No", "NEONv1"};
7957 static const char *arm_attr_tag_ABI_PCS_config[] =
7958 {"None", "Bare platform", "Linux application", "Linux DSO", "PalmOS 2004",
7959 "PalmOS (reserved)", "SymbianOS 2004", "SymbianOS (reserved)"};
7960 static const char *arm_attr_tag_ABI_PCS_R9_use[] =
7961 {"V6", "SB", "TLS", "Unused"};
7962 static const char *arm_attr_tag_ABI_PCS_RW_data[] =
7963 {"Absolute", "PC-relative", "SB-relative", "None"};
7964 static const char *arm_attr_tag_ABI_PCS_RO_DATA[] =
7965 {"Absolute", "PC-relative", "None"};
7966 static const char *arm_attr_tag_ABI_PCS_GOT_use[] =
7967 {"None", "direct", "GOT-indirect"};
7968 static const char *arm_attr_tag_ABI_PCS_wchar_t[] =
7969 {"None", "??? 1", "2", "??? 3", "4"};
7970 static const char *arm_attr_tag_ABI_FP_rounding[] = {"Unused", "Needed"};
7971 static const char *arm_attr_tag_ABI_FP_denormal[] = {"Unused", "Needed"};
7972 static const char *arm_attr_tag_ABI_FP_exceptions[] = {"Unused", "Needed"};
7973 static const char *arm_attr_tag_ABI_FP_user_exceptions[] = {"Unused", "Needed"};
7974 static const char *arm_attr_tag_ABI_FP_number_model[] =
7975 {"Unused", "Finite", "RTABI", "IEEE 754"};
7976 static const char *arm_attr_tag_ABI_align8_needed[] = {"No", "Yes", "4-byte"};
7977 static const char *arm_attr_tag_ABI_align8_preserved[] =
7978 {"No", "Yes, except leaf SP", "Yes"};
7979 static const char *arm_attr_tag_ABI_enum_size[] =
7980 {"Unused", "small", "int", "forced to int"};
7981 static const char *arm_attr_tag_ABI_HardFP_use[] =
7982 {"As Tag_VFP_arch", "SP only", "DP only", "SP and DP"};
7983 static const char *arm_attr_tag_ABI_VFP_args[] =
7984 {"AAPCS", "VFP registers", "custom"};
7985 static const char *arm_attr_tag_ABI_WMMX_args[] =
7986 {"AAPCS", "WMMX registers", "custom"};
7987 static const char *arm_attr_tag_ABI_optimization_goals[] =
7988 {"None", "Prefer Speed", "Aggressive Speed", "Prefer Size",
7989 "Aggressive Size", "Prefer Debug", "Aggressive Debug"};
7990 static const char *arm_attr_tag_ABI_FP_optimization_goals[] =
7991 {"None", "Prefer Speed", "Aggressive Speed", "Prefer Size",
7992 "Aggressive Size", "Prefer Accuracy", "Aggressive Accuracy"};
7994 #define LOOKUP(id, name) \
7995 {id, #name, 0x80 | ARRAY_SIZE(arm_attr_tag_##name), arm_attr_tag_##name}
7996 static arm_attr_public_tag arm_attr_public_tags[] =
7998 {4, "CPU_raw_name", 1, NULL},
7999 {5, "CPU_name", 1, NULL},
8000 LOOKUP(6, CPU_arch),
8001 {7, "CPU_arch_profile", 0, NULL},
8002 LOOKUP(8, ARM_ISA_use),
8003 LOOKUP(9, THUMB_ISA_use),
8004 LOOKUP(10, VFP_arch),
8005 LOOKUP(11, WMMX_arch),
8006 LOOKUP(12, NEON_arch),
8007 LOOKUP(13, ABI_PCS_config),
8008 LOOKUP(14, ABI_PCS_R9_use),
8009 LOOKUP(15, ABI_PCS_RW_data),
8010 LOOKUP(16, ABI_PCS_RO_DATA),
8011 LOOKUP(17, ABI_PCS_GOT_use),
8012 LOOKUP(18, ABI_PCS_wchar_t),
8013 LOOKUP(19, ABI_FP_rounding),
8014 LOOKUP(20, ABI_FP_denormal),
8015 LOOKUP(21, ABI_FP_exceptions),
8016 LOOKUP(22, ABI_FP_user_exceptions),
8017 LOOKUP(23, ABI_FP_number_model),
8018 LOOKUP(24, ABI_align8_needed),
8019 LOOKUP(25, ABI_align8_preserved),
8020 LOOKUP(26, ABI_enum_size),
8021 LOOKUP(27, ABI_HardFP_use),
8022 LOOKUP(28, ABI_VFP_args),
8023 LOOKUP(29, ABI_WMMX_args),
8024 LOOKUP(30, ABI_optimization_goals),
8025 LOOKUP(31, ABI_FP_optimization_goals),
8026 {32, "compatibility", 0, NULL}
8030 /* Read an unsigned LEB128 encoded value from p. Set *PLEN to the number of
8033 read_uleb128 (unsigned char *p, unsigned int *plen)
8047 val |= ((unsigned int)c & 0x7f) << shift;
8056 static unsigned char *
8057 display_arm_attribute (unsigned char *p)
8062 arm_attr_public_tag *attr;
8066 tag = read_uleb128 (p, &len);
8069 for (i = 0; i < ARRAY_SIZE(arm_attr_public_tags); i++)
8071 if (arm_attr_public_tags[i].tag == tag)
8073 attr = &arm_attr_public_tags[i];
8080 printf (" Tag_%s: ", attr->name);
8086 case 7: /* Tag_CPU_arch_profile. */
8087 val = read_uleb128 (p, &len);
8091 case 0: printf ("None\n"); break;
8092 case 'A': printf ("Application\n"); break;
8093 case 'R': printf ("Realtime\n"); break;
8094 case 'M': printf ("Microcontroller\n"); break;
8095 default: printf ("??? (%d)\n", val); break;
8099 case 32: /* Tag_compatibility. */
8100 val = read_uleb128 (p, &len);
8102 printf ("flag = %d, vendor = %s\n", val, p);
8103 p += strlen((char *)p) + 1;
8117 assert (attr->type & 0x80);
8118 val = read_uleb128 (p, &len);
8120 type = attr->type & 0x7f;
8122 printf ("??? (%d)\n", val);
8124 printf ("%s\n", attr->table[val]);
8131 type = 1; /* String. */
8133 type = 2; /* uleb128. */
8134 printf (" Tag_unknown_%d: ", tag);
8139 printf ("\"%s\"\n", p);
8140 p += strlen((char *)p) + 1;
8144 val = read_uleb128 (p, &len);
8146 printf ("%d (0x%x)\n", val, val);
8153 process_arm_specific (FILE *file)
8155 Elf_Internal_Shdr *sect;
8156 unsigned char *contents;
8159 bfd_vma section_len;
8163 /* Find the section header so that we get the size. */
8164 for (i = 0, sect = section_headers;
8165 i < elf_header.e_shnum;
8168 if (sect->sh_type != SHT_ARM_ATTRIBUTES)
8171 contents = get_data (NULL, file, sect->sh_offset, 1, sect->sh_size,
8179 len = sect->sh_size - 1;
8184 bfd_boolean public_section;
8186 section_len = byte_get (p, 4);
8188 if (section_len > len)
8190 printf (_("ERROR: Bad section length (%d > %d)\n"),
8191 (int)section_len, (int)len);
8195 printf ("Attribute Section: %s\n", p);
8196 if (strcmp ((char *)p, "aeabi") == 0)
8197 public_section = TRUE;
8199 public_section = FALSE;
8200 namelen = strlen ((char *)p) + 1;
8202 section_len -= namelen + 4;
8203 while (section_len > 0)
8208 size = byte_get (p, 4);
8209 if (size > section_len)
8211 printf (_("ERROR: Bad subsection length (%d > %d)\n"),
8212 (int)size, (int)section_len);
8215 section_len -= size;
8221 printf ("File Attributes\n");
8224 printf ("Section Attributes:");
8227 printf ("Symbol Attributes:");
8232 val = read_uleb128 (p, &i);
8236 printf (" %d", val);
8241 printf ("Unknown tag: %d\n", tag);
8242 public_section = FALSE;
8248 p = display_arm_attribute(p);
8252 /* ??? Do something sensible, like dump hex. */
8253 printf (" Unknown section contexts\n");
8261 printf (_("Unknown format '%c'\n"), *p);
8270 process_mips_specific (FILE *file)
8272 Elf_Internal_Dyn *entry;
8273 size_t liblist_offset = 0;
8274 size_t liblistno = 0;
8275 size_t conflictsno = 0;
8276 size_t options_offset = 0;
8277 size_t conflicts_offset = 0;
8279 /* We have a lot of special sections. Thanks SGI! */
8280 if (dynamic_section == NULL)
8281 /* No information available. */
8284 for (entry = dynamic_section; entry->d_tag != DT_NULL; ++entry)
8285 switch (entry->d_tag)
8287 case DT_MIPS_LIBLIST:
8289 = offset_from_vma (file, entry->d_un.d_val,
8290 liblistno * sizeof (Elf32_External_Lib));
8292 case DT_MIPS_LIBLISTNO:
8293 liblistno = entry->d_un.d_val;
8295 case DT_MIPS_OPTIONS:
8296 options_offset = offset_from_vma (file, entry->d_un.d_val, 0);
8298 case DT_MIPS_CONFLICT:
8300 = offset_from_vma (file, entry->d_un.d_val,
8301 conflictsno * sizeof (Elf32_External_Conflict));
8303 case DT_MIPS_CONFLICTNO:
8304 conflictsno = entry->d_un.d_val;
8310 if (liblist_offset != 0 && liblistno != 0 && do_dynamic)
8312 Elf32_External_Lib *elib;
8315 elib = get_data (NULL, file, liblist_offset,
8316 liblistno, sizeof (Elf32_External_Lib),
8320 printf ("\nSection '.liblist' contains %lu entries:\n",
8321 (unsigned long) liblistno);
8322 fputs (" Library Time Stamp Checksum Version Flags\n",
8325 for (cnt = 0; cnt < liblistno; ++cnt)
8332 liblist.l_name = BYTE_GET (elib[cnt].l_name);
8333 time = BYTE_GET (elib[cnt].l_time_stamp);
8334 liblist.l_checksum = BYTE_GET (elib[cnt].l_checksum);
8335 liblist.l_version = BYTE_GET (elib[cnt].l_version);
8336 liblist.l_flags = BYTE_GET (elib[cnt].l_flags);
8338 tmp = gmtime (&time);
8339 snprintf (timebuf, sizeof (timebuf),
8340 "%04u-%02u-%02uT%02u:%02u:%02u",
8341 tmp->tm_year + 1900, tmp->tm_mon + 1, tmp->tm_mday,
8342 tmp->tm_hour, tmp->tm_min, tmp->tm_sec);
8344 printf ("%3lu: ", (unsigned long) cnt);
8345 if (VALID_DYNAMIC_NAME (liblist.l_name))
8346 print_symbol (20, GET_DYNAMIC_NAME (liblist.l_name));
8348 printf ("<corrupt: %9ld>", liblist.l_name);
8349 printf (" %s %#10lx %-7ld", timebuf, liblist.l_checksum,
8352 if (liblist.l_flags == 0)
8363 { " EXACT_MATCH", LL_EXACT_MATCH },
8364 { " IGNORE_INT_VER", LL_IGNORE_INT_VER },
8365 { " REQUIRE_MINOR", LL_REQUIRE_MINOR },
8366 { " EXPORTS", LL_EXPORTS },
8367 { " DELAY_LOAD", LL_DELAY_LOAD },
8368 { " DELTA", LL_DELTA }
8370 int flags = liblist.l_flags;
8374 fcnt < sizeof (l_flags_vals) / sizeof (l_flags_vals[0]);
8376 if ((flags & l_flags_vals[fcnt].bit) != 0)
8378 fputs (l_flags_vals[fcnt].name, stdout);
8379 flags ^= l_flags_vals[fcnt].bit;
8382 printf (" %#x", (unsigned int) flags);
8392 if (options_offset != 0)
8394 Elf_External_Options *eopt;
8395 Elf_Internal_Shdr *sect = section_headers;
8396 Elf_Internal_Options *iopt;
8397 Elf_Internal_Options *option;
8401 /* Find the section header so that we get the size. */
8402 while (sect->sh_type != SHT_MIPS_OPTIONS)
8405 eopt = get_data (NULL, file, options_offset, 1, sect->sh_size,
8409 iopt = cmalloc ((sect->sh_size / sizeof (eopt)), sizeof (*iopt));
8412 error (_("Out of memory"));
8419 while (offset < sect->sh_size)
8421 Elf_External_Options *eoption;
8423 eoption = (Elf_External_Options *) ((char *) eopt + offset);
8425 option->kind = BYTE_GET (eoption->kind);
8426 option->size = BYTE_GET (eoption->size);
8427 option->section = BYTE_GET (eoption->section);
8428 option->info = BYTE_GET (eoption->info);
8430 offset += option->size;
8436 printf (_("\nSection '%s' contains %d entries:\n"),
8437 SECTION_NAME (sect), cnt);
8445 switch (option->kind)
8448 /* This shouldn't happen. */
8449 printf (" NULL %d %lx", option->section, option->info);
8452 printf (" REGINFO ");
8453 if (elf_header.e_machine == EM_MIPS)
8456 Elf32_External_RegInfo *ereg;
8457 Elf32_RegInfo reginfo;
8459 ereg = (Elf32_External_RegInfo *) (option + 1);
8460 reginfo.ri_gprmask = BYTE_GET (ereg->ri_gprmask);
8461 reginfo.ri_cprmask[0] = BYTE_GET (ereg->ri_cprmask[0]);
8462 reginfo.ri_cprmask[1] = BYTE_GET (ereg->ri_cprmask[1]);
8463 reginfo.ri_cprmask[2] = BYTE_GET (ereg->ri_cprmask[2]);
8464 reginfo.ri_cprmask[3] = BYTE_GET (ereg->ri_cprmask[3]);
8465 reginfo.ri_gp_value = BYTE_GET (ereg->ri_gp_value);
8467 printf ("GPR %08lx GP 0x%lx\n",
8469 (unsigned long) reginfo.ri_gp_value);
8470 printf (" CPR0 %08lx CPR1 %08lx CPR2 %08lx CPR3 %08lx\n",
8471 reginfo.ri_cprmask[0], reginfo.ri_cprmask[1],
8472 reginfo.ri_cprmask[2], reginfo.ri_cprmask[3]);
8477 Elf64_External_RegInfo *ereg;
8478 Elf64_Internal_RegInfo reginfo;
8480 ereg = (Elf64_External_RegInfo *) (option + 1);
8481 reginfo.ri_gprmask = BYTE_GET (ereg->ri_gprmask);
8482 reginfo.ri_cprmask[0] = BYTE_GET (ereg->ri_cprmask[0]);
8483 reginfo.ri_cprmask[1] = BYTE_GET (ereg->ri_cprmask[1]);
8484 reginfo.ri_cprmask[2] = BYTE_GET (ereg->ri_cprmask[2]);
8485 reginfo.ri_cprmask[3] = BYTE_GET (ereg->ri_cprmask[3]);
8486 reginfo.ri_gp_value = BYTE_GET (ereg->ri_gp_value);
8488 printf ("GPR %08lx GP 0x",
8489 reginfo.ri_gprmask);
8490 printf_vma (reginfo.ri_gp_value);
8493 printf (" CPR0 %08lx CPR1 %08lx CPR2 %08lx CPR3 %08lx\n",
8494 reginfo.ri_cprmask[0], reginfo.ri_cprmask[1],
8495 reginfo.ri_cprmask[2], reginfo.ri_cprmask[3]);
8499 case ODK_EXCEPTIONS:
8500 fputs (" EXCEPTIONS fpe_min(", stdout);
8501 process_mips_fpe_exception (option->info & OEX_FPU_MIN);
8502 fputs (") fpe_max(", stdout);
8503 process_mips_fpe_exception ((option->info & OEX_FPU_MAX) >> 8);
8504 fputs (")", stdout);
8506 if (option->info & OEX_PAGE0)
8507 fputs (" PAGE0", stdout);
8508 if (option->info & OEX_SMM)
8509 fputs (" SMM", stdout);
8510 if (option->info & OEX_FPDBUG)
8511 fputs (" FPDBUG", stdout);
8512 if (option->info & OEX_DISMISS)
8513 fputs (" DISMISS", stdout);
8516 fputs (" PAD ", stdout);
8517 if (option->info & OPAD_PREFIX)
8518 fputs (" PREFIX", stdout);
8519 if (option->info & OPAD_POSTFIX)
8520 fputs (" POSTFIX", stdout);
8521 if (option->info & OPAD_SYMBOL)
8522 fputs (" SYMBOL", stdout);
8525 fputs (" HWPATCH ", stdout);
8526 if (option->info & OHW_R4KEOP)
8527 fputs (" R4KEOP", stdout);
8528 if (option->info & OHW_R8KPFETCH)
8529 fputs (" R8KPFETCH", stdout);
8530 if (option->info & OHW_R5KEOP)
8531 fputs (" R5KEOP", stdout);
8532 if (option->info & OHW_R5KCVTL)
8533 fputs (" R5KCVTL", stdout);
8536 fputs (" FILL ", stdout);
8537 /* XXX Print content of info word? */
8540 fputs (" TAGS ", stdout);
8541 /* XXX Print content of info word? */
8544 fputs (" HWAND ", stdout);
8545 if (option->info & OHWA0_R4KEOP_CHECKED)
8546 fputs (" R4KEOP_CHECKED", stdout);
8547 if (option->info & OHWA0_R4KEOP_CLEAN)
8548 fputs (" R4KEOP_CLEAN", stdout);
8551 fputs (" HWOR ", stdout);
8552 if (option->info & OHWA0_R4KEOP_CHECKED)
8553 fputs (" R4KEOP_CHECKED", stdout);
8554 if (option->info & OHWA0_R4KEOP_CLEAN)
8555 fputs (" R4KEOP_CLEAN", stdout);
8558 printf (" GP_GROUP %#06lx self-contained %#06lx",
8559 option->info & OGP_GROUP,
8560 (option->info & OGP_SELF) >> 16);
8563 printf (" IDENT %#06lx self-contained %#06lx",
8564 option->info & OGP_GROUP,
8565 (option->info & OGP_SELF) >> 16);
8568 /* This shouldn't happen. */
8569 printf (" %3d ??? %d %lx",
8570 option->kind, option->section, option->info);
8574 len = sizeof (*eopt);
8575 while (len < option->size)
8576 if (((char *) option)[len] >= ' '
8577 && ((char *) option)[len] < 0x7f)
8578 printf ("%c", ((char *) option)[len++]);
8580 printf ("\\%03o", ((char *) option)[len++]);
8582 fputs ("\n", stdout);
8590 if (conflicts_offset != 0 && conflictsno != 0)
8592 Elf32_Conflict *iconf;
8595 if (dynamic_symbols == NULL)
8597 error (_("conflict list found without a dynamic symbol table"));
8601 iconf = cmalloc (conflictsno, sizeof (*iconf));
8604 error (_("Out of memory"));
8610 Elf32_External_Conflict *econf32;
8612 econf32 = get_data (NULL, file, conflicts_offset,
8613 conflictsno, sizeof (*econf32), _("conflict"));
8617 for (cnt = 0; cnt < conflictsno; ++cnt)
8618 iconf[cnt] = BYTE_GET (econf32[cnt]);
8624 Elf64_External_Conflict *econf64;
8626 econf64 = get_data (NULL, file, conflicts_offset,
8627 conflictsno, sizeof (*econf64), _("conflict"));
8631 for (cnt = 0; cnt < conflictsno; ++cnt)
8632 iconf[cnt] = BYTE_GET (econf64[cnt]);
8637 printf (_("\nSection '.conflict' contains %lu entries:\n"),
8638 (unsigned long) conflictsno);
8639 puts (_(" Num: Index Value Name"));
8641 for (cnt = 0; cnt < conflictsno; ++cnt)
8643 Elf_Internal_Sym *psym = & dynamic_symbols[iconf[cnt]];
8645 printf ("%5lu: %8lu ", (unsigned long) cnt, iconf[cnt]);
8646 print_vma (psym->st_value, FULL_HEX);
8648 if (VALID_DYNAMIC_NAME (psym->st_name))
8649 print_symbol (25, GET_DYNAMIC_NAME (psym->st_name));
8651 printf ("<corrupt: %14ld>", psym->st_name);
8662 process_gnu_liblist (FILE *file)
8664 Elf_Internal_Shdr *section, *string_sec;
8665 Elf32_External_Lib *elib;
8674 for (i = 0, section = section_headers;
8675 i < elf_header.e_shnum;
8678 switch (section->sh_type)
8680 case SHT_GNU_LIBLIST:
8681 if (SECTION_HEADER_INDEX (section->sh_link) >= elf_header.e_shnum)
8684 elib = get_data (NULL, file, section->sh_offset, 1, section->sh_size,
8689 string_sec = SECTION_HEADER (section->sh_link);
8691 strtab = get_data (NULL, file, string_sec->sh_offset, 1,
8692 string_sec->sh_size, _("liblist string table"));
8693 strtab_size = string_sec->sh_size;
8696 || section->sh_entsize != sizeof (Elf32_External_Lib))
8702 printf (_("\nLibrary list section '%s' contains %lu entries:\n"),
8703 SECTION_NAME (section),
8704 (long) (section->sh_size / sizeof (Elf32_External_Lib)));
8706 puts (" Library Time Stamp Checksum Version Flags");
8708 for (cnt = 0; cnt < section->sh_size / sizeof (Elf32_External_Lib);
8716 liblist.l_name = BYTE_GET (elib[cnt].l_name);
8717 time = BYTE_GET (elib[cnt].l_time_stamp);
8718 liblist.l_checksum = BYTE_GET (elib[cnt].l_checksum);
8719 liblist.l_version = BYTE_GET (elib[cnt].l_version);
8720 liblist.l_flags = BYTE_GET (elib[cnt].l_flags);
8722 tmp = gmtime (&time);
8723 snprintf (timebuf, sizeof (timebuf),
8724 "%04u-%02u-%02uT%02u:%02u:%02u",
8725 tmp->tm_year + 1900, tmp->tm_mon + 1, tmp->tm_mday,
8726 tmp->tm_hour, tmp->tm_min, tmp->tm_sec);
8728 printf ("%3lu: ", (unsigned long) cnt);
8730 printf ("%-20s", liblist.l_name < strtab_size
8731 ? strtab + liblist.l_name : "<corrupt>");
8733 printf ("%-20.20s", liblist.l_name < strtab_size
8734 ? strtab + liblist.l_name : "<corrupt>");
8735 printf (" %s %#010lx %-7ld %-7ld\n", timebuf, liblist.l_checksum,
8736 liblist.l_version, liblist.l_flags);
8747 get_note_type (unsigned e_type)
8749 static char buff[64];
8751 if (elf_header.e_type == ET_CORE)
8755 return _("NT_AUXV (auxiliary vector)");
8757 return _("NT_PRSTATUS (prstatus structure)");
8759 return _("NT_FPREGSET (floating point registers)");
8761 return _("NT_PRPSINFO (prpsinfo structure)");
8763 return _("NT_TASKSTRUCT (task structure)");
8765 return _("NT_PRXFPREG (user_xfpregs structure)");
8767 return _("NT_PSTATUS (pstatus structure)");
8769 return _("NT_FPREGS (floating point registers)");
8771 return _("NT_PSINFO (psinfo structure)");
8773 return _("NT_LWPSTATUS (lwpstatus_t structure)");
8775 return _("NT_LWPSINFO (lwpsinfo_t structure)");
8776 case NT_WIN32PSTATUS:
8777 return _("NT_WIN32PSTATUS (win32_pstatus structure)");
8785 return _("NT_VERSION (version)");
8787 return _("NT_ARCH (architecture)");
8792 snprintf (buff, sizeof (buff), _("Unknown note type: (0x%08x)"), e_type);
8797 get_netbsd_elfcore_note_type (unsigned e_type)
8799 static char buff[64];
8801 if (e_type == NT_NETBSDCORE_PROCINFO)
8803 /* NetBSD core "procinfo" structure. */
8804 return _("NetBSD procinfo structure");
8807 /* As of Jan 2002 there are no other machine-independent notes
8808 defined for NetBSD core files. If the note type is less
8809 than the start of the machine-dependent note types, we don't
8812 if (e_type < NT_NETBSDCORE_FIRSTMACH)
8814 snprintf (buff, sizeof (buff), _("Unknown note type: (0x%08x)"), e_type);
8818 switch (elf_header.e_machine)
8820 /* On the Alpha, SPARC (32-bit and 64-bit), PT_GETREGS == mach+0
8821 and PT_GETFPREGS == mach+2. */
8826 case EM_SPARC32PLUS:
8830 case NT_NETBSDCORE_FIRSTMACH+0:
8831 return _("PT_GETREGS (reg structure)");
8832 case NT_NETBSDCORE_FIRSTMACH+2:
8833 return _("PT_GETFPREGS (fpreg structure)");
8839 /* On all other arch's, PT_GETREGS == mach+1 and
8840 PT_GETFPREGS == mach+3. */
8844 case NT_NETBSDCORE_FIRSTMACH+1:
8845 return _("PT_GETREGS (reg structure)");
8846 case NT_NETBSDCORE_FIRSTMACH+3:
8847 return _("PT_GETFPREGS (fpreg structure)");
8853 snprintf (buff, sizeof (buff), _("PT_FIRSTMACH+%d"),
8854 e_type - NT_NETBSDCORE_FIRSTMACH);
8858 /* Note that by the ELF standard, the name field is already null byte
8859 terminated, and namesz includes the terminating null byte.
8860 I.E. the value of namesz for the name "FSF" is 4.
8862 If the value of namesz is zero, there is no name present. */
8864 process_note (Elf_Internal_Note *pnote)
8868 if (pnote->namesz == 0)
8869 /* If there is no note name, then use the default set of
8870 note type strings. */
8871 nt = get_note_type (pnote->type);
8873 else if (const_strneq (pnote->namedata, "NetBSD-CORE"))
8874 /* NetBSD-specific core file notes. */
8875 nt = get_netbsd_elfcore_note_type (pnote->type);
8878 /* Don't recognize this note name; just use the default set of
8879 note type strings. */
8880 nt = get_note_type (pnote->type);
8882 printf (" %s\t\t0x%08lx\t%s\n",
8883 pnote->namesz ? pnote->namedata : "(NONE)",
8890 process_corefile_note_segment (FILE *file, bfd_vma offset, bfd_vma length)
8892 Elf_External_Note *pnotes;
8893 Elf_External_Note *external;
8899 pnotes = get_data (NULL, file, offset, 1, length, _("notes"));
8905 printf (_("\nNotes at offset 0x%08lx with length 0x%08lx:\n"),
8906 (unsigned long) offset, (unsigned long) length);
8907 printf (_(" Owner\t\tData size\tDescription\n"));
8909 while (external < (Elf_External_Note *)((char *) pnotes + length))
8911 Elf_External_Note *next;
8912 Elf_Internal_Note inote;
8915 inote.type = BYTE_GET (external->type);
8916 inote.namesz = BYTE_GET (external->namesz);
8917 inote.namedata = external->name;
8918 inote.descsz = BYTE_GET (external->descsz);
8919 inote.descdata = inote.namedata + align_power (inote.namesz, 2);
8920 inote.descpos = offset + (inote.descdata - (char *) pnotes);
8922 next = (Elf_External_Note *)(inote.descdata + align_power (inote.descsz, 2));
8924 if (((char *) next) > (((char *) pnotes) + length))
8926 warn (_("corrupt note found at offset %lx into core notes\n"),
8927 (long)((char *)external - (char *)pnotes));
8928 warn (_(" type: %lx, namesize: %08lx, descsize: %08lx\n"),
8929 inote.type, inote.namesz, inote.descsz);
8935 /* Verify that name is null terminated. It appears that at least
8936 one version of Linux (RedHat 6.0) generates corefiles that don't
8937 comply with the ELF spec by failing to include the null byte in
8939 if (inote.namedata[inote.namesz] != '\0')
8941 temp = malloc (inote.namesz + 1);
8945 error (_("Out of memory\n"));
8950 strncpy (temp, inote.namedata, inote.namesz);
8951 temp[inote.namesz] = 0;
8953 /* warn (_("'%s' NOTE name not properly null terminated\n"), temp); */
8954 inote.namedata = temp;
8957 res &= process_note (& inote);
8972 process_corefile_note_segments (FILE *file)
8974 Elf_Internal_Phdr *segment;
8978 if (! get_program_headers (file))
8981 for (i = 0, segment = program_headers;
8982 i < elf_header.e_phnum;
8985 if (segment->p_type == PT_NOTE)
8986 res &= process_corefile_note_segment (file,
8987 (bfd_vma) segment->p_offset,
8988 (bfd_vma) segment->p_filesz);
8995 process_note_sections (FILE *file)
8997 Elf_Internal_Shdr *section;
9001 for (i = 0, section = section_headers;
9002 i < elf_header.e_shnum;
9004 if (section->sh_type == SHT_NOTE)
9005 res &= process_corefile_note_segment (file,
9006 (bfd_vma) section->sh_offset,
9007 (bfd_vma) section->sh_size);
9013 process_notes (FILE *file)
9015 /* If we have not been asked to display the notes then do nothing. */
9019 if (elf_header.e_type != ET_CORE)
9020 return process_note_sections (file);
9022 /* No program headers means no NOTE segment. */
9023 if (elf_header.e_phnum > 0)
9024 return process_corefile_note_segments (file);
9026 printf (_("No note segments present in the core file.\n"));
9031 process_arch_specific (FILE *file)
9036 switch (elf_header.e_machine)
9039 return process_arm_specific (file);
9041 case EM_MIPS_RS3_LE:
9042 return process_mips_specific (file);
9051 get_file_header (FILE *file)
9053 /* Read in the identity array. */
9054 if (fread (elf_header.e_ident, EI_NIDENT, 1, file) != 1)
9057 /* Determine how to read the rest of the header. */
9058 switch (elf_header.e_ident[EI_DATA])
9060 default: /* fall through */
9061 case ELFDATANONE: /* fall through */
9063 byte_get = byte_get_little_endian;
9064 byte_put = byte_put_little_endian;
9067 byte_get = byte_get_big_endian;
9068 byte_put = byte_put_big_endian;
9072 /* For now we only support 32 bit and 64 bit ELF files. */
9073 is_32bit_elf = (elf_header.e_ident[EI_CLASS] != ELFCLASS64);
9075 /* Read in the rest of the header. */
9078 Elf32_External_Ehdr ehdr32;
9080 if (fread (ehdr32.e_type, sizeof (ehdr32) - EI_NIDENT, 1, file) != 1)
9083 elf_header.e_type = BYTE_GET (ehdr32.e_type);
9084 elf_header.e_machine = BYTE_GET (ehdr32.e_machine);
9085 elf_header.e_version = BYTE_GET (ehdr32.e_version);
9086 elf_header.e_entry = BYTE_GET (ehdr32.e_entry);
9087 elf_header.e_phoff = BYTE_GET (ehdr32.e_phoff);
9088 elf_header.e_shoff = BYTE_GET (ehdr32.e_shoff);
9089 elf_header.e_flags = BYTE_GET (ehdr32.e_flags);
9090 elf_header.e_ehsize = BYTE_GET (ehdr32.e_ehsize);
9091 elf_header.e_phentsize = BYTE_GET (ehdr32.e_phentsize);
9092 elf_header.e_phnum = BYTE_GET (ehdr32.e_phnum);
9093 elf_header.e_shentsize = BYTE_GET (ehdr32.e_shentsize);
9094 elf_header.e_shnum = BYTE_GET (ehdr32.e_shnum);
9095 elf_header.e_shstrndx = BYTE_GET (ehdr32.e_shstrndx);
9099 Elf64_External_Ehdr ehdr64;
9101 /* If we have been compiled with sizeof (bfd_vma) == 4, then
9102 we will not be able to cope with the 64bit data found in
9103 64 ELF files. Detect this now and abort before we start
9104 overwriting things. */
9105 if (sizeof (bfd_vma) < 8)
9107 error (_("This instance of readelf has been built without support for a\n\
9108 64 bit data type and so it cannot read 64 bit ELF files.\n"));
9112 if (fread (ehdr64.e_type, sizeof (ehdr64) - EI_NIDENT, 1, file) != 1)
9115 elf_header.e_type = BYTE_GET (ehdr64.e_type);
9116 elf_header.e_machine = BYTE_GET (ehdr64.e_machine);
9117 elf_header.e_version = BYTE_GET (ehdr64.e_version);
9118 elf_header.e_entry = BYTE_GET (ehdr64.e_entry);
9119 elf_header.e_phoff = BYTE_GET (ehdr64.e_phoff);
9120 elf_header.e_shoff = BYTE_GET (ehdr64.e_shoff);
9121 elf_header.e_flags = BYTE_GET (ehdr64.e_flags);
9122 elf_header.e_ehsize = BYTE_GET (ehdr64.e_ehsize);
9123 elf_header.e_phentsize = BYTE_GET (ehdr64.e_phentsize);
9124 elf_header.e_phnum = BYTE_GET (ehdr64.e_phnum);
9125 elf_header.e_shentsize = BYTE_GET (ehdr64.e_shentsize);
9126 elf_header.e_shnum = BYTE_GET (ehdr64.e_shnum);
9127 elf_header.e_shstrndx = BYTE_GET (ehdr64.e_shstrndx);
9130 if (elf_header.e_shoff)
9132 /* There may be some extensions in the first section header. Don't
9133 bomb if we can't read it. */
9135 get_32bit_section_headers (file, 1);
9137 get_64bit_section_headers (file, 1);
9140 is_relocatable = elf_header.e_type == ET_REL;
9145 /* Process one ELF object file according to the command line options.
9146 This file may actually be stored in an archive. The file is
9147 positioned at the start of the ELF object. */
9150 process_object (char *file_name, FILE *file)
9154 if (! get_file_header (file))
9156 error (_("%s: Failed to read file header\n"), file_name);
9160 /* Initialise per file variables. */
9161 for (i = NUM_ELEM (version_info); i--;)
9162 version_info[i] = 0;
9164 for (i = NUM_ELEM (dynamic_info); i--;)
9165 dynamic_info[i] = 0;
9167 /* Process the file. */
9169 printf (_("\nFile: %s\n"), file_name);
9171 /* Initialise the dump_sects array from the cmdline_dump_sects array.
9172 Note we do this even if cmdline_dump_sects is empty because we
9173 must make sure that the dump_sets array is zeroed out before each
9174 object file is processed. */
9175 if (num_dump_sects > num_cmdline_dump_sects)
9176 memset (dump_sects, 0, num_dump_sects);
9178 if (num_cmdline_dump_sects > 0)
9180 if (num_dump_sects == 0)
9181 /* A sneaky way of allocating the dump_sects array. */
9182 request_dump (num_cmdline_dump_sects, 0);
9184 assert (num_dump_sects >= num_cmdline_dump_sects);
9185 memcpy (dump_sects, cmdline_dump_sects, num_cmdline_dump_sects);
9188 if (! process_file_header ())
9191 if (! process_section_headers (file))
9193 /* Without loaded section headers we cannot process lots of
9195 do_unwind = do_version = do_dump = do_arch = 0;
9197 if (! do_using_dynamic)
9198 do_syms = do_reloc = 0;
9201 if (! process_section_groups (file))
9203 /* Without loaded section groups we cannot process unwind. */
9207 if (process_program_headers (file))
9208 process_dynamic_section (file);
9210 process_relocs (file);
9212 process_unwind (file);
9214 process_symbol_table (file);
9216 process_syminfo (file);
9218 process_version_sections (file);
9220 process_section_contents (file);
9222 process_notes (file);
9224 process_gnu_liblist (file);
9226 process_arch_specific (file);
9228 if (program_headers)
9230 free (program_headers);
9231 program_headers = NULL;
9234 if (section_headers)
9236 free (section_headers);
9237 section_headers = NULL;
9242 free (string_table);
9243 string_table = NULL;
9244 string_table_length = 0;
9247 if (dynamic_strings)
9249 free (dynamic_strings);
9250 dynamic_strings = NULL;
9251 dynamic_strings_length = 0;
9254 if (dynamic_symbols)
9256 free (dynamic_symbols);
9257 dynamic_symbols = NULL;
9258 num_dynamic_syms = 0;
9261 if (dynamic_syminfo)
9263 free (dynamic_syminfo);
9264 dynamic_syminfo = NULL;
9267 if (section_headers_groups)
9269 free (section_headers_groups);
9270 section_headers_groups = NULL;
9275 struct group_list *g, *next;
9277 for (i = 0; i < group_count; i++)
9279 for (g = section_groups [i].root; g != NULL; g = next)
9286 free (section_groups);
9287 section_groups = NULL;
9290 free_debug_memory ();
9295 /* Process an ELF archive. The file is positioned just after the
9299 process_archive (char *file_name, FILE *file)
9301 struct ar_hdr arhdr;
9304 char *longnames = NULL;
9305 unsigned long longnames_size = 0;
9306 size_t file_name_size;
9311 got = fread (&arhdr, 1, sizeof arhdr, file);
9312 if (got != sizeof arhdr)
9317 error (_("%s: failed to read archive header\n"), file_name);
9321 if (const_strneq (arhdr.ar_name, "/ "))
9323 /* This is the archive symbol table. Skip it.
9324 FIXME: We should have an option to dump it. */
9325 size = strtoul (arhdr.ar_size, NULL, 10);
9326 if (fseek (file, size + (size & 1), SEEK_CUR) != 0)
9328 error (_("%s: failed to skip archive symbol table\n"), file_name);
9332 got = fread (&arhdr, 1, sizeof arhdr, file);
9333 if (got != sizeof arhdr)
9338 error (_("%s: failed to read archive header\n"), file_name);
9343 if (const_strneq (arhdr.ar_name, "// "))
9345 /* This is the archive string table holding long member
9348 longnames_size = strtoul (arhdr.ar_size, NULL, 10);
9350 longnames = malloc (longnames_size);
9351 if (longnames == NULL)
9353 error (_("Out of memory\n"));
9357 if (fread (longnames, longnames_size, 1, file) != 1)
9360 error (_("%s: failed to read string table\n"), file_name);
9364 if ((longnames_size & 1) != 0)
9367 got = fread (&arhdr, 1, sizeof arhdr, file);
9368 if (got != sizeof arhdr)
9375 error (_("%s: failed to read archive header\n"), file_name);
9380 file_name_size = strlen (file_name);
9389 if (arhdr.ar_name[0] == '/')
9393 off = strtoul (arhdr.ar_name + 1, NULL, 10);
9394 if (off >= longnames_size)
9396 error (_("%s: invalid archive string table offset %lu\n"), file_name, off);
9401 name = longnames + off;
9402 nameend = memchr (name, '/', longnames_size - off);
9406 name = arhdr.ar_name;
9407 nameend = memchr (name, '/', 16);
9410 if (nameend == NULL)
9412 error (_("%s: bad archive file name\n"), file_name);
9417 namealc = malloc (file_name_size + (nameend - name) + 3);
9418 if (namealc == NULL)
9420 error (_("Out of memory\n"));
9425 memcpy (namealc, file_name, file_name_size);
9426 namealc[file_name_size] = '(';
9427 memcpy (namealc + file_name_size + 1, name, nameend - name);
9428 namealc[file_name_size + 1 + (nameend - name)] = ')';
9429 namealc[file_name_size + 2 + (nameend - name)] = '\0';
9431 archive_file_offset = ftell (file);
9432 archive_file_size = strtoul (arhdr.ar_size, NULL, 10);
9434 ret |= process_object (namealc, file);
9439 (archive_file_offset
9441 + (archive_file_size & 1)),
9444 error (_("%s: failed to seek to next archive header\n"), file_name);
9449 got = fread (&arhdr, 1, sizeof arhdr, file);
9450 if (got != sizeof arhdr)
9455 error (_("%s: failed to read archive header\n"), file_name);
9468 process_file (char *file_name)
9471 struct stat statbuf;
9475 if (stat (file_name, &statbuf) < 0)
9477 if (errno == ENOENT)
9478 error (_("'%s': No such file\n"), file_name);
9480 error (_("Could not locate '%s'. System error message: %s\n"),
9481 file_name, strerror (errno));
9485 if (! S_ISREG (statbuf.st_mode))
9487 error (_("'%s' is not an ordinary file\n"), file_name);
9491 file = fopen (file_name, "rb");
9494 error (_("Input file '%s' is not readable.\n"), file_name);
9498 if (fread (armag, SARMAG, 1, file) != 1)
9500 error (_("%s: Failed to read file header\n"), file_name);
9505 if (memcmp (armag, ARMAG, SARMAG) == 0)
9506 ret = process_archive (file_name, file);
9510 archive_file_size = archive_file_offset = 0;
9511 ret = process_object (file_name, file);
9519 #ifdef SUPPORT_DISASSEMBLY
9520 /* Needed by the i386 disassembler. For extra credit, someone could
9521 fix this so that we insert symbolic addresses here, esp for GOT/PLT
9525 print_address (unsigned int addr, FILE *outfile)
9527 fprintf (outfile,"0x%8.8x", addr);
9530 /* Needed by the i386 disassembler. */
9532 db_task_printsym (unsigned int addr)
9534 print_address (addr, stderr);
9539 main (int argc, char **argv)
9543 #if defined (HAVE_SETLOCALE) && defined (HAVE_LC_MESSAGES)
9544 setlocale (LC_MESSAGES, "");
9546 #if defined (HAVE_SETLOCALE)
9547 setlocale (LC_CTYPE, "");
9549 bindtextdomain (PACKAGE, LOCALEDIR);
9550 textdomain (PACKAGE);
9552 expandargv (&argc, &argv);
9554 parse_args (argc, argv);
9556 if (num_dump_sects > 0)
9558 /* Make a copy of the dump_sects array. */
9559 cmdline_dump_sects = malloc (num_dump_sects);
9560 if (cmdline_dump_sects == NULL)
9561 error (_("Out of memory allocating dump request table."));
9564 memcpy (cmdline_dump_sects, dump_sects, num_dump_sects);
9565 num_cmdline_dump_sects = num_dump_sects;
9569 if (optind < (argc - 1))
9573 while (optind < argc)
9574 err |= process_file (argv[optind++]);
9576 if (dump_sects != NULL)
9578 if (cmdline_dump_sects != NULL)
9579 free (cmdline_dump_sects);