1 /* readelf.c -- display contents of an ELF format file
2 Copyright 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005
3 Free Software Foundation, Inc.
5 Originally developed by Eric Youngdale <eric@andante.jic.com>
6 Modifications by Nick Clifton <nickc@redhat.com>
8 This file is part of GNU Binutils.
10 This program is free software; you can redistribute it and/or modify
11 it under the terms of the GNU General Public License as published by
12 the Free Software Foundation; either version 2 of the License, or
13 (at your option) any later version.
15 This program is distributed in the hope that it will be useful,
16 but WITHOUT ANY WARRANTY; without even the implied warranty of
17 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 GNU General Public License for more details.
20 You should have received a copy of the GNU General Public License
21 along with this program; if not, write to the Free Software
22 Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA
25 /* The difference between readelf and objdump:
27 Both programs are capable of displaying the contents of ELF format files,
28 so why does the binutils project have two file dumpers ?
30 The reason is that objdump sees an ELF file through a BFD filter of the
31 world; if BFD has a bug where, say, it disagrees about a machine constant
32 in e_flags, then the odds are good that it will remain internally
33 consistent. The linker sees it the BFD way, objdump sees it the BFD way,
34 GAS sees it the BFD way. There was need for a tool to go find out what
35 the file actually says.
37 This is why the readelf program does not link against the BFD library - it
38 exists as an independent program to help verify the correct working of BFD.
40 There is also the case that readelf can provide more information about an
41 ELF file than is provided by objdump. In particular it can display DWARF
42 debugging information which (at the moment) objdump cannot. */
45 #include <sys/types.h>
51 /* Define BFD64 here, even if our default architecture is 32 bit ELF
52 as this will allow us to read in and parse 64bit and 32bit ELF files.
53 Only do this if we believe that the compiler can support a 64 bit
54 data type. For now we only rely on GCC being able to do this. */
60 #include "elf/common.h"
61 #include "elf/external.h"
62 #include "elf/internal.h"
63 #include "elf/dwarf2.h"
65 /* The following headers use the elf/reloc-macros.h file to
66 automatically generate relocation recognition functions
67 such as elf_mips_reloc_type() */
69 #define RELOC_MACROS_GEN_FUNC
71 #include "elf/alpha.h"
91 #include "elf/m68hc11.h"
92 #include "elf/mcore.h"
95 #include "elf/mn10200.h"
96 #include "elf/mn10300.h"
98 #include "elf/msp430.h"
102 #include "elf/ppc64.h"
103 #include "elf/s390.h"
105 #include "elf/sparc.h"
106 #include "elf/v850.h"
108 #include "elf/x86-64.h"
109 #include "elf/xstormy16.h"
111 #include "elf/iq2000.h"
112 #include "elf/xtensa.h"
118 #include "libiberty.h"
120 char *program_name = "readelf";
121 static long archive_file_offset;
122 static unsigned long archive_file_size;
123 static unsigned long dynamic_addr;
124 static bfd_size_type dynamic_size;
125 static unsigned int dynamic_nent;
126 static char *dynamic_strings;
127 static unsigned long dynamic_strings_length;
128 static char *string_table;
129 static unsigned long string_table_length;
130 static unsigned long num_dynamic_syms;
131 static Elf_Internal_Sym *dynamic_symbols;
132 static Elf_Internal_Syminfo *dynamic_syminfo;
133 static unsigned long dynamic_syminfo_offset;
134 static unsigned int dynamic_syminfo_nent;
135 static char program_interpreter[64];
136 static bfd_vma dynamic_info[DT_JMPREL + 1];
137 static bfd_vma version_info[16];
138 static Elf_Internal_Ehdr elf_header;
139 static Elf_Internal_Shdr *section_headers;
140 static Elf_Internal_Phdr *program_headers;
141 static Elf_Internal_Dyn *dynamic_section;
142 static Elf_Internal_Shdr *symtab_shndx_hdr;
143 static int show_name;
144 static int do_dynamic;
147 static int do_sections;
148 static int do_section_groups;
149 static int do_full_section_name;
150 static int do_segments;
151 static int do_unwind;
152 static int do_using_dynamic;
153 static int do_header;
155 static int do_version;
157 static int do_histogram;
158 static int do_debugging;
159 static int do_debug_info;
160 static int do_debug_abbrevs;
161 static int do_debug_lines;
162 static int do_debug_pubnames;
163 static int do_debug_aranges;
164 static int do_debug_ranges;
165 static int do_debug_frames;
166 static int do_debug_frames_interp;
167 static int do_debug_macinfo;
168 static int do_debug_str;
169 static int do_debug_loc;
172 static int is_32bit_elf;
173 static int have_frame_base;
174 static int need_base_address;
175 static bfd_vma eh_addr_size;
179 struct group_list *next;
180 unsigned int section_index;
185 struct group_list *root;
186 unsigned int group_index;
189 static size_t group_count;
190 static struct group *section_groups;
191 static struct group **section_headers_groups;
193 /* A dynamic array of flags indicating for which sections a hex dump
194 has been requested (via the -x switch) and/or a disassembly dump
195 (via the -i switch). */
196 char *cmdline_dump_sects = NULL;
197 unsigned num_cmdline_dump_sects = 0;
199 /* A dynamic array of flags indicating for which sections a dump of
200 some kind has been requested. It is reset on a per-object file
201 basis and then initialised from the cmdline_dump_sects array and
202 the results of interpreting the -w switch. */
203 char *dump_sects = NULL;
204 unsigned int num_dump_sects = 0;
206 #define HEX_DUMP (1 << 0)
207 #define DISASS_DUMP (1 << 1)
208 #define DEBUG_DUMP (1 << 2)
210 /* How to print a vma value. */
211 typedef enum print_mode
223 static bfd_vma (*byte_get) (unsigned char *, int);
224 static void (*byte_put) (unsigned char *, bfd_vma, int);
228 #define SECTION_NAME(X) ((X) == NULL ? "<none>" : \
229 ((X)->sh_name >= string_table_length \
230 ? "<corrupt>" : string_table + (X)->sh_name))
232 /* Given st_shndx I, map to section_headers index. */
233 #define SECTION_HEADER_INDEX(I) \
234 ((I) < SHN_LORESERVE \
236 : ((I) <= SHN_HIRESERVE \
238 : (I) - (SHN_HIRESERVE + 1 - SHN_LORESERVE)))
240 /* Reverse of the above. */
241 #define SECTION_HEADER_NUM(N) \
242 ((N) < SHN_LORESERVE \
244 : (N) + (SHN_HIRESERVE + 1 - SHN_LORESERVE))
246 #define SECTION_HEADER(I) (section_headers + SECTION_HEADER_INDEX (I))
248 #define DT_VERSIONTAGIDX(tag) (DT_VERNEEDNUM - (tag)) /* Reverse order! */
250 #define BYTE_GET(field) byte_get (field, sizeof (field))
252 #define NUM_ELEM(array) (sizeof (array) / sizeof ((array)[0]))
254 #define GET_ELF_SYMBOLS(file, section) \
255 (is_32bit_elf ? get_32bit_elf_symbols (file, section) \
256 : get_64bit_elf_symbols (file, section))
258 #define VALID_DYNAMIC_NAME(offset) ((dynamic_strings != NULL) && (offset < dynamic_strings_length))
259 /* GET_DYNAMIC_NAME asssumes that VALID_DYNAMIC_NAME has
260 already been called and verified that the string exists. */
261 #define GET_DYNAMIC_NAME(offset) (dynamic_strings + offset)
263 /* This is just a bit of syntatic sugar. */
264 #define streq(a,b) (strcmp ((a), (b)) == 0)
265 #define strneq(a,b,n) (strncmp ((a), (b), (n)) == 0)
267 static void ATTRIBUTE_PRINTF_1
268 error (const char *message, ...)
272 va_start (args, message);
273 fprintf (stderr, _("%s: Error: "), program_name);
274 vfprintf (stderr, message, args);
278 static void ATTRIBUTE_PRINTF_1
279 warn (const char *message, ...)
283 va_start (args, message);
284 fprintf (stderr, _("%s: Warning: "), program_name);
285 vfprintf (stderr, message, args);
290 cmalloc (size_t nmemb, size_t size)
292 /* Check for overflow. */
293 if (nmemb >= ~(size_t) 0 / size)
296 return malloc (nmemb * size);
300 xcmalloc (size_t nmemb, size_t size)
302 /* Check for overflow. */
303 if (nmemb >= ~(size_t) 0 / size)
306 return xmalloc (nmemb * size);
310 xcrealloc (void *ptr, size_t nmemb, size_t size)
312 /* Check for overflow. */
313 if (nmemb >= ~(size_t) 0 / size)
316 return xrealloc (ptr, nmemb * size);
320 get_data (void *var, FILE *file, long offset, size_t size, size_t nmemb,
325 if (size == 0 || nmemb == 0)
328 if (fseek (file, archive_file_offset + offset, SEEK_SET))
330 error (_("Unable to seek to 0x%lx for %s\n"),
331 archive_file_offset + offset, reason);
338 /* Check for overflow. */
339 if (nmemb < (~(size_t) 0 - 1) / size)
340 /* + 1 so that we can '\0' terminate invalid string table sections. */
341 mvar = malloc (size * nmemb + 1);
345 error (_("Out of memory allocating 0x%lx bytes for %s\n"),
346 (unsigned long)(size * nmemb), reason);
350 ((char *) mvar)[size * nmemb] = '\0';
353 if (fread (mvar, size, nmemb, file) != nmemb)
355 error (_("Unable to read in 0x%lx bytes of %s\n"),
356 (unsigned long)(size * nmemb), reason);
366 byte_get_little_endian (unsigned char *field, int size)
374 return ((unsigned int) (field[0]))
375 | (((unsigned int) (field[1])) << 8);
379 /* We want to extract data from an 8 byte wide field and
380 place it into a 4 byte wide field. Since this is a little
381 endian source we can just use the 4 byte extraction code. */
385 return ((unsigned long) (field[0]))
386 | (((unsigned long) (field[1])) << 8)
387 | (((unsigned long) (field[2])) << 16)
388 | (((unsigned long) (field[3])) << 24);
392 return ((bfd_vma) (field[0]))
393 | (((bfd_vma) (field[1])) << 8)
394 | (((bfd_vma) (field[2])) << 16)
395 | (((bfd_vma) (field[3])) << 24)
396 | (((bfd_vma) (field[4])) << 32)
397 | (((bfd_vma) (field[5])) << 40)
398 | (((bfd_vma) (field[6])) << 48)
399 | (((bfd_vma) (field[7])) << 56);
402 error (_("Unhandled data length: %d\n"), size);
408 byte_get_signed (unsigned char *field, int size)
410 bfd_vma x = byte_get (field, size);
415 return (x ^ 0x80) - 0x80;
417 return (x ^ 0x8000) - 0x8000;
419 return (x ^ 0x80000000) - 0x80000000;
428 byte_put_little_endian (unsigned char *field, bfd_vma value, int size)
433 field[7] = (((value >> 24) >> 24) >> 8) & 0xff;
434 field[6] = ((value >> 24) >> 24) & 0xff;
435 field[5] = ((value >> 24) >> 16) & 0xff;
436 field[4] = ((value >> 24) >> 8) & 0xff;
439 field[3] = (value >> 24) & 0xff;
440 field[2] = (value >> 16) & 0xff;
443 field[1] = (value >> 8) & 0xff;
446 field[0] = value & 0xff;
450 error (_("Unhandled data length: %d\n"), size);
455 #if defined BFD64 && !BFD_HOST_64BIT_LONG
457 print_dec_vma (bfd_vma vma, int is_signed)
463 if (is_signed && (bfd_signed_vma) vma < 0)
472 *bufp++ = '0' + vma % 10;
484 print_hex_vma (bfd_vma vma)
492 char digit = '0' + (vma & 0x0f);
494 digit += 'a' - '0' - 10;
507 /* Print a VMA value. */
509 print_vma (bfd_vma vma, print_mode mode)
518 return printf ("0x%8.8lx", (unsigned long) vma);
521 return printf ("%8.8lx", (unsigned long) vma);
525 return printf ("%5ld", (long) vma);
529 return printf ("0x%lx", (unsigned long) vma);
532 return printf ("%lx", (unsigned long) vma);
535 return printf ("%ld", (unsigned long) vma);
538 return printf ("%lu", (unsigned long) vma);
561 #if BFD_HOST_64BIT_LONG
562 return nc + printf ("%lx", vma);
564 return nc + print_hex_vma (vma);
568 #if BFD_HOST_64BIT_LONG
569 return printf ("%ld", vma);
571 return print_dec_vma (vma, 1);
575 #if BFD_HOST_64BIT_LONG
577 return printf ("%5ld", vma);
579 return printf ("%#lx", vma);
582 return printf ("%5ld", _bfd_int64_low (vma));
584 return print_hex_vma (vma);
588 #if BFD_HOST_64BIT_LONG
589 return printf ("%lu", vma);
591 return print_dec_vma (vma, 0);
599 /* Display a symbol on stdout. If do_wide is not true then
600 format the symbol to be at most WIDTH characters,
601 truncating as necessary. If WIDTH is negative then
602 format the string to be exactly - WIDTH characters,
603 truncating or padding as necessary. */
606 print_symbol (int width, const char *symbol)
609 printf ("%s", symbol);
611 printf ("%-*.*s", width, width, symbol);
613 printf ("%-.*s", width, symbol);
617 byte_get_big_endian (unsigned char *field, int size)
625 return ((unsigned int) (field[1])) | (((int) (field[0])) << 8);
629 /* Although we are extracing data from an 8 byte wide field,
630 we are returning only 4 bytes of data. */
635 return ((unsigned long) (field[3]))
636 | (((unsigned long) (field[2])) << 8)
637 | (((unsigned long) (field[1])) << 16)
638 | (((unsigned long) (field[0])) << 24);
642 return ((bfd_vma) (field[7]))
643 | (((bfd_vma) (field[6])) << 8)
644 | (((bfd_vma) (field[5])) << 16)
645 | (((bfd_vma) (field[4])) << 24)
646 | (((bfd_vma) (field[3])) << 32)
647 | (((bfd_vma) (field[2])) << 40)
648 | (((bfd_vma) (field[1])) << 48)
649 | (((bfd_vma) (field[0])) << 56);
653 error (_("Unhandled data length: %d\n"), size);
659 byte_put_big_endian (unsigned char *field, bfd_vma value, int size)
664 field[7] = value & 0xff;
665 field[6] = (value >> 8) & 0xff;
666 field[5] = (value >> 16) & 0xff;
667 field[4] = (value >> 24) & 0xff;
672 field[3] = value & 0xff;
673 field[2] = (value >> 8) & 0xff;
677 field[1] = value & 0xff;
681 field[0] = value & 0xff;
685 error (_("Unhandled data length: %d\n"), size);
690 /* Return a pointer to section NAME, or NULL if no such section exists. */
692 static Elf_Internal_Shdr *
693 find_section (const char *name)
697 for (i = 0; i < elf_header.e_shnum; i++)
698 if (streq (SECTION_NAME (section_headers + i), name))
699 return section_headers + i;
704 /* Guess the relocation size commonly used by the specific machines. */
707 guess_is_rela (unsigned long e_machine)
711 /* Targets that use REL relocations. */
726 /* Targets that use RELA relocations. */
741 case EM_CYGNUS_MN10200:
743 case EM_CYGNUS_MN10300:
791 warn (_("Don't know about relocations on this machine architecture\n"));
797 slurp_rela_relocs (FILE *file,
798 unsigned long rel_offset,
799 unsigned long rel_size,
800 Elf_Internal_Rela **relasp,
801 unsigned long *nrelasp)
803 Elf_Internal_Rela *relas;
804 unsigned long nrelas;
809 Elf32_External_Rela *erelas;
811 erelas = get_data (NULL, file, rel_offset, 1, rel_size, _("relocs"));
815 nrelas = rel_size / sizeof (Elf32_External_Rela);
817 relas = cmalloc (nrelas, sizeof (Elf_Internal_Rela));
822 error (_("out of memory parsing relocs"));
826 for (i = 0; i < nrelas; i++)
828 relas[i].r_offset = BYTE_GET (erelas[i].r_offset);
829 relas[i].r_info = BYTE_GET (erelas[i].r_info);
830 relas[i].r_addend = BYTE_GET (erelas[i].r_addend);
837 Elf64_External_Rela *erelas;
839 erelas = get_data (NULL, file, rel_offset, 1, rel_size, _("relocs"));
843 nrelas = rel_size / sizeof (Elf64_External_Rela);
845 relas = cmalloc (nrelas, sizeof (Elf_Internal_Rela));
850 error (_("out of memory parsing relocs"));
854 for (i = 0; i < nrelas; i++)
856 relas[i].r_offset = BYTE_GET (erelas[i].r_offset);
857 relas[i].r_info = BYTE_GET (erelas[i].r_info);
858 relas[i].r_addend = BYTE_GET (erelas[i].r_addend);
869 slurp_rel_relocs (FILE *file,
870 unsigned long rel_offset,
871 unsigned long rel_size,
872 Elf_Internal_Rela **relsp,
873 unsigned long *nrelsp)
875 Elf_Internal_Rela *rels;
881 Elf32_External_Rel *erels;
883 erels = get_data (NULL, file, rel_offset, 1, rel_size, _("relocs"));
887 nrels = rel_size / sizeof (Elf32_External_Rel);
889 rels = cmalloc (nrels, sizeof (Elf_Internal_Rela));
894 error (_("out of memory parsing relocs"));
898 for (i = 0; i < nrels; i++)
900 rels[i].r_offset = BYTE_GET (erels[i].r_offset);
901 rels[i].r_info = BYTE_GET (erels[i].r_info);
902 rels[i].r_addend = 0;
909 Elf64_External_Rel *erels;
911 erels = get_data (NULL, file, rel_offset, 1, rel_size, _("relocs"));
915 nrels = rel_size / sizeof (Elf64_External_Rel);
917 rels = cmalloc (nrels, sizeof (Elf_Internal_Rela));
922 error (_("out of memory parsing relocs"));
926 for (i = 0; i < nrels; i++)
928 rels[i].r_offset = BYTE_GET (erels[i].r_offset);
929 rels[i].r_info = BYTE_GET (erels[i].r_info);
930 rels[i].r_addend = 0;
940 /* Display the contents of the relocation data found at the specified
944 dump_relocations (FILE *file,
945 unsigned long rel_offset,
946 unsigned long rel_size,
947 Elf_Internal_Sym *symtab,
950 unsigned long strtablen,
954 Elf_Internal_Rela *rels;
957 if (is_rela == UNKNOWN)
958 is_rela = guess_is_rela (elf_header.e_machine);
962 if (!slurp_rela_relocs (file, rel_offset, rel_size, &rels, &rel_size))
967 if (!slurp_rel_relocs (file, rel_offset, rel_size, &rels, &rel_size))
976 printf (_(" Offset Info Type Sym. Value Symbol's Name + Addend\n"));
978 printf (_(" Offset Info Type Sym.Value Sym. Name + Addend\n"));
983 printf (_(" Offset Info Type Sym. Value Symbol's Name\n"));
985 printf (_(" Offset Info Type Sym.Value Sym. Name\n"));
993 printf (_(" Offset Info Type Symbol's Value Symbol's Name + Addend\n"));
995 printf (_(" Offset Info Type Sym. Value Sym. Name + Addend\n"));
1000 printf (_(" Offset Info Type Symbol's Value Symbol's Name\n"));
1002 printf (_(" Offset Info Type Sym. Value Sym. Name\n"));
1006 for (i = 0; i < rel_size; i++)
1009 const char *rtype2 = NULL;
1010 const char *rtype3 = NULL;
1013 bfd_vma symtab_index;
1018 offset = rels[i].r_offset;
1019 info = rels[i].r_info;
1023 type = ELF32_R_TYPE (info);
1024 symtab_index = ELF32_R_SYM (info);
1028 /* The #ifdef BFD64 below is to prevent a compile time warning.
1029 We know that if we do not have a 64 bit data type that we
1030 will never execute this code anyway. */
1032 if (elf_header.e_machine == EM_MIPS)
1034 /* In little-endian objects, r_info isn't really a 64-bit
1035 little-endian value: it has a 32-bit little-endian
1036 symbol index followed by four individual byte fields.
1037 Reorder INFO accordingly. */
1038 if (elf_header.e_ident[EI_DATA] != ELFDATA2MSB)
1039 info = (((info & 0xffffffff) << 32)
1040 | ((info >> 56) & 0xff)
1041 | ((info >> 40) & 0xff00)
1042 | ((info >> 24) & 0xff0000)
1043 | ((info >> 8) & 0xff000000));
1044 type = ELF64_MIPS_R_TYPE (info);
1045 type2 = ELF64_MIPS_R_TYPE2 (info);
1046 type3 = ELF64_MIPS_R_TYPE3 (info);
1048 else if (elf_header.e_machine == EM_SPARCV9)
1049 type = ELF64_R_TYPE_ID (info);
1051 type = ELF64_R_TYPE (info);
1053 symtab_index = ELF64_R_SYM (info);
1059 #ifdef _bfd_int64_low
1060 printf ("%8.8lx %8.8lx ", _bfd_int64_low (offset), _bfd_int64_low (info));
1062 printf ("%8.8lx %8.8lx ", offset, info);
1067 #ifdef _bfd_int64_low
1069 ? "%8.8lx%8.8lx %8.8lx%8.8lx "
1070 : "%4.4lx%8.8lx %4.4lx%8.8lx ",
1071 _bfd_int64_high (offset),
1072 _bfd_int64_low (offset),
1073 _bfd_int64_high (info),
1074 _bfd_int64_low (info));
1077 ? "%16.16lx %16.16lx "
1078 : "%12.12lx %12.12lx ",
1083 switch (elf_header.e_machine)
1090 case EM_CYGNUS_M32R:
1091 rtype = elf_m32r_reloc_type (type);
1096 rtype = elf_i386_reloc_type (type);
1101 rtype = elf_m68hc11_reloc_type (type);
1105 rtype = elf_m68k_reloc_type (type);
1109 rtype = elf_i960_reloc_type (type);
1114 rtype = elf_avr_reloc_type (type);
1117 case EM_OLD_SPARCV9:
1118 case EM_SPARC32PLUS:
1121 rtype = elf_sparc_reloc_type (type);
1125 case EM_CYGNUS_V850:
1126 rtype = v850_reloc_type (type);
1130 case EM_CYGNUS_D10V:
1131 rtype = elf_d10v_reloc_type (type);
1135 case EM_CYGNUS_D30V:
1136 rtype = elf_d30v_reloc_type (type);
1140 rtype = elf_dlx_reloc_type (type);
1144 rtype = elf_sh_reloc_type (type);
1148 case EM_CYGNUS_MN10300:
1149 rtype = elf_mn10300_reloc_type (type);
1153 case EM_CYGNUS_MN10200:
1154 rtype = elf_mn10200_reloc_type (type);
1158 case EM_CYGNUS_FR30:
1159 rtype = elf_fr30_reloc_type (type);
1163 rtype = elf_frv_reloc_type (type);
1167 rtype = elf_mcore_reloc_type (type);
1171 rtype = elf_mmix_reloc_type (type);
1176 rtype = elf_msp430_reloc_type (type);
1180 rtype = elf_ppc_reloc_type (type);
1184 rtype = elf_ppc64_reloc_type (type);
1188 case EM_MIPS_RS3_LE:
1189 rtype = elf_mips_reloc_type (type);
1192 rtype2 = elf_mips_reloc_type (type2);
1193 rtype3 = elf_mips_reloc_type (type3);
1198 rtype = elf_alpha_reloc_type (type);
1202 rtype = elf_arm_reloc_type (type);
1206 rtype = elf_arc_reloc_type (type);
1210 rtype = elf_hppa_reloc_type (type);
1216 rtype = elf_h8_reloc_type (type);
1221 rtype = elf_or32_reloc_type (type);
1226 rtype = elf_pj_reloc_type (type);
1229 rtype = elf_ia64_reloc_type (type);
1233 rtype = elf_cris_reloc_type (type);
1237 rtype = elf_i860_reloc_type (type);
1241 rtype = elf_x86_64_reloc_type (type);
1245 rtype = i370_reloc_type (type);
1250 rtype = elf_s390_reloc_type (type);
1254 rtype = elf_xstormy16_reloc_type (type);
1258 rtype = elf_crx_reloc_type (type);
1262 rtype = elf_vax_reloc_type (type);
1267 rtype = elf_ip2k_reloc_type (type);
1271 rtype = elf_iq2000_reloc_type (type);
1276 rtype = elf_xtensa_reloc_type (type);
1280 rtype = elf_ms1_reloc_type (type);
1285 #ifdef _bfd_int64_low
1286 printf (_("unrecognized: %-7lx"), _bfd_int64_low (type));
1288 printf (_("unrecognized: %-7lx"), type);
1291 printf (do_wide ? "%-22.22s" : "%-17.17s", rtype);
1293 if (elf_header.e_machine == EM_ALPHA
1294 && streq (rtype, "R_ALPHA_LITUSE")
1297 switch (rels[i].r_addend)
1299 case LITUSE_ALPHA_ADDR: rtype = "ADDR"; break;
1300 case LITUSE_ALPHA_BASE: rtype = "BASE"; break;
1301 case LITUSE_ALPHA_BYTOFF: rtype = "BYTOFF"; break;
1302 case LITUSE_ALPHA_JSR: rtype = "JSR"; break;
1303 case LITUSE_ALPHA_TLSGD: rtype = "TLSGD"; break;
1304 case LITUSE_ALPHA_TLSLDM: rtype = "TLSLDM"; break;
1305 case LITUSE_ALPHA_JSRDIRECT: rtype = "JSRDIRECT"; break;
1306 default: rtype = NULL;
1309 printf (" (%s)", rtype);
1313 printf (_("<unknown addend: %lx>"),
1314 (unsigned long) rels[i].r_addend);
1317 else if (symtab_index)
1319 if (symtab == NULL || symtab_index >= nsyms)
1320 printf (" bad symbol index: %08lx", (unsigned long) symtab_index);
1323 Elf_Internal_Sym *psym;
1325 psym = symtab + symtab_index;
1328 print_vma (psym->st_value, LONG_HEX);
1329 printf (is_32bit_elf ? " " : " ");
1331 if (psym->st_name == 0)
1333 const char *sec_name = "<null>";
1336 if (ELF_ST_TYPE (psym->st_info) == STT_SECTION)
1338 bfd_vma sec_index = (bfd_vma) -1;
1340 if (psym->st_shndx < SHN_LORESERVE)
1341 sec_index = psym->st_shndx;
1342 else if (psym->st_shndx > SHN_HIRESERVE)
1343 sec_index = psym->st_shndx - (SHN_HIRESERVE + 1
1346 if (sec_index != (bfd_vma) -1)
1347 sec_name = SECTION_NAME (section_headers + sec_index);
1348 else if (psym->st_shndx == SHN_ABS)
1350 else if (psym->st_shndx == SHN_COMMON)
1351 sec_name = "COMMON";
1352 else if (elf_header.e_machine == EM_IA_64
1353 && elf_header.e_ident[EI_OSABI] == ELFOSABI_HPUX
1354 && psym->st_shndx == SHN_IA_64_ANSI_COMMON)
1355 sec_name = "ANSI_COM";
1358 sprintf (name_buf, "<section 0x%x>",
1359 (unsigned int) psym->st_shndx);
1360 sec_name = name_buf;
1363 print_symbol (22, sec_name);
1365 else if (strtab == NULL)
1366 printf (_("<string table index: %3ld>"), psym->st_name);
1367 else if (psym->st_name >= strtablen)
1368 printf (_("<corrupt string table index: %3ld>"), psym->st_name);
1370 print_symbol (22, strtab + psym->st_name);
1373 printf (" + %lx", (unsigned long) rels[i].r_addend);
1378 printf ("%*c", is_32bit_elf ?
1379 (do_wide ? 34 : 28) : (do_wide ? 26 : 20), ' ');
1380 print_vma (rels[i].r_addend, LONG_HEX);
1383 if (elf_header.e_machine == EM_SPARCV9 && streq (rtype, "R_SPARC_OLO10"))
1384 printf (" + %lx", (unsigned long) ELF64_R_TYPE_DATA (info));
1388 if (! is_32bit_elf && elf_header.e_machine == EM_MIPS)
1390 printf (" Type2: ");
1393 #ifdef _bfd_int64_low
1394 printf (_("unrecognized: %-7lx"), _bfd_int64_low (type2));
1396 printf (_("unrecognized: %-7lx"), type2);
1399 printf ("%-17.17s", rtype2);
1401 printf ("\n Type3: ");
1404 #ifdef _bfd_int64_low
1405 printf (_("unrecognized: %-7lx"), _bfd_int64_low (type3));
1407 printf (_("unrecognized: %-7lx"), type3);
1410 printf ("%-17.17s", rtype3);
1422 get_mips_dynamic_type (unsigned long type)
1426 case DT_MIPS_RLD_VERSION: return "MIPS_RLD_VERSION";
1427 case DT_MIPS_TIME_STAMP: return "MIPS_TIME_STAMP";
1428 case DT_MIPS_ICHECKSUM: return "MIPS_ICHECKSUM";
1429 case DT_MIPS_IVERSION: return "MIPS_IVERSION";
1430 case DT_MIPS_FLAGS: return "MIPS_FLAGS";
1431 case DT_MIPS_BASE_ADDRESS: return "MIPS_BASE_ADDRESS";
1432 case DT_MIPS_MSYM: return "MIPS_MSYM";
1433 case DT_MIPS_CONFLICT: return "MIPS_CONFLICT";
1434 case DT_MIPS_LIBLIST: return "MIPS_LIBLIST";
1435 case DT_MIPS_LOCAL_GOTNO: return "MIPS_LOCAL_GOTNO";
1436 case DT_MIPS_CONFLICTNO: return "MIPS_CONFLICTNO";
1437 case DT_MIPS_LIBLISTNO: return "MIPS_LIBLISTNO";
1438 case DT_MIPS_SYMTABNO: return "MIPS_SYMTABNO";
1439 case DT_MIPS_UNREFEXTNO: return "MIPS_UNREFEXTNO";
1440 case DT_MIPS_GOTSYM: return "MIPS_GOTSYM";
1441 case DT_MIPS_HIPAGENO: return "MIPS_HIPAGENO";
1442 case DT_MIPS_RLD_MAP: return "MIPS_RLD_MAP";
1443 case DT_MIPS_DELTA_CLASS: return "MIPS_DELTA_CLASS";
1444 case DT_MIPS_DELTA_CLASS_NO: return "MIPS_DELTA_CLASS_NO";
1445 case DT_MIPS_DELTA_INSTANCE: return "MIPS_DELTA_INSTANCE";
1446 case DT_MIPS_DELTA_INSTANCE_NO: return "MIPS_DELTA_INSTANCE_NO";
1447 case DT_MIPS_DELTA_RELOC: return "MIPS_DELTA_RELOC";
1448 case DT_MIPS_DELTA_RELOC_NO: return "MIPS_DELTA_RELOC_NO";
1449 case DT_MIPS_DELTA_SYM: return "MIPS_DELTA_SYM";
1450 case DT_MIPS_DELTA_SYM_NO: return "MIPS_DELTA_SYM_NO";
1451 case DT_MIPS_DELTA_CLASSSYM: return "MIPS_DELTA_CLASSSYM";
1452 case DT_MIPS_DELTA_CLASSSYM_NO: return "MIPS_DELTA_CLASSSYM_NO";
1453 case DT_MIPS_CXX_FLAGS: return "MIPS_CXX_FLAGS";
1454 case DT_MIPS_PIXIE_INIT: return "MIPS_PIXIE_INIT";
1455 case DT_MIPS_SYMBOL_LIB: return "MIPS_SYMBOL_LIB";
1456 case DT_MIPS_LOCALPAGE_GOTIDX: return "MIPS_LOCALPAGE_GOTIDX";
1457 case DT_MIPS_LOCAL_GOTIDX: return "MIPS_LOCAL_GOTIDX";
1458 case DT_MIPS_HIDDEN_GOTIDX: return "MIPS_HIDDEN_GOTIDX";
1459 case DT_MIPS_PROTECTED_GOTIDX: return "MIPS_PROTECTED_GOTIDX";
1460 case DT_MIPS_OPTIONS: return "MIPS_OPTIONS";
1461 case DT_MIPS_INTERFACE: return "MIPS_INTERFACE";
1462 case DT_MIPS_DYNSTR_ALIGN: return "MIPS_DYNSTR_ALIGN";
1463 case DT_MIPS_INTERFACE_SIZE: return "MIPS_INTERFACE_SIZE";
1464 case DT_MIPS_RLD_TEXT_RESOLVE_ADDR: return "MIPS_RLD_TEXT_RESOLVE_ADDR";
1465 case DT_MIPS_PERF_SUFFIX: return "MIPS_PERF_SUFFIX";
1466 case DT_MIPS_COMPACT_SIZE: return "MIPS_COMPACT_SIZE";
1467 case DT_MIPS_GP_VALUE: return "MIPS_GP_VALUE";
1468 case DT_MIPS_AUX_DYNAMIC: return "MIPS_AUX_DYNAMIC";
1475 get_sparc64_dynamic_type (unsigned long type)
1479 case DT_SPARC_REGISTER: return "SPARC_REGISTER";
1486 get_ppc_dynamic_type (unsigned long type)
1490 case DT_PPC_GOT: return "PPC_GOT";
1497 get_ppc64_dynamic_type (unsigned long type)
1501 case DT_PPC64_GLINK: return "PPC64_GLINK";
1502 case DT_PPC64_OPD: return "PPC64_OPD";
1503 case DT_PPC64_OPDSZ: return "PPC64_OPDSZ";
1510 get_parisc_dynamic_type (unsigned long type)
1514 case DT_HP_LOAD_MAP: return "HP_LOAD_MAP";
1515 case DT_HP_DLD_FLAGS: return "HP_DLD_FLAGS";
1516 case DT_HP_DLD_HOOK: return "HP_DLD_HOOK";
1517 case DT_HP_UX10_INIT: return "HP_UX10_INIT";
1518 case DT_HP_UX10_INITSZ: return "HP_UX10_INITSZ";
1519 case DT_HP_PREINIT: return "HP_PREINIT";
1520 case DT_HP_PREINITSZ: return "HP_PREINITSZ";
1521 case DT_HP_NEEDED: return "HP_NEEDED";
1522 case DT_HP_TIME_STAMP: return "HP_TIME_STAMP";
1523 case DT_HP_CHECKSUM: return "HP_CHECKSUM";
1524 case DT_HP_GST_SIZE: return "HP_GST_SIZE";
1525 case DT_HP_GST_VERSION: return "HP_GST_VERSION";
1526 case DT_HP_GST_HASHVAL: return "HP_GST_HASHVAL";
1533 get_ia64_dynamic_type (unsigned long type)
1537 case DT_IA_64_PLT_RESERVE: return "IA_64_PLT_RESERVE";
1544 get_alpha_dynamic_type (unsigned long type)
1548 case DT_ALPHA_PLTRO: return "ALPHA_PLTRO";
1555 get_dynamic_type (unsigned long type)
1557 static char buff[64];
1561 case DT_NULL: return "NULL";
1562 case DT_NEEDED: return "NEEDED";
1563 case DT_PLTRELSZ: return "PLTRELSZ";
1564 case DT_PLTGOT: return "PLTGOT";
1565 case DT_HASH: return "HASH";
1566 case DT_STRTAB: return "STRTAB";
1567 case DT_SYMTAB: return "SYMTAB";
1568 case DT_RELA: return "RELA";
1569 case DT_RELASZ: return "RELASZ";
1570 case DT_RELAENT: return "RELAENT";
1571 case DT_STRSZ: return "STRSZ";
1572 case DT_SYMENT: return "SYMENT";
1573 case DT_INIT: return "INIT";
1574 case DT_FINI: return "FINI";
1575 case DT_SONAME: return "SONAME";
1576 case DT_RPATH: return "RPATH";
1577 case DT_SYMBOLIC: return "SYMBOLIC";
1578 case DT_REL: return "REL";
1579 case DT_RELSZ: return "RELSZ";
1580 case DT_RELENT: return "RELENT";
1581 case DT_PLTREL: return "PLTREL";
1582 case DT_DEBUG: return "DEBUG";
1583 case DT_TEXTREL: return "TEXTREL";
1584 case DT_JMPREL: return "JMPREL";
1585 case DT_BIND_NOW: return "BIND_NOW";
1586 case DT_INIT_ARRAY: return "INIT_ARRAY";
1587 case DT_FINI_ARRAY: return "FINI_ARRAY";
1588 case DT_INIT_ARRAYSZ: return "INIT_ARRAYSZ";
1589 case DT_FINI_ARRAYSZ: return "FINI_ARRAYSZ";
1590 case DT_RUNPATH: return "RUNPATH";
1591 case DT_FLAGS: return "FLAGS";
1593 case DT_PREINIT_ARRAY: return "PREINIT_ARRAY";
1594 case DT_PREINIT_ARRAYSZ: return "PREINIT_ARRAYSZ";
1596 case DT_CHECKSUM: return "CHECKSUM";
1597 case DT_PLTPADSZ: return "PLTPADSZ";
1598 case DT_MOVEENT: return "MOVEENT";
1599 case DT_MOVESZ: return "MOVESZ";
1600 case DT_FEATURE: return "FEATURE";
1601 case DT_POSFLAG_1: return "POSFLAG_1";
1602 case DT_SYMINSZ: return "SYMINSZ";
1603 case DT_SYMINENT: return "SYMINENT"; /* aka VALRNGHI */
1605 case DT_ADDRRNGLO: return "ADDRRNGLO";
1606 case DT_CONFIG: return "CONFIG";
1607 case DT_DEPAUDIT: return "DEPAUDIT";
1608 case DT_AUDIT: return "AUDIT";
1609 case DT_PLTPAD: return "PLTPAD";
1610 case DT_MOVETAB: return "MOVETAB";
1611 case DT_SYMINFO: return "SYMINFO"; /* aka ADDRRNGHI */
1613 case DT_VERSYM: return "VERSYM";
1615 case DT_RELACOUNT: return "RELACOUNT";
1616 case DT_RELCOUNT: return "RELCOUNT";
1617 case DT_FLAGS_1: return "FLAGS_1";
1618 case DT_VERDEF: return "VERDEF";
1619 case DT_VERDEFNUM: return "VERDEFNUM";
1620 case DT_VERNEED: return "VERNEED";
1621 case DT_VERNEEDNUM: return "VERNEEDNUM";
1623 case DT_AUXILIARY: return "AUXILIARY";
1624 case DT_USED: return "USED";
1625 case DT_FILTER: return "FILTER";
1627 case DT_GNU_PRELINKED: return "GNU_PRELINKED";
1628 case DT_GNU_CONFLICT: return "GNU_CONFLICT";
1629 case DT_GNU_CONFLICTSZ: return "GNU_CONFLICTSZ";
1630 case DT_GNU_LIBLIST: return "GNU_LIBLIST";
1631 case DT_GNU_LIBLISTSZ: return "GNU_LIBLISTSZ";
1634 if ((type >= DT_LOPROC) && (type <= DT_HIPROC))
1638 switch (elf_header.e_machine)
1641 case EM_MIPS_RS3_LE:
1642 result = get_mips_dynamic_type (type);
1645 result = get_sparc64_dynamic_type (type);
1648 result = get_ppc_dynamic_type (type);
1651 result = get_ppc64_dynamic_type (type);
1654 result = get_ia64_dynamic_type (type);
1657 result = get_alpha_dynamic_type (type);
1667 snprintf (buff, sizeof (buff), _("Processor Specific: %lx"), type);
1669 else if ((type >= DT_LOOS) && (type <= DT_HIOS))
1673 switch (elf_header.e_machine)
1676 result = get_parisc_dynamic_type (type);
1686 snprintf (buff, sizeof (buff), _("Operating System specific: %lx"),
1690 snprintf (buff, sizeof (buff), _("<unknown>: %lx"), type);
1697 get_file_type (unsigned e_type)
1699 static char buff[32];
1703 case ET_NONE: return _("NONE (None)");
1704 case ET_REL: return _("REL (Relocatable file)");
1705 case ET_EXEC: return _("EXEC (Executable file)");
1706 case ET_DYN: return _("DYN (Shared object file)");
1707 case ET_CORE: return _("CORE (Core file)");
1710 if ((e_type >= ET_LOPROC) && (e_type <= ET_HIPROC))
1711 snprintf (buff, sizeof (buff), _("Processor Specific: (%x)"), e_type);
1712 else if ((e_type >= ET_LOOS) && (e_type <= ET_HIOS))
1713 snprintf (buff, sizeof (buff), _("OS Specific: (%x)"), e_type);
1715 snprintf (buff, sizeof (buff), _("<unknown>: %x"), e_type);
1721 get_machine_name (unsigned e_machine)
1723 static char buff[64]; /* XXX */
1727 case EM_NONE: return _("None");
1728 case EM_M32: return "WE32100";
1729 case EM_SPARC: return "Sparc";
1730 case EM_386: return "Intel 80386";
1731 case EM_68K: return "MC68000";
1732 case EM_88K: return "MC88000";
1733 case EM_486: return "Intel 80486";
1734 case EM_860: return "Intel 80860";
1735 case EM_MIPS: return "MIPS R3000";
1736 case EM_S370: return "IBM System/370";
1737 case EM_MIPS_RS3_LE: return "MIPS R4000 big-endian";
1738 case EM_OLD_SPARCV9: return "Sparc v9 (old)";
1739 case EM_PARISC: return "HPPA";
1740 case EM_PPC_OLD: return "Power PC (old)";
1741 case EM_SPARC32PLUS: return "Sparc v8+" ;
1742 case EM_960: return "Intel 90860";
1743 case EM_PPC: return "PowerPC";
1744 case EM_PPC64: return "PowerPC64";
1745 case EM_V800: return "NEC V800";
1746 case EM_FR20: return "Fujitsu FR20";
1747 case EM_RH32: return "TRW RH32";
1748 case EM_MCORE: return "MCORE";
1749 case EM_ARM: return "ARM";
1750 case EM_OLD_ALPHA: return "Digital Alpha (old)";
1751 case EM_SH: return "Renesas / SuperH SH";
1752 case EM_SPARCV9: return "Sparc v9";
1753 case EM_TRICORE: return "Siemens Tricore";
1754 case EM_ARC: return "ARC";
1755 case EM_H8_300: return "Renesas H8/300";
1756 case EM_H8_300H: return "Renesas H8/300H";
1757 case EM_H8S: return "Renesas H8S";
1758 case EM_H8_500: return "Renesas H8/500";
1759 case EM_IA_64: return "Intel IA-64";
1760 case EM_MIPS_X: return "Stanford MIPS-X";
1761 case EM_COLDFIRE: return "Motorola Coldfire";
1762 case EM_68HC12: return "Motorola M68HC12";
1763 case EM_ALPHA: return "Alpha";
1764 case EM_CYGNUS_D10V:
1765 case EM_D10V: return "d10v";
1766 case EM_CYGNUS_D30V:
1767 case EM_D30V: return "d30v";
1768 case EM_CYGNUS_M32R:
1769 case EM_M32R: return "Renesas M32R (formerly Mitsubishi M32r)";
1770 case EM_CYGNUS_V850:
1771 case EM_V850: return "NEC v850";
1772 case EM_CYGNUS_MN10300:
1773 case EM_MN10300: return "mn10300";
1774 case EM_CYGNUS_MN10200:
1775 case EM_MN10200: return "mn10200";
1776 case EM_CYGNUS_FR30:
1777 case EM_FR30: return "Fujitsu FR30";
1778 case EM_CYGNUS_FRV: return "Fujitsu FR-V";
1780 case EM_PJ: return "picoJava";
1781 case EM_MMA: return "Fujitsu Multimedia Accelerator";
1782 case EM_PCP: return "Siemens PCP";
1783 case EM_NCPU: return "Sony nCPU embedded RISC processor";
1784 case EM_NDR1: return "Denso NDR1 microprocesspr";
1785 case EM_STARCORE: return "Motorola Star*Core processor";
1786 case EM_ME16: return "Toyota ME16 processor";
1787 case EM_ST100: return "STMicroelectronics ST100 processor";
1788 case EM_TINYJ: return "Advanced Logic Corp. TinyJ embedded processor";
1789 case EM_FX66: return "Siemens FX66 microcontroller";
1790 case EM_ST9PLUS: return "STMicroelectronics ST9+ 8/16 bit microcontroller";
1791 case EM_ST7: return "STMicroelectronics ST7 8-bit microcontroller";
1792 case EM_68HC16: return "Motorola MC68HC16 Microcontroller";
1793 case EM_68HC11: return "Motorola MC68HC11 Microcontroller";
1794 case EM_68HC08: return "Motorola MC68HC08 Microcontroller";
1795 case EM_68HC05: return "Motorola MC68HC05 Microcontroller";
1796 case EM_SVX: return "Silicon Graphics SVx";
1797 case EM_ST19: return "STMicroelectronics ST19 8-bit microcontroller";
1798 case EM_VAX: return "Digital VAX";
1800 case EM_AVR: return "Atmel AVR 8-bit microcontroller";
1801 case EM_CRIS: return "Axis Communications 32-bit embedded processor";
1802 case EM_JAVELIN: return "Infineon Technologies 32-bit embedded cpu";
1803 case EM_FIREPATH: return "Element 14 64-bit DSP processor";
1804 case EM_ZSP: return "LSI Logic's 16-bit DSP processor";
1805 case EM_MMIX: return "Donald Knuth's educational 64-bit processor";
1806 case EM_HUANY: return "Harvard Universitys's machine-independent object format";
1807 case EM_PRISM: return "Vitesse Prism";
1808 case EM_X86_64: return "Advanced Micro Devices X86-64";
1810 case EM_S390: return "IBM S/390";
1811 case EM_XSTORMY16: return "Sanyo Xstormy16 CPU core";
1813 case EM_OR32: return "OpenRISC";
1814 case EM_CRX: return "National Semiconductor CRX microprocessor";
1815 case EM_DLX: return "OpenDLX";
1817 case EM_IP2K: return "Ubicom IP2xxx 8-bit microcontrollers";
1818 case EM_IQ2000: return "Vitesse IQ2000";
1820 case EM_XTENSA: return "Tensilica Xtensa Processor";
1821 case EM_MS1: return "Morpho Techologies MS1 processor";
1823 snprintf (buff, sizeof (buff), _("<unknown>: %x"), e_machine);
1829 decode_ARM_machine_flags (unsigned e_flags, char buf[])
1834 eabi = EF_ARM_EABI_VERSION (e_flags);
1835 e_flags &= ~ EF_ARM_EABIMASK;
1837 /* Handle "generic" ARM flags. */
1838 if (e_flags & EF_ARM_RELEXEC)
1840 strcat (buf, ", relocatable executable");
1841 e_flags &= ~ EF_ARM_RELEXEC;
1844 if (e_flags & EF_ARM_HASENTRY)
1846 strcat (buf, ", has entry point");
1847 e_flags &= ~ EF_ARM_HASENTRY;
1850 /* Now handle EABI specific flags. */
1854 strcat (buf, ", <unrecognized EABI>");
1859 case EF_ARM_EABI_VER1:
1860 strcat (buf, ", Version1 EABI");
1865 /* Process flags one bit at a time. */
1866 flag = e_flags & - e_flags;
1871 case EF_ARM_SYMSARESORTED: /* Conflicts with EF_ARM_INTERWORK. */
1872 strcat (buf, ", sorted symbol tables");
1882 case EF_ARM_EABI_VER2:
1883 strcat (buf, ", Version2 EABI");
1888 /* Process flags one bit at a time. */
1889 flag = e_flags & - e_flags;
1894 case EF_ARM_SYMSARESORTED: /* Conflicts with EF_ARM_INTERWORK. */
1895 strcat (buf, ", sorted symbol tables");
1898 case EF_ARM_DYNSYMSUSESEGIDX:
1899 strcat (buf, ", dynamic symbols use segment index");
1902 case EF_ARM_MAPSYMSFIRST:
1903 strcat (buf, ", mapping symbols precede others");
1913 case EF_ARM_EABI_VER3:
1914 strcat (buf, ", Version3 EABI");
1917 case EF_ARM_EABI_VER4:
1918 strcat (buf, ", Version4 EABI");
1923 /* Process flags one bit at a time. */
1924 flag = e_flags & - e_flags;
1930 strcat (buf, ", BE8");
1934 strcat (buf, ", LE8");
1944 case EF_ARM_EABI_UNKNOWN:
1945 strcat (buf, ", GNU EABI");
1950 /* Process flags one bit at a time. */
1951 flag = e_flags & - e_flags;
1956 case EF_ARM_INTERWORK:
1957 strcat (buf, ", interworking enabled");
1960 case EF_ARM_APCS_26:
1961 strcat (buf, ", uses APCS/26");
1964 case EF_ARM_APCS_FLOAT:
1965 strcat (buf, ", uses APCS/float");
1969 strcat (buf, ", position independent");
1973 strcat (buf, ", 8 bit structure alignment");
1976 case EF_ARM_NEW_ABI:
1977 strcat (buf, ", uses new ABI");
1980 case EF_ARM_OLD_ABI:
1981 strcat (buf, ", uses old ABI");
1984 case EF_ARM_SOFT_FLOAT:
1985 strcat (buf, ", software FP");
1988 case EF_ARM_VFP_FLOAT:
1989 strcat (buf, ", VFP");
1992 case EF_ARM_MAVERICK_FLOAT:
1993 strcat (buf, ", Maverick FP");
2004 strcat (buf,", <unknown>");
2008 get_machine_flags (unsigned e_flags, unsigned e_machine)
2010 static char buf[1024];
2022 decode_ARM_machine_flags (e_flags, buf);
2026 switch (e_flags & EF_FRV_CPU_MASK)
2028 case EF_FRV_CPU_GENERIC:
2032 strcat (buf, ", fr???");
2035 case EF_FRV_CPU_FR300:
2036 strcat (buf, ", fr300");
2039 case EF_FRV_CPU_FR400:
2040 strcat (buf, ", fr400");
2042 case EF_FRV_CPU_FR405:
2043 strcat (buf, ", fr405");
2046 case EF_FRV_CPU_FR450:
2047 strcat (buf, ", fr450");
2050 case EF_FRV_CPU_FR500:
2051 strcat (buf, ", fr500");
2053 case EF_FRV_CPU_FR550:
2054 strcat (buf, ", fr550");
2057 case EF_FRV_CPU_SIMPLE:
2058 strcat (buf, ", simple");
2060 case EF_FRV_CPU_TOMCAT:
2061 strcat (buf, ", tomcat");
2067 if (e_flags & EF_CPU32)
2068 strcat (buf, ", cpu32");
2069 if (e_flags & EF_M68000)
2070 strcat (buf, ", m68000");
2074 if (e_flags & EF_PPC_EMB)
2075 strcat (buf, ", emb");
2077 if (e_flags & EF_PPC_RELOCATABLE)
2078 strcat (buf, ", relocatable");
2080 if (e_flags & EF_PPC_RELOCATABLE_LIB)
2081 strcat (buf, ", relocatable-lib");
2085 case EM_CYGNUS_V850:
2086 switch (e_flags & EF_V850_ARCH)
2089 strcat (buf, ", v850e1");
2092 strcat (buf, ", v850e");
2095 strcat (buf, ", v850");
2098 strcat (buf, ", unknown v850 architecture variant");
2104 case EM_CYGNUS_M32R:
2105 if ((e_flags & EF_M32R_ARCH) == E_M32R_ARCH)
2106 strcat (buf, ", m32r");
2111 case EM_MIPS_RS3_LE:
2112 if (e_flags & EF_MIPS_NOREORDER)
2113 strcat (buf, ", noreorder");
2115 if (e_flags & EF_MIPS_PIC)
2116 strcat (buf, ", pic");
2118 if (e_flags & EF_MIPS_CPIC)
2119 strcat (buf, ", cpic");
2121 if (e_flags & EF_MIPS_UCODE)
2122 strcat (buf, ", ugen_reserved");
2124 if (e_flags & EF_MIPS_ABI2)
2125 strcat (buf, ", abi2");
2127 if (e_flags & EF_MIPS_OPTIONS_FIRST)
2128 strcat (buf, ", odk first");
2130 if (e_flags & EF_MIPS_32BITMODE)
2131 strcat (buf, ", 32bitmode");
2133 switch ((e_flags & EF_MIPS_MACH))
2135 case E_MIPS_MACH_3900: strcat (buf, ", 3900"); break;
2136 case E_MIPS_MACH_4010: strcat (buf, ", 4010"); break;
2137 case E_MIPS_MACH_4100: strcat (buf, ", 4100"); break;
2138 case E_MIPS_MACH_4111: strcat (buf, ", 4111"); break;
2139 case E_MIPS_MACH_4120: strcat (buf, ", 4120"); break;
2140 case E_MIPS_MACH_4650: strcat (buf, ", 4650"); break;
2141 case E_MIPS_MACH_5400: strcat (buf, ", 5400"); break;
2142 case E_MIPS_MACH_5500: strcat (buf, ", 5500"); break;
2143 case E_MIPS_MACH_SB1: strcat (buf, ", sb1"); break;
2144 case E_MIPS_MACH_9000: strcat (buf, ", 9000"); break;
2146 /* We simply ignore the field in this case to avoid confusion:
2147 MIPS ELF does not specify EF_MIPS_MACH, it is a GNU
2150 default: strcat (buf, ", unknown CPU"); break;
2153 switch ((e_flags & EF_MIPS_ABI))
2155 case E_MIPS_ABI_O32: strcat (buf, ", o32"); break;
2156 case E_MIPS_ABI_O64: strcat (buf, ", o64"); break;
2157 case E_MIPS_ABI_EABI32: strcat (buf, ", eabi32"); break;
2158 case E_MIPS_ABI_EABI64: strcat (buf, ", eabi64"); break;
2160 /* We simply ignore the field in this case to avoid confusion:
2161 MIPS ELF does not specify EF_MIPS_ABI, it is a GNU extension.
2162 This means it is likely to be an o32 file, but not for
2165 default: strcat (buf, ", unknown ABI"); break;
2168 if (e_flags & EF_MIPS_ARCH_ASE_MDMX)
2169 strcat (buf, ", mdmx");
2171 if (e_flags & EF_MIPS_ARCH_ASE_M16)
2172 strcat (buf, ", mips16");
2174 switch ((e_flags & EF_MIPS_ARCH))
2176 case E_MIPS_ARCH_1: strcat (buf, ", mips1"); break;
2177 case E_MIPS_ARCH_2: strcat (buf, ", mips2"); break;
2178 case E_MIPS_ARCH_3: strcat (buf, ", mips3"); break;
2179 case E_MIPS_ARCH_4: strcat (buf, ", mips4"); break;
2180 case E_MIPS_ARCH_5: strcat (buf, ", mips5"); break;
2181 case E_MIPS_ARCH_32: strcat (buf, ", mips32"); break;
2182 case E_MIPS_ARCH_32R2: strcat (buf, ", mips32r2"); break;
2183 case E_MIPS_ARCH_64: strcat (buf, ", mips64"); break;
2184 case E_MIPS_ARCH_64R2: strcat (buf, ", mips64r2"); break;
2185 default: strcat (buf, ", unknown ISA"); break;
2191 switch ((e_flags & EF_SH_MACH_MASK))
2193 case EF_SH1: strcat (buf, ", sh1"); break;
2194 case EF_SH2: strcat (buf, ", sh2"); break;
2195 case EF_SH3: strcat (buf, ", sh3"); break;
2196 case EF_SH_DSP: strcat (buf, ", sh-dsp"); break;
2197 case EF_SH3_DSP: strcat (buf, ", sh3-dsp"); break;
2198 case EF_SH4AL_DSP: strcat (buf, ", sh4al-dsp"); break;
2199 case EF_SH3E: strcat (buf, ", sh3e"); break;
2200 case EF_SH4: strcat (buf, ", sh4"); break;
2201 case EF_SH5: strcat (buf, ", sh5"); break;
2202 case EF_SH2E: strcat (buf, ", sh2e"); break;
2203 case EF_SH4A: strcat (buf, ", sh4a"); break;
2204 case EF_SH2A: strcat (buf, ", sh2a"); break;
2205 case EF_SH4_NOFPU: strcat (buf, ", sh4-nofpu"); break;
2206 case EF_SH4A_NOFPU: strcat (buf, ", sh4a-nofpu"); break;
2207 case EF_SH2A_NOFPU: strcat (buf, ", sh2a-nofpu"); break;
2208 default: strcat (buf, ", unknown ISA"); break;
2214 if (e_flags & EF_SPARC_32PLUS)
2215 strcat (buf, ", v8+");
2217 if (e_flags & EF_SPARC_SUN_US1)
2218 strcat (buf, ", ultrasparcI");
2220 if (e_flags & EF_SPARC_SUN_US3)
2221 strcat (buf, ", ultrasparcIII");
2223 if (e_flags & EF_SPARC_HAL_R1)
2224 strcat (buf, ", halr1");
2226 if (e_flags & EF_SPARC_LEDATA)
2227 strcat (buf, ", ledata");
2229 if ((e_flags & EF_SPARCV9_MM) == EF_SPARCV9_TSO)
2230 strcat (buf, ", tso");
2232 if ((e_flags & EF_SPARCV9_MM) == EF_SPARCV9_PSO)
2233 strcat (buf, ", pso");
2235 if ((e_flags & EF_SPARCV9_MM) == EF_SPARCV9_RMO)
2236 strcat (buf, ", rmo");
2240 switch (e_flags & EF_PARISC_ARCH)
2242 case EFA_PARISC_1_0:
2243 strcpy (buf, ", PA-RISC 1.0");
2245 case EFA_PARISC_1_1:
2246 strcpy (buf, ", PA-RISC 1.1");
2248 case EFA_PARISC_2_0:
2249 strcpy (buf, ", PA-RISC 2.0");
2254 if (e_flags & EF_PARISC_TRAPNIL)
2255 strcat (buf, ", trapnil");
2256 if (e_flags & EF_PARISC_EXT)
2257 strcat (buf, ", ext");
2258 if (e_flags & EF_PARISC_LSB)
2259 strcat (buf, ", lsb");
2260 if (e_flags & EF_PARISC_WIDE)
2261 strcat (buf, ", wide");
2262 if (e_flags & EF_PARISC_NO_KABP)
2263 strcat (buf, ", no kabp");
2264 if (e_flags & EF_PARISC_LAZYSWAP)
2265 strcat (buf, ", lazyswap");
2270 if ((e_flags & EF_PICOJAVA_NEWCALLS) == EF_PICOJAVA_NEWCALLS)
2271 strcat (buf, ", new calling convention");
2273 if ((e_flags & EF_PICOJAVA_GNUCALLS) == EF_PICOJAVA_GNUCALLS)
2274 strcat (buf, ", gnu calling convention");
2278 if ((e_flags & EF_IA_64_ABI64))
2279 strcat (buf, ", 64-bit");
2281 strcat (buf, ", 32-bit");
2282 if ((e_flags & EF_IA_64_REDUCEDFP))
2283 strcat (buf, ", reduced fp model");
2284 if ((e_flags & EF_IA_64_NOFUNCDESC_CONS_GP))
2285 strcat (buf, ", no function descriptors, constant gp");
2286 else if ((e_flags & EF_IA_64_CONS_GP))
2287 strcat (buf, ", constant gp");
2288 if ((e_flags & EF_IA_64_ABSOLUTE))
2289 strcat (buf, ", absolute");
2293 if ((e_flags & EF_VAX_NONPIC))
2294 strcat (buf, ", non-PIC");
2295 if ((e_flags & EF_VAX_DFLOAT))
2296 strcat (buf, ", D-Float");
2297 if ((e_flags & EF_VAX_GFLOAT))
2298 strcat (buf, ", G-Float");
2307 get_osabi_name (unsigned int osabi)
2309 static char buff[32];
2313 case ELFOSABI_NONE: return "UNIX - System V";
2314 case ELFOSABI_HPUX: return "UNIX - HP-UX";
2315 case ELFOSABI_NETBSD: return "UNIX - NetBSD";
2316 case ELFOSABI_LINUX: return "UNIX - Linux";
2317 case ELFOSABI_HURD: return "GNU/Hurd";
2318 case ELFOSABI_SOLARIS: return "UNIX - Solaris";
2319 case ELFOSABI_AIX: return "UNIX - AIX";
2320 case ELFOSABI_IRIX: return "UNIX - IRIX";
2321 case ELFOSABI_FREEBSD: return "UNIX - FreeBSD";
2322 case ELFOSABI_TRU64: return "UNIX - TRU64";
2323 case ELFOSABI_MODESTO: return "Novell - Modesto";
2324 case ELFOSABI_OPENBSD: return "UNIX - OpenBSD";
2325 case ELFOSABI_OPENVMS: return "VMS - OpenVMS";
2326 case ELFOSABI_NSK: return "HP - Non-Stop Kernel";
2327 case ELFOSABI_AROS: return "Amiga Research OS";
2328 case ELFOSABI_STANDALONE: return _("Standalone App");
2329 case ELFOSABI_ARM: return "ARM";
2331 snprintf (buff, sizeof (buff), _("<unknown: %x>"), osabi);
2337 get_arm_segment_type (unsigned long type)
2351 get_mips_segment_type (unsigned long type)
2355 case PT_MIPS_REGINFO:
2357 case PT_MIPS_RTPROC:
2359 case PT_MIPS_OPTIONS:
2369 get_parisc_segment_type (unsigned long type)
2373 case PT_HP_TLS: return "HP_TLS";
2374 case PT_HP_CORE_NONE: return "HP_CORE_NONE";
2375 case PT_HP_CORE_VERSION: return "HP_CORE_VERSION";
2376 case PT_HP_CORE_KERNEL: return "HP_CORE_KERNEL";
2377 case PT_HP_CORE_COMM: return "HP_CORE_COMM";
2378 case PT_HP_CORE_PROC: return "HP_CORE_PROC";
2379 case PT_HP_CORE_LOADABLE: return "HP_CORE_LOADABLE";
2380 case PT_HP_CORE_STACK: return "HP_CORE_STACK";
2381 case PT_HP_CORE_SHM: return "HP_CORE_SHM";
2382 case PT_HP_CORE_MMF: return "HP_CORE_MMF";
2383 case PT_HP_PARALLEL: return "HP_PARALLEL";
2384 case PT_HP_FASTBIND: return "HP_FASTBIND";
2385 case PT_PARISC_ARCHEXT: return "PARISC_ARCHEXT";
2386 case PT_PARISC_UNWIND: return "PARISC_UNWIND";
2395 get_ia64_segment_type (unsigned long type)
2399 case PT_IA_64_ARCHEXT: return "IA_64_ARCHEXT";
2400 case PT_IA_64_UNWIND: return "IA_64_UNWIND";
2401 case PT_HP_TLS: return "HP_TLS";
2402 case PT_IA_64_HP_OPT_ANOT: return "HP_OPT_ANNOT";
2403 case PT_IA_64_HP_HSL_ANOT: return "HP_HSL_ANNOT";
2404 case PT_IA_64_HP_STACK: return "HP_STACK";
2413 get_segment_type (unsigned long p_type)
2415 static char buff[32];
2419 case PT_NULL: return "NULL";
2420 case PT_LOAD: return "LOAD";
2421 case PT_DYNAMIC: return "DYNAMIC";
2422 case PT_INTERP: return "INTERP";
2423 case PT_NOTE: return "NOTE";
2424 case PT_SHLIB: return "SHLIB";
2425 case PT_PHDR: return "PHDR";
2426 case PT_TLS: return "TLS";
2428 case PT_GNU_EH_FRAME:
2429 return "GNU_EH_FRAME";
2430 case PT_GNU_STACK: return "GNU_STACK";
2431 case PT_GNU_RELRO: return "GNU_RELRO";
2434 if ((p_type >= PT_LOPROC) && (p_type <= PT_HIPROC))
2438 switch (elf_header.e_machine)
2441 result = get_arm_segment_type (p_type);
2444 case EM_MIPS_RS3_LE:
2445 result = get_mips_segment_type (p_type);
2448 result = get_parisc_segment_type (p_type);
2451 result = get_ia64_segment_type (p_type);
2461 sprintf (buff, "LOPROC+%lx", p_type - PT_LOPROC);
2463 else if ((p_type >= PT_LOOS) && (p_type <= PT_HIOS))
2467 switch (elf_header.e_machine)
2470 result = get_parisc_segment_type (p_type);
2473 result = get_ia64_segment_type (p_type);
2483 sprintf (buff, "LOOS+%lx", p_type - PT_LOOS);
2486 snprintf (buff, sizeof (buff), _("<unknown>: %lx"), p_type);
2493 get_mips_section_type_name (unsigned int sh_type)
2497 case SHT_MIPS_LIBLIST: return "MIPS_LIBLIST";
2498 case SHT_MIPS_MSYM: return "MIPS_MSYM";
2499 case SHT_MIPS_CONFLICT: return "MIPS_CONFLICT";
2500 case SHT_MIPS_GPTAB: return "MIPS_GPTAB";
2501 case SHT_MIPS_UCODE: return "MIPS_UCODE";
2502 case SHT_MIPS_DEBUG: return "MIPS_DEBUG";
2503 case SHT_MIPS_REGINFO: return "MIPS_REGINFO";
2504 case SHT_MIPS_PACKAGE: return "MIPS_PACKAGE";
2505 case SHT_MIPS_PACKSYM: return "MIPS_PACKSYM";
2506 case SHT_MIPS_RELD: return "MIPS_RELD";
2507 case SHT_MIPS_IFACE: return "MIPS_IFACE";
2508 case SHT_MIPS_CONTENT: return "MIPS_CONTENT";
2509 case SHT_MIPS_OPTIONS: return "MIPS_OPTIONS";
2510 case SHT_MIPS_SHDR: return "MIPS_SHDR";
2511 case SHT_MIPS_FDESC: return "MIPS_FDESC";
2512 case SHT_MIPS_EXTSYM: return "MIPS_EXTSYM";
2513 case SHT_MIPS_DENSE: return "MIPS_DENSE";
2514 case SHT_MIPS_PDESC: return "MIPS_PDESC";
2515 case SHT_MIPS_LOCSYM: return "MIPS_LOCSYM";
2516 case SHT_MIPS_AUXSYM: return "MIPS_AUXSYM";
2517 case SHT_MIPS_OPTSYM: return "MIPS_OPTSYM";
2518 case SHT_MIPS_LOCSTR: return "MIPS_LOCSTR";
2519 case SHT_MIPS_LINE: return "MIPS_LINE";
2520 case SHT_MIPS_RFDESC: return "MIPS_RFDESC";
2521 case SHT_MIPS_DELTASYM: return "MIPS_DELTASYM";
2522 case SHT_MIPS_DELTAINST: return "MIPS_DELTAINST";
2523 case SHT_MIPS_DELTACLASS: return "MIPS_DELTACLASS";
2524 case SHT_MIPS_DWARF: return "MIPS_DWARF";
2525 case SHT_MIPS_DELTADECL: return "MIPS_DELTADECL";
2526 case SHT_MIPS_SYMBOL_LIB: return "MIPS_SYMBOL_LIB";
2527 case SHT_MIPS_EVENTS: return "MIPS_EVENTS";
2528 case SHT_MIPS_TRANSLATE: return "MIPS_TRANSLATE";
2529 case SHT_MIPS_PIXIE: return "MIPS_PIXIE";
2530 case SHT_MIPS_XLATE: return "MIPS_XLATE";
2531 case SHT_MIPS_XLATE_DEBUG: return "MIPS_XLATE_DEBUG";
2532 case SHT_MIPS_WHIRL: return "MIPS_WHIRL";
2533 case SHT_MIPS_EH_REGION: return "MIPS_EH_REGION";
2534 case SHT_MIPS_XLATE_OLD: return "MIPS_XLATE_OLD";
2535 case SHT_MIPS_PDR_EXCEPTION: return "MIPS_PDR_EXCEPTION";
2543 get_parisc_section_type_name (unsigned int sh_type)
2547 case SHT_PARISC_EXT: return "PARISC_EXT";
2548 case SHT_PARISC_UNWIND: return "PARISC_UNWIND";
2549 case SHT_PARISC_DOC: return "PARISC_DOC";
2557 get_ia64_section_type_name (unsigned int sh_type)
2559 /* If the top 8 bits are 0x78 the next 8 are the os/abi ID. */
2560 if ((sh_type & 0xFF000000) == SHT_IA_64_LOPSREG)
2561 return get_osabi_name ((sh_type & 0x00FF0000) >> 16);
2565 case SHT_IA_64_EXT: return "IA_64_EXT";
2566 case SHT_IA_64_UNWIND: return "IA_64_UNWIND";
2567 case SHT_IA_64_PRIORITY_INIT: return "IA_64_PRIORITY_INIT";
2575 get_x86_64_section_type_name (unsigned int sh_type)
2579 case SHT_X86_64_UNWIND: return "X86_64_UNWIND";
2587 get_arm_section_type_name (unsigned int sh_type)
2600 get_section_type_name (unsigned int sh_type)
2602 static char buff[32];
2606 case SHT_NULL: return "NULL";
2607 case SHT_PROGBITS: return "PROGBITS";
2608 case SHT_SYMTAB: return "SYMTAB";
2609 case SHT_STRTAB: return "STRTAB";
2610 case SHT_RELA: return "RELA";
2611 case SHT_HASH: return "HASH";
2612 case SHT_DYNAMIC: return "DYNAMIC";
2613 case SHT_NOTE: return "NOTE";
2614 case SHT_NOBITS: return "NOBITS";
2615 case SHT_REL: return "REL";
2616 case SHT_SHLIB: return "SHLIB";
2617 case SHT_DYNSYM: return "DYNSYM";
2618 case SHT_INIT_ARRAY: return "INIT_ARRAY";
2619 case SHT_FINI_ARRAY: return "FINI_ARRAY";
2620 case SHT_PREINIT_ARRAY: return "PREINIT_ARRAY";
2621 case SHT_GROUP: return "GROUP";
2622 case SHT_SYMTAB_SHNDX: return "SYMTAB SECTION INDICIES";
2623 case SHT_GNU_verdef: return "VERDEF";
2624 case SHT_GNU_verneed: return "VERNEED";
2625 case SHT_GNU_versym: return "VERSYM";
2626 case 0x6ffffff0: return "VERSYM";
2627 case 0x6ffffffc: return "VERDEF";
2628 case 0x7ffffffd: return "AUXILIARY";
2629 case 0x7fffffff: return "FILTER";
2630 case SHT_GNU_LIBLIST: return "GNU_LIBLIST";
2633 if ((sh_type >= SHT_LOPROC) && (sh_type <= SHT_HIPROC))
2637 switch (elf_header.e_machine)
2640 case EM_MIPS_RS3_LE:
2641 result = get_mips_section_type_name (sh_type);
2644 result = get_parisc_section_type_name (sh_type);
2647 result = get_ia64_section_type_name (sh_type);
2650 result = get_x86_64_section_type_name (sh_type);
2653 result = get_arm_section_type_name (sh_type);
2663 sprintf (buff, "LOPROC+%x", sh_type - SHT_LOPROC);
2665 else if ((sh_type >= SHT_LOOS) && (sh_type <= SHT_HIOS))
2666 sprintf (buff, "LOOS+%x", sh_type - SHT_LOOS);
2667 else if ((sh_type >= SHT_LOUSER) && (sh_type <= SHT_HIUSER))
2668 sprintf (buff, "LOUSER+%x", sh_type - SHT_LOUSER);
2670 snprintf (buff, sizeof (buff), _("<unknown>: %x"), sh_type);
2676 #define OPTION_DEBUG_DUMP 512
2678 static struct option options[] =
2680 {"all", no_argument, 0, 'a'},
2681 {"file-header", no_argument, 0, 'h'},
2682 {"program-headers", no_argument, 0, 'l'},
2683 {"headers", no_argument, 0, 'e'},
2684 {"histogram", no_argument, 0, 'I'},
2685 {"segments", no_argument, 0, 'l'},
2686 {"sections", no_argument, 0, 'S'},
2687 {"section-headers", no_argument, 0, 'S'},
2688 {"section-groups", no_argument, 0, 'g'},
2689 {"full-section-name",no_argument, 0, 'N'},
2690 {"symbols", no_argument, 0, 's'},
2691 {"syms", no_argument, 0, 's'},
2692 {"relocs", no_argument, 0, 'r'},
2693 {"notes", no_argument, 0, 'n'},
2694 {"dynamic", no_argument, 0, 'd'},
2695 {"arch-specific", no_argument, 0, 'A'},
2696 {"version-info", no_argument, 0, 'V'},
2697 {"use-dynamic", no_argument, 0, 'D'},
2698 {"hex-dump", required_argument, 0, 'x'},
2699 {"debug-dump", optional_argument, 0, OPTION_DEBUG_DUMP},
2700 {"unwind", no_argument, 0, 'u'},
2701 #ifdef SUPPORT_DISASSEMBLY
2702 {"instruction-dump", required_argument, 0, 'i'},
2705 {"version", no_argument, 0, 'v'},
2706 {"wide", no_argument, 0, 'W'},
2707 {"help", no_argument, 0, 'H'},
2708 {0, no_argument, 0, 0}
2714 fprintf (stdout, _("Usage: readelf <option(s)> elf-file(s)\n"));
2715 fprintf (stdout, _(" Display information about the contents of ELF format files\n"));
2716 fprintf (stdout, _(" Options are:\n\
2717 -a --all Equivalent to: -h -l -S -s -r -d -V -A -I\n\
2718 -h --file-header Display the ELF file header\n\
2719 -l --program-headers Display the program headers\n\
2720 --segments An alias for --program-headers\n\
2721 -S --section-headers Display the sections' header\n\
2722 --sections An alias for --section-headers\n\
2723 -g --section-groups Display the section groups\n\
2724 -N --full-section-name\n\
2725 Display the full section name\n\
2726 -e --headers Equivalent to: -h -l -S\n\
2727 -s --syms Display the symbol table\n\
2728 --symbols An alias for --syms\n\
2729 -n --notes Display the core notes (if present)\n\
2730 -r --relocs Display the relocations (if present)\n\
2731 -u --unwind Display the unwind info (if present)\n\
2732 -d --dynamic Display the dynamic section (if present)\n\
2733 -V --version-info Display the version sections (if present)\n\
2734 -A --arch-specific Display architecture specific information (if any).\n\
2735 -D --use-dynamic Use the dynamic section info when displaying symbols\n\
2736 -x --hex-dump=<number> Dump the contents of section <number>\n\
2737 -w[liaprmfFsoR] or\n\
2738 --debug-dump[=line,=info,=abbrev,=pubnames,=aranges,=macro,=frames,=str,=loc,=Ranges]\n\
2739 Display the contents of DWARF2 debug sections\n"));
2740 #ifdef SUPPORT_DISASSEMBLY
2741 fprintf (stdout, _("\
2742 -i --instruction-dump=<number>\n\
2743 Disassemble the contents of section <number>\n"));
2745 fprintf (stdout, _("\
2746 -I --histogram Display histogram of bucket list lengths\n\
2747 -W --wide Allow output width to exceed 80 characters\n\
2748 -H --help Display this information\n\
2749 -v --version Display the version number of readelf\n"));
2750 fprintf (stdout, _("Report bugs to %s\n"), REPORT_BUGS_TO);
2755 /* Record the fact that the user wants the contents of section number
2756 SECTION to be displayed using the method(s) encoded as flags bits
2757 in TYPE. Note, TYPE can be zero if we are creating the array for
2761 request_dump (unsigned int section, int type)
2763 if (section >= num_dump_sects)
2765 char *new_dump_sects;
2767 new_dump_sects = calloc (section + 1, 1);
2769 if (new_dump_sects == NULL)
2770 error (_("Out of memory allocating dump request table."));
2773 /* Copy current flag settings. */
2774 memcpy (new_dump_sects, dump_sects, num_dump_sects);
2778 dump_sects = new_dump_sects;
2779 num_dump_sects = section + 1;
2784 dump_sects[section] |= type;
2790 parse_args (int argc, char **argv)
2797 while ((c = getopt_long
2798 (argc, argv, "ersuahnldSDAINgw::x:i:vVWH", options, NULL)) != EOF)
2819 do_section_groups++;
2827 do_section_groups++;
2830 do_full_section_name++;
2872 section = strtoul (optarg, & cp, 0);
2873 if (! *cp && section >= 0)
2875 request_dump (section, HEX_DUMP);
2885 unsigned int index = 0;
2889 while (optarg[index])
2890 switch (optarg[index++])
2899 do_debug_abbrevs = 1;
2909 do_debug_pubnames = 1;
2913 do_debug_aranges = 1;
2917 do_debug_ranges = 1;
2921 do_debug_frames_interp = 1;
2923 do_debug_frames = 1;
2928 do_debug_macinfo = 1;
2942 warn (_("Unrecognized debug option '%s'\n"), optarg);
2947 case OPTION_DEBUG_DUMP:
2955 const char * option;
2958 debug_dump_long_opts;
2960 debug_dump_long_opts opts_table [] =
2962 /* Please keep this table alpha- sorted. */
2963 { "Ranges", & do_debug_ranges },
2964 { "abbrev", & do_debug_abbrevs },
2965 { "aranges", & do_debug_aranges },
2966 { "frames", & do_debug_frames },
2967 { "frames-interp", & do_debug_frames_interp },
2968 { "info", & do_debug_info },
2969 { "line", & do_debug_lines },
2970 { "loc", & do_debug_loc },
2971 { "macro", & do_debug_macinfo },
2972 { "pubnames", & do_debug_pubnames },
2973 /* This entry is for compatability
2974 with earlier versions of readelf. */
2975 { "ranges", & do_debug_aranges },
2976 { "str", & do_debug_str },
2987 debug_dump_long_opts * entry;
2989 for (entry = opts_table; entry->option; entry++)
2991 size_t len = strlen (entry->option);
2993 if (strneq (p, entry->option, len)
2994 && (p[len] == ',' || p[len] == '\0'))
2996 * entry->variable = 1;
2998 /* The --debug-dump=frames-interp option also
2999 enables the --debug-dump=frames option. */
3000 if (do_debug_frames_interp)
3001 do_debug_frames = 1;
3008 if (entry->option == NULL)
3010 warn (_("Unrecognized debug option '%s'\n"), p);
3011 p = strchr (p, ',');
3021 #ifdef SUPPORT_DISASSEMBLY
3024 section = strtoul (optarg, & cp, 0);
3025 if (! *cp && section >= 0)
3027 request_dump (section, DISASS_DUMP);
3033 print_version (program_name);
3043 /* xgettext:c-format */
3044 error (_("Invalid option '-%c'\n"), c);
3051 if (!do_dynamic && !do_syms && !do_reloc && !do_unwind && !do_sections
3052 && !do_segments && !do_header && !do_dump && !do_version
3053 && !do_histogram && !do_debugging && !do_arch && !do_notes
3054 && !do_section_groups)
3058 warn (_("Nothing to do.\n"));
3064 get_elf_class (unsigned int elf_class)
3066 static char buff[32];
3070 case ELFCLASSNONE: return _("none");
3071 case ELFCLASS32: return "ELF32";
3072 case ELFCLASS64: return "ELF64";
3074 snprintf (buff, sizeof (buff), _("<unknown: %x>"), elf_class);
3080 get_data_encoding (unsigned int encoding)
3082 static char buff[32];
3086 case ELFDATANONE: return _("none");
3087 case ELFDATA2LSB: return _("2's complement, little endian");
3088 case ELFDATA2MSB: return _("2's complement, big endian");
3090 snprintf (buff, sizeof (buff), _("<unknown: %x>"), encoding);
3095 /* Decode the data held in 'elf_header'. */
3098 process_file_header (void)
3100 if ( elf_header.e_ident[EI_MAG0] != ELFMAG0
3101 || elf_header.e_ident[EI_MAG1] != ELFMAG1
3102 || elf_header.e_ident[EI_MAG2] != ELFMAG2
3103 || elf_header.e_ident[EI_MAG3] != ELFMAG3)
3106 (_("Not an ELF file - it has the wrong magic bytes at the start\n"));
3114 printf (_("ELF Header:\n"));
3115 printf (_(" Magic: "));
3116 for (i = 0; i < EI_NIDENT; i++)
3117 printf ("%2.2x ", elf_header.e_ident[i]);
3119 printf (_(" Class: %s\n"),
3120 get_elf_class (elf_header.e_ident[EI_CLASS]));
3121 printf (_(" Data: %s\n"),
3122 get_data_encoding (elf_header.e_ident[EI_DATA]));
3123 printf (_(" Version: %d %s\n"),
3124 elf_header.e_ident[EI_VERSION],
3125 (elf_header.e_ident[EI_VERSION] == EV_CURRENT
3127 : (elf_header.e_ident[EI_VERSION] != EV_NONE
3130 printf (_(" OS/ABI: %s\n"),
3131 get_osabi_name (elf_header.e_ident[EI_OSABI]));
3132 printf (_(" ABI Version: %d\n"),
3133 elf_header.e_ident[EI_ABIVERSION]);
3134 printf (_(" Type: %s\n"),
3135 get_file_type (elf_header.e_type));
3136 printf (_(" Machine: %s\n"),
3137 get_machine_name (elf_header.e_machine));
3138 printf (_(" Version: 0x%lx\n"),
3139 (unsigned long) elf_header.e_version);
3141 printf (_(" Entry point address: "));
3142 print_vma ((bfd_vma) elf_header.e_entry, PREFIX_HEX);
3143 printf (_("\n Start of program headers: "));
3144 print_vma ((bfd_vma) elf_header.e_phoff, DEC);
3145 printf (_(" (bytes into file)\n Start of section headers: "));
3146 print_vma ((bfd_vma) elf_header.e_shoff, DEC);
3147 printf (_(" (bytes into file)\n"));
3149 printf (_(" Flags: 0x%lx%s\n"),
3150 (unsigned long) elf_header.e_flags,
3151 get_machine_flags (elf_header.e_flags, elf_header.e_machine));
3152 printf (_(" Size of this header: %ld (bytes)\n"),
3153 (long) elf_header.e_ehsize);
3154 printf (_(" Size of program headers: %ld (bytes)\n"),
3155 (long) elf_header.e_phentsize);
3156 printf (_(" Number of program headers: %ld\n"),
3157 (long) elf_header.e_phnum);
3158 printf (_(" Size of section headers: %ld (bytes)\n"),
3159 (long) elf_header.e_shentsize);
3160 printf (_(" Number of section headers: %ld"),
3161 (long) elf_header.e_shnum);
3162 if (section_headers != NULL && elf_header.e_shnum == 0)
3163 printf (" (%ld)", (long) section_headers[0].sh_size);
3164 putc ('\n', stdout);
3165 printf (_(" Section header string table index: %ld"),
3166 (long) elf_header.e_shstrndx);
3167 if (section_headers != NULL && elf_header.e_shstrndx == SHN_XINDEX)
3168 printf (" (%ld)", (long) section_headers[0].sh_link);
3169 putc ('\n', stdout);
3172 if (section_headers != NULL)
3174 if (elf_header.e_shnum == 0)
3175 elf_header.e_shnum = section_headers[0].sh_size;
3176 if (elf_header.e_shstrndx == SHN_XINDEX)
3177 elf_header.e_shstrndx = section_headers[0].sh_link;
3178 free (section_headers);
3179 section_headers = NULL;
3187 get_32bit_program_headers (FILE *file, Elf_Internal_Phdr *program_headers)
3189 Elf32_External_Phdr *phdrs;
3190 Elf32_External_Phdr *external;
3191 Elf_Internal_Phdr *internal;
3194 phdrs = get_data (NULL, file, elf_header.e_phoff,
3195 elf_header.e_phentsize, elf_header.e_phnum,
3196 _("program headers"));
3200 for (i = 0, internal = program_headers, external = phdrs;
3201 i < elf_header.e_phnum;
3202 i++, internal++, external++)
3204 internal->p_type = BYTE_GET (external->p_type);
3205 internal->p_offset = BYTE_GET (external->p_offset);
3206 internal->p_vaddr = BYTE_GET (external->p_vaddr);
3207 internal->p_paddr = BYTE_GET (external->p_paddr);
3208 internal->p_filesz = BYTE_GET (external->p_filesz);
3209 internal->p_memsz = BYTE_GET (external->p_memsz);
3210 internal->p_flags = BYTE_GET (external->p_flags);
3211 internal->p_align = BYTE_GET (external->p_align);
3220 get_64bit_program_headers (FILE *file, Elf_Internal_Phdr *program_headers)
3222 Elf64_External_Phdr *phdrs;
3223 Elf64_External_Phdr *external;
3224 Elf_Internal_Phdr *internal;
3227 phdrs = get_data (NULL, file, elf_header.e_phoff,
3228 elf_header.e_phentsize, elf_header.e_phnum,
3229 _("program headers"));
3233 for (i = 0, internal = program_headers, external = phdrs;
3234 i < elf_header.e_phnum;
3235 i++, internal++, external++)
3237 internal->p_type = BYTE_GET (external->p_type);
3238 internal->p_flags = BYTE_GET (external->p_flags);
3239 internal->p_offset = BYTE_GET (external->p_offset);
3240 internal->p_vaddr = BYTE_GET (external->p_vaddr);
3241 internal->p_paddr = BYTE_GET (external->p_paddr);
3242 internal->p_filesz = BYTE_GET (external->p_filesz);
3243 internal->p_memsz = BYTE_GET (external->p_memsz);
3244 internal->p_align = BYTE_GET (external->p_align);
3252 /* Returns 1 if the program headers were read into `program_headers'. */
3255 get_program_headers (FILE *file)
3257 Elf_Internal_Phdr *phdrs;
3259 /* Check cache of prior read. */
3260 if (program_headers != NULL)
3263 phdrs = cmalloc (elf_header.e_phnum, sizeof (Elf_Internal_Phdr));
3267 error (_("Out of memory\n"));
3272 ? get_32bit_program_headers (file, phdrs)
3273 : get_64bit_program_headers (file, phdrs))
3275 program_headers = phdrs;
3283 /* Returns 1 if the program headers were loaded. */
3286 process_program_headers (FILE *file)
3288 Elf_Internal_Phdr *segment;
3291 if (elf_header.e_phnum == 0)
3294 printf (_("\nThere are no program headers in this file.\n"));
3298 if (do_segments && !do_header)
3300 printf (_("\nElf file type is %s\n"), get_file_type (elf_header.e_type));
3301 printf (_("Entry point "));
3302 print_vma ((bfd_vma) elf_header.e_entry, PREFIX_HEX);
3303 printf (_("\nThere are %d program headers, starting at offset "),
3304 elf_header.e_phnum);
3305 print_vma ((bfd_vma) elf_header.e_phoff, DEC);
3309 if (! get_program_headers (file))
3314 if (elf_header.e_phnum > 1)
3315 printf (_("\nProgram Headers:\n"));
3317 printf (_("\nProgram Headers:\n"));
3321 (_(" Type Offset VirtAddr PhysAddr FileSiz MemSiz Flg Align\n"));
3324 (_(" Type Offset VirtAddr PhysAddr FileSiz MemSiz Flg Align\n"));
3328 (_(" Type Offset VirtAddr PhysAddr\n"));
3330 (_(" FileSiz MemSiz Flags Align\n"));
3337 for (i = 0, segment = program_headers;
3338 i < elf_header.e_phnum;
3343 printf (" %-14.14s ", get_segment_type (segment->p_type));
3347 printf ("0x%6.6lx ", (unsigned long) segment->p_offset);
3348 printf ("0x%8.8lx ", (unsigned long) segment->p_vaddr);
3349 printf ("0x%8.8lx ", (unsigned long) segment->p_paddr);
3350 printf ("0x%5.5lx ", (unsigned long) segment->p_filesz);
3351 printf ("0x%5.5lx ", (unsigned long) segment->p_memsz);
3353 (segment->p_flags & PF_R ? 'R' : ' '),
3354 (segment->p_flags & PF_W ? 'W' : ' '),
3355 (segment->p_flags & PF_X ? 'E' : ' '));
3356 printf ("%#lx", (unsigned long) segment->p_align);
3360 if ((unsigned long) segment->p_offset == segment->p_offset)
3361 printf ("0x%6.6lx ", (unsigned long) segment->p_offset);
3364 print_vma (segment->p_offset, FULL_HEX);
3368 print_vma (segment->p_vaddr, FULL_HEX);
3370 print_vma (segment->p_paddr, FULL_HEX);
3373 if ((unsigned long) segment->p_filesz == segment->p_filesz)
3374 printf ("0x%6.6lx ", (unsigned long) segment->p_filesz);
3377 print_vma (segment->p_filesz, FULL_HEX);
3381 if ((unsigned long) segment->p_memsz == segment->p_memsz)
3382 printf ("0x%6.6lx", (unsigned long) segment->p_memsz);
3385 print_vma (segment->p_offset, FULL_HEX);
3389 (segment->p_flags & PF_R ? 'R' : ' '),
3390 (segment->p_flags & PF_W ? 'W' : ' '),
3391 (segment->p_flags & PF_X ? 'E' : ' '));
3393 if ((unsigned long) segment->p_align == segment->p_align)
3394 printf ("%#lx", (unsigned long) segment->p_align);
3397 print_vma (segment->p_align, PREFIX_HEX);
3402 print_vma (segment->p_offset, FULL_HEX);
3404 print_vma (segment->p_vaddr, FULL_HEX);
3406 print_vma (segment->p_paddr, FULL_HEX);
3408 print_vma (segment->p_filesz, FULL_HEX);
3410 print_vma (segment->p_memsz, FULL_HEX);
3412 (segment->p_flags & PF_R ? 'R' : ' '),
3413 (segment->p_flags & PF_W ? 'W' : ' '),
3414 (segment->p_flags & PF_X ? 'E' : ' '));
3415 print_vma (segment->p_align, HEX);
3419 switch (segment->p_type)
3423 error (_("more than one dynamic segment\n"));
3425 /* Try to locate the .dynamic section. If there is
3426 a section header table, we can easily locate it. */
3427 if (section_headers != NULL)
3429 Elf_Internal_Shdr *sec;
3431 sec = find_section (".dynamic");
3432 if (sec == NULL || sec->sh_size == 0)
3434 error (_("no .dynamic section in the dynamic segment"));
3438 dynamic_addr = sec->sh_offset;
3439 dynamic_size = sec->sh_size;
3441 if (dynamic_addr < segment->p_offset
3442 || dynamic_addr > segment->p_offset + segment->p_filesz)
3443 warn (_("the .dynamic section is not contained within the dynamic segment"));
3444 else if (dynamic_addr > segment->p_offset)
3445 warn (_("the .dynamic section is not the first section in the dynamic segment."));
3449 /* Otherwise, we can only assume that the .dynamic
3450 section is the first section in the DYNAMIC segment. */
3451 dynamic_addr = segment->p_offset;
3452 dynamic_size = segment->p_filesz;
3457 if (fseek (file, archive_file_offset + (long) segment->p_offset,
3459 error (_("Unable to find program interpreter name\n"));
3462 program_interpreter[0] = 0;
3463 fscanf (file, "%63s", program_interpreter);
3466 printf (_("\n [Requesting program interpreter: %s]"),
3467 program_interpreter);
3473 putc ('\n', stdout);
3476 if (do_segments && section_headers != NULL && string_table != NULL)
3478 printf (_("\n Section to Segment mapping:\n"));
3479 printf (_(" Segment Sections...\n"));
3481 for (i = 0; i < elf_header.e_phnum; i++)
3484 Elf_Internal_Shdr *section;
3486 segment = program_headers + i;
3487 section = section_headers;
3489 printf (" %2.2d ", i);
3491 for (j = 1; j < elf_header.e_shnum; j++, section++)
3493 if (section->sh_size > 0
3494 /* Compare allocated sections by VMA, unallocated
3495 sections by file offset. */
3496 && (section->sh_flags & SHF_ALLOC
3497 ? (section->sh_addr >= segment->p_vaddr
3498 && section->sh_addr + section->sh_size
3499 <= segment->p_vaddr + segment->p_memsz)
3500 : ((bfd_vma) section->sh_offset >= segment->p_offset
3501 && (section->sh_offset + section->sh_size
3502 <= segment->p_offset + segment->p_filesz)))
3503 /* .tbss is special. It doesn't contribute memory space
3504 to normal segments. */
3505 && (!((section->sh_flags & SHF_TLS) != 0
3506 && section->sh_type == SHT_NOBITS)
3507 || segment->p_type == PT_TLS))
3508 printf ("%s ", SECTION_NAME (section));
3519 /* Find the file offset corresponding to VMA by using the program headers. */
3522 offset_from_vma (FILE *file, bfd_vma vma, bfd_size_type size)
3524 Elf_Internal_Phdr *seg;
3526 if (! get_program_headers (file))
3528 warn (_("Cannot interpret virtual addresses without program headers.\n"));
3532 for (seg = program_headers;
3533 seg < program_headers + elf_header.e_phnum;
3536 if (seg->p_type != PT_LOAD)
3539 if (vma >= (seg->p_vaddr & -seg->p_align)
3540 && vma + size <= seg->p_vaddr + seg->p_filesz)
3541 return vma - seg->p_vaddr + seg->p_offset;
3544 warn (_("Virtual address 0x%lx not located in any PT_LOAD segment.\n"),
3551 get_32bit_section_headers (FILE *file, unsigned int num)
3553 Elf32_External_Shdr *shdrs;
3554 Elf_Internal_Shdr *internal;
3557 shdrs = get_data (NULL, file, elf_header.e_shoff,
3558 elf_header.e_shentsize, num, _("section headers"));
3562 section_headers = cmalloc (num, sizeof (Elf_Internal_Shdr));
3564 if (section_headers == NULL)
3566 error (_("Out of memory\n"));
3570 for (i = 0, internal = section_headers;
3574 internal->sh_name = BYTE_GET (shdrs[i].sh_name);
3575 internal->sh_type = BYTE_GET (shdrs[i].sh_type);
3576 internal->sh_flags = BYTE_GET (shdrs[i].sh_flags);
3577 internal->sh_addr = BYTE_GET (shdrs[i].sh_addr);
3578 internal->sh_offset = BYTE_GET (shdrs[i].sh_offset);
3579 internal->sh_size = BYTE_GET (shdrs[i].sh_size);
3580 internal->sh_link = BYTE_GET (shdrs[i].sh_link);
3581 internal->sh_info = BYTE_GET (shdrs[i].sh_info);
3582 internal->sh_addralign = BYTE_GET (shdrs[i].sh_addralign);
3583 internal->sh_entsize = BYTE_GET (shdrs[i].sh_entsize);
3592 get_64bit_section_headers (FILE *file, unsigned int num)
3594 Elf64_External_Shdr *shdrs;
3595 Elf_Internal_Shdr *internal;
3598 shdrs = get_data (NULL, file, elf_header.e_shoff,
3599 elf_header.e_shentsize, num, _("section headers"));
3603 section_headers = cmalloc (num, sizeof (Elf_Internal_Shdr));
3605 if (section_headers == NULL)
3607 error (_("Out of memory\n"));
3611 for (i = 0, internal = section_headers;
3615 internal->sh_name = BYTE_GET (shdrs[i].sh_name);
3616 internal->sh_type = BYTE_GET (shdrs[i].sh_type);
3617 internal->sh_flags = BYTE_GET (shdrs[i].sh_flags);
3618 internal->sh_addr = BYTE_GET (shdrs[i].sh_addr);
3619 internal->sh_size = BYTE_GET (shdrs[i].sh_size);
3620 internal->sh_entsize = BYTE_GET (shdrs[i].sh_entsize);
3621 internal->sh_link = BYTE_GET (shdrs[i].sh_link);
3622 internal->sh_info = BYTE_GET (shdrs[i].sh_info);
3623 internal->sh_offset = BYTE_GET (shdrs[i].sh_offset);
3624 internal->sh_addralign = BYTE_GET (shdrs[i].sh_addralign);
3632 static Elf_Internal_Sym *
3633 get_32bit_elf_symbols (FILE *file, Elf_Internal_Shdr *section)
3635 unsigned long number;
3636 Elf32_External_Sym *esyms;
3637 Elf_External_Sym_Shndx *shndx;
3638 Elf_Internal_Sym *isyms;
3639 Elf_Internal_Sym *psym;
3642 esyms = get_data (NULL, file, section->sh_offset, 1, section->sh_size,
3648 if (symtab_shndx_hdr != NULL
3649 && (symtab_shndx_hdr->sh_link
3650 == (unsigned long) SECTION_HEADER_NUM (section - section_headers)))
3652 shndx = get_data (NULL, file, symtab_shndx_hdr->sh_offset,
3653 1, symtab_shndx_hdr->sh_size, _("symtab shndx"));
3661 number = section->sh_size / section->sh_entsize;
3662 isyms = cmalloc (number, sizeof (Elf_Internal_Sym));
3666 error (_("Out of memory\n"));
3673 for (j = 0, psym = isyms;
3677 psym->st_name = BYTE_GET (esyms[j].st_name);
3678 psym->st_value = BYTE_GET (esyms[j].st_value);
3679 psym->st_size = BYTE_GET (esyms[j].st_size);
3680 psym->st_shndx = BYTE_GET (esyms[j].st_shndx);
3681 if (psym->st_shndx == SHN_XINDEX && shndx != NULL)
3683 = byte_get ((unsigned char *) &shndx[j], sizeof (shndx[j]));
3684 psym->st_info = BYTE_GET (esyms[j].st_info);
3685 psym->st_other = BYTE_GET (esyms[j].st_other);
3695 static Elf_Internal_Sym *
3696 get_64bit_elf_symbols (FILE *file, Elf_Internal_Shdr *section)
3698 unsigned long number;
3699 Elf64_External_Sym *esyms;
3700 Elf_External_Sym_Shndx *shndx;
3701 Elf_Internal_Sym *isyms;
3702 Elf_Internal_Sym *psym;
3705 esyms = get_data (NULL, file, section->sh_offset, 1, section->sh_size,
3711 if (symtab_shndx_hdr != NULL
3712 && (symtab_shndx_hdr->sh_link
3713 == (unsigned long) SECTION_HEADER_NUM (section - section_headers)))
3715 shndx = get_data (NULL, file, symtab_shndx_hdr->sh_offset,
3716 1, symtab_shndx_hdr->sh_size, _("symtab shndx"));
3724 number = section->sh_size / section->sh_entsize;
3725 isyms = cmalloc (number, sizeof (Elf_Internal_Sym));
3729 error (_("Out of memory\n"));
3736 for (j = 0, psym = isyms;
3740 psym->st_name = BYTE_GET (esyms[j].st_name);
3741 psym->st_info = BYTE_GET (esyms[j].st_info);
3742 psym->st_other = BYTE_GET (esyms[j].st_other);
3743 psym->st_shndx = BYTE_GET (esyms[j].st_shndx);
3744 if (psym->st_shndx == SHN_XINDEX && shndx != NULL)
3746 = byte_get ((unsigned char *) &shndx[j], sizeof (shndx[j]));
3747 psym->st_value = BYTE_GET (esyms[j].st_value);
3748 psym->st_size = BYTE_GET (esyms[j].st_size);
3759 get_elf_section_flags (bfd_vma sh_flags)
3761 static char buff[33];
3768 flag = sh_flags & - sh_flags;
3773 case SHF_WRITE: *p = 'W'; break;
3774 case SHF_ALLOC: *p = 'A'; break;
3775 case SHF_EXECINSTR: *p = 'X'; break;
3776 case SHF_MERGE: *p = 'M'; break;
3777 case SHF_STRINGS: *p = 'S'; break;
3778 case SHF_INFO_LINK: *p = 'I'; break;
3779 case SHF_LINK_ORDER: *p = 'L'; break;
3780 case SHF_OS_NONCONFORMING: *p = 'O'; break;
3781 case SHF_GROUP: *p = 'G'; break;
3782 case SHF_TLS: *p = 'T'; break;
3785 if (flag & SHF_MASKOS)
3788 sh_flags &= ~ SHF_MASKOS;
3790 else if (flag & SHF_MASKPROC)
3793 sh_flags &= ~ SHF_MASKPROC;
3807 process_section_headers (FILE *file)
3809 Elf_Internal_Shdr *section;
3812 section_headers = NULL;
3814 if (elf_header.e_shnum == 0)
3817 printf (_("\nThere are no sections in this file.\n"));
3822 if (do_sections && !do_header)
3823 printf (_("There are %d section headers, starting at offset 0x%lx:\n"),
3824 elf_header.e_shnum, (unsigned long) elf_header.e_shoff);
3828 if (! get_32bit_section_headers (file, elf_header.e_shnum))
3831 else if (! get_64bit_section_headers (file, elf_header.e_shnum))
3834 /* Read in the string table, so that we have names to display. */
3835 if (SECTION_HEADER_INDEX (elf_header.e_shstrndx) < elf_header.e_shnum)
3837 section = SECTION_HEADER (elf_header.e_shstrndx);
3839 if (section->sh_size != 0)
3841 string_table = get_data (NULL, file, section->sh_offset,
3842 1, section->sh_size, _("string table"));
3844 string_table_length = string_table != NULL ? section->sh_size : 0;
3848 /* Scan the sections for the dynamic symbol table
3849 and dynamic string table and debug sections. */
3850 dynamic_symbols = NULL;
3851 dynamic_strings = NULL;
3852 dynamic_syminfo = NULL;
3853 symtab_shndx_hdr = NULL;
3855 eh_addr_size = is_32bit_elf ? 4 : 8;
3856 switch (elf_header.e_machine)
3859 case EM_MIPS_RS3_LE:
3860 /* The 64-bit MIPS EABI uses a combination of 32-bit ELF and 64-bit
3861 FDE addresses. However, the ABI also has a semi-official ILP32
3862 variant for which the normal FDE address size rules apply.
3864 GCC 4.0 marks EABI64 objects with a dummy .gcc_compiled_longXX
3865 section, where XX is the size of longs in bits. Unfortunately,
3866 earlier compilers provided no way of distinguishing ILP32 objects
3867 from LP64 objects, so if there's any doubt, we should assume that
3868 the official LP64 form is being used. */
3869 if ((elf_header.e_flags & EF_MIPS_ABI) == E_MIPS_ABI_EABI64
3870 && find_section (".gcc_compiled_long32") == NULL)
3875 #define CHECK_ENTSIZE_VALUES(section, i, size32, size64) \
3878 size_t expected_entsize \
3879 = is_32bit_elf ? size32 : size64; \
3880 if (section->sh_entsize != expected_entsize) \
3881 error (_("Section %d has invalid sh_entsize %lx (expected %lx)\n"), \
3882 i, (unsigned long int) section->sh_entsize, \
3883 (unsigned long int) expected_entsize); \
3884 section->sh_entsize = expected_entsize; \
3887 #define CHECK_ENTSIZE(section, i, type) \
3888 CHECK_ENTSIZE_VALUES (section, i, sizeof (Elf32_External_##type), \
3889 sizeof (Elf64_External_##type))
3891 for (i = 0, section = section_headers;
3892 i < elf_header.e_shnum;
3895 char *name = SECTION_NAME (section);
3897 if (section->sh_type == SHT_DYNSYM)
3899 if (dynamic_symbols != NULL)
3901 error (_("File contains multiple dynamic symbol tables\n"));
3905 CHECK_ENTSIZE (section, i, Sym);
3906 num_dynamic_syms = section->sh_size / section->sh_entsize;
3907 dynamic_symbols = GET_ELF_SYMBOLS (file, section);
3909 else if (section->sh_type == SHT_STRTAB
3910 && streq (name, ".dynstr"))
3912 if (dynamic_strings != NULL)
3914 error (_("File contains multiple dynamic string tables\n"));
3918 dynamic_strings = get_data (NULL, file, section->sh_offset,
3919 1, section->sh_size, _("dynamic strings"));
3920 dynamic_strings_length = section->sh_size;
3922 else if (section->sh_type == SHT_SYMTAB_SHNDX)
3924 if (symtab_shndx_hdr != NULL)
3926 error (_("File contains multiple symtab shndx tables\n"));
3929 symtab_shndx_hdr = section;
3931 else if (section->sh_type == SHT_SYMTAB)
3932 CHECK_ENTSIZE (section, i, Sym);
3933 else if (section->sh_type == SHT_GROUP)
3934 CHECK_ENTSIZE_VALUES (section, i, GRP_ENTRY_SIZE, GRP_ENTRY_SIZE);
3935 else if (section->sh_type == SHT_REL)
3936 CHECK_ENTSIZE (section, i, Rel);
3937 else if (section->sh_type == SHT_RELA)
3938 CHECK_ENTSIZE (section, i, Rela);
3939 else if ((do_debugging || do_debug_info || do_debug_abbrevs
3940 || do_debug_lines || do_debug_pubnames || do_debug_aranges
3941 || do_debug_frames || do_debug_macinfo || do_debug_str
3942 || do_debug_loc || do_debug_ranges)
3943 && strneq (name, ".debug_", 7))
3948 || (do_debug_info && streq (name, "info"))
3949 || (do_debug_abbrevs && streq (name, "abbrev"))
3950 || (do_debug_lines && streq (name, "line"))
3951 || (do_debug_pubnames && streq (name, "pubnames"))
3952 || (do_debug_aranges && streq (name, "aranges"))
3953 || (do_debug_ranges && streq (name, "ranges"))
3954 || (do_debug_frames && streq (name, "frame"))
3955 || (do_debug_macinfo && streq (name, "macinfo"))
3956 || (do_debug_str && streq (name, "str"))
3957 || (do_debug_loc && streq (name, "loc"))
3959 request_dump (i, DEBUG_DUMP);
3961 /* linkonce section to be combined with .debug_info at link time. */
3962 else if ((do_debugging || do_debug_info)
3963 && strneq (name, ".gnu.linkonce.wi.", 17))
3964 request_dump (i, DEBUG_DUMP);
3965 else if (do_debug_frames && streq (name, ".eh_frame"))
3966 request_dump (i, DEBUG_DUMP);
3972 if (elf_header.e_shnum > 1)
3973 printf (_("\nSection Headers:\n"));
3975 printf (_("\nSection Header:\n"));
3979 if (do_full_section_name)
3981 printf (_(" [Nr] Name\n"));
3982 printf (_(" Type Addr Off Size ES Flg Lk Inf Al\n"));
3986 (_(" [Nr] Name Type Addr Off Size ES Flg Lk Inf Al\n"));
3990 if (do_full_section_name)
3992 printf (_(" [Nr] Name\n"));
3993 printf (_(" Type Address Off Size ES Flg Lk Inf Al\n"));
3997 (_(" [Nr] Name Type Address Off Size ES Flg Lk Inf Al\n"));
4001 if (do_full_section_name)
4003 printf (_(" [Nr] Name\n"));
4004 printf (_(" Flags Type Address Offset\n"));
4005 printf (_(" Size EntSize Link Info Align\n"));
4009 printf (_(" [Nr] Name Type Address Offset\n"));
4010 printf (_(" Size EntSize Flags Link Info Align\n"));
4014 for (i = 0, section = section_headers;
4015 i < elf_header.e_shnum;
4018 if (do_full_section_name)
4020 printf (" [%2u] %s\n",
4021 SECTION_HEADER_NUM (i),
4022 SECTION_NAME (section));
4023 if (is_32bit_elf || do_wide)
4024 printf (" %-15.15s ",
4025 get_section_type_name (section->sh_type));
4028 printf (" [%2u] %-17.17s %-15.15s ",
4029 SECTION_HEADER_NUM (i),
4030 SECTION_NAME (section),
4031 get_section_type_name (section->sh_type));
4035 print_vma (section->sh_addr, LONG_HEX);
4037 printf ( " %6.6lx %6.6lx %2.2lx",
4038 (unsigned long) section->sh_offset,
4039 (unsigned long) section->sh_size,
4040 (unsigned long) section->sh_entsize);
4042 printf (" %3s ", get_elf_section_flags (section->sh_flags));
4044 printf ("%2ld %3lu %2ld\n",
4045 (unsigned long) section->sh_link,
4046 (unsigned long) section->sh_info,
4047 (unsigned long) section->sh_addralign);
4051 print_vma (section->sh_addr, LONG_HEX);
4053 if ((long) section->sh_offset == section->sh_offset)
4054 printf (" %6.6lx", (unsigned long) section->sh_offset);
4058 print_vma (section->sh_offset, LONG_HEX);
4061 if ((unsigned long) section->sh_size == section->sh_size)
4062 printf (" %6.6lx", (unsigned long) section->sh_size);
4066 print_vma (section->sh_size, LONG_HEX);
4069 if ((unsigned long) section->sh_entsize == section->sh_entsize)
4070 printf (" %2.2lx", (unsigned long) section->sh_entsize);
4074 print_vma (section->sh_entsize, LONG_HEX);
4077 printf (" %3s ", get_elf_section_flags (section->sh_flags));
4079 printf ("%2ld %3lu ",
4080 (unsigned long) section->sh_link,
4081 (unsigned long) section->sh_info);
4083 if ((unsigned long) section->sh_addralign == section->sh_addralign)
4084 printf ("%2ld\n", (unsigned long) section->sh_addralign);
4087 print_vma (section->sh_addralign, DEC);
4091 else if (do_full_section_name)
4093 printf (" %-15.15s %-15.15s ",
4094 get_elf_section_flags (section->sh_flags),
4095 get_section_type_name (section->sh_type));
4097 print_vma (section->sh_addr, LONG_HEX);
4098 if ((long) section->sh_offset == section->sh_offset)
4099 printf (" %8.8lx", (unsigned long) section->sh_offset);
4103 print_vma (section->sh_offset, LONG_HEX);
4106 print_vma (section->sh_size, LONG_HEX);
4108 print_vma (section->sh_entsize, LONG_HEX);
4110 printf (" %2ld %3lu %ld\n",
4111 (unsigned long) section->sh_link,
4112 (unsigned long) section->sh_info,
4113 (unsigned long) section->sh_addralign);
4118 print_vma (section->sh_addr, LONG_HEX);
4119 if ((long) section->sh_offset == section->sh_offset)
4120 printf (" %8.8lx", (unsigned long) section->sh_offset);
4124 print_vma (section->sh_offset, LONG_HEX);
4127 print_vma (section->sh_size, LONG_HEX);
4129 print_vma (section->sh_entsize, LONG_HEX);
4131 printf (" %3s ", get_elf_section_flags (section->sh_flags));
4133 printf (" %2ld %3lu %ld\n",
4134 (unsigned long) section->sh_link,
4135 (unsigned long) section->sh_info,
4136 (unsigned long) section->sh_addralign);
4140 printf (_("Key to Flags:\n\
4141 W (write), A (alloc), X (execute), M (merge), S (strings)\n\
4142 I (info), L (link order), G (group), x (unknown)\n\
4143 O (extra OS processing required) o (OS specific), p (processor specific)\n"));
4149 get_group_flags (unsigned int flags)
4151 static char buff[32];
4158 snprintf (buff, sizeof (buff), _("[<unknown>: 0x%x]"), flags);
4165 process_section_groups (FILE *file)
4167 Elf_Internal_Shdr *section;
4169 struct group *group;
4170 Elf_Internal_Shdr *symtab_sec, *strtab_sec;
4171 Elf_Internal_Sym *symtab;
4175 /* Don't process section groups unless needed. */
4176 if (!do_unwind && !do_section_groups)
4179 if (elf_header.e_shnum == 0)
4181 if (do_section_groups)
4182 printf (_("\nThere are no sections in this file.\n"));
4187 if (section_headers == NULL)
4189 error (_("Section headers are not available!\n"));
4193 section_headers_groups = calloc (elf_header.e_shnum,
4194 sizeof (struct group *));
4196 if (section_headers_groups == NULL)
4198 error (_("Out of memory\n"));
4202 /* Scan the sections for the group section. */
4204 for (i = 0, section = section_headers;
4205 i < elf_header.e_shnum;
4207 if (section->sh_type == SHT_GROUP)
4210 if (group_count == 0)
4212 if (do_section_groups)
4213 printf (_("\nThere are no section groups in this file.\n"));
4218 section_groups = calloc (group_count, sizeof (struct group));
4220 if (section_groups == NULL)
4222 error (_("Out of memory\n"));
4231 for (i = 0, section = section_headers, group = section_groups;
4232 i < elf_header.e_shnum;
4235 if (section->sh_type == SHT_GROUP)
4237 char *name = SECTION_NAME (section);
4239 unsigned char *start, *indices;
4240 unsigned int entry, j, size;
4241 Elf_Internal_Shdr *sec;
4242 Elf_Internal_Sym *sym;
4244 /* Get the symbol table. */
4245 if (SECTION_HEADER_INDEX (section->sh_link) >= elf_header.e_shnum
4246 || ((sec = SECTION_HEADER (section->sh_link))->sh_type
4249 error (_("Bad sh_link in group section `%s'\n"), name);
4253 if (symtab_sec != sec)
4258 symtab = GET_ELF_SYMBOLS (file, symtab_sec);
4261 sym = symtab + section->sh_info;
4263 if (ELF_ST_TYPE (sym->st_info) == STT_SECTION)
4265 bfd_vma sec_index = SECTION_HEADER_INDEX (sym->st_shndx);
4268 error (_("Bad sh_info in group section `%s'\n"), name);
4272 group_name = SECTION_NAME (section_headers + sec_index);
4281 /* Get the string table. */
4282 if (SECTION_HEADER_INDEX (symtab_sec->sh_link)
4283 >= elf_header.e_shnum)
4292 != (sec = SECTION_HEADER (symtab_sec->sh_link)))
4297 strtab = get_data (NULL, file, strtab_sec->sh_offset,
4298 1, strtab_sec->sh_size,
4300 strtab_size = strtab != NULL ? strtab_sec->sh_size : 0;
4302 group_name = sym->st_name < strtab_size
4303 ? strtab + sym->st_name : "<corrupt>";
4306 start = get_data (NULL, file, section->sh_offset,
4307 1, section->sh_size, _("section data"));
4310 size = (section->sh_size / section->sh_entsize) - 1;
4311 entry = byte_get (indices, 4);
4314 if (do_section_groups)
4316 printf ("\n%s group section [%5u] `%s' [%s] contains %u sections:\n",
4317 get_group_flags (entry), i, name, group_name, size);
4319 printf (_(" [Index] Name\n"));
4322 group->group_index = i;
4324 for (j = 0; j < size; j++)
4326 struct group_list *g;
4328 entry = byte_get (indices, 4);
4331 if (SECTION_HEADER_INDEX (entry) >= elf_header.e_shnum)
4333 error (_("section [%5u] in group section [%5u] > maximum section [%5u]\n"),
4334 entry, i, elf_header.e_shnum - 1);
4337 else if (entry >= SHN_LORESERVE && entry <= SHN_HIRESERVE)
4339 error (_("invalid section [%5u] in group section [%5u]\n"),
4344 if (section_headers_groups [SECTION_HEADER_INDEX (entry)]
4349 error (_("section [%5u] in group section [%5u] already in group section [%5u]\n"),
4351 section_headers_groups [SECTION_HEADER_INDEX (entry)]->group_index);
4356 /* Intel C/C++ compiler may put section 0 in a
4357 section group. We just warn it the first time
4358 and ignore it afterwards. */
4359 static int warned = 0;
4362 error (_("section 0 in group section [%5u]\n"),
4363 section_headers_groups [SECTION_HEADER_INDEX (entry)]->group_index);
4369 section_headers_groups [SECTION_HEADER_INDEX (entry)]
4372 if (do_section_groups)
4374 sec = SECTION_HEADER (entry);
4375 printf (" [%5u] %s\n", entry, SECTION_NAME (sec));
4378 g = xmalloc (sizeof (struct group_list));
4379 g->section_index = entry;
4380 g->next = group->root;
4404 } dynamic_relocations [] =
4406 { "REL", DT_REL, DT_RELSZ, FALSE },
4407 { "RELA", DT_RELA, DT_RELASZ, TRUE },
4408 { "PLT", DT_JMPREL, DT_PLTRELSZ, UNKNOWN }
4411 /* Process the reloc section. */
4414 process_relocs (FILE *file)
4416 unsigned long rel_size;
4417 unsigned long rel_offset;
4423 if (do_using_dynamic)
4427 int has_dynamic_reloc;
4430 has_dynamic_reloc = 0;
4432 for (i = 0; i < ARRAY_SIZE (dynamic_relocations); i++)
4434 is_rela = dynamic_relocations [i].rela;
4435 name = dynamic_relocations [i].name;
4436 rel_size = dynamic_info [dynamic_relocations [i].size];
4437 rel_offset = dynamic_info [dynamic_relocations [i].reloc];
4439 has_dynamic_reloc |= rel_size;
4441 if (is_rela == UNKNOWN)
4443 if (dynamic_relocations [i].reloc == DT_JMPREL)
4444 switch (dynamic_info[DT_PLTREL])
4458 (_("\n'%s' relocation section at offset 0x%lx contains %ld bytes:\n"),
4459 name, rel_offset, rel_size);
4461 dump_relocations (file,
4462 offset_from_vma (file, rel_offset, rel_size),
4464 dynamic_symbols, num_dynamic_syms,
4465 dynamic_strings, dynamic_strings_length, is_rela);
4469 if (! has_dynamic_reloc)
4470 printf (_("\nThere are no dynamic relocations in this file.\n"));
4474 Elf_Internal_Shdr *section;
4478 for (i = 0, section = section_headers;
4479 i < elf_header.e_shnum;
4482 if ( section->sh_type != SHT_RELA
4483 && section->sh_type != SHT_REL)
4486 rel_offset = section->sh_offset;
4487 rel_size = section->sh_size;
4491 Elf_Internal_Shdr *strsec;
4494 printf (_("\nRelocation section "));
4496 if (string_table == NULL)
4497 printf ("%d", section->sh_name);
4499 printf (_("'%s'"), SECTION_NAME (section));
4501 printf (_(" at offset 0x%lx contains %lu entries:\n"),
4502 rel_offset, (unsigned long) (rel_size / section->sh_entsize));
4504 is_rela = section->sh_type == SHT_RELA;
4506 if (section->sh_link
4507 && SECTION_HEADER_INDEX (section->sh_link)
4508 < elf_header.e_shnum)
4510 Elf_Internal_Shdr *symsec;
4511 Elf_Internal_Sym *symtab;
4512 unsigned long nsyms;
4513 unsigned long strtablen = 0;
4514 char *strtab = NULL;
4516 symsec = SECTION_HEADER (section->sh_link);
4517 if (symsec->sh_type != SHT_SYMTAB
4518 && symsec->sh_type != SHT_DYNSYM)
4521 nsyms = symsec->sh_size / symsec->sh_entsize;
4522 symtab = GET_ELF_SYMBOLS (file, symsec);
4527 if (SECTION_HEADER_INDEX (symsec->sh_link)
4528 < elf_header.e_shnum)
4530 strsec = SECTION_HEADER (symsec->sh_link);
4532 strtab = get_data (NULL, file, strsec->sh_offset,
4535 strtablen = strtab == NULL ? 0 : strsec->sh_size;
4538 dump_relocations (file, rel_offset, rel_size,
4539 symtab, nsyms, strtab, strtablen, is_rela);
4545 dump_relocations (file, rel_offset, rel_size,
4546 NULL, 0, NULL, 0, is_rela);
4553 printf (_("\nThere are no relocations in this file.\n"));
4559 /* Process the unwind section. */
4561 #include "unwind-ia64.h"
4563 /* An absolute address consists of a section and an offset. If the
4564 section is NULL, the offset itself is the address, otherwise, the
4565 address equals to LOAD_ADDRESS(section) + offset. */
4569 unsigned short section;
4573 struct ia64_unw_aux_info
4575 struct ia64_unw_table_entry
4577 struct absaddr start;
4579 struct absaddr info;
4581 *table; /* Unwind table. */
4582 unsigned long table_len; /* Length of unwind table. */
4583 unsigned char *info; /* Unwind info. */
4584 unsigned long info_size; /* Size of unwind info. */
4585 bfd_vma info_addr; /* starting address of unwind info. */
4586 bfd_vma seg_base; /* Starting address of segment. */
4587 Elf_Internal_Sym *symtab; /* The symbol table. */
4588 unsigned long nsyms; /* Number of symbols. */
4589 char *strtab; /* The string table. */
4590 unsigned long strtab_size; /* Size of string table. */
4594 find_symbol_for_address (Elf_Internal_Sym *symtab,
4595 unsigned long nsyms,
4597 unsigned long strtab_size,
4598 struct absaddr addr,
4599 const char **symname,
4602 bfd_vma dist = 0x100000;
4603 Elf_Internal_Sym *sym, *best = NULL;
4606 for (i = 0, sym = symtab; i < nsyms; ++i, ++sym)
4608 if (ELF_ST_TYPE (sym->st_info) == STT_FUNC
4609 && sym->st_name != 0
4610 && (addr.section == SHN_UNDEF || addr.section == sym->st_shndx)
4611 && addr.offset >= sym->st_value
4612 && addr.offset - sym->st_value < dist)
4615 dist = addr.offset - sym->st_value;
4622 *symname = (best->st_name >= strtab_size
4623 ? "<corrupt>" : strtab + best->st_name);
4628 *offset = addr.offset;
4632 dump_ia64_unwind (struct ia64_unw_aux_info *aux)
4634 struct ia64_unw_table_entry *tp;
4637 for (tp = aux->table; tp < aux->table + aux->table_len; ++tp)
4641 const unsigned char *dp;
4642 const unsigned char *head;
4643 const char *procname;
4645 find_symbol_for_address (aux->symtab, aux->nsyms, aux->strtab,
4646 aux->strtab_size, tp->start, &procname, &offset);
4648 fputs ("\n<", stdout);
4652 fputs (procname, stdout);
4655 printf ("+%lx", (unsigned long) offset);
4658 fputs (">: [", stdout);
4659 print_vma (tp->start.offset, PREFIX_HEX);
4660 fputc ('-', stdout);
4661 print_vma (tp->end.offset, PREFIX_HEX);
4662 printf ("], info at +0x%lx\n",
4663 (unsigned long) (tp->info.offset - aux->seg_base));
4665 head = aux->info + (tp->info.offset - aux->info_addr);
4666 stamp = byte_get ((unsigned char *) head, sizeof (stamp));
4668 printf (" v%u, flags=0x%lx (%s%s), len=%lu bytes\n",
4669 (unsigned) UNW_VER (stamp),
4670 (unsigned long) ((stamp & UNW_FLAG_MASK) >> 32),
4671 UNW_FLAG_EHANDLER (stamp) ? " ehandler" : "",
4672 UNW_FLAG_UHANDLER (stamp) ? " uhandler" : "",
4673 (unsigned long) (eh_addr_size * UNW_LENGTH (stamp)));
4675 if (UNW_VER (stamp) != 1)
4677 printf ("\tUnknown version.\n");
4682 for (dp = head + 8; dp < head + 8 + eh_addr_size * UNW_LENGTH (stamp);)
4683 dp = unw_decode (dp, in_body, & in_body);
4688 slurp_ia64_unwind_table (FILE *file,
4689 struct ia64_unw_aux_info *aux,
4690 Elf_Internal_Shdr *sec)
4692 unsigned long size, nrelas, i;
4693 Elf_Internal_Phdr *seg;
4694 struct ia64_unw_table_entry *tep;
4695 Elf_Internal_Shdr *relsec;
4696 Elf_Internal_Rela *rela, *rp;
4697 unsigned char *table, *tp;
4698 Elf_Internal_Sym *sym;
4699 const char *relname;
4701 /* First, find the starting address of the segment that includes
4704 if (elf_header.e_phnum)
4706 if (! get_program_headers (file))
4709 for (seg = program_headers;
4710 seg < program_headers + elf_header.e_phnum;
4713 if (seg->p_type != PT_LOAD)
4716 if (sec->sh_addr >= seg->p_vaddr
4717 && (sec->sh_addr + sec->sh_size <= seg->p_vaddr + seg->p_memsz))
4719 aux->seg_base = seg->p_vaddr;
4725 /* Second, build the unwind table from the contents of the unwind section: */
4726 size = sec->sh_size;
4727 table = get_data (NULL, file, sec->sh_offset, 1, size, _("unwind table"));
4731 aux->table = xcmalloc (size / (3 * eh_addr_size), sizeof (aux->table[0]));
4733 for (tp = table; tp < table + size; tp += 3 * eh_addr_size, ++tep)
4735 tep->start.section = SHN_UNDEF;
4736 tep->end.section = SHN_UNDEF;
4737 tep->info.section = SHN_UNDEF;
4740 tep->start.offset = byte_get ((unsigned char *) tp + 0, 4);
4741 tep->end.offset = byte_get ((unsigned char *) tp + 4, 4);
4742 tep->info.offset = byte_get ((unsigned char *) tp + 8, 4);
4746 tep->start.offset = BYTE_GET ((unsigned char *) tp + 0);
4747 tep->end.offset = BYTE_GET ((unsigned char *) tp + 8);
4748 tep->info.offset = BYTE_GET ((unsigned char *) tp + 16);
4750 tep->start.offset += aux->seg_base;
4751 tep->end.offset += aux->seg_base;
4752 tep->info.offset += aux->seg_base;
4756 /* Third, apply any relocations to the unwind table: */
4758 for (relsec = section_headers;
4759 relsec < section_headers + elf_header.e_shnum;
4762 if (relsec->sh_type != SHT_RELA
4763 || SECTION_HEADER_INDEX (relsec->sh_info) >= elf_header.e_shnum
4764 || SECTION_HEADER (relsec->sh_info) != sec)
4767 if (!slurp_rela_relocs (file, relsec->sh_offset, relsec->sh_size,
4771 for (rp = rela; rp < rela + nrelas; ++rp)
4775 relname = elf_ia64_reloc_type (ELF32_R_TYPE (rp->r_info));
4776 sym = aux->symtab + ELF32_R_SYM (rp->r_info);
4780 relname = elf_ia64_reloc_type (ELF64_R_TYPE (rp->r_info));
4781 sym = aux->symtab + ELF64_R_SYM (rp->r_info);
4784 if (! strneq (relname, "R_IA64_SEGREL", 13))
4786 warn (_("Skipping unexpected relocation type %s\n"), relname);
4790 i = rp->r_offset / (3 * eh_addr_size);
4792 switch (rp->r_offset/eh_addr_size % 3)
4795 aux->table[i].start.section = sym->st_shndx;
4796 aux->table[i].start.offset += rp->r_addend + sym->st_value;
4799 aux->table[i].end.section = sym->st_shndx;
4800 aux->table[i].end.offset += rp->r_addend + sym->st_value;
4803 aux->table[i].info.section = sym->st_shndx;
4804 aux->table[i].info.offset += rp->r_addend + sym->st_value;
4814 aux->table_len = size / (3 * eh_addr_size);
4819 ia64_process_unwind (FILE *file)
4821 Elf_Internal_Shdr *sec, *unwsec = NULL, *strsec;
4822 unsigned long i, unwcount = 0, unwstart = 0;
4823 struct ia64_unw_aux_info aux;
4825 memset (& aux, 0, sizeof (aux));
4827 for (i = 0, sec = section_headers; i < elf_header.e_shnum; ++i, ++sec)
4829 if (sec->sh_type == SHT_SYMTAB
4830 && SECTION_HEADER_INDEX (sec->sh_link) < elf_header.e_shnum)
4832 aux.nsyms = sec->sh_size / sec->sh_entsize;
4833 aux.symtab = GET_ELF_SYMBOLS (file, sec);
4835 strsec = SECTION_HEADER (sec->sh_link);
4836 aux.strtab = get_data (NULL, file, strsec->sh_offset,
4837 1, strsec->sh_size, _("string table"));
4838 aux.strtab_size = aux.strtab != NULL ? strsec->sh_size : 0;
4840 else if (sec->sh_type == SHT_IA_64_UNWIND)
4845 printf (_("\nThere are no unwind sections in this file.\n"));
4847 while (unwcount-- > 0)
4852 for (i = unwstart, sec = section_headers + unwstart;
4853 i < elf_header.e_shnum; ++i, ++sec)
4854 if (sec->sh_type == SHT_IA_64_UNWIND)
4861 len = sizeof (ELF_STRING_ia64_unwind_once) - 1;
4863 if ((unwsec->sh_flags & SHF_GROUP) != 0)
4865 /* We need to find which section group it is in. */
4866 struct group_list *g = section_headers_groups [i]->root;
4868 for (; g != NULL; g = g->next)
4870 sec = SECTION_HEADER (g->section_index);
4872 if (streq (SECTION_NAME (sec), ELF_STRING_ia64_unwind_info))
4877 i = elf_header.e_shnum;
4879 else if (strneq (SECTION_NAME (unwsec), ELF_STRING_ia64_unwind_once, len))
4881 /* .gnu.linkonce.ia64unw.FOO -> .gnu.linkonce.ia64unwi.FOO. */
4882 len2 = sizeof (ELF_STRING_ia64_unwind_info_once) - 1;
4883 suffix = SECTION_NAME (unwsec) + len;
4884 for (i = 0, sec = section_headers; i < elf_header.e_shnum;
4886 if (strneq (SECTION_NAME (sec), ELF_STRING_ia64_unwind_info_once, len2)
4887 && streq (SECTION_NAME (sec) + len2, suffix))
4892 /* .IA_64.unwindFOO -> .IA_64.unwind_infoFOO
4893 .IA_64.unwind or BAR -> .IA_64.unwind_info. */
4894 len = sizeof (ELF_STRING_ia64_unwind) - 1;
4895 len2 = sizeof (ELF_STRING_ia64_unwind_info) - 1;
4897 if (strneq (SECTION_NAME (unwsec), ELF_STRING_ia64_unwind, len))
4898 suffix = SECTION_NAME (unwsec) + len;
4899 for (i = 0, sec = section_headers; i < elf_header.e_shnum;
4901 if (strneq (SECTION_NAME (sec), ELF_STRING_ia64_unwind_info, len2)
4902 && streq (SECTION_NAME (sec) + len2, suffix))
4906 if (i == elf_header.e_shnum)
4908 printf (_("\nCould not find unwind info section for "));
4910 if (string_table == NULL)
4911 printf ("%d", unwsec->sh_name);
4913 printf (_("'%s'"), SECTION_NAME (unwsec));
4917 aux.info_size = sec->sh_size;
4918 aux.info_addr = sec->sh_addr;
4919 aux.info = get_data (NULL, file, sec->sh_offset, 1, aux.info_size,
4922 printf (_("\nUnwind section "));
4924 if (string_table == NULL)
4925 printf ("%d", unwsec->sh_name);
4927 printf (_("'%s'"), SECTION_NAME (unwsec));
4929 printf (_(" at offset 0x%lx contains %lu entries:\n"),
4930 (unsigned long) unwsec->sh_offset,
4931 (unsigned long) (unwsec->sh_size / (3 * eh_addr_size)));
4933 (void) slurp_ia64_unwind_table (file, & aux, unwsec);
4935 if (aux.table_len > 0)
4936 dump_ia64_unwind (& aux);
4939 free ((char *) aux.table);
4941 free ((char *) aux.info);
4950 free ((char *) aux.strtab);
4955 struct hppa_unw_aux_info
4957 struct hppa_unw_table_entry
4959 struct absaddr start;
4961 unsigned int Cannot_unwind:1; /* 0 */
4962 unsigned int Millicode:1; /* 1 */
4963 unsigned int Millicode_save_sr0:1; /* 2 */
4964 unsigned int Region_description:2; /* 3..4 */
4965 unsigned int reserved1:1; /* 5 */
4966 unsigned int Entry_SR:1; /* 6 */
4967 unsigned int Entry_FR:4; /* number saved */ /* 7..10 */
4968 unsigned int Entry_GR:5; /* number saved */ /* 11..15 */
4969 unsigned int Args_stored:1; /* 16 */
4970 unsigned int Variable_Frame:1; /* 17 */
4971 unsigned int Separate_Package_Body:1; /* 18 */
4972 unsigned int Frame_Extension_Millicode:1; /* 19 */
4973 unsigned int Stack_Overflow_Check:1; /* 20 */
4974 unsigned int Two_Instruction_SP_Increment:1; /* 21 */
4975 unsigned int Ada_Region:1; /* 22 */
4976 unsigned int cxx_info:1; /* 23 */
4977 unsigned int cxx_try_catch:1; /* 24 */
4978 unsigned int sched_entry_seq:1; /* 25 */
4979 unsigned int reserved2:1; /* 26 */
4980 unsigned int Save_SP:1; /* 27 */
4981 unsigned int Save_RP:1; /* 28 */
4982 unsigned int Save_MRP_in_frame:1; /* 29 */
4983 unsigned int extn_ptr_defined:1; /* 30 */
4984 unsigned int Cleanup_defined:1; /* 31 */
4986 unsigned int MPE_XL_interrupt_marker:1; /* 0 */
4987 unsigned int HP_UX_interrupt_marker:1; /* 1 */
4988 unsigned int Large_frame:1; /* 2 */
4989 unsigned int Pseudo_SP_Set:1; /* 3 */
4990 unsigned int reserved4:1; /* 4 */
4991 unsigned int Total_frame_size:27; /* 5..31 */
4993 *table; /* Unwind table. */
4994 unsigned long table_len; /* Length of unwind table. */
4995 bfd_vma seg_base; /* Starting address of segment. */
4996 Elf_Internal_Sym *symtab; /* The symbol table. */
4997 unsigned long nsyms; /* Number of symbols. */
4998 char *strtab; /* The string table. */
4999 unsigned long strtab_size; /* Size of string table. */
5003 dump_hppa_unwind (struct hppa_unw_aux_info *aux)
5005 struct hppa_unw_table_entry *tp;
5007 for (tp = aux->table; tp < aux->table + aux->table_len; ++tp)
5010 const char *procname;
5012 find_symbol_for_address (aux->symtab, aux->nsyms, aux->strtab,
5013 aux->strtab_size, tp->start, &procname,
5016 fputs ("\n<", stdout);
5020 fputs (procname, stdout);
5023 printf ("+%lx", (unsigned long) offset);
5026 fputs (">: [", stdout);
5027 print_vma (tp->start.offset, PREFIX_HEX);
5028 fputc ('-', stdout);
5029 print_vma (tp->end.offset, PREFIX_HEX);
5032 #define PF(_m) if (tp->_m) printf (#_m " ");
5033 #define PV(_m) if (tp->_m) printf (#_m "=%d ", tp->_m);
5036 PF(Millicode_save_sr0);
5037 /* PV(Region_description); */
5043 PF(Separate_Package_Body);
5044 PF(Frame_Extension_Millicode);
5045 PF(Stack_Overflow_Check);
5046 PF(Two_Instruction_SP_Increment);
5050 PF(sched_entry_seq);
5053 PF(Save_MRP_in_frame);
5054 PF(extn_ptr_defined);
5055 PF(Cleanup_defined);
5056 PF(MPE_XL_interrupt_marker);
5057 PF(HP_UX_interrupt_marker);
5060 PV(Total_frame_size);
5069 slurp_hppa_unwind_table (FILE *file,
5070 struct hppa_unw_aux_info *aux,
5071 Elf_Internal_Shdr *sec)
5073 unsigned long size, unw_ent_size, nrelas, i;
5074 Elf_Internal_Phdr *seg;
5075 struct hppa_unw_table_entry *tep;
5076 Elf_Internal_Shdr *relsec;
5077 Elf_Internal_Rela *rela, *rp;
5078 unsigned char *table, *tp;
5079 Elf_Internal_Sym *sym;
5080 const char *relname;
5082 /* First, find the starting address of the segment that includes
5085 if (elf_header.e_phnum)
5087 if (! get_program_headers (file))
5090 for (seg = program_headers;
5091 seg < program_headers + elf_header.e_phnum;
5094 if (seg->p_type != PT_LOAD)
5097 if (sec->sh_addr >= seg->p_vaddr
5098 && (sec->sh_addr + sec->sh_size <= seg->p_vaddr + seg->p_memsz))
5100 aux->seg_base = seg->p_vaddr;
5106 /* Second, build the unwind table from the contents of the unwind
5108 size = sec->sh_size;
5109 table = get_data (NULL, file, sec->sh_offset, 1, size, _("unwind table"));
5113 unw_ent_size = 2 * eh_addr_size + 8;
5115 tep = aux->table = xcmalloc (size / unw_ent_size, sizeof (aux->table[0]));
5117 for (tp = table; tp < table + size; tp += (2 * eh_addr_size + 8), ++tep)
5119 unsigned int tmp1, tmp2;
5121 tep->start.section = SHN_UNDEF;
5122 tep->end.section = SHN_UNDEF;
5126 tep->start.offset = byte_get ((unsigned char *) tp + 0, 4);
5127 tep->end.offset = byte_get ((unsigned char *) tp + 4, 4);
5128 tmp1 = byte_get ((unsigned char *) tp + 8, 4);
5129 tmp2 = byte_get ((unsigned char *) tp + 12, 4);
5133 tep->start.offset = BYTE_GET ((unsigned char *) tp + 0);
5134 tep->end.offset = BYTE_GET ((unsigned char *) tp + 8);
5135 tmp1 = byte_get ((unsigned char *) tp + 16, 4);
5136 tmp2 = byte_get ((unsigned char *) tp + 20, 4);
5139 tep->Cannot_unwind = (tmp1 >> 31) & 0x1;
5140 tep->Millicode = (tmp1 >> 30) & 0x1;
5141 tep->Millicode_save_sr0 = (tmp1 >> 29) & 0x1;
5142 tep->Region_description = (tmp1 >> 27) & 0x3;
5143 tep->reserved1 = (tmp1 >> 26) & 0x1;
5144 tep->Entry_SR = (tmp1 >> 25) & 0x1;
5145 tep->Entry_FR = (tmp1 >> 21) & 0xf;
5146 tep->Entry_GR = (tmp1 >> 16) & 0x1f;
5147 tep->Args_stored = (tmp1 >> 15) & 0x1;
5148 tep->Variable_Frame = (tmp1 >> 14) & 0x1;
5149 tep->Separate_Package_Body = (tmp1 >> 13) & 0x1;
5150 tep->Frame_Extension_Millicode = (tmp1 >> 12) & 0x1;
5151 tep->Stack_Overflow_Check = (tmp1 >> 11) & 0x1;
5152 tep->Two_Instruction_SP_Increment = (tmp1 >> 10) & 0x1;
5153 tep->Ada_Region = (tmp1 >> 9) & 0x1;
5154 tep->cxx_info = (tmp1 >> 8) & 0x1;
5155 tep->cxx_try_catch = (tmp1 >> 7) & 0x1;
5156 tep->sched_entry_seq = (tmp1 >> 6) & 0x1;
5157 tep->reserved2 = (tmp1 >> 5) & 0x1;
5158 tep->Save_SP = (tmp1 >> 4) & 0x1;
5159 tep->Save_RP = (tmp1 >> 3) & 0x1;
5160 tep->Save_MRP_in_frame = (tmp1 >> 2) & 0x1;
5161 tep->extn_ptr_defined = (tmp1 >> 1) & 0x1;
5162 tep->Cleanup_defined = tmp1 & 0x1;
5164 tep->MPE_XL_interrupt_marker = (tmp2 >> 31) & 0x1;
5165 tep->HP_UX_interrupt_marker = (tmp2 >> 30) & 0x1;
5166 tep->Large_frame = (tmp2 >> 29) & 0x1;
5167 tep->Pseudo_SP_Set = (tmp2 >> 28) & 0x1;
5168 tep->reserved4 = (tmp2 >> 27) & 0x1;
5169 tep->Total_frame_size = tmp2 & 0x7ffffff;
5171 tep->start.offset += aux->seg_base;
5172 tep->end.offset += aux->seg_base;
5176 /* Third, apply any relocations to the unwind table. */
5178 for (relsec = section_headers;
5179 relsec < section_headers + elf_header.e_shnum;
5182 if (relsec->sh_type != SHT_RELA
5183 || SECTION_HEADER_INDEX (relsec->sh_info) >= elf_header.e_shnum
5184 || SECTION_HEADER (relsec->sh_info) != sec)
5187 if (!slurp_rela_relocs (file, relsec->sh_offset, relsec->sh_size,
5191 for (rp = rela; rp < rela + nrelas; ++rp)
5195 relname = elf_hppa_reloc_type (ELF32_R_TYPE (rp->r_info));
5196 sym = aux->symtab + ELF32_R_SYM (rp->r_info);
5200 relname = elf_hppa_reloc_type (ELF64_R_TYPE (rp->r_info));
5201 sym = aux->symtab + ELF64_R_SYM (rp->r_info);
5204 /* R_PARISC_SEGREL32 or R_PARISC_SEGREL64. */
5205 if (strncmp (relname, "R_PARISC_SEGREL", 15) != 0)
5207 warn (_("Skipping unexpected relocation type %s\n"), relname);
5211 i = rp->r_offset / unw_ent_size;
5213 switch ((rp->r_offset % unw_ent_size) / eh_addr_size)
5216 aux->table[i].start.section = sym->st_shndx;
5217 aux->table[i].start.offset += sym->st_value + rp->r_addend;
5220 aux->table[i].end.section = sym->st_shndx;
5221 aux->table[i].end.offset += sym->st_value + rp->r_addend;
5231 aux->table_len = size / unw_ent_size;
5237 hppa_process_unwind (FILE *file)
5239 struct hppa_unw_aux_info aux;
5240 Elf_Internal_Shdr *unwsec = NULL;
5241 Elf_Internal_Shdr *strsec;
5242 Elf_Internal_Shdr *sec;
5245 memset (& aux, 0, sizeof (aux));
5247 if (string_table == NULL)
5250 for (i = 0, sec = section_headers; i < elf_header.e_shnum; ++i, ++sec)
5252 if (sec->sh_type == SHT_SYMTAB
5253 && SECTION_HEADER_INDEX (sec->sh_link) < elf_header.e_shnum)
5255 aux.nsyms = sec->sh_size / sec->sh_entsize;
5256 aux.symtab = GET_ELF_SYMBOLS (file, sec);
5258 strsec = SECTION_HEADER (sec->sh_link);
5259 aux.strtab = get_data (NULL, file, strsec->sh_offset,
5260 1, strsec->sh_size, _("string table"));
5261 aux.strtab_size = aux.strtab != NULL ? strsec->sh_size : 0;
5263 else if (streq (SECTION_NAME (sec), ".PARISC.unwind"))
5268 printf (_("\nThere are no unwind sections in this file.\n"));
5270 for (i = 0, sec = section_headers; i < elf_header.e_shnum; ++i, ++sec)
5272 if (streq (SECTION_NAME (sec), ".PARISC.unwind"))
5274 printf (_("\nUnwind section "));
5275 printf (_("'%s'"), SECTION_NAME (sec));
5277 printf (_(" at offset 0x%lx contains %lu entries:\n"),
5278 (unsigned long) sec->sh_offset,
5279 (unsigned long) (sec->sh_size / (2 * eh_addr_size + 8)));
5281 slurp_hppa_unwind_table (file, &aux, sec);
5282 if (aux.table_len > 0)
5283 dump_hppa_unwind (&aux);
5286 free ((char *) aux.table);
5294 free ((char *) aux.strtab);
5300 process_unwind (FILE *file)
5302 struct unwind_handler {
5304 int (*handler)(FILE *file);
5306 { EM_IA_64, ia64_process_unwind },
5307 { EM_PARISC, hppa_process_unwind },
5315 for (i = 0; handlers[i].handler != NULL; i++)
5316 if (elf_header.e_machine == handlers[i].machtype)
5317 return handlers[i].handler (file);
5319 printf (_("\nThere are no unwind sections in this file.\n"));
5324 dynamic_section_mips_val (Elf_Internal_Dyn *entry)
5326 switch (entry->d_tag)
5329 if (entry->d_un.d_val == 0)
5333 static const char * opts[] =
5335 "QUICKSTART", "NOTPOT", "NO_LIBRARY_REPLACEMENT",
5336 "NO_MOVE", "SGI_ONLY", "GUARANTEE_INIT", "DELTA_C_PLUS_PLUS",
5337 "GUARANTEE_START_INIT", "PIXIE", "DEFAULT_DELAY_LOAD",
5338 "REQUICKSTART", "REQUICKSTARTED", "CORD", "NO_UNRES_UNDEF",
5343 for (cnt = 0; cnt < NUM_ELEM (opts); ++cnt)
5344 if (entry->d_un.d_val & (1 << cnt))
5346 printf ("%s%s", first ? "" : " ", opts[cnt]);
5353 case DT_MIPS_IVERSION:
5354 if (VALID_DYNAMIC_NAME (entry->d_un.d_val))
5355 printf ("Interface Version: %s\n", GET_DYNAMIC_NAME (entry->d_un.d_val));
5357 printf ("<corrupt: %ld>\n", (long) entry->d_un.d_ptr);
5360 case DT_MIPS_TIME_STAMP:
5365 time_t time = entry->d_un.d_val;
5366 tmp = gmtime (&time);
5367 snprintf (timebuf, sizeof (timebuf), "%04u-%02u-%02uT%02u:%02u:%02u",
5368 tmp->tm_year + 1900, tmp->tm_mon + 1, tmp->tm_mday,
5369 tmp->tm_hour, tmp->tm_min, tmp->tm_sec);
5370 printf ("Time Stamp: %s\n", timebuf);
5374 case DT_MIPS_RLD_VERSION:
5375 case DT_MIPS_LOCAL_GOTNO:
5376 case DT_MIPS_CONFLICTNO:
5377 case DT_MIPS_LIBLISTNO:
5378 case DT_MIPS_SYMTABNO:
5379 case DT_MIPS_UNREFEXTNO:
5380 case DT_MIPS_HIPAGENO:
5381 case DT_MIPS_DELTA_CLASS_NO:
5382 case DT_MIPS_DELTA_INSTANCE_NO:
5383 case DT_MIPS_DELTA_RELOC_NO:
5384 case DT_MIPS_DELTA_SYM_NO:
5385 case DT_MIPS_DELTA_CLASSSYM_NO:
5386 case DT_MIPS_COMPACT_SIZE:
5387 printf ("%ld\n", (long) entry->d_un.d_ptr);
5391 printf ("%#lx\n", (long) entry->d_un.d_ptr);
5397 dynamic_section_parisc_val (Elf_Internal_Dyn *entry)
5399 switch (entry->d_tag)
5401 case DT_HP_DLD_FLAGS:
5410 { DT_HP_DEBUG_PRIVATE, "HP_DEBUG_PRIVATE" },
5411 { DT_HP_DEBUG_CALLBACK, "HP_DEBUG_CALLBACK" },
5412 { DT_HP_DEBUG_CALLBACK_BOR, "HP_DEBUG_CALLBACK_BOR" },
5413 { DT_HP_NO_ENVVAR, "HP_NO_ENVVAR" },
5414 { DT_HP_BIND_NOW, "HP_BIND_NOW" },
5415 { DT_HP_BIND_NONFATAL, "HP_BIND_NONFATAL" },
5416 { DT_HP_BIND_VERBOSE, "HP_BIND_VERBOSE" },
5417 { DT_HP_BIND_RESTRICTED, "HP_BIND_RESTRICTED" },
5418 { DT_HP_BIND_SYMBOLIC, "HP_BIND_SYMBOLIC" },
5419 { DT_HP_RPATH_FIRST, "HP_RPATH_FIRST" },
5420 { DT_HP_BIND_DEPTH_FIRST, "HP_BIND_DEPTH_FIRST" }
5424 bfd_vma val = entry->d_un.d_val;
5426 for (cnt = 0; cnt < sizeof (flags) / sizeof (flags[0]); ++cnt)
5427 if (val & flags[cnt].bit)
5431 fputs (flags[cnt].str, stdout);
5433 val ^= flags[cnt].bit;
5436 if (val != 0 || first)
5440 print_vma (val, HEX);
5446 print_vma (entry->d_un.d_ptr, PREFIX_HEX);
5453 dynamic_section_ia64_val (Elf_Internal_Dyn *entry)
5455 switch (entry->d_tag)
5457 case DT_IA_64_PLT_RESERVE:
5458 /* First 3 slots reserved. */
5459 print_vma (entry->d_un.d_ptr, PREFIX_HEX);
5461 print_vma (entry->d_un.d_ptr + (3 * 8), PREFIX_HEX);
5465 print_vma (entry->d_un.d_ptr, PREFIX_HEX);
5472 get_32bit_dynamic_section (FILE *file)
5474 Elf32_External_Dyn *edyn, *ext;
5475 Elf_Internal_Dyn *entry;
5477 edyn = get_data (NULL, file, dynamic_addr, 1, dynamic_size,
5478 _("dynamic section"));
5482 /* SGI's ELF has more than one section in the DYNAMIC segment, and we
5483 might not have the luxury of section headers. Look for the DT_NULL
5484 terminator to determine the number of entries. */
5485 for (ext = edyn, dynamic_nent = 0;
5486 (char *) ext < (char *) edyn + dynamic_size;
5490 if (BYTE_GET (ext->d_tag) == DT_NULL)
5494 dynamic_section = cmalloc (dynamic_nent, sizeof (*entry));
5495 if (dynamic_section == NULL)
5497 error (_("Out of memory\n"));
5502 for (ext = edyn, entry = dynamic_section;
5503 entry < dynamic_section + dynamic_nent;
5506 entry->d_tag = BYTE_GET (ext->d_tag);
5507 entry->d_un.d_val = BYTE_GET (ext->d_un.d_val);
5516 get_64bit_dynamic_section (FILE *file)
5518 Elf64_External_Dyn *edyn, *ext;
5519 Elf_Internal_Dyn *entry;
5521 edyn = get_data (NULL, file, dynamic_addr, 1, dynamic_size,
5522 _("dynamic section"));
5526 /* SGI's ELF has more than one section in the DYNAMIC segment, and we
5527 might not have the luxury of section headers. Look for the DT_NULL
5528 terminator to determine the number of entries. */
5529 for (ext = edyn, dynamic_nent = 0;
5530 (char *) ext < (char *) edyn + dynamic_size;
5534 if (BYTE_GET (ext->d_tag) == DT_NULL)
5538 dynamic_section = cmalloc (dynamic_nent, sizeof (*entry));
5539 if (dynamic_section == NULL)
5541 error (_("Out of memory\n"));
5546 for (ext = edyn, entry = dynamic_section;
5547 entry < dynamic_section + dynamic_nent;
5550 entry->d_tag = BYTE_GET (ext->d_tag);
5551 entry->d_un.d_val = BYTE_GET (ext->d_un.d_val);
5560 print_dynamic_flags (bfd_vma flags)
5568 flag = flags & - flags;
5578 case DF_ORIGIN: fputs ("ORIGIN", stdout); break;
5579 case DF_SYMBOLIC: fputs ("SYMBOLIC", stdout); break;
5580 case DF_TEXTREL: fputs ("TEXTREL", stdout); break;
5581 case DF_BIND_NOW: fputs ("BIND_NOW", stdout); break;
5582 case DF_STATIC_TLS: fputs ("STATIC_TLS", stdout); break;
5583 default: fputs ("unknown", stdout); break;
5589 /* Parse and display the contents of the dynamic section. */
5592 process_dynamic_section (FILE *file)
5594 Elf_Internal_Dyn *entry;
5596 if (dynamic_size == 0)
5599 printf (_("\nThere is no dynamic section in this file.\n"));
5606 if (! get_32bit_dynamic_section (file))
5609 else if (! get_64bit_dynamic_section (file))
5612 /* Find the appropriate symbol table. */
5613 if (dynamic_symbols == NULL)
5615 for (entry = dynamic_section;
5616 entry < dynamic_section + dynamic_nent;
5619 Elf_Internal_Shdr section;
5621 if (entry->d_tag != DT_SYMTAB)
5624 dynamic_info[DT_SYMTAB] = entry->d_un.d_val;
5626 /* Since we do not know how big the symbol table is,
5627 we default to reading in the entire file (!) and
5628 processing that. This is overkill, I know, but it
5630 section.sh_offset = offset_from_vma (file, entry->d_un.d_val, 0);
5632 if (archive_file_offset != 0)
5633 section.sh_size = archive_file_size - section.sh_offset;
5636 if (fseek (file, 0, SEEK_END))
5637 error (_("Unable to seek to end of file!"));
5639 section.sh_size = ftell (file) - section.sh_offset;
5643 section.sh_entsize = sizeof (Elf32_External_Sym);
5645 section.sh_entsize = sizeof (Elf64_External_Sym);
5647 num_dynamic_syms = section.sh_size / section.sh_entsize;
5648 if (num_dynamic_syms < 1)
5650 error (_("Unable to determine the number of symbols to load\n"));
5654 dynamic_symbols = GET_ELF_SYMBOLS (file, §ion);
5658 /* Similarly find a string table. */
5659 if (dynamic_strings == NULL)
5661 for (entry = dynamic_section;
5662 entry < dynamic_section + dynamic_nent;
5665 unsigned long offset;
5668 if (entry->d_tag != DT_STRTAB)
5671 dynamic_info[DT_STRTAB] = entry->d_un.d_val;
5673 /* Since we do not know how big the string table is,
5674 we default to reading in the entire file (!) and
5675 processing that. This is overkill, I know, but it
5678 offset = offset_from_vma (file, entry->d_un.d_val, 0);
5680 if (archive_file_offset != 0)
5681 str_tab_len = archive_file_size - offset;
5684 if (fseek (file, 0, SEEK_END))
5685 error (_("Unable to seek to end of file\n"));
5686 str_tab_len = ftell (file) - offset;
5689 if (str_tab_len < 1)
5692 (_("Unable to determine the length of the dynamic string table\n"));
5696 dynamic_strings = get_data (NULL, file, offset, 1, str_tab_len,
5697 _("dynamic string table"));
5698 dynamic_strings_length = str_tab_len;
5703 /* And find the syminfo section if available. */
5704 if (dynamic_syminfo == NULL)
5706 unsigned long syminsz = 0;
5708 for (entry = dynamic_section;
5709 entry < dynamic_section + dynamic_nent;
5712 if (entry->d_tag == DT_SYMINENT)
5714 /* Note: these braces are necessary to avoid a syntax
5715 error from the SunOS4 C compiler. */
5716 assert (sizeof (Elf_External_Syminfo) == entry->d_un.d_val);
5718 else if (entry->d_tag == DT_SYMINSZ)
5719 syminsz = entry->d_un.d_val;
5720 else if (entry->d_tag == DT_SYMINFO)
5721 dynamic_syminfo_offset = offset_from_vma (file, entry->d_un.d_val,
5725 if (dynamic_syminfo_offset != 0 && syminsz != 0)
5727 Elf_External_Syminfo *extsyminfo, *extsym;
5728 Elf_Internal_Syminfo *syminfo;
5730 /* There is a syminfo section. Read the data. */
5731 extsyminfo = get_data (NULL, file, dynamic_syminfo_offset, 1,
5732 syminsz, _("symbol information"));
5736 dynamic_syminfo = malloc (syminsz);
5737 if (dynamic_syminfo == NULL)
5739 error (_("Out of memory\n"));
5743 dynamic_syminfo_nent = syminsz / sizeof (Elf_External_Syminfo);
5744 for (syminfo = dynamic_syminfo, extsym = extsyminfo;
5745 syminfo < dynamic_syminfo + dynamic_syminfo_nent;
5746 ++syminfo, ++extsym)
5748 syminfo->si_boundto = BYTE_GET (extsym->si_boundto);
5749 syminfo->si_flags = BYTE_GET (extsym->si_flags);
5756 if (do_dynamic && dynamic_addr)
5757 printf (_("\nDynamic section at offset 0x%lx contains %u entries:\n"),
5758 dynamic_addr, dynamic_nent);
5760 printf (_(" Tag Type Name/Value\n"));
5762 for (entry = dynamic_section;
5763 entry < dynamic_section + dynamic_nent;
5771 print_vma (entry->d_tag, FULL_HEX);
5772 dtype = get_dynamic_type (entry->d_tag);
5773 printf (" (%s)%*s", dtype,
5774 ((is_32bit_elf ? 27 : 19)
5775 - (int) strlen (dtype)),
5779 switch (entry->d_tag)
5783 print_dynamic_flags (entry->d_un.d_val);
5793 switch (entry->d_tag)
5796 printf (_("Auxiliary library"));
5800 printf (_("Filter library"));
5804 printf (_("Configuration file"));
5808 printf (_("Dependency audit library"));
5812 printf (_("Audit library"));
5816 if (VALID_DYNAMIC_NAME (entry->d_un.d_val))
5817 printf (": [%s]\n", GET_DYNAMIC_NAME (entry->d_un.d_val));
5821 print_vma (entry->d_un.d_val, PREFIX_HEX);
5830 printf (_("Flags:"));
5832 if (entry->d_un.d_val == 0)
5833 printf (_(" None\n"));
5836 unsigned long int val = entry->d_un.d_val;
5838 if (val & DTF_1_PARINIT)
5840 printf (" PARINIT");
5841 val ^= DTF_1_PARINIT;
5843 if (val & DTF_1_CONFEXP)
5845 printf (" CONFEXP");
5846 val ^= DTF_1_CONFEXP;
5849 printf (" %lx", val);
5858 printf (_("Flags:"));
5860 if (entry->d_un.d_val == 0)
5861 printf (_(" None\n"));
5864 unsigned long int val = entry->d_un.d_val;
5866 if (val & DF_P1_LAZYLOAD)
5868 printf (" LAZYLOAD");
5869 val ^= DF_P1_LAZYLOAD;
5871 if (val & DF_P1_GROUPPERM)
5873 printf (" GROUPPERM");
5874 val ^= DF_P1_GROUPPERM;
5877 printf (" %lx", val);
5886 printf (_("Flags:"));
5887 if (entry->d_un.d_val == 0)
5888 printf (_(" None\n"));
5891 unsigned long int val = entry->d_un.d_val;
5898 if (val & DF_1_GLOBAL)
5903 if (val & DF_1_GROUP)
5908 if (val & DF_1_NODELETE)
5910 printf (" NODELETE");
5911 val ^= DF_1_NODELETE;
5913 if (val & DF_1_LOADFLTR)
5915 printf (" LOADFLTR");
5916 val ^= DF_1_LOADFLTR;
5918 if (val & DF_1_INITFIRST)
5920 printf (" INITFIRST");
5921 val ^= DF_1_INITFIRST;
5923 if (val & DF_1_NOOPEN)
5928 if (val & DF_1_ORIGIN)
5933 if (val & DF_1_DIRECT)
5938 if (val & DF_1_TRANS)
5943 if (val & DF_1_INTERPOSE)
5945 printf (" INTERPOSE");
5946 val ^= DF_1_INTERPOSE;
5948 if (val & DF_1_NODEFLIB)
5950 printf (" NODEFLIB");
5951 val ^= DF_1_NODEFLIB;
5953 if (val & DF_1_NODUMP)
5958 if (val & DF_1_CONLFAT)
5960 printf (" CONLFAT");
5961 val ^= DF_1_CONLFAT;
5964 printf (" %lx", val);
5971 dynamic_info[entry->d_tag] = entry->d_un.d_val;
5973 puts (get_dynamic_type (entry->d_un.d_val));
5993 dynamic_info[entry->d_tag] = entry->d_un.d_val;
5999 if (VALID_DYNAMIC_NAME (entry->d_un.d_val))
6000 name = GET_DYNAMIC_NAME (entry->d_un.d_val);
6006 switch (entry->d_tag)
6009 printf (_("Shared library: [%s]"), name);
6011 if (streq (name, program_interpreter))
6012 printf (_(" program interpreter"));
6016 printf (_("Library soname: [%s]"), name);
6020 printf (_("Library rpath: [%s]"), name);
6024 printf (_("Library runpath: [%s]"), name);
6028 print_vma (entry->d_un.d_val, PREFIX_HEX);
6033 print_vma (entry->d_un.d_val, PREFIX_HEX);
6046 dynamic_info[entry->d_tag] = entry->d_un.d_val;
6050 case DT_INIT_ARRAYSZ:
6051 case DT_FINI_ARRAYSZ:
6052 case DT_GNU_CONFLICTSZ:
6053 case DT_GNU_LIBLISTSZ:
6056 print_vma (entry->d_un.d_val, UNSIGNED);
6057 printf (" (bytes)\n");
6067 print_vma (entry->d_un.d_val, UNSIGNED);
6080 if (entry->d_tag == DT_USED
6081 && VALID_DYNAMIC_NAME (entry->d_un.d_val))
6083 char *name = GET_DYNAMIC_NAME (entry->d_un.d_val);
6087 printf (_("Not needed object: [%s]\n"), name);
6092 print_vma (entry->d_un.d_val, PREFIX_HEX);
6098 /* The value of this entry is ignored. */
6103 case DT_GNU_PRELINKED:
6107 time_t time = entry->d_un.d_val;
6109 tmp = gmtime (&time);
6110 printf ("%04u-%02u-%02uT%02u:%02u:%02u\n",
6111 tmp->tm_year + 1900, tmp->tm_mon + 1, tmp->tm_mday,
6112 tmp->tm_hour, tmp->tm_min, tmp->tm_sec);
6118 if ((entry->d_tag >= DT_VERSYM) && (entry->d_tag <= DT_VERNEEDNUM))
6119 version_info[DT_VERSIONTAGIDX (entry->d_tag)] =
6124 switch (elf_header.e_machine)
6127 case EM_MIPS_RS3_LE:
6128 dynamic_section_mips_val (entry);
6131 dynamic_section_parisc_val (entry);
6134 dynamic_section_ia64_val (entry);
6137 print_vma (entry->d_un.d_val, PREFIX_HEX);
6149 get_ver_flags (unsigned int flags)
6151 static char buff[32];
6158 if (flags & VER_FLG_BASE)
6159 strcat (buff, "BASE ");
6161 if (flags & VER_FLG_WEAK)
6163 if (flags & VER_FLG_BASE)
6164 strcat (buff, "| ");
6166 strcat (buff, "WEAK ");
6169 if (flags & ~(VER_FLG_BASE | VER_FLG_WEAK))
6170 strcat (buff, "| <unknown>");
6175 /* Display the contents of the version sections. */
6177 process_version_sections (FILE *file)
6179 Elf_Internal_Shdr *section;
6186 for (i = 0, section = section_headers;
6187 i < elf_header.e_shnum;
6190 switch (section->sh_type)
6192 case SHT_GNU_verdef:
6194 Elf_External_Verdef *edefs;
6201 (_("\nVersion definition section '%s' contains %ld entries:\n"),
6202 SECTION_NAME (section), section->sh_info);
6204 printf (_(" Addr: 0x"));
6205 printf_vma (section->sh_addr);
6206 printf (_(" Offset: %#08lx Link: %lx (%s)\n"),
6207 (unsigned long) section->sh_offset, section->sh_link,
6208 SECTION_HEADER_INDEX (section->sh_link)
6209 < elf_header.e_shnum
6210 ? SECTION_NAME (SECTION_HEADER (section->sh_link))
6213 edefs = get_data (NULL, file, section->sh_offset, 1,
6215 _("version definition section"));
6219 for (idx = cnt = 0; cnt < section->sh_info; ++cnt)
6222 Elf_External_Verdef *edef;
6223 Elf_Internal_Verdef ent;
6224 Elf_External_Verdaux *eaux;
6225 Elf_Internal_Verdaux aux;
6229 vstart = ((char *) edefs) + idx;
6231 edef = (Elf_External_Verdef *) vstart;
6233 ent.vd_version = BYTE_GET (edef->vd_version);
6234 ent.vd_flags = BYTE_GET (edef->vd_flags);
6235 ent.vd_ndx = BYTE_GET (edef->vd_ndx);
6236 ent.vd_cnt = BYTE_GET (edef->vd_cnt);
6237 ent.vd_hash = BYTE_GET (edef->vd_hash);
6238 ent.vd_aux = BYTE_GET (edef->vd_aux);
6239 ent.vd_next = BYTE_GET (edef->vd_next);
6241 printf (_(" %#06x: Rev: %d Flags: %s"),
6242 idx, ent.vd_version, get_ver_flags (ent.vd_flags));
6244 printf (_(" Index: %d Cnt: %d "),
6245 ent.vd_ndx, ent.vd_cnt);
6247 vstart += ent.vd_aux;
6249 eaux = (Elf_External_Verdaux *) vstart;
6251 aux.vda_name = BYTE_GET (eaux->vda_name);
6252 aux.vda_next = BYTE_GET (eaux->vda_next);
6254 if (VALID_DYNAMIC_NAME (aux.vda_name))
6255 printf (_("Name: %s\n"), GET_DYNAMIC_NAME (aux.vda_name));
6257 printf (_("Name index: %ld\n"), aux.vda_name);
6259 isum = idx + ent.vd_aux;
6261 for (j = 1; j < ent.vd_cnt; j++)
6263 isum += aux.vda_next;
6264 vstart += aux.vda_next;
6266 eaux = (Elf_External_Verdaux *) vstart;
6268 aux.vda_name = BYTE_GET (eaux->vda_name);
6269 aux.vda_next = BYTE_GET (eaux->vda_next);
6271 if (VALID_DYNAMIC_NAME (aux.vda_name))
6272 printf (_(" %#06x: Parent %d: %s\n"),
6273 isum, j, GET_DYNAMIC_NAME (aux.vda_name));
6275 printf (_(" %#06x: Parent %d, name index: %ld\n"),
6276 isum, j, aux.vda_name);
6286 case SHT_GNU_verneed:
6288 Elf_External_Verneed *eneed;
6294 printf (_("\nVersion needs section '%s' contains %ld entries:\n"),
6295 SECTION_NAME (section), section->sh_info);
6297 printf (_(" Addr: 0x"));
6298 printf_vma (section->sh_addr);
6299 printf (_(" Offset: %#08lx Link to section: %ld (%s)\n"),
6300 (unsigned long) section->sh_offset, section->sh_link,
6301 SECTION_HEADER_INDEX (section->sh_link)
6302 < elf_header.e_shnum
6303 ? SECTION_NAME (SECTION_HEADER (section->sh_link))
6306 eneed = get_data (NULL, file, section->sh_offset, 1,
6308 _("version need section"));
6312 for (idx = cnt = 0; cnt < section->sh_info; ++cnt)
6314 Elf_External_Verneed *entry;
6315 Elf_Internal_Verneed ent;
6320 vstart = ((char *) eneed) + idx;
6322 entry = (Elf_External_Verneed *) vstart;
6324 ent.vn_version = BYTE_GET (entry->vn_version);
6325 ent.vn_cnt = BYTE_GET (entry->vn_cnt);
6326 ent.vn_file = BYTE_GET (entry->vn_file);
6327 ent.vn_aux = BYTE_GET (entry->vn_aux);
6328 ent.vn_next = BYTE_GET (entry->vn_next);
6330 printf (_(" %#06x: Version: %d"), idx, ent.vn_version);
6332 if (VALID_DYNAMIC_NAME (ent.vn_file))
6333 printf (_(" File: %s"), GET_DYNAMIC_NAME (ent.vn_file));
6335 printf (_(" File: %lx"), ent.vn_file);
6337 printf (_(" Cnt: %d\n"), ent.vn_cnt);
6339 vstart += ent.vn_aux;
6341 for (j = 0, isum = idx + ent.vn_aux; j < ent.vn_cnt; ++j)
6343 Elf_External_Vernaux *eaux;
6344 Elf_Internal_Vernaux aux;
6346 eaux = (Elf_External_Vernaux *) vstart;
6348 aux.vna_hash = BYTE_GET (eaux->vna_hash);
6349 aux.vna_flags = BYTE_GET (eaux->vna_flags);
6350 aux.vna_other = BYTE_GET (eaux->vna_other);
6351 aux.vna_name = BYTE_GET (eaux->vna_name);
6352 aux.vna_next = BYTE_GET (eaux->vna_next);
6354 if (VALID_DYNAMIC_NAME (aux.vna_name))
6355 printf (_(" %#06x: Name: %s"),
6356 isum, GET_DYNAMIC_NAME (aux.vna_name));
6358 printf (_(" %#06x: Name index: %lx"),
6359 isum, aux.vna_name);
6361 printf (_(" Flags: %s Version: %d\n"),
6362 get_ver_flags (aux.vna_flags), aux.vna_other);
6364 isum += aux.vna_next;
6365 vstart += aux.vna_next;
6375 case SHT_GNU_versym:
6377 Elf_Internal_Shdr *link_section;
6380 unsigned char *edata;
6381 unsigned short *data;
6383 Elf_Internal_Sym *symbols;
6384 Elf_Internal_Shdr *string_sec;
6387 if (SECTION_HEADER_INDEX (section->sh_link) >= elf_header.e_shnum)
6390 link_section = SECTION_HEADER (section->sh_link);
6391 total = section->sh_size / sizeof (Elf_External_Versym);
6393 if (SECTION_HEADER_INDEX (link_section->sh_link)
6394 >= elf_header.e_shnum)
6399 symbols = GET_ELF_SYMBOLS (file, link_section);
6401 string_sec = SECTION_HEADER (link_section->sh_link);
6403 strtab = get_data (NULL, file, string_sec->sh_offset, 1,
6404 string_sec->sh_size, _("version string table"));
6408 printf (_("\nVersion symbols section '%s' contains %d entries:\n"),
6409 SECTION_NAME (section), total);
6411 printf (_(" Addr: "));
6412 printf_vma (section->sh_addr);
6413 printf (_(" Offset: %#08lx Link: %lx (%s)\n"),
6414 (unsigned long) section->sh_offset, section->sh_link,
6415 SECTION_NAME (link_section));
6417 off = offset_from_vma (file,
6418 version_info[DT_VERSIONTAGIDX (DT_VERSYM)],
6419 total * sizeof (short));
6420 edata = get_data (NULL, file, off, total, sizeof (short),
6421 _("version symbol data"));
6428 data = cmalloc (total, sizeof (short));
6430 for (cnt = total; cnt --;)
6431 data[cnt] = byte_get (edata + cnt * sizeof (short),
6436 for (cnt = 0; cnt < total; cnt += 4)
6439 int check_def, check_need;
6442 printf (" %03x:", cnt);
6444 for (j = 0; (j < 4) && (cnt + j) < total; ++j)
6445 switch (data[cnt + j])
6448 fputs (_(" 0 (*local*) "), stdout);
6452 fputs (_(" 1 (*global*) "), stdout);
6456 nn = printf ("%4x%c", data[cnt + j] & 0x7fff,
6457 data[cnt + j] & 0x8000 ? 'h' : ' ');
6461 if (SECTION_HEADER_INDEX (symbols[cnt + j].st_shndx)
6462 >= elf_header.e_shnum
6463 || SECTION_HEADER (symbols[cnt + j].st_shndx)->sh_type
6466 if (symbols[cnt + j].st_shndx == SHN_UNDEF)
6473 && version_info[DT_VERSIONTAGIDX (DT_VERNEED)])
6475 Elf_Internal_Verneed ivn;
6476 unsigned long offset;
6478 offset = offset_from_vma
6479 (file, version_info[DT_VERSIONTAGIDX (DT_VERNEED)],
6480 sizeof (Elf_External_Verneed));
6484 Elf_Internal_Vernaux ivna;
6485 Elf_External_Verneed evn;
6486 Elf_External_Vernaux evna;
6487 unsigned long a_off;
6489 get_data (&evn, file, offset, sizeof (evn), 1,
6492 ivn.vn_aux = BYTE_GET (evn.vn_aux);
6493 ivn.vn_next = BYTE_GET (evn.vn_next);
6495 a_off = offset + ivn.vn_aux;
6499 get_data (&evna, file, a_off, sizeof (evna),
6500 1, _("version need aux (2)"));
6502 ivna.vna_next = BYTE_GET (evna.vna_next);
6503 ivna.vna_other = BYTE_GET (evna.vna_other);
6505 a_off += ivna.vna_next;
6507 while (ivna.vna_other != data[cnt + j]
6508 && ivna.vna_next != 0);
6510 if (ivna.vna_other == data[cnt + j])
6512 ivna.vna_name = BYTE_GET (evna.vna_name);
6514 name = strtab + ivna.vna_name;
6515 nn += printf ("(%s%-*s",
6517 12 - (int) strlen (name),
6523 offset += ivn.vn_next;
6525 while (ivn.vn_next);
6528 if (check_def && data[cnt + j] != 0x8001
6529 && version_info[DT_VERSIONTAGIDX (DT_VERDEF)])
6531 Elf_Internal_Verdef ivd;
6532 Elf_External_Verdef evd;
6533 unsigned long offset;
6535 offset = offset_from_vma
6536 (file, version_info[DT_VERSIONTAGIDX (DT_VERDEF)],
6541 get_data (&evd, file, offset, sizeof (evd), 1,
6544 ivd.vd_next = BYTE_GET (evd.vd_next);
6545 ivd.vd_ndx = BYTE_GET (evd.vd_ndx);
6547 offset += ivd.vd_next;
6549 while (ivd.vd_ndx != (data[cnt + j] & 0x7fff)
6550 && ivd.vd_next != 0);
6552 if (ivd.vd_ndx == (data[cnt + j] & 0x7fff))
6554 Elf_External_Verdaux evda;
6555 Elf_Internal_Verdaux ivda;
6557 ivd.vd_aux = BYTE_GET (evd.vd_aux);
6559 get_data (&evda, file,
6560 offset - ivd.vd_next + ivd.vd_aux,
6562 _("version def aux"));
6564 ivda.vda_name = BYTE_GET (evda.vda_name);
6566 name = strtab + ivda.vda_name;
6567 nn += printf ("(%s%-*s",
6569 12 - (int) strlen (name),
6575 printf ("%*c", 18 - nn, ' ');
6593 printf (_("\nNo version information found in this file.\n"));
6599 get_symbol_binding (unsigned int binding)
6601 static char buff[32];
6605 case STB_LOCAL: return "LOCAL";
6606 case STB_GLOBAL: return "GLOBAL";
6607 case STB_WEAK: return "WEAK";
6609 if (binding >= STB_LOPROC && binding <= STB_HIPROC)
6610 snprintf (buff, sizeof (buff), _("<processor specific>: %d"),
6612 else if (binding >= STB_LOOS && binding <= STB_HIOS)
6613 snprintf (buff, sizeof (buff), _("<OS specific>: %d"), binding);
6615 snprintf (buff, sizeof (buff), _("<unknown>: %d"), binding);
6621 get_symbol_type (unsigned int type)
6623 static char buff[32];
6627 case STT_NOTYPE: return "NOTYPE";
6628 case STT_OBJECT: return "OBJECT";
6629 case STT_FUNC: return "FUNC";
6630 case STT_SECTION: return "SECTION";
6631 case STT_FILE: return "FILE";
6632 case STT_COMMON: return "COMMON";
6633 case STT_TLS: return "TLS";
6635 if (type >= STT_LOPROC && type <= STT_HIPROC)
6637 if (elf_header.e_machine == EM_ARM && type == STT_ARM_TFUNC)
6638 return "THUMB_FUNC";
6640 if (elf_header.e_machine == EM_SPARCV9 && type == STT_REGISTER)
6643 if (elf_header.e_machine == EM_PARISC && type == STT_PARISC_MILLI)
6644 return "PARISC_MILLI";
6646 snprintf (buff, sizeof (buff), _("<processor specific>: %d"), type);
6648 else if (type >= STT_LOOS && type <= STT_HIOS)
6650 if (elf_header.e_machine == EM_PARISC)
6652 if (type == STT_HP_OPAQUE)
6654 if (type == STT_HP_STUB)
6658 snprintf (buff, sizeof (buff), _("<OS specific>: %d"), type);
6661 snprintf (buff, sizeof (buff), _("<unknown>: %d"), type);
6667 get_symbol_visibility (unsigned int visibility)
6671 case STV_DEFAULT: return "DEFAULT";
6672 case STV_INTERNAL: return "INTERNAL";
6673 case STV_HIDDEN: return "HIDDEN";
6674 case STV_PROTECTED: return "PROTECTED";
6680 get_symbol_index_type (unsigned int type)
6682 static char buff[32];
6686 case SHN_UNDEF: return "UND";
6687 case SHN_ABS: return "ABS";
6688 case SHN_COMMON: return "COM";
6690 if (type == SHN_IA_64_ANSI_COMMON
6691 && elf_header.e_machine == EM_IA_64
6692 && elf_header.e_ident[EI_OSABI] == ELFOSABI_HPUX)
6694 else if (type >= SHN_LOPROC && type <= SHN_HIPROC)
6695 sprintf (buff, "PRC[0x%04x]", type);
6696 else if (type >= SHN_LOOS && type <= SHN_HIOS)
6697 sprintf (buff, "OS [0x%04x]", type);
6698 else if (type >= SHN_LORESERVE && type <= SHN_HIRESERVE)
6699 sprintf (buff, "RSV[0x%04x]", type);
6701 sprintf (buff, "%3d", type);
6709 get_dynamic_data (FILE *file, unsigned int number, unsigned int ent_size)
6711 unsigned char *e_data;
6714 e_data = cmalloc (number, ent_size);
6718 error (_("Out of memory\n"));
6722 if (fread (e_data, ent_size, number, file) != number)
6724 error (_("Unable to read in dynamic data\n"));
6728 i_data = cmalloc (number, sizeof (*i_data));
6732 error (_("Out of memory\n"));
6738 i_data[number] = byte_get (e_data + number * ent_size, ent_size);
6745 /* Dump the symbol table. */
6747 process_symbol_table (FILE *file)
6749 Elf_Internal_Shdr *section;
6750 bfd_vma nbuckets = 0;
6751 bfd_vma nchains = 0;
6752 bfd_vma *buckets = NULL;
6753 bfd_vma *chains = NULL;
6755 if (! do_syms && !do_histogram)
6758 if (dynamic_info[DT_HASH] && ((do_using_dynamic && dynamic_strings != NULL)
6761 unsigned char nb[8];
6762 unsigned char nc[8];
6763 int hash_ent_size = 4;
6765 if ((elf_header.e_machine == EM_ALPHA
6766 || elf_header.e_machine == EM_S390
6767 || elf_header.e_machine == EM_S390_OLD)
6768 && elf_header.e_ident[EI_CLASS] == ELFCLASS64)
6772 (archive_file_offset
6773 + offset_from_vma (file, dynamic_info[DT_HASH],
6774 sizeof nb + sizeof nc)),
6777 error (_("Unable to seek to start of dynamic information"));
6781 if (fread (nb, hash_ent_size, 1, file) != 1)
6783 error (_("Failed to read in number of buckets\n"));
6787 if (fread (nc, hash_ent_size, 1, file) != 1)
6789 error (_("Failed to read in number of chains\n"));
6793 nbuckets = byte_get (nb, hash_ent_size);
6794 nchains = byte_get (nc, hash_ent_size);
6796 buckets = get_dynamic_data (file, nbuckets, hash_ent_size);
6797 chains = get_dynamic_data (file, nchains, hash_ent_size);
6799 if (buckets == NULL || chains == NULL)
6804 && dynamic_info[DT_HASH] && do_using_dynamic && dynamic_strings != NULL)
6809 printf (_("\nSymbol table for image:\n"));
6811 printf (_(" Num Buc: Value Size Type Bind Vis Ndx Name\n"));
6813 printf (_(" Num Buc: Value Size Type Bind Vis Ndx Name\n"));
6815 for (hn = 0; hn < nbuckets; hn++)
6820 for (si = buckets[hn]; si < nchains && si > 0; si = chains[si])
6822 Elf_Internal_Sym *psym;
6825 psym = dynamic_symbols + si;
6827 n = print_vma (si, DEC_5);
6829 fputs (" " + n, stdout);
6830 printf (" %3lu: ", hn);
6831 print_vma (psym->st_value, LONG_HEX);
6833 print_vma (psym->st_size, DEC_5);
6835 printf (" %6s", get_symbol_type (ELF_ST_TYPE (psym->st_info)));
6836 printf (" %6s", get_symbol_binding (ELF_ST_BIND (psym->st_info)));
6837 printf (" %3s", get_symbol_visibility (ELF_ST_VISIBILITY (psym->st_other)));
6838 printf (" %3.3s ", get_symbol_index_type (psym->st_shndx));
6839 if (VALID_DYNAMIC_NAME (psym->st_name))
6840 print_symbol (25, GET_DYNAMIC_NAME (psym->st_name));
6842 printf (" <corrupt: %14ld>", psym->st_name);
6847 else if (do_syms && !do_using_dynamic)
6851 for (i = 0, section = section_headers;
6852 i < elf_header.e_shnum;
6856 char *strtab = NULL;
6857 unsigned long int strtab_size = 0;
6858 Elf_Internal_Sym *symtab;
6859 Elf_Internal_Sym *psym;
6862 if ( section->sh_type != SHT_SYMTAB
6863 && section->sh_type != SHT_DYNSYM)
6866 printf (_("\nSymbol table '%s' contains %lu entries:\n"),
6867 SECTION_NAME (section),
6868 (unsigned long) (section->sh_size / section->sh_entsize));
6870 printf (_(" Num: Value Size Type Bind Vis Ndx Name\n"));
6872 printf (_(" Num: Value Size Type Bind Vis Ndx Name\n"));
6874 symtab = GET_ELF_SYMBOLS (file, section);
6878 if (section->sh_link == elf_header.e_shstrndx)
6880 strtab = string_table;
6881 strtab_size = string_table_length;
6883 else if (SECTION_HEADER_INDEX (section->sh_link) < elf_header.e_shnum)
6885 Elf_Internal_Shdr *string_sec;
6887 string_sec = SECTION_HEADER (section->sh_link);
6889 strtab = get_data (NULL, file, string_sec->sh_offset,
6890 1, string_sec->sh_size, _("string table"));
6891 strtab_size = strtab != NULL ? string_sec->sh_size : 0;
6894 for (si = 0, psym = symtab;
6895 si < section->sh_size / section->sh_entsize;
6898 printf ("%6d: ", si);
6899 print_vma (psym->st_value, LONG_HEX);
6901 print_vma (psym->st_size, DEC_5);
6902 printf (" %-7s", get_symbol_type (ELF_ST_TYPE (psym->st_info)));
6903 printf (" %-6s", get_symbol_binding (ELF_ST_BIND (psym->st_info)));
6904 printf (" %-3s", get_symbol_visibility (ELF_ST_VISIBILITY (psym->st_other)));
6905 printf (" %4s ", get_symbol_index_type (psym->st_shndx));
6906 print_symbol (25, psym->st_name < strtab_size
6907 ? strtab + psym->st_name : "<corrupt>");
6909 if (section->sh_type == SHT_DYNSYM &&
6910 version_info[DT_VERSIONTAGIDX (DT_VERSYM)] != 0)
6912 unsigned char data[2];
6913 unsigned short vers_data;
6914 unsigned long offset;
6918 offset = offset_from_vma
6919 (file, version_info[DT_VERSIONTAGIDX (DT_VERSYM)],
6920 sizeof data + si * sizeof (vers_data));
6922 get_data (&data, file, offset + si * sizeof (vers_data),
6923 sizeof (data), 1, _("version data"));
6925 vers_data = byte_get (data, 2);
6927 is_nobits = (SECTION_HEADER_INDEX (psym->st_shndx)
6928 < elf_header.e_shnum
6929 && SECTION_HEADER (psym->st_shndx)->sh_type
6932 check_def = (psym->st_shndx != SHN_UNDEF);
6934 if ((vers_data & 0x8000) || vers_data > 1)
6936 if (version_info[DT_VERSIONTAGIDX (DT_VERNEED)]
6937 && (is_nobits || ! check_def))
6939 Elf_External_Verneed evn;
6940 Elf_Internal_Verneed ivn;
6941 Elf_Internal_Vernaux ivna;
6943 /* We must test both. */
6944 offset = offset_from_vma
6945 (file, version_info[DT_VERSIONTAGIDX (DT_VERNEED)],
6950 unsigned long vna_off;
6952 get_data (&evn, file, offset, sizeof (evn), 1,
6955 ivn.vn_aux = BYTE_GET (evn.vn_aux);
6956 ivn.vn_next = BYTE_GET (evn.vn_next);
6958 vna_off = offset + ivn.vn_aux;
6962 Elf_External_Vernaux evna;
6964 get_data (&evna, file, vna_off,
6966 _("version need aux (3)"));
6968 ivna.vna_other = BYTE_GET (evna.vna_other);
6969 ivna.vna_next = BYTE_GET (evna.vna_next);
6970 ivna.vna_name = BYTE_GET (evna.vna_name);
6972 vna_off += ivna.vna_next;
6974 while (ivna.vna_other != vers_data
6975 && ivna.vna_next != 0);
6977 if (ivna.vna_other == vers_data)
6980 offset += ivn.vn_next;
6982 while (ivn.vn_next != 0);
6984 if (ivna.vna_other == vers_data)
6987 ivna.vna_name < strtab_size
6988 ? strtab + ivna.vna_name : "<corrupt>",
6992 else if (! is_nobits)
6993 error (_("bad dynamic symbol"));
7000 if (vers_data != 0x8001
7001 && version_info[DT_VERSIONTAGIDX (DT_VERDEF)])
7003 Elf_Internal_Verdef ivd;
7004 Elf_Internal_Verdaux ivda;
7005 Elf_External_Verdaux evda;
7006 unsigned long offset;
7008 offset = offset_from_vma
7010 version_info[DT_VERSIONTAGIDX (DT_VERDEF)],
7011 sizeof (Elf_External_Verdef));
7015 Elf_External_Verdef evd;
7017 get_data (&evd, file, offset, sizeof (evd),
7018 1, _("version def"));
7020 ivd.vd_ndx = BYTE_GET (evd.vd_ndx);
7021 ivd.vd_aux = BYTE_GET (evd.vd_aux);
7022 ivd.vd_next = BYTE_GET (evd.vd_next);
7024 offset += ivd.vd_next;
7026 while (ivd.vd_ndx != (vers_data & 0x7fff)
7027 && ivd.vd_next != 0);
7029 offset -= ivd.vd_next;
7030 offset += ivd.vd_aux;
7032 get_data (&evda, file, offset, sizeof (evda),
7033 1, _("version def aux"));
7035 ivda.vda_name = BYTE_GET (evda.vda_name);
7037 if (psym->st_name != ivda.vda_name)
7038 printf ((vers_data & 0x8000)
7040 ivda.vda_name < strtab_size
7041 ? strtab + ivda.vda_name : "<corrupt>");
7051 if (strtab != string_table)
7057 (_("\nDynamic symbol information is not available for displaying symbols.\n"));
7059 if (do_histogram && buckets != NULL)
7061 unsigned long *lengths;
7062 unsigned long *counts;
7065 unsigned long maxlength = 0;
7066 unsigned long nzero_counts = 0;
7067 unsigned long nsyms = 0;
7069 printf (_("\nHistogram for bucket list length (total of %lu buckets):\n"),
7070 (unsigned long) nbuckets);
7071 printf (_(" Length Number %% of total Coverage\n"));
7073 lengths = calloc (nbuckets, sizeof (*lengths));
7074 if (lengths == NULL)
7076 error (_("Out of memory"));
7079 for (hn = 0; hn < nbuckets; ++hn)
7081 for (si = buckets[hn]; si > 0 && si < nchains; si = chains[si])
7084 if (maxlength < ++lengths[hn])
7089 counts = calloc (maxlength + 1, sizeof (*counts));
7092 error (_("Out of memory"));
7096 for (hn = 0; hn < nbuckets; ++hn)
7097 ++counts[lengths[hn]];
7102 printf (" 0 %-10lu (%5.1f%%)\n",
7103 counts[0], (counts[0] * 100.0) / nbuckets);
7104 for (i = 1; i <= maxlength; ++i)
7106 nzero_counts += counts[i] * i;
7107 printf ("%7lu %-10lu (%5.1f%%) %5.1f%%\n",
7108 i, counts[i], (counts[i] * 100.0) / nbuckets,
7109 (nzero_counts * 100.0) / nsyms);
7117 if (buckets != NULL)
7127 process_syminfo (FILE *file ATTRIBUTE_UNUSED)
7131 if (dynamic_syminfo == NULL
7133 /* No syminfo, this is ok. */
7136 /* There better should be a dynamic symbol section. */
7137 if (dynamic_symbols == NULL || dynamic_strings == NULL)
7141 printf (_("\nDynamic info segment at offset 0x%lx contains %d entries:\n"),
7142 dynamic_syminfo_offset, dynamic_syminfo_nent);
7144 printf (_(" Num: Name BoundTo Flags\n"));
7145 for (i = 0; i < dynamic_syminfo_nent; ++i)
7147 unsigned short int flags = dynamic_syminfo[i].si_flags;
7149 printf ("%4d: ", i);
7150 if (VALID_DYNAMIC_NAME (dynamic_symbols[i].st_name))
7151 print_symbol (30, GET_DYNAMIC_NAME (dynamic_symbols[i].st_name));
7153 printf ("<corrupt: %19ld>", dynamic_symbols[i].st_name);
7156 switch (dynamic_syminfo[i].si_boundto)
7158 case SYMINFO_BT_SELF:
7159 fputs ("SELF ", stdout);
7161 case SYMINFO_BT_PARENT:
7162 fputs ("PARENT ", stdout);
7165 if (dynamic_syminfo[i].si_boundto > 0
7166 && dynamic_syminfo[i].si_boundto < dynamic_nent
7167 && VALID_DYNAMIC_NAME (dynamic_section[dynamic_syminfo[i].si_boundto].d_un.d_val))
7169 print_symbol (10, GET_DYNAMIC_NAME (dynamic_section[dynamic_syminfo[i].si_boundto].d_un.d_val));
7173 printf ("%-10d ", dynamic_syminfo[i].si_boundto);
7177 if (flags & SYMINFO_FLG_DIRECT)
7179 if (flags & SYMINFO_FLG_PASSTHRU)
7180 printf (" PASSTHRU");
7181 if (flags & SYMINFO_FLG_COPY)
7183 if (flags & SYMINFO_FLG_LAZYLOAD)
7184 printf (" LAZYLOAD");
7192 #ifdef SUPPORT_DISASSEMBLY
7194 disassemble_section (Elf_Internal_Shdr *section, FILE *file)
7196 printf (_("\nAssembly dump of section %s\n"),
7197 SECTION_NAME (section));
7199 /* XXX -- to be done --- XXX */
7206 dump_section (Elf_Internal_Shdr *section, FILE *file)
7208 bfd_size_type bytes;
7210 unsigned char *data;
7211 unsigned char *start;
7213 bytes = section->sh_size;
7215 if (bytes == 0 || section->sh_type == SHT_NOBITS)
7217 printf (_("\nSection '%s' has no data to dump.\n"),
7218 SECTION_NAME (section));
7222 printf (_("\nHex dump of section '%s':\n"), SECTION_NAME (section));
7224 addr = section->sh_addr;
7226 start = get_data (NULL, file, section->sh_offset, 1, bytes,
7239 lbytes = (bytes > 16 ? 16 : bytes);
7241 printf (" 0x%8.8lx ", (unsigned long) addr);
7243 switch (elf_header.e_ident[EI_DATA])
7247 for (j = 15; j >= 0; j --)
7250 printf ("%2.2x", data[j]);
7260 for (j = 0; j < 16; j++)
7263 printf ("%2.2x", data[j]);
7273 for (j = 0; j < lbytes; j++)
7276 if (k >= ' ' && k < 0x7f)
7295 static unsigned long int
7296 read_leb128 (unsigned char *data, unsigned int *length_return, int sign)
7298 unsigned long int result = 0;
7299 unsigned int num_read = 0;
7300 unsigned int shift = 0;
7308 result |= ((unsigned long int) (byte & 0x7f)) << shift;
7313 while (byte & 0x80);
7315 if (length_return != NULL)
7316 *length_return = num_read;
7318 if (sign && (shift < 8 * sizeof (result)) && (byte & 0x40))
7319 result |= -1L << shift;
7324 typedef struct State_Machine_Registers
7326 unsigned long address;
7329 unsigned int column;
7333 /* This variable hold the number of the last entry seen
7334 in the File Table. */
7335 unsigned int last_file_entry;
7338 static SMR state_machine_regs;
7341 reset_state_machine (int is_stmt)
7343 state_machine_regs.address = 0;
7344 state_machine_regs.file = 1;
7345 state_machine_regs.line = 1;
7346 state_machine_regs.column = 0;
7347 state_machine_regs.is_stmt = is_stmt;
7348 state_machine_regs.basic_block = 0;
7349 state_machine_regs.end_sequence = 0;
7350 state_machine_regs.last_file_entry = 0;
7353 /* Handled an extend line op.
7354 Returns the number of bytes read. */
7357 process_extended_line_op (unsigned char *data, int is_stmt, int pointer_size)
7359 unsigned char op_code;
7360 unsigned int bytes_read;
7362 unsigned char *name;
7365 len = read_leb128 (data, & bytes_read, 0);
7370 warn (_("badly formed extended line op encountered!\n"));
7377 printf (_(" Extended opcode %d: "), op_code);
7381 case DW_LNE_end_sequence:
7382 printf (_("End of Sequence\n\n"));
7383 reset_state_machine (is_stmt);
7386 case DW_LNE_set_address:
7387 adr = byte_get (data, pointer_size);
7388 printf (_("set Address to 0x%lx\n"), adr);
7389 state_machine_regs.address = adr;
7392 case DW_LNE_define_file:
7393 printf (_(" define new File Table entry\n"));
7394 printf (_(" Entry\tDir\tTime\tSize\tName\n"));
7396 printf (_(" %d\t"), ++state_machine_regs.last_file_entry);
7398 data += strlen ((char *) data) + 1;
7399 printf (_("%lu\t"), read_leb128 (data, & bytes_read, 0));
7401 printf (_("%lu\t"), read_leb128 (data, & bytes_read, 0));
7403 printf (_("%lu\t"), read_leb128 (data, & bytes_read, 0));
7404 printf (_("%s\n\n"), name);
7408 printf (_("UNKNOWN: length %d\n"), len - bytes_read);
7415 static const char *debug_str_contents;
7416 static bfd_vma debug_str_size;
7419 load_debug_str (FILE *file)
7421 Elf_Internal_Shdr *sec;
7423 /* If it is already loaded, do nothing. */
7424 if (debug_str_contents != NULL)
7427 /* Locate the .debug_str section. */
7428 sec = find_section (".debug_str");
7432 debug_str_size = sec->sh_size;
7434 debug_str_contents = get_data (NULL, file, sec->sh_offset, 1, sec->sh_size,
7435 _("debug_str section data"));
7439 free_debug_str (void)
7441 if (debug_str_contents == NULL)
7444 free ((char *) debug_str_contents);
7445 debug_str_contents = NULL;
7450 fetch_indirect_string (unsigned long offset)
7452 if (debug_str_contents == NULL)
7453 return _("<no .debug_str section>");
7455 if (offset > debug_str_size)
7457 warn (_("DW_FORM_strp offset too big: %lx\n"), offset);
7458 return _("<offset is too big>");
7461 return debug_str_contents + offset;
7464 static const char *debug_loc_contents;
7465 static bfd_vma debug_loc_size;
7468 load_debug_loc (FILE *file)
7470 Elf_Internal_Shdr *sec;
7472 /* If it is already loaded, do nothing. */
7473 if (debug_loc_contents != NULL)
7476 /* Locate the .debug_loc section. */
7477 sec = find_section (".debug_loc");
7481 debug_loc_size = sec->sh_size;
7483 debug_loc_contents = get_data (NULL, file, sec->sh_offset, 1, sec->sh_size,
7484 _("debug_loc section data"));
7488 free_debug_loc (void)
7490 if (debug_loc_contents == NULL)
7493 free ((char *) debug_loc_contents);
7494 debug_loc_contents = NULL;
7498 static const char * debug_range_contents;
7499 static unsigned long debug_range_size;
7502 load_debug_range (FILE *file)
7504 Elf_Internal_Shdr *sec;
7506 /* If it is already loaded, do nothing. */
7507 if (debug_range_contents != NULL)
7510 /* Locate the .debug_ranges section. */
7511 sec = find_section (".debug_ranges");
7515 debug_range_size = sec->sh_size;
7517 debug_range_contents = get_data (NULL, file, sec->sh_offset, 1, sec->sh_size,
7518 _("debug_range section data"));
7522 free_debug_range (void)
7524 if (debug_range_contents == NULL)
7527 free ((char *) debug_range_contents);
7528 debug_range_contents = NULL;
7529 debug_range_size = 0;
7532 /* Apply addends of RELA relocations. */
7535 debug_apply_rela_addends (FILE *file,
7536 Elf_Internal_Shdr *section,
7538 unsigned char *sec_data,
7539 unsigned char *start,
7542 Elf_Internal_Shdr *relsec;
7544 if (end - start < reloc_size)
7547 for (relsec = section_headers;
7548 relsec < section_headers + elf_header.e_shnum;
7551 unsigned long nrelas;
7552 Elf_Internal_Rela *rela, *rp;
7553 Elf_Internal_Shdr *symsec;
7554 Elf_Internal_Sym *symtab;
7555 Elf_Internal_Sym *sym;
7557 if (relsec->sh_type != SHT_RELA
7558 || SECTION_HEADER_INDEX (relsec->sh_info) >= elf_header.e_shnum
7559 || SECTION_HEADER (relsec->sh_info) != section
7560 || relsec->sh_size == 0
7561 || SECTION_HEADER_INDEX (relsec->sh_link) >= elf_header.e_shnum)
7564 if (!slurp_rela_relocs (file, relsec->sh_offset, relsec->sh_size,
7568 symsec = SECTION_HEADER (relsec->sh_link);
7569 symtab = GET_ELF_SYMBOLS (file, symsec);
7571 for (rp = rela; rp < rela + nrelas; ++rp)
7575 if (rp->r_offset >= (bfd_vma) (start - sec_data)
7576 && rp->r_offset < (bfd_vma) (end - sec_data) - reloc_size)
7577 loc = sec_data + rp->r_offset;
7583 sym = symtab + ELF32_R_SYM (rp->r_info);
7585 if (ELF32_R_SYM (rp->r_info) != 0
7586 && ELF32_ST_TYPE (sym->st_info) != STT_SECTION
7587 /* Relocations against object symbols can happen,
7588 eg when referencing a global array. For an
7589 example of this see the _clz.o binary in libgcc.a. */
7590 && ELF32_ST_TYPE (sym->st_info) != STT_OBJECT)
7592 warn (_("skipping unexpected symbol type %s in relocation in section .rela%s\n"),
7593 get_symbol_type (ELF32_ST_TYPE (sym->st_info)),
7594 SECTION_NAME (section));
7600 /* In MIPS little-endian objects, r_info isn't really a
7601 64-bit little-endian value: it has a 32-bit little-endian
7602 symbol index followed by four individual byte fields.
7603 Reorder INFO accordingly. */
7604 if (elf_header.e_machine == EM_MIPS
7605 && elf_header.e_ident[EI_DATA] != ELFDATA2MSB)
7606 rp->r_info = (((rp->r_info & 0xffffffff) << 32)
7607 | ((rp->r_info >> 56) & 0xff)
7608 | ((rp->r_info >> 40) & 0xff00)
7609 | ((rp->r_info >> 24) & 0xff0000)
7610 | ((rp->r_info >> 8) & 0xff000000));
7612 sym = symtab + ELF64_R_SYM (rp->r_info);
7614 if (ELF64_R_SYM (rp->r_info) != 0
7615 && ELF64_ST_TYPE (sym->st_info) != STT_SECTION
7616 && ELF64_ST_TYPE (sym->st_info) != STT_OBJECT)
7618 warn (_("skipping unexpected symbol type %s in relocation in section .rela.%s\n"),
7619 get_symbol_type (ELF64_ST_TYPE (sym->st_info)),
7620 SECTION_NAME (section));
7625 byte_put (loc, rp->r_addend, reloc_size);
7635 /* FIXME: There are better and more efficient ways to handle
7636 these structures. For now though, I just want something that
7637 is simple to implement. */
7638 typedef struct abbrev_attr
7640 unsigned long attribute;
7642 struct abbrev_attr *next;
7646 typedef struct abbrev_entry
7648 unsigned long entry;
7651 struct abbrev_attr *first_attr;
7652 struct abbrev_attr *last_attr;
7653 struct abbrev_entry *next;
7657 static abbrev_entry *first_abbrev = NULL;
7658 static abbrev_entry *last_abbrev = NULL;
7663 abbrev_entry *abbrev;
7665 for (abbrev = first_abbrev; abbrev;)
7667 abbrev_entry *next = abbrev->next;
7670 for (attr = abbrev->first_attr; attr;)
7672 abbrev_attr *next = attr->next;
7682 last_abbrev = first_abbrev = NULL;
7686 add_abbrev (unsigned long number, unsigned long tag, int children)
7688 abbrev_entry *entry;
7690 entry = malloc (sizeof (*entry));
7696 entry->entry = number;
7698 entry->children = children;
7699 entry->first_attr = NULL;
7700 entry->last_attr = NULL;
7703 if (first_abbrev == NULL)
7704 first_abbrev = entry;
7706 last_abbrev->next = entry;
7708 last_abbrev = entry;
7712 add_abbrev_attr (unsigned long attribute, unsigned long form)
7716 attr = malloc (sizeof (*attr));
7722 attr->attribute = attribute;
7726 if (last_abbrev->first_attr == NULL)
7727 last_abbrev->first_attr = attr;
7729 last_abbrev->last_attr->next = attr;
7731 last_abbrev->last_attr = attr;
7734 /* Processes the (partial) contents of a .debug_abbrev section.
7735 Returns NULL if the end of the section was encountered.
7736 Returns the address after the last byte read if the end of
7737 an abbreviation set was found. */
7739 static unsigned char *
7740 process_abbrev_section (unsigned char *start, unsigned char *end)
7742 if (first_abbrev != NULL)
7747 unsigned int bytes_read;
7748 unsigned long entry;
7750 unsigned long attribute;
7753 entry = read_leb128 (start, & bytes_read, 0);
7754 start += bytes_read;
7756 /* A single zero is supposed to end the section according
7757 to the standard. If there's more, then signal that to
7760 return start == end ? NULL : start;
7762 tag = read_leb128 (start, & bytes_read, 0);
7763 start += bytes_read;
7765 children = *start++;
7767 add_abbrev (entry, tag, children);
7773 attribute = read_leb128 (start, & bytes_read, 0);
7774 start += bytes_read;
7776 form = read_leb128 (start, & bytes_read, 0);
7777 start += bytes_read;
7780 add_abbrev_attr (attribute, form);
7782 while (attribute != 0);
7789 get_TAG_name (unsigned long tag)
7793 case DW_TAG_padding: return "DW_TAG_padding";
7794 case DW_TAG_array_type: return "DW_TAG_array_type";
7795 case DW_TAG_class_type: return "DW_TAG_class_type";
7796 case DW_TAG_entry_point: return "DW_TAG_entry_point";
7797 case DW_TAG_enumeration_type: return "DW_TAG_enumeration_type";
7798 case DW_TAG_formal_parameter: return "DW_TAG_formal_parameter";
7799 case DW_TAG_imported_declaration: return "DW_TAG_imported_declaration";
7800 case DW_TAG_label: return "DW_TAG_label";
7801 case DW_TAG_lexical_block: return "DW_TAG_lexical_block";
7802 case DW_TAG_member: return "DW_TAG_member";
7803 case DW_TAG_pointer_type: return "DW_TAG_pointer_type";
7804 case DW_TAG_reference_type: return "DW_TAG_reference_type";
7805 case DW_TAG_compile_unit: return "DW_TAG_compile_unit";
7806 case DW_TAG_string_type: return "DW_TAG_string_type";
7807 case DW_TAG_structure_type: return "DW_TAG_structure_type";
7808 case DW_TAG_subroutine_type: return "DW_TAG_subroutine_type";
7809 case DW_TAG_typedef: return "DW_TAG_typedef";
7810 case DW_TAG_union_type: return "DW_TAG_union_type";
7811 case DW_TAG_unspecified_parameters: return "DW_TAG_unspecified_parameters";
7812 case DW_TAG_variant: return "DW_TAG_variant";
7813 case DW_TAG_common_block: return "DW_TAG_common_block";
7814 case DW_TAG_common_inclusion: return "DW_TAG_common_inclusion";
7815 case DW_TAG_inheritance: return "DW_TAG_inheritance";
7816 case DW_TAG_inlined_subroutine: return "DW_TAG_inlined_subroutine";
7817 case DW_TAG_module: return "DW_TAG_module";
7818 case DW_TAG_ptr_to_member_type: return "DW_TAG_ptr_to_member_type";
7819 case DW_TAG_set_type: return "DW_TAG_set_type";
7820 case DW_TAG_subrange_type: return "DW_TAG_subrange_type";
7821 case DW_TAG_with_stmt: return "DW_TAG_with_stmt";
7822 case DW_TAG_access_declaration: return "DW_TAG_access_declaration";
7823 case DW_TAG_base_type: return "DW_TAG_base_type";
7824 case DW_TAG_catch_block: return "DW_TAG_catch_block";
7825 case DW_TAG_const_type: return "DW_TAG_const_type";
7826 case DW_TAG_constant: return "DW_TAG_constant";
7827 case DW_TAG_enumerator: return "DW_TAG_enumerator";
7828 case DW_TAG_file_type: return "DW_TAG_file_type";
7829 case DW_TAG_friend: return "DW_TAG_friend";
7830 case DW_TAG_namelist: return "DW_TAG_namelist";
7831 case DW_TAG_namelist_item: return "DW_TAG_namelist_item";
7832 case DW_TAG_packed_type: return "DW_TAG_packed_type";
7833 case DW_TAG_subprogram: return "DW_TAG_subprogram";
7834 case DW_TAG_template_type_param: return "DW_TAG_template_type_param";
7835 case DW_TAG_template_value_param: return "DW_TAG_template_value_param";
7836 case DW_TAG_thrown_type: return "DW_TAG_thrown_type";
7837 case DW_TAG_try_block: return "DW_TAG_try_block";
7838 case DW_TAG_variant_part: return "DW_TAG_variant_part";
7839 case DW_TAG_variable: return "DW_TAG_variable";
7840 case DW_TAG_volatile_type: return "DW_TAG_volatile_type";
7841 case DW_TAG_MIPS_loop: return "DW_TAG_MIPS_loop";
7842 case DW_TAG_format_label: return "DW_TAG_format_label";
7843 case DW_TAG_function_template: return "DW_TAG_function_template";
7844 case DW_TAG_class_template: return "DW_TAG_class_template";
7845 /* DWARF 2.1 values. */
7846 case DW_TAG_dwarf_procedure: return "DW_TAG_dwarf_procedure";
7847 case DW_TAG_restrict_type: return "DW_TAG_restrict_type";
7848 case DW_TAG_interface_type: return "DW_TAG_interface_type";
7849 case DW_TAG_namespace: return "DW_TAG_namespace";
7850 case DW_TAG_imported_module: return "DW_TAG_imported_module";
7851 case DW_TAG_unspecified_type: return "DW_TAG_unspecified_type";
7852 case DW_TAG_partial_unit: return "DW_TAG_partial_unit";
7853 case DW_TAG_imported_unit: return "DW_TAG_imported_unit";
7855 case DW_TAG_upc_shared_type: return "DW_TAG_upc_shared_type";
7856 case DW_TAG_upc_strict_type: return "DW_TAG_upc_strict_type";
7857 case DW_TAG_upc_relaxed_type: return "DW_TAG_upc_relaxed_type";
7860 static char buffer[100];
7862 snprintf (buffer, sizeof (buffer), _("Unknown TAG value: %lx"), tag);
7869 get_FORM_name (unsigned long form)
7873 case DW_FORM_addr: return "DW_FORM_addr";
7874 case DW_FORM_block2: return "DW_FORM_block2";
7875 case DW_FORM_block4: return "DW_FORM_block4";
7876 case DW_FORM_data2: return "DW_FORM_data2";
7877 case DW_FORM_data4: return "DW_FORM_data4";
7878 case DW_FORM_data8: return "DW_FORM_data8";
7879 case DW_FORM_string: return "DW_FORM_string";
7880 case DW_FORM_block: return "DW_FORM_block";
7881 case DW_FORM_block1: return "DW_FORM_block1";
7882 case DW_FORM_data1: return "DW_FORM_data1";
7883 case DW_FORM_flag: return "DW_FORM_flag";
7884 case DW_FORM_sdata: return "DW_FORM_sdata";
7885 case DW_FORM_strp: return "DW_FORM_strp";
7886 case DW_FORM_udata: return "DW_FORM_udata";
7887 case DW_FORM_ref_addr: return "DW_FORM_ref_addr";
7888 case DW_FORM_ref1: return "DW_FORM_ref1";
7889 case DW_FORM_ref2: return "DW_FORM_ref2";
7890 case DW_FORM_ref4: return "DW_FORM_ref4";
7891 case DW_FORM_ref8: return "DW_FORM_ref8";
7892 case DW_FORM_ref_udata: return "DW_FORM_ref_udata";
7893 case DW_FORM_indirect: return "DW_FORM_indirect";
7896 static char buffer[100];
7898 snprintf (buffer, sizeof (buffer), _("Unknown FORM value: %lx"), form);
7904 static unsigned char *
7905 display_block (unsigned char *data, unsigned long length)
7907 printf (_(" %lu byte block: "), length);
7910 printf ("%lx ", (unsigned long) byte_get (data++, 1));
7916 decode_location_expression (unsigned char * data,
7917 unsigned int pointer_size,
7918 unsigned long length,
7919 unsigned long cu_offset)
7922 unsigned int bytes_read;
7923 unsigned long uvalue;
7924 unsigned char *end = data + length;
7925 int need_frame_base = 0;
7934 printf ("DW_OP_addr: %lx",
7935 (unsigned long) byte_get (data, pointer_size));
7936 data += pointer_size;
7939 printf ("DW_OP_deref");
7942 printf ("DW_OP_const1u: %lu", (unsigned long) byte_get (data++, 1));
7945 printf ("DW_OP_const1s: %ld", (long) byte_get_signed (data++, 1));
7948 printf ("DW_OP_const2u: %lu", (unsigned long) byte_get (data, 2));
7952 printf ("DW_OP_const2s: %ld", (long) byte_get_signed (data, 2));
7956 printf ("DW_OP_const4u: %lu", (unsigned long) byte_get (data, 4));
7960 printf ("DW_OP_const4s: %ld", (long) byte_get_signed (data, 4));
7964 printf ("DW_OP_const8u: %lu %lu", (unsigned long) byte_get (data, 4),
7965 (unsigned long) byte_get (data + 4, 4));
7969 printf ("DW_OP_const8s: %ld %ld", (long) byte_get (data, 4),
7970 (long) byte_get (data + 4, 4));
7974 printf ("DW_OP_constu: %lu", read_leb128 (data, &bytes_read, 0));
7978 printf ("DW_OP_consts: %ld", read_leb128 (data, &bytes_read, 1));
7982 printf ("DW_OP_dup");
7985 printf ("DW_OP_drop");
7988 printf ("DW_OP_over");
7991 printf ("DW_OP_pick: %ld", (unsigned long) byte_get (data++, 1));
7994 printf ("DW_OP_swap");
7997 printf ("DW_OP_rot");
8000 printf ("DW_OP_xderef");
8003 printf ("DW_OP_abs");
8006 printf ("DW_OP_and");
8009 printf ("DW_OP_div");
8012 printf ("DW_OP_minus");
8015 printf ("DW_OP_mod");
8018 printf ("DW_OP_mul");
8021 printf ("DW_OP_neg");
8024 printf ("DW_OP_not");
8027 printf ("DW_OP_or");
8030 printf ("DW_OP_plus");
8032 case DW_OP_plus_uconst:
8033 printf ("DW_OP_plus_uconst: %lu",
8034 read_leb128 (data, &bytes_read, 0));
8038 printf ("DW_OP_shl");
8041 printf ("DW_OP_shr");
8044 printf ("DW_OP_shra");
8047 printf ("DW_OP_xor");
8050 printf ("DW_OP_bra: %ld", (long) byte_get_signed (data, 2));
8054 printf ("DW_OP_eq");
8057 printf ("DW_OP_ge");
8060 printf ("DW_OP_gt");
8063 printf ("DW_OP_le");
8066 printf ("DW_OP_lt");
8069 printf ("DW_OP_ne");
8072 printf ("DW_OP_skip: %ld", (long) byte_get_signed (data, 2));
8108 printf ("DW_OP_lit%d", op - DW_OP_lit0);
8143 printf ("DW_OP_reg%d", op - DW_OP_reg0);
8178 printf ("DW_OP_breg%d: %ld", op - DW_OP_breg0,
8179 read_leb128 (data, &bytes_read, 1));
8184 printf ("DW_OP_regx: %lu", read_leb128 (data, &bytes_read, 0));
8188 need_frame_base = 1;
8189 printf ("DW_OP_fbreg: %ld", read_leb128 (data, &bytes_read, 1));
8193 uvalue = read_leb128 (data, &bytes_read, 0);
8195 printf ("DW_OP_bregx: %lu %ld", uvalue,
8196 read_leb128 (data, &bytes_read, 1));
8200 printf ("DW_OP_piece: %lu", read_leb128 (data, &bytes_read, 0));
8203 case DW_OP_deref_size:
8204 printf ("DW_OP_deref_size: %ld", (long) byte_get (data++, 1));
8206 case DW_OP_xderef_size:
8207 printf ("DW_OP_xderef_size: %ld", (long) byte_get (data++, 1));
8210 printf ("DW_OP_nop");
8213 /* DWARF 3 extensions. */
8214 case DW_OP_push_object_address:
8215 printf ("DW_OP_push_object_address");
8218 /* XXX: Strictly speaking for 64-bit DWARF3 files
8219 this ought to be an 8-byte wide computation. */
8220 printf ("DW_OP_call2: <%lx>", (long) byte_get (data, 2) + cu_offset);
8224 /* XXX: Strictly speaking for 64-bit DWARF3 files
8225 this ought to be an 8-byte wide computation. */
8226 printf ("DW_OP_call4: <%lx>", (long) byte_get (data, 4) + cu_offset);
8229 case DW_OP_call_ref:
8230 printf ("DW_OP_call_ref");
8233 /* GNU extensions. */
8234 case DW_OP_GNU_push_tls_address:
8235 printf ("DW_OP_GNU_push_tls_address");
8239 if (op >= DW_OP_lo_user
8240 && op <= DW_OP_hi_user)
8241 printf (_("(User defined location op)"));
8243 printf (_("(Unknown location op)"));
8244 /* No way to tell where the next op is, so just bail. */
8245 return need_frame_base;
8248 /* Separate the ops. */
8253 return need_frame_base;
8256 /* This structure records the information that
8257 we extract from the.debug_info section. */
8260 unsigned int pointer_size;
8261 unsigned long cu_offset;
8262 unsigned long base_address;
8263 /* This is an array of offsets to the location list table. */
8264 unsigned long *loc_offsets;
8265 int *have_frame_base;
8266 unsigned int num_loc_offsets;
8267 unsigned int max_loc_offsets;
8268 unsigned long *range_lists;
8269 unsigned int num_range_lists;
8270 unsigned int max_range_lists;
8274 static debug_info * debug_information = NULL;
8275 static unsigned int num_debug_info_entries = 0;
8276 static unsigned int last_pointer_size = 0;
8277 static int warned_about_missing_comp_units = FALSE;
8279 static unsigned char *
8280 read_and_display_attr_value (unsigned long attribute,
8282 unsigned char *data,
8283 unsigned long cu_offset,
8284 unsigned long pointer_size,
8285 unsigned long offset_size,
8287 debug_info *debug_info_p,
8290 unsigned long uvalue = 0;
8291 unsigned char *block_start = NULL;
8292 unsigned int bytes_read;
8299 case DW_FORM_ref_addr:
8300 if (dwarf_version == 2)
8302 uvalue = byte_get (data, pointer_size);
8303 data += pointer_size;
8305 else if (dwarf_version == 3)
8307 uvalue = byte_get (data, offset_size);
8308 data += offset_size;
8312 error (_("Internal error: DWARF version is not 2 or 3.\n"));
8317 uvalue = byte_get (data, pointer_size);
8318 data += pointer_size;
8322 uvalue = byte_get (data, offset_size);
8323 data += offset_size;
8329 uvalue = byte_get (data++, 1);
8334 uvalue = byte_get (data, 2);
8340 uvalue = byte_get (data, 4);
8345 uvalue = read_leb128 (data, & bytes_read, 1);
8349 case DW_FORM_ref_udata:
8351 uvalue = read_leb128 (data, & bytes_read, 0);
8355 case DW_FORM_indirect:
8356 form = read_leb128 (data, & bytes_read, 0);
8359 printf (" %s", get_FORM_name (form));
8360 return read_and_display_attr_value (attribute, form, data,
8361 cu_offset, pointer_size,
8362 offset_size, dwarf_version,
8363 debug_info_p, do_loc);
8368 case DW_FORM_ref_addr:
8370 printf (" <#%lx>", uvalue);
8376 case DW_FORM_ref_udata:
8378 printf (" <%lx>", uvalue + cu_offset);
8384 printf (" %#lx", uvalue);
8393 printf (" %ld", uvalue);
8400 uvalue = byte_get (data, 4);
8401 printf (" %lx", uvalue);
8402 printf (" %lx", (unsigned long) byte_get (data + 4, 4));
8404 if ((do_loc || do_debug_loc || do_debug_ranges)
8405 && num_debug_info_entries == 0)
8407 if (sizeof (uvalue) == 8)
8408 uvalue = byte_get (data, 8);
8410 error (_("DW_FORM_data8 is unsupported when sizeof (unsigned long) != 8\n"));
8415 case DW_FORM_string:
8417 printf (" %s", data);
8418 data += strlen ((char *) data) + 1;
8422 uvalue = read_leb128 (data, & bytes_read, 0);
8423 block_start = data + bytes_read;
8425 data = block_start + uvalue;
8427 data = display_block (block_start, uvalue);
8430 case DW_FORM_block1:
8431 uvalue = byte_get (data, 1);
8432 block_start = data + 1;
8434 data = block_start + uvalue;
8436 data = display_block (block_start, uvalue);
8439 case DW_FORM_block2:
8440 uvalue = byte_get (data, 2);
8441 block_start = data + 2;
8443 data = block_start + uvalue;
8445 data = display_block (block_start, uvalue);
8448 case DW_FORM_block4:
8449 uvalue = byte_get (data, 4);
8450 block_start = data + 4;
8452 data = block_start + uvalue;
8454 data = display_block (block_start, uvalue);
8459 printf (_(" (indirect string, offset: 0x%lx): %s"),
8460 uvalue, fetch_indirect_string (uvalue));
8463 case DW_FORM_indirect:
8464 /* Handled above. */
8468 warn (_("Unrecognized form: %lu\n"), form);
8472 /* For some attributes we can display further information. */
8473 if ((do_loc || do_debug_loc || do_debug_ranges)
8474 && num_debug_info_entries == 0)
8478 case DW_AT_frame_base:
8479 have_frame_base = 1;
8480 case DW_AT_location:
8481 case DW_AT_data_member_location:
8482 case DW_AT_vtable_elem_location:
8483 case DW_AT_allocated:
8484 case DW_AT_associated:
8485 case DW_AT_data_location:
8487 case DW_AT_upper_bound:
8488 case DW_AT_lower_bound:
8489 if (form == DW_FORM_data4 || form == DW_FORM_data8)
8491 /* Process location list. */
8492 unsigned int max = debug_info_p->max_loc_offsets;
8493 unsigned int num = debug_info_p->num_loc_offsets;
8495 if (max == 0 || num >= max)
8498 debug_info_p->loc_offsets
8499 = xcrealloc (debug_info_p->loc_offsets,
8500 max, sizeof (*debug_info_p->loc_offsets));
8501 debug_info_p->have_frame_base
8502 = xcrealloc (debug_info_p->have_frame_base,
8503 max, sizeof (*debug_info_p->have_frame_base));
8504 debug_info_p->max_loc_offsets = max;
8506 debug_info_p->loc_offsets [num] = uvalue;
8507 debug_info_p->have_frame_base [num] = have_frame_base;
8508 debug_info_p->num_loc_offsets++;
8513 if (need_base_address)
8514 debug_info_p->base_address = uvalue;
8518 if (form == DW_FORM_data4 || form == DW_FORM_data8)
8520 /* Process range list. */
8521 unsigned int max = debug_info_p->max_range_lists;
8522 unsigned int num = debug_info_p->num_range_lists;
8524 if (max == 0 || num >= max)
8527 debug_info_p->range_lists
8528 = xcrealloc (debug_info_p->range_lists,
8529 max, sizeof (*debug_info_p->range_lists));
8530 debug_info_p->max_range_lists = max;
8532 debug_info_p->range_lists [num] = uvalue;
8533 debug_info_p->num_range_lists++;
8552 case DW_INL_not_inlined:
8553 printf (_("(not inlined)"));
8555 case DW_INL_inlined:
8556 printf (_("(inlined)"));
8558 case DW_INL_declared_not_inlined:
8559 printf (_("(declared as inline but ignored)"));
8561 case DW_INL_declared_inlined:
8562 printf (_("(declared as inline and inlined)"));
8565 printf (_(" (Unknown inline attribute value: %lx)"), uvalue);
8570 case DW_AT_language:
8573 case DW_LANG_C: printf ("(non-ANSI C)"); break;
8574 case DW_LANG_C89: printf ("(ANSI C)"); break;
8575 case DW_LANG_C_plus_plus: printf ("(C++)"); break;
8576 case DW_LANG_Fortran77: printf ("(FORTRAN 77)"); break;
8577 case DW_LANG_Fortran90: printf ("(Fortran 90)"); break;
8578 case DW_LANG_Modula2: printf ("(Modula 2)"); break;
8579 case DW_LANG_Pascal83: printf ("(ANSI Pascal)"); break;
8580 case DW_LANG_Ada83: printf ("(Ada)"); break;
8581 case DW_LANG_Cobol74: printf ("(Cobol 74)"); break;
8582 case DW_LANG_Cobol85: printf ("(Cobol 85)"); break;
8583 /* DWARF 2.1 values. */
8584 case DW_LANG_C99: printf ("(ANSI C99)"); break;
8585 case DW_LANG_Ada95: printf ("(ADA 95)"); break;
8586 case DW_LANG_Fortran95: printf ("(Fortran 95)"); break;
8587 /* MIPS extension. */
8588 case DW_LANG_Mips_Assembler: printf ("(MIPS assembler)"); break;
8589 /* UPC extension. */
8590 case DW_LANG_Upc: printf ("(Unified Parallel C)"); break;
8592 printf ("(Unknown: %lx)", uvalue);
8597 case DW_AT_encoding:
8600 case DW_ATE_void: printf ("(void)"); break;
8601 case DW_ATE_address: printf ("(machine address)"); break;
8602 case DW_ATE_boolean: printf ("(boolean)"); break;
8603 case DW_ATE_complex_float: printf ("(complex float)"); break;
8604 case DW_ATE_float: printf ("(float)"); break;
8605 case DW_ATE_signed: printf ("(signed)"); break;
8606 case DW_ATE_signed_char: printf ("(signed char)"); break;
8607 case DW_ATE_unsigned: printf ("(unsigned)"); break;
8608 case DW_ATE_unsigned_char: printf ("(unsigned char)"); break;
8609 /* DWARF 2.1 value. */
8610 case DW_ATE_imaginary_float: printf ("(imaginary float)"); break;
8611 /* GNU extension. */
8612 case DW_ATE_GNU_decimal_float: printf ("(decimal float)"); break;
8614 if (uvalue >= DW_ATE_lo_user
8615 && uvalue <= DW_ATE_hi_user)
8616 printf ("(user defined type)");
8618 printf ("(unknown type)");
8623 case DW_AT_accessibility:
8626 case DW_ACCESS_public: printf ("(public)"); break;
8627 case DW_ACCESS_protected: printf ("(protected)"); break;
8628 case DW_ACCESS_private: printf ("(private)"); break;
8630 printf ("(unknown accessibility)");
8635 case DW_AT_visibility:
8638 case DW_VIS_local: printf ("(local)"); break;
8639 case DW_VIS_exported: printf ("(exported)"); break;
8640 case DW_VIS_qualified: printf ("(qualified)"); break;
8641 default: printf ("(unknown visibility)"); break;
8645 case DW_AT_virtuality:
8648 case DW_VIRTUALITY_none: printf ("(none)"); break;
8649 case DW_VIRTUALITY_virtual: printf ("(virtual)"); break;
8650 case DW_VIRTUALITY_pure_virtual:printf ("(pure_virtual)"); break;
8651 default: printf ("(unknown virtuality)"); break;
8655 case DW_AT_identifier_case:
8658 case DW_ID_case_sensitive: printf ("(case_sensitive)"); break;
8659 case DW_ID_up_case: printf ("(up_case)"); break;
8660 case DW_ID_down_case: printf ("(down_case)"); break;
8661 case DW_ID_case_insensitive: printf ("(case_insensitive)"); break;
8662 default: printf ("(unknown case)"); break;
8666 case DW_AT_calling_convention:
8669 case DW_CC_normal: printf ("(normal)"); break;
8670 case DW_CC_program: printf ("(program)"); break;
8671 case DW_CC_nocall: printf ("(nocall)"); break;
8673 if (uvalue >= DW_CC_lo_user
8674 && uvalue <= DW_CC_hi_user)
8675 printf ("(user defined)");
8677 printf ("(unknown convention)");
8681 case DW_AT_ordering:
8684 case -1: printf ("(undefined)"); break;
8685 case 0: printf ("(row major)"); break;
8686 case 1: printf ("(column major)"); break;
8690 case DW_AT_frame_base:
8691 have_frame_base = 1;
8692 case DW_AT_location:
8693 case DW_AT_data_member_location:
8694 case DW_AT_vtable_elem_location:
8695 case DW_AT_allocated:
8696 case DW_AT_associated:
8697 case DW_AT_data_location:
8699 case DW_AT_upper_bound:
8700 case DW_AT_lower_bound:
8703 int need_frame_base;
8706 need_frame_base = decode_location_expression (block_start,
8711 if (need_frame_base && !have_frame_base)
8712 printf (_(" [without DW_AT_frame_base]"));
8714 else if (form == DW_FORM_data4 || form == DW_FORM_data8)
8715 printf (_("(location list)"));
8727 get_AT_name (unsigned long attribute)
8731 case DW_AT_sibling: return "DW_AT_sibling";
8732 case DW_AT_location: return "DW_AT_location";
8733 case DW_AT_name: return "DW_AT_name";
8734 case DW_AT_ordering: return "DW_AT_ordering";
8735 case DW_AT_subscr_data: return "DW_AT_subscr_data";
8736 case DW_AT_byte_size: return "DW_AT_byte_size";
8737 case DW_AT_bit_offset: return "DW_AT_bit_offset";
8738 case DW_AT_bit_size: return "DW_AT_bit_size";
8739 case DW_AT_element_list: return "DW_AT_element_list";
8740 case DW_AT_stmt_list: return "DW_AT_stmt_list";
8741 case DW_AT_low_pc: return "DW_AT_low_pc";
8742 case DW_AT_high_pc: return "DW_AT_high_pc";
8743 case DW_AT_language: return "DW_AT_language";
8744 case DW_AT_member: return "DW_AT_member";
8745 case DW_AT_discr: return "DW_AT_discr";
8746 case DW_AT_discr_value: return "DW_AT_discr_value";
8747 case DW_AT_visibility: return "DW_AT_visibility";
8748 case DW_AT_import: return "DW_AT_import";
8749 case DW_AT_string_length: return "DW_AT_string_length";
8750 case DW_AT_common_reference: return "DW_AT_common_reference";
8751 case DW_AT_comp_dir: return "DW_AT_comp_dir";
8752 case DW_AT_const_value: return "DW_AT_const_value";
8753 case DW_AT_containing_type: return "DW_AT_containing_type";
8754 case DW_AT_default_value: return "DW_AT_default_value";
8755 case DW_AT_inline: return "DW_AT_inline";
8756 case DW_AT_is_optional: return "DW_AT_is_optional";
8757 case DW_AT_lower_bound: return "DW_AT_lower_bound";
8758 case DW_AT_producer: return "DW_AT_producer";
8759 case DW_AT_prototyped: return "DW_AT_prototyped";
8760 case DW_AT_return_addr: return "DW_AT_return_addr";
8761 case DW_AT_start_scope: return "DW_AT_start_scope";
8762 case DW_AT_stride_size: return "DW_AT_stride_size";
8763 case DW_AT_upper_bound: return "DW_AT_upper_bound";
8764 case DW_AT_abstract_origin: return "DW_AT_abstract_origin";
8765 case DW_AT_accessibility: return "DW_AT_accessibility";
8766 case DW_AT_address_class: return "DW_AT_address_class";
8767 case DW_AT_artificial: return "DW_AT_artificial";
8768 case DW_AT_base_types: return "DW_AT_base_types";
8769 case DW_AT_calling_convention: return "DW_AT_calling_convention";
8770 case DW_AT_count: return "DW_AT_count";
8771 case DW_AT_data_member_location: return "DW_AT_data_member_location";
8772 case DW_AT_decl_column: return "DW_AT_decl_column";
8773 case DW_AT_decl_file: return "DW_AT_decl_file";
8774 case DW_AT_decl_line: return "DW_AT_decl_line";
8775 case DW_AT_declaration: return "DW_AT_declaration";
8776 case DW_AT_discr_list: return "DW_AT_discr_list";
8777 case DW_AT_encoding: return "DW_AT_encoding";
8778 case DW_AT_external: return "DW_AT_external";
8779 case DW_AT_frame_base: return "DW_AT_frame_base";
8780 case DW_AT_friend: return "DW_AT_friend";
8781 case DW_AT_identifier_case: return "DW_AT_identifier_case";
8782 case DW_AT_macro_info: return "DW_AT_macro_info";
8783 case DW_AT_namelist_items: return "DW_AT_namelist_items";
8784 case DW_AT_priority: return "DW_AT_priority";
8785 case DW_AT_segment: return "DW_AT_segment";
8786 case DW_AT_specification: return "DW_AT_specification";
8787 case DW_AT_static_link: return "DW_AT_static_link";
8788 case DW_AT_type: return "DW_AT_type";
8789 case DW_AT_use_location: return "DW_AT_use_location";
8790 case DW_AT_variable_parameter: return "DW_AT_variable_parameter";
8791 case DW_AT_virtuality: return "DW_AT_virtuality";
8792 case DW_AT_vtable_elem_location: return "DW_AT_vtable_elem_location";
8793 /* DWARF 2.1 values. */
8794 case DW_AT_allocated: return "DW_AT_allocated";
8795 case DW_AT_associated: return "DW_AT_associated";
8796 case DW_AT_data_location: return "DW_AT_data_location";
8797 case DW_AT_stride: return "DW_AT_stride";
8798 case DW_AT_entry_pc: return "DW_AT_entry_pc";
8799 case DW_AT_use_UTF8: return "DW_AT_use_UTF8";
8800 case DW_AT_extension: return "DW_AT_extension";
8801 case DW_AT_ranges: return "DW_AT_ranges";
8802 case DW_AT_trampoline: return "DW_AT_trampoline";
8803 case DW_AT_call_column: return "DW_AT_call_column";
8804 case DW_AT_call_file: return "DW_AT_call_file";
8805 case DW_AT_call_line: return "DW_AT_call_line";
8806 /* SGI/MIPS extensions. */
8807 case DW_AT_MIPS_fde: return "DW_AT_MIPS_fde";
8808 case DW_AT_MIPS_loop_begin: return "DW_AT_MIPS_loop_begin";
8809 case DW_AT_MIPS_tail_loop_begin: return "DW_AT_MIPS_tail_loop_begin";
8810 case DW_AT_MIPS_epilog_begin: return "DW_AT_MIPS_epilog_begin";
8811 case DW_AT_MIPS_loop_unroll_factor: return "DW_AT_MIPS_loop_unroll_factor";
8812 case DW_AT_MIPS_software_pipeline_depth:
8813 return "DW_AT_MIPS_software_pipeline_depth";
8814 case DW_AT_MIPS_linkage_name: return "DW_AT_MIPS_linkage_name";
8815 case DW_AT_MIPS_stride: return "DW_AT_MIPS_stride";
8816 case DW_AT_MIPS_abstract_name: return "DW_AT_MIPS_abstract_name";
8817 case DW_AT_MIPS_clone_origin: return "DW_AT_MIPS_clone_origin";
8818 case DW_AT_MIPS_has_inlines: return "DW_AT_MIPS_has_inlines";
8819 /* GNU extensions. */
8820 case DW_AT_sf_names: return "DW_AT_sf_names";
8821 case DW_AT_src_info: return "DW_AT_src_info";
8822 case DW_AT_mac_info: return "DW_AT_mac_info";
8823 case DW_AT_src_coords: return "DW_AT_src_coords";
8824 case DW_AT_body_begin: return "DW_AT_body_begin";
8825 case DW_AT_body_end: return "DW_AT_body_end";
8826 case DW_AT_GNU_vector: return "DW_AT_GNU_vector";
8827 /* UPC extension. */
8828 case DW_AT_upc_threads_scaled: return "DW_AT_upc_threads_scaled";
8831 static char buffer[100];
8833 snprintf (buffer, sizeof (buffer), _("Unknown AT value: %lx"),
8840 static unsigned char *
8841 read_and_display_attr (unsigned long attribute,
8843 unsigned char *data,
8844 unsigned long cu_offset,
8845 unsigned long pointer_size,
8846 unsigned long offset_size,
8848 debug_info *debug_info_p,
8852 printf (" %-18s:", get_AT_name (attribute));
8853 data = read_and_display_attr_value (attribute, form, data, cu_offset,
8854 pointer_size, offset_size,
8855 dwarf_version, debug_info_p,
8863 /* Process the contents of a .debug_info section. If do_loc is non-zero
8864 then we are scanning for location lists and we do not want to display
8865 anything to the user. */
8868 process_debug_info (Elf_Internal_Shdr *section, unsigned char *start,
8869 FILE *file, int do_loc)
8871 unsigned char *end = start + section->sh_size;
8872 unsigned char *section_begin;
8874 unsigned int num_units = 0;
8876 if ((do_loc || do_debug_loc || do_debug_ranges)
8877 && num_debug_info_entries == 0)
8879 unsigned long length;
8881 /* First scan the section to get the number of comp units. */
8882 for (section_begin = start, num_units = 0; section_begin < end;
8885 /* Read the first 4 bytes. For a 32-bit DWARF section, this
8886 will be the length. For a 64-bit DWARF section, it'll be
8887 the escape code 0xffffffff followed by an 8 byte length. */
8888 length = byte_get (section_begin, 4);
8890 if (length == 0xffffffff)
8892 length = byte_get (section_begin + 4, 8);
8893 section_begin += length + 12;
8896 section_begin += length + 4;
8901 error (_("No comp units in .debug_info section ?"));
8905 /* Then allocate an array to hold the information. */
8906 debug_information = cmalloc (num_units,
8907 sizeof (* debug_information));
8908 if (debug_information == NULL)
8910 error (_("Not enough memory for a debug info array of %u entries"),
8918 printf (_("The section %s contains:\n\n"),
8919 SECTION_NAME (section));
8921 load_debug_str (file);
8922 load_debug_loc (file);
8923 load_debug_range (file);
8926 for (section_begin = start, unit = 0; start < end; unit++)
8928 DWARF2_Internal_CompUnit compunit;
8929 unsigned char *hdrptr;
8930 unsigned char *cu_abbrev_offset_ptr;
8931 unsigned char *tags;
8933 unsigned long cu_offset;
8935 int initial_length_size;
8939 compunit.cu_length = byte_get (hdrptr, 4);
8942 if (compunit.cu_length == 0xffffffff)
8944 compunit.cu_length = byte_get (hdrptr, 8);
8947 initial_length_size = 12;
8952 initial_length_size = 4;
8955 compunit.cu_version = byte_get (hdrptr, 2);
8958 cu_offset = start - section_begin;
8959 start += compunit.cu_length + initial_length_size;
8961 if (elf_header.e_type == ET_REL
8962 && !debug_apply_rela_addends (file, section, offset_size,
8963 section_begin, hdrptr, start))
8966 cu_abbrev_offset_ptr = hdrptr;
8967 compunit.cu_abbrev_offset = byte_get (hdrptr, offset_size);
8968 hdrptr += offset_size;
8970 compunit.cu_pointer_size = byte_get (hdrptr, 1);
8972 if ((do_loc || do_debug_loc || do_debug_ranges)
8973 && num_debug_info_entries == 0)
8975 debug_information [unit].cu_offset = cu_offset;
8976 debug_information [unit].pointer_size
8977 = compunit.cu_pointer_size;
8978 debug_information [unit].base_address = 0;
8979 debug_information [unit].loc_offsets = NULL;
8980 debug_information [unit].have_frame_base = NULL;
8981 debug_information [unit].max_loc_offsets = 0;
8982 debug_information [unit].num_loc_offsets = 0;
8983 debug_information [unit].range_lists = NULL;
8984 debug_information [unit].max_range_lists= 0;
8985 debug_information [unit].num_range_lists = 0;
8992 printf (_(" Compilation Unit @ offset 0x%lx:\n"), cu_offset);
8993 printf (_(" Length: %ld\n"), compunit.cu_length);
8994 printf (_(" Version: %d\n"), compunit.cu_version);
8995 printf (_(" Abbrev Offset: %ld\n"), compunit.cu_abbrev_offset);
8996 printf (_(" Pointer Size: %d\n"), compunit.cu_pointer_size);
8999 if (compunit.cu_version != 2 && compunit.cu_version != 3)
9001 warn (_("Only version 2 and 3 DWARF debug information is currently supported.\n"));
9007 /* Read in the abbrevs used by this compilation unit. */
9009 Elf_Internal_Shdr *sec;
9010 unsigned char *begin;
9012 /* Locate the .debug_abbrev section and process it. */
9013 sec = find_section (".debug_abbrev");
9016 warn (_("Unable to locate .debug_abbrev section!\n"));
9020 begin = get_data (NULL, file, sec->sh_offset, 1, sec->sh_size,
9021 _("debug_abbrev section data"));
9025 process_abbrev_section (begin + compunit.cu_abbrev_offset,
9026 begin + sec->sh_size);
9032 while (tags < start)
9034 unsigned int bytes_read;
9035 unsigned long abbrev_number;
9036 abbrev_entry *entry;
9039 abbrev_number = read_leb128 (tags, & bytes_read, 0);
9042 /* A null DIE marks the end of a list of children. */
9043 if (abbrev_number == 0)
9049 /* Scan through the abbreviation list until we reach the
9051 for (entry = first_abbrev;
9052 entry && entry->entry != abbrev_number;
9053 entry = entry->next)
9058 warn (_("Unable to locate entry %lu in the abbreviation table\n"),
9064 printf (_(" <%d><%lx>: Abbrev Number: %lu (%s)\n"),
9066 (unsigned long) (tags - section_begin
9069 get_TAG_name (entry->tag));
9074 need_base_address = 0;
9076 case DW_TAG_compile_unit:
9077 need_base_address = 1;
9079 case DW_TAG_entry_point:
9080 case DW_TAG_inlined_subroutine:
9081 case DW_TAG_subprogram:
9082 need_base_address = 0;
9083 /* Assuming that there is no DW_AT_frame_base. */
9084 have_frame_base = 0;
9088 for (attr = entry->first_attr; attr; attr = attr->next)
9089 tags = read_and_display_attr (attr->attribute,
9092 compunit.cu_pointer_size,
9094 compunit.cu_version,
9095 &debug_information [unit],
9098 if (entry->children)
9103 /* Set num_debug_info_entries here so that it can be used to check if
9104 we need to process .debug_loc and .debug_ranges sections. */
9105 if ((do_loc || do_debug_loc || do_debug_ranges)
9106 && num_debug_info_entries == 0)
9107 num_debug_info_entries = num_units;
9111 free_debug_range ();
9121 /* Retrieve the pointer size associated with the given compilation unit.
9122 Optionally the offset of this unit into the .debug_info section is
9123 also retutned. If there is no .debug_info section then an error
9124 message is issued and 0 is returned. If the requested comp unit has
9125 not been defined in the .debug_info section then a warning message
9126 is issued and the last know pointer size is returned. This message
9127 is only issued once per section dumped per file dumped. */
9130 get_pointer_size_and_offset_of_comp_unit (unsigned int comp_unit,
9131 const char * section_name,
9132 unsigned long * offset_return)
9134 unsigned long offset = 0;
9136 if (num_debug_info_entries == 0)
9137 error (_("%s section needs a populated .debug_info section\n"),
9140 else if (comp_unit >= num_debug_info_entries)
9142 if (!warned_about_missing_comp_units)
9144 warn (_("%s section has more comp units than .debug_info section\n"),
9146 warn (_("assuming that the pointer size is %d, from the last comp unit in .debug_info\n\n"),
9148 warned_about_missing_comp_units = TRUE;
9153 last_pointer_size = debug_information [comp_unit].pointer_size;
9154 offset = debug_information [comp_unit].cu_offset;
9157 if (offset_return != NULL)
9158 * offset_return = offset;
9160 return last_pointer_size;
9163 /* Locate and scan the .debug_info section in the file and record the pointer
9164 sizes and offsets for the compilation units in it. Usually an executable
9165 will have just one pointer size, but this is not guaranteed, and so we try
9166 not to make any assumptions. Returns zero upon failure, or the number of
9167 compilation units upon success. */
9170 get_debug_info (FILE * file)
9172 Elf_Internal_Shdr * section;
9173 unsigned char * start;
9176 /* Reset the last pointer size so that we can issue correct error
9177 messages if we are displaying the contents of more than one section. */
9178 last_pointer_size = 0;
9179 warned_about_missing_comp_units = FALSE;
9181 /* If we already have the information there is nothing else to do. */
9182 if (num_debug_info_entries > 0)
9183 return num_debug_info_entries;
9185 section = find_section (".debug_info");
9186 if (section == NULL)
9189 start = get_data (NULL, file, section->sh_offset, 1, section->sh_size,
9190 _("extracting information from .debug_info section"));
9194 ret = process_debug_info (section, start, file, 1);
9197 return ret ? num_debug_info_entries : 0;
9201 display_debug_lines (Elf_Internal_Shdr *section,
9202 unsigned char *start, FILE *file)
9204 unsigned char *data = start;
9205 unsigned char *end = start + section->sh_size;
9206 unsigned int comp_unit = 0;
9208 printf (_("\nDump of debug contents of section %s:\n\n"),
9209 SECTION_NAME (section));
9211 get_debug_info (file);
9215 DWARF2_Internal_LineInfo info;
9216 unsigned char *standard_opcodes;
9217 unsigned char *end_of_sequence;
9218 unsigned char *hdrptr;
9219 unsigned int pointer_size;
9220 int initial_length_size;
9226 /* Check the length of the block. */
9227 info.li_length = byte_get (hdrptr, 4);
9230 if (info.li_length == 0xffffffff)
9232 /* This section is 64-bit DWARF 3. */
9233 info.li_length = byte_get (hdrptr, 8);
9236 initial_length_size = 12;
9241 initial_length_size = 4;
9244 if (info.li_length + initial_length_size > section->sh_size)
9247 (_("The line info appears to be corrupt - the section is too small\n"));
9251 /* Check its version number. */
9252 info.li_version = byte_get (hdrptr, 2);
9254 if (info.li_version != 2 && info.li_version != 3)
9256 warn (_("Only DWARF version 2 and 3 line info is currently supported.\n"));
9260 info.li_prologue_length = byte_get (hdrptr, offset_size);
9261 hdrptr += offset_size;
9262 info.li_min_insn_length = byte_get (hdrptr, 1);
9264 info.li_default_is_stmt = byte_get (hdrptr, 1);
9266 info.li_line_base = byte_get (hdrptr, 1);
9268 info.li_line_range = byte_get (hdrptr, 1);
9270 info.li_opcode_base = byte_get (hdrptr, 1);
9273 /* Sign extend the line base field. */
9274 info.li_line_base <<= 24;
9275 info.li_line_base >>= 24;
9277 /* Get the pointer size from the comp unit associated
9278 with this block of line number information. */
9279 pointer_size = get_pointer_size_and_offset_of_comp_unit
9280 (comp_unit, ".debug_line", NULL);
9283 printf (_(" Length: %ld\n"), info.li_length);
9284 printf (_(" DWARF Version: %d\n"), info.li_version);
9285 printf (_(" Prologue Length: %d\n"), info.li_prologue_length);
9286 printf (_(" Minimum Instruction Length: %d\n"), info.li_min_insn_length);
9287 printf (_(" Initial value of 'is_stmt': %d\n"), info.li_default_is_stmt);
9288 printf (_(" Line Base: %d\n"), info.li_line_base);
9289 printf (_(" Line Range: %d\n"), info.li_line_range);
9290 printf (_(" Opcode Base: %d\n"), info.li_opcode_base);
9291 printf (_(" (Pointer size: %u)%s\n"),
9293 warned_about_missing_comp_units ? " [assumed]" : "" );
9295 end_of_sequence = data + info.li_length + initial_length_size;
9297 reset_state_machine (info.li_default_is_stmt);
9299 /* Display the contents of the Opcodes table. */
9300 standard_opcodes = hdrptr;
9302 printf (_("\n Opcodes:\n"));
9304 for (i = 1; i < info.li_opcode_base; i++)
9305 printf (_(" Opcode %d has %d args\n"), i, standard_opcodes[i - 1]);
9307 /* Display the contents of the Directory table. */
9308 data = standard_opcodes + info.li_opcode_base - 1;
9311 printf (_("\n The Directory Table is empty.\n"));
9314 printf (_("\n The Directory Table:\n"));
9318 printf (_(" %s\n"), data);
9320 data += strlen ((char *) data) + 1;
9324 /* Skip the NUL at the end of the table. */
9327 /* Display the contents of the File Name table. */
9329 printf (_("\n The File Name Table is empty.\n"));
9332 printf (_("\n The File Name Table:\n"));
9333 printf (_(" Entry\tDir\tTime\tSize\tName\n"));
9337 unsigned char *name;
9338 unsigned int bytes_read;
9340 printf (_(" %d\t"), ++state_machine_regs.last_file_entry);
9343 data += strlen ((char *) data) + 1;
9345 printf (_("%lu\t"), read_leb128 (data, & bytes_read, 0));
9347 printf (_("%lu\t"), read_leb128 (data, & bytes_read, 0));
9349 printf (_("%lu\t"), read_leb128 (data, & bytes_read, 0));
9351 printf (_("%s\n"), name);
9355 /* Skip the NUL at the end of the table. */
9358 /* Now display the statements. */
9359 printf (_("\n Line Number Statements:\n"));
9361 while (data < end_of_sequence)
9363 unsigned char op_code;
9365 unsigned int bytes_read;
9369 if (op_code >= info.li_opcode_base)
9371 op_code -= info.li_opcode_base;
9372 adv = (op_code / info.li_line_range) * info.li_min_insn_length;
9373 state_machine_regs.address += adv;
9374 printf (_(" Special opcode %d: advance Address by %d to 0x%lx"),
9375 op_code, adv, state_machine_regs.address);
9376 adv = (op_code % info.li_line_range) + info.li_line_base;
9377 state_machine_regs.line += adv;
9378 printf (_(" and Line by %d to %d\n"),
9379 adv, state_machine_regs.line);
9381 else switch (op_code)
9383 case DW_LNS_extended_op:
9384 if (pointer_size == 0)
9386 warn (_("Extend line ops need a valid pointer size, guessing at 4\n"));
9390 data += process_extended_line_op (data, info.li_default_is_stmt,
9395 printf (_(" Copy\n"));
9398 case DW_LNS_advance_pc:
9399 adv = info.li_min_insn_length * read_leb128 (data, & bytes_read, 0);
9401 state_machine_regs.address += adv;
9402 printf (_(" Advance PC by %d to %lx\n"), adv,
9403 state_machine_regs.address);
9406 case DW_LNS_advance_line:
9407 adv = read_leb128 (data, & bytes_read, 1);
9409 state_machine_regs.line += adv;
9410 printf (_(" Advance Line by %d to %d\n"), adv,
9411 state_machine_regs.line);
9414 case DW_LNS_set_file:
9415 adv = read_leb128 (data, & bytes_read, 0);
9417 printf (_(" Set File Name to entry %d in the File Name Table\n"),
9419 state_machine_regs.file = adv;
9422 case DW_LNS_set_column:
9423 adv = read_leb128 (data, & bytes_read, 0);
9425 printf (_(" Set column to %d\n"), adv);
9426 state_machine_regs.column = adv;
9429 case DW_LNS_negate_stmt:
9430 adv = state_machine_regs.is_stmt;
9432 printf (_(" Set is_stmt to %d\n"), adv);
9433 state_machine_regs.is_stmt = adv;
9436 case DW_LNS_set_basic_block:
9437 printf (_(" Set basic block\n"));
9438 state_machine_regs.basic_block = 1;
9441 case DW_LNS_const_add_pc:
9442 adv = (((255 - info.li_opcode_base) / info.li_line_range)
9443 * info.li_min_insn_length);
9444 state_machine_regs.address += adv;
9445 printf (_(" Advance PC by constant %d to 0x%lx\n"), adv,
9446 state_machine_regs.address);
9449 case DW_LNS_fixed_advance_pc:
9450 adv = byte_get (data, 2);
9452 state_machine_regs.address += adv;
9453 printf (_(" Advance PC by fixed size amount %d to 0x%lx\n"),
9454 adv, state_machine_regs.address);
9457 case DW_LNS_set_prologue_end:
9458 printf (_(" Set prologue_end to true\n"));
9461 case DW_LNS_set_epilogue_begin:
9462 printf (_(" Set epilogue_begin to true\n"));
9465 case DW_LNS_set_isa:
9466 adv = read_leb128 (data, & bytes_read, 0);
9468 printf (_(" Set ISA to %d\n"), adv);
9472 printf (_(" Unknown opcode %d with operands: "), op_code);
9474 for (i = standard_opcodes[op_code - 1]; i > 0 ; --i)
9476 printf ("0x%lx%s", read_leb128 (data, &bytes_read, 0),
9477 i == 1 ? "" : ", ");
9491 display_debug_pubnames (Elf_Internal_Shdr *section,
9492 unsigned char *start,
9493 FILE *file ATTRIBUTE_UNUSED)
9495 DWARF2_Internal_PubNames pubnames;
9498 end = start + section->sh_size;
9500 printf (_("Contents of the %s section:\n\n"), SECTION_NAME (section));
9504 unsigned char *data;
9505 unsigned long offset;
9506 int offset_size, initial_length_size;
9510 pubnames.pn_length = byte_get (data, 4);
9512 if (pubnames.pn_length == 0xffffffff)
9514 pubnames.pn_length = byte_get (data, 8);
9517 initial_length_size = 12;
9522 initial_length_size = 4;
9525 pubnames.pn_version = byte_get (data, 2);
9527 pubnames.pn_offset = byte_get (data, offset_size);
9528 data += offset_size;
9529 pubnames.pn_size = byte_get (data, offset_size);
9530 data += offset_size;
9532 start += pubnames.pn_length + initial_length_size;
9534 if (pubnames.pn_version != 2 && pubnames.pn_version != 3)
9536 static int warned = 0;
9540 warn (_("Only DWARF 2 and 3 pubnames are currently supported\n"));
9547 printf (_(" Length: %ld\n"),
9548 pubnames.pn_length);
9549 printf (_(" Version: %d\n"),
9550 pubnames.pn_version);
9551 printf (_(" Offset into .debug_info section: %ld\n"),
9552 pubnames.pn_offset);
9553 printf (_(" Size of area in .debug_info section: %ld\n"),
9556 printf (_("\n Offset\tName\n"));
9560 offset = byte_get (data, offset_size);
9564 data += offset_size;
9565 printf (" %-6ld\t\t%s\n", offset, data);
9566 data += strlen ((char *) data) + 1;
9569 while (offset != 0);
9577 display_debug_macinfo (Elf_Internal_Shdr *section,
9578 unsigned char *start,
9579 FILE *file ATTRIBUTE_UNUSED)
9581 unsigned char *end = start + section->sh_size;
9582 unsigned char *curr = start;
9583 unsigned int bytes_read;
9584 enum dwarf_macinfo_record_type op;
9586 printf (_("Contents of the %s section:\n\n"), SECTION_NAME (section));
9590 unsigned int lineno;
9598 case DW_MACINFO_start_file:
9600 unsigned int filenum;
9602 lineno = read_leb128 (curr, & bytes_read, 0);
9604 filenum = read_leb128 (curr, & bytes_read, 0);
9607 printf (_(" DW_MACINFO_start_file - lineno: %d filenum: %d\n"),
9612 case DW_MACINFO_end_file:
9613 printf (_(" DW_MACINFO_end_file\n"));
9616 case DW_MACINFO_define:
9617 lineno = read_leb128 (curr, & bytes_read, 0);
9619 string = (char *) curr;
9620 curr += strlen (string) + 1;
9621 printf (_(" DW_MACINFO_define - lineno : %d macro : %s\n"),
9625 case DW_MACINFO_undef:
9626 lineno = read_leb128 (curr, & bytes_read, 0);
9628 string = (char *) curr;
9629 curr += strlen (string) + 1;
9630 printf (_(" DW_MACINFO_undef - lineno : %d macro : %s\n"),
9634 case DW_MACINFO_vendor_ext:
9636 unsigned int constant;
9638 constant = read_leb128 (curr, & bytes_read, 0);
9640 string = (char *) curr;
9641 curr += strlen (string) + 1;
9642 printf (_(" DW_MACINFO_vendor_ext - constant : %d string : %s\n"),
9654 display_debug_abbrev (Elf_Internal_Shdr *section,
9655 unsigned char *start,
9656 FILE *file ATTRIBUTE_UNUSED)
9658 abbrev_entry *entry;
9659 unsigned char *end = start + section->sh_size;
9661 printf (_("Contents of the %s section:\n\n"), SECTION_NAME (section));
9665 start = process_abbrev_section (start, end);
9667 if (first_abbrev == NULL)
9670 printf (_(" Number TAG\n"));
9672 for (entry = first_abbrev; entry; entry = entry->next)
9676 printf (_(" %ld %s [%s]\n"),
9678 get_TAG_name (entry->tag),
9679 entry->children ? _("has children") : _("no children"));
9681 for (attr = entry->first_attr; attr; attr = attr->next)
9682 printf (_(" %-18s %s\n"),
9683 get_AT_name (attr->attribute),
9684 get_FORM_name (attr->form));
9697 display_debug_loc (Elf_Internal_Shdr *section,
9698 unsigned char *start, FILE *file)
9700 unsigned char *section_end;
9701 unsigned long bytes;
9702 unsigned char *section_begin = start;
9703 unsigned int num_loc_list = 0;
9704 unsigned long last_offset = 0;
9705 unsigned int first = 0;
9708 int seen_first_offset = 0;
9709 int use_debug_info = 1;
9710 unsigned char *next;
9712 bytes = section->sh_size;
9713 section_end = start + bytes;
9717 printf (_("\nThe .debug_loc section is empty.\n"));
9721 get_debug_info (file);
9723 /* Check the order of location list in .debug_info section. If
9724 offsets of location lists are in the ascending order, we can
9725 use `debug_information' directly. */
9726 for (i = 0; i < num_debug_info_entries; i++)
9730 num = debug_information [i].num_loc_offsets;
9731 num_loc_list += num;
9733 /* Check if we can use `debug_information' directly. */
9734 if (use_debug_info && num != 0)
9736 if (!seen_first_offset)
9738 /* This is the first location list. */
9739 last_offset = debug_information [i].loc_offsets [0];
9741 seen_first_offset = 1;
9747 for (; j < num; j++)
9750 debug_information [i].loc_offsets [j])
9755 last_offset = debug_information [i].loc_offsets [j];
9760 if (!use_debug_info)
9761 /* FIXME: Should we handle this case? */
9762 error (_("Location lists in .debug_info section aren't in ascending order!\n"));
9764 if (!seen_first_offset)
9765 error (_("No location lists in .debug_info section!\n"));
9767 if (debug_information [first].loc_offsets [0] != 0)
9768 warn (_("Location lists in .debug_loc section start at 0x%lx\n"),
9769 debug_information [first].loc_offsets [0]);
9771 printf (_("Contents of the .debug_loc section:\n\n"));
9772 printf (_(" Offset Begin End Expression\n"));
9774 seen_first_offset = 0;
9775 for (i = first; i < num_debug_info_entries; i++)
9777 unsigned long begin;
9779 unsigned short length;
9780 unsigned long offset;
9781 unsigned int pointer_size;
9782 unsigned long cu_offset;
9783 unsigned long base_address;
9784 int need_frame_base;
9787 pointer_size = debug_information [i].pointer_size;
9788 cu_offset = debug_information [i].cu_offset;
9790 for (j = 0; j < debug_information [i].num_loc_offsets; j++)
9792 has_frame_base = debug_information [i].have_frame_base [j];
9793 offset = debug_information [i].loc_offsets [j];
9794 next = section_begin + offset;
9795 base_address = debug_information [i].base_address;
9797 if (!seen_first_offset)
9798 seen_first_offset = 1;
9802 warn (_("There is a hole [0x%lx - 0x%lx] in .debug_loc section.\n"),
9803 (long)(start - section_begin), (long)(next - section_begin));
9804 else if (start > next)
9805 warn (_("There is an overlap [0x%lx - 0x%lx] in .debug_loc section.\n"),
9806 (long)(start - section_begin), (long)(next - section_begin));
9810 if (offset >= bytes)
9812 warn (_("Offset 0x%lx is bigger than .debug_loc section size.\n"),
9819 if (start + 2 * pointer_size > section_end)
9821 warn (_("Location list starting at offset 0x%lx is not terminated.\n"),
9826 begin = byte_get (start, pointer_size);
9827 start += pointer_size;
9828 end = byte_get (start, pointer_size);
9829 start += pointer_size;
9831 if (begin == 0 && end == 0)
9833 printf (_(" %8.8lx <End of list>\n"), offset);
9837 /* Check base address specifiers. */
9838 if (begin == -1UL && end != -1UL)
9841 printf (_(" %8.8lx %8.8lx %8.8lx (base address)\n"),
9842 offset, begin, end);
9846 if (start + 2 > section_end)
9848 warn (_("Location list starting at offset 0x%lx is not terminated.\n"),
9853 length = byte_get (start, 2);
9856 if (start + length > section_end)
9858 warn (_("Location list starting at offset 0x%lx is not terminated.\n"),
9863 printf (" %8.8lx %8.8lx %8.8lx (",
9864 offset, begin + base_address, end + base_address);
9865 need_frame_base = decode_location_expression (start,
9871 if (need_frame_base && !has_frame_base)
9872 printf (_(" [without DW_AT_frame_base]"));
9875 fputs (_(" (start == end)"), stdout);
9876 else if (begin > end)
9877 fputs (_(" (start > end)"), stdout);
9889 display_debug_str (Elf_Internal_Shdr *section,
9890 unsigned char *start,
9891 FILE *file ATTRIBUTE_UNUSED)
9893 unsigned long bytes;
9896 addr = section->sh_addr;
9897 bytes = section->sh_size;
9901 printf (_("\nThe .debug_str section is empty.\n"));
9905 printf (_("Contents of the .debug_str section:\n\n"));
9913 lbytes = (bytes > 16 ? 16 : bytes);
9915 printf (" 0x%8.8lx ", (unsigned long) addr);
9917 for (j = 0; j < 16; j++)
9920 printf ("%2.2x", start[j]);
9928 for (j = 0; j < lbytes; j++)
9931 if (k >= ' ' && k < 0x80)
9951 display_debug_info (Elf_Internal_Shdr * section,
9952 unsigned char * start, FILE * file)
9954 return process_debug_info (section, start, file, 0);
9959 display_debug_aranges (Elf_Internal_Shdr *section,
9960 unsigned char *start,
9961 FILE *file ATTRIBUTE_UNUSED)
9963 unsigned char *end = start + section->sh_size;
9965 printf (_("The section %s contains:\n\n"), SECTION_NAME (section));
9969 unsigned char *hdrptr;
9970 DWARF2_Internal_ARange arange;
9971 unsigned char *ranges;
9972 unsigned long length;
9973 unsigned long address;
9976 int initial_length_size;
9980 arange.ar_length = byte_get (hdrptr, 4);
9983 if (arange.ar_length == 0xffffffff)
9985 arange.ar_length = byte_get (hdrptr, 8);
9988 initial_length_size = 12;
9993 initial_length_size = 4;
9996 arange.ar_version = byte_get (hdrptr, 2);
9999 arange.ar_info_offset = byte_get (hdrptr, offset_size);
10000 hdrptr += offset_size;
10002 arange.ar_pointer_size = byte_get (hdrptr, 1);
10005 arange.ar_segment_size = byte_get (hdrptr, 1);
10008 if (arange.ar_version != 2 && arange.ar_version != 3)
10010 warn (_("Only DWARF 2 and 3 aranges are currently supported.\n"));
10014 printf (_(" Length: %ld\n"), arange.ar_length);
10015 printf (_(" Version: %d\n"), arange.ar_version);
10016 printf (_(" Offset into .debug_info: %lx\n"), arange.ar_info_offset);
10017 printf (_(" Pointer Size: %d\n"), arange.ar_pointer_size);
10018 printf (_(" Segment Size: %d\n"), arange.ar_segment_size);
10020 printf (_("\n Address Length\n"));
10024 /* Must pad to an alignment boundary that is twice the pointer size. */
10025 excess = (hdrptr - start) % (2 * arange.ar_pointer_size);
10027 ranges += (2 * arange.ar_pointer_size) - excess;
10031 address = byte_get (ranges, arange.ar_pointer_size);
10033 ranges += arange.ar_pointer_size;
10035 length = byte_get (ranges, arange.ar_pointer_size);
10037 ranges += arange.ar_pointer_size;
10039 /* A pair of zeros marks the end of the list. */
10040 if (address == 0 && length == 0)
10043 printf (" %8.8lx %lu\n", address, length);
10046 start += arange.ar_length + initial_length_size;
10055 display_debug_ranges (Elf_Internal_Shdr *section,
10056 unsigned char *start,
10057 FILE *file ATTRIBUTE_UNUSED)
10059 unsigned char *section_end;
10060 unsigned long bytes;
10061 unsigned char *section_begin = start;
10062 unsigned int num_range_list = 0;
10063 unsigned long last_offset = 0;
10064 unsigned int first = 0;
10067 int seen_first_offset = 0;
10068 int use_debug_info = 1;
10069 unsigned char *next;
10071 bytes = section->sh_size;
10072 section_end = start + bytes;
10076 printf (_("\nThe .debug_ranges section is empty.\n"));
10080 get_debug_info (file);
10082 /* Check the order of range list in .debug_info section. If
10083 offsets of range lists are in the ascending order, we can
10084 use `debug_information' directly. */
10085 for (i = 0; i < num_debug_info_entries; i++)
10089 num = debug_information [i].num_range_lists;
10090 num_range_list += num;
10092 /* Check if we can use `debug_information' directly. */
10093 if (use_debug_info && num != 0)
10095 if (!seen_first_offset)
10097 /* This is the first range list. */
10098 last_offset = debug_information [i].range_lists [0];
10100 seen_first_offset = 1;
10106 for (; j < num; j++)
10109 debug_information [i].range_lists [j])
10111 use_debug_info = 0;
10114 last_offset = debug_information [i].range_lists [j];
10119 if (!use_debug_info)
10120 /* FIXME: Should we handle this case? */
10121 error (_("Range lists in .debug_info section aren't in ascending order!\n"));
10123 if (!seen_first_offset)
10124 error (_("No range lists in .debug_info section!\n"));
10126 if (debug_information [first].range_lists [0] != 0)
10127 warn (_("Range lists in .debug_ranges section start at 0x%lx\n"),
10128 debug_information [first].range_lists [0]);
10130 printf (_("Contents of the .debug_ranges section:\n\n"));
10131 printf (_(" Offset Begin End\n"));
10133 seen_first_offset = 0;
10134 for (i = first; i < num_debug_info_entries; i++)
10136 unsigned long begin;
10138 unsigned long offset;
10139 unsigned int pointer_size;
10140 unsigned long base_address;
10142 pointer_size = debug_information [i].pointer_size;
10144 for (j = 0; j < debug_information [i].num_range_lists; j++)
10146 offset = debug_information [i].range_lists [j];
10147 next = section_begin + offset;
10148 base_address = debug_information [i].base_address;
10150 if (!seen_first_offset)
10151 seen_first_offset = 1;
10155 warn (_("There is a hole [0x%lx - 0x%lx] in .debug_ranges section.\n"),
10156 (long)(start - section_begin), (long)(next - section_begin));
10157 else if (start > next)
10158 warn (_("There is an overlap [0x%lx - 0x%lx] in .debug_ranges section.\n"),
10159 (long)(start - section_begin), (long)(next - section_begin));
10165 begin = byte_get (start, pointer_size);
10166 start += pointer_size;
10167 end = byte_get (start, pointer_size);
10168 start += pointer_size;
10170 if (begin == 0 && end == 0)
10172 printf (_(" %8.8lx <End of list>\n"), offset);
10176 /* Check base address specifiers. */
10177 if (begin == -1UL && end != -1UL)
10179 base_address = end;
10180 printf (" %8.8lx %8.8lx %8.8lx (base address)\n",
10181 offset, begin, end);
10185 printf (" %8.8lx %8.8lx %8.8lx",
10186 offset, begin + base_address, end + base_address);
10189 fputs (_(" (start == end)"), stdout);
10190 else if (begin > end)
10191 fputs (_(" (start > end)"), stdout);
10201 typedef struct Frame_Chunk
10203 struct Frame_Chunk *next;
10204 unsigned char *chunk_start;
10206 /* DW_CFA_{undefined,same_value,offset,register,unreferenced} */
10207 short int *col_type;
10209 char *augmentation;
10210 unsigned int code_factor;
10212 unsigned long pc_begin;
10213 unsigned long pc_range;
10217 unsigned char fde_encoding;
10218 unsigned char cfa_exp;
10222 /* A marker for a col_type that means this column was never referenced
10223 in the frame info. */
10224 #define DW_CFA_unreferenced (-1)
10227 frame_need_space (Frame_Chunk *fc, int reg)
10229 int prev = fc->ncols;
10231 if (reg < fc->ncols)
10234 fc->ncols = reg + 1;
10235 fc->col_type = xcrealloc (fc->col_type, fc->ncols, sizeof (short int));
10236 fc->col_offset = xcrealloc (fc->col_offset, fc->ncols, sizeof (int));
10238 while (prev < fc->ncols)
10240 fc->col_type[prev] = DW_CFA_unreferenced;
10241 fc->col_offset[prev] = 0;
10247 frame_display_row (Frame_Chunk *fc, int *need_col_headers, int *max_regs)
10252 if (*max_regs < fc->ncols)
10253 *max_regs = fc->ncols;
10255 if (*need_col_headers)
10257 *need_col_headers = 0;
10259 printf (" LOC CFA ");
10261 for (r = 0; r < *max_regs; r++)
10262 if (fc->col_type[r] != DW_CFA_unreferenced)
10267 printf ("r%-4d", r);
10273 printf ("%08lx ", fc->pc_begin);
10275 strcpy (tmp, "exp");
10277 sprintf (tmp, "r%d%+d", fc->cfa_reg, fc->cfa_offset);
10278 printf ("%-8s ", tmp);
10280 for (r = 0; r < fc->ncols; r++)
10282 if (fc->col_type[r] != DW_CFA_unreferenced)
10284 switch (fc->col_type[r])
10286 case DW_CFA_undefined:
10289 case DW_CFA_same_value:
10292 case DW_CFA_offset:
10293 sprintf (tmp, "c%+d", fc->col_offset[r]);
10295 case DW_CFA_register:
10296 sprintf (tmp, "r%d", fc->col_offset[r]);
10298 case DW_CFA_expression:
10299 strcpy (tmp, "exp");
10302 strcpy (tmp, "n/a");
10305 printf ("%-5s", tmp);
10312 size_of_encoded_value (int encoding)
10314 switch (encoding & 0x7)
10317 case 0: return eh_addr_size;
10325 get_encoded_value (unsigned char *data, int encoding)
10327 int size = size_of_encoded_value (encoding);
10328 if (encoding & DW_EH_PE_signed)
10329 return byte_get_signed (data, size);
10331 return byte_get (data, size);
10334 #define GET(N) byte_get (start, N); start += N
10335 #define LEB() read_leb128 (start, & length_return, 0); start += length_return
10336 #define SLEB() read_leb128 (start, & length_return, 1); start += length_return
10339 display_debug_frames (Elf_Internal_Shdr *section,
10340 unsigned char *start,
10341 FILE *file ATTRIBUTE_UNUSED)
10343 unsigned char *end = start + section->sh_size;
10344 unsigned char *section_start = start;
10345 Frame_Chunk *chunks = 0;
10346 Frame_Chunk *remembered_state = 0;
10348 int is_eh = streq (SECTION_NAME (section), ".eh_frame");
10349 unsigned int length_return;
10352 printf (_("The section %s contains:\n"), SECTION_NAME (section));
10354 while (start < end)
10356 unsigned char *saved_start;
10357 unsigned char *block_end;
10358 unsigned long length;
10359 unsigned long cie_id;
10362 int need_col_headers = 1;
10363 unsigned char *augmentation_data = NULL;
10364 unsigned long augmentation_data_len = 0;
10365 int encoded_ptr_size = eh_addr_size;
10367 int initial_length_size;
10369 saved_start = start;
10370 length = byte_get (start, 4); start += 4;
10374 printf ("\n%08lx ZERO terminator\n\n",
10375 (unsigned long)(saved_start - section_start));
10379 if (length == 0xffffffff)
10381 length = byte_get (start, 8);
10384 initial_length_size = 12;
10389 initial_length_size = 4;
10392 block_end = saved_start + length + initial_length_size;
10393 cie_id = byte_get (start, offset_size); start += offset_size;
10395 if (elf_header.e_type == ET_REL
10396 && !debug_apply_rela_addends (file, section, offset_size,
10397 section_start, start, block_end))
10400 if (is_eh ? (cie_id == 0) : (cie_id == DW_CIE_ID))
10404 fc = xmalloc (sizeof (Frame_Chunk));
10405 memset (fc, 0, sizeof (Frame_Chunk));
10409 fc->chunk_start = saved_start;
10411 fc->col_type = xmalloc (sizeof (short int));
10412 fc->col_offset = xmalloc (sizeof (int));
10413 frame_need_space (fc, max_regs-1);
10415 version = *start++;
10417 fc->augmentation = (char *) start;
10418 start = (unsigned char *) strchr ((char *) start, '\0') + 1;
10420 if (fc->augmentation[0] == 'z')
10422 fc->code_factor = LEB ();
10423 fc->data_factor = SLEB ();
10432 augmentation_data_len = LEB ();
10433 augmentation_data = start;
10434 start += augmentation_data_len;
10436 else if (streq (fc->augmentation, "eh"))
10438 start += eh_addr_size;
10439 fc->code_factor = LEB ();
10440 fc->data_factor = SLEB ();
10452 fc->code_factor = LEB ();
10453 fc->data_factor = SLEB ();
10465 if (do_debug_frames_interp)
10466 printf ("\n%08lx %08lx %08lx CIE \"%s\" cf=%d df=%d ra=%d\n",
10467 (unsigned long)(saved_start - section_start), length, cie_id,
10468 fc->augmentation, fc->code_factor, fc->data_factor,
10472 printf ("\n%08lx %08lx %08lx CIE\n",
10473 (unsigned long)(saved_start - section_start), length, cie_id);
10474 printf (" Version: %d\n", version);
10475 printf (" Augmentation: \"%s\"\n", fc->augmentation);
10476 printf (" Code alignment factor: %u\n", fc->code_factor);
10477 printf (" Data alignment factor: %d\n", fc->data_factor);
10478 printf (" Return address column: %d\n", fc->ra);
10480 if (augmentation_data_len)
10483 printf (" Augmentation data: ");
10484 for (i = 0; i < augmentation_data_len; ++i)
10485 printf (" %02x", augmentation_data[i]);
10491 if (augmentation_data_len)
10493 unsigned char *p, *q;
10494 p = (unsigned char *) fc->augmentation + 1;
10495 q = augmentation_data;
10501 else if (*p == 'P')
10502 q += 1 + size_of_encoded_value (*q);
10503 else if (*p == 'R')
10504 fc->fde_encoding = *q++;
10510 if (fc->fde_encoding)
10511 encoded_ptr_size = size_of_encoded_value (fc->fde_encoding);
10514 frame_need_space (fc, fc->ra);
10518 unsigned char *look_for;
10519 static Frame_Chunk fde_fc;
10522 memset (fc, 0, sizeof (Frame_Chunk));
10524 look_for = is_eh ? start - 4 - cie_id : section_start + cie_id;
10526 for (cie = chunks; cie ; cie = cie->next)
10527 if (cie->chunk_start == look_for)
10532 warn ("Invalid CIE pointer %08lx in FDE at %p\n",
10533 cie_id, saved_start);
10536 fc->col_type = xmalloc (sizeof (short int));
10537 fc->col_offset = xmalloc (sizeof (int));
10538 frame_need_space (fc, max_regs - 1);
10540 fc->augmentation = "";
10541 fc->fde_encoding = 0;
10545 fc->ncols = cie->ncols;
10546 fc->col_type = xcmalloc (fc->ncols, sizeof (short int));
10547 fc->col_offset = xcmalloc (fc->ncols, sizeof (int));
10548 memcpy (fc->col_type, cie->col_type, fc->ncols * sizeof (short int));
10549 memcpy (fc->col_offset, cie->col_offset, fc->ncols * sizeof (int));
10550 fc->augmentation = cie->augmentation;
10551 fc->code_factor = cie->code_factor;
10552 fc->data_factor = cie->data_factor;
10553 fc->cfa_reg = cie->cfa_reg;
10554 fc->cfa_offset = cie->cfa_offset;
10556 frame_need_space (fc, max_regs-1);
10557 fc->fde_encoding = cie->fde_encoding;
10560 if (fc->fde_encoding)
10561 encoded_ptr_size = size_of_encoded_value (fc->fde_encoding);
10563 fc->pc_begin = get_encoded_value (start, fc->fde_encoding);
10564 if ((fc->fde_encoding & 0x70) == DW_EH_PE_pcrel
10565 /* Don't adjust for ET_REL since there's invariably a pcrel
10566 reloc here, which we haven't applied. */
10567 && elf_header.e_type != ET_REL)
10568 fc->pc_begin += section->sh_addr + (start - section_start);
10569 start += encoded_ptr_size;
10570 fc->pc_range = byte_get (start, encoded_ptr_size);
10571 start += encoded_ptr_size;
10573 if (cie->augmentation[0] == 'z')
10575 augmentation_data_len = LEB ();
10576 augmentation_data = start;
10577 start += augmentation_data_len;
10580 printf ("\n%08lx %08lx %08lx FDE cie=%08lx pc=%08lx..%08lx\n",
10581 (unsigned long)(saved_start - section_start), length, cie_id,
10582 (unsigned long)(cie->chunk_start - section_start),
10583 fc->pc_begin, fc->pc_begin + fc->pc_range);
10584 if (! do_debug_frames_interp && augmentation_data_len)
10588 printf (" Augmentation data: ");
10589 for (i = 0; i < augmentation_data_len; ++i)
10590 printf (" %02x", augmentation_data[i]);
10596 /* At this point, fc is the current chunk, cie (if any) is set, and
10597 we're about to interpret instructions for the chunk. */
10598 /* ??? At present we need to do this always, since this sizes the
10599 fc->col_type and fc->col_offset arrays, which we write into always.
10600 We should probably split the interpreted and non-interpreted bits
10601 into two different routines, since there's so much that doesn't
10602 really overlap between them. */
10603 if (1 || do_debug_frames_interp)
10605 /* Start by making a pass over the chunk, allocating storage
10606 and taking note of what registers are used. */
10607 unsigned char *tmp = start;
10609 while (start < block_end)
10612 unsigned long reg, tmp;
10619 /* Warning: if you add any more cases to this switch, be
10620 sure to add them to the corresponding switch below. */
10623 case DW_CFA_advance_loc:
10625 case DW_CFA_offset:
10627 frame_need_space (fc, opa);
10628 fc->col_type[opa] = DW_CFA_undefined;
10630 case DW_CFA_restore:
10631 frame_need_space (fc, opa);
10632 fc->col_type[opa] = DW_CFA_undefined;
10634 case DW_CFA_set_loc:
10635 start += encoded_ptr_size;
10637 case DW_CFA_advance_loc1:
10640 case DW_CFA_advance_loc2:
10643 case DW_CFA_advance_loc4:
10646 case DW_CFA_offset_extended:
10647 reg = LEB (); LEB ();
10648 frame_need_space (fc, reg);
10649 fc->col_type[reg] = DW_CFA_undefined;
10651 case DW_CFA_restore_extended:
10653 frame_need_space (fc, reg);
10654 fc->col_type[reg] = DW_CFA_undefined;
10656 case DW_CFA_undefined:
10658 frame_need_space (fc, reg);
10659 fc->col_type[reg] = DW_CFA_undefined;
10661 case DW_CFA_same_value:
10663 frame_need_space (fc, reg);
10664 fc->col_type[reg] = DW_CFA_undefined;
10666 case DW_CFA_register:
10667 reg = LEB (); LEB ();
10668 frame_need_space (fc, reg);
10669 fc->col_type[reg] = DW_CFA_undefined;
10671 case DW_CFA_def_cfa:
10674 case DW_CFA_def_cfa_register:
10677 case DW_CFA_def_cfa_offset:
10680 case DW_CFA_def_cfa_expression:
10684 case DW_CFA_expression:
10688 frame_need_space (fc, reg);
10689 fc->col_type[reg] = DW_CFA_undefined;
10691 case DW_CFA_offset_extended_sf:
10692 reg = LEB (); SLEB ();
10693 frame_need_space (fc, reg);
10694 fc->col_type[reg] = DW_CFA_undefined;
10696 case DW_CFA_def_cfa_sf:
10699 case DW_CFA_def_cfa_offset_sf:
10702 case DW_CFA_MIPS_advance_loc8:
10705 case DW_CFA_GNU_args_size:
10708 case DW_CFA_GNU_negative_offset_extended:
10709 reg = LEB (); LEB ();
10710 frame_need_space (fc, reg);
10711 fc->col_type[reg] = DW_CFA_undefined;
10720 /* Now we know what registers are used, make a second pass over
10721 the chunk, this time actually printing out the info. */
10723 while (start < block_end)
10726 unsigned long ul, reg, roffs;
10735 /* Warning: if you add any more cases to this switch, be
10736 sure to add them to the corresponding switch above. */
10739 case DW_CFA_advance_loc:
10740 if (do_debug_frames_interp)
10741 frame_display_row (fc, &need_col_headers, &max_regs);
10743 printf (" DW_CFA_advance_loc: %d to %08lx\n",
10744 opa * fc->code_factor,
10745 fc->pc_begin + opa * fc->code_factor);
10746 fc->pc_begin += opa * fc->code_factor;
10749 case DW_CFA_offset:
10751 if (! do_debug_frames_interp)
10752 printf (" DW_CFA_offset: r%d at cfa%+ld\n",
10753 opa, roffs * fc->data_factor);
10754 fc->col_type[opa] = DW_CFA_offset;
10755 fc->col_offset[opa] = roffs * fc->data_factor;
10758 case DW_CFA_restore:
10759 if (! do_debug_frames_interp)
10760 printf (" DW_CFA_restore: r%d\n", opa);
10761 fc->col_type[opa] = cie->col_type[opa];
10762 fc->col_offset[opa] = cie->col_offset[opa];
10765 case DW_CFA_set_loc:
10766 vma = get_encoded_value (start, fc->fde_encoding);
10767 if ((fc->fde_encoding & 0x70) == DW_EH_PE_pcrel
10768 && elf_header.e_type != ET_REL)
10769 vma += section->sh_addr + (start - section_start);
10770 start += encoded_ptr_size;
10771 if (do_debug_frames_interp)
10772 frame_display_row (fc, &need_col_headers, &max_regs);
10774 printf (" DW_CFA_set_loc: %08lx\n", (unsigned long)vma);
10775 fc->pc_begin = vma;
10778 case DW_CFA_advance_loc1:
10779 ofs = byte_get (start, 1); start += 1;
10780 if (do_debug_frames_interp)
10781 frame_display_row (fc, &need_col_headers, &max_regs);
10783 printf (" DW_CFA_advance_loc1: %ld to %08lx\n",
10784 ofs * fc->code_factor,
10785 fc->pc_begin + ofs * fc->code_factor);
10786 fc->pc_begin += ofs * fc->code_factor;
10789 case DW_CFA_advance_loc2:
10790 ofs = byte_get (start, 2); start += 2;
10791 if (do_debug_frames_interp)
10792 frame_display_row (fc, &need_col_headers, &max_regs);
10794 printf (" DW_CFA_advance_loc2: %ld to %08lx\n",
10795 ofs * fc->code_factor,
10796 fc->pc_begin + ofs * fc->code_factor);
10797 fc->pc_begin += ofs * fc->code_factor;
10800 case DW_CFA_advance_loc4:
10801 ofs = byte_get (start, 4); start += 4;
10802 if (do_debug_frames_interp)
10803 frame_display_row (fc, &need_col_headers, &max_regs);
10805 printf (" DW_CFA_advance_loc4: %ld to %08lx\n",
10806 ofs * fc->code_factor,
10807 fc->pc_begin + ofs * fc->code_factor);
10808 fc->pc_begin += ofs * fc->code_factor;
10811 case DW_CFA_offset_extended:
10814 if (! do_debug_frames_interp)
10815 printf (" DW_CFA_offset_extended: r%ld at cfa%+ld\n",
10816 reg, roffs * fc->data_factor);
10817 fc->col_type[reg] = DW_CFA_offset;
10818 fc->col_offset[reg] = roffs * fc->data_factor;
10821 case DW_CFA_restore_extended:
10823 if (! do_debug_frames_interp)
10824 printf (" DW_CFA_restore_extended: r%ld\n", reg);
10825 fc->col_type[reg] = cie->col_type[reg];
10826 fc->col_offset[reg] = cie->col_offset[reg];
10829 case DW_CFA_undefined:
10831 if (! do_debug_frames_interp)
10832 printf (" DW_CFA_undefined: r%ld\n", reg);
10833 fc->col_type[reg] = DW_CFA_undefined;
10834 fc->col_offset[reg] = 0;
10837 case DW_CFA_same_value:
10839 if (! do_debug_frames_interp)
10840 printf (" DW_CFA_same_value: r%ld\n", reg);
10841 fc->col_type[reg] = DW_CFA_same_value;
10842 fc->col_offset[reg] = 0;
10845 case DW_CFA_register:
10848 if (! do_debug_frames_interp)
10849 printf (" DW_CFA_register: r%ld in r%ld\n", reg, roffs);
10850 fc->col_type[reg] = DW_CFA_register;
10851 fc->col_offset[reg] = roffs;
10854 case DW_CFA_remember_state:
10855 if (! do_debug_frames_interp)
10856 printf (" DW_CFA_remember_state\n");
10857 rs = xmalloc (sizeof (Frame_Chunk));
10858 rs->ncols = fc->ncols;
10859 rs->col_type = xcmalloc (rs->ncols, sizeof (short int));
10860 rs->col_offset = xcmalloc (rs->ncols, sizeof (int));
10861 memcpy (rs->col_type, fc->col_type, rs->ncols);
10862 memcpy (rs->col_offset, fc->col_offset, rs->ncols * sizeof (int));
10863 rs->next = remembered_state;
10864 remembered_state = rs;
10867 case DW_CFA_restore_state:
10868 if (! do_debug_frames_interp)
10869 printf (" DW_CFA_restore_state\n");
10870 rs = remembered_state;
10873 remembered_state = rs->next;
10874 frame_need_space (fc, rs->ncols-1);
10875 memcpy (fc->col_type, rs->col_type, rs->ncols);
10876 memcpy (fc->col_offset, rs->col_offset,
10877 rs->ncols * sizeof (int));
10878 free (rs->col_type);
10879 free (rs->col_offset);
10882 else if (do_debug_frames_interp)
10883 printf ("Mismatched DW_CFA_restore_state\n");
10886 case DW_CFA_def_cfa:
10887 fc->cfa_reg = LEB ();
10888 fc->cfa_offset = LEB ();
10890 if (! do_debug_frames_interp)
10891 printf (" DW_CFA_def_cfa: r%d ofs %d\n",
10892 fc->cfa_reg, fc->cfa_offset);
10895 case DW_CFA_def_cfa_register:
10896 fc->cfa_reg = LEB ();
10898 if (! do_debug_frames_interp)
10899 printf (" DW_CFA_def_cfa_reg: r%d\n", fc->cfa_reg);
10902 case DW_CFA_def_cfa_offset:
10903 fc->cfa_offset = LEB ();
10904 if (! do_debug_frames_interp)
10905 printf (" DW_CFA_def_cfa_offset: %d\n", fc->cfa_offset);
10909 if (! do_debug_frames_interp)
10910 printf (" DW_CFA_nop\n");
10913 case DW_CFA_def_cfa_expression:
10915 if (! do_debug_frames_interp)
10917 printf (" DW_CFA_def_cfa_expression (");
10918 decode_location_expression (start, eh_addr_size, ul, 0);
10925 case DW_CFA_expression:
10928 if (! do_debug_frames_interp)
10930 printf (" DW_CFA_expression: r%ld (", reg);
10931 decode_location_expression (start, eh_addr_size, ul, 0);
10934 fc->col_type[reg] = DW_CFA_expression;
10938 case DW_CFA_offset_extended_sf:
10941 frame_need_space (fc, reg);
10942 if (! do_debug_frames_interp)
10943 printf (" DW_CFA_offset_extended_sf: r%ld at cfa%+ld\n",
10944 reg, l * fc->data_factor);
10945 fc->col_type[reg] = DW_CFA_offset;
10946 fc->col_offset[reg] = l * fc->data_factor;
10949 case DW_CFA_def_cfa_sf:
10950 fc->cfa_reg = LEB ();
10951 fc->cfa_offset = SLEB ();
10952 fc->cfa_offset = fc->cfa_offset * fc->data_factor;
10954 if (! do_debug_frames_interp)
10955 printf (" DW_CFA_def_cfa_sf: r%d ofs %d\n",
10956 fc->cfa_reg, fc->cfa_offset);
10959 case DW_CFA_def_cfa_offset_sf:
10960 fc->cfa_offset = SLEB ();
10961 fc->cfa_offset = fc->cfa_offset * fc->data_factor;
10962 if (! do_debug_frames_interp)
10963 printf (" DW_CFA_def_cfa_offset_sf: %d\n", fc->cfa_offset);
10966 case DW_CFA_MIPS_advance_loc8:
10967 ofs = byte_get (start, 8); start += 8;
10968 if (do_debug_frames_interp)
10969 frame_display_row (fc, &need_col_headers, &max_regs);
10971 printf (" DW_CFA_MIPS_advance_loc8: %ld to %08lx\n",
10972 ofs * fc->code_factor,
10973 fc->pc_begin + ofs * fc->code_factor);
10974 fc->pc_begin += ofs * fc->code_factor;
10977 case DW_CFA_GNU_window_save:
10978 if (! do_debug_frames_interp)
10979 printf (" DW_CFA_GNU_window_save\n");
10982 case DW_CFA_GNU_args_size:
10984 if (! do_debug_frames_interp)
10985 printf (" DW_CFA_GNU_args_size: %ld\n", ul);
10988 case DW_CFA_GNU_negative_offset_extended:
10991 frame_need_space (fc, reg);
10992 if (! do_debug_frames_interp)
10993 printf (" DW_CFA_GNU_negative_offset_extended: r%ld at cfa%+ld\n",
10994 reg, l * fc->data_factor);
10995 fc->col_type[reg] = DW_CFA_offset;
10996 fc->col_offset[reg] = l * fc->data_factor;
11000 warn (_("unsupported or unknown DW_CFA_%d\n"), op);
11005 if (do_debug_frames_interp)
11006 frame_display_row (fc, &need_col_headers, &max_regs);
11021 display_debug_not_supported (Elf_Internal_Shdr *section,
11022 unsigned char *start ATTRIBUTE_UNUSED,
11023 FILE *file ATTRIBUTE_UNUSED)
11025 printf (_("Displaying the debug contents of section %s is not yet supported.\n"),
11026 SECTION_NAME (section));
11031 /* A structure containing the name of a debug section
11032 and a pointer to a function that can decode it. */
11035 const char *const name;
11036 int (*display) (Elf_Internal_Shdr *, unsigned char *, FILE *);
11040 { ".debug_abbrev", display_debug_abbrev },
11041 { ".debug_aranges", display_debug_aranges },
11042 { ".debug_frame", display_debug_frames },
11043 { ".debug_info", display_debug_info },
11044 { ".debug_line", display_debug_lines },
11045 { ".debug_pubnames", display_debug_pubnames },
11046 { ".eh_frame", display_debug_frames },
11047 { ".debug_macinfo", display_debug_macinfo },
11048 { ".debug_str", display_debug_str },
11049 { ".debug_loc", display_debug_loc },
11050 { ".debug_pubtypes", display_debug_pubnames },
11051 { ".debug_ranges", display_debug_ranges },
11052 { ".debug_static_func", display_debug_not_supported },
11053 { ".debug_static_vars", display_debug_not_supported },
11054 { ".debug_types", display_debug_not_supported },
11055 { ".debug_weaknames", display_debug_not_supported }
11059 display_debug_section (Elf_Internal_Shdr *section, FILE *file)
11061 char *name = SECTION_NAME (section);
11062 bfd_size_type length;
11066 length = section->sh_size;
11069 printf (_("\nSection '%s' has no debugging data.\n"), name);
11073 if (strneq (name, ".gnu.linkonce.wi.", 17))
11074 name = ".debug_info";
11076 /* See if we know how to display the contents of this section. */
11077 for (i = NUM_ELEM (debug_displays); i--;)
11078 if (streq (debug_displays[i].name, name))
11080 unsigned char *start;
11082 start = get_data (NULL, file, section->sh_offset, 1, length,
11083 _("debug section data"));
11090 result &= debug_displays[i].display (section, start, file);
11093 /* If we loaded in the abbrev section
11094 at some point, we must release it here. */
11102 printf (_("Unrecognized debug section: %s\n"), name);
11110 process_section_contents (FILE *file)
11112 Elf_Internal_Shdr *section;
11118 for (i = 0, section = section_headers;
11119 i < elf_header.e_shnum && i < num_dump_sects;
11122 #ifdef SUPPORT_DISASSEMBLY
11123 if (dump_sects[i] & DISASS_DUMP)
11124 disassemble_section (section, file);
11126 if (dump_sects[i] & HEX_DUMP)
11127 dump_section (section, file);
11129 if (dump_sects[i] & DEBUG_DUMP)
11130 display_debug_section (section, file);
11133 /* Check to see if the user requested a
11134 dump of a section that does not exist. */
11135 while (i++ < num_dump_sects)
11137 warn (_("Section %d was not dumped because it does not exist!\n"), i);
11141 process_mips_fpe_exception (int mask)
11146 if (mask & OEX_FPU_INEX)
11147 fputs ("INEX", stdout), first = 0;
11148 if (mask & OEX_FPU_UFLO)
11149 printf ("%sUFLO", first ? "" : "|"), first = 0;
11150 if (mask & OEX_FPU_OFLO)
11151 printf ("%sOFLO", first ? "" : "|"), first = 0;
11152 if (mask & OEX_FPU_DIV0)
11153 printf ("%sDIV0", first ? "" : "|"), first = 0;
11154 if (mask & OEX_FPU_INVAL)
11155 printf ("%sINVAL", first ? "" : "|");
11158 fputs ("0", stdout);
11162 process_mips_specific (FILE *file)
11164 Elf_Internal_Dyn *entry;
11165 size_t liblist_offset = 0;
11166 size_t liblistno = 0;
11167 size_t conflictsno = 0;
11168 size_t options_offset = 0;
11169 size_t conflicts_offset = 0;
11171 /* We have a lot of special sections. Thanks SGI! */
11172 if (dynamic_section == NULL)
11173 /* No information available. */
11176 for (entry = dynamic_section; entry->d_tag != DT_NULL; ++entry)
11177 switch (entry->d_tag)
11179 case DT_MIPS_LIBLIST:
11181 = offset_from_vma (file, entry->d_un.d_val,
11182 liblistno * sizeof (Elf32_External_Lib));
11184 case DT_MIPS_LIBLISTNO:
11185 liblistno = entry->d_un.d_val;
11187 case DT_MIPS_OPTIONS:
11188 options_offset = offset_from_vma (file, entry->d_un.d_val, 0);
11190 case DT_MIPS_CONFLICT:
11192 = offset_from_vma (file, entry->d_un.d_val,
11193 conflictsno * sizeof (Elf32_External_Conflict));
11195 case DT_MIPS_CONFLICTNO:
11196 conflictsno = entry->d_un.d_val;
11202 if (liblist_offset != 0 && liblistno != 0 && do_dynamic)
11204 Elf32_External_Lib *elib;
11207 elib = get_data (NULL, file, liblist_offset,
11208 liblistno, sizeof (Elf32_External_Lib),
11212 printf ("\nSection '.liblist' contains %lu entries:\n",
11213 (unsigned long) liblistno);
11214 fputs (" Library Time Stamp Checksum Version Flags\n",
11217 for (cnt = 0; cnt < liblistno; ++cnt)
11224 liblist.l_name = BYTE_GET (elib[cnt].l_name);
11225 time = BYTE_GET (elib[cnt].l_time_stamp);
11226 liblist.l_checksum = BYTE_GET (elib[cnt].l_checksum);
11227 liblist.l_version = BYTE_GET (elib[cnt].l_version);
11228 liblist.l_flags = BYTE_GET (elib[cnt].l_flags);
11230 tmp = gmtime (&time);
11231 snprintf (timebuf, sizeof (timebuf),
11232 "%04u-%02u-%02uT%02u:%02u:%02u",
11233 tmp->tm_year + 1900, tmp->tm_mon + 1, tmp->tm_mday,
11234 tmp->tm_hour, tmp->tm_min, tmp->tm_sec);
11236 printf ("%3lu: ", (unsigned long) cnt);
11237 if (VALID_DYNAMIC_NAME (liblist.l_name))
11238 print_symbol (20, GET_DYNAMIC_NAME (liblist.l_name));
11240 printf ("<corrupt: %9ld>", liblist.l_name);
11241 printf (" %s %#10lx %-7ld", timebuf, liblist.l_checksum,
11242 liblist.l_version);
11244 if (liblist.l_flags == 0)
11248 static const struct
11255 { " EXACT_MATCH", LL_EXACT_MATCH },
11256 { " IGNORE_INT_VER", LL_IGNORE_INT_VER },
11257 { " REQUIRE_MINOR", LL_REQUIRE_MINOR },
11258 { " EXPORTS", LL_EXPORTS },
11259 { " DELAY_LOAD", LL_DELAY_LOAD },
11260 { " DELTA", LL_DELTA }
11262 int flags = liblist.l_flags;
11266 fcnt < sizeof (l_flags_vals) / sizeof (l_flags_vals[0]);
11268 if ((flags & l_flags_vals[fcnt].bit) != 0)
11270 fputs (l_flags_vals[fcnt].name, stdout);
11271 flags ^= l_flags_vals[fcnt].bit;
11274 printf (" %#x", (unsigned int) flags);
11284 if (options_offset != 0)
11286 Elf_External_Options *eopt;
11287 Elf_Internal_Shdr *sect = section_headers;
11288 Elf_Internal_Options *iopt;
11289 Elf_Internal_Options *option;
11293 /* Find the section header so that we get the size. */
11294 while (sect->sh_type != SHT_MIPS_OPTIONS)
11297 eopt = get_data (NULL, file, options_offset, 1, sect->sh_size,
11301 iopt = cmalloc ((sect->sh_size / sizeof (eopt)), sizeof (*iopt));
11304 error (_("Out of memory"));
11311 while (offset < sect->sh_size)
11313 Elf_External_Options *eoption;
11315 eoption = (Elf_External_Options *) ((char *) eopt + offset);
11317 option->kind = BYTE_GET (eoption->kind);
11318 option->size = BYTE_GET (eoption->size);
11319 option->section = BYTE_GET (eoption->section);
11320 option->info = BYTE_GET (eoption->info);
11322 offset += option->size;
11328 printf (_("\nSection '%s' contains %d entries:\n"),
11329 SECTION_NAME (sect), cnt);
11337 switch (option->kind)
11340 /* This shouldn't happen. */
11341 printf (" NULL %d %lx", option->section, option->info);
11344 printf (" REGINFO ");
11345 if (elf_header.e_machine == EM_MIPS)
11348 Elf32_External_RegInfo *ereg;
11349 Elf32_RegInfo reginfo;
11351 ereg = (Elf32_External_RegInfo *) (option + 1);
11352 reginfo.ri_gprmask = BYTE_GET (ereg->ri_gprmask);
11353 reginfo.ri_cprmask[0] = BYTE_GET (ereg->ri_cprmask[0]);
11354 reginfo.ri_cprmask[1] = BYTE_GET (ereg->ri_cprmask[1]);
11355 reginfo.ri_cprmask[2] = BYTE_GET (ereg->ri_cprmask[2]);
11356 reginfo.ri_cprmask[3] = BYTE_GET (ereg->ri_cprmask[3]);
11357 reginfo.ri_gp_value = BYTE_GET (ereg->ri_gp_value);
11359 printf ("GPR %08lx GP 0x%lx\n",
11360 reginfo.ri_gprmask,
11361 (unsigned long) reginfo.ri_gp_value);
11362 printf (" CPR0 %08lx CPR1 %08lx CPR2 %08lx CPR3 %08lx\n",
11363 reginfo.ri_cprmask[0], reginfo.ri_cprmask[1],
11364 reginfo.ri_cprmask[2], reginfo.ri_cprmask[3]);
11369 Elf64_External_RegInfo *ereg;
11370 Elf64_Internal_RegInfo reginfo;
11372 ereg = (Elf64_External_RegInfo *) (option + 1);
11373 reginfo.ri_gprmask = BYTE_GET (ereg->ri_gprmask);
11374 reginfo.ri_cprmask[0] = BYTE_GET (ereg->ri_cprmask[0]);
11375 reginfo.ri_cprmask[1] = BYTE_GET (ereg->ri_cprmask[1]);
11376 reginfo.ri_cprmask[2] = BYTE_GET (ereg->ri_cprmask[2]);
11377 reginfo.ri_cprmask[3] = BYTE_GET (ereg->ri_cprmask[3]);
11378 reginfo.ri_gp_value = BYTE_GET (ereg->ri_gp_value);
11380 printf ("GPR %08lx GP 0x",
11381 reginfo.ri_gprmask);
11382 printf_vma (reginfo.ri_gp_value);
11385 printf (" CPR0 %08lx CPR1 %08lx CPR2 %08lx CPR3 %08lx\n",
11386 reginfo.ri_cprmask[0], reginfo.ri_cprmask[1],
11387 reginfo.ri_cprmask[2], reginfo.ri_cprmask[3]);
11391 case ODK_EXCEPTIONS:
11392 fputs (" EXCEPTIONS fpe_min(", stdout);
11393 process_mips_fpe_exception (option->info & OEX_FPU_MIN);
11394 fputs (") fpe_max(", stdout);
11395 process_mips_fpe_exception ((option->info & OEX_FPU_MAX) >> 8);
11396 fputs (")", stdout);
11398 if (option->info & OEX_PAGE0)
11399 fputs (" PAGE0", stdout);
11400 if (option->info & OEX_SMM)
11401 fputs (" SMM", stdout);
11402 if (option->info & OEX_FPDBUG)
11403 fputs (" FPDBUG", stdout);
11404 if (option->info & OEX_DISMISS)
11405 fputs (" DISMISS", stdout);
11408 fputs (" PAD ", stdout);
11409 if (option->info & OPAD_PREFIX)
11410 fputs (" PREFIX", stdout);
11411 if (option->info & OPAD_POSTFIX)
11412 fputs (" POSTFIX", stdout);
11413 if (option->info & OPAD_SYMBOL)
11414 fputs (" SYMBOL", stdout);
11417 fputs (" HWPATCH ", stdout);
11418 if (option->info & OHW_R4KEOP)
11419 fputs (" R4KEOP", stdout);
11420 if (option->info & OHW_R8KPFETCH)
11421 fputs (" R8KPFETCH", stdout);
11422 if (option->info & OHW_R5KEOP)
11423 fputs (" R5KEOP", stdout);
11424 if (option->info & OHW_R5KCVTL)
11425 fputs (" R5KCVTL", stdout);
11428 fputs (" FILL ", stdout);
11429 /* XXX Print content of info word? */
11432 fputs (" TAGS ", stdout);
11433 /* XXX Print content of info word? */
11436 fputs (" HWAND ", stdout);
11437 if (option->info & OHWA0_R4KEOP_CHECKED)
11438 fputs (" R4KEOP_CHECKED", stdout);
11439 if (option->info & OHWA0_R4KEOP_CLEAN)
11440 fputs (" R4KEOP_CLEAN", stdout);
11443 fputs (" HWOR ", stdout);
11444 if (option->info & OHWA0_R4KEOP_CHECKED)
11445 fputs (" R4KEOP_CHECKED", stdout);
11446 if (option->info & OHWA0_R4KEOP_CLEAN)
11447 fputs (" R4KEOP_CLEAN", stdout);
11450 printf (" GP_GROUP %#06lx self-contained %#06lx",
11451 option->info & OGP_GROUP,
11452 (option->info & OGP_SELF) >> 16);
11455 printf (" IDENT %#06lx self-contained %#06lx",
11456 option->info & OGP_GROUP,
11457 (option->info & OGP_SELF) >> 16);
11460 /* This shouldn't happen. */
11461 printf (" %3d ??? %d %lx",
11462 option->kind, option->section, option->info);
11466 len = sizeof (*eopt);
11467 while (len < option->size)
11468 if (((char *) option)[len] >= ' '
11469 && ((char *) option)[len] < 0x7f)
11470 printf ("%c", ((char *) option)[len++]);
11472 printf ("\\%03o", ((char *) option)[len++]);
11474 fputs ("\n", stdout);
11482 if (conflicts_offset != 0 && conflictsno != 0)
11484 Elf32_Conflict *iconf;
11487 if (dynamic_symbols == NULL)
11489 error (_("conflict list found without a dynamic symbol table"));
11493 iconf = cmalloc (conflictsno, sizeof (*iconf));
11496 error (_("Out of memory"));
11502 Elf32_External_Conflict *econf32;
11504 econf32 = get_data (NULL, file, conflicts_offset,
11505 conflictsno, sizeof (*econf32), _("conflict"));
11509 for (cnt = 0; cnt < conflictsno; ++cnt)
11510 iconf[cnt] = BYTE_GET (econf32[cnt]);
11516 Elf64_External_Conflict *econf64;
11518 econf64 = get_data (NULL, file, conflicts_offset,
11519 conflictsno, sizeof (*econf64), _("conflict"));
11523 for (cnt = 0; cnt < conflictsno; ++cnt)
11524 iconf[cnt] = BYTE_GET (econf64[cnt]);
11529 printf (_("\nSection '.conflict' contains %lu entries:\n"),
11530 (unsigned long) conflictsno);
11531 puts (_(" Num: Index Value Name"));
11533 for (cnt = 0; cnt < conflictsno; ++cnt)
11535 Elf_Internal_Sym *psym = & dynamic_symbols[iconf[cnt]];
11537 printf ("%5lu: %8lu ", (unsigned long) cnt, iconf[cnt]);
11538 print_vma (psym->st_value, FULL_HEX);
11540 if (VALID_DYNAMIC_NAME (psym->st_name))
11541 print_symbol (25, GET_DYNAMIC_NAME (psym->st_name));
11543 printf ("<corrupt: %14ld>", psym->st_name);
11554 process_gnu_liblist (FILE *file)
11556 Elf_Internal_Shdr *section, *string_sec;
11557 Elf32_External_Lib *elib;
11559 size_t strtab_size;
11566 for (i = 0, section = section_headers;
11567 i < elf_header.e_shnum;
11570 switch (section->sh_type)
11572 case SHT_GNU_LIBLIST:
11573 if (SECTION_HEADER_INDEX (section->sh_link) >= elf_header.e_shnum)
11576 elib = get_data (NULL, file, section->sh_offset, 1, section->sh_size,
11581 string_sec = SECTION_HEADER (section->sh_link);
11583 strtab = get_data (NULL, file, string_sec->sh_offset, 1,
11584 string_sec->sh_size, _("liblist string table"));
11585 strtab_size = string_sec->sh_size;
11588 || section->sh_entsize != sizeof (Elf32_External_Lib))
11594 printf (_("\nLibrary list section '%s' contains %lu entries:\n"),
11595 SECTION_NAME (section),
11596 (long) (section->sh_size / sizeof (Elf32_External_Lib)));
11598 puts (" Library Time Stamp Checksum Version Flags");
11600 for (cnt = 0; cnt < section->sh_size / sizeof (Elf32_External_Lib);
11608 liblist.l_name = BYTE_GET (elib[cnt].l_name);
11609 time = BYTE_GET (elib[cnt].l_time_stamp);
11610 liblist.l_checksum = BYTE_GET (elib[cnt].l_checksum);
11611 liblist.l_version = BYTE_GET (elib[cnt].l_version);
11612 liblist.l_flags = BYTE_GET (elib[cnt].l_flags);
11614 tmp = gmtime (&time);
11615 snprintf (timebuf, sizeof (timebuf),
11616 "%04u-%02u-%02uT%02u:%02u:%02u",
11617 tmp->tm_year + 1900, tmp->tm_mon + 1, tmp->tm_mday,
11618 tmp->tm_hour, tmp->tm_min, tmp->tm_sec);
11620 printf ("%3lu: ", (unsigned long) cnt);
11622 printf ("%-20s", liblist.l_name < strtab_size
11623 ? strtab + liblist.l_name : "<corrupt>");
11625 printf ("%-20.20s", liblist.l_name < strtab_size
11626 ? strtab + liblist.l_name : "<corrupt>");
11627 printf (" %s %#010lx %-7ld %-7ld\n", timebuf, liblist.l_checksum,
11628 liblist.l_version, liblist.l_flags);
11638 static const char *
11639 get_note_type (unsigned e_type)
11641 static char buff[64];
11643 if (elf_header.e_type == ET_CORE)
11647 return _("NT_AUXV (auxiliary vector)");
11649 return _("NT_PRSTATUS (prstatus structure)");
11651 return _("NT_FPREGSET (floating point registers)");
11653 return _("NT_PRPSINFO (prpsinfo structure)");
11654 case NT_TASKSTRUCT:
11655 return _("NT_TASKSTRUCT (task structure)");
11657 return _("NT_PRXFPREG (user_xfpregs structure)");
11659 return _("NT_PSTATUS (pstatus structure)");
11661 return _("NT_FPREGS (floating point registers)");
11663 return _("NT_PSINFO (psinfo structure)");
11665 return _("NT_LWPSTATUS (lwpstatus_t structure)");
11667 return _("NT_LWPSINFO (lwpsinfo_t structure)");
11668 case NT_WIN32PSTATUS:
11669 return _("NT_WIN32PSTATUS (win32_pstatus structure)");
11677 return _("NT_VERSION (version)");
11679 return _("NT_ARCH (architecture)");
11684 snprintf (buff, sizeof (buff), _("Unknown note type: (0x%08x)"), e_type);
11688 static const char *
11689 get_netbsd_elfcore_note_type (unsigned e_type)
11691 static char buff[64];
11693 if (e_type == NT_NETBSDCORE_PROCINFO)
11695 /* NetBSD core "procinfo" structure. */
11696 return _("NetBSD procinfo structure");
11699 /* As of Jan 2002 there are no other machine-independent notes
11700 defined for NetBSD core files. If the note type is less
11701 than the start of the machine-dependent note types, we don't
11704 if (e_type < NT_NETBSDCORE_FIRSTMACH)
11706 snprintf (buff, sizeof (buff), _("Unknown note type: (0x%08x)"), e_type);
11710 switch (elf_header.e_machine)
11712 /* On the Alpha, SPARC (32-bit and 64-bit), PT_GETREGS == mach+0
11713 and PT_GETFPREGS == mach+2. */
11718 case EM_SPARC32PLUS:
11722 case NT_NETBSDCORE_FIRSTMACH+0:
11723 return _("PT_GETREGS (reg structure)");
11724 case NT_NETBSDCORE_FIRSTMACH+2:
11725 return _("PT_GETFPREGS (fpreg structure)");
11731 /* On all other arch's, PT_GETREGS == mach+1 and
11732 PT_GETFPREGS == mach+3. */
11736 case NT_NETBSDCORE_FIRSTMACH+1:
11737 return _("PT_GETREGS (reg structure)");
11738 case NT_NETBSDCORE_FIRSTMACH+3:
11739 return _("PT_GETFPREGS (fpreg structure)");
11745 snprintf (buff, sizeof (buff), _("PT_FIRSTMACH+%d"),
11746 e_type - NT_NETBSDCORE_FIRSTMACH);
11750 /* Note that by the ELF standard, the name field is already null byte
11751 terminated, and namesz includes the terminating null byte.
11752 I.E. the value of namesz for the name "FSF" is 4.
11754 If the value of namesz is zero, there is no name present. */
11756 process_note (Elf_Internal_Note *pnote)
11760 if (pnote->namesz == 0)
11761 /* If there is no note name, then use the default set of
11762 note type strings. */
11763 nt = get_note_type (pnote->type);
11765 else if (strneq (pnote->namedata, "NetBSD-CORE", 11))
11766 /* NetBSD-specific core file notes. */
11767 nt = get_netbsd_elfcore_note_type (pnote->type);
11770 /* Don't recognize this note name; just use the default set of
11771 note type strings. */
11772 nt = get_note_type (pnote->type);
11774 printf (" %s\t\t0x%08lx\t%s\n",
11775 pnote->namesz ? pnote->namedata : "(NONE)",
11776 pnote->descsz, nt);
11782 process_corefile_note_segment (FILE *file, bfd_vma offset, bfd_vma length)
11784 Elf_External_Note *pnotes;
11785 Elf_External_Note *external;
11791 pnotes = get_data (NULL, file, offset, 1, length, _("notes"));
11797 printf (_("\nNotes at offset 0x%08lx with length 0x%08lx:\n"),
11798 (unsigned long) offset, (unsigned long) length);
11799 printf (_(" Owner\t\tData size\tDescription\n"));
11801 while (external < (Elf_External_Note *)((char *) pnotes + length))
11803 Elf_External_Note *next;
11804 Elf_Internal_Note inote;
11807 inote.type = BYTE_GET (external->type);
11808 inote.namesz = BYTE_GET (external->namesz);
11809 inote.namedata = external->name;
11810 inote.descsz = BYTE_GET (external->descsz);
11811 inote.descdata = inote.namedata + align_power (inote.namesz, 2);
11812 inote.descpos = offset + (inote.descdata - (char *) pnotes);
11814 next = (Elf_External_Note *)(inote.descdata + align_power (inote.descsz, 2));
11816 if (((char *) next) > (((char *) pnotes) + length))
11818 warn (_("corrupt note found at offset %lx into core notes\n"),
11819 (long)((char *)external - (char *)pnotes));
11820 warn (_(" type: %lx, namesize: %08lx, descsize: %08lx\n"),
11821 inote.type, inote.namesz, inote.descsz);
11827 /* Verify that name is null terminated. It appears that at least
11828 one version of Linux (RedHat 6.0) generates corefiles that don't
11829 comply with the ELF spec by failing to include the null byte in
11831 if (inote.namedata[inote.namesz] != '\0')
11833 temp = malloc (inote.namesz + 1);
11837 error (_("Out of memory\n"));
11842 strncpy (temp, inote.namedata, inote.namesz);
11843 temp[inote.namesz] = 0;
11845 /* warn (_("'%s' NOTE name not properly null terminated\n"), temp); */
11846 inote.namedata = temp;
11849 res &= process_note (& inote);
11864 process_corefile_note_segments (FILE *file)
11866 Elf_Internal_Phdr *segment;
11870 if (! get_program_headers (file))
11873 for (i = 0, segment = program_headers;
11874 i < elf_header.e_phnum;
11877 if (segment->p_type == PT_NOTE)
11878 res &= process_corefile_note_segment (file,
11879 (bfd_vma) segment->p_offset,
11880 (bfd_vma) segment->p_filesz);
11887 process_note_sections (FILE *file)
11889 Elf_Internal_Shdr *section;
11893 for (i = 0, section = section_headers;
11894 i < elf_header.e_shnum;
11896 if (section->sh_type == SHT_NOTE)
11897 res &= process_corefile_note_segment (file,
11898 (bfd_vma) section->sh_offset,
11899 (bfd_vma) section->sh_size);
11905 process_notes (FILE *file)
11907 /* If we have not been asked to display the notes then do nothing. */
11911 if (elf_header.e_type != ET_CORE)
11912 return process_note_sections (file);
11914 /* No program headers means no NOTE segment. */
11915 if (elf_header.e_phnum > 0)
11916 return process_corefile_note_segments (file);
11918 printf (_("No note segments present in the core file.\n"));
11923 process_arch_specific (FILE *file)
11928 switch (elf_header.e_machine)
11931 case EM_MIPS_RS3_LE:
11932 return process_mips_specific (file);
11941 get_file_header (FILE *file)
11943 /* Read in the identity array. */
11944 if (fread (elf_header.e_ident, EI_NIDENT, 1, file) != 1)
11947 /* Determine how to read the rest of the header. */
11948 switch (elf_header.e_ident[EI_DATA])
11950 default: /* fall through */
11951 case ELFDATANONE: /* fall through */
11953 byte_get = byte_get_little_endian;
11954 byte_put = byte_put_little_endian;
11957 byte_get = byte_get_big_endian;
11958 byte_put = byte_put_big_endian;
11962 /* For now we only support 32 bit and 64 bit ELF files. */
11963 is_32bit_elf = (elf_header.e_ident[EI_CLASS] != ELFCLASS64);
11965 /* Read in the rest of the header. */
11968 Elf32_External_Ehdr ehdr32;
11970 if (fread (ehdr32.e_type, sizeof (ehdr32) - EI_NIDENT, 1, file) != 1)
11973 elf_header.e_type = BYTE_GET (ehdr32.e_type);
11974 elf_header.e_machine = BYTE_GET (ehdr32.e_machine);
11975 elf_header.e_version = BYTE_GET (ehdr32.e_version);
11976 elf_header.e_entry = BYTE_GET (ehdr32.e_entry);
11977 elf_header.e_phoff = BYTE_GET (ehdr32.e_phoff);
11978 elf_header.e_shoff = BYTE_GET (ehdr32.e_shoff);
11979 elf_header.e_flags = BYTE_GET (ehdr32.e_flags);
11980 elf_header.e_ehsize = BYTE_GET (ehdr32.e_ehsize);
11981 elf_header.e_phentsize = BYTE_GET (ehdr32.e_phentsize);
11982 elf_header.e_phnum = BYTE_GET (ehdr32.e_phnum);
11983 elf_header.e_shentsize = BYTE_GET (ehdr32.e_shentsize);
11984 elf_header.e_shnum = BYTE_GET (ehdr32.e_shnum);
11985 elf_header.e_shstrndx = BYTE_GET (ehdr32.e_shstrndx);
11989 Elf64_External_Ehdr ehdr64;
11991 /* If we have been compiled with sizeof (bfd_vma) == 4, then
11992 we will not be able to cope with the 64bit data found in
11993 64 ELF files. Detect this now and abort before we start
11994 overwriting things. */
11995 if (sizeof (bfd_vma) < 8)
11997 error (_("This instance of readelf has been built without support for a\n\
11998 64 bit data type and so it cannot read 64 bit ELF files.\n"));
12002 if (fread (ehdr64.e_type, sizeof (ehdr64) - EI_NIDENT, 1, file) != 1)
12005 elf_header.e_type = BYTE_GET (ehdr64.e_type);
12006 elf_header.e_machine = BYTE_GET (ehdr64.e_machine);
12007 elf_header.e_version = BYTE_GET (ehdr64.e_version);
12008 elf_header.e_entry = BYTE_GET (ehdr64.e_entry);
12009 elf_header.e_phoff = BYTE_GET (ehdr64.e_phoff);
12010 elf_header.e_shoff = BYTE_GET (ehdr64.e_shoff);
12011 elf_header.e_flags = BYTE_GET (ehdr64.e_flags);
12012 elf_header.e_ehsize = BYTE_GET (ehdr64.e_ehsize);
12013 elf_header.e_phentsize = BYTE_GET (ehdr64.e_phentsize);
12014 elf_header.e_phnum = BYTE_GET (ehdr64.e_phnum);
12015 elf_header.e_shentsize = BYTE_GET (ehdr64.e_shentsize);
12016 elf_header.e_shnum = BYTE_GET (ehdr64.e_shnum);
12017 elf_header.e_shstrndx = BYTE_GET (ehdr64.e_shstrndx);
12020 if (elf_header.e_shoff)
12022 /* There may be some extensions in the first section header. Don't
12023 bomb if we can't read it. */
12025 get_32bit_section_headers (file, 1);
12027 get_64bit_section_headers (file, 1);
12033 /* Process one ELF object file according to the command line options.
12034 This file may actually be stored in an archive. The file is
12035 positioned at the start of the ELF object. */
12038 process_object (char *file_name, FILE *file)
12042 if (! get_file_header (file))
12044 error (_("%s: Failed to read file header\n"), file_name);
12048 /* Initialise per file variables. */
12049 for (i = NUM_ELEM (version_info); i--;)
12050 version_info[i] = 0;
12052 for (i = NUM_ELEM (dynamic_info); i--;)
12053 dynamic_info[i] = 0;
12055 /* Process the file. */
12057 printf (_("\nFile: %s\n"), file_name);
12059 /* Initialise the dump_sects array from the cmdline_dump_sects array.
12060 Note we do this even if cmdline_dump_sects is empty because we
12061 must make sure that the dump_sets array is zeroed out before each
12062 object file is processed. */
12063 if (num_dump_sects > num_cmdline_dump_sects)
12064 memset (dump_sects, 0, num_dump_sects);
12066 if (num_cmdline_dump_sects > 0)
12068 if (num_dump_sects == 0)
12069 /* A sneaky way of allocating the dump_sects array. */
12070 request_dump (num_cmdline_dump_sects, 0);
12072 assert (num_dump_sects >= num_cmdline_dump_sects);
12073 memcpy (dump_sects, cmdline_dump_sects, num_cmdline_dump_sects);
12076 if (! process_file_header ())
12079 if (! process_section_headers (file))
12081 /* Without loaded section headers we cannot process lots of
12083 do_unwind = do_version = do_dump = do_arch = 0;
12085 if (! do_using_dynamic)
12086 do_syms = do_reloc = 0;
12089 if (! process_section_groups (file))
12091 /* Without loaded section groups we cannot process unwind. */
12095 if (process_program_headers (file))
12096 process_dynamic_section (file);
12098 process_relocs (file);
12100 process_unwind (file);
12102 process_symbol_table (file);
12104 process_syminfo (file);
12106 process_version_sections (file);
12108 process_section_contents (file);
12110 process_notes (file);
12112 process_gnu_liblist (file);
12114 process_arch_specific (file);
12116 if (program_headers)
12118 free (program_headers);
12119 program_headers = NULL;
12122 if (section_headers)
12124 free (section_headers);
12125 section_headers = NULL;
12130 free (string_table);
12131 string_table = NULL;
12132 string_table_length = 0;
12135 if (dynamic_strings)
12137 free (dynamic_strings);
12138 dynamic_strings = NULL;
12139 dynamic_strings_length = 0;
12142 if (dynamic_symbols)
12144 free (dynamic_symbols);
12145 dynamic_symbols = NULL;
12146 num_dynamic_syms = 0;
12149 if (dynamic_syminfo)
12151 free (dynamic_syminfo);
12152 dynamic_syminfo = NULL;
12155 if (section_headers_groups)
12157 free (section_headers_groups);
12158 section_headers_groups = NULL;
12161 if (section_groups)
12163 struct group_list *g, *next;
12165 for (i = 0; i < group_count; i++)
12167 for (g = section_groups [i].root; g != NULL; g = next)
12174 free (section_groups);
12175 section_groups = NULL;
12178 if (debug_information)
12180 for (i = 0; i < num_debug_info_entries; i++)
12182 if (!debug_information [i].max_loc_offsets)
12184 free (debug_information [i].loc_offsets);
12185 free (debug_information [i].have_frame_base);
12187 if (!debug_information [i].max_range_lists)
12188 free (debug_information [i].range_lists);
12190 free (debug_information);
12191 debug_information = NULL;
12192 num_debug_info_entries = 0;
12198 /* Process an ELF archive. The file is positioned just after the
12202 process_archive (char *file_name, FILE *file)
12204 struct ar_hdr arhdr;
12206 unsigned long size;
12207 char *longnames = NULL;
12208 unsigned long longnames_size = 0;
12209 size_t file_name_size;
12214 got = fread (&arhdr, 1, sizeof arhdr, file);
12215 if (got != sizeof arhdr)
12220 error (_("%s: failed to read archive header\n"), file_name);
12224 if (memcmp (arhdr.ar_name, "/ ", 16) == 0)
12226 /* This is the archive symbol table. Skip it.
12227 FIXME: We should have an option to dump it. */
12228 size = strtoul (arhdr.ar_size, NULL, 10);
12229 if (fseek (file, size + (size & 1), SEEK_CUR) != 0)
12231 error (_("%s: failed to skip archive symbol table\n"), file_name);
12235 got = fread (&arhdr, 1, sizeof arhdr, file);
12236 if (got != sizeof arhdr)
12241 error (_("%s: failed to read archive header\n"), file_name);
12246 if (memcmp (arhdr.ar_name, "// ", 16) == 0)
12248 /* This is the archive string table holding long member
12251 longnames_size = strtoul (arhdr.ar_size, NULL, 10);
12253 longnames = malloc (longnames_size);
12254 if (longnames == NULL)
12256 error (_("Out of memory\n"));
12260 if (fread (longnames, longnames_size, 1, file) != 1)
12263 error (_("%s: failed to read string table\n"), file_name);
12267 if ((longnames_size & 1) != 0)
12270 got = fread (&arhdr, 1, sizeof arhdr, file);
12271 if (got != sizeof arhdr)
12278 error (_("%s: failed to read archive header\n"), file_name);
12283 file_name_size = strlen (file_name);
12292 if (arhdr.ar_name[0] == '/')
12296 off = strtoul (arhdr.ar_name + 1, NULL, 10);
12297 if (off >= longnames_size)
12299 error (_("%s: invalid archive string table offset %lu\n"), file_name, off);
12304 name = longnames + off;
12305 nameend = memchr (name, '/', longnames_size - off);
12309 name = arhdr.ar_name;
12310 nameend = memchr (name, '/', 16);
12313 if (nameend == NULL)
12315 error (_("%s: bad archive file name\n"), file_name);
12320 namealc = malloc (file_name_size + (nameend - name) + 3);
12321 if (namealc == NULL)
12323 error (_("Out of memory\n"));
12328 memcpy (namealc, file_name, file_name_size);
12329 namealc[file_name_size] = '(';
12330 memcpy (namealc + file_name_size + 1, name, nameend - name);
12331 namealc[file_name_size + 1 + (nameend - name)] = ')';
12332 namealc[file_name_size + 2 + (nameend - name)] = '\0';
12334 archive_file_offset = ftell (file);
12335 archive_file_size = strtoul (arhdr.ar_size, NULL, 10);
12337 ret |= process_object (namealc, file);
12342 (archive_file_offset
12343 + archive_file_size
12344 + (archive_file_size & 1)),
12347 error (_("%s: failed to seek to next archive header\n"), file_name);
12352 got = fread (&arhdr, 1, sizeof arhdr, file);
12353 if (got != sizeof arhdr)
12358 error (_("%s: failed to read archive header\n"), file_name);
12364 if (longnames != 0)
12371 process_file (char *file_name)
12374 struct stat statbuf;
12375 char armag[SARMAG];
12378 if (stat (file_name, &statbuf) < 0)
12380 if (errno == ENOENT)
12381 error (_("'%s': No such file\n"), file_name);
12383 error (_("Could not locate '%s'. System error message: %s\n"),
12384 file_name, strerror (errno));
12388 if (! S_ISREG (statbuf.st_mode))
12390 error (_("'%s' is not an ordinary file\n"), file_name);
12394 file = fopen (file_name, "rb");
12397 error (_("Input file '%s' is not readable.\n"), file_name);
12401 if (fread (armag, SARMAG, 1, file) != 1)
12403 error (_("%s: Failed to read file header\n"), file_name);
12408 if (memcmp (armag, ARMAG, SARMAG) == 0)
12409 ret = process_archive (file_name, file);
12413 archive_file_size = archive_file_offset = 0;
12414 ret = process_object (file_name, file);
12422 #ifdef SUPPORT_DISASSEMBLY
12423 /* Needed by the i386 disassembler. For extra credit, someone could
12424 fix this so that we insert symbolic addresses here, esp for GOT/PLT
12428 print_address (unsigned int addr, FILE *outfile)
12430 fprintf (outfile,"0x%8.8x", addr);
12433 /* Needed by the i386 disassembler. */
12435 db_task_printsym (unsigned int addr)
12437 print_address (addr, stderr);
12442 main (int argc, char **argv)
12446 #if defined (HAVE_SETLOCALE) && defined (HAVE_LC_MESSAGES)
12447 setlocale (LC_MESSAGES, "");
12449 #if defined (HAVE_SETLOCALE)
12450 setlocale (LC_CTYPE, "");
12452 bindtextdomain (PACKAGE, LOCALEDIR);
12453 textdomain (PACKAGE);
12455 parse_args (argc, argv);
12457 if (num_dump_sects > 0)
12459 /* Make a copy of the dump_sects array. */
12460 cmdline_dump_sects = malloc (num_dump_sects);
12461 if (cmdline_dump_sects == NULL)
12462 error (_("Out of memory allocating dump request table."));
12465 memcpy (cmdline_dump_sects, dump_sects, num_dump_sects);
12466 num_cmdline_dump_sects = num_dump_sects;
12470 if (optind < (argc - 1))
12474 while (optind < argc)
12475 err |= process_file (argv[optind++]);
12477 if (dump_sects != NULL)
12479 if (cmdline_dump_sects != NULL)
12480 free (cmdline_dump_sects);