1 /* readelf.c -- display contents of an ELF format file
2 Copyright 1998, 1999, 2000, 2001, 2002, 2003 Free Software Foundation, Inc.
4 Originally developed by Eric Youngdale <eric@andante.jic.com>
5 Modifications by Nick Clifton <nickc@redhat.com>
7 This file is part of GNU Binutils.
9 This program is free software; you can redistribute it and/or modify
10 it under the terms of the GNU General Public License as published by
11 the Free Software Foundation; either version 2 of the License, or
12 (at your option) any later version.
14 This program is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 GNU General Public License for more details.
19 You should have received a copy of the GNU General Public License
20 along with this program; if not, write to the Free Software
21 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
26 #include <sys/types.h>
32 /* Define BFD64 here, even if our default architecture is 32 bit ELF
33 as this will allow us to read in and parse 64bit and 32bit ELF files.
34 Only do this if we believe that the compiler can support a 64 bit
35 data type. For now we only rely on GCC being able to do this. */
41 #include "elf/common.h"
42 #include "elf/external.h"
43 #include "elf/internal.h"
44 #include "elf/dwarf2.h"
46 /* The following headers use the elf/reloc-macros.h file to
47 automatically generate relocation recognition functions
48 such as elf_mips_reloc_type() */
50 #define RELOC_MACROS_GEN_FUNC
52 #include "elf/alpha.h"
72 #include "elf/m68hc11.h"
73 #include "elf/mcore.h"
76 #include "elf/mn10200.h"
77 #include "elf/mn10300.h"
78 #include "elf/msp430.h"
82 #include "elf/ppc64.h"
85 #include "elf/sparc.h"
88 #include "elf/x86-64.h"
89 #include "elf/xstormy16.h"
90 #include "elf/iq2000.h"
91 #include "elf/xtensa.h"
95 #include "libiberty.h"
97 char *program_name
= "readelf";
98 unsigned long dynamic_addr
;
99 bfd_size_type dynamic_size
;
100 char *dynamic_strings
;
102 unsigned long string_table_length
;
103 unsigned long num_dynamic_syms
;
104 Elf_Internal_Sym
*dynamic_symbols
;
105 Elf_Internal_Syminfo
*dynamic_syminfo
;
106 unsigned long dynamic_syminfo_offset
;
107 unsigned int dynamic_syminfo_nent
;
108 char program_interpreter
[64];
109 long dynamic_info
[DT_JMPREL
+ 1];
110 long version_info
[16];
112 Elf_Internal_Ehdr elf_header
;
113 Elf_Internal_Shdr
*section_headers
;
114 Elf_Internal_Dyn
*dynamic_segment
;
115 Elf_Internal_Shdr
*symtab_shndx_hdr
;
123 int do_using_dynamic
;
131 int do_debug_abbrevs
;
133 int do_debug_pubnames
;
134 int do_debug_aranges
;
136 int do_debug_frames_interp
;
137 int do_debug_macinfo
;
144 /* A dynamic array of flags indicating which sections require dumping. */
145 char *dump_sects
= NULL
;
146 unsigned int num_dump_sects
= 0;
148 #define HEX_DUMP (1 << 0)
149 #define DISASS_DUMP (1 << 1)
150 #define DEBUG_DUMP (1 << 2)
152 /* How to rpint a vma value. */
153 typedef enum print_mode
165 /* Forward declarations for dumb compilers. */
166 static void print_vma
167 PARAMS ((bfd_vma
, print_mode
));
168 static void print_symbol
169 PARAMS ((int, const char *));
170 static bfd_vma (*byte_get
)
171 PARAMS ((unsigned char *, int));
172 static bfd_vma byte_get_little_endian
173 PARAMS ((unsigned char *, int));
174 static bfd_vma byte_get_big_endian
175 PARAMS ((unsigned char *, int));
176 static void (*byte_put
)
177 PARAMS ((unsigned char *, bfd_vma
, int));
178 static void byte_put_little_endian
179 PARAMS ((unsigned char *, bfd_vma
, int));
180 static void byte_put_big_endian
181 PARAMS ((unsigned char *, bfd_vma
, int));
182 static const char *get_mips_dynamic_type
183 PARAMS ((unsigned long));
184 static const char *get_sparc64_dynamic_type
185 PARAMS ((unsigned long));
186 static const char *get_ppc64_dynamic_type
187 PARAMS ((unsigned long));
188 static const char *get_parisc_dynamic_type
189 PARAMS ((unsigned long));
190 static const char *get_ia64_dynamic_type
191 PARAMS ((unsigned long));
192 static const char *get_dynamic_type
193 PARAMS ((unsigned long));
194 static int slurp_rela_relocs
195 PARAMS ((FILE *, unsigned long, unsigned long, Elf_Internal_Rela
**,
197 static int slurp_rel_relocs
198 PARAMS ((FILE *, unsigned long, unsigned long, Elf_Internal_Rela
**,
200 static int dump_relocations
201 PARAMS ((FILE *, unsigned long, unsigned long, Elf_Internal_Sym
*,
202 unsigned long, char *, int));
203 static char *get_file_type
205 static char *get_machine_name
207 static void decode_ARM_machine_flags
208 PARAMS ((unsigned, char[]));
209 static char *get_machine_flags
210 PARAMS ((unsigned, unsigned));
211 static const char *get_mips_segment_type
212 PARAMS ((unsigned long));
213 static const char *get_parisc_segment_type
214 PARAMS ((unsigned long));
215 static const char *get_ia64_segment_type
216 PARAMS ((unsigned long));
217 static const char *get_segment_type
218 PARAMS ((unsigned long));
219 static const char *get_mips_section_type_name
220 PARAMS ((unsigned int));
221 static const char *get_parisc_section_type_name
222 PARAMS ((unsigned int));
223 static const char *get_ia64_section_type_name
224 PARAMS ((unsigned int));
225 static const char *get_section_type_name
226 PARAMS ((unsigned int));
227 static const char *get_symbol_binding
228 PARAMS ((unsigned int));
229 static const char *get_symbol_type
230 PARAMS ((unsigned int));
231 static const char *get_symbol_visibility
232 PARAMS ((unsigned int));
233 static const char *get_symbol_index_type
234 PARAMS ((unsigned int));
235 static const char *get_dynamic_flags
239 static void parse_args
240 PARAMS ((int, char **));
241 static int process_file_header
243 static int process_program_headers
245 static int process_section_headers
247 static int process_unwind
249 static void dynamic_segment_mips_val
250 PARAMS ((Elf_Internal_Dyn
*));
251 static void dynamic_segment_parisc_val
252 PARAMS ((Elf_Internal_Dyn
*));
253 static void dynamic_segment_ia64_val
254 PARAMS ((Elf_Internal_Dyn
*));
255 static int process_dynamic_segment
257 static int process_symbol_table
259 static int process_syminfo
261 static int process_section_contents
263 static void process_mips_fpe_exception
265 static int process_mips_specific
267 static int process_file
269 static int process_relocs
271 static int process_version_sections
273 static char *get_ver_flags
274 PARAMS ((unsigned int));
275 static int get_32bit_section_headers
276 PARAMS ((FILE *, unsigned int));
277 static int get_64bit_section_headers
278 PARAMS ((FILE *, unsigned int));
279 static int get_32bit_program_headers
280 PARAMS ((FILE *, Elf_Internal_Phdr
*));
281 static int get_64bit_program_headers
282 PARAMS ((FILE *, Elf_Internal_Phdr
*));
283 static int get_file_header
285 static Elf_Internal_Sym
*get_32bit_elf_symbols
286 PARAMS ((FILE *, Elf_Internal_Shdr
*));
287 static Elf_Internal_Sym
*get_64bit_elf_symbols
288 PARAMS ((FILE *, Elf_Internal_Shdr
*));
289 static const char *get_elf_section_flags
291 static int *get_dynamic_data
292 PARAMS ((FILE *, unsigned int));
293 static int get_32bit_dynamic_segment
295 static int get_64bit_dynamic_segment
297 #ifdef SUPPORT_DISASSEMBLY
298 static int disassemble_section
299 PARAMS ((Elf_Internal_Shdr
*, FILE *));
301 static int dump_section
302 PARAMS ((Elf_Internal_Shdr
*, FILE *));
303 static int display_debug_section
304 PARAMS ((Elf_Internal_Shdr
*, FILE *));
305 static int display_debug_info
306 PARAMS ((Elf_Internal_Shdr
*, unsigned char *, FILE *));
307 static int display_debug_not_supported
308 PARAMS ((Elf_Internal_Shdr
*, unsigned char *, FILE *));
309 static int prescan_debug_info
310 PARAMS ((Elf_Internal_Shdr
*, unsigned char *, FILE *));
311 static int display_debug_lines
312 PARAMS ((Elf_Internal_Shdr
*, unsigned char *, FILE *));
313 static int display_debug_pubnames
314 PARAMS ((Elf_Internal_Shdr
*, unsigned char *, FILE *));
315 static int display_debug_abbrev
316 PARAMS ((Elf_Internal_Shdr
*, unsigned char *, FILE *));
317 static int display_debug_aranges
318 PARAMS ((Elf_Internal_Shdr
*, unsigned char *, FILE *));
319 static int display_debug_frames
320 PARAMS ((Elf_Internal_Shdr
*, unsigned char *, FILE *));
321 static int display_debug_macinfo
322 PARAMS ((Elf_Internal_Shdr
*, unsigned char *, FILE *));
323 static int display_debug_str
324 PARAMS ((Elf_Internal_Shdr
*, unsigned char *, FILE *));
325 static int display_debug_loc
326 PARAMS ((Elf_Internal_Shdr
*, unsigned char *, FILE *));
327 static unsigned char *process_abbrev_section
328 PARAMS ((unsigned char *, unsigned char *));
329 static void load_debug_str
331 static void free_debug_str
333 static const char *fetch_indirect_string
334 PARAMS ((unsigned long));
335 static void load_debug_loc
337 static void free_debug_loc
339 static unsigned long read_leb128
340 PARAMS ((unsigned char *, int *, int));
341 static int process_extended_line_op
342 PARAMS ((unsigned char *, int, int));
343 static void reset_state_machine
345 static char *get_TAG_name
346 PARAMS ((unsigned long));
347 static char *get_AT_name
348 PARAMS ((unsigned long));
349 static char *get_FORM_name
350 PARAMS ((unsigned long));
351 static void free_abbrevs
353 static void add_abbrev
354 PARAMS ((unsigned long, unsigned long, int));
355 static void add_abbrev_attr
356 PARAMS ((unsigned long, unsigned long));
357 static unsigned char *read_and_display_attr
358 PARAMS ((unsigned long, unsigned long, unsigned char *, unsigned long,
359 unsigned long, unsigned long, int));
360 static unsigned char *read_and_display_attr_value
361 PARAMS ((unsigned long, unsigned long, unsigned char *, unsigned long,
362 unsigned long, unsigned long, int));
363 static unsigned char *display_block
364 PARAMS ((unsigned char *, unsigned long));
365 static void decode_location_expression
366 PARAMS ((unsigned char *, unsigned int, unsigned long));
367 static void request_dump
368 PARAMS ((unsigned int, int));
369 static const char *get_elf_class
370 PARAMS ((unsigned int));
371 static const char *get_data_encoding
372 PARAMS ((unsigned int));
373 static const char *get_osabi_name
374 PARAMS ((unsigned int));
375 static int guess_is_rela
376 PARAMS ((unsigned long));
377 static const char *get_note_type
378 PARAMS ((unsigned int));
379 static const char *get_netbsd_elfcore_note_type
380 PARAMS ((unsigned int));
381 static int process_note
382 PARAMS ((Elf_Internal_Note
*));
383 static int process_corefile_note_segment
384 PARAMS ((FILE *, bfd_vma
, bfd_vma
));
385 static int process_corefile_note_segments
387 static int process_corefile_contents
389 static int process_arch_specific
391 static int process_gnu_liblist
394 typedef int Elf32_Word
;
398 #define SECTION_NAME(X) ((X) == NULL ? "<none>" : \
399 ((X)->sh_name >= string_table_length \
400 ? "<corrupt>" : string_table + (X)->sh_name))
402 /* Given st_shndx I, map to section_headers index. */
403 #define SECTION_HEADER_INDEX(I) \
404 ((I) < SHN_LORESERVE \
406 : ((I) <= SHN_HIRESERVE \
408 : (I) - (SHN_HIRESERVE + 1 - SHN_LORESERVE)))
410 /* Reverse of the above. */
411 #define SECTION_HEADER_NUM(N) \
412 ((N) < SHN_LORESERVE \
414 : (N) + (SHN_HIRESERVE + 1 - SHN_LORESERVE))
416 #define SECTION_HEADER(I) (section_headers + SECTION_HEADER_INDEX (I))
418 #define DT_VERSIONTAGIDX(tag) (DT_VERNEEDNUM - (tag)) /* Reverse order! */
420 #define BYTE_GET(field) byte_get (field, sizeof (field))
422 /* If we can support a 64 bit data type then BFD64 should be defined
423 and sizeof (bfd_vma) == 8. In this case when translating from an
424 external 8 byte field to an internal field, we can assume that the
425 internal field is also 8 bytes wide and so we can extract all the data.
426 If, however, BFD64 is not defined, then we must assume that the
427 internal data structure only has 4 byte wide fields that are the
428 equivalent of the 8 byte wide external counterparts, and so we must
429 truncate the data. */
431 #define BYTE_GET8(field) byte_get (field, -8)
433 #define BYTE_GET8(field) byte_get (field, 8)
436 #define NUM_ELEM(array) (sizeof (array) / sizeof ((array)[0]))
438 #define GET_ELF_SYMBOLS(file, section) \
439 (is_32bit_elf ? get_32bit_elf_symbols (file, section) \
440 : get_64bit_elf_symbols (file, section))
444 error
VPARAMS ((const char *message
, ...))
446 VA_OPEN (args
, message
);
447 VA_FIXEDARG (args
, const char *, message
);
449 fprintf (stderr
, _("%s: Error: "), program_name
);
450 vfprintf (stderr
, message
, args
);
455 warn
VPARAMS ((const char *message
, ...))
457 VA_OPEN (args
, message
);
458 VA_FIXEDARG (args
, const char *, message
);
460 fprintf (stderr
, _("%s: Warning: "), program_name
);
461 vfprintf (stderr
, message
, args
);
465 static PTR get_data
PARAMS ((PTR
, FILE *, long, size_t, const char *));
468 get_data (var
, file
, offset
, size
, reason
)
480 if (fseek (file
, offset
, SEEK_SET
))
482 error (_("Unable to seek to %x for %s\n"), offset
, reason
);
489 mvar
= (PTR
) malloc (size
);
493 error (_("Out of memory allocating %d bytes for %s\n"),
499 if (fread (mvar
, size
, 1, file
) != 1)
501 error (_("Unable to read in %d bytes of %s\n"), size
, reason
);
511 byte_get_little_endian (field
, size
)
512 unsigned char *field
;
521 return ((unsigned int) (field
[0]))
522 | (((unsigned int) (field
[1])) << 8);
526 /* We want to extract data from an 8 byte wide field and
527 place it into a 4 byte wide field. Since this is a little
528 endian source we can just use the 4 byte extraction code. */
532 return ((unsigned long) (field
[0]))
533 | (((unsigned long) (field
[1])) << 8)
534 | (((unsigned long) (field
[2])) << 16)
535 | (((unsigned long) (field
[3])) << 24);
540 /* This is a special case, generated by the BYTE_GET8 macro.
541 It means that we are loading an 8 byte value from a field
542 in an external structure into an 8 byte value in a field
543 in an internal strcuture. */
544 return ((bfd_vma
) (field
[0]))
545 | (((bfd_vma
) (field
[1])) << 8)
546 | (((bfd_vma
) (field
[2])) << 16)
547 | (((bfd_vma
) (field
[3])) << 24)
548 | (((bfd_vma
) (field
[4])) << 32)
549 | (((bfd_vma
) (field
[5])) << 40)
550 | (((bfd_vma
) (field
[6])) << 48)
551 | (((bfd_vma
) (field
[7])) << 56);
554 error (_("Unhandled data length: %d\n"), size
);
560 byte_put_little_endian (field
, value
, size
)
561 unsigned char * field
;
568 field
[7] = (((value
>> 24) >> 24) >> 8) & 0xff;
569 field
[6] = ((value
>> 24) >> 24) & 0xff;
570 field
[5] = ((value
>> 24) >> 16) & 0xff;
571 field
[4] = ((value
>> 24) >> 8) & 0xff;
574 field
[3] = (value
>> 24) & 0xff;
575 field
[2] = (value
>> 16) & 0xff;
578 field
[1] = (value
>> 8) & 0xff;
581 field
[0] = value
& 0xff;
585 error (_("Unhandled data length: %d\n"), size
);
590 /* Print a VMA value. */
592 print_vma (vma
, mode
)
602 case FULL_HEX
: printf ("0x"); /* drop through */
603 case LONG_HEX
: printf ("%8.8lx", (unsigned long) vma
); break;
604 case PREFIX_HEX
: printf ("0x"); /* drop through */
605 case HEX
: printf ("%lx", (unsigned long) vma
); break;
606 case DEC
: printf ("%ld", (unsigned long) vma
); break;
607 case DEC_5
: printf ("%5ld", (long) vma
); break;
608 case UNSIGNED
: printf ("%lu", (unsigned long) vma
); break;
629 #if BFD_HOST_64BIT_LONG
632 if (_bfd_int64_high (vma
))
633 printf ("%lx%8.8lx", _bfd_int64_high (vma
), _bfd_int64_low (vma
));
635 printf ("%lx", _bfd_int64_low (vma
));
640 #if BFD_HOST_64BIT_LONG
643 if (_bfd_int64_high (vma
))
645 printf ("++%ld", _bfd_int64_low (vma
));
647 printf ("%ld", _bfd_int64_low (vma
));
652 #if BFD_HOST_64BIT_LONG
653 printf ("%5ld", vma
);
655 if (_bfd_int64_high (vma
))
657 printf ("++%ld", _bfd_int64_low (vma
));
659 printf ("%5ld", _bfd_int64_low (vma
));
664 #if BFD_HOST_64BIT_LONG
667 if (_bfd_int64_high (vma
))
669 printf ("++%lu", _bfd_int64_low (vma
));
671 printf ("%lu", _bfd_int64_low (vma
));
679 /* Display a symbol on stdout. If do_wide is not true then
680 format the symbol to be at most WIDTH characters,
681 truncating as necessary. If WIDTH is negative then
682 format the string to be exactly - WIDTH characters,
683 truncating or padding as necessary. */
686 print_symbol (width
, symbol
)
691 printf ("%s", symbol
);
693 printf ("%-*.*s", width
, width
, symbol
);
695 printf ("%-.*s", width
, symbol
);
699 byte_get_big_endian (field
, size
)
700 unsigned char *field
;
709 return ((unsigned int) (field
[1])) | (((int) (field
[0])) << 8);
712 return ((unsigned long) (field
[3]))
713 | (((unsigned long) (field
[2])) << 8)
714 | (((unsigned long) (field
[1])) << 16)
715 | (((unsigned long) (field
[0])) << 24);
719 /* Although we are extracing data from an 8 byte wide field, we
720 are returning only 4 bytes of data. */
721 return ((unsigned long) (field
[7]))
722 | (((unsigned long) (field
[6])) << 8)
723 | (((unsigned long) (field
[5])) << 16)
724 | (((unsigned long) (field
[4])) << 24);
728 /* This is a special case, generated by the BYTE_GET8 macro.
729 It means that we are loading an 8 byte value from a field
730 in an external structure into an 8 byte value in a field
731 in an internal strcuture. */
732 return ((bfd_vma
) (field
[7]))
733 | (((bfd_vma
) (field
[6])) << 8)
734 | (((bfd_vma
) (field
[5])) << 16)
735 | (((bfd_vma
) (field
[4])) << 24)
736 | (((bfd_vma
) (field
[3])) << 32)
737 | (((bfd_vma
) (field
[2])) << 40)
738 | (((bfd_vma
) (field
[1])) << 48)
739 | (((bfd_vma
) (field
[0])) << 56);
743 error (_("Unhandled data length: %d\n"), size
);
749 byte_put_big_endian (field
, value
, size
)
750 unsigned char * field
;
757 field
[7] = value
& 0xff;
758 field
[6] = (value
>> 8) & 0xff;
759 field
[5] = (value
>> 16) & 0xff;
760 field
[4] = (value
>> 24) & 0xff;
765 field
[3] = value
& 0xff;
766 field
[2] = (value
>> 8) & 0xff;
770 field
[1] = value
& 0xff;
774 field
[0] = value
& 0xff;
778 error (_("Unhandled data length: %d\n"), size
);
783 /* Guess the relocation size commonly used by the specific machines. */
786 guess_is_rela (e_machine
)
787 unsigned long e_machine
;
791 /* Targets that use REL relocations. */
807 /* Targets that use RELA relocations. */
822 case EM_CYGNUS_MN10200
:
824 case EM_CYGNUS_MN10300
:
869 warn (_("Don't know about relocations on this machine architecture\n"));
875 slurp_rela_relocs (file
, rel_offset
, rel_size
, relasp
, nrelasp
)
877 unsigned long rel_offset
;
878 unsigned long rel_size
;
879 Elf_Internal_Rela
**relasp
;
880 unsigned long *nrelasp
;
882 Elf_Internal_Rela
*relas
;
883 unsigned long nrelas
;
888 Elf32_External_Rela
*erelas
;
890 erelas
= (Elf32_External_Rela
*) get_data (NULL
, file
, rel_offset
,
891 rel_size
, _("relocs"));
895 nrelas
= rel_size
/ sizeof (Elf32_External_Rela
);
897 relas
= (Elf_Internal_Rela
*)
898 malloc (nrelas
* sizeof (Elf_Internal_Rela
));
902 error(_("out of memory parsing relocs"));
906 for (i
= 0; i
< nrelas
; i
++)
908 relas
[i
].r_offset
= BYTE_GET (erelas
[i
].r_offset
);
909 relas
[i
].r_info
= BYTE_GET (erelas
[i
].r_info
);
910 relas
[i
].r_addend
= BYTE_GET (erelas
[i
].r_addend
);
917 Elf64_External_Rela
*erelas
;
919 erelas
= (Elf64_External_Rela
*) get_data (NULL
, file
, rel_offset
,
920 rel_size
, _("relocs"));
924 nrelas
= rel_size
/ sizeof (Elf64_External_Rela
);
926 relas
= (Elf_Internal_Rela
*)
927 malloc (nrelas
* sizeof (Elf_Internal_Rela
));
931 error(_("out of memory parsing relocs"));
935 for (i
= 0; i
< nrelas
; i
++)
937 relas
[i
].r_offset
= BYTE_GET8 (erelas
[i
].r_offset
);
938 relas
[i
].r_info
= BYTE_GET8 (erelas
[i
].r_info
);
939 relas
[i
].r_addend
= BYTE_GET8 (erelas
[i
].r_addend
);
950 slurp_rel_relocs (file
, rel_offset
, rel_size
, relsp
, nrelsp
)
952 unsigned long rel_offset
;
953 unsigned long rel_size
;
954 Elf_Internal_Rela
**relsp
;
955 unsigned long *nrelsp
;
957 Elf_Internal_Rela
*rels
;
963 Elf32_External_Rel
*erels
;
965 erels
= (Elf32_External_Rel
*) get_data (NULL
, file
, rel_offset
,
966 rel_size
, _("relocs"));
970 nrels
= rel_size
/ sizeof (Elf32_External_Rel
);
972 rels
= (Elf_Internal_Rela
*) malloc (nrels
* sizeof (Elf_Internal_Rela
));
976 error(_("out of memory parsing relocs"));
980 for (i
= 0; i
< nrels
; i
++)
982 rels
[i
].r_offset
= BYTE_GET (erels
[i
].r_offset
);
983 rels
[i
].r_info
= BYTE_GET (erels
[i
].r_info
);
984 rels
[i
].r_addend
= 0;
991 Elf64_External_Rel
*erels
;
993 erels
= (Elf64_External_Rel
*) get_data (NULL
, file
, rel_offset
,
994 rel_size
, _("relocs"));
998 nrels
= rel_size
/ sizeof (Elf64_External_Rel
);
1000 rels
= (Elf_Internal_Rela
*) malloc (nrels
* sizeof (Elf_Internal_Rela
));
1004 error(_("out of memory parsing relocs"));
1008 for (i
= 0; i
< nrels
; i
++)
1010 rels
[i
].r_offset
= BYTE_GET8 (erels
[i
].r_offset
);
1011 rels
[i
].r_info
= BYTE_GET8 (erels
[i
].r_info
);
1012 rels
[i
].r_addend
= 0;
1022 /* Display the contents of the relocation data found at the specified offset. */
1025 dump_relocations (file
, rel_offset
, rel_size
, symtab
, nsyms
, strtab
, is_rela
)
1027 unsigned long rel_offset
;
1028 unsigned long rel_size
;
1029 Elf_Internal_Sym
*symtab
;
1030 unsigned long nsyms
;
1035 Elf_Internal_Rela
*rels
;
1038 if (is_rela
== UNKNOWN
)
1039 is_rela
= guess_is_rela (elf_header
.e_machine
);
1043 if (!slurp_rela_relocs (file
, rel_offset
, rel_size
, &rels
, &rel_size
))
1048 if (!slurp_rel_relocs (file
, rel_offset
, rel_size
, &rels
, &rel_size
))
1057 printf (_(" Offset Info Type Sym. Value Symbol's Name + Addend\n"));
1059 printf (_(" Offset Info Type Sym.Value Sym. Name + Addend\n"));
1064 printf (_(" Offset Info Type Sym. Value Symbol's Name\n"));
1066 printf (_(" Offset Info Type Sym.Value Sym. Name\n"));
1074 printf (_(" Offset Info Type Symbol's Value Symbol's Name + Addend\n"));
1076 printf (_(" Offset Info Type Sym. Value Sym. Name + Addend\n"));
1081 printf (_(" Offset Info Type Symbol's Value Symbol's Name\n"));
1083 printf (_(" Offset Info Type Sym. Value Sym. Name\n"));
1087 for (i
= 0; i
< rel_size
; i
++)
1090 const char *rtype2
= NULL
;
1091 const char *rtype3
= NULL
;
1094 bfd_vma symtab_index
;
1096 bfd_vma type2
= (bfd_vma
) NULL
;
1097 bfd_vma type3
= (bfd_vma
) NULL
;
1099 offset
= rels
[i
].r_offset
;
1100 info
= rels
[i
].r_info
;
1104 type
= ELF32_R_TYPE (info
);
1105 symtab_index
= ELF32_R_SYM (info
);
1109 /* The #ifdef BFD64 below is to prevent a compile time warning.
1110 We know that if we do not have a 64 bit data type that we
1111 will never execute this code anyway. */
1113 if (elf_header
.e_machine
== EM_MIPS
)
1115 /* In little-endian objects, r_info isn't really a 64-bit
1116 little-endian value: it has a 32-bit little-endian
1117 symbol index followed by four individual byte fields.
1118 Reorder INFO accordingly. */
1119 if (elf_header
.e_ident
[EI_DATA
] != ELFDATA2MSB
)
1120 info
= (((info
& 0xffffffff) << 32)
1121 | ((info
>> 56) & 0xff)
1122 | ((info
>> 40) & 0xff00)
1123 | ((info
>> 24) & 0xff0000)
1124 | ((info
>> 8) & 0xff000000));
1125 type
= ELF64_MIPS_R_TYPE (info
);
1126 type2
= ELF64_MIPS_R_TYPE2 (info
);
1127 type3
= ELF64_MIPS_R_TYPE3 (info
);
1129 else if (elf_header
.e_machine
== EM_SPARCV9
)
1130 type
= ELF64_R_TYPE_ID (info
);
1132 type
= ELF64_R_TYPE (info
);
1134 symtab_index
= ELF64_R_SYM (info
);
1140 #ifdef _bfd_int64_low
1141 printf ("%8.8lx %8.8lx ", _bfd_int64_low (offset
), _bfd_int64_low (info
));
1143 printf ("%8.8lx %8.8lx ", offset
, info
);
1148 #ifdef _bfd_int64_low
1150 ? "%8.8lx%8.8lx %8.8lx%8.8lx "
1151 : "%4.4lx%8.8lx %4.4lx%8.8lx ",
1152 _bfd_int64_high (offset
),
1153 _bfd_int64_low (offset
),
1154 _bfd_int64_high (info
),
1155 _bfd_int64_low (info
));
1158 ? "%16.16lx %16.16lx "
1159 : "%12.12lx %12.12lx ",
1164 switch (elf_header
.e_machine
)
1171 case EM_CYGNUS_M32R
:
1172 rtype
= elf_m32r_reloc_type (type
);
1177 rtype
= elf_i386_reloc_type (type
);
1182 rtype
= elf_m68hc11_reloc_type (type
);
1186 rtype
= elf_m68k_reloc_type (type
);
1190 rtype
= elf_i960_reloc_type (type
);
1195 rtype
= elf_avr_reloc_type (type
);
1198 case EM_OLD_SPARCV9
:
1199 case EM_SPARC32PLUS
:
1202 rtype
= elf_sparc_reloc_type (type
);
1206 case EM_CYGNUS_V850
:
1207 rtype
= v850_reloc_type (type
);
1211 case EM_CYGNUS_D10V
:
1212 rtype
= elf_d10v_reloc_type (type
);
1216 case EM_CYGNUS_D30V
:
1217 rtype
= elf_d30v_reloc_type (type
);
1221 rtype
= elf_dlx_reloc_type (type
);
1225 rtype
= elf_sh_reloc_type (type
);
1229 case EM_CYGNUS_MN10300
:
1230 rtype
= elf_mn10300_reloc_type (type
);
1234 case EM_CYGNUS_MN10200
:
1235 rtype
= elf_mn10200_reloc_type (type
);
1239 case EM_CYGNUS_FR30
:
1240 rtype
= elf_fr30_reloc_type (type
);
1244 rtype
= elf_frv_reloc_type (type
);
1248 rtype
= elf_mcore_reloc_type (type
);
1252 rtype
= elf_mmix_reloc_type (type
);
1257 rtype
= elf_msp430_reloc_type (type
);
1261 rtype
= elf_ppc_reloc_type (type
);
1265 rtype
= elf_ppc64_reloc_type (type
);
1269 case EM_MIPS_RS3_LE
:
1270 rtype
= elf_mips_reloc_type (type
);
1273 rtype2
= elf_mips_reloc_type (type2
);
1274 rtype3
= elf_mips_reloc_type (type3
);
1279 rtype
= elf_alpha_reloc_type (type
);
1283 rtype
= elf_arm_reloc_type (type
);
1287 rtype
= elf_arc_reloc_type (type
);
1291 rtype
= elf_hppa_reloc_type (type
);
1297 rtype
= elf_h8_reloc_type (type
);
1302 rtype
= elf_or32_reloc_type (type
);
1307 rtype
= elf_pj_reloc_type (type
);
1310 rtype
= elf_ia64_reloc_type (type
);
1314 rtype
= elf_cris_reloc_type (type
);
1318 rtype
= elf_i860_reloc_type (type
);
1322 rtype
= elf_x86_64_reloc_type (type
);
1326 rtype
= i370_reloc_type (type
);
1331 rtype
= elf_s390_reloc_type (type
);
1335 rtype
= elf_xstormy16_reloc_type (type
);
1339 rtype
= elf_vax_reloc_type (type
);
1344 rtype
= elf_ip2k_reloc_type (type
);
1348 rtype
= elf_iq2000_reloc_type (type
);
1353 rtype
= elf_xtensa_reloc_type (type
);
1358 #ifdef _bfd_int64_low
1359 printf (_("unrecognized: %-7lx"), _bfd_int64_low (type
));
1361 printf (_("unrecognized: %-7lx"), type
);
1364 printf (do_wide
? "%-22.22s" : "%-17.17s", rtype
);
1368 if (symtab
== NULL
|| symtab_index
>= nsyms
)
1369 printf (" bad symbol index: %08lx", (unsigned long) symtab_index
);
1372 Elf_Internal_Sym
*psym
;
1374 psym
= symtab
+ symtab_index
;
1377 print_vma (psym
->st_value
, LONG_HEX
);
1378 printf (is_32bit_elf
? " " : " ");
1380 if (psym
->st_name
== 0)
1382 const char *sec_name
= "<null>";
1385 if (ELF_ST_TYPE (psym
->st_info
) == STT_SECTION
)
1387 bfd_vma sec_index
= (bfd_vma
) -1;
1389 if (psym
->st_shndx
< SHN_LORESERVE
)
1390 sec_index
= psym
->st_shndx
;
1391 else if (psym
->st_shndx
> SHN_LORESERVE
)
1392 sec_index
= psym
->st_shndx
- (SHN_HIRESERVE
+ 1
1395 if (sec_index
!= (bfd_vma
) -1)
1396 sec_name
= SECTION_NAME (section_headers
+ sec_index
);
1397 else if (psym
->st_shndx
== SHN_ABS
)
1399 else if (psym
->st_shndx
== SHN_COMMON
)
1400 sec_name
= "COMMON";
1403 sprintf (name_buf
, "<section 0x%x>",
1404 (unsigned int) psym
->st_shndx
);
1405 sec_name
= name_buf
;
1408 print_symbol (22, sec_name
);
1410 else if (strtab
== NULL
)
1411 printf (_("<string table index %3ld>"), psym
->st_name
);
1413 print_symbol (22, strtab
+ psym
->st_name
);
1416 printf (" + %lx", (unsigned long) rels
[i
].r_addend
);
1421 printf ("%*c", is_32bit_elf
? (do_wide
? 34 : 28) : (do_wide
? 26 : 20), ' ');
1422 print_vma (rels
[i
].r_addend
, LONG_HEX
);
1425 if (elf_header
.e_machine
== EM_SPARCV9
1426 && !strcmp (rtype
, "R_SPARC_OLO10"))
1427 printf (" + %lx", (unsigned long) ELF64_R_TYPE_DATA (info
));
1431 if (! is_32bit_elf
&& elf_header
.e_machine
== EM_MIPS
)
1433 printf (" Type2: ");
1436 #ifdef _bfd_int64_low
1437 printf (_("unrecognized: %-7lx"), _bfd_int64_low (type2
));
1439 printf (_("unrecognized: %-7lx"), type2
);
1442 printf ("%-17.17s", rtype2
);
1444 printf("\n Type3: ");
1447 #ifdef _bfd_int64_low
1448 printf (_("unrecognized: %-7lx"), _bfd_int64_low (type3
));
1450 printf (_("unrecognized: %-7lx"), type3
);
1453 printf ("%-17.17s", rtype3
);
1465 get_mips_dynamic_type (type
)
1470 case DT_MIPS_RLD_VERSION
: return "MIPS_RLD_VERSION";
1471 case DT_MIPS_TIME_STAMP
: return "MIPS_TIME_STAMP";
1472 case DT_MIPS_ICHECKSUM
: return "MIPS_ICHECKSUM";
1473 case DT_MIPS_IVERSION
: return "MIPS_IVERSION";
1474 case DT_MIPS_FLAGS
: return "MIPS_FLAGS";
1475 case DT_MIPS_BASE_ADDRESS
: return "MIPS_BASE_ADDRESS";
1476 case DT_MIPS_MSYM
: return "MIPS_MSYM";
1477 case DT_MIPS_CONFLICT
: return "MIPS_CONFLICT";
1478 case DT_MIPS_LIBLIST
: return "MIPS_LIBLIST";
1479 case DT_MIPS_LOCAL_GOTNO
: return "MIPS_LOCAL_GOTNO";
1480 case DT_MIPS_CONFLICTNO
: return "MIPS_CONFLICTNO";
1481 case DT_MIPS_LIBLISTNO
: return "MIPS_LIBLISTNO";
1482 case DT_MIPS_SYMTABNO
: return "MIPS_SYMTABNO";
1483 case DT_MIPS_UNREFEXTNO
: return "MIPS_UNREFEXTNO";
1484 case DT_MIPS_GOTSYM
: return "MIPS_GOTSYM";
1485 case DT_MIPS_HIPAGENO
: return "MIPS_HIPAGENO";
1486 case DT_MIPS_RLD_MAP
: return "MIPS_RLD_MAP";
1487 case DT_MIPS_DELTA_CLASS
: return "MIPS_DELTA_CLASS";
1488 case DT_MIPS_DELTA_CLASS_NO
: return "MIPS_DELTA_CLASS_NO";
1489 case DT_MIPS_DELTA_INSTANCE
: return "MIPS_DELTA_INSTANCE";
1490 case DT_MIPS_DELTA_INSTANCE_NO
: return "MIPS_DELTA_INSTANCE_NO";
1491 case DT_MIPS_DELTA_RELOC
: return "MIPS_DELTA_RELOC";
1492 case DT_MIPS_DELTA_RELOC_NO
: return "MIPS_DELTA_RELOC_NO";
1493 case DT_MIPS_DELTA_SYM
: return "MIPS_DELTA_SYM";
1494 case DT_MIPS_DELTA_SYM_NO
: return "MIPS_DELTA_SYM_NO";
1495 case DT_MIPS_DELTA_CLASSSYM
: return "MIPS_DELTA_CLASSSYM";
1496 case DT_MIPS_DELTA_CLASSSYM_NO
: return "MIPS_DELTA_CLASSSYM_NO";
1497 case DT_MIPS_CXX_FLAGS
: return "MIPS_CXX_FLAGS";
1498 case DT_MIPS_PIXIE_INIT
: return "MIPS_PIXIE_INIT";
1499 case DT_MIPS_SYMBOL_LIB
: return "MIPS_SYMBOL_LIB";
1500 case DT_MIPS_LOCALPAGE_GOTIDX
: return "MIPS_LOCALPAGE_GOTIDX";
1501 case DT_MIPS_LOCAL_GOTIDX
: return "MIPS_LOCAL_GOTIDX";
1502 case DT_MIPS_HIDDEN_GOTIDX
: return "MIPS_HIDDEN_GOTIDX";
1503 case DT_MIPS_PROTECTED_GOTIDX
: return "MIPS_PROTECTED_GOTIDX";
1504 case DT_MIPS_OPTIONS
: return "MIPS_OPTIONS";
1505 case DT_MIPS_INTERFACE
: return "MIPS_INTERFACE";
1506 case DT_MIPS_DYNSTR_ALIGN
: return "MIPS_DYNSTR_ALIGN";
1507 case DT_MIPS_INTERFACE_SIZE
: return "MIPS_INTERFACE_SIZE";
1508 case DT_MIPS_RLD_TEXT_RESOLVE_ADDR
: return "MIPS_RLD_TEXT_RESOLVE_ADDR";
1509 case DT_MIPS_PERF_SUFFIX
: return "MIPS_PERF_SUFFIX";
1510 case DT_MIPS_COMPACT_SIZE
: return "MIPS_COMPACT_SIZE";
1511 case DT_MIPS_GP_VALUE
: return "MIPS_GP_VALUE";
1512 case DT_MIPS_AUX_DYNAMIC
: return "MIPS_AUX_DYNAMIC";
1519 get_sparc64_dynamic_type (type
)
1524 case DT_SPARC_REGISTER
: return "SPARC_REGISTER";
1531 get_ppc64_dynamic_type (type
)
1536 case DT_PPC64_GLINK
: return "PPC64_GLINK";
1537 case DT_PPC64_OPD
: return "PPC64_OPD";
1538 case DT_PPC64_OPDSZ
: return "PPC64_OPDSZ";
1545 get_parisc_dynamic_type (type
)
1550 case DT_HP_LOAD_MAP
: return "HP_LOAD_MAP";
1551 case DT_HP_DLD_FLAGS
: return "HP_DLD_FLAGS";
1552 case DT_HP_DLD_HOOK
: return "HP_DLD_HOOK";
1553 case DT_HP_UX10_INIT
: return "HP_UX10_INIT";
1554 case DT_HP_UX10_INITSZ
: return "HP_UX10_INITSZ";
1555 case DT_HP_PREINIT
: return "HP_PREINIT";
1556 case DT_HP_PREINITSZ
: return "HP_PREINITSZ";
1557 case DT_HP_NEEDED
: return "HP_NEEDED";
1558 case DT_HP_TIME_STAMP
: return "HP_TIME_STAMP";
1559 case DT_HP_CHECKSUM
: return "HP_CHECKSUM";
1560 case DT_HP_GST_SIZE
: return "HP_GST_SIZE";
1561 case DT_HP_GST_VERSION
: return "HP_GST_VERSION";
1562 case DT_HP_GST_HASHVAL
: return "HP_GST_HASHVAL";
1569 get_ia64_dynamic_type (type
)
1574 case DT_IA_64_PLT_RESERVE
: return "IA_64_PLT_RESERVE";
1581 get_dynamic_type (type
)
1584 static char buff
[32];
1588 case DT_NULL
: return "NULL";
1589 case DT_NEEDED
: return "NEEDED";
1590 case DT_PLTRELSZ
: return "PLTRELSZ";
1591 case DT_PLTGOT
: return "PLTGOT";
1592 case DT_HASH
: return "HASH";
1593 case DT_STRTAB
: return "STRTAB";
1594 case DT_SYMTAB
: return "SYMTAB";
1595 case DT_RELA
: return "RELA";
1596 case DT_RELASZ
: return "RELASZ";
1597 case DT_RELAENT
: return "RELAENT";
1598 case DT_STRSZ
: return "STRSZ";
1599 case DT_SYMENT
: return "SYMENT";
1600 case DT_INIT
: return "INIT";
1601 case DT_FINI
: return "FINI";
1602 case DT_SONAME
: return "SONAME";
1603 case DT_RPATH
: return "RPATH";
1604 case DT_SYMBOLIC
: return "SYMBOLIC";
1605 case DT_REL
: return "REL";
1606 case DT_RELSZ
: return "RELSZ";
1607 case DT_RELENT
: return "RELENT";
1608 case DT_PLTREL
: return "PLTREL";
1609 case DT_DEBUG
: return "DEBUG";
1610 case DT_TEXTREL
: return "TEXTREL";
1611 case DT_JMPREL
: return "JMPREL";
1612 case DT_BIND_NOW
: return "BIND_NOW";
1613 case DT_INIT_ARRAY
: return "INIT_ARRAY";
1614 case DT_FINI_ARRAY
: return "FINI_ARRAY";
1615 case DT_INIT_ARRAYSZ
: return "INIT_ARRAYSZ";
1616 case DT_FINI_ARRAYSZ
: return "FINI_ARRAYSZ";
1617 case DT_RUNPATH
: return "RUNPATH";
1618 case DT_FLAGS
: return "FLAGS";
1620 case DT_PREINIT_ARRAY
: return "PREINIT_ARRAY";
1621 case DT_PREINIT_ARRAYSZ
: return "PREINIT_ARRAYSZ";
1623 case DT_CHECKSUM
: return "CHECKSUM";
1624 case DT_PLTPADSZ
: return "PLTPADSZ";
1625 case DT_MOVEENT
: return "MOVEENT";
1626 case DT_MOVESZ
: return "MOVESZ";
1627 case DT_FEATURE
: return "FEATURE";
1628 case DT_POSFLAG_1
: return "POSFLAG_1";
1629 case DT_SYMINSZ
: return "SYMINSZ";
1630 case DT_SYMINENT
: return "SYMINENT"; /* aka VALRNGHI */
1632 case DT_ADDRRNGLO
: return "ADDRRNGLO";
1633 case DT_CONFIG
: return "CONFIG";
1634 case DT_DEPAUDIT
: return "DEPAUDIT";
1635 case DT_AUDIT
: return "AUDIT";
1636 case DT_PLTPAD
: return "PLTPAD";
1637 case DT_MOVETAB
: return "MOVETAB";
1638 case DT_SYMINFO
: return "SYMINFO"; /* aka ADDRRNGHI */
1640 case DT_VERSYM
: return "VERSYM";
1642 case DT_RELACOUNT
: return "RELACOUNT";
1643 case DT_RELCOUNT
: return "RELCOUNT";
1644 case DT_FLAGS_1
: return "FLAGS_1";
1645 case DT_VERDEF
: return "VERDEF";
1646 case DT_VERDEFNUM
: return "VERDEFNUM";
1647 case DT_VERNEED
: return "VERNEED";
1648 case DT_VERNEEDNUM
: return "VERNEEDNUM";
1650 case DT_AUXILIARY
: return "AUXILIARY";
1651 case DT_USED
: return "USED";
1652 case DT_FILTER
: return "FILTER";
1654 case DT_GNU_PRELINKED
: return "GNU_PRELINKED";
1655 case DT_GNU_CONFLICT
: return "GNU_CONFLICT";
1656 case DT_GNU_CONFLICTSZ
: return "GNU_CONFLICTSZ";
1657 case DT_GNU_LIBLIST
: return "GNU_LIBLIST";
1658 case DT_GNU_LIBLISTSZ
: return "GNU_LIBLISTSZ";
1661 if ((type
>= DT_LOPROC
) && (type
<= DT_HIPROC
))
1665 switch (elf_header
.e_machine
)
1668 case EM_MIPS_RS3_LE
:
1669 result
= get_mips_dynamic_type (type
);
1672 result
= get_sparc64_dynamic_type (type
);
1675 result
= get_ppc64_dynamic_type (type
);
1678 result
= get_ia64_dynamic_type (type
);
1688 sprintf (buff
, _("Processor Specific: %lx"), type
);
1690 else if ((type
>= DT_LOOS
) && (type
<= DT_HIOS
))
1694 switch (elf_header
.e_machine
)
1697 result
= get_parisc_dynamic_type (type
);
1707 sprintf (buff
, _("Operating System specific: %lx"), type
);
1710 sprintf (buff
, _("<unknown>: %lx"), type
);
1717 get_file_type (e_type
)
1720 static char buff
[32];
1724 case ET_NONE
: return _("NONE (None)");
1725 case ET_REL
: return _("REL (Relocatable file)");
1726 case ET_EXEC
: return _("EXEC (Executable file)");
1727 case ET_DYN
: return _("DYN (Shared object file)");
1728 case ET_CORE
: return _("CORE (Core file)");
1731 if ((e_type
>= ET_LOPROC
) && (e_type
<= ET_HIPROC
))
1732 sprintf (buff
, _("Processor Specific: (%x)"), e_type
);
1733 else if ((e_type
>= ET_LOOS
) && (e_type
<= ET_HIOS
))
1734 sprintf (buff
, _("OS Specific: (%x)"), e_type
);
1736 sprintf (buff
, _("<unknown>: %x"), e_type
);
1742 get_machine_name (e_machine
)
1745 static char buff
[64]; /* XXX */
1749 case EM_NONE
: return _("None");
1750 case EM_M32
: return "WE32100";
1751 case EM_SPARC
: return "Sparc";
1752 case EM_386
: return "Intel 80386";
1753 case EM_68K
: return "MC68000";
1754 case EM_88K
: return "MC88000";
1755 case EM_486
: return "Intel 80486";
1756 case EM_860
: return "Intel 80860";
1757 case EM_MIPS
: return "MIPS R3000";
1758 case EM_S370
: return "IBM System/370";
1759 case EM_MIPS_RS3_LE
: return "MIPS R4000 big-endian";
1760 case EM_OLD_SPARCV9
: return "Sparc v9 (old)";
1761 case EM_PARISC
: return "HPPA";
1762 case EM_PPC_OLD
: return "Power PC (old)";
1763 case EM_SPARC32PLUS
: return "Sparc v8+" ;
1764 case EM_960
: return "Intel 90860";
1765 case EM_PPC
: return "PowerPC";
1766 case EM_PPC64
: return "PowerPC64";
1767 case EM_V800
: return "NEC V800";
1768 case EM_FR20
: return "Fujitsu FR20";
1769 case EM_RH32
: return "TRW RH32";
1770 case EM_MCORE
: return "MCORE";
1771 case EM_ARM
: return "ARM";
1772 case EM_OLD_ALPHA
: return "Digital Alpha (old)";
1773 case EM_SH
: return "Renesas / SuperH SH";
1774 case EM_SPARCV9
: return "Sparc v9";
1775 case EM_TRICORE
: return "Siemens Tricore";
1776 case EM_ARC
: return "ARC";
1777 case EM_H8_300
: return "Renesas H8/300";
1778 case EM_H8_300H
: return "Renesas H8/300H";
1779 case EM_H8S
: return "Renesas H8S";
1780 case EM_H8_500
: return "Renesas H8/500";
1781 case EM_IA_64
: return "Intel IA-64";
1782 case EM_MIPS_X
: return "Stanford MIPS-X";
1783 case EM_COLDFIRE
: return "Motorola Coldfire";
1784 case EM_68HC12
: return "Motorola M68HC12";
1785 case EM_ALPHA
: return "Alpha";
1786 case EM_CYGNUS_D10V
:
1787 case EM_D10V
: return "d10v";
1788 case EM_CYGNUS_D30V
:
1789 case EM_D30V
: return "d30v";
1790 case EM_CYGNUS_M32R
:
1791 case EM_M32R
: return "Renesas M32R (formerly Mitsubishi M32r)";
1792 case EM_CYGNUS_V850
:
1793 case EM_V850
: return "NEC v850";
1794 case EM_CYGNUS_MN10300
:
1795 case EM_MN10300
: return "mn10300";
1796 case EM_CYGNUS_MN10200
:
1797 case EM_MN10200
: return "mn10200";
1798 case EM_CYGNUS_FR30
:
1799 case EM_FR30
: return "Fujitsu FR30";
1800 case EM_CYGNUS_FRV
: return "Fujitsu FR-V";
1802 case EM_PJ
: return "picoJava";
1803 case EM_MMA
: return "Fujitsu Multimedia Accelerator";
1804 case EM_PCP
: return "Siemens PCP";
1805 case EM_NCPU
: return "Sony nCPU embedded RISC processor";
1806 case EM_NDR1
: return "Denso NDR1 microprocesspr";
1807 case EM_STARCORE
: return "Motorola Star*Core processor";
1808 case EM_ME16
: return "Toyota ME16 processor";
1809 case EM_ST100
: return "STMicroelectronics ST100 processor";
1810 case EM_TINYJ
: return "Advanced Logic Corp. TinyJ embedded processor";
1811 case EM_FX66
: return "Siemens FX66 microcontroller";
1812 case EM_ST9PLUS
: return "STMicroelectronics ST9+ 8/16 bit microcontroller";
1813 case EM_ST7
: return "STMicroelectronics ST7 8-bit microcontroller";
1814 case EM_68HC16
: return "Motorola MC68HC16 Microcontroller";
1815 case EM_68HC11
: return "Motorola MC68HC11 Microcontroller";
1816 case EM_68HC08
: return "Motorola MC68HC08 Microcontroller";
1817 case EM_68HC05
: return "Motorola MC68HC05 Microcontroller";
1818 case EM_SVX
: return "Silicon Graphics SVx";
1819 case EM_ST19
: return "STMicroelectronics ST19 8-bit microcontroller";
1820 case EM_VAX
: return "Digital VAX";
1822 case EM_AVR
: return "Atmel AVR 8-bit microcontroller";
1823 case EM_CRIS
: return "Axis Communications 32-bit embedded processor";
1824 case EM_JAVELIN
: return "Infineon Technologies 32-bit embedded cpu";
1825 case EM_FIREPATH
: return "Element 14 64-bit DSP processor";
1826 case EM_ZSP
: return "LSI Logic's 16-bit DSP processor";
1827 case EM_MMIX
: return "Donald Knuth's educational 64-bit processor";
1828 case EM_HUANY
: return "Harvard Universitys's machine-independent object format";
1829 case EM_PRISM
: return "Vitesse Prism";
1830 case EM_X86_64
: return "Advanced Micro Devices X86-64";
1832 case EM_S390
: return "IBM S/390";
1833 case EM_XSTORMY16
: return "Sanyo Xstormy16 CPU core";
1835 case EM_OR32
: return "OpenRISC";
1836 case EM_DLX
: return "OpenDLX";
1838 case EM_IP2K
: return "Ubicom IP2xxx 8-bit microcontrollers";
1839 case EM_IQ2000
: return "Vitesse IQ2000";
1841 case EM_XTENSA
: return "Tensilica Xtensa Processor";
1843 sprintf (buff
, _("<unknown>: %x"), e_machine
);
1849 decode_ARM_machine_flags (e_flags
, buf
)
1856 eabi
= EF_ARM_EABI_VERSION (e_flags
);
1857 e_flags
&= ~ EF_ARM_EABIMASK
;
1859 /* Handle "generic" ARM flags. */
1860 if (e_flags
& EF_ARM_RELEXEC
)
1862 strcat (buf
, ", relocatable executable");
1863 e_flags
&= ~ EF_ARM_RELEXEC
;
1866 if (e_flags
& EF_ARM_HASENTRY
)
1868 strcat (buf
, ", has entry point");
1869 e_flags
&= ~ EF_ARM_HASENTRY
;
1872 /* Now handle EABI specific flags. */
1876 strcat (buf
, ", <unrecognized EABI>");
1881 case EF_ARM_EABI_VER1
:
1882 strcat (buf
, ", Version1 EABI");
1887 /* Process flags one bit at a time. */
1888 flag
= e_flags
& - e_flags
;
1893 case EF_ARM_SYMSARESORTED
: /* Conflicts with EF_ARM_INTERWORK. */
1894 strcat (buf
, ", sorted symbol tables");
1904 case EF_ARM_EABI_VER2
:
1905 strcat (buf
, ", Version2 EABI");
1910 /* Process flags one bit at a time. */
1911 flag
= e_flags
& - e_flags
;
1916 case EF_ARM_SYMSARESORTED
: /* Conflicts with EF_ARM_INTERWORK. */
1917 strcat (buf
, ", sorted symbol tables");
1920 case EF_ARM_DYNSYMSUSESEGIDX
:
1921 strcat (buf
, ", dynamic symbols use segment index");
1924 case EF_ARM_MAPSYMSFIRST
:
1925 strcat (buf
, ", mapping symbols precede others");
1935 case EF_ARM_EABI_UNKNOWN
:
1936 strcat (buf
, ", GNU EABI");
1941 /* Process flags one bit at a time. */
1942 flag
= e_flags
& - e_flags
;
1947 case EF_ARM_INTERWORK
:
1948 strcat (buf
, ", interworking enabled");
1951 case EF_ARM_APCS_26
:
1952 strcat (buf
, ", uses APCS/26");
1955 case EF_ARM_APCS_FLOAT
:
1956 strcat (buf
, ", uses APCS/float");
1960 strcat (buf
, ", position independent");
1964 strcat (buf
, ", 8 bit structure alignment");
1967 case EF_ARM_NEW_ABI
:
1968 strcat (buf
, ", uses new ABI");
1971 case EF_ARM_OLD_ABI
:
1972 strcat (buf
, ", uses old ABI");
1975 case EF_ARM_SOFT_FLOAT
:
1976 strcat (buf
, ", software FP");
1979 case EF_ARM_MAVERICK_FLOAT
:
1980 strcat (buf
, ", Maverick FP");
1991 strcat (buf
,", <unknown>");
1995 get_machine_flags (e_flags
, e_machine
)
1999 static char buf
[1024];
2011 decode_ARM_machine_flags (e_flags
, buf
);
2015 if (e_flags
& EF_CPU32
)
2016 strcat (buf
, ", cpu32");
2017 if (e_flags
& EF_M68000
)
2018 strcat (buf
, ", m68000");
2022 if (e_flags
& EF_PPC_EMB
)
2023 strcat (buf
, ", emb");
2025 if (e_flags
& EF_PPC_RELOCATABLE
)
2026 strcat (buf
, ", relocatable");
2028 if (e_flags
& EF_PPC_RELOCATABLE_LIB
)
2029 strcat (buf
, ", relocatable-lib");
2033 case EM_CYGNUS_V850
:
2034 switch (e_flags
& EF_V850_ARCH
)
2037 strcat (buf
, ", v850e");
2040 strcat (buf
, ", v850");
2043 strcat (buf
, ", unknown v850 architecture variant");
2049 case EM_CYGNUS_M32R
:
2050 if ((e_flags
& EF_M32R_ARCH
) == E_M32R_ARCH
)
2051 strcat (buf
, ", m32r");
2056 case EM_MIPS_RS3_LE
:
2057 if (e_flags
& EF_MIPS_NOREORDER
)
2058 strcat (buf
, ", noreorder");
2060 if (e_flags
& EF_MIPS_PIC
)
2061 strcat (buf
, ", pic");
2063 if (e_flags
& EF_MIPS_CPIC
)
2064 strcat (buf
, ", cpic");
2066 if (e_flags
& EF_MIPS_UCODE
)
2067 strcat (buf
, ", ugen_reserved");
2069 if (e_flags
& EF_MIPS_ABI2
)
2070 strcat (buf
, ", abi2");
2072 if (e_flags
& EF_MIPS_OPTIONS_FIRST
)
2073 strcat (buf
, ", odk first");
2075 if (e_flags
& EF_MIPS_32BITMODE
)
2076 strcat (buf
, ", 32bitmode");
2078 switch ((e_flags
& EF_MIPS_MACH
))
2080 case E_MIPS_MACH_3900
: strcat (buf
, ", 3900"); break;
2081 case E_MIPS_MACH_4010
: strcat (buf
, ", 4010"); break;
2082 case E_MIPS_MACH_4100
: strcat (buf
, ", 4100"); break;
2083 case E_MIPS_MACH_4111
: strcat (buf
, ", 4111"); break;
2084 case E_MIPS_MACH_4120
: strcat (buf
, ", 4120"); break;
2085 case E_MIPS_MACH_4650
: strcat (buf
, ", 4650"); break;
2086 case E_MIPS_MACH_5400
: strcat (buf
, ", 5400"); break;
2087 case E_MIPS_MACH_5500
: strcat (buf
, ", 5500"); break;
2088 case E_MIPS_MACH_SB1
: strcat (buf
, ", sb1"); break;
2090 /* We simply ignore the field in this case to avoid confusion:
2091 MIPS ELF does not specify EF_MIPS_MACH, it is a GNU
2094 default: strcat (buf
, ", unknown CPU"); break;
2097 switch ((e_flags
& EF_MIPS_ABI
))
2099 case E_MIPS_ABI_O32
: strcat (buf
, ", o32"); break;
2100 case E_MIPS_ABI_O64
: strcat (buf
, ", o64"); break;
2101 case E_MIPS_ABI_EABI32
: strcat (buf
, ", eabi32"); break;
2102 case E_MIPS_ABI_EABI64
: strcat (buf
, ", eabi64"); break;
2104 /* We simply ignore the field in this case to avoid confusion:
2105 MIPS ELF does not specify EF_MIPS_ABI, it is a GNU extension.
2106 This means it is likely to be an o32 file, but not for
2109 default: strcat (buf
, ", unknown ABI"); break;
2112 if (e_flags
& EF_MIPS_ARCH_ASE_MDMX
)
2113 strcat (buf
, ", mdmx");
2115 if (e_flags
& EF_MIPS_ARCH_ASE_M16
)
2116 strcat (buf
, ", mips16");
2118 switch ((e_flags
& EF_MIPS_ARCH
))
2120 case E_MIPS_ARCH_1
: strcat (buf
, ", mips1"); break;
2121 case E_MIPS_ARCH_2
: strcat (buf
, ", mips2"); break;
2122 case E_MIPS_ARCH_3
: strcat (buf
, ", mips3"); break;
2123 case E_MIPS_ARCH_4
: strcat (buf
, ", mips4"); break;
2124 case E_MIPS_ARCH_5
: strcat (buf
, ", mips5"); break;
2125 case E_MIPS_ARCH_32
: strcat (buf
, ", mips32"); break;
2126 case E_MIPS_ARCH_32R2
: strcat (buf
, ", mips32r2"); break;
2127 case E_MIPS_ARCH_64
: strcat (buf
, ", mips64"); break;
2128 default: strcat (buf
, ", unknown ISA"); break;
2134 if (e_flags
& EF_SPARC_32PLUS
)
2135 strcat (buf
, ", v8+");
2137 if (e_flags
& EF_SPARC_SUN_US1
)
2138 strcat (buf
, ", ultrasparcI");
2140 if (e_flags
& EF_SPARC_SUN_US3
)
2141 strcat (buf
, ", ultrasparcIII");
2143 if (e_flags
& EF_SPARC_HAL_R1
)
2144 strcat (buf
, ", halr1");
2146 if (e_flags
& EF_SPARC_LEDATA
)
2147 strcat (buf
, ", ledata");
2149 if ((e_flags
& EF_SPARCV9_MM
) == EF_SPARCV9_TSO
)
2150 strcat (buf
, ", tso");
2152 if ((e_flags
& EF_SPARCV9_MM
) == EF_SPARCV9_PSO
)
2153 strcat (buf
, ", pso");
2155 if ((e_flags
& EF_SPARCV9_MM
) == EF_SPARCV9_RMO
)
2156 strcat (buf
, ", rmo");
2160 switch (e_flags
& EF_PARISC_ARCH
)
2162 case EFA_PARISC_1_0
:
2163 strcpy (buf
, ", PA-RISC 1.0");
2165 case EFA_PARISC_1_1
:
2166 strcpy (buf
, ", PA-RISC 1.1");
2168 case EFA_PARISC_2_0
:
2169 strcpy (buf
, ", PA-RISC 2.0");
2174 if (e_flags
& EF_PARISC_TRAPNIL
)
2175 strcat (buf
, ", trapnil");
2176 if (e_flags
& EF_PARISC_EXT
)
2177 strcat (buf
, ", ext");
2178 if (e_flags
& EF_PARISC_LSB
)
2179 strcat (buf
, ", lsb");
2180 if (e_flags
& EF_PARISC_WIDE
)
2181 strcat (buf
, ", wide");
2182 if (e_flags
& EF_PARISC_NO_KABP
)
2183 strcat (buf
, ", no kabp");
2184 if (e_flags
& EF_PARISC_LAZYSWAP
)
2185 strcat (buf
, ", lazyswap");
2190 if ((e_flags
& EF_PICOJAVA_NEWCALLS
) == EF_PICOJAVA_NEWCALLS
)
2191 strcat (buf
, ", new calling convention");
2193 if ((e_flags
& EF_PICOJAVA_GNUCALLS
) == EF_PICOJAVA_GNUCALLS
)
2194 strcat (buf
, ", gnu calling convention");
2198 if ((e_flags
& EF_IA_64_ABI64
))
2199 strcat (buf
, ", 64-bit");
2201 strcat (buf
, ", 32-bit");
2202 if ((e_flags
& EF_IA_64_REDUCEDFP
))
2203 strcat (buf
, ", reduced fp model");
2204 if ((e_flags
& EF_IA_64_NOFUNCDESC_CONS_GP
))
2205 strcat (buf
, ", no function descriptors, constant gp");
2206 else if ((e_flags
& EF_IA_64_CONS_GP
))
2207 strcat (buf
, ", constant gp");
2208 if ((e_flags
& EF_IA_64_ABSOLUTE
))
2209 strcat (buf
, ", absolute");
2213 if ((e_flags
& EF_VAX_NONPIC
))
2214 strcat (buf
, ", non-PIC");
2215 if ((e_flags
& EF_VAX_DFLOAT
))
2216 strcat (buf
, ", D-Float");
2217 if ((e_flags
& EF_VAX_GFLOAT
))
2218 strcat (buf
, ", G-Float");
2227 get_mips_segment_type (type
)
2232 case PT_MIPS_REGINFO
:
2234 case PT_MIPS_RTPROC
:
2236 case PT_MIPS_OPTIONS
:
2246 get_parisc_segment_type (type
)
2251 case PT_HP_TLS
: return "HP_TLS";
2252 case PT_HP_CORE_NONE
: return "HP_CORE_NONE";
2253 case PT_HP_CORE_VERSION
: return "HP_CORE_VERSION";
2254 case PT_HP_CORE_KERNEL
: return "HP_CORE_KERNEL";
2255 case PT_HP_CORE_COMM
: return "HP_CORE_COMM";
2256 case PT_HP_CORE_PROC
: return "HP_CORE_PROC";
2257 case PT_HP_CORE_LOADABLE
: return "HP_CORE_LOADABLE";
2258 case PT_HP_CORE_STACK
: return "HP_CORE_STACK";
2259 case PT_HP_CORE_SHM
: return "HP_CORE_SHM";
2260 case PT_HP_CORE_MMF
: return "HP_CORE_MMF";
2261 case PT_HP_PARALLEL
: return "HP_PARALLEL";
2262 case PT_HP_FASTBIND
: return "HP_FASTBIND";
2263 case PT_PARISC_ARCHEXT
: return "PARISC_ARCHEXT";
2264 case PT_PARISC_UNWIND
: return "PARISC_UNWIND";
2273 get_ia64_segment_type (type
)
2278 case PT_IA_64_ARCHEXT
: return "IA_64_ARCHEXT";
2279 case PT_IA_64_UNWIND
: return "IA_64_UNWIND";
2280 case PT_HP_TLS
: return "HP_TLS";
2281 case PT_IA_64_HP_OPT_ANOT
: return "HP_OPT_ANNOT";
2282 case PT_IA_64_HP_HSL_ANOT
: return "HP_HSL_ANNOT";
2283 case PT_IA_64_HP_STACK
: return "HP_STACK";
2292 get_segment_type (p_type
)
2293 unsigned long p_type
;
2295 static char buff
[32];
2299 case PT_NULL
: return "NULL";
2300 case PT_LOAD
: return "LOAD";
2301 case PT_DYNAMIC
: return "DYNAMIC";
2302 case PT_INTERP
: return "INTERP";
2303 case PT_NOTE
: return "NOTE";
2304 case PT_SHLIB
: return "SHLIB";
2305 case PT_PHDR
: return "PHDR";
2306 case PT_TLS
: return "TLS";
2308 case PT_GNU_EH_FRAME
:
2309 return "GNU_EH_FRAME";
2312 if ((p_type
>= PT_LOPROC
) && (p_type
<= PT_HIPROC
))
2316 switch (elf_header
.e_machine
)
2319 case EM_MIPS_RS3_LE
:
2320 result
= get_mips_segment_type (p_type
);
2323 result
= get_parisc_segment_type (p_type
);
2326 result
= get_ia64_segment_type (p_type
);
2336 sprintf (buff
, "LOPROC+%lx", p_type
- PT_LOPROC
);
2338 else if ((p_type
>= PT_LOOS
) && (p_type
<= PT_HIOS
))
2342 switch (elf_header
.e_machine
)
2345 result
= get_parisc_segment_type (p_type
);
2348 result
= get_ia64_segment_type (p_type
);
2358 sprintf (buff
, "LOOS+%lx", p_type
- PT_LOOS
);
2361 sprintf (buff
, _("<unknown>: %lx"), p_type
);
2368 get_mips_section_type_name (sh_type
)
2369 unsigned int sh_type
;
2373 case SHT_MIPS_LIBLIST
: return "MIPS_LIBLIST";
2374 case SHT_MIPS_MSYM
: return "MIPS_MSYM";
2375 case SHT_MIPS_CONFLICT
: return "MIPS_CONFLICT";
2376 case SHT_MIPS_GPTAB
: return "MIPS_GPTAB";
2377 case SHT_MIPS_UCODE
: return "MIPS_UCODE";
2378 case SHT_MIPS_DEBUG
: return "MIPS_DEBUG";
2379 case SHT_MIPS_REGINFO
: return "MIPS_REGINFO";
2380 case SHT_MIPS_PACKAGE
: return "MIPS_PACKAGE";
2381 case SHT_MIPS_PACKSYM
: return "MIPS_PACKSYM";
2382 case SHT_MIPS_RELD
: return "MIPS_RELD";
2383 case SHT_MIPS_IFACE
: return "MIPS_IFACE";
2384 case SHT_MIPS_CONTENT
: return "MIPS_CONTENT";
2385 case SHT_MIPS_OPTIONS
: return "MIPS_OPTIONS";
2386 case SHT_MIPS_SHDR
: return "MIPS_SHDR";
2387 case SHT_MIPS_FDESC
: return "MIPS_FDESC";
2388 case SHT_MIPS_EXTSYM
: return "MIPS_EXTSYM";
2389 case SHT_MIPS_DENSE
: return "MIPS_DENSE";
2390 case SHT_MIPS_PDESC
: return "MIPS_PDESC";
2391 case SHT_MIPS_LOCSYM
: return "MIPS_LOCSYM";
2392 case SHT_MIPS_AUXSYM
: return "MIPS_AUXSYM";
2393 case SHT_MIPS_OPTSYM
: return "MIPS_OPTSYM";
2394 case SHT_MIPS_LOCSTR
: return "MIPS_LOCSTR";
2395 case SHT_MIPS_LINE
: return "MIPS_LINE";
2396 case SHT_MIPS_RFDESC
: return "MIPS_RFDESC";
2397 case SHT_MIPS_DELTASYM
: return "MIPS_DELTASYM";
2398 case SHT_MIPS_DELTAINST
: return "MIPS_DELTAINST";
2399 case SHT_MIPS_DELTACLASS
: return "MIPS_DELTACLASS";
2400 case SHT_MIPS_DWARF
: return "MIPS_DWARF";
2401 case SHT_MIPS_DELTADECL
: return "MIPS_DELTADECL";
2402 case SHT_MIPS_SYMBOL_LIB
: return "MIPS_SYMBOL_LIB";
2403 case SHT_MIPS_EVENTS
: return "MIPS_EVENTS";
2404 case SHT_MIPS_TRANSLATE
: return "MIPS_TRANSLATE";
2405 case SHT_MIPS_PIXIE
: return "MIPS_PIXIE";
2406 case SHT_MIPS_XLATE
: return "MIPS_XLATE";
2407 case SHT_MIPS_XLATE_DEBUG
: return "MIPS_XLATE_DEBUG";
2408 case SHT_MIPS_WHIRL
: return "MIPS_WHIRL";
2409 case SHT_MIPS_EH_REGION
: return "MIPS_EH_REGION";
2410 case SHT_MIPS_XLATE_OLD
: return "MIPS_XLATE_OLD";
2411 case SHT_MIPS_PDR_EXCEPTION
: return "MIPS_PDR_EXCEPTION";
2419 get_parisc_section_type_name (sh_type
)
2420 unsigned int sh_type
;
2424 case SHT_PARISC_EXT
: return "PARISC_EXT";
2425 case SHT_PARISC_UNWIND
: return "PARISC_UNWIND";
2426 case SHT_PARISC_DOC
: return "PARISC_DOC";
2434 get_ia64_section_type_name (sh_type
)
2435 unsigned int sh_type
;
2437 /* If the top 8 bits are 0x78 the next 8 are the os/abi ID. */
2438 if ((sh_type
& 0xFF000000) == SHT_IA_64_LOPSREG
)
2439 return get_osabi_name ((sh_type
& 0x00FF0000) >> 16);
2443 case SHT_IA_64_EXT
: return "IA_64_EXT";
2444 case SHT_IA_64_UNWIND
: return "IA_64_UNWIND";
2445 case SHT_IA_64_PRIORITY_INIT
: return "IA_64_PRIORITY_INIT";
2453 get_section_type_name (sh_type
)
2454 unsigned int sh_type
;
2456 static char buff
[32];
2460 case SHT_NULL
: return "NULL";
2461 case SHT_PROGBITS
: return "PROGBITS";
2462 case SHT_SYMTAB
: return "SYMTAB";
2463 case SHT_STRTAB
: return "STRTAB";
2464 case SHT_RELA
: return "RELA";
2465 case SHT_HASH
: return "HASH";
2466 case SHT_DYNAMIC
: return "DYNAMIC";
2467 case SHT_NOTE
: return "NOTE";
2468 case SHT_NOBITS
: return "NOBITS";
2469 case SHT_REL
: return "REL";
2470 case SHT_SHLIB
: return "SHLIB";
2471 case SHT_DYNSYM
: return "DYNSYM";
2472 case SHT_INIT_ARRAY
: return "INIT_ARRAY";
2473 case SHT_FINI_ARRAY
: return "FINI_ARRAY";
2474 case SHT_PREINIT_ARRAY
: return "PREINIT_ARRAY";
2475 case SHT_GROUP
: return "GROUP";
2476 case SHT_SYMTAB_SHNDX
: return "SYMTAB SECTION INDICIES";
2477 case SHT_GNU_verdef
: return "VERDEF";
2478 case SHT_GNU_verneed
: return "VERNEED";
2479 case SHT_GNU_versym
: return "VERSYM";
2480 case 0x6ffffff0: return "VERSYM";
2481 case 0x6ffffffc: return "VERDEF";
2482 case 0x7ffffffd: return "AUXILIARY";
2483 case 0x7fffffff: return "FILTER";
2484 case SHT_GNU_LIBLIST
: return "GNU_LIBLIST";
2487 if ((sh_type
>= SHT_LOPROC
) && (sh_type
<= SHT_HIPROC
))
2491 switch (elf_header
.e_machine
)
2494 case EM_MIPS_RS3_LE
:
2495 result
= get_mips_section_type_name (sh_type
);
2498 result
= get_parisc_section_type_name (sh_type
);
2501 result
= get_ia64_section_type_name (sh_type
);
2511 sprintf (buff
, "LOPROC+%x", sh_type
- SHT_LOPROC
);
2513 else if ((sh_type
>= SHT_LOOS
) && (sh_type
<= SHT_HIOS
))
2514 sprintf (buff
, "LOOS+%x", sh_type
- SHT_LOOS
);
2515 else if ((sh_type
>= SHT_LOUSER
) && (sh_type
<= SHT_HIUSER
))
2516 sprintf (buff
, "LOUSER+%x", sh_type
- SHT_LOUSER
);
2518 sprintf (buff
, _("<unknown>: %x"), sh_type
);
2524 #define OPTION_DEBUG_DUMP 512
2526 struct option options
[] =
2528 {"all", no_argument
, 0, 'a'},
2529 {"file-header", no_argument
, 0, 'h'},
2530 {"program-headers", no_argument
, 0, 'l'},
2531 {"headers", no_argument
, 0, 'e'},
2532 {"histogram", no_argument
, 0, 'I'},
2533 {"segments", no_argument
, 0, 'l'},
2534 {"sections", no_argument
, 0, 'S'},
2535 {"section-headers", no_argument
, 0, 'S'},
2536 {"symbols", no_argument
, 0, 's'},
2537 {"syms", no_argument
, 0, 's'},
2538 {"relocs", no_argument
, 0, 'r'},
2539 {"notes", no_argument
, 0, 'n'},
2540 {"dynamic", no_argument
, 0, 'd'},
2541 {"arch-specific", no_argument
, 0, 'A'},
2542 {"version-info", no_argument
, 0, 'V'},
2543 {"use-dynamic", no_argument
, 0, 'D'},
2544 {"hex-dump", required_argument
, 0, 'x'},
2545 {"debug-dump", optional_argument
, 0, OPTION_DEBUG_DUMP
},
2546 {"unwind", no_argument
, 0, 'u'},
2547 #ifdef SUPPORT_DISASSEMBLY
2548 {"instruction-dump", required_argument
, 0, 'i'},
2551 {"version", no_argument
, 0, 'v'},
2552 {"wide", no_argument
, 0, 'W'},
2553 {"help", no_argument
, 0, 'H'},
2554 {0, no_argument
, 0, 0}
2560 fprintf (stdout
, _("Usage: readelf <option(s)> elf-file(s)\n"));
2561 fprintf (stdout
, _(" Display information about the contents of ELF format files\n"));
2562 fprintf (stdout
, _(" Options are:\n\
2563 -a --all Equivalent to: -h -l -S -s -r -d -V -A -I\n\
2564 -h --file-header Display the ELF file header\n\
2565 -l --program-headers Display the program headers\n\
2566 --segments An alias for --program-headers\n\
2567 -S --section-headers Display the sections' header\n\
2568 --sections An alias for --section-headers\n\
2569 -e --headers Equivalent to: -h -l -S\n\
2570 -s --syms Display the symbol table\n\
2571 --symbols An alias for --syms\n\
2572 -n --notes Display the core notes (if present)\n\
2573 -r --relocs Display the relocations (if present)\n\
2574 -u --unwind Display the unwind info (if present)\n\
2575 -d --dynamic Display the dynamic segment (if present)\n\
2576 -V --version-info Display the version sections (if present)\n\
2577 -A --arch-specific Display architecture specific information (if any).\n\
2578 -D --use-dynamic Use the dynamic section info when displaying symbols\n\
2579 -x --hex-dump=<number> Dump the contents of section <number>\n\
2580 -w[liaprmfFso] or\n\
2581 --debug-dump[=line,=info,=abbrev,=pubnames,=ranges,=macro,=frames,=str,=loc]\n\
2582 Display the contents of DWARF2 debug sections\n"));
2583 #ifdef SUPPORT_DISASSEMBLY
2584 fprintf (stdout
, _("\
2585 -i --instruction-dump=<number>\n\
2586 Disassemble the contents of section <number>\n"));
2588 fprintf (stdout
, _("\
2589 -I --histogram Display histogram of bucket list lengths\n\
2590 -W --wide Allow output width to exceed 80 characters\n\
2591 -H --help Display this information\n\
2592 -v --version Display the version number of readelf\n"));
2593 fprintf (stdout
, _("Report bugs to %s\n"), REPORT_BUGS_TO
);
2599 request_dump (section
, type
)
2600 unsigned int section
;
2603 if (section
>= num_dump_sects
)
2605 char *new_dump_sects
;
2607 new_dump_sects
= (char *) calloc (section
+ 1, 1);
2609 if (new_dump_sects
== NULL
)
2610 error (_("Out of memory allocating dump request table."));
2613 /* Copy current flag settings. */
2614 memcpy (new_dump_sects
, dump_sects
, num_dump_sects
);
2618 dump_sects
= new_dump_sects
;
2619 num_dump_sects
= section
+ 1;
2624 dump_sects
[section
] |= type
;
2630 parse_args (argc
, argv
)
2639 while ((c
= getopt_long
2640 (argc
, argv
, "ersuahnldSDAIw::x:i:vVWH", options
, NULL
)) != EOF
)
2707 section
= strtoul (optarg
, & cp
, 0);
2708 if (! *cp
&& section
>= 0)
2710 request_dump (section
, HEX_DUMP
);
2720 unsigned int index
= 0;
2724 while (optarg
[index
])
2725 switch (optarg
[index
++])
2734 do_debug_abbrevs
= 1;
2744 do_debug_pubnames
= 1;
2749 do_debug_aranges
= 1;
2753 do_debug_frames_interp
= 1;
2755 do_debug_frames
= 1;
2760 do_debug_macinfo
= 1;
2774 warn (_("Unrecognized debug option '%s'\n"), optarg
);
2779 case OPTION_DEBUG_DUMP
:
2785 static const char *debug_dump_opt
[]
2786 = { "line", "info", "abbrev", "pubnames", "ranges",
2787 "macro", "frames", "frames-interp", "str", "loc", NULL
};
2796 for (index
= 0; debug_dump_opt
[index
]; index
++)
2798 size_t len
= strlen (debug_dump_opt
[index
]);
2800 if (strncmp (p
, debug_dump_opt
[index
], len
) == 0
2801 && (p
[len
] == ',' || p
[len
] == '\0'))
2810 do_debug_abbrevs
= 1;
2821 do_debug_pubnames
= 1;
2825 do_debug_aranges
= 1;
2830 do_debug_frames_interp
= 1;
2831 do_debug_frames
= 1;
2835 do_debug_macinfo
= 1;
2848 if (debug_dump_opt
[index
] == NULL
)
2850 warn (_("Unrecognized debug option '%s'\n"), p
);
2851 p
= strchr (p
, ',');
2861 #ifdef SUPPORT_DISASSEMBLY
2864 section
= strtoul (optarg
, & cp
, 0);
2865 if (! *cp
&& section
>= 0)
2867 request_dump (section
, DISASS_DUMP
);
2873 print_version (program_name
);
2883 /* xgettext:c-format */
2884 error (_("Invalid option '-%c'\n"), c
);
2891 if (!do_dynamic
&& !do_syms
&& !do_reloc
&& !do_unwind
&& !do_sections
2892 && !do_segments
&& !do_header
&& !do_dump
&& !do_version
2893 && !do_histogram
&& !do_debugging
&& !do_arch
&& !do_notes
)
2897 warn (_("Nothing to do.\n"));
2903 get_elf_class (elf_class
)
2904 unsigned int elf_class
;
2906 static char buff
[32];
2910 case ELFCLASSNONE
: return _("none");
2911 case ELFCLASS32
: return "ELF32";
2912 case ELFCLASS64
: return "ELF64";
2914 sprintf (buff
, _("<unknown: %x>"), elf_class
);
2920 get_data_encoding (encoding
)
2921 unsigned int encoding
;
2923 static char buff
[32];
2927 case ELFDATANONE
: return _("none");
2928 case ELFDATA2LSB
: return _("2's complement, little endian");
2929 case ELFDATA2MSB
: return _("2's complement, big endian");
2931 sprintf (buff
, _("<unknown: %x>"), encoding
);
2937 get_osabi_name (osabi
)
2940 static char buff
[32];
2944 case ELFOSABI_NONE
: return "UNIX - System V";
2945 case ELFOSABI_HPUX
: return "UNIX - HP-UX";
2946 case ELFOSABI_NETBSD
: return "UNIX - NetBSD";
2947 case ELFOSABI_LINUX
: return "UNIX - Linux";
2948 case ELFOSABI_HURD
: return "GNU/Hurd";
2949 case ELFOSABI_SOLARIS
: return "UNIX - Solaris";
2950 case ELFOSABI_AIX
: return "UNIX - AIX";
2951 case ELFOSABI_IRIX
: return "UNIX - IRIX";
2952 case ELFOSABI_FREEBSD
: return "UNIX - FreeBSD";
2953 case ELFOSABI_TRU64
: return "UNIX - TRU64";
2954 case ELFOSABI_MODESTO
: return "Novell - Modesto";
2955 case ELFOSABI_OPENBSD
: return "UNIX - OpenBSD";
2956 case ELFOSABI_OPENVMS
: return "VMS - OpenVMS";
2957 case ELFOSABI_NSK
: return "HP - Non-Stop Kernel";
2958 case ELFOSABI_AROS
: return "Amiga Research OS";
2959 case ELFOSABI_STANDALONE
: return _("Standalone App");
2960 case ELFOSABI_ARM
: return "ARM";
2962 sprintf (buff
, _("<unknown: %x>"), osabi
);
2967 /* Decode the data held in 'elf_header'. */
2970 process_file_header ()
2972 if ( elf_header
.e_ident
[EI_MAG0
] != ELFMAG0
2973 || elf_header
.e_ident
[EI_MAG1
] != ELFMAG1
2974 || elf_header
.e_ident
[EI_MAG2
] != ELFMAG2
2975 || elf_header
.e_ident
[EI_MAG3
] != ELFMAG3
)
2978 (_("Not an ELF file - it has the wrong magic bytes at the start\n"));
2986 printf (_("ELF Header:\n"));
2987 printf (_(" Magic: "));
2988 for (i
= 0; i
< EI_NIDENT
; i
++)
2989 printf ("%2.2x ", elf_header
.e_ident
[i
]);
2991 printf (_(" Class: %s\n"),
2992 get_elf_class (elf_header
.e_ident
[EI_CLASS
]));
2993 printf (_(" Data: %s\n"),
2994 get_data_encoding (elf_header
.e_ident
[EI_DATA
]));
2995 printf (_(" Version: %d %s\n"),
2996 elf_header
.e_ident
[EI_VERSION
],
2997 (elf_header
.e_ident
[EI_VERSION
] == EV_CURRENT
2999 : (elf_header
.e_ident
[EI_VERSION
] != EV_NONE
3002 printf (_(" OS/ABI: %s\n"),
3003 get_osabi_name (elf_header
.e_ident
[EI_OSABI
]));
3004 printf (_(" ABI Version: %d\n"),
3005 elf_header
.e_ident
[EI_ABIVERSION
]);
3006 printf (_(" Type: %s\n"),
3007 get_file_type (elf_header
.e_type
));
3008 printf (_(" Machine: %s\n"),
3009 get_machine_name (elf_header
.e_machine
));
3010 printf (_(" Version: 0x%lx\n"),
3011 (unsigned long) elf_header
.e_version
);
3013 printf (_(" Entry point address: "));
3014 print_vma ((bfd_vma
) elf_header
.e_entry
, PREFIX_HEX
);
3015 printf (_("\n Start of program headers: "));
3016 print_vma ((bfd_vma
) elf_header
.e_phoff
, DEC
);
3017 printf (_(" (bytes into file)\n Start of section headers: "));
3018 print_vma ((bfd_vma
) elf_header
.e_shoff
, DEC
);
3019 printf (_(" (bytes into file)\n"));
3021 printf (_(" Flags: 0x%lx%s\n"),
3022 (unsigned long) elf_header
.e_flags
,
3023 get_machine_flags (elf_header
.e_flags
, elf_header
.e_machine
));
3024 printf (_(" Size of this header: %ld (bytes)\n"),
3025 (long) elf_header
.e_ehsize
);
3026 printf (_(" Size of program headers: %ld (bytes)\n"),
3027 (long) elf_header
.e_phentsize
);
3028 printf (_(" Number of program headers: %ld\n"),
3029 (long) elf_header
.e_phnum
);
3030 printf (_(" Size of section headers: %ld (bytes)\n"),
3031 (long) elf_header
.e_shentsize
);
3032 printf (_(" Number of section headers: %ld"),
3033 (long) elf_header
.e_shnum
);
3034 if (section_headers
!= NULL
&& elf_header
.e_shnum
== 0)
3035 printf (" (%ld)", (long) section_headers
[0].sh_size
);
3036 putc ('\n', stdout
);
3037 printf (_(" Section header string table index: %ld"),
3038 (long) elf_header
.e_shstrndx
);
3039 if (section_headers
!= NULL
&& elf_header
.e_shstrndx
== SHN_XINDEX
)
3040 printf (" (%ld)", (long) section_headers
[0].sh_link
);
3041 putc ('\n', stdout
);
3044 if (section_headers
!= NULL
)
3046 if (elf_header
.e_shnum
== 0)
3047 elf_header
.e_shnum
= section_headers
[0].sh_size
;
3048 if (elf_header
.e_shstrndx
== SHN_XINDEX
)
3049 elf_header
.e_shstrndx
= section_headers
[0].sh_link
;
3050 free (section_headers
);
3051 section_headers
= NULL
;
3059 get_32bit_program_headers (file
, program_headers
)
3061 Elf_Internal_Phdr
*program_headers
;
3063 Elf32_External_Phdr
*phdrs
;
3064 Elf32_External_Phdr
*external
;
3065 Elf_Internal_Phdr
*internal
;
3068 phdrs
= ((Elf32_External_Phdr
*)
3069 get_data (NULL
, file
, elf_header
.e_phoff
,
3070 elf_header
.e_phentsize
* elf_header
.e_phnum
,
3071 _("program headers")));
3075 for (i
= 0, internal
= program_headers
, external
= phdrs
;
3076 i
< elf_header
.e_phnum
;
3077 i
++, internal
++, external
++)
3079 internal
->p_type
= BYTE_GET (external
->p_type
);
3080 internal
->p_offset
= BYTE_GET (external
->p_offset
);
3081 internal
->p_vaddr
= BYTE_GET (external
->p_vaddr
);
3082 internal
->p_paddr
= BYTE_GET (external
->p_paddr
);
3083 internal
->p_filesz
= BYTE_GET (external
->p_filesz
);
3084 internal
->p_memsz
= BYTE_GET (external
->p_memsz
);
3085 internal
->p_flags
= BYTE_GET (external
->p_flags
);
3086 internal
->p_align
= BYTE_GET (external
->p_align
);
3095 get_64bit_program_headers (file
, program_headers
)
3097 Elf_Internal_Phdr
*program_headers
;
3099 Elf64_External_Phdr
*phdrs
;
3100 Elf64_External_Phdr
*external
;
3101 Elf_Internal_Phdr
*internal
;
3104 phdrs
= ((Elf64_External_Phdr
*)
3105 get_data (NULL
, file
, elf_header
.e_phoff
,
3106 elf_header
.e_phentsize
* elf_header
.e_phnum
,
3107 _("program headers")));
3111 for (i
= 0, internal
= program_headers
, external
= phdrs
;
3112 i
< elf_header
.e_phnum
;
3113 i
++, internal
++, external
++)
3115 internal
->p_type
= BYTE_GET (external
->p_type
);
3116 internal
->p_flags
= BYTE_GET (external
->p_flags
);
3117 internal
->p_offset
= BYTE_GET8 (external
->p_offset
);
3118 internal
->p_vaddr
= BYTE_GET8 (external
->p_vaddr
);
3119 internal
->p_paddr
= BYTE_GET8 (external
->p_paddr
);
3120 internal
->p_filesz
= BYTE_GET8 (external
->p_filesz
);
3121 internal
->p_memsz
= BYTE_GET8 (external
->p_memsz
);
3122 internal
->p_align
= BYTE_GET8 (external
->p_align
);
3130 /* Returns 1 if the program headers were loaded. */
3133 process_program_headers (file
)
3136 Elf_Internal_Phdr
*program_headers
;
3137 Elf_Internal_Phdr
*segment
;
3140 if (elf_header
.e_phnum
== 0)
3143 printf (_("\nThere are no program headers in this file.\n"));
3147 if (do_segments
&& !do_header
)
3149 printf (_("\nElf file type is %s\n"), get_file_type (elf_header
.e_type
));
3150 printf (_("Entry point "));
3151 print_vma ((bfd_vma
) elf_header
.e_entry
, PREFIX_HEX
);
3152 printf (_("\nThere are %d program headers, starting at offset "),
3153 elf_header
.e_phnum
);
3154 print_vma ((bfd_vma
) elf_header
.e_phoff
, DEC
);
3158 program_headers
= (Elf_Internal_Phdr
*) malloc
3159 (elf_header
.e_phnum
* sizeof (Elf_Internal_Phdr
));
3161 if (program_headers
== NULL
)
3163 error (_("Out of memory\n"));
3168 i
= get_32bit_program_headers (file
, program_headers
);
3170 i
= get_64bit_program_headers (file
, program_headers
);
3174 free (program_headers
);
3180 if (elf_header
.e_phnum
> 1)
3181 printf (_("\nProgram Headers:\n"));
3183 printf (_("\nProgram Headers:\n"));
3187 (_(" Type Offset VirtAddr PhysAddr FileSiz MemSiz Flg Align\n"));
3190 (_(" Type Offset VirtAddr PhysAddr FileSiz MemSiz Flg Align\n"));
3194 (_(" Type Offset VirtAddr PhysAddr\n"));
3196 (_(" FileSiz MemSiz Flags Align\n"));
3204 for (i
= 0, segment
= program_headers
;
3205 i
< elf_header
.e_phnum
;
3210 printf (" %-14.14s ", get_segment_type (segment
->p_type
));
3214 printf ("0x%6.6lx ", (unsigned long) segment
->p_offset
);
3215 printf ("0x%8.8lx ", (unsigned long) segment
->p_vaddr
);
3216 printf ("0x%8.8lx ", (unsigned long) segment
->p_paddr
);
3217 printf ("0x%5.5lx ", (unsigned long) segment
->p_filesz
);
3218 printf ("0x%5.5lx ", (unsigned long) segment
->p_memsz
);
3220 (segment
->p_flags
& PF_R
? 'R' : ' '),
3221 (segment
->p_flags
& PF_W
? 'W' : ' '),
3222 (segment
->p_flags
& PF_X
? 'E' : ' '));
3223 printf ("%#lx", (unsigned long) segment
->p_align
);
3227 if ((unsigned long) segment
->p_offset
== segment
->p_offset
)
3228 printf ("0x%6.6lx ", (unsigned long) segment
->p_offset
);
3231 print_vma (segment
->p_offset
, FULL_HEX
);
3235 print_vma (segment
->p_vaddr
, FULL_HEX
);
3237 print_vma (segment
->p_paddr
, FULL_HEX
);
3240 if ((unsigned long) segment
->p_filesz
== segment
->p_filesz
)
3241 printf ("0x%6.6lx ", (unsigned long) segment
->p_filesz
);
3244 print_vma (segment
->p_filesz
, FULL_HEX
);
3248 if ((unsigned long) segment
->p_memsz
== segment
->p_memsz
)
3249 printf ("0x%6.6lx", (unsigned long) segment
->p_memsz
);
3252 print_vma (segment
->p_offset
, FULL_HEX
);
3256 (segment
->p_flags
& PF_R
? 'R' : ' '),
3257 (segment
->p_flags
& PF_W
? 'W' : ' '),
3258 (segment
->p_flags
& PF_X
? 'E' : ' '));
3260 if ((unsigned long) segment
->p_align
== segment
->p_align
)
3261 printf ("%#lx", (unsigned long) segment
->p_align
);
3264 print_vma (segment
->p_align
, PREFIX_HEX
);
3269 print_vma (segment
->p_offset
, FULL_HEX
);
3271 print_vma (segment
->p_vaddr
, FULL_HEX
);
3273 print_vma (segment
->p_paddr
, FULL_HEX
);
3275 print_vma (segment
->p_filesz
, FULL_HEX
);
3277 print_vma (segment
->p_memsz
, FULL_HEX
);
3279 (segment
->p_flags
& PF_R
? 'R' : ' '),
3280 (segment
->p_flags
& PF_W
? 'W' : ' '),
3281 (segment
->p_flags
& PF_X
? 'E' : ' '));
3282 print_vma (segment
->p_align
, HEX
);
3286 switch (segment
->p_type
)
3291 unsigned long align_mask
= -segment
->p_align
;
3293 if (align_mask
== 0)
3295 loadaddr
= ((segment
->p_vaddr
& align_mask
)
3296 - (segment
->p_offset
& align_mask
));
3302 error (_("more than one dynamic segment\n"));
3304 dynamic_addr
= segment
->p_offset
;
3305 dynamic_size
= segment
->p_filesz
;
3309 if (fseek (file
, (long) segment
->p_offset
, SEEK_SET
))
3310 error (_("Unable to find program interpreter name\n"));
3313 program_interpreter
[0] = 0;
3314 fscanf (file
, "%63s", program_interpreter
);
3317 printf (_("\n [Requesting program interpreter: %s]"),
3318 program_interpreter
);
3324 putc ('\n', stdout
);
3333 if (do_segments
&& section_headers
!= NULL
)
3335 printf (_("\n Section to Segment mapping:\n"));
3336 printf (_(" Segment Sections...\n"));
3338 assert (string_table
!= NULL
);
3340 for (i
= 0; i
< elf_header
.e_phnum
; i
++)
3343 Elf_Internal_Shdr
*section
;
3345 segment
= program_headers
+ i
;
3346 section
= section_headers
;
3348 printf (" %2.2d ", i
);
3350 for (j
= 1; j
< elf_header
.e_shnum
; j
++, section
++)
3352 if (section
->sh_size
> 0
3353 /* Compare allocated sections by VMA, unallocated
3354 sections by file offset. */
3355 && (section
->sh_flags
& SHF_ALLOC
3356 ? (section
->sh_addr
>= segment
->p_vaddr
3357 && section
->sh_addr
+ section
->sh_size
3358 <= segment
->p_vaddr
+ segment
->p_memsz
)
3359 : ((bfd_vma
) section
->sh_offset
>= segment
->p_offset
3360 && (section
->sh_offset
+ section
->sh_size
3361 <= segment
->p_offset
+ segment
->p_filesz
))))
3362 printf ("%s ", SECTION_NAME (section
));
3369 free (program_headers
);
3376 get_32bit_section_headers (file
, num
)
3380 Elf32_External_Shdr
*shdrs
;
3381 Elf_Internal_Shdr
*internal
;
3384 shdrs
= ((Elf32_External_Shdr
*)
3385 get_data (NULL
, file
, elf_header
.e_shoff
,
3386 elf_header
.e_shentsize
* num
,
3387 _("section headers")));
3391 section_headers
= ((Elf_Internal_Shdr
*)
3392 malloc (num
* sizeof (Elf_Internal_Shdr
)));
3394 if (section_headers
== NULL
)
3396 error (_("Out of memory\n"));
3400 for (i
= 0, internal
= section_headers
;
3404 internal
->sh_name
= BYTE_GET (shdrs
[i
].sh_name
);
3405 internal
->sh_type
= BYTE_GET (shdrs
[i
].sh_type
);
3406 internal
->sh_flags
= BYTE_GET (shdrs
[i
].sh_flags
);
3407 internal
->sh_addr
= BYTE_GET (shdrs
[i
].sh_addr
);
3408 internal
->sh_offset
= BYTE_GET (shdrs
[i
].sh_offset
);
3409 internal
->sh_size
= BYTE_GET (shdrs
[i
].sh_size
);
3410 internal
->sh_link
= BYTE_GET (shdrs
[i
].sh_link
);
3411 internal
->sh_info
= BYTE_GET (shdrs
[i
].sh_info
);
3412 internal
->sh_addralign
= BYTE_GET (shdrs
[i
].sh_addralign
);
3413 internal
->sh_entsize
= BYTE_GET (shdrs
[i
].sh_entsize
);
3422 get_64bit_section_headers (file
, num
)
3426 Elf64_External_Shdr
*shdrs
;
3427 Elf_Internal_Shdr
*internal
;
3430 shdrs
= ((Elf64_External_Shdr
*)
3431 get_data (NULL
, file
, elf_header
.e_shoff
,
3432 elf_header
.e_shentsize
* num
,
3433 _("section headers")));
3437 section_headers
= ((Elf_Internal_Shdr
*)
3438 malloc (num
* sizeof (Elf_Internal_Shdr
)));
3440 if (section_headers
== NULL
)
3442 error (_("Out of memory\n"));
3446 for (i
= 0, internal
= section_headers
;
3450 internal
->sh_name
= BYTE_GET (shdrs
[i
].sh_name
);
3451 internal
->sh_type
= BYTE_GET (shdrs
[i
].sh_type
);
3452 internal
->sh_flags
= BYTE_GET8 (shdrs
[i
].sh_flags
);
3453 internal
->sh_addr
= BYTE_GET8 (shdrs
[i
].sh_addr
);
3454 internal
->sh_size
= BYTE_GET8 (shdrs
[i
].sh_size
);
3455 internal
->sh_entsize
= BYTE_GET8 (shdrs
[i
].sh_entsize
);
3456 internal
->sh_link
= BYTE_GET (shdrs
[i
].sh_link
);
3457 internal
->sh_info
= BYTE_GET (shdrs
[i
].sh_info
);
3458 internal
->sh_offset
= BYTE_GET (shdrs
[i
].sh_offset
);
3459 internal
->sh_addralign
= BYTE_GET (shdrs
[i
].sh_addralign
);
3467 static Elf_Internal_Sym
*
3468 get_32bit_elf_symbols (file
, section
)
3470 Elf_Internal_Shdr
*section
;
3472 unsigned long number
;
3473 Elf32_External_Sym
*esyms
;
3474 Elf_External_Sym_Shndx
*shndx
;
3475 Elf_Internal_Sym
*isyms
;
3476 Elf_Internal_Sym
*psym
;
3479 esyms
= ((Elf32_External_Sym
*)
3480 get_data (NULL
, file
, section
->sh_offset
,
3481 section
->sh_size
, _("symbols")));
3486 if (symtab_shndx_hdr
!= NULL
3487 && (symtab_shndx_hdr
->sh_link
3488 == (unsigned long) SECTION_HEADER_NUM (section
- section_headers
)))
3490 shndx
= ((Elf_External_Sym_Shndx
*)
3491 get_data (NULL
, file
, symtab_shndx_hdr
->sh_offset
,
3492 symtab_shndx_hdr
->sh_size
, _("symtab shndx")));
3500 number
= section
->sh_size
/ section
->sh_entsize
;
3501 isyms
= (Elf_Internal_Sym
*) malloc (number
* sizeof (Elf_Internal_Sym
));
3505 error (_("Out of memory\n"));
3512 for (j
= 0, psym
= isyms
;
3516 psym
->st_name
= BYTE_GET (esyms
[j
].st_name
);
3517 psym
->st_value
= BYTE_GET (esyms
[j
].st_value
);
3518 psym
->st_size
= BYTE_GET (esyms
[j
].st_size
);
3519 psym
->st_shndx
= BYTE_GET (esyms
[j
].st_shndx
);
3520 if (psym
->st_shndx
== SHN_XINDEX
&& shndx
!= NULL
)
3522 = byte_get ((unsigned char *) &shndx
[j
], sizeof (shndx
[j
]));
3523 psym
->st_info
= BYTE_GET (esyms
[j
].st_info
);
3524 psym
->st_other
= BYTE_GET (esyms
[j
].st_other
);
3534 static Elf_Internal_Sym
*
3535 get_64bit_elf_symbols (file
, section
)
3537 Elf_Internal_Shdr
*section
;
3539 unsigned long number
;
3540 Elf64_External_Sym
*esyms
;
3541 Elf_External_Sym_Shndx
*shndx
;
3542 Elf_Internal_Sym
*isyms
;
3543 Elf_Internal_Sym
*psym
;
3546 esyms
= ((Elf64_External_Sym
*)
3547 get_data (NULL
, file
, section
->sh_offset
,
3548 section
->sh_size
, _("symbols")));
3553 if (symtab_shndx_hdr
!= NULL
3554 && (symtab_shndx_hdr
->sh_link
3555 == (unsigned long) SECTION_HEADER_NUM (section
- section_headers
)))
3557 shndx
= ((Elf_External_Sym_Shndx
*)
3558 get_data (NULL
, file
, symtab_shndx_hdr
->sh_offset
,
3559 symtab_shndx_hdr
->sh_size
, _("symtab shndx")));
3567 number
= section
->sh_size
/ section
->sh_entsize
;
3568 isyms
= (Elf_Internal_Sym
*) malloc (number
* sizeof (Elf_Internal_Sym
));
3572 error (_("Out of memory\n"));
3579 for (j
= 0, psym
= isyms
;
3583 psym
->st_name
= BYTE_GET (esyms
[j
].st_name
);
3584 psym
->st_info
= BYTE_GET (esyms
[j
].st_info
);
3585 psym
->st_other
= BYTE_GET (esyms
[j
].st_other
);
3586 psym
->st_shndx
= BYTE_GET (esyms
[j
].st_shndx
);
3587 if (psym
->st_shndx
== SHN_XINDEX
&& shndx
!= NULL
)
3589 = byte_get ((unsigned char *) &shndx
[j
], sizeof (shndx
[j
]));
3590 psym
->st_value
= BYTE_GET8 (esyms
[j
].st_value
);
3591 psym
->st_size
= BYTE_GET8 (esyms
[j
].st_size
);
3602 get_elf_section_flags (sh_flags
)
3605 static char buff
[32];
3613 flag
= sh_flags
& - sh_flags
;
3618 case SHF_WRITE
: strcat (buff
, "W"); break;
3619 case SHF_ALLOC
: strcat (buff
, "A"); break;
3620 case SHF_EXECINSTR
: strcat (buff
, "X"); break;
3621 case SHF_MERGE
: strcat (buff
, "M"); break;
3622 case SHF_STRINGS
: strcat (buff
, "S"); break;
3623 case SHF_INFO_LINK
: strcat (buff
, "I"); break;
3624 case SHF_LINK_ORDER
: strcat (buff
, "L"); break;
3625 case SHF_OS_NONCONFORMING
: strcat (buff
, "O"); break;
3626 case SHF_GROUP
: strcat (buff
, "G"); break;
3627 case SHF_TLS
: strcat (buff
, "T"); break;
3630 if (flag
& SHF_MASKOS
)
3633 sh_flags
&= ~ SHF_MASKOS
;
3635 else if (flag
& SHF_MASKPROC
)
3638 sh_flags
&= ~ SHF_MASKPROC
;
3650 process_section_headers (file
)
3653 Elf_Internal_Shdr
*section
;
3656 section_headers
= NULL
;
3658 if (elf_header
.e_shnum
== 0)
3661 printf (_("\nThere are no sections in this file.\n"));
3666 if (do_sections
&& !do_header
)
3667 printf (_("There are %d section headers, starting at offset 0x%lx:\n"),
3668 elf_header
.e_shnum
, (unsigned long) elf_header
.e_shoff
);
3672 if (! get_32bit_section_headers (file
, elf_header
.e_shnum
))
3675 else if (! get_64bit_section_headers (file
, elf_header
.e_shnum
))
3678 /* Read in the string table, so that we have names to display. */
3679 section
= SECTION_HEADER (elf_header
.e_shstrndx
);
3681 if (section
->sh_size
!= 0)
3683 string_table
= (char *) get_data (NULL
, file
, section
->sh_offset
,
3684 section
->sh_size
, _("string table"));
3686 string_table_length
= section
->sh_size
;
3689 /* Scan the sections for the dynamic symbol table
3690 and dynamic string table and debug sections. */
3691 dynamic_symbols
= NULL
;
3692 dynamic_strings
= NULL
;
3693 dynamic_syminfo
= NULL
;
3694 symtab_shndx_hdr
= NULL
;
3696 for (i
= 0, section
= section_headers
;
3697 i
< elf_header
.e_shnum
;
3700 char *name
= SECTION_NAME (section
);
3702 if (section
->sh_type
== SHT_DYNSYM
)
3704 if (dynamic_symbols
!= NULL
)
3706 error (_("File contains multiple dynamic symbol tables\n"));
3710 num_dynamic_syms
= section
->sh_size
/ section
->sh_entsize
;
3711 dynamic_symbols
= GET_ELF_SYMBOLS (file
, section
);
3713 else if (section
->sh_type
== SHT_STRTAB
3714 && strcmp (name
, ".dynstr") == 0)
3716 if (dynamic_strings
!= NULL
)
3718 error (_("File contains multiple dynamic string tables\n"));
3722 dynamic_strings
= (char *) get_data (NULL
, file
, section
->sh_offset
,
3724 _("dynamic strings"));
3726 else if (section
->sh_type
== SHT_SYMTAB_SHNDX
)
3728 if (symtab_shndx_hdr
!= NULL
)
3730 error (_("File contains multiple symtab shndx tables\n"));
3733 symtab_shndx_hdr
= section
;
3735 else if ((do_debugging
|| do_debug_info
|| do_debug_abbrevs
3736 || do_debug_lines
|| do_debug_pubnames
|| do_debug_aranges
3737 || do_debug_frames
|| do_debug_macinfo
|| do_debug_str
3739 && strncmp (name
, ".debug_", 7) == 0)
3744 || (do_debug_info
&& (strcmp (name
, "info") == 0))
3745 || (do_debug_abbrevs
&& (strcmp (name
, "abbrev") == 0))
3746 || (do_debug_lines
&& (strcmp (name
, "line") == 0))
3747 || (do_debug_pubnames
&& (strcmp (name
, "pubnames") == 0))
3748 || (do_debug_aranges
&& (strcmp (name
, "aranges") == 0))
3749 || (do_debug_frames
&& (strcmp (name
, "frame") == 0))
3750 || (do_debug_macinfo
&& (strcmp (name
, "macinfo") == 0))
3751 || (do_debug_str
&& (strcmp (name
, "str") == 0))
3752 || (do_debug_loc
&& (strcmp (name
, "loc") == 0))
3754 request_dump (i
, DEBUG_DUMP
);
3756 /* linkonce section to be combined with .debug_info at link time. */
3757 else if ((do_debugging
|| do_debug_info
)
3758 && strncmp (name
, ".gnu.linkonce.wi.", 17) == 0)
3759 request_dump (i
, DEBUG_DUMP
);
3760 else if (do_debug_frames
&& strcmp (name
, ".eh_frame") == 0)
3761 request_dump (i
, DEBUG_DUMP
);
3767 if (elf_header
.e_shnum
> 1)
3768 printf (_("\nSection Headers:\n"));
3770 printf (_("\nSection Header:\n"));
3774 (_(" [Nr] Name Type Addr Off Size ES Flg Lk Inf Al\n"));
3777 (_(" [Nr] Name Type Address Off Size ES Flg Lk Inf Al\n"));
3780 printf (_(" [Nr] Name Type Address Offset\n"));
3781 printf (_(" Size EntSize Flags Link Info Align\n"));
3784 for (i
= 0, section
= section_headers
;
3785 i
< elf_header
.e_shnum
;
3788 printf (" [%2u] %-17.17s %-15.15s ",
3789 SECTION_HEADER_NUM (i
),
3790 SECTION_NAME (section
),
3791 get_section_type_name (section
->sh_type
));
3795 print_vma (section
->sh_addr
, LONG_HEX
);
3797 printf ( " %6.6lx %6.6lx %2.2lx",
3798 (unsigned long) section
->sh_offset
,
3799 (unsigned long) section
->sh_size
,
3800 (unsigned long) section
->sh_entsize
);
3802 printf (" %3s ", get_elf_section_flags (section
->sh_flags
));
3804 printf ("%2ld %3lx %2ld\n",
3805 (unsigned long) section
->sh_link
,
3806 (unsigned long) section
->sh_info
,
3807 (unsigned long) section
->sh_addralign
);
3811 print_vma (section
->sh_addr
, LONG_HEX
);
3813 if ((long) section
->sh_offset
== section
->sh_offset
)
3814 printf (" %6.6lx", (unsigned long) section
->sh_offset
);
3818 print_vma (section
->sh_offset
, LONG_HEX
);
3821 if ((unsigned long) section
->sh_size
== section
->sh_size
)
3822 printf (" %6.6lx", (unsigned long) section
->sh_size
);
3826 print_vma (section
->sh_size
, LONG_HEX
);
3829 if ((unsigned long) section
->sh_entsize
== section
->sh_entsize
)
3830 printf (" %2.2lx", (unsigned long) section
->sh_entsize
);
3834 print_vma (section
->sh_entsize
, LONG_HEX
);
3837 printf (" %3s ", get_elf_section_flags (section
->sh_flags
));
3839 printf ("%2ld %3lx ",
3840 (unsigned long) section
->sh_link
,
3841 (unsigned long) section
->sh_info
);
3843 if ((unsigned long) section
->sh_addralign
== section
->sh_addralign
)
3844 printf ("%2ld\n", (unsigned long) section
->sh_addralign
);
3847 print_vma (section
->sh_addralign
, DEC
);
3854 print_vma (section
->sh_addr
, LONG_HEX
);
3855 if ((long) section
->sh_offset
== section
->sh_offset
)
3856 printf (" %8.8lx", (unsigned long) section
->sh_offset
);
3860 print_vma (section
->sh_offset
, LONG_HEX
);
3863 print_vma (section
->sh_size
, LONG_HEX
);
3865 print_vma (section
->sh_entsize
, LONG_HEX
);
3867 printf (" %3s ", get_elf_section_flags (section
->sh_flags
));
3869 printf (" %2ld %3lx %ld\n",
3870 (unsigned long) section
->sh_link
,
3871 (unsigned long) section
->sh_info
,
3872 (unsigned long) section
->sh_addralign
);
3876 printf (_("Key to Flags:\n\
3877 W (write), A (alloc), X (execute), M (merge), S (strings)\n\
3878 I (info), L (link order), G (group), x (unknown)\n\
3879 O (extra OS processing required) o (OS specific), p (processor specific)\n"));
3890 } dynamic_relocations
[] =
3892 { "REL", DT_REL
, DT_RELSZ
, FALSE
},
3893 { "RELA", DT_RELA
, DT_RELASZ
, TRUE
},
3894 { "PLT", DT_JMPREL
, DT_PLTRELSZ
, UNKNOWN
}
3897 /* Process the reloc section. */
3899 process_relocs (file
)
3902 unsigned long rel_size
;
3903 unsigned long rel_offset
;
3909 if (do_using_dynamic
)
3913 int has_dynamic_reloc
;
3916 has_dynamic_reloc
= 0;
3918 for (i
= 0; i
< ARRAY_SIZE (dynamic_relocations
); i
++)
3920 is_rela
= dynamic_relocations
[i
].rela
;
3921 name
= dynamic_relocations
[i
].name
;
3922 rel_size
= dynamic_info
[dynamic_relocations
[i
].size
];
3923 rel_offset
= dynamic_info
[dynamic_relocations
[i
].reloc
];
3925 has_dynamic_reloc
|= rel_size
;
3927 if (is_rela
== UNKNOWN
)
3929 if (dynamic_relocations
[i
].reloc
== DT_JMPREL
)
3930 switch (dynamic_info
[DT_PLTREL
])
3944 (_("\n'%s' relocation section at offset 0x%lx contains %ld bytes:\n"),
3945 name
, rel_offset
, rel_size
);
3947 dump_relocations (file
, rel_offset
- loadaddr
, rel_size
,
3948 dynamic_symbols
, num_dynamic_syms
,
3949 dynamic_strings
, is_rela
);
3953 if (! has_dynamic_reloc
)
3954 printf (_("\nThere are no dynamic relocations in this file.\n"));
3958 Elf_Internal_Shdr
*section
;
3962 for (i
= 0, section
= section_headers
;
3963 i
< elf_header
.e_shnum
;
3966 if ( section
->sh_type
!= SHT_RELA
3967 && section
->sh_type
!= SHT_REL
)
3970 rel_offset
= section
->sh_offset
;
3971 rel_size
= section
->sh_size
;
3975 Elf_Internal_Shdr
*strsec
;
3976 Elf_Internal_Sym
*symtab
;
3979 unsigned long nsyms
;
3981 printf (_("\nRelocation section "));
3983 if (string_table
== NULL
)
3984 printf ("%d", section
->sh_name
);
3986 printf (_("'%s'"), SECTION_NAME (section
));
3988 printf (_(" at offset 0x%lx contains %lu entries:\n"),
3989 rel_offset
, (unsigned long) (rel_size
/ section
->sh_entsize
));
3994 if (section
->sh_link
)
3996 Elf_Internal_Shdr
*symsec
;
3998 symsec
= SECTION_HEADER (section
->sh_link
);
3999 nsyms
= symsec
->sh_size
/ symsec
->sh_entsize
;
4000 symtab
= GET_ELF_SYMBOLS (file
, symsec
);
4005 strsec
= SECTION_HEADER (symsec
->sh_link
);
4007 strtab
= (char *) get_data (NULL
, file
, strsec
->sh_offset
,
4011 is_rela
= section
->sh_type
== SHT_RELA
;
4013 dump_relocations (file
, rel_offset
, rel_size
,
4014 symtab
, nsyms
, strtab
, is_rela
);
4026 printf (_("\nThere are no relocations in this file.\n"));
4032 #include "unwind-ia64.h"
4034 /* An absolute address consists of a section and an offset. If the
4035 section is NULL, the offset itself is the address, otherwise, the
4036 address equals to LOAD_ADDRESS(section) + offset. */
4040 unsigned short section
;
4046 struct unw_table_entry
4048 struct absaddr start
;
4050 struct absaddr info
;
4052 *table
; /* Unwind table. */
4053 unsigned long table_len
; /* Length of unwind table. */
4054 unsigned char *info
; /* Unwind info. */
4055 unsigned long info_size
; /* Size of unwind info. */
4056 bfd_vma info_addr
; /* starting address of unwind info. */
4057 bfd_vma seg_base
; /* Starting address of segment. */
4058 Elf_Internal_Sym
*symtab
; /* The symbol table. */
4059 unsigned long nsyms
; /* Number of symbols. */
4060 char *strtab
; /* The string table. */
4061 unsigned long strtab_size
; /* Size of string table. */
4064 static void find_symbol_for_address
4065 PARAMS ((struct unw_aux_info
*, struct absaddr
, const char **, bfd_vma
*));
4066 static void dump_ia64_unwind
4067 PARAMS ((struct unw_aux_info
*));
4068 static int slurp_ia64_unwind_table
4069 PARAMS ((FILE *, struct unw_aux_info
*, Elf_Internal_Shdr
*));
4072 find_symbol_for_address (aux
, addr
, symname
, offset
)
4073 struct unw_aux_info
*aux
;
4074 struct absaddr addr
;
4075 const char **symname
;
4078 bfd_vma dist
= (bfd_vma
) 0x100000;
4079 Elf_Internal_Sym
*sym
, *best
= NULL
;
4082 for (i
= 0, sym
= aux
->symtab
; i
< aux
->nsyms
; ++i
, ++sym
)
4084 if (ELF_ST_TYPE (sym
->st_info
) == STT_FUNC
4085 && sym
->st_name
!= 0
4086 && (addr
.section
== SHN_UNDEF
|| addr
.section
== sym
->st_shndx
)
4087 && addr
.offset
>= sym
->st_value
4088 && addr
.offset
- sym
->st_value
< dist
)
4091 dist
= addr
.offset
- sym
->st_value
;
4098 *symname
= (best
->st_name
>= aux
->strtab_size
4099 ? "<corrupt>" : aux
->strtab
+ best
->st_name
);
4104 *offset
= addr
.offset
;
4108 dump_ia64_unwind (aux
)
4109 struct unw_aux_info
*aux
;
4112 struct unw_table_entry
*tp
;
4115 addr_size
= is_32bit_elf
? 4 : 8;
4117 for (tp
= aux
->table
; tp
< aux
->table
+ aux
->table_len
; ++tp
)
4121 const unsigned char *dp
;
4122 const unsigned char *head
;
4123 const char *procname
;
4125 find_symbol_for_address (aux
, tp
->start
, &procname
, &offset
);
4127 fputs ("\n<", stdout
);
4131 fputs (procname
, stdout
);
4134 printf ("+%lx", (unsigned long) offset
);
4137 fputs (">: [", stdout
);
4138 print_vma (tp
->start
.offset
, PREFIX_HEX
);
4139 fputc ('-', stdout
);
4140 print_vma (tp
->end
.offset
, PREFIX_HEX
);
4141 printf ("], info at +0x%lx\n",
4142 (unsigned long) (tp
->info
.offset
- aux
->seg_base
));
4144 head
= aux
->info
+ (tp
->info
.offset
- aux
->info_addr
);
4145 stamp
= BYTE_GET8 ((unsigned char *) head
);
4147 printf (" v%u, flags=0x%lx (%s%s), len=%lu bytes\n",
4148 (unsigned) UNW_VER (stamp
),
4149 (unsigned long) ((stamp
& UNW_FLAG_MASK
) >> 32),
4150 UNW_FLAG_EHANDLER (stamp
) ? " ehandler" : "",
4151 UNW_FLAG_UHANDLER (stamp
) ? " uhandler" : "",
4152 (unsigned long) (addr_size
* UNW_LENGTH (stamp
)));
4154 if (UNW_VER (stamp
) != 1)
4156 printf ("\tUnknown version.\n");
4161 for (dp
= head
+ 8; dp
< head
+ 8 + addr_size
* UNW_LENGTH (stamp
);)
4162 dp
= unw_decode (dp
, in_body
, & in_body
);
4167 slurp_ia64_unwind_table (file
, aux
, sec
)
4169 struct unw_aux_info
*aux
;
4170 Elf_Internal_Shdr
*sec
;
4172 unsigned long size
, addr_size
, nrelas
, i
;
4173 Elf_Internal_Phdr
*prog_hdrs
, *seg
;
4174 struct unw_table_entry
*tep
;
4175 Elf_Internal_Shdr
*relsec
;
4176 Elf_Internal_Rela
*rela
, *rp
;
4177 unsigned char *table
, *tp
;
4178 Elf_Internal_Sym
*sym
;
4179 const char *relname
;
4182 addr_size
= is_32bit_elf
? 4 : 8;
4184 /* First, find the starting address of the segment that includes
4187 if (elf_header
.e_phnum
)
4189 prog_hdrs
= (Elf_Internal_Phdr
*)
4190 xmalloc (elf_header
.e_phnum
* sizeof (Elf_Internal_Phdr
));
4193 result
= get_32bit_program_headers (file
, prog_hdrs
);
4195 result
= get_64bit_program_headers (file
, prog_hdrs
);
4203 for (seg
= prog_hdrs
; seg
< prog_hdrs
+ elf_header
.e_phnum
; ++seg
)
4205 if (seg
->p_type
!= PT_LOAD
)
4208 if (sec
->sh_addr
>= seg
->p_vaddr
4209 && (sec
->sh_addr
+ sec
->sh_size
<= seg
->p_vaddr
+ seg
->p_memsz
))
4211 aux
->seg_base
= seg
->p_vaddr
;
4219 /* Second, build the unwind table from the contents of the unwind section: */
4220 size
= sec
->sh_size
;
4221 table
= (char *) get_data (NULL
, file
, sec
->sh_offset
,
4222 size
, _("unwind table"));
4226 tep
= aux
->table
= xmalloc (size
/ (3 * addr_size
) * sizeof (aux
->table
[0]));
4227 for (tp
= table
; tp
< table
+ size
; tp
+= 3 * addr_size
, ++tep
)
4229 tep
->start
.section
= SHN_UNDEF
;
4230 tep
->end
.section
= SHN_UNDEF
;
4231 tep
->info
.section
= SHN_UNDEF
;
4234 tep
->start
.offset
= byte_get ((unsigned char *) tp
+ 0, 4);
4235 tep
->end
.offset
= byte_get ((unsigned char *) tp
+ 4, 4);
4236 tep
->info
.offset
= byte_get ((unsigned char *) tp
+ 8, 4);
4240 tep
->start
.offset
= BYTE_GET8 ((unsigned char *) tp
+ 0);
4241 tep
->end
.offset
= BYTE_GET8 ((unsigned char *) tp
+ 8);
4242 tep
->info
.offset
= BYTE_GET8 ((unsigned char *) tp
+ 16);
4244 tep
->start
.offset
+= aux
->seg_base
;
4245 tep
->end
.offset
+= aux
->seg_base
;
4246 tep
->info
.offset
+= aux
->seg_base
;
4250 /* Third, apply any relocations to the unwind table: */
4252 for (relsec
= section_headers
;
4253 relsec
< section_headers
+ elf_header
.e_shnum
;
4256 if (relsec
->sh_type
!= SHT_RELA
4257 || SECTION_HEADER (relsec
->sh_info
) != sec
)
4260 if (!slurp_rela_relocs (file
, relsec
->sh_offset
, relsec
->sh_size
,
4264 for (rp
= rela
; rp
< rela
+ nrelas
; ++rp
)
4268 relname
= elf_ia64_reloc_type (ELF32_R_TYPE (rp
->r_info
));
4269 sym
= aux
->symtab
+ ELF32_R_SYM (rp
->r_info
);
4271 if (ELF32_ST_TYPE (sym
->st_info
) != STT_SECTION
)
4273 warn (_("Skipping unexpected symbol type %u\n"),
4274 ELF32_ST_TYPE (sym
->st_info
));
4280 relname
= elf_ia64_reloc_type (ELF64_R_TYPE (rp
->r_info
));
4281 sym
= aux
->symtab
+ ELF64_R_SYM (rp
->r_info
);
4283 if (ELF64_ST_TYPE (sym
->st_info
) != STT_SECTION
)
4285 warn (_("Skipping unexpected symbol type %u\n"),
4286 ELF64_ST_TYPE (sym
->st_info
));
4291 if (strncmp (relname
, "R_IA64_SEGREL", 13) != 0)
4293 warn (_("Skipping unexpected relocation type %s\n"), relname
);
4297 i
= rp
->r_offset
/ (3 * addr_size
);
4299 switch (rp
->r_offset
/addr_size
% 3)
4302 aux
->table
[i
].start
.section
= sym
->st_shndx
;
4303 aux
->table
[i
].start
.offset
+= rp
->r_addend
;
4306 aux
->table
[i
].end
.section
= sym
->st_shndx
;
4307 aux
->table
[i
].end
.offset
+= rp
->r_addend
;
4310 aux
->table
[i
].info
.section
= sym
->st_shndx
;
4311 aux
->table
[i
].info
.offset
+= rp
->r_addend
;
4321 aux
->table_len
= size
/ (3 * addr_size
);
4326 process_unwind (file
)
4329 Elf_Internal_Shdr
*sec
, *unwsec
= NULL
, *strsec
;
4330 unsigned long i
, addr_size
, unwcount
= 0, unwstart
= 0;
4331 struct unw_aux_info aux
;
4336 if (elf_header
.e_machine
!= EM_IA_64
)
4338 printf (_("\nThere are no unwind sections in this file.\n"));
4342 memset (& aux
, 0, sizeof (aux
));
4344 addr_size
= is_32bit_elf
? 4 : 8;
4346 for (i
= 0, sec
= section_headers
; i
< elf_header
.e_shnum
; ++i
, ++sec
)
4348 if (sec
->sh_type
== SHT_SYMTAB
)
4350 aux
.nsyms
= sec
->sh_size
/ sec
->sh_entsize
;
4351 aux
.symtab
= GET_ELF_SYMBOLS (file
, sec
);
4353 strsec
= SECTION_HEADER (sec
->sh_link
);
4354 aux
.strtab_size
= strsec
->sh_size
;
4355 aux
.strtab
= (char *) get_data (NULL
, file
, strsec
->sh_offset
,
4356 aux
.strtab_size
, _("string table"));
4358 else if (sec
->sh_type
== SHT_IA_64_UNWIND
)
4363 printf (_("\nThere are no unwind sections in this file.\n"));
4365 while (unwcount
-- > 0)
4370 for (i
= unwstart
, sec
= section_headers
+ unwstart
;
4371 i
< elf_header
.e_shnum
; ++i
, ++sec
)
4372 if (sec
->sh_type
== SHT_IA_64_UNWIND
)
4379 len
= sizeof (ELF_STRING_ia64_unwind_once
) - 1;
4381 if (strncmp (SECTION_NAME (unwsec
), ELF_STRING_ia64_unwind_once
,
4384 /* .gnu.linkonce.ia64unw.FOO -> .gnu.linkonce.ia64unwi.FOO */
4385 len2
= sizeof (ELF_STRING_ia64_unwind_info_once
) - 1;
4386 suffix
= SECTION_NAME (unwsec
) + len
;
4387 for (i
= 0, sec
= section_headers
; i
< elf_header
.e_shnum
;
4389 if (strncmp (SECTION_NAME (sec
),
4390 ELF_STRING_ia64_unwind_info_once
, len2
) == 0
4391 && strcmp (SECTION_NAME (sec
) + len2
, suffix
) == 0)
4396 /* .IA_64.unwindFOO -> .IA_64.unwind_infoFOO
4397 .IA_64.unwind or BAR -> .IA_64.unwind_info */
4398 len
= sizeof (ELF_STRING_ia64_unwind
) - 1;
4399 len2
= sizeof (ELF_STRING_ia64_unwind_info
) - 1;
4401 if (strncmp (SECTION_NAME (unwsec
), ELF_STRING_ia64_unwind
,
4403 suffix
= SECTION_NAME (unwsec
) + len
;
4404 for (i
= 0, sec
= section_headers
; i
< elf_header
.e_shnum
;
4406 if (strncmp (SECTION_NAME (sec
),
4407 ELF_STRING_ia64_unwind_info
, len2
) == 0
4408 && strcmp (SECTION_NAME (sec
) + len2
, suffix
) == 0)
4412 if (i
== elf_header
.e_shnum
)
4414 printf (_("\nCould not find unwind info section for "));
4416 if (string_table
== NULL
)
4417 printf ("%d", unwsec
->sh_name
);
4419 printf (_("'%s'"), SECTION_NAME (unwsec
));
4423 aux
.info_size
= sec
->sh_size
;
4424 aux
.info_addr
= sec
->sh_addr
;
4425 aux
.info
= (char *) get_data (NULL
, file
, sec
->sh_offset
,
4426 aux
.info_size
, _("unwind info"));
4428 printf (_("\nUnwind section "));
4430 if (string_table
== NULL
)
4431 printf ("%d", unwsec
->sh_name
);
4433 printf (_("'%s'"), SECTION_NAME (unwsec
));
4435 printf (_(" at offset 0x%lx contains %lu entries:\n"),
4436 (unsigned long) unwsec
->sh_offset
,
4437 (unsigned long) (unwsec
->sh_size
/ (3 * addr_size
)));
4439 (void) slurp_ia64_unwind_table (file
, & aux
, unwsec
);
4441 if (aux
.table_len
> 0)
4442 dump_ia64_unwind (& aux
);
4445 free ((char *) aux
.table
);
4447 free ((char *) aux
.info
);
4456 free ((char *) aux
.strtab
);
4462 dynamic_segment_mips_val (entry
)
4463 Elf_Internal_Dyn
*entry
;
4465 switch (entry
->d_tag
)
4468 if (entry
->d_un
.d_val
== 0)
4472 static const char * opts
[] =
4474 "QUICKSTART", "NOTPOT", "NO_LIBRARY_REPLACEMENT",
4475 "NO_MOVE", "SGI_ONLY", "GUARANTEE_INIT", "DELTA_C_PLUS_PLUS",
4476 "GUARANTEE_START_INIT", "PIXIE", "DEFAULT_DELAY_LOAD",
4477 "REQUICKSTART", "REQUICKSTARTED", "CORD", "NO_UNRES_UNDEF",
4482 for (cnt
= 0; cnt
< NUM_ELEM (opts
); ++cnt
)
4483 if (entry
->d_un
.d_val
& (1 << cnt
))
4485 printf ("%s%s", first
? "" : " ", opts
[cnt
]);
4492 case DT_MIPS_IVERSION
:
4493 if (dynamic_strings
!= NULL
)
4494 printf ("Interface Version: %s\n",
4495 dynamic_strings
+ entry
->d_un
.d_val
);
4497 printf ("%ld\n", (long) entry
->d_un
.d_ptr
);
4500 case DT_MIPS_TIME_STAMP
:
4505 time_t time
= entry
->d_un
.d_val
;
4506 tmp
= gmtime (&time
);
4507 sprintf (timebuf
, "%04u-%02u-%02uT%02u:%02u:%02u",
4508 tmp
->tm_year
+ 1900, tmp
->tm_mon
+ 1, tmp
->tm_mday
,
4509 tmp
->tm_hour
, tmp
->tm_min
, tmp
->tm_sec
);
4510 printf ("Time Stamp: %s\n", timebuf
);
4514 case DT_MIPS_RLD_VERSION
:
4515 case DT_MIPS_LOCAL_GOTNO
:
4516 case DT_MIPS_CONFLICTNO
:
4517 case DT_MIPS_LIBLISTNO
:
4518 case DT_MIPS_SYMTABNO
:
4519 case DT_MIPS_UNREFEXTNO
:
4520 case DT_MIPS_HIPAGENO
:
4521 case DT_MIPS_DELTA_CLASS_NO
:
4522 case DT_MIPS_DELTA_INSTANCE_NO
:
4523 case DT_MIPS_DELTA_RELOC_NO
:
4524 case DT_MIPS_DELTA_SYM_NO
:
4525 case DT_MIPS_DELTA_CLASSSYM_NO
:
4526 case DT_MIPS_COMPACT_SIZE
:
4527 printf ("%ld\n", (long) entry
->d_un
.d_ptr
);
4531 printf ("%#lx\n", (long) entry
->d_un
.d_ptr
);
4537 dynamic_segment_parisc_val (entry
)
4538 Elf_Internal_Dyn
*entry
;
4540 switch (entry
->d_tag
)
4542 case DT_HP_DLD_FLAGS
:
4551 { DT_HP_DEBUG_PRIVATE
, "HP_DEBUG_PRIVATE" },
4552 { DT_HP_DEBUG_CALLBACK
, "HP_DEBUG_CALLBACK" },
4553 { DT_HP_DEBUG_CALLBACK_BOR
, "HP_DEBUG_CALLBACK_BOR" },
4554 { DT_HP_NO_ENVVAR
, "HP_NO_ENVVAR" },
4555 { DT_HP_BIND_NOW
, "HP_BIND_NOW" },
4556 { DT_HP_BIND_NONFATAL
, "HP_BIND_NONFATAL" },
4557 { DT_HP_BIND_VERBOSE
, "HP_BIND_VERBOSE" },
4558 { DT_HP_BIND_RESTRICTED
, "HP_BIND_RESTRICTED" },
4559 { DT_HP_BIND_SYMBOLIC
, "HP_BIND_SYMBOLIC" },
4560 { DT_HP_RPATH_FIRST
, "HP_RPATH_FIRST" },
4561 { DT_HP_BIND_DEPTH_FIRST
, "HP_BIND_DEPTH_FIRST" }
4565 bfd_vma val
= entry
->d_un
.d_val
;
4567 for (cnt
= 0; cnt
< sizeof (flags
) / sizeof (flags
[0]); ++cnt
)
4568 if (val
& flags
[cnt
].bit
)
4572 fputs (flags
[cnt
].str
, stdout
);
4574 val
^= flags
[cnt
].bit
;
4577 if (val
!= 0 || first
)
4581 print_vma (val
, HEX
);
4587 print_vma (entry
->d_un
.d_ptr
, PREFIX_HEX
);
4594 dynamic_segment_ia64_val (entry
)
4595 Elf_Internal_Dyn
*entry
;
4597 switch (entry
->d_tag
)
4599 case DT_IA_64_PLT_RESERVE
:
4600 /* First 3 bytes reserved. */
4601 print_vma (entry
->d_un
.d_ptr
, PREFIX_HEX
);
4603 print_vma (entry
->d_un
.d_ptr
+ (3 * 8), PREFIX_HEX
);
4609 get_32bit_dynamic_segment (file
)
4612 Elf32_External_Dyn
*edyn
;
4613 Elf_Internal_Dyn
*entry
;
4616 edyn
= (Elf32_External_Dyn
*) get_data (NULL
, file
, dynamic_addr
,
4617 dynamic_size
, _("dynamic segment"));
4621 /* SGI's ELF has more than one section in the DYNAMIC segment. Determine
4622 how large this .dynamic is now. We can do this even before the byte
4623 swapping since the DT_NULL tag is recognizable. */
4625 while (*(Elf32_Word
*) edyn
[dynamic_size
++].d_tag
!= DT_NULL
)
4628 dynamic_segment
= (Elf_Internal_Dyn
*)
4629 malloc (dynamic_size
* sizeof (Elf_Internal_Dyn
));
4631 if (dynamic_segment
== NULL
)
4633 error (_("Out of memory\n"));
4638 for (i
= 0, entry
= dynamic_segment
;
4642 entry
->d_tag
= BYTE_GET (edyn
[i
].d_tag
);
4643 entry
->d_un
.d_val
= BYTE_GET (edyn
[i
].d_un
.d_val
);
4652 get_64bit_dynamic_segment (file
)
4655 Elf64_External_Dyn
*edyn
;
4656 Elf_Internal_Dyn
*entry
;
4659 edyn
= (Elf64_External_Dyn
*) get_data (NULL
, file
, dynamic_addr
,
4660 dynamic_size
, _("dynamic segment"));
4664 /* SGI's ELF has more than one section in the DYNAMIC segment. Determine
4665 how large this .dynamic is now. We can do this even before the byte
4666 swapping since the DT_NULL tag is recognizable. */
4668 while (*(bfd_vma
*) edyn
[dynamic_size
++].d_tag
!= DT_NULL
)
4671 dynamic_segment
= (Elf_Internal_Dyn
*)
4672 malloc (dynamic_size
* sizeof (Elf_Internal_Dyn
));
4674 if (dynamic_segment
== NULL
)
4676 error (_("Out of memory\n"));
4681 for (i
= 0, entry
= dynamic_segment
;
4685 entry
->d_tag
= BYTE_GET8 (edyn
[i
].d_tag
);
4686 entry
->d_un
.d_val
= BYTE_GET8 (edyn
[i
].d_un
.d_val
);
4695 get_dynamic_flags (flags
)
4698 static char buff
[128];
4706 flag
= flags
& - flags
;
4714 case DF_ORIGIN
: strcpy (p
, "ORIGIN"); break;
4715 case DF_SYMBOLIC
: strcpy (p
, "SYMBOLIC"); break;
4716 case DF_TEXTREL
: strcpy (p
, "TEXTREL"); break;
4717 case DF_BIND_NOW
: strcpy (p
, "BIND_NOW"); break;
4718 case DF_STATIC_TLS
: strcpy (p
, "STATIC_TLS"); break;
4719 default: strcpy (p
, "unknown"); break;
4722 p
= strchr (p
, '\0');
4727 /* Parse and display the contents of the dynamic segment. */
4729 process_dynamic_segment (file
)
4732 Elf_Internal_Dyn
*entry
;
4735 if (dynamic_size
== 0)
4738 printf (_("\nThere is no dynamic segment in this file.\n"));
4745 if (! get_32bit_dynamic_segment (file
))
4748 else if (! get_64bit_dynamic_segment (file
))
4751 /* Find the appropriate symbol table. */
4752 if (dynamic_symbols
== NULL
)
4754 for (i
= 0, entry
= dynamic_segment
;
4758 Elf_Internal_Shdr section
;
4760 if (entry
->d_tag
!= DT_SYMTAB
)
4763 dynamic_info
[DT_SYMTAB
] = entry
->d_un
.d_val
;
4765 /* Since we do not know how big the symbol table is,
4766 we default to reading in the entire file (!) and
4767 processing that. This is overkill, I know, but it
4769 section
.sh_offset
= entry
->d_un
.d_val
- loadaddr
;
4771 if (fseek (file
, 0, SEEK_END
))
4772 error (_("Unable to seek to end of file!"));
4774 section
.sh_size
= ftell (file
) - section
.sh_offset
;
4776 section
.sh_entsize
= sizeof (Elf32_External_Sym
);
4778 section
.sh_entsize
= sizeof (Elf64_External_Sym
);
4780 num_dynamic_syms
= section
.sh_size
/ section
.sh_entsize
;
4781 if (num_dynamic_syms
< 1)
4783 error (_("Unable to determine the number of symbols to load\n"));
4787 dynamic_symbols
= GET_ELF_SYMBOLS (file
, §ion
);
4791 /* Similarly find a string table. */
4792 if (dynamic_strings
== NULL
)
4794 for (i
= 0, entry
= dynamic_segment
;
4798 unsigned long offset
;
4801 if (entry
->d_tag
!= DT_STRTAB
)
4804 dynamic_info
[DT_STRTAB
] = entry
->d_un
.d_val
;
4806 /* Since we do not know how big the string table is,
4807 we default to reading in the entire file (!) and
4808 processing that. This is overkill, I know, but it
4811 offset
= entry
->d_un
.d_val
- loadaddr
;
4812 if (fseek (file
, 0, SEEK_END
))
4813 error (_("Unable to seek to end of file\n"));
4814 str_tab_len
= ftell (file
) - offset
;
4816 if (str_tab_len
< 1)
4819 (_("Unable to determine the length of the dynamic string table\n"));
4823 dynamic_strings
= (char *) get_data (NULL
, file
, offset
, str_tab_len
,
4824 _("dynamic string table"));
4829 /* And find the syminfo section if available. */
4830 if (dynamic_syminfo
== NULL
)
4832 unsigned long syminsz
= 0;
4834 for (i
= 0, entry
= dynamic_segment
;
4838 if (entry
->d_tag
== DT_SYMINENT
)
4840 /* Note: these braces are necessary to avoid a syntax
4841 error from the SunOS4 C compiler. */
4842 assert (sizeof (Elf_External_Syminfo
) == entry
->d_un
.d_val
);
4844 else if (entry
->d_tag
== DT_SYMINSZ
)
4845 syminsz
= entry
->d_un
.d_val
;
4846 else if (entry
->d_tag
== DT_SYMINFO
)
4847 dynamic_syminfo_offset
= entry
->d_un
.d_val
- loadaddr
;
4850 if (dynamic_syminfo_offset
!= 0 && syminsz
!= 0)
4852 Elf_External_Syminfo
*extsyminfo
;
4853 Elf_Internal_Syminfo
*syminfo
;
4855 /* There is a syminfo section. Read the data. */
4856 extsyminfo
= ((Elf_External_Syminfo
*)
4857 get_data (NULL
, file
, dynamic_syminfo_offset
,
4858 syminsz
, _("symbol information")));
4862 dynamic_syminfo
= (Elf_Internal_Syminfo
*) malloc (syminsz
);
4863 if (dynamic_syminfo
== NULL
)
4865 error (_("Out of memory\n"));
4869 dynamic_syminfo_nent
= syminsz
/ sizeof (Elf_External_Syminfo
);
4870 for (i
= 0, syminfo
= dynamic_syminfo
; i
< dynamic_syminfo_nent
;
4873 syminfo
->si_boundto
= BYTE_GET (extsyminfo
[i
].si_boundto
);
4874 syminfo
->si_flags
= BYTE_GET (extsyminfo
[i
].si_flags
);
4881 if (do_dynamic
&& dynamic_addr
)
4882 printf (_("\nDynamic segment at offset 0x%lx contains %ld entries:\n"),
4883 dynamic_addr
, (long) dynamic_size
);
4885 printf (_(" Tag Type Name/Value\n"));
4887 for (i
= 0, entry
= dynamic_segment
;
4896 print_vma (entry
->d_tag
, FULL_HEX
);
4897 dtype
= get_dynamic_type (entry
->d_tag
);
4898 printf (" (%s)%*s", dtype
,
4899 ((is_32bit_elf
? 27 : 19)
4900 - (int) strlen (dtype
)),
4904 switch (entry
->d_tag
)
4908 puts (get_dynamic_flags (entry
->d_un
.d_val
));
4918 switch (entry
->d_tag
)
4921 printf (_("Auxiliary library"));
4925 printf (_("Filter library"));
4929 printf (_("Configuration file"));
4933 printf (_("Dependency audit library"));
4937 printf (_("Audit library"));
4941 if (dynamic_strings
)
4942 printf (": [%s]\n", dynamic_strings
+ entry
->d_un
.d_val
);
4946 print_vma (entry
->d_un
.d_val
, PREFIX_HEX
);
4955 printf (_("Flags:"));
4957 if (entry
->d_un
.d_val
== 0)
4958 printf (_(" None\n"));
4961 unsigned long int val
= entry
->d_un
.d_val
;
4963 if (val
& DTF_1_PARINIT
)
4965 printf (" PARINIT");
4966 val
^= DTF_1_PARINIT
;
4968 if (val
& DTF_1_CONFEXP
)
4970 printf (" CONFEXP");
4971 val
^= DTF_1_CONFEXP
;
4974 printf (" %lx", val
);
4983 printf (_("Flags:"));
4985 if (entry
->d_un
.d_val
== 0)
4986 printf (_(" None\n"));
4989 unsigned long int val
= entry
->d_un
.d_val
;
4991 if (val
& DF_P1_LAZYLOAD
)
4993 printf (" LAZYLOAD");
4994 val
^= DF_P1_LAZYLOAD
;
4996 if (val
& DF_P1_GROUPPERM
)
4998 printf (" GROUPPERM");
4999 val
^= DF_P1_GROUPPERM
;
5002 printf (" %lx", val
);
5011 printf (_("Flags:"));
5012 if (entry
->d_un
.d_val
== 0)
5013 printf (_(" None\n"));
5016 unsigned long int val
= entry
->d_un
.d_val
;
5023 if (val
& DF_1_GLOBAL
)
5028 if (val
& DF_1_GROUP
)
5033 if (val
& DF_1_NODELETE
)
5035 printf (" NODELETE");
5036 val
^= DF_1_NODELETE
;
5038 if (val
& DF_1_LOADFLTR
)
5040 printf (" LOADFLTR");
5041 val
^= DF_1_LOADFLTR
;
5043 if (val
& DF_1_INITFIRST
)
5045 printf (" INITFIRST");
5046 val
^= DF_1_INITFIRST
;
5048 if (val
& DF_1_NOOPEN
)
5053 if (val
& DF_1_ORIGIN
)
5058 if (val
& DF_1_DIRECT
)
5063 if (val
& DF_1_TRANS
)
5068 if (val
& DF_1_INTERPOSE
)
5070 printf (" INTERPOSE");
5071 val
^= DF_1_INTERPOSE
;
5073 if (val
& DF_1_NODEFLIB
)
5075 printf (" NODEFLIB");
5076 val
^= DF_1_NODEFLIB
;
5078 if (val
& DF_1_NODUMP
)
5083 if (val
& DF_1_CONLFAT
)
5085 printf (" CONLFAT");
5086 val
^= DF_1_CONLFAT
;
5089 printf (" %lx", val
);
5096 dynamic_info
[entry
->d_tag
] = entry
->d_un
.d_val
;
5098 puts (get_dynamic_type (entry
->d_un
.d_val
));
5118 dynamic_info
[entry
->d_tag
] = entry
->d_un
.d_val
;
5124 if (dynamic_strings
== NULL
)
5127 name
= dynamic_strings
+ entry
->d_un
.d_val
;
5131 switch (entry
->d_tag
)
5134 printf (_("Shared library: [%s]"), name
);
5136 if (strcmp (name
, program_interpreter
) == 0)
5137 printf (_(" program interpreter"));
5141 printf (_("Library soname: [%s]"), name
);
5145 printf (_("Library rpath: [%s]"), name
);
5149 printf (_("Library runpath: [%s]"), name
);
5153 print_vma (entry
->d_un
.d_val
, PREFIX_HEX
);
5158 print_vma (entry
->d_un
.d_val
, PREFIX_HEX
);
5171 dynamic_info
[entry
->d_tag
] = entry
->d_un
.d_val
;
5175 case DT_INIT_ARRAYSZ
:
5176 case DT_FINI_ARRAYSZ
:
5177 case DT_GNU_CONFLICTSZ
:
5178 case DT_GNU_LIBLISTSZ
:
5181 print_vma (entry
->d_un
.d_val
, UNSIGNED
);
5182 printf (" (bytes)\n");
5192 print_vma (entry
->d_un
.d_val
, UNSIGNED
);
5205 if (dynamic_strings
!= NULL
&& entry
->d_tag
== DT_USED
)
5209 name
= dynamic_strings
+ entry
->d_un
.d_val
;
5213 printf (_("Not needed object: [%s]\n"), name
);
5218 print_vma (entry
->d_un
.d_val
, PREFIX_HEX
);
5224 /* The value of this entry is ignored. */
5229 case DT_GNU_PRELINKED
:
5233 time_t time
= entry
->d_un
.d_val
;
5235 tmp
= gmtime (&time
);
5236 printf ("%04u-%02u-%02uT%02u:%02u:%02u\n",
5237 tmp
->tm_year
+ 1900, tmp
->tm_mon
+ 1, tmp
->tm_mday
,
5238 tmp
->tm_hour
, tmp
->tm_min
, tmp
->tm_sec
);
5244 if ((entry
->d_tag
>= DT_VERSYM
) && (entry
->d_tag
<= DT_VERNEEDNUM
))
5245 version_info
[DT_VERSIONTAGIDX (entry
->d_tag
)] =
5250 switch (elf_header
.e_machine
)
5253 case EM_MIPS_RS3_LE
:
5254 dynamic_segment_mips_val (entry
);
5257 dynamic_segment_parisc_val (entry
);
5260 dynamic_segment_ia64_val (entry
);
5263 print_vma (entry
->d_un
.d_val
, PREFIX_HEX
);
5275 get_ver_flags (flags
)
5278 static char buff
[32];
5285 if (flags
& VER_FLG_BASE
)
5286 strcat (buff
, "BASE ");
5288 if (flags
& VER_FLG_WEAK
)
5290 if (flags
& VER_FLG_BASE
)
5291 strcat (buff
, "| ");
5293 strcat (buff
, "WEAK ");
5296 if (flags
& ~(VER_FLG_BASE
| VER_FLG_WEAK
))
5297 strcat (buff
, "| <unknown>");
5302 /* Display the contents of the version sections. */
5304 process_version_sections (file
)
5307 Elf_Internal_Shdr
*section
;
5314 for (i
= 0, section
= section_headers
;
5315 i
< elf_header
.e_shnum
;
5318 switch (section
->sh_type
)
5320 case SHT_GNU_verdef
:
5322 Elf_External_Verdef
*edefs
;
5329 (_("\nVersion definition section '%s' contains %ld entries:\n"),
5330 SECTION_NAME (section
), section
->sh_info
);
5332 printf (_(" Addr: 0x"));
5333 printf_vma (section
->sh_addr
);
5334 printf (_(" Offset: %#08lx Link: %lx (%s)\n"),
5335 (unsigned long) section
->sh_offset
, section
->sh_link
,
5336 SECTION_NAME (SECTION_HEADER (section
->sh_link
)));
5338 edefs
= ((Elf_External_Verdef
*)
5339 get_data (NULL
, file
, section
->sh_offset
,
5341 _("version definition section")));
5345 for (idx
= cnt
= 0; cnt
< section
->sh_info
; ++cnt
)
5348 Elf_External_Verdef
*edef
;
5349 Elf_Internal_Verdef ent
;
5350 Elf_External_Verdaux
*eaux
;
5351 Elf_Internal_Verdaux aux
;
5355 vstart
= ((char *) edefs
) + idx
;
5357 edef
= (Elf_External_Verdef
*) vstart
;
5359 ent
.vd_version
= BYTE_GET (edef
->vd_version
);
5360 ent
.vd_flags
= BYTE_GET (edef
->vd_flags
);
5361 ent
.vd_ndx
= BYTE_GET (edef
->vd_ndx
);
5362 ent
.vd_cnt
= BYTE_GET (edef
->vd_cnt
);
5363 ent
.vd_hash
= BYTE_GET (edef
->vd_hash
);
5364 ent
.vd_aux
= BYTE_GET (edef
->vd_aux
);
5365 ent
.vd_next
= BYTE_GET (edef
->vd_next
);
5367 printf (_(" %#06x: Rev: %d Flags: %s"),
5368 idx
, ent
.vd_version
, get_ver_flags (ent
.vd_flags
));
5370 printf (_(" Index: %d Cnt: %d "),
5371 ent
.vd_ndx
, ent
.vd_cnt
);
5373 vstart
+= ent
.vd_aux
;
5375 eaux
= (Elf_External_Verdaux
*) vstart
;
5377 aux
.vda_name
= BYTE_GET (eaux
->vda_name
);
5378 aux
.vda_next
= BYTE_GET (eaux
->vda_next
);
5380 if (dynamic_strings
)
5381 printf (_("Name: %s\n"), dynamic_strings
+ aux
.vda_name
);
5383 printf (_("Name index: %ld\n"), aux
.vda_name
);
5385 isum
= idx
+ ent
.vd_aux
;
5387 for (j
= 1; j
< ent
.vd_cnt
; j
++)
5389 isum
+= aux
.vda_next
;
5390 vstart
+= aux
.vda_next
;
5392 eaux
= (Elf_External_Verdaux
*) vstart
;
5394 aux
.vda_name
= BYTE_GET (eaux
->vda_name
);
5395 aux
.vda_next
= BYTE_GET (eaux
->vda_next
);
5397 if (dynamic_strings
)
5398 printf (_(" %#06x: Parent %d: %s\n"),
5399 isum
, j
, dynamic_strings
+ aux
.vda_name
);
5401 printf (_(" %#06x: Parent %d, name index: %ld\n"),
5402 isum
, j
, aux
.vda_name
);
5412 case SHT_GNU_verneed
:
5414 Elf_External_Verneed
*eneed
;
5420 printf (_("\nVersion needs section '%s' contains %ld entries:\n"),
5421 SECTION_NAME (section
), section
->sh_info
);
5423 printf (_(" Addr: 0x"));
5424 printf_vma (section
->sh_addr
);
5425 printf (_(" Offset: %#08lx Link to section: %ld (%s)\n"),
5426 (unsigned long) section
->sh_offset
, section
->sh_link
,
5427 SECTION_NAME (SECTION_HEADER (section
->sh_link
)));
5429 eneed
= ((Elf_External_Verneed
*)
5430 get_data (NULL
, file
, section
->sh_offset
,
5431 section
->sh_size
, _("version need section")));
5435 for (idx
= cnt
= 0; cnt
< section
->sh_info
; ++cnt
)
5437 Elf_External_Verneed
*entry
;
5438 Elf_Internal_Verneed ent
;
5443 vstart
= ((char *) eneed
) + idx
;
5445 entry
= (Elf_External_Verneed
*) vstart
;
5447 ent
.vn_version
= BYTE_GET (entry
->vn_version
);
5448 ent
.vn_cnt
= BYTE_GET (entry
->vn_cnt
);
5449 ent
.vn_file
= BYTE_GET (entry
->vn_file
);
5450 ent
.vn_aux
= BYTE_GET (entry
->vn_aux
);
5451 ent
.vn_next
= BYTE_GET (entry
->vn_next
);
5453 printf (_(" %#06x: Version: %d"), idx
, ent
.vn_version
);
5455 if (dynamic_strings
)
5456 printf (_(" File: %s"), dynamic_strings
+ ent
.vn_file
);
5458 printf (_(" File: %lx"), ent
.vn_file
);
5460 printf (_(" Cnt: %d\n"), ent
.vn_cnt
);
5462 vstart
+= ent
.vn_aux
;
5464 for (j
= 0, isum
= idx
+ ent
.vn_aux
; j
< ent
.vn_cnt
; ++j
)
5466 Elf_External_Vernaux
*eaux
;
5467 Elf_Internal_Vernaux aux
;
5469 eaux
= (Elf_External_Vernaux
*) vstart
;
5471 aux
.vna_hash
= BYTE_GET (eaux
->vna_hash
);
5472 aux
.vna_flags
= BYTE_GET (eaux
->vna_flags
);
5473 aux
.vna_other
= BYTE_GET (eaux
->vna_other
);
5474 aux
.vna_name
= BYTE_GET (eaux
->vna_name
);
5475 aux
.vna_next
= BYTE_GET (eaux
->vna_next
);
5477 if (dynamic_strings
)
5478 printf (_(" %#06x: Name: %s"),
5479 isum
, dynamic_strings
+ aux
.vna_name
);
5481 printf (_(" %#06x: Name index: %lx"),
5482 isum
, aux
.vna_name
);
5484 printf (_(" Flags: %s Version: %d\n"),
5485 get_ver_flags (aux
.vna_flags
), aux
.vna_other
);
5487 isum
+= aux
.vna_next
;
5488 vstart
+= aux
.vna_next
;
5498 case SHT_GNU_versym
:
5500 Elf_Internal_Shdr
*link_section
;
5503 unsigned char *edata
;
5504 unsigned short *data
;
5506 Elf_Internal_Sym
*symbols
;
5507 Elf_Internal_Shdr
*string_sec
;
5509 link_section
= SECTION_HEADER (section
->sh_link
);
5510 total
= section
->sh_size
/ section
->sh_entsize
;
5514 symbols
= GET_ELF_SYMBOLS (file
, link_section
);
5516 string_sec
= SECTION_HEADER (link_section
->sh_link
);
5518 strtab
= (char *) get_data (NULL
, file
, string_sec
->sh_offset
,
5519 string_sec
->sh_size
,
5520 _("version string table"));
5524 printf (_("\nVersion symbols section '%s' contains %d entries:\n"),
5525 SECTION_NAME (section
), total
);
5527 printf (_(" Addr: "));
5528 printf_vma (section
->sh_addr
);
5529 printf (_(" Offset: %#08lx Link: %lx (%s)\n"),
5530 (unsigned long) section
->sh_offset
, section
->sh_link
,
5531 SECTION_NAME (link_section
));
5535 get_data (NULL
, file
,
5536 version_info
[DT_VERSIONTAGIDX (DT_VERSYM
)] - loadaddr
,
5537 total
* sizeof (short), _("version symbol data")));
5544 data
= (unsigned short *) malloc (total
* sizeof (short));
5546 for (cnt
= total
; cnt
--;)
5547 data
[cnt
] = byte_get (edata
+ cnt
* sizeof (short),
5552 for (cnt
= 0; cnt
< total
; cnt
+= 4)
5555 int check_def
, check_need
;
5558 printf (" %03x:", cnt
);
5560 for (j
= 0; (j
< 4) && (cnt
+ j
) < total
; ++j
)
5561 switch (data
[cnt
+ j
])
5564 fputs (_(" 0 (*local*) "), stdout
);
5568 fputs (_(" 1 (*global*) "), stdout
);
5572 nn
= printf ("%4x%c", data
[cnt
+ j
] & 0x7fff,
5573 data
[cnt
+ j
] & 0x8000 ? 'h' : ' ');
5577 if (SECTION_HEADER (symbols
[cnt
+ j
].st_shndx
)->sh_type
5580 if (symbols
[cnt
+ j
].st_shndx
== SHN_UNDEF
)
5587 && version_info
[DT_VERSIONTAGIDX (DT_VERNEED
)])
5589 Elf_Internal_Verneed ivn
;
5590 unsigned long offset
;
5592 offset
= version_info
[DT_VERSIONTAGIDX (DT_VERNEED
)]
5597 Elf_Internal_Vernaux ivna
;
5598 Elf_External_Verneed evn
;
5599 Elf_External_Vernaux evna
;
5600 unsigned long a_off
;
5602 get_data (&evn
, file
, offset
, sizeof (evn
),
5605 ivn
.vn_aux
= BYTE_GET (evn
.vn_aux
);
5606 ivn
.vn_next
= BYTE_GET (evn
.vn_next
);
5608 a_off
= offset
+ ivn
.vn_aux
;
5612 get_data (&evna
, file
, a_off
, sizeof (evna
),
5613 _("version need aux (2)"));
5615 ivna
.vna_next
= BYTE_GET (evna
.vna_next
);
5616 ivna
.vna_other
= BYTE_GET (evna
.vna_other
);
5618 a_off
+= ivna
.vna_next
;
5620 while (ivna
.vna_other
!= data
[cnt
+ j
]
5621 && ivna
.vna_next
!= 0);
5623 if (ivna
.vna_other
== data
[cnt
+ j
])
5625 ivna
.vna_name
= BYTE_GET (evna
.vna_name
);
5627 name
= strtab
+ ivna
.vna_name
;
5628 nn
+= printf ("(%s%-*s",
5630 12 - (int) strlen (name
),
5636 offset
+= ivn
.vn_next
;
5638 while (ivn
.vn_next
);
5641 if (check_def
&& data
[cnt
+ j
] != 0x8001
5642 && version_info
[DT_VERSIONTAGIDX (DT_VERDEF
)])
5644 Elf_Internal_Verdef ivd
;
5645 Elf_External_Verdef evd
;
5646 unsigned long offset
;
5648 offset
= (version_info
[DT_VERSIONTAGIDX (DT_VERDEF
)]
5653 get_data (&evd
, file
, offset
, sizeof (evd
),
5656 ivd
.vd_next
= BYTE_GET (evd
.vd_next
);
5657 ivd
.vd_ndx
= BYTE_GET (evd
.vd_ndx
);
5659 offset
+= ivd
.vd_next
;
5661 while (ivd
.vd_ndx
!= (data
[cnt
+ j
] & 0x7fff)
5662 && ivd
.vd_next
!= 0);
5664 if (ivd
.vd_ndx
== (data
[cnt
+ j
] & 0x7fff))
5666 Elf_External_Verdaux evda
;
5667 Elf_Internal_Verdaux ivda
;
5669 ivd
.vd_aux
= BYTE_GET (evd
.vd_aux
);
5671 get_data (&evda
, file
,
5672 offset
- ivd
.vd_next
+ ivd
.vd_aux
,
5673 sizeof (evda
), _("version def aux"));
5675 ivda
.vda_name
= BYTE_GET (evda
.vda_name
);
5677 name
= strtab
+ ivda
.vda_name
;
5678 nn
+= printf ("(%s%-*s",
5680 12 - (int) strlen (name
),
5686 printf ("%*c", 18 - nn
, ' ');
5704 printf (_("\nNo version information found in this file.\n"));
5710 get_symbol_binding (binding
)
5711 unsigned int binding
;
5713 static char buff
[32];
5717 case STB_LOCAL
: return "LOCAL";
5718 case STB_GLOBAL
: return "GLOBAL";
5719 case STB_WEAK
: return "WEAK";
5721 if (binding
>= STB_LOPROC
&& binding
<= STB_HIPROC
)
5722 sprintf (buff
, _("<processor specific>: %d"), binding
);
5723 else if (binding
>= STB_LOOS
&& binding
<= STB_HIOS
)
5724 sprintf (buff
, _("<OS specific>: %d"), binding
);
5726 sprintf (buff
, _("<unknown>: %d"), binding
);
5732 get_symbol_type (type
)
5735 static char buff
[32];
5739 case STT_NOTYPE
: return "NOTYPE";
5740 case STT_OBJECT
: return "OBJECT";
5741 case STT_FUNC
: return "FUNC";
5742 case STT_SECTION
: return "SECTION";
5743 case STT_FILE
: return "FILE";
5744 case STT_COMMON
: return "COMMON";
5745 case STT_TLS
: return "TLS";
5747 if (type
>= STT_LOPROC
&& type
<= STT_HIPROC
)
5749 if (elf_header
.e_machine
== EM_ARM
&& type
== STT_ARM_TFUNC
)
5750 return "THUMB_FUNC";
5752 if (elf_header
.e_machine
== EM_SPARCV9
&& type
== STT_REGISTER
)
5755 if (elf_header
.e_machine
== EM_PARISC
&& type
== STT_PARISC_MILLI
)
5756 return "PARISC_MILLI";
5758 sprintf (buff
, _("<processor specific>: %d"), type
);
5760 else if (type
>= STT_LOOS
&& type
<= STT_HIOS
)
5762 if (elf_header
.e_machine
== EM_PARISC
)
5764 if (type
== STT_HP_OPAQUE
)
5766 if (type
== STT_HP_STUB
)
5770 sprintf (buff
, _("<OS specific>: %d"), type
);
5773 sprintf (buff
, _("<unknown>: %d"), type
);
5779 get_symbol_visibility (visibility
)
5780 unsigned int visibility
;
5784 case STV_DEFAULT
: return "DEFAULT";
5785 case STV_INTERNAL
: return "INTERNAL";
5786 case STV_HIDDEN
: return "HIDDEN";
5787 case STV_PROTECTED
: return "PROTECTED";
5793 get_symbol_index_type (type
)
5796 static char buff
[32];
5800 case SHN_UNDEF
: return "UND";
5801 case SHN_ABS
: return "ABS";
5802 case SHN_COMMON
: return "COM";
5804 if (type
>= SHN_LOPROC
&& type
<= SHN_HIPROC
)
5805 sprintf (buff
, "PRC[0x%04x]", type
);
5806 else if (type
>= SHN_LOOS
&& type
<= SHN_HIOS
)
5807 sprintf (buff
, "OS [0x%04x]", type
);
5808 else if (type
>= SHN_LORESERVE
&& type
<= SHN_HIRESERVE
)
5809 sprintf (buff
, "RSV[0x%04x]", type
);
5811 sprintf (buff
, "%3d", type
);
5819 get_dynamic_data (file
, number
)
5821 unsigned int number
;
5823 unsigned char *e_data
;
5826 e_data
= (unsigned char *) malloc (number
* 4);
5830 error (_("Out of memory\n"));
5834 if (fread (e_data
, 4, number
, file
) != number
)
5836 error (_("Unable to read in dynamic data\n"));
5840 i_data
= (int *) malloc (number
* sizeof (*i_data
));
5844 error (_("Out of memory\n"));
5850 i_data
[number
] = byte_get (e_data
+ number
* 4, 4);
5857 /* Dump the symbol table. */
5859 process_symbol_table (file
)
5862 Elf_Internal_Shdr
*section
;
5863 unsigned char nb
[4];
5864 unsigned char nc
[4];
5867 int *buckets
= NULL
;
5870 if (! do_syms
&& !do_histogram
)
5873 if (dynamic_info
[DT_HASH
] && ((do_using_dynamic
&& dynamic_strings
!= NULL
)
5876 if (fseek (file
, dynamic_info
[DT_HASH
] - loadaddr
, SEEK_SET
))
5878 error (_("Unable to seek to start of dynamic information"));
5882 if (fread (nb
, sizeof (nb
), 1, file
) != 1)
5884 error (_("Failed to read in number of buckets\n"));
5888 if (fread (nc
, sizeof (nc
), 1, file
) != 1)
5890 error (_("Failed to read in number of chains\n"));
5894 nbuckets
= byte_get (nb
, 4);
5895 nchains
= byte_get (nc
, 4);
5897 buckets
= get_dynamic_data (file
, nbuckets
);
5898 chains
= get_dynamic_data (file
, nchains
);
5900 if (buckets
== NULL
|| chains
== NULL
)
5905 && dynamic_info
[DT_HASH
] && do_using_dynamic
&& dynamic_strings
!= NULL
)
5910 printf (_("\nSymbol table for image:\n"));
5912 printf (_(" Num Buc: Value Size Type Bind Vis Ndx Name\n"));
5914 printf (_(" Num Buc: Value Size Type Bind Vis Ndx Name\n"));
5916 for (hn
= 0; hn
< nbuckets
; hn
++)
5921 for (si
= buckets
[hn
]; si
< nchains
&& si
> 0; si
= chains
[si
])
5923 Elf_Internal_Sym
*psym
;
5925 psym
= dynamic_symbols
+ si
;
5927 printf (" %3d %3d: ", si
, hn
);
5928 print_vma (psym
->st_value
, LONG_HEX
);
5930 print_vma (psym
->st_size
, DEC_5
);
5932 printf (" %6s", get_symbol_type (ELF_ST_TYPE (psym
->st_info
)));
5933 printf (" %6s", get_symbol_binding (ELF_ST_BIND (psym
->st_info
)));
5934 printf (" %3s", get_symbol_visibility (ELF_ST_VISIBILITY (psym
->st_other
)));
5935 printf (" %3.3s ", get_symbol_index_type (psym
->st_shndx
));
5936 print_symbol (25, dynamic_strings
+ psym
->st_name
);
5941 else if (do_syms
&& !do_using_dynamic
)
5945 for (i
= 0, section
= section_headers
;
5946 i
< elf_header
.e_shnum
;
5951 Elf_Internal_Sym
*symtab
;
5952 Elf_Internal_Sym
*psym
;
5955 if ( section
->sh_type
!= SHT_SYMTAB
5956 && section
->sh_type
!= SHT_DYNSYM
)
5959 printf (_("\nSymbol table '%s' contains %lu entries:\n"),
5960 SECTION_NAME (section
),
5961 (unsigned long) (section
->sh_size
/ section
->sh_entsize
));
5963 printf (_(" Num: Value Size Type Bind Vis Ndx Name\n"));
5965 printf (_(" Num: Value Size Type Bind Vis Ndx Name\n"));
5967 symtab
= GET_ELF_SYMBOLS (file
, section
);
5971 if (section
->sh_link
== elf_header
.e_shstrndx
)
5972 strtab
= string_table
;
5975 Elf_Internal_Shdr
*string_sec
;
5977 string_sec
= SECTION_HEADER (section
->sh_link
);
5979 strtab
= (char *) get_data (NULL
, file
, string_sec
->sh_offset
,
5980 string_sec
->sh_size
,
5984 for (si
= 0, psym
= symtab
;
5985 si
< section
->sh_size
/ section
->sh_entsize
;
5988 printf ("%6d: ", si
);
5989 print_vma (psym
->st_value
, LONG_HEX
);
5991 print_vma (psym
->st_size
, DEC_5
);
5992 printf (" %-7s", get_symbol_type (ELF_ST_TYPE (psym
->st_info
)));
5993 printf (" %-6s", get_symbol_binding (ELF_ST_BIND (psym
->st_info
)));
5994 printf (" %-3s", get_symbol_visibility (ELF_ST_VISIBILITY (psym
->st_other
)));
5995 printf (" %4s ", get_symbol_index_type (psym
->st_shndx
));
5996 print_symbol (25, strtab
+ psym
->st_name
);
5998 if (section
->sh_type
== SHT_DYNSYM
&&
5999 version_info
[DT_VERSIONTAGIDX (DT_VERSYM
)] != 0)
6001 unsigned char data
[2];
6002 unsigned short vers_data
;
6003 unsigned long offset
;
6007 offset
= version_info
[DT_VERSIONTAGIDX (DT_VERSYM
)]
6010 get_data (&data
, file
, offset
+ si
* sizeof (vers_data
),
6011 sizeof (data
), _("version data"));
6013 vers_data
= byte_get (data
, 2);
6015 is_nobits
= (SECTION_HEADER (psym
->st_shndx
)->sh_type
6018 check_def
= (psym
->st_shndx
!= SHN_UNDEF
);
6020 if ((vers_data
& 0x8000) || vers_data
> 1)
6022 if (version_info
[DT_VERSIONTAGIDX (DT_VERNEED
)]
6023 && (is_nobits
|| ! check_def
))
6025 Elf_External_Verneed evn
;
6026 Elf_Internal_Verneed ivn
;
6027 Elf_Internal_Vernaux ivna
;
6029 /* We must test both. */
6030 offset
= (version_info
[DT_VERSIONTAGIDX (DT_VERNEED
)]
6035 unsigned long vna_off
;
6037 get_data (&evn
, file
, offset
, sizeof (evn
),
6040 ivn
.vn_aux
= BYTE_GET (evn
.vn_aux
);
6041 ivn
.vn_next
= BYTE_GET (evn
.vn_next
);
6043 vna_off
= offset
+ ivn
.vn_aux
;
6047 Elf_External_Vernaux evna
;
6049 get_data (&evna
, file
, vna_off
,
6051 _("version need aux (3)"));
6053 ivna
.vna_other
= BYTE_GET (evna
.vna_other
);
6054 ivna
.vna_next
= BYTE_GET (evna
.vna_next
);
6055 ivna
.vna_name
= BYTE_GET (evna
.vna_name
);
6057 vna_off
+= ivna
.vna_next
;
6059 while (ivna
.vna_other
!= vers_data
6060 && ivna
.vna_next
!= 0);
6062 if (ivna
.vna_other
== vers_data
)
6065 offset
+= ivn
.vn_next
;
6067 while (ivn
.vn_next
!= 0);
6069 if (ivna
.vna_other
== vers_data
)
6072 strtab
+ ivna
.vna_name
, ivna
.vna_other
);
6075 else if (! is_nobits
)
6076 error (_("bad dynamic symbol"));
6083 if (vers_data
!= 0x8001
6084 && version_info
[DT_VERSIONTAGIDX (DT_VERDEF
)])
6086 Elf_Internal_Verdef ivd
;
6087 Elf_Internal_Verdaux ivda
;
6088 Elf_External_Verdaux evda
;
6089 unsigned long offset
;
6092 = (version_info
[DT_VERSIONTAGIDX (DT_VERDEF
)]
6097 Elf_External_Verdef evd
;
6099 get_data (&evd
, file
, offset
, sizeof (evd
),
6102 ivd
.vd_ndx
= BYTE_GET (evd
.vd_ndx
);
6103 ivd
.vd_aux
= BYTE_GET (evd
.vd_aux
);
6104 ivd
.vd_next
= BYTE_GET (evd
.vd_next
);
6106 offset
+= ivd
.vd_next
;
6108 while (ivd
.vd_ndx
!= (vers_data
& 0x7fff)
6109 && ivd
.vd_next
!= 0);
6111 offset
-= ivd
.vd_next
;
6112 offset
+= ivd
.vd_aux
;
6114 get_data (&evda
, file
, offset
, sizeof (evda
),
6115 _("version def aux"));
6117 ivda
.vda_name
= BYTE_GET (evda
.vda_name
);
6119 if (psym
->st_name
!= ivda
.vda_name
)
6120 printf ((vers_data
& 0x8000)
6122 strtab
+ ivda
.vda_name
);
6132 if (strtab
!= string_table
)
6138 (_("\nDynamic symbol information is not available for displaying symbols.\n"));
6140 if (do_histogram
&& buckets
!= NULL
)
6147 int nzero_counts
= 0;
6150 printf (_("\nHistogram for bucket list length (total of %d buckets):\n"),
6152 printf (_(" Length Number %% of total Coverage\n"));
6154 lengths
= (int *) calloc (nbuckets
, sizeof (int));
6155 if (lengths
== NULL
)
6157 error (_("Out of memory"));
6160 for (hn
= 0; hn
< nbuckets
; ++hn
)
6165 for (si
= buckets
[hn
]; si
> 0 && si
< nchains
; si
= chains
[si
])
6168 if (maxlength
< ++lengths
[hn
])
6173 counts
= (int *) calloc (maxlength
+ 1, sizeof (int));
6176 error (_("Out of memory"));
6180 for (hn
= 0; hn
< nbuckets
; ++hn
)
6181 ++counts
[lengths
[hn
]];
6185 printf (" 0 %-10d (%5.1f%%)\n",
6186 counts
[0], (counts
[0] * 100.0) / nbuckets
);
6187 for (si
= 1; si
<= maxlength
; ++si
)
6189 nzero_counts
+= counts
[si
] * si
;
6190 printf ("%7d %-10d (%5.1f%%) %5.1f%%\n",
6191 si
, counts
[si
], (counts
[si
] * 100.0) / nbuckets
,
6192 (nzero_counts
* 100.0) / nsyms
);
6200 if (buckets
!= NULL
)
6210 process_syminfo (file
)
6211 FILE *file ATTRIBUTE_UNUSED
;
6215 if (dynamic_syminfo
== NULL
6217 /* No syminfo, this is ok. */
6220 /* There better should be a dynamic symbol section. */
6221 if (dynamic_symbols
== NULL
|| dynamic_strings
== NULL
)
6225 printf (_("\nDynamic info segment at offset 0x%lx contains %d entries:\n"),
6226 dynamic_syminfo_offset
, dynamic_syminfo_nent
);
6228 printf (_(" Num: Name BoundTo Flags\n"));
6229 for (i
= 0; i
< dynamic_syminfo_nent
; ++i
)
6231 unsigned short int flags
= dynamic_syminfo
[i
].si_flags
;
6233 printf ("%4d: ", i
);
6234 print_symbol (30, dynamic_strings
+ dynamic_symbols
[i
].st_name
);
6237 switch (dynamic_syminfo
[i
].si_boundto
)
6239 case SYMINFO_BT_SELF
:
6240 fputs ("SELF ", stdout
);
6242 case SYMINFO_BT_PARENT
:
6243 fputs ("PARENT ", stdout
);
6246 if (dynamic_syminfo
[i
].si_boundto
> 0
6247 && dynamic_syminfo
[i
].si_boundto
< dynamic_size
)
6252 [dynamic_syminfo
[i
].si_boundto
].d_un
.d_val
));
6256 printf ("%-10d ", dynamic_syminfo
[i
].si_boundto
);
6260 if (flags
& SYMINFO_FLG_DIRECT
)
6262 if (flags
& SYMINFO_FLG_PASSTHRU
)
6263 printf (" PASSTHRU");
6264 if (flags
& SYMINFO_FLG_COPY
)
6266 if (flags
& SYMINFO_FLG_LAZYLOAD
)
6267 printf (" LAZYLOAD");
6275 #ifdef SUPPORT_DISASSEMBLY
6277 disassemble_section (section
, file
)
6278 Elf_Internal_Shdr
*section
;
6281 printf (_("\nAssembly dump of section %s\n"),
6282 SECTION_NAME (section
));
6284 /* XXX -- to be done --- XXX */
6291 dump_section (section
, file
)
6292 Elf_Internal_Shdr
*section
;
6295 bfd_size_type bytes
;
6297 unsigned char *data
;
6298 unsigned char *start
;
6300 bytes
= section
->sh_size
;
6304 printf (_("\nSection '%s' has no data to dump.\n"),
6305 SECTION_NAME (section
));
6309 printf (_("\nHex dump of section '%s':\n"), SECTION_NAME (section
));
6311 addr
= section
->sh_addr
;
6313 start
= (unsigned char *) get_data (NULL
, file
, section
->sh_offset
, bytes
,
6326 lbytes
= (bytes
> 16 ? 16 : bytes
);
6328 printf (" 0x%8.8lx ", (unsigned long) addr
);
6330 switch (elf_header
.e_ident
[EI_DATA
])
6334 for (j
= 15; j
>= 0; j
--)
6337 printf ("%2.2x", data
[j
]);
6347 for (j
= 0; j
< 16; j
++)
6350 printf ("%2.2x", data
[j
]);
6360 for (j
= 0; j
< lbytes
; j
++)
6363 if (k
>= ' ' && k
< 0x80)
6382 static unsigned long int
6383 read_leb128 (data
, length_return
, sign
)
6384 unsigned char *data
;
6388 unsigned long int result
= 0;
6389 unsigned int num_read
= 0;
6398 result
|= (byte
& 0x7f) << shift
;
6403 while (byte
& 0x80);
6405 if (length_return
!= NULL
)
6406 *length_return
= num_read
;
6408 if (sign
&& (shift
< 32) && (byte
& 0x40))
6409 result
|= -1 << shift
;
6414 typedef struct State_Machine_Registers
6416 unsigned long address
;
6419 unsigned int column
;
6423 /* This variable hold the number of the last entry seen
6424 in the File Table. */
6425 unsigned int last_file_entry
;
6428 static SMR state_machine_regs
;
6431 reset_state_machine (is_stmt
)
6434 state_machine_regs
.address
= 0;
6435 state_machine_regs
.file
= 1;
6436 state_machine_regs
.line
= 1;
6437 state_machine_regs
.column
= 0;
6438 state_machine_regs
.is_stmt
= is_stmt
;
6439 state_machine_regs
.basic_block
= 0;
6440 state_machine_regs
.end_sequence
= 0;
6441 state_machine_regs
.last_file_entry
= 0;
6444 /* Handled an extend line op. Returns true if this is the end
6447 process_extended_line_op (data
, is_stmt
, pointer_size
)
6448 unsigned char *data
;
6452 unsigned char op_code
;
6455 unsigned char *name
;
6458 len
= read_leb128 (data
, & bytes_read
, 0);
6463 warn (_("badly formed extended line op encountered!\n"));
6470 printf (_(" Extended opcode %d: "), op_code
);
6474 case DW_LNE_end_sequence
:
6475 printf (_("End of Sequence\n\n"));
6476 reset_state_machine (is_stmt
);
6479 case DW_LNE_set_address
:
6480 adr
= byte_get (data
, pointer_size
);
6481 printf (_("set Address to 0x%lx\n"), adr
);
6482 state_machine_regs
.address
= adr
;
6485 case DW_LNE_define_file
:
6486 printf (_(" define new File Table entry\n"));
6487 printf (_(" Entry\tDir\tTime\tSize\tName\n"));
6489 printf (_(" %d\t"), ++state_machine_regs
.last_file_entry
);
6491 data
+= strlen ((char *) data
) + 1;
6492 printf (_("%lu\t"), read_leb128 (data
, & bytes_read
, 0));
6494 printf (_("%lu\t"), read_leb128 (data
, & bytes_read
, 0));
6496 printf (_("%lu\t"), read_leb128 (data
, & bytes_read
, 0));
6497 printf (_("%s\n\n"), name
);
6501 printf (_("UNKNOWN: length %d\n"), len
- bytes_read
);
6508 /* Size of pointers in the .debug_line section. This information is not
6509 really present in that section. It's obtained before dumping the debug
6510 sections by doing some pre-scan of the .debug_info section. */
6511 static int debug_line_pointer_size
= 4;
6514 display_debug_lines (section
, start
, file
)
6515 Elf_Internal_Shdr
*section
;
6516 unsigned char * start
;
6517 FILE *file ATTRIBUTE_UNUSED
;
6519 unsigned char *hdrptr
;
6520 DWARF2_Internal_LineInfo info
;
6521 unsigned char *standard_opcodes
;
6522 unsigned char *data
= start
;
6523 unsigned char *end
= start
+ section
->sh_size
;
6524 unsigned char *end_of_sequence
;
6527 int initial_length_size
;
6529 printf (_("\nDump of debug contents of section %s:\n\n"),
6530 SECTION_NAME (section
));
6536 /* Check the length of the block. */
6537 info
.li_length
= byte_get (hdrptr
, 4);
6540 if (info
.li_length
== 0xffffffff)
6542 /* This section is 64-bit DWARF 3. */
6543 info
.li_length
= byte_get (hdrptr
, 8);
6546 initial_length_size
= 12;
6551 initial_length_size
= 4;
6554 if (info
.li_length
+ initial_length_size
> section
->sh_size
)
6557 (_("The line info appears to be corrupt - the section is too small\n"));
6561 /* Check its version number. */
6562 info
.li_version
= byte_get (hdrptr
, 2);
6564 if (info
.li_version
!= 2 && info
.li_version
!= 3)
6566 warn (_("Only DWARF version 2 and 3 line info is currently supported.\n"));
6570 info
.li_prologue_length
= byte_get (hdrptr
, offset_size
);
6571 hdrptr
+= offset_size
;
6572 info
.li_min_insn_length
= byte_get (hdrptr
, 1);
6574 info
.li_default_is_stmt
= byte_get (hdrptr
, 1);
6576 info
.li_line_base
= byte_get (hdrptr
, 1);
6578 info
.li_line_range
= byte_get (hdrptr
, 1);
6580 info
.li_opcode_base
= byte_get (hdrptr
, 1);
6583 /* Sign extend the line base field. */
6584 info
.li_line_base
<<= 24;
6585 info
.li_line_base
>>= 24;
6587 printf (_(" Length: %ld\n"), info
.li_length
);
6588 printf (_(" DWARF Version: %d\n"), info
.li_version
);
6589 printf (_(" Prologue Length: %d\n"), info
.li_prologue_length
);
6590 printf (_(" Minimum Instruction Length: %d\n"), info
.li_min_insn_length
);
6591 printf (_(" Initial value of 'is_stmt': %d\n"), info
.li_default_is_stmt
);
6592 printf (_(" Line Base: %d\n"), info
.li_line_base
);
6593 printf (_(" Line Range: %d\n"), info
.li_line_range
);
6594 printf (_(" Opcode Base: %d\n"), info
.li_opcode_base
);
6596 end_of_sequence
= data
+ info
.li_length
+ initial_length_size
;
6598 reset_state_machine (info
.li_default_is_stmt
);
6600 /* Display the contents of the Opcodes table. */
6601 standard_opcodes
= hdrptr
;
6603 printf (_("\n Opcodes:\n"));
6605 for (i
= 1; i
< info
.li_opcode_base
; i
++)
6606 printf (_(" Opcode %d has %d args\n"), i
, standard_opcodes
[i
- 1]);
6608 /* Display the contents of the Directory table. */
6609 data
= standard_opcodes
+ info
.li_opcode_base
- 1;
6612 printf (_("\n The Directory Table is empty.\n"));
6615 printf (_("\n The Directory Table:\n"));
6619 printf (_(" %s\n"), data
);
6621 data
+= strlen ((char *) data
) + 1;
6625 /* Skip the NUL at the end of the table. */
6628 /* Display the contents of the File Name table. */
6630 printf (_("\n The File Name Table is empty.\n"));
6633 printf (_("\n The File Name Table:\n"));
6634 printf (_(" Entry\tDir\tTime\tSize\tName\n"));
6638 unsigned char *name
;
6641 printf (_(" %d\t"), ++state_machine_regs
.last_file_entry
);
6644 data
+= strlen ((char *) data
) + 1;
6646 printf (_("%lu\t"), read_leb128 (data
, & bytes_read
, 0));
6648 printf (_("%lu\t"), read_leb128 (data
, & bytes_read
, 0));
6650 printf (_("%lu\t"), read_leb128 (data
, & bytes_read
, 0));
6652 printf (_("%s\n"), name
);
6656 /* Skip the NUL at the end of the table. */
6659 /* Now display the statements. */
6660 printf (_("\n Line Number Statements:\n"));
6663 while (data
< end_of_sequence
)
6665 unsigned char op_code
;
6671 if (op_code
>= info
.li_opcode_base
)
6673 op_code
-= info
.li_opcode_base
;
6674 adv
= (op_code
/ info
.li_line_range
) * info
.li_min_insn_length
;
6675 state_machine_regs
.address
+= adv
;
6676 printf (_(" Special opcode %d: advance Address by %d to 0x%lx"),
6677 op_code
, adv
, state_machine_regs
.address
);
6678 adv
= (op_code
% info
.li_line_range
) + info
.li_line_base
;
6679 state_machine_regs
.line
+= adv
;
6680 printf (_(" and Line by %d to %d\n"),
6681 adv
, state_machine_regs
.line
);
6683 else switch (op_code
)
6685 case DW_LNS_extended_op
:
6686 data
+= process_extended_line_op (data
, info
.li_default_is_stmt
,
6687 debug_line_pointer_size
);
6691 printf (_(" Copy\n"));
6694 case DW_LNS_advance_pc
:
6695 adv
= info
.li_min_insn_length
* read_leb128 (data
, & bytes_read
, 0);
6697 state_machine_regs
.address
+= adv
;
6698 printf (_(" Advance PC by %d to %lx\n"), adv
,
6699 state_machine_regs
.address
);
6702 case DW_LNS_advance_line
:
6703 adv
= read_leb128 (data
, & bytes_read
, 1);
6705 state_machine_regs
.line
+= adv
;
6706 printf (_(" Advance Line by %d to %d\n"), adv
,
6707 state_machine_regs
.line
);
6710 case DW_LNS_set_file
:
6711 adv
= read_leb128 (data
, & bytes_read
, 0);
6713 printf (_(" Set File Name to entry %d in the File Name Table\n"),
6715 state_machine_regs
.file
= adv
;
6718 case DW_LNS_set_column
:
6719 adv
= read_leb128 (data
, & bytes_read
, 0);
6721 printf (_(" Set column to %d\n"), adv
);
6722 state_machine_regs
.column
= adv
;
6725 case DW_LNS_negate_stmt
:
6726 adv
= state_machine_regs
.is_stmt
;
6728 printf (_(" Set is_stmt to %d\n"), adv
);
6729 state_machine_regs
.is_stmt
= adv
;
6732 case DW_LNS_set_basic_block
:
6733 printf (_(" Set basic block\n"));
6734 state_machine_regs
.basic_block
= 1;
6737 case DW_LNS_const_add_pc
:
6738 adv
= (((255 - info
.li_opcode_base
) / info
.li_line_range
)
6739 * info
.li_min_insn_length
);
6740 state_machine_regs
.address
+= adv
;
6741 printf (_(" Advance PC by constant %d to 0x%lx\n"), adv
,
6742 state_machine_regs
.address
);
6745 case DW_LNS_fixed_advance_pc
:
6746 adv
= byte_get (data
, 2);
6748 state_machine_regs
.address
+= adv
;
6749 printf (_(" Advance PC by fixed size amount %d to 0x%lx\n"),
6750 adv
, state_machine_regs
.address
);
6753 case DW_LNS_set_prologue_end
:
6754 printf (_(" Set prologue_end to true\n"));
6757 case DW_LNS_set_epilogue_begin
:
6758 printf (_(" Set epilogue_begin to true\n"));
6761 case DW_LNS_set_isa
:
6762 adv
= read_leb128 (data
, & bytes_read
, 0);
6764 printf (_(" Set ISA to %d\n"), adv
);
6768 printf (_(" Unknown opcode %d with operands: "), op_code
);
6771 for (i
= standard_opcodes
[op_code
- 1]; i
> 0 ; --i
)
6773 printf ("0x%lx%s", read_leb128 (data
, &bytes_read
, 0),
6774 i
== 1 ? "" : ", ");
6789 display_debug_pubnames (section
, start
, file
)
6790 Elf_Internal_Shdr
*section
;
6791 unsigned char *start
;
6792 FILE *file ATTRIBUTE_UNUSED
;
6794 DWARF2_Internal_PubNames pubnames
;
6797 end
= start
+ section
->sh_size
;
6799 printf (_("Contents of the %s section:\n\n"), SECTION_NAME (section
));
6803 unsigned char *data
;
6804 unsigned long offset
;
6805 int offset_size
, initial_length_size
;
6809 pubnames
.pn_length
= byte_get (data
, 4);
6811 if (pubnames
.pn_length
== 0xffffffff)
6813 pubnames
.pn_length
= byte_get (data
, 8);
6816 initial_length_size
= 12;
6821 initial_length_size
= 4;
6824 pubnames
.pn_version
= byte_get (data
, 2);
6826 pubnames
.pn_offset
= byte_get (data
, offset_size
);
6827 data
+= offset_size
;
6828 pubnames
.pn_size
= byte_get (data
, offset_size
);
6829 data
+= offset_size
;
6831 start
+= pubnames
.pn_length
+ initial_length_size
;
6833 if (pubnames
.pn_version
!= 2 && pubnames
.pn_version
!= 3)
6835 static int warned
= 0;
6839 warn (_("Only DWARF 2 and 3 pubnames are currently supported\n"));
6846 printf (_(" Length: %ld\n"),
6847 pubnames
.pn_length
);
6848 printf (_(" Version: %d\n"),
6849 pubnames
.pn_version
);
6850 printf (_(" Offset into .debug_info section: %ld\n"),
6851 pubnames
.pn_offset
);
6852 printf (_(" Size of area in .debug_info section: %ld\n"),
6855 printf (_("\n Offset\tName\n"));
6859 offset
= byte_get (data
, offset_size
);
6863 data
+= offset_size
;
6864 printf (" %ld\t\t%s\n", offset
, data
);
6865 data
+= strlen ((char *) data
) + 1;
6868 while (offset
!= 0);
6881 case DW_TAG_padding
: return "DW_TAG_padding";
6882 case DW_TAG_array_type
: return "DW_TAG_array_type";
6883 case DW_TAG_class_type
: return "DW_TAG_class_type";
6884 case DW_TAG_entry_point
: return "DW_TAG_entry_point";
6885 case DW_TAG_enumeration_type
: return "DW_TAG_enumeration_type";
6886 case DW_TAG_formal_parameter
: return "DW_TAG_formal_parameter";
6887 case DW_TAG_imported_declaration
: return "DW_TAG_imported_declaration";
6888 case DW_TAG_label
: return "DW_TAG_label";
6889 case DW_TAG_lexical_block
: return "DW_TAG_lexical_block";
6890 case DW_TAG_member
: return "DW_TAG_member";
6891 case DW_TAG_pointer_type
: return "DW_TAG_pointer_type";
6892 case DW_TAG_reference_type
: return "DW_TAG_reference_type";
6893 case DW_TAG_compile_unit
: return "DW_TAG_compile_unit";
6894 case DW_TAG_string_type
: return "DW_TAG_string_type";
6895 case DW_TAG_structure_type
: return "DW_TAG_structure_type";
6896 case DW_TAG_subroutine_type
: return "DW_TAG_subroutine_type";
6897 case DW_TAG_typedef
: return "DW_TAG_typedef";
6898 case DW_TAG_union_type
: return "DW_TAG_union_type";
6899 case DW_TAG_unspecified_parameters
: return "DW_TAG_unspecified_parameters";
6900 case DW_TAG_variant
: return "DW_TAG_variant";
6901 case DW_TAG_common_block
: return "DW_TAG_common_block";
6902 case DW_TAG_common_inclusion
: return "DW_TAG_common_inclusion";
6903 case DW_TAG_inheritance
: return "DW_TAG_inheritance";
6904 case DW_TAG_inlined_subroutine
: return "DW_TAG_inlined_subroutine";
6905 case DW_TAG_module
: return "DW_TAG_module";
6906 case DW_TAG_ptr_to_member_type
: return "DW_TAG_ptr_to_member_type";
6907 case DW_TAG_set_type
: return "DW_TAG_set_type";
6908 case DW_TAG_subrange_type
: return "DW_TAG_subrange_type";
6909 case DW_TAG_with_stmt
: return "DW_TAG_with_stmt";
6910 case DW_TAG_access_declaration
: return "DW_TAG_access_declaration";
6911 case DW_TAG_base_type
: return "DW_TAG_base_type";
6912 case DW_TAG_catch_block
: return "DW_TAG_catch_block";
6913 case DW_TAG_const_type
: return "DW_TAG_const_type";
6914 case DW_TAG_constant
: return "DW_TAG_constant";
6915 case DW_TAG_enumerator
: return "DW_TAG_enumerator";
6916 case DW_TAG_file_type
: return "DW_TAG_file_type";
6917 case DW_TAG_friend
: return "DW_TAG_friend";
6918 case DW_TAG_namelist
: return "DW_TAG_namelist";
6919 case DW_TAG_namelist_item
: return "DW_TAG_namelist_item";
6920 case DW_TAG_packed_type
: return "DW_TAG_packed_type";
6921 case DW_TAG_subprogram
: return "DW_TAG_subprogram";
6922 case DW_TAG_template_type_param
: return "DW_TAG_template_type_param";
6923 case DW_TAG_template_value_param
: return "DW_TAG_template_value_param";
6924 case DW_TAG_thrown_type
: return "DW_TAG_thrown_type";
6925 case DW_TAG_try_block
: return "DW_TAG_try_block";
6926 case DW_TAG_variant_part
: return "DW_TAG_variant_part";
6927 case DW_TAG_variable
: return "DW_TAG_variable";
6928 case DW_TAG_volatile_type
: return "DW_TAG_volatile_type";
6929 case DW_TAG_MIPS_loop
: return "DW_TAG_MIPS_loop";
6930 case DW_TAG_format_label
: return "DW_TAG_format_label";
6931 case DW_TAG_function_template
: return "DW_TAG_function_template";
6932 case DW_TAG_class_template
: return "DW_TAG_class_template";
6933 /* DWARF 2.1 values. */
6934 case DW_TAG_dwarf_procedure
: return "DW_TAG_dwarf_procedure";
6935 case DW_TAG_restrict_type
: return "DW_TAG_restrict_type";
6936 case DW_TAG_interface_type
: return "DW_TAG_interface_type";
6937 case DW_TAG_namespace
: return "DW_TAG_namespace";
6938 case DW_TAG_imported_module
: return "DW_TAG_imported_module";
6939 case DW_TAG_unspecified_type
: return "DW_TAG_unspecified_type";
6940 case DW_TAG_partial_unit
: return "DW_TAG_partial_unit";
6941 case DW_TAG_imported_unit
: return "DW_TAG_imported_unit";
6943 case DW_TAG_upc_shared_type
: return "DW_TAG_upc_shared_type";
6944 case DW_TAG_upc_strict_type
: return "DW_TAG_upc_strict_type";
6945 case DW_TAG_upc_relaxed_type
: return "DW_TAG_upc_relaxed_type";
6948 static char buffer
[100];
6950 sprintf (buffer
, _("Unknown TAG value: %lx"), tag
);
6957 get_AT_name (attribute
)
6958 unsigned long attribute
;
6962 case DW_AT_sibling
: return "DW_AT_sibling";
6963 case DW_AT_location
: return "DW_AT_location";
6964 case DW_AT_name
: return "DW_AT_name";
6965 case DW_AT_ordering
: return "DW_AT_ordering";
6966 case DW_AT_subscr_data
: return "DW_AT_subscr_data";
6967 case DW_AT_byte_size
: return "DW_AT_byte_size";
6968 case DW_AT_bit_offset
: return "DW_AT_bit_offset";
6969 case DW_AT_bit_size
: return "DW_AT_bit_size";
6970 case DW_AT_element_list
: return "DW_AT_element_list";
6971 case DW_AT_stmt_list
: return "DW_AT_stmt_list";
6972 case DW_AT_low_pc
: return "DW_AT_low_pc";
6973 case DW_AT_high_pc
: return "DW_AT_high_pc";
6974 case DW_AT_language
: return "DW_AT_language";
6975 case DW_AT_member
: return "DW_AT_member";
6976 case DW_AT_discr
: return "DW_AT_discr";
6977 case DW_AT_discr_value
: return "DW_AT_discr_value";
6978 case DW_AT_visibility
: return "DW_AT_visibility";
6979 case DW_AT_import
: return "DW_AT_import";
6980 case DW_AT_string_length
: return "DW_AT_string_length";
6981 case DW_AT_common_reference
: return "DW_AT_common_reference";
6982 case DW_AT_comp_dir
: return "DW_AT_comp_dir";
6983 case DW_AT_const_value
: return "DW_AT_const_value";
6984 case DW_AT_containing_type
: return "DW_AT_containing_type";
6985 case DW_AT_default_value
: return "DW_AT_default_value";
6986 case DW_AT_inline
: return "DW_AT_inline";
6987 case DW_AT_is_optional
: return "DW_AT_is_optional";
6988 case DW_AT_lower_bound
: return "DW_AT_lower_bound";
6989 case DW_AT_producer
: return "DW_AT_producer";
6990 case DW_AT_prototyped
: return "DW_AT_prototyped";
6991 case DW_AT_return_addr
: return "DW_AT_return_addr";
6992 case DW_AT_start_scope
: return "DW_AT_start_scope";
6993 case DW_AT_stride_size
: return "DW_AT_stride_size";
6994 case DW_AT_upper_bound
: return "DW_AT_upper_bound";
6995 case DW_AT_abstract_origin
: return "DW_AT_abstract_origin";
6996 case DW_AT_accessibility
: return "DW_AT_accessibility";
6997 case DW_AT_address_class
: return "DW_AT_address_class";
6998 case DW_AT_artificial
: return "DW_AT_artificial";
6999 case DW_AT_base_types
: return "DW_AT_base_types";
7000 case DW_AT_calling_convention
: return "DW_AT_calling_convention";
7001 case DW_AT_count
: return "DW_AT_count";
7002 case DW_AT_data_member_location
: return "DW_AT_data_member_location";
7003 case DW_AT_decl_column
: return "DW_AT_decl_column";
7004 case DW_AT_decl_file
: return "DW_AT_decl_file";
7005 case DW_AT_decl_line
: return "DW_AT_decl_line";
7006 case DW_AT_declaration
: return "DW_AT_declaration";
7007 case DW_AT_discr_list
: return "DW_AT_discr_list";
7008 case DW_AT_encoding
: return "DW_AT_encoding";
7009 case DW_AT_external
: return "DW_AT_external";
7010 case DW_AT_frame_base
: return "DW_AT_frame_base";
7011 case DW_AT_friend
: return "DW_AT_friend";
7012 case DW_AT_identifier_case
: return "DW_AT_identifier_case";
7013 case DW_AT_macro_info
: return "DW_AT_macro_info";
7014 case DW_AT_namelist_items
: return "DW_AT_namelist_items";
7015 case DW_AT_priority
: return "DW_AT_priority";
7016 case DW_AT_segment
: return "DW_AT_segment";
7017 case DW_AT_specification
: return "DW_AT_specification";
7018 case DW_AT_static_link
: return "DW_AT_static_link";
7019 case DW_AT_type
: return "DW_AT_type";
7020 case DW_AT_use_location
: return "DW_AT_use_location";
7021 case DW_AT_variable_parameter
: return "DW_AT_variable_parameter";
7022 case DW_AT_virtuality
: return "DW_AT_virtuality";
7023 case DW_AT_vtable_elem_location
: return "DW_AT_vtable_elem_location";
7024 /* DWARF 2.1 values. */
7025 case DW_AT_allocated
: return "DW_AT_allocated";
7026 case DW_AT_associated
: return "DW_AT_associated";
7027 case DW_AT_data_location
: return "DW_AT_data_location";
7028 case DW_AT_stride
: return "DW_AT_stride";
7029 case DW_AT_entry_pc
: return "DW_AT_entry_pc";
7030 case DW_AT_use_UTF8
: return "DW_AT_use_UTF8";
7031 case DW_AT_extension
: return "DW_AT_extension";
7032 case DW_AT_ranges
: return "DW_AT_ranges";
7033 case DW_AT_trampoline
: return "DW_AT_trampoline";
7034 case DW_AT_call_column
: return "DW_AT_call_column";
7035 case DW_AT_call_file
: return "DW_AT_call_file";
7036 case DW_AT_call_line
: return "DW_AT_call_line";
7037 /* SGI/MIPS extensions. */
7038 case DW_AT_MIPS_fde
: return "DW_AT_MIPS_fde";
7039 case DW_AT_MIPS_loop_begin
: return "DW_AT_MIPS_loop_begin";
7040 case DW_AT_MIPS_tail_loop_begin
: return "DW_AT_MIPS_tail_loop_begin";
7041 case DW_AT_MIPS_epilog_begin
: return "DW_AT_MIPS_epilog_begin";
7042 case DW_AT_MIPS_loop_unroll_factor
: return "DW_AT_MIPS_loop_unroll_factor";
7043 case DW_AT_MIPS_software_pipeline_depth
:
7044 return "DW_AT_MIPS_software_pipeline_depth";
7045 case DW_AT_MIPS_linkage_name
: return "DW_AT_MIPS_linkage_name";
7046 case DW_AT_MIPS_stride
: return "DW_AT_MIPS_stride";
7047 case DW_AT_MIPS_abstract_name
: return "DW_AT_MIPS_abstract_name";
7048 case DW_AT_MIPS_clone_origin
: return "DW_AT_MIPS_clone_origin";
7049 case DW_AT_MIPS_has_inlines
: return "DW_AT_MIPS_has_inlines";
7050 /* GNU extensions. */
7051 case DW_AT_sf_names
: return "DW_AT_sf_names";
7052 case DW_AT_src_info
: return "DW_AT_src_info";
7053 case DW_AT_mac_info
: return "DW_AT_mac_info";
7054 case DW_AT_src_coords
: return "DW_AT_src_coords";
7055 case DW_AT_body_begin
: return "DW_AT_body_begin";
7056 case DW_AT_body_end
: return "DW_AT_body_end";
7057 case DW_AT_GNU_vector
: return "DW_AT_GNU_vector";
7058 /* UPC extension. */
7059 case DW_AT_upc_threads_scaled
: return "DW_AT_upc_threads_scaled";
7062 static char buffer
[100];
7064 sprintf (buffer
, _("Unknown AT value: %lx"), attribute
);
7071 get_FORM_name (form
)
7076 case DW_FORM_addr
: return "DW_FORM_addr";
7077 case DW_FORM_block2
: return "DW_FORM_block2";
7078 case DW_FORM_block4
: return "DW_FORM_block4";
7079 case DW_FORM_data2
: return "DW_FORM_data2";
7080 case DW_FORM_data4
: return "DW_FORM_data4";
7081 case DW_FORM_data8
: return "DW_FORM_data8";
7082 case DW_FORM_string
: return "DW_FORM_string";
7083 case DW_FORM_block
: return "DW_FORM_block";
7084 case DW_FORM_block1
: return "DW_FORM_block1";
7085 case DW_FORM_data1
: return "DW_FORM_data1";
7086 case DW_FORM_flag
: return "DW_FORM_flag";
7087 case DW_FORM_sdata
: return "DW_FORM_sdata";
7088 case DW_FORM_strp
: return "DW_FORM_strp";
7089 case DW_FORM_udata
: return "DW_FORM_udata";
7090 case DW_FORM_ref_addr
: return "DW_FORM_ref_addr";
7091 case DW_FORM_ref1
: return "DW_FORM_ref1";
7092 case DW_FORM_ref2
: return "DW_FORM_ref2";
7093 case DW_FORM_ref4
: return "DW_FORM_ref4";
7094 case DW_FORM_ref8
: return "DW_FORM_ref8";
7095 case DW_FORM_ref_udata
: return "DW_FORM_ref_udata";
7096 case DW_FORM_indirect
: return "DW_FORM_indirect";
7099 static char buffer
[100];
7101 sprintf (buffer
, _("Unknown FORM value: %lx"), form
);
7107 /* FIXME: There are better and more effiecint ways to handle
7108 these structures. For now though, I just want something that
7109 is simple to implement. */
7110 typedef struct abbrev_attr
7112 unsigned long attribute
;
7114 struct abbrev_attr
*next
;
7118 typedef struct abbrev_entry
7120 unsigned long entry
;
7123 struct abbrev_attr
*first_attr
;
7124 struct abbrev_attr
*last_attr
;
7125 struct abbrev_entry
*next
;
7129 static abbrev_entry
*first_abbrev
= NULL
;
7130 static abbrev_entry
*last_abbrev
= NULL
;
7135 abbrev_entry
*abbrev
;
7137 for (abbrev
= first_abbrev
; abbrev
;)
7139 abbrev_entry
*next
= abbrev
->next
;
7142 for (attr
= abbrev
->first_attr
; attr
;)
7144 abbrev_attr
*next
= attr
->next
;
7154 last_abbrev
= first_abbrev
= NULL
;
7158 add_abbrev (number
, tag
, children
)
7159 unsigned long number
;
7163 abbrev_entry
*entry
;
7165 entry
= (abbrev_entry
*) malloc (sizeof (*entry
));
7171 entry
->entry
= number
;
7173 entry
->children
= children
;
7174 entry
->first_attr
= NULL
;
7175 entry
->last_attr
= NULL
;
7178 if (first_abbrev
== NULL
)
7179 first_abbrev
= entry
;
7181 last_abbrev
->next
= entry
;
7183 last_abbrev
= entry
;
7187 add_abbrev_attr (attribute
, form
)
7188 unsigned long attribute
;
7193 attr
= (abbrev_attr
*) malloc (sizeof (*attr
));
7199 attr
->attribute
= attribute
;
7203 if (last_abbrev
->first_attr
== NULL
)
7204 last_abbrev
->first_attr
= attr
;
7206 last_abbrev
->last_attr
->next
= attr
;
7208 last_abbrev
->last_attr
= attr
;
7211 /* Processes the (partial) contents of a .debug_abbrev section.
7212 Returns NULL if the end of the section was encountered.
7213 Returns the address after the last byte read if the end of
7214 an abbreviation set was found. */
7216 static unsigned char *
7217 process_abbrev_section (start
, end
)
7218 unsigned char *start
;
7221 if (first_abbrev
!= NULL
)
7227 unsigned long entry
;
7229 unsigned long attribute
;
7232 entry
= read_leb128 (start
, & bytes_read
, 0);
7233 start
+= bytes_read
;
7235 /* A single zero is supposed to end the section according
7236 to the standard. If there's more, then signal that to
7239 return start
== end
? NULL
: start
;
7241 tag
= read_leb128 (start
, & bytes_read
, 0);
7242 start
+= bytes_read
;
7244 children
= *start
++;
7246 add_abbrev (entry
, tag
, children
);
7252 attribute
= read_leb128 (start
, & bytes_read
, 0);
7253 start
+= bytes_read
;
7255 form
= read_leb128 (start
, & bytes_read
, 0);
7256 start
+= bytes_read
;
7259 add_abbrev_attr (attribute
, form
);
7261 while (attribute
!= 0);
7269 display_debug_macinfo (section
, start
, file
)
7270 Elf_Internal_Shdr
*section
;
7271 unsigned char *start
;
7272 FILE *file ATTRIBUTE_UNUSED
;
7274 unsigned char *end
= start
+ section
->sh_size
;
7275 unsigned char *curr
= start
;
7276 unsigned int bytes_read
;
7277 enum dwarf_macinfo_record_type op
;
7279 printf (_("Contents of the %s section:\n\n"), SECTION_NAME (section
));
7283 unsigned int lineno
;
7291 case DW_MACINFO_start_file
:
7293 unsigned int filenum
;
7295 lineno
= read_leb128 (curr
, & bytes_read
, 0);
7297 filenum
= read_leb128 (curr
, & bytes_read
, 0);
7300 printf (_(" DW_MACINFO_start_file - lineno: %d filenum: %d\n"), lineno
, filenum
);
7304 case DW_MACINFO_end_file
:
7305 printf (_(" DW_MACINFO_end_file\n"));
7308 case DW_MACINFO_define
:
7309 lineno
= read_leb128 (curr
, & bytes_read
, 0);
7312 curr
+= strlen (string
) + 1;
7313 printf (_(" DW_MACINFO_define - lineno : %d macro : %s\n"), lineno
, string
);
7316 case DW_MACINFO_undef
:
7317 lineno
= read_leb128 (curr
, & bytes_read
, 0);
7320 curr
+= strlen (string
) + 1;
7321 printf (_(" DW_MACINFO_undef - lineno : %d macro : %s\n"), lineno
, string
);
7324 case DW_MACINFO_vendor_ext
:
7326 unsigned int constant
;
7328 constant
= read_leb128 (curr
, & bytes_read
, 0);
7331 curr
+= strlen (string
) + 1;
7332 printf (_(" DW_MACINFO_vendor_ext - constant : %d string : %s\n"), constant
, string
);
7343 display_debug_abbrev (section
, start
, file
)
7344 Elf_Internal_Shdr
*section
;
7345 unsigned char *start
;
7346 FILE *file ATTRIBUTE_UNUSED
;
7348 abbrev_entry
*entry
;
7349 unsigned char *end
= start
+ section
->sh_size
;
7351 printf (_("Contents of the %s section:\n\n"), SECTION_NAME (section
));
7355 start
= process_abbrev_section (start
, end
);
7357 if (first_abbrev
== NULL
)
7360 printf (_(" Number TAG\n"));
7362 for (entry
= first_abbrev
; entry
; entry
= entry
->next
)
7366 printf (_(" %ld %s [%s]\n"),
7368 get_TAG_name (entry
->tag
),
7369 entry
->children
? _("has children") : _("no children"));
7371 for (attr
= entry
->first_attr
; attr
; attr
= attr
->next
)
7373 printf (_(" %-18s %s\n"),
7374 get_AT_name (attr
->attribute
),
7375 get_FORM_name (attr
->form
));
7389 static unsigned char *
7390 display_block (data
, length
)
7391 unsigned char *data
;
7392 unsigned long length
;
7394 printf (_(" %lu byte block: "), length
);
7397 printf ("%lx ", (unsigned long) byte_get (data
++, 1));
7403 decode_location_expression (data
, pointer_size
, length
)
7404 unsigned char * data
;
7405 unsigned int pointer_size
;
7406 unsigned long length
;
7410 unsigned long uvalue
;
7411 unsigned char *end
= data
+ length
;
7420 printf ("DW_OP_addr: %lx",
7421 (unsigned long) byte_get (data
, pointer_size
));
7422 data
+= pointer_size
;
7425 printf ("DW_OP_deref");
7428 printf ("DW_OP_const1u: %lu", (unsigned long) byte_get (data
++, 1));
7431 printf ("DW_OP_const1s: %ld", (long) byte_get (data
++, 1));
7434 printf ("DW_OP_const2u: %lu", (unsigned long) byte_get (data
, 2));
7438 printf ("DW_OP_const2s: %ld", (long) byte_get (data
, 2));
7442 printf ("DW_OP_const4u: %lu", (unsigned long) byte_get (data
, 4));
7446 printf ("DW_OP_const4s: %ld", (long) byte_get (data
, 4));
7450 printf ("DW_OP_const8u: %lu %lu", (unsigned long) byte_get (data
, 4),
7451 (unsigned long) byte_get (data
+ 4, 4));
7455 printf ("DW_OP_const8s: %ld %ld", (long) byte_get (data
, 4),
7456 (long) byte_get (data
+ 4, 4));
7460 printf ("DW_OP_constu: %lu", read_leb128 (data
, &bytes_read
, 0));
7464 printf ("DW_OP_consts: %ld", read_leb128 (data
, &bytes_read
, 1));
7468 printf ("DW_OP_dup");
7471 printf ("DW_OP_drop");
7474 printf ("DW_OP_over");
7477 printf ("DW_OP_pick: %ld", (unsigned long) byte_get (data
++, 1));
7480 printf ("DW_OP_swap");
7483 printf ("DW_OP_rot");
7486 printf ("DW_OP_xderef");
7489 printf ("DW_OP_abs");
7492 printf ("DW_OP_and");
7495 printf ("DW_OP_div");
7498 printf ("DW_OP_minus");
7501 printf ("DW_OP_mod");
7504 printf ("DW_OP_mul");
7507 printf ("DW_OP_neg");
7510 printf ("DW_OP_not");
7513 printf ("DW_OP_or");
7516 printf ("DW_OP_plus");
7518 case DW_OP_plus_uconst
:
7519 printf ("DW_OP_plus_uconst: %lu",
7520 read_leb128 (data
, &bytes_read
, 0));
7524 printf ("DW_OP_shl");
7527 printf ("DW_OP_shr");
7530 printf ("DW_OP_shra");
7533 printf ("DW_OP_xor");
7536 printf ("DW_OP_bra: %ld", (long) byte_get (data
, 2));
7540 printf ("DW_OP_eq");
7543 printf ("DW_OP_ge");
7546 printf ("DW_OP_gt");
7549 printf ("DW_OP_le");
7552 printf ("DW_OP_lt");
7555 printf ("DW_OP_ne");
7558 printf ("DW_OP_skip: %ld", (long) byte_get (data
, 2));
7594 printf ("DW_OP_lit%d", op
- DW_OP_lit0
);
7629 printf ("DW_OP_reg%d", op
- DW_OP_reg0
);
7664 printf ("DW_OP_breg%d: %ld", op
- DW_OP_breg0
,
7665 read_leb128 (data
, &bytes_read
, 1));
7670 printf ("DW_OP_regx: %lu", read_leb128 (data
, &bytes_read
, 0));
7674 printf ("DW_OP_fbreg: %ld", read_leb128 (data
, &bytes_read
, 1));
7678 uvalue
= read_leb128 (data
, &bytes_read
, 0);
7680 printf ("DW_OP_bregx: %lu %ld", uvalue
,
7681 read_leb128 (data
, &bytes_read
, 1));
7685 printf ("DW_OP_piece: %lu", read_leb128 (data
, &bytes_read
, 0));
7688 case DW_OP_deref_size
:
7689 printf ("DW_OP_deref_size: %ld", (long) byte_get (data
++, 1));
7691 case DW_OP_xderef_size
:
7692 printf ("DW_OP_xderef_size: %ld", (long) byte_get (data
++, 1));
7695 printf ("DW_OP_nop");
7698 /* DWARF 3 extensions. */
7699 case DW_OP_push_object_address
:
7700 printf ("DW_OP_push_object_address");
7703 printf ("DW_OP_call2: <%lx>", (long) byte_get (data
, 2));
7707 printf ("DW_OP_call4: <%lx>", (long) byte_get (data
, 4));
7710 case DW_OP_call_ref
:
7711 printf ("DW_OP_call_ref");
7714 /* GNU extensions. */
7715 case DW_OP_GNU_push_tls_address
:
7716 printf ("DW_OP_GNU_push_tls_address");
7720 if (op
>= DW_OP_lo_user
7721 && op
<= DW_OP_hi_user
)
7722 printf (_("(User defined location op)"));
7724 printf (_("(Unknown location op)"));
7725 /* No way to tell where the next op is, so just bail. */
7729 /* Separate the ops. */
7735 static const char *debug_loc_contents
;
7736 static bfd_vma debug_loc_size
;
7739 load_debug_loc (file
)
7742 Elf_Internal_Shdr
*sec
;
7745 /* If it is already loaded, do nothing. */
7746 if (debug_loc_contents
!= NULL
)
7749 /* Locate the .debug_loc section. */
7750 for (i
= 0, sec
= section_headers
;
7751 i
< elf_header
.e_shnum
;
7753 if (strcmp (SECTION_NAME (sec
), ".debug_loc") == 0)
7756 if (i
== elf_header
.e_shnum
|| sec
->sh_size
== 0)
7759 debug_loc_size
= sec
->sh_size
;
7761 debug_loc_contents
= ((char *)
7762 get_data (NULL
, file
, sec
->sh_offset
, sec
->sh_size
,
7763 _("debug_loc section data")));
7769 if (debug_loc_contents
== NULL
)
7772 free ((char *) debug_loc_contents
);
7773 debug_loc_contents
= NULL
;
7779 display_debug_loc (section
, start
, file
)
7780 Elf_Internal_Shdr
*section
;
7781 unsigned char *start
;
7782 FILE *file ATTRIBUTE_UNUSED
;
7784 unsigned char *section_end
;
7785 unsigned long bytes
;
7786 unsigned char *section_begin
= start
;
7789 addr
= section
->sh_addr
;
7790 bytes
= section
->sh_size
;
7791 section_end
= start
+ bytes
;
7795 printf (_("\nThe .debug_loc section is empty.\n"));
7799 printf (_("Contents of the .debug_loc section:\n\n"));
7800 printf (_("\n Offset Begin End Expression\n"));
7802 while (start
< section_end
)
7804 unsigned long begin
;
7806 unsigned short length
;
7807 unsigned long offset
;
7809 offset
= start
- section_begin
;
7813 /* Normally, the lists in the debug_loc section are related to a
7814 given compilation unit, and thus, we would use the pointer size
7815 of that compilation unit. However, since we are displaying it
7816 seperately here, we either have to store pointer sizes of all
7817 compilation units, or assume they don't change. We assume,
7818 like the debug_line display, that it doesn't change. */
7819 begin
= byte_get (start
, debug_line_pointer_size
);
7820 start
+= debug_line_pointer_size
;
7821 end
= byte_get (start
, debug_line_pointer_size
);
7822 start
+= debug_line_pointer_size
;
7824 if (begin
== 0 && end
== 0)
7827 /* For now, skip any base address specifiers. */
7828 if (begin
== 0xffffffff)
7834 length
= byte_get (start
, 2);
7837 printf (" %8.8lx %8.8lx %8.8lx (", offset
, begin
, end
);
7838 decode_location_expression (start
, debug_line_pointer_size
, length
);
7848 static const char *debug_str_contents
;
7849 static bfd_vma debug_str_size
;
7852 load_debug_str (file
)
7855 Elf_Internal_Shdr
*sec
;
7858 /* If it is already loaded, do nothing. */
7859 if (debug_str_contents
!= NULL
)
7862 /* Locate the .debug_str section. */
7863 for (i
= 0, sec
= section_headers
;
7864 i
< elf_header
.e_shnum
;
7866 if (strcmp (SECTION_NAME (sec
), ".debug_str") == 0)
7869 if (i
== elf_header
.e_shnum
|| sec
->sh_size
== 0)
7872 debug_str_size
= sec
->sh_size
;
7874 debug_str_contents
= ((char *)
7875 get_data (NULL
, file
, sec
->sh_offset
, sec
->sh_size
,
7876 _("debug_str section data")));
7882 if (debug_str_contents
== NULL
)
7885 free ((char *) debug_str_contents
);
7886 debug_str_contents
= NULL
;
7891 fetch_indirect_string (offset
)
7892 unsigned long offset
;
7894 if (debug_str_contents
== NULL
)
7895 return _("<no .debug_str section>");
7897 if (offset
> debug_str_size
)
7898 return _("<offset is too big>");
7900 return debug_str_contents
+ offset
;
7904 display_debug_str (section
, start
, file
)
7905 Elf_Internal_Shdr
*section
;
7906 unsigned char *start
;
7907 FILE *file ATTRIBUTE_UNUSED
;
7909 unsigned long bytes
;
7912 addr
= section
->sh_addr
;
7913 bytes
= section
->sh_size
;
7917 printf (_("\nThe .debug_str section is empty.\n"));
7921 printf (_("Contents of the .debug_str section:\n\n"));
7929 lbytes
= (bytes
> 16 ? 16 : bytes
);
7931 printf (" 0x%8.8lx ", (unsigned long) addr
);
7933 for (j
= 0; j
< 16; j
++)
7936 printf ("%2.2x", start
[j
]);
7944 for (j
= 0; j
< lbytes
; j
++)
7947 if (k
>= ' ' && k
< 0x80)
7963 static unsigned char *
7964 read_and_display_attr_value (attribute
, form
, data
, cu_offset
, pointer_size
,
7965 offset_size
, dwarf_version
)
7966 unsigned long attribute
;
7968 unsigned char *data
;
7969 unsigned long cu_offset
;
7970 unsigned long pointer_size
;
7971 unsigned long offset_size
;
7974 unsigned long uvalue
= 0;
7975 unsigned char *block_start
= NULL
;
7983 case DW_FORM_ref_addr
:
7984 if (dwarf_version
== 2)
7986 uvalue
= byte_get (data
, pointer_size
);
7987 data
+= pointer_size
;
7989 else if (dwarf_version
== 3)
7991 uvalue
= byte_get (data
, offset_size
);
7992 data
+= offset_size
;
7996 error (_("Internal error: DWARF version is not 2 or 3.\n"));
8001 uvalue
= byte_get (data
, pointer_size
);
8002 data
+= pointer_size
;
8006 uvalue
= byte_get (data
, offset_size
);
8007 data
+= offset_size
;
8013 uvalue
= byte_get (data
++, 1);
8018 uvalue
= byte_get (data
, 2);
8024 uvalue
= byte_get (data
, 4);
8029 uvalue
= read_leb128 (data
, & bytes_read
, 1);
8033 case DW_FORM_ref_udata
:
8035 uvalue
= read_leb128 (data
, & bytes_read
, 0);
8039 case DW_FORM_indirect
:
8040 form
= read_leb128 (data
, & bytes_read
, 0);
8042 printf (" %s", get_FORM_name (form
));
8043 return read_and_display_attr_value (attribute
, form
, data
, cu_offset
,
8044 pointer_size
, offset_size
,
8050 case DW_FORM_ref_addr
:
8051 printf (" <#%lx>", uvalue
);
8057 case DW_FORM_ref_udata
:
8058 printf (" <%lx>", uvalue
+ cu_offset
);
8062 printf (" %#lx", uvalue
);
8070 printf (" %ld", uvalue
);
8075 uvalue
= byte_get (data
, 4);
8076 printf (" %lx", uvalue
);
8077 printf (" %lx", (unsigned long) byte_get (data
+ 4, 4));
8081 case DW_FORM_string
:
8082 printf (" %s", data
);
8083 data
+= strlen ((char *) data
) + 1;
8087 uvalue
= read_leb128 (data
, & bytes_read
, 0);
8088 block_start
= data
+ bytes_read
;
8089 data
= display_block (block_start
, uvalue
);
8092 case DW_FORM_block1
:
8093 uvalue
= byte_get (data
, 1);
8094 block_start
= data
+ 1;
8095 data
= display_block (block_start
, uvalue
);
8098 case DW_FORM_block2
:
8099 uvalue
= byte_get (data
, 2);
8100 block_start
= data
+ 2;
8101 data
= display_block (block_start
, uvalue
);
8104 case DW_FORM_block4
:
8105 uvalue
= byte_get (data
, 4);
8106 block_start
= data
+ 4;
8107 data
= display_block (block_start
, uvalue
);
8111 printf (_(" (indirect string, offset: 0x%lx): %s"),
8112 uvalue
, fetch_indirect_string (uvalue
));
8115 case DW_FORM_indirect
:
8116 /* Handled above. */
8120 warn (_("Unrecognized form: %d\n"), form
);
8124 /* For some attributes we can display futher information. */
8133 case DW_INL_not_inlined
:
8134 printf (_("(not inlined)"));
8136 case DW_INL_inlined
:
8137 printf (_("(inlined)"));
8139 case DW_INL_declared_not_inlined
:
8140 printf (_("(declared as inline but ignored)"));
8142 case DW_INL_declared_inlined
:
8143 printf (_("(declared as inline and inlined)"));
8146 printf (_(" (Unknown inline attribute value: %lx)"), uvalue
);
8151 case DW_AT_language
:
8154 case DW_LANG_C
: printf ("(non-ANSI C)"); break;
8155 case DW_LANG_C89
: printf ("(ANSI C)"); break;
8156 case DW_LANG_C_plus_plus
: printf ("(C++)"); break;
8157 case DW_LANG_Fortran77
: printf ("(FORTRAN 77)"); break;
8158 case DW_LANG_Fortran90
: printf ("(Fortran 90)"); break;
8159 case DW_LANG_Modula2
: printf ("(Modula 2)"); break;
8160 case DW_LANG_Pascal83
: printf ("(ANSI Pascal)"); break;
8161 case DW_LANG_Ada83
: printf ("(Ada)"); break;
8162 case DW_LANG_Cobol74
: printf ("(Cobol 74)"); break;
8163 case DW_LANG_Cobol85
: printf ("(Cobol 85)"); break;
8164 /* DWARF 2.1 values. */
8165 case DW_LANG_C99
: printf ("(ANSI C99)"); break;
8166 case DW_LANG_Ada95
: printf ("(ADA 95)"); break;
8167 case DW_LANG_Fortran95
: printf ("(Fortran 95)"); break;
8168 /* MIPS extension. */
8169 case DW_LANG_Mips_Assembler
: printf ("(MIPS assembler)"); break;
8170 /* UPC extension. */
8171 case DW_LANG_Upc
: printf ("(Unified Parallel C)"); break;
8173 printf ("(Unknown: %lx)", uvalue
);
8178 case DW_AT_encoding
:
8181 case DW_ATE_void
: printf ("(void)"); break;
8182 case DW_ATE_address
: printf ("(machine address)"); break;
8183 case DW_ATE_boolean
: printf ("(boolean)"); break;
8184 case DW_ATE_complex_float
: printf ("(complex float)"); break;
8185 case DW_ATE_float
: printf ("(float)"); break;
8186 case DW_ATE_signed
: printf ("(signed)"); break;
8187 case DW_ATE_signed_char
: printf ("(signed char)"); break;
8188 case DW_ATE_unsigned
: printf ("(unsigned)"); break;
8189 case DW_ATE_unsigned_char
: printf ("(unsigned char)"); break;
8190 /* DWARF 2.1 value. */
8191 case DW_ATE_imaginary_float
: printf ("(imaginary float)"); break;
8193 if (uvalue
>= DW_ATE_lo_user
8194 && uvalue
<= DW_ATE_hi_user
)
8195 printf ("(user defined type)");
8197 printf ("(unknown type)");
8202 case DW_AT_accessibility
:
8205 case DW_ACCESS_public
: printf ("(public)"); break;
8206 case DW_ACCESS_protected
: printf ("(protected)"); break;
8207 case DW_ACCESS_private
: printf ("(private)"); break;
8209 printf ("(unknown accessibility)");
8214 case DW_AT_visibility
:
8217 case DW_VIS_local
: printf ("(local)"); break;
8218 case DW_VIS_exported
: printf ("(exported)"); break;
8219 case DW_VIS_qualified
: printf ("(qualified)"); break;
8220 default: printf ("(unknown visibility)"); break;
8224 case DW_AT_virtuality
:
8227 case DW_VIRTUALITY_none
: printf ("(none)"); break;
8228 case DW_VIRTUALITY_virtual
: printf ("(virtual)"); break;
8229 case DW_VIRTUALITY_pure_virtual
:printf ("(pure_virtual)"); break;
8230 default: printf ("(unknown virtuality)"); break;
8234 case DW_AT_identifier_case
:
8237 case DW_ID_case_sensitive
: printf ("(case_sensitive)"); break;
8238 case DW_ID_up_case
: printf ("(up_case)"); break;
8239 case DW_ID_down_case
: printf ("(down_case)"); break;
8240 case DW_ID_case_insensitive
: printf ("(case_insensitive)"); break;
8241 default: printf ("(unknown case)"); break;
8245 case DW_AT_calling_convention
:
8248 case DW_CC_normal
: printf ("(normal)"); break;
8249 case DW_CC_program
: printf ("(program)"); break;
8250 case DW_CC_nocall
: printf ("(nocall)"); break;
8252 if (uvalue
>= DW_CC_lo_user
8253 && uvalue
<= DW_CC_hi_user
)
8254 printf ("(user defined)");
8256 printf ("(unknown convention)");
8260 case DW_AT_ordering
:
8263 case -1: printf ("(undefined)"); break;
8264 case 0: printf ("(row major)"); break;
8265 case 1: printf ("(column major)"); break;
8269 case DW_AT_frame_base
:
8270 case DW_AT_location
:
8271 case DW_AT_data_member_location
:
8272 case DW_AT_vtable_elem_location
:
8273 case DW_AT_allocated
:
8274 case DW_AT_associated
:
8275 case DW_AT_data_location
:
8277 case DW_AT_upper_bound
:
8278 case DW_AT_lower_bound
:
8282 decode_location_expression (block_start
, pointer_size
, uvalue
);
8285 else if (form
== DW_FORM_data4
|| form
== DW_FORM_data8
)
8288 printf ("location list");
8300 static unsigned char *
8301 read_and_display_attr (attribute
, form
, data
, cu_offset
, pointer_size
,
8302 offset_size
, dwarf_version
)
8303 unsigned long attribute
;
8305 unsigned char *data
;
8306 unsigned long cu_offset
;
8307 unsigned long pointer_size
;
8308 unsigned long offset_size
;
8311 printf (" %-18s:", get_AT_name (attribute
));
8312 data
= read_and_display_attr_value (attribute
, form
, data
, cu_offset
,
8313 pointer_size
, offset_size
, dwarf_version
);
8319 display_debug_info (section
, start
, file
)
8320 Elf_Internal_Shdr
*section
;
8321 unsigned char *start
;
8324 unsigned char *end
= start
+ section
->sh_size
;
8325 unsigned char *section_begin
= start
;
8327 printf (_("The section %s contains:\n\n"), SECTION_NAME (section
));
8329 load_debug_str (file
);
8330 load_debug_loc (file
);
8334 DWARF2_Internal_CompUnit compunit
;
8335 Elf_Internal_Shdr
*relsec
;
8336 unsigned char *hdrptr
;
8337 unsigned char *cu_abbrev_offset_ptr
;
8338 unsigned char *tags
;
8341 unsigned long cu_offset
;
8343 int initial_length_size
;
8347 compunit
.cu_length
= byte_get (hdrptr
, 4);
8350 if (compunit
.cu_length
== 0xffffffff)
8352 compunit
.cu_length
= byte_get (hdrptr
, 8);
8355 initial_length_size
= 12;
8360 initial_length_size
= 4;
8363 compunit
.cu_version
= byte_get (hdrptr
, 2);
8366 /* Apply addends of RELA relocations. */
8367 for (relsec
= section_headers
;
8368 relsec
< section_headers
+ elf_header
.e_shnum
;
8371 unsigned long nrelas
;
8372 Elf_Internal_Rela
*rela
, *rp
;
8373 Elf_Internal_Shdr
*symsec
;
8374 Elf_Internal_Sym
*symtab
;
8375 Elf_Internal_Sym
*sym
;
8377 if (relsec
->sh_type
!= SHT_RELA
8378 || SECTION_HEADER (relsec
->sh_info
) != section
8379 || relsec
->sh_size
== 0)
8382 if (!slurp_rela_relocs (file
, relsec
->sh_offset
, relsec
->sh_size
,
8386 symsec
= SECTION_HEADER (relsec
->sh_link
);
8387 symtab
= GET_ELF_SYMBOLS (file
, symsec
);
8389 for (rp
= rela
; rp
< rela
+ nrelas
; ++rp
)
8393 if (rp
->r_offset
>= (bfd_vma
) (hdrptr
- section_begin
)
8394 && section
->sh_size
> (bfd_vma
) offset_size
8395 && rp
->r_offset
<= section
->sh_size
- offset_size
)
8396 loc
= section_begin
+ rp
->r_offset
;
8402 sym
= symtab
+ ELF32_R_SYM (rp
->r_info
);
8404 if (ELF32_R_SYM (rp
->r_info
) != 0
8405 && ELF32_ST_TYPE (sym
->st_info
) != STT_SECTION
)
8407 warn (_("Skipping unexpected symbol type %u\n"),
8408 ELF32_ST_TYPE (sym
->st_info
));
8414 sym
= symtab
+ ELF64_R_SYM (rp
->r_info
);
8416 if (ELF64_R_SYM (rp
->r_info
) != 0
8417 && ELF64_ST_TYPE (sym
->st_info
) != STT_SECTION
)
8419 warn (_("Skipping unexpected symbol type %u\n"),
8420 ELF64_ST_TYPE (sym
->st_info
));
8425 byte_put (loc
, rp
->r_addend
, offset_size
);
8432 cu_abbrev_offset_ptr
= hdrptr
;
8433 compunit
.cu_abbrev_offset
= byte_get (hdrptr
, offset_size
);
8434 hdrptr
+= offset_size
;
8436 compunit
.cu_pointer_size
= byte_get (hdrptr
, 1);
8440 cu_offset
= start
- section_begin
;
8441 start
+= compunit
.cu_length
+ initial_length_size
;
8443 printf (_(" Compilation Unit @ %lx:\n"), cu_offset
);
8444 printf (_(" Length: %ld\n"), compunit
.cu_length
);
8445 printf (_(" Version: %d\n"), compunit
.cu_version
);
8446 printf (_(" Abbrev Offset: %ld\n"), compunit
.cu_abbrev_offset
);
8447 printf (_(" Pointer Size: %d\n"), compunit
.cu_pointer_size
);
8449 if (compunit
.cu_version
!= 2 && compunit
.cu_version
!= 3)
8451 warn (_("Only version 2 and 3 DWARF debug information is currently supported.\n"));
8457 /* Read in the abbrevs used by this compilation unit. */
8459 Elf_Internal_Shdr
*sec
;
8460 unsigned char *begin
;
8462 /* Locate the .debug_abbrev section and process it. */
8463 for (i
= 0, sec
= section_headers
;
8464 i
< elf_header
.e_shnum
;
8466 if (strcmp (SECTION_NAME (sec
), ".debug_abbrev") == 0)
8469 if (i
== elf_header
.e_shnum
|| sec
->sh_size
== 0)
8471 warn (_("Unable to locate .debug_abbrev section!\n"));
8475 begin
= ((unsigned char *)
8476 get_data (NULL
, file
, sec
->sh_offset
, sec
->sh_size
,
8477 _("debug_abbrev section data")));
8481 process_abbrev_section (begin
+ compunit
.cu_abbrev_offset
,
8482 begin
+ sec
->sh_size
);
8488 while (tags
< start
)
8491 unsigned long abbrev_number
;
8492 abbrev_entry
*entry
;
8495 abbrev_number
= read_leb128 (tags
, & bytes_read
, 0);
8498 /* A null DIE marks the end of a list of children. */
8499 if (abbrev_number
== 0)
8505 /* Scan through the abbreviation list until we reach the
8507 for (entry
= first_abbrev
;
8508 entry
&& entry
->entry
!= abbrev_number
;
8509 entry
= entry
->next
)
8514 warn (_("Unable to locate entry %lu in the abbreviation table\n"),
8519 printf (_(" <%d><%lx>: Abbrev Number: %lu (%s)\n"),
8521 (unsigned long) (tags
- section_begin
- bytes_read
),
8523 get_TAG_name (entry
->tag
));
8525 for (attr
= entry
->first_attr
; attr
; attr
= attr
->next
)
8526 tags
= read_and_display_attr (attr
->attribute
,
8529 compunit
.cu_pointer_size
,
8531 compunit
.cu_version
);
8533 if (entry
->children
)
8547 display_debug_aranges (section
, start
, file
)
8548 Elf_Internal_Shdr
*section
;
8549 unsigned char *start
;
8550 FILE *file ATTRIBUTE_UNUSED
;
8552 unsigned char *end
= start
+ section
->sh_size
;
8554 printf (_("The section %s contains:\n\n"), SECTION_NAME (section
));
8558 unsigned char *hdrptr
;
8559 DWARF2_Internal_ARange arange
;
8560 unsigned char *ranges
;
8561 unsigned long length
;
8562 unsigned long address
;
8565 int initial_length_size
;
8569 arange
.ar_length
= byte_get (hdrptr
, 4);
8572 if (arange
.ar_length
== 0xffffffff)
8574 arange
.ar_length
= byte_get (hdrptr
, 8);
8577 initial_length_size
= 12;
8582 initial_length_size
= 4;
8585 arange
.ar_version
= byte_get (hdrptr
, 2);
8588 arange
.ar_info_offset
= byte_get (hdrptr
, offset_size
);
8589 hdrptr
+= offset_size
;
8591 arange
.ar_pointer_size
= byte_get (hdrptr
, 1);
8594 arange
.ar_segment_size
= byte_get (hdrptr
, 1);
8597 if (arange
.ar_version
!= 2 && arange
.ar_version
!= 3)
8599 warn (_("Only DWARF 2 and 3 aranges are currently supported.\n"));
8603 printf (_(" Length: %ld\n"), arange
.ar_length
);
8604 printf (_(" Version: %d\n"), arange
.ar_version
);
8605 printf (_(" Offset into .debug_info: %lx\n"), arange
.ar_info_offset
);
8606 printf (_(" Pointer Size: %d\n"), arange
.ar_pointer_size
);
8607 printf (_(" Segment Size: %d\n"), arange
.ar_segment_size
);
8609 printf (_("\n Address Length\n"));
8613 /* Must pad to an alignment boundary that is twice the pointer size. */
8614 excess
= (hdrptr
- start
) % (2 * arange
.ar_pointer_size
);
8616 ranges
+= (2 * arange
.ar_pointer_size
) - excess
;
8620 address
= byte_get (ranges
, arange
.ar_pointer_size
);
8622 ranges
+= arange
.ar_pointer_size
;
8624 length
= byte_get (ranges
, arange
.ar_pointer_size
);
8626 ranges
+= arange
.ar_pointer_size
;
8628 /* A pair of zeros marks the end of the list. */
8629 if (address
== 0 && length
== 0)
8632 printf (" %8.8lx %lu\n", address
, length
);
8635 start
+= arange
.ar_length
+ initial_length_size
;
8643 typedef struct Frame_Chunk
8645 struct Frame_Chunk
*next
;
8646 unsigned char *chunk_start
;
8648 /* DW_CFA_{undefined,same_value,offset,register,unreferenced} */
8649 short int *col_type
;
8652 unsigned int code_factor
;
8654 unsigned long pc_begin
;
8655 unsigned long pc_range
;
8659 unsigned char fde_encoding
;
8660 unsigned char cfa_exp
;
8664 /* A marker for a col_type that means this column was never referenced
8665 in the frame info. */
8666 #define DW_CFA_unreferenced (-1)
8668 static void frame_need_space
PARAMS ((Frame_Chunk
*, int));
8669 static void frame_display_row
PARAMS ((Frame_Chunk
*, int *, int *));
8670 static int size_of_encoded_value
PARAMS ((int));
8673 frame_need_space (fc
, reg
)
8677 int prev
= fc
->ncols
;
8679 if (reg
< fc
->ncols
)
8682 fc
->ncols
= reg
+ 1;
8683 fc
->col_type
= (short int *) xrealloc (fc
->col_type
,
8684 fc
->ncols
* sizeof (short int));
8685 fc
->col_offset
= (int *) xrealloc (fc
->col_offset
,
8686 fc
->ncols
* sizeof (int));
8688 while (prev
< fc
->ncols
)
8690 fc
->col_type
[prev
] = DW_CFA_unreferenced
;
8691 fc
->col_offset
[prev
] = 0;
8697 frame_display_row (fc
, need_col_headers
, max_regs
)
8699 int *need_col_headers
;
8705 if (*max_regs
< fc
->ncols
)
8706 *max_regs
= fc
->ncols
;
8708 if (*need_col_headers
)
8710 *need_col_headers
= 0;
8712 printf (" LOC CFA ");
8714 for (r
= 0; r
< *max_regs
; r
++)
8715 if (fc
->col_type
[r
] != DW_CFA_unreferenced
)
8720 printf ("r%-4d", r
);
8726 printf ("%08lx ", fc
->pc_begin
);
8728 strcpy (tmp
, "exp");
8730 sprintf (tmp
, "r%d%+d", fc
->cfa_reg
, fc
->cfa_offset
);
8731 printf ("%-8s ", tmp
);
8733 for (r
= 0; r
< fc
->ncols
; r
++)
8735 if (fc
->col_type
[r
] != DW_CFA_unreferenced
)
8737 switch (fc
->col_type
[r
])
8739 case DW_CFA_undefined
:
8742 case DW_CFA_same_value
:
8746 sprintf (tmp
, "c%+d", fc
->col_offset
[r
]);
8748 case DW_CFA_register
:
8749 sprintf (tmp
, "r%d", fc
->col_offset
[r
]);
8751 case DW_CFA_expression
:
8752 strcpy (tmp
, "exp");
8755 strcpy (tmp
, "n/a");
8758 printf ("%-5s", tmp
);
8765 size_of_encoded_value (encoding
)
8768 switch (encoding
& 0x7)
8771 case 0: return is_32bit_elf
? 4 : 8;
8778 #define GET(N) byte_get (start, N); start += N
8779 #define LEB() read_leb128 (start, & length_return, 0); start += length_return
8780 #define SLEB() read_leb128 (start, & length_return, 1); start += length_return
8783 display_debug_frames (section
, start
, file
)
8784 Elf_Internal_Shdr
*section
;
8785 unsigned char *start
;
8786 FILE *file ATTRIBUTE_UNUSED
;
8788 unsigned char *end
= start
+ section
->sh_size
;
8789 unsigned char *section_start
= start
;
8790 Frame_Chunk
*chunks
= 0;
8791 Frame_Chunk
*remembered_state
= 0;
8793 int is_eh
= (strcmp (SECTION_NAME (section
), ".eh_frame") == 0);
8796 int addr_size
= is_32bit_elf
? 4 : 8;
8798 printf (_("The section %s contains:\n"), SECTION_NAME (section
));
8802 unsigned char *saved_start
;
8803 unsigned char *block_end
;
8804 unsigned long length
;
8805 unsigned long cie_id
;
8808 int need_col_headers
= 1;
8809 unsigned char *augmentation_data
= NULL
;
8810 unsigned long augmentation_data_len
= 0;
8811 int encoded_ptr_size
= addr_size
;
8813 int initial_length_size
;
8815 saved_start
= start
;
8816 length
= byte_get (start
, 4); start
+= 4;
8820 printf ("\n%08lx ZERO terminator\n\n",
8821 (unsigned long)(saved_start
- section_start
));
8825 if (length
== 0xffffffff)
8827 length
= byte_get (start
, 8);
8830 initial_length_size
= 12;
8835 initial_length_size
= 4;
8838 block_end
= saved_start
+ length
+ initial_length_size
;
8839 cie_id
= byte_get (start
, offset_size
); start
+= offset_size
;
8841 if (is_eh
? (cie_id
== 0) : (cie_id
== DW_CIE_ID
))
8845 fc
= (Frame_Chunk
*) xmalloc (sizeof (Frame_Chunk
));
8846 memset (fc
, 0, sizeof (Frame_Chunk
));
8850 fc
->chunk_start
= saved_start
;
8852 fc
->col_type
= (short int *) xmalloc (sizeof (short int));
8853 fc
->col_offset
= (int *) xmalloc (sizeof (int));
8854 frame_need_space (fc
, max_regs
-1);
8858 fc
->augmentation
= start
;
8859 start
= strchr (start
, '\0') + 1;
8861 if (fc
->augmentation
[0] == 'z')
8863 fc
->code_factor
= LEB ();
8864 fc
->data_factor
= SLEB ();
8865 fc
->ra
= byte_get (start
, 1); start
+= 1;
8866 augmentation_data_len
= LEB ();
8867 augmentation_data
= start
;
8868 start
+= augmentation_data_len
;
8870 else if (strcmp (fc
->augmentation
, "eh") == 0)
8873 fc
->code_factor
= LEB ();
8874 fc
->data_factor
= SLEB ();
8875 fc
->ra
= byte_get (start
, 1); start
+= 1;
8879 fc
->code_factor
= LEB ();
8880 fc
->data_factor
= SLEB ();
8881 fc
->ra
= byte_get (start
, 1); start
+= 1;
8885 if (do_debug_frames_interp
)
8886 printf ("\n%08lx %08lx %08lx CIE \"%s\" cf=%d df=%d ra=%d\n",
8887 (unsigned long)(saved_start
- section_start
), length
, cie_id
,
8888 fc
->augmentation
, fc
->code_factor
, fc
->data_factor
,
8892 printf ("\n%08lx %08lx %08lx CIE\n",
8893 (unsigned long)(saved_start
- section_start
), length
, cie_id
);
8894 printf (" Version: %d\n", version
);
8895 printf (" Augmentation: \"%s\"\n", fc
->augmentation
);
8896 printf (" Code alignment factor: %u\n", fc
->code_factor
);
8897 printf (" Data alignment factor: %d\n", fc
->data_factor
);
8898 printf (" Return address column: %d\n", fc
->ra
);
8900 if (augmentation_data_len
)
8903 printf (" Augmentation data: ");
8904 for (i
= 0; i
< augmentation_data_len
; ++i
)
8905 printf (" %02x", augmentation_data
[i
]);
8911 if (augmentation_data_len
)
8913 unsigned char *p
, *q
;
8914 p
= fc
->augmentation
+ 1;
8915 q
= augmentation_data
;
8922 q
+= 1 + size_of_encoded_value (*q
);
8924 fc
->fde_encoding
= *q
++;
8930 if (fc
->fde_encoding
)
8931 encoded_ptr_size
= size_of_encoded_value (fc
->fde_encoding
);
8934 frame_need_space (fc
, fc
->ra
);
8938 unsigned char *look_for
;
8939 static Frame_Chunk fde_fc
;
8942 memset (fc
, 0, sizeof (Frame_Chunk
));
8944 look_for
= is_eh
? start
- 4 - cie_id
: section_start
+ cie_id
;
8946 for (cie
= chunks
; cie
; cie
= cie
->next
)
8947 if (cie
->chunk_start
== look_for
)
8952 warn ("Invalid CIE pointer %08lx in FDE at %08lx\n",
8953 cie_id
, saved_start
);
8956 fc
->col_type
= (short int *) xmalloc (sizeof (short int));
8957 fc
->col_offset
= (int *) xmalloc (sizeof (int));
8958 frame_need_space (fc
, max_regs
- 1);
8960 fc
->augmentation
= "";
8961 fc
->fde_encoding
= 0;
8965 fc
->ncols
= cie
->ncols
;
8966 fc
->col_type
= (short int *) xmalloc (fc
->ncols
* sizeof (short int));
8967 fc
->col_offset
= (int *) xmalloc (fc
->ncols
* sizeof (int));
8968 memcpy (fc
->col_type
, cie
->col_type
, fc
->ncols
* sizeof (short int));
8969 memcpy (fc
->col_offset
, cie
->col_offset
, fc
->ncols
* sizeof (int));
8970 fc
->augmentation
= cie
->augmentation
;
8971 fc
->code_factor
= cie
->code_factor
;
8972 fc
->data_factor
= cie
->data_factor
;
8973 fc
->cfa_reg
= cie
->cfa_reg
;
8974 fc
->cfa_offset
= cie
->cfa_offset
;
8976 frame_need_space (fc
, max_regs
-1);
8977 fc
->fde_encoding
= cie
->fde_encoding
;
8980 if (fc
->fde_encoding
)
8981 encoded_ptr_size
= size_of_encoded_value (fc
->fde_encoding
);
8983 fc
->pc_begin
= byte_get (start
, encoded_ptr_size
);
8984 if ((fc
->fde_encoding
& 0x70) == DW_EH_PE_pcrel
)
8985 fc
->pc_begin
+= section
->sh_addr
+ (start
- section_start
);
8986 start
+= encoded_ptr_size
;
8987 fc
->pc_range
= byte_get (start
, encoded_ptr_size
);
8988 start
+= encoded_ptr_size
;
8990 if (cie
->augmentation
[0] == 'z')
8992 augmentation_data_len
= LEB ();
8993 augmentation_data
= start
;
8994 start
+= augmentation_data_len
;
8997 printf ("\n%08lx %08lx %08lx FDE cie=%08lx pc=%08lx..%08lx\n",
8998 (unsigned long)(saved_start
- section_start
), length
, cie_id
,
8999 (unsigned long)(cie
->chunk_start
- section_start
),
9000 fc
->pc_begin
, fc
->pc_begin
+ fc
->pc_range
);
9001 if (! do_debug_frames_interp
&& augmentation_data_len
)
9004 printf (" Augmentation data: ");
9005 for (i
= 0; i
< augmentation_data_len
; ++i
)
9006 printf (" %02x", augmentation_data
[i
]);
9012 /* At this point, fc is the current chunk, cie (if any) is set, and we're
9013 about to interpret instructions for the chunk. */
9015 if (do_debug_frames_interp
)
9017 /* Start by making a pass over the chunk, allocating storage
9018 and taking note of what registers are used. */
9019 unsigned char *tmp
= start
;
9021 while (start
< block_end
)
9024 unsigned long reg
, tmp
;
9031 /* Warning: if you add any more cases to this switch, be
9032 sure to add them to the corresponding switch below. */
9035 case DW_CFA_advance_loc
:
9039 frame_need_space (fc
, opa
);
9040 fc
->col_type
[opa
] = DW_CFA_undefined
;
9042 case DW_CFA_restore
:
9043 frame_need_space (fc
, opa
);
9044 fc
->col_type
[opa
] = DW_CFA_undefined
;
9046 case DW_CFA_set_loc
:
9047 start
+= encoded_ptr_size
;
9049 case DW_CFA_advance_loc1
:
9052 case DW_CFA_advance_loc2
:
9055 case DW_CFA_advance_loc4
:
9058 case DW_CFA_offset_extended
:
9059 reg
= LEB (); LEB ();
9060 frame_need_space (fc
, reg
);
9061 fc
->col_type
[reg
] = DW_CFA_undefined
;
9063 case DW_CFA_restore_extended
:
9065 frame_need_space (fc
, reg
);
9066 fc
->col_type
[reg
] = DW_CFA_undefined
;
9068 case DW_CFA_undefined
:
9070 frame_need_space (fc
, reg
);
9071 fc
->col_type
[reg
] = DW_CFA_undefined
;
9073 case DW_CFA_same_value
:
9075 frame_need_space (fc
, reg
);
9076 fc
->col_type
[reg
] = DW_CFA_undefined
;
9078 case DW_CFA_register
:
9079 reg
= LEB (); LEB ();
9080 frame_need_space (fc
, reg
);
9081 fc
->col_type
[reg
] = DW_CFA_undefined
;
9083 case DW_CFA_def_cfa
:
9086 case DW_CFA_def_cfa_register
:
9089 case DW_CFA_def_cfa_offset
:
9092 case DW_CFA_def_cfa_expression
:
9096 case DW_CFA_expression
:
9100 frame_need_space (fc
, reg
);
9101 fc
->col_type
[reg
] = DW_CFA_undefined
;
9103 case DW_CFA_offset_extended_sf
:
9104 reg
= LEB (); SLEB ();
9105 frame_need_space (fc
, reg
);
9106 fc
->col_type
[reg
] = DW_CFA_undefined
;
9108 case DW_CFA_def_cfa_sf
:
9111 case DW_CFA_def_cfa_offset_sf
:
9114 case DW_CFA_MIPS_advance_loc8
:
9117 case DW_CFA_GNU_args_size
:
9120 case DW_CFA_GNU_negative_offset_extended
:
9121 reg
= LEB (); LEB ();
9122 frame_need_space (fc
, reg
);
9123 fc
->col_type
[reg
] = DW_CFA_undefined
;
9132 /* Now we know what registers are used, make a second pass over
9133 the chunk, this time actually printing out the info. */
9135 while (start
< block_end
)
9138 unsigned long ul
, reg
, roffs
;
9147 /* Warning: if you add any more cases to this switch, be
9148 sure to add them to the corresponding switch above. */
9151 case DW_CFA_advance_loc
:
9152 if (do_debug_frames_interp
)
9153 frame_display_row (fc
, &need_col_headers
, &max_regs
);
9155 printf (" DW_CFA_advance_loc: %d to %08lx\n",
9156 opa
* fc
->code_factor
,
9157 fc
->pc_begin
+ opa
* fc
->code_factor
);
9158 fc
->pc_begin
+= opa
* fc
->code_factor
;
9163 if (! do_debug_frames_interp
)
9164 printf (" DW_CFA_offset: r%d at cfa%+ld\n",
9165 opa
, roffs
* fc
->data_factor
);
9166 fc
->col_type
[opa
] = DW_CFA_offset
;
9167 fc
->col_offset
[opa
] = roffs
* fc
->data_factor
;
9170 case DW_CFA_restore
:
9171 if (! do_debug_frames_interp
)
9172 printf (" DW_CFA_restore: r%d\n", opa
);
9173 fc
->col_type
[opa
] = cie
->col_type
[opa
];
9174 fc
->col_offset
[opa
] = cie
->col_offset
[opa
];
9177 case DW_CFA_set_loc
:
9178 vma
= byte_get (start
, encoded_ptr_size
);
9179 if ((fc
->fde_encoding
& 0x70) == DW_EH_PE_pcrel
)
9180 vma
+= section
->sh_addr
+ (start
- section_start
);
9181 start
+= encoded_ptr_size
;
9182 if (do_debug_frames_interp
)
9183 frame_display_row (fc
, &need_col_headers
, &max_regs
);
9185 printf (" DW_CFA_set_loc: %08lx\n", (unsigned long)vma
);
9189 case DW_CFA_advance_loc1
:
9190 ofs
= byte_get (start
, 1); start
+= 1;
9191 if (do_debug_frames_interp
)
9192 frame_display_row (fc
, &need_col_headers
, &max_regs
);
9194 printf (" DW_CFA_advance_loc1: %ld to %08lx\n",
9195 ofs
* fc
->code_factor
,
9196 fc
->pc_begin
+ ofs
* fc
->code_factor
);
9197 fc
->pc_begin
+= ofs
* fc
->code_factor
;
9200 case DW_CFA_advance_loc2
:
9201 ofs
= byte_get (start
, 2); start
+= 2;
9202 if (do_debug_frames_interp
)
9203 frame_display_row (fc
, &need_col_headers
, &max_regs
);
9205 printf (" DW_CFA_advance_loc2: %ld to %08lx\n",
9206 ofs
* fc
->code_factor
,
9207 fc
->pc_begin
+ ofs
* fc
->code_factor
);
9208 fc
->pc_begin
+= ofs
* fc
->code_factor
;
9211 case DW_CFA_advance_loc4
:
9212 ofs
= byte_get (start
, 4); start
+= 4;
9213 if (do_debug_frames_interp
)
9214 frame_display_row (fc
, &need_col_headers
, &max_regs
);
9216 printf (" DW_CFA_advance_loc4: %ld to %08lx\n",
9217 ofs
* fc
->code_factor
,
9218 fc
->pc_begin
+ ofs
* fc
->code_factor
);
9219 fc
->pc_begin
+= ofs
* fc
->code_factor
;
9222 case DW_CFA_offset_extended
:
9225 if (! do_debug_frames_interp
)
9226 printf (" DW_CFA_offset_extended: r%ld at cfa%+ld\n",
9227 reg
, roffs
* fc
->data_factor
);
9228 fc
->col_type
[reg
] = DW_CFA_offset
;
9229 fc
->col_offset
[reg
] = roffs
* fc
->data_factor
;
9232 case DW_CFA_restore_extended
:
9234 if (! do_debug_frames_interp
)
9235 printf (" DW_CFA_restore_extended: r%ld\n", reg
);
9236 fc
->col_type
[reg
] = cie
->col_type
[reg
];
9237 fc
->col_offset
[reg
] = cie
->col_offset
[reg
];
9240 case DW_CFA_undefined
:
9242 if (! do_debug_frames_interp
)
9243 printf (" DW_CFA_undefined: r%ld\n", reg
);
9244 fc
->col_type
[reg
] = DW_CFA_undefined
;
9245 fc
->col_offset
[reg
] = 0;
9248 case DW_CFA_same_value
:
9250 if (! do_debug_frames_interp
)
9251 printf (" DW_CFA_same_value: r%ld\n", reg
);
9252 fc
->col_type
[reg
] = DW_CFA_same_value
;
9253 fc
->col_offset
[reg
] = 0;
9256 case DW_CFA_register
:
9259 if (! do_debug_frames_interp
)
9260 printf (" DW_CFA_register: r%ld\n", reg
);
9261 fc
->col_type
[reg
] = DW_CFA_register
;
9262 fc
->col_offset
[reg
] = roffs
;
9265 case DW_CFA_remember_state
:
9266 if (! do_debug_frames_interp
)
9267 printf (" DW_CFA_remember_state\n");
9268 rs
= (Frame_Chunk
*) xmalloc (sizeof (Frame_Chunk
));
9269 rs
->ncols
= fc
->ncols
;
9270 rs
->col_type
= (short int *) xmalloc (rs
->ncols
* sizeof (short int));
9271 rs
->col_offset
= (int *) xmalloc (rs
->ncols
* sizeof (int));
9272 memcpy (rs
->col_type
, fc
->col_type
, rs
->ncols
);
9273 memcpy (rs
->col_offset
, fc
->col_offset
, rs
->ncols
* sizeof (int));
9274 rs
->next
= remembered_state
;
9275 remembered_state
= rs
;
9278 case DW_CFA_restore_state
:
9279 if (! do_debug_frames_interp
)
9280 printf (" DW_CFA_restore_state\n");
9281 rs
= remembered_state
;
9282 remembered_state
= rs
->next
;
9283 frame_need_space (fc
, rs
->ncols
-1);
9284 memcpy (fc
->col_type
, rs
->col_type
, rs
->ncols
);
9285 memcpy (fc
->col_offset
, rs
->col_offset
, rs
->ncols
* sizeof (int));
9286 free (rs
->col_type
);
9287 free (rs
->col_offset
);
9291 case DW_CFA_def_cfa
:
9292 fc
->cfa_reg
= LEB ();
9293 fc
->cfa_offset
= LEB ();
9295 if (! do_debug_frames_interp
)
9296 printf (" DW_CFA_def_cfa: r%d ofs %d\n",
9297 fc
->cfa_reg
, fc
->cfa_offset
);
9300 case DW_CFA_def_cfa_register
:
9301 fc
->cfa_reg
= LEB ();
9303 if (! do_debug_frames_interp
)
9304 printf (" DW_CFA_def_cfa_reg: r%d\n", fc
->cfa_reg
);
9307 case DW_CFA_def_cfa_offset
:
9308 fc
->cfa_offset
= LEB ();
9309 if (! do_debug_frames_interp
)
9310 printf (" DW_CFA_def_cfa_offset: %d\n", fc
->cfa_offset
);
9314 if (! do_debug_frames_interp
)
9315 printf (" DW_CFA_nop\n");
9318 case DW_CFA_def_cfa_expression
:
9320 if (! do_debug_frames_interp
)
9322 printf (" DW_CFA_def_cfa_expression (");
9323 decode_location_expression (start
, addr_size
, ul
);
9330 case DW_CFA_expression
:
9333 if (! do_debug_frames_interp
)
9335 printf (" DW_CFA_expression: r%ld (", reg
);
9336 decode_location_expression (start
, addr_size
, ul
);
9339 fc
->col_type
[reg
] = DW_CFA_expression
;
9343 case DW_CFA_offset_extended_sf
:
9346 frame_need_space (fc
, reg
);
9347 if (! do_debug_frames_interp
)
9348 printf (" DW_CFA_offset_extended_sf: r%ld at cfa%+ld\n",
9349 reg
, l
* fc
->data_factor
);
9350 fc
->col_type
[reg
] = DW_CFA_offset
;
9351 fc
->col_offset
[reg
] = l
* fc
->data_factor
;
9354 case DW_CFA_def_cfa_sf
:
9355 fc
->cfa_reg
= LEB ();
9356 fc
->cfa_offset
= SLEB ();
9358 if (! do_debug_frames_interp
)
9359 printf (" DW_CFA_def_cfa_sf: r%d ofs %d\n",
9360 fc
->cfa_reg
, fc
->cfa_offset
);
9363 case DW_CFA_def_cfa_offset_sf
:
9364 fc
->cfa_offset
= SLEB ();
9365 if (! do_debug_frames_interp
)
9366 printf (" DW_CFA_def_cfa_offset_sf: %d\n", fc
->cfa_offset
);
9369 case DW_CFA_MIPS_advance_loc8
:
9370 ofs
= byte_get (start
, 8); start
+= 8;
9371 if (do_debug_frames_interp
)
9372 frame_display_row (fc
, &need_col_headers
, &max_regs
);
9374 printf (" DW_CFA_MIPS_advance_loc8: %ld to %08lx\n",
9375 ofs
* fc
->code_factor
,
9376 fc
->pc_begin
+ ofs
* fc
->code_factor
);
9377 fc
->pc_begin
+= ofs
* fc
->code_factor
;
9380 case DW_CFA_GNU_window_save
:
9381 if (! do_debug_frames_interp
)
9382 printf (" DW_CFA_GNU_window_save\n");
9385 case DW_CFA_GNU_args_size
:
9387 if (! do_debug_frames_interp
)
9388 printf (" DW_CFA_GNU_args_size: %ld\n", ul
);
9391 case DW_CFA_GNU_negative_offset_extended
:
9394 frame_need_space (fc
, reg
);
9395 if (! do_debug_frames_interp
)
9396 printf (" DW_CFA_GNU_negative_offset_extended: r%ld at cfa%+ld\n",
9397 reg
, l
* fc
->data_factor
);
9398 fc
->col_type
[reg
] = DW_CFA_offset
;
9399 fc
->col_offset
[reg
] = l
* fc
->data_factor
;
9403 fprintf (stderr
, "unsupported or unknown DW_CFA_%d\n", op
);
9408 if (do_debug_frames_interp
)
9409 frame_display_row (fc
, &need_col_headers
, &max_regs
);
9424 display_debug_not_supported (section
, start
, file
)
9425 Elf_Internal_Shdr
*section
;
9426 unsigned char *start ATTRIBUTE_UNUSED
;
9427 FILE *file ATTRIBUTE_UNUSED
;
9429 printf (_("Displaying the debug contents of section %s is not yet supported.\n"),
9430 SECTION_NAME (section
));
9435 /* Pre-scan the .debug_info section to record the size of address.
9436 When dumping the .debug_line, we use that size information, assuming
9437 that all compilation units have the same address size. */
9439 prescan_debug_info (section
, start
, file
)
9440 Elf_Internal_Shdr
*section ATTRIBUTE_UNUSED
;
9441 unsigned char *start
;
9442 FILE *file ATTRIBUTE_UNUSED
;
9444 unsigned long length
;
9446 /* Read the first 4 bytes. For a 32-bit DWARF section, this will
9447 be the length. For a 64-bit DWARF section, it'll be the escape
9448 code 0xffffffff followed by an 8 byte length. For the purposes
9449 of this prescan, we don't care about the actual length, but the
9450 presence of the escape bytes does affect the location of the byte
9451 which describes the address size. */
9452 length
= byte_get (start
, 4);
9454 if (length
== 0xffffffff)
9456 /* For 64-bit DWARF, the 1-byte address_size field is 22 bytes
9457 from the start of the section. This is computed as follows:
9459 unit_length: 12 bytes
9461 debug_abbrev_offset: 8 bytes
9462 -----------------------------
9465 debug_line_pointer_size
= byte_get (start
+ 22, 1);
9469 /* For 32-bit DWARF, the 1-byte address_size field is 10 bytes from
9470 the start of the section:
9471 unit_length: 4 bytes
9473 debug_abbrev_offset: 4 bytes
9474 -----------------------------
9477 debug_line_pointer_size
= byte_get (start
+ 10, 1);
9482 /* A structure containing the name of a debug section and a pointer
9483 to a function that can decode it. The third field is a prescan
9484 function to be run over the section before displaying any of the
9488 const char *const name
;
9489 int (*display
) PARAMS ((Elf_Internal_Shdr
*, unsigned char *, FILE *));
9490 int (*prescan
) PARAMS ((Elf_Internal_Shdr
*, unsigned char *, FILE *));
9494 { ".debug_abbrev", display_debug_abbrev
, NULL
},
9495 { ".debug_aranges", display_debug_aranges
, NULL
},
9496 { ".debug_frame", display_debug_frames
, NULL
},
9497 { ".debug_info", display_debug_info
, prescan_debug_info
},
9498 { ".debug_line", display_debug_lines
, NULL
},
9499 { ".debug_pubnames", display_debug_pubnames
, NULL
},
9500 { ".eh_frame", display_debug_frames
, NULL
},
9501 { ".debug_macinfo", display_debug_macinfo
, NULL
},
9502 { ".debug_str", display_debug_str
, NULL
},
9503 { ".debug_loc", display_debug_loc
, NULL
},
9504 { ".debug_pubtypes", display_debug_not_supported
, NULL
},
9505 { ".debug_ranges", display_debug_not_supported
, NULL
},
9506 { ".debug_static_func", display_debug_not_supported
, NULL
},
9507 { ".debug_static_vars", display_debug_not_supported
, NULL
},
9508 { ".debug_types", display_debug_not_supported
, NULL
},
9509 { ".debug_weaknames", display_debug_not_supported
, NULL
}
9513 display_debug_section (section
, file
)
9514 Elf_Internal_Shdr
*section
;
9517 char *name
= SECTION_NAME (section
);
9518 bfd_size_type length
;
9519 unsigned char *start
;
9522 length
= section
->sh_size
;
9525 printf (_("\nSection '%s' has no debugging data.\n"), name
);
9529 start
= (unsigned char *) get_data (NULL
, file
, section
->sh_offset
, length
,
9530 _("debug section data"));
9534 /* See if we know how to display the contents of this section. */
9535 if (strncmp (name
, ".gnu.linkonce.wi.", 17) == 0)
9536 name
= ".debug_info";
9538 for (i
= NUM_ELEM (debug_displays
); i
--;)
9539 if (strcmp (debug_displays
[i
].name
, name
) == 0)
9541 debug_displays
[i
].display (section
, start
, file
);
9546 printf (_("Unrecognized debug section: %s\n"), name
);
9550 /* If we loaded in the abbrev section at some point,
9551 we must release it here. */
9558 process_section_contents (file
)
9561 Elf_Internal_Shdr
*section
;
9567 /* Pre-scan the debug sections to find some debug information not
9568 present in some of them. For the .debug_line, we must find out the
9569 size of address (specified in .debug_info and .debug_aranges). */
9570 for (i
= 0, section
= section_headers
;
9571 i
< elf_header
.e_shnum
&& i
< num_dump_sects
;
9574 char *name
= SECTION_NAME (section
);
9577 if (section
->sh_size
== 0)
9580 /* See if there is some pre-scan operation for this section. */
9581 for (j
= NUM_ELEM (debug_displays
); j
--;)
9582 if (strcmp (debug_displays
[j
].name
, name
) == 0)
9584 if (debug_displays
[j
].prescan
!= NULL
)
9586 bfd_size_type length
;
9587 unsigned char *start
;
9589 length
= section
->sh_size
;
9590 start
= ((unsigned char *)
9591 get_data (NULL
, file
, section
->sh_offset
, length
,
9592 _("debug section data")));
9596 debug_displays
[j
].prescan (section
, start
, file
);
9604 for (i
= 0, section
= section_headers
;
9605 i
< elf_header
.e_shnum
&& i
< num_dump_sects
;
9608 #ifdef SUPPORT_DISASSEMBLY
9609 if (dump_sects
[i
] & DISASS_DUMP
)
9610 disassemble_section (section
, file
);
9612 if (dump_sects
[i
] & HEX_DUMP
)
9613 dump_section (section
, file
);
9615 if (dump_sects
[i
] & DEBUG_DUMP
)
9616 display_debug_section (section
, file
);
9619 if (i
< num_dump_sects
)
9620 warn (_("Some sections were not dumped because they do not exist!\n"));
9626 process_mips_fpe_exception (mask
)
9632 if (mask
& OEX_FPU_INEX
)
9633 fputs ("INEX", stdout
), first
= 0;
9634 if (mask
& OEX_FPU_UFLO
)
9635 printf ("%sUFLO", first
? "" : "|"), first
= 0;
9636 if (mask
& OEX_FPU_OFLO
)
9637 printf ("%sOFLO", first
? "" : "|"), first
= 0;
9638 if (mask
& OEX_FPU_DIV0
)
9639 printf ("%sDIV0", first
? "" : "|"), first
= 0;
9640 if (mask
& OEX_FPU_INVAL
)
9641 printf ("%sINVAL", first
? "" : "|");
9644 fputs ("0", stdout
);
9648 process_mips_specific (file
)
9651 Elf_Internal_Dyn
*entry
;
9652 size_t liblist_offset
= 0;
9653 size_t liblistno
= 0;
9654 size_t conflictsno
= 0;
9655 size_t options_offset
= 0;
9656 size_t conflicts_offset
= 0;
9658 /* We have a lot of special sections. Thanks SGI! */
9659 if (dynamic_segment
== NULL
)
9660 /* No information available. */
9663 for (entry
= dynamic_segment
; entry
->d_tag
!= DT_NULL
; ++entry
)
9664 switch (entry
->d_tag
)
9666 case DT_MIPS_LIBLIST
:
9667 liblist_offset
= entry
->d_un
.d_val
- loadaddr
;
9669 case DT_MIPS_LIBLISTNO
:
9670 liblistno
= entry
->d_un
.d_val
;
9672 case DT_MIPS_OPTIONS
:
9673 options_offset
= entry
->d_un
.d_val
- loadaddr
;
9675 case DT_MIPS_CONFLICT
:
9676 conflicts_offset
= entry
->d_un
.d_val
- loadaddr
;
9678 case DT_MIPS_CONFLICTNO
:
9679 conflictsno
= entry
->d_un
.d_val
;
9685 if (liblist_offset
!= 0 && liblistno
!= 0 && do_dynamic
)
9687 Elf32_External_Lib
*elib
;
9690 elib
= ((Elf32_External_Lib
*)
9691 get_data (NULL
, file
, liblist_offset
,
9692 liblistno
* sizeof (Elf32_External_Lib
),
9696 printf ("\nSection '.liblist' contains %lu entries:\n",
9697 (unsigned long) liblistno
);
9698 fputs (" Library Time Stamp Checksum Version Flags\n",
9701 for (cnt
= 0; cnt
< liblistno
; ++cnt
)
9708 liblist
.l_name
= BYTE_GET (elib
[cnt
].l_name
);
9709 time
= BYTE_GET (elib
[cnt
].l_time_stamp
);
9710 liblist
.l_checksum
= BYTE_GET (elib
[cnt
].l_checksum
);
9711 liblist
.l_version
= BYTE_GET (elib
[cnt
].l_version
);
9712 liblist
.l_flags
= BYTE_GET (elib
[cnt
].l_flags
);
9714 tmp
= gmtime (&time
);
9715 sprintf (timebuf
, "%04u-%02u-%02uT%02u:%02u:%02u",
9716 tmp
->tm_year
+ 1900, tmp
->tm_mon
+ 1, tmp
->tm_mday
,
9717 tmp
->tm_hour
, tmp
->tm_min
, tmp
->tm_sec
);
9719 printf ("%3lu: ", (unsigned long) cnt
);
9720 print_symbol (20, dynamic_strings
+ liblist
.l_name
);
9721 printf (" %s %#10lx %-7ld", timebuf
, liblist
.l_checksum
,
9724 if (liblist
.l_flags
== 0)
9735 { " EXACT_MATCH", LL_EXACT_MATCH
},
9736 { " IGNORE_INT_VER", LL_IGNORE_INT_VER
},
9737 { " REQUIRE_MINOR", LL_REQUIRE_MINOR
},
9738 { " EXPORTS", LL_EXPORTS
},
9739 { " DELAY_LOAD", LL_DELAY_LOAD
},
9740 { " DELTA", LL_DELTA
}
9742 int flags
= liblist
.l_flags
;
9746 fcnt
< sizeof (l_flags_vals
) / sizeof (l_flags_vals
[0]);
9748 if ((flags
& l_flags_vals
[fcnt
].bit
) != 0)
9750 fputs (l_flags_vals
[fcnt
].name
, stdout
);
9751 flags
^= l_flags_vals
[fcnt
].bit
;
9754 printf (" %#x", (unsigned int) flags
);
9764 if (options_offset
!= 0)
9766 Elf_External_Options
*eopt
;
9767 Elf_Internal_Shdr
*sect
= section_headers
;
9768 Elf_Internal_Options
*iopt
;
9769 Elf_Internal_Options
*option
;
9773 /* Find the section header so that we get the size. */
9774 while (sect
->sh_type
!= SHT_MIPS_OPTIONS
)
9777 eopt
= (Elf_External_Options
*) get_data (NULL
, file
, options_offset
,
9778 sect
->sh_size
, _("options"));
9781 iopt
= ((Elf_Internal_Options
*)
9782 malloc ((sect
->sh_size
/ sizeof (eopt
)) * sizeof (*iopt
)));
9785 error (_("Out of memory"));
9792 while (offset
< sect
->sh_size
)
9794 Elf_External_Options
*eoption
;
9796 eoption
= (Elf_External_Options
*) ((char *) eopt
+ offset
);
9798 option
->kind
= BYTE_GET (eoption
->kind
);
9799 option
->size
= BYTE_GET (eoption
->size
);
9800 option
->section
= BYTE_GET (eoption
->section
);
9801 option
->info
= BYTE_GET (eoption
->info
);
9803 offset
+= option
->size
;
9809 printf (_("\nSection '%s' contains %d entries:\n"),
9810 SECTION_NAME (sect
), cnt
);
9818 switch (option
->kind
)
9821 /* This shouldn't happen. */
9822 printf (" NULL %d %lx", option
->section
, option
->info
);
9825 printf (" REGINFO ");
9826 if (elf_header
.e_machine
== EM_MIPS
)
9829 Elf32_External_RegInfo
*ereg
;
9830 Elf32_RegInfo reginfo
;
9832 ereg
= (Elf32_External_RegInfo
*) (option
+ 1);
9833 reginfo
.ri_gprmask
= BYTE_GET (ereg
->ri_gprmask
);
9834 reginfo
.ri_cprmask
[0] = BYTE_GET (ereg
->ri_cprmask
[0]);
9835 reginfo
.ri_cprmask
[1] = BYTE_GET (ereg
->ri_cprmask
[1]);
9836 reginfo
.ri_cprmask
[2] = BYTE_GET (ereg
->ri_cprmask
[2]);
9837 reginfo
.ri_cprmask
[3] = BYTE_GET (ereg
->ri_cprmask
[3]);
9838 reginfo
.ri_gp_value
= BYTE_GET (ereg
->ri_gp_value
);
9840 printf ("GPR %08lx GP 0x%lx\n",
9842 (unsigned long) reginfo
.ri_gp_value
);
9843 printf (" CPR0 %08lx CPR1 %08lx CPR2 %08lx CPR3 %08lx\n",
9844 reginfo
.ri_cprmask
[0], reginfo
.ri_cprmask
[1],
9845 reginfo
.ri_cprmask
[2], reginfo
.ri_cprmask
[3]);
9850 Elf64_External_RegInfo
*ereg
;
9851 Elf64_Internal_RegInfo reginfo
;
9853 ereg
= (Elf64_External_RegInfo
*) (option
+ 1);
9854 reginfo
.ri_gprmask
= BYTE_GET (ereg
->ri_gprmask
);
9855 reginfo
.ri_cprmask
[0] = BYTE_GET (ereg
->ri_cprmask
[0]);
9856 reginfo
.ri_cprmask
[1] = BYTE_GET (ereg
->ri_cprmask
[1]);
9857 reginfo
.ri_cprmask
[2] = BYTE_GET (ereg
->ri_cprmask
[2]);
9858 reginfo
.ri_cprmask
[3] = BYTE_GET (ereg
->ri_cprmask
[3]);
9859 reginfo
.ri_gp_value
= BYTE_GET8 (ereg
->ri_gp_value
);
9861 printf ("GPR %08lx GP 0x",
9862 reginfo
.ri_gprmask
);
9863 printf_vma (reginfo
.ri_gp_value
);
9866 printf (" CPR0 %08lx CPR1 %08lx CPR2 %08lx CPR3 %08lx\n",
9867 reginfo
.ri_cprmask
[0], reginfo
.ri_cprmask
[1],
9868 reginfo
.ri_cprmask
[2], reginfo
.ri_cprmask
[3]);
9872 case ODK_EXCEPTIONS
:
9873 fputs (" EXCEPTIONS fpe_min(", stdout
);
9874 process_mips_fpe_exception (option
->info
& OEX_FPU_MIN
);
9875 fputs (") fpe_max(", stdout
);
9876 process_mips_fpe_exception ((option
->info
& OEX_FPU_MAX
) >> 8);
9877 fputs (")", stdout
);
9879 if (option
->info
& OEX_PAGE0
)
9880 fputs (" PAGE0", stdout
);
9881 if (option
->info
& OEX_SMM
)
9882 fputs (" SMM", stdout
);
9883 if (option
->info
& OEX_FPDBUG
)
9884 fputs (" FPDBUG", stdout
);
9885 if (option
->info
& OEX_DISMISS
)
9886 fputs (" DISMISS", stdout
);
9889 fputs (" PAD ", stdout
);
9890 if (option
->info
& OPAD_PREFIX
)
9891 fputs (" PREFIX", stdout
);
9892 if (option
->info
& OPAD_POSTFIX
)
9893 fputs (" POSTFIX", stdout
);
9894 if (option
->info
& OPAD_SYMBOL
)
9895 fputs (" SYMBOL", stdout
);
9898 fputs (" HWPATCH ", stdout
);
9899 if (option
->info
& OHW_R4KEOP
)
9900 fputs (" R4KEOP", stdout
);
9901 if (option
->info
& OHW_R8KPFETCH
)
9902 fputs (" R8KPFETCH", stdout
);
9903 if (option
->info
& OHW_R5KEOP
)
9904 fputs (" R5KEOP", stdout
);
9905 if (option
->info
& OHW_R5KCVTL
)
9906 fputs (" R5KCVTL", stdout
);
9909 fputs (" FILL ", stdout
);
9910 /* XXX Print content of info word? */
9913 fputs (" TAGS ", stdout
);
9914 /* XXX Print content of info word? */
9917 fputs (" HWAND ", stdout
);
9918 if (option
->info
& OHWA0_R4KEOP_CHECKED
)
9919 fputs (" R4KEOP_CHECKED", stdout
);
9920 if (option
->info
& OHWA0_R4KEOP_CLEAN
)
9921 fputs (" R4KEOP_CLEAN", stdout
);
9924 fputs (" HWOR ", stdout
);
9925 if (option
->info
& OHWA0_R4KEOP_CHECKED
)
9926 fputs (" R4KEOP_CHECKED", stdout
);
9927 if (option
->info
& OHWA0_R4KEOP_CLEAN
)
9928 fputs (" R4KEOP_CLEAN", stdout
);
9931 printf (" GP_GROUP %#06lx self-contained %#06lx",
9932 option
->info
& OGP_GROUP
,
9933 (option
->info
& OGP_SELF
) >> 16);
9936 printf (" IDENT %#06lx self-contained %#06lx",
9937 option
->info
& OGP_GROUP
,
9938 (option
->info
& OGP_SELF
) >> 16);
9941 /* This shouldn't happen. */
9942 printf (" %3d ??? %d %lx",
9943 option
->kind
, option
->section
, option
->info
);
9947 len
= sizeof (*eopt
);
9948 while (len
< option
->size
)
9949 if (((char *) option
)[len
] >= ' '
9950 && ((char *) option
)[len
] < 0x7f)
9951 printf ("%c", ((char *) option
)[len
++]);
9953 printf ("\\%03o", ((char *) option
)[len
++]);
9955 fputs ("\n", stdout
);
9963 if (conflicts_offset
!= 0 && conflictsno
!= 0)
9965 Elf32_Conflict
*iconf
;
9968 if (dynamic_symbols
== NULL
)
9970 error (_("conflict list found without a dynamic symbol table"));
9974 iconf
= (Elf32_Conflict
*) malloc (conflictsno
* sizeof (*iconf
));
9977 error (_("Out of memory"));
9983 Elf32_External_Conflict
*econf32
;
9985 econf32
= ((Elf32_External_Conflict
*)
9986 get_data (NULL
, file
, conflicts_offset
,
9987 conflictsno
* sizeof (*econf32
),
9992 for (cnt
= 0; cnt
< conflictsno
; ++cnt
)
9993 iconf
[cnt
] = BYTE_GET (econf32
[cnt
]);
9999 Elf64_External_Conflict
*econf64
;
10001 econf64
= ((Elf64_External_Conflict
*)
10002 get_data (NULL
, file
, conflicts_offset
,
10003 conflictsno
* sizeof (*econf64
),
10008 for (cnt
= 0; cnt
< conflictsno
; ++cnt
)
10009 iconf
[cnt
] = BYTE_GET (econf64
[cnt
]);
10014 printf (_("\nSection '.conflict' contains %ld entries:\n"),
10015 (long) conflictsno
);
10016 puts (_(" Num: Index Value Name"));
10018 for (cnt
= 0; cnt
< conflictsno
; ++cnt
)
10020 Elf_Internal_Sym
*psym
= & dynamic_symbols
[iconf
[cnt
]];
10022 printf ("%5lu: %8lu ", (unsigned long) cnt
, iconf
[cnt
]);
10023 print_vma (psym
->st_value
, FULL_HEX
);
10025 print_symbol (25, dynamic_strings
+ psym
->st_name
);
10036 process_gnu_liblist (file
)
10039 Elf_Internal_Shdr
*section
, *string_sec
;
10040 Elf32_External_Lib
*elib
;
10048 for (i
= 0, section
= section_headers
;
10049 i
< elf_header
.e_shnum
;
10052 switch (section
->sh_type
)
10054 case SHT_GNU_LIBLIST
:
10055 elib
= ((Elf32_External_Lib
*)
10056 get_data (NULL
, file
, section
->sh_offset
, section
->sh_size
,
10061 string_sec
= SECTION_HEADER (section
->sh_link
);
10063 strtab
= (char *) get_data (NULL
, file
, string_sec
->sh_offset
,
10064 string_sec
->sh_size
,
10065 _("liblist string table"));
10068 || section
->sh_entsize
!= sizeof (Elf32_External_Lib
))
10074 printf (_("\nLibrary list section '%s' contains %lu entries:\n"),
10075 SECTION_NAME (section
),
10076 (long) (section
->sh_size
/ sizeof (Elf32_External_Lib
)));
10078 puts (" Library Time Stamp Checksum Version Flags");
10080 for (cnt
= 0; cnt
< section
->sh_size
/ sizeof (Elf32_External_Lib
);
10088 liblist
.l_name
= BYTE_GET (elib
[cnt
].l_name
);
10089 time
= BYTE_GET (elib
[cnt
].l_time_stamp
);
10090 liblist
.l_checksum
= BYTE_GET (elib
[cnt
].l_checksum
);
10091 liblist
.l_version
= BYTE_GET (elib
[cnt
].l_version
);
10092 liblist
.l_flags
= BYTE_GET (elib
[cnt
].l_flags
);
10094 tmp
= gmtime (&time
);
10095 sprintf (timebuf
, "%04u-%02u-%02uT%02u:%02u:%02u",
10096 tmp
->tm_year
+ 1900, tmp
->tm_mon
+ 1, tmp
->tm_mday
,
10097 tmp
->tm_hour
, tmp
->tm_min
, tmp
->tm_sec
);
10099 printf ("%3lu: ", (unsigned long) cnt
);
10101 printf ("%-20s", strtab
+ liblist
.l_name
);
10103 printf ("%-20.20s", strtab
+ liblist
.l_name
);
10104 printf (" %s %#010lx %-7ld %-7ld\n", timebuf
, liblist
.l_checksum
,
10105 liblist
.l_version
, liblist
.l_flags
);
10115 static const char *
10116 get_note_type (e_type
)
10119 static char buff
[64];
10123 case NT_PRSTATUS
: return _("NT_PRSTATUS (prstatus structure)");
10124 case NT_FPREGSET
: return _("NT_FPREGSET (floating point registers)");
10125 case NT_PRPSINFO
: return _("NT_PRPSINFO (prpsinfo structure)");
10126 case NT_TASKSTRUCT
: return _("NT_TASKSTRUCT (task structure)");
10127 case NT_PRXFPREG
: return _("NT_PRXFPREG (user_xfpregs structure)");
10128 case NT_PSTATUS
: return _("NT_PSTATUS (pstatus structure)");
10129 case NT_FPREGS
: return _("NT_FPREGS (floating point registers)");
10130 case NT_PSINFO
: return _("NT_PSINFO (psinfo structure)");
10131 case NT_LWPSTATUS
: return _("NT_LWPSTATUS (lwpstatus_t structure)");
10132 case NT_LWPSINFO
: return _("NT_LWPSINFO (lwpsinfo_t structure)");
10133 case NT_WIN32PSTATUS
: return _("NT_WIN32PSTATUS (win32_pstatus structure)");
10135 sprintf (buff
, _("Unknown note type: (0x%08x)"), e_type
);
10140 static const char *
10141 get_netbsd_elfcore_note_type (e_type
)
10144 static char buff
[64];
10146 if (e_type
== NT_NETBSDCORE_PROCINFO
)
10148 /* NetBSD core "procinfo" structure. */
10149 return _("NetBSD procinfo structure");
10152 /* As of Jan 2002 there are no other machine-independent notes
10153 defined for NetBSD core files. If the note type is less
10154 than the start of the machine-dependent note types, we don't
10157 if (e_type
< NT_NETBSDCORE_FIRSTMACH
)
10159 sprintf (buff
, _("Unknown note type: (0x%08x)"), e_type
);
10163 switch (elf_header
.e_machine
)
10165 /* On the Alpha, SPARC (32-bit and 64-bit), PT_GETREGS == mach+0
10166 and PT_GETFPREGS == mach+2. */
10171 case EM_SPARC32PLUS
:
10175 case NT_NETBSDCORE_FIRSTMACH
+0:
10176 return _("PT_GETREGS (reg structure)");
10177 case NT_NETBSDCORE_FIRSTMACH
+2:
10178 return _("PT_GETFPREGS (fpreg structure)");
10184 /* On all other arch's, PT_GETREGS == mach+1 and
10185 PT_GETFPREGS == mach+3. */
10189 case NT_NETBSDCORE_FIRSTMACH
+1:
10190 return _("PT_GETREGS (reg structure)");
10191 case NT_NETBSDCORE_FIRSTMACH
+3:
10192 return _("PT_GETFPREGS (fpreg structure)");
10198 sprintf (buff
, _("PT_FIRSTMACH+%d"), e_type
- NT_NETBSDCORE_FIRSTMACH
);
10202 /* Note that by the ELF standard, the name field is already null byte
10203 terminated, and namesz includes the terminating null byte.
10204 I.E. the value of namesz for the name "FSF" is 4.
10206 If the value of namesz is zero, there is no name present. */
10208 process_note (pnote
)
10209 Elf_Internal_Note
*pnote
;
10213 if (pnote
->namesz
== 0)
10215 /* If there is no note name, then use the default set of
10216 note type strings. */
10217 nt
= get_note_type (pnote
->type
);
10219 else if (strncmp (pnote
->namedata
, "NetBSD-CORE", 11) == 0)
10221 /* NetBSD-specific core file notes. */
10222 nt
= get_netbsd_elfcore_note_type (pnote
->type
);
10226 /* Don't recognize this note name; just use the default set of
10227 note type strings. */
10228 nt
= get_note_type (pnote
->type
);
10231 printf (" %s\t\t0x%08lx\t%s\n",
10232 pnote
->namesz
? pnote
->namedata
: "(NONE)",
10233 pnote
->descsz
, nt
);
10239 process_corefile_note_segment (file
, offset
, length
)
10244 Elf_External_Note
*pnotes
;
10245 Elf_External_Note
*external
;
10251 pnotes
= (Elf_External_Note
*) get_data (NULL
, file
, offset
, length
,
10258 printf (_("\nNotes at offset 0x%08lx with length 0x%08lx:\n"),
10259 (unsigned long) offset
, (unsigned long) length
);
10260 printf (_(" Owner\t\tData size\tDescription\n"));
10262 while (external
< (Elf_External_Note
*)((char *) pnotes
+ length
))
10264 Elf_External_Note
*next
;
10265 Elf_Internal_Note inote
;
10268 inote
.type
= BYTE_GET (external
->type
);
10269 inote
.namesz
= BYTE_GET (external
->namesz
);
10270 inote
.namedata
= external
->name
;
10271 inote
.descsz
= BYTE_GET (external
->descsz
);
10272 inote
.descdata
= inote
.namedata
+ align_power (inote
.namesz
, 2);
10273 inote
.descpos
= offset
+ (inote
.descdata
- (char *) pnotes
);
10275 next
= (Elf_External_Note
*)(inote
.descdata
+ align_power (inote
.descsz
, 2));
10277 if (((char *) next
) > (((char *) pnotes
) + length
))
10279 warn (_("corrupt note found at offset %x into core notes\n"),
10280 ((char *) external
) - ((char *) pnotes
));
10281 warn (_(" type: %x, namesize: %08lx, descsize: %08lx\n"),
10282 inote
.type
, inote
.namesz
, inote
.descsz
);
10288 /* Verify that name is null terminated. It appears that at least
10289 one version of Linux (RedHat 6.0) generates corefiles that don't
10290 comply with the ELF spec by failing to include the null byte in
10292 if (inote
.namedata
[inote
.namesz
] != '\0')
10294 temp
= malloc (inote
.namesz
+ 1);
10298 error (_("Out of memory\n"));
10303 strncpy (temp
, inote
.namedata
, inote
.namesz
);
10304 temp
[inote
.namesz
] = 0;
10306 /* warn (_("'%s' NOTE name not properly null terminated\n"), temp); */
10307 inote
.namedata
= temp
;
10310 res
&= process_note (& inote
);
10325 process_corefile_note_segments (file
)
10328 Elf_Internal_Phdr
*program_headers
;
10329 Elf_Internal_Phdr
*segment
;
10333 program_headers
= (Elf_Internal_Phdr
*) malloc
10334 (elf_header
.e_phnum
* sizeof (Elf_Internal_Phdr
));
10336 if (program_headers
== NULL
)
10338 error (_("Out of memory\n"));
10343 i
= get_32bit_program_headers (file
, program_headers
);
10345 i
= get_64bit_program_headers (file
, program_headers
);
10349 free (program_headers
);
10353 for (i
= 0, segment
= program_headers
;
10354 i
< elf_header
.e_phnum
;
10357 if (segment
->p_type
== PT_NOTE
)
10358 res
&= process_corefile_note_segment (file
,
10359 (bfd_vma
) segment
->p_offset
,
10360 (bfd_vma
) segment
->p_filesz
);
10363 free (program_headers
);
10369 process_corefile_contents (file
)
10372 /* If we have not been asked to display the notes then do nothing. */
10376 /* If file is not a core file then exit. */
10377 if (elf_header
.e_type
!= ET_CORE
)
10380 /* No program headers means no NOTE segment. */
10381 if (elf_header
.e_phnum
== 0)
10383 printf (_("No note segments present in the core file.\n"));
10387 return process_corefile_note_segments (file
);
10391 process_arch_specific (file
)
10397 switch (elf_header
.e_machine
)
10400 case EM_MIPS_RS3_LE
:
10401 return process_mips_specific (file
);
10410 get_file_header (file
)
10413 /* Read in the identity array. */
10414 if (fread (elf_header
.e_ident
, EI_NIDENT
, 1, file
) != 1)
10417 /* Determine how to read the rest of the header. */
10418 switch (elf_header
.e_ident
[EI_DATA
])
10420 default: /* fall through */
10421 case ELFDATANONE
: /* fall through */
10423 byte_get
= byte_get_little_endian
;
10424 byte_put
= byte_put_little_endian
;
10427 byte_get
= byte_get_big_endian
;
10428 byte_put
= byte_put_big_endian
;
10432 /* For now we only support 32 bit and 64 bit ELF files. */
10433 is_32bit_elf
= (elf_header
.e_ident
[EI_CLASS
] != ELFCLASS64
);
10435 /* Read in the rest of the header. */
10438 Elf32_External_Ehdr ehdr32
;
10440 if (fread (ehdr32
.e_type
, sizeof (ehdr32
) - EI_NIDENT
, 1, file
) != 1)
10443 elf_header
.e_type
= BYTE_GET (ehdr32
.e_type
);
10444 elf_header
.e_machine
= BYTE_GET (ehdr32
.e_machine
);
10445 elf_header
.e_version
= BYTE_GET (ehdr32
.e_version
);
10446 elf_header
.e_entry
= BYTE_GET (ehdr32
.e_entry
);
10447 elf_header
.e_phoff
= BYTE_GET (ehdr32
.e_phoff
);
10448 elf_header
.e_shoff
= BYTE_GET (ehdr32
.e_shoff
);
10449 elf_header
.e_flags
= BYTE_GET (ehdr32
.e_flags
);
10450 elf_header
.e_ehsize
= BYTE_GET (ehdr32
.e_ehsize
);
10451 elf_header
.e_phentsize
= BYTE_GET (ehdr32
.e_phentsize
);
10452 elf_header
.e_phnum
= BYTE_GET (ehdr32
.e_phnum
);
10453 elf_header
.e_shentsize
= BYTE_GET (ehdr32
.e_shentsize
);
10454 elf_header
.e_shnum
= BYTE_GET (ehdr32
.e_shnum
);
10455 elf_header
.e_shstrndx
= BYTE_GET (ehdr32
.e_shstrndx
);
10459 Elf64_External_Ehdr ehdr64
;
10461 /* If we have been compiled with sizeof (bfd_vma) == 4, then
10462 we will not be able to cope with the 64bit data found in
10463 64 ELF files. Detect this now and abort before we start
10464 overwritting things. */
10465 if (sizeof (bfd_vma
) < 8)
10467 error (_("This instance of readelf has been built without support for a\n\
10468 64 bit data type and so it cannot read 64 bit ELF files.\n"));
10472 if (fread (ehdr64
.e_type
, sizeof (ehdr64
) - EI_NIDENT
, 1, file
) != 1)
10475 elf_header
.e_type
= BYTE_GET (ehdr64
.e_type
);
10476 elf_header
.e_machine
= BYTE_GET (ehdr64
.e_machine
);
10477 elf_header
.e_version
= BYTE_GET (ehdr64
.e_version
);
10478 elf_header
.e_entry
= BYTE_GET8 (ehdr64
.e_entry
);
10479 elf_header
.e_phoff
= BYTE_GET8 (ehdr64
.e_phoff
);
10480 elf_header
.e_shoff
= BYTE_GET8 (ehdr64
.e_shoff
);
10481 elf_header
.e_flags
= BYTE_GET (ehdr64
.e_flags
);
10482 elf_header
.e_ehsize
= BYTE_GET (ehdr64
.e_ehsize
);
10483 elf_header
.e_phentsize
= BYTE_GET (ehdr64
.e_phentsize
);
10484 elf_header
.e_phnum
= BYTE_GET (ehdr64
.e_phnum
);
10485 elf_header
.e_shentsize
= BYTE_GET (ehdr64
.e_shentsize
);
10486 elf_header
.e_shnum
= BYTE_GET (ehdr64
.e_shnum
);
10487 elf_header
.e_shstrndx
= BYTE_GET (ehdr64
.e_shstrndx
);
10490 if (elf_header
.e_shoff
)
10492 /* There may be some extensions in the first section header. Don't
10493 bomb if we can't read it. */
10495 get_32bit_section_headers (file
, 1);
10497 get_64bit_section_headers (file
, 1);
10504 process_file (file_name
)
10508 struct stat statbuf
;
10511 if (stat (file_name
, & statbuf
) < 0)
10513 error (_("Cannot stat input file %s.\n"), file_name
);
10517 file
= fopen (file_name
, "rb");
10520 error (_("Input file %s not found.\n"), file_name
);
10524 if (! get_file_header (file
))
10526 error (_("%s: Failed to read file header\n"), file_name
);
10531 /* Initialise per file variables. */
10532 for (i
= NUM_ELEM (version_info
); i
--;)
10533 version_info
[i
] = 0;
10535 for (i
= NUM_ELEM (dynamic_info
); i
--;)
10536 dynamic_info
[i
] = 0;
10538 /* Process the file. */
10540 printf (_("\nFile: %s\n"), file_name
);
10542 if (! process_file_header ())
10548 if (! process_section_headers (file
))
10550 /* Without loaded section headers we
10551 cannot process lots of things. */
10552 do_unwind
= do_version
= do_dump
= do_arch
= 0;
10554 if (! do_using_dynamic
)
10555 do_syms
= do_reloc
= 0;
10558 if (process_program_headers (file
))
10559 process_dynamic_segment (file
);
10561 process_relocs (file
);
10563 process_unwind (file
);
10565 process_symbol_table (file
);
10567 process_syminfo (file
);
10569 process_version_sections (file
);
10571 process_section_contents (file
);
10573 process_corefile_contents (file
);
10575 process_gnu_liblist (file
);
10577 process_arch_specific (file
);
10581 if (section_headers
)
10583 free (section_headers
);
10584 section_headers
= NULL
;
10589 free (string_table
);
10590 string_table
= NULL
;
10591 string_table_length
= 0;
10594 if (dynamic_strings
)
10596 free (dynamic_strings
);
10597 dynamic_strings
= NULL
;
10600 if (dynamic_symbols
)
10602 free (dynamic_symbols
);
10603 dynamic_symbols
= NULL
;
10604 num_dynamic_syms
= 0;
10607 if (dynamic_syminfo
)
10609 free (dynamic_syminfo
);
10610 dynamic_syminfo
= NULL
;
10616 #ifdef SUPPORT_DISASSEMBLY
10617 /* Needed by the i386 disassembler. For extra credit, someone could
10618 fix this so that we insert symbolic addresses here, esp for GOT/PLT
10622 print_address (unsigned int addr
, FILE *outfile
)
10624 fprintf (outfile
,"0x%8.8x", addr
);
10627 /* Needed by the i386 disassembler. */
10629 db_task_printsym (unsigned int addr
)
10631 print_address (addr
, stderr
);
10635 int main
PARAMS ((int, char **));
10643 char *cmdline_dump_sects
= NULL
;
10644 unsigned num_cmdline_dump_sects
= 0;
10646 #if defined (HAVE_SETLOCALE) && defined (HAVE_LC_MESSAGES)
10647 setlocale (LC_MESSAGES
, "");
10649 #if defined (HAVE_SETLOCALE)
10650 setlocale (LC_CTYPE
, "");
10652 bindtextdomain (PACKAGE
, LOCALEDIR
);
10653 textdomain (PACKAGE
);
10655 parse_args (argc
, argv
);
10657 if (optind
< (argc
- 1))
10660 /* When processing more than one file remember the dump requests
10661 issued on command line to reset them after each file. */
10662 if (optind
+ 1 < argc
&& dump_sects
!= NULL
)
10664 cmdline_dump_sects
= malloc (num_dump_sects
);
10665 if (cmdline_dump_sects
== NULL
)
10666 error (_("Out of memory allocating dump request table."));
10669 memcpy (cmdline_dump_sects
, dump_sects
, num_dump_sects
);
10670 num_cmdline_dump_sects
= num_dump_sects
;
10675 while (optind
< argc
)
10677 err
|= process_file (argv
[optind
++]);
10679 /* Reset dump requests. */
10680 if (optind
< argc
&& dump_sects
!= NULL
)
10682 num_dump_sects
= num_cmdline_dump_sects
;
10683 if (num_cmdline_dump_sects
> 0)
10684 memcpy (dump_sects
, cmdline_dump_sects
, num_cmdline_dump_sects
);
10688 if (dump_sects
!= NULL
)
10690 if (cmdline_dump_sects
!= NULL
)
10691 free (cmdline_dump_sects
);