1 /* readelf.c -- display contents of an ELF format file
2 Copyright 1998, 1999, 2000, 2001, 2002, 2003 Free Software Foundation, Inc.
4 Originally developed by Eric Youngdale <eric@andante.jic.com>
5 Modifications by Nick Clifton <nickc@redhat.com>
7 This file is part of GNU Binutils.
9 This program is free software; you can redistribute it and/or modify
10 it under the terms of the GNU General Public License as published by
11 the Free Software Foundation; either version 2 of the License, or
12 (at your option) any later version.
14 This program is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 GNU General Public License for more details.
19 You should have received a copy of the GNU General Public License
20 along with this program; if not, write to the Free Software
21 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
24 /* The difference between readelf and objdump:
26 Both programs are capabale of displaying the contents of ELF format files,
27 so why does the binutils project have two file dumpers ?
29 The reason is that objdump sees an ELF file through a BFD filter of the
30 world; if BFD has a bug where, say, it disagrees about a machine constant
31 in e_flags, then the odds are good that it will remain internally
32 consistent. The linker sees it the BFD way, objdump sees it the BFD way,
33 GAS sees it the BFD way. There was need for a tool to go find out what
34 the file actually says.
36 This is why the readelf program does not link against the BFD library - it
37 exists as an independent program to help verify the correct working of BFD.
39 There is also the case that readelf can provide more information about an
40 ELF file than is provided by objdump. In particular it can display DWARF
41 debugging information which (at the moment) objdump cannot. */
44 #include <sys/types.h>
50 /* Define BFD64 here, even if our default architecture is 32 bit ELF
51 as this will allow us to read in and parse 64bit and 32bit ELF files.
52 Only do this if we believe that the compiler can support a 64 bit
53 data type. For now we only rely on GCC being able to do this. */
59 #include "elf/common.h"
60 #include "elf/external.h"
61 #include "elf/internal.h"
62 #include "elf/dwarf2.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"
90 #include "elf/m68hc11.h"
91 #include "elf/mcore.h"
94 #include "elf/mn10200.h"
95 #include "elf/mn10300.h"
96 #include "elf/msp430.h"
100 #include "elf/ppc64.h"
101 #include "elf/s390.h"
103 #include "elf/sparc.h"
104 #include "elf/v850.h"
106 #include "elf/x86-64.h"
107 #include "elf/xstormy16.h"
108 #include "elf/iq2000.h"
109 #include "elf/xtensa.h"
115 #include "libiberty.h"
117 char *program_name = "readelf";
118 long archive_file_offset;
119 unsigned long archive_file_size;
120 unsigned long dynamic_addr;
121 bfd_size_type dynamic_size;
122 char *dynamic_strings;
124 unsigned long string_table_length;
125 unsigned long num_dynamic_syms;
126 Elf_Internal_Sym *dynamic_symbols;
127 Elf_Internal_Syminfo *dynamic_syminfo;
128 unsigned long dynamic_syminfo_offset;
129 unsigned int dynamic_syminfo_nent;
130 char program_interpreter[64];
131 bfd_vma dynamic_info[DT_JMPREL + 1];
132 bfd_vma version_info[16];
133 Elf_Internal_Ehdr elf_header;
134 Elf_Internal_Shdr *section_headers;
135 Elf_Internal_Phdr *program_headers;
136 Elf_Internal_Dyn *dynamic_segment;
137 Elf_Internal_Shdr *symtab_shndx_hdr;
143 int do_section_groups;
146 int do_using_dynamic;
154 int do_debug_abbrevs;
156 int do_debug_pubnames;
157 int do_debug_aranges;
159 int do_debug_frames_interp;
160 int do_debug_macinfo;
167 /* A dynamic array of flags indicating which sections require dumping. */
168 char *dump_sects = NULL;
169 unsigned int num_dump_sects = 0;
171 #define HEX_DUMP (1 << 0)
172 #define DISASS_DUMP (1 << 1)
173 #define DEBUG_DUMP (1 << 2)
175 /* How to rpint a vma value. */
176 typedef enum print_mode
188 static bfd_vma (*byte_get) (unsigned char *, int);
189 static void (*byte_put) (unsigned char *, bfd_vma, int);
191 typedef int Elf32_Word;
195 #define SECTION_NAME(X) ((X) == NULL ? "<none>" : \
196 ((X)->sh_name >= string_table_length \
197 ? "<corrupt>" : string_table + (X)->sh_name))
199 /* Given st_shndx I, map to section_headers index. */
200 #define SECTION_HEADER_INDEX(I) \
201 ((I) < SHN_LORESERVE \
203 : ((I) <= SHN_HIRESERVE \
205 : (I) - (SHN_HIRESERVE + 1 - SHN_LORESERVE)))
207 /* Reverse of the above. */
208 #define SECTION_HEADER_NUM(N) \
209 ((N) < SHN_LORESERVE \
211 : (N) + (SHN_HIRESERVE + 1 - SHN_LORESERVE))
213 #define SECTION_HEADER(I) (section_headers + SECTION_HEADER_INDEX (I))
215 #define DT_VERSIONTAGIDX(tag) (DT_VERNEEDNUM - (tag)) /* Reverse order! */
217 #define BYTE_GET(field) byte_get (field, sizeof (field))
219 /* If we can support a 64 bit data type then BFD64 should be defined
220 and sizeof (bfd_vma) == 8. In this case when translating from an
221 external 8 byte field to an internal field, we can assume that the
222 internal field is also 8 bytes wide and so we can extract all the data.
223 If, however, BFD64 is not defined, then we must assume that the
224 internal data structure only has 4 byte wide fields that are the
225 equivalent of the 8 byte wide external counterparts, and so we must
226 truncate the data. */
228 #define BYTE_GET8(field) byte_get (field, -8)
230 #define BYTE_GET8(field) byte_get (field, 8)
233 #define NUM_ELEM(array) (sizeof (array) / sizeof ((array)[0]))
235 #define GET_ELF_SYMBOLS(file, section) \
236 (is_32bit_elf ? get_32bit_elf_symbols (file, section) \
237 : get_64bit_elf_symbols (file, section))
241 error (const char *message, ...)
245 va_start (args, message);
246 fprintf (stderr, _("%s: Error: "), program_name);
247 vfprintf (stderr, message, args);
252 warn (const char *message, ...)
256 va_start (args, message);
257 fprintf (stderr, _("%s: Warning: "), program_name);
258 vfprintf (stderr, message, args);
263 get_data (void *var, FILE *file, long offset, size_t size, const char *reason)
270 if (fseek (file, archive_file_offset + offset, SEEK_SET))
272 error (_("Unable to seek to 0x%x for %s\n"),
273 archive_file_offset + offset, reason);
280 mvar = malloc (size);
284 error (_("Out of memory allocating 0x%x bytes for %s\n"),
290 if (fread (mvar, size, 1, file) != 1)
292 error (_("Unable to read in 0x%x bytes of %s\n"), size, reason);
302 byte_get_little_endian (unsigned char *field, int size)
310 return ((unsigned int) (field[0]))
311 | (((unsigned int) (field[1])) << 8);
315 /* We want to extract data from an 8 byte wide field and
316 place it into a 4 byte wide field. Since this is a little
317 endian source we can just use the 4 byte extraction code. */
321 return ((unsigned long) (field[0]))
322 | (((unsigned long) (field[1])) << 8)
323 | (((unsigned long) (field[2])) << 16)
324 | (((unsigned long) (field[3])) << 24);
329 /* This is a special case, generated by the BYTE_GET8 macro.
330 It means that we are loading an 8 byte value from a field
331 in an external structure into an 8 byte value in a field
332 in an internal structure. */
333 return ((bfd_vma) (field[0]))
334 | (((bfd_vma) (field[1])) << 8)
335 | (((bfd_vma) (field[2])) << 16)
336 | (((bfd_vma) (field[3])) << 24)
337 | (((bfd_vma) (field[4])) << 32)
338 | (((bfd_vma) (field[5])) << 40)
339 | (((bfd_vma) (field[6])) << 48)
340 | (((bfd_vma) (field[7])) << 56);
343 error (_("Unhandled data length: %d\n"), size);
349 byte_get_signed (unsigned char *field, int size)
351 bfd_vma x = byte_get (field, size);
356 return (x ^ 0x80) - 0x80;
358 return (x ^ 0x8000) - 0x8000;
360 return (x ^ 0x80000000) - 0x80000000;
370 byte_put_little_endian (unsigned char *field, bfd_vma value, int size)
375 field[7] = (((value >> 24) >> 24) >> 8) & 0xff;
376 field[6] = ((value >> 24) >> 24) & 0xff;
377 field[5] = ((value >> 24) >> 16) & 0xff;
378 field[4] = ((value >> 24) >> 8) & 0xff;
381 field[3] = (value >> 24) & 0xff;
382 field[2] = (value >> 16) & 0xff;
385 field[1] = (value >> 8) & 0xff;
388 field[0] = value & 0xff;
392 error (_("Unhandled data length: %d\n"), size);
397 /* Print a VMA value. */
399 print_vma (bfd_vma vma, print_mode mode)
411 printf ("%8.8lx", (unsigned long) vma);
417 printf ("%5ld", (long) vma);
425 printf ("%lx", (unsigned long) vma);
429 printf ("%ld", (unsigned long) vma);
433 printf ("%lu", (unsigned long) vma);
455 #if BFD_HOST_64BIT_LONG
458 if (_bfd_int64_high (vma))
459 printf ("%lx%8.8lx", _bfd_int64_high (vma), _bfd_int64_low (vma));
461 printf ("%lx", _bfd_int64_low (vma));
466 #if BFD_HOST_64BIT_LONG
469 if (_bfd_int64_high (vma))
471 printf ("++%ld", _bfd_int64_low (vma));
473 printf ("%ld", _bfd_int64_low (vma));
478 #if BFD_HOST_64BIT_LONG
480 printf ("%5ld", vma);
482 printf ("%#lx", vma);
484 if (_bfd_int64_high (vma))
486 printf ("++%ld", _bfd_int64_low (vma));
487 else if (vma <= 99999)
488 printf ("%5ld", _bfd_int64_low (vma));
490 printf ("%#lx", _bfd_int64_low (vma));
495 #if BFD_HOST_64BIT_LONG
498 if (_bfd_int64_high (vma))
500 printf ("++%lu", _bfd_int64_low (vma));
502 printf ("%lu", _bfd_int64_low (vma));
510 /* Display a symbol on stdout. If do_wide is not true then
511 format the symbol to be at most WIDTH characters,
512 truncating as necessary. If WIDTH is negative then
513 format the string to be exactly - WIDTH characters,
514 truncating or padding as necessary. */
517 print_symbol (int width, const char *symbol)
520 printf ("%s", symbol);
522 printf ("%-*.*s", width, width, symbol);
524 printf ("%-.*s", width, symbol);
528 byte_get_big_endian (unsigned char *field, int size)
536 return ((unsigned int) (field[1])) | (((int) (field[0])) << 8);
539 return ((unsigned long) (field[3]))
540 | (((unsigned long) (field[2])) << 8)
541 | (((unsigned long) (field[1])) << 16)
542 | (((unsigned long) (field[0])) << 24);
546 /* Although we are extracing data from an 8 byte wide field, we
547 are returning only 4 bytes of data. */
548 return ((unsigned long) (field[7]))
549 | (((unsigned long) (field[6])) << 8)
550 | (((unsigned long) (field[5])) << 16)
551 | (((unsigned long) (field[4])) << 24);
555 /* This is a special case, generated by the BYTE_GET8 macro.
556 It means that we are loading an 8 byte value from a field
557 in an external structure into an 8 byte value in a field
558 in an internal structure. */
559 return ((bfd_vma) (field[7]))
560 | (((bfd_vma) (field[6])) << 8)
561 | (((bfd_vma) (field[5])) << 16)
562 | (((bfd_vma) (field[4])) << 24)
563 | (((bfd_vma) (field[3])) << 32)
564 | (((bfd_vma) (field[2])) << 40)
565 | (((bfd_vma) (field[1])) << 48)
566 | (((bfd_vma) (field[0])) << 56);
570 error (_("Unhandled data length: %d\n"), size);
576 byte_put_big_endian (unsigned char *field, bfd_vma value, int size)
581 field[7] = value & 0xff;
582 field[6] = (value >> 8) & 0xff;
583 field[5] = (value >> 16) & 0xff;
584 field[4] = (value >> 24) & 0xff;
589 field[3] = value & 0xff;
590 field[2] = (value >> 8) & 0xff;
594 field[1] = value & 0xff;
598 field[0] = value & 0xff;
602 error (_("Unhandled data length: %d\n"), size);
607 /* Guess the relocation size commonly used by the specific machines. */
610 guess_is_rela (unsigned long e_machine)
614 /* Targets that use REL relocations. */
629 /* Targets that use RELA relocations. */
644 case EM_CYGNUS_MN10200:
646 case EM_CYGNUS_MN10300:
692 warn (_("Don't know about relocations on this machine architecture\n"));
698 slurp_rela_relocs (FILE *file,
699 unsigned long rel_offset,
700 unsigned long rel_size,
701 Elf_Internal_Rela **relasp,
702 unsigned long *nrelasp)
704 Elf_Internal_Rela *relas;
705 unsigned long nrelas;
710 Elf32_External_Rela *erelas;
712 erelas = get_data (NULL, file, rel_offset, rel_size, _("relocs"));
716 nrelas = rel_size / sizeof (Elf32_External_Rela);
718 relas = malloc (nrelas * sizeof (Elf_Internal_Rela));
722 error(_("out of memory parsing relocs"));
726 for (i = 0; i < nrelas; i++)
728 relas[i].r_offset = BYTE_GET (erelas[i].r_offset);
729 relas[i].r_info = BYTE_GET (erelas[i].r_info);
730 relas[i].r_addend = BYTE_GET (erelas[i].r_addend);
737 Elf64_External_Rela *erelas;
739 erelas = get_data (NULL, file, rel_offset, rel_size, _("relocs"));
743 nrelas = rel_size / sizeof (Elf64_External_Rela);
745 relas = malloc (nrelas * sizeof (Elf_Internal_Rela));
749 error(_("out of memory parsing relocs"));
753 for (i = 0; i < nrelas; i++)
755 relas[i].r_offset = BYTE_GET8 (erelas[i].r_offset);
756 relas[i].r_info = BYTE_GET8 (erelas[i].r_info);
757 relas[i].r_addend = BYTE_GET8 (erelas[i].r_addend);
768 slurp_rel_relocs (FILE *file,
769 unsigned long rel_offset,
770 unsigned long rel_size,
771 Elf_Internal_Rela **relsp,
772 unsigned long *nrelsp)
774 Elf_Internal_Rela *rels;
780 Elf32_External_Rel *erels;
782 erels = get_data (NULL, file, rel_offset, rel_size, _("relocs"));
786 nrels = rel_size / sizeof (Elf32_External_Rel);
788 rels = malloc (nrels * sizeof (Elf_Internal_Rela));
792 error(_("out of memory parsing relocs"));
796 for (i = 0; i < nrels; i++)
798 rels[i].r_offset = BYTE_GET (erels[i].r_offset);
799 rels[i].r_info = BYTE_GET (erels[i].r_info);
800 rels[i].r_addend = 0;
807 Elf64_External_Rel *erels;
809 erels = get_data (NULL, file, rel_offset, rel_size, _("relocs"));
813 nrels = rel_size / sizeof (Elf64_External_Rel);
815 rels = malloc (nrels * sizeof (Elf_Internal_Rela));
819 error(_("out of memory parsing relocs"));
823 for (i = 0; i < nrels; i++)
825 rels[i].r_offset = BYTE_GET8 (erels[i].r_offset);
826 rels[i].r_info = BYTE_GET8 (erels[i].r_info);
827 rels[i].r_addend = 0;
837 /* Display the contents of the relocation data found at the specified
841 dump_relocations (FILE *file,
842 unsigned long rel_offset,
843 unsigned long rel_size,
844 Elf_Internal_Sym *symtab,
850 Elf_Internal_Rela *rels;
853 if (is_rela == UNKNOWN)
854 is_rela = guess_is_rela (elf_header.e_machine);
858 if (!slurp_rela_relocs (file, rel_offset, rel_size, &rels, &rel_size))
863 if (!slurp_rel_relocs (file, rel_offset, rel_size, &rels, &rel_size))
872 printf (_(" Offset Info Type Sym. Value Symbol's Name + Addend\n"));
874 printf (_(" Offset Info Type Sym.Value Sym. Name + Addend\n"));
879 printf (_(" Offset Info Type Sym. Value Symbol's Name\n"));
881 printf (_(" Offset Info Type Sym.Value Sym. Name\n"));
889 printf (_(" Offset Info Type Symbol's Value Symbol's Name + Addend\n"));
891 printf (_(" Offset Info Type Sym. Value Sym. Name + Addend\n"));
896 printf (_(" Offset Info Type Symbol's Value Symbol's Name\n"));
898 printf (_(" Offset Info Type Sym. Value Sym. Name\n"));
902 for (i = 0; i < rel_size; i++)
905 const char *rtype2 = NULL;
906 const char *rtype3 = NULL;
909 bfd_vma symtab_index;
914 offset = rels[i].r_offset;
915 info = rels[i].r_info;
919 type = ELF32_R_TYPE (info);
920 symtab_index = ELF32_R_SYM (info);
924 /* The #ifdef BFD64 below is to prevent a compile time warning.
925 We know that if we do not have a 64 bit data type that we
926 will never execute this code anyway. */
928 if (elf_header.e_machine == EM_MIPS)
930 /* In little-endian objects, r_info isn't really a 64-bit
931 little-endian value: it has a 32-bit little-endian
932 symbol index followed by four individual byte fields.
933 Reorder INFO accordingly. */
934 if (elf_header.e_ident[EI_DATA] != ELFDATA2MSB)
935 info = (((info & 0xffffffff) << 32)
936 | ((info >> 56) & 0xff)
937 | ((info >> 40) & 0xff00)
938 | ((info >> 24) & 0xff0000)
939 | ((info >> 8) & 0xff000000));
940 type = ELF64_MIPS_R_TYPE (info);
941 type2 = ELF64_MIPS_R_TYPE2 (info);
942 type3 = ELF64_MIPS_R_TYPE3 (info);
944 else if (elf_header.e_machine == EM_SPARCV9)
945 type = ELF64_R_TYPE_ID (info);
947 type = ELF64_R_TYPE (info);
949 symtab_index = ELF64_R_SYM (info);
955 #ifdef _bfd_int64_low
956 printf ("%8.8lx %8.8lx ", _bfd_int64_low (offset), _bfd_int64_low (info));
958 printf ("%8.8lx %8.8lx ", offset, info);
963 #ifdef _bfd_int64_low
965 ? "%8.8lx%8.8lx %8.8lx%8.8lx "
966 : "%4.4lx%8.8lx %4.4lx%8.8lx ",
967 _bfd_int64_high (offset),
968 _bfd_int64_low (offset),
969 _bfd_int64_high (info),
970 _bfd_int64_low (info));
973 ? "%16.16lx %16.16lx "
974 : "%12.12lx %12.12lx ",
979 switch (elf_header.e_machine)
987 rtype = elf_m32r_reloc_type (type);
992 rtype = elf_i386_reloc_type (type);
997 rtype = elf_m68hc11_reloc_type (type);
1001 rtype = elf_m68k_reloc_type (type);
1005 rtype = elf_i960_reloc_type (type);
1010 rtype = elf_avr_reloc_type (type);
1013 case EM_OLD_SPARCV9:
1014 case EM_SPARC32PLUS:
1017 rtype = elf_sparc_reloc_type (type);
1021 case EM_CYGNUS_V850:
1022 rtype = v850_reloc_type (type);
1026 case EM_CYGNUS_D10V:
1027 rtype = elf_d10v_reloc_type (type);
1031 case EM_CYGNUS_D30V:
1032 rtype = elf_d30v_reloc_type (type);
1036 rtype = elf_dlx_reloc_type (type);
1040 rtype = elf_sh_reloc_type (type);
1044 case EM_CYGNUS_MN10300:
1045 rtype = elf_mn10300_reloc_type (type);
1049 case EM_CYGNUS_MN10200:
1050 rtype = elf_mn10200_reloc_type (type);
1054 case EM_CYGNUS_FR30:
1055 rtype = elf_fr30_reloc_type (type);
1059 rtype = elf_frv_reloc_type (type);
1063 rtype = elf_mcore_reloc_type (type);
1067 rtype = elf_mmix_reloc_type (type);
1072 rtype = elf_msp430_reloc_type (type);
1076 rtype = elf_ppc_reloc_type (type);
1080 rtype = elf_ppc64_reloc_type (type);
1084 case EM_MIPS_RS3_LE:
1085 rtype = elf_mips_reloc_type (type);
1088 rtype2 = elf_mips_reloc_type (type2);
1089 rtype3 = elf_mips_reloc_type (type3);
1094 rtype = elf_alpha_reloc_type (type);
1098 rtype = elf_arm_reloc_type (type);
1102 rtype = elf_arc_reloc_type (type);
1106 rtype = elf_hppa_reloc_type (type);
1112 rtype = elf_h8_reloc_type (type);
1117 rtype = elf_or32_reloc_type (type);
1122 rtype = elf_pj_reloc_type (type);
1125 rtype = elf_ia64_reloc_type (type);
1129 rtype = elf_cris_reloc_type (type);
1133 rtype = elf_i860_reloc_type (type);
1137 rtype = elf_x86_64_reloc_type (type);
1141 rtype = i370_reloc_type (type);
1146 rtype = elf_s390_reloc_type (type);
1150 rtype = elf_xstormy16_reloc_type (type);
1154 rtype = elf_vax_reloc_type (type);
1159 rtype = elf_ip2k_reloc_type (type);
1163 rtype = elf_iq2000_reloc_type (type);
1168 rtype = elf_xtensa_reloc_type (type);
1173 #ifdef _bfd_int64_low
1174 printf (_("unrecognized: %-7lx"), _bfd_int64_low (type));
1176 printf (_("unrecognized: %-7lx"), type);
1179 printf (do_wide ? "%-22.22s" : "%-17.17s", rtype);
1183 if (symtab == NULL || symtab_index >= nsyms)
1184 printf (" bad symbol index: %08lx", (unsigned long) symtab_index);
1187 Elf_Internal_Sym *psym;
1189 psym = symtab + symtab_index;
1192 print_vma (psym->st_value, LONG_HEX);
1193 printf (is_32bit_elf ? " " : " ");
1195 if (psym->st_name == 0)
1197 const char *sec_name = "<null>";
1200 if (ELF_ST_TYPE (psym->st_info) == STT_SECTION)
1202 bfd_vma sec_index = (bfd_vma) -1;
1204 if (psym->st_shndx < SHN_LORESERVE)
1205 sec_index = psym->st_shndx;
1206 else if (psym->st_shndx > SHN_LORESERVE)
1207 sec_index = psym->st_shndx - (SHN_HIRESERVE + 1
1210 if (sec_index != (bfd_vma) -1)
1211 sec_name = SECTION_NAME (section_headers + sec_index);
1212 else if (psym->st_shndx == SHN_ABS)
1214 else if (psym->st_shndx == SHN_COMMON)
1215 sec_name = "COMMON";
1216 else if (elf_header.e_machine == EM_IA_64
1217 && elf_header.e_ident[EI_OSABI] == ELFOSABI_HPUX
1218 && psym->st_shndx == SHN_IA_64_ANSI_COMMON)
1219 sec_name = "ANSI_COM";
1222 sprintf (name_buf, "<section 0x%x>",
1223 (unsigned int) psym->st_shndx);
1224 sec_name = name_buf;
1227 print_symbol (22, sec_name);
1229 else if (strtab == NULL)
1230 printf (_("<string table index %3ld>"), psym->st_name);
1232 print_symbol (22, strtab + psym->st_name);
1235 printf (" + %lx", (unsigned long) rels[i].r_addend);
1240 printf ("%*c", is_32bit_elf ? (do_wide ? 34 : 28) : (do_wide ? 26 : 20), ' ');
1241 print_vma (rels[i].r_addend, LONG_HEX);
1244 if (elf_header.e_machine == EM_SPARCV9
1245 && !strcmp (rtype, "R_SPARC_OLO10"))
1246 printf (" + %lx", (unsigned long) ELF64_R_TYPE_DATA (info));
1250 if (! is_32bit_elf && elf_header.e_machine == EM_MIPS)
1252 printf (" Type2: ");
1255 #ifdef _bfd_int64_low
1256 printf (_("unrecognized: %-7lx"), _bfd_int64_low (type2));
1258 printf (_("unrecognized: %-7lx"), type2);
1261 printf ("%-17.17s", rtype2);
1263 printf("\n Type3: ");
1266 #ifdef _bfd_int64_low
1267 printf (_("unrecognized: %-7lx"), _bfd_int64_low (type3));
1269 printf (_("unrecognized: %-7lx"), type3);
1272 printf ("%-17.17s", rtype3);
1284 get_mips_dynamic_type (unsigned long type)
1288 case DT_MIPS_RLD_VERSION: return "MIPS_RLD_VERSION";
1289 case DT_MIPS_TIME_STAMP: return "MIPS_TIME_STAMP";
1290 case DT_MIPS_ICHECKSUM: return "MIPS_ICHECKSUM";
1291 case DT_MIPS_IVERSION: return "MIPS_IVERSION";
1292 case DT_MIPS_FLAGS: return "MIPS_FLAGS";
1293 case DT_MIPS_BASE_ADDRESS: return "MIPS_BASE_ADDRESS";
1294 case DT_MIPS_MSYM: return "MIPS_MSYM";
1295 case DT_MIPS_CONFLICT: return "MIPS_CONFLICT";
1296 case DT_MIPS_LIBLIST: return "MIPS_LIBLIST";
1297 case DT_MIPS_LOCAL_GOTNO: return "MIPS_LOCAL_GOTNO";
1298 case DT_MIPS_CONFLICTNO: return "MIPS_CONFLICTNO";
1299 case DT_MIPS_LIBLISTNO: return "MIPS_LIBLISTNO";
1300 case DT_MIPS_SYMTABNO: return "MIPS_SYMTABNO";
1301 case DT_MIPS_UNREFEXTNO: return "MIPS_UNREFEXTNO";
1302 case DT_MIPS_GOTSYM: return "MIPS_GOTSYM";
1303 case DT_MIPS_HIPAGENO: return "MIPS_HIPAGENO";
1304 case DT_MIPS_RLD_MAP: return "MIPS_RLD_MAP";
1305 case DT_MIPS_DELTA_CLASS: return "MIPS_DELTA_CLASS";
1306 case DT_MIPS_DELTA_CLASS_NO: return "MIPS_DELTA_CLASS_NO";
1307 case DT_MIPS_DELTA_INSTANCE: return "MIPS_DELTA_INSTANCE";
1308 case DT_MIPS_DELTA_INSTANCE_NO: return "MIPS_DELTA_INSTANCE_NO";
1309 case DT_MIPS_DELTA_RELOC: return "MIPS_DELTA_RELOC";
1310 case DT_MIPS_DELTA_RELOC_NO: return "MIPS_DELTA_RELOC_NO";
1311 case DT_MIPS_DELTA_SYM: return "MIPS_DELTA_SYM";
1312 case DT_MIPS_DELTA_SYM_NO: return "MIPS_DELTA_SYM_NO";
1313 case DT_MIPS_DELTA_CLASSSYM: return "MIPS_DELTA_CLASSSYM";
1314 case DT_MIPS_DELTA_CLASSSYM_NO: return "MIPS_DELTA_CLASSSYM_NO";
1315 case DT_MIPS_CXX_FLAGS: return "MIPS_CXX_FLAGS";
1316 case DT_MIPS_PIXIE_INIT: return "MIPS_PIXIE_INIT";
1317 case DT_MIPS_SYMBOL_LIB: return "MIPS_SYMBOL_LIB";
1318 case DT_MIPS_LOCALPAGE_GOTIDX: return "MIPS_LOCALPAGE_GOTIDX";
1319 case DT_MIPS_LOCAL_GOTIDX: return "MIPS_LOCAL_GOTIDX";
1320 case DT_MIPS_HIDDEN_GOTIDX: return "MIPS_HIDDEN_GOTIDX";
1321 case DT_MIPS_PROTECTED_GOTIDX: return "MIPS_PROTECTED_GOTIDX";
1322 case DT_MIPS_OPTIONS: return "MIPS_OPTIONS";
1323 case DT_MIPS_INTERFACE: return "MIPS_INTERFACE";
1324 case DT_MIPS_DYNSTR_ALIGN: return "MIPS_DYNSTR_ALIGN";
1325 case DT_MIPS_INTERFACE_SIZE: return "MIPS_INTERFACE_SIZE";
1326 case DT_MIPS_RLD_TEXT_RESOLVE_ADDR: return "MIPS_RLD_TEXT_RESOLVE_ADDR";
1327 case DT_MIPS_PERF_SUFFIX: return "MIPS_PERF_SUFFIX";
1328 case DT_MIPS_COMPACT_SIZE: return "MIPS_COMPACT_SIZE";
1329 case DT_MIPS_GP_VALUE: return "MIPS_GP_VALUE";
1330 case DT_MIPS_AUX_DYNAMIC: return "MIPS_AUX_DYNAMIC";
1337 get_sparc64_dynamic_type (unsigned long type)
1341 case DT_SPARC_REGISTER: return "SPARC_REGISTER";
1348 get_ppc64_dynamic_type (unsigned long type)
1352 case DT_PPC64_GLINK: return "PPC64_GLINK";
1353 case DT_PPC64_OPD: return "PPC64_OPD";
1354 case DT_PPC64_OPDSZ: return "PPC64_OPDSZ";
1361 get_parisc_dynamic_type (unsigned long type)
1365 case DT_HP_LOAD_MAP: return "HP_LOAD_MAP";
1366 case DT_HP_DLD_FLAGS: return "HP_DLD_FLAGS";
1367 case DT_HP_DLD_HOOK: return "HP_DLD_HOOK";
1368 case DT_HP_UX10_INIT: return "HP_UX10_INIT";
1369 case DT_HP_UX10_INITSZ: return "HP_UX10_INITSZ";
1370 case DT_HP_PREINIT: return "HP_PREINIT";
1371 case DT_HP_PREINITSZ: return "HP_PREINITSZ";
1372 case DT_HP_NEEDED: return "HP_NEEDED";
1373 case DT_HP_TIME_STAMP: return "HP_TIME_STAMP";
1374 case DT_HP_CHECKSUM: return "HP_CHECKSUM";
1375 case DT_HP_GST_SIZE: return "HP_GST_SIZE";
1376 case DT_HP_GST_VERSION: return "HP_GST_VERSION";
1377 case DT_HP_GST_HASHVAL: return "HP_GST_HASHVAL";
1384 get_ia64_dynamic_type (unsigned long type)
1388 case DT_IA_64_PLT_RESERVE: return "IA_64_PLT_RESERVE";
1395 get_dynamic_type (unsigned long type)
1397 static char buff[32];
1401 case DT_NULL: return "NULL";
1402 case DT_NEEDED: return "NEEDED";
1403 case DT_PLTRELSZ: return "PLTRELSZ";
1404 case DT_PLTGOT: return "PLTGOT";
1405 case DT_HASH: return "HASH";
1406 case DT_STRTAB: return "STRTAB";
1407 case DT_SYMTAB: return "SYMTAB";
1408 case DT_RELA: return "RELA";
1409 case DT_RELASZ: return "RELASZ";
1410 case DT_RELAENT: return "RELAENT";
1411 case DT_STRSZ: return "STRSZ";
1412 case DT_SYMENT: return "SYMENT";
1413 case DT_INIT: return "INIT";
1414 case DT_FINI: return "FINI";
1415 case DT_SONAME: return "SONAME";
1416 case DT_RPATH: return "RPATH";
1417 case DT_SYMBOLIC: return "SYMBOLIC";
1418 case DT_REL: return "REL";
1419 case DT_RELSZ: return "RELSZ";
1420 case DT_RELENT: return "RELENT";
1421 case DT_PLTREL: return "PLTREL";
1422 case DT_DEBUG: return "DEBUG";
1423 case DT_TEXTREL: return "TEXTREL";
1424 case DT_JMPREL: return "JMPREL";
1425 case DT_BIND_NOW: return "BIND_NOW";
1426 case DT_INIT_ARRAY: return "INIT_ARRAY";
1427 case DT_FINI_ARRAY: return "FINI_ARRAY";
1428 case DT_INIT_ARRAYSZ: return "INIT_ARRAYSZ";
1429 case DT_FINI_ARRAYSZ: return "FINI_ARRAYSZ";
1430 case DT_RUNPATH: return "RUNPATH";
1431 case DT_FLAGS: return "FLAGS";
1433 case DT_PREINIT_ARRAY: return "PREINIT_ARRAY";
1434 case DT_PREINIT_ARRAYSZ: return "PREINIT_ARRAYSZ";
1436 case DT_CHECKSUM: return "CHECKSUM";
1437 case DT_PLTPADSZ: return "PLTPADSZ";
1438 case DT_MOVEENT: return "MOVEENT";
1439 case DT_MOVESZ: return "MOVESZ";
1440 case DT_FEATURE: return "FEATURE";
1441 case DT_POSFLAG_1: return "POSFLAG_1";
1442 case DT_SYMINSZ: return "SYMINSZ";
1443 case DT_SYMINENT: return "SYMINENT"; /* aka VALRNGHI */
1445 case DT_ADDRRNGLO: return "ADDRRNGLO";
1446 case DT_CONFIG: return "CONFIG";
1447 case DT_DEPAUDIT: return "DEPAUDIT";
1448 case DT_AUDIT: return "AUDIT";
1449 case DT_PLTPAD: return "PLTPAD";
1450 case DT_MOVETAB: return "MOVETAB";
1451 case DT_SYMINFO: return "SYMINFO"; /* aka ADDRRNGHI */
1453 case DT_VERSYM: return "VERSYM";
1455 case DT_RELACOUNT: return "RELACOUNT";
1456 case DT_RELCOUNT: return "RELCOUNT";
1457 case DT_FLAGS_1: return "FLAGS_1";
1458 case DT_VERDEF: return "VERDEF";
1459 case DT_VERDEFNUM: return "VERDEFNUM";
1460 case DT_VERNEED: return "VERNEED";
1461 case DT_VERNEEDNUM: return "VERNEEDNUM";
1463 case DT_AUXILIARY: return "AUXILIARY";
1464 case DT_USED: return "USED";
1465 case DT_FILTER: return "FILTER";
1467 case DT_GNU_PRELINKED: return "GNU_PRELINKED";
1468 case DT_GNU_CONFLICT: return "GNU_CONFLICT";
1469 case DT_GNU_CONFLICTSZ: return "GNU_CONFLICTSZ";
1470 case DT_GNU_LIBLIST: return "GNU_LIBLIST";
1471 case DT_GNU_LIBLISTSZ: return "GNU_LIBLISTSZ";
1474 if ((type >= DT_LOPROC) && (type <= DT_HIPROC))
1478 switch (elf_header.e_machine)
1481 case EM_MIPS_RS3_LE:
1482 result = get_mips_dynamic_type (type);
1485 result = get_sparc64_dynamic_type (type);
1488 result = get_ppc64_dynamic_type (type);
1491 result = get_ia64_dynamic_type (type);
1501 sprintf (buff, _("Processor Specific: %lx"), type);
1503 else if ((type >= DT_LOOS) && (type <= DT_HIOS))
1507 switch (elf_header.e_machine)
1510 result = get_parisc_dynamic_type (type);
1520 sprintf (buff, _("Operating System specific: %lx"), type);
1523 sprintf (buff, _("<unknown>: %lx"), type);
1530 get_file_type (unsigned e_type)
1532 static char buff[32];
1536 case ET_NONE: return _("NONE (None)");
1537 case ET_REL: return _("REL (Relocatable file)");
1538 case ET_EXEC: return _("EXEC (Executable file)");
1539 case ET_DYN: return _("DYN (Shared object file)");
1540 case ET_CORE: return _("CORE (Core file)");
1543 if ((e_type >= ET_LOPROC) && (e_type <= ET_HIPROC))
1544 sprintf (buff, _("Processor Specific: (%x)"), e_type);
1545 else if ((e_type >= ET_LOOS) && (e_type <= ET_HIOS))
1546 sprintf (buff, _("OS Specific: (%x)"), e_type);
1548 sprintf (buff, _("<unknown>: %x"), e_type);
1554 get_machine_name (unsigned e_machine)
1556 static char buff[64]; /* XXX */
1560 case EM_NONE: return _("None");
1561 case EM_M32: return "WE32100";
1562 case EM_SPARC: return "Sparc";
1563 case EM_386: return "Intel 80386";
1564 case EM_68K: return "MC68000";
1565 case EM_88K: return "MC88000";
1566 case EM_486: return "Intel 80486";
1567 case EM_860: return "Intel 80860";
1568 case EM_MIPS: return "MIPS R3000";
1569 case EM_S370: return "IBM System/370";
1570 case EM_MIPS_RS3_LE: return "MIPS R4000 big-endian";
1571 case EM_OLD_SPARCV9: return "Sparc v9 (old)";
1572 case EM_PARISC: return "HPPA";
1573 case EM_PPC_OLD: return "Power PC (old)";
1574 case EM_SPARC32PLUS: return "Sparc v8+" ;
1575 case EM_960: return "Intel 90860";
1576 case EM_PPC: return "PowerPC";
1577 case EM_PPC64: return "PowerPC64";
1578 case EM_V800: return "NEC V800";
1579 case EM_FR20: return "Fujitsu FR20";
1580 case EM_RH32: return "TRW RH32";
1581 case EM_MCORE: return "MCORE";
1582 case EM_ARM: return "ARM";
1583 case EM_OLD_ALPHA: return "Digital Alpha (old)";
1584 case EM_SH: return "Renesas / SuperH SH";
1585 case EM_SPARCV9: return "Sparc v9";
1586 case EM_TRICORE: return "Siemens Tricore";
1587 case EM_ARC: return "ARC";
1588 case EM_H8_300: return "Renesas H8/300";
1589 case EM_H8_300H: return "Renesas H8/300H";
1590 case EM_H8S: return "Renesas H8S";
1591 case EM_H8_500: return "Renesas H8/500";
1592 case EM_IA_64: return "Intel IA-64";
1593 case EM_MIPS_X: return "Stanford MIPS-X";
1594 case EM_COLDFIRE: return "Motorola Coldfire";
1595 case EM_68HC12: return "Motorola M68HC12";
1596 case EM_ALPHA: return "Alpha";
1597 case EM_CYGNUS_D10V:
1598 case EM_D10V: return "d10v";
1599 case EM_CYGNUS_D30V:
1600 case EM_D30V: return "d30v";
1601 case EM_CYGNUS_M32R:
1602 case EM_M32R: return "Renesas M32R (formerly Mitsubishi M32r)";
1603 case EM_CYGNUS_V850:
1604 case EM_V850: return "NEC v850";
1605 case EM_CYGNUS_MN10300:
1606 case EM_MN10300: return "mn10300";
1607 case EM_CYGNUS_MN10200:
1608 case EM_MN10200: return "mn10200";
1609 case EM_CYGNUS_FR30:
1610 case EM_FR30: return "Fujitsu FR30";
1611 case EM_CYGNUS_FRV: return "Fujitsu FR-V";
1613 case EM_PJ: return "picoJava";
1614 case EM_MMA: return "Fujitsu Multimedia Accelerator";
1615 case EM_PCP: return "Siemens PCP";
1616 case EM_NCPU: return "Sony nCPU embedded RISC processor";
1617 case EM_NDR1: return "Denso NDR1 microprocesspr";
1618 case EM_STARCORE: return "Motorola Star*Core processor";
1619 case EM_ME16: return "Toyota ME16 processor";
1620 case EM_ST100: return "STMicroelectronics ST100 processor";
1621 case EM_TINYJ: return "Advanced Logic Corp. TinyJ embedded processor";
1622 case EM_FX66: return "Siemens FX66 microcontroller";
1623 case EM_ST9PLUS: return "STMicroelectronics ST9+ 8/16 bit microcontroller";
1624 case EM_ST7: return "STMicroelectronics ST7 8-bit microcontroller";
1625 case EM_68HC16: return "Motorola MC68HC16 Microcontroller";
1626 case EM_68HC11: return "Motorola MC68HC11 Microcontroller";
1627 case EM_68HC08: return "Motorola MC68HC08 Microcontroller";
1628 case EM_68HC05: return "Motorola MC68HC05 Microcontroller";
1629 case EM_SVX: return "Silicon Graphics SVx";
1630 case EM_ST19: return "STMicroelectronics ST19 8-bit microcontroller";
1631 case EM_VAX: return "Digital VAX";
1633 case EM_AVR: return "Atmel AVR 8-bit microcontroller";
1634 case EM_CRIS: return "Axis Communications 32-bit embedded processor";
1635 case EM_JAVELIN: return "Infineon Technologies 32-bit embedded cpu";
1636 case EM_FIREPATH: return "Element 14 64-bit DSP processor";
1637 case EM_ZSP: return "LSI Logic's 16-bit DSP processor";
1638 case EM_MMIX: return "Donald Knuth's educational 64-bit processor";
1639 case EM_HUANY: return "Harvard Universitys's machine-independent object format";
1640 case EM_PRISM: return "Vitesse Prism";
1641 case EM_X86_64: return "Advanced Micro Devices X86-64";
1643 case EM_S390: return "IBM S/390";
1644 case EM_XSTORMY16: return "Sanyo Xstormy16 CPU core";
1646 case EM_OR32: return "OpenRISC";
1647 case EM_DLX: return "OpenDLX";
1649 case EM_IP2K: return "Ubicom IP2xxx 8-bit microcontrollers";
1650 case EM_IQ2000: return "Vitesse IQ2000";
1652 case EM_XTENSA: return "Tensilica Xtensa Processor";
1654 sprintf (buff, _("<unknown>: %x"), e_machine);
1660 decode_ARM_machine_flags (unsigned e_flags, char buf[])
1665 eabi = EF_ARM_EABI_VERSION (e_flags);
1666 e_flags &= ~ EF_ARM_EABIMASK;
1668 /* Handle "generic" ARM flags. */
1669 if (e_flags & EF_ARM_RELEXEC)
1671 strcat (buf, ", relocatable executable");
1672 e_flags &= ~ EF_ARM_RELEXEC;
1675 if (e_flags & EF_ARM_HASENTRY)
1677 strcat (buf, ", has entry point");
1678 e_flags &= ~ EF_ARM_HASENTRY;
1681 /* Now handle EABI specific flags. */
1685 strcat (buf, ", <unrecognized EABI>");
1690 case EF_ARM_EABI_VER1:
1691 strcat (buf, ", Version1 EABI");
1696 /* Process flags one bit at a time. */
1697 flag = e_flags & - e_flags;
1702 case EF_ARM_SYMSARESORTED: /* Conflicts with EF_ARM_INTERWORK. */
1703 strcat (buf, ", sorted symbol tables");
1713 case EF_ARM_EABI_VER2:
1714 strcat (buf, ", Version2 EABI");
1719 /* Process flags one bit at a time. */
1720 flag = e_flags & - e_flags;
1725 case EF_ARM_SYMSARESORTED: /* Conflicts with EF_ARM_INTERWORK. */
1726 strcat (buf, ", sorted symbol tables");
1729 case EF_ARM_DYNSYMSUSESEGIDX:
1730 strcat (buf, ", dynamic symbols use segment index");
1733 case EF_ARM_MAPSYMSFIRST:
1734 strcat (buf, ", mapping symbols precede others");
1744 case EF_ARM_EABI_VER3:
1745 strcat (buf, ", Version3 EABI");
1750 /* Process flags one bit at a time. */
1751 flag = e_flags & - e_flags;
1757 strcat (buf, ", BE8");
1761 strcat (buf, ", LE8");
1771 case EF_ARM_EABI_UNKNOWN:
1772 strcat (buf, ", GNU EABI");
1777 /* Process flags one bit at a time. */
1778 flag = e_flags & - e_flags;
1783 case EF_ARM_INTERWORK:
1784 strcat (buf, ", interworking enabled");
1787 case EF_ARM_APCS_26:
1788 strcat (buf, ", uses APCS/26");
1791 case EF_ARM_APCS_FLOAT:
1792 strcat (buf, ", uses APCS/float");
1796 strcat (buf, ", position independent");
1800 strcat (buf, ", 8 bit structure alignment");
1803 case EF_ARM_NEW_ABI:
1804 strcat (buf, ", uses new ABI");
1807 case EF_ARM_OLD_ABI:
1808 strcat (buf, ", uses old ABI");
1811 case EF_ARM_SOFT_FLOAT:
1812 strcat (buf, ", software FP");
1815 case EF_ARM_MAVERICK_FLOAT:
1816 strcat (buf, ", Maverick FP");
1827 strcat (buf,", <unknown>");
1831 get_machine_flags (unsigned e_flags, unsigned e_machine)
1833 static char buf[1024];
1845 decode_ARM_machine_flags (e_flags, buf);
1849 if (e_flags & EF_CPU32)
1850 strcat (buf, ", cpu32");
1851 if (e_flags & EF_M68000)
1852 strcat (buf, ", m68000");
1856 if (e_flags & EF_PPC_EMB)
1857 strcat (buf, ", emb");
1859 if (e_flags & EF_PPC_RELOCATABLE)
1860 strcat (buf, ", relocatable");
1862 if (e_flags & EF_PPC_RELOCATABLE_LIB)
1863 strcat (buf, ", relocatable-lib");
1867 case EM_CYGNUS_V850:
1868 switch (e_flags & EF_V850_ARCH)
1871 strcat (buf, ", v850e1");
1874 strcat (buf, ", v850e");
1877 strcat (buf, ", v850");
1880 strcat (buf, ", unknown v850 architecture variant");
1886 case EM_CYGNUS_M32R:
1887 if ((e_flags & EF_M32R_ARCH) == E_M32R_ARCH)
1888 strcat (buf, ", m32r");
1893 case EM_MIPS_RS3_LE:
1894 if (e_flags & EF_MIPS_NOREORDER)
1895 strcat (buf, ", noreorder");
1897 if (e_flags & EF_MIPS_PIC)
1898 strcat (buf, ", pic");
1900 if (e_flags & EF_MIPS_CPIC)
1901 strcat (buf, ", cpic");
1903 if (e_flags & EF_MIPS_UCODE)
1904 strcat (buf, ", ugen_reserved");
1906 if (e_flags & EF_MIPS_ABI2)
1907 strcat (buf, ", abi2");
1909 if (e_flags & EF_MIPS_OPTIONS_FIRST)
1910 strcat (buf, ", odk first");
1912 if (e_flags & EF_MIPS_32BITMODE)
1913 strcat (buf, ", 32bitmode");
1915 switch ((e_flags & EF_MIPS_MACH))
1917 case E_MIPS_MACH_3900: strcat (buf, ", 3900"); break;
1918 case E_MIPS_MACH_4010: strcat (buf, ", 4010"); break;
1919 case E_MIPS_MACH_4100: strcat (buf, ", 4100"); break;
1920 case E_MIPS_MACH_4111: strcat (buf, ", 4111"); break;
1921 case E_MIPS_MACH_4120: strcat (buf, ", 4120"); break;
1922 case E_MIPS_MACH_4650: strcat (buf, ", 4650"); break;
1923 case E_MIPS_MACH_5400: strcat (buf, ", 5400"); break;
1924 case E_MIPS_MACH_5500: strcat (buf, ", 5500"); break;
1925 case E_MIPS_MACH_SB1: strcat (buf, ", sb1"); break;
1927 /* We simply ignore the field in this case to avoid confusion:
1928 MIPS ELF does not specify EF_MIPS_MACH, it is a GNU
1931 default: strcat (buf, ", unknown CPU"); break;
1934 switch ((e_flags & EF_MIPS_ABI))
1936 case E_MIPS_ABI_O32: strcat (buf, ", o32"); break;
1937 case E_MIPS_ABI_O64: strcat (buf, ", o64"); break;
1938 case E_MIPS_ABI_EABI32: strcat (buf, ", eabi32"); break;
1939 case E_MIPS_ABI_EABI64: strcat (buf, ", eabi64"); break;
1941 /* We simply ignore the field in this case to avoid confusion:
1942 MIPS ELF does not specify EF_MIPS_ABI, it is a GNU extension.
1943 This means it is likely to be an o32 file, but not for
1946 default: strcat (buf, ", unknown ABI"); break;
1949 if (e_flags & EF_MIPS_ARCH_ASE_MDMX)
1950 strcat (buf, ", mdmx");
1952 if (e_flags & EF_MIPS_ARCH_ASE_M16)
1953 strcat (buf, ", mips16");
1955 switch ((e_flags & EF_MIPS_ARCH))
1957 case E_MIPS_ARCH_1: strcat (buf, ", mips1"); break;
1958 case E_MIPS_ARCH_2: strcat (buf, ", mips2"); break;
1959 case E_MIPS_ARCH_3: strcat (buf, ", mips3"); break;
1960 case E_MIPS_ARCH_4: strcat (buf, ", mips4"); break;
1961 case E_MIPS_ARCH_5: strcat (buf, ", mips5"); break;
1962 case E_MIPS_ARCH_32: strcat (buf, ", mips32"); break;
1963 case E_MIPS_ARCH_32R2: strcat (buf, ", mips32r2"); break;
1964 case E_MIPS_ARCH_64: strcat (buf, ", mips64"); break;
1965 case E_MIPS_ARCH_64R2: strcat (buf, ", mips64r2"); break;
1966 default: strcat (buf, ", unknown ISA"); break;
1972 if (e_flags & EF_SPARC_32PLUS)
1973 strcat (buf, ", v8+");
1975 if (e_flags & EF_SPARC_SUN_US1)
1976 strcat (buf, ", ultrasparcI");
1978 if (e_flags & EF_SPARC_SUN_US3)
1979 strcat (buf, ", ultrasparcIII");
1981 if (e_flags & EF_SPARC_HAL_R1)
1982 strcat (buf, ", halr1");
1984 if (e_flags & EF_SPARC_LEDATA)
1985 strcat (buf, ", ledata");
1987 if ((e_flags & EF_SPARCV9_MM) == EF_SPARCV9_TSO)
1988 strcat (buf, ", tso");
1990 if ((e_flags & EF_SPARCV9_MM) == EF_SPARCV9_PSO)
1991 strcat (buf, ", pso");
1993 if ((e_flags & EF_SPARCV9_MM) == EF_SPARCV9_RMO)
1994 strcat (buf, ", rmo");
1998 switch (e_flags & EF_PARISC_ARCH)
2000 case EFA_PARISC_1_0:
2001 strcpy (buf, ", PA-RISC 1.0");
2003 case EFA_PARISC_1_1:
2004 strcpy (buf, ", PA-RISC 1.1");
2006 case EFA_PARISC_2_0:
2007 strcpy (buf, ", PA-RISC 2.0");
2012 if (e_flags & EF_PARISC_TRAPNIL)
2013 strcat (buf, ", trapnil");
2014 if (e_flags & EF_PARISC_EXT)
2015 strcat (buf, ", ext");
2016 if (e_flags & EF_PARISC_LSB)
2017 strcat (buf, ", lsb");
2018 if (e_flags & EF_PARISC_WIDE)
2019 strcat (buf, ", wide");
2020 if (e_flags & EF_PARISC_NO_KABP)
2021 strcat (buf, ", no kabp");
2022 if (e_flags & EF_PARISC_LAZYSWAP)
2023 strcat (buf, ", lazyswap");
2028 if ((e_flags & EF_PICOJAVA_NEWCALLS) == EF_PICOJAVA_NEWCALLS)
2029 strcat (buf, ", new calling convention");
2031 if ((e_flags & EF_PICOJAVA_GNUCALLS) == EF_PICOJAVA_GNUCALLS)
2032 strcat (buf, ", gnu calling convention");
2036 if ((e_flags & EF_IA_64_ABI64))
2037 strcat (buf, ", 64-bit");
2039 strcat (buf, ", 32-bit");
2040 if ((e_flags & EF_IA_64_REDUCEDFP))
2041 strcat (buf, ", reduced fp model");
2042 if ((e_flags & EF_IA_64_NOFUNCDESC_CONS_GP))
2043 strcat (buf, ", no function descriptors, constant gp");
2044 else if ((e_flags & EF_IA_64_CONS_GP))
2045 strcat (buf, ", constant gp");
2046 if ((e_flags & EF_IA_64_ABSOLUTE))
2047 strcat (buf, ", absolute");
2051 if ((e_flags & EF_VAX_NONPIC))
2052 strcat (buf, ", non-PIC");
2053 if ((e_flags & EF_VAX_DFLOAT))
2054 strcat (buf, ", D-Float");
2055 if ((e_flags & EF_VAX_GFLOAT))
2056 strcat (buf, ", G-Float");
2065 get_osabi_name (unsigned int osabi)
2067 static char buff[32];
2071 case ELFOSABI_NONE: return "UNIX - System V";
2072 case ELFOSABI_HPUX: return "UNIX - HP-UX";
2073 case ELFOSABI_NETBSD: return "UNIX - NetBSD";
2074 case ELFOSABI_LINUX: return "UNIX - Linux";
2075 case ELFOSABI_HURD: return "GNU/Hurd";
2076 case ELFOSABI_SOLARIS: return "UNIX - Solaris";
2077 case ELFOSABI_AIX: return "UNIX - AIX";
2078 case ELFOSABI_IRIX: return "UNIX - IRIX";
2079 case ELFOSABI_FREEBSD: return "UNIX - FreeBSD";
2080 case ELFOSABI_TRU64: return "UNIX - TRU64";
2081 case ELFOSABI_MODESTO: return "Novell - Modesto";
2082 case ELFOSABI_OPENBSD: return "UNIX - OpenBSD";
2083 case ELFOSABI_OPENVMS: return "VMS - OpenVMS";
2084 case ELFOSABI_NSK: return "HP - Non-Stop Kernel";
2085 case ELFOSABI_AROS: return "Amiga Research OS";
2086 case ELFOSABI_STANDALONE: return _("Standalone App");
2087 case ELFOSABI_ARM: return "ARM";
2089 sprintf (buff, _("<unknown: %x>"), osabi);
2095 get_mips_segment_type (unsigned long type)
2099 case PT_MIPS_REGINFO:
2101 case PT_MIPS_RTPROC:
2103 case PT_MIPS_OPTIONS:
2113 get_parisc_segment_type (unsigned long type)
2117 case PT_HP_TLS: return "HP_TLS";
2118 case PT_HP_CORE_NONE: return "HP_CORE_NONE";
2119 case PT_HP_CORE_VERSION: return "HP_CORE_VERSION";
2120 case PT_HP_CORE_KERNEL: return "HP_CORE_KERNEL";
2121 case PT_HP_CORE_COMM: return "HP_CORE_COMM";
2122 case PT_HP_CORE_PROC: return "HP_CORE_PROC";
2123 case PT_HP_CORE_LOADABLE: return "HP_CORE_LOADABLE";
2124 case PT_HP_CORE_STACK: return "HP_CORE_STACK";
2125 case PT_HP_CORE_SHM: return "HP_CORE_SHM";
2126 case PT_HP_CORE_MMF: return "HP_CORE_MMF";
2127 case PT_HP_PARALLEL: return "HP_PARALLEL";
2128 case PT_HP_FASTBIND: return "HP_FASTBIND";
2129 case PT_PARISC_ARCHEXT: return "PARISC_ARCHEXT";
2130 case PT_PARISC_UNWIND: return "PARISC_UNWIND";
2139 get_ia64_segment_type (unsigned long type)
2143 case PT_IA_64_ARCHEXT: return "IA_64_ARCHEXT";
2144 case PT_IA_64_UNWIND: return "IA_64_UNWIND";
2145 case PT_HP_TLS: return "HP_TLS";
2146 case PT_IA_64_HP_OPT_ANOT: return "HP_OPT_ANNOT";
2147 case PT_IA_64_HP_HSL_ANOT: return "HP_HSL_ANNOT";
2148 case PT_IA_64_HP_STACK: return "HP_STACK";
2157 get_segment_type (unsigned long p_type)
2159 static char buff[32];
2163 case PT_NULL: return "NULL";
2164 case PT_LOAD: return "LOAD";
2165 case PT_DYNAMIC: return "DYNAMIC";
2166 case PT_INTERP: return "INTERP";
2167 case PT_NOTE: return "NOTE";
2168 case PT_SHLIB: return "SHLIB";
2169 case PT_PHDR: return "PHDR";
2170 case PT_TLS: return "TLS";
2172 case PT_GNU_EH_FRAME:
2173 return "GNU_EH_FRAME";
2174 case PT_GNU_STACK: return "STACK";
2177 if ((p_type >= PT_LOPROC) && (p_type <= PT_HIPROC))
2181 switch (elf_header.e_machine)
2184 case EM_MIPS_RS3_LE:
2185 result = get_mips_segment_type (p_type);
2188 result = get_parisc_segment_type (p_type);
2191 result = get_ia64_segment_type (p_type);
2201 sprintf (buff, "LOPROC+%lx", p_type - PT_LOPROC);
2203 else if ((p_type >= PT_LOOS) && (p_type <= PT_HIOS))
2207 switch (elf_header.e_machine)
2210 result = get_parisc_segment_type (p_type);
2213 result = get_ia64_segment_type (p_type);
2223 sprintf (buff, "LOOS+%lx", p_type - PT_LOOS);
2226 sprintf (buff, _("<unknown>: %lx"), p_type);
2233 get_mips_section_type_name (unsigned int sh_type)
2237 case SHT_MIPS_LIBLIST: return "MIPS_LIBLIST";
2238 case SHT_MIPS_MSYM: return "MIPS_MSYM";
2239 case SHT_MIPS_CONFLICT: return "MIPS_CONFLICT";
2240 case SHT_MIPS_GPTAB: return "MIPS_GPTAB";
2241 case SHT_MIPS_UCODE: return "MIPS_UCODE";
2242 case SHT_MIPS_DEBUG: return "MIPS_DEBUG";
2243 case SHT_MIPS_REGINFO: return "MIPS_REGINFO";
2244 case SHT_MIPS_PACKAGE: return "MIPS_PACKAGE";
2245 case SHT_MIPS_PACKSYM: return "MIPS_PACKSYM";
2246 case SHT_MIPS_RELD: return "MIPS_RELD";
2247 case SHT_MIPS_IFACE: return "MIPS_IFACE";
2248 case SHT_MIPS_CONTENT: return "MIPS_CONTENT";
2249 case SHT_MIPS_OPTIONS: return "MIPS_OPTIONS";
2250 case SHT_MIPS_SHDR: return "MIPS_SHDR";
2251 case SHT_MIPS_FDESC: return "MIPS_FDESC";
2252 case SHT_MIPS_EXTSYM: return "MIPS_EXTSYM";
2253 case SHT_MIPS_DENSE: return "MIPS_DENSE";
2254 case SHT_MIPS_PDESC: return "MIPS_PDESC";
2255 case SHT_MIPS_LOCSYM: return "MIPS_LOCSYM";
2256 case SHT_MIPS_AUXSYM: return "MIPS_AUXSYM";
2257 case SHT_MIPS_OPTSYM: return "MIPS_OPTSYM";
2258 case SHT_MIPS_LOCSTR: return "MIPS_LOCSTR";
2259 case SHT_MIPS_LINE: return "MIPS_LINE";
2260 case SHT_MIPS_RFDESC: return "MIPS_RFDESC";
2261 case SHT_MIPS_DELTASYM: return "MIPS_DELTASYM";
2262 case SHT_MIPS_DELTAINST: return "MIPS_DELTAINST";
2263 case SHT_MIPS_DELTACLASS: return "MIPS_DELTACLASS";
2264 case SHT_MIPS_DWARF: return "MIPS_DWARF";
2265 case SHT_MIPS_DELTADECL: return "MIPS_DELTADECL";
2266 case SHT_MIPS_SYMBOL_LIB: return "MIPS_SYMBOL_LIB";
2267 case SHT_MIPS_EVENTS: return "MIPS_EVENTS";
2268 case SHT_MIPS_TRANSLATE: return "MIPS_TRANSLATE";
2269 case SHT_MIPS_PIXIE: return "MIPS_PIXIE";
2270 case SHT_MIPS_XLATE: return "MIPS_XLATE";
2271 case SHT_MIPS_XLATE_DEBUG: return "MIPS_XLATE_DEBUG";
2272 case SHT_MIPS_WHIRL: return "MIPS_WHIRL";
2273 case SHT_MIPS_EH_REGION: return "MIPS_EH_REGION";
2274 case SHT_MIPS_XLATE_OLD: return "MIPS_XLATE_OLD";
2275 case SHT_MIPS_PDR_EXCEPTION: return "MIPS_PDR_EXCEPTION";
2283 get_parisc_section_type_name (unsigned int sh_type)
2287 case SHT_PARISC_EXT: return "PARISC_EXT";
2288 case SHT_PARISC_UNWIND: return "PARISC_UNWIND";
2289 case SHT_PARISC_DOC: return "PARISC_DOC";
2297 get_ia64_section_type_name (unsigned int sh_type)
2299 /* If the top 8 bits are 0x78 the next 8 are the os/abi ID. */
2300 if ((sh_type & 0xFF000000) == SHT_IA_64_LOPSREG)
2301 return get_osabi_name ((sh_type & 0x00FF0000) >> 16);
2305 case SHT_IA_64_EXT: return "IA_64_EXT";
2306 case SHT_IA_64_UNWIND: return "IA_64_UNWIND";
2307 case SHT_IA_64_PRIORITY_INIT: return "IA_64_PRIORITY_INIT";
2315 get_section_type_name (unsigned int sh_type)
2317 static char buff[32];
2321 case SHT_NULL: return "NULL";
2322 case SHT_PROGBITS: return "PROGBITS";
2323 case SHT_SYMTAB: return "SYMTAB";
2324 case SHT_STRTAB: return "STRTAB";
2325 case SHT_RELA: return "RELA";
2326 case SHT_HASH: return "HASH";
2327 case SHT_DYNAMIC: return "DYNAMIC";
2328 case SHT_NOTE: return "NOTE";
2329 case SHT_NOBITS: return "NOBITS";
2330 case SHT_REL: return "REL";
2331 case SHT_SHLIB: return "SHLIB";
2332 case SHT_DYNSYM: return "DYNSYM";
2333 case SHT_INIT_ARRAY: return "INIT_ARRAY";
2334 case SHT_FINI_ARRAY: return "FINI_ARRAY";
2335 case SHT_PREINIT_ARRAY: return "PREINIT_ARRAY";
2336 case SHT_GROUP: return "GROUP";
2337 case SHT_SYMTAB_SHNDX: return "SYMTAB SECTION INDICIES";
2338 case SHT_GNU_verdef: return "VERDEF";
2339 case SHT_GNU_verneed: return "VERNEED";
2340 case SHT_GNU_versym: return "VERSYM";
2341 case 0x6ffffff0: return "VERSYM";
2342 case 0x6ffffffc: return "VERDEF";
2343 case 0x7ffffffd: return "AUXILIARY";
2344 case 0x7fffffff: return "FILTER";
2345 case SHT_GNU_LIBLIST: return "GNU_LIBLIST";
2348 if ((sh_type >= SHT_LOPROC) && (sh_type <= SHT_HIPROC))
2352 switch (elf_header.e_machine)
2355 case EM_MIPS_RS3_LE:
2356 result = get_mips_section_type_name (sh_type);
2359 result = get_parisc_section_type_name (sh_type);
2362 result = get_ia64_section_type_name (sh_type);
2372 sprintf (buff, "LOPROC+%x", sh_type - SHT_LOPROC);
2374 else if ((sh_type >= SHT_LOOS) && (sh_type <= SHT_HIOS))
2375 sprintf (buff, "LOOS+%x", sh_type - SHT_LOOS);
2376 else if ((sh_type >= SHT_LOUSER) && (sh_type <= SHT_HIUSER))
2377 sprintf (buff, "LOUSER+%x", sh_type - SHT_LOUSER);
2379 sprintf (buff, _("<unknown>: %x"), sh_type);
2385 #define OPTION_DEBUG_DUMP 512
2387 struct option options[] =
2389 {"all", no_argument, 0, 'a'},
2390 {"file-header", no_argument, 0, 'h'},
2391 {"program-headers", no_argument, 0, 'l'},
2392 {"headers", no_argument, 0, 'e'},
2393 {"histogram", no_argument, 0, 'I'},
2394 {"segments", no_argument, 0, 'l'},
2395 {"sections", no_argument, 0, 'S'},
2396 {"section-headers", no_argument, 0, 'S'},
2397 {"section-groups", no_argument, 0, 'g'},
2398 {"symbols", no_argument, 0, 's'},
2399 {"syms", no_argument, 0, 's'},
2400 {"relocs", no_argument, 0, 'r'},
2401 {"notes", no_argument, 0, 'n'},
2402 {"dynamic", no_argument, 0, 'd'},
2403 {"arch-specific", no_argument, 0, 'A'},
2404 {"version-info", no_argument, 0, 'V'},
2405 {"use-dynamic", no_argument, 0, 'D'},
2406 {"hex-dump", required_argument, 0, 'x'},
2407 {"debug-dump", optional_argument, 0, OPTION_DEBUG_DUMP},
2408 {"unwind", no_argument, 0, 'u'},
2409 #ifdef SUPPORT_DISASSEMBLY
2410 {"instruction-dump", required_argument, 0, 'i'},
2413 {"version", no_argument, 0, 'v'},
2414 {"wide", no_argument, 0, 'W'},
2415 {"help", no_argument, 0, 'H'},
2416 {0, no_argument, 0, 0}
2422 fprintf (stdout, _("Usage: readelf <option(s)> elf-file(s)\n"));
2423 fprintf (stdout, _(" Display information about the contents of ELF format files\n"));
2424 fprintf (stdout, _(" Options are:\n\
2425 -a --all Equivalent to: -h -l -S -s -r -d -V -A -I\n\
2426 -h --file-header Display the ELF file header\n\
2427 -l --program-headers Display the program headers\n\
2428 --segments An alias for --program-headers\n\
2429 -S --section-headers Display the sections' header\n\
2430 --sections An alias for --section-headers\n\
2431 -g --section-groups Display the section groups\n\
2432 -e --headers Equivalent to: -h -l -S\n\
2433 -s --syms Display the symbol table\n\
2434 --symbols An alias for --syms\n\
2435 -n --notes Display the core notes (if present)\n\
2436 -r --relocs Display the relocations (if present)\n\
2437 -u --unwind Display the unwind info (if present)\n\
2438 -d --dynamic Display the dynamic segment (if present)\n\
2439 -V --version-info Display the version sections (if present)\n\
2440 -A --arch-specific Display architecture specific information (if any).\n\
2441 -D --use-dynamic Use the dynamic section info when displaying symbols\n\
2442 -x --hex-dump=<number> Dump the contents of section <number>\n\
2443 -w[liaprmfFso] or\n\
2444 --debug-dump[=line,=info,=abbrev,=pubnames,=ranges,=macro,=frames,=str,=loc]\n\
2445 Display the contents of DWARF2 debug sections\n"));
2446 #ifdef SUPPORT_DISASSEMBLY
2447 fprintf (stdout, _("\
2448 -i --instruction-dump=<number>\n\
2449 Disassemble the contents of section <number>\n"));
2451 fprintf (stdout, _("\
2452 -I --histogram Display histogram of bucket list lengths\n\
2453 -W --wide Allow output width to exceed 80 characters\n\
2454 -H --help Display this information\n\
2455 -v --version Display the version number of readelf\n"));
2456 fprintf (stdout, _("Report bugs to %s\n"), REPORT_BUGS_TO);
2462 request_dump (unsigned int section, int type)
2464 if (section >= num_dump_sects)
2466 char *new_dump_sects;
2468 new_dump_sects = calloc (section + 1, 1);
2470 if (new_dump_sects == NULL)
2471 error (_("Out of memory allocating dump request table."));
2474 /* Copy current flag settings. */
2475 memcpy (new_dump_sects, dump_sects, num_dump_sects);
2479 dump_sects = new_dump_sects;
2480 num_dump_sects = section + 1;
2485 dump_sects[section] |= type;
2491 parse_args (int argc, char **argv)
2498 while ((c = getopt_long
2499 (argc, argv, "ersuahnldSDAIgw::x:i:vVWH", options, NULL)) != EOF)
2520 do_section_groups++;
2528 do_section_groups++;
2570 section = strtoul (optarg, & cp, 0);
2571 if (! *cp && section >= 0)
2573 request_dump (section, HEX_DUMP);
2583 unsigned int index = 0;
2587 while (optarg[index])
2588 switch (optarg[index++])
2597 do_debug_abbrevs = 1;
2607 do_debug_pubnames = 1;
2612 do_debug_aranges = 1;
2616 do_debug_frames_interp = 1;
2618 do_debug_frames = 1;
2623 do_debug_macinfo = 1;
2637 warn (_("Unrecognized debug option '%s'\n"), optarg);
2642 case OPTION_DEBUG_DUMP:
2648 static const char *debug_dump_opt[]
2649 = { "line", "info", "abbrev", "pubnames", "ranges",
2650 "macro", "frames", "frames-interp", "str", "loc", NULL };
2659 for (index = 0; debug_dump_opt[index]; index++)
2661 size_t len = strlen (debug_dump_opt[index]);
2663 if (strncmp (p, debug_dump_opt[index], len) == 0
2664 && (p[len] == ',' || p[len] == '\0'))
2673 do_debug_abbrevs = 1;
2684 do_debug_pubnames = 1;
2688 do_debug_aranges = 1;
2693 do_debug_frames_interp = 1;
2694 do_debug_frames = 1;
2698 do_debug_macinfo = 1;
2711 if (debug_dump_opt[index] == NULL)
2713 warn (_("Unrecognized debug option '%s'\n"), p);
2714 p = strchr (p, ',');
2724 #ifdef SUPPORT_DISASSEMBLY
2727 section = strtoul (optarg, & cp, 0);
2728 if (! *cp && section >= 0)
2730 request_dump (section, DISASS_DUMP);
2736 print_version (program_name);
2746 /* xgettext:c-format */
2747 error (_("Invalid option '-%c'\n"), c);
2754 if (!do_dynamic && !do_syms && !do_reloc && !do_unwind && !do_sections
2755 && !do_segments && !do_header && !do_dump && !do_version
2756 && !do_histogram && !do_debugging && !do_arch && !do_notes
2757 && !do_section_groups)
2761 warn (_("Nothing to do.\n"));
2767 get_elf_class (unsigned int elf_class)
2769 static char buff[32];
2773 case ELFCLASSNONE: return _("none");
2774 case ELFCLASS32: return "ELF32";
2775 case ELFCLASS64: return "ELF64";
2777 sprintf (buff, _("<unknown: %x>"), elf_class);
2783 get_data_encoding (unsigned int encoding)
2785 static char buff[32];
2789 case ELFDATANONE: return _("none");
2790 case ELFDATA2LSB: return _("2's complement, little endian");
2791 case ELFDATA2MSB: return _("2's complement, big endian");
2793 sprintf (buff, _("<unknown: %x>"), encoding);
2798 /* Decode the data held in 'elf_header'. */
2801 process_file_header (void)
2803 if ( elf_header.e_ident[EI_MAG0] != ELFMAG0
2804 || elf_header.e_ident[EI_MAG1] != ELFMAG1
2805 || elf_header.e_ident[EI_MAG2] != ELFMAG2
2806 || elf_header.e_ident[EI_MAG3] != ELFMAG3)
2809 (_("Not an ELF file - it has the wrong magic bytes at the start\n"));
2817 printf (_("ELF Header:\n"));
2818 printf (_(" Magic: "));
2819 for (i = 0; i < EI_NIDENT; i++)
2820 printf ("%2.2x ", elf_header.e_ident[i]);
2822 printf (_(" Class: %s\n"),
2823 get_elf_class (elf_header.e_ident[EI_CLASS]));
2824 printf (_(" Data: %s\n"),
2825 get_data_encoding (elf_header.e_ident[EI_DATA]));
2826 printf (_(" Version: %d %s\n"),
2827 elf_header.e_ident[EI_VERSION],
2828 (elf_header.e_ident[EI_VERSION] == EV_CURRENT
2830 : (elf_header.e_ident[EI_VERSION] != EV_NONE
2833 printf (_(" OS/ABI: %s\n"),
2834 get_osabi_name (elf_header.e_ident[EI_OSABI]));
2835 printf (_(" ABI Version: %d\n"),
2836 elf_header.e_ident[EI_ABIVERSION]);
2837 printf (_(" Type: %s\n"),
2838 get_file_type (elf_header.e_type));
2839 printf (_(" Machine: %s\n"),
2840 get_machine_name (elf_header.e_machine));
2841 printf (_(" Version: 0x%lx\n"),
2842 (unsigned long) elf_header.e_version);
2844 printf (_(" Entry point address: "));
2845 print_vma ((bfd_vma) elf_header.e_entry, PREFIX_HEX);
2846 printf (_("\n Start of program headers: "));
2847 print_vma ((bfd_vma) elf_header.e_phoff, DEC);
2848 printf (_(" (bytes into file)\n Start of section headers: "));
2849 print_vma ((bfd_vma) elf_header.e_shoff, DEC);
2850 printf (_(" (bytes into file)\n"));
2852 printf (_(" Flags: 0x%lx%s\n"),
2853 (unsigned long) elf_header.e_flags,
2854 get_machine_flags (elf_header.e_flags, elf_header.e_machine));
2855 printf (_(" Size of this header: %ld (bytes)\n"),
2856 (long) elf_header.e_ehsize);
2857 printf (_(" Size of program headers: %ld (bytes)\n"),
2858 (long) elf_header.e_phentsize);
2859 printf (_(" Number of program headers: %ld\n"),
2860 (long) elf_header.e_phnum);
2861 printf (_(" Size of section headers: %ld (bytes)\n"),
2862 (long) elf_header.e_shentsize);
2863 printf (_(" Number of section headers: %ld"),
2864 (long) elf_header.e_shnum);
2865 if (section_headers != NULL && elf_header.e_shnum == 0)
2866 printf (" (%ld)", (long) section_headers[0].sh_size);
2867 putc ('\n', stdout);
2868 printf (_(" Section header string table index: %ld"),
2869 (long) elf_header.e_shstrndx);
2870 if (section_headers != NULL && elf_header.e_shstrndx == SHN_XINDEX)
2871 printf (" (%ld)", (long) section_headers[0].sh_link);
2872 putc ('\n', stdout);
2875 if (section_headers != NULL)
2877 if (elf_header.e_shnum == 0)
2878 elf_header.e_shnum = section_headers[0].sh_size;
2879 if (elf_header.e_shstrndx == SHN_XINDEX)
2880 elf_header.e_shstrndx = section_headers[0].sh_link;
2881 free (section_headers);
2882 section_headers = NULL;
2890 get_32bit_program_headers (FILE *file, Elf_Internal_Phdr *program_headers)
2892 Elf32_External_Phdr *phdrs;
2893 Elf32_External_Phdr *external;
2894 Elf_Internal_Phdr *internal;
2897 phdrs = get_data (NULL, file, elf_header.e_phoff,
2898 elf_header.e_phentsize * elf_header.e_phnum,
2899 _("program headers"));
2903 for (i = 0, internal = program_headers, external = phdrs;
2904 i < elf_header.e_phnum;
2905 i++, internal++, external++)
2907 internal->p_type = BYTE_GET (external->p_type);
2908 internal->p_offset = BYTE_GET (external->p_offset);
2909 internal->p_vaddr = BYTE_GET (external->p_vaddr);
2910 internal->p_paddr = BYTE_GET (external->p_paddr);
2911 internal->p_filesz = BYTE_GET (external->p_filesz);
2912 internal->p_memsz = BYTE_GET (external->p_memsz);
2913 internal->p_flags = BYTE_GET (external->p_flags);
2914 internal->p_align = BYTE_GET (external->p_align);
2923 get_64bit_program_headers (FILE *file, Elf_Internal_Phdr *program_headers)
2925 Elf64_External_Phdr *phdrs;
2926 Elf64_External_Phdr *external;
2927 Elf_Internal_Phdr *internal;
2930 phdrs = get_data (NULL, file, elf_header.e_phoff,
2931 elf_header.e_phentsize * elf_header.e_phnum,
2932 _("program headers"));
2936 for (i = 0, internal = program_headers, external = phdrs;
2937 i < elf_header.e_phnum;
2938 i++, internal++, external++)
2940 internal->p_type = BYTE_GET (external->p_type);
2941 internal->p_flags = BYTE_GET (external->p_flags);
2942 internal->p_offset = BYTE_GET8 (external->p_offset);
2943 internal->p_vaddr = BYTE_GET8 (external->p_vaddr);
2944 internal->p_paddr = BYTE_GET8 (external->p_paddr);
2945 internal->p_filesz = BYTE_GET8 (external->p_filesz);
2946 internal->p_memsz = BYTE_GET8 (external->p_memsz);
2947 internal->p_align = BYTE_GET8 (external->p_align);
2955 /* Returns 1 if the program headers were read into `program_headers'. */
2958 get_program_headers (FILE *file)
2960 Elf_Internal_Phdr *phdrs;
2962 /* Check cache of prior read. */
2963 if (program_headers != NULL)
2966 phdrs = malloc (elf_header.e_phnum * sizeof (Elf_Internal_Phdr));
2970 error (_("Out of memory\n"));
2975 ? get_32bit_program_headers (file, phdrs)
2976 : get_64bit_program_headers (file, phdrs))
2978 program_headers = phdrs;
2986 /* Returns 1 if the program headers were loaded. */
2989 process_program_headers (FILE *file)
2991 Elf_Internal_Phdr *segment;
2994 if (elf_header.e_phnum == 0)
2997 printf (_("\nThere are no program headers in this file.\n"));
3001 if (do_segments && !do_header)
3003 printf (_("\nElf file type is %s\n"), get_file_type (elf_header.e_type));
3004 printf (_("Entry point "));
3005 print_vma ((bfd_vma) elf_header.e_entry, PREFIX_HEX);
3006 printf (_("\nThere are %d program headers, starting at offset "),
3007 elf_header.e_phnum);
3008 print_vma ((bfd_vma) elf_header.e_phoff, DEC);
3012 if (! get_program_headers (file))
3017 if (elf_header.e_phnum > 1)
3018 printf (_("\nProgram Headers:\n"));
3020 printf (_("\nProgram Headers:\n"));
3024 (_(" Type Offset VirtAddr PhysAddr FileSiz MemSiz Flg Align\n"));
3027 (_(" Type Offset VirtAddr PhysAddr FileSiz MemSiz Flg Align\n"));
3031 (_(" Type Offset VirtAddr PhysAddr\n"));
3033 (_(" FileSiz MemSiz Flags Align\n"));
3040 for (i = 0, segment = program_headers;
3041 i < elf_header.e_phnum;
3046 printf (" %-14.14s ", get_segment_type (segment->p_type));
3050 printf ("0x%6.6lx ", (unsigned long) segment->p_offset);
3051 printf ("0x%8.8lx ", (unsigned long) segment->p_vaddr);
3052 printf ("0x%8.8lx ", (unsigned long) segment->p_paddr);
3053 printf ("0x%5.5lx ", (unsigned long) segment->p_filesz);
3054 printf ("0x%5.5lx ", (unsigned long) segment->p_memsz);
3056 (segment->p_flags & PF_R ? 'R' : ' '),
3057 (segment->p_flags & PF_W ? 'W' : ' '),
3058 (segment->p_flags & PF_X ? 'E' : ' '));
3059 printf ("%#lx", (unsigned long) segment->p_align);
3063 if ((unsigned long) segment->p_offset == segment->p_offset)
3064 printf ("0x%6.6lx ", (unsigned long) segment->p_offset);
3067 print_vma (segment->p_offset, FULL_HEX);
3071 print_vma (segment->p_vaddr, FULL_HEX);
3073 print_vma (segment->p_paddr, FULL_HEX);
3076 if ((unsigned long) segment->p_filesz == segment->p_filesz)
3077 printf ("0x%6.6lx ", (unsigned long) segment->p_filesz);
3080 print_vma (segment->p_filesz, FULL_HEX);
3084 if ((unsigned long) segment->p_memsz == segment->p_memsz)
3085 printf ("0x%6.6lx", (unsigned long) segment->p_memsz);
3088 print_vma (segment->p_offset, FULL_HEX);
3092 (segment->p_flags & PF_R ? 'R' : ' '),
3093 (segment->p_flags & PF_W ? 'W' : ' '),
3094 (segment->p_flags & PF_X ? 'E' : ' '));
3096 if ((unsigned long) segment->p_align == segment->p_align)
3097 printf ("%#lx", (unsigned long) segment->p_align);
3100 print_vma (segment->p_align, PREFIX_HEX);
3105 print_vma (segment->p_offset, FULL_HEX);
3107 print_vma (segment->p_vaddr, FULL_HEX);
3109 print_vma (segment->p_paddr, FULL_HEX);
3111 print_vma (segment->p_filesz, FULL_HEX);
3113 print_vma (segment->p_memsz, FULL_HEX);
3115 (segment->p_flags & PF_R ? 'R' : ' '),
3116 (segment->p_flags & PF_W ? 'W' : ' '),
3117 (segment->p_flags & PF_X ? 'E' : ' '));
3118 print_vma (segment->p_align, HEX);
3122 switch (segment->p_type)
3126 error (_("more than one dynamic segment\n"));
3128 dynamic_addr = segment->p_offset;
3129 dynamic_size = segment->p_filesz;
3133 if (fseek (file, archive_file_offset + (long) segment->p_offset,
3135 error (_("Unable to find program interpreter name\n"));
3138 program_interpreter[0] = 0;
3139 fscanf (file, "%63s", program_interpreter);
3142 printf (_("\n [Requesting program interpreter: %s]"),
3143 program_interpreter);
3149 putc ('\n', stdout);
3152 if (do_segments && section_headers != NULL)
3154 printf (_("\n Section to Segment mapping:\n"));
3155 printf (_(" Segment Sections...\n"));
3157 assert (string_table != NULL);
3159 for (i = 0; i < elf_header.e_phnum; i++)
3162 Elf_Internal_Shdr *section;
3164 segment = program_headers + i;
3165 section = section_headers;
3167 printf (" %2.2d ", i);
3169 for (j = 1; j < elf_header.e_shnum; j++, section++)
3171 if (section->sh_size > 0
3172 /* Compare allocated sections by VMA, unallocated
3173 sections by file offset. */
3174 && (section->sh_flags & SHF_ALLOC
3175 ? (section->sh_addr >= segment->p_vaddr
3176 && section->sh_addr + section->sh_size
3177 <= segment->p_vaddr + segment->p_memsz)
3178 : ((bfd_vma) section->sh_offset >= segment->p_offset
3179 && (section->sh_offset + section->sh_size
3180 <= segment->p_offset + segment->p_filesz))))
3181 printf ("%s ", SECTION_NAME (section));
3192 /* Find the file offset corresponding to VMA by using the program headers. */
3195 offset_from_vma (FILE *file, bfd_vma vma, bfd_size_type size)
3197 Elf_Internal_Phdr *seg;
3199 if (! get_program_headers (file))
3201 warn (_("Cannot interpret virtual addresses without program headers.\n"));
3205 for (seg = program_headers;
3206 seg < program_headers + elf_header.e_phnum;
3209 if (seg->p_type != PT_LOAD)
3212 if (vma >= (seg->p_vaddr & -seg->p_align)
3213 && vma + size <= seg->p_vaddr + seg->p_filesz)
3214 return vma - seg->p_vaddr + seg->p_offset;
3217 warn (_("Virtual address 0x%lx not located in any PT_LOAD segment.\n"),
3224 get_32bit_section_headers (FILE *file, unsigned int num)
3226 Elf32_External_Shdr *shdrs;
3227 Elf_Internal_Shdr *internal;
3230 shdrs = get_data (NULL, file, elf_header.e_shoff,
3231 elf_header.e_shentsize * num, _("section headers"));
3235 section_headers = malloc (num * sizeof (Elf_Internal_Shdr));
3237 if (section_headers == NULL)
3239 error (_("Out of memory\n"));
3243 for (i = 0, internal = section_headers;
3247 internal->sh_name = BYTE_GET (shdrs[i].sh_name);
3248 internal->sh_type = BYTE_GET (shdrs[i].sh_type);
3249 internal->sh_flags = BYTE_GET (shdrs[i].sh_flags);
3250 internal->sh_addr = BYTE_GET (shdrs[i].sh_addr);
3251 internal->sh_offset = BYTE_GET (shdrs[i].sh_offset);
3252 internal->sh_size = BYTE_GET (shdrs[i].sh_size);
3253 internal->sh_link = BYTE_GET (shdrs[i].sh_link);
3254 internal->sh_info = BYTE_GET (shdrs[i].sh_info);
3255 internal->sh_addralign = BYTE_GET (shdrs[i].sh_addralign);
3256 internal->sh_entsize = BYTE_GET (shdrs[i].sh_entsize);
3265 get_64bit_section_headers (FILE *file, unsigned int num)
3267 Elf64_External_Shdr *shdrs;
3268 Elf_Internal_Shdr *internal;
3271 shdrs = get_data (NULL, file, elf_header.e_shoff,
3272 elf_header.e_shentsize * num, _("section headers"));
3276 section_headers = malloc (num * sizeof (Elf_Internal_Shdr));
3278 if (section_headers == NULL)
3280 error (_("Out of memory\n"));
3284 for (i = 0, internal = section_headers;
3288 internal->sh_name = BYTE_GET (shdrs[i].sh_name);
3289 internal->sh_type = BYTE_GET (shdrs[i].sh_type);
3290 internal->sh_flags = BYTE_GET8 (shdrs[i].sh_flags);
3291 internal->sh_addr = BYTE_GET8 (shdrs[i].sh_addr);
3292 internal->sh_size = BYTE_GET8 (shdrs[i].sh_size);
3293 internal->sh_entsize = BYTE_GET8 (shdrs[i].sh_entsize);
3294 internal->sh_link = BYTE_GET (shdrs[i].sh_link);
3295 internal->sh_info = BYTE_GET (shdrs[i].sh_info);
3296 internal->sh_offset = BYTE_GET (shdrs[i].sh_offset);
3297 internal->sh_addralign = BYTE_GET (shdrs[i].sh_addralign);
3305 static Elf_Internal_Sym *
3306 get_32bit_elf_symbols (FILE *file, Elf_Internal_Shdr *section)
3308 unsigned long number;
3309 Elf32_External_Sym *esyms;
3310 Elf_External_Sym_Shndx *shndx;
3311 Elf_Internal_Sym *isyms;
3312 Elf_Internal_Sym *psym;
3315 esyms = get_data (NULL, file, section->sh_offset, section->sh_size,
3321 if (symtab_shndx_hdr != NULL
3322 && (symtab_shndx_hdr->sh_link
3323 == (unsigned long) SECTION_HEADER_NUM (section - section_headers)))
3325 shndx = get_data (NULL, file, symtab_shndx_hdr->sh_offset,
3326 symtab_shndx_hdr->sh_size, _("symtab shndx"));
3334 number = section->sh_size / section->sh_entsize;
3335 isyms = malloc (number * sizeof (Elf_Internal_Sym));
3339 error (_("Out of memory\n"));
3346 for (j = 0, psym = isyms;
3350 psym->st_name = BYTE_GET (esyms[j].st_name);
3351 psym->st_value = BYTE_GET (esyms[j].st_value);
3352 psym->st_size = BYTE_GET (esyms[j].st_size);
3353 psym->st_shndx = BYTE_GET (esyms[j].st_shndx);
3354 if (psym->st_shndx == SHN_XINDEX && shndx != NULL)
3356 = byte_get ((unsigned char *) &shndx[j], sizeof (shndx[j]));
3357 psym->st_info = BYTE_GET (esyms[j].st_info);
3358 psym->st_other = BYTE_GET (esyms[j].st_other);
3368 static Elf_Internal_Sym *
3369 get_64bit_elf_symbols (FILE *file, Elf_Internal_Shdr *section)
3371 unsigned long number;
3372 Elf64_External_Sym *esyms;
3373 Elf_External_Sym_Shndx *shndx;
3374 Elf_Internal_Sym *isyms;
3375 Elf_Internal_Sym *psym;
3378 esyms = get_data (NULL, file, section->sh_offset, section->sh_size,
3384 if (symtab_shndx_hdr != NULL
3385 && (symtab_shndx_hdr->sh_link
3386 == (unsigned long) SECTION_HEADER_NUM (section - section_headers)))
3388 shndx = get_data (NULL, file, symtab_shndx_hdr->sh_offset,
3389 symtab_shndx_hdr->sh_size, _("symtab shndx"));
3397 number = section->sh_size / section->sh_entsize;
3398 isyms = malloc (number * sizeof (Elf_Internal_Sym));
3402 error (_("Out of memory\n"));
3409 for (j = 0, psym = isyms;
3413 psym->st_name = BYTE_GET (esyms[j].st_name);
3414 psym->st_info = BYTE_GET (esyms[j].st_info);
3415 psym->st_other = BYTE_GET (esyms[j].st_other);
3416 psym->st_shndx = BYTE_GET (esyms[j].st_shndx);
3417 if (psym->st_shndx == SHN_XINDEX && shndx != NULL)
3419 = byte_get ((unsigned char *) &shndx[j], sizeof (shndx[j]));
3420 psym->st_value = BYTE_GET8 (esyms[j].st_value);
3421 psym->st_size = BYTE_GET8 (esyms[j].st_size);
3432 get_elf_section_flags (bfd_vma sh_flags)
3434 static char buff[32];
3442 flag = sh_flags & - sh_flags;
3447 case SHF_WRITE: strcat (buff, "W"); break;
3448 case SHF_ALLOC: strcat (buff, "A"); break;
3449 case SHF_EXECINSTR: strcat (buff, "X"); break;
3450 case SHF_MERGE: strcat (buff, "M"); break;
3451 case SHF_STRINGS: strcat (buff, "S"); break;
3452 case SHF_INFO_LINK: strcat (buff, "I"); break;
3453 case SHF_LINK_ORDER: strcat (buff, "L"); break;
3454 case SHF_OS_NONCONFORMING: strcat (buff, "O"); break;
3455 case SHF_GROUP: strcat (buff, "G"); break;
3456 case SHF_TLS: strcat (buff, "T"); break;
3459 if (flag & SHF_MASKOS)
3462 sh_flags &= ~ SHF_MASKOS;
3464 else if (flag & SHF_MASKPROC)
3467 sh_flags &= ~ SHF_MASKPROC;
3479 process_section_headers (FILE *file)
3481 Elf_Internal_Shdr *section;
3484 section_headers = NULL;
3486 if (elf_header.e_shnum == 0)
3489 printf (_("\nThere are no sections in this file.\n"));
3494 if (do_sections && !do_header)
3495 printf (_("There are %d section headers, starting at offset 0x%lx:\n"),
3496 elf_header.e_shnum, (unsigned long) elf_header.e_shoff);
3500 if (! get_32bit_section_headers (file, elf_header.e_shnum))
3503 else if (! get_64bit_section_headers (file, elf_header.e_shnum))
3506 /* Read in the string table, so that we have names to display. */
3507 section = SECTION_HEADER (elf_header.e_shstrndx);
3509 if (section->sh_size != 0)
3511 string_table = get_data (NULL, file, section->sh_offset,
3512 section->sh_size, _("string table"));
3514 if (string_table == NULL)
3517 string_table_length = section->sh_size;
3520 /* Scan the sections for the dynamic symbol table
3521 and dynamic string table and debug sections. */
3522 dynamic_symbols = NULL;
3523 dynamic_strings = NULL;
3524 dynamic_syminfo = NULL;
3525 symtab_shndx_hdr = NULL;
3527 for (i = 0, section = section_headers;
3528 i < elf_header.e_shnum;
3531 char *name = SECTION_NAME (section);
3533 if (section->sh_type == SHT_DYNSYM)
3535 if (dynamic_symbols != NULL)
3537 error (_("File contains multiple dynamic symbol tables\n"));
3541 num_dynamic_syms = section->sh_size / section->sh_entsize;
3542 dynamic_symbols = GET_ELF_SYMBOLS (file, section);
3544 else if (section->sh_type == SHT_STRTAB
3545 && strcmp (name, ".dynstr") == 0)
3547 if (dynamic_strings != NULL)
3549 error (_("File contains multiple dynamic string tables\n"));
3553 dynamic_strings = get_data (NULL, file, section->sh_offset,
3554 section->sh_size, _("dynamic strings"));
3556 else if (section->sh_type == SHT_SYMTAB_SHNDX)
3558 if (symtab_shndx_hdr != NULL)
3560 error (_("File contains multiple symtab shndx tables\n"));
3563 symtab_shndx_hdr = section;
3565 else if ((do_debugging || do_debug_info || do_debug_abbrevs
3566 || do_debug_lines || do_debug_pubnames || do_debug_aranges
3567 || do_debug_frames || do_debug_macinfo || do_debug_str
3569 && strncmp (name, ".debug_", 7) == 0)
3574 || (do_debug_info && (strcmp (name, "info") == 0))
3575 || (do_debug_abbrevs && (strcmp (name, "abbrev") == 0))
3576 || (do_debug_lines && (strcmp (name, "line") == 0))
3577 || (do_debug_pubnames && (strcmp (name, "pubnames") == 0))
3578 || (do_debug_aranges && (strcmp (name, "aranges") == 0))
3579 || (do_debug_frames && (strcmp (name, "frame") == 0))
3580 || (do_debug_macinfo && (strcmp (name, "macinfo") == 0))
3581 || (do_debug_str && (strcmp (name, "str") == 0))
3582 || (do_debug_loc && (strcmp (name, "loc") == 0))
3584 request_dump (i, DEBUG_DUMP);
3586 /* linkonce section to be combined with .debug_info at link time. */
3587 else if ((do_debugging || do_debug_info)
3588 && strncmp (name, ".gnu.linkonce.wi.", 17) == 0)
3589 request_dump (i, DEBUG_DUMP);
3590 else if (do_debug_frames && strcmp (name, ".eh_frame") == 0)
3591 request_dump (i, DEBUG_DUMP);
3597 if (elf_header.e_shnum > 1)
3598 printf (_("\nSection Headers:\n"));
3600 printf (_("\nSection Header:\n"));
3604 (_(" [Nr] Name Type Addr Off Size ES Flg Lk Inf Al\n"));
3607 (_(" [Nr] Name Type Address Off Size ES Flg Lk Inf Al\n"));
3610 printf (_(" [Nr] Name Type Address Offset\n"));
3611 printf (_(" Size EntSize Flags Link Info Align\n"));
3614 for (i = 0, section = section_headers;
3615 i < elf_header.e_shnum;
3618 printf (" [%2u] %-17.17s %-15.15s ",
3619 SECTION_HEADER_NUM (i),
3620 SECTION_NAME (section),
3621 get_section_type_name (section->sh_type));
3625 print_vma (section->sh_addr, LONG_HEX);
3627 printf ( " %6.6lx %6.6lx %2.2lx",
3628 (unsigned long) section->sh_offset,
3629 (unsigned long) section->sh_size,
3630 (unsigned long) section->sh_entsize);
3632 printf (" %3s ", get_elf_section_flags (section->sh_flags));
3634 printf ("%2ld %3lx %2ld\n",
3635 (unsigned long) section->sh_link,
3636 (unsigned long) section->sh_info,
3637 (unsigned long) section->sh_addralign);
3641 print_vma (section->sh_addr, LONG_HEX);
3643 if ((long) section->sh_offset == section->sh_offset)
3644 printf (" %6.6lx", (unsigned long) section->sh_offset);
3648 print_vma (section->sh_offset, LONG_HEX);
3651 if ((unsigned long) section->sh_size == section->sh_size)
3652 printf (" %6.6lx", (unsigned long) section->sh_size);
3656 print_vma (section->sh_size, LONG_HEX);
3659 if ((unsigned long) section->sh_entsize == section->sh_entsize)
3660 printf (" %2.2lx", (unsigned long) section->sh_entsize);
3664 print_vma (section->sh_entsize, LONG_HEX);
3667 printf (" %3s ", get_elf_section_flags (section->sh_flags));
3669 printf ("%2ld %3lx ",
3670 (unsigned long) section->sh_link,
3671 (unsigned long) section->sh_info);
3673 if ((unsigned long) section->sh_addralign == section->sh_addralign)
3674 printf ("%2ld\n", (unsigned long) section->sh_addralign);
3677 print_vma (section->sh_addralign, DEC);
3684 print_vma (section->sh_addr, LONG_HEX);
3685 if ((long) section->sh_offset == section->sh_offset)
3686 printf (" %8.8lx", (unsigned long) section->sh_offset);
3690 print_vma (section->sh_offset, LONG_HEX);
3693 print_vma (section->sh_size, LONG_HEX);
3695 print_vma (section->sh_entsize, LONG_HEX);
3697 printf (" %3s ", get_elf_section_flags (section->sh_flags));
3699 printf (" %2ld %3lx %ld\n",
3700 (unsigned long) section->sh_link,
3701 (unsigned long) section->sh_info,
3702 (unsigned long) section->sh_addralign);
3706 printf (_("Key to Flags:\n\
3707 W (write), A (alloc), X (execute), M (merge), S (strings)\n\
3708 I (info), L (link order), G (group), x (unknown)\n\
3709 O (extra OS processing required) o (OS specific), p (processor specific)\n"));
3715 get_group_flags (unsigned int flags)
3717 static char buff[32];
3724 sprintf (buff, _("[<unknown>: 0x%x]"), flags);
3731 process_section_groups (FILE *file)
3733 Elf_Internal_Shdr *section;
3736 if (!do_section_groups)
3739 if (elf_header.e_shnum == 0)
3741 if (do_section_groups)
3742 printf (_("\nThere are no section groups in this file.\n"));
3747 if (section_headers == NULL)
3749 error (_("Section headers are not available!\n"));
3753 /* Scan the sections for the group section. */
3754 for (i = 0, section = section_headers;
3755 i < elf_header.e_shnum;
3758 if (section->sh_type == SHT_GROUP)
3760 char *name = SECTION_NAME (section);
3761 char *group_name, *strtab, *start, *indices;
3762 unsigned int entry, j, size;
3763 Elf_Internal_Sym *sym;
3764 Elf_Internal_Shdr *symtab_sec, *strtab_sec, *sec;
3765 Elf_Internal_Sym *symtab;
3767 /* Get the symbol table. */
3768 symtab_sec = SECTION_HEADER (section->sh_link);
3769 if (symtab_sec->sh_type != SHT_SYMTAB)
3771 error (_("Bad sh_link in group section `%s'\n"), name);
3774 symtab = GET_ELF_SYMBOLS (file, symtab_sec);
3776 sym = symtab + section->sh_info;
3778 if (ELF_ST_TYPE (sym->st_info) == STT_SECTION)
3780 bfd_vma sec_index = SECTION_HEADER_INDEX (sym->st_shndx);
3783 error (_("Bad sh_info in group section `%s'\n"), name);
3787 group_name = SECTION_NAME (section_headers + sec_index);
3792 /* Get the string table. */
3793 strtab_sec = SECTION_HEADER (symtab_sec->sh_link);
3794 strtab = get_data (NULL, file, strtab_sec->sh_offset,
3795 strtab_sec->sh_size,
3798 group_name = strtab + sym->st_name;
3801 start = get_data (NULL, file, section->sh_offset,
3802 section->sh_size, _("section data"));
3805 size = (section->sh_size / section->sh_entsize) - 1;
3806 entry = byte_get (indices, 4);
3808 printf ("\n%s group section `%s' [%s] contains %u sections:\n",
3809 get_group_flags (entry), name, group_name, size);
3811 printf (_(" [Index] Name\n"));
3812 for (j = 0; j < size; j++)
3814 entry = byte_get (indices, 4);
3817 sec = SECTION_HEADER (entry);
3818 printf (" [%5u] %s\n",
3819 entry, SECTION_NAME (sec));
3838 } dynamic_relocations [] =
3840 { "REL", DT_REL, DT_RELSZ, FALSE },
3841 { "RELA", DT_RELA, DT_RELASZ, TRUE },
3842 { "PLT", DT_JMPREL, DT_PLTRELSZ, UNKNOWN }
3845 /* Process the reloc section. */
3847 process_relocs (FILE *file)
3849 unsigned long rel_size;
3850 unsigned long rel_offset;
3856 if (do_using_dynamic)
3860 int has_dynamic_reloc;
3863 has_dynamic_reloc = 0;
3865 for (i = 0; i < ARRAY_SIZE (dynamic_relocations); i++)
3867 is_rela = dynamic_relocations [i].rela;
3868 name = dynamic_relocations [i].name;
3869 rel_size = dynamic_info [dynamic_relocations [i].size];
3870 rel_offset = dynamic_info [dynamic_relocations [i].reloc];
3872 has_dynamic_reloc |= rel_size;
3874 if (is_rela == UNKNOWN)
3876 if (dynamic_relocations [i].reloc == DT_JMPREL)
3877 switch (dynamic_info[DT_PLTREL])
3891 (_("\n'%s' relocation section at offset 0x%lx contains %ld bytes:\n"),
3892 name, rel_offset, rel_size);
3894 dump_relocations (file,
3895 offset_from_vma (file, rel_offset, rel_size),
3897 dynamic_symbols, num_dynamic_syms,
3898 dynamic_strings, is_rela);
3902 if (! has_dynamic_reloc)
3903 printf (_("\nThere are no dynamic relocations in this file.\n"));
3907 Elf_Internal_Shdr *section;
3911 for (i = 0, section = section_headers;
3912 i < elf_header.e_shnum;
3915 if ( section->sh_type != SHT_RELA
3916 && section->sh_type != SHT_REL)
3919 rel_offset = section->sh_offset;
3920 rel_size = section->sh_size;
3924 Elf_Internal_Shdr *strsec;
3925 Elf_Internal_Sym *symtab;
3928 unsigned long nsyms;
3930 printf (_("\nRelocation section "));
3932 if (string_table == NULL)
3933 printf ("%d", section->sh_name);
3935 printf (_("'%s'"), SECTION_NAME (section));
3937 printf (_(" at offset 0x%lx contains %lu entries:\n"),
3938 rel_offset, (unsigned long) (rel_size / section->sh_entsize));
3943 if (section->sh_link)
3945 Elf_Internal_Shdr *symsec;
3947 symsec = SECTION_HEADER (section->sh_link);
3948 nsyms = symsec->sh_size / symsec->sh_entsize;
3949 symtab = GET_ELF_SYMBOLS (file, symsec);
3954 strsec = SECTION_HEADER (symsec->sh_link);
3956 strtab = get_data (NULL, file, strsec->sh_offset,
3957 strsec->sh_size, _("string table"));
3959 is_rela = section->sh_type == SHT_RELA;
3961 dump_relocations (file, rel_offset, rel_size,
3962 symtab, nsyms, strtab, is_rela);
3974 printf (_("\nThere are no relocations in this file.\n"));
3980 #include "unwind-ia64.h"
3982 /* An absolute address consists of a section and an offset. If the
3983 section is NULL, the offset itself is the address, otherwise, the
3984 address equals to LOAD_ADDRESS(section) + offset. */
3988 unsigned short section;
3994 struct unw_table_entry
3996 struct absaddr start;
3998 struct absaddr info;
4000 *table; /* Unwind table. */
4001 unsigned long table_len; /* Length of unwind table. */
4002 unsigned char *info; /* Unwind info. */
4003 unsigned long info_size; /* Size of unwind info. */
4004 bfd_vma info_addr; /* starting address of unwind info. */
4005 bfd_vma seg_base; /* Starting address of segment. */
4006 Elf_Internal_Sym *symtab; /* The symbol table. */
4007 unsigned long nsyms; /* Number of symbols. */
4008 char *strtab; /* The string table. */
4009 unsigned long strtab_size; /* Size of string table. */
4013 find_symbol_for_address (struct unw_aux_info *aux,
4014 struct absaddr addr,
4015 const char **symname,
4018 bfd_vma dist = 0x100000;
4019 Elf_Internal_Sym *sym, *best = NULL;
4022 for (i = 0, sym = aux->symtab; i < aux->nsyms; ++i, ++sym)
4024 if (ELF_ST_TYPE (sym->st_info) == STT_FUNC
4025 && sym->st_name != 0
4026 && (addr.section == SHN_UNDEF || addr.section == sym->st_shndx)
4027 && addr.offset >= sym->st_value
4028 && addr.offset - sym->st_value < dist)
4031 dist = addr.offset - sym->st_value;
4038 *symname = (best->st_name >= aux->strtab_size
4039 ? "<corrupt>" : aux->strtab + best->st_name);
4044 *offset = addr.offset;
4048 dump_ia64_unwind (struct unw_aux_info *aux)
4051 struct unw_table_entry *tp;
4054 addr_size = is_32bit_elf ? 4 : 8;
4056 for (tp = aux->table; tp < aux->table + aux->table_len; ++tp)
4060 const unsigned char *dp;
4061 const unsigned char *head;
4062 const char *procname;
4064 find_symbol_for_address (aux, tp->start, &procname, &offset);
4066 fputs ("\n<", stdout);
4070 fputs (procname, stdout);
4073 printf ("+%lx", (unsigned long) offset);
4076 fputs (">: [", stdout);
4077 print_vma (tp->start.offset, PREFIX_HEX);
4078 fputc ('-', stdout);
4079 print_vma (tp->end.offset, PREFIX_HEX);
4080 printf ("], info at +0x%lx\n",
4081 (unsigned long) (tp->info.offset - aux->seg_base));
4083 head = aux->info + (tp->info.offset - aux->info_addr);
4084 stamp = BYTE_GET8 ((unsigned char *) head);
4086 printf (" v%u, flags=0x%lx (%s%s), len=%lu bytes\n",
4087 (unsigned) UNW_VER (stamp),
4088 (unsigned long) ((stamp & UNW_FLAG_MASK) >> 32),
4089 UNW_FLAG_EHANDLER (stamp) ? " ehandler" : "",
4090 UNW_FLAG_UHANDLER (stamp) ? " uhandler" : "",
4091 (unsigned long) (addr_size * UNW_LENGTH (stamp)));
4093 if (UNW_VER (stamp) != 1)
4095 printf ("\tUnknown version.\n");
4100 for (dp = head + 8; dp < head + 8 + addr_size * UNW_LENGTH (stamp);)
4101 dp = unw_decode (dp, in_body, & in_body);
4106 slurp_ia64_unwind_table (FILE *file,
4107 struct unw_aux_info *aux,
4108 Elf_Internal_Shdr *sec)
4110 unsigned long size, addr_size, nrelas, i;
4111 Elf_Internal_Phdr *seg;
4112 struct unw_table_entry *tep;
4113 Elf_Internal_Shdr *relsec;
4114 Elf_Internal_Rela *rela, *rp;
4115 unsigned char *table, *tp;
4116 Elf_Internal_Sym *sym;
4117 const char *relname;
4119 addr_size = is_32bit_elf ? 4 : 8;
4121 /* First, find the starting address of the segment that includes
4124 if (elf_header.e_phnum)
4126 if (! get_program_headers (file))
4129 for (seg = program_headers;
4130 seg < program_headers + elf_header.e_phnum;
4133 if (seg->p_type != PT_LOAD)
4136 if (sec->sh_addr >= seg->p_vaddr
4137 && (sec->sh_addr + sec->sh_size <= seg->p_vaddr + seg->p_memsz))
4139 aux->seg_base = seg->p_vaddr;
4145 /* Second, build the unwind table from the contents of the unwind section: */
4146 size = sec->sh_size;
4147 table = get_data (NULL, file, sec->sh_offset, size, _("unwind table"));
4151 tep = aux->table = xmalloc (size / (3 * addr_size) * sizeof (aux->table[0]));
4152 for (tp = table; tp < table + size; tp += 3 * addr_size, ++tep)
4154 tep->start.section = SHN_UNDEF;
4155 tep->end.section = SHN_UNDEF;
4156 tep->info.section = SHN_UNDEF;
4159 tep->start.offset = byte_get ((unsigned char *) tp + 0, 4);
4160 tep->end.offset = byte_get ((unsigned char *) tp + 4, 4);
4161 tep->info.offset = byte_get ((unsigned char *) tp + 8, 4);
4165 tep->start.offset = BYTE_GET8 ((unsigned char *) tp + 0);
4166 tep->end.offset = BYTE_GET8 ((unsigned char *) tp + 8);
4167 tep->info.offset = BYTE_GET8 ((unsigned char *) tp + 16);
4169 tep->start.offset += aux->seg_base;
4170 tep->end.offset += aux->seg_base;
4171 tep->info.offset += aux->seg_base;
4175 /* Third, apply any relocations to the unwind table: */
4177 for (relsec = section_headers;
4178 relsec < section_headers + elf_header.e_shnum;
4181 if (relsec->sh_type != SHT_RELA
4182 || SECTION_HEADER (relsec->sh_info) != sec)
4185 if (!slurp_rela_relocs (file, relsec->sh_offset, relsec->sh_size,
4189 for (rp = rela; rp < rela + nrelas; ++rp)
4193 relname = elf_ia64_reloc_type (ELF32_R_TYPE (rp->r_info));
4194 sym = aux->symtab + ELF32_R_SYM (rp->r_info);
4196 if (ELF32_ST_TYPE (sym->st_info) != STT_SECTION)
4198 warn (_("Skipping unexpected symbol type %u\n"),
4199 ELF32_ST_TYPE (sym->st_info));
4205 relname = elf_ia64_reloc_type (ELF64_R_TYPE (rp->r_info));
4206 sym = aux->symtab + ELF64_R_SYM (rp->r_info);
4208 if (ELF64_ST_TYPE (sym->st_info) != STT_SECTION)
4210 warn (_("Skipping unexpected symbol type %u\n"),
4211 ELF64_ST_TYPE (sym->st_info));
4216 if (strncmp (relname, "R_IA64_SEGREL", 13) != 0)
4218 warn (_("Skipping unexpected relocation type %s\n"), relname);
4222 i = rp->r_offset / (3 * addr_size);
4224 switch (rp->r_offset/addr_size % 3)
4227 aux->table[i].start.section = sym->st_shndx;
4228 aux->table[i].start.offset += rp->r_addend;
4231 aux->table[i].end.section = sym->st_shndx;
4232 aux->table[i].end.offset += rp->r_addend;
4235 aux->table[i].info.section = sym->st_shndx;
4236 aux->table[i].info.offset += rp->r_addend;
4246 aux->table_len = size / (3 * addr_size);
4251 process_unwind (FILE *file)
4253 Elf_Internal_Shdr *sec, *unwsec = NULL, *strsec;
4254 unsigned long i, addr_size, unwcount = 0, unwstart = 0;
4255 struct unw_aux_info aux;
4260 if (elf_header.e_machine != EM_IA_64)
4262 printf (_("\nThere are no unwind sections in this file.\n"));
4266 memset (& aux, 0, sizeof (aux));
4268 addr_size = is_32bit_elf ? 4 : 8;
4270 for (i = 0, sec = section_headers; i < elf_header.e_shnum; ++i, ++sec)
4272 if (sec->sh_type == SHT_SYMTAB)
4274 aux.nsyms = sec->sh_size / sec->sh_entsize;
4275 aux.symtab = GET_ELF_SYMBOLS (file, sec);
4277 strsec = SECTION_HEADER (sec->sh_link);
4278 aux.strtab_size = strsec->sh_size;
4279 aux.strtab = get_data (NULL, file, strsec->sh_offset,
4280 aux.strtab_size, _("string table"));
4282 else if (sec->sh_type == SHT_IA_64_UNWIND)
4287 printf (_("\nThere are no unwind sections in this file.\n"));
4289 while (unwcount-- > 0)
4294 for (i = unwstart, sec = section_headers + unwstart;
4295 i < elf_header.e_shnum; ++i, ++sec)
4296 if (sec->sh_type == SHT_IA_64_UNWIND)
4303 len = sizeof (ELF_STRING_ia64_unwind_once) - 1;
4305 if (strncmp (SECTION_NAME (unwsec), ELF_STRING_ia64_unwind_once,
4308 /* .gnu.linkonce.ia64unw.FOO -> .gnu.linkonce.ia64unwi.FOO */
4309 len2 = sizeof (ELF_STRING_ia64_unwind_info_once) - 1;
4310 suffix = SECTION_NAME (unwsec) + len;
4311 for (i = 0, sec = section_headers; i < elf_header.e_shnum;
4313 if (strncmp (SECTION_NAME (sec),
4314 ELF_STRING_ia64_unwind_info_once, len2) == 0
4315 && strcmp (SECTION_NAME (sec) + len2, suffix) == 0)
4320 /* .IA_64.unwindFOO -> .IA_64.unwind_infoFOO
4321 .IA_64.unwind or BAR -> .IA_64.unwind_info */
4322 len = sizeof (ELF_STRING_ia64_unwind) - 1;
4323 len2 = sizeof (ELF_STRING_ia64_unwind_info) - 1;
4325 if (strncmp (SECTION_NAME (unwsec), ELF_STRING_ia64_unwind,
4327 suffix = SECTION_NAME (unwsec) + len;
4328 for (i = 0, sec = section_headers; i < elf_header.e_shnum;
4330 if (strncmp (SECTION_NAME (sec),
4331 ELF_STRING_ia64_unwind_info, len2) == 0
4332 && strcmp (SECTION_NAME (sec) + len2, suffix) == 0)
4336 if (i == elf_header.e_shnum)
4338 printf (_("\nCould not find unwind info section for "));
4340 if (string_table == NULL)
4341 printf ("%d", unwsec->sh_name);
4343 printf (_("'%s'"), SECTION_NAME (unwsec));
4347 aux.info_size = sec->sh_size;
4348 aux.info_addr = sec->sh_addr;
4349 aux.info = get_data (NULL, file, sec->sh_offset, aux.info_size,
4352 printf (_("\nUnwind section "));
4354 if (string_table == NULL)
4355 printf ("%d", unwsec->sh_name);
4357 printf (_("'%s'"), SECTION_NAME (unwsec));
4359 printf (_(" at offset 0x%lx contains %lu entries:\n"),
4360 (unsigned long) unwsec->sh_offset,
4361 (unsigned long) (unwsec->sh_size / (3 * addr_size)));
4363 (void) slurp_ia64_unwind_table (file, & aux, unwsec);
4365 if (aux.table_len > 0)
4366 dump_ia64_unwind (& aux);
4369 free ((char *) aux.table);
4371 free ((char *) aux.info);
4380 free ((char *) aux.strtab);
4386 dynamic_segment_mips_val (Elf_Internal_Dyn *entry)
4388 switch (entry->d_tag)
4391 if (entry->d_un.d_val == 0)
4395 static const char * opts[] =
4397 "QUICKSTART", "NOTPOT", "NO_LIBRARY_REPLACEMENT",
4398 "NO_MOVE", "SGI_ONLY", "GUARANTEE_INIT", "DELTA_C_PLUS_PLUS",
4399 "GUARANTEE_START_INIT", "PIXIE", "DEFAULT_DELAY_LOAD",
4400 "REQUICKSTART", "REQUICKSTARTED", "CORD", "NO_UNRES_UNDEF",
4405 for (cnt = 0; cnt < NUM_ELEM (opts); ++cnt)
4406 if (entry->d_un.d_val & (1 << cnt))
4408 printf ("%s%s", first ? "" : " ", opts[cnt]);
4415 case DT_MIPS_IVERSION:
4416 if (dynamic_strings != NULL)
4417 printf ("Interface Version: %s\n",
4418 dynamic_strings + entry->d_un.d_val);
4420 printf ("%ld\n", (long) entry->d_un.d_ptr);
4423 case DT_MIPS_TIME_STAMP:
4428 time_t time = entry->d_un.d_val;
4429 tmp = gmtime (&time);
4430 sprintf (timebuf, "%04u-%02u-%02uT%02u:%02u:%02u",
4431 tmp->tm_year + 1900, tmp->tm_mon + 1, tmp->tm_mday,
4432 tmp->tm_hour, tmp->tm_min, tmp->tm_sec);
4433 printf ("Time Stamp: %s\n", timebuf);
4437 case DT_MIPS_RLD_VERSION:
4438 case DT_MIPS_LOCAL_GOTNO:
4439 case DT_MIPS_CONFLICTNO:
4440 case DT_MIPS_LIBLISTNO:
4441 case DT_MIPS_SYMTABNO:
4442 case DT_MIPS_UNREFEXTNO:
4443 case DT_MIPS_HIPAGENO:
4444 case DT_MIPS_DELTA_CLASS_NO:
4445 case DT_MIPS_DELTA_INSTANCE_NO:
4446 case DT_MIPS_DELTA_RELOC_NO:
4447 case DT_MIPS_DELTA_SYM_NO:
4448 case DT_MIPS_DELTA_CLASSSYM_NO:
4449 case DT_MIPS_COMPACT_SIZE:
4450 printf ("%ld\n", (long) entry->d_un.d_ptr);
4454 printf ("%#lx\n", (long) entry->d_un.d_ptr);
4460 dynamic_segment_parisc_val (Elf_Internal_Dyn *entry)
4462 switch (entry->d_tag)
4464 case DT_HP_DLD_FLAGS:
4473 { DT_HP_DEBUG_PRIVATE, "HP_DEBUG_PRIVATE" },
4474 { DT_HP_DEBUG_CALLBACK, "HP_DEBUG_CALLBACK" },
4475 { DT_HP_DEBUG_CALLBACK_BOR, "HP_DEBUG_CALLBACK_BOR" },
4476 { DT_HP_NO_ENVVAR, "HP_NO_ENVVAR" },
4477 { DT_HP_BIND_NOW, "HP_BIND_NOW" },
4478 { DT_HP_BIND_NONFATAL, "HP_BIND_NONFATAL" },
4479 { DT_HP_BIND_VERBOSE, "HP_BIND_VERBOSE" },
4480 { DT_HP_BIND_RESTRICTED, "HP_BIND_RESTRICTED" },
4481 { DT_HP_BIND_SYMBOLIC, "HP_BIND_SYMBOLIC" },
4482 { DT_HP_RPATH_FIRST, "HP_RPATH_FIRST" },
4483 { DT_HP_BIND_DEPTH_FIRST, "HP_BIND_DEPTH_FIRST" }
4487 bfd_vma val = entry->d_un.d_val;
4489 for (cnt = 0; cnt < sizeof (flags) / sizeof (flags[0]); ++cnt)
4490 if (val & flags[cnt].bit)
4494 fputs (flags[cnt].str, stdout);
4496 val ^= flags[cnt].bit;
4499 if (val != 0 || first)
4503 print_vma (val, HEX);
4509 print_vma (entry->d_un.d_ptr, PREFIX_HEX);
4516 dynamic_segment_ia64_val (Elf_Internal_Dyn *entry)
4518 switch (entry->d_tag)
4520 case DT_IA_64_PLT_RESERVE:
4521 /* First 3 slots reserved. */
4522 print_vma (entry->d_un.d_ptr, PREFIX_HEX);
4524 print_vma (entry->d_un.d_ptr + (3 * 8), PREFIX_HEX);
4528 print_vma (entry->d_un.d_ptr, PREFIX_HEX);
4535 get_32bit_dynamic_segment (FILE *file)
4537 Elf32_External_Dyn *edyn;
4538 Elf_Internal_Dyn *entry;
4541 edyn = get_data (NULL, file, dynamic_addr, dynamic_size,
4542 _("dynamic segment"));
4546 /* SGI's ELF has more than one section in the DYNAMIC segment. Determine
4547 how large this .dynamic is now. We can do this even before the byte
4548 swapping since the DT_NULL tag is recognizable. */
4550 while (*(Elf32_Word *) edyn[dynamic_size++].d_tag != DT_NULL)
4553 dynamic_segment = malloc (dynamic_size * sizeof (Elf_Internal_Dyn));
4555 if (dynamic_segment == NULL)
4557 error (_("Out of memory\n"));
4562 for (i = 0, entry = dynamic_segment;
4566 entry->d_tag = BYTE_GET (edyn[i].d_tag);
4567 entry->d_un.d_val = BYTE_GET (edyn[i].d_un.d_val);
4576 get_64bit_dynamic_segment (FILE *file)
4578 Elf64_External_Dyn *edyn;
4579 Elf_Internal_Dyn *entry;
4582 edyn = get_data (NULL, file, dynamic_addr, dynamic_size,
4583 _("dynamic segment"));
4587 /* SGI's ELF has more than one section in the DYNAMIC segment. Determine
4588 how large this .dynamic is now. We can do this even before the byte
4589 swapping since the DT_NULL tag is recognizable. */
4591 while (*(bfd_vma *) edyn[dynamic_size++].d_tag != DT_NULL)
4594 dynamic_segment = malloc (dynamic_size * sizeof (Elf_Internal_Dyn));
4596 if (dynamic_segment == NULL)
4598 error (_("Out of memory\n"));
4603 for (i = 0, entry = dynamic_segment;
4607 entry->d_tag = BYTE_GET8 (edyn[i].d_tag);
4608 entry->d_un.d_val = BYTE_GET8 (edyn[i].d_un.d_val);
4617 get_dynamic_flags (bfd_vma flags)
4619 static char buff[128];
4627 flag = flags & - flags;
4635 case DF_ORIGIN: strcpy (p, "ORIGIN"); break;
4636 case DF_SYMBOLIC: strcpy (p, "SYMBOLIC"); break;
4637 case DF_TEXTREL: strcpy (p, "TEXTREL"); break;
4638 case DF_BIND_NOW: strcpy (p, "BIND_NOW"); break;
4639 case DF_STATIC_TLS: strcpy (p, "STATIC_TLS"); break;
4640 default: strcpy (p, "unknown"); break;
4643 p = strchr (p, '\0');
4648 /* Parse and display the contents of the dynamic segment. */
4650 process_dynamic_segment (FILE *file)
4652 Elf_Internal_Dyn *entry;
4655 if (dynamic_size == 0)
4658 printf (_("\nThere is no dynamic segment in this file.\n"));
4665 if (! get_32bit_dynamic_segment (file))
4668 else if (! get_64bit_dynamic_segment (file))
4671 /* Find the appropriate symbol table. */
4672 if (dynamic_symbols == NULL)
4674 for (i = 0, entry = dynamic_segment;
4678 Elf_Internal_Shdr section;
4680 if (entry->d_tag != DT_SYMTAB)
4683 dynamic_info[DT_SYMTAB] = entry->d_un.d_val;
4685 /* Since we do not know how big the symbol table is,
4686 we default to reading in the entire file (!) and
4687 processing that. This is overkill, I know, but it
4689 section.sh_offset = offset_from_vma (file, entry->d_un.d_val, 0);
4691 if (archive_file_offset != 0)
4692 section.sh_size = archive_file_size - section.sh_offset;
4695 if (fseek (file, 0, SEEK_END))
4696 error (_("Unable to seek to end of file!"));
4698 section.sh_size = ftell (file) - section.sh_offset;
4702 section.sh_entsize = sizeof (Elf32_External_Sym);
4704 section.sh_entsize = sizeof (Elf64_External_Sym);
4706 num_dynamic_syms = section.sh_size / section.sh_entsize;
4707 if (num_dynamic_syms < 1)
4709 error (_("Unable to determine the number of symbols to load\n"));
4713 dynamic_symbols = GET_ELF_SYMBOLS (file, §ion);
4717 /* Similarly find a string table. */
4718 if (dynamic_strings == NULL)
4720 for (i = 0, entry = dynamic_segment;
4724 unsigned long offset;
4727 if (entry->d_tag != DT_STRTAB)
4730 dynamic_info[DT_STRTAB] = entry->d_un.d_val;
4732 /* Since we do not know how big the string table is,
4733 we default to reading in the entire file (!) and
4734 processing that. This is overkill, I know, but it
4737 offset = offset_from_vma (file, entry->d_un.d_val, 0);
4739 if (archive_file_offset != 0)
4740 str_tab_len = archive_file_size - offset;
4743 if (fseek (file, 0, SEEK_END))
4744 error (_("Unable to seek to end of file\n"));
4745 str_tab_len = ftell (file) - offset;
4748 if (str_tab_len < 1)
4751 (_("Unable to determine the length of the dynamic string table\n"));
4755 dynamic_strings = get_data (NULL, file, offset, str_tab_len,
4756 _("dynamic string table"));
4761 /* And find the syminfo section if available. */
4762 if (dynamic_syminfo == NULL)
4764 unsigned long syminsz = 0;
4766 for (i = 0, entry = dynamic_segment;
4770 if (entry->d_tag == DT_SYMINENT)
4772 /* Note: these braces are necessary to avoid a syntax
4773 error from the SunOS4 C compiler. */
4774 assert (sizeof (Elf_External_Syminfo) == entry->d_un.d_val);
4776 else if (entry->d_tag == DT_SYMINSZ)
4777 syminsz = entry->d_un.d_val;
4778 else if (entry->d_tag == DT_SYMINFO)
4779 dynamic_syminfo_offset = offset_from_vma (file, entry->d_un.d_val,
4783 if (dynamic_syminfo_offset != 0 && syminsz != 0)
4785 Elf_External_Syminfo *extsyminfo;
4786 Elf_Internal_Syminfo *syminfo;
4788 /* There is a syminfo section. Read the data. */
4789 extsyminfo = get_data (NULL, file, dynamic_syminfo_offset, syminsz,
4790 _("symbol information"));
4794 dynamic_syminfo = malloc (syminsz);
4795 if (dynamic_syminfo == NULL)
4797 error (_("Out of memory\n"));
4801 dynamic_syminfo_nent = syminsz / sizeof (Elf_External_Syminfo);
4802 for (i = 0, syminfo = dynamic_syminfo; i < dynamic_syminfo_nent;
4805 syminfo->si_boundto = BYTE_GET (extsyminfo[i].si_boundto);
4806 syminfo->si_flags = BYTE_GET (extsyminfo[i].si_flags);
4813 if (do_dynamic && dynamic_addr)
4814 printf (_("\nDynamic segment at offset 0x%lx contains %ld entries:\n"),
4815 dynamic_addr, (long) dynamic_size);
4817 printf (_(" Tag Type Name/Value\n"));
4819 for (i = 0, entry = dynamic_segment;
4828 print_vma (entry->d_tag, FULL_HEX);
4829 dtype = get_dynamic_type (entry->d_tag);
4830 printf (" (%s)%*s", dtype,
4831 ((is_32bit_elf ? 27 : 19)
4832 - (int) strlen (dtype)),
4836 switch (entry->d_tag)
4840 puts (get_dynamic_flags (entry->d_un.d_val));
4850 switch (entry->d_tag)
4853 printf (_("Auxiliary library"));
4857 printf (_("Filter library"));
4861 printf (_("Configuration file"));
4865 printf (_("Dependency audit library"));
4869 printf (_("Audit library"));
4873 if (dynamic_strings)
4874 printf (": [%s]\n", dynamic_strings + entry->d_un.d_val);
4878 print_vma (entry->d_un.d_val, PREFIX_HEX);
4887 printf (_("Flags:"));
4889 if (entry->d_un.d_val == 0)
4890 printf (_(" None\n"));
4893 unsigned long int val = entry->d_un.d_val;
4895 if (val & DTF_1_PARINIT)
4897 printf (" PARINIT");
4898 val ^= DTF_1_PARINIT;
4900 if (val & DTF_1_CONFEXP)
4902 printf (" CONFEXP");
4903 val ^= DTF_1_CONFEXP;
4906 printf (" %lx", val);
4915 printf (_("Flags:"));
4917 if (entry->d_un.d_val == 0)
4918 printf (_(" None\n"));
4921 unsigned long int val = entry->d_un.d_val;
4923 if (val & DF_P1_LAZYLOAD)
4925 printf (" LAZYLOAD");
4926 val ^= DF_P1_LAZYLOAD;
4928 if (val & DF_P1_GROUPPERM)
4930 printf (" GROUPPERM");
4931 val ^= DF_P1_GROUPPERM;
4934 printf (" %lx", val);
4943 printf (_("Flags:"));
4944 if (entry->d_un.d_val == 0)
4945 printf (_(" None\n"));
4948 unsigned long int val = entry->d_un.d_val;
4955 if (val & DF_1_GLOBAL)
4960 if (val & DF_1_GROUP)
4965 if (val & DF_1_NODELETE)
4967 printf (" NODELETE");
4968 val ^= DF_1_NODELETE;
4970 if (val & DF_1_LOADFLTR)
4972 printf (" LOADFLTR");
4973 val ^= DF_1_LOADFLTR;
4975 if (val & DF_1_INITFIRST)
4977 printf (" INITFIRST");
4978 val ^= DF_1_INITFIRST;
4980 if (val & DF_1_NOOPEN)
4985 if (val & DF_1_ORIGIN)
4990 if (val & DF_1_DIRECT)
4995 if (val & DF_1_TRANS)
5000 if (val & DF_1_INTERPOSE)
5002 printf (" INTERPOSE");
5003 val ^= DF_1_INTERPOSE;
5005 if (val & DF_1_NODEFLIB)
5007 printf (" NODEFLIB");
5008 val ^= DF_1_NODEFLIB;
5010 if (val & DF_1_NODUMP)
5015 if (val & DF_1_CONLFAT)
5017 printf (" CONLFAT");
5018 val ^= DF_1_CONLFAT;
5021 printf (" %lx", val);
5028 dynamic_info[entry->d_tag] = entry->d_un.d_val;
5030 puts (get_dynamic_type (entry->d_un.d_val));
5050 dynamic_info[entry->d_tag] = entry->d_un.d_val;
5056 if (dynamic_strings == NULL)
5059 name = dynamic_strings + entry->d_un.d_val;
5063 switch (entry->d_tag)
5066 printf (_("Shared library: [%s]"), name);
5068 if (strcmp (name, program_interpreter) == 0)
5069 printf (_(" program interpreter"));
5073 printf (_("Library soname: [%s]"), name);
5077 printf (_("Library rpath: [%s]"), name);
5081 printf (_("Library runpath: [%s]"), name);
5085 print_vma (entry->d_un.d_val, PREFIX_HEX);
5090 print_vma (entry->d_un.d_val, PREFIX_HEX);
5103 dynamic_info[entry->d_tag] = entry->d_un.d_val;
5107 case DT_INIT_ARRAYSZ:
5108 case DT_FINI_ARRAYSZ:
5109 case DT_GNU_CONFLICTSZ:
5110 case DT_GNU_LIBLISTSZ:
5113 print_vma (entry->d_un.d_val, UNSIGNED);
5114 printf (" (bytes)\n");
5124 print_vma (entry->d_un.d_val, UNSIGNED);
5137 if (dynamic_strings != NULL && entry->d_tag == DT_USED)
5141 name = dynamic_strings + entry->d_un.d_val;
5145 printf (_("Not needed object: [%s]\n"), name);
5150 print_vma (entry->d_un.d_val, PREFIX_HEX);
5156 /* The value of this entry is ignored. */
5161 case DT_GNU_PRELINKED:
5165 time_t time = entry->d_un.d_val;
5167 tmp = gmtime (&time);
5168 printf ("%04u-%02u-%02uT%02u:%02u:%02u\n",
5169 tmp->tm_year + 1900, tmp->tm_mon + 1, tmp->tm_mday,
5170 tmp->tm_hour, tmp->tm_min, tmp->tm_sec);
5176 if ((entry->d_tag >= DT_VERSYM) && (entry->d_tag <= DT_VERNEEDNUM))
5177 version_info[DT_VERSIONTAGIDX (entry->d_tag)] =
5182 switch (elf_header.e_machine)
5185 case EM_MIPS_RS3_LE:
5186 dynamic_segment_mips_val (entry);
5189 dynamic_segment_parisc_val (entry);
5192 dynamic_segment_ia64_val (entry);
5195 print_vma (entry->d_un.d_val, PREFIX_HEX);
5207 get_ver_flags (unsigned int flags)
5209 static char buff[32];
5216 if (flags & VER_FLG_BASE)
5217 strcat (buff, "BASE ");
5219 if (flags & VER_FLG_WEAK)
5221 if (flags & VER_FLG_BASE)
5222 strcat (buff, "| ");
5224 strcat (buff, "WEAK ");
5227 if (flags & ~(VER_FLG_BASE | VER_FLG_WEAK))
5228 strcat (buff, "| <unknown>");
5233 /* Display the contents of the version sections. */
5235 process_version_sections (FILE *file)
5237 Elf_Internal_Shdr *section;
5244 for (i = 0, section = section_headers;
5245 i < elf_header.e_shnum;
5248 switch (section->sh_type)
5250 case SHT_GNU_verdef:
5252 Elf_External_Verdef *edefs;
5259 (_("\nVersion definition section '%s' contains %ld entries:\n"),
5260 SECTION_NAME (section), section->sh_info);
5262 printf (_(" Addr: 0x"));
5263 printf_vma (section->sh_addr);
5264 printf (_(" Offset: %#08lx Link: %lx (%s)\n"),
5265 (unsigned long) section->sh_offset, section->sh_link,
5266 SECTION_NAME (SECTION_HEADER (section->sh_link)));
5268 edefs = get_data (NULL, file, section->sh_offset, section->sh_size,
5269 _("version definition section"));
5273 for (idx = cnt = 0; cnt < section->sh_info; ++cnt)
5276 Elf_External_Verdef *edef;
5277 Elf_Internal_Verdef ent;
5278 Elf_External_Verdaux *eaux;
5279 Elf_Internal_Verdaux aux;
5283 vstart = ((char *) edefs) + idx;
5285 edef = (Elf_External_Verdef *) vstart;
5287 ent.vd_version = BYTE_GET (edef->vd_version);
5288 ent.vd_flags = BYTE_GET (edef->vd_flags);
5289 ent.vd_ndx = BYTE_GET (edef->vd_ndx);
5290 ent.vd_cnt = BYTE_GET (edef->vd_cnt);
5291 ent.vd_hash = BYTE_GET (edef->vd_hash);
5292 ent.vd_aux = BYTE_GET (edef->vd_aux);
5293 ent.vd_next = BYTE_GET (edef->vd_next);
5295 printf (_(" %#06x: Rev: %d Flags: %s"),
5296 idx, ent.vd_version, get_ver_flags (ent.vd_flags));
5298 printf (_(" Index: %d Cnt: %d "),
5299 ent.vd_ndx, ent.vd_cnt);
5301 vstart += ent.vd_aux;
5303 eaux = (Elf_External_Verdaux *) vstart;
5305 aux.vda_name = BYTE_GET (eaux->vda_name);
5306 aux.vda_next = BYTE_GET (eaux->vda_next);
5308 if (dynamic_strings)
5309 printf (_("Name: %s\n"), dynamic_strings + aux.vda_name);
5311 printf (_("Name index: %ld\n"), aux.vda_name);
5313 isum = idx + ent.vd_aux;
5315 for (j = 1; j < ent.vd_cnt; j++)
5317 isum += aux.vda_next;
5318 vstart += aux.vda_next;
5320 eaux = (Elf_External_Verdaux *) vstart;
5322 aux.vda_name = BYTE_GET (eaux->vda_name);
5323 aux.vda_next = BYTE_GET (eaux->vda_next);
5325 if (dynamic_strings)
5326 printf (_(" %#06x: Parent %d: %s\n"),
5327 isum, j, dynamic_strings + aux.vda_name);
5329 printf (_(" %#06x: Parent %d, name index: %ld\n"),
5330 isum, j, aux.vda_name);
5340 case SHT_GNU_verneed:
5342 Elf_External_Verneed *eneed;
5348 printf (_("\nVersion needs section '%s' contains %ld entries:\n"),
5349 SECTION_NAME (section), section->sh_info);
5351 printf (_(" Addr: 0x"));
5352 printf_vma (section->sh_addr);
5353 printf (_(" Offset: %#08lx Link to section: %ld (%s)\n"),
5354 (unsigned long) section->sh_offset, section->sh_link,
5355 SECTION_NAME (SECTION_HEADER (section->sh_link)));
5357 eneed = get_data (NULL, file, section->sh_offset, section->sh_size,
5358 _("version need section"));
5362 for (idx = cnt = 0; cnt < section->sh_info; ++cnt)
5364 Elf_External_Verneed *entry;
5365 Elf_Internal_Verneed ent;
5370 vstart = ((char *) eneed) + idx;
5372 entry = (Elf_External_Verneed *) vstart;
5374 ent.vn_version = BYTE_GET (entry->vn_version);
5375 ent.vn_cnt = BYTE_GET (entry->vn_cnt);
5376 ent.vn_file = BYTE_GET (entry->vn_file);
5377 ent.vn_aux = BYTE_GET (entry->vn_aux);
5378 ent.vn_next = BYTE_GET (entry->vn_next);
5380 printf (_(" %#06x: Version: %d"), idx, ent.vn_version);
5382 if (dynamic_strings)
5383 printf (_(" File: %s"), dynamic_strings + ent.vn_file);
5385 printf (_(" File: %lx"), ent.vn_file);
5387 printf (_(" Cnt: %d\n"), ent.vn_cnt);
5389 vstart += ent.vn_aux;
5391 for (j = 0, isum = idx + ent.vn_aux; j < ent.vn_cnt; ++j)
5393 Elf_External_Vernaux *eaux;
5394 Elf_Internal_Vernaux aux;
5396 eaux = (Elf_External_Vernaux *) vstart;
5398 aux.vna_hash = BYTE_GET (eaux->vna_hash);
5399 aux.vna_flags = BYTE_GET (eaux->vna_flags);
5400 aux.vna_other = BYTE_GET (eaux->vna_other);
5401 aux.vna_name = BYTE_GET (eaux->vna_name);
5402 aux.vna_next = BYTE_GET (eaux->vna_next);
5404 if (dynamic_strings)
5405 printf (_(" %#06x: Name: %s"),
5406 isum, dynamic_strings + aux.vna_name);
5408 printf (_(" %#06x: Name index: %lx"),
5409 isum, aux.vna_name);
5411 printf (_(" Flags: %s Version: %d\n"),
5412 get_ver_flags (aux.vna_flags), aux.vna_other);
5414 isum += aux.vna_next;
5415 vstart += aux.vna_next;
5425 case SHT_GNU_versym:
5427 Elf_Internal_Shdr *link_section;
5430 unsigned char *edata;
5431 unsigned short *data;
5433 Elf_Internal_Sym *symbols;
5434 Elf_Internal_Shdr *string_sec;
5437 link_section = SECTION_HEADER (section->sh_link);
5438 total = section->sh_size / section->sh_entsize;
5442 symbols = GET_ELF_SYMBOLS (file, link_section);
5444 string_sec = SECTION_HEADER (link_section->sh_link);
5446 strtab = get_data (NULL, file, string_sec->sh_offset,
5447 string_sec->sh_size, _("version string table"));
5451 printf (_("\nVersion symbols section '%s' contains %d entries:\n"),
5452 SECTION_NAME (section), total);
5454 printf (_(" Addr: "));
5455 printf_vma (section->sh_addr);
5456 printf (_(" Offset: %#08lx Link: %lx (%s)\n"),
5457 (unsigned long) section->sh_offset, section->sh_link,
5458 SECTION_NAME (link_section));
5460 off = offset_from_vma (file,
5461 version_info[DT_VERSIONTAGIDX (DT_VERSYM)],
5462 total * sizeof (short));
5463 edata = get_data (NULL, file, off, total * sizeof (short),
5464 _("version symbol data"));
5471 data = malloc (total * sizeof (short));
5473 for (cnt = total; cnt --;)
5474 data[cnt] = byte_get (edata + cnt * sizeof (short),
5479 for (cnt = 0; cnt < total; cnt += 4)
5482 int check_def, check_need;
5485 printf (" %03x:", cnt);
5487 for (j = 0; (j < 4) && (cnt + j) < total; ++j)
5488 switch (data[cnt + j])
5491 fputs (_(" 0 (*local*) "), stdout);
5495 fputs (_(" 1 (*global*) "), stdout);
5499 nn = printf ("%4x%c", data[cnt + j] & 0x7fff,
5500 data[cnt + j] & 0x8000 ? 'h' : ' ');
5504 if (SECTION_HEADER (symbols[cnt + j].st_shndx)->sh_type
5507 if (symbols[cnt + j].st_shndx == SHN_UNDEF)
5514 && version_info[DT_VERSIONTAGIDX (DT_VERNEED)])
5516 Elf_Internal_Verneed ivn;
5517 unsigned long offset;
5519 offset = offset_from_vma
5520 (file, version_info[DT_VERSIONTAGIDX (DT_VERNEED)],
5521 sizeof (Elf_External_Verneed));
5525 Elf_Internal_Vernaux ivna;
5526 Elf_External_Verneed evn;
5527 Elf_External_Vernaux evna;
5528 unsigned long a_off;
5530 get_data (&evn, file, offset, sizeof (evn),
5533 ivn.vn_aux = BYTE_GET (evn.vn_aux);
5534 ivn.vn_next = BYTE_GET (evn.vn_next);
5536 a_off = offset + ivn.vn_aux;
5540 get_data (&evna, file, a_off, sizeof (evna),
5541 _("version need aux (2)"));
5543 ivna.vna_next = BYTE_GET (evna.vna_next);
5544 ivna.vna_other = BYTE_GET (evna.vna_other);
5546 a_off += ivna.vna_next;
5548 while (ivna.vna_other != data[cnt + j]
5549 && ivna.vna_next != 0);
5551 if (ivna.vna_other == data[cnt + j])
5553 ivna.vna_name = BYTE_GET (evna.vna_name);
5555 name = strtab + ivna.vna_name;
5556 nn += printf ("(%s%-*s",
5558 12 - (int) strlen (name),
5564 offset += ivn.vn_next;
5566 while (ivn.vn_next);
5569 if (check_def && data[cnt + j] != 0x8001
5570 && version_info[DT_VERSIONTAGIDX (DT_VERDEF)])
5572 Elf_Internal_Verdef ivd;
5573 Elf_External_Verdef evd;
5574 unsigned long offset;
5576 offset = offset_from_vma
5577 (file, version_info[DT_VERSIONTAGIDX (DT_VERDEF)],
5582 get_data (&evd, file, offset, sizeof (evd),
5585 ivd.vd_next = BYTE_GET (evd.vd_next);
5586 ivd.vd_ndx = BYTE_GET (evd.vd_ndx);
5588 offset += ivd.vd_next;
5590 while (ivd.vd_ndx != (data[cnt + j] & 0x7fff)
5591 && ivd.vd_next != 0);
5593 if (ivd.vd_ndx == (data[cnt + j] & 0x7fff))
5595 Elf_External_Verdaux evda;
5596 Elf_Internal_Verdaux ivda;
5598 ivd.vd_aux = BYTE_GET (evd.vd_aux);
5600 get_data (&evda, file,
5601 offset - ivd.vd_next + ivd.vd_aux,
5602 sizeof (evda), _("version def aux"));
5604 ivda.vda_name = BYTE_GET (evda.vda_name);
5606 name = strtab + ivda.vda_name;
5607 nn += printf ("(%s%-*s",
5609 12 - (int) strlen (name),
5615 printf ("%*c", 18 - nn, ' ');
5633 printf (_("\nNo version information found in this file.\n"));
5639 get_symbol_binding (unsigned int binding)
5641 static char buff[32];
5645 case STB_LOCAL: return "LOCAL";
5646 case STB_GLOBAL: return "GLOBAL";
5647 case STB_WEAK: return "WEAK";
5649 if (binding >= STB_LOPROC && binding <= STB_HIPROC)
5650 sprintf (buff, _("<processor specific>: %d"), binding);
5651 else if (binding >= STB_LOOS && binding <= STB_HIOS)
5652 sprintf (buff, _("<OS specific>: %d"), binding);
5654 sprintf (buff, _("<unknown>: %d"), binding);
5660 get_symbol_type (unsigned int type)
5662 static char buff[32];
5666 case STT_NOTYPE: return "NOTYPE";
5667 case STT_OBJECT: return "OBJECT";
5668 case STT_FUNC: return "FUNC";
5669 case STT_SECTION: return "SECTION";
5670 case STT_FILE: return "FILE";
5671 case STT_COMMON: return "COMMON";
5672 case STT_TLS: return "TLS";
5674 if (type >= STT_LOPROC && type <= STT_HIPROC)
5676 if (elf_header.e_machine == EM_ARM && type == STT_ARM_TFUNC)
5677 return "THUMB_FUNC";
5679 if (elf_header.e_machine == EM_SPARCV9 && type == STT_REGISTER)
5682 if (elf_header.e_machine == EM_PARISC && type == STT_PARISC_MILLI)
5683 return "PARISC_MILLI";
5685 sprintf (buff, _("<processor specific>: %d"), type);
5687 else if (type >= STT_LOOS && type <= STT_HIOS)
5689 if (elf_header.e_machine == EM_PARISC)
5691 if (type == STT_HP_OPAQUE)
5693 if (type == STT_HP_STUB)
5697 sprintf (buff, _("<OS specific>: %d"), type);
5700 sprintf (buff, _("<unknown>: %d"), type);
5706 get_symbol_visibility (unsigned int visibility)
5710 case STV_DEFAULT: return "DEFAULT";
5711 case STV_INTERNAL: return "INTERNAL";
5712 case STV_HIDDEN: return "HIDDEN";
5713 case STV_PROTECTED: return "PROTECTED";
5719 get_symbol_index_type (unsigned int type)
5721 static char buff[32];
5725 case SHN_UNDEF: return "UND";
5726 case SHN_ABS: return "ABS";
5727 case SHN_COMMON: return "COM";
5729 if (type == SHN_IA_64_ANSI_COMMON
5730 && elf_header.e_machine == EM_IA_64
5731 && elf_header.e_ident[EI_OSABI] == ELFOSABI_HPUX)
5733 else if (type >= SHN_LOPROC && type <= SHN_HIPROC)
5734 sprintf (buff, "PRC[0x%04x]", type);
5735 else if (type >= SHN_LOOS && type <= SHN_HIOS)
5736 sprintf (buff, "OS [0x%04x]", type);
5737 else if (type >= SHN_LORESERVE && type <= SHN_HIRESERVE)
5738 sprintf (buff, "RSV[0x%04x]", type);
5740 sprintf (buff, "%3d", type);
5748 get_dynamic_data (FILE *file, unsigned int number)
5750 unsigned char *e_data;
5753 e_data = malloc (number * 4);
5757 error (_("Out of memory\n"));
5761 if (fread (e_data, 4, number, file) != number)
5763 error (_("Unable to read in dynamic data\n"));
5767 i_data = malloc (number * sizeof (*i_data));
5771 error (_("Out of memory\n"));
5777 i_data[number] = byte_get (e_data + number * 4, 4);
5784 /* Dump the symbol table. */
5786 process_symbol_table (FILE *file)
5788 Elf_Internal_Shdr *section;
5789 unsigned char nb[4];
5790 unsigned char nc[4];
5793 int *buckets = NULL;
5796 if (! do_syms && !do_histogram)
5799 if (dynamic_info[DT_HASH] && ((do_using_dynamic && dynamic_strings != NULL)
5803 (archive_file_offset
5804 + offset_from_vma (file, dynamic_info[DT_HASH],
5805 sizeof nb + sizeof nc)),
5808 error (_("Unable to seek to start of dynamic information"));
5812 if (fread (nb, sizeof (nb), 1, file) != 1)
5814 error (_("Failed to read in number of buckets\n"));
5818 if (fread (nc, sizeof (nc), 1, file) != 1)
5820 error (_("Failed to read in number of chains\n"));
5824 nbuckets = byte_get (nb, 4);
5825 nchains = byte_get (nc, 4);
5827 buckets = get_dynamic_data (file, nbuckets);
5828 chains = get_dynamic_data (file, nchains);
5830 if (buckets == NULL || chains == NULL)
5835 && dynamic_info[DT_HASH] && do_using_dynamic && dynamic_strings != NULL)
5840 printf (_("\nSymbol table for image:\n"));
5842 printf (_(" Num Buc: Value Size Type Bind Vis Ndx Name\n"));
5844 printf (_(" Num Buc: Value Size Type Bind Vis Ndx Name\n"));
5846 for (hn = 0; hn < nbuckets; hn++)
5851 for (si = buckets[hn]; si < nchains && si > 0; si = chains[si])
5853 Elf_Internal_Sym *psym;
5855 psym = dynamic_symbols + si;
5857 printf (" %3d %3d: ", si, hn);
5858 print_vma (psym->st_value, LONG_HEX);
5860 print_vma (psym->st_size, DEC_5);
5862 printf (" %6s", get_symbol_type (ELF_ST_TYPE (psym->st_info)));
5863 printf (" %6s", get_symbol_binding (ELF_ST_BIND (psym->st_info)));
5864 printf (" %3s", get_symbol_visibility (ELF_ST_VISIBILITY (psym->st_other)));
5865 printf (" %3.3s ", get_symbol_index_type (psym->st_shndx));
5866 print_symbol (25, dynamic_strings + psym->st_name);
5871 else if (do_syms && !do_using_dynamic)
5875 for (i = 0, section = section_headers;
5876 i < elf_header.e_shnum;
5881 Elf_Internal_Sym *symtab;
5882 Elf_Internal_Sym *psym;
5885 if ( section->sh_type != SHT_SYMTAB
5886 && section->sh_type != SHT_DYNSYM)
5889 printf (_("\nSymbol table '%s' contains %lu entries:\n"),
5890 SECTION_NAME (section),
5891 (unsigned long) (section->sh_size / section->sh_entsize));
5893 printf (_(" Num: Value Size Type Bind Vis Ndx Name\n"));
5895 printf (_(" Num: Value Size Type Bind Vis Ndx Name\n"));
5897 symtab = GET_ELF_SYMBOLS (file, section);
5901 if (section->sh_link == elf_header.e_shstrndx)
5902 strtab = string_table;
5905 Elf_Internal_Shdr *string_sec;
5907 string_sec = SECTION_HEADER (section->sh_link);
5909 strtab = get_data (NULL, file, string_sec->sh_offset,
5910 string_sec->sh_size, _("string table"));
5913 for (si = 0, psym = symtab;
5914 si < section->sh_size / section->sh_entsize;
5917 printf ("%6d: ", si);
5918 print_vma (psym->st_value, LONG_HEX);
5920 print_vma (psym->st_size, DEC_5);
5921 printf (" %-7s", get_symbol_type (ELF_ST_TYPE (psym->st_info)));
5922 printf (" %-6s", get_symbol_binding (ELF_ST_BIND (psym->st_info)));
5923 printf (" %-3s", get_symbol_visibility (ELF_ST_VISIBILITY (psym->st_other)));
5924 printf (" %4s ", get_symbol_index_type (psym->st_shndx));
5925 print_symbol (25, strtab + psym->st_name);
5927 if (section->sh_type == SHT_DYNSYM &&
5928 version_info[DT_VERSIONTAGIDX (DT_VERSYM)] != 0)
5930 unsigned char data[2];
5931 unsigned short vers_data;
5932 unsigned long offset;
5936 offset = offset_from_vma
5937 (file, version_info[DT_VERSIONTAGIDX (DT_VERSYM)],
5938 sizeof data + si * sizeof (vers_data));
5940 get_data (&data, file, offset + si * sizeof (vers_data),
5941 sizeof (data), _("version data"));
5943 vers_data = byte_get (data, 2);
5945 is_nobits = (SECTION_HEADER (psym->st_shndx)->sh_type
5948 check_def = (psym->st_shndx != SHN_UNDEF);
5950 if ((vers_data & 0x8000) || vers_data > 1)
5952 if (version_info[DT_VERSIONTAGIDX (DT_VERNEED)]
5953 && (is_nobits || ! check_def))
5955 Elf_External_Verneed evn;
5956 Elf_Internal_Verneed ivn;
5957 Elf_Internal_Vernaux ivna;
5959 /* We must test both. */
5960 offset = offset_from_vma
5961 (file, version_info[DT_VERSIONTAGIDX (DT_VERNEED)],
5966 unsigned long vna_off;
5968 get_data (&evn, file, offset, sizeof (evn),
5971 ivn.vn_aux = BYTE_GET (evn.vn_aux);
5972 ivn.vn_next = BYTE_GET (evn.vn_next);
5974 vna_off = offset + ivn.vn_aux;
5978 Elf_External_Vernaux evna;
5980 get_data (&evna, file, vna_off,
5982 _("version need aux (3)"));
5984 ivna.vna_other = BYTE_GET (evna.vna_other);
5985 ivna.vna_next = BYTE_GET (evna.vna_next);
5986 ivna.vna_name = BYTE_GET (evna.vna_name);
5988 vna_off += ivna.vna_next;
5990 while (ivna.vna_other != vers_data
5991 && ivna.vna_next != 0);
5993 if (ivna.vna_other == vers_data)
5996 offset += ivn.vn_next;
5998 while (ivn.vn_next != 0);
6000 if (ivna.vna_other == vers_data)
6003 strtab + ivna.vna_name, ivna.vna_other);
6006 else if (! is_nobits)
6007 error (_("bad dynamic symbol"));
6014 if (vers_data != 0x8001
6015 && version_info[DT_VERSIONTAGIDX (DT_VERDEF)])
6017 Elf_Internal_Verdef ivd;
6018 Elf_Internal_Verdaux ivda;
6019 Elf_External_Verdaux evda;
6020 unsigned long offset;
6022 offset = offset_from_vma
6024 version_info[DT_VERSIONTAGIDX (DT_VERDEF)],
6025 sizeof (Elf_External_Verdef));
6029 Elf_External_Verdef evd;
6031 get_data (&evd, file, offset, sizeof (evd),
6034 ivd.vd_ndx = BYTE_GET (evd.vd_ndx);
6035 ivd.vd_aux = BYTE_GET (evd.vd_aux);
6036 ivd.vd_next = BYTE_GET (evd.vd_next);
6038 offset += ivd.vd_next;
6040 while (ivd.vd_ndx != (vers_data & 0x7fff)
6041 && ivd.vd_next != 0);
6043 offset -= ivd.vd_next;
6044 offset += ivd.vd_aux;
6046 get_data (&evda, file, offset, sizeof (evda),
6047 _("version def aux"));
6049 ivda.vda_name = BYTE_GET (evda.vda_name);
6051 if (psym->st_name != ivda.vda_name)
6052 printf ((vers_data & 0x8000)
6054 strtab + ivda.vda_name);
6064 if (strtab != string_table)
6070 (_("\nDynamic symbol information is not available for displaying symbols.\n"));
6072 if (do_histogram && buckets != NULL)
6079 int nzero_counts = 0;
6082 printf (_("\nHistogram for bucket list length (total of %d buckets):\n"),
6084 printf (_(" Length Number %% of total Coverage\n"));
6086 lengths = calloc (nbuckets, sizeof (int));
6087 if (lengths == NULL)
6089 error (_("Out of memory"));
6092 for (hn = 0; hn < nbuckets; ++hn)
6097 for (si = buckets[hn]; si > 0 && si < nchains; si = chains[si])
6100 if (maxlength < ++lengths[hn])
6105 counts = calloc (maxlength + 1, sizeof (int));
6108 error (_("Out of memory"));
6112 for (hn = 0; hn < nbuckets; ++hn)
6113 ++counts[lengths[hn]];
6117 printf (" 0 %-10d (%5.1f%%)\n",
6118 counts[0], (counts[0] * 100.0) / nbuckets);
6119 for (si = 1; si <= maxlength; ++si)
6121 nzero_counts += counts[si] * si;
6122 printf ("%7d %-10d (%5.1f%%) %5.1f%%\n",
6123 si, counts[si], (counts[si] * 100.0) / nbuckets,
6124 (nzero_counts * 100.0) / nsyms);
6132 if (buckets != NULL)
6142 process_syminfo (FILE *file ATTRIBUTE_UNUSED)
6146 if (dynamic_syminfo == NULL
6148 /* No syminfo, this is ok. */
6151 /* There better should be a dynamic symbol section. */
6152 if (dynamic_symbols == NULL || dynamic_strings == NULL)
6156 printf (_("\nDynamic info segment at offset 0x%lx contains %d entries:\n"),
6157 dynamic_syminfo_offset, dynamic_syminfo_nent);
6159 printf (_(" Num: Name BoundTo Flags\n"));
6160 for (i = 0; i < dynamic_syminfo_nent; ++i)
6162 unsigned short int flags = dynamic_syminfo[i].si_flags;
6164 printf ("%4d: ", i);
6165 print_symbol (30, dynamic_strings + dynamic_symbols[i].st_name);
6168 switch (dynamic_syminfo[i].si_boundto)
6170 case SYMINFO_BT_SELF:
6171 fputs ("SELF ", stdout);
6173 case SYMINFO_BT_PARENT:
6174 fputs ("PARENT ", stdout);
6177 if (dynamic_syminfo[i].si_boundto > 0
6178 && dynamic_syminfo[i].si_boundto < dynamic_size)
6183 [dynamic_syminfo[i].si_boundto].d_un.d_val));
6187 printf ("%-10d ", dynamic_syminfo[i].si_boundto);
6191 if (flags & SYMINFO_FLG_DIRECT)
6193 if (flags & SYMINFO_FLG_PASSTHRU)
6194 printf (" PASSTHRU");
6195 if (flags & SYMINFO_FLG_COPY)
6197 if (flags & SYMINFO_FLG_LAZYLOAD)
6198 printf (" LAZYLOAD");
6206 #ifdef SUPPORT_DISASSEMBLY
6208 disassemble_section (Elf_Internal_Shdr *section, FILE *file)
6210 printf (_("\nAssembly dump of section %s\n"),
6211 SECTION_NAME (section));
6213 /* XXX -- to be done --- XXX */
6220 dump_section (Elf_Internal_Shdr *section, FILE *file)
6222 bfd_size_type bytes;
6224 unsigned char *data;
6225 unsigned char *start;
6227 bytes = section->sh_size;
6229 if (bytes == 0 || section->sh_type == SHT_NOBITS)
6231 printf (_("\nSection '%s' has no data to dump.\n"),
6232 SECTION_NAME (section));
6236 printf (_("\nHex dump of section '%s':\n"), SECTION_NAME (section));
6238 addr = section->sh_addr;
6240 start = get_data (NULL, file, section->sh_offset, bytes, _("section data"));
6252 lbytes = (bytes > 16 ? 16 : bytes);
6254 printf (" 0x%8.8lx ", (unsigned long) addr);
6256 switch (elf_header.e_ident[EI_DATA])
6260 for (j = 15; j >= 0; j --)
6263 printf ("%2.2x", data[j]);
6273 for (j = 0; j < 16; j++)
6276 printf ("%2.2x", data[j]);
6286 for (j = 0; j < lbytes; j++)
6289 if (k >= ' ' && k < 0x7f)
6308 static unsigned long int
6309 read_leb128 (unsigned char *data, int *length_return, int sign)
6311 unsigned long int result = 0;
6312 unsigned int num_read = 0;
6321 result |= (byte & 0x7f) << shift;
6326 while (byte & 0x80);
6328 if (length_return != NULL)
6329 *length_return = num_read;
6331 if (sign && (shift < 32) && (byte & 0x40))
6332 result |= -1 << shift;
6337 typedef struct State_Machine_Registers
6339 unsigned long address;
6342 unsigned int column;
6346 /* This variable hold the number of the last entry seen
6347 in the File Table. */
6348 unsigned int last_file_entry;
6351 static SMR state_machine_regs;
6354 reset_state_machine (int is_stmt)
6356 state_machine_regs.address = 0;
6357 state_machine_regs.file = 1;
6358 state_machine_regs.line = 1;
6359 state_machine_regs.column = 0;
6360 state_machine_regs.is_stmt = is_stmt;
6361 state_machine_regs.basic_block = 0;
6362 state_machine_regs.end_sequence = 0;
6363 state_machine_regs.last_file_entry = 0;
6366 /* Handled an extend line op. Returns true if this is the end
6369 process_extended_line_op (unsigned char *data, int is_stmt, int pointer_size)
6371 unsigned char op_code;
6374 unsigned char *name;
6377 len = read_leb128 (data, & bytes_read, 0);
6382 warn (_("badly formed extended line op encountered!\n"));
6389 printf (_(" Extended opcode %d: "), op_code);
6393 case DW_LNE_end_sequence:
6394 printf (_("End of Sequence\n\n"));
6395 reset_state_machine (is_stmt);
6398 case DW_LNE_set_address:
6399 adr = byte_get (data, pointer_size);
6400 printf (_("set Address to 0x%lx\n"), adr);
6401 state_machine_regs.address = adr;
6404 case DW_LNE_define_file:
6405 printf (_(" define new File Table entry\n"));
6406 printf (_(" Entry\tDir\tTime\tSize\tName\n"));
6408 printf (_(" %d\t"), ++state_machine_regs.last_file_entry);
6410 data += strlen ((char *) data) + 1;
6411 printf (_("%lu\t"), read_leb128 (data, & bytes_read, 0));
6413 printf (_("%lu\t"), read_leb128 (data, & bytes_read, 0));
6415 printf (_("%lu\t"), read_leb128 (data, & bytes_read, 0));
6416 printf (_("%s\n\n"), name);
6420 printf (_("UNKNOWN: length %d\n"), len - bytes_read);
6427 /* Finds section NAME inside FILE and returns a
6428 pointer to it, or NULL upon failure. */
6430 static Elf_Internal_Shdr *
6431 find_section (const char * name)
6433 Elf_Internal_Shdr *sec;
6436 for (i = elf_header.e_shnum, sec = section_headers + i - 1;
6438 if (strcmp (SECTION_NAME (sec), name) == 0)
6441 if (i && sec && sec->sh_size != 0)
6447 /* Size of pointers in the .debug_line section. This information is not
6448 really present in that section. It's obtained before dumping the debug
6449 sections by doing some pre-scan of the .debug_info section. */
6450 static unsigned int * debug_line_pointer_sizes = NULL;
6451 static unsigned int num_debug_line_pointer_sizes = 0;
6453 /* Locate and scan the .debug_info section in the file and record the pointer
6454 sizes for the compilation units in it. Usually an executable will have
6455 just one pointer size, but this is not guaranteed, and so we try not to
6456 make any assumptions. Returns zero upon failure, or the number of
6457 compilation units upon success. */
6460 get_debug_line_pointer_sizes (FILE * file)
6462 Elf_Internal_Shdr * section;
6463 unsigned char * start;
6464 unsigned char * end;
6465 unsigned char * begin;
6466 unsigned long length;
6467 unsigned int num_units;
6470 section = find_section (".debug_info");
6471 if (section == NULL)
6474 length = section->sh_size;
6475 start = get_data (NULL, file, section->sh_offset, section->sh_size,
6476 _("extracting pointer sizes from .debug_info section"));
6480 end = start + section->sh_size;
6481 /* First scan the section to get the number of comp units. */
6482 for (begin = start, num_units = 0; begin < end; num_units++)
6484 /* Read the first 4 bytes. For a 32-bit DWARF section, this will
6485 be the length. For a 64-bit DWARF section, it'll be the escape
6486 code 0xffffffff followed by an 8 byte length. */
6487 length = byte_get (begin, 4);
6489 if (length == 0xffffffff)
6491 length = byte_get (begin + 4, 8);
6492 begin += length + 12;
6495 begin += length + 4;
6500 error (_("No comp units in .debug_info section ?"));
6505 /* Then allocate an array to hold the pointer sizes. */
6506 debug_line_pointer_sizes = malloc (num_units * sizeof * debug_line_pointer_sizes);
6507 if (debug_line_pointer_sizes == NULL)
6509 error (_("Not enough memory for a pointer size array of %u entries"),
6515 /* Populate the array. */
6516 for (begin = start, unit = 0; begin < end; unit++)
6518 length = byte_get (begin, 4);
6519 if (length == 0xffffffff)
6521 /* For 64-bit DWARF, the 1-byte address_size field is 22 bytes
6522 from the start of the section. This is computed as follows:
6524 unit_length: 12 bytes
6526 debug_abbrev_offset: 8 bytes
6527 -----------------------------
6530 debug_line_pointer_sizes [unit] = byte_get (begin + 22, 1);
6531 length = byte_get (begin + 4, 8);
6532 begin += length + 12;
6536 /* For 32-bit DWARF, the 1-byte address_size field is 10 bytes from
6537 the start of the section:
6539 unit_length: 4 bytes
6541 debug_abbrev_offset: 4 bytes
6542 -----------------------------
6545 debug_line_pointer_sizes [unit] = byte_get (begin + 10, 1);
6546 begin += length + 4;
6551 num_debug_line_pointer_sizes = num_units;
6556 display_debug_lines (Elf_Internal_Shdr *section,
6557 unsigned char *start, FILE *file)
6559 unsigned char *hdrptr;
6560 DWARF2_Internal_LineInfo info;
6561 unsigned char *standard_opcodes;
6562 unsigned char *data = start;
6563 unsigned char *end = start + section->sh_size;
6564 unsigned char *end_of_sequence;
6567 int initial_length_size;
6568 unsigned int comp_unit = 0;
6570 printf (_("\nDump of debug contents of section %s:\n\n"),
6571 SECTION_NAME (section));
6573 if (num_debug_line_pointer_sizes == 0)
6574 get_debug_line_pointer_sizes (file);
6578 unsigned int pointer_size;
6582 /* Check the length of the block. */
6583 info.li_length = byte_get (hdrptr, 4);
6586 if (info.li_length == 0xffffffff)
6588 /* This section is 64-bit DWARF 3. */
6589 info.li_length = byte_get (hdrptr, 8);
6592 initial_length_size = 12;
6597 initial_length_size = 4;
6600 if (info.li_length + initial_length_size > section->sh_size)
6603 (_("The line info appears to be corrupt - the section is too small\n"));
6607 /* Check its version number. */
6608 info.li_version = byte_get (hdrptr, 2);
6610 if (info.li_version != 2 && info.li_version != 3)
6612 warn (_("Only DWARF version 2 and 3 line info is currently supported.\n"));
6616 info.li_prologue_length = byte_get (hdrptr, offset_size);
6617 hdrptr += offset_size;
6618 info.li_min_insn_length = byte_get (hdrptr, 1);
6620 info.li_default_is_stmt = byte_get (hdrptr, 1);
6622 info.li_line_base = byte_get (hdrptr, 1);
6624 info.li_line_range = byte_get (hdrptr, 1);
6626 info.li_opcode_base = byte_get (hdrptr, 1);
6629 /* Sign extend the line base field. */
6630 info.li_line_base <<= 24;
6631 info.li_line_base >>= 24;
6633 /* Get the pointer size from the comp unit associated
6634 with this block of line number information. */
6635 if (comp_unit >= num_debug_line_pointer_sizes)
6637 error (_("Not enough comp units for .debug_lines section\n"));
6642 pointer_size = debug_line_pointer_sizes [comp_unit];
6646 printf (_(" Length: %ld\n"), info.li_length);
6647 printf (_(" DWARF Version: %d\n"), info.li_version);
6648 printf (_(" Prologue Length: %d\n"), info.li_prologue_length);
6649 printf (_(" Minimum Instruction Length: %d\n"), info.li_min_insn_length);
6650 printf (_(" Initial value of 'is_stmt': %d\n"), info.li_default_is_stmt);
6651 printf (_(" Line Base: %d\n"), info.li_line_base);
6652 printf (_(" Line Range: %d\n"), info.li_line_range);
6653 printf (_(" Opcode Base: %d\n"), info.li_opcode_base);
6654 printf (_(" (Pointer size: %u)\n"), pointer_size);
6656 end_of_sequence = data + info.li_length + initial_length_size;
6658 reset_state_machine (info.li_default_is_stmt);
6660 /* Display the contents of the Opcodes table. */
6661 standard_opcodes = hdrptr;
6663 printf (_("\n Opcodes:\n"));
6665 for (i = 1; i < info.li_opcode_base; i++)
6666 printf (_(" Opcode %d has %d args\n"), i, standard_opcodes[i - 1]);
6668 /* Display the contents of the Directory table. */
6669 data = standard_opcodes + info.li_opcode_base - 1;
6672 printf (_("\n The Directory Table is empty.\n"));
6675 printf (_("\n The Directory Table:\n"));
6679 printf (_(" %s\n"), data);
6681 data += strlen ((char *) data) + 1;
6685 /* Skip the NUL at the end of the table. */
6688 /* Display the contents of the File Name table. */
6690 printf (_("\n The File Name Table is empty.\n"));
6693 printf (_("\n The File Name Table:\n"));
6694 printf (_(" Entry\tDir\tTime\tSize\tName\n"));
6698 unsigned char *name;
6701 printf (_(" %d\t"), ++state_machine_regs.last_file_entry);
6704 data += strlen ((char *) data) + 1;
6706 printf (_("%lu\t"), read_leb128 (data, & bytes_read, 0));
6708 printf (_("%lu\t"), read_leb128 (data, & bytes_read, 0));
6710 printf (_("%lu\t"), read_leb128 (data, & bytes_read, 0));
6712 printf (_("%s\n"), name);
6716 /* Skip the NUL at the end of the table. */
6719 /* Now display the statements. */
6720 printf (_("\n Line Number Statements:\n"));
6723 while (data < end_of_sequence)
6725 unsigned char op_code;
6731 if (op_code >= info.li_opcode_base)
6733 op_code -= info.li_opcode_base;
6734 adv = (op_code / info.li_line_range) * info.li_min_insn_length;
6735 state_machine_regs.address += adv;
6736 printf (_(" Special opcode %d: advance Address by %d to 0x%lx"),
6737 op_code, adv, state_machine_regs.address);
6738 adv = (op_code % info.li_line_range) + info.li_line_base;
6739 state_machine_regs.line += adv;
6740 printf (_(" and Line by %d to %d\n"),
6741 adv, state_machine_regs.line);
6743 else switch (op_code)
6745 case DW_LNS_extended_op:
6746 data += process_extended_line_op (data, info.li_default_is_stmt,
6751 printf (_(" Copy\n"));
6754 case DW_LNS_advance_pc:
6755 adv = info.li_min_insn_length * read_leb128 (data, & bytes_read, 0);
6757 state_machine_regs.address += adv;
6758 printf (_(" Advance PC by %d to %lx\n"), adv,
6759 state_machine_regs.address);
6762 case DW_LNS_advance_line:
6763 adv = read_leb128 (data, & bytes_read, 1);
6765 state_machine_regs.line += adv;
6766 printf (_(" Advance Line by %d to %d\n"), adv,
6767 state_machine_regs.line);
6770 case DW_LNS_set_file:
6771 adv = read_leb128 (data, & bytes_read, 0);
6773 printf (_(" Set File Name to entry %d in the File Name Table\n"),
6775 state_machine_regs.file = adv;
6778 case DW_LNS_set_column:
6779 adv = read_leb128 (data, & bytes_read, 0);
6781 printf (_(" Set column to %d\n"), adv);
6782 state_machine_regs.column = adv;
6785 case DW_LNS_negate_stmt:
6786 adv = state_machine_regs.is_stmt;
6788 printf (_(" Set is_stmt to %d\n"), adv);
6789 state_machine_regs.is_stmt = adv;
6792 case DW_LNS_set_basic_block:
6793 printf (_(" Set basic block\n"));
6794 state_machine_regs.basic_block = 1;
6797 case DW_LNS_const_add_pc:
6798 adv = (((255 - info.li_opcode_base) / info.li_line_range)
6799 * info.li_min_insn_length);
6800 state_machine_regs.address += adv;
6801 printf (_(" Advance PC by constant %d to 0x%lx\n"), adv,
6802 state_machine_regs.address);
6805 case DW_LNS_fixed_advance_pc:
6806 adv = byte_get (data, 2);
6808 state_machine_regs.address += adv;
6809 printf (_(" Advance PC by fixed size amount %d to 0x%lx\n"),
6810 adv, state_machine_regs.address);
6813 case DW_LNS_set_prologue_end:
6814 printf (_(" Set prologue_end to true\n"));
6817 case DW_LNS_set_epilogue_begin:
6818 printf (_(" Set epilogue_begin to true\n"));
6821 case DW_LNS_set_isa:
6822 adv = read_leb128 (data, & bytes_read, 0);
6824 printf (_(" Set ISA to %d\n"), adv);
6828 printf (_(" Unknown opcode %d with operands: "), op_code);
6831 for (i = standard_opcodes[op_code - 1]; i > 0 ; --i)
6833 printf ("0x%lx%s", read_leb128 (data, &bytes_read, 0),
6834 i == 1 ? "" : ", ");
6849 display_debug_pubnames (Elf_Internal_Shdr *section,
6850 unsigned char *start,
6851 FILE *file ATTRIBUTE_UNUSED)
6853 DWARF2_Internal_PubNames pubnames;
6856 end = start + section->sh_size;
6858 printf (_("Contents of the %s section:\n\n"), SECTION_NAME (section));
6862 unsigned char *data;
6863 unsigned long offset;
6864 int offset_size, initial_length_size;
6868 pubnames.pn_length = byte_get (data, 4);
6870 if (pubnames.pn_length == 0xffffffff)
6872 pubnames.pn_length = byte_get (data, 8);
6875 initial_length_size = 12;
6880 initial_length_size = 4;
6883 pubnames.pn_version = byte_get (data, 2);
6885 pubnames.pn_offset = byte_get (data, offset_size);
6886 data += offset_size;
6887 pubnames.pn_size = byte_get (data, offset_size);
6888 data += offset_size;
6890 start += pubnames.pn_length + initial_length_size;
6892 if (pubnames.pn_version != 2 && pubnames.pn_version != 3)
6894 static int warned = 0;
6898 warn (_("Only DWARF 2 and 3 pubnames are currently supported\n"));
6905 printf (_(" Length: %ld\n"),
6906 pubnames.pn_length);
6907 printf (_(" Version: %d\n"),
6908 pubnames.pn_version);
6909 printf (_(" Offset into .debug_info section: %ld\n"),
6910 pubnames.pn_offset);
6911 printf (_(" Size of area in .debug_info section: %ld\n"),
6914 printf (_("\n Offset\tName\n"));
6918 offset = byte_get (data, offset_size);
6922 data += offset_size;
6923 printf (" %-6ld\t\t%s\n", offset, data);
6924 data += strlen ((char *) data) + 1;
6927 while (offset != 0);
6935 get_TAG_name (unsigned long tag)
6939 case DW_TAG_padding: return "DW_TAG_padding";
6940 case DW_TAG_array_type: return "DW_TAG_array_type";
6941 case DW_TAG_class_type: return "DW_TAG_class_type";
6942 case DW_TAG_entry_point: return "DW_TAG_entry_point";
6943 case DW_TAG_enumeration_type: return "DW_TAG_enumeration_type";
6944 case DW_TAG_formal_parameter: return "DW_TAG_formal_parameter";
6945 case DW_TAG_imported_declaration: return "DW_TAG_imported_declaration";
6946 case DW_TAG_label: return "DW_TAG_label";
6947 case DW_TAG_lexical_block: return "DW_TAG_lexical_block";
6948 case DW_TAG_member: return "DW_TAG_member";
6949 case DW_TAG_pointer_type: return "DW_TAG_pointer_type";
6950 case DW_TAG_reference_type: return "DW_TAG_reference_type";
6951 case DW_TAG_compile_unit: return "DW_TAG_compile_unit";
6952 case DW_TAG_string_type: return "DW_TAG_string_type";
6953 case DW_TAG_structure_type: return "DW_TAG_structure_type";
6954 case DW_TAG_subroutine_type: return "DW_TAG_subroutine_type";
6955 case DW_TAG_typedef: return "DW_TAG_typedef";
6956 case DW_TAG_union_type: return "DW_TAG_union_type";
6957 case DW_TAG_unspecified_parameters: return "DW_TAG_unspecified_parameters";
6958 case DW_TAG_variant: return "DW_TAG_variant";
6959 case DW_TAG_common_block: return "DW_TAG_common_block";
6960 case DW_TAG_common_inclusion: return "DW_TAG_common_inclusion";
6961 case DW_TAG_inheritance: return "DW_TAG_inheritance";
6962 case DW_TAG_inlined_subroutine: return "DW_TAG_inlined_subroutine";
6963 case DW_TAG_module: return "DW_TAG_module";
6964 case DW_TAG_ptr_to_member_type: return "DW_TAG_ptr_to_member_type";
6965 case DW_TAG_set_type: return "DW_TAG_set_type";
6966 case DW_TAG_subrange_type: return "DW_TAG_subrange_type";
6967 case DW_TAG_with_stmt: return "DW_TAG_with_stmt";
6968 case DW_TAG_access_declaration: return "DW_TAG_access_declaration";
6969 case DW_TAG_base_type: return "DW_TAG_base_type";
6970 case DW_TAG_catch_block: return "DW_TAG_catch_block";
6971 case DW_TAG_const_type: return "DW_TAG_const_type";
6972 case DW_TAG_constant: return "DW_TAG_constant";
6973 case DW_TAG_enumerator: return "DW_TAG_enumerator";
6974 case DW_TAG_file_type: return "DW_TAG_file_type";
6975 case DW_TAG_friend: return "DW_TAG_friend";
6976 case DW_TAG_namelist: return "DW_TAG_namelist";
6977 case DW_TAG_namelist_item: return "DW_TAG_namelist_item";
6978 case DW_TAG_packed_type: return "DW_TAG_packed_type";
6979 case DW_TAG_subprogram: return "DW_TAG_subprogram";
6980 case DW_TAG_template_type_param: return "DW_TAG_template_type_param";
6981 case DW_TAG_template_value_param: return "DW_TAG_template_value_param";
6982 case DW_TAG_thrown_type: return "DW_TAG_thrown_type";
6983 case DW_TAG_try_block: return "DW_TAG_try_block";
6984 case DW_TAG_variant_part: return "DW_TAG_variant_part";
6985 case DW_TAG_variable: return "DW_TAG_variable";
6986 case DW_TAG_volatile_type: return "DW_TAG_volatile_type";
6987 case DW_TAG_MIPS_loop: return "DW_TAG_MIPS_loop";
6988 case DW_TAG_format_label: return "DW_TAG_format_label";
6989 case DW_TAG_function_template: return "DW_TAG_function_template";
6990 case DW_TAG_class_template: return "DW_TAG_class_template";
6991 /* DWARF 2.1 values. */
6992 case DW_TAG_dwarf_procedure: return "DW_TAG_dwarf_procedure";
6993 case DW_TAG_restrict_type: return "DW_TAG_restrict_type";
6994 case DW_TAG_interface_type: return "DW_TAG_interface_type";
6995 case DW_TAG_namespace: return "DW_TAG_namespace";
6996 case DW_TAG_imported_module: return "DW_TAG_imported_module";
6997 case DW_TAG_unspecified_type: return "DW_TAG_unspecified_type";
6998 case DW_TAG_partial_unit: return "DW_TAG_partial_unit";
6999 case DW_TAG_imported_unit: return "DW_TAG_imported_unit";
7001 case DW_TAG_upc_shared_type: return "DW_TAG_upc_shared_type";
7002 case DW_TAG_upc_strict_type: return "DW_TAG_upc_strict_type";
7003 case DW_TAG_upc_relaxed_type: return "DW_TAG_upc_relaxed_type";
7006 static char buffer[100];
7008 sprintf (buffer, _("Unknown TAG value: %lx"), tag);
7015 get_AT_name (unsigned long attribute)
7019 case DW_AT_sibling: return "DW_AT_sibling";
7020 case DW_AT_location: return "DW_AT_location";
7021 case DW_AT_name: return "DW_AT_name";
7022 case DW_AT_ordering: return "DW_AT_ordering";
7023 case DW_AT_subscr_data: return "DW_AT_subscr_data";
7024 case DW_AT_byte_size: return "DW_AT_byte_size";
7025 case DW_AT_bit_offset: return "DW_AT_bit_offset";
7026 case DW_AT_bit_size: return "DW_AT_bit_size";
7027 case DW_AT_element_list: return "DW_AT_element_list";
7028 case DW_AT_stmt_list: return "DW_AT_stmt_list";
7029 case DW_AT_low_pc: return "DW_AT_low_pc";
7030 case DW_AT_high_pc: return "DW_AT_high_pc";
7031 case DW_AT_language: return "DW_AT_language";
7032 case DW_AT_member: return "DW_AT_member";
7033 case DW_AT_discr: return "DW_AT_discr";
7034 case DW_AT_discr_value: return "DW_AT_discr_value";
7035 case DW_AT_visibility: return "DW_AT_visibility";
7036 case DW_AT_import: return "DW_AT_import";
7037 case DW_AT_string_length: return "DW_AT_string_length";
7038 case DW_AT_common_reference: return "DW_AT_common_reference";
7039 case DW_AT_comp_dir: return "DW_AT_comp_dir";
7040 case DW_AT_const_value: return "DW_AT_const_value";
7041 case DW_AT_containing_type: return "DW_AT_containing_type";
7042 case DW_AT_default_value: return "DW_AT_default_value";
7043 case DW_AT_inline: return "DW_AT_inline";
7044 case DW_AT_is_optional: return "DW_AT_is_optional";
7045 case DW_AT_lower_bound: return "DW_AT_lower_bound";
7046 case DW_AT_producer: return "DW_AT_producer";
7047 case DW_AT_prototyped: return "DW_AT_prototyped";
7048 case DW_AT_return_addr: return "DW_AT_return_addr";
7049 case DW_AT_start_scope: return "DW_AT_start_scope";
7050 case DW_AT_stride_size: return "DW_AT_stride_size";
7051 case DW_AT_upper_bound: return "DW_AT_upper_bound";
7052 case DW_AT_abstract_origin: return "DW_AT_abstract_origin";
7053 case DW_AT_accessibility: return "DW_AT_accessibility";
7054 case DW_AT_address_class: return "DW_AT_address_class";
7055 case DW_AT_artificial: return "DW_AT_artificial";
7056 case DW_AT_base_types: return "DW_AT_base_types";
7057 case DW_AT_calling_convention: return "DW_AT_calling_convention";
7058 case DW_AT_count: return "DW_AT_count";
7059 case DW_AT_data_member_location: return "DW_AT_data_member_location";
7060 case DW_AT_decl_column: return "DW_AT_decl_column";
7061 case DW_AT_decl_file: return "DW_AT_decl_file";
7062 case DW_AT_decl_line: return "DW_AT_decl_line";
7063 case DW_AT_declaration: return "DW_AT_declaration";
7064 case DW_AT_discr_list: return "DW_AT_discr_list";
7065 case DW_AT_encoding: return "DW_AT_encoding";
7066 case DW_AT_external: return "DW_AT_external";
7067 case DW_AT_frame_base: return "DW_AT_frame_base";
7068 case DW_AT_friend: return "DW_AT_friend";
7069 case DW_AT_identifier_case: return "DW_AT_identifier_case";
7070 case DW_AT_macro_info: return "DW_AT_macro_info";
7071 case DW_AT_namelist_items: return "DW_AT_namelist_items";
7072 case DW_AT_priority: return "DW_AT_priority";
7073 case DW_AT_segment: return "DW_AT_segment";
7074 case DW_AT_specification: return "DW_AT_specification";
7075 case DW_AT_static_link: return "DW_AT_static_link";
7076 case DW_AT_type: return "DW_AT_type";
7077 case DW_AT_use_location: return "DW_AT_use_location";
7078 case DW_AT_variable_parameter: return "DW_AT_variable_parameter";
7079 case DW_AT_virtuality: return "DW_AT_virtuality";
7080 case DW_AT_vtable_elem_location: return "DW_AT_vtable_elem_location";
7081 /* DWARF 2.1 values. */
7082 case DW_AT_allocated: return "DW_AT_allocated";
7083 case DW_AT_associated: return "DW_AT_associated";
7084 case DW_AT_data_location: return "DW_AT_data_location";
7085 case DW_AT_stride: return "DW_AT_stride";
7086 case DW_AT_entry_pc: return "DW_AT_entry_pc";
7087 case DW_AT_use_UTF8: return "DW_AT_use_UTF8";
7088 case DW_AT_extension: return "DW_AT_extension";
7089 case DW_AT_ranges: return "DW_AT_ranges";
7090 case DW_AT_trampoline: return "DW_AT_trampoline";
7091 case DW_AT_call_column: return "DW_AT_call_column";
7092 case DW_AT_call_file: return "DW_AT_call_file";
7093 case DW_AT_call_line: return "DW_AT_call_line";
7094 /* SGI/MIPS extensions. */
7095 case DW_AT_MIPS_fde: return "DW_AT_MIPS_fde";
7096 case DW_AT_MIPS_loop_begin: return "DW_AT_MIPS_loop_begin";
7097 case DW_AT_MIPS_tail_loop_begin: return "DW_AT_MIPS_tail_loop_begin";
7098 case DW_AT_MIPS_epilog_begin: return "DW_AT_MIPS_epilog_begin";
7099 case DW_AT_MIPS_loop_unroll_factor: return "DW_AT_MIPS_loop_unroll_factor";
7100 case DW_AT_MIPS_software_pipeline_depth:
7101 return "DW_AT_MIPS_software_pipeline_depth";
7102 case DW_AT_MIPS_linkage_name: return "DW_AT_MIPS_linkage_name";
7103 case DW_AT_MIPS_stride: return "DW_AT_MIPS_stride";
7104 case DW_AT_MIPS_abstract_name: return "DW_AT_MIPS_abstract_name";
7105 case DW_AT_MIPS_clone_origin: return "DW_AT_MIPS_clone_origin";
7106 case DW_AT_MIPS_has_inlines: return "DW_AT_MIPS_has_inlines";
7107 /* GNU extensions. */
7108 case DW_AT_sf_names: return "DW_AT_sf_names";
7109 case DW_AT_src_info: return "DW_AT_src_info";
7110 case DW_AT_mac_info: return "DW_AT_mac_info";
7111 case DW_AT_src_coords: return "DW_AT_src_coords";
7112 case DW_AT_body_begin: return "DW_AT_body_begin";
7113 case DW_AT_body_end: return "DW_AT_body_end";
7114 case DW_AT_GNU_vector: return "DW_AT_GNU_vector";
7115 /* UPC extension. */
7116 case DW_AT_upc_threads_scaled: return "DW_AT_upc_threads_scaled";
7119 static char buffer[100];
7121 sprintf (buffer, _("Unknown AT value: %lx"), attribute);
7128 get_FORM_name (unsigned long form)
7132 case DW_FORM_addr: return "DW_FORM_addr";
7133 case DW_FORM_block2: return "DW_FORM_block2";
7134 case DW_FORM_block4: return "DW_FORM_block4";
7135 case DW_FORM_data2: return "DW_FORM_data2";
7136 case DW_FORM_data4: return "DW_FORM_data4";
7137 case DW_FORM_data8: return "DW_FORM_data8";
7138 case DW_FORM_string: return "DW_FORM_string";
7139 case DW_FORM_block: return "DW_FORM_block";
7140 case DW_FORM_block1: return "DW_FORM_block1";
7141 case DW_FORM_data1: return "DW_FORM_data1";
7142 case DW_FORM_flag: return "DW_FORM_flag";
7143 case DW_FORM_sdata: return "DW_FORM_sdata";
7144 case DW_FORM_strp: return "DW_FORM_strp";
7145 case DW_FORM_udata: return "DW_FORM_udata";
7146 case DW_FORM_ref_addr: return "DW_FORM_ref_addr";
7147 case DW_FORM_ref1: return "DW_FORM_ref1";
7148 case DW_FORM_ref2: return "DW_FORM_ref2";
7149 case DW_FORM_ref4: return "DW_FORM_ref4";
7150 case DW_FORM_ref8: return "DW_FORM_ref8";
7151 case DW_FORM_ref_udata: return "DW_FORM_ref_udata";
7152 case DW_FORM_indirect: return "DW_FORM_indirect";
7155 static char buffer[100];
7157 sprintf (buffer, _("Unknown FORM value: %lx"), form);
7163 /* FIXME: There are better and more efficient ways to handle
7164 these structures. For now though, I just want something that
7165 is simple to implement. */
7166 typedef struct abbrev_attr
7168 unsigned long attribute;
7170 struct abbrev_attr *next;
7174 typedef struct abbrev_entry
7176 unsigned long entry;
7179 struct abbrev_attr *first_attr;
7180 struct abbrev_attr *last_attr;
7181 struct abbrev_entry *next;
7185 static abbrev_entry *first_abbrev = NULL;
7186 static abbrev_entry *last_abbrev = NULL;
7191 abbrev_entry *abbrev;
7193 for (abbrev = first_abbrev; abbrev;)
7195 abbrev_entry *next = abbrev->next;
7198 for (attr = abbrev->first_attr; attr;)
7200 abbrev_attr *next = attr->next;
7210 last_abbrev = first_abbrev = NULL;
7214 add_abbrev (unsigned long number, unsigned long tag, int children)
7216 abbrev_entry *entry;
7218 entry = malloc (sizeof (*entry));
7224 entry->entry = number;
7226 entry->children = children;
7227 entry->first_attr = NULL;
7228 entry->last_attr = NULL;
7231 if (first_abbrev == NULL)
7232 first_abbrev = entry;
7234 last_abbrev->next = entry;
7236 last_abbrev = entry;
7240 add_abbrev_attr (unsigned long attribute, unsigned long form)
7244 attr = malloc (sizeof (*attr));
7250 attr->attribute = attribute;
7254 if (last_abbrev->first_attr == NULL)
7255 last_abbrev->first_attr = attr;
7257 last_abbrev->last_attr->next = attr;
7259 last_abbrev->last_attr = attr;
7262 /* Processes the (partial) contents of a .debug_abbrev section.
7263 Returns NULL if the end of the section was encountered.
7264 Returns the address after the last byte read if the end of
7265 an abbreviation set was found. */
7267 static unsigned char *
7268 process_abbrev_section (unsigned char *start, unsigned char *end)
7270 if (first_abbrev != NULL)
7276 unsigned long entry;
7278 unsigned long attribute;
7281 entry = read_leb128 (start, & bytes_read, 0);
7282 start += bytes_read;
7284 /* A single zero is supposed to end the section according
7285 to the standard. If there's more, then signal that to
7288 return start == end ? NULL : start;
7290 tag = read_leb128 (start, & bytes_read, 0);
7291 start += bytes_read;
7293 children = *start++;
7295 add_abbrev (entry, tag, children);
7301 attribute = read_leb128 (start, & bytes_read, 0);
7302 start += bytes_read;
7304 form = read_leb128 (start, & bytes_read, 0);
7305 start += bytes_read;
7308 add_abbrev_attr (attribute, form);
7310 while (attribute != 0);
7318 display_debug_macinfo (Elf_Internal_Shdr *section,
7319 unsigned char *start,
7320 FILE *file ATTRIBUTE_UNUSED)
7322 unsigned char *end = start + section->sh_size;
7323 unsigned char *curr = start;
7324 unsigned int bytes_read;
7325 enum dwarf_macinfo_record_type op;
7327 printf (_("Contents of the %s section:\n\n"), SECTION_NAME (section));
7331 unsigned int lineno;
7339 case DW_MACINFO_start_file:
7341 unsigned int filenum;
7343 lineno = read_leb128 (curr, & bytes_read, 0);
7345 filenum = read_leb128 (curr, & bytes_read, 0);
7348 printf (_(" DW_MACINFO_start_file - lineno: %d filenum: %d\n"), lineno, filenum);
7352 case DW_MACINFO_end_file:
7353 printf (_(" DW_MACINFO_end_file\n"));
7356 case DW_MACINFO_define:
7357 lineno = read_leb128 (curr, & bytes_read, 0);
7360 curr += strlen (string) + 1;
7361 printf (_(" DW_MACINFO_define - lineno : %d macro : %s\n"), lineno, string);
7364 case DW_MACINFO_undef:
7365 lineno = read_leb128 (curr, & bytes_read, 0);
7368 curr += strlen (string) + 1;
7369 printf (_(" DW_MACINFO_undef - lineno : %d macro : %s\n"), lineno, string);
7372 case DW_MACINFO_vendor_ext:
7374 unsigned int constant;
7376 constant = read_leb128 (curr, & bytes_read, 0);
7379 curr += strlen (string) + 1;
7380 printf (_(" DW_MACINFO_vendor_ext - constant : %d string : %s\n"), constant, string);
7391 display_debug_abbrev (Elf_Internal_Shdr *section,
7392 unsigned char *start,
7393 FILE *file ATTRIBUTE_UNUSED)
7395 abbrev_entry *entry;
7396 unsigned char *end = start + section->sh_size;
7398 printf (_("Contents of the %s section:\n\n"), SECTION_NAME (section));
7402 start = process_abbrev_section (start, end);
7404 if (first_abbrev == NULL)
7407 printf (_(" Number TAG\n"));
7409 for (entry = first_abbrev; entry; entry = entry->next)
7413 printf (_(" %ld %s [%s]\n"),
7415 get_TAG_name (entry->tag),
7416 entry->children ? _("has children") : _("no children"));
7418 for (attr = entry->first_attr; attr; attr = attr->next)
7420 printf (_(" %-18s %s\n"),
7421 get_AT_name (attr->attribute),
7422 get_FORM_name (attr->form));
7436 static unsigned char *
7437 display_block (unsigned char *data, unsigned long length)
7439 printf (_(" %lu byte block: "), length);
7442 printf ("%lx ", (unsigned long) byte_get (data++, 1));
7448 decode_location_expression (unsigned char * data,
7449 unsigned int pointer_size,
7450 unsigned long length)
7454 unsigned long uvalue;
7455 unsigned char *end = data + length;
7464 printf ("DW_OP_addr: %lx",
7465 (unsigned long) byte_get (data, pointer_size));
7466 data += pointer_size;
7469 printf ("DW_OP_deref");
7472 printf ("DW_OP_const1u: %lu", (unsigned long) byte_get (data++, 1));
7475 printf ("DW_OP_const1s: %ld", (long) byte_get (data++, 1));
7478 printf ("DW_OP_const2u: %lu", (unsigned long) byte_get (data, 2));
7482 printf ("DW_OP_const2s: %ld", (long) byte_get (data, 2));
7486 printf ("DW_OP_const4u: %lu", (unsigned long) byte_get (data, 4));
7490 printf ("DW_OP_const4s: %ld", (long) byte_get (data, 4));
7494 printf ("DW_OP_const8u: %lu %lu", (unsigned long) byte_get (data, 4),
7495 (unsigned long) byte_get (data + 4, 4));
7499 printf ("DW_OP_const8s: %ld %ld", (long) byte_get (data, 4),
7500 (long) byte_get (data + 4, 4));
7504 printf ("DW_OP_constu: %lu", read_leb128 (data, &bytes_read, 0));
7508 printf ("DW_OP_consts: %ld", read_leb128 (data, &bytes_read, 1));
7512 printf ("DW_OP_dup");
7515 printf ("DW_OP_drop");
7518 printf ("DW_OP_over");
7521 printf ("DW_OP_pick: %ld", (unsigned long) byte_get (data++, 1));
7524 printf ("DW_OP_swap");
7527 printf ("DW_OP_rot");
7530 printf ("DW_OP_xderef");
7533 printf ("DW_OP_abs");
7536 printf ("DW_OP_and");
7539 printf ("DW_OP_div");
7542 printf ("DW_OP_minus");
7545 printf ("DW_OP_mod");
7548 printf ("DW_OP_mul");
7551 printf ("DW_OP_neg");
7554 printf ("DW_OP_not");
7557 printf ("DW_OP_or");
7560 printf ("DW_OP_plus");
7562 case DW_OP_plus_uconst:
7563 printf ("DW_OP_plus_uconst: %lu",
7564 read_leb128 (data, &bytes_read, 0));
7568 printf ("DW_OP_shl");
7571 printf ("DW_OP_shr");
7574 printf ("DW_OP_shra");
7577 printf ("DW_OP_xor");
7580 printf ("DW_OP_bra: %ld", (long) byte_get (data, 2));
7584 printf ("DW_OP_eq");
7587 printf ("DW_OP_ge");
7590 printf ("DW_OP_gt");
7593 printf ("DW_OP_le");
7596 printf ("DW_OP_lt");
7599 printf ("DW_OP_ne");
7602 printf ("DW_OP_skip: %ld", (long) byte_get (data, 2));
7638 printf ("DW_OP_lit%d", op - DW_OP_lit0);
7673 printf ("DW_OP_reg%d", op - DW_OP_reg0);
7708 printf ("DW_OP_breg%d: %ld", op - DW_OP_breg0,
7709 read_leb128 (data, &bytes_read, 1));
7714 printf ("DW_OP_regx: %lu", read_leb128 (data, &bytes_read, 0));
7718 printf ("DW_OP_fbreg: %ld", read_leb128 (data, &bytes_read, 1));
7722 uvalue = read_leb128 (data, &bytes_read, 0);
7724 printf ("DW_OP_bregx: %lu %ld", uvalue,
7725 read_leb128 (data, &bytes_read, 1));
7729 printf ("DW_OP_piece: %lu", read_leb128 (data, &bytes_read, 0));
7732 case DW_OP_deref_size:
7733 printf ("DW_OP_deref_size: %ld", (long) byte_get (data++, 1));
7735 case DW_OP_xderef_size:
7736 printf ("DW_OP_xderef_size: %ld", (long) byte_get (data++, 1));
7739 printf ("DW_OP_nop");
7742 /* DWARF 3 extensions. */
7743 case DW_OP_push_object_address:
7744 printf ("DW_OP_push_object_address");
7747 printf ("DW_OP_call2: <%lx>", (long) byte_get (data, 2));
7751 printf ("DW_OP_call4: <%lx>", (long) byte_get (data, 4));
7754 case DW_OP_call_ref:
7755 printf ("DW_OP_call_ref");
7758 /* GNU extensions. */
7759 case DW_OP_GNU_push_tls_address:
7760 printf ("DW_OP_GNU_push_tls_address");
7764 if (op >= DW_OP_lo_user
7765 && op <= DW_OP_hi_user)
7766 printf (_("(User defined location op)"));
7768 printf (_("(Unknown location op)"));
7769 /* No way to tell where the next op is, so just bail. */
7773 /* Separate the ops. */
7779 static const char *debug_loc_contents;
7780 static bfd_vma debug_loc_size;
7783 load_debug_loc (FILE *file)
7785 Elf_Internal_Shdr *sec;
7787 /* If it is already loaded, do nothing. */
7788 if (debug_loc_contents != NULL)
7791 /* Locate the .debug_loc section. */
7792 sec = find_section (".debug_loc");
7796 debug_loc_size = sec->sh_size;
7798 debug_loc_contents = get_data (NULL, file, sec->sh_offset, sec->sh_size,
7799 _("debug_loc section data"));
7803 free_debug_loc (void)
7805 if (debug_loc_contents == NULL)
7808 free ((char *) debug_loc_contents);
7809 debug_loc_contents = NULL;
7815 display_debug_loc (Elf_Internal_Shdr *section,
7816 unsigned char *start, FILE *file)
7818 unsigned char *section_end;
7819 unsigned long bytes;
7820 unsigned char *section_begin = start;
7822 unsigned int comp_unit = 0;
7824 addr = section->sh_addr;
7825 bytes = section->sh_size;
7826 section_end = start + bytes;
7830 printf (_("\nThe .debug_loc section is empty.\n"));
7834 if (num_debug_line_pointer_sizes == 0)
7835 get_debug_line_pointer_sizes (file);
7837 printf (_("Contents of the .debug_loc section:\n\n"));
7838 printf (_("\n Offset Begin End Expression\n"));
7840 while (start < section_end)
7842 unsigned long begin;
7844 unsigned short length;
7845 unsigned long offset;
7846 unsigned int pointer_size;
7848 offset = start - section_begin;
7850 /* Get the pointer size from the comp unit associated
7851 with this block of location information. */
7852 if (comp_unit >= num_debug_line_pointer_sizes)
7854 error (_("Not enough comp units for .debug_loc section\n"));
7859 pointer_size = debug_line_pointer_sizes [comp_unit];
7865 begin = byte_get (start, pointer_size);
7866 start += pointer_size;
7867 end = byte_get (start, pointer_size);
7868 start += pointer_size;
7870 if (begin == 0 && end == 0)
7873 /* For now, skip any base address specifiers. */
7874 if (begin == 0xffffffff)
7880 length = byte_get (start, 2);
7883 printf (" %8.8lx %8.8lx %8.8lx (", offset, begin, end);
7884 decode_location_expression (start, pointer_size, length);
7894 static const char *debug_str_contents;
7895 static bfd_vma debug_str_size;
7898 load_debug_str (FILE *file)
7900 Elf_Internal_Shdr *sec;
7902 /* If it is already loaded, do nothing. */
7903 if (debug_str_contents != NULL)
7906 /* Locate the .debug_str section. */
7907 sec = find_section (".debug_str");
7911 debug_str_size = sec->sh_size;
7913 debug_str_contents = get_data (NULL, file, sec->sh_offset, sec->sh_size,
7914 _("debug_str section data"));
7918 free_debug_str (void)
7920 if (debug_str_contents == NULL)
7923 free ((char *) debug_str_contents);
7924 debug_str_contents = NULL;
7929 fetch_indirect_string (unsigned long offset)
7931 if (debug_str_contents == NULL)
7932 return _("<no .debug_str section>");
7934 if (offset > debug_str_size)
7935 return _("<offset is too big>");
7937 return debug_str_contents + offset;
7941 display_debug_str (Elf_Internal_Shdr *section,
7942 unsigned char *start,
7943 FILE *file ATTRIBUTE_UNUSED)
7945 unsigned long bytes;
7948 addr = section->sh_addr;
7949 bytes = section->sh_size;
7953 printf (_("\nThe .debug_str section is empty.\n"));
7957 printf (_("Contents of the .debug_str section:\n\n"));
7965 lbytes = (bytes > 16 ? 16 : bytes);
7967 printf (" 0x%8.8lx ", (unsigned long) addr);
7969 for (j = 0; j < 16; j++)
7972 printf ("%2.2x", start[j]);
7980 for (j = 0; j < lbytes; j++)
7983 if (k >= ' ' && k < 0x80)
7999 static unsigned char *
8000 read_and_display_attr_value (unsigned long attribute,
8002 unsigned char *data,
8003 unsigned long cu_offset,
8004 unsigned long pointer_size,
8005 unsigned long offset_size,
8008 unsigned long uvalue = 0;
8009 unsigned char *block_start = NULL;
8017 case DW_FORM_ref_addr:
8018 if (dwarf_version == 2)
8020 uvalue = byte_get (data, pointer_size);
8021 data += pointer_size;
8023 else if (dwarf_version == 3)
8025 uvalue = byte_get (data, offset_size);
8026 data += offset_size;
8030 error (_("Internal error: DWARF version is not 2 or 3.\n"));
8035 uvalue = byte_get (data, pointer_size);
8036 data += pointer_size;
8040 uvalue = byte_get (data, offset_size);
8041 data += offset_size;
8047 uvalue = byte_get (data++, 1);
8052 uvalue = byte_get (data, 2);
8058 uvalue = byte_get (data, 4);
8063 uvalue = read_leb128 (data, & bytes_read, 1);
8067 case DW_FORM_ref_udata:
8069 uvalue = read_leb128 (data, & bytes_read, 0);
8073 case DW_FORM_indirect:
8074 form = read_leb128 (data, & bytes_read, 0);
8076 printf (" %s", get_FORM_name (form));
8077 return read_and_display_attr_value (attribute, form, data, cu_offset,
8078 pointer_size, offset_size,
8084 case DW_FORM_ref_addr:
8085 printf (" <#%lx>", uvalue);
8091 case DW_FORM_ref_udata:
8092 printf (" <%lx>", uvalue + cu_offset);
8096 printf (" %#lx", uvalue);
8105 printf (" %ld", uvalue);
8110 uvalue = byte_get (data, 4);
8111 printf (" %lx", uvalue);
8112 printf (" %lx", (unsigned long) byte_get (data + 4, 4));
8116 case DW_FORM_string:
8117 printf (" %s", data);
8118 data += strlen ((char *) data) + 1;
8122 uvalue = read_leb128 (data, & bytes_read, 0);
8123 block_start = data + bytes_read;
8124 data = display_block (block_start, uvalue);
8127 case DW_FORM_block1:
8128 uvalue = byte_get (data, 1);
8129 block_start = data + 1;
8130 data = display_block (block_start, uvalue);
8133 case DW_FORM_block2:
8134 uvalue = byte_get (data, 2);
8135 block_start = data + 2;
8136 data = display_block (block_start, uvalue);
8139 case DW_FORM_block4:
8140 uvalue = byte_get (data, 4);
8141 block_start = data + 4;
8142 data = display_block (block_start, uvalue);
8146 printf (_(" (indirect string, offset: 0x%lx): %s"),
8147 uvalue, fetch_indirect_string (uvalue));
8150 case DW_FORM_indirect:
8151 /* Handled above. */
8155 warn (_("Unrecognized form: %d\n"), form);
8159 /* For some attributes we can display further information. */
8168 case DW_INL_not_inlined:
8169 printf (_("(not inlined)"));
8171 case DW_INL_inlined:
8172 printf (_("(inlined)"));
8174 case DW_INL_declared_not_inlined:
8175 printf (_("(declared as inline but ignored)"));
8177 case DW_INL_declared_inlined:
8178 printf (_("(declared as inline and inlined)"));
8181 printf (_(" (Unknown inline attribute value: %lx)"), uvalue);
8186 case DW_AT_language:
8189 case DW_LANG_C: printf ("(non-ANSI C)"); break;
8190 case DW_LANG_C89: printf ("(ANSI C)"); break;
8191 case DW_LANG_C_plus_plus: printf ("(C++)"); break;
8192 case DW_LANG_Fortran77: printf ("(FORTRAN 77)"); break;
8193 case DW_LANG_Fortran90: printf ("(Fortran 90)"); break;
8194 case DW_LANG_Modula2: printf ("(Modula 2)"); break;
8195 case DW_LANG_Pascal83: printf ("(ANSI Pascal)"); break;
8196 case DW_LANG_Ada83: printf ("(Ada)"); break;
8197 case DW_LANG_Cobol74: printf ("(Cobol 74)"); break;
8198 case DW_LANG_Cobol85: printf ("(Cobol 85)"); break;
8199 /* DWARF 2.1 values. */
8200 case DW_LANG_C99: printf ("(ANSI C99)"); break;
8201 case DW_LANG_Ada95: printf ("(ADA 95)"); break;
8202 case DW_LANG_Fortran95: printf ("(Fortran 95)"); break;
8203 /* MIPS extension. */
8204 case DW_LANG_Mips_Assembler: printf ("(MIPS assembler)"); break;
8205 /* UPC extension. */
8206 case DW_LANG_Upc: printf ("(Unified Parallel C)"); break;
8208 printf ("(Unknown: %lx)", uvalue);
8213 case DW_AT_encoding:
8216 case DW_ATE_void: printf ("(void)"); break;
8217 case DW_ATE_address: printf ("(machine address)"); break;
8218 case DW_ATE_boolean: printf ("(boolean)"); break;
8219 case DW_ATE_complex_float: printf ("(complex float)"); break;
8220 case DW_ATE_float: printf ("(float)"); break;
8221 case DW_ATE_signed: printf ("(signed)"); break;
8222 case DW_ATE_signed_char: printf ("(signed char)"); break;
8223 case DW_ATE_unsigned: printf ("(unsigned)"); break;
8224 case DW_ATE_unsigned_char: printf ("(unsigned char)"); break;
8225 /* DWARF 2.1 value. */
8226 case DW_ATE_imaginary_float: printf ("(imaginary float)"); break;
8228 if (uvalue >= DW_ATE_lo_user
8229 && uvalue <= DW_ATE_hi_user)
8230 printf ("(user defined type)");
8232 printf ("(unknown type)");
8237 case DW_AT_accessibility:
8240 case DW_ACCESS_public: printf ("(public)"); break;
8241 case DW_ACCESS_protected: printf ("(protected)"); break;
8242 case DW_ACCESS_private: printf ("(private)"); break;
8244 printf ("(unknown accessibility)");
8249 case DW_AT_visibility:
8252 case DW_VIS_local: printf ("(local)"); break;
8253 case DW_VIS_exported: printf ("(exported)"); break;
8254 case DW_VIS_qualified: printf ("(qualified)"); break;
8255 default: printf ("(unknown visibility)"); break;
8259 case DW_AT_virtuality:
8262 case DW_VIRTUALITY_none: printf ("(none)"); break;
8263 case DW_VIRTUALITY_virtual: printf ("(virtual)"); break;
8264 case DW_VIRTUALITY_pure_virtual:printf ("(pure_virtual)"); break;
8265 default: printf ("(unknown virtuality)"); break;
8269 case DW_AT_identifier_case:
8272 case DW_ID_case_sensitive: printf ("(case_sensitive)"); break;
8273 case DW_ID_up_case: printf ("(up_case)"); break;
8274 case DW_ID_down_case: printf ("(down_case)"); break;
8275 case DW_ID_case_insensitive: printf ("(case_insensitive)"); break;
8276 default: printf ("(unknown case)"); break;
8280 case DW_AT_calling_convention:
8283 case DW_CC_normal: printf ("(normal)"); break;
8284 case DW_CC_program: printf ("(program)"); break;
8285 case DW_CC_nocall: printf ("(nocall)"); break;
8287 if (uvalue >= DW_CC_lo_user
8288 && uvalue <= DW_CC_hi_user)
8289 printf ("(user defined)");
8291 printf ("(unknown convention)");
8295 case DW_AT_ordering:
8298 case -1: printf ("(undefined)"); break;
8299 case 0: printf ("(row major)"); break;
8300 case 1: printf ("(column major)"); break;
8304 case DW_AT_frame_base:
8305 case DW_AT_location:
8306 case DW_AT_data_member_location:
8307 case DW_AT_vtable_elem_location:
8308 case DW_AT_allocated:
8309 case DW_AT_associated:
8310 case DW_AT_data_location:
8312 case DW_AT_upper_bound:
8313 case DW_AT_lower_bound:
8317 decode_location_expression (block_start, pointer_size, uvalue);
8320 else if (form == DW_FORM_data4 || form == DW_FORM_data8)
8323 printf ("location list");
8335 static unsigned char *
8336 read_and_display_attr (unsigned long attribute,
8338 unsigned char *data,
8339 unsigned long cu_offset,
8340 unsigned long pointer_size,
8341 unsigned long offset_size,
8344 printf (" %-18s:", get_AT_name (attribute));
8345 data = read_and_display_attr_value (attribute, form, data, cu_offset,
8346 pointer_size, offset_size, dwarf_version);
8352 display_debug_info (Elf_Internal_Shdr *section,
8353 unsigned char *start,
8356 unsigned char *end = start + section->sh_size;
8357 unsigned char *section_begin = start;
8359 printf (_("The section %s contains:\n\n"), SECTION_NAME (section));
8361 load_debug_str (file);
8362 load_debug_loc (file);
8366 DWARF2_Internal_CompUnit compunit;
8367 Elf_Internal_Shdr *relsec;
8368 unsigned char *hdrptr;
8369 unsigned char *cu_abbrev_offset_ptr;
8370 unsigned char *tags;
8372 unsigned long cu_offset;
8374 int initial_length_size;
8378 compunit.cu_length = byte_get (hdrptr, 4);
8381 if (compunit.cu_length == 0xffffffff)
8383 compunit.cu_length = byte_get (hdrptr, 8);
8386 initial_length_size = 12;
8391 initial_length_size = 4;
8394 compunit.cu_version = byte_get (hdrptr, 2);
8397 /* Apply addends of RELA relocations. */
8398 for (relsec = section_headers;
8399 relsec < section_headers + elf_header.e_shnum;
8402 unsigned long nrelas;
8403 Elf_Internal_Rela *rela, *rp;
8404 Elf_Internal_Shdr *symsec;
8405 Elf_Internal_Sym *symtab;
8406 Elf_Internal_Sym *sym;
8408 if (relsec->sh_type != SHT_RELA
8409 || SECTION_HEADER (relsec->sh_info) != section
8410 || relsec->sh_size == 0)
8413 if (!slurp_rela_relocs (file, relsec->sh_offset, relsec->sh_size,
8417 symsec = SECTION_HEADER (relsec->sh_link);
8418 symtab = GET_ELF_SYMBOLS (file, symsec);
8420 for (rp = rela; rp < rela + nrelas; ++rp)
8424 if (rp->r_offset >= (bfd_vma) (hdrptr - section_begin)
8425 && section->sh_size > (bfd_vma) offset_size
8426 && rp->r_offset <= section->sh_size - offset_size)
8427 loc = section_begin + rp->r_offset;
8433 sym = symtab + ELF32_R_SYM (rp->r_info);
8435 if (ELF32_R_SYM (rp->r_info) != 0
8436 && ELF32_ST_TYPE (sym->st_info) != STT_SECTION)
8438 warn (_("Skipping unexpected symbol type %u\n"),
8439 ELF32_ST_TYPE (sym->st_info));
8445 sym = symtab + ELF64_R_SYM (rp->r_info);
8447 if (ELF64_R_SYM (rp->r_info) != 0
8448 && ELF64_ST_TYPE (sym->st_info) != STT_SECTION)
8450 warn (_("Skipping unexpected symbol type %u\n"),
8451 ELF64_ST_TYPE (sym->st_info));
8456 byte_put (loc, rp->r_addend, offset_size);
8463 cu_abbrev_offset_ptr = hdrptr;
8464 compunit.cu_abbrev_offset = byte_get (hdrptr, offset_size);
8465 hdrptr += offset_size;
8467 compunit.cu_pointer_size = byte_get (hdrptr, 1);
8471 cu_offset = start - section_begin;
8472 start += compunit.cu_length + initial_length_size;
8474 printf (_(" Compilation Unit @ %lx:\n"), cu_offset);
8475 printf (_(" Length: %ld\n"), compunit.cu_length);
8476 printf (_(" Version: %d\n"), compunit.cu_version);
8477 printf (_(" Abbrev Offset: %ld\n"), compunit.cu_abbrev_offset);
8478 printf (_(" Pointer Size: %d\n"), compunit.cu_pointer_size);
8480 if (compunit.cu_version != 2 && compunit.cu_version != 3)
8482 warn (_("Only version 2 and 3 DWARF debug information is currently supported.\n"));
8488 /* Read in the abbrevs used by this compilation unit. */
8490 Elf_Internal_Shdr *sec;
8491 unsigned char *begin;
8493 /* Locate the .debug_abbrev section and process it. */
8494 sec = find_section (".debug_abbrev");
8497 warn (_("Unable to locate .debug_abbrev section!\n"));
8501 begin = get_data (NULL, file, sec->sh_offset, sec->sh_size,
8502 _("debug_abbrev section data"));
8506 process_abbrev_section (begin + compunit.cu_abbrev_offset,
8507 begin + sec->sh_size);
8513 while (tags < start)
8516 unsigned long abbrev_number;
8517 abbrev_entry *entry;
8520 abbrev_number = read_leb128 (tags, & bytes_read, 0);
8523 /* A null DIE marks the end of a list of children. */
8524 if (abbrev_number == 0)
8530 /* Scan through the abbreviation list until we reach the
8532 for (entry = first_abbrev;
8533 entry && entry->entry != abbrev_number;
8534 entry = entry->next)
8539 warn (_("Unable to locate entry %lu in the abbreviation table\n"),
8544 printf (_(" <%d><%lx>: Abbrev Number: %lu (%s)\n"),
8546 (unsigned long) (tags - section_begin - bytes_read),
8548 get_TAG_name (entry->tag));
8550 for (attr = entry->first_attr; attr; attr = attr->next)
8551 tags = read_and_display_attr (attr->attribute,
8554 compunit.cu_pointer_size,
8556 compunit.cu_version);
8558 if (entry->children)
8572 display_debug_aranges (Elf_Internal_Shdr *section,
8573 unsigned char *start,
8574 FILE *file ATTRIBUTE_UNUSED)
8576 unsigned char *end = start + section->sh_size;
8578 printf (_("The section %s contains:\n\n"), SECTION_NAME (section));
8582 unsigned char *hdrptr;
8583 DWARF2_Internal_ARange arange;
8584 unsigned char *ranges;
8585 unsigned long length;
8586 unsigned long address;
8589 int initial_length_size;
8593 arange.ar_length = byte_get (hdrptr, 4);
8596 if (arange.ar_length == 0xffffffff)
8598 arange.ar_length = byte_get (hdrptr, 8);
8601 initial_length_size = 12;
8606 initial_length_size = 4;
8609 arange.ar_version = byte_get (hdrptr, 2);
8612 arange.ar_info_offset = byte_get (hdrptr, offset_size);
8613 hdrptr += offset_size;
8615 arange.ar_pointer_size = byte_get (hdrptr, 1);
8618 arange.ar_segment_size = byte_get (hdrptr, 1);
8621 if (arange.ar_version != 2 && arange.ar_version != 3)
8623 warn (_("Only DWARF 2 and 3 aranges are currently supported.\n"));
8627 printf (_(" Length: %ld\n"), arange.ar_length);
8628 printf (_(" Version: %d\n"), arange.ar_version);
8629 printf (_(" Offset into .debug_info: %lx\n"), arange.ar_info_offset);
8630 printf (_(" Pointer Size: %d\n"), arange.ar_pointer_size);
8631 printf (_(" Segment Size: %d\n"), arange.ar_segment_size);
8633 printf (_("\n Address Length\n"));
8637 /* Must pad to an alignment boundary that is twice the pointer size. */
8638 excess = (hdrptr - start) % (2 * arange.ar_pointer_size);
8640 ranges += (2 * arange.ar_pointer_size) - excess;
8644 address = byte_get (ranges, arange.ar_pointer_size);
8646 ranges += arange.ar_pointer_size;
8648 length = byte_get (ranges, arange.ar_pointer_size);
8650 ranges += arange.ar_pointer_size;
8652 /* A pair of zeros marks the end of the list. */
8653 if (address == 0 && length == 0)
8656 printf (" %8.8lx %lu\n", address, length);
8659 start += arange.ar_length + initial_length_size;
8667 typedef struct Frame_Chunk
8669 struct Frame_Chunk *next;
8670 unsigned char *chunk_start;
8672 /* DW_CFA_{undefined,same_value,offset,register,unreferenced} */
8673 short int *col_type;
8676 unsigned int code_factor;
8678 unsigned long pc_begin;
8679 unsigned long pc_range;
8683 unsigned char fde_encoding;
8684 unsigned char cfa_exp;
8688 /* A marker for a col_type that means this column was never referenced
8689 in the frame info. */
8690 #define DW_CFA_unreferenced (-1)
8693 frame_need_space (Frame_Chunk *fc, int reg)
8695 int prev = fc->ncols;
8697 if (reg < fc->ncols)
8700 fc->ncols = reg + 1;
8701 fc->col_type = xrealloc (fc->col_type, fc->ncols * sizeof (short int));
8702 fc->col_offset = xrealloc (fc->col_offset, fc->ncols * sizeof (int));
8704 while (prev < fc->ncols)
8706 fc->col_type[prev] = DW_CFA_unreferenced;
8707 fc->col_offset[prev] = 0;
8713 frame_display_row (Frame_Chunk *fc, int *need_col_headers, int *max_regs)
8718 if (*max_regs < fc->ncols)
8719 *max_regs = fc->ncols;
8721 if (*need_col_headers)
8723 *need_col_headers = 0;
8725 printf (" LOC CFA ");
8727 for (r = 0; r < *max_regs; r++)
8728 if (fc->col_type[r] != DW_CFA_unreferenced)
8733 printf ("r%-4d", r);
8739 printf ("%08lx ", fc->pc_begin);
8741 strcpy (tmp, "exp");
8743 sprintf (tmp, "r%d%+d", fc->cfa_reg, fc->cfa_offset);
8744 printf ("%-8s ", tmp);
8746 for (r = 0; r < fc->ncols; r++)
8748 if (fc->col_type[r] != DW_CFA_unreferenced)
8750 switch (fc->col_type[r])
8752 case DW_CFA_undefined:
8755 case DW_CFA_same_value:
8759 sprintf (tmp, "c%+d", fc->col_offset[r]);
8761 case DW_CFA_register:
8762 sprintf (tmp, "r%d", fc->col_offset[r]);
8764 case DW_CFA_expression:
8765 strcpy (tmp, "exp");
8768 strcpy (tmp, "n/a");
8771 printf ("%-5s", tmp);
8778 size_of_encoded_value (int encoding)
8780 switch (encoding & 0x7)
8783 case 0: return is_32bit_elf ? 4 : 8;
8791 get_encoded_value (unsigned char *data, int encoding)
8793 int size = size_of_encoded_value (encoding);
8794 if (encoding & DW_EH_PE_signed)
8795 return byte_get_signed (data, size);
8797 return byte_get (data, size);
8800 #define GET(N) byte_get (start, N); start += N
8801 #define LEB() read_leb128 (start, & length_return, 0); start += length_return
8802 #define SLEB() read_leb128 (start, & length_return, 1); start += length_return
8805 display_debug_frames (Elf_Internal_Shdr *section,
8806 unsigned char *start,
8807 FILE *file ATTRIBUTE_UNUSED)
8809 unsigned char *end = start + section->sh_size;
8810 unsigned char *section_start = start;
8811 Frame_Chunk *chunks = 0;
8812 Frame_Chunk *remembered_state = 0;
8814 int is_eh = (strcmp (SECTION_NAME (section), ".eh_frame") == 0);
8817 int addr_size = is_32bit_elf ? 4 : 8;
8819 printf (_("The section %s contains:\n"), SECTION_NAME (section));
8823 unsigned char *saved_start;
8824 unsigned char *block_end;
8825 unsigned long length;
8826 unsigned long cie_id;
8829 int need_col_headers = 1;
8830 unsigned char *augmentation_data = NULL;
8831 unsigned long augmentation_data_len = 0;
8832 int encoded_ptr_size = addr_size;
8834 int initial_length_size;
8836 saved_start = start;
8837 length = byte_get (start, 4); start += 4;
8841 printf ("\n%08lx ZERO terminator\n\n",
8842 (unsigned long)(saved_start - section_start));
8846 if (length == 0xffffffff)
8848 length = byte_get (start, 8);
8851 initial_length_size = 12;
8856 initial_length_size = 4;
8859 block_end = saved_start + length + initial_length_size;
8860 cie_id = byte_get (start, offset_size); start += offset_size;
8862 if (is_eh ? (cie_id == 0) : (cie_id == DW_CIE_ID))
8866 fc = xmalloc (sizeof (Frame_Chunk));
8867 memset (fc, 0, sizeof (Frame_Chunk));
8871 fc->chunk_start = saved_start;
8873 fc->col_type = xmalloc (sizeof (short int));
8874 fc->col_offset = xmalloc (sizeof (int));
8875 frame_need_space (fc, max_regs-1);
8879 fc->augmentation = start;
8880 start = strchr (start, '\0') + 1;
8882 if (fc->augmentation[0] == 'z')
8884 fc->code_factor = LEB ();
8885 fc->data_factor = SLEB ();
8886 fc->ra = byte_get (start, 1); start += 1;
8887 augmentation_data_len = LEB ();
8888 augmentation_data = start;
8889 start += augmentation_data_len;
8891 else if (strcmp (fc->augmentation, "eh") == 0)
8894 fc->code_factor = LEB ();
8895 fc->data_factor = SLEB ();
8896 fc->ra = byte_get (start, 1); start += 1;
8900 fc->code_factor = LEB ();
8901 fc->data_factor = SLEB ();
8902 fc->ra = byte_get (start, 1); start += 1;
8906 if (do_debug_frames_interp)
8907 printf ("\n%08lx %08lx %08lx CIE \"%s\" cf=%d df=%d ra=%d\n",
8908 (unsigned long)(saved_start - section_start), length, cie_id,
8909 fc->augmentation, fc->code_factor, fc->data_factor,
8913 printf ("\n%08lx %08lx %08lx CIE\n",
8914 (unsigned long)(saved_start - section_start), length, cie_id);
8915 printf (" Version: %d\n", version);
8916 printf (" Augmentation: \"%s\"\n", fc->augmentation);
8917 printf (" Code alignment factor: %u\n", fc->code_factor);
8918 printf (" Data alignment factor: %d\n", fc->data_factor);
8919 printf (" Return address column: %d\n", fc->ra);
8921 if (augmentation_data_len)
8924 printf (" Augmentation data: ");
8925 for (i = 0; i < augmentation_data_len; ++i)
8926 printf (" %02x", augmentation_data[i]);
8932 if (augmentation_data_len)
8934 unsigned char *p, *q;
8935 p = fc->augmentation + 1;
8936 q = augmentation_data;
8943 q += 1 + size_of_encoded_value (*q);
8945 fc->fde_encoding = *q++;
8951 if (fc->fde_encoding)
8952 encoded_ptr_size = size_of_encoded_value (fc->fde_encoding);
8955 frame_need_space (fc, fc->ra);
8959 unsigned char *look_for;
8960 static Frame_Chunk fde_fc;
8963 memset (fc, 0, sizeof (Frame_Chunk));
8965 look_for = is_eh ? start - 4 - cie_id : section_start + cie_id;
8967 for (cie = chunks; cie ; cie = cie->next)
8968 if (cie->chunk_start == look_for)
8973 warn ("Invalid CIE pointer %08lx in FDE at %08lx\n",
8974 cie_id, saved_start);
8977 fc->col_type = xmalloc (sizeof (short int));
8978 fc->col_offset = xmalloc (sizeof (int));
8979 frame_need_space (fc, max_regs - 1);
8981 fc->augmentation = "";
8982 fc->fde_encoding = 0;
8986 fc->ncols = cie->ncols;
8987 fc->col_type = xmalloc (fc->ncols * sizeof (short int));
8988 fc->col_offset = xmalloc (fc->ncols * sizeof (int));
8989 memcpy (fc->col_type, cie->col_type, fc->ncols * sizeof (short int));
8990 memcpy (fc->col_offset, cie->col_offset, fc->ncols * sizeof (int));
8991 fc->augmentation = cie->augmentation;
8992 fc->code_factor = cie->code_factor;
8993 fc->data_factor = cie->data_factor;
8994 fc->cfa_reg = cie->cfa_reg;
8995 fc->cfa_offset = cie->cfa_offset;
8997 frame_need_space (fc, max_regs-1);
8998 fc->fde_encoding = cie->fde_encoding;
9001 if (fc->fde_encoding)
9002 encoded_ptr_size = size_of_encoded_value (fc->fde_encoding);
9004 fc->pc_begin = get_encoded_value (start, fc->fde_encoding);
9005 if ((fc->fde_encoding & 0x70) == DW_EH_PE_pcrel)
9006 fc->pc_begin += section->sh_addr + (start - section_start);
9007 start += encoded_ptr_size;
9008 fc->pc_range = byte_get (start, encoded_ptr_size);
9009 start += encoded_ptr_size;
9011 if (cie->augmentation[0] == 'z')
9013 augmentation_data_len = LEB ();
9014 augmentation_data = start;
9015 start += augmentation_data_len;
9018 printf ("\n%08lx %08lx %08lx FDE cie=%08lx pc=%08lx..%08lx\n",
9019 (unsigned long)(saved_start - section_start), length, cie_id,
9020 (unsigned long)(cie->chunk_start - section_start),
9021 fc->pc_begin, fc->pc_begin + fc->pc_range);
9022 if (! do_debug_frames_interp && augmentation_data_len)
9025 printf (" Augmentation data: ");
9026 for (i = 0; i < augmentation_data_len; ++i)
9027 printf (" %02x", augmentation_data[i]);
9033 /* At this point, fc is the current chunk, cie (if any) is set, and we're
9034 about to interpret instructions for the chunk. */
9035 /* ??? At present we need to do this always, since this sizes the
9036 fc->col_type and fc->col_offset arrays, which we write into always.
9037 We should probably split the interpreted and non-interpreted bits
9038 into two different routines, since there's so much that doesn't
9039 really overlap between them. */
9040 if (1 || do_debug_frames_interp)
9042 /* Start by making a pass over the chunk, allocating storage
9043 and taking note of what registers are used. */
9044 unsigned char *tmp = start;
9046 while (start < block_end)
9049 unsigned long reg, tmp;
9056 /* Warning: if you add any more cases to this switch, be
9057 sure to add them to the corresponding switch below. */
9060 case DW_CFA_advance_loc:
9064 frame_need_space (fc, opa);
9065 fc->col_type[opa] = DW_CFA_undefined;
9067 case DW_CFA_restore:
9068 frame_need_space (fc, opa);
9069 fc->col_type[opa] = DW_CFA_undefined;
9071 case DW_CFA_set_loc:
9072 start += encoded_ptr_size;
9074 case DW_CFA_advance_loc1:
9077 case DW_CFA_advance_loc2:
9080 case DW_CFA_advance_loc4:
9083 case DW_CFA_offset_extended:
9084 reg = LEB (); LEB ();
9085 frame_need_space (fc, reg);
9086 fc->col_type[reg] = DW_CFA_undefined;
9088 case DW_CFA_restore_extended:
9090 frame_need_space (fc, reg);
9091 fc->col_type[reg] = DW_CFA_undefined;
9093 case DW_CFA_undefined:
9095 frame_need_space (fc, reg);
9096 fc->col_type[reg] = DW_CFA_undefined;
9098 case DW_CFA_same_value:
9100 frame_need_space (fc, reg);
9101 fc->col_type[reg] = DW_CFA_undefined;
9103 case DW_CFA_register:
9104 reg = LEB (); LEB ();
9105 frame_need_space (fc, reg);
9106 fc->col_type[reg] = DW_CFA_undefined;
9108 case DW_CFA_def_cfa:
9111 case DW_CFA_def_cfa_register:
9114 case DW_CFA_def_cfa_offset:
9117 case DW_CFA_def_cfa_expression:
9121 case DW_CFA_expression:
9125 frame_need_space (fc, reg);
9126 fc->col_type[reg] = DW_CFA_undefined;
9128 case DW_CFA_offset_extended_sf:
9129 reg = LEB (); SLEB ();
9130 frame_need_space (fc, reg);
9131 fc->col_type[reg] = DW_CFA_undefined;
9133 case DW_CFA_def_cfa_sf:
9136 case DW_CFA_def_cfa_offset_sf:
9139 case DW_CFA_MIPS_advance_loc8:
9142 case DW_CFA_GNU_args_size:
9145 case DW_CFA_GNU_negative_offset_extended:
9146 reg = LEB (); LEB ();
9147 frame_need_space (fc, reg);
9148 fc->col_type[reg] = DW_CFA_undefined;
9157 /* Now we know what registers are used, make a second pass over
9158 the chunk, this time actually printing out the info. */
9160 while (start < block_end)
9163 unsigned long ul, reg, roffs;
9172 /* Warning: if you add any more cases to this switch, be
9173 sure to add them to the corresponding switch above. */
9176 case DW_CFA_advance_loc:
9177 if (do_debug_frames_interp)
9178 frame_display_row (fc, &need_col_headers, &max_regs);
9180 printf (" DW_CFA_advance_loc: %d to %08lx\n",
9181 opa * fc->code_factor,
9182 fc->pc_begin + opa * fc->code_factor);
9183 fc->pc_begin += opa * fc->code_factor;
9188 if (! do_debug_frames_interp)
9189 printf (" DW_CFA_offset: r%d at cfa%+ld\n",
9190 opa, roffs * fc->data_factor);
9191 fc->col_type[opa] = DW_CFA_offset;
9192 fc->col_offset[opa] = roffs * fc->data_factor;
9195 case DW_CFA_restore:
9196 if (! do_debug_frames_interp)
9197 printf (" DW_CFA_restore: r%d\n", opa);
9198 fc->col_type[opa] = cie->col_type[opa];
9199 fc->col_offset[opa] = cie->col_offset[opa];
9202 case DW_CFA_set_loc:
9203 vma = get_encoded_value (start, fc->fde_encoding);
9204 if ((fc->fde_encoding & 0x70) == DW_EH_PE_pcrel)
9205 vma += section->sh_addr + (start - section_start);
9206 start += encoded_ptr_size;
9207 if (do_debug_frames_interp)
9208 frame_display_row (fc, &need_col_headers, &max_regs);
9210 printf (" DW_CFA_set_loc: %08lx\n", (unsigned long)vma);
9214 case DW_CFA_advance_loc1:
9215 ofs = byte_get (start, 1); start += 1;
9216 if (do_debug_frames_interp)
9217 frame_display_row (fc, &need_col_headers, &max_regs);
9219 printf (" DW_CFA_advance_loc1: %ld to %08lx\n",
9220 ofs * fc->code_factor,
9221 fc->pc_begin + ofs * fc->code_factor);
9222 fc->pc_begin += ofs * fc->code_factor;
9225 case DW_CFA_advance_loc2:
9226 ofs = byte_get (start, 2); start += 2;
9227 if (do_debug_frames_interp)
9228 frame_display_row (fc, &need_col_headers, &max_regs);
9230 printf (" DW_CFA_advance_loc2: %ld to %08lx\n",
9231 ofs * fc->code_factor,
9232 fc->pc_begin + ofs * fc->code_factor);
9233 fc->pc_begin += ofs * fc->code_factor;
9236 case DW_CFA_advance_loc4:
9237 ofs = byte_get (start, 4); start += 4;
9238 if (do_debug_frames_interp)
9239 frame_display_row (fc, &need_col_headers, &max_regs);
9241 printf (" DW_CFA_advance_loc4: %ld to %08lx\n",
9242 ofs * fc->code_factor,
9243 fc->pc_begin + ofs * fc->code_factor);
9244 fc->pc_begin += ofs * fc->code_factor;
9247 case DW_CFA_offset_extended:
9250 if (! do_debug_frames_interp)
9251 printf (" DW_CFA_offset_extended: r%ld at cfa%+ld\n",
9252 reg, roffs * fc->data_factor);
9253 fc->col_type[reg] = DW_CFA_offset;
9254 fc->col_offset[reg] = roffs * fc->data_factor;
9257 case DW_CFA_restore_extended:
9259 if (! do_debug_frames_interp)
9260 printf (" DW_CFA_restore_extended: r%ld\n", reg);
9261 fc->col_type[reg] = cie->col_type[reg];
9262 fc->col_offset[reg] = cie->col_offset[reg];
9265 case DW_CFA_undefined:
9267 if (! do_debug_frames_interp)
9268 printf (" DW_CFA_undefined: r%ld\n", reg);
9269 fc->col_type[reg] = DW_CFA_undefined;
9270 fc->col_offset[reg] = 0;
9273 case DW_CFA_same_value:
9275 if (! do_debug_frames_interp)
9276 printf (" DW_CFA_same_value: r%ld\n", reg);
9277 fc->col_type[reg] = DW_CFA_same_value;
9278 fc->col_offset[reg] = 0;
9281 case DW_CFA_register:
9284 if (! do_debug_frames_interp)
9285 printf (" DW_CFA_register: r%ld in r%ld\n", reg, roffs);
9286 fc->col_type[reg] = DW_CFA_register;
9287 fc->col_offset[reg] = roffs;
9290 case DW_CFA_remember_state:
9291 if (! do_debug_frames_interp)
9292 printf (" DW_CFA_remember_state\n");
9293 rs = xmalloc (sizeof (Frame_Chunk));
9294 rs->ncols = fc->ncols;
9295 rs->col_type = xmalloc (rs->ncols * sizeof (short int));
9296 rs->col_offset = xmalloc (rs->ncols * sizeof (int));
9297 memcpy (rs->col_type, fc->col_type, rs->ncols);
9298 memcpy (rs->col_offset, fc->col_offset, rs->ncols * sizeof (int));
9299 rs->next = remembered_state;
9300 remembered_state = rs;
9303 case DW_CFA_restore_state:
9304 if (! do_debug_frames_interp)
9305 printf (" DW_CFA_restore_state\n");
9306 rs = remembered_state;
9309 remembered_state = rs->next;
9310 frame_need_space (fc, rs->ncols-1);
9311 memcpy (fc->col_type, rs->col_type, rs->ncols);
9312 memcpy (fc->col_offset, rs->col_offset,
9313 rs->ncols * sizeof (int));
9314 free (rs->col_type);
9315 free (rs->col_offset);
9318 else if (do_debug_frames_interp)
9319 printf ("Mismatched DW_CFA_restore_state\n");
9322 case DW_CFA_def_cfa:
9323 fc->cfa_reg = LEB ();
9324 fc->cfa_offset = LEB ();
9326 if (! do_debug_frames_interp)
9327 printf (" DW_CFA_def_cfa: r%d ofs %d\n",
9328 fc->cfa_reg, fc->cfa_offset);
9331 case DW_CFA_def_cfa_register:
9332 fc->cfa_reg = LEB ();
9334 if (! do_debug_frames_interp)
9335 printf (" DW_CFA_def_cfa_reg: r%d\n", fc->cfa_reg);
9338 case DW_CFA_def_cfa_offset:
9339 fc->cfa_offset = LEB ();
9340 if (! do_debug_frames_interp)
9341 printf (" DW_CFA_def_cfa_offset: %d\n", fc->cfa_offset);
9345 if (! do_debug_frames_interp)
9346 printf (" DW_CFA_nop\n");
9349 case DW_CFA_def_cfa_expression:
9351 if (! do_debug_frames_interp)
9353 printf (" DW_CFA_def_cfa_expression (");
9354 decode_location_expression (start, addr_size, ul);
9361 case DW_CFA_expression:
9364 if (! do_debug_frames_interp)
9366 printf (" DW_CFA_expression: r%ld (", reg);
9367 decode_location_expression (start, addr_size, ul);
9370 fc->col_type[reg] = DW_CFA_expression;
9374 case DW_CFA_offset_extended_sf:
9377 frame_need_space (fc, reg);
9378 if (! do_debug_frames_interp)
9379 printf (" DW_CFA_offset_extended_sf: r%ld at cfa%+ld\n",
9380 reg, l * fc->data_factor);
9381 fc->col_type[reg] = DW_CFA_offset;
9382 fc->col_offset[reg] = l * fc->data_factor;
9385 case DW_CFA_def_cfa_sf:
9386 fc->cfa_reg = LEB ();
9387 fc->cfa_offset = SLEB ();
9389 if (! do_debug_frames_interp)
9390 printf (" DW_CFA_def_cfa_sf: r%d ofs %d\n",
9391 fc->cfa_reg, fc->cfa_offset);
9394 case DW_CFA_def_cfa_offset_sf:
9395 fc->cfa_offset = SLEB ();
9396 if (! do_debug_frames_interp)
9397 printf (" DW_CFA_def_cfa_offset_sf: %d\n", fc->cfa_offset);
9400 case DW_CFA_MIPS_advance_loc8:
9401 ofs = byte_get (start, 8); start += 8;
9402 if (do_debug_frames_interp)
9403 frame_display_row (fc, &need_col_headers, &max_regs);
9405 printf (" DW_CFA_MIPS_advance_loc8: %ld to %08lx\n",
9406 ofs * fc->code_factor,
9407 fc->pc_begin + ofs * fc->code_factor);
9408 fc->pc_begin += ofs * fc->code_factor;
9411 case DW_CFA_GNU_window_save:
9412 if (! do_debug_frames_interp)
9413 printf (" DW_CFA_GNU_window_save\n");
9416 case DW_CFA_GNU_args_size:
9418 if (! do_debug_frames_interp)
9419 printf (" DW_CFA_GNU_args_size: %ld\n", ul);
9422 case DW_CFA_GNU_negative_offset_extended:
9425 frame_need_space (fc, reg);
9426 if (! do_debug_frames_interp)
9427 printf (" DW_CFA_GNU_negative_offset_extended: r%ld at cfa%+ld\n",
9428 reg, l * fc->data_factor);
9429 fc->col_type[reg] = DW_CFA_offset;
9430 fc->col_offset[reg] = l * fc->data_factor;
9434 fprintf (stderr, "unsupported or unknown DW_CFA_%d\n", op);
9439 if (do_debug_frames_interp)
9440 frame_display_row (fc, &need_col_headers, &max_regs);
9455 display_debug_not_supported (Elf_Internal_Shdr *section,
9456 unsigned char *start ATTRIBUTE_UNUSED,
9457 FILE *file ATTRIBUTE_UNUSED)
9459 printf (_("Displaying the debug contents of section %s is not yet supported.\n"),
9460 SECTION_NAME (section));
9465 /* A structure containing the name of a debug section
9466 and a pointer to a function that can decode it. */
9469 const char *const name;
9470 int (*display) (Elf_Internal_Shdr *, unsigned char *, FILE *);
9474 { ".debug_abbrev", display_debug_abbrev },
9475 { ".debug_aranges", display_debug_aranges },
9476 { ".debug_frame", display_debug_frames },
9477 { ".debug_info", display_debug_info },
9478 { ".debug_line", display_debug_lines },
9479 { ".debug_pubnames", display_debug_pubnames },
9480 { ".eh_frame", display_debug_frames },
9481 { ".debug_macinfo", display_debug_macinfo },
9482 { ".debug_str", display_debug_str },
9483 { ".debug_loc", display_debug_loc },
9484 { ".debug_pubtypes", display_debug_pubnames },
9485 { ".debug_ranges", display_debug_not_supported },
9486 { ".debug_static_func", display_debug_not_supported },
9487 { ".debug_static_vars", display_debug_not_supported },
9488 { ".debug_types", display_debug_not_supported },
9489 { ".debug_weaknames", display_debug_not_supported }
9493 display_debug_section (Elf_Internal_Shdr *section, FILE *file)
9495 char *name = SECTION_NAME (section);
9496 bfd_size_type length;
9497 unsigned char *start;
9500 length = section->sh_size;
9503 printf (_("\nSection '%s' has no debugging data.\n"), name);
9507 start = get_data (NULL, file, section->sh_offset, length,
9508 _("debug section data"));
9512 /* See if we know how to display the contents of this section. */
9513 if (strncmp (name, ".gnu.linkonce.wi.", 17) == 0)
9514 name = ".debug_info";
9516 for (i = NUM_ELEM (debug_displays); i--;)
9517 if (strcmp (debug_displays[i].name, name) == 0)
9519 debug_displays[i].display (section, start, file);
9524 printf (_("Unrecognized debug section: %s\n"), name);
9528 /* If we loaded in the abbrev section at some point,
9529 we must release it here. */
9536 process_section_contents (FILE *file)
9538 Elf_Internal_Shdr *section;
9544 for (i = 0, section = section_headers;
9545 i < elf_header.e_shnum && i < num_dump_sects;
9548 #ifdef SUPPORT_DISASSEMBLY
9549 if (dump_sects[i] & DISASS_DUMP)
9550 disassemble_section (section, file);
9552 if (dump_sects[i] & HEX_DUMP)
9553 dump_section (section, file);
9555 if (dump_sects[i] & DEBUG_DUMP)
9556 display_debug_section (section, file);
9559 if (i < num_dump_sects)
9560 warn (_("Some sections were not dumped because they do not exist!\n"));
9566 process_mips_fpe_exception (int mask)
9571 if (mask & OEX_FPU_INEX)
9572 fputs ("INEX", stdout), first = 0;
9573 if (mask & OEX_FPU_UFLO)
9574 printf ("%sUFLO", first ? "" : "|"), first = 0;
9575 if (mask & OEX_FPU_OFLO)
9576 printf ("%sOFLO", first ? "" : "|"), first = 0;
9577 if (mask & OEX_FPU_DIV0)
9578 printf ("%sDIV0", first ? "" : "|"), first = 0;
9579 if (mask & OEX_FPU_INVAL)
9580 printf ("%sINVAL", first ? "" : "|");
9583 fputs ("0", stdout);
9587 process_mips_specific (FILE *file)
9589 Elf_Internal_Dyn *entry;
9590 size_t liblist_offset = 0;
9591 size_t liblistno = 0;
9592 size_t conflictsno = 0;
9593 size_t options_offset = 0;
9594 size_t conflicts_offset = 0;
9596 /* We have a lot of special sections. Thanks SGI! */
9597 if (dynamic_segment == NULL)
9598 /* No information available. */
9601 for (entry = dynamic_segment; entry->d_tag != DT_NULL; ++entry)
9602 switch (entry->d_tag)
9604 case DT_MIPS_LIBLIST:
9606 = offset_from_vma (file, entry->d_un.d_val,
9607 liblistno * sizeof (Elf32_External_Lib));
9609 case DT_MIPS_LIBLISTNO:
9610 liblistno = entry->d_un.d_val;
9612 case DT_MIPS_OPTIONS:
9613 options_offset = offset_from_vma (file, entry->d_un.d_val, 0);
9615 case DT_MIPS_CONFLICT:
9617 = offset_from_vma (file, entry->d_un.d_val,
9618 conflictsno * sizeof (Elf32_External_Conflict));
9620 case DT_MIPS_CONFLICTNO:
9621 conflictsno = entry->d_un.d_val;
9627 if (liblist_offset != 0 && liblistno != 0 && do_dynamic)
9629 Elf32_External_Lib *elib;
9632 elib = get_data (NULL, file, liblist_offset,
9633 liblistno * sizeof (Elf32_External_Lib),
9637 printf ("\nSection '.liblist' contains %lu entries:\n",
9638 (unsigned long) liblistno);
9639 fputs (" Library Time Stamp Checksum Version Flags\n",
9642 for (cnt = 0; cnt < liblistno; ++cnt)
9649 liblist.l_name = BYTE_GET (elib[cnt].l_name);
9650 time = BYTE_GET (elib[cnt].l_time_stamp);
9651 liblist.l_checksum = BYTE_GET (elib[cnt].l_checksum);
9652 liblist.l_version = BYTE_GET (elib[cnt].l_version);
9653 liblist.l_flags = BYTE_GET (elib[cnt].l_flags);
9655 tmp = gmtime (&time);
9656 sprintf (timebuf, "%04u-%02u-%02uT%02u:%02u:%02u",
9657 tmp->tm_year + 1900, tmp->tm_mon + 1, tmp->tm_mday,
9658 tmp->tm_hour, tmp->tm_min, tmp->tm_sec);
9660 printf ("%3lu: ", (unsigned long) cnt);
9661 print_symbol (20, dynamic_strings + liblist.l_name);
9662 printf (" %s %#10lx %-7ld", timebuf, liblist.l_checksum,
9665 if (liblist.l_flags == 0)
9676 { " EXACT_MATCH", LL_EXACT_MATCH },
9677 { " IGNORE_INT_VER", LL_IGNORE_INT_VER },
9678 { " REQUIRE_MINOR", LL_REQUIRE_MINOR },
9679 { " EXPORTS", LL_EXPORTS },
9680 { " DELAY_LOAD", LL_DELAY_LOAD },
9681 { " DELTA", LL_DELTA }
9683 int flags = liblist.l_flags;
9687 fcnt < sizeof (l_flags_vals) / sizeof (l_flags_vals[0]);
9689 if ((flags & l_flags_vals[fcnt].bit) != 0)
9691 fputs (l_flags_vals[fcnt].name, stdout);
9692 flags ^= l_flags_vals[fcnt].bit;
9695 printf (" %#x", (unsigned int) flags);
9705 if (options_offset != 0)
9707 Elf_External_Options *eopt;
9708 Elf_Internal_Shdr *sect = section_headers;
9709 Elf_Internal_Options *iopt;
9710 Elf_Internal_Options *option;
9714 /* Find the section header so that we get the size. */
9715 while (sect->sh_type != SHT_MIPS_OPTIONS)
9718 eopt = get_data (NULL, file, options_offset, sect->sh_size,
9722 iopt = malloc ((sect->sh_size / sizeof (eopt)) * sizeof (*iopt));
9725 error (_("Out of memory"));
9732 while (offset < sect->sh_size)
9734 Elf_External_Options *eoption;
9736 eoption = (Elf_External_Options *) ((char *) eopt + offset);
9738 option->kind = BYTE_GET (eoption->kind);
9739 option->size = BYTE_GET (eoption->size);
9740 option->section = BYTE_GET (eoption->section);
9741 option->info = BYTE_GET (eoption->info);
9743 offset += option->size;
9749 printf (_("\nSection '%s' contains %d entries:\n"),
9750 SECTION_NAME (sect), cnt);
9758 switch (option->kind)
9761 /* This shouldn't happen. */
9762 printf (" NULL %d %lx", option->section, option->info);
9765 printf (" REGINFO ");
9766 if (elf_header.e_machine == EM_MIPS)
9769 Elf32_External_RegInfo *ereg;
9770 Elf32_RegInfo reginfo;
9772 ereg = (Elf32_External_RegInfo *) (option + 1);
9773 reginfo.ri_gprmask = BYTE_GET (ereg->ri_gprmask);
9774 reginfo.ri_cprmask[0] = BYTE_GET (ereg->ri_cprmask[0]);
9775 reginfo.ri_cprmask[1] = BYTE_GET (ereg->ri_cprmask[1]);
9776 reginfo.ri_cprmask[2] = BYTE_GET (ereg->ri_cprmask[2]);
9777 reginfo.ri_cprmask[3] = BYTE_GET (ereg->ri_cprmask[3]);
9778 reginfo.ri_gp_value = BYTE_GET (ereg->ri_gp_value);
9780 printf ("GPR %08lx GP 0x%lx\n",
9782 (unsigned long) reginfo.ri_gp_value);
9783 printf (" CPR0 %08lx CPR1 %08lx CPR2 %08lx CPR3 %08lx\n",
9784 reginfo.ri_cprmask[0], reginfo.ri_cprmask[1],
9785 reginfo.ri_cprmask[2], reginfo.ri_cprmask[3]);
9790 Elf64_External_RegInfo *ereg;
9791 Elf64_Internal_RegInfo reginfo;
9793 ereg = (Elf64_External_RegInfo *) (option + 1);
9794 reginfo.ri_gprmask = BYTE_GET (ereg->ri_gprmask);
9795 reginfo.ri_cprmask[0] = BYTE_GET (ereg->ri_cprmask[0]);
9796 reginfo.ri_cprmask[1] = BYTE_GET (ereg->ri_cprmask[1]);
9797 reginfo.ri_cprmask[2] = BYTE_GET (ereg->ri_cprmask[2]);
9798 reginfo.ri_cprmask[3] = BYTE_GET (ereg->ri_cprmask[3]);
9799 reginfo.ri_gp_value = BYTE_GET8 (ereg->ri_gp_value);
9801 printf ("GPR %08lx GP 0x",
9802 reginfo.ri_gprmask);
9803 printf_vma (reginfo.ri_gp_value);
9806 printf (" CPR0 %08lx CPR1 %08lx CPR2 %08lx CPR3 %08lx\n",
9807 reginfo.ri_cprmask[0], reginfo.ri_cprmask[1],
9808 reginfo.ri_cprmask[2], reginfo.ri_cprmask[3]);
9812 case ODK_EXCEPTIONS:
9813 fputs (" EXCEPTIONS fpe_min(", stdout);
9814 process_mips_fpe_exception (option->info & OEX_FPU_MIN);
9815 fputs (") fpe_max(", stdout);
9816 process_mips_fpe_exception ((option->info & OEX_FPU_MAX) >> 8);
9817 fputs (")", stdout);
9819 if (option->info & OEX_PAGE0)
9820 fputs (" PAGE0", stdout);
9821 if (option->info & OEX_SMM)
9822 fputs (" SMM", stdout);
9823 if (option->info & OEX_FPDBUG)
9824 fputs (" FPDBUG", stdout);
9825 if (option->info & OEX_DISMISS)
9826 fputs (" DISMISS", stdout);
9829 fputs (" PAD ", stdout);
9830 if (option->info & OPAD_PREFIX)
9831 fputs (" PREFIX", stdout);
9832 if (option->info & OPAD_POSTFIX)
9833 fputs (" POSTFIX", stdout);
9834 if (option->info & OPAD_SYMBOL)
9835 fputs (" SYMBOL", stdout);
9838 fputs (" HWPATCH ", stdout);
9839 if (option->info & OHW_R4KEOP)
9840 fputs (" R4KEOP", stdout);
9841 if (option->info & OHW_R8KPFETCH)
9842 fputs (" R8KPFETCH", stdout);
9843 if (option->info & OHW_R5KEOP)
9844 fputs (" R5KEOP", stdout);
9845 if (option->info & OHW_R5KCVTL)
9846 fputs (" R5KCVTL", stdout);
9849 fputs (" FILL ", stdout);
9850 /* XXX Print content of info word? */
9853 fputs (" TAGS ", stdout);
9854 /* XXX Print content of info word? */
9857 fputs (" HWAND ", stdout);
9858 if (option->info & OHWA0_R4KEOP_CHECKED)
9859 fputs (" R4KEOP_CHECKED", stdout);
9860 if (option->info & OHWA0_R4KEOP_CLEAN)
9861 fputs (" R4KEOP_CLEAN", stdout);
9864 fputs (" HWOR ", stdout);
9865 if (option->info & OHWA0_R4KEOP_CHECKED)
9866 fputs (" R4KEOP_CHECKED", stdout);
9867 if (option->info & OHWA0_R4KEOP_CLEAN)
9868 fputs (" R4KEOP_CLEAN", stdout);
9871 printf (" GP_GROUP %#06lx self-contained %#06lx",
9872 option->info & OGP_GROUP,
9873 (option->info & OGP_SELF) >> 16);
9876 printf (" IDENT %#06lx self-contained %#06lx",
9877 option->info & OGP_GROUP,
9878 (option->info & OGP_SELF) >> 16);
9881 /* This shouldn't happen. */
9882 printf (" %3d ??? %d %lx",
9883 option->kind, option->section, option->info);
9887 len = sizeof (*eopt);
9888 while (len < option->size)
9889 if (((char *) option)[len] >= ' '
9890 && ((char *) option)[len] < 0x7f)
9891 printf ("%c", ((char *) option)[len++]);
9893 printf ("\\%03o", ((char *) option)[len++]);
9895 fputs ("\n", stdout);
9903 if (conflicts_offset != 0 && conflictsno != 0)
9905 Elf32_Conflict *iconf;
9908 if (dynamic_symbols == NULL)
9910 error (_("conflict list found without a dynamic symbol table"));
9914 iconf = malloc (conflictsno * sizeof (*iconf));
9917 error (_("Out of memory"));
9923 Elf32_External_Conflict *econf32;
9925 econf32 = get_data (NULL, file, conflicts_offset,
9926 conflictsno * sizeof (*econf32), _("conflict"));
9930 for (cnt = 0; cnt < conflictsno; ++cnt)
9931 iconf[cnt] = BYTE_GET (econf32[cnt]);
9937 Elf64_External_Conflict *econf64;
9939 econf64 = get_data (NULL, file, conflicts_offset,
9940 conflictsno * sizeof (*econf64), _("conflict"));
9944 for (cnt = 0; cnt < conflictsno; ++cnt)
9945 iconf[cnt] = BYTE_GET (econf64[cnt]);
9950 printf (_("\nSection '.conflict' contains %lu entries:\n"),
9951 (unsigned long) conflictsno);
9952 puts (_(" Num: Index Value Name"));
9954 for (cnt = 0; cnt < conflictsno; ++cnt)
9956 Elf_Internal_Sym *psym = & dynamic_symbols[iconf[cnt]];
9958 printf ("%5lu: %8lu ", (unsigned long) cnt, iconf[cnt]);
9959 print_vma (psym->st_value, FULL_HEX);
9961 print_symbol (25, dynamic_strings + psym->st_name);
9972 process_gnu_liblist (FILE *file)
9974 Elf_Internal_Shdr *section, *string_sec;
9975 Elf32_External_Lib *elib;
9983 for (i = 0, section = section_headers;
9984 i < elf_header.e_shnum;
9987 switch (section->sh_type)
9989 case SHT_GNU_LIBLIST:
9990 elib = get_data (NULL, file, section->sh_offset, section->sh_size,
9995 string_sec = SECTION_HEADER (section->sh_link);
9997 strtab = get_data (NULL, file, string_sec->sh_offset,
9998 string_sec->sh_size, _("liblist string table"));
10001 || section->sh_entsize != sizeof (Elf32_External_Lib))
10007 printf (_("\nLibrary list section '%s' contains %lu entries:\n"),
10008 SECTION_NAME (section),
10009 (long) (section->sh_size / sizeof (Elf32_External_Lib)));
10011 puts (" Library Time Stamp Checksum Version Flags");
10013 for (cnt = 0; cnt < section->sh_size / sizeof (Elf32_External_Lib);
10021 liblist.l_name = BYTE_GET (elib[cnt].l_name);
10022 time = BYTE_GET (elib[cnt].l_time_stamp);
10023 liblist.l_checksum = BYTE_GET (elib[cnt].l_checksum);
10024 liblist.l_version = BYTE_GET (elib[cnt].l_version);
10025 liblist.l_flags = BYTE_GET (elib[cnt].l_flags);
10027 tmp = gmtime (&time);
10028 sprintf (timebuf, "%04u-%02u-%02uT%02u:%02u:%02u",
10029 tmp->tm_year + 1900, tmp->tm_mon + 1, tmp->tm_mday,
10030 tmp->tm_hour, tmp->tm_min, tmp->tm_sec);
10032 printf ("%3lu: ", (unsigned long) cnt);
10034 printf ("%-20s", strtab + liblist.l_name);
10036 printf ("%-20.20s", strtab + liblist.l_name);
10037 printf (" %s %#010lx %-7ld %-7ld\n", timebuf, liblist.l_checksum,
10038 liblist.l_version, liblist.l_flags);
10048 static const char *
10049 get_note_type (unsigned e_type)
10051 static char buff[64];
10055 case NT_AUXV: return _("NT_AUXV (auxiliary vector)");
10056 case NT_PRSTATUS: return _("NT_PRSTATUS (prstatus structure)");
10057 case NT_FPREGSET: return _("NT_FPREGSET (floating point registers)");
10058 case NT_PRPSINFO: return _("NT_PRPSINFO (prpsinfo structure)");
10059 case NT_TASKSTRUCT: return _("NT_TASKSTRUCT (task structure)");
10060 case NT_PRXFPREG: return _("NT_PRXFPREG (user_xfpregs structure)");
10061 case NT_PSTATUS: return _("NT_PSTATUS (pstatus structure)");
10062 case NT_FPREGS: return _("NT_FPREGS (floating point registers)");
10063 case NT_PSINFO: return _("NT_PSINFO (psinfo structure)");
10064 case NT_LWPSTATUS: return _("NT_LWPSTATUS (lwpstatus_t structure)");
10065 case NT_LWPSINFO: return _("NT_LWPSINFO (lwpsinfo_t structure)");
10066 case NT_WIN32PSTATUS: return _("NT_WIN32PSTATUS (win32_pstatus structure)");
10068 sprintf (buff, _("Unknown note type: (0x%08x)"), e_type);
10073 static const char *
10074 get_netbsd_elfcore_note_type (unsigned e_type)
10076 static char buff[64];
10078 if (e_type == NT_NETBSDCORE_PROCINFO)
10080 /* NetBSD core "procinfo" structure. */
10081 return _("NetBSD procinfo structure");
10084 /* As of Jan 2002 there are no other machine-independent notes
10085 defined for NetBSD core files. If the note type is less
10086 than the start of the machine-dependent note types, we don't
10089 if (e_type < NT_NETBSDCORE_FIRSTMACH)
10091 sprintf (buff, _("Unknown note type: (0x%08x)"), e_type);
10095 switch (elf_header.e_machine)
10097 /* On the Alpha, SPARC (32-bit and 64-bit), PT_GETREGS == mach+0
10098 and PT_GETFPREGS == mach+2. */
10103 case EM_SPARC32PLUS:
10107 case NT_NETBSDCORE_FIRSTMACH+0:
10108 return _("PT_GETREGS (reg structure)");
10109 case NT_NETBSDCORE_FIRSTMACH+2:
10110 return _("PT_GETFPREGS (fpreg structure)");
10116 /* On all other arch's, PT_GETREGS == mach+1 and
10117 PT_GETFPREGS == mach+3. */
10121 case NT_NETBSDCORE_FIRSTMACH+1:
10122 return _("PT_GETREGS (reg structure)");
10123 case NT_NETBSDCORE_FIRSTMACH+3:
10124 return _("PT_GETFPREGS (fpreg structure)");
10130 sprintf (buff, _("PT_FIRSTMACH+%d"), e_type - NT_NETBSDCORE_FIRSTMACH);
10134 /* Note that by the ELF standard, the name field is already null byte
10135 terminated, and namesz includes the terminating null byte.
10136 I.E. the value of namesz for the name "FSF" is 4.
10138 If the value of namesz is zero, there is no name present. */
10140 process_note (Elf_Internal_Note *pnote)
10144 if (pnote->namesz == 0)
10146 /* If there is no note name, then use the default set of
10147 note type strings. */
10148 nt = get_note_type (pnote->type);
10150 else if (strncmp (pnote->namedata, "NetBSD-CORE", 11) == 0)
10152 /* NetBSD-specific core file notes. */
10153 nt = get_netbsd_elfcore_note_type (pnote->type);
10157 /* Don't recognize this note name; just use the default set of
10158 note type strings. */
10159 nt = get_note_type (pnote->type);
10162 printf (" %s\t\t0x%08lx\t%s\n",
10163 pnote->namesz ? pnote->namedata : "(NONE)",
10164 pnote->descsz, nt);
10170 process_corefile_note_segment (FILE *file, bfd_vma offset, bfd_vma length)
10172 Elf_External_Note *pnotes;
10173 Elf_External_Note *external;
10179 pnotes = get_data (NULL, file, offset, length, _("notes"));
10185 printf (_("\nNotes at offset 0x%08lx with length 0x%08lx:\n"),
10186 (unsigned long) offset, (unsigned long) length);
10187 printf (_(" Owner\t\tData size\tDescription\n"));
10189 while (external < (Elf_External_Note *)((char *) pnotes + length))
10191 Elf_External_Note *next;
10192 Elf_Internal_Note inote;
10195 inote.type = BYTE_GET (external->type);
10196 inote.namesz = BYTE_GET (external->namesz);
10197 inote.namedata = external->name;
10198 inote.descsz = BYTE_GET (external->descsz);
10199 inote.descdata = inote.namedata + align_power (inote.namesz, 2);
10200 inote.descpos = offset + (inote.descdata - (char *) pnotes);
10202 next = (Elf_External_Note *)(inote.descdata + align_power (inote.descsz, 2));
10204 if (((char *) next) > (((char *) pnotes) + length))
10206 warn (_("corrupt note found at offset %x into core notes\n"),
10207 ((char *) external) - ((char *) pnotes));
10208 warn (_(" type: %x, namesize: %08lx, descsize: %08lx\n"),
10209 inote.type, inote.namesz, inote.descsz);
10215 /* Verify that name is null terminated. It appears that at least
10216 one version of Linux (RedHat 6.0) generates corefiles that don't
10217 comply with the ELF spec by failing to include the null byte in
10219 if (inote.namedata[inote.namesz] != '\0')
10221 temp = malloc (inote.namesz + 1);
10225 error (_("Out of memory\n"));
10230 strncpy (temp, inote.namedata, inote.namesz);
10231 temp[inote.namesz] = 0;
10233 /* warn (_("'%s' NOTE name not properly null terminated\n"), temp); */
10234 inote.namedata = temp;
10237 res &= process_note (& inote);
10252 process_corefile_note_segments (FILE *file)
10254 Elf_Internal_Phdr *segment;
10258 if (! get_program_headers (file))
10261 for (i = 0, segment = program_headers;
10262 i < elf_header.e_phnum;
10265 if (segment->p_type == PT_NOTE)
10266 res &= process_corefile_note_segment (file,
10267 (bfd_vma) segment->p_offset,
10268 (bfd_vma) segment->p_filesz);
10275 process_corefile_contents (FILE *file)
10277 /* If we have not been asked to display the notes then do nothing. */
10281 /* If file is not a core file then exit. */
10282 if (elf_header.e_type != ET_CORE)
10285 /* No program headers means no NOTE segment. */
10286 if (elf_header.e_phnum == 0)
10288 printf (_("No note segments present in the core file.\n"));
10292 return process_corefile_note_segments (file);
10296 process_arch_specific (FILE *file)
10301 switch (elf_header.e_machine)
10304 case EM_MIPS_RS3_LE:
10305 return process_mips_specific (file);
10314 get_file_header (FILE *file)
10316 /* Read in the identity array. */
10317 if (fread (elf_header.e_ident, EI_NIDENT, 1, file) != 1)
10320 /* Determine how to read the rest of the header. */
10321 switch (elf_header.e_ident[EI_DATA])
10323 default: /* fall through */
10324 case ELFDATANONE: /* fall through */
10326 byte_get = byte_get_little_endian;
10327 byte_put = byte_put_little_endian;
10330 byte_get = byte_get_big_endian;
10331 byte_put = byte_put_big_endian;
10335 /* For now we only support 32 bit and 64 bit ELF files. */
10336 is_32bit_elf = (elf_header.e_ident[EI_CLASS] != ELFCLASS64);
10338 /* Read in the rest of the header. */
10341 Elf32_External_Ehdr ehdr32;
10343 if (fread (ehdr32.e_type, sizeof (ehdr32) - EI_NIDENT, 1, file) != 1)
10346 elf_header.e_type = BYTE_GET (ehdr32.e_type);
10347 elf_header.e_machine = BYTE_GET (ehdr32.e_machine);
10348 elf_header.e_version = BYTE_GET (ehdr32.e_version);
10349 elf_header.e_entry = BYTE_GET (ehdr32.e_entry);
10350 elf_header.e_phoff = BYTE_GET (ehdr32.e_phoff);
10351 elf_header.e_shoff = BYTE_GET (ehdr32.e_shoff);
10352 elf_header.e_flags = BYTE_GET (ehdr32.e_flags);
10353 elf_header.e_ehsize = BYTE_GET (ehdr32.e_ehsize);
10354 elf_header.e_phentsize = BYTE_GET (ehdr32.e_phentsize);
10355 elf_header.e_phnum = BYTE_GET (ehdr32.e_phnum);
10356 elf_header.e_shentsize = BYTE_GET (ehdr32.e_shentsize);
10357 elf_header.e_shnum = BYTE_GET (ehdr32.e_shnum);
10358 elf_header.e_shstrndx = BYTE_GET (ehdr32.e_shstrndx);
10362 Elf64_External_Ehdr ehdr64;
10364 /* If we have been compiled with sizeof (bfd_vma) == 4, then
10365 we will not be able to cope with the 64bit data found in
10366 64 ELF files. Detect this now and abort before we start
10367 overwriting things. */
10368 if (sizeof (bfd_vma) < 8)
10370 error (_("This instance of readelf has been built without support for a\n\
10371 64 bit data type and so it cannot read 64 bit ELF files.\n"));
10375 if (fread (ehdr64.e_type, sizeof (ehdr64) - EI_NIDENT, 1, file) != 1)
10378 elf_header.e_type = BYTE_GET (ehdr64.e_type);
10379 elf_header.e_machine = BYTE_GET (ehdr64.e_machine);
10380 elf_header.e_version = BYTE_GET (ehdr64.e_version);
10381 elf_header.e_entry = BYTE_GET8 (ehdr64.e_entry);
10382 elf_header.e_phoff = BYTE_GET8 (ehdr64.e_phoff);
10383 elf_header.e_shoff = BYTE_GET8 (ehdr64.e_shoff);
10384 elf_header.e_flags = BYTE_GET (ehdr64.e_flags);
10385 elf_header.e_ehsize = BYTE_GET (ehdr64.e_ehsize);
10386 elf_header.e_phentsize = BYTE_GET (ehdr64.e_phentsize);
10387 elf_header.e_phnum = BYTE_GET (ehdr64.e_phnum);
10388 elf_header.e_shentsize = BYTE_GET (ehdr64.e_shentsize);
10389 elf_header.e_shnum = BYTE_GET (ehdr64.e_shnum);
10390 elf_header.e_shstrndx = BYTE_GET (ehdr64.e_shstrndx);
10393 if (elf_header.e_shoff)
10395 /* There may be some extensions in the first section header. Don't
10396 bomb if we can't read it. */
10398 get_32bit_section_headers (file, 1);
10400 get_64bit_section_headers (file, 1);
10406 /* Process one ELF object file according to the command line options.
10407 This file may actually be stored in an archive. The file is
10408 positioned at the start of the ELF object. */
10411 process_object (char *file_name, FILE *file)
10415 if (! get_file_header (file))
10417 error (_("%s: Failed to read file header\n"), file_name);
10421 /* Initialise per file variables. */
10422 for (i = NUM_ELEM (version_info); i--;)
10423 version_info[i] = 0;
10425 for (i = NUM_ELEM (dynamic_info); i--;)
10426 dynamic_info[i] = 0;
10428 /* Process the file. */
10430 printf (_("\nFile: %s\n"), file_name);
10432 if (! process_file_header ())
10435 if (! process_section_headers (file))
10437 /* Without loaded section headers we
10438 cannot process lots of things. */
10439 do_unwind = do_version = do_dump = do_arch = 0;
10441 if (! do_using_dynamic)
10442 do_syms = do_reloc = 0;
10445 if (process_program_headers (file))
10446 process_dynamic_segment (file);
10448 process_relocs (file);
10450 process_unwind (file);
10452 process_symbol_table (file);
10454 process_syminfo (file);
10456 process_version_sections (file);
10458 process_section_contents (file);
10460 process_section_groups (file);
10462 process_corefile_contents (file);
10464 process_gnu_liblist (file);
10466 process_arch_specific (file);
10468 if (program_headers)
10470 free (program_headers);
10471 program_headers = NULL;
10474 if (section_headers)
10476 free (section_headers);
10477 section_headers = NULL;
10482 free (string_table);
10483 string_table = NULL;
10484 string_table_length = 0;
10487 if (dynamic_strings)
10489 free (dynamic_strings);
10490 dynamic_strings = NULL;
10493 if (dynamic_symbols)
10495 free (dynamic_symbols);
10496 dynamic_symbols = NULL;
10497 num_dynamic_syms = 0;
10500 if (dynamic_syminfo)
10502 free (dynamic_syminfo);
10503 dynamic_syminfo = NULL;
10509 /* Process an ELF archive. The file is positioned just after the
10513 process_archive (char *file_name, FILE *file)
10515 struct ar_hdr arhdr;
10517 unsigned long size;
10518 char *longnames = NULL;
10519 unsigned long longnames_size = 0;
10520 size_t file_name_size;
10525 got = fread (&arhdr, 1, sizeof arhdr, file);
10526 if (got != sizeof arhdr)
10531 error (_("%s: failed to read archive header\n"), file_name);
10535 if (memcmp (arhdr.ar_name, "/ ", 16) == 0)
10537 /* This is the archive symbol table. Skip it.
10538 FIXME: We should have an option to dump it. */
10539 size = strtoul (arhdr.ar_size, NULL, 10);
10540 if (fseek (file, size + (size & 1), SEEK_CUR) != 0)
10542 error (_("%s: failed to skip archive symbol table\n"), file_name);
10546 got = fread (&arhdr, 1, sizeof arhdr, file);
10547 if (got != sizeof arhdr)
10552 error (_("%s: failed to read archive header\n"), file_name);
10557 if (memcmp (arhdr.ar_name, "// ", 16) == 0)
10559 /* This is the archive string table holding long member
10562 longnames_size = strtoul (arhdr.ar_size, NULL, 10);
10564 longnames = malloc (longnames_size);
10565 if (longnames == NULL)
10567 error (_("Out of memory\n"));
10571 if (fread (longnames, longnames_size, 1, file) != 1)
10574 error(_("%s: failed to read string table\n"), file_name);
10578 if ((longnames_size & 1) != 0)
10581 got = fread (&arhdr, 1, sizeof arhdr, file);
10582 if (got != sizeof arhdr)
10589 error (_("%s: failed to read archive header\n"), file_name);
10594 file_name_size = strlen (file_name);
10603 if (arhdr.ar_name[0] == '/')
10607 off = strtoul (arhdr.ar_name + 1, NULL, 10);
10608 if (off >= longnames_size)
10610 error (_("%s: invalid archive string table offset %lu\n"), off);
10615 name = longnames + off;
10616 nameend = memchr (name, '/', longnames_size - off);
10620 name = arhdr.ar_name;
10621 nameend = memchr (name, '/', 16);
10624 if (nameend == NULL)
10626 error (_("%s: bad archive file name\n"));
10631 namealc = malloc (file_name_size + (nameend - name) + 3);
10632 if (namealc == NULL)
10634 error (_("Out of memory\n"));
10639 memcpy (namealc, file_name, file_name_size);
10640 namealc[file_name_size] = '(';
10641 memcpy (namealc + file_name_size + 1, name, nameend - name);
10642 namealc[file_name_size + 1 + (nameend - name)] = ')';
10643 namealc[file_name_size + 2 + (nameend - name)] = '\0';
10645 archive_file_offset = ftell (file);
10646 archive_file_size = strtoul (arhdr.ar_size, NULL, 10);
10648 ret |= process_object (namealc, file);
10653 (archive_file_offset
10654 + archive_file_size
10655 + (archive_file_size & 1)),
10658 error (_("%s: failed to seek to next archive header\n"), file_name);
10663 got = fread (&arhdr, 1, sizeof arhdr, file);
10664 if (got != sizeof arhdr)
10669 error (_("%s: failed to read archive header\n"), file_name);
10675 if (longnames != 0)
10682 process_file (char *file_name)
10685 struct stat statbuf;
10686 char armag[SARMAG];
10689 if (stat (file_name, &statbuf) < 0)
10691 if (errno == ENOENT)
10692 error (_("'%s': No such file\n"), file_name);
10694 error (_("Could not locate '%s'. System error message: %s\n"),
10695 file_name, strerror (errno));
10699 if (! S_ISREG (statbuf.st_mode))
10701 error (_("'%s' is not an ordinary file\n"), file_name);
10705 file = fopen (file_name, "rb");
10708 error (_("Input file '%s' is not readable.\n"), file_name);
10712 if (fread (armag, SARMAG, 1, file) != 1)
10714 error (_("%s: Failed to read file header\n"), file_name);
10719 if (memcmp (armag, ARMAG, SARMAG) == 0)
10720 ret = process_archive (file_name, file);
10724 archive_file_size = archive_file_offset = 0;
10725 ret = process_object (file_name, file);
10733 #ifdef SUPPORT_DISASSEMBLY
10734 /* Needed by the i386 disassembler. For extra credit, someone could
10735 fix this so that we insert symbolic addresses here, esp for GOT/PLT
10739 print_address (unsigned int addr, FILE *outfile)
10741 fprintf (outfile,"0x%8.8x", addr);
10744 /* Needed by the i386 disassembler. */
10746 db_task_printsym (unsigned int addr)
10748 print_address (addr, stderr);
10753 main (int argc, char **argv)
10756 char *cmdline_dump_sects = NULL;
10757 unsigned num_cmdline_dump_sects = 0;
10759 #if defined (HAVE_SETLOCALE) && defined (HAVE_LC_MESSAGES)
10760 setlocale (LC_MESSAGES, "");
10762 #if defined (HAVE_SETLOCALE)
10763 setlocale (LC_CTYPE, "");
10765 bindtextdomain (PACKAGE, LOCALEDIR);
10766 textdomain (PACKAGE);
10768 parse_args (argc, argv);
10770 if (optind < (argc - 1))
10773 /* When processing more than one file remember the dump requests
10774 issued on command line to reset them after each file. */
10775 if (optind + 1 < argc && dump_sects != NULL)
10777 cmdline_dump_sects = malloc (num_dump_sects);
10778 if (cmdline_dump_sects == NULL)
10779 error (_("Out of memory allocating dump request table."));
10782 memcpy (cmdline_dump_sects, dump_sects, num_dump_sects);
10783 num_cmdline_dump_sects = num_dump_sects;
10788 while (optind < argc)
10790 err |= process_file (argv[optind++]);
10792 /* Reset dump requests. */
10793 if (optind < argc && dump_sects != NULL)
10795 num_dump_sects = num_cmdline_dump_sects;
10796 if (num_cmdline_dump_sects > 0)
10797 memcpy (dump_sects, cmdline_dump_sects, num_cmdline_dump_sects);
10801 if (dump_sects != NULL)
10803 if (cmdline_dump_sects != NULL)
10804 free (cmdline_dump_sects);