include/elf:
[deliverable/binutils-gdb.git] / binutils / readelf.c
1 /* readelf.c -- display contents of an ELF format file
2 Copyright 1998, 1999, 2000, 2001, 2002 Free Software Foundation, Inc.
3
4 Originally developed by Eric Youngdale <eric@andante.jic.com>
5 Modifications by Nick Clifton <nickc@redhat.com>
6
7 This file is part of GNU Binutils.
8
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.
13
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.
18
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
22 02111-1307, USA. */
23 \f
24
25 #include <assert.h>
26 #include <sys/types.h>
27 #include <sys/stat.h>
28 #include <stdio.h>
29 #include <time.h>
30
31 #if __GNUC__ >= 2
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 belive that the compiler can support a 64 bit
35 data type. For now we only rely on GCC being able to do this. */
36 #define BFD64
37 #endif
38
39 #include "bfd.h"
40
41 #include "elf/common.h"
42 #include "elf/external.h"
43 #include "elf/internal.h"
44 #include "elf/dwarf2.h"
45
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() */
49
50 #define RELOC_MACROS_GEN_FUNC
51
52 #include "elf/alpha.h"
53 #include "elf/arc.h"
54 #include "elf/arm.h"
55 #include "elf/avr.h"
56 #include "elf/cris.h"
57 #include "elf/d10v.h"
58 #include "elf/d30v.h"
59 #include "elf/dlx.h"
60 #include "elf/fr30.h"
61 #include "elf/frv.h"
62 #include "elf/h8.h"
63 #include "elf/hppa.h"
64 #include "elf/i386.h"
65 #include "elf/i860.h"
66 #include "elf/i960.h"
67 #include "elf/ia64.h"
68 #include "elf/m32r.h"
69 #include "elf/m68k.h"
70 #include "elf/m68hc11.h"
71 #include "elf/mcore.h"
72 #include "elf/mips.h"
73 #include "elf/mmix.h"
74 #include "elf/mn10200.h"
75 #include "elf/mn10300.h"
76 #include "elf/or32.h"
77 #include "elf/pj.h"
78 #include "elf/ppc.h"
79 #include "elf/s390.h"
80 #include "elf/sh.h"
81 #include "elf/sparc.h"
82 #include "elf/v850.h"
83 #include "elf/vax.h"
84 #include "elf/x86-64.h"
85 #include "elf/xstormy16.h"
86
87 #include "bucomm.h"
88 #include "getopt.h"
89
90 char * program_name = "readelf";
91 unsigned int dynamic_addr;
92 bfd_size_type dynamic_size;
93 unsigned int rela_addr;
94 unsigned int rela_size;
95 char * dynamic_strings;
96 char * string_table;
97 unsigned long string_table_length;
98 unsigned long num_dynamic_syms;
99 Elf_Internal_Sym * dynamic_symbols;
100 Elf_Internal_Syminfo * dynamic_syminfo;
101 unsigned long dynamic_syminfo_offset;
102 unsigned int dynamic_syminfo_nent;
103 char program_interpreter [64];
104 int dynamic_info[DT_JMPREL + 1];
105 int version_info[16];
106 int loadaddr = 0;
107 Elf_Internal_Ehdr elf_header;
108 Elf_Internal_Shdr * section_headers;
109 Elf_Internal_Dyn * dynamic_segment;
110 Elf_Internal_Shdr * symtab_shndx_hdr;
111 int show_name;
112 int do_dynamic;
113 int do_syms;
114 int do_reloc;
115 int do_sections;
116 int do_segments;
117 int do_unwind;
118 int do_using_dynamic;
119 int do_header;
120 int do_dump;
121 int do_version;
122 int do_wide;
123 int do_histogram;
124 int do_debugging;
125 int do_debug_info;
126 int do_debug_abbrevs;
127 int do_debug_lines;
128 int do_debug_pubnames;
129 int do_debug_aranges;
130 int do_debug_frames;
131 int do_debug_frames_interp;
132 int do_debug_macinfo;
133 int do_debug_str;
134 int do_debug_loc;
135 int do_arch;
136 int do_notes;
137 int is_32bit_elf;
138
139 /* A dynamic array of flags indicating which sections require dumping. */
140 char * dump_sects = NULL;
141 unsigned int num_dump_sects = 0;
142
143 #define HEX_DUMP (1 << 0)
144 #define DISASS_DUMP (1 << 1)
145 #define DEBUG_DUMP (1 << 2)
146
147 /* How to rpint a vma value. */
148 typedef enum print_mode
149 {
150 HEX,
151 DEC,
152 DEC_5,
153 UNSIGNED,
154 PREFIX_HEX,
155 FULL_HEX,
156 LONG_HEX
157 }
158 print_mode;
159
160 /* Forward declarations for dumb compilers. */
161 static void print_vma PARAMS ((bfd_vma, print_mode));
162 static void print_symbol PARAMS ((int, char *));
163 static bfd_vma (* byte_get) PARAMS ((unsigned char *, int));
164 static bfd_vma byte_get_little_endian PARAMS ((unsigned char *, int));
165 static bfd_vma byte_get_big_endian PARAMS ((unsigned char *, int));
166 static const char * get_mips_dynamic_type PARAMS ((unsigned long));
167 static const char * get_sparc64_dynamic_type PARAMS ((unsigned long));
168 static const char * get_ppc64_dynamic_type PARAMS ((unsigned long));
169 static const char * get_parisc_dynamic_type PARAMS ((unsigned long));
170 static const char * get_dynamic_type PARAMS ((unsigned long));
171 static int slurp_rela_relocs PARAMS ((FILE *, unsigned long, unsigned long, Elf_Internal_Rela **, unsigned long *));
172 static int slurp_rel_relocs PARAMS ((FILE *, unsigned long, unsigned long, Elf_Internal_Rel **, unsigned long *));
173 static int dump_relocations PARAMS ((FILE *, unsigned long, unsigned long, Elf_Internal_Sym *, unsigned long, char *, int));
174 static char * get_file_type PARAMS ((unsigned));
175 static char * get_machine_name PARAMS ((unsigned));
176 static void decode_ARM_machine_flags PARAMS ((unsigned, char []));
177 static char * get_machine_flags PARAMS ((unsigned, unsigned));
178 static const char * get_mips_segment_type PARAMS ((unsigned long));
179 static const char * get_parisc_segment_type PARAMS ((unsigned long));
180 static const char * get_ia64_segment_type PARAMS ((unsigned long));
181 static const char * get_segment_type PARAMS ((unsigned long));
182 static const char * get_mips_section_type_name PARAMS ((unsigned int));
183 static const char * get_parisc_section_type_name PARAMS ((unsigned int));
184 static const char * get_ia64_section_type_name PARAMS ((unsigned int));
185 static const char * get_section_type_name PARAMS ((unsigned int));
186 static const char * get_symbol_binding PARAMS ((unsigned int));
187 static const char * get_symbol_type PARAMS ((unsigned int));
188 static const char * get_symbol_visibility PARAMS ((unsigned int));
189 static const char * get_symbol_index_type PARAMS ((unsigned int));
190 static const char * get_dynamic_flags PARAMS ((bfd_vma));
191 static void usage PARAMS ((void));
192 static void parse_args PARAMS ((int, char **));
193 static int process_file_header PARAMS ((void));
194 static int process_program_headers PARAMS ((FILE *));
195 static int process_section_headers PARAMS ((FILE *));
196 static int process_unwind PARAMS ((FILE *));
197 static void dynamic_segment_mips_val PARAMS ((Elf_Internal_Dyn *));
198 static void dynamic_segment_parisc_val PARAMS ((Elf_Internal_Dyn *));
199 static int process_dynamic_segment PARAMS ((FILE *));
200 static int process_symbol_table PARAMS ((FILE *));
201 static int process_syminfo PARAMS ((FILE *));
202 static int process_section_contents PARAMS ((FILE *));
203 static void process_mips_fpe_exception PARAMS ((int));
204 static int process_mips_specific PARAMS ((FILE *));
205 static int process_file PARAMS ((char *));
206 static int process_relocs PARAMS ((FILE *));
207 static int process_version_sections PARAMS ((FILE *));
208 static char * get_ver_flags PARAMS ((unsigned int));
209 static int get_32bit_section_headers PARAMS ((FILE *, unsigned int));
210 static int get_64bit_section_headers PARAMS ((FILE *, unsigned int));
211 static int get_32bit_program_headers PARAMS ((FILE *, Elf_Internal_Phdr *));
212 static int get_64bit_program_headers PARAMS ((FILE *, Elf_Internal_Phdr *));
213 static int get_file_header PARAMS ((FILE *));
214 static Elf_Internal_Sym * get_32bit_elf_symbols PARAMS ((FILE *, Elf_Internal_Shdr *));
215 static Elf_Internal_Sym * get_64bit_elf_symbols PARAMS ((FILE *, Elf_Internal_Shdr *));
216 static const char * get_elf_section_flags PARAMS ((bfd_vma));
217 static int * get_dynamic_data PARAMS ((FILE *, unsigned int));
218 static int get_32bit_dynamic_segment PARAMS ((FILE *));
219 static int get_64bit_dynamic_segment PARAMS ((FILE *));
220 #ifdef SUPPORT_DISASSEMBLY
221 static int disassemble_section PARAMS ((Elf32_Internal_Shdr *, FILE *));
222 #endif
223 static int dump_section PARAMS ((Elf32_Internal_Shdr *, FILE *));
224 static int display_debug_section PARAMS ((Elf32_Internal_Shdr *, FILE *));
225 static int display_debug_info PARAMS ((Elf32_Internal_Shdr *, unsigned char *, FILE *));
226 static int display_debug_not_supported PARAMS ((Elf32_Internal_Shdr *, unsigned char *, FILE *));
227 static int prescan_debug_info PARAMS ((Elf32_Internal_Shdr *, unsigned char *, FILE *));
228 static int display_debug_lines PARAMS ((Elf32_Internal_Shdr *, unsigned char *, FILE *));
229 static int display_debug_pubnames PARAMS ((Elf32_Internal_Shdr *, unsigned char *, FILE *));
230 static int display_debug_abbrev PARAMS ((Elf32_Internal_Shdr *, unsigned char *, FILE *));
231 static int display_debug_aranges PARAMS ((Elf32_Internal_Shdr *, unsigned char *, FILE *));
232 static int display_debug_frames PARAMS ((Elf32_Internal_Shdr *, unsigned char *, FILE *));
233 static int display_debug_macinfo PARAMS ((Elf32_Internal_Shdr *, unsigned char *, FILE *));
234 static int display_debug_str PARAMS ((Elf32_Internal_Shdr *, unsigned char *, FILE *));
235 static int display_debug_loc PARAMS ((Elf32_Internal_Shdr *, unsigned char *, FILE *));
236 static unsigned char * process_abbrev_section PARAMS ((unsigned char *, unsigned char *));
237 static void load_debug_str PARAMS ((FILE *));
238 static void free_debug_str PARAMS ((void));
239 static const char * fetch_indirect_string PARAMS ((unsigned long));
240 static void load_debug_loc PARAMS ((FILE *));
241 static void free_debug_loc PARAMS ((void));
242 static unsigned long read_leb128 PARAMS ((unsigned char *, int *, int));
243 static int process_extended_line_op PARAMS ((unsigned char *, int, int));
244 static void reset_state_machine PARAMS ((int));
245 static char * get_TAG_name PARAMS ((unsigned long));
246 static char * get_AT_name PARAMS ((unsigned long));
247 static char * get_FORM_name PARAMS ((unsigned long));
248 static void free_abbrevs PARAMS ((void));
249 static void add_abbrev PARAMS ((unsigned long, unsigned long, int));
250 static void add_abbrev_attr PARAMS ((unsigned long, unsigned long));
251 static unsigned char * read_and_display_attr PARAMS ((unsigned long, unsigned long, unsigned char *, unsigned long, unsigned long));
252 static unsigned char * read_and_display_attr_value PARAMS ((unsigned long, unsigned long, unsigned char *, unsigned long, unsigned long));
253 static unsigned char * display_block PARAMS ((unsigned char *, unsigned long));
254 static void decode_location_expression PARAMS ((unsigned char *, unsigned int, unsigned long));
255 static void request_dump PARAMS ((unsigned int, int));
256 static const char * get_elf_class PARAMS ((unsigned int));
257 static const char * get_data_encoding PARAMS ((unsigned int));
258 static const char * get_osabi_name PARAMS ((unsigned int));
259 static int guess_is_rela PARAMS ((unsigned long));
260 static const char * get_note_type PARAMS ((unsigned int));
261 static const char * get_netbsd_elfcore_note_type PARAMS ((unsigned int));
262 static int process_note PARAMS ((Elf32_Internal_Note *));
263 static int process_corefile_note_segment PARAMS ((FILE *, bfd_vma, bfd_vma));
264 static int process_corefile_note_segments PARAMS ((FILE *));
265 static int process_corefile_contents PARAMS ((FILE *));
266 static int process_arch_specific PARAMS ((FILE *));
267
268 typedef int Elf32_Word;
269
270 #ifndef TRUE
271 #define TRUE 1
272 #define FALSE 0
273 #endif
274 #define UNKNOWN -1
275
276 #define SECTION_NAME(X) ((X) == NULL ? "<none>" : \
277 ((X)->sh_name >= string_table_length \
278 ? "<corrupt>" : string_table + (X)->sh_name))
279
280 /* Given st_shndx I, map to section_headers index. */
281 #define SECTION_HEADER_INDEX(I) \
282 ((I) < SHN_LORESERVE \
283 ? (I) \
284 : ((I) <= SHN_HIRESERVE \
285 ? 0 \
286 : (I) - (SHN_HIRESERVE + 1 - SHN_LORESERVE)))
287
288 /* Reverse of the above. */
289 #define SECTION_HEADER_NUM(N) \
290 ((N) < SHN_LORESERVE \
291 ? (N) \
292 : (N) + (SHN_HIRESERVE + 1 - SHN_LORESERVE))
293
294 #define SECTION_HEADER(I) (section_headers + SECTION_HEADER_INDEX (I))
295
296 #define DT_VERSIONTAGIDX(tag) (DT_VERNEEDNUM - (tag)) /* Reverse order! */
297
298 #define BYTE_GET(field) byte_get (field, sizeof (field))
299
300 /* If we can support a 64 bit data type then BFD64 should be defined
301 and sizeof (bfd_vma) == 8. In this case when translating from an
302 external 8 byte field to an internal field, we can assume that the
303 internal field is also 8 bytes wide and so we can extract all the data.
304 If, however, BFD64 is not defined, then we must assume that the
305 internal data structure only has 4 byte wide fields that are the
306 equivalent of the 8 byte wide external counterparts, and so we must
307 truncate the data. */
308 #ifdef BFD64
309 #define BYTE_GET8(field) byte_get (field, -8)
310 #else
311 #define BYTE_GET8(field) byte_get (field, 8)
312 #endif
313
314 #define NUM_ELEM(array) (sizeof (array) / sizeof ((array)[0]))
315
316 #define GET_ELF_SYMBOLS(file, section) \
317 (is_32bit_elf ? get_32bit_elf_symbols (file, section) \
318 : get_64bit_elf_symbols (file, section))
319
320
321 static void
322 error VPARAMS ((const char *message, ...))
323 {
324 VA_OPEN (args, message);
325 VA_FIXEDARG (args, const char *, message);
326
327 fprintf (stderr, _("%s: Error: "), program_name);
328 vfprintf (stderr, message, args);
329 VA_CLOSE (args);
330 }
331
332 static void
333 warn VPARAMS ((const char *message, ...))
334 {
335 VA_OPEN (args, message);
336 VA_FIXEDARG (args, const char *, message);
337
338 fprintf (stderr, _("%s: Warning: "), program_name);
339 vfprintf (stderr, message, args);
340 VA_CLOSE (args);
341 }
342
343 static PTR get_data PARAMS ((PTR, FILE *, long, size_t, const char *));
344
345 static PTR
346 get_data (var, file, offset, size, reason)
347 PTR var;
348 FILE *file;
349 long offset;
350 size_t size;
351 const char *reason;
352 {
353 PTR mvar;
354
355 if (size == 0)
356 return NULL;
357
358 if (fseek (file, offset, SEEK_SET))
359 {
360 error (_("Unable to seek to %x for %s\n"), offset, reason);
361 return NULL;
362 }
363
364 mvar = var;
365 if (mvar == NULL)
366 {
367 mvar = (PTR) malloc (size);
368
369 if (mvar == NULL)
370 {
371 error (_("Out of memory allocating %d bytes for %s\n"),
372 size, reason);
373 return NULL;
374 }
375 }
376
377 if (fread (mvar, size, 1, file) != 1)
378 {
379 error (_("Unable to read in %d bytes of %s\n"), size, reason);
380 if (mvar != var)
381 free (mvar);
382 return NULL;
383 }
384
385 return mvar;
386 }
387
388 static bfd_vma
389 byte_get_little_endian (field, size)
390 unsigned char * field;
391 int size;
392 {
393 switch (size)
394 {
395 case 1:
396 return * field;
397
398 case 2:
399 return ((unsigned int) (field [0]))
400 | (((unsigned int) (field [1])) << 8);
401
402 #ifndef BFD64
403 case 8:
404 /* We want to extract data from an 8 byte wide field and
405 place it into a 4 byte wide field. Since this is a little
406 endian source we can juts use the 4 byte extraction code. */
407 /* Fall through. */
408 #endif
409 case 4:
410 return ((unsigned long) (field [0]))
411 | (((unsigned long) (field [1])) << 8)
412 | (((unsigned long) (field [2])) << 16)
413 | (((unsigned long) (field [3])) << 24);
414
415 #ifdef BFD64
416 case 8:
417 case -8:
418 /* This is a special case, generated by the BYTE_GET8 macro.
419 It means that we are loading an 8 byte value from a field
420 in an external structure into an 8 byte value in a field
421 in an internal strcuture. */
422 return ((bfd_vma) (field [0]))
423 | (((bfd_vma) (field [1])) << 8)
424 | (((bfd_vma) (field [2])) << 16)
425 | (((bfd_vma) (field [3])) << 24)
426 | (((bfd_vma) (field [4])) << 32)
427 | (((bfd_vma) (field [5])) << 40)
428 | (((bfd_vma) (field [6])) << 48)
429 | (((bfd_vma) (field [7])) << 56);
430 #endif
431 default:
432 error (_("Unhandled data length: %d\n"), size);
433 abort ();
434 }
435 }
436
437 /* Print a VMA value. */
438 static void
439 print_vma (vma, mode)
440 bfd_vma vma;
441 print_mode mode;
442 {
443 #ifdef BFD64
444 if (is_32bit_elf)
445 #endif
446 {
447 switch (mode)
448 {
449 case FULL_HEX: printf ("0x"); /* drop through */
450 case LONG_HEX: printf ("%8.8lx", (unsigned long) vma); break;
451 case PREFIX_HEX: printf ("0x"); /* drop through */
452 case HEX: printf ("%lx", (unsigned long) vma); break;
453 case DEC: printf ("%ld", (unsigned long) vma); break;
454 case DEC_5: printf ("%5ld", (long) vma); break;
455 case UNSIGNED: printf ("%lu", (unsigned long) vma); break;
456 }
457 }
458 #ifdef BFD64
459 else
460 {
461 switch (mode)
462 {
463 case FULL_HEX:
464 printf ("0x");
465 /* drop through */
466
467 case LONG_HEX:
468 printf_vma (vma);
469 break;
470
471 case PREFIX_HEX:
472 printf ("0x");
473 /* drop through */
474
475 case HEX:
476 #if BFD_HOST_64BIT_LONG
477 printf ("%lx", vma);
478 #else
479 if (_bfd_int64_high (vma))
480 printf ("%lx%8.8lx", _bfd_int64_high (vma), _bfd_int64_low (vma));
481 else
482 printf ("%lx", _bfd_int64_low (vma));
483 #endif
484 break;
485
486 case DEC:
487 #if BFD_HOST_64BIT_LONG
488 printf ("%ld", vma);
489 #else
490 if (_bfd_int64_high (vma))
491 /* ugg */
492 printf ("++%ld", _bfd_int64_low (vma));
493 else
494 printf ("%ld", _bfd_int64_low (vma));
495 #endif
496 break;
497
498 case DEC_5:
499 #if BFD_HOST_64BIT_LONG
500 printf ("%5ld", vma);
501 #else
502 if (_bfd_int64_high (vma))
503 /* ugg */
504 printf ("++%ld", _bfd_int64_low (vma));
505 else
506 printf ("%5ld", _bfd_int64_low (vma));
507 #endif
508 break;
509
510 case UNSIGNED:
511 #if BFD_HOST_64BIT_LONG
512 printf ("%lu", vma);
513 #else
514 if (_bfd_int64_high (vma))
515 /* ugg */
516 printf ("++%lu", _bfd_int64_low (vma));
517 else
518 printf ("%lu", _bfd_int64_low (vma));
519 #endif
520 break;
521 }
522 }
523 #endif
524 }
525
526 /* Display a symbol on stdout. If do_wide is not true then
527 format the symbol to be at most WIDTH characters,
528 truhncating as necessary. If WIDTH is negative then
529 format the string to be exactly - WIDTH characters,
530 truncating or padding as necessary. */
531
532 static void
533 print_symbol (width, symbol)
534 int width;
535 char * symbol;
536 {
537 if (do_wide)
538 printf (symbol);
539 else if (width < 0)
540 printf ("%-*.*s", width, width, symbol);
541 else
542 printf ("%-.*s", width, symbol);
543 }
544
545 static bfd_vma
546 byte_get_big_endian (field, size)
547 unsigned char * field;
548 int size;
549 {
550 switch (size)
551 {
552 case 1:
553 return * field;
554
555 case 2:
556 return ((unsigned int) (field [1])) | (((int) (field [0])) << 8);
557
558 case 4:
559 return ((unsigned long) (field [3]))
560 | (((unsigned long) (field [2])) << 8)
561 | (((unsigned long) (field [1])) << 16)
562 | (((unsigned long) (field [0])) << 24);
563
564 #ifndef BFD64
565 case 8:
566 /* Although we are extracing data from an 8 byte wide field, we
567 are returning only 4 bytes of data. */
568 return ((unsigned long) (field [7]))
569 | (((unsigned long) (field [6])) << 8)
570 | (((unsigned long) (field [5])) << 16)
571 | (((unsigned long) (field [4])) << 24);
572 #else
573 case 8:
574 case -8:
575 /* This is a special case, generated by the BYTE_GET8 macro.
576 It means that we are loading an 8 byte value from a field
577 in an external structure into an 8 byte value in a field
578 in an internal strcuture. */
579 return ((bfd_vma) (field [7]))
580 | (((bfd_vma) (field [6])) << 8)
581 | (((bfd_vma) (field [5])) << 16)
582 | (((bfd_vma) (field [4])) << 24)
583 | (((bfd_vma) (field [3])) << 32)
584 | (((bfd_vma) (field [2])) << 40)
585 | (((bfd_vma) (field [1])) << 48)
586 | (((bfd_vma) (field [0])) << 56);
587 #endif
588
589 default:
590 error (_("Unhandled data length: %d\n"), size);
591 abort ();
592 }
593 }
594
595 /* Guess the relocation size commonly used by the specific machines. */
596
597 static int
598 guess_is_rela (e_machine)
599 unsigned long e_machine;
600 {
601 switch (e_machine)
602 {
603 /* Targets that use REL relocations. */
604 case EM_ARM:
605 case EM_386:
606 case EM_486:
607 case EM_960:
608 case EM_DLX:
609 case EM_OPENRISC:
610 case EM_OR32:
611 case EM_M32R:
612 case EM_CYGNUS_M32R:
613 case EM_D10V:
614 case EM_CYGNUS_D10V:
615 case EM_MIPS:
616 case EM_MIPS_RS3_LE:
617 return FALSE;
618
619 /* Targets that use RELA relocations. */
620 case EM_68K:
621 case EM_H8_300:
622 case EM_H8_300H:
623 case EM_H8S:
624 case EM_SPARC32PLUS:
625 case EM_SPARCV9:
626 case EM_SPARC:
627 case EM_PPC:
628 case EM_PPC64:
629 case EM_V850:
630 case EM_CYGNUS_V850:
631 case EM_D30V:
632 case EM_CYGNUS_D30V:
633 case EM_MN10200:
634 case EM_CYGNUS_MN10200:
635 case EM_MN10300:
636 case EM_CYGNUS_MN10300:
637 case EM_FR30:
638 case EM_CYGNUS_FR30:
639 case EM_CYGNUS_FRV:
640 case EM_SH:
641 case EM_ALPHA:
642 case EM_MCORE:
643 case EM_IA_64:
644 case EM_AVR:
645 case EM_AVR_OLD:
646 case EM_CRIS:
647 case EM_860:
648 case EM_X86_64:
649 case EM_S390:
650 case EM_S390_OLD:
651 case EM_MMIX:
652 case EM_XSTORMY16:
653 case EM_VAX:
654 return TRUE;
655
656 case EM_MMA:
657 case EM_PCP:
658 case EM_NCPU:
659 case EM_NDR1:
660 case EM_STARCORE:
661 case EM_ME16:
662 case EM_ST100:
663 case EM_TINYJ:
664 case EM_FX66:
665 case EM_ST9PLUS:
666 case EM_ST7:
667 case EM_68HC16:
668 case EM_68HC11:
669 case EM_68HC08:
670 case EM_68HC05:
671 case EM_SVX:
672 case EM_ST19:
673 default:
674 warn (_("Don't know about relocations on this machine architecture\n"));
675 return FALSE;
676 }
677 }
678
679 static int
680 slurp_rela_relocs (file, rel_offset, rel_size, relasp, nrelasp)
681 FILE *file;
682 unsigned long rel_offset;
683 unsigned long rel_size;
684 Elf_Internal_Rela **relasp;
685 unsigned long *nrelasp;
686 {
687 Elf_Internal_Rela *relas;
688 unsigned long nrelas;
689 unsigned int i;
690
691 if (is_32bit_elf)
692 {
693 Elf32_External_Rela * erelas;
694
695 erelas = (Elf32_External_Rela *) get_data (NULL, file, rel_offset,
696 rel_size, _("relocs"));
697 if (!erelas)
698 return 0;
699
700 nrelas = rel_size / sizeof (Elf32_External_Rela);
701
702 relas = (Elf_Internal_Rela *)
703 malloc (nrelas * sizeof (Elf_Internal_Rela));
704
705 if (relas == NULL)
706 {
707 error(_("out of memory parsing relocs"));
708 return 0;
709 }
710
711 for (i = 0; i < nrelas; i++)
712 {
713 relas[i].r_offset = BYTE_GET (erelas[i].r_offset);
714 relas[i].r_info = BYTE_GET (erelas[i].r_info);
715 relas[i].r_addend = BYTE_GET (erelas[i].r_addend);
716 }
717
718 free (erelas);
719 }
720 else
721 {
722 Elf64_External_Rela * erelas;
723
724 erelas = (Elf64_External_Rela *) get_data (NULL, file, rel_offset,
725 rel_size, _("relocs"));
726 if (!erelas)
727 return 0;
728
729 nrelas = rel_size / sizeof (Elf64_External_Rela);
730
731 relas = (Elf_Internal_Rela *)
732 malloc (nrelas * sizeof (Elf_Internal_Rela));
733
734 if (relas == NULL)
735 {
736 error(_("out of memory parsing relocs"));
737 return 0;
738 }
739
740 for (i = 0; i < nrelas; i++)
741 {
742 relas[i].r_offset = BYTE_GET8 (erelas[i].r_offset);
743 relas[i].r_info = BYTE_GET8 (erelas[i].r_info);
744 relas[i].r_addend = BYTE_GET8 (erelas[i].r_addend);
745 }
746
747 free (erelas);
748 }
749 *relasp = relas;
750 *nrelasp = nrelas;
751 return 1;
752 }
753
754 static int
755 slurp_rel_relocs (file, rel_offset, rel_size, relsp, nrelsp)
756 FILE *file;
757 unsigned long rel_offset;
758 unsigned long rel_size;
759 Elf_Internal_Rel **relsp;
760 unsigned long *nrelsp;
761 {
762 Elf_Internal_Rel *rels;
763 unsigned long nrels;
764 unsigned int i;
765
766 if (is_32bit_elf)
767 {
768 Elf32_External_Rel * erels;
769
770 erels = (Elf32_External_Rel *) get_data (NULL, file, rel_offset,
771 rel_size, _("relocs"));
772 if (!erels)
773 return 0;
774
775 nrels = rel_size / sizeof (Elf32_External_Rel);
776
777 rels = (Elf_Internal_Rel *) malloc (nrels * sizeof (Elf_Internal_Rel));
778
779 if (rels == NULL)
780 {
781 error(_("out of memory parsing relocs"));
782 return 0;
783 }
784
785 for (i = 0; i < nrels; i++)
786 {
787 rels[i].r_offset = BYTE_GET (erels[i].r_offset);
788 rels[i].r_info = BYTE_GET (erels[i].r_info);
789 }
790
791 free (erels);
792 }
793 else
794 {
795 Elf64_External_Rel * erels;
796
797 erels = (Elf64_External_Rel *) get_data (NULL, file, rel_offset,
798 rel_size, _("relocs"));
799 if (!erels)
800 return 0;
801
802 nrels = rel_size / sizeof (Elf64_External_Rel);
803
804 rels = (Elf_Internal_Rel *) malloc (nrels * sizeof (Elf_Internal_Rel));
805
806 if (rels == NULL)
807 {
808 error(_("out of memory parsing relocs"));
809 return 0;
810 }
811
812 for (i = 0; i < nrels; i++)
813 {
814 rels[i].r_offset = BYTE_GET8 (erels[i].r_offset);
815 rels[i].r_info = BYTE_GET8 (erels[i].r_info);
816 }
817
818 free (erels);
819 }
820 *relsp = rels;
821 *nrelsp = nrels;
822 return 1;
823 }
824
825 /* Display the contents of the relocation data found at the specified offset. */
826 static int
827 dump_relocations (file, rel_offset, rel_size, symtab, nsyms, strtab, is_rela)
828 FILE * file;
829 unsigned long rel_offset;
830 unsigned long rel_size;
831 Elf_Internal_Sym * symtab;
832 unsigned long nsyms;
833 char * strtab;
834 int is_rela;
835 {
836 unsigned int i;
837 Elf_Internal_Rel * rels;
838 Elf_Internal_Rela * relas;
839
840
841 if (is_rela == UNKNOWN)
842 is_rela = guess_is_rela (elf_header.e_machine);
843
844 if (is_rela)
845 {
846 if (!slurp_rela_relocs (file, rel_offset, rel_size, &relas, &rel_size))
847 return 0;
848 }
849 else
850 {
851 if (!slurp_rel_relocs (file, rel_offset, rel_size, &rels, &rel_size))
852 return 0;
853 }
854
855 if (is_32bit_elf)
856 {
857 if (is_rela)
858 {
859 if (do_wide)
860 printf (_(" Offset Info Type Sym. Value Symbol's Name + Addend\n"));
861 else
862 printf (_(" Offset Info Type Sym.Value Sym. Name + Addend\n"));
863 }
864 else
865 {
866 if (do_wide)
867 printf (_(" Offset Info Type Sym. Value Symbol's Name\n"));
868 else
869 printf (_(" Offset Info Type Sym.Value Sym. Name\n"));
870 }
871 }
872 else
873 {
874 if (is_rela)
875 {
876 if (do_wide)
877 printf (_(" Offset Info Type Symbol's Value Symbol's Name + Addend\n"));
878 else
879 printf (_(" Offset Info Type Sym. Value Sym. Name + Addend\n"));
880 }
881 else
882 {
883 if (do_wide)
884 printf (_(" Offset Info Type Symbol's Value Symbol's Name\n"));
885 else
886 printf (_(" Offset Info Type Sym. Value Sym. Name\n"));
887 }
888 }
889
890 for (i = 0; i < rel_size; i++)
891 {
892 const char * rtype;
893 const char * rtype2 = NULL;
894 const char * rtype3 = NULL;
895 bfd_vma offset;
896 bfd_vma info;
897 bfd_vma symtab_index;
898 bfd_vma type;
899 bfd_vma type2 = (bfd_vma) NULL;
900 bfd_vma type3 = (bfd_vma) NULL;
901
902 if (is_rela)
903 {
904 offset = relas [i].r_offset;
905 info = relas [i].r_info;
906 }
907 else
908 {
909 offset = rels [i].r_offset;
910 info = rels [i].r_info;
911 }
912
913 if (is_32bit_elf)
914 {
915 type = ELF32_R_TYPE (info);
916 symtab_index = ELF32_R_SYM (info);
917 }
918 else
919 {
920 if (elf_header.e_machine == EM_MIPS)
921 {
922 type = ELF64_MIPS_R_TYPE (info);
923 type2 = ELF64_MIPS_R_TYPE2 (info);
924 type3 = ELF64_MIPS_R_TYPE3 (info);
925 }
926 else if (elf_header.e_machine == EM_SPARCV9)
927 type = ELF64_R_TYPE_ID (info);
928 else
929 type = ELF64_R_TYPE (info);
930 /* The #ifdef BFD64 below is to prevent a compile time warning.
931 We know that if we do not have a 64 bit data type that we
932 will never execute this code anyway. */
933 #ifdef BFD64
934 symtab_index = ELF64_R_SYM (info);
935 #endif
936 }
937
938 if (is_32bit_elf)
939 {
940 #ifdef _bfd_int64_low
941 printf ("%8.8lx %8.8lx ", _bfd_int64_low (offset), _bfd_int64_low (info));
942 #else
943 printf ("%8.8lx %8.8lx ", offset, info);
944 #endif
945 }
946 else
947 {
948 #ifdef _bfd_int64_low
949 printf (do_wide
950 ? "%8.8lx%8.8lx %8.8lx%8.8lx "
951 : "%4.4lx%8.8lx %4.4lx%8.8lx ",
952 _bfd_int64_high (offset),
953 _bfd_int64_low (offset),
954 _bfd_int64_high (info),
955 _bfd_int64_low (info));
956 #else
957 printf (do_wide
958 ? "%16.16lx %16.16lx "
959 : "%12.12lx %12.12lx ",
960 offset, info);
961 #endif
962 }
963
964 switch (elf_header.e_machine)
965 {
966 default:
967 rtype = NULL;
968 break;
969
970 case EM_M32R:
971 case EM_CYGNUS_M32R:
972 rtype = elf_m32r_reloc_type (type);
973 break;
974
975 case EM_386:
976 case EM_486:
977 rtype = elf_i386_reloc_type (type);
978 break;
979
980 case EM_68HC11:
981 case EM_68HC12:
982 rtype = elf_m68hc11_reloc_type (type);
983 break;
984
985 case EM_68K:
986 rtype = elf_m68k_reloc_type (type);
987 break;
988
989 case EM_960:
990 rtype = elf_i960_reloc_type (type);
991 break;
992
993 case EM_AVR:
994 case EM_AVR_OLD:
995 rtype = elf_avr_reloc_type (type);
996 break;
997
998 case EM_OLD_SPARCV9:
999 case EM_SPARC32PLUS:
1000 case EM_SPARCV9:
1001 case EM_SPARC:
1002 rtype = elf_sparc_reloc_type (type);
1003 break;
1004
1005 case EM_V850:
1006 case EM_CYGNUS_V850:
1007 rtype = v850_reloc_type (type);
1008 break;
1009
1010 case EM_D10V:
1011 case EM_CYGNUS_D10V:
1012 rtype = elf_d10v_reloc_type (type);
1013 break;
1014
1015 case EM_D30V:
1016 case EM_CYGNUS_D30V:
1017 rtype = elf_d30v_reloc_type (type);
1018 break;
1019
1020 case EM_DLX:
1021 rtype = elf_dlx_reloc_type (type);
1022 break;
1023
1024 case EM_SH:
1025 rtype = elf_sh_reloc_type (type);
1026 break;
1027
1028 case EM_MN10300:
1029 case EM_CYGNUS_MN10300:
1030 rtype = elf_mn10300_reloc_type (type);
1031 break;
1032
1033 case EM_MN10200:
1034 case EM_CYGNUS_MN10200:
1035 rtype = elf_mn10200_reloc_type (type);
1036 break;
1037
1038 case EM_FR30:
1039 case EM_CYGNUS_FR30:
1040 rtype = elf_fr30_reloc_type (type);
1041 break;
1042
1043 case EM_CYGNUS_FRV:
1044 rtype = elf_frv_reloc_type (type);
1045 break;
1046
1047 case EM_MCORE:
1048 rtype = elf_mcore_reloc_type (type);
1049 break;
1050
1051 case EM_MMIX:
1052 rtype = elf_mmix_reloc_type (type);
1053 break;
1054
1055 case EM_PPC:
1056 case EM_PPC64:
1057 rtype = elf_ppc_reloc_type (type);
1058 break;
1059
1060 case EM_MIPS:
1061 case EM_MIPS_RS3_LE:
1062 rtype = elf_mips_reloc_type (type);
1063 if (!is_32bit_elf)
1064 {
1065 rtype2 = elf_mips_reloc_type (type2);
1066 rtype3 = elf_mips_reloc_type (type3);
1067 }
1068 break;
1069
1070 case EM_ALPHA:
1071 rtype = elf_alpha_reloc_type (type);
1072 break;
1073
1074 case EM_ARM:
1075 rtype = elf_arm_reloc_type (type);
1076 break;
1077
1078 case EM_ARC:
1079 rtype = elf_arc_reloc_type (type);
1080 break;
1081
1082 case EM_PARISC:
1083 rtype = elf_hppa_reloc_type (type);
1084 break;
1085
1086 case EM_H8_300:
1087 case EM_H8_300H:
1088 case EM_H8S:
1089 rtype = elf_h8_reloc_type (type);
1090 break;
1091
1092 case EM_OPENRISC:
1093 case EM_OR32:
1094 rtype = elf_or32_reloc_type (type);
1095 break;
1096
1097 case EM_PJ:
1098 case EM_PJ_OLD:
1099 rtype = elf_pj_reloc_type (type);
1100 break;
1101 case EM_IA_64:
1102 rtype = elf_ia64_reloc_type (type);
1103 break;
1104
1105 case EM_CRIS:
1106 rtype = elf_cris_reloc_type (type);
1107 break;
1108
1109 case EM_860:
1110 rtype = elf_i860_reloc_type (type);
1111 break;
1112
1113 case EM_X86_64:
1114 rtype = elf_x86_64_reloc_type (type);
1115 break;
1116
1117 case EM_S390_OLD:
1118 case EM_S390:
1119 rtype = elf_s390_reloc_type (type);
1120 break;
1121
1122 case EM_XSTORMY16:
1123 rtype = elf_xstormy16_reloc_type (type);
1124 break;
1125
1126 case EM_VAX:
1127 rtype = elf_vax_reloc_type (type);
1128 break;
1129 }
1130
1131 if (rtype == NULL)
1132 #ifdef _bfd_int64_low
1133 printf (_("unrecognized: %-7lx"), _bfd_int64_low (type));
1134 #else
1135 printf (_("unrecognized: %-7lx"), type);
1136 #endif
1137 else
1138 printf (do_wide ? "%-21.21s" : "%-17.17s", rtype);
1139
1140 if (symtab_index)
1141 {
1142 if (symtab == NULL || symtab_index >= nsyms)
1143 printf (" bad symbol index: %08lx", (unsigned long) symtab_index);
1144 else
1145 {
1146 Elf_Internal_Sym * psym;
1147
1148 psym = symtab + symtab_index;
1149
1150 printf (" ");
1151 print_vma (psym->st_value, LONG_HEX);
1152 printf (is_32bit_elf ? " " : " ");
1153
1154 if (psym->st_name == 0)
1155 print_symbol (22, SECTION_NAME (section_headers + psym->st_shndx));
1156 else if (strtab == NULL)
1157 printf (_("<string table index %3ld>"), psym->st_name);
1158 else
1159 print_symbol (22, strtab + psym->st_name);
1160
1161 if (is_rela)
1162 printf (" + %lx", (unsigned long) relas [i].r_addend);
1163 }
1164 }
1165 else if (is_rela)
1166 {
1167 printf ("%*c", is_32bit_elf ? (do_wide ? 34 : 28) : (do_wide ? 26 : 20), ' ');
1168 print_vma (relas[i].r_addend, LONG_HEX);
1169 }
1170
1171 if (elf_header.e_machine == EM_SPARCV9
1172 && !strcmp (rtype, "R_SPARC_OLO10"))
1173 printf (" + %lx", (unsigned long) ELF64_R_TYPE_DATA (info));
1174
1175 putchar ('\n');
1176
1177 if (! is_32bit_elf && elf_header.e_machine == EM_MIPS)
1178 {
1179 printf (" Type2: ");
1180
1181 if (rtype2 == NULL)
1182 #ifdef _bfd_int64_low
1183 printf (_("unrecognized: %-7lx"), _bfd_int64_low (type2));
1184 #else
1185 printf (_("unrecognized: %-7lx"), type2);
1186 #endif
1187 else
1188 printf ("%-17.17s", rtype2);
1189
1190 printf("\n Type3: ");
1191
1192 if (rtype3 == NULL)
1193 #ifdef _bfd_int64_low
1194 printf (_("unrecognized: %-7lx"), _bfd_int64_low (type3));
1195 #else
1196 printf (_("unrecognized: %-7lx"), type3);
1197 #endif
1198 else
1199 printf ("%-17.17s", rtype3);
1200
1201 putchar ('\n');
1202 }
1203 }
1204
1205 if (is_rela)
1206 free (relas);
1207 else
1208 free (rels);
1209
1210 return 1;
1211 }
1212
1213 static const char *
1214 get_mips_dynamic_type (type)
1215 unsigned long type;
1216 {
1217 switch (type)
1218 {
1219 case DT_MIPS_RLD_VERSION: return "MIPS_RLD_VERSION";
1220 case DT_MIPS_TIME_STAMP: return "MIPS_TIME_STAMP";
1221 case DT_MIPS_ICHECKSUM: return "MIPS_ICHECKSUM";
1222 case DT_MIPS_IVERSION: return "MIPS_IVERSION";
1223 case DT_MIPS_FLAGS: return "MIPS_FLAGS";
1224 case DT_MIPS_BASE_ADDRESS: return "MIPS_BASE_ADDRESS";
1225 case DT_MIPS_MSYM: return "MIPS_MSYM";
1226 case DT_MIPS_CONFLICT: return "MIPS_CONFLICT";
1227 case DT_MIPS_LIBLIST: return "MIPS_LIBLIST";
1228 case DT_MIPS_LOCAL_GOTNO: return "MIPS_LOCAL_GOTNO";
1229 case DT_MIPS_CONFLICTNO: return "MIPS_CONFLICTNO";
1230 case DT_MIPS_LIBLISTNO: return "MIPS_LIBLISTNO";
1231 case DT_MIPS_SYMTABNO: return "MIPS_SYMTABNO";
1232 case DT_MIPS_UNREFEXTNO: return "MIPS_UNREFEXTNO";
1233 case DT_MIPS_GOTSYM: return "MIPS_GOTSYM";
1234 case DT_MIPS_HIPAGENO: return "MIPS_HIPAGENO";
1235 case DT_MIPS_RLD_MAP: return "MIPS_RLD_MAP";
1236 case DT_MIPS_DELTA_CLASS: return "MIPS_DELTA_CLASS";
1237 case DT_MIPS_DELTA_CLASS_NO: return "MIPS_DELTA_CLASS_NO";
1238 case DT_MIPS_DELTA_INSTANCE: return "MIPS_DELTA_INSTANCE";
1239 case DT_MIPS_DELTA_INSTANCE_NO: return "MIPS_DELTA_INSTANCE_NO";
1240 case DT_MIPS_DELTA_RELOC: return "MIPS_DELTA_RELOC";
1241 case DT_MIPS_DELTA_RELOC_NO: return "MIPS_DELTA_RELOC_NO";
1242 case DT_MIPS_DELTA_SYM: return "MIPS_DELTA_SYM";
1243 case DT_MIPS_DELTA_SYM_NO: return "MIPS_DELTA_SYM_NO";
1244 case DT_MIPS_DELTA_CLASSSYM: return "MIPS_DELTA_CLASSSYM";
1245 case DT_MIPS_DELTA_CLASSSYM_NO: return "MIPS_DELTA_CLASSSYM_NO";
1246 case DT_MIPS_CXX_FLAGS: return "MIPS_CXX_FLAGS";
1247 case DT_MIPS_PIXIE_INIT: return "MIPS_PIXIE_INIT";
1248 case DT_MIPS_SYMBOL_LIB: return "MIPS_SYMBOL_LIB";
1249 case DT_MIPS_LOCALPAGE_GOTIDX: return "MIPS_LOCALPAGE_GOTIDX";
1250 case DT_MIPS_LOCAL_GOTIDX: return "MIPS_LOCAL_GOTIDX";
1251 case DT_MIPS_HIDDEN_GOTIDX: return "MIPS_HIDDEN_GOTIDX";
1252 case DT_MIPS_PROTECTED_GOTIDX: return "MIPS_PROTECTED_GOTIDX";
1253 case DT_MIPS_OPTIONS: return "MIPS_OPTIONS";
1254 case DT_MIPS_INTERFACE: return "MIPS_INTERFACE";
1255 case DT_MIPS_DYNSTR_ALIGN: return "MIPS_DYNSTR_ALIGN";
1256 case DT_MIPS_INTERFACE_SIZE: return "MIPS_INTERFACE_SIZE";
1257 case DT_MIPS_RLD_TEXT_RESOLVE_ADDR: return "MIPS_RLD_TEXT_RESOLVE_ADDR";
1258 case DT_MIPS_PERF_SUFFIX: return "MIPS_PERF_SUFFIX";
1259 case DT_MIPS_COMPACT_SIZE: return "MIPS_COMPACT_SIZE";
1260 case DT_MIPS_GP_VALUE: return "MIPS_GP_VALUE";
1261 case DT_MIPS_AUX_DYNAMIC: return "MIPS_AUX_DYNAMIC";
1262 default:
1263 return NULL;
1264 }
1265 }
1266
1267 static const char *
1268 get_sparc64_dynamic_type (type)
1269 unsigned long type;
1270 {
1271 switch (type)
1272 {
1273 case DT_SPARC_REGISTER: return "SPARC_REGISTER";
1274 default:
1275 return NULL;
1276 }
1277 }
1278
1279 static const char *
1280 get_ppc64_dynamic_type (type)
1281 unsigned long type;
1282 {
1283 switch (type)
1284 {
1285 case DT_PPC64_GLINK: return "PPC64_GLINK";
1286 case DT_PPC64_OPD: return "PPC64_OPD";
1287 case DT_PPC64_OPDSZ: return "PPC64_OPDSZ";
1288 default:
1289 return NULL;
1290 }
1291 }
1292
1293 static const char *
1294 get_parisc_dynamic_type (type)
1295 unsigned long type;
1296 {
1297 switch (type)
1298 {
1299 case DT_HP_LOAD_MAP: return "HP_LOAD_MAP";
1300 case DT_HP_DLD_FLAGS: return "HP_DLD_FLAGS";
1301 case DT_HP_DLD_HOOK: return "HP_DLD_HOOK";
1302 case DT_HP_UX10_INIT: return "HP_UX10_INIT";
1303 case DT_HP_UX10_INITSZ: return "HP_UX10_INITSZ";
1304 case DT_HP_PREINIT: return "HP_PREINIT";
1305 case DT_HP_PREINITSZ: return "HP_PREINITSZ";
1306 case DT_HP_NEEDED: return "HP_NEEDED";
1307 case DT_HP_TIME_STAMP: return "HP_TIME_STAMP";
1308 case DT_HP_CHECKSUM: return "HP_CHECKSUM";
1309 case DT_HP_GST_SIZE: return "HP_GST_SIZE";
1310 case DT_HP_GST_VERSION: return "HP_GST_VERSION";
1311 case DT_HP_GST_HASHVAL: return "HP_GST_HASHVAL";
1312 default:
1313 return NULL;
1314 }
1315 }
1316
1317 static const char *
1318 get_dynamic_type (type)
1319 unsigned long type;
1320 {
1321 static char buff [32];
1322
1323 switch (type)
1324 {
1325 case DT_NULL: return "NULL";
1326 case DT_NEEDED: return "NEEDED";
1327 case DT_PLTRELSZ: return "PLTRELSZ";
1328 case DT_PLTGOT: return "PLTGOT";
1329 case DT_HASH: return "HASH";
1330 case DT_STRTAB: return "STRTAB";
1331 case DT_SYMTAB: return "SYMTAB";
1332 case DT_RELA: return "RELA";
1333 case DT_RELASZ: return "RELASZ";
1334 case DT_RELAENT: return "RELAENT";
1335 case DT_STRSZ: return "STRSZ";
1336 case DT_SYMENT: return "SYMENT";
1337 case DT_INIT: return "INIT";
1338 case DT_FINI: return "FINI";
1339 case DT_SONAME: return "SONAME";
1340 case DT_RPATH: return "RPATH";
1341 case DT_SYMBOLIC: return "SYMBOLIC";
1342 case DT_REL: return "REL";
1343 case DT_RELSZ: return "RELSZ";
1344 case DT_RELENT: return "RELENT";
1345 case DT_PLTREL: return "PLTREL";
1346 case DT_DEBUG: return "DEBUG";
1347 case DT_TEXTREL: return "TEXTREL";
1348 case DT_JMPREL: return "JMPREL";
1349 case DT_BIND_NOW: return "BIND_NOW";
1350 case DT_INIT_ARRAY: return "INIT_ARRAY";
1351 case DT_FINI_ARRAY: return "FINI_ARRAY";
1352 case DT_INIT_ARRAYSZ: return "INIT_ARRAYSZ";
1353 case DT_FINI_ARRAYSZ: return "FINI_ARRAYSZ";
1354 case DT_RUNPATH: return "RUNPATH";
1355 case DT_FLAGS: return "FLAGS";
1356
1357 case DT_PREINIT_ARRAY: return "PREINIT_ARRAY";
1358 case DT_PREINIT_ARRAYSZ: return "PREINIT_ARRAYSZ";
1359
1360 case DT_CHECKSUM: return "CHECKSUM";
1361 case DT_PLTPADSZ: return "PLTPADSZ";
1362 case DT_MOVEENT: return "MOVEENT";
1363 case DT_MOVESZ: return "MOVESZ";
1364 case DT_FEATURE: return "FEATURE";
1365 case DT_POSFLAG_1: return "POSFLAG_1";
1366 case DT_SYMINSZ: return "SYMINSZ";
1367 case DT_SYMINENT: return "SYMINENT"; /* aka VALRNGHI */
1368
1369 case DT_ADDRRNGLO: return "ADDRRNGLO";
1370 case DT_CONFIG: return "CONFIG";
1371 case DT_DEPAUDIT: return "DEPAUDIT";
1372 case DT_AUDIT: return "AUDIT";
1373 case DT_PLTPAD: return "PLTPAD";
1374 case DT_MOVETAB: return "MOVETAB";
1375 case DT_SYMINFO: return "SYMINFO"; /* aka ADDRRNGHI */
1376
1377 case DT_VERSYM: return "VERSYM";
1378
1379 case DT_RELACOUNT: return "RELACOUNT";
1380 case DT_RELCOUNT: return "RELCOUNT";
1381 case DT_FLAGS_1: return "FLAGS_1";
1382 case DT_VERDEF: return "VERDEF";
1383 case DT_VERDEFNUM: return "VERDEFNUM";
1384 case DT_VERNEED: return "VERNEED";
1385 case DT_VERNEEDNUM: return "VERNEEDNUM";
1386
1387 case DT_AUXILIARY: return "AUXILIARY";
1388 case DT_USED: return "USED";
1389 case DT_FILTER: return "FILTER";
1390
1391 default:
1392 if ((type >= DT_LOPROC) && (type <= DT_HIPROC))
1393 {
1394 const char * result;
1395
1396 switch (elf_header.e_machine)
1397 {
1398 case EM_MIPS:
1399 case EM_MIPS_RS3_LE:
1400 result = get_mips_dynamic_type (type);
1401 break;
1402 case EM_SPARCV9:
1403 result = get_sparc64_dynamic_type (type);
1404 break;
1405 case EM_PPC64:
1406 result = get_ppc64_dynamic_type (type);
1407 break;
1408 default:
1409 result = NULL;
1410 break;
1411 }
1412
1413 if (result != NULL)
1414 return result;
1415
1416 sprintf (buff, _("Processor Specific: %lx"), type);
1417 }
1418 else if ((type >= DT_LOOS) && (type <= DT_HIOS))
1419 {
1420 const char * result;
1421
1422 switch (elf_header.e_machine)
1423 {
1424 case EM_PARISC:
1425 result = get_parisc_dynamic_type (type);
1426 break;
1427 default:
1428 result = NULL;
1429 break;
1430 }
1431
1432 if (result != NULL)
1433 return result;
1434
1435 sprintf (buff, _("Operating System specific: %lx"), type);
1436 }
1437 else
1438 sprintf (buff, _("<unknown>: %lx"), type);
1439
1440 return buff;
1441 }
1442 }
1443
1444 static char *
1445 get_file_type (e_type)
1446 unsigned e_type;
1447 {
1448 static char buff [32];
1449
1450 switch (e_type)
1451 {
1452 case ET_NONE: return _("NONE (None)");
1453 case ET_REL: return _("REL (Relocatable file)");
1454 case ET_EXEC: return _("EXEC (Executable file)");
1455 case ET_DYN: return _("DYN (Shared object file)");
1456 case ET_CORE: return _("CORE (Core file)");
1457
1458 default:
1459 if ((e_type >= ET_LOPROC) && (e_type <= ET_HIPROC))
1460 sprintf (buff, _("Processor Specific: (%x)"), e_type);
1461 else if ((e_type >= ET_LOOS) && (e_type <= ET_HIOS))
1462 sprintf (buff, _("OS Specific: (%x)"), e_type);
1463 else
1464 sprintf (buff, _("<unknown>: %x"), e_type);
1465 return buff;
1466 }
1467 }
1468
1469 static char *
1470 get_machine_name (e_machine)
1471 unsigned e_machine;
1472 {
1473 static char buff [64]; /* XXX */
1474
1475 switch (e_machine)
1476 {
1477 case EM_NONE: return _("None");
1478 case EM_M32: return "WE32100";
1479 case EM_SPARC: return "Sparc";
1480 case EM_386: return "Intel 80386";
1481 case EM_68K: return "MC68000";
1482 case EM_88K: return "MC88000";
1483 case EM_486: return "Intel 80486";
1484 case EM_860: return "Intel 80860";
1485 case EM_MIPS: return "MIPS R3000";
1486 case EM_S370: return "IBM System/370";
1487 case EM_MIPS_RS3_LE: return "MIPS R4000 big-endian";
1488 case EM_OLD_SPARCV9: return "Sparc v9 (old)";
1489 case EM_PARISC: return "HPPA";
1490 case EM_PPC_OLD: return "Power PC (old)";
1491 case EM_SPARC32PLUS: return "Sparc v8+" ;
1492 case EM_960: return "Intel 90860";
1493 case EM_PPC: return "PowerPC";
1494 case EM_PPC64: return "PowerPC64";
1495 case EM_V800: return "NEC V800";
1496 case EM_FR20: return "Fujitsu FR20";
1497 case EM_RH32: return "TRW RH32";
1498 case EM_MCORE: return "MCORE";
1499 case EM_ARM: return "ARM";
1500 case EM_OLD_ALPHA: return "Digital Alpha (old)";
1501 case EM_SH: return "Hitachi SH";
1502 case EM_SPARCV9: return "Sparc v9";
1503 case EM_TRICORE: return "Siemens Tricore";
1504 case EM_ARC: return "ARC";
1505 case EM_H8_300: return "Hitachi H8/300";
1506 case EM_H8_300H: return "Hitachi H8/300H";
1507 case EM_H8S: return "Hitachi H8S";
1508 case EM_H8_500: return "Hitachi H8/500";
1509 case EM_IA_64: return "Intel IA-64";
1510 case EM_MIPS_X: return "Stanford MIPS-X";
1511 case EM_COLDFIRE: return "Motorola Coldfire";
1512 case EM_68HC12: return "Motorola M68HC12";
1513 case EM_ALPHA: return "Alpha";
1514 case EM_CYGNUS_D10V:
1515 case EM_D10V: return "d10v";
1516 case EM_CYGNUS_D30V:
1517 case EM_D30V: return "d30v";
1518 case EM_CYGNUS_M32R:
1519 case EM_M32R: return "Mitsubishi M32r";
1520 case EM_CYGNUS_V850:
1521 case EM_V850: return "NEC v850";
1522 case EM_CYGNUS_MN10300:
1523 case EM_MN10300: return "mn10300";
1524 case EM_CYGNUS_MN10200:
1525 case EM_MN10200: return "mn10200";
1526 case EM_CYGNUS_FR30:
1527 case EM_FR30: return "Fujitsu FR30";
1528 case EM_CYGNUS_FRV: return "Fujitsu FR-V";
1529 case EM_PJ_OLD:
1530 case EM_PJ: return "picoJava";
1531 case EM_MMA: return "Fujitsu Multimedia Accelerator";
1532 case EM_PCP: return "Siemens PCP";
1533 case EM_NCPU: return "Sony nCPU embedded RISC processor";
1534 case EM_NDR1: return "Denso NDR1 microprocesspr";
1535 case EM_STARCORE: return "Motorola Star*Core processor";
1536 case EM_ME16: return "Toyota ME16 processor";
1537 case EM_ST100: return "STMicroelectronics ST100 processor";
1538 case EM_TINYJ: return "Advanced Logic Corp. TinyJ embedded processor";
1539 case EM_FX66: return "Siemens FX66 microcontroller";
1540 case EM_ST9PLUS: return "STMicroelectronics ST9+ 8/16 bit microcontroller";
1541 case EM_ST7: return "STMicroelectronics ST7 8-bit microcontroller";
1542 case EM_68HC16: return "Motorola MC68HC16 Microcontroller";
1543 case EM_68HC11: return "Motorola MC68HC11 Microcontroller";
1544 case EM_68HC08: return "Motorola MC68HC08 Microcontroller";
1545 case EM_68HC05: return "Motorola MC68HC05 Microcontroller";
1546 case EM_SVX: return "Silicon Graphics SVx";
1547 case EM_ST19: return "STMicroelectronics ST19 8-bit microcontroller";
1548 case EM_VAX: return "Digital VAX";
1549 case EM_AVR_OLD:
1550 case EM_AVR: return "Atmel AVR 8-bit microcontroller";
1551 case EM_CRIS: return "Axis Communications 32-bit embedded processor";
1552 case EM_JAVELIN: return "Infineon Technologies 32-bit embedded cpu";
1553 case EM_FIREPATH: return "Element 14 64-bit DSP processor";
1554 case EM_ZSP: return "LSI Logic's 16-bit DSP processor";
1555 case EM_MMIX: return "Donald Knuth's educational 64-bit processor";
1556 case EM_HUANY: return "Harvard Universitys's machine-independent object format";
1557 case EM_PRISM: return "SiTera Prism";
1558 case EM_X86_64: return "Advanced Micro Devices X86-64";
1559 case EM_S390_OLD:
1560 case EM_S390: return "IBM S/390";
1561 case EM_XSTORMY16: return "Sanyo Xstormy16 CPU core";
1562 case EM_OPENRISC:
1563 case EM_OR32: return "OpenRISC";
1564 case EM_DLX: return "OpenDLX";
1565 default:
1566 sprintf (buff, _("<unknown>: %x"), e_machine);
1567 return buff;
1568 }
1569 }
1570
1571 static void
1572 decode_ARM_machine_flags (e_flags, buf)
1573 unsigned e_flags;
1574 char buf[];
1575 {
1576 unsigned eabi;
1577 int unknown = 0;
1578
1579 eabi = EF_ARM_EABI_VERSION (e_flags);
1580 e_flags &= ~ EF_ARM_EABIMASK;
1581
1582 /* Handle "generic" ARM flags. */
1583 if (e_flags & EF_ARM_RELEXEC)
1584 {
1585 strcat (buf, ", relocatable executable");
1586 e_flags &= ~ EF_ARM_RELEXEC;
1587 }
1588
1589 if (e_flags & EF_ARM_HASENTRY)
1590 {
1591 strcat (buf, ", has entry point");
1592 e_flags &= ~ EF_ARM_HASENTRY;
1593 }
1594
1595 /* Now handle EABI specific flags. */
1596 switch (eabi)
1597 {
1598 default:
1599 strcat (buf, ", <unrecognized EABI>");
1600 if (e_flags)
1601 unknown = 1;
1602 break;
1603
1604 case EF_ARM_EABI_VER1:
1605 strcat (buf, ", Version1 EABI");
1606 while (e_flags)
1607 {
1608 unsigned flag;
1609
1610 /* Process flags one bit at a time. */
1611 flag = e_flags & - e_flags;
1612 e_flags &= ~ flag;
1613
1614 switch (flag)
1615 {
1616 case EF_ARM_SYMSARESORTED: /* Conflicts with EF_ARM_INTERWORK. */
1617 strcat (buf, ", sorted symbol tables");
1618 break;
1619
1620 default:
1621 unknown = 1;
1622 break;
1623 }
1624 }
1625 break;
1626
1627 case EF_ARM_EABI_VER2:
1628 strcat (buf, ", Version2 EABI");
1629 while (e_flags)
1630 {
1631 unsigned flag;
1632
1633 /* Process flags one bit at a time. */
1634 flag = e_flags & - e_flags;
1635 e_flags &= ~ flag;
1636
1637 switch (flag)
1638 {
1639 case EF_ARM_SYMSARESORTED: /* Conflicts with EF_ARM_INTERWORK. */
1640 strcat (buf, ", sorted symbol tables");
1641 break;
1642
1643 case EF_ARM_DYNSYMSUSESEGIDX:
1644 strcat (buf, ", dynamic symbols use segment index");
1645 break;
1646
1647 case EF_ARM_MAPSYMSFIRST:
1648 strcat (buf, ", mapping symbols precede others");
1649 break;
1650
1651 default:
1652 unknown = 1;
1653 break;
1654 }
1655 }
1656 break;
1657
1658 case EF_ARM_EABI_UNKNOWN:
1659 strcat (buf, ", GNU EABI");
1660 while (e_flags)
1661 {
1662 unsigned flag;
1663
1664 /* Process flags one bit at a time. */
1665 flag = e_flags & - e_flags;
1666 e_flags &= ~ flag;
1667
1668 switch (flag)
1669 {
1670 case EF_ARM_INTERWORK:
1671 strcat (buf, ", interworking enabled");
1672 break;
1673
1674 case EF_ARM_APCS_26:
1675 strcat (buf, ", uses APCS/26");
1676 break;
1677
1678 case EF_ARM_APCS_FLOAT:
1679 strcat (buf, ", uses APCS/float");
1680 break;
1681
1682 case EF_ARM_PIC:
1683 strcat (buf, ", position independent");
1684 break;
1685
1686 case EF_ARM_ALIGN8:
1687 strcat (buf, ", 8 bit structure alignment");
1688 break;
1689
1690 case EF_ARM_NEW_ABI:
1691 strcat (buf, ", uses new ABI");
1692 break;
1693
1694 case EF_ARM_OLD_ABI:
1695 strcat (buf, ", uses old ABI");
1696 break;
1697
1698 case EF_ARM_SOFT_FLOAT:
1699 strcat (buf, ", software FP");
1700 break;
1701
1702 default:
1703 unknown = 1;
1704 break;
1705 }
1706 }
1707 }
1708
1709 if (unknown)
1710 strcat (buf,", <unknown>");
1711 }
1712
1713 static char *
1714 get_machine_flags (e_flags, e_machine)
1715 unsigned e_flags;
1716 unsigned e_machine;
1717 {
1718 static char buf [1024];
1719
1720 buf[0] = '\0';
1721
1722 if (e_flags)
1723 {
1724 switch (e_machine)
1725 {
1726 default:
1727 break;
1728
1729 case EM_ARM:
1730 decode_ARM_machine_flags (e_flags, buf);
1731 break;
1732
1733 case EM_68K:
1734 if (e_flags & EF_CPU32)
1735 strcat (buf, ", cpu32");
1736 if (e_flags & EF_M68000)
1737 strcat (buf, ", m68000");
1738 break;
1739
1740 case EM_PPC:
1741 if (e_flags & EF_PPC_EMB)
1742 strcat (buf, ", emb");
1743
1744 if (e_flags & EF_PPC_RELOCATABLE)
1745 strcat (buf, ", relocatable");
1746
1747 if (e_flags & EF_PPC_RELOCATABLE_LIB)
1748 strcat (buf, ", relocatable-lib");
1749 break;
1750
1751 case EM_V850:
1752 case EM_CYGNUS_V850:
1753 switch (e_flags & EF_V850_ARCH)
1754 {
1755 case E_V850E_ARCH:
1756 strcat (buf, ", v850e");
1757 break;
1758 case E_V850EA_ARCH:
1759 strcat (buf, ", v850ea");
1760 break;
1761 case E_V850_ARCH:
1762 strcat (buf, ", v850");
1763 break;
1764 default:
1765 strcat (buf, ", unknown v850 architecture variant");
1766 break;
1767 }
1768 break;
1769
1770 case EM_M32R:
1771 case EM_CYGNUS_M32R:
1772 if ((e_flags & EF_M32R_ARCH) == E_M32R_ARCH)
1773 strcat (buf, ", m32r");
1774
1775 break;
1776
1777 case EM_MIPS:
1778 case EM_MIPS_RS3_LE:
1779 if (e_flags & EF_MIPS_NOREORDER)
1780 strcat (buf, ", noreorder");
1781
1782 if (e_flags & EF_MIPS_PIC)
1783 strcat (buf, ", pic");
1784
1785 if (e_flags & EF_MIPS_CPIC)
1786 strcat (buf, ", cpic");
1787
1788 if (e_flags & EF_MIPS_UCODE)
1789 strcat (buf, ", ugen_reserved");
1790
1791 if (e_flags & EF_MIPS_ABI2)
1792 strcat (buf, ", abi2");
1793
1794 if (e_flags & EF_MIPS_OPTIONS_FIRST)
1795 strcat (buf, ", odk first");
1796
1797 if (e_flags & EF_MIPS_32BITMODE)
1798 strcat (buf, ", 32bitmode");
1799
1800 switch ((e_flags & EF_MIPS_MACH))
1801 {
1802 case E_MIPS_MACH_3900: strcat (buf, ", 3900"); break;
1803 case E_MIPS_MACH_4010: strcat (buf, ", 4010"); break;
1804 case E_MIPS_MACH_4100: strcat (buf, ", 4100"); break;
1805 case E_MIPS_MACH_4650: strcat (buf, ", 4650"); break;
1806 case E_MIPS_MACH_4111: strcat (buf, ", 4111"); break;
1807 case E_MIPS_MACH_SB1: strcat (buf, ", sb1"); break;
1808 case 0:
1809 /* We simply ignore the field in this case to avoid confusion:
1810 MIPS ELF does not specify EF_MIPS_MACH, it is a GNU
1811 extension. */
1812 break;
1813 default: strcat (buf, ", unknown CPU"); break;
1814 }
1815
1816 switch ((e_flags & EF_MIPS_ABI))
1817 {
1818 case E_MIPS_ABI_O32: strcat (buf, ", o32"); break;
1819 case E_MIPS_ABI_O64: strcat (buf, ", o64"); break;
1820 case E_MIPS_ABI_EABI32: strcat (buf, ", eabi32"); break;
1821 case E_MIPS_ABI_EABI64: strcat (buf, ", eabi64"); break;
1822 case 0:
1823 /* We simply ignore the field in this case to avoid confusion:
1824 MIPS ELF does not specify EF_MIPS_ABI, it is a GNU extension.
1825 This means it is likely to be an o32 file, but not for
1826 sure. */
1827 break;
1828 default: strcat (buf, ", unknown ABI"); break;
1829 }
1830
1831 if (e_flags & EF_MIPS_ARCH_ASE_MDMX)
1832 strcat (buf, ", mdmx");
1833
1834 if (e_flags & EF_MIPS_ARCH_ASE_M16)
1835 strcat (buf, ", mips16");
1836
1837 switch ((e_flags & EF_MIPS_ARCH))
1838 {
1839 case E_MIPS_ARCH_1: strcat (buf, ", mips1"); break;
1840 case E_MIPS_ARCH_2: strcat (buf, ", mips2"); break;
1841 case E_MIPS_ARCH_3: strcat (buf, ", mips3"); break;
1842 case E_MIPS_ARCH_4: strcat (buf, ", mips4"); break;
1843 case E_MIPS_ARCH_5: strcat (buf, ", mips5"); break;
1844 case E_MIPS_ARCH_32: strcat (buf, ", mips32"); break;
1845 case E_MIPS_ARCH_64: strcat (buf, ", mips64"); break;
1846 default: strcat (buf, ", unknown ISA"); break;
1847 }
1848
1849 break;
1850
1851 case EM_SPARCV9:
1852 if (e_flags & EF_SPARC_32PLUS)
1853 strcat (buf, ", v8+");
1854
1855 if (e_flags & EF_SPARC_SUN_US1)
1856 strcat (buf, ", ultrasparcI");
1857
1858 if (e_flags & EF_SPARC_SUN_US3)
1859 strcat (buf, ", ultrasparcIII");
1860
1861 if (e_flags & EF_SPARC_HAL_R1)
1862 strcat (buf, ", halr1");
1863
1864 if (e_flags & EF_SPARC_LEDATA)
1865 strcat (buf, ", ledata");
1866
1867 if ((e_flags & EF_SPARCV9_MM) == EF_SPARCV9_TSO)
1868 strcat (buf, ", tso");
1869
1870 if ((e_flags & EF_SPARCV9_MM) == EF_SPARCV9_PSO)
1871 strcat (buf, ", pso");
1872
1873 if ((e_flags & EF_SPARCV9_MM) == EF_SPARCV9_RMO)
1874 strcat (buf, ", rmo");
1875 break;
1876
1877 case EM_PARISC:
1878 switch (e_flags & EF_PARISC_ARCH)
1879 {
1880 case EFA_PARISC_1_0:
1881 strcpy (buf, ", PA-RISC 1.0");
1882 break;
1883 case EFA_PARISC_1_1:
1884 strcpy (buf, ", PA-RISC 1.1");
1885 break;
1886 case EFA_PARISC_2_0:
1887 strcpy (buf, ", PA-RISC 2.0");
1888 break;
1889 default:
1890 break;
1891 }
1892 if (e_flags & EF_PARISC_TRAPNIL)
1893 strcat (buf, ", trapnil");
1894 if (e_flags & EF_PARISC_EXT)
1895 strcat (buf, ", ext");
1896 if (e_flags & EF_PARISC_LSB)
1897 strcat (buf, ", lsb");
1898 if (e_flags & EF_PARISC_WIDE)
1899 strcat (buf, ", wide");
1900 if (e_flags & EF_PARISC_NO_KABP)
1901 strcat (buf, ", no kabp");
1902 if (e_flags & EF_PARISC_LAZYSWAP)
1903 strcat (buf, ", lazyswap");
1904 break;
1905
1906 case EM_PJ:
1907 case EM_PJ_OLD:
1908 if ((e_flags & EF_PICOJAVA_NEWCALLS) == EF_PICOJAVA_NEWCALLS)
1909 strcat (buf, ", new calling convention");
1910
1911 if ((e_flags & EF_PICOJAVA_GNUCALLS) == EF_PICOJAVA_GNUCALLS)
1912 strcat (buf, ", gnu calling convention");
1913 break;
1914
1915 case EM_IA_64:
1916 if ((e_flags & EF_IA_64_ABI64))
1917 strcat (buf, ", 64-bit");
1918 else
1919 strcat (buf, ", 32-bit");
1920 if ((e_flags & EF_IA_64_REDUCEDFP))
1921 strcat (buf, ", reduced fp model");
1922 if ((e_flags & EF_IA_64_NOFUNCDESC_CONS_GP))
1923 strcat (buf, ", no function descriptors, constant gp");
1924 else if ((e_flags & EF_IA_64_CONS_GP))
1925 strcat (buf, ", constant gp");
1926 if ((e_flags & EF_IA_64_ABSOLUTE))
1927 strcat (buf, ", absolute");
1928 break;
1929
1930 case EM_VAX:
1931 if ((e_flags & EF_VAX_NONPIC))
1932 strcat (buf, ", non-PIC");
1933 if ((e_flags & EF_VAX_DFLOAT))
1934 strcat (buf, ", D-Float");
1935 if ((e_flags & EF_VAX_GFLOAT))
1936 strcat (buf, ", G-Float");
1937 break;
1938 }
1939 }
1940
1941 return buf;
1942 }
1943
1944 static const char *
1945 get_mips_segment_type (type)
1946 unsigned long type;
1947 {
1948 switch (type)
1949 {
1950 case PT_MIPS_REGINFO:
1951 return "REGINFO";
1952 case PT_MIPS_RTPROC:
1953 return "RTPROC";
1954 case PT_MIPS_OPTIONS:
1955 return "OPTIONS";
1956 default:
1957 break;
1958 }
1959
1960 return NULL;
1961 }
1962
1963 static const char *
1964 get_parisc_segment_type (type)
1965 unsigned long type;
1966 {
1967 switch (type)
1968 {
1969 case PT_HP_TLS: return "HP_TLS";
1970 case PT_HP_CORE_NONE: return "HP_CORE_NONE";
1971 case PT_HP_CORE_VERSION: return "HP_CORE_VERSION";
1972 case PT_HP_CORE_KERNEL: return "HP_CORE_KERNEL";
1973 case PT_HP_CORE_COMM: return "HP_CORE_COMM";
1974 case PT_HP_CORE_PROC: return "HP_CORE_PROC";
1975 case PT_HP_CORE_LOADABLE: return "HP_CORE_LOADABLE";
1976 case PT_HP_CORE_STACK: return "HP_CORE_STACK";
1977 case PT_HP_CORE_SHM: return "HP_CORE_SHM";
1978 case PT_HP_CORE_MMF: return "HP_CORE_MMF";
1979 case PT_HP_PARALLEL: return "HP_PARALLEL";
1980 case PT_HP_FASTBIND: return "HP_FASTBIND";
1981 case PT_PARISC_ARCHEXT: return "PARISC_ARCHEXT";
1982 case PT_PARISC_UNWIND: return "PARISC_UNWIND";
1983 default:
1984 break;
1985 }
1986
1987 return NULL;
1988 }
1989
1990 static const char *
1991 get_ia64_segment_type (type)
1992 unsigned long type;
1993 {
1994 switch (type)
1995 {
1996 case PT_IA_64_ARCHEXT: return "IA_64_ARCHEXT";
1997 case PT_IA_64_UNWIND: return "IA_64_UNWIND";
1998 case PT_HP_TLS: return "HP_TLS";
1999 case PT_IA_64_HP_OPT_ANOT: return "HP_OPT_ANNOT";
2000 case PT_IA_64_HP_HSL_ANOT: return "HP_HSL_ANNOT";
2001 case PT_IA_64_HP_STACK: return "HP_STACK";
2002 default:
2003 break;
2004 }
2005
2006 return NULL;
2007 }
2008
2009 static const char *
2010 get_segment_type (p_type)
2011 unsigned long p_type;
2012 {
2013 static char buff [32];
2014
2015 switch (p_type)
2016 {
2017 case PT_NULL: return "NULL";
2018 case PT_LOAD: return "LOAD";
2019 case PT_DYNAMIC: return "DYNAMIC";
2020 case PT_INTERP: return "INTERP";
2021 case PT_NOTE: return "NOTE";
2022 case PT_SHLIB: return "SHLIB";
2023 case PT_PHDR: return "PHDR";
2024 case PT_TLS: return "TLS";
2025
2026 case PT_GNU_EH_FRAME:
2027 return "GNU_EH_FRAME";
2028
2029 default:
2030 if ((p_type >= PT_LOPROC) && (p_type <= PT_HIPROC))
2031 {
2032 const char * result;
2033
2034 switch (elf_header.e_machine)
2035 {
2036 case EM_MIPS:
2037 case EM_MIPS_RS3_LE:
2038 result = get_mips_segment_type (p_type);
2039 break;
2040 case EM_PARISC:
2041 result = get_parisc_segment_type (p_type);
2042 break;
2043 case EM_IA_64:
2044 result = get_ia64_segment_type (p_type);
2045 break;
2046 default:
2047 result = NULL;
2048 break;
2049 }
2050
2051 if (result != NULL)
2052 return result;
2053
2054 sprintf (buff, "LOPROC+%lx", p_type - PT_LOPROC);
2055 }
2056 else if ((p_type >= PT_LOOS) && (p_type <= PT_HIOS))
2057 {
2058 const char * result;
2059
2060 switch (elf_header.e_machine)
2061 {
2062 case EM_PARISC:
2063 result = get_parisc_segment_type (p_type);
2064 break;
2065 case EM_IA_64:
2066 result = get_ia64_segment_type (p_type);
2067 break;
2068 default:
2069 result = NULL;
2070 break;
2071 }
2072
2073 if (result != NULL)
2074 return result;
2075
2076 sprintf (buff, "LOOS+%lx", p_type - PT_LOOS);
2077 }
2078 else
2079 sprintf (buff, _("<unknown>: %lx"), p_type);
2080
2081 return buff;
2082 }
2083 }
2084
2085 static const char *
2086 get_mips_section_type_name (sh_type)
2087 unsigned int sh_type;
2088 {
2089 switch (sh_type)
2090 {
2091 case SHT_MIPS_LIBLIST: return "MIPS_LIBLIST";
2092 case SHT_MIPS_MSYM: return "MIPS_MSYM";
2093 case SHT_MIPS_CONFLICT: return "MIPS_CONFLICT";
2094 case SHT_MIPS_GPTAB: return "MIPS_GPTAB";
2095 case SHT_MIPS_UCODE: return "MIPS_UCODE";
2096 case SHT_MIPS_DEBUG: return "MIPS_DEBUG";
2097 case SHT_MIPS_REGINFO: return "MIPS_REGINFO";
2098 case SHT_MIPS_PACKAGE: return "MIPS_PACKAGE";
2099 case SHT_MIPS_PACKSYM: return "MIPS_PACKSYM";
2100 case SHT_MIPS_RELD: return "MIPS_RELD";
2101 case SHT_MIPS_IFACE: return "MIPS_IFACE";
2102 case SHT_MIPS_CONTENT: return "MIPS_CONTENT";
2103 case SHT_MIPS_OPTIONS: return "MIPS_OPTIONS";
2104 case SHT_MIPS_SHDR: return "MIPS_SHDR";
2105 case SHT_MIPS_FDESC: return "MIPS_FDESC";
2106 case SHT_MIPS_EXTSYM: return "MIPS_EXTSYM";
2107 case SHT_MIPS_DENSE: return "MIPS_DENSE";
2108 case SHT_MIPS_PDESC: return "MIPS_PDESC";
2109 case SHT_MIPS_LOCSYM: return "MIPS_LOCSYM";
2110 case SHT_MIPS_AUXSYM: return "MIPS_AUXSYM";
2111 case SHT_MIPS_OPTSYM: return "MIPS_OPTSYM";
2112 case SHT_MIPS_LOCSTR: return "MIPS_LOCSTR";
2113 case SHT_MIPS_LINE: return "MIPS_LINE";
2114 case SHT_MIPS_RFDESC: return "MIPS_RFDESC";
2115 case SHT_MIPS_DELTASYM: return "MIPS_DELTASYM";
2116 case SHT_MIPS_DELTAINST: return "MIPS_DELTAINST";
2117 case SHT_MIPS_DELTACLASS: return "MIPS_DELTACLASS";
2118 case SHT_MIPS_DWARF: return "MIPS_DWARF";
2119 case SHT_MIPS_DELTADECL: return "MIPS_DELTADECL";
2120 case SHT_MIPS_SYMBOL_LIB: return "MIPS_SYMBOL_LIB";
2121 case SHT_MIPS_EVENTS: return "MIPS_EVENTS";
2122 case SHT_MIPS_TRANSLATE: return "MIPS_TRANSLATE";
2123 case SHT_MIPS_PIXIE: return "MIPS_PIXIE";
2124 case SHT_MIPS_XLATE: return "MIPS_XLATE";
2125 case SHT_MIPS_XLATE_DEBUG: return "MIPS_XLATE_DEBUG";
2126 case SHT_MIPS_WHIRL: return "MIPS_WHIRL";
2127 case SHT_MIPS_EH_REGION: return "MIPS_EH_REGION";
2128 case SHT_MIPS_XLATE_OLD: return "MIPS_XLATE_OLD";
2129 case SHT_MIPS_PDR_EXCEPTION: return "MIPS_PDR_EXCEPTION";
2130 default:
2131 break;
2132 }
2133 return NULL;
2134 }
2135
2136 static const char *
2137 get_parisc_section_type_name (sh_type)
2138 unsigned int sh_type;
2139 {
2140 switch (sh_type)
2141 {
2142 case SHT_PARISC_EXT: return "PARISC_EXT";
2143 case SHT_PARISC_UNWIND: return "PARISC_UNWIND";
2144 case SHT_PARISC_DOC: return "PARISC_DOC";
2145 default:
2146 break;
2147 }
2148 return NULL;
2149 }
2150
2151 static const char *
2152 get_ia64_section_type_name (sh_type)
2153 unsigned int sh_type;
2154 {
2155 switch (sh_type)
2156 {
2157 case SHT_IA_64_EXT: return "IA_64_EXT";
2158 case SHT_IA_64_UNWIND: return "IA_64_UNWIND";
2159 default:
2160 break;
2161 }
2162 return NULL;
2163 }
2164
2165 static const char *
2166 get_section_type_name (sh_type)
2167 unsigned int sh_type;
2168 {
2169 static char buff [32];
2170
2171 switch (sh_type)
2172 {
2173 case SHT_NULL: return "NULL";
2174 case SHT_PROGBITS: return "PROGBITS";
2175 case SHT_SYMTAB: return "SYMTAB";
2176 case SHT_STRTAB: return "STRTAB";
2177 case SHT_RELA: return "RELA";
2178 case SHT_HASH: return "HASH";
2179 case SHT_DYNAMIC: return "DYNAMIC";
2180 case SHT_NOTE: return "NOTE";
2181 case SHT_NOBITS: return "NOBITS";
2182 case SHT_REL: return "REL";
2183 case SHT_SHLIB: return "SHLIB";
2184 case SHT_DYNSYM: return "DYNSYM";
2185 case SHT_INIT_ARRAY: return "INIT_ARRAY";
2186 case SHT_FINI_ARRAY: return "FINI_ARRAY";
2187 case SHT_PREINIT_ARRAY: return "PREINIT_ARRAY";
2188 case SHT_GROUP: return "GROUP";
2189 case SHT_SYMTAB_SHNDX: return "SYMTAB SECTION INDICIES";
2190 case SHT_GNU_verdef: return "VERDEF";
2191 case SHT_GNU_verneed: return "VERNEED";
2192 case SHT_GNU_versym: return "VERSYM";
2193 case 0x6ffffff0: return "VERSYM";
2194 case 0x6ffffffc: return "VERDEF";
2195 case 0x7ffffffd: return "AUXILIARY";
2196 case 0x7fffffff: return "FILTER";
2197
2198 default:
2199 if ((sh_type >= SHT_LOPROC) && (sh_type <= SHT_HIPROC))
2200 {
2201 const char * result;
2202
2203 switch (elf_header.e_machine)
2204 {
2205 case EM_MIPS:
2206 case EM_MIPS_RS3_LE:
2207 result = get_mips_section_type_name (sh_type);
2208 break;
2209 case EM_PARISC:
2210 result = get_parisc_section_type_name (sh_type);
2211 break;
2212 case EM_IA_64:
2213 result = get_ia64_section_type_name (sh_type);
2214 break;
2215 default:
2216 result = NULL;
2217 break;
2218 }
2219
2220 if (result != NULL)
2221 return result;
2222
2223 sprintf (buff, "LOPROC+%x", sh_type - SHT_LOPROC);
2224 }
2225 else if ((sh_type >= SHT_LOOS) && (sh_type <= SHT_HIOS))
2226 sprintf (buff, "LOOS+%x", sh_type - SHT_LOOS);
2227 else if ((sh_type >= SHT_LOUSER) && (sh_type <= SHT_HIUSER))
2228 sprintf (buff, "LOUSER+%x", sh_type - SHT_LOUSER);
2229 else
2230 sprintf (buff, _("<unknown>: %x"), sh_type);
2231
2232 return buff;
2233 }
2234 }
2235
2236 struct option options [] =
2237 {
2238 {"all", no_argument, 0, 'a'},
2239 {"file-header", no_argument, 0, 'h'},
2240 {"program-headers", no_argument, 0, 'l'},
2241 {"headers", no_argument, 0, 'e'},
2242 {"histogram", no_argument, 0, 'I'},
2243 {"segments", no_argument, 0, 'l'},
2244 {"sections", no_argument, 0, 'S'},
2245 {"section-headers", no_argument, 0, 'S'},
2246 {"symbols", no_argument, 0, 's'},
2247 {"syms", no_argument, 0, 's'},
2248 {"relocs", no_argument, 0, 'r'},
2249 {"notes", no_argument, 0, 'n'},
2250 {"dynamic", no_argument, 0, 'd'},
2251 {"arch-specific", no_argument, 0, 'A'},
2252 {"version-info", no_argument, 0, 'V'},
2253 {"use-dynamic", no_argument, 0, 'D'},
2254 {"hex-dump", required_argument, 0, 'x'},
2255 {"debug-dump", optional_argument, 0, 'w'},
2256 {"unwind", no_argument, 0, 'u'},
2257 #ifdef SUPPORT_DISASSEMBLY
2258 {"instruction-dump", required_argument, 0, 'i'},
2259 #endif
2260
2261 {"version", no_argument, 0, 'v'},
2262 {"wide", no_argument, 0, 'W'},
2263 {"help", no_argument, 0, 'H'},
2264 {0, no_argument, 0, 0}
2265 };
2266
2267 static void
2268 usage ()
2269 {
2270 fprintf (stdout, _("Usage: readelf <option(s)> elf-file(s)\n"));
2271 fprintf (stdout, _(" Display information about the contents of ELF format files\n"));
2272 fprintf (stdout, _(" Options are:\n\
2273 -a --all Equivalent to: -h -l -S -s -r -d -V -A -I\n\
2274 -h --file-header Display the ELF file header\n\
2275 -l --program-headers Display the program headers\n\
2276 --segments An alias for --program-headers\n\
2277 -S --section-headers Display the sections' header\n\
2278 --sections An alias for --section-headers\n\
2279 -e --headers Equivalent to: -h -l -S\n\
2280 -s --syms Display the symbol table\n\
2281 --symbols An alias for --syms\n\
2282 -n --notes Display the core notes (if present)\n\
2283 -r --relocs Display the relocations (if present)\n\
2284 -u --unwind Display the unwind info (if present)\n\
2285 -d --dynamic Display the dynamic segment (if present)\n\
2286 -V --version-info Display the version sections (if present)\n\
2287 -A --arch-specific Display architecture specific information (if any).\n\
2288 -D --use-dynamic Use the dynamic section info when displaying symbols\n\
2289 -x --hex-dump=<number> Dump the contents of section <number>\n\
2290 -w --debug-dump[=line,=info,=abbrev,=pubnames,=ranges,=macro,=frames,=str,=loc]\n\
2291 Display the contents of DWARF2 debug sections\n"));
2292 #ifdef SUPPORT_DISASSEMBLY
2293 fprintf (stdout, _("\
2294 -i --instruction-dump=<number>\n\
2295 Disassemble the contents of section <number>\n"));
2296 #endif
2297 fprintf (stdout, _("\
2298 -I --histogram Display histogram of bucket list lengths\n\
2299 -W --wide Allow output width to exceed 80 characters\n\
2300 -H --help Display this information\n\
2301 -v --version Display the version number of readelf\n"));
2302 fprintf (stdout, _("Report bugs to %s\n"), REPORT_BUGS_TO);
2303
2304 exit (0);
2305 }
2306
2307 static void
2308 request_dump (section, type)
2309 unsigned int section;
2310 int type;
2311 {
2312 if (section >= num_dump_sects)
2313 {
2314 char * new_dump_sects;
2315
2316 new_dump_sects = (char *) calloc (section + 1, 1);
2317
2318 if (new_dump_sects == NULL)
2319 error (_("Out of memory allocating dump request table."));
2320 else
2321 {
2322 /* Copy current flag settings. */
2323 memcpy (new_dump_sects, dump_sects, num_dump_sects);
2324
2325 free (dump_sects);
2326
2327 dump_sects = new_dump_sects;
2328 num_dump_sects = section + 1;
2329 }
2330 }
2331
2332 if (dump_sects)
2333 dump_sects [section] |= type;
2334
2335 return;
2336 }
2337
2338 static void
2339 parse_args (argc, argv)
2340 int argc;
2341 char ** argv;
2342 {
2343 int c;
2344
2345 if (argc < 2)
2346 usage ();
2347
2348 while ((c = getopt_long
2349 (argc, argv, "ersuahnldSDAIw::x:i:vVW", options, NULL)) != EOF)
2350 {
2351 char * cp;
2352 int section;
2353
2354 switch (c)
2355 {
2356 case 0:
2357 /* Long options. */
2358 break;
2359 case 'H':
2360 usage ();
2361 break;
2362
2363 case 'a':
2364 do_syms ++;
2365 do_reloc ++;
2366 do_unwind ++;
2367 do_dynamic ++;
2368 do_header ++;
2369 do_sections ++;
2370 do_segments ++;
2371 do_version ++;
2372 do_histogram ++;
2373 do_arch ++;
2374 do_notes ++;
2375 break;
2376 case 'e':
2377 do_header ++;
2378 do_sections ++;
2379 do_segments ++;
2380 break;
2381 case 'A':
2382 do_arch ++;
2383 break;
2384 case 'D':
2385 do_using_dynamic ++;
2386 break;
2387 case 'r':
2388 do_reloc ++;
2389 break;
2390 case 'u':
2391 do_unwind ++;
2392 break;
2393 case 'h':
2394 do_header ++;
2395 break;
2396 case 'l':
2397 do_segments ++;
2398 break;
2399 case 's':
2400 do_syms ++;
2401 break;
2402 case 'S':
2403 do_sections ++;
2404 break;
2405 case 'd':
2406 do_dynamic ++;
2407 break;
2408 case 'I':
2409 do_histogram ++;
2410 break;
2411 case 'n':
2412 do_notes ++;
2413 break;
2414 case 'x':
2415 do_dump ++;
2416 section = strtoul (optarg, & cp, 0);
2417 if (! * cp && section >= 0)
2418 {
2419 request_dump (section, HEX_DUMP);
2420 break;
2421 }
2422 goto oops;
2423 case 'w':
2424 do_dump ++;
2425 if (optarg == 0)
2426 do_debugging = 1;
2427 else
2428 {
2429 unsigned int index = 0;
2430
2431 do_debugging = 0;
2432
2433 while (optarg[index])
2434 switch (optarg[index++])
2435 {
2436 case 'i':
2437 case 'I':
2438 do_debug_info = 1;
2439 break;
2440
2441 case 'a':
2442 case 'A':
2443 do_debug_abbrevs = 1;
2444 break;
2445
2446 case 'l':
2447 case 'L':
2448 do_debug_lines = 1;
2449 break;
2450
2451 case 'p':
2452 case 'P':
2453 do_debug_pubnames = 1;
2454 break;
2455
2456 case 'r':
2457 case 'R':
2458 do_debug_aranges = 1;
2459 break;
2460
2461 case 'F':
2462 do_debug_frames_interp = 1;
2463 case 'f':
2464 do_debug_frames = 1;
2465 break;
2466
2467 case 'm':
2468 case 'M':
2469 do_debug_macinfo = 1;
2470 break;
2471
2472 case 's':
2473 case 'S':
2474 do_debug_str = 1;
2475 break;
2476
2477 case 'o':
2478 case 'O':
2479 do_debug_loc = 1;
2480 break;
2481
2482 default:
2483 warn (_("Unrecognized debug option '%s'\n"), optarg);
2484 break;
2485 }
2486 }
2487 break;
2488 #ifdef SUPPORT_DISASSEMBLY
2489 case 'i':
2490 do_dump ++;
2491 section = strtoul (optarg, & cp, 0);
2492 if (! * cp && section >= 0)
2493 {
2494 request_dump (section, DISASS_DUMP);
2495 break;
2496 }
2497 goto oops;
2498 #endif
2499 case 'v':
2500 print_version (program_name);
2501 break;
2502 case 'V':
2503 do_version ++;
2504 break;
2505 case 'W':
2506 do_wide ++;
2507 break;
2508 default:
2509 oops:
2510 /* xgettext:c-format */
2511 error (_("Invalid option '-%c'\n"), c);
2512 /* Drop through. */
2513 case '?':
2514 usage ();
2515 }
2516 }
2517
2518 if (!do_dynamic && !do_syms && !do_reloc && !do_unwind && !do_sections
2519 && !do_segments && !do_header && !do_dump && !do_version
2520 && !do_histogram && !do_debugging && !do_arch && !do_notes)
2521 usage ();
2522 else if (argc < 3)
2523 {
2524 warn (_("Nothing to do.\n"));
2525 usage();
2526 }
2527 }
2528
2529 static const char *
2530 get_elf_class (elf_class)
2531 unsigned int elf_class;
2532 {
2533 static char buff [32];
2534
2535 switch (elf_class)
2536 {
2537 case ELFCLASSNONE: return _("none");
2538 case ELFCLASS32: return "ELF32";
2539 case ELFCLASS64: return "ELF64";
2540 default:
2541 sprintf (buff, _("<unknown: %x>"), elf_class);
2542 return buff;
2543 }
2544 }
2545
2546 static const char *
2547 get_data_encoding (encoding)
2548 unsigned int encoding;
2549 {
2550 static char buff [32];
2551
2552 switch (encoding)
2553 {
2554 case ELFDATANONE: return _("none");
2555 case ELFDATA2LSB: return _("2's complement, little endian");
2556 case ELFDATA2MSB: return _("2's complement, big endian");
2557 default:
2558 sprintf (buff, _("<unknown: %x>"), encoding);
2559 return buff;
2560 }
2561 }
2562
2563 static const char *
2564 get_osabi_name (osabi)
2565 unsigned int osabi;
2566 {
2567 static char buff [32];
2568
2569 switch (osabi)
2570 {
2571 case ELFOSABI_NONE: return "UNIX - System V";
2572 case ELFOSABI_HPUX: return "UNIX - HP-UX";
2573 case ELFOSABI_NETBSD: return "UNIX - NetBSD";
2574 case ELFOSABI_LINUX: return "UNIX - Linux";
2575 case ELFOSABI_HURD: return "GNU/Hurd";
2576 case ELFOSABI_SOLARIS: return "UNIX - Solaris";
2577 case ELFOSABI_AIX: return "UNIX - AIX";
2578 case ELFOSABI_IRIX: return "UNIX - IRIX";
2579 case ELFOSABI_FREEBSD: return "UNIX - FreeBSD";
2580 case ELFOSABI_TRU64: return "UNIX - TRU64";
2581 case ELFOSABI_MODESTO: return "Novell - Modesto";
2582 case ELFOSABI_OPENBSD: return "UNIX - OpenBSD";
2583 case ELFOSABI_STANDALONE: return _("Standalone App");
2584 case ELFOSABI_ARM: return "ARM";
2585 default:
2586 sprintf (buff, _("<unknown: %x>"), osabi);
2587 return buff;
2588 }
2589 }
2590
2591 /* Decode the data held in 'elf_header'. */
2592 static int
2593 process_file_header ()
2594 {
2595 if ( elf_header.e_ident [EI_MAG0] != ELFMAG0
2596 || elf_header.e_ident [EI_MAG1] != ELFMAG1
2597 || elf_header.e_ident [EI_MAG2] != ELFMAG2
2598 || elf_header.e_ident [EI_MAG3] != ELFMAG3)
2599 {
2600 error
2601 (_("Not an ELF file - it has the wrong magic bytes at the start\n"));
2602 return 0;
2603 }
2604
2605 if (do_header)
2606 {
2607 int i;
2608
2609 printf (_("ELF Header:\n"));
2610 printf (_(" Magic: "));
2611 for (i = 0; i < EI_NIDENT; i ++)
2612 printf ("%2.2x ", elf_header.e_ident [i]);
2613 printf ("\n");
2614 printf (_(" Class: %s\n"),
2615 get_elf_class (elf_header.e_ident [EI_CLASS]));
2616 printf (_(" Data: %s\n"),
2617 get_data_encoding (elf_header.e_ident [EI_DATA]));
2618 printf (_(" Version: %d %s\n"),
2619 elf_header.e_ident [EI_VERSION],
2620 (elf_header.e_ident [EI_VERSION] == EV_CURRENT
2621 ? "(current)"
2622 : (elf_header.e_ident [EI_VERSION] != EV_NONE
2623 ? "<unknown: %lx>"
2624 : "")));
2625 printf (_(" OS/ABI: %s\n"),
2626 get_osabi_name (elf_header.e_ident [EI_OSABI]));
2627 printf (_(" ABI Version: %d\n"),
2628 elf_header.e_ident [EI_ABIVERSION]);
2629 printf (_(" Type: %s\n"),
2630 get_file_type (elf_header.e_type));
2631 printf (_(" Machine: %s\n"),
2632 get_machine_name (elf_header.e_machine));
2633 printf (_(" Version: 0x%lx\n"),
2634 (unsigned long) elf_header.e_version);
2635
2636 printf (_(" Entry point address: "));
2637 print_vma ((bfd_vma) elf_header.e_entry, PREFIX_HEX);
2638 printf (_("\n Start of program headers: "));
2639 print_vma ((bfd_vma) elf_header.e_phoff, DEC);
2640 printf (_(" (bytes into file)\n Start of section headers: "));
2641 print_vma ((bfd_vma) elf_header.e_shoff, DEC);
2642 printf (_(" (bytes into file)\n"));
2643
2644 printf (_(" Flags: 0x%lx%s\n"),
2645 (unsigned long) elf_header.e_flags,
2646 get_machine_flags (elf_header.e_flags, elf_header.e_machine));
2647 printf (_(" Size of this header: %ld (bytes)\n"),
2648 (long) elf_header.e_ehsize);
2649 printf (_(" Size of program headers: %ld (bytes)\n"),
2650 (long) elf_header.e_phentsize);
2651 printf (_(" Number of program headers: %ld\n"),
2652 (long) elf_header.e_phnum);
2653 printf (_(" Size of section headers: %ld (bytes)\n"),
2654 (long) elf_header.e_shentsize);
2655 printf (_(" Number of section headers: %ld"),
2656 (long) elf_header.e_shnum);
2657 if (section_headers != NULL && elf_header.e_shnum == 0)
2658 printf (" (%ld)", (long) section_headers[0].sh_size);
2659 putc ('\n', stdout);
2660 printf (_(" Section header string table index: %ld"),
2661 (long) elf_header.e_shstrndx);
2662 if (section_headers != NULL && elf_header.e_shstrndx == SHN_XINDEX)
2663 printf (" (%ld)", (long) section_headers[0].sh_link);
2664 putc ('\n', stdout);
2665 }
2666
2667 if (section_headers != NULL)
2668 {
2669 if (elf_header.e_shnum == 0)
2670 elf_header.e_shnum = section_headers[0].sh_size;
2671 if (elf_header.e_shstrndx == SHN_XINDEX)
2672 elf_header.e_shstrndx = section_headers[0].sh_link;
2673 free (section_headers);
2674 section_headers = NULL;
2675 }
2676
2677 return 1;
2678 }
2679
2680
2681 static int
2682 get_32bit_program_headers (file, program_headers)
2683 FILE * file;
2684 Elf_Internal_Phdr * program_headers;
2685 {
2686 Elf32_External_Phdr * phdrs;
2687 Elf32_External_Phdr * external;
2688 Elf32_Internal_Phdr * internal;
2689 unsigned int i;
2690
2691 phdrs = ((Elf32_External_Phdr *)
2692 get_data (NULL, file, elf_header.e_phoff,
2693 elf_header.e_phentsize * elf_header.e_phnum,
2694 _("program headers")));
2695 if (!phdrs)
2696 return 0;
2697
2698 for (i = 0, internal = program_headers, external = phdrs;
2699 i < elf_header.e_phnum;
2700 i ++, internal ++, external ++)
2701 {
2702 internal->p_type = BYTE_GET (external->p_type);
2703 internal->p_offset = BYTE_GET (external->p_offset);
2704 internal->p_vaddr = BYTE_GET (external->p_vaddr);
2705 internal->p_paddr = BYTE_GET (external->p_paddr);
2706 internal->p_filesz = BYTE_GET (external->p_filesz);
2707 internal->p_memsz = BYTE_GET (external->p_memsz);
2708 internal->p_flags = BYTE_GET (external->p_flags);
2709 internal->p_align = BYTE_GET (external->p_align);
2710 }
2711
2712 free (phdrs);
2713
2714 return 1;
2715 }
2716
2717 static int
2718 get_64bit_program_headers (file, program_headers)
2719 FILE * file;
2720 Elf_Internal_Phdr * program_headers;
2721 {
2722 Elf64_External_Phdr * phdrs;
2723 Elf64_External_Phdr * external;
2724 Elf64_Internal_Phdr * internal;
2725 unsigned int i;
2726
2727 phdrs = ((Elf64_External_Phdr *)
2728 get_data (NULL, file, elf_header.e_phoff,
2729 elf_header.e_phentsize * elf_header.e_phnum,
2730 _("program headers")));
2731 if (!phdrs)
2732 return 0;
2733
2734 for (i = 0, internal = program_headers, external = phdrs;
2735 i < elf_header.e_phnum;
2736 i ++, internal ++, external ++)
2737 {
2738 internal->p_type = BYTE_GET (external->p_type);
2739 internal->p_flags = BYTE_GET (external->p_flags);
2740 internal->p_offset = BYTE_GET8 (external->p_offset);
2741 internal->p_vaddr = BYTE_GET8 (external->p_vaddr);
2742 internal->p_paddr = BYTE_GET8 (external->p_paddr);
2743 internal->p_filesz = BYTE_GET8 (external->p_filesz);
2744 internal->p_memsz = BYTE_GET8 (external->p_memsz);
2745 internal->p_align = BYTE_GET8 (external->p_align);
2746 }
2747
2748 free (phdrs);
2749
2750 return 1;
2751 }
2752
2753 static int
2754 process_program_headers (file)
2755 FILE * file;
2756 {
2757 Elf_Internal_Phdr * program_headers;
2758 Elf_Internal_Phdr * segment;
2759 unsigned int i;
2760
2761 if (elf_header.e_phnum == 0)
2762 {
2763 if (do_segments)
2764 printf (_("\nThere are no program headers in this file.\n"));
2765 return 1;
2766 }
2767
2768 if (do_segments && !do_header)
2769 {
2770 printf (_("\nElf file type is %s\n"), get_file_type (elf_header.e_type));
2771 printf (_("Entry point "));
2772 print_vma ((bfd_vma) elf_header.e_entry, PREFIX_HEX);
2773 printf (_("\nThere are %d program headers, starting at offset "),
2774 elf_header.e_phnum);
2775 print_vma ((bfd_vma) elf_header.e_phoff, DEC);
2776 printf ("\n");
2777 }
2778
2779 program_headers = (Elf_Internal_Phdr *) malloc
2780 (elf_header.e_phnum * sizeof (Elf_Internal_Phdr));
2781
2782 if (program_headers == NULL)
2783 {
2784 error (_("Out of memory\n"));
2785 return 0;
2786 }
2787
2788 if (is_32bit_elf)
2789 i = get_32bit_program_headers (file, program_headers);
2790 else
2791 i = get_64bit_program_headers (file, program_headers);
2792
2793 if (i == 0)
2794 {
2795 free (program_headers);
2796 return 0;
2797 }
2798
2799 if (do_segments)
2800 {
2801 if (elf_header.e_phnum > 1)
2802 printf (_("\nProgram Headers:\n"));
2803 else
2804 printf (_("\nProgram Headers:\n"));
2805
2806 if (is_32bit_elf)
2807 printf
2808 (_(" Type Offset VirtAddr PhysAddr FileSiz MemSiz Flg Align\n"));
2809 else if (do_wide)
2810 printf
2811 (_(" Type Offset VirtAddr PhysAddr FileSiz MemSiz Flg Align\n"));
2812 else
2813 {
2814 printf
2815 (_(" Type Offset VirtAddr PhysAddr\n"));
2816 printf
2817 (_(" FileSiz MemSiz Flags Align\n"));
2818 }
2819 }
2820
2821 loadaddr = -1;
2822 dynamic_addr = 0;
2823 dynamic_size = 0;
2824
2825 for (i = 0, segment = program_headers;
2826 i < elf_header.e_phnum;
2827 i ++, segment ++)
2828 {
2829 if (do_segments)
2830 {
2831 printf (" %-14.14s ", get_segment_type (segment->p_type));
2832
2833 if (is_32bit_elf)
2834 {
2835 printf ("0x%6.6lx ", (unsigned long) segment->p_offset);
2836 printf ("0x%8.8lx ", (unsigned long) segment->p_vaddr);
2837 printf ("0x%8.8lx ", (unsigned long) segment->p_paddr);
2838 printf ("0x%5.5lx ", (unsigned long) segment->p_filesz);
2839 printf ("0x%5.5lx ", (unsigned long) segment->p_memsz);
2840 printf ("%c%c%c ",
2841 (segment->p_flags & PF_R ? 'R' : ' '),
2842 (segment->p_flags & PF_W ? 'W' : ' '),
2843 (segment->p_flags & PF_X ? 'E' : ' '));
2844 printf ("%#lx", (unsigned long) segment->p_align);
2845 }
2846 else if (do_wide)
2847 {
2848 if ((unsigned long) segment->p_offset == segment->p_offset)
2849 printf ("0x%6.6lx ", (unsigned long) segment->p_offset);
2850 else
2851 {
2852 print_vma (segment->p_offset, FULL_HEX);
2853 putchar (' ');
2854 }
2855
2856 print_vma (segment->p_vaddr, FULL_HEX);
2857 putchar (' ');
2858 print_vma (segment->p_paddr, FULL_HEX);
2859 putchar (' ');
2860
2861 if ((unsigned long) segment->p_filesz == segment->p_filesz)
2862 printf ("0x%6.6lx ", (unsigned long) segment->p_filesz);
2863 else
2864 {
2865 print_vma (segment->p_filesz, FULL_HEX);
2866 putchar (' ');
2867 }
2868
2869 if ((unsigned long) segment->p_memsz == segment->p_memsz)
2870 printf ("0x%6.6lx", (unsigned long) segment->p_memsz);
2871 else
2872 {
2873 print_vma (segment->p_offset, FULL_HEX);
2874 }
2875
2876 printf (" %c%c%c ",
2877 (segment->p_flags & PF_R ? 'R' : ' '),
2878 (segment->p_flags & PF_W ? 'W' : ' '),
2879 (segment->p_flags & PF_X ? 'E' : ' '));
2880
2881 if ((unsigned long) segment->p_align == segment->p_align)
2882 printf ("%#lx", (unsigned long) segment->p_align);
2883 else
2884 {
2885 print_vma (segment->p_align, PREFIX_HEX);
2886 }
2887 }
2888 else
2889 {
2890 print_vma (segment->p_offset, FULL_HEX);
2891 putchar (' ');
2892 print_vma (segment->p_vaddr, FULL_HEX);
2893 putchar (' ');
2894 print_vma (segment->p_paddr, FULL_HEX);
2895 printf ("\n ");
2896 print_vma (segment->p_filesz, FULL_HEX);
2897 putchar (' ');
2898 print_vma (segment->p_memsz, FULL_HEX);
2899 printf (" %c%c%c ",
2900 (segment->p_flags & PF_R ? 'R' : ' '),
2901 (segment->p_flags & PF_W ? 'W' : ' '),
2902 (segment->p_flags & PF_X ? 'E' : ' '));
2903 print_vma (segment->p_align, HEX);
2904 }
2905 }
2906
2907 switch (segment->p_type)
2908 {
2909 case PT_LOAD:
2910 if (loadaddr == -1)
2911 loadaddr = (segment->p_vaddr & 0xfffff000)
2912 - (segment->p_offset & 0xfffff000);
2913 break;
2914
2915 case PT_DYNAMIC:
2916 if (dynamic_addr)
2917 error (_("more than one dynamic segment\n"));
2918
2919 dynamic_addr = segment->p_offset;
2920 dynamic_size = segment->p_filesz;
2921 break;
2922
2923 case PT_INTERP:
2924 if (fseek (file, (long) segment->p_offset, SEEK_SET))
2925 error (_("Unable to find program interpreter name\n"));
2926 else
2927 {
2928 program_interpreter[0] = 0;
2929 fscanf (file, "%63s", program_interpreter);
2930
2931 if (do_segments)
2932 printf (_("\n [Requesting program interpreter: %s]"),
2933 program_interpreter);
2934 }
2935 break;
2936 }
2937
2938 if (do_segments)
2939 putc ('\n', stdout);
2940 }
2941
2942 if (loadaddr == -1)
2943 {
2944 /* Very strange. */
2945 loadaddr = 0;
2946 }
2947
2948 if (do_segments && section_headers != NULL)
2949 {
2950 printf (_("\n Section to Segment mapping:\n"));
2951 printf (_(" Segment Sections...\n"));
2952
2953 assert (string_table != NULL);
2954
2955 for (i = 0; i < elf_header.e_phnum; i++)
2956 {
2957 unsigned int j;
2958 Elf_Internal_Shdr * section;
2959
2960 segment = program_headers + i;
2961 section = section_headers;
2962
2963 printf (" %2.2d ", i);
2964
2965 for (j = 1; j < elf_header.e_shnum; j++, section ++)
2966 {
2967 if (section->sh_size > 0
2968 /* Compare allocated sections by VMA, unallocated
2969 sections by file offset. */
2970 && (section->sh_flags & SHF_ALLOC
2971 ? (section->sh_addr >= segment->p_vaddr
2972 && section->sh_addr + section->sh_size
2973 <= segment->p_vaddr + segment->p_memsz)
2974 : ((bfd_vma) section->sh_offset >= segment->p_offset
2975 && (section->sh_offset + section->sh_size
2976 <= segment->p_offset + segment->p_filesz))))
2977 printf ("%s ", SECTION_NAME (section));
2978 }
2979
2980 putc ('\n',stdout);
2981 }
2982 }
2983
2984 free (program_headers);
2985
2986 return 1;
2987 }
2988
2989
2990 static int
2991 get_32bit_section_headers (file, num)
2992 FILE * file;
2993 unsigned int num;
2994 {
2995 Elf32_External_Shdr * shdrs;
2996 Elf32_Internal_Shdr * internal;
2997 unsigned int i;
2998
2999 shdrs = ((Elf32_External_Shdr *)
3000 get_data (NULL, file, elf_header.e_shoff,
3001 elf_header.e_shentsize * num,
3002 _("section headers")));
3003 if (!shdrs)
3004 return 0;
3005
3006 section_headers = ((Elf_Internal_Shdr *)
3007 malloc (num * sizeof (Elf_Internal_Shdr)));
3008
3009 if (section_headers == NULL)
3010 {
3011 error (_("Out of memory\n"));
3012 return 0;
3013 }
3014
3015 for (i = 0, internal = section_headers;
3016 i < num;
3017 i ++, internal ++)
3018 {
3019 internal->sh_name = BYTE_GET (shdrs[i].sh_name);
3020 internal->sh_type = BYTE_GET (shdrs[i].sh_type);
3021 internal->sh_flags = BYTE_GET (shdrs[i].sh_flags);
3022 internal->sh_addr = BYTE_GET (shdrs[i].sh_addr);
3023 internal->sh_offset = BYTE_GET (shdrs[i].sh_offset);
3024 internal->sh_size = BYTE_GET (shdrs[i].sh_size);
3025 internal->sh_link = BYTE_GET (shdrs[i].sh_link);
3026 internal->sh_info = BYTE_GET (shdrs[i].sh_info);
3027 internal->sh_addralign = BYTE_GET (shdrs[i].sh_addralign);
3028 internal->sh_entsize = BYTE_GET (shdrs[i].sh_entsize);
3029 }
3030
3031 free (shdrs);
3032
3033 return 1;
3034 }
3035
3036 static int
3037 get_64bit_section_headers (file, num)
3038 FILE * file;
3039 unsigned int num;
3040 {
3041 Elf64_External_Shdr * shdrs;
3042 Elf64_Internal_Shdr * internal;
3043 unsigned int i;
3044
3045 shdrs = ((Elf64_External_Shdr *)
3046 get_data (NULL, file, elf_header.e_shoff,
3047 elf_header.e_shentsize * num,
3048 _("section headers")));
3049 if (!shdrs)
3050 return 0;
3051
3052 section_headers = ((Elf_Internal_Shdr *)
3053 malloc (num * sizeof (Elf_Internal_Shdr)));
3054
3055 if (section_headers == NULL)
3056 {
3057 error (_("Out of memory\n"));
3058 return 0;
3059 }
3060
3061 for (i = 0, internal = section_headers;
3062 i < num;
3063 i ++, internal ++)
3064 {
3065 internal->sh_name = BYTE_GET (shdrs[i].sh_name);
3066 internal->sh_type = BYTE_GET (shdrs[i].sh_type);
3067 internal->sh_flags = BYTE_GET8 (shdrs[i].sh_flags);
3068 internal->sh_addr = BYTE_GET8 (shdrs[i].sh_addr);
3069 internal->sh_size = BYTE_GET8 (shdrs[i].sh_size);
3070 internal->sh_entsize = BYTE_GET8 (shdrs[i].sh_entsize);
3071 internal->sh_link = BYTE_GET (shdrs[i].sh_link);
3072 internal->sh_info = BYTE_GET (shdrs[i].sh_info);
3073 internal->sh_offset = BYTE_GET (shdrs[i].sh_offset);
3074 internal->sh_addralign = BYTE_GET (shdrs[i].sh_addralign);
3075 }
3076
3077 free (shdrs);
3078
3079 return 1;
3080 }
3081
3082 static Elf_Internal_Sym *
3083 get_32bit_elf_symbols (file, section)
3084 FILE * file;
3085 Elf_Internal_Shdr *section;
3086 {
3087 unsigned long number;
3088 Elf32_External_Sym * esyms;
3089 Elf_External_Sym_Shndx *shndx;
3090 Elf_Internal_Sym * isyms;
3091 Elf_Internal_Sym * psym;
3092 unsigned int j;
3093
3094 esyms = ((Elf32_External_Sym *)
3095 get_data (NULL, file, section->sh_offset,
3096 section->sh_size, _("symbols")));
3097 if (!esyms)
3098 return NULL;
3099
3100 shndx = NULL;
3101 if (symtab_shndx_hdr != NULL
3102 && (symtab_shndx_hdr->sh_link
3103 == (unsigned long) SECTION_HEADER_NUM (section - section_headers)))
3104 {
3105 shndx = ((Elf_External_Sym_Shndx *)
3106 get_data (NULL, file, symtab_shndx_hdr->sh_offset,
3107 symtab_shndx_hdr->sh_size, _("symtab shndx")));
3108 if (!shndx)
3109 {
3110 free (esyms);
3111 return NULL;
3112 }
3113 }
3114
3115 number = section->sh_size / section->sh_entsize;
3116 isyms = (Elf_Internal_Sym *) malloc (number * sizeof (Elf_Internal_Sym));
3117
3118 if (isyms == NULL)
3119 {
3120 error (_("Out of memory\n"));
3121 if (shndx)
3122 free (shndx);
3123 free (esyms);
3124 return NULL;
3125 }
3126
3127 for (j = 0, psym = isyms;
3128 j < number;
3129 j ++, psym ++)
3130 {
3131 psym->st_name = BYTE_GET (esyms[j].st_name);
3132 psym->st_value = BYTE_GET (esyms[j].st_value);
3133 psym->st_size = BYTE_GET (esyms[j].st_size);
3134 psym->st_shndx = BYTE_GET (esyms[j].st_shndx);
3135 if (psym->st_shndx == SHN_XINDEX && shndx != NULL)
3136 psym->st_shndx
3137 = byte_get ((unsigned char *) &shndx[j], sizeof (shndx[j]));
3138 psym->st_info = BYTE_GET (esyms[j].st_info);
3139 psym->st_other = BYTE_GET (esyms[j].st_other);
3140 }
3141
3142 if (shndx)
3143 free (shndx);
3144 free (esyms);
3145
3146 return isyms;
3147 }
3148
3149 static Elf_Internal_Sym *
3150 get_64bit_elf_symbols (file, section)
3151 FILE * file;
3152 Elf_Internal_Shdr *section;
3153 {
3154 unsigned long number;
3155 Elf64_External_Sym * esyms;
3156 Elf_External_Sym_Shndx *shndx;
3157 Elf_Internal_Sym * isyms;
3158 Elf_Internal_Sym * psym;
3159 unsigned int j;
3160
3161 esyms = ((Elf64_External_Sym *)
3162 get_data (NULL, file, section->sh_offset,
3163 section->sh_size, _("symbols")));
3164 if (!esyms)
3165 return NULL;
3166
3167 shndx = NULL;
3168 if (symtab_shndx_hdr != NULL
3169 && (symtab_shndx_hdr->sh_link
3170 == (unsigned long) SECTION_HEADER_NUM (section - section_headers)))
3171 {
3172 shndx = ((Elf_External_Sym_Shndx *)
3173 get_data (NULL, file, symtab_shndx_hdr->sh_offset,
3174 symtab_shndx_hdr->sh_size, _("symtab shndx")));
3175 if (!shndx)
3176 {
3177 free (esyms);
3178 return NULL;
3179 }
3180 }
3181
3182 number = section->sh_size / section->sh_entsize;
3183 isyms = (Elf_Internal_Sym *) malloc (number * sizeof (Elf_Internal_Sym));
3184
3185 if (isyms == NULL)
3186 {
3187 error (_("Out of memory\n"));
3188 if (shndx)
3189 free (shndx);
3190 free (esyms);
3191 return NULL;
3192 }
3193
3194 for (j = 0, psym = isyms;
3195 j < number;
3196 j ++, psym ++)
3197 {
3198 psym->st_name = BYTE_GET (esyms[j].st_name);
3199 psym->st_info = BYTE_GET (esyms[j].st_info);
3200 psym->st_other = BYTE_GET (esyms[j].st_other);
3201 psym->st_shndx = BYTE_GET (esyms[j].st_shndx);
3202 if (psym->st_shndx == SHN_XINDEX && shndx != NULL)
3203 psym->st_shndx
3204 = byte_get ((unsigned char *) &shndx[j], sizeof (shndx[j]));
3205 psym->st_value = BYTE_GET8 (esyms[j].st_value);
3206 psym->st_size = BYTE_GET8 (esyms[j].st_size);
3207 }
3208
3209 if (shndx)
3210 free (shndx);
3211 free (esyms);
3212
3213 return isyms;
3214 }
3215
3216 static const char *
3217 get_elf_section_flags (sh_flags)
3218 bfd_vma sh_flags;
3219 {
3220 static char buff [32];
3221
3222 * buff = 0;
3223
3224 while (sh_flags)
3225 {
3226 bfd_vma flag;
3227
3228 flag = sh_flags & - sh_flags;
3229 sh_flags &= ~ flag;
3230
3231 switch (flag)
3232 {
3233 case SHF_WRITE: strcat (buff, "W"); break;
3234 case SHF_ALLOC: strcat (buff, "A"); break;
3235 case SHF_EXECINSTR: strcat (buff, "X"); break;
3236 case SHF_MERGE: strcat (buff, "M"); break;
3237 case SHF_STRINGS: strcat (buff, "S"); break;
3238 case SHF_INFO_LINK: strcat (buff, "I"); break;
3239 case SHF_LINK_ORDER: strcat (buff, "L"); break;
3240 case SHF_OS_NONCONFORMING: strcat (buff, "O"); break;
3241 case SHF_GROUP: strcat (buff, "G"); break;
3242 case SHF_TLS: strcat (buff, "T"); break;
3243
3244 default:
3245 if (flag & SHF_MASKOS)
3246 {
3247 strcat (buff, "o");
3248 sh_flags &= ~ SHF_MASKOS;
3249 }
3250 else if (flag & SHF_MASKPROC)
3251 {
3252 strcat (buff, "p");
3253 sh_flags &= ~ SHF_MASKPROC;
3254 }
3255 else
3256 strcat (buff, "x");
3257 break;
3258 }
3259 }
3260
3261 return buff;
3262 }
3263
3264 static int
3265 process_section_headers (file)
3266 FILE * file;
3267 {
3268 Elf_Internal_Shdr * section;
3269 unsigned int i;
3270
3271 section_headers = NULL;
3272
3273 if (elf_header.e_shnum == 0)
3274 {
3275 if (do_sections)
3276 printf (_("\nThere are no sections in this file.\n"));
3277
3278 return 1;
3279 }
3280
3281 if (do_sections && !do_header)
3282 printf (_("There are %d section headers, starting at offset 0x%lx:\n"),
3283 elf_header.e_shnum, (unsigned long) elf_header.e_shoff);
3284
3285 if (is_32bit_elf)
3286 {
3287 if (! get_32bit_section_headers (file, elf_header.e_shnum))
3288 return 0;
3289 }
3290 else if (! get_64bit_section_headers (file, elf_header.e_shnum))
3291 return 0;
3292
3293 /* Read in the string table, so that we have names to display. */
3294 section = SECTION_HEADER (elf_header.e_shstrndx);
3295
3296 if (section->sh_size != 0)
3297 {
3298 string_table = (char *) get_data (NULL, file, section->sh_offset,
3299 section->sh_size, _("string table"));
3300
3301 string_table_length = section->sh_size;
3302 }
3303
3304 /* Scan the sections for the dynamic symbol table
3305 and dynamic string table and debug sections. */
3306 dynamic_symbols = NULL;
3307 dynamic_strings = NULL;
3308 dynamic_syminfo = NULL;
3309
3310 for (i = 0, section = section_headers;
3311 i < elf_header.e_shnum;
3312 i ++, section ++)
3313 {
3314 char * name = SECTION_NAME (section);
3315
3316 if (section->sh_type == SHT_DYNSYM)
3317 {
3318 if (dynamic_symbols != NULL)
3319 {
3320 error (_("File contains multiple dynamic symbol tables\n"));
3321 continue;
3322 }
3323
3324 num_dynamic_syms = section->sh_size / section->sh_entsize;
3325 dynamic_symbols = GET_ELF_SYMBOLS (file, section);
3326 }
3327 else if (section->sh_type == SHT_STRTAB
3328 && strcmp (name, ".dynstr") == 0)
3329 {
3330 if (dynamic_strings != NULL)
3331 {
3332 error (_("File contains multiple dynamic string tables\n"));
3333 continue;
3334 }
3335
3336 dynamic_strings = (char *) get_data (NULL, file, section->sh_offset,
3337 section->sh_size,
3338 _("dynamic strings"));
3339 }
3340 else if (section->sh_type == SHT_SYMTAB_SHNDX)
3341 {
3342 if (symtab_shndx_hdr != NULL)
3343 {
3344 error (_("File contains multiple symtab shndx tables\n"));
3345 continue;
3346 }
3347 symtab_shndx_hdr = section;
3348 }
3349 else if ((do_debugging || do_debug_info || do_debug_abbrevs
3350 || do_debug_lines || do_debug_pubnames || do_debug_aranges
3351 || do_debug_frames || do_debug_macinfo || do_debug_str
3352 || do_debug_loc)
3353 && strncmp (name, ".debug_", 7) == 0)
3354 {
3355 name += 7;
3356
3357 if (do_debugging
3358 || (do_debug_info && (strcmp (name, "info") == 0))
3359 || (do_debug_abbrevs && (strcmp (name, "abbrev") == 0))
3360 || (do_debug_lines && (strcmp (name, "line") == 0))
3361 || (do_debug_pubnames && (strcmp (name, "pubnames") == 0))
3362 || (do_debug_aranges && (strcmp (name, "aranges") == 0))
3363 || (do_debug_frames && (strcmp (name, "frame") == 0))
3364 || (do_debug_macinfo && (strcmp (name, "macinfo") == 0))
3365 || (do_debug_str && (strcmp (name, "str") == 0))
3366 || (do_debug_loc && (strcmp (name, "loc") == 0))
3367 )
3368 request_dump (i, DEBUG_DUMP);
3369 }
3370 /* linkonce section to be combined with .debug_info at link time. */
3371 else if ((do_debugging || do_debug_info)
3372 && strncmp (name, ".gnu.linkonce.wi.", 17) == 0)
3373 request_dump (i, DEBUG_DUMP);
3374 else if (do_debug_frames && strcmp (name, ".eh_frame") == 0)
3375 request_dump (i, DEBUG_DUMP);
3376 }
3377
3378 if (! do_sections)
3379 return 1;
3380
3381 if (elf_header.e_shnum > 1)
3382 printf (_("\nSection Headers:\n"));
3383 else
3384 printf (_("\nSection Header:\n"));
3385
3386 if (is_32bit_elf)
3387 printf
3388 (_(" [Nr] Name Type Addr Off Size ES Flg Lk Inf Al\n"));
3389 else if (do_wide)
3390 printf
3391 (_(" [Nr] Name Type Address Off Size ES Flg Lk Inf Al\n"));
3392 else
3393 {
3394 printf (_(" [Nr] Name Type Address Offset\n"));
3395 printf (_(" Size EntSize Flags Link Info Align\n"));
3396 }
3397
3398 for (i = 0, section = section_headers;
3399 i < elf_header.e_shnum;
3400 i ++, section ++)
3401 {
3402 printf (" [%2u] %-17.17s %-15.15s ",
3403 SECTION_HEADER_NUM (i),
3404 SECTION_NAME (section),
3405 get_section_type_name (section->sh_type));
3406
3407 if (is_32bit_elf)
3408 {
3409 print_vma (section->sh_addr, LONG_HEX);
3410
3411 printf ( " %6.6lx %6.6lx %2.2lx",
3412 (unsigned long) section->sh_offset,
3413 (unsigned long) section->sh_size,
3414 (unsigned long) section->sh_entsize);
3415
3416 printf (" %3s ", get_elf_section_flags (section->sh_flags));
3417
3418 printf ("%2ld %3lx %2ld\n",
3419 (unsigned long) section->sh_link,
3420 (unsigned long) section->sh_info,
3421 (unsigned long) section->sh_addralign);
3422 }
3423 else if (do_wide)
3424 {
3425 print_vma (section->sh_addr, LONG_HEX);
3426
3427 if ((long) section->sh_offset == section->sh_offset)
3428 printf (" %6.6lx", (unsigned long) section->sh_offset);
3429 else
3430 {
3431 putchar (' ');
3432 print_vma (section->sh_offset, LONG_HEX);
3433 }
3434
3435 if ((unsigned long) section->sh_size == section->sh_size)
3436 printf (" %6.6lx", (unsigned long) section->sh_size);
3437 else
3438 {
3439 putchar (' ');
3440 print_vma (section->sh_size, LONG_HEX);
3441 }
3442
3443 if ((unsigned long) section->sh_entsize == section->sh_entsize)
3444 printf (" %2.2lx", (unsigned long) section->sh_entsize);
3445 else
3446 {
3447 putchar (' ');
3448 print_vma (section->sh_entsize, LONG_HEX);
3449 }
3450
3451 printf (" %3s ", get_elf_section_flags (section->sh_flags));
3452
3453 printf ("%2ld %3lx ",
3454 (unsigned long) section->sh_link,
3455 (unsigned long) section->sh_info);
3456
3457 if ((unsigned long) section->sh_addralign == section->sh_addralign)
3458 printf ("%2ld\n", (unsigned long) section->sh_addralign);
3459 else
3460 {
3461 print_vma (section->sh_addralign, DEC);
3462 putchar ('\n');
3463 }
3464 }
3465 else
3466 {
3467 putchar (' ');
3468 print_vma (section->sh_addr, LONG_HEX);
3469 if ((long) section->sh_offset == section->sh_offset)
3470 printf (" %8.8lx", (unsigned long) section->sh_offset);
3471 else
3472 {
3473 printf (" ");
3474 print_vma (section->sh_offset, LONG_HEX);
3475 }
3476 printf ("\n ");
3477 print_vma (section->sh_size, LONG_HEX);
3478 printf (" ");
3479 print_vma (section->sh_entsize, LONG_HEX);
3480
3481 printf (" %3s ", get_elf_section_flags (section->sh_flags));
3482
3483 printf (" %2ld %3lx %ld\n",
3484 (unsigned long) section->sh_link,
3485 (unsigned long) section->sh_info,
3486 (unsigned long) section->sh_addralign);
3487 }
3488 }
3489
3490 printf (_("Key to Flags:\n\
3491 W (write), A (alloc), X (execute), M (merge), S (strings)\n\
3492 I (info), L (link order), G (group), x (unknown)\n\
3493 O (extra OS processing required) o (OS specific), p (processor specific)\n"));
3494
3495 return 1;
3496 }
3497
3498 /* Process the reloc section. */
3499 static int
3500 process_relocs (file)
3501 FILE * file;
3502 {
3503 unsigned long rel_size;
3504 unsigned long rel_offset;
3505
3506
3507 if (!do_reloc)
3508 return 1;
3509
3510 if (do_using_dynamic)
3511 {
3512 int is_rela = FALSE;
3513
3514 rel_size = 0;
3515 rel_offset = 0;
3516
3517 if (dynamic_info[DT_REL])
3518 {
3519 rel_offset = dynamic_info[DT_REL];
3520 rel_size = dynamic_info[DT_RELSZ];
3521 is_rela = FALSE;
3522 }
3523 else if (dynamic_info [DT_RELA])
3524 {
3525 rel_offset = dynamic_info[DT_RELA];
3526 rel_size = dynamic_info[DT_RELASZ];
3527 is_rela = TRUE;
3528 }
3529 else if (dynamic_info[DT_JMPREL])
3530 {
3531 rel_offset = dynamic_info[DT_JMPREL];
3532 rel_size = dynamic_info[DT_PLTRELSZ];
3533
3534 switch (dynamic_info[DT_PLTREL])
3535 {
3536 case DT_REL:
3537 is_rela = FALSE;
3538 break;
3539 case DT_RELA:
3540 is_rela = TRUE;
3541 break;
3542 default:
3543 is_rela = UNKNOWN;
3544 break;
3545 }
3546 }
3547
3548 if (rel_size)
3549 {
3550 printf
3551 (_("\nRelocation section at offset 0x%lx contains %ld bytes:\n"),
3552 rel_offset, rel_size);
3553
3554 dump_relocations (file, rel_offset - loadaddr, rel_size,
3555 dynamic_symbols, num_dynamic_syms, dynamic_strings, is_rela);
3556 }
3557 else
3558 printf (_("\nThere are no dynamic relocations in this file.\n"));
3559 }
3560 else
3561 {
3562 Elf32_Internal_Shdr * section;
3563 unsigned long i;
3564 int found = 0;
3565
3566 for (i = 0, section = section_headers;
3567 i < elf_header.e_shnum;
3568 i++, section ++)
3569 {
3570 if ( section->sh_type != SHT_RELA
3571 && section->sh_type != SHT_REL)
3572 continue;
3573
3574 rel_offset = section->sh_offset;
3575 rel_size = section->sh_size;
3576
3577 if (rel_size)
3578 {
3579 Elf32_Internal_Shdr * strsec;
3580 Elf_Internal_Sym * symtab;
3581 char * strtab;
3582 int is_rela;
3583 unsigned long nsyms;
3584
3585 printf (_("\nRelocation section "));
3586
3587 if (string_table == NULL)
3588 printf ("%d", section->sh_name);
3589 else
3590 printf (_("'%s'"), SECTION_NAME (section));
3591
3592 printf (_(" at offset 0x%lx contains %lu entries:\n"),
3593 rel_offset, (unsigned long) (rel_size / section->sh_entsize));
3594
3595 symtab = NULL;
3596 strtab = NULL;
3597 nsyms = 0;
3598 if (section->sh_link)
3599 {
3600 Elf32_Internal_Shdr * symsec;
3601
3602 symsec = SECTION_HEADER (section->sh_link);
3603 nsyms = symsec->sh_size / symsec->sh_entsize;
3604 symtab = GET_ELF_SYMBOLS (file, symsec);
3605
3606 if (symtab == NULL)
3607 continue;
3608
3609 strsec = SECTION_HEADER (symsec->sh_link);
3610
3611 strtab = (char *) get_data (NULL, file, strsec->sh_offset,
3612 strsec->sh_size,
3613 _("string table"));
3614 }
3615 is_rela = section->sh_type == SHT_RELA;
3616
3617 dump_relocations (file, rel_offset, rel_size,
3618 symtab, nsyms, strtab, is_rela);
3619
3620 if (strtab)
3621 free (strtab);
3622 if (symtab)
3623 free (symtab);
3624
3625 found = 1;
3626 }
3627 }
3628
3629 if (! found)
3630 printf (_("\nThere are no relocations in this file.\n"));
3631 }
3632
3633 return 1;
3634 }
3635
3636 #include "unwind-ia64.h"
3637
3638 /* An absolute address consists of a section and an offset. If the
3639 section is NULL, the offset itself is the address, otherwise, the
3640 address equals to LOAD_ADDRESS(section) + offset. */
3641
3642 struct absaddr
3643 {
3644 unsigned short section;
3645 bfd_vma offset;
3646 };
3647
3648 struct unw_aux_info
3649 {
3650 struct unw_table_entry
3651 {
3652 struct absaddr start;
3653 struct absaddr end;
3654 struct absaddr info;
3655 }
3656 *table; /* Unwind table. */
3657 unsigned long table_len; /* Length of unwind table. */
3658 unsigned char * info; /* Unwind info. */
3659 unsigned long info_size; /* Size of unwind info. */
3660 bfd_vma info_addr; /* starting address of unwind info. */
3661 bfd_vma seg_base; /* Starting address of segment. */
3662 Elf_Internal_Sym * symtab; /* The symbol table. */
3663 unsigned long nsyms; /* Number of symbols. */
3664 char * strtab; /* The string table. */
3665 unsigned long strtab_size; /* Size of string table. */
3666 };
3667
3668 static void find_symbol_for_address PARAMS ((struct unw_aux_info *,
3669 struct absaddr, const char **,
3670 bfd_vma *));
3671 static void dump_ia64_unwind PARAMS ((struct unw_aux_info *));
3672 static int slurp_ia64_unwind_table PARAMS ((FILE *, struct unw_aux_info *,
3673 Elf32_Internal_Shdr *));
3674
3675 static void
3676 find_symbol_for_address (aux, addr, symname, offset)
3677 struct unw_aux_info *aux;
3678 struct absaddr addr;
3679 const char **symname;
3680 bfd_vma *offset;
3681 {
3682 bfd_vma dist = (bfd_vma) 0x100000;
3683 Elf_Internal_Sym *sym, *best = NULL;
3684 unsigned long i;
3685
3686 for (i = 0, sym = aux->symtab; i < aux->nsyms; ++i, ++sym)
3687 {
3688 if (ELF_ST_TYPE (sym->st_info) == STT_FUNC
3689 && sym->st_name != 0
3690 && (addr.section == SHN_UNDEF || addr.section == sym->st_shndx)
3691 && addr.offset >= sym->st_value
3692 && addr.offset - sym->st_value < dist)
3693 {
3694 best = sym;
3695 dist = addr.offset - sym->st_value;
3696 if (!dist)
3697 break;
3698 }
3699 }
3700 if (best)
3701 {
3702 *symname = (best->st_name >= aux->strtab_size
3703 ? "<corrupt>" : aux->strtab + best->st_name);
3704 *offset = dist;
3705 return;
3706 }
3707 *symname = NULL;
3708 *offset = addr.offset;
3709 }
3710
3711 static void
3712 dump_ia64_unwind (aux)
3713 struct unw_aux_info *aux;
3714 {
3715 bfd_vma addr_size;
3716 struct unw_table_entry * tp;
3717 int in_body;
3718
3719 addr_size = is_32bit_elf ? 4 : 8;
3720
3721 for (tp = aux->table; tp < aux->table + aux->table_len; ++tp)
3722 {
3723 bfd_vma stamp;
3724 bfd_vma offset;
3725 const unsigned char * dp;
3726 const unsigned char * head;
3727 const char * procname;
3728
3729 find_symbol_for_address (aux, tp->start, &procname, &offset);
3730
3731 fputs ("\n<", stdout);
3732
3733 if (procname)
3734 {
3735 fputs (procname, stdout);
3736
3737 if (offset)
3738 printf ("+%lx", (unsigned long) offset);
3739 }
3740
3741 fputs (">: [", stdout);
3742 print_vma (tp->start.offset, PREFIX_HEX);
3743 fputc ('-', stdout);
3744 print_vma (tp->end.offset, PREFIX_HEX);
3745 printf ("), info at +0x%lx\n",
3746 (unsigned long) (tp->info.offset - aux->seg_base));
3747
3748 head = aux->info + (tp->info.offset - aux->info_addr);
3749 stamp = BYTE_GET8 ((unsigned char *) head);
3750
3751 printf (" v%u, flags=0x%lx (%s%s ), len=%lu bytes\n",
3752 (unsigned) UNW_VER (stamp),
3753 (unsigned long) ((stamp & UNW_FLAG_MASK) >> 32),
3754 UNW_FLAG_EHANDLER (stamp) ? " ehandler" : "",
3755 UNW_FLAG_UHANDLER (stamp) ? " uhandler" : "",
3756 (unsigned long) (addr_size * UNW_LENGTH (stamp)));
3757
3758 if (UNW_VER (stamp) != 1)
3759 {
3760 printf ("\tUnknown version.\n");
3761 continue;
3762 }
3763
3764 in_body = 0;
3765 for (dp = head + 8; dp < head + 8 + addr_size * UNW_LENGTH (stamp);)
3766 dp = unw_decode (dp, in_body, & in_body);
3767 }
3768 }
3769
3770 static int
3771 slurp_ia64_unwind_table (file, aux, sec)
3772 FILE *file;
3773 struct unw_aux_info *aux;
3774 Elf32_Internal_Shdr *sec;
3775 {
3776 unsigned long size, addr_size, nrelas, i;
3777 Elf_Internal_Phdr *prog_hdrs, *seg;
3778 struct unw_table_entry *tep;
3779 Elf32_Internal_Shdr *relsec;
3780 Elf_Internal_Rela *rela, *rp;
3781 unsigned char *table, *tp;
3782 Elf_Internal_Sym *sym;
3783 const char *relname;
3784 int result;
3785
3786 addr_size = is_32bit_elf ? 4 : 8;
3787
3788 /* First, find the starting address of the segment that includes
3789 this section: */
3790
3791 if (elf_header.e_phnum)
3792 {
3793 prog_hdrs = (Elf_Internal_Phdr *)
3794 xmalloc (elf_header.e_phnum * sizeof (Elf_Internal_Phdr));
3795
3796 if (is_32bit_elf)
3797 result = get_32bit_program_headers (file, prog_hdrs);
3798 else
3799 result = get_64bit_program_headers (file, prog_hdrs);
3800
3801 if (!result)
3802 {
3803 free (prog_hdrs);
3804 return 0;
3805 }
3806
3807 for (seg = prog_hdrs; seg < prog_hdrs + elf_header.e_phnum; ++seg)
3808 {
3809 if (seg->p_type != PT_LOAD)
3810 continue;
3811
3812 if (sec->sh_addr >= seg->p_vaddr
3813 && (sec->sh_addr + sec->sh_size <= seg->p_vaddr + seg->p_memsz))
3814 {
3815 aux->seg_base = seg->p_vaddr;
3816 break;
3817 }
3818 }
3819
3820 free (prog_hdrs);
3821 }
3822
3823 /* Second, build the unwind table from the contents of the unwind section: */
3824 size = sec->sh_size;
3825 table = (char *) get_data (NULL, file, sec->sh_offset,
3826 size, _("unwind table"));
3827 if (!table)
3828 return 0;
3829
3830 tep = aux->table = xmalloc (size / (3 * addr_size) * sizeof (aux->table[0]));
3831 for (tp = table; tp < table + size; tp += 3 * addr_size, ++ tep)
3832 {
3833 tep->start.section = SHN_UNDEF;
3834 tep->end.section = SHN_UNDEF;
3835 tep->info.section = SHN_UNDEF;
3836 if (is_32bit_elf)
3837 {
3838 tep->start.offset = byte_get ((unsigned char *) tp + 0, 4);
3839 tep->end.offset = byte_get ((unsigned char *) tp + 4, 4);
3840 tep->info.offset = byte_get ((unsigned char *) tp + 8, 4);
3841 }
3842 else
3843 {
3844 tep->start.offset = BYTE_GET8 ((unsigned char *) tp + 0);
3845 tep->end.offset = BYTE_GET8 ((unsigned char *) tp + 8);
3846 tep->info.offset = BYTE_GET8 ((unsigned char *) tp + 16);
3847 }
3848 tep->start.offset += aux->seg_base;
3849 tep->end.offset += aux->seg_base;
3850 tep->info.offset += aux->seg_base;
3851 }
3852 free (table);
3853
3854 /* Third, apply any relocations to the unwind table: */
3855
3856 for (relsec = section_headers;
3857 relsec < section_headers + elf_header.e_shnum;
3858 ++relsec)
3859 {
3860 if (relsec->sh_type != SHT_RELA
3861 || SECTION_HEADER (relsec->sh_info) != sec)
3862 continue;
3863
3864 if (!slurp_rela_relocs (file, relsec->sh_offset, relsec->sh_size,
3865 & rela, & nrelas))
3866 return 0;
3867
3868 for (rp = rela; rp < rela + nrelas; ++rp)
3869 {
3870 if (is_32bit_elf)
3871 {
3872 relname = elf_ia64_reloc_type (ELF32_R_TYPE (rp->r_info));
3873 sym = aux->symtab + ELF32_R_SYM (rp->r_info);
3874
3875 if (ELF32_ST_TYPE (sym->st_info) != STT_SECTION)
3876 {
3877 warn (_("Skipping unexpected symbol type %u\n"),
3878 ELF32_ST_TYPE (sym->st_info));
3879 continue;
3880 }
3881 }
3882 else
3883 {
3884 relname = elf_ia64_reloc_type (ELF64_R_TYPE (rp->r_info));
3885 sym = aux->symtab + ELF64_R_SYM (rp->r_info);
3886
3887 if (ELF64_ST_TYPE (sym->st_info) != STT_SECTION)
3888 {
3889 warn (_("Skipping unexpected symbol type %u\n"),
3890 ELF64_ST_TYPE (sym->st_info));
3891 continue;
3892 }
3893 }
3894
3895 if (strncmp (relname, "R_IA64_SEGREL", 13) != 0)
3896 {
3897 warn (_("Skipping unexpected relocation type %s\n"), relname);
3898 continue;
3899 }
3900
3901 i = rp->r_offset / (3 * addr_size);
3902
3903 switch (rp->r_offset/addr_size % 3)
3904 {
3905 case 0:
3906 aux->table[i].start.section = sym->st_shndx;
3907 aux->table[i].start.offset += rp->r_addend;
3908 break;
3909 case 1:
3910 aux->table[i].end.section = sym->st_shndx;
3911 aux->table[i].end.offset += rp->r_addend;
3912 break;
3913 case 2:
3914 aux->table[i].info.section = sym->st_shndx;
3915 aux->table[i].info.offset += rp->r_addend;
3916 break;
3917 default:
3918 break;
3919 }
3920 }
3921
3922 free (rela);
3923 }
3924
3925 aux->table_len = size / (3 * addr_size);
3926 return 1;
3927 }
3928
3929 static int
3930 process_unwind (file)
3931 FILE * file;
3932 {
3933 Elf32_Internal_Shdr *sec, *unwsec = NULL, *strsec;
3934 unsigned long i, addr_size, unwcount = 0, unwstart = 0;
3935 struct unw_aux_info aux;
3936
3937 if (!do_unwind)
3938 return 1;
3939
3940 if (elf_header.e_machine != EM_IA_64)
3941 {
3942 printf (_("\nThere are no unwind sections in this file.\n"));
3943 return 1;
3944 }
3945
3946 memset (& aux, 0, sizeof (aux));
3947
3948 addr_size = is_32bit_elf ? 4 : 8;
3949
3950 for (i = 0, sec = section_headers; i < elf_header.e_shnum; ++i, ++sec)
3951 {
3952 if (sec->sh_type == SHT_SYMTAB)
3953 {
3954 aux.nsyms = sec->sh_size / sec->sh_entsize;
3955 aux.symtab = GET_ELF_SYMBOLS (file, sec);
3956
3957 strsec = SECTION_HEADER (sec->sh_link);
3958 aux.strtab_size = strsec->sh_size;
3959 aux.strtab = (char *) get_data (NULL, file, strsec->sh_offset,
3960 aux.strtab_size, _("string table"));
3961 }
3962 else if (sec->sh_type == SHT_IA_64_UNWIND)
3963 unwcount++;
3964 }
3965
3966 if (!unwcount)
3967 printf (_("\nThere are no unwind sections in this file.\n"));
3968
3969 while (unwcount-- > 0)
3970 {
3971 char *suffix;
3972 size_t len, len2;
3973
3974 for (i = unwstart, sec = section_headers + unwstart;
3975 i < elf_header.e_shnum; ++i, ++sec)
3976 if (sec->sh_type == SHT_IA_64_UNWIND)
3977 {
3978 unwsec = sec;
3979 break;
3980 }
3981
3982 unwstart = i + 1;
3983 len = sizeof (ELF_STRING_ia64_unwind_once) - 1;
3984
3985 if (strncmp (SECTION_NAME (unwsec), ELF_STRING_ia64_unwind_once,
3986 len) == 0)
3987 {
3988 /* .gnu.linkonce.ia64unw.FOO -> .gnu.linkonce.ia64unwi.FOO */
3989 len2 = sizeof (ELF_STRING_ia64_unwind_info_once) - 1;
3990 suffix = SECTION_NAME (unwsec) + len;
3991 for (i = 0, sec = section_headers; i < elf_header.e_shnum;
3992 ++i, ++sec)
3993 if (strncmp (SECTION_NAME (sec),
3994 ELF_STRING_ia64_unwind_info_once, len2) == 0
3995 && strcmp (SECTION_NAME (sec) + len2, suffix) == 0)
3996 break;
3997 }
3998 else
3999 {
4000 /* .IA_64.unwindFOO -> .IA_64.unwind_infoFOO
4001 .IA_64.unwind or BAR -> .IA_64.unwind_info */
4002 len = sizeof (ELF_STRING_ia64_unwind) - 1;
4003 len2 = sizeof (ELF_STRING_ia64_unwind_info) - 1;
4004 suffix = "";
4005 if (strncmp (SECTION_NAME (unwsec), ELF_STRING_ia64_unwind,
4006 len) == 0)
4007 suffix = SECTION_NAME (unwsec) + len;
4008 for (i = 0, sec = section_headers; i < elf_header.e_shnum;
4009 ++i, ++sec)
4010 if (strncmp (SECTION_NAME (sec),
4011 ELF_STRING_ia64_unwind_info, len2) == 0
4012 && strcmp (SECTION_NAME (sec) + len2, suffix) == 0)
4013 break;
4014 }
4015
4016 if (i == elf_header.e_shnum)
4017 {
4018 printf (_("\nCould not find unwind info section for "));
4019
4020 if (string_table == NULL)
4021 printf ("%d", unwsec->sh_name);
4022 else
4023 printf (_("'%s'"), SECTION_NAME (unwsec));
4024 }
4025 else
4026 {
4027 aux.info_size = sec->sh_size;
4028 aux.info_addr = sec->sh_addr;
4029 aux.info = (char *) get_data (NULL, file, sec->sh_offset,
4030 aux.info_size, _("unwind info"));
4031
4032 printf (_("\nUnwind section "));
4033
4034 if (string_table == NULL)
4035 printf ("%d", unwsec->sh_name);
4036 else
4037 printf (_("'%s'"), SECTION_NAME (unwsec));
4038
4039 printf (_(" at offset 0x%lx contains %lu entries:\n"),
4040 (unsigned long) unwsec->sh_offset,
4041 (unsigned long) (unwsec->sh_size / (3 * addr_size)));
4042
4043 (void) slurp_ia64_unwind_table (file, & aux, unwsec);
4044
4045 if (aux.table_len > 0)
4046 dump_ia64_unwind (& aux);
4047
4048 if (aux.table)
4049 free ((char *) aux.table);
4050 if (aux.info)
4051 free ((char *) aux.info);
4052 aux.table = NULL;
4053 aux.info = NULL;
4054 }
4055 }
4056
4057 if (aux.symtab)
4058 free (aux.symtab);
4059 if (aux.strtab)
4060 free ((char *) aux.strtab);
4061
4062 return 1;
4063 }
4064
4065 static void
4066 dynamic_segment_mips_val (entry)
4067 Elf_Internal_Dyn * entry;
4068 {
4069 switch (entry->d_tag)
4070 {
4071 case DT_MIPS_FLAGS:
4072 if (entry->d_un.d_val == 0)
4073 printf ("NONE\n");
4074 else
4075 {
4076 static const char * opts[] =
4077 {
4078 "QUICKSTART", "NOTPOT", "NO_LIBRARY_REPLACEMENT",
4079 "NO_MOVE", "SGI_ONLY", "GUARANTEE_INIT", "DELTA_C_PLUS_PLUS",
4080 "GUARANTEE_START_INIT", "PIXIE", "DEFAULT_DELAY_LOAD",
4081 "REQUICKSTART", "REQUICKSTARTED", "CORD", "NO_UNRES_UNDEF",
4082 "RLD_ORDER_SAFE"
4083 };
4084 unsigned int cnt;
4085 int first = 1;
4086 for (cnt = 0; cnt < NUM_ELEM (opts); ++ cnt)
4087 if (entry->d_un.d_val & (1 << cnt))
4088 {
4089 printf ("%s%s", first ? "" : " ", opts[cnt]);
4090 first = 0;
4091 }
4092 puts ("");
4093 }
4094 break;
4095
4096 case DT_MIPS_IVERSION:
4097 if (dynamic_strings != NULL)
4098 printf ("Interface Version: %s\n",
4099 dynamic_strings + entry->d_un.d_val);
4100 else
4101 printf ("%ld\n", (long) entry->d_un.d_ptr);
4102 break;
4103
4104 case DT_MIPS_TIME_STAMP:
4105 {
4106 char timebuf[20];
4107 struct tm * tmp;
4108
4109 time_t time = entry->d_un.d_val;
4110 tmp = gmtime (&time);
4111 sprintf (timebuf, "%04u-%02u-%02uT%02u:%02u:%02u",
4112 tmp->tm_year + 1900, tmp->tm_mon + 1, tmp->tm_mday,
4113 tmp->tm_hour, tmp->tm_min, tmp->tm_sec);
4114 printf ("Time Stamp: %s\n", timebuf);
4115 }
4116 break;
4117
4118 case DT_MIPS_RLD_VERSION:
4119 case DT_MIPS_LOCAL_GOTNO:
4120 case DT_MIPS_CONFLICTNO:
4121 case DT_MIPS_LIBLISTNO:
4122 case DT_MIPS_SYMTABNO:
4123 case DT_MIPS_UNREFEXTNO:
4124 case DT_MIPS_HIPAGENO:
4125 case DT_MIPS_DELTA_CLASS_NO:
4126 case DT_MIPS_DELTA_INSTANCE_NO:
4127 case DT_MIPS_DELTA_RELOC_NO:
4128 case DT_MIPS_DELTA_SYM_NO:
4129 case DT_MIPS_DELTA_CLASSSYM_NO:
4130 case DT_MIPS_COMPACT_SIZE:
4131 printf ("%ld\n", (long) entry->d_un.d_ptr);
4132 break;
4133
4134 default:
4135 printf ("%#lx\n", (long) entry->d_un.d_ptr);
4136 }
4137 }
4138
4139
4140 static void
4141 dynamic_segment_parisc_val (entry)
4142 Elf_Internal_Dyn * entry;
4143 {
4144 switch (entry->d_tag)
4145 {
4146 case DT_HP_DLD_FLAGS:
4147 {
4148 static struct
4149 {
4150 long int bit;
4151 const char * str;
4152 }
4153 flags[] =
4154 {
4155 { DT_HP_DEBUG_PRIVATE, "HP_DEBUG_PRIVATE" },
4156 { DT_HP_DEBUG_CALLBACK, "HP_DEBUG_CALLBACK" },
4157 { DT_HP_DEBUG_CALLBACK_BOR, "HP_DEBUG_CALLBACK_BOR" },
4158 { DT_HP_NO_ENVVAR, "HP_NO_ENVVAR" },
4159 { DT_HP_BIND_NOW, "HP_BIND_NOW" },
4160 { DT_HP_BIND_NONFATAL, "HP_BIND_NONFATAL" },
4161 { DT_HP_BIND_VERBOSE, "HP_BIND_VERBOSE" },
4162 { DT_HP_BIND_RESTRICTED, "HP_BIND_RESTRICTED" },
4163 { DT_HP_BIND_SYMBOLIC, "HP_BIND_SYMBOLIC" },
4164 { DT_HP_RPATH_FIRST, "HP_RPATH_FIRST" },
4165 { DT_HP_BIND_DEPTH_FIRST, "HP_BIND_DEPTH_FIRST" }
4166 };
4167 int first = 1;
4168 size_t cnt;
4169 bfd_vma val = entry->d_un.d_val;
4170
4171 for (cnt = 0; cnt < sizeof (flags) / sizeof (flags[0]); ++cnt)
4172 if (val & flags[cnt].bit)
4173 {
4174 if (! first)
4175 putchar (' ');
4176 fputs (flags[cnt].str, stdout);
4177 first = 0;
4178 val ^= flags[cnt].bit;
4179 }
4180
4181 if (val != 0 || first)
4182 {
4183 if (! first)
4184 putchar (' ');
4185 print_vma (val, HEX);
4186 }
4187 }
4188 break;
4189
4190 default:
4191 print_vma (entry->d_un.d_ptr, PREFIX_HEX);
4192 break;
4193 }
4194 }
4195
4196 static int
4197 get_32bit_dynamic_segment (file)
4198 FILE * file;
4199 {
4200 Elf32_External_Dyn * edyn;
4201 Elf_Internal_Dyn * entry;
4202 bfd_size_type i;
4203
4204 edyn = (Elf32_External_Dyn *) get_data (NULL, file, dynamic_addr,
4205 dynamic_size, _("dynamic segment"));
4206 if (!edyn)
4207 return 0;
4208
4209 /* SGI's ELF has more than one section in the DYNAMIC segment. Determine
4210 how large this .dynamic is now. We can do this even before the byte
4211 swapping since the DT_NULL tag is recognizable. */
4212 dynamic_size = 0;
4213 while (*(Elf32_Word *) edyn [dynamic_size++].d_tag != DT_NULL)
4214 ;
4215
4216 dynamic_segment = (Elf_Internal_Dyn *)
4217 malloc (dynamic_size * sizeof (Elf_Internal_Dyn));
4218
4219 if (dynamic_segment == NULL)
4220 {
4221 error (_("Out of memory\n"));
4222 free (edyn);
4223 return 0;
4224 }
4225
4226 for (i = 0, entry = dynamic_segment;
4227 i < dynamic_size;
4228 i ++, entry ++)
4229 {
4230 entry->d_tag = BYTE_GET (edyn [i].d_tag);
4231 entry->d_un.d_val = BYTE_GET (edyn [i].d_un.d_val);
4232 }
4233
4234 free (edyn);
4235
4236 return 1;
4237 }
4238
4239 static int
4240 get_64bit_dynamic_segment (file)
4241 FILE * file;
4242 {
4243 Elf64_External_Dyn * edyn;
4244 Elf_Internal_Dyn * entry;
4245 bfd_size_type i;
4246
4247 edyn = (Elf64_External_Dyn *) get_data (NULL, file, dynamic_addr,
4248 dynamic_size, _("dynamic segment"));
4249 if (!edyn)
4250 return 0;
4251
4252 /* SGI's ELF has more than one section in the DYNAMIC segment. Determine
4253 how large this .dynamic is now. We can do this even before the byte
4254 swapping since the DT_NULL tag is recognizable. */
4255 dynamic_size = 0;
4256 while (*(bfd_vma *) edyn [dynamic_size ++].d_tag != DT_NULL)
4257 ;
4258
4259 dynamic_segment = (Elf_Internal_Dyn *)
4260 malloc (dynamic_size * sizeof (Elf_Internal_Dyn));
4261
4262 if (dynamic_segment == NULL)
4263 {
4264 error (_("Out of memory\n"));
4265 free (edyn);
4266 return 0;
4267 }
4268
4269 for (i = 0, entry = dynamic_segment;
4270 i < dynamic_size;
4271 i ++, entry ++)
4272 {
4273 entry->d_tag = BYTE_GET8 (edyn [i].d_tag);
4274 entry->d_un.d_val = BYTE_GET8 (edyn [i].d_un.d_val);
4275 }
4276
4277 free (edyn);
4278
4279 return 1;
4280 }
4281
4282 static const char *
4283 get_dynamic_flags (flags)
4284 bfd_vma flags;
4285 {
4286 static char buff [128];
4287 char *p = buff;
4288
4289 *p = '\0';
4290 while (flags)
4291 {
4292 bfd_vma flag;
4293
4294 flag = flags & - flags;
4295 flags &= ~ flag;
4296
4297 if (p != buff)
4298 *p++ = ' ';
4299
4300 switch (flag)
4301 {
4302 case DF_ORIGIN: strcpy (p, "ORIGIN"); break;
4303 case DF_SYMBOLIC: strcpy (p, "SYMBOLIC"); break;
4304 case DF_TEXTREL: strcpy (p, "TEXTREL"); break;
4305 case DF_BIND_NOW: strcpy (p, "BIND_NOW"); break;
4306 case DF_STATIC_TLS: strcpy (p, "STATIC_TLS"); break;
4307 default: strcpy (p, "unknown"); break;
4308 }
4309
4310 p = strchr (p, '\0');
4311 }
4312 return buff;
4313 }
4314
4315 /* Parse and display the contents of the dynamic segment. */
4316 static int
4317 process_dynamic_segment (file)
4318 FILE * file;
4319 {
4320 Elf_Internal_Dyn * entry;
4321 bfd_size_type i;
4322
4323 if (dynamic_size == 0)
4324 {
4325 if (do_dynamic)
4326 printf (_("\nThere is no dynamic segment in this file.\n"));
4327
4328 return 1;
4329 }
4330
4331 if (is_32bit_elf)
4332 {
4333 if (! get_32bit_dynamic_segment (file))
4334 return 0;
4335 }
4336 else if (! get_64bit_dynamic_segment (file))
4337 return 0;
4338
4339 /* Find the appropriate symbol table. */
4340 if (dynamic_symbols == NULL)
4341 {
4342 for (i = 0, entry = dynamic_segment;
4343 i < dynamic_size;
4344 ++i, ++ entry)
4345 {
4346 Elf32_Internal_Shdr section;
4347
4348 if (entry->d_tag != DT_SYMTAB)
4349 continue;
4350
4351 dynamic_info[DT_SYMTAB] = entry->d_un.d_val;
4352
4353 /* Since we do not know how big the symbol table is,
4354 we default to reading in the entire file (!) and
4355 processing that. This is overkill, I know, but it
4356 should work. */
4357 section.sh_offset = entry->d_un.d_val - loadaddr;
4358
4359 if (fseek (file, 0, SEEK_END))
4360 error (_("Unable to seek to end of file!"));
4361
4362 section.sh_size = ftell (file) - section.sh_offset;
4363 if (is_32bit_elf)
4364 section.sh_entsize = sizeof (Elf32_External_Sym);
4365 else
4366 section.sh_entsize = sizeof (Elf64_External_Sym);
4367
4368 num_dynamic_syms = section.sh_size / section.sh_entsize;
4369 if (num_dynamic_syms < 1)
4370 {
4371 error (_("Unable to determine the number of symbols to load\n"));
4372 continue;
4373 }
4374
4375 dynamic_symbols = GET_ELF_SYMBOLS (file, &section);
4376 }
4377 }
4378
4379 /* Similarly find a string table. */
4380 if (dynamic_strings == NULL)
4381 {
4382 for (i = 0, entry = dynamic_segment;
4383 i < dynamic_size;
4384 ++i, ++ entry)
4385 {
4386 unsigned long offset;
4387 long str_tab_len;
4388
4389 if (entry->d_tag != DT_STRTAB)
4390 continue;
4391
4392 dynamic_info[DT_STRTAB] = entry->d_un.d_val;
4393
4394 /* Since we do not know how big the string table is,
4395 we default to reading in the entire file (!) and
4396 processing that. This is overkill, I know, but it
4397 should work. */
4398
4399 offset = entry->d_un.d_val - loadaddr;
4400 if (fseek (file, 0, SEEK_END))
4401 error (_("Unable to seek to end of file\n"));
4402 str_tab_len = ftell (file) - offset;
4403
4404 if (str_tab_len < 1)
4405 {
4406 error
4407 (_("Unable to determine the length of the dynamic string table\n"));
4408 continue;
4409 }
4410
4411 dynamic_strings = (char *) get_data (NULL, file, offset, str_tab_len,
4412 _("dynamic string table"));
4413 break;
4414 }
4415 }
4416
4417 /* And find the syminfo section if available. */
4418 if (dynamic_syminfo == NULL)
4419 {
4420 unsigned int syminsz = 0;
4421
4422 for (i = 0, entry = dynamic_segment;
4423 i < dynamic_size;
4424 ++i, ++ entry)
4425 {
4426 if (entry->d_tag == DT_SYMINENT)
4427 {
4428 /* Note: these braces are necessary to avoid a syntax
4429 error from the SunOS4 C compiler. */
4430 assert (sizeof (Elf_External_Syminfo) == entry->d_un.d_val);
4431 }
4432 else if (entry->d_tag == DT_SYMINSZ)
4433 syminsz = entry->d_un.d_val;
4434 else if (entry->d_tag == DT_SYMINFO)
4435 dynamic_syminfo_offset = entry->d_un.d_val - loadaddr;
4436 }
4437
4438 if (dynamic_syminfo_offset != 0 && syminsz != 0)
4439 {
4440 Elf_External_Syminfo * extsyminfo;
4441 Elf_Internal_Syminfo * syminfo;
4442
4443 /* There is a syminfo section. Read the data. */
4444 extsyminfo = ((Elf_External_Syminfo *)
4445 get_data (NULL, file, dynamic_syminfo_offset,
4446 syminsz, _("symbol information")));
4447 if (!extsyminfo)
4448 return 0;
4449
4450 dynamic_syminfo = (Elf_Internal_Syminfo *) malloc (syminsz);
4451 if (dynamic_syminfo == NULL)
4452 {
4453 error (_("Out of memory\n"));
4454 return 0;
4455 }
4456
4457 dynamic_syminfo_nent = syminsz / sizeof (Elf_External_Syminfo);
4458 for (i = 0, syminfo = dynamic_syminfo; i < dynamic_syminfo_nent;
4459 ++i, ++syminfo)
4460 {
4461 syminfo->si_boundto = BYTE_GET (extsyminfo[i].si_boundto);
4462 syminfo->si_flags = BYTE_GET (extsyminfo[i].si_flags);
4463 }
4464
4465 free (extsyminfo);
4466 }
4467 }
4468
4469 if (do_dynamic && dynamic_addr)
4470 printf (_("\nDynamic segment at offset 0x%x contains %ld entries:\n"),
4471 dynamic_addr, (long) dynamic_size);
4472 if (do_dynamic)
4473 printf (_(" Tag Type Name/Value\n"));
4474
4475 for (i = 0, entry = dynamic_segment;
4476 i < dynamic_size;
4477 i++, entry ++)
4478 {
4479 if (do_dynamic)
4480 {
4481 const char * dtype;
4482
4483 putchar (' ');
4484 print_vma (entry->d_tag, FULL_HEX);
4485 dtype = get_dynamic_type (entry->d_tag);
4486 printf (" (%s)%*s", dtype,
4487 ((is_32bit_elf ? 27 : 19)
4488 - (int) strlen (dtype)),
4489 " ");
4490 }
4491
4492 switch (entry->d_tag)
4493 {
4494 case DT_FLAGS:
4495 if (do_dynamic)
4496 puts (get_dynamic_flags (entry->d_un.d_val));
4497 break;
4498
4499 case DT_AUXILIARY:
4500 case DT_FILTER:
4501 case DT_CONFIG:
4502 case DT_DEPAUDIT:
4503 case DT_AUDIT:
4504 if (do_dynamic)
4505 {
4506 switch (entry->d_tag)
4507 {
4508 case DT_AUXILIARY:
4509 printf (_("Auxiliary library"));
4510 break;
4511
4512 case DT_FILTER:
4513 printf (_("Filter library"));
4514 break;
4515
4516 case DT_CONFIG:
4517 printf (_("Configuration file"));
4518 break;
4519
4520 case DT_DEPAUDIT:
4521 printf (_("Dependency audit library"));
4522 break;
4523
4524 case DT_AUDIT:
4525 printf (_("Audit library"));
4526 break;
4527 }
4528
4529 if (dynamic_strings)
4530 printf (": [%s]\n", dynamic_strings + entry->d_un.d_val);
4531 else
4532 {
4533 printf (": ");
4534 print_vma (entry->d_un.d_val, PREFIX_HEX);
4535 putchar ('\n');
4536 }
4537 }
4538 break;
4539
4540 case DT_FEATURE:
4541 if (do_dynamic)
4542 {
4543 printf (_("Flags:"));
4544 if (entry->d_un.d_val == 0)
4545 printf (_(" None\n"));
4546 else
4547 {
4548 unsigned long int val = entry->d_un.d_val;
4549 if (val & DTF_1_PARINIT)
4550 {
4551 printf (" PARINIT");
4552 val ^= DTF_1_PARINIT;
4553 }
4554 if (val & DTF_1_CONFEXP)
4555 {
4556 printf (" CONFEXP");
4557 val ^= DTF_1_CONFEXP;
4558 }
4559 if (val != 0)
4560 printf (" %lx", val);
4561 puts ("");
4562 }
4563 }
4564 break;
4565
4566 case DT_POSFLAG_1:
4567 if (do_dynamic)
4568 {
4569 printf (_("Flags:"));
4570 if (entry->d_un.d_val == 0)
4571 printf (_(" None\n"));
4572 else
4573 {
4574 unsigned long int val = entry->d_un.d_val;
4575 if (val & DF_P1_LAZYLOAD)
4576 {
4577 printf (" LAZYLOAD");
4578 val ^= DF_P1_LAZYLOAD;
4579 }
4580 if (val & DF_P1_GROUPPERM)
4581 {
4582 printf (" GROUPPERM");
4583 val ^= DF_P1_GROUPPERM;
4584 }
4585 if (val != 0)
4586 printf (" %lx", val);
4587 puts ("");
4588 }
4589 }
4590 break;
4591
4592 case DT_FLAGS_1:
4593 if (do_dynamic)
4594 {
4595 printf (_("Flags:"));
4596 if (entry->d_un.d_val == 0)
4597 printf (_(" None\n"));
4598 else
4599 {
4600 unsigned long int val = entry->d_un.d_val;
4601 if (val & DF_1_NOW)
4602 {
4603 printf (" NOW");
4604 val ^= DF_1_NOW;
4605 }
4606 if (val & DF_1_GLOBAL)
4607 {
4608 printf (" GLOBAL");
4609 val ^= DF_1_GLOBAL;
4610 }
4611 if (val & DF_1_GROUP)
4612 {
4613 printf (" GROUP");
4614 val ^= DF_1_GROUP;
4615 }
4616 if (val & DF_1_NODELETE)
4617 {
4618 printf (" NODELETE");
4619 val ^= DF_1_NODELETE;
4620 }
4621 if (val & DF_1_LOADFLTR)
4622 {
4623 printf (" LOADFLTR");
4624 val ^= DF_1_LOADFLTR;
4625 }
4626 if (val & DF_1_INITFIRST)
4627 {
4628 printf (" INITFIRST");
4629 val ^= DF_1_INITFIRST;
4630 }
4631 if (val & DF_1_NOOPEN)
4632 {
4633 printf (" NOOPEN");
4634 val ^= DF_1_NOOPEN;
4635 }
4636 if (val & DF_1_ORIGIN)
4637 {
4638 printf (" ORIGIN");
4639 val ^= DF_1_ORIGIN;
4640 }
4641 if (val & DF_1_DIRECT)
4642 {
4643 printf (" DIRECT");
4644 val ^= DF_1_DIRECT;
4645 }
4646 if (val & DF_1_TRANS)
4647 {
4648 printf (" TRANS");
4649 val ^= DF_1_TRANS;
4650 }
4651 if (val & DF_1_INTERPOSE)
4652 {
4653 printf (" INTERPOSE");
4654 val ^= DF_1_INTERPOSE;
4655 }
4656 if (val & DF_1_NODEFLIB)
4657 {
4658 printf (" NODEFLIB");
4659 val ^= DF_1_NODEFLIB;
4660 }
4661 if (val & DF_1_NODUMP)
4662 {
4663 printf (" NODUMP");
4664 val ^= DF_1_NODUMP;
4665 }
4666 if (val & DF_1_CONLFAT)
4667 {
4668 printf (" CONLFAT");
4669 val ^= DF_1_CONLFAT;
4670 }
4671 if (val != 0)
4672 printf (" %lx", val);
4673 puts ("");
4674 }
4675 }
4676 break;
4677
4678 case DT_PLTREL:
4679 if (do_dynamic)
4680 puts (get_dynamic_type (entry->d_un.d_val));
4681 break;
4682
4683 case DT_NULL :
4684 case DT_NEEDED :
4685 case DT_PLTGOT :
4686 case DT_HASH :
4687 case DT_STRTAB :
4688 case DT_SYMTAB :
4689 case DT_RELA :
4690 case DT_INIT :
4691 case DT_FINI :
4692 case DT_SONAME :
4693 case DT_RPATH :
4694 case DT_SYMBOLIC:
4695 case DT_REL :
4696 case DT_DEBUG :
4697 case DT_TEXTREL :
4698 case DT_JMPREL :
4699 case DT_RUNPATH :
4700 dynamic_info[entry->d_tag] = entry->d_un.d_val;
4701
4702 if (do_dynamic)
4703 {
4704 char * name;
4705
4706 if (dynamic_strings == NULL)
4707 name = NULL;
4708 else
4709 name = dynamic_strings + entry->d_un.d_val;
4710
4711 if (name)
4712 {
4713 switch (entry->d_tag)
4714 {
4715 case DT_NEEDED:
4716 printf (_("Shared library: [%s]"), name);
4717
4718 if (strcmp (name, program_interpreter) == 0)
4719 printf (_(" program interpreter"));
4720 break;
4721
4722 case DT_SONAME:
4723 printf (_("Library soname: [%s]"), name);
4724 break;
4725
4726 case DT_RPATH:
4727 printf (_("Library rpath: [%s]"), name);
4728 break;
4729
4730 case DT_RUNPATH:
4731 printf (_("Library runpath: [%s]"), name);
4732 break;
4733
4734 default:
4735 print_vma (entry->d_un.d_val, PREFIX_HEX);
4736 break;
4737 }
4738 }
4739 else
4740 print_vma (entry->d_un.d_val, PREFIX_HEX);
4741
4742 putchar ('\n');
4743 }
4744 break;
4745
4746 case DT_PLTRELSZ:
4747 case DT_RELASZ :
4748 case DT_STRSZ :
4749 case DT_RELSZ :
4750 case DT_RELAENT :
4751 case DT_SYMENT :
4752 case DT_RELENT :
4753 case DT_PLTPADSZ:
4754 case DT_MOVEENT :
4755 case DT_MOVESZ :
4756 case DT_INIT_ARRAYSZ:
4757 case DT_FINI_ARRAYSZ:
4758 if (do_dynamic)
4759 {
4760 print_vma (entry->d_un.d_val, UNSIGNED);
4761 printf (" (bytes)\n");
4762 }
4763 break;
4764
4765 case DT_VERDEFNUM:
4766 case DT_VERNEEDNUM:
4767 case DT_RELACOUNT:
4768 case DT_RELCOUNT:
4769 if (do_dynamic)
4770 {
4771 print_vma (entry->d_un.d_val, UNSIGNED);
4772 putchar ('\n');
4773 }
4774 break;
4775
4776 case DT_SYMINSZ:
4777 case DT_SYMINENT:
4778 case DT_SYMINFO:
4779 case DT_USED:
4780 case DT_INIT_ARRAY:
4781 case DT_FINI_ARRAY:
4782 if (do_dynamic)
4783 {
4784 if (dynamic_strings != NULL && entry->d_tag == DT_USED)
4785 {
4786 char * name;
4787
4788 name = dynamic_strings + entry->d_un.d_val;
4789
4790 if (* name)
4791 {
4792 printf (_("Not needed object: [%s]\n"), name);
4793 break;
4794 }
4795 }
4796
4797 print_vma (entry->d_un.d_val, PREFIX_HEX);
4798 putchar ('\n');
4799 }
4800 break;
4801
4802 case DT_BIND_NOW:
4803 /* The value of this entry is ignored. */
4804 break;
4805
4806 default:
4807 if ((entry->d_tag >= DT_VERSYM) && (entry->d_tag <= DT_VERNEEDNUM))
4808 version_info [DT_VERSIONTAGIDX (entry->d_tag)] =
4809 entry->d_un.d_val;
4810
4811 if (do_dynamic)
4812 {
4813 switch (elf_header.e_machine)
4814 {
4815 case EM_MIPS:
4816 case EM_MIPS_RS3_LE:
4817 dynamic_segment_mips_val (entry);
4818 break;
4819 case EM_PARISC:
4820 dynamic_segment_parisc_val (entry);
4821 break;
4822 default:
4823 print_vma (entry->d_un.d_val, PREFIX_HEX);
4824 putchar ('\n');
4825 }
4826 }
4827 break;
4828 }
4829 }
4830
4831 return 1;
4832 }
4833
4834 static char *
4835 get_ver_flags (flags)
4836 unsigned int flags;
4837 {
4838 static char buff [32];
4839
4840 buff[0] = 0;
4841
4842 if (flags == 0)
4843 return _("none");
4844
4845 if (flags & VER_FLG_BASE)
4846 strcat (buff, "BASE ");
4847
4848 if (flags & VER_FLG_WEAK)
4849 {
4850 if (flags & VER_FLG_BASE)
4851 strcat (buff, "| ");
4852
4853 strcat (buff, "WEAK ");
4854 }
4855
4856 if (flags & ~(VER_FLG_BASE | VER_FLG_WEAK))
4857 strcat (buff, "| <unknown>");
4858
4859 return buff;
4860 }
4861
4862 /* Display the contents of the version sections. */
4863 static int
4864 process_version_sections (file)
4865 FILE * file;
4866 {
4867 Elf32_Internal_Shdr * section;
4868 unsigned i;
4869 int found = 0;
4870
4871 if (! do_version)
4872 return 1;
4873
4874 for (i = 0, section = section_headers;
4875 i < elf_header.e_shnum;
4876 i++, section ++)
4877 {
4878 switch (section->sh_type)
4879 {
4880 case SHT_GNU_verdef:
4881 {
4882 Elf_External_Verdef * edefs;
4883 unsigned int idx;
4884 unsigned int cnt;
4885
4886 found = 1;
4887
4888 printf
4889 (_("\nVersion definition section '%s' contains %ld entries:\n"),
4890 SECTION_NAME (section), section->sh_info);
4891
4892 printf (_(" Addr: 0x"));
4893 printf_vma (section->sh_addr);
4894 printf (_(" Offset: %#08lx Link: %lx (%s)\n"),
4895 (unsigned long) section->sh_offset, section->sh_link,
4896 SECTION_NAME (SECTION_HEADER (section->sh_link)));
4897
4898 edefs = ((Elf_External_Verdef *)
4899 get_data (NULL, file, section->sh_offset,
4900 section->sh_size,
4901 _("version definition section")));
4902 if (!edefs)
4903 break;
4904
4905 for (idx = cnt = 0; cnt < section->sh_info; ++ cnt)
4906 {
4907 char * vstart;
4908 Elf_External_Verdef * edef;
4909 Elf_Internal_Verdef ent;
4910 Elf_External_Verdaux * eaux;
4911 Elf_Internal_Verdaux aux;
4912 int j;
4913 int isum;
4914
4915 vstart = ((char *) edefs) + idx;
4916
4917 edef = (Elf_External_Verdef *) vstart;
4918
4919 ent.vd_version = BYTE_GET (edef->vd_version);
4920 ent.vd_flags = BYTE_GET (edef->vd_flags);
4921 ent.vd_ndx = BYTE_GET (edef->vd_ndx);
4922 ent.vd_cnt = BYTE_GET (edef->vd_cnt);
4923 ent.vd_hash = BYTE_GET (edef->vd_hash);
4924 ent.vd_aux = BYTE_GET (edef->vd_aux);
4925 ent.vd_next = BYTE_GET (edef->vd_next);
4926
4927 printf (_(" %#06x: Rev: %d Flags: %s"),
4928 idx, ent.vd_version, get_ver_flags (ent.vd_flags));
4929
4930 printf (_(" Index: %d Cnt: %d "),
4931 ent.vd_ndx, ent.vd_cnt);
4932
4933 vstart += ent.vd_aux;
4934
4935 eaux = (Elf_External_Verdaux *) vstart;
4936
4937 aux.vda_name = BYTE_GET (eaux->vda_name);
4938 aux.vda_next = BYTE_GET (eaux->vda_next);
4939
4940 if (dynamic_strings)
4941 printf (_("Name: %s\n"), dynamic_strings + aux.vda_name);
4942 else
4943 printf (_("Name index: %ld\n"), aux.vda_name);
4944
4945 isum = idx + ent.vd_aux;
4946
4947 for (j = 1; j < ent.vd_cnt; j ++)
4948 {
4949 isum += aux.vda_next;
4950 vstart += aux.vda_next;
4951
4952 eaux = (Elf_External_Verdaux *) vstart;
4953
4954 aux.vda_name = BYTE_GET (eaux->vda_name);
4955 aux.vda_next = BYTE_GET (eaux->vda_next);
4956
4957 if (dynamic_strings)
4958 printf (_(" %#06x: Parent %d: %s\n"),
4959 isum, j, dynamic_strings + aux.vda_name);
4960 else
4961 printf (_(" %#06x: Parent %d, name index: %ld\n"),
4962 isum, j, aux.vda_name);
4963 }
4964
4965 idx += ent.vd_next;
4966 }
4967
4968 free (edefs);
4969 }
4970 break;
4971
4972 case SHT_GNU_verneed:
4973 {
4974 Elf_External_Verneed * eneed;
4975 unsigned int idx;
4976 unsigned int cnt;
4977
4978 found = 1;
4979
4980 printf (_("\nVersion needs section '%s' contains %ld entries:\n"),
4981 SECTION_NAME (section), section->sh_info);
4982
4983 printf (_(" Addr: 0x"));
4984 printf_vma (section->sh_addr);
4985 printf (_(" Offset: %#08lx Link to section: %ld (%s)\n"),
4986 (unsigned long) section->sh_offset, section->sh_link,
4987 SECTION_NAME (SECTION_HEADER (section->sh_link)));
4988
4989 eneed = ((Elf_External_Verneed *)
4990 get_data (NULL, file, section->sh_offset,
4991 section->sh_size, _("version need section")));
4992 if (!eneed)
4993 break;
4994
4995 for (idx = cnt = 0; cnt < section->sh_info; ++cnt)
4996 {
4997 Elf_External_Verneed * entry;
4998 Elf_Internal_Verneed ent;
4999 int j;
5000 int isum;
5001 char * vstart;
5002
5003 vstart = ((char *) eneed) + idx;
5004
5005 entry = (Elf_External_Verneed *) vstart;
5006
5007 ent.vn_version = BYTE_GET (entry->vn_version);
5008 ent.vn_cnt = BYTE_GET (entry->vn_cnt);
5009 ent.vn_file = BYTE_GET (entry->vn_file);
5010 ent.vn_aux = BYTE_GET (entry->vn_aux);
5011 ent.vn_next = BYTE_GET (entry->vn_next);
5012
5013 printf (_(" %#06x: Version: %d"), idx, ent.vn_version);
5014
5015 if (dynamic_strings)
5016 printf (_(" File: %s"), dynamic_strings + ent.vn_file);
5017 else
5018 printf (_(" File: %lx"), ent.vn_file);
5019
5020 printf (_(" Cnt: %d\n"), ent.vn_cnt);
5021
5022 vstart += ent.vn_aux;
5023
5024 for (j = 0, isum = idx + ent.vn_aux; j < ent.vn_cnt; ++j)
5025 {
5026 Elf_External_Vernaux * eaux;
5027 Elf_Internal_Vernaux aux;
5028
5029 eaux = (Elf_External_Vernaux *) vstart;
5030
5031 aux.vna_hash = BYTE_GET (eaux->vna_hash);
5032 aux.vna_flags = BYTE_GET (eaux->vna_flags);
5033 aux.vna_other = BYTE_GET (eaux->vna_other);
5034 aux.vna_name = BYTE_GET (eaux->vna_name);
5035 aux.vna_next = BYTE_GET (eaux->vna_next);
5036
5037 if (dynamic_strings)
5038 printf (_(" %#06x: Name: %s"),
5039 isum, dynamic_strings + aux.vna_name);
5040 else
5041 printf (_(" %#06x: Name index: %lx"),
5042 isum, aux.vna_name);
5043
5044 printf (_(" Flags: %s Version: %d\n"),
5045 get_ver_flags (aux.vna_flags), aux.vna_other);
5046
5047 isum += aux.vna_next;
5048 vstart += aux.vna_next;
5049 }
5050
5051 idx += ent.vn_next;
5052 }
5053
5054 free (eneed);
5055 }
5056 break;
5057
5058 case SHT_GNU_versym:
5059 {
5060 Elf32_Internal_Shdr * link_section;
5061 int total;
5062 int cnt;
5063 unsigned char * edata;
5064 unsigned short * data;
5065 char * strtab;
5066 Elf_Internal_Sym * symbols;
5067 Elf32_Internal_Shdr * string_sec;
5068
5069 link_section = SECTION_HEADER (section->sh_link);
5070 total = section->sh_size / section->sh_entsize;
5071
5072 found = 1;
5073
5074 symbols = GET_ELF_SYMBOLS (file, link_section);
5075
5076 string_sec = SECTION_HEADER (link_section->sh_link);
5077
5078 strtab = (char *) get_data (NULL, file, string_sec->sh_offset,
5079 string_sec->sh_size,
5080 _("version string table"));
5081 if (!strtab)
5082 break;
5083
5084 printf (_("\nVersion symbols section '%s' contains %d entries:\n"),
5085 SECTION_NAME (section), total);
5086
5087 printf (_(" Addr: "));
5088 printf_vma (section->sh_addr);
5089 printf (_(" Offset: %#08lx Link: %lx (%s)\n"),
5090 (unsigned long) section->sh_offset, section->sh_link,
5091 SECTION_NAME (link_section));
5092
5093 edata =
5094 ((unsigned char *)
5095 get_data (NULL, file,
5096 version_info[DT_VERSIONTAGIDX (DT_VERSYM)] - loadaddr,
5097 total * sizeof (short), _("version symbol data")));
5098 if (!edata)
5099 {
5100 free (strtab);
5101 break;
5102 }
5103
5104 data = (unsigned short *) malloc (total * sizeof (short));
5105
5106 for (cnt = total; cnt --;)
5107 data [cnt] = byte_get (edata + cnt * sizeof (short),
5108 sizeof (short));
5109
5110 free (edata);
5111
5112 for (cnt = 0; cnt < total; cnt += 4)
5113 {
5114 int j, nn;
5115 int check_def, check_need;
5116 char * name;
5117
5118 printf (" %03x:", cnt);
5119
5120 for (j = 0; (j < 4) && (cnt + j) < total; ++j)
5121 switch (data [cnt + j])
5122 {
5123 case 0:
5124 fputs (_(" 0 (*local*) "), stdout);
5125 break;
5126
5127 case 1:
5128 fputs (_(" 1 (*global*) "), stdout);
5129 break;
5130
5131 default:
5132 nn = printf ("%4x%c", data [cnt + j] & 0x7fff,
5133 data [cnt + j] & 0x8000 ? 'h' : ' ');
5134
5135 check_def = 1;
5136 check_need = 1;
5137 if (SECTION_HEADER (symbols [cnt + j].st_shndx)->sh_type
5138 != SHT_NOBITS)
5139 {
5140 if (symbols [cnt + j].st_shndx == SHN_UNDEF)
5141 check_def = 0;
5142 else
5143 check_need = 0;
5144 }
5145
5146 if (check_need
5147 && version_info [DT_VERSIONTAGIDX (DT_VERNEED)])
5148 {
5149 Elf_Internal_Verneed ivn;
5150 unsigned long offset;
5151
5152 offset = version_info [DT_VERSIONTAGIDX (DT_VERNEED)]
5153 - loadaddr;
5154
5155 do
5156 {
5157 Elf_Internal_Vernaux ivna;
5158 Elf_External_Verneed evn;
5159 Elf_External_Vernaux evna;
5160 unsigned long a_off;
5161
5162 get_data (&evn, file, offset, sizeof (evn),
5163 _("version need"));
5164
5165 ivn.vn_aux = BYTE_GET (evn.vn_aux);
5166 ivn.vn_next = BYTE_GET (evn.vn_next);
5167
5168 a_off = offset + ivn.vn_aux;
5169
5170 do
5171 {
5172 get_data (&evna, file, a_off, sizeof (evna),
5173 _("version need aux (2)"));
5174
5175 ivna.vna_next = BYTE_GET (evna.vna_next);
5176 ivna.vna_other = BYTE_GET (evna.vna_other);
5177
5178 a_off += ivna.vna_next;
5179 }
5180 while (ivna.vna_other != data [cnt + j]
5181 && ivna.vna_next != 0);
5182
5183 if (ivna.vna_other == data [cnt + j])
5184 {
5185 ivna.vna_name = BYTE_GET (evna.vna_name);
5186
5187 name = strtab + ivna.vna_name;
5188 nn += printf ("(%s%-*s",
5189 name,
5190 12 - (int) strlen (name),
5191 ")");
5192 check_def = 0;
5193 break;
5194 }
5195
5196 offset += ivn.vn_next;
5197 }
5198 while (ivn.vn_next);
5199 }
5200
5201 if (check_def && data [cnt + j] != 0x8001
5202 && version_info [DT_VERSIONTAGIDX (DT_VERDEF)])
5203 {
5204 Elf_Internal_Verdef ivd;
5205 Elf_External_Verdef evd;
5206 unsigned long offset;
5207
5208 offset = version_info
5209 [DT_VERSIONTAGIDX (DT_VERDEF)] - loadaddr;
5210
5211 do
5212 {
5213 get_data (&evd, file, offset, sizeof (evd),
5214 _("version def"));
5215
5216 ivd.vd_next = BYTE_GET (evd.vd_next);
5217 ivd.vd_ndx = BYTE_GET (evd.vd_ndx);
5218
5219 offset += ivd.vd_next;
5220 }
5221 while (ivd.vd_ndx != (data [cnt + j] & 0x7fff)
5222 && ivd.vd_next != 0);
5223
5224 if (ivd.vd_ndx == (data [cnt + j] & 0x7fff))
5225 {
5226 Elf_External_Verdaux evda;
5227 Elf_Internal_Verdaux ivda;
5228
5229 ivd.vd_aux = BYTE_GET (evd.vd_aux);
5230
5231 get_data (&evda, file,
5232 offset - ivd.vd_next + ivd.vd_aux,
5233 sizeof (evda), _("version def aux"));
5234
5235 ivda.vda_name = BYTE_GET (evda.vda_name);
5236
5237 name = strtab + ivda.vda_name;
5238 nn += printf ("(%s%-*s",
5239 name,
5240 12 - (int) strlen (name),
5241 ")");
5242 }
5243 }
5244
5245 if (nn < 18)
5246 printf ("%*c", 18 - nn, ' ');
5247 }
5248
5249 putchar ('\n');
5250 }
5251
5252 free (data);
5253 free (strtab);
5254 free (symbols);
5255 }
5256 break;
5257
5258 default:
5259 break;
5260 }
5261 }
5262
5263 if (! found)
5264 printf (_("\nNo version information found in this file.\n"));
5265
5266 return 1;
5267 }
5268
5269 static const char *
5270 get_symbol_binding (binding)
5271 unsigned int binding;
5272 {
5273 static char buff [32];
5274
5275 switch (binding)
5276 {
5277 case STB_LOCAL: return "LOCAL";
5278 case STB_GLOBAL: return "GLOBAL";
5279 case STB_WEAK: return "WEAK";
5280 default:
5281 if (binding >= STB_LOPROC && binding <= STB_HIPROC)
5282 sprintf (buff, _("<processor specific>: %d"), binding);
5283 else if (binding >= STB_LOOS && binding <= STB_HIOS)
5284 sprintf (buff, _("<OS specific>: %d"), binding);
5285 else
5286 sprintf (buff, _("<unknown>: %d"), binding);
5287 return buff;
5288 }
5289 }
5290
5291 static const char *
5292 get_symbol_type (type)
5293 unsigned int type;
5294 {
5295 static char buff [32];
5296
5297 switch (type)
5298 {
5299 case STT_NOTYPE: return "NOTYPE";
5300 case STT_OBJECT: return "OBJECT";
5301 case STT_FUNC: return "FUNC";
5302 case STT_SECTION: return "SECTION";
5303 case STT_FILE: return "FILE";
5304 case STT_COMMON: return "COMMON";
5305 case STT_TLS: return "TLS";
5306 default:
5307 if (type >= STT_LOPROC && type <= STT_HIPROC)
5308 {
5309 if (elf_header.e_machine == EM_ARM && type == STT_ARM_TFUNC)
5310 return "THUMB_FUNC";
5311
5312 if (elf_header.e_machine == EM_SPARCV9 && type == STT_REGISTER)
5313 return "REGISTER";
5314
5315 if (elf_header.e_machine == EM_PARISC && type == STT_PARISC_MILLI)
5316 return "PARISC_MILLI";
5317
5318 sprintf (buff, _("<processor specific>: %d"), type);
5319 }
5320 else if (type >= STT_LOOS && type <= STT_HIOS)
5321 {
5322 if (elf_header.e_machine == EM_PARISC)
5323 {
5324 if (type == STT_HP_OPAQUE)
5325 return "HP_OPAQUE";
5326 if (type == STT_HP_STUB)
5327 return "HP_STUB";
5328 }
5329
5330 sprintf (buff, _("<OS specific>: %d"), type);
5331 }
5332 else
5333 sprintf (buff, _("<unknown>: %d"), type);
5334 return buff;
5335 }
5336 }
5337
5338 static const char *
5339 get_symbol_visibility (visibility)
5340 unsigned int visibility;
5341 {
5342 switch (visibility)
5343 {
5344 case STV_DEFAULT: return "DEFAULT";
5345 case STV_INTERNAL: return "INTERNAL";
5346 case STV_HIDDEN: return "HIDDEN";
5347 case STV_PROTECTED: return "PROTECTED";
5348 default: abort ();
5349 }
5350 }
5351
5352 static const char *
5353 get_symbol_index_type (type)
5354 unsigned int type;
5355 {
5356 switch (type)
5357 {
5358 case SHN_UNDEF: return "UND";
5359 case SHN_ABS: return "ABS";
5360 case SHN_COMMON: return "COM";
5361 default:
5362 if (type >= SHN_LOPROC && type <= SHN_HIPROC)
5363 return "PRC";
5364 else if (type >= SHN_LOOS && type <= SHN_HIOS)
5365 return "OS ";
5366 else if (type >= SHN_LORESERVE && type <= SHN_HIRESERVE)
5367 return "RSV";
5368 else
5369 {
5370 static char buff [32];
5371
5372 sprintf (buff, "%3d", type);
5373 return buff;
5374 }
5375 }
5376 }
5377
5378 static int *
5379 get_dynamic_data (file, number)
5380 FILE * file;
5381 unsigned int number;
5382 {
5383 unsigned char * e_data;
5384 int * i_data;
5385
5386 e_data = (unsigned char *) malloc (number * 4);
5387
5388 if (e_data == NULL)
5389 {
5390 error (_("Out of memory\n"));
5391 return NULL;
5392 }
5393
5394 if (fread (e_data, 4, number, file) != number)
5395 {
5396 error (_("Unable to read in dynamic data\n"));
5397 return NULL;
5398 }
5399
5400 i_data = (int *) malloc (number * sizeof (* i_data));
5401
5402 if (i_data == NULL)
5403 {
5404 error (_("Out of memory\n"));
5405 free (e_data);
5406 return NULL;
5407 }
5408
5409 while (number--)
5410 i_data [number] = byte_get (e_data + number * 4, 4);
5411
5412 free (e_data);
5413
5414 return i_data;
5415 }
5416
5417 /* Dump the symbol table. */
5418 static int
5419 process_symbol_table (file)
5420 FILE * file;
5421 {
5422 Elf32_Internal_Shdr * section;
5423 unsigned char nb [4];
5424 unsigned char nc [4];
5425 int nbuckets = 0;
5426 int nchains = 0;
5427 int * buckets = NULL;
5428 int * chains = NULL;
5429
5430 if (! do_syms && !do_histogram)
5431 return 1;
5432
5433 if (dynamic_info[DT_HASH] && ((do_using_dynamic && dynamic_strings != NULL)
5434 || do_histogram))
5435 {
5436 if (fseek (file, dynamic_info[DT_HASH] - loadaddr, SEEK_SET))
5437 {
5438 error (_("Unable to seek to start of dynamic information"));
5439 return 0;
5440 }
5441
5442 if (fread (nb, sizeof (nb), 1, file) != 1)
5443 {
5444 error (_("Failed to read in number of buckets\n"));
5445 return 0;
5446 }
5447
5448 if (fread (nc, sizeof (nc), 1, file) != 1)
5449 {
5450 error (_("Failed to read in number of chains\n"));
5451 return 0;
5452 }
5453
5454 nbuckets = byte_get (nb, 4);
5455 nchains = byte_get (nc, 4);
5456
5457 buckets = get_dynamic_data (file, nbuckets);
5458 chains = get_dynamic_data (file, nchains);
5459
5460 if (buckets == NULL || chains == NULL)
5461 return 0;
5462 }
5463
5464 if (do_syms
5465 && dynamic_info[DT_HASH] && do_using_dynamic && dynamic_strings != NULL)
5466 {
5467 int hn;
5468 int si;
5469
5470 printf (_("\nSymbol table for image:\n"));
5471 if (is_32bit_elf)
5472 printf (_(" Num Buc: Value Size Type Bind Vis Ndx Name\n"));
5473 else
5474 printf (_(" Num Buc: Value Size Type Bind Vis Ndx Name\n"));
5475
5476 for (hn = 0; hn < nbuckets; hn++)
5477 {
5478 if (! buckets [hn])
5479 continue;
5480
5481 for (si = buckets [hn]; si < nchains && si > 0; si = chains [si])
5482 {
5483 Elf_Internal_Sym * psym;
5484
5485 psym = dynamic_symbols + si;
5486
5487 printf (" %3d %3d: ", si, hn);
5488 print_vma (psym->st_value, LONG_HEX);
5489 putchar (' ' );
5490 print_vma (psym->st_size, DEC_5);
5491
5492 printf (" %6s", get_symbol_type (ELF_ST_TYPE (psym->st_info)));
5493 printf (" %6s", get_symbol_binding (ELF_ST_BIND (psym->st_info)));
5494 printf (" %3s", get_symbol_visibility (ELF_ST_VISIBILITY (psym->st_other)));
5495 printf (" %3.3s ", get_symbol_index_type (psym->st_shndx));
5496 print_symbol (25, dynamic_strings + psym->st_name);
5497 putchar ('\n');
5498 }
5499 }
5500 }
5501 else if (do_syms && !do_using_dynamic)
5502 {
5503 unsigned int i;
5504
5505 for (i = 0, section = section_headers;
5506 i < elf_header.e_shnum;
5507 i++, section++)
5508 {
5509 unsigned int si;
5510 char * strtab;
5511 Elf_Internal_Sym * symtab;
5512 Elf_Internal_Sym * psym;
5513
5514
5515 if ( section->sh_type != SHT_SYMTAB
5516 && section->sh_type != SHT_DYNSYM)
5517 continue;
5518
5519 printf (_("\nSymbol table '%s' contains %lu entries:\n"),
5520 SECTION_NAME (section),
5521 (unsigned long) (section->sh_size / section->sh_entsize));
5522 if (is_32bit_elf)
5523 printf (_(" Num: Value Size Type Bind Vis Ndx Name\n"));
5524 else
5525 printf (_(" Num: Value Size Type Bind Vis Ndx Name\n"));
5526
5527 symtab = GET_ELF_SYMBOLS (file, section);
5528 if (symtab == NULL)
5529 continue;
5530
5531 if (section->sh_link == elf_header.e_shstrndx)
5532 strtab = string_table;
5533 else
5534 {
5535 Elf32_Internal_Shdr * string_sec;
5536
5537 string_sec = SECTION_HEADER (section->sh_link);
5538
5539 strtab = (char *) get_data (NULL, file, string_sec->sh_offset,
5540 string_sec->sh_size,
5541 _("string table"));
5542 }
5543
5544 for (si = 0, psym = symtab;
5545 si < section->sh_size / section->sh_entsize;
5546 si ++, psym ++)
5547 {
5548 printf ("%6d: ", si);
5549 print_vma (psym->st_value, LONG_HEX);
5550 putchar (' ');
5551 print_vma (psym->st_size, DEC_5);
5552 printf (" %-7s", get_symbol_type (ELF_ST_TYPE (psym->st_info)));
5553 printf (" %-6s", get_symbol_binding (ELF_ST_BIND (psym->st_info)));
5554 printf (" %-3s", get_symbol_visibility (ELF_ST_VISIBILITY (psym->st_other)));
5555 printf (" %4s ", get_symbol_index_type (psym->st_shndx));
5556 print_symbol (25, strtab + psym->st_name);
5557
5558 if (section->sh_type == SHT_DYNSYM &&
5559 version_info [DT_VERSIONTAGIDX (DT_VERSYM)] != 0)
5560 {
5561 unsigned char data[2];
5562 unsigned short vers_data;
5563 unsigned long offset;
5564 int is_nobits;
5565 int check_def;
5566
5567 offset = version_info [DT_VERSIONTAGIDX (DT_VERSYM)]
5568 - loadaddr;
5569
5570 get_data (&data, file, offset + si * sizeof (vers_data),
5571 sizeof (data), _("version data"));
5572
5573 vers_data = byte_get (data, 2);
5574
5575 is_nobits = (SECTION_HEADER (psym->st_shndx)->sh_type
5576 == SHT_NOBITS);
5577
5578 check_def = (psym->st_shndx != SHN_UNDEF);
5579
5580 if ((vers_data & 0x8000) || vers_data > 1)
5581 {
5582 if (version_info [DT_VERSIONTAGIDX (DT_VERNEED)]
5583 && (is_nobits || ! check_def))
5584 {
5585 Elf_External_Verneed evn;
5586 Elf_Internal_Verneed ivn;
5587 Elf_Internal_Vernaux ivna;
5588
5589 /* We must test both. */
5590 offset = version_info
5591 [DT_VERSIONTAGIDX (DT_VERNEED)] - loadaddr;
5592
5593 do
5594 {
5595 unsigned long vna_off;
5596
5597 get_data (&evn, file, offset, sizeof (evn),
5598 _("version need"));
5599
5600 ivn.vn_aux = BYTE_GET (evn.vn_aux);
5601 ivn.vn_next = BYTE_GET (evn.vn_next);
5602
5603 vna_off = offset + ivn.vn_aux;
5604
5605 do
5606 {
5607 Elf_External_Vernaux evna;
5608
5609 get_data (&evna, file, vna_off,
5610 sizeof (evna),
5611 _("version need aux (3)"));
5612
5613 ivna.vna_other = BYTE_GET (evna.vna_other);
5614 ivna.vna_next = BYTE_GET (evna.vna_next);
5615 ivna.vna_name = BYTE_GET (evna.vna_name);
5616
5617 vna_off += ivna.vna_next;
5618 }
5619 while (ivna.vna_other != vers_data
5620 && ivna.vna_next != 0);
5621
5622 if (ivna.vna_other == vers_data)
5623 break;
5624
5625 offset += ivn.vn_next;
5626 }
5627 while (ivn.vn_next != 0);
5628
5629 if (ivna.vna_other == vers_data)
5630 {
5631 printf ("@%s (%d)",
5632 strtab + ivna.vna_name, ivna.vna_other);
5633 check_def = 0;
5634 }
5635 else if (! is_nobits)
5636 error (_("bad dynamic symbol"));
5637 else
5638 check_def = 1;
5639 }
5640
5641 if (check_def)
5642 {
5643 if (vers_data != 0x8001
5644 && version_info [DT_VERSIONTAGIDX (DT_VERDEF)])
5645 {
5646 Elf_Internal_Verdef ivd;
5647 Elf_Internal_Verdaux ivda;
5648 Elf_External_Verdaux evda;
5649 unsigned long offset;
5650
5651 offset =
5652 version_info [DT_VERSIONTAGIDX (DT_VERDEF)]
5653 - loadaddr;
5654
5655 do
5656 {
5657 Elf_External_Verdef evd;
5658
5659 get_data (&evd, file, offset, sizeof (evd),
5660 _("version def"));
5661
5662 ivd.vd_ndx = BYTE_GET (evd.vd_ndx);
5663 ivd.vd_aux = BYTE_GET (evd.vd_aux);
5664 ivd.vd_next = BYTE_GET (evd.vd_next);
5665
5666 offset += ivd.vd_next;
5667 }
5668 while (ivd.vd_ndx != (vers_data & 0x7fff)
5669 && ivd.vd_next != 0);
5670
5671 offset -= ivd.vd_next;
5672 offset += ivd.vd_aux;
5673
5674 get_data (&evda, file, offset, sizeof (evda),
5675 _("version def aux"));
5676
5677 ivda.vda_name = BYTE_GET (evda.vda_name);
5678
5679 if (psym->st_name != ivda.vda_name)
5680 printf ((vers_data & 0x8000)
5681 ? "@%s" : "@@%s",
5682 strtab + ivda.vda_name);
5683 }
5684 }
5685 }
5686 }
5687
5688 putchar ('\n');
5689 }
5690
5691 free (symtab);
5692 if (strtab != string_table)
5693 free (strtab);
5694 }
5695 }
5696 else if (do_syms)
5697 printf
5698 (_("\nDynamic symbol information is not available for displaying symbols.\n"));
5699
5700 if (do_histogram && buckets != NULL)
5701 {
5702 int * lengths;
5703 int * counts;
5704 int hn;
5705 int si;
5706 int maxlength = 0;
5707 int nzero_counts = 0;
5708 int nsyms = 0;
5709
5710 printf (_("\nHistogram for bucket list length (total of %d buckets):\n"),
5711 nbuckets);
5712 printf (_(" Length Number %% of total Coverage\n"));
5713
5714 lengths = (int *) calloc (nbuckets, sizeof (int));
5715 if (lengths == NULL)
5716 {
5717 error (_("Out of memory"));
5718 return 0;
5719 }
5720 for (hn = 0; hn < nbuckets; ++hn)
5721 {
5722 if (! buckets [hn])
5723 continue;
5724
5725 for (si = buckets[hn]; si > 0 && si < nchains; si = chains[si])
5726 {
5727 ++ nsyms;
5728 if (maxlength < ++lengths[hn])
5729 ++ maxlength;
5730 }
5731 }
5732
5733 counts = (int *) calloc (maxlength + 1, sizeof (int));
5734 if (counts == NULL)
5735 {
5736 error (_("Out of memory"));
5737 return 0;
5738 }
5739
5740 for (hn = 0; hn < nbuckets; ++hn)
5741 ++ counts [lengths [hn]];
5742
5743 if (nbuckets > 0)
5744 {
5745 printf (" 0 %-10d (%5.1f%%)\n",
5746 counts[0], (counts[0] * 100.0) / nbuckets);
5747 for (si = 1; si <= maxlength; ++si)
5748 {
5749 nzero_counts += counts[si] * si;
5750 printf ("%7d %-10d (%5.1f%%) %5.1f%%\n",
5751 si, counts[si], (counts[si] * 100.0) / nbuckets,
5752 (nzero_counts * 100.0) / nsyms);
5753 }
5754 }
5755
5756 free (counts);
5757 free (lengths);
5758 }
5759
5760 if (buckets != NULL)
5761 {
5762 free (buckets);
5763 free (chains);
5764 }
5765
5766 return 1;
5767 }
5768
5769 static int
5770 process_syminfo (file)
5771 FILE * file ATTRIBUTE_UNUSED;
5772 {
5773 unsigned int i;
5774
5775 if (dynamic_syminfo == NULL
5776 || !do_dynamic)
5777 /* No syminfo, this is ok. */
5778 return 1;
5779
5780 /* There better should be a dynamic symbol section. */
5781 if (dynamic_symbols == NULL || dynamic_strings == NULL)
5782 return 0;
5783
5784 if (dynamic_addr)
5785 printf (_("\nDynamic info segment at offset 0x%lx contains %d entries:\n"),
5786 dynamic_syminfo_offset, dynamic_syminfo_nent);
5787
5788 printf (_(" Num: Name BoundTo Flags\n"));
5789 for (i = 0; i < dynamic_syminfo_nent; ++i)
5790 {
5791 unsigned short int flags = dynamic_syminfo[i].si_flags;
5792
5793 printf ("%4d: ", i);
5794 print_symbol (30, dynamic_strings + dynamic_symbols[i].st_name);
5795 putchar (' ');
5796
5797 switch (dynamic_syminfo[i].si_boundto)
5798 {
5799 case SYMINFO_BT_SELF:
5800 fputs ("SELF ", stdout);
5801 break;
5802 case SYMINFO_BT_PARENT:
5803 fputs ("PARENT ", stdout);
5804 break;
5805 default:
5806 if (dynamic_syminfo[i].si_boundto > 0
5807 && dynamic_syminfo[i].si_boundto < dynamic_size)
5808 {
5809 print_symbol (10, dynamic_strings
5810 + dynamic_segment
5811 [dynamic_syminfo[i].si_boundto].d_un.d_val);
5812 putchar (' ' );
5813 }
5814 else
5815 printf ("%-10d ", dynamic_syminfo[i].si_boundto);
5816 break;
5817 }
5818
5819 if (flags & SYMINFO_FLG_DIRECT)
5820 printf (" DIRECT");
5821 if (flags & SYMINFO_FLG_PASSTHRU)
5822 printf (" PASSTHRU");
5823 if (flags & SYMINFO_FLG_COPY)
5824 printf (" COPY");
5825 if (flags & SYMINFO_FLG_LAZYLOAD)
5826 printf (" LAZYLOAD");
5827
5828 puts ("");
5829 }
5830
5831 return 1;
5832 }
5833
5834 #ifdef SUPPORT_DISASSEMBLY
5835 static void
5836 disassemble_section (section, file)
5837 Elf32_Internal_Shdr * section;
5838 FILE * file;
5839 {
5840 printf (_("\nAssembly dump of section %s\n"),
5841 SECTION_NAME (section));
5842
5843 /* XXX -- to be done --- XXX */
5844
5845 return 1;
5846 }
5847 #endif
5848
5849 static int
5850 dump_section (section, file)
5851 Elf32_Internal_Shdr * section;
5852 FILE * file;
5853 {
5854 bfd_size_type bytes;
5855 bfd_vma addr;
5856 unsigned char * data;
5857 unsigned char * start;
5858
5859 bytes = section->sh_size;
5860
5861 if (bytes == 0)
5862 {
5863 printf (_("\nSection '%s' has no data to dump.\n"),
5864 SECTION_NAME (section));
5865 return 0;
5866 }
5867 else
5868 printf (_("\nHex dump of section '%s':\n"), SECTION_NAME (section));
5869
5870 addr = section->sh_addr;
5871
5872 start = (unsigned char *) get_data (NULL, file, section->sh_offset, bytes,
5873 _("section data"));
5874 if (!start)
5875 return 0;
5876
5877 data = start;
5878
5879 while (bytes)
5880 {
5881 int j;
5882 int k;
5883 int lbytes;
5884
5885 lbytes = (bytes > 16 ? 16 : bytes);
5886
5887 printf (" 0x%8.8lx ", (unsigned long) addr);
5888
5889 switch (elf_header.e_ident [EI_DATA])
5890 {
5891 default:
5892 case ELFDATA2LSB:
5893 for (j = 15; j >= 0; j --)
5894 {
5895 if (j < lbytes)
5896 printf ("%2.2x", data [j]);
5897 else
5898 printf (" ");
5899
5900 if (!(j & 0x3))
5901 printf (" ");
5902 }
5903 break;
5904
5905 case ELFDATA2MSB:
5906 for (j = 0; j < 16; j++)
5907 {
5908 if (j < lbytes)
5909 printf ("%2.2x", data [j]);
5910 else
5911 printf (" ");
5912
5913 if ((j & 3) == 3)
5914 printf (" ");
5915 }
5916 break;
5917 }
5918
5919 for (j = 0; j < lbytes; j++)
5920 {
5921 k = data [j];
5922 if (k >= ' ' && k < 0x80)
5923 printf ("%c", k);
5924 else
5925 printf (".");
5926 }
5927
5928 putchar ('\n');
5929
5930 data += lbytes;
5931 addr += lbytes;
5932 bytes -= lbytes;
5933 }
5934
5935 free (start);
5936
5937 return 1;
5938 }
5939
5940
5941 static unsigned long int
5942 read_leb128 (data, length_return, sign)
5943 unsigned char * data;
5944 int * length_return;
5945 int sign;
5946 {
5947 unsigned long int result = 0;
5948 unsigned int num_read = 0;
5949 int shift = 0;
5950 unsigned char byte;
5951
5952 do
5953 {
5954 byte = * data ++;
5955 num_read ++;
5956
5957 result |= (byte & 0x7f) << shift;
5958
5959 shift += 7;
5960
5961 }
5962 while (byte & 0x80);
5963
5964 if (length_return != NULL)
5965 * length_return = num_read;
5966
5967 if (sign && (shift < 32) && (byte & 0x40))
5968 result |= -1 << shift;
5969
5970 return result;
5971 }
5972
5973 typedef struct State_Machine_Registers
5974 {
5975 unsigned long address;
5976 unsigned int file;
5977 unsigned int line;
5978 unsigned int column;
5979 int is_stmt;
5980 int basic_block;
5981 int end_sequence;
5982 /* This variable hold the number of the last entry seen
5983 in the File Table. */
5984 unsigned int last_file_entry;
5985 } SMR;
5986
5987 static SMR state_machine_regs;
5988
5989 static void
5990 reset_state_machine (is_stmt)
5991 int is_stmt;
5992 {
5993 state_machine_regs.address = 0;
5994 state_machine_regs.file = 1;
5995 state_machine_regs.line = 1;
5996 state_machine_regs.column = 0;
5997 state_machine_regs.is_stmt = is_stmt;
5998 state_machine_regs.basic_block = 0;
5999 state_machine_regs.end_sequence = 0;
6000 state_machine_regs.last_file_entry = 0;
6001 }
6002
6003 /* Handled an extend line op. Returns true if this is the end
6004 of sequence. */
6005 static int
6006 process_extended_line_op (data, is_stmt, pointer_size)
6007 unsigned char * data;
6008 int is_stmt;
6009 int pointer_size;
6010 {
6011 unsigned char op_code;
6012 int bytes_read;
6013 unsigned int len;
6014 unsigned char * name;
6015 unsigned long adr;
6016
6017 len = read_leb128 (data, & bytes_read, 0);
6018 data += bytes_read;
6019
6020 if (len == 0)
6021 {
6022 warn (_("badly formed extended line op encountered!\n"));
6023 return bytes_read;
6024 }
6025
6026 len += bytes_read;
6027 op_code = * data ++;
6028
6029 printf (_(" Extended opcode %d: "), op_code);
6030
6031 switch (op_code)
6032 {
6033 case DW_LNE_end_sequence:
6034 printf (_("End of Sequence\n\n"));
6035 reset_state_machine (is_stmt);
6036 break;
6037
6038 case DW_LNE_set_address:
6039 adr = byte_get (data, pointer_size);
6040 printf (_("set Address to 0x%lx\n"), adr);
6041 state_machine_regs.address = adr;
6042 break;
6043
6044 case DW_LNE_define_file:
6045 printf (_(" define new File Table entry\n"));
6046 printf (_(" Entry\tDir\tTime\tSize\tName\n"));
6047
6048 printf (_(" %d\t"), ++ state_machine_regs.last_file_entry);
6049 name = data;
6050 data += strlen ((char *) data) + 1;
6051 printf (_("%lu\t"), read_leb128 (data, & bytes_read, 0));
6052 data += bytes_read;
6053 printf (_("%lu\t"), read_leb128 (data, & bytes_read, 0));
6054 data += bytes_read;
6055 printf (_("%lu\t"), read_leb128 (data, & bytes_read, 0));
6056 printf (_("%s\n\n"), name);
6057 break;
6058
6059 default:
6060 printf (_("UNKNOWN: length %d\n"), len - bytes_read);
6061 break;
6062 }
6063
6064 return len;
6065 }
6066
6067 /* Size of pointers in the .debug_line section. This information is not
6068 really present in that section. It's obtained before dumping the debug
6069 sections by doing some pre-scan of the .debug_info section. */
6070 static int debug_line_pointer_size = 4;
6071
6072 static int
6073 display_debug_lines (section, start, file)
6074 Elf32_Internal_Shdr * section;
6075 unsigned char * start;
6076 FILE * file ATTRIBUTE_UNUSED;
6077 {
6078 DWARF2_External_LineInfo * external;
6079 DWARF2_Internal_LineInfo info;
6080 unsigned char * standard_opcodes;
6081 unsigned char * data = start;
6082 unsigned char * end = start + section->sh_size;
6083 unsigned char * end_of_sequence;
6084 int i;
6085
6086 printf (_("\nDump of debug contents of section %s:\n\n"),
6087 SECTION_NAME (section));
6088
6089 while (data < end)
6090 {
6091 external = (DWARF2_External_LineInfo *) data;
6092
6093 /* Check the length of the block. */
6094 info.li_length = BYTE_GET (external->li_length);
6095
6096 if (info.li_length == 0xffffffff)
6097 {
6098 warn (_("64-bit DWARF line info is not supported yet.\n"));
6099 break;
6100 }
6101
6102 if (info.li_length + sizeof (external->li_length) > section->sh_size)
6103 {
6104 warn
6105 (_("The line info appears to be corrupt - the section is too small\n"));
6106 return 0;
6107 }
6108
6109 /* Check its version number. */
6110 info.li_version = BYTE_GET (external->li_version);
6111 if (info.li_version != 2)
6112 {
6113 warn (_("Only DWARF version 2 line info is currently supported.\n"));
6114 return 0;
6115 }
6116
6117 info.li_prologue_length = BYTE_GET (external->li_prologue_length);
6118 info.li_min_insn_length = BYTE_GET (external->li_min_insn_length);
6119 info.li_default_is_stmt = BYTE_GET (external->li_default_is_stmt);
6120 info.li_line_base = BYTE_GET (external->li_line_base);
6121 info.li_line_range = BYTE_GET (external->li_line_range);
6122 info.li_opcode_base = BYTE_GET (external->li_opcode_base);
6123
6124 /* Sign extend the line base field. */
6125 info.li_line_base <<= 24;
6126 info.li_line_base >>= 24;
6127
6128 printf (_(" Length: %ld\n"), info.li_length);
6129 printf (_(" DWARF Version: %d\n"), info.li_version);
6130 printf (_(" Prologue Length: %d\n"), info.li_prologue_length);
6131 printf (_(" Minimum Instruction Length: %d\n"), info.li_min_insn_length);
6132 printf (_(" Initial value of 'is_stmt': %d\n"), info.li_default_is_stmt);
6133 printf (_(" Line Base: %d\n"), info.li_line_base);
6134 printf (_(" Line Range: %d\n"), info.li_line_range);
6135 printf (_(" Opcode Base: %d\n"), info.li_opcode_base);
6136
6137 end_of_sequence = data + info.li_length + sizeof (external->li_length);
6138
6139 reset_state_machine (info.li_default_is_stmt);
6140
6141 /* Display the contents of the Opcodes table. */
6142 standard_opcodes = data + sizeof (* external);
6143
6144 printf (_("\n Opcodes:\n"));
6145
6146 for (i = 1; i < info.li_opcode_base; i++)
6147 printf (_(" Opcode %d has %d args\n"), i, standard_opcodes[i - 1]);
6148
6149 /* Display the contents of the Directory table. */
6150 data = standard_opcodes + info.li_opcode_base - 1;
6151
6152 if (* data == 0)
6153 printf (_("\n The Directory Table is empty.\n"));
6154 else
6155 {
6156 printf (_("\n The Directory Table:\n"));
6157
6158 while (* data != 0)
6159 {
6160 printf (_(" %s\n"), data);
6161
6162 data += strlen ((char *) data) + 1;
6163 }
6164 }
6165
6166 /* Skip the NUL at the end of the table. */
6167 data ++;
6168
6169 /* Display the contents of the File Name table. */
6170 if (* data == 0)
6171 printf (_("\n The File Name Table is empty.\n"));
6172 else
6173 {
6174 printf (_("\n The File Name Table:\n"));
6175 printf (_(" Entry\tDir\tTime\tSize\tName\n"));
6176
6177 while (* data != 0)
6178 {
6179 unsigned char * name;
6180 int bytes_read;
6181
6182 printf (_(" %d\t"), ++ state_machine_regs.last_file_entry);
6183 name = data;
6184
6185 data += strlen ((char *) data) + 1;
6186
6187 printf (_("%lu\t"), read_leb128 (data, & bytes_read, 0));
6188 data += bytes_read;
6189 printf (_("%lu\t"), read_leb128 (data, & bytes_read, 0));
6190 data += bytes_read;
6191 printf (_("%lu\t"), read_leb128 (data, & bytes_read, 0));
6192 data += bytes_read;
6193 printf (_("%s\n"), name);
6194 }
6195 }
6196
6197 /* Skip the NUL at the end of the table. */
6198 data ++;
6199
6200 /* Now display the statements. */
6201 printf (_("\n Line Number Statements:\n"));
6202
6203
6204 while (data < end_of_sequence)
6205 {
6206 unsigned char op_code;
6207 int adv;
6208 int bytes_read;
6209
6210 op_code = * data ++;
6211
6212 if (op_code >= info.li_opcode_base)
6213 {
6214 op_code -= info.li_opcode_base;
6215 adv = (op_code / info.li_line_range) * info.li_min_insn_length;
6216 state_machine_regs.address += adv;
6217 printf (_(" Special opcode %d: advance Address by %d to 0x%lx"),
6218 op_code, adv, state_machine_regs.address);
6219 adv = (op_code % info.li_line_range) + info.li_line_base;
6220 state_machine_regs.line += adv;
6221 printf (_(" and Line by %d to %d\n"),
6222 adv, state_machine_regs.line);
6223 }
6224 else switch (op_code)
6225 {
6226 case DW_LNS_extended_op:
6227 data += process_extended_line_op (data, info.li_default_is_stmt,
6228 debug_line_pointer_size);
6229 break;
6230
6231 case DW_LNS_copy:
6232 printf (_(" Copy\n"));
6233 break;
6234
6235 case DW_LNS_advance_pc:
6236 adv = info.li_min_insn_length * read_leb128 (data, & bytes_read, 0);
6237 data += bytes_read;
6238 state_machine_regs.address += adv;
6239 printf (_(" Advance PC by %d to %lx\n"), adv,
6240 state_machine_regs.address);
6241 break;
6242
6243 case DW_LNS_advance_line:
6244 adv = read_leb128 (data, & bytes_read, 1);
6245 data += bytes_read;
6246 state_machine_regs.line += adv;
6247 printf (_(" Advance Line by %d to %d\n"), adv,
6248 state_machine_regs.line);
6249 break;
6250
6251 case DW_LNS_set_file:
6252 adv = read_leb128 (data, & bytes_read, 0);
6253 data += bytes_read;
6254 printf (_(" Set File Name to entry %d in the File Name Table\n"),
6255 adv);
6256 state_machine_regs.file = adv;
6257 break;
6258
6259 case DW_LNS_set_column:
6260 adv = read_leb128 (data, & bytes_read, 0);
6261 data += bytes_read;
6262 printf (_(" Set column to %d\n"), adv);
6263 state_machine_regs.column = adv;
6264 break;
6265
6266 case DW_LNS_negate_stmt:
6267 adv = state_machine_regs.is_stmt;
6268 adv = ! adv;
6269 printf (_(" Set is_stmt to %d\n"), adv);
6270 state_machine_regs.is_stmt = adv;
6271 break;
6272
6273 case DW_LNS_set_basic_block:
6274 printf (_(" Set basic block\n"));
6275 state_machine_regs.basic_block = 1;
6276 break;
6277
6278 case DW_LNS_const_add_pc:
6279 adv = (((255 - info.li_opcode_base) / info.li_line_range)
6280 * info.li_min_insn_length);
6281 state_machine_regs.address += adv;
6282 printf (_(" Advance PC by constant %d to 0x%lx\n"), adv,
6283 state_machine_regs.address);
6284 break;
6285
6286 case DW_LNS_fixed_advance_pc:
6287 adv = byte_get (data, 2);
6288 data += 2;
6289 state_machine_regs.address += adv;
6290 printf (_(" Advance PC by fixed size amount %d to 0x%lx\n"),
6291 adv, state_machine_regs.address);
6292 break;
6293
6294 case DW_LNS_set_prologue_end:
6295 printf (_(" Set prologue_end to true\n"));
6296 break;
6297
6298 case DW_LNS_set_epilogue_begin:
6299 printf (_(" Set epilogue_begin to true\n"));
6300 break;
6301
6302 case DW_LNS_set_isa:
6303 adv = read_leb128 (data, & bytes_read, 0);
6304 data += bytes_read;
6305 printf (_(" Set ISA to %d\n"), adv);
6306 break;
6307
6308 default:
6309 printf (_(" Unknown opcode %d with operands: "), op_code);
6310 {
6311 int i;
6312 for (i = standard_opcodes[op_code - 1]; i > 0 ; --i)
6313 {
6314 printf ("0x%lx%s", read_leb128 (data, &bytes_read, 0),
6315 i == 1 ? "" : ", ");
6316 data += bytes_read;
6317 }
6318 putchar ('\n');
6319 }
6320 break;
6321 }
6322 }
6323 putchar ('\n');
6324 }
6325
6326 return 1;
6327 }
6328
6329 static int
6330 display_debug_pubnames (section, start, file)
6331 Elf32_Internal_Shdr * section;
6332 unsigned char * start;
6333 FILE * file ATTRIBUTE_UNUSED;
6334 {
6335 DWARF2_External_PubNames * external;
6336 DWARF2_Internal_PubNames pubnames;
6337 unsigned char * end;
6338
6339 end = start + section->sh_size;
6340
6341 printf (_("Contents of the %s section:\n\n"), SECTION_NAME (section));
6342
6343 while (start < end)
6344 {
6345 unsigned char * data;
6346 unsigned long offset;
6347
6348 external = (DWARF2_External_PubNames *) start;
6349
6350 pubnames.pn_length = BYTE_GET (external->pn_length);
6351 pubnames.pn_version = BYTE_GET (external->pn_version);
6352 pubnames.pn_offset = BYTE_GET (external->pn_offset);
6353 pubnames.pn_size = BYTE_GET (external->pn_size);
6354
6355 data = start + sizeof (* external);
6356 start += pubnames.pn_length + sizeof (external->pn_length);
6357
6358 if (pubnames.pn_length == 0xffffffff)
6359 {
6360 warn (_("64-bit DWARF pubnames are not supported yet.\n"));
6361 break;
6362 }
6363
6364 if (pubnames.pn_version != 2)
6365 {
6366 static int warned = 0;
6367
6368 if (! warned)
6369 {
6370 warn (_("Only DWARF 2 pubnames are currently supported\n"));
6371 warned = 1;
6372 }
6373
6374 continue;
6375 }
6376
6377 printf (_(" Length: %ld\n"),
6378 pubnames.pn_length);
6379 printf (_(" Version: %d\n"),
6380 pubnames.pn_version);
6381 printf (_(" Offset into .debug_info section: %ld\n"),
6382 pubnames.pn_offset);
6383 printf (_(" Size of area in .debug_info section: %ld\n"),
6384 pubnames.pn_size);
6385
6386 printf (_("\n Offset\tName\n"));
6387
6388 do
6389 {
6390 offset = byte_get (data, 4);
6391
6392 if (offset != 0)
6393 {
6394 data += 4;
6395 printf (" %ld\t\t%s\n", offset, data);
6396 data += strlen ((char *) data) + 1;
6397 }
6398 }
6399 while (offset != 0);
6400 }
6401
6402 printf ("\n");
6403 return 1;
6404 }
6405
6406 static char *
6407 get_TAG_name (tag)
6408 unsigned long tag;
6409 {
6410 switch (tag)
6411 {
6412 case DW_TAG_padding: return "DW_TAG_padding";
6413 case DW_TAG_array_type: return "DW_TAG_array_type";
6414 case DW_TAG_class_type: return "DW_TAG_class_type";
6415 case DW_TAG_entry_point: return "DW_TAG_entry_point";
6416 case DW_TAG_enumeration_type: return "DW_TAG_enumeration_type";
6417 case DW_TAG_formal_parameter: return "DW_TAG_formal_parameter";
6418 case DW_TAG_imported_declaration: return "DW_TAG_imported_declaration";
6419 case DW_TAG_label: return "DW_TAG_label";
6420 case DW_TAG_lexical_block: return "DW_TAG_lexical_block";
6421 case DW_TAG_member: return "DW_TAG_member";
6422 case DW_TAG_pointer_type: return "DW_TAG_pointer_type";
6423 case DW_TAG_reference_type: return "DW_TAG_reference_type";
6424 case DW_TAG_compile_unit: return "DW_TAG_compile_unit";
6425 case DW_TAG_string_type: return "DW_TAG_string_type";
6426 case DW_TAG_structure_type: return "DW_TAG_structure_type";
6427 case DW_TAG_subroutine_type: return "DW_TAG_subroutine_type";
6428 case DW_TAG_typedef: return "DW_TAG_typedef";
6429 case DW_TAG_union_type: return "DW_TAG_union_type";
6430 case DW_TAG_unspecified_parameters: return "DW_TAG_unspecified_parameters";
6431 case DW_TAG_variant: return "DW_TAG_variant";
6432 case DW_TAG_common_block: return "DW_TAG_common_block";
6433 case DW_TAG_common_inclusion: return "DW_TAG_common_inclusion";
6434 case DW_TAG_inheritance: return "DW_TAG_inheritance";
6435 case DW_TAG_inlined_subroutine: return "DW_TAG_inlined_subroutine";
6436 case DW_TAG_module: return "DW_TAG_module";
6437 case DW_TAG_ptr_to_member_type: return "DW_TAG_ptr_to_member_type";
6438 case DW_TAG_set_type: return "DW_TAG_set_type";
6439 case DW_TAG_subrange_type: return "DW_TAG_subrange_type";
6440 case DW_TAG_with_stmt: return "DW_TAG_with_stmt";
6441 case DW_TAG_access_declaration: return "DW_TAG_access_declaration";
6442 case DW_TAG_base_type: return "DW_TAG_base_type";
6443 case DW_TAG_catch_block: return "DW_TAG_catch_block";
6444 case DW_TAG_const_type: return "DW_TAG_const_type";
6445 case DW_TAG_constant: return "DW_TAG_constant";
6446 case DW_TAG_enumerator: return "DW_TAG_enumerator";
6447 case DW_TAG_file_type: return "DW_TAG_file_type";
6448 case DW_TAG_friend: return "DW_TAG_friend";
6449 case DW_TAG_namelist: return "DW_TAG_namelist";
6450 case DW_TAG_namelist_item: return "DW_TAG_namelist_item";
6451 case DW_TAG_packed_type: return "DW_TAG_packed_type";
6452 case DW_TAG_subprogram: return "DW_TAG_subprogram";
6453 case DW_TAG_template_type_param: return "DW_TAG_template_type_param";
6454 case DW_TAG_template_value_param: return "DW_TAG_template_value_param";
6455 case DW_TAG_thrown_type: return "DW_TAG_thrown_type";
6456 case DW_TAG_try_block: return "DW_TAG_try_block";
6457 case DW_TAG_variant_part: return "DW_TAG_variant_part";
6458 case DW_TAG_variable: return "DW_TAG_variable";
6459 case DW_TAG_volatile_type: return "DW_TAG_volatile_type";
6460 case DW_TAG_MIPS_loop: return "DW_TAG_MIPS_loop";
6461 case DW_TAG_format_label: return "DW_TAG_format_label";
6462 case DW_TAG_function_template: return "DW_TAG_function_template";
6463 case DW_TAG_class_template: return "DW_TAG_class_template";
6464 /* DWARF 2.1 values. */
6465 case DW_TAG_dwarf_procedure: return "DW_TAG_dwarf_procedure";
6466 case DW_TAG_restrict_type: return "DW_TAG_restrict_type";
6467 case DW_TAG_interface_type: return "DW_TAG_interface_type";
6468 case DW_TAG_namespace: return "DW_TAG_namespace";
6469 case DW_TAG_imported_module: return "DW_TAG_imported_module";
6470 case DW_TAG_unspecified_type: return "DW_TAG_unspecified_type";
6471 case DW_TAG_partial_unit: return "DW_TAG_partial_unit";
6472 case DW_TAG_imported_unit: return "DW_TAG_imported_unit";
6473 default:
6474 {
6475 static char buffer [100];
6476
6477 sprintf (buffer, _("Unknown TAG value: %lx"), tag);
6478 return buffer;
6479 }
6480 }
6481 }
6482
6483 static char *
6484 get_AT_name (attribute)
6485 unsigned long attribute;
6486 {
6487 switch (attribute)
6488 {
6489 case DW_AT_sibling: return "DW_AT_sibling";
6490 case DW_AT_location: return "DW_AT_location";
6491 case DW_AT_name: return "DW_AT_name";
6492 case DW_AT_ordering: return "DW_AT_ordering";
6493 case DW_AT_subscr_data: return "DW_AT_subscr_data";
6494 case DW_AT_byte_size: return "DW_AT_byte_size";
6495 case DW_AT_bit_offset: return "DW_AT_bit_offset";
6496 case DW_AT_bit_size: return "DW_AT_bit_size";
6497 case DW_AT_element_list: return "DW_AT_element_list";
6498 case DW_AT_stmt_list: return "DW_AT_stmt_list";
6499 case DW_AT_low_pc: return "DW_AT_low_pc";
6500 case DW_AT_high_pc: return "DW_AT_high_pc";
6501 case DW_AT_language: return "DW_AT_language";
6502 case DW_AT_member: return "DW_AT_member";
6503 case DW_AT_discr: return "DW_AT_discr";
6504 case DW_AT_discr_value: return "DW_AT_discr_value";
6505 case DW_AT_visibility: return "DW_AT_visibility";
6506 case DW_AT_import: return "DW_AT_import";
6507 case DW_AT_string_length: return "DW_AT_string_length";
6508 case DW_AT_common_reference: return "DW_AT_common_reference";
6509 case DW_AT_comp_dir: return "DW_AT_comp_dir";
6510 case DW_AT_const_value: return "DW_AT_const_value";
6511 case DW_AT_containing_type: return "DW_AT_containing_type";
6512 case DW_AT_default_value: return "DW_AT_default_value";
6513 case DW_AT_inline: return "DW_AT_inline";
6514 case DW_AT_is_optional: return "DW_AT_is_optional";
6515 case DW_AT_lower_bound: return "DW_AT_lower_bound";
6516 case DW_AT_producer: return "DW_AT_producer";
6517 case DW_AT_prototyped: return "DW_AT_prototyped";
6518 case DW_AT_return_addr: return "DW_AT_return_addr";
6519 case DW_AT_start_scope: return "DW_AT_start_scope";
6520 case DW_AT_stride_size: return "DW_AT_stride_size";
6521 case DW_AT_upper_bound: return "DW_AT_upper_bound";
6522 case DW_AT_abstract_origin: return "DW_AT_abstract_origin";
6523 case DW_AT_accessibility: return "DW_AT_accessibility";
6524 case DW_AT_address_class: return "DW_AT_address_class";
6525 case DW_AT_artificial: return "DW_AT_artificial";
6526 case DW_AT_base_types: return "DW_AT_base_types";
6527 case DW_AT_calling_convention: return "DW_AT_calling_convention";
6528 case DW_AT_count: return "DW_AT_count";
6529 case DW_AT_data_member_location: return "DW_AT_data_member_location";
6530 case DW_AT_decl_column: return "DW_AT_decl_column";
6531 case DW_AT_decl_file: return "DW_AT_decl_file";
6532 case DW_AT_decl_line: return "DW_AT_decl_line";
6533 case DW_AT_declaration: return "DW_AT_declaration";
6534 case DW_AT_discr_list: return "DW_AT_discr_list";
6535 case DW_AT_encoding: return "DW_AT_encoding";
6536 case DW_AT_external: return "DW_AT_external";
6537 case DW_AT_frame_base: return "DW_AT_frame_base";
6538 case DW_AT_friend: return "DW_AT_friend";
6539 case DW_AT_identifier_case: return "DW_AT_identifier_case";
6540 case DW_AT_macro_info: return "DW_AT_macro_info";
6541 case DW_AT_namelist_items: return "DW_AT_namelist_items";
6542 case DW_AT_priority: return "DW_AT_priority";
6543 case DW_AT_segment: return "DW_AT_segment";
6544 case DW_AT_specification: return "DW_AT_specification";
6545 case DW_AT_static_link: return "DW_AT_static_link";
6546 case DW_AT_type: return "DW_AT_type";
6547 case DW_AT_use_location: return "DW_AT_use_location";
6548 case DW_AT_variable_parameter: return "DW_AT_variable_parameter";
6549 case DW_AT_virtuality: return "DW_AT_virtuality";
6550 case DW_AT_vtable_elem_location: return "DW_AT_vtable_elem_location";
6551 /* DWARF 2.1 values. */
6552 case DW_AT_allocated: return "DW_AT_allocated";
6553 case DW_AT_associated: return "DW_AT_associated";
6554 case DW_AT_data_location: return "DW_AT_data_location";
6555 case DW_AT_stride: return "DW_AT_stride";
6556 case DW_AT_entry_pc: return "DW_AT_entry_pc";
6557 case DW_AT_use_UTF8: return "DW_AT_use_UTF8";
6558 case DW_AT_extension: return "DW_AT_extension";
6559 case DW_AT_ranges: return "DW_AT_ranges";
6560 case DW_AT_trampoline: return "DW_AT_trampoline";
6561 case DW_AT_call_column: return "DW_AT_call_column";
6562 case DW_AT_call_file: return "DW_AT_call_file";
6563 case DW_AT_call_line: return "DW_AT_call_line";
6564 /* SGI/MIPS extensions. */
6565 case DW_AT_MIPS_fde: return "DW_AT_MIPS_fde";
6566 case DW_AT_MIPS_loop_begin: return "DW_AT_MIPS_loop_begin";
6567 case DW_AT_MIPS_tail_loop_begin: return "DW_AT_MIPS_tail_loop_begin";
6568 case DW_AT_MIPS_epilog_begin: return "DW_AT_MIPS_epilog_begin";
6569 case DW_AT_MIPS_loop_unroll_factor: return "DW_AT_MIPS_loop_unroll_factor";
6570 case DW_AT_MIPS_software_pipeline_depth: return "DW_AT_MIPS_software_pipeline_depth";
6571 case DW_AT_MIPS_linkage_name: return "DW_AT_MIPS_linkage_name";
6572 case DW_AT_MIPS_stride: return "DW_AT_MIPS_stride";
6573 case DW_AT_MIPS_abstract_name: return "DW_AT_MIPS_abstract_name";
6574 case DW_AT_MIPS_clone_origin: return "DW_AT_MIPS_clone_origin";
6575 case DW_AT_MIPS_has_inlines: return "DW_AT_MIPS_has_inlines";
6576 /* GNU extensions. */
6577 case DW_AT_sf_names: return "DW_AT_sf_names";
6578 case DW_AT_src_info: return "DW_AT_src_info";
6579 case DW_AT_mac_info: return "DW_AT_mac_info";
6580 case DW_AT_src_coords: return "DW_AT_src_coords";
6581 case DW_AT_body_begin: return "DW_AT_body_begin";
6582 case DW_AT_body_end: return "DW_AT_body_end";
6583 case DW_AT_GNU_vector: return "DW_AT_GNU_vector";
6584 default:
6585 {
6586 static char buffer [100];
6587
6588 sprintf (buffer, _("Unknown AT value: %lx"), attribute);
6589 return buffer;
6590 }
6591 }
6592 }
6593
6594 static char *
6595 get_FORM_name (form)
6596 unsigned long form;
6597 {
6598 switch (form)
6599 {
6600 case DW_FORM_addr: return "DW_FORM_addr";
6601 case DW_FORM_block2: return "DW_FORM_block2";
6602 case DW_FORM_block4: return "DW_FORM_block4";
6603 case DW_FORM_data2: return "DW_FORM_data2";
6604 case DW_FORM_data4: return "DW_FORM_data4";
6605 case DW_FORM_data8: return "DW_FORM_data8";
6606 case DW_FORM_string: return "DW_FORM_string";
6607 case DW_FORM_block: return "DW_FORM_block";
6608 case DW_FORM_block1: return "DW_FORM_block1";
6609 case DW_FORM_data1: return "DW_FORM_data1";
6610 case DW_FORM_flag: return "DW_FORM_flag";
6611 case DW_FORM_sdata: return "DW_FORM_sdata";
6612 case DW_FORM_strp: return "DW_FORM_strp";
6613 case DW_FORM_udata: return "DW_FORM_udata";
6614 case DW_FORM_ref_addr: return "DW_FORM_ref_addr";
6615 case DW_FORM_ref1: return "DW_FORM_ref1";
6616 case DW_FORM_ref2: return "DW_FORM_ref2";
6617 case DW_FORM_ref4: return "DW_FORM_ref4";
6618 case DW_FORM_ref8: return "DW_FORM_ref8";
6619 case DW_FORM_ref_udata: return "DW_FORM_ref_udata";
6620 case DW_FORM_indirect: return "DW_FORM_indirect";
6621 default:
6622 {
6623 static char buffer [100];
6624
6625 sprintf (buffer, _("Unknown FORM value: %lx"), form);
6626 return buffer;
6627 }
6628 }
6629 }
6630
6631 /* FIXME: There are better and more effiecint ways to handle
6632 these structures. For now though, I just want something that
6633 is simple to implement. */
6634 typedef struct abbrev_attr
6635 {
6636 unsigned long attribute;
6637 unsigned long form;
6638 struct abbrev_attr * next;
6639 }
6640 abbrev_attr;
6641
6642 typedef struct abbrev_entry
6643 {
6644 unsigned long entry;
6645 unsigned long tag;
6646 int children;
6647 struct abbrev_attr * first_attr;
6648 struct abbrev_attr * last_attr;
6649 struct abbrev_entry * next;
6650 }
6651 abbrev_entry;
6652
6653 static abbrev_entry * first_abbrev = NULL;
6654 static abbrev_entry * last_abbrev = NULL;
6655
6656 static void
6657 free_abbrevs PARAMS ((void))
6658 {
6659 abbrev_entry * abbrev;
6660
6661 for (abbrev = first_abbrev; abbrev;)
6662 {
6663 abbrev_entry * next = abbrev->next;
6664 abbrev_attr * attr;
6665
6666 for (attr = abbrev->first_attr; attr;)
6667 {
6668 abbrev_attr * next = attr->next;
6669
6670 free (attr);
6671 attr = next;
6672 }
6673
6674 free (abbrev);
6675 abbrev = next;
6676 }
6677
6678 last_abbrev = first_abbrev = NULL;
6679 }
6680
6681 static void
6682 add_abbrev (number, tag, children)
6683 unsigned long number;
6684 unsigned long tag;
6685 int children;
6686 {
6687 abbrev_entry * entry;
6688
6689 entry = (abbrev_entry *) malloc (sizeof (* entry));
6690
6691 if (entry == NULL)
6692 /* ugg */
6693 return;
6694
6695 entry->entry = number;
6696 entry->tag = tag;
6697 entry->children = children;
6698 entry->first_attr = NULL;
6699 entry->last_attr = NULL;
6700 entry->next = NULL;
6701
6702 if (first_abbrev == NULL)
6703 first_abbrev = entry;
6704 else
6705 last_abbrev->next = entry;
6706
6707 last_abbrev = entry;
6708 }
6709
6710 static void
6711 add_abbrev_attr (attribute, form)
6712 unsigned long attribute;
6713 unsigned long form;
6714 {
6715 abbrev_attr * attr;
6716
6717 attr = (abbrev_attr *) malloc (sizeof (* attr));
6718
6719 if (attr == NULL)
6720 /* ugg */
6721 return;
6722
6723 attr->attribute = attribute;
6724 attr->form = form;
6725 attr->next = NULL;
6726
6727 if (last_abbrev->first_attr == NULL)
6728 last_abbrev->first_attr = attr;
6729 else
6730 last_abbrev->last_attr->next = attr;
6731
6732 last_abbrev->last_attr = attr;
6733 }
6734
6735 /* Processes the (partial) contents of a .debug_abbrev section.
6736 Returns NULL if the end of the section was encountered.
6737 Returns the address after the last byte read if the end of
6738 an abbreviation set was found. */
6739
6740 static unsigned char *
6741 process_abbrev_section (start, end)
6742 unsigned char * start;
6743 unsigned char * end;
6744 {
6745 if (first_abbrev != NULL)
6746 return NULL;
6747
6748 while (start < end)
6749 {
6750 int bytes_read;
6751 unsigned long entry;
6752 unsigned long tag;
6753 unsigned long attribute;
6754 int children;
6755
6756 entry = read_leb128 (start, & bytes_read, 0);
6757 start += bytes_read;
6758
6759 /* A single zero is supposed to end the section according
6760 to the standard. If there's more, then signal that to
6761 the caller. */
6762 if (entry == 0)
6763 return start == end ? NULL : start;
6764
6765 tag = read_leb128 (start, & bytes_read, 0);
6766 start += bytes_read;
6767
6768 children = * start ++;
6769
6770 add_abbrev (entry, tag, children);
6771
6772 do
6773 {
6774 unsigned long form;
6775
6776 attribute = read_leb128 (start, & bytes_read, 0);
6777 start += bytes_read;
6778
6779 form = read_leb128 (start, & bytes_read, 0);
6780 start += bytes_read;
6781
6782 if (attribute != 0)
6783 add_abbrev_attr (attribute, form);
6784 }
6785 while (attribute != 0);
6786 }
6787
6788 return NULL;
6789 }
6790
6791
6792 static int
6793 display_debug_macinfo (section, start, file)
6794 Elf32_Internal_Shdr * section;
6795 unsigned char * start;
6796 FILE * file ATTRIBUTE_UNUSED;
6797 {
6798 unsigned char * end = start + section->sh_size;
6799 unsigned char * curr = start;
6800 unsigned int bytes_read;
6801 enum dwarf_macinfo_record_type op;
6802
6803 printf (_("Contents of the %s section:\n\n"), SECTION_NAME (section));
6804
6805 while (curr < end)
6806 {
6807 unsigned int lineno;
6808 const char * string;
6809
6810 op = * curr;
6811 curr ++;
6812
6813 switch (op)
6814 {
6815 case DW_MACINFO_start_file:
6816 {
6817 unsigned int filenum;
6818
6819 lineno = read_leb128 (curr, & bytes_read, 0);
6820 curr += bytes_read;
6821 filenum = read_leb128 (curr, & bytes_read, 0);
6822 curr += bytes_read;
6823
6824 printf (_(" DW_MACINFO_start_file - lineno: %d filenum: %d\n"), lineno, filenum);
6825 }
6826 break;
6827
6828 case DW_MACINFO_end_file:
6829 printf (_(" DW_MACINFO_end_file\n"));
6830 break;
6831
6832 case DW_MACINFO_define:
6833 lineno = read_leb128 (curr, & bytes_read, 0);
6834 curr += bytes_read;
6835 string = curr;
6836 curr += strlen (string) + 1;
6837 printf (_(" DW_MACINFO_define - lineno : %d macro : %s\n"), lineno, string);
6838 break;
6839
6840 case DW_MACINFO_undef:
6841 lineno = read_leb128 (curr, & bytes_read, 0);
6842 curr += bytes_read;
6843 string = curr;
6844 curr += strlen (string) + 1;
6845 printf (_(" DW_MACINFO_undef - lineno : %d macro : %s\n"), lineno, string);
6846 break;
6847
6848 case DW_MACINFO_vendor_ext:
6849 {
6850 unsigned int constant;
6851
6852 constant = read_leb128 (curr, & bytes_read, 0);
6853 curr += bytes_read;
6854 string = curr;
6855 curr += strlen (string) + 1;
6856 printf (_(" DW_MACINFO_vendor_ext - constant : %d string : %s\n"), constant, string);
6857 }
6858 break;
6859 }
6860 }
6861
6862 return 1;
6863 }
6864
6865
6866 static int
6867 display_debug_abbrev (section, start, file)
6868 Elf32_Internal_Shdr * section;
6869 unsigned char * start;
6870 FILE * file ATTRIBUTE_UNUSED;
6871 {
6872 abbrev_entry * entry;
6873 unsigned char * end = start + section->sh_size;
6874
6875 printf (_("Contents of the %s section:\n\n"), SECTION_NAME (section));
6876
6877 do
6878 {
6879 start = process_abbrev_section (start, end);
6880
6881 if (first_abbrev == NULL)
6882 continue;
6883
6884 printf (_(" Number TAG\n"));
6885
6886 for (entry = first_abbrev; entry; entry = entry->next)
6887 {
6888 abbrev_attr * attr;
6889
6890 printf (_(" %ld %s [%s]\n"),
6891 entry->entry,
6892 get_TAG_name (entry->tag),
6893 entry->children ? _("has children") : _("no children"));
6894
6895 for (attr = entry->first_attr; attr; attr = attr->next)
6896 {
6897 printf (_(" %-18s %s\n"),
6898 get_AT_name (attr->attribute),
6899 get_FORM_name (attr->form));
6900 }
6901 }
6902
6903 free_abbrevs ();
6904 }
6905 while (start);
6906
6907 printf ("\n");
6908
6909 return 1;
6910 }
6911
6912
6913 static unsigned char *
6914 display_block (data, length)
6915 unsigned char * data;
6916 unsigned long length;
6917 {
6918 printf (_(" %lu byte block: "), length);
6919
6920 while (length --)
6921 printf ("%lx ", (unsigned long) byte_get (data ++, 1));
6922
6923 return data;
6924 }
6925
6926 static void
6927 decode_location_expression (data, pointer_size, length)
6928 unsigned char * data;
6929 unsigned int pointer_size;
6930 unsigned long length;
6931 {
6932 unsigned op;
6933 int bytes_read;
6934 unsigned long uvalue;
6935 unsigned char * end = data + length;
6936
6937 while (data < end)
6938 {
6939 op = * data ++;
6940
6941 switch (op)
6942 {
6943 case DW_OP_addr:
6944 printf ("DW_OP_addr: %lx",
6945 (unsigned long) byte_get (data, pointer_size));
6946 data += pointer_size;
6947 break;
6948 case DW_OP_deref:
6949 printf ("DW_OP_deref");
6950 break;
6951 case DW_OP_const1u:
6952 printf ("DW_OP_const1u: %lu", (unsigned long) byte_get (data++, 1));
6953 break;
6954 case DW_OP_const1s:
6955 printf ("DW_OP_const1s: %ld", (long) byte_get (data++, 1));
6956 break;
6957 case DW_OP_const2u:
6958 printf ("DW_OP_const2u: %lu", (unsigned long) byte_get (data, 2));
6959 data += 2;
6960 break;
6961 case DW_OP_const2s:
6962 printf ("DW_OP_const2s: %ld", (long) byte_get (data, 2));
6963 data += 2;
6964 break;
6965 case DW_OP_const4u:
6966 printf ("DW_OP_const4u: %lu", (unsigned long) byte_get (data, 4));
6967 data += 4;
6968 break;
6969 case DW_OP_const4s:
6970 printf ("DW_OP_const4s: %ld", (long) byte_get (data, 4));
6971 data += 4;
6972 break;
6973 case DW_OP_const8u:
6974 printf ("DW_OP_const8u: %lu %lu", (unsigned long) byte_get (data, 4),
6975 (unsigned long) byte_get (data + 4, 4));
6976 data += 8;
6977 break;
6978 case DW_OP_const8s:
6979 printf ("DW_OP_const8s: %ld %ld", (long) byte_get (data, 4),
6980 (long) byte_get (data + 4, 4));
6981 data += 8;
6982 break;
6983 case DW_OP_constu:
6984 printf ("DW_OP_constu: %lu", read_leb128 (data, &bytes_read, 0));
6985 data += bytes_read;
6986 break;
6987 case DW_OP_consts:
6988 printf ("DW_OP_consts: %ld", read_leb128 (data, &bytes_read, 1));
6989 data += bytes_read;
6990 break;
6991 case DW_OP_dup:
6992 printf ("DW_OP_dup");
6993 break;
6994 case DW_OP_drop:
6995 printf ("DW_OP_drop");
6996 break;
6997 case DW_OP_over:
6998 printf ("DW_OP_over");
6999 break;
7000 case DW_OP_pick:
7001 printf ("DW_OP_pick: %ld", (unsigned long) byte_get (data++, 1));
7002 break;
7003 case DW_OP_swap:
7004 printf ("DW_OP_swap");
7005 break;
7006 case DW_OP_rot:
7007 printf ("DW_OP_rot");
7008 break;
7009 case DW_OP_xderef:
7010 printf ("DW_OP_xderef");
7011 break;
7012 case DW_OP_abs:
7013 printf ("DW_OP_abs");
7014 break;
7015 case DW_OP_and:
7016 printf ("DW_OP_and");
7017 break;
7018 case DW_OP_div:
7019 printf ("DW_OP_div");
7020 break;
7021 case DW_OP_minus:
7022 printf ("DW_OP_minus");
7023 break;
7024 case DW_OP_mod:
7025 printf ("DW_OP_mod");
7026 break;
7027 case DW_OP_mul:
7028 printf ("DW_OP_mul");
7029 break;
7030 case DW_OP_neg:
7031 printf ("DW_OP_neg");
7032 break;
7033 case DW_OP_not:
7034 printf ("DW_OP_not");
7035 break;
7036 case DW_OP_or:
7037 printf ("DW_OP_or");
7038 break;
7039 case DW_OP_plus:
7040 printf ("DW_OP_plus");
7041 break;
7042 case DW_OP_plus_uconst:
7043 printf ("DW_OP_plus_uconst: %lu",
7044 read_leb128 (data, &bytes_read, 0));
7045 data += bytes_read;
7046 break;
7047 case DW_OP_shl:
7048 printf ("DW_OP_shl");
7049 break;
7050 case DW_OP_shr:
7051 printf ("DW_OP_shr");
7052 break;
7053 case DW_OP_shra:
7054 printf ("DW_OP_shra");
7055 break;
7056 case DW_OP_xor:
7057 printf ("DW_OP_xor");
7058 break;
7059 case DW_OP_bra:
7060 printf ("DW_OP_bra: %ld", (long) byte_get (data, 2));
7061 data += 2;
7062 break;
7063 case DW_OP_eq:
7064 printf ("DW_OP_eq");
7065 break;
7066 case DW_OP_ge:
7067 printf ("DW_OP_ge");
7068 break;
7069 case DW_OP_gt:
7070 printf ("DW_OP_gt");
7071 break;
7072 case DW_OP_le:
7073 printf ("DW_OP_le");
7074 break;
7075 case DW_OP_lt:
7076 printf ("DW_OP_lt");
7077 break;
7078 case DW_OP_ne:
7079 printf ("DW_OP_ne");
7080 break;
7081 case DW_OP_skip:
7082 printf ("DW_OP_skip: %ld", (long) byte_get (data, 2));
7083 data += 2;
7084 break;
7085
7086 case DW_OP_lit0:
7087 case DW_OP_lit1:
7088 case DW_OP_lit2:
7089 case DW_OP_lit3:
7090 case DW_OP_lit4:
7091 case DW_OP_lit5:
7092 case DW_OP_lit6:
7093 case DW_OP_lit7:
7094 case DW_OP_lit8:
7095 case DW_OP_lit9:
7096 case DW_OP_lit10:
7097 case DW_OP_lit11:
7098 case DW_OP_lit12:
7099 case DW_OP_lit13:
7100 case DW_OP_lit14:
7101 case DW_OP_lit15:
7102 case DW_OP_lit16:
7103 case DW_OP_lit17:
7104 case DW_OP_lit18:
7105 case DW_OP_lit19:
7106 case DW_OP_lit20:
7107 case DW_OP_lit21:
7108 case DW_OP_lit22:
7109 case DW_OP_lit23:
7110 case DW_OP_lit24:
7111 case DW_OP_lit25:
7112 case DW_OP_lit26:
7113 case DW_OP_lit27:
7114 case DW_OP_lit28:
7115 case DW_OP_lit29:
7116 case DW_OP_lit30:
7117 case DW_OP_lit31:
7118 printf ("DW_OP_lit%d", op - DW_OP_lit0);
7119 break;
7120
7121 case DW_OP_reg0:
7122 case DW_OP_reg1:
7123 case DW_OP_reg2:
7124 case DW_OP_reg3:
7125 case DW_OP_reg4:
7126 case DW_OP_reg5:
7127 case DW_OP_reg6:
7128 case DW_OP_reg7:
7129 case DW_OP_reg8:
7130 case DW_OP_reg9:
7131 case DW_OP_reg10:
7132 case DW_OP_reg11:
7133 case DW_OP_reg12:
7134 case DW_OP_reg13:
7135 case DW_OP_reg14:
7136 case DW_OP_reg15:
7137 case DW_OP_reg16:
7138 case DW_OP_reg17:
7139 case DW_OP_reg18:
7140 case DW_OP_reg19:
7141 case DW_OP_reg20:
7142 case DW_OP_reg21:
7143 case DW_OP_reg22:
7144 case DW_OP_reg23:
7145 case DW_OP_reg24:
7146 case DW_OP_reg25:
7147 case DW_OP_reg26:
7148 case DW_OP_reg27:
7149 case DW_OP_reg28:
7150 case DW_OP_reg29:
7151 case DW_OP_reg30:
7152 case DW_OP_reg31:
7153 printf ("DW_OP_reg%d", op - DW_OP_reg0);
7154 break;
7155
7156 case DW_OP_breg0:
7157 case DW_OP_breg1:
7158 case DW_OP_breg2:
7159 case DW_OP_breg3:
7160 case DW_OP_breg4:
7161 case DW_OP_breg5:
7162 case DW_OP_breg6:
7163 case DW_OP_breg7:
7164 case DW_OP_breg8:
7165 case DW_OP_breg9:
7166 case DW_OP_breg10:
7167 case DW_OP_breg11:
7168 case DW_OP_breg12:
7169 case DW_OP_breg13:
7170 case DW_OP_breg14:
7171 case DW_OP_breg15:
7172 case DW_OP_breg16:
7173 case DW_OP_breg17:
7174 case DW_OP_breg18:
7175 case DW_OP_breg19:
7176 case DW_OP_breg20:
7177 case DW_OP_breg21:
7178 case DW_OP_breg22:
7179 case DW_OP_breg23:
7180 case DW_OP_breg24:
7181 case DW_OP_breg25:
7182 case DW_OP_breg26:
7183 case DW_OP_breg27:
7184 case DW_OP_breg28:
7185 case DW_OP_breg29:
7186 case DW_OP_breg30:
7187 case DW_OP_breg31:
7188 printf ("DW_OP_breg%d: %ld", op - DW_OP_breg0,
7189 read_leb128 (data, &bytes_read, 1));
7190 data += bytes_read;
7191 break;
7192
7193 case DW_OP_regx:
7194 printf ("DW_OP_regx: %lu", read_leb128 (data, &bytes_read, 0));
7195 data += bytes_read;
7196 break;
7197 case DW_OP_fbreg:
7198 printf ("DW_OP_fbreg: %ld", read_leb128 (data, &bytes_read, 1));
7199 data += bytes_read;
7200 break;
7201 case DW_OP_bregx:
7202 uvalue = read_leb128 (data, &bytes_read, 0);
7203 data += bytes_read;
7204 printf ("DW_OP_bregx: %lu %ld", uvalue,
7205 read_leb128 (data, &bytes_read, 1));
7206 data += bytes_read;
7207 break;
7208 case DW_OP_piece:
7209 printf ("DW_OP_piece: %lu", read_leb128 (data, &bytes_read, 0));
7210 data += bytes_read;
7211 break;
7212 case DW_OP_deref_size:
7213 printf ("DW_OP_deref_size: %ld", (long) byte_get (data++, 1));
7214 break;
7215 case DW_OP_xderef_size:
7216 printf ("DW_OP_xderef_size: %ld", (long) byte_get (data++, 1));
7217 break;
7218 case DW_OP_nop:
7219 printf ("DW_OP_nop");
7220 break;
7221
7222 /* DWARF 2.1 extensions. */
7223 case DW_OP_push_object_address:
7224 printf ("DW_OP_push_object_address");
7225 break;
7226 case DW_OP_call2:
7227 printf ("DW_OP_call2: <%lx>", (long) byte_get (data, 2));
7228 data += 2;
7229 break;
7230 case DW_OP_call4:
7231 printf ("DW_OP_call4: <%lx>", (long) byte_get (data, 4));
7232 data += 4;
7233 break;
7234 case DW_OP_calli:
7235 printf ("DW_OP_calli");
7236 break;
7237
7238 default:
7239 if (op >= DW_OP_lo_user
7240 && op <= DW_OP_hi_user)
7241 printf (_("(User defined location op)"));
7242 else
7243 printf (_("(Unknown location op)"));
7244 /* No way to tell where the next op is, so just bail. */
7245 return;
7246 }
7247
7248 /* Separate the ops. */
7249 printf ("; ");
7250 }
7251 }
7252
7253 static const char * debug_loc_contents;
7254 static bfd_vma debug_loc_size;
7255
7256 static void
7257 load_debug_loc (file)
7258 FILE * file;
7259 {
7260 Elf32_Internal_Shdr * sec;
7261 unsigned int i;
7262
7263 /* If it is already loaded, do nothing. */
7264 if (debug_loc_contents != NULL)
7265 return;
7266
7267 /* Locate the .debug_loc section. */
7268 for (i = 0, sec = section_headers;
7269 i < elf_header.e_shnum;
7270 i ++, sec ++)
7271 if (strcmp (SECTION_NAME (sec), ".debug_loc") == 0)
7272 break;
7273
7274 if (i == elf_header.e_shnum || sec->sh_size == 0)
7275 return;
7276
7277 debug_loc_size = sec->sh_size;
7278
7279 debug_loc_contents = ((char *)
7280 get_data (NULL, file, sec->sh_offset, sec->sh_size,
7281 _("debug_loc section data")));
7282 }
7283
7284 static void
7285 free_debug_loc ()
7286 {
7287 if (debug_loc_contents == NULL)
7288 return;
7289
7290 free ((char *) debug_loc_contents);
7291 debug_loc_contents = NULL;
7292 debug_loc_size = 0;
7293 }
7294
7295
7296 static int
7297 display_debug_loc (section, start, file)
7298 Elf32_Internal_Shdr * section;
7299 unsigned char * start;
7300 FILE * file ATTRIBUTE_UNUSED;
7301 {
7302 unsigned char *section_end;
7303 unsigned long bytes;
7304 unsigned char *section_begin = start;
7305 bfd_vma addr;
7306
7307 addr = section->sh_addr;
7308 bytes = section->sh_size;
7309 section_end = start + bytes;
7310 if (bytes == 0)
7311 {
7312 printf (_("\nThe .debug_loc section is empty.\n"));
7313 return 0;
7314 }
7315 printf (_("Contents of the .debug_loc section:\n\n"));
7316 printf (_("\n Offset Begin End Expression\n"));
7317 while (start < section_end)
7318 {
7319 unsigned long begin;
7320 unsigned long end;
7321 unsigned short length;
7322 unsigned long offset;
7323
7324 offset = start - section_begin;
7325
7326 while (1)
7327 {
7328 /* Normally, the lists in the debug_loc section are related to a
7329 given compilation unit, and thus, we would use the
7330 pointer size of that compilation unit. However, since we are
7331 displaying it seperately here, we either have to store
7332 pointer sizes of all compilation units, or assume they don't
7333 change. We assume, like the debug_line display, that
7334 it doesn't change. */
7335 begin = byte_get (start, debug_line_pointer_size);
7336 start += debug_line_pointer_size;
7337 end = byte_get (start, debug_line_pointer_size);
7338 start += debug_line_pointer_size;
7339
7340 if (begin == 0 && end == 0)
7341 break;
7342
7343 begin += addr;
7344 end += addr;
7345
7346 length = byte_get (start, 2);
7347 start += 2;
7348
7349 printf (" %8.8lx %8.8lx %8.8lx (", offset, begin, end);
7350 decode_location_expression (start, debug_line_pointer_size, length);
7351 printf (")\n");
7352
7353 start += length;
7354 }
7355 printf ("\n");
7356 }
7357 return 1;
7358 }
7359
7360 static const char * debug_str_contents;
7361 static bfd_vma debug_str_size;
7362
7363 static void
7364 load_debug_str (file)
7365 FILE * file;
7366 {
7367 Elf32_Internal_Shdr * sec;
7368 unsigned int i;
7369
7370 /* If it is already loaded, do nothing. */
7371 if (debug_str_contents != NULL)
7372 return;
7373
7374 /* Locate the .debug_str section. */
7375 for (i = 0, sec = section_headers;
7376 i < elf_header.e_shnum;
7377 i ++, sec ++)
7378 if (strcmp (SECTION_NAME (sec), ".debug_str") == 0)
7379 break;
7380
7381 if (i == elf_header.e_shnum || sec->sh_size == 0)
7382 return;
7383
7384 debug_str_size = sec->sh_size;
7385
7386 debug_str_contents = ((char *)
7387 get_data (NULL, file, sec->sh_offset, sec->sh_size,
7388 _("debug_str section data")));
7389 }
7390
7391 static void
7392 free_debug_str ()
7393 {
7394 if (debug_str_contents == NULL)
7395 return;
7396
7397 free ((char *) debug_str_contents);
7398 debug_str_contents = NULL;
7399 debug_str_size = 0;
7400 }
7401
7402 static const char *
7403 fetch_indirect_string (offset)
7404 unsigned long offset;
7405 {
7406 if (debug_str_contents == NULL)
7407 return _("<no .debug_str section>");
7408
7409 if (offset > debug_str_size)
7410 return _("<offset is too big>");
7411
7412 return debug_str_contents + offset;
7413 }
7414
7415
7416 static int
7417 display_debug_str (section, start, file)
7418 Elf32_Internal_Shdr * section;
7419 unsigned char * start;
7420 FILE * file ATTRIBUTE_UNUSED;
7421 {
7422 unsigned long bytes;
7423 bfd_vma addr;
7424
7425 addr = section->sh_addr;
7426 bytes = section->sh_size;
7427
7428 if (bytes == 0)
7429 {
7430 printf (_("\nThe .debug_str section is empty.\n"));
7431 return 0;
7432 }
7433
7434 printf (_("Contents of the .debug_str section:\n\n"));
7435
7436 while (bytes)
7437 {
7438 int j;
7439 int k;
7440 int lbytes;
7441
7442 lbytes = (bytes > 16 ? 16 : bytes);
7443
7444 printf (" 0x%8.8lx ", (unsigned long) addr);
7445
7446 for (j = 0; j < 16; j++)
7447 {
7448 if (j < lbytes)
7449 printf ("%2.2x", start [j]);
7450 else
7451 printf (" ");
7452
7453 if ((j & 3) == 3)
7454 printf (" ");
7455 }
7456
7457 for (j = 0; j < lbytes; j++)
7458 {
7459 k = start [j];
7460 if (k >= ' ' && k < 0x80)
7461 printf ("%c", k);
7462 else
7463 printf (".");
7464 }
7465
7466 putchar ('\n');
7467
7468 start += lbytes;
7469 addr += lbytes;
7470 bytes -= lbytes;
7471 }
7472
7473 return 1;
7474 }
7475
7476
7477 static unsigned char *
7478 read_and_display_attr_value (attribute, form, data, cu_offset, pointer_size)
7479 unsigned long attribute;
7480 unsigned long form;
7481 unsigned char * data;
7482 unsigned long cu_offset;
7483 unsigned long pointer_size;
7484 {
7485 unsigned long uvalue = 0;
7486 unsigned char * block_start = NULL;
7487 int bytes_read;
7488
7489 switch (form)
7490 {
7491 default:
7492 break;
7493
7494 case DW_FORM_ref_addr:
7495 case DW_FORM_addr:
7496 uvalue = byte_get (data, pointer_size);
7497 data += pointer_size;
7498 break;
7499
7500 case DW_FORM_strp:
7501 uvalue = byte_get (data, /* offset_size */ 4);
7502 data += /* offset_size */ 4;
7503 break;
7504
7505 case DW_FORM_ref1:
7506 case DW_FORM_flag:
7507 case DW_FORM_data1:
7508 uvalue = byte_get (data ++, 1);
7509 break;
7510
7511 case DW_FORM_ref2:
7512 case DW_FORM_data2:
7513 uvalue = byte_get (data, 2);
7514 data += 2;
7515 break;
7516
7517 case DW_FORM_ref4:
7518 case DW_FORM_data4:
7519 uvalue = byte_get (data, 4);
7520 data += 4;
7521 break;
7522
7523 case DW_FORM_sdata:
7524 uvalue = read_leb128 (data, & bytes_read, 1);
7525 data += bytes_read;
7526 break;
7527
7528 case DW_FORM_ref_udata:
7529 case DW_FORM_udata:
7530 uvalue = read_leb128 (data, & bytes_read, 0);
7531 data += bytes_read;
7532 break;
7533
7534 case DW_FORM_indirect:
7535 form = read_leb128 (data, & bytes_read, 0);
7536 data += bytes_read;
7537 printf (" %s", get_FORM_name (form));
7538 return read_and_display_attr_value (attribute, form, data, cu_offset,
7539 pointer_size);
7540 }
7541
7542 switch (form)
7543 {
7544 case DW_FORM_ref_addr:
7545 printf (" <#%lx>", uvalue);
7546 break;
7547
7548 case DW_FORM_ref1:
7549 case DW_FORM_ref2:
7550 case DW_FORM_ref4:
7551 case DW_FORM_ref_udata:
7552 printf (" <%lx>", uvalue + cu_offset);
7553 break;
7554
7555 case DW_FORM_addr:
7556 printf (" %#lx", uvalue);
7557
7558 case DW_FORM_flag:
7559 case DW_FORM_data1:
7560 case DW_FORM_data2:
7561 case DW_FORM_data4:
7562 case DW_FORM_sdata:
7563 case DW_FORM_udata:
7564 printf (" %ld", uvalue);
7565 break;
7566
7567 case DW_FORM_ref8:
7568 case DW_FORM_data8:
7569 uvalue = byte_get (data, 4);
7570 printf (" %lx", uvalue);
7571 printf (" %lx", (unsigned long) byte_get (data + 4, 4));
7572 data += 8;
7573 break;
7574
7575 case DW_FORM_string:
7576 printf (" %s", data);
7577 data += strlen ((char *) data) + 1;
7578 break;
7579
7580 case DW_FORM_block:
7581 uvalue = read_leb128 (data, & bytes_read, 0);
7582 block_start = data + bytes_read;
7583 data = display_block (block_start, uvalue);
7584 break;
7585
7586 case DW_FORM_block1:
7587 uvalue = byte_get (data, 1);
7588 block_start = data + 1;
7589 data = display_block (block_start, uvalue);
7590 break;
7591
7592 case DW_FORM_block2:
7593 uvalue = byte_get (data, 2);
7594 block_start = data + 2;
7595 data = display_block (block_start, uvalue);
7596 break;
7597
7598 case DW_FORM_block4:
7599 uvalue = byte_get (data, 4);
7600 block_start = data + 4;
7601 data = display_block (block_start, uvalue);
7602 break;
7603
7604 case DW_FORM_strp:
7605 printf (_(" (indirect string, offset: 0x%lx): "), uvalue);
7606 printf (fetch_indirect_string (uvalue));
7607 break;
7608
7609 case DW_FORM_indirect:
7610 /* Handled above. */
7611 break;
7612
7613 default:
7614 warn (_("Unrecognized form: %d\n"), form);
7615 break;
7616 }
7617
7618 /* For some attributes we can display futher information. */
7619
7620 printf ("\t");
7621
7622 switch (attribute)
7623 {
7624 case DW_AT_inline:
7625 switch (uvalue)
7626 {
7627 case DW_INL_not_inlined: printf (_("(not inlined)")); break;
7628 case DW_INL_inlined: printf (_("(inlined)")); break;
7629 case DW_INL_declared_not_inlined: printf (_("(declared as inline but ignored)")); break;
7630 case DW_INL_declared_inlined: printf (_("(declared as inline and inlined)")); break;
7631 default: printf (_(" (Unknown inline attribute value: %lx)"), uvalue); break;
7632 }
7633 break;
7634
7635 case DW_AT_language:
7636 switch (uvalue)
7637 {
7638 case DW_LANG_C: printf ("(non-ANSI C)"); break;
7639 case DW_LANG_C89: printf ("(ANSI C)"); break;
7640 case DW_LANG_C_plus_plus: printf ("(C++)"); break;
7641 case DW_LANG_Fortran77: printf ("(FORTRAN 77)"); break;
7642 case DW_LANG_Fortran90: printf ("(Fortran 90)"); break;
7643 case DW_LANG_Modula2: printf ("(Modula 2)"); break;
7644 case DW_LANG_Pascal83: printf ("(ANSI Pascal)"); break;
7645 case DW_LANG_Ada83: printf ("(Ada)"); break;
7646 case DW_LANG_Cobol74: printf ("(Cobol 74)"); break;
7647 case DW_LANG_Cobol85: printf ("(Cobol 85)"); break;
7648 /* DWARF 2.1 values. */
7649 case DW_LANG_C99: printf ("(ANSI C99)"); break;
7650 case DW_LANG_Ada95: printf ("(ADA 95)"); break;
7651 case DW_LANG_Fortran95: printf ("(Fortran 95)"); break;
7652 /* MIPS extension. */
7653 case DW_LANG_Mips_Assembler: printf ("(MIPS assembler)"); break;
7654 default: printf ("(Unknown: %lx)", uvalue); break;
7655 }
7656 break;
7657
7658 case DW_AT_encoding:
7659 switch (uvalue)
7660 {
7661 case DW_ATE_void: printf ("(void)"); break;
7662 case DW_ATE_address: printf ("(machine address)"); break;
7663 case DW_ATE_boolean: printf ("(boolean)"); break;
7664 case DW_ATE_complex_float: printf ("(complex float)"); break;
7665 case DW_ATE_float: printf ("(float)"); break;
7666 case DW_ATE_signed: printf ("(signed)"); break;
7667 case DW_ATE_signed_char: printf ("(signed char)"); break;
7668 case DW_ATE_unsigned: printf ("(unsigned)"); break;
7669 case DW_ATE_unsigned_char: printf ("(unsigned char)"); break;
7670 /* DWARF 2.1 value. */
7671 case DW_ATE_imaginary_float: printf ("(imaginary float)"); break;
7672 default:
7673 if (uvalue >= DW_ATE_lo_user
7674 && uvalue <= DW_ATE_hi_user)
7675 printf ("(user defined type)");
7676 else
7677 printf ("(unknown type)");
7678 break;
7679 }
7680 break;
7681
7682 case DW_AT_accessibility:
7683 switch (uvalue)
7684 {
7685 case DW_ACCESS_public: printf ("(public)"); break;
7686 case DW_ACCESS_protected: printf ("(protected)"); break;
7687 case DW_ACCESS_private: printf ("(private)"); break;
7688 default: printf ("(unknown accessibility)"); break;
7689 }
7690 break;
7691
7692 case DW_AT_visibility:
7693 switch (uvalue)
7694 {
7695 case DW_VIS_local: printf ("(local)"); break;
7696 case DW_VIS_exported: printf ("(exported)"); break;
7697 case DW_VIS_qualified: printf ("(qualified)"); break;
7698 default: printf ("(unknown visibility)"); break;
7699 }
7700 break;
7701
7702 case DW_AT_virtuality:
7703 switch (uvalue)
7704 {
7705 case DW_VIRTUALITY_none: printf ("(none)"); break;
7706 case DW_VIRTUALITY_virtual: printf ("(virtual)"); break;
7707 case DW_VIRTUALITY_pure_virtual:printf ("(pure_virtual)"); break;
7708 default: printf ("(unknown virtuality)"); break;
7709 }
7710 break;
7711
7712 case DW_AT_identifier_case:
7713 switch (uvalue)
7714 {
7715 case DW_ID_case_sensitive: printf ("(case_sensitive)"); break;
7716 case DW_ID_up_case: printf ("(up_case)"); break;
7717 case DW_ID_down_case: printf ("(down_case)"); break;
7718 case DW_ID_case_insensitive: printf ("(case_insensitive)"); break;
7719 default: printf ("(unknown case)"); break;
7720 }
7721 break;
7722
7723 case DW_AT_calling_convention:
7724 switch (uvalue)
7725 {
7726 case DW_CC_normal: printf ("(normal)"); break;
7727 case DW_CC_program: printf ("(program)"); break;
7728 case DW_CC_nocall: printf ("(nocall)"); break;
7729 default:
7730 if (uvalue >= DW_CC_lo_user
7731 && uvalue <= DW_CC_hi_user)
7732 printf ("(user defined)");
7733 else
7734 printf ("(unknown convention)");
7735 }
7736 break;
7737
7738 case DW_AT_ordering:
7739 switch (uvalue)
7740 {
7741 case -1: printf ("(undefined)"); break;
7742 case 0: printf ("(row major)"); break;
7743 case 1: printf ("(column major)"); break;
7744 }
7745 break;
7746
7747 case DW_AT_frame_base:
7748 case DW_AT_location:
7749 case DW_AT_data_member_location:
7750 case DW_AT_vtable_elem_location:
7751 case DW_AT_allocated:
7752 case DW_AT_associated:
7753 case DW_AT_data_location:
7754 case DW_AT_stride:
7755 case DW_AT_upper_bound:
7756 case DW_AT_lower_bound:
7757 if (block_start)
7758 {
7759 printf ("(");
7760 decode_location_expression (block_start, pointer_size, uvalue);
7761 printf (")");
7762 }
7763 else if (form == DW_FORM_data4)
7764 {
7765 printf ("(");
7766 printf ("location list");
7767 printf (")");
7768 }
7769 break;
7770
7771 default:
7772 break;
7773 }
7774
7775 return data;
7776 }
7777
7778 static unsigned char *
7779 read_and_display_attr (attribute, form, data, cu_offset, pointer_size)
7780 unsigned long attribute;
7781 unsigned long form;
7782 unsigned char * data;
7783 unsigned long cu_offset;
7784 unsigned long pointer_size;
7785 {
7786 printf (" %-18s:", get_AT_name (attribute));
7787 data = read_and_display_attr_value (attribute, form, data, cu_offset,
7788 pointer_size);
7789 printf ("\n");
7790 return data;
7791 }
7792
7793 static int
7794 display_debug_info (section, start, file)
7795 Elf32_Internal_Shdr * section;
7796 unsigned char * start;
7797 FILE * file;
7798 {
7799 unsigned char * end = start + section->sh_size;
7800 unsigned char * section_begin = start;
7801
7802 printf (_("The section %s contains:\n\n"), SECTION_NAME (section));
7803
7804 load_debug_str (file);
7805 load_debug_loc (file);
7806
7807 while (start < end)
7808 {
7809 DWARF2_External_CompUnit * external;
7810 DWARF2_Internal_CompUnit compunit;
7811 Elf32_Internal_Shdr * relsec;
7812 unsigned char * tags;
7813 unsigned int i;
7814 int level;
7815 unsigned long cu_offset;
7816
7817 external = (DWARF2_External_CompUnit *) start;
7818
7819 compunit.cu_length = BYTE_GET (external->cu_length);
7820 compunit.cu_version = BYTE_GET (external->cu_version);
7821 compunit.cu_abbrev_offset = BYTE_GET (external->cu_abbrev_offset);
7822 compunit.cu_pointer_size = BYTE_GET (external->cu_pointer_size);
7823
7824 if (compunit.cu_length == 0xffffffff)
7825 {
7826 warn (_("64-bit DWARF debug info is not supported yet.\n"));
7827 break;
7828 }
7829
7830 /* Check for RELA relocations in the abbrev_offset address, and
7831 apply them. */
7832 for (relsec = section_headers;
7833 relsec < section_headers + elf_header.e_shnum;
7834 ++relsec)
7835 {
7836 unsigned long nrelas;
7837 Elf_Internal_Rela *rela, *rp;
7838 Elf32_Internal_Shdr *symsec;
7839 Elf_Internal_Sym *symtab;
7840 Elf_Internal_Sym *sym;
7841
7842 if (relsec->sh_type != SHT_RELA
7843 || SECTION_HEADER (relsec->sh_info) != section)
7844 continue;
7845
7846 if (!slurp_rela_relocs (file, relsec->sh_offset, relsec->sh_size,
7847 & rela, & nrelas))
7848 return 0;
7849
7850 symsec = SECTION_HEADER (relsec->sh_link);
7851 symtab = GET_ELF_SYMBOLS (file, symsec);
7852
7853 for (rp = rela; rp < rela + nrelas; ++rp)
7854 {
7855 if (rp->r_offset
7856 != (bfd_vma) ((unsigned char *) &external->cu_abbrev_offset
7857 - section_begin))
7858 continue;
7859
7860 if (is_32bit_elf)
7861 {
7862 sym = symtab + ELF32_R_SYM (rp->r_info);
7863
7864 if (ELF32_ST_TYPE (sym->st_info) != STT_SECTION)
7865 {
7866 warn (_("Skipping unexpected symbol type %u\n"),
7867 ELF32_ST_TYPE (sym->st_info));
7868 continue;
7869 }
7870 }
7871 else
7872 {
7873 sym = symtab + ELF64_R_SYM (rp->r_info);
7874
7875 if (ELF64_ST_TYPE (sym->st_info) != STT_SECTION)
7876 {
7877 warn (_("Skipping unexpected symbol type %u\n"),
7878 ELF64_ST_TYPE (sym->st_info));
7879 continue;
7880 }
7881 }
7882
7883 compunit.cu_abbrev_offset += rp->r_addend;
7884 break;
7885 }
7886
7887 free (rela);
7888 break;
7889 }
7890
7891 tags = start + sizeof (* external);
7892 cu_offset = start - section_begin;
7893 start += compunit.cu_length + sizeof (external->cu_length);
7894
7895 printf (_(" Compilation Unit @ %lx:\n"), cu_offset);
7896 printf (_(" Length: %ld\n"), compunit.cu_length);
7897 printf (_(" Version: %d\n"), compunit.cu_version);
7898 printf (_(" Abbrev Offset: %ld\n"), compunit.cu_abbrev_offset);
7899 printf (_(" Pointer Size: %d\n"), compunit.cu_pointer_size);
7900
7901 if (compunit.cu_version != 2)
7902 {
7903 warn (_("Only version 2 DWARF debug information is currently supported.\n"));
7904 continue;
7905 }
7906
7907 free_abbrevs ();
7908
7909 /* Read in the abbrevs used by this compilation unit. */
7910
7911 {
7912 Elf32_Internal_Shdr * sec;
7913 unsigned char * begin;
7914
7915 /* Locate the .debug_abbrev section and process it. */
7916 for (i = 0, sec = section_headers;
7917 i < elf_header.e_shnum;
7918 i ++, sec ++)
7919 if (strcmp (SECTION_NAME (sec), ".debug_abbrev") == 0)
7920 break;
7921
7922 if (i == elf_header.e_shnum || sec->sh_size == 0)
7923 {
7924 warn (_("Unable to locate .debug_abbrev section!\n"));
7925 return 0;
7926 }
7927
7928 begin = ((unsigned char *)
7929 get_data (NULL, file, sec->sh_offset, sec->sh_size,
7930 _("debug_abbrev section data")));
7931 if (!begin)
7932 return 0;
7933
7934 process_abbrev_section (begin + compunit.cu_abbrev_offset,
7935 begin + sec->sh_size);
7936
7937 free (begin);
7938 }
7939
7940 level = 0;
7941 while (tags < start)
7942 {
7943 int bytes_read;
7944 unsigned long abbrev_number;
7945 abbrev_entry * entry;
7946 abbrev_attr * attr;
7947
7948 abbrev_number = read_leb128 (tags, & bytes_read, 0);
7949 tags += bytes_read;
7950
7951 /* A null DIE marks the end of a list of children. */
7952 if (abbrev_number == 0)
7953 {
7954 --level;
7955 continue;
7956 }
7957
7958 /* Scan through the abbreviation list until we reach the
7959 correct entry. */
7960 for (entry = first_abbrev;
7961 entry && entry->entry != abbrev_number;
7962 entry = entry->next)
7963 continue;
7964
7965 if (entry == NULL)
7966 {
7967 warn (_("Unable to locate entry %lu in the abbreviation table\n"),
7968 abbrev_number);
7969 return 0;
7970 }
7971
7972 printf (_(" <%d><%lx>: Abbrev Number: %lu (%s)\n"),
7973 level,
7974 (unsigned long) (tags - section_begin - bytes_read),
7975 abbrev_number,
7976 get_TAG_name (entry->tag));
7977
7978 for (attr = entry->first_attr; attr; attr = attr->next)
7979 tags = read_and_display_attr (attr->attribute,
7980 attr->form,
7981 tags, cu_offset,
7982 compunit.cu_pointer_size);
7983
7984 if (entry->children)
7985 ++level;
7986 }
7987 }
7988
7989 free_debug_str ();
7990 free_debug_loc ();
7991
7992 printf ("\n");
7993
7994 return 1;
7995 }
7996
7997 static int
7998 display_debug_aranges (section, start, file)
7999 Elf32_Internal_Shdr * section;
8000 unsigned char * start;
8001 FILE * file ATTRIBUTE_UNUSED;
8002 {
8003 unsigned char * end = start + section->sh_size;
8004
8005 printf (_("The section %s contains:\n\n"), SECTION_NAME (section));
8006
8007 while (start < end)
8008 {
8009 DWARF2_External_ARange * external;
8010 DWARF2_Internal_ARange arange;
8011 unsigned char * ranges;
8012 unsigned long length;
8013 unsigned long address;
8014 int excess;
8015
8016 external = (DWARF2_External_ARange *) start;
8017
8018 arange.ar_length = BYTE_GET (external->ar_length);
8019 arange.ar_version = BYTE_GET (external->ar_version);
8020 arange.ar_info_offset = BYTE_GET (external->ar_info_offset);
8021 arange.ar_pointer_size = BYTE_GET (external->ar_pointer_size);
8022 arange.ar_segment_size = BYTE_GET (external->ar_segment_size);
8023
8024 if (arange.ar_length == 0xffffffff)
8025 {
8026 warn (_("64-bit DWARF aranges are not supported yet.\n"));
8027 break;
8028 }
8029
8030 if (arange.ar_version != 2)
8031 {
8032 warn (_("Only DWARF 2 aranges are currently supported.\n"));
8033 break;
8034 }
8035
8036 printf (_(" Length: %ld\n"), arange.ar_length);
8037 printf (_(" Version: %d\n"), arange.ar_version);
8038 printf (_(" Offset into .debug_info: %lx\n"), arange.ar_info_offset);
8039 printf (_(" Pointer Size: %d\n"), arange.ar_pointer_size);
8040 printf (_(" Segment Size: %d\n"), arange.ar_segment_size);
8041
8042 printf (_("\n Address Length\n"));
8043
8044 ranges = start + sizeof (* external);
8045
8046 /* Must pad to an alignment boundary that is twice the pointer size. */
8047 excess = sizeof (* external) % (2 * arange.ar_pointer_size);
8048 if (excess)
8049 ranges += (2 * arange.ar_pointer_size) - excess;
8050
8051 for (;;)
8052 {
8053 address = byte_get (ranges, arange.ar_pointer_size);
8054
8055 ranges += arange.ar_pointer_size;
8056
8057 length = byte_get (ranges, arange.ar_pointer_size);
8058
8059 ranges += arange.ar_pointer_size;
8060
8061 /* A pair of zeros marks the end of the list. */
8062 if (address == 0 && length == 0)
8063 break;
8064
8065 printf (" %8.8lx %lu\n", address, length);
8066 }
8067
8068 start += arange.ar_length + sizeof (external->ar_length);
8069 }
8070
8071 printf ("\n");
8072
8073 return 1;
8074 }
8075
8076 typedef struct Frame_Chunk
8077 {
8078 struct Frame_Chunk * next;
8079 unsigned char * chunk_start;
8080 int ncols;
8081 /* DW_CFA_{undefined,same_value,offset,register,unreferenced} */
8082 short int * col_type;
8083 int * col_offset;
8084 char * augmentation;
8085 unsigned int code_factor;
8086 int data_factor;
8087 unsigned long pc_begin;
8088 unsigned long pc_range;
8089 int cfa_reg;
8090 int cfa_offset;
8091 int ra;
8092 unsigned char fde_encoding;
8093 }
8094 Frame_Chunk;
8095
8096 /* A marker for a col_type that means this column was never referenced
8097 in the frame info. */
8098 #define DW_CFA_unreferenced (-1)
8099
8100 static void frame_need_space PARAMS ((Frame_Chunk *, int));
8101 static void frame_display_row PARAMS ((Frame_Chunk *, int *, int *));
8102 static int size_of_encoded_value PARAMS ((int));
8103
8104 static void
8105 frame_need_space (fc, reg)
8106 Frame_Chunk * fc;
8107 int reg;
8108 {
8109 int prev = fc->ncols;
8110
8111 if (reg < fc->ncols)
8112 return;
8113
8114 fc->ncols = reg + 1;
8115 fc->col_type = (short int *) xrealloc (fc->col_type,
8116 fc->ncols * sizeof (short int));
8117 fc->col_offset = (int *) xrealloc (fc->col_offset,
8118 fc->ncols * sizeof (int));
8119
8120 while (prev < fc->ncols)
8121 {
8122 fc->col_type[prev] = DW_CFA_unreferenced;
8123 fc->col_offset[prev] = 0;
8124 prev++;
8125 }
8126 }
8127
8128 static void
8129 frame_display_row (fc, need_col_headers, max_regs)
8130 Frame_Chunk * fc;
8131 int * need_col_headers;
8132 int * max_regs;
8133 {
8134 int r;
8135 char tmp[100];
8136
8137 if (* max_regs < fc->ncols)
8138 * max_regs = fc->ncols;
8139
8140 if (* need_col_headers)
8141 {
8142 * need_col_headers = 0;
8143
8144 printf (" LOC CFA ");
8145
8146 for (r = 0; r < * max_regs; r++)
8147 if (fc->col_type[r] != DW_CFA_unreferenced)
8148 {
8149 if (r == fc->ra)
8150 printf ("ra ");
8151 else
8152 printf ("r%-4d", r);
8153 }
8154
8155 printf ("\n");
8156 }
8157
8158 printf ("%08lx ", fc->pc_begin);
8159 sprintf (tmp, "r%d%+d", fc->cfa_reg, fc->cfa_offset);
8160 printf ("%-8s ", tmp);
8161
8162 for (r = 0; r < fc->ncols; r++)
8163 {
8164 if (fc->col_type[r] != DW_CFA_unreferenced)
8165 {
8166 switch (fc->col_type[r])
8167 {
8168 case DW_CFA_undefined:
8169 strcpy (tmp, "u");
8170 break;
8171 case DW_CFA_same_value:
8172 strcpy (tmp, "s");
8173 break;
8174 case DW_CFA_offset:
8175 sprintf (tmp, "c%+d", fc->col_offset[r]);
8176 break;
8177 case DW_CFA_register:
8178 sprintf (tmp, "r%d", fc->col_offset[r]);
8179 break;
8180 default:
8181 strcpy (tmp, "n/a");
8182 break;
8183 }
8184 printf ("%-5s", tmp);
8185 }
8186 }
8187 printf ("\n");
8188 }
8189
8190 static int
8191 size_of_encoded_value (encoding)
8192 int encoding;
8193 {
8194 switch (encoding & 0x7)
8195 {
8196 default: /* ??? */
8197 case 0: return is_32bit_elf ? 4 : 8;
8198 case 2: return 2;
8199 case 3: return 4;
8200 case 4: return 8;
8201 }
8202 }
8203
8204 #define GET(N) byte_get (start, N); start += N
8205 #define LEB() read_leb128 (start, & length_return, 0); start += length_return
8206 #define SLEB() read_leb128 (start, & length_return, 1); start += length_return
8207
8208 static int
8209 display_debug_frames (section, start, file)
8210 Elf32_Internal_Shdr * section;
8211 unsigned char * start;
8212 FILE * file ATTRIBUTE_UNUSED;
8213 {
8214 unsigned char * end = start + section->sh_size;
8215 unsigned char * section_start = start;
8216 Frame_Chunk * chunks = 0;
8217 Frame_Chunk * remembered_state = 0;
8218 Frame_Chunk * rs;
8219 int is_eh = (strcmp (SECTION_NAME (section), ".eh_frame") == 0);
8220 int length_return;
8221 int max_regs = 0;
8222 int addr_size = is_32bit_elf ? 4 : 8;
8223
8224 printf (_("The section %s contains:\n"), SECTION_NAME (section));
8225
8226 while (start < end)
8227 {
8228 unsigned char * saved_start;
8229 unsigned char * block_end;
8230 unsigned long length;
8231 unsigned long cie_id;
8232 Frame_Chunk * fc;
8233 Frame_Chunk * cie;
8234 int need_col_headers = 1;
8235 unsigned char * augmentation_data = NULL;
8236 unsigned long augmentation_data_len = 0;
8237 int encoded_ptr_size = addr_size;
8238
8239 saved_start = start;
8240 length = byte_get (start, 4); start += 4;
8241
8242 if (length == 0)
8243 return 1;
8244
8245 if (length == 0xffffffff)
8246 {
8247 warn (_("64-bit DWARF format frames are not supported yet.\n"));
8248 break;
8249 }
8250
8251 block_end = saved_start + length + 4;
8252 cie_id = byte_get (start, 4); start += 4;
8253
8254 if (is_eh ? (cie_id == 0) : (cie_id == DW_CIE_ID))
8255 {
8256 int version;
8257
8258 fc = (Frame_Chunk *) xmalloc (sizeof (Frame_Chunk));
8259 memset (fc, 0, sizeof (Frame_Chunk));
8260
8261 fc->next = chunks;
8262 chunks = fc;
8263 fc->chunk_start = saved_start;
8264 fc->ncols = 0;
8265 fc->col_type = (short int *) xmalloc (sizeof (short int));
8266 fc->col_offset = (int *) xmalloc (sizeof (int));
8267 frame_need_space (fc, max_regs-1);
8268
8269 version = *start++;
8270
8271 fc->augmentation = start;
8272 start = strchr (start, '\0') + 1;
8273
8274 if (fc->augmentation[0] == 'z')
8275 {
8276 fc->code_factor = LEB ();
8277 fc->data_factor = SLEB ();
8278 fc->ra = byte_get (start, 1); start += 1;
8279 augmentation_data_len = LEB ();
8280 augmentation_data = start;
8281 start += augmentation_data_len;
8282 }
8283 else if (strcmp (fc->augmentation, "eh") == 0)
8284 {
8285 start += addr_size;
8286 fc->code_factor = LEB ();
8287 fc->data_factor = SLEB ();
8288 fc->ra = byte_get (start, 1); start += 1;
8289 }
8290 else
8291 {
8292 fc->code_factor = LEB ();
8293 fc->data_factor = SLEB ();
8294 fc->ra = byte_get (start, 1); start += 1;
8295 }
8296 cie = fc;
8297
8298 if (do_debug_frames_interp)
8299 printf ("\n%08lx %08lx %08lx CIE \"%s\" cf=%d df=%d ra=%d\n",
8300 (unsigned long)(saved_start - section_start), length, cie_id,
8301 fc->augmentation, fc->code_factor, fc->data_factor,
8302 fc->ra);
8303 else
8304 {
8305 printf ("\n%08lx %08lx %08lx CIE\n",
8306 (unsigned long)(saved_start - section_start), length, cie_id);
8307 printf (" Version: %d\n", version);
8308 printf (" Augmentation: \"%s\"\n", fc->augmentation);
8309 printf (" Code alignment factor: %u\n", fc->code_factor);
8310 printf (" Data alignment factor: %d\n", fc->data_factor);
8311 printf (" Return address column: %d\n", fc->ra);
8312
8313 if (augmentation_data_len)
8314 {
8315 unsigned long i;
8316 printf (" Augmentation data: ");
8317 for (i = 0; i < augmentation_data_len; ++i)
8318 printf (" %02x", augmentation_data[i]);
8319 putchar ('\n');
8320 }
8321 putchar ('\n');
8322 }
8323
8324 if (augmentation_data_len)
8325 {
8326 unsigned char *p, *q;
8327 p = fc->augmentation + 1;
8328 q = augmentation_data;
8329
8330 while (1)
8331 {
8332 if (*p == 'L')
8333 q++;
8334 else if (*p == 'P')
8335 q += 1 + size_of_encoded_value (*q);
8336 else if (*p == 'R')
8337 fc->fde_encoding = *q++;
8338 else
8339 break;
8340 p++;
8341 }
8342
8343 if (fc->fde_encoding)
8344 encoded_ptr_size = size_of_encoded_value (fc->fde_encoding);
8345 }
8346
8347 frame_need_space (fc, fc->ra);
8348 }
8349 else
8350 {
8351 unsigned char * look_for;
8352 static Frame_Chunk fde_fc;
8353
8354 fc = & fde_fc;
8355 memset (fc, 0, sizeof (Frame_Chunk));
8356
8357 look_for = is_eh ? start - 4 - cie_id : section_start + cie_id;
8358
8359 for (cie = chunks; cie ; cie = cie->next)
8360 if (cie->chunk_start == look_for)
8361 break;
8362
8363 if (!cie)
8364 {
8365 warn ("Invalid CIE pointer %08lx in FDE at %08lx\n",
8366 cie_id, saved_start);
8367 start = block_end;
8368 fc->ncols = 0;
8369 fc->col_type = (short int *) xmalloc (sizeof (short int));
8370 fc->col_offset = (int *) xmalloc (sizeof (int));
8371 frame_need_space (fc, max_regs - 1);
8372 cie = fc;
8373 fc->augmentation = "";
8374 fc->fde_encoding = 0;
8375 }
8376 else
8377 {
8378 fc->ncols = cie->ncols;
8379 fc->col_type = (short int *) xmalloc (fc->ncols * sizeof (short int));
8380 fc->col_offset = (int *) xmalloc (fc->ncols * sizeof (int));
8381 memcpy (fc->col_type, cie->col_type, fc->ncols * sizeof (short int));
8382 memcpy (fc->col_offset, cie->col_offset, fc->ncols * sizeof (int));
8383 fc->augmentation = cie->augmentation;
8384 fc->code_factor = cie->code_factor;
8385 fc->data_factor = cie->data_factor;
8386 fc->cfa_reg = cie->cfa_reg;
8387 fc->cfa_offset = cie->cfa_offset;
8388 fc->ra = cie->ra;
8389 frame_need_space (fc, max_regs-1);
8390 fc->fde_encoding = cie->fde_encoding;
8391 }
8392
8393 if (fc->fde_encoding)
8394 encoded_ptr_size = size_of_encoded_value (fc->fde_encoding);
8395
8396 fc->pc_begin = byte_get (start, encoded_ptr_size);
8397 start += encoded_ptr_size;
8398 fc->pc_range = byte_get (start, encoded_ptr_size);
8399 start += encoded_ptr_size;
8400
8401 if (cie->augmentation[0] == 'z')
8402 {
8403 augmentation_data_len = LEB ();
8404 augmentation_data = start;
8405 start += augmentation_data_len;
8406 }
8407
8408 printf ("\n%08lx %08lx %08lx FDE cie=%08lx pc=%08lx..%08lx\n",
8409 (unsigned long)(saved_start - section_start), length, cie_id,
8410 (unsigned long)(cie->chunk_start - section_start),
8411 fc->pc_begin, fc->pc_begin + fc->pc_range);
8412 if (! do_debug_frames_interp && augmentation_data_len)
8413 {
8414 unsigned long i;
8415 printf (" Augmentation data: ");
8416 for (i = 0; i < augmentation_data_len; ++i)
8417 printf (" %02x", augmentation_data[i]);
8418 putchar ('\n');
8419 putchar ('\n');
8420 }
8421 }
8422
8423 /* At this point, fc is the current chunk, cie (if any) is set, and we're
8424 about to interpret instructions for the chunk. */
8425
8426 if (do_debug_frames_interp)
8427 {
8428 /* Start by making a pass over the chunk, allocating storage
8429 and taking note of what registers are used. */
8430 unsigned char * tmp = start;
8431
8432 while (start < block_end)
8433 {
8434 unsigned op, opa;
8435 unsigned long reg;
8436
8437 op = * start ++;
8438 opa = op & 0x3f;
8439 if (op & 0xc0)
8440 op &= 0xc0;
8441
8442 /* Warning: if you add any more cases to this switch, be
8443 sure to add them to the corresponding switch below. */
8444 switch (op)
8445 {
8446 case DW_CFA_advance_loc:
8447 break;
8448 case DW_CFA_offset:
8449 LEB ();
8450 frame_need_space (fc, opa);
8451 fc->col_type[opa] = DW_CFA_undefined;
8452 break;
8453 case DW_CFA_restore:
8454 frame_need_space (fc, opa);
8455 fc->col_type[opa] = DW_CFA_undefined;
8456 break;
8457 case DW_CFA_set_loc:
8458 start += encoded_ptr_size;
8459 break;
8460 case DW_CFA_advance_loc1:
8461 start += 1;
8462 break;
8463 case DW_CFA_advance_loc2:
8464 start += 2;
8465 break;
8466 case DW_CFA_advance_loc4:
8467 start += 4;
8468 break;
8469 case DW_CFA_offset_extended:
8470 reg = LEB (); LEB ();
8471 frame_need_space (fc, reg);
8472 fc->col_type[reg] = DW_CFA_undefined;
8473 break;
8474 case DW_CFA_restore_extended:
8475 reg = LEB ();
8476 frame_need_space (fc, reg);
8477 fc->col_type[reg] = DW_CFA_undefined;
8478 break;
8479 case DW_CFA_undefined:
8480 reg = LEB ();
8481 frame_need_space (fc, reg);
8482 fc->col_type[reg] = DW_CFA_undefined;
8483 break;
8484 case DW_CFA_same_value:
8485 reg = LEB ();
8486 frame_need_space (fc, reg);
8487 fc->col_type[reg] = DW_CFA_undefined;
8488 break;
8489 case DW_CFA_register:
8490 reg = LEB (); LEB ();
8491 frame_need_space (fc, reg);
8492 fc->col_type[reg] = DW_CFA_undefined;
8493 break;
8494 case DW_CFA_def_cfa:
8495 LEB (); LEB ();
8496 break;
8497 case DW_CFA_def_cfa_register:
8498 LEB ();
8499 break;
8500 case DW_CFA_def_cfa_offset:
8501 LEB ();
8502 break;
8503 case DW_CFA_offset_extended_sf:
8504 reg = LEB (); SLEB ();
8505 frame_need_space (fc, reg);
8506 fc->col_type[reg] = DW_CFA_undefined;
8507 break;
8508 case DW_CFA_def_cfa_sf:
8509 LEB (); SLEB ();
8510 break;
8511 case DW_CFA_def_cfa_offset_sf:
8512 SLEB ();
8513 break;
8514 case DW_CFA_GNU_args_size:
8515 LEB ();
8516 break;
8517 case DW_CFA_GNU_negative_offset_extended:
8518 reg = LEB (); LEB ();
8519 frame_need_space (fc, reg);
8520 fc->col_type[reg] = DW_CFA_undefined;
8521
8522 default:
8523 break;
8524 }
8525 }
8526 start = tmp;
8527 }
8528
8529 /* Now we know what registers are used, make a second pass over
8530 the chunk, this time actually printing out the info. */
8531
8532 while (start < block_end)
8533 {
8534 unsigned op, opa;
8535 unsigned long ul, reg, roffs;
8536 long l, ofs;
8537 bfd_vma vma;
8538
8539 op = * start ++;
8540 opa = op & 0x3f;
8541 if (op & 0xc0)
8542 op &= 0xc0;
8543
8544 /* Warning: if you add any more cases to this switch, be
8545 sure to add them to the corresponding switch above. */
8546 switch (op)
8547 {
8548 case DW_CFA_advance_loc:
8549 if (do_debug_frames_interp)
8550 frame_display_row (fc, &need_col_headers, &max_regs);
8551 else
8552 printf (" DW_CFA_advance_loc: %d to %08lx\n",
8553 opa * fc->code_factor,
8554 fc->pc_begin + opa * fc->code_factor);
8555 fc->pc_begin += opa * fc->code_factor;
8556 break;
8557
8558 case DW_CFA_offset:
8559 roffs = LEB ();
8560 if (! do_debug_frames_interp)
8561 printf (" DW_CFA_offset: r%d at cfa%+ld\n",
8562 opa, roffs * fc->data_factor);
8563 fc->col_type[opa] = DW_CFA_offset;
8564 fc->col_offset[opa] = roffs * fc->data_factor;
8565 break;
8566
8567 case DW_CFA_restore:
8568 if (! do_debug_frames_interp)
8569 printf (" DW_CFA_restore: r%d\n", opa);
8570 fc->col_type[opa] = cie->col_type[opa];
8571 fc->col_offset[opa] = cie->col_offset[opa];
8572 break;
8573
8574 case DW_CFA_set_loc:
8575 vma = byte_get (start, encoded_ptr_size);
8576 start += encoded_ptr_size;
8577 if (do_debug_frames_interp)
8578 frame_display_row (fc, &need_col_headers, &max_regs);
8579 else
8580 printf (" DW_CFA_set_loc: %08lx\n", (unsigned long)vma);
8581 fc->pc_begin = vma;
8582 break;
8583
8584 case DW_CFA_advance_loc1:
8585 ofs = byte_get (start, 1); start += 1;
8586 if (do_debug_frames_interp)
8587 frame_display_row (fc, &need_col_headers, &max_regs);
8588 else
8589 printf (" DW_CFA_advance_loc1: %ld to %08lx\n",
8590 ofs * fc->code_factor,
8591 fc->pc_begin + ofs * fc->code_factor);
8592 fc->pc_begin += ofs * fc->code_factor;
8593 break;
8594
8595 case DW_CFA_advance_loc2:
8596 ofs = byte_get (start, 2); start += 2;
8597 if (do_debug_frames_interp)
8598 frame_display_row (fc, &need_col_headers, &max_regs);
8599 else
8600 printf (" DW_CFA_advance_loc2: %ld to %08lx\n",
8601 ofs * fc->code_factor,
8602 fc->pc_begin + ofs * fc->code_factor);
8603 fc->pc_begin += ofs * fc->code_factor;
8604 break;
8605
8606 case DW_CFA_advance_loc4:
8607 ofs = byte_get (start, 4); start += 4;
8608 if (do_debug_frames_interp)
8609 frame_display_row (fc, &need_col_headers, &max_regs);
8610 else
8611 printf (" DW_CFA_advance_loc4: %ld to %08lx\n",
8612 ofs * fc->code_factor,
8613 fc->pc_begin + ofs * fc->code_factor);
8614 fc->pc_begin += ofs * fc->code_factor;
8615 break;
8616
8617 case DW_CFA_offset_extended:
8618 reg = LEB ();
8619 roffs = LEB ();
8620 if (! do_debug_frames_interp)
8621 printf (" DW_CFA_offset_extended: r%ld at cfa%+ld\n",
8622 reg, roffs * fc->data_factor);
8623 fc->col_type[reg] = DW_CFA_offset;
8624 fc->col_offset[reg] = roffs * fc->data_factor;
8625 break;
8626
8627 case DW_CFA_restore_extended:
8628 reg = LEB ();
8629 if (! do_debug_frames_interp)
8630 printf (" DW_CFA_restore_extended: r%ld\n", reg);
8631 fc->col_type[reg] = cie->col_type[reg];
8632 fc->col_offset[reg] = cie->col_offset[reg];
8633 break;
8634
8635 case DW_CFA_undefined:
8636 reg = LEB ();
8637 if (! do_debug_frames_interp)
8638 printf (" DW_CFA_undefined: r%ld\n", reg);
8639 fc->col_type[reg] = DW_CFA_undefined;
8640 fc->col_offset[reg] = 0;
8641 break;
8642
8643 case DW_CFA_same_value:
8644 reg = LEB ();
8645 if (! do_debug_frames_interp)
8646 printf (" DW_CFA_same_value: r%ld\n", reg);
8647 fc->col_type[reg] = DW_CFA_same_value;
8648 fc->col_offset[reg] = 0;
8649 break;
8650
8651 case DW_CFA_register:
8652 reg = LEB ();
8653 roffs = LEB ();
8654 if (! do_debug_frames_interp)
8655 printf (" DW_CFA_register: r%ld\n", reg);
8656 fc->col_type[reg] = DW_CFA_register;
8657 fc->col_offset[reg] = roffs;
8658 break;
8659
8660 case DW_CFA_remember_state:
8661 if (! do_debug_frames_interp)
8662 printf (" DW_CFA_remember_state\n");
8663 rs = (Frame_Chunk *) xmalloc (sizeof (Frame_Chunk));
8664 rs->ncols = fc->ncols;
8665 rs->col_type = (short int *) xmalloc (rs->ncols * sizeof (short int));
8666 rs->col_offset = (int *) xmalloc (rs->ncols * sizeof (int));
8667 memcpy (rs->col_type, fc->col_type, rs->ncols);
8668 memcpy (rs->col_offset, fc->col_offset, rs->ncols * sizeof (int));
8669 rs->next = remembered_state;
8670 remembered_state = rs;
8671 break;
8672
8673 case DW_CFA_restore_state:
8674 if (! do_debug_frames_interp)
8675 printf (" DW_CFA_restore_state\n");
8676 rs = remembered_state;
8677 remembered_state = rs->next;
8678 frame_need_space (fc, rs->ncols-1);
8679 memcpy (fc->col_type, rs->col_type, rs->ncols);
8680 memcpy (fc->col_offset, rs->col_offset, rs->ncols * sizeof (int));
8681 free (rs->col_type);
8682 free (rs->col_offset);
8683 free (rs);
8684 break;
8685
8686 case DW_CFA_def_cfa:
8687 fc->cfa_reg = LEB ();
8688 fc->cfa_offset = LEB ();
8689 if (! do_debug_frames_interp)
8690 printf (" DW_CFA_def_cfa: r%d ofs %d\n",
8691 fc->cfa_reg, fc->cfa_offset);
8692 break;
8693
8694 case DW_CFA_def_cfa_register:
8695 fc->cfa_reg = LEB ();
8696 if (! do_debug_frames_interp)
8697 printf (" DW_CFA_def_cfa_reg: r%d\n", fc->cfa_reg);
8698 break;
8699
8700 case DW_CFA_def_cfa_offset:
8701 fc->cfa_offset = LEB ();
8702 if (! do_debug_frames_interp)
8703 printf (" DW_CFA_def_cfa_offset: %d\n", fc->cfa_offset);
8704 break;
8705
8706 case DW_CFA_nop:
8707 if (! do_debug_frames_interp)
8708 printf (" DW_CFA_nop\n");
8709 break;
8710
8711 case DW_CFA_offset_extended_sf:
8712 reg = LEB ();
8713 l = SLEB ();
8714 frame_need_space (fc, reg);
8715 if (! do_debug_frames_interp)
8716 printf (" DW_CFA_offset_extended_sf: r%ld at cfa%+ld\n",
8717 reg, l * fc->data_factor);
8718 fc->col_type[reg] = DW_CFA_offset;
8719 fc->col_offset[reg] = l * fc->data_factor;
8720 break;
8721
8722 case DW_CFA_def_cfa_sf:
8723 fc->cfa_reg = LEB ();
8724 fc->cfa_offset = SLEB ();
8725 if (! do_debug_frames_interp)
8726 printf (" DW_CFA_def_cfa_sf: r%d ofs %d\n",
8727 fc->cfa_reg, fc->cfa_offset);
8728 break;
8729
8730 case DW_CFA_def_cfa_offset_sf:
8731 fc->cfa_offset = SLEB ();
8732 if (! do_debug_frames_interp)
8733 printf (" DW_CFA_def_cfa_offset_sf: %d\n", fc->cfa_offset);
8734 break;
8735
8736 case DW_CFA_GNU_window_save:
8737 if (! do_debug_frames_interp)
8738 printf (" DW_CFA_GNU_window_save\n");
8739 break;
8740
8741 case DW_CFA_GNU_args_size:
8742 ul = LEB ();
8743 if (! do_debug_frames_interp)
8744 printf (" DW_CFA_GNU_args_size: %ld\n", ul);
8745 break;
8746
8747 case DW_CFA_GNU_negative_offset_extended:
8748 reg = LEB ();
8749 l = - LEB ();
8750 frame_need_space (fc, reg);
8751 if (! do_debug_frames_interp)
8752 printf (" DW_CFA_GNU_negative_offset_extended: r%ld at cfa%+ld\n",
8753 reg, l * fc->data_factor);
8754 fc->col_type[reg] = DW_CFA_offset;
8755 fc->col_offset[reg] = l * fc->data_factor;
8756 break;
8757
8758 /* FIXME: How do we handle these? */
8759 case DW_CFA_def_cfa_expression:
8760 fprintf (stderr, "unsupported DW_CFA_def_cfa_expression\n");
8761 start = block_end;
8762 break;
8763
8764 case DW_CFA_expression:
8765 fprintf (stderr, "unsupported DW_CFA_expression\n");
8766 start = block_end;
8767 break;
8768
8769 default:
8770 fprintf (stderr, "unsupported or unknown DW_CFA_%d\n", op);
8771 start = block_end;
8772 }
8773 }
8774
8775 if (do_debug_frames_interp)
8776 frame_display_row (fc, &need_col_headers, &max_regs);
8777
8778 start = block_end;
8779 }
8780
8781 printf ("\n");
8782
8783 return 1;
8784 }
8785
8786 #undef GET
8787 #undef LEB
8788 #undef SLEB
8789
8790 static int
8791 display_debug_not_supported (section, start, file)
8792 Elf32_Internal_Shdr * section;
8793 unsigned char * start ATTRIBUTE_UNUSED;
8794 FILE * file ATTRIBUTE_UNUSED;
8795 {
8796 printf (_("Displaying the debug contents of section %s is not yet supported.\n"),
8797 SECTION_NAME (section));
8798
8799 return 1;
8800 }
8801
8802 /* Pre-scan the .debug_info section to record the size of address.
8803 When dumping the .debug_line, we use that size information, assuming
8804 that all compilation units have the same address size. */
8805 static int
8806 prescan_debug_info (section, start, file)
8807 Elf32_Internal_Shdr * section ATTRIBUTE_UNUSED;
8808 unsigned char * start;
8809 FILE * file ATTRIBUTE_UNUSED;
8810 {
8811 DWARF2_External_CompUnit * external;
8812
8813 external = (DWARF2_External_CompUnit *) start;
8814
8815 debug_line_pointer_size = BYTE_GET (external->cu_pointer_size);
8816 return 0;
8817 }
8818
8819 /* A structure containing the name of a debug section and a pointer
8820 to a function that can decode it. The third field is a prescan
8821 function to be run over the section before displaying any of the
8822 sections. */
8823 struct
8824 {
8825 const char * const name;
8826 int (* display) PARAMS ((Elf32_Internal_Shdr *, unsigned char *, FILE *));
8827 int (* prescan) PARAMS ((Elf32_Internal_Shdr *, unsigned char *, FILE *));
8828 }
8829 debug_displays[] =
8830 {
8831 { ".debug_abbrev", display_debug_abbrev, NULL },
8832 { ".debug_aranges", display_debug_aranges, NULL },
8833 { ".debug_frame", display_debug_frames, NULL },
8834 { ".debug_info", display_debug_info, prescan_debug_info },
8835 { ".debug_line", display_debug_lines, NULL },
8836 { ".debug_pubnames", display_debug_pubnames, NULL },
8837 { ".eh_frame", display_debug_frames, NULL },
8838 { ".debug_macinfo", display_debug_macinfo, NULL },
8839 { ".debug_str", display_debug_str, NULL },
8840 { ".debug_loc", display_debug_loc, NULL },
8841 { ".debug_pubtypes", display_debug_not_supported, NULL },
8842 { ".debug_ranges", display_debug_not_supported, NULL },
8843 { ".debug_static_func", display_debug_not_supported, NULL },
8844 { ".debug_static_vars", display_debug_not_supported, NULL },
8845 { ".debug_types", display_debug_not_supported, NULL },
8846 { ".debug_weaknames", display_debug_not_supported, NULL }
8847 };
8848
8849 static int
8850 display_debug_section (section, file)
8851 Elf32_Internal_Shdr * section;
8852 FILE * file;
8853 {
8854 char * name = SECTION_NAME (section);
8855 bfd_size_type length;
8856 unsigned char * start;
8857 int i;
8858
8859 length = section->sh_size;
8860 if (length == 0)
8861 {
8862 printf (_("\nSection '%s' has no debugging data.\n"), name);
8863 return 0;
8864 }
8865
8866 start = (unsigned char *) get_data (NULL, file, section->sh_offset, length,
8867 _("debug section data"));
8868 if (!start)
8869 return 0;
8870
8871 /* See if we know how to display the contents of this section. */
8872 if (strncmp (name, ".gnu.linkonce.wi.", 17) == 0)
8873 name = ".debug_info";
8874
8875 for (i = NUM_ELEM (debug_displays); i--;)
8876 if (strcmp (debug_displays[i].name, name) == 0)
8877 {
8878 debug_displays[i].display (section, start, file);
8879 break;
8880 }
8881
8882 if (i == -1)
8883 printf (_("Unrecognized debug section: %s\n"), name);
8884
8885 free (start);
8886
8887 /* If we loaded in the abbrev section at some point,
8888 we must release it here. */
8889 free_abbrevs ();
8890
8891 return 1;
8892 }
8893
8894 static int
8895 process_section_contents (file)
8896 FILE * file;
8897 {
8898 Elf32_Internal_Shdr * section;
8899 unsigned int i;
8900
8901 if (! do_dump)
8902 return 1;
8903
8904 /* Pre-scan the debug sections to find some debug information not
8905 present in some of them. For the .debug_line, we must find out the
8906 size of address (specified in .debug_info and .debug_aranges). */
8907 for (i = 0, section = section_headers;
8908 i < elf_header.e_shnum && i < num_dump_sects;
8909 i ++, section ++)
8910 {
8911 char * name = SECTION_NAME (section);
8912 int j;
8913
8914 if (section->sh_size == 0)
8915 continue;
8916
8917 /* See if there is some pre-scan operation for this section. */
8918 for (j = NUM_ELEM (debug_displays); j--;)
8919 if (strcmp (debug_displays[j].name, name) == 0)
8920 {
8921 if (debug_displays[j].prescan != NULL)
8922 {
8923 bfd_size_type length;
8924 unsigned char * start;
8925
8926 length = section->sh_size;
8927 start = ((unsigned char *)
8928 get_data (NULL, file, section->sh_offset, length,
8929 _("debug section data")));
8930 if (!start)
8931 return 0;
8932
8933 debug_displays[j].prescan (section, start, file);
8934 free (start);
8935 }
8936
8937 break;
8938 }
8939 }
8940
8941 for (i = 0, section = section_headers;
8942 i < elf_header.e_shnum && i < num_dump_sects;
8943 i ++, section ++)
8944 {
8945 #ifdef SUPPORT_DISASSEMBLY
8946 if (dump_sects[i] & DISASS_DUMP)
8947 disassemble_section (section, file);
8948 #endif
8949 if (dump_sects[i] & HEX_DUMP)
8950 dump_section (section, file);
8951
8952 if (dump_sects[i] & DEBUG_DUMP)
8953 display_debug_section (section, file);
8954 }
8955
8956 if (i < num_dump_sects)
8957 warn (_("Some sections were not dumped because they do not exist!\n"));
8958
8959 return 1;
8960 }
8961
8962 static void
8963 process_mips_fpe_exception (mask)
8964 int mask;
8965 {
8966 if (mask)
8967 {
8968 int first = 1;
8969 if (mask & OEX_FPU_INEX)
8970 fputs ("INEX", stdout), first = 0;
8971 if (mask & OEX_FPU_UFLO)
8972 printf ("%sUFLO", first ? "" : "|"), first = 0;
8973 if (mask & OEX_FPU_OFLO)
8974 printf ("%sOFLO", first ? "" : "|"), first = 0;
8975 if (mask & OEX_FPU_DIV0)
8976 printf ("%sDIV0", first ? "" : "|"), first = 0;
8977 if (mask & OEX_FPU_INVAL)
8978 printf ("%sINVAL", first ? "" : "|");
8979 }
8980 else
8981 fputs ("0", stdout);
8982 }
8983
8984 static int
8985 process_mips_specific (file)
8986 FILE * file;
8987 {
8988 Elf_Internal_Dyn * entry;
8989 size_t liblist_offset = 0;
8990 size_t liblistno = 0;
8991 size_t conflictsno = 0;
8992 size_t options_offset = 0;
8993 size_t conflicts_offset = 0;
8994
8995 /* We have a lot of special sections. Thanks SGI! */
8996 if (dynamic_segment == NULL)
8997 /* No information available. */
8998 return 0;
8999
9000 for (entry = dynamic_segment; entry->d_tag != DT_NULL; ++entry)
9001 switch (entry->d_tag)
9002 {
9003 case DT_MIPS_LIBLIST:
9004 liblist_offset = entry->d_un.d_val - loadaddr;
9005 break;
9006 case DT_MIPS_LIBLISTNO:
9007 liblistno = entry->d_un.d_val;
9008 break;
9009 case DT_MIPS_OPTIONS:
9010 options_offset = entry->d_un.d_val - loadaddr;
9011 break;
9012 case DT_MIPS_CONFLICT:
9013 conflicts_offset = entry->d_un.d_val - loadaddr;
9014 break;
9015 case DT_MIPS_CONFLICTNO:
9016 conflictsno = entry->d_un.d_val;
9017 break;
9018 default:
9019 break;
9020 }
9021
9022 if (liblist_offset != 0 && liblistno != 0 && do_dynamic)
9023 {
9024 Elf32_External_Lib * elib;
9025 size_t cnt;
9026
9027 elib = ((Elf32_External_Lib *)
9028 get_data (NULL, file, liblist_offset,
9029 liblistno * sizeof (Elf32_External_Lib),
9030 _("liblist")));
9031 if (elib)
9032 {
9033 printf ("\nSection '.liblist' contains %lu entries:\n",
9034 (unsigned long) liblistno);
9035 fputs (" Library Time Stamp Checksum Version Flags\n",
9036 stdout);
9037
9038 for (cnt = 0; cnt < liblistno; ++cnt)
9039 {
9040 Elf32_Lib liblist;
9041 time_t time;
9042 char timebuf[20];
9043 struct tm * tmp;
9044
9045 liblist.l_name = BYTE_GET (elib[cnt].l_name);
9046 time = BYTE_GET (elib[cnt].l_time_stamp);
9047 liblist.l_checksum = BYTE_GET (elib[cnt].l_checksum);
9048 liblist.l_version = BYTE_GET (elib[cnt].l_version);
9049 liblist.l_flags = BYTE_GET (elib[cnt].l_flags);
9050
9051 tmp = gmtime (&time);
9052 sprintf (timebuf, "%04u-%02u-%02uT%02u:%02u:%02u",
9053 tmp->tm_year + 1900, tmp->tm_mon + 1, tmp->tm_mday,
9054 tmp->tm_hour, tmp->tm_min, tmp->tm_sec);
9055
9056 printf ("%3lu: ", (unsigned long) cnt);
9057 print_symbol (20, dynamic_strings + liblist.l_name);
9058 printf (" %s %#10lx %-7ld", timebuf, liblist.l_checksum,
9059 liblist.l_version);
9060
9061 if (liblist.l_flags == 0)
9062 puts (" NONE");
9063 else
9064 {
9065 static const struct
9066 {
9067 const char * name;
9068 int bit;
9069 }
9070 l_flags_vals[] =
9071 {
9072 { " EXACT_MATCH", LL_EXACT_MATCH },
9073 { " IGNORE_INT_VER", LL_IGNORE_INT_VER },
9074 { " REQUIRE_MINOR", LL_REQUIRE_MINOR },
9075 { " EXPORTS", LL_EXPORTS },
9076 { " DELAY_LOAD", LL_DELAY_LOAD },
9077 { " DELTA", LL_DELTA }
9078 };
9079 int flags = liblist.l_flags;
9080 size_t fcnt;
9081
9082 for (fcnt = 0;
9083 fcnt < sizeof (l_flags_vals) / sizeof (l_flags_vals[0]);
9084 ++fcnt)
9085 if ((flags & l_flags_vals[fcnt].bit) != 0)
9086 {
9087 fputs (l_flags_vals[fcnt].name, stdout);
9088 flags ^= l_flags_vals[fcnt].bit;
9089 }
9090 if (flags != 0)
9091 printf (" %#x", (unsigned int) flags);
9092
9093 puts ("");
9094 }
9095 }
9096
9097 free (elib);
9098 }
9099 }
9100
9101 if (options_offset != 0)
9102 {
9103 Elf_External_Options * eopt;
9104 Elf_Internal_Shdr * sect = section_headers;
9105 Elf_Internal_Options * iopt;
9106 Elf_Internal_Options * option;
9107 size_t offset;
9108 int cnt;
9109
9110 /* Find the section header so that we get the size. */
9111 while (sect->sh_type != SHT_MIPS_OPTIONS)
9112 ++ sect;
9113
9114 eopt = (Elf_External_Options *) get_data (NULL, file, options_offset,
9115 sect->sh_size, _("options"));
9116 if (eopt)
9117 {
9118 iopt = ((Elf_Internal_Options *)
9119 malloc ((sect->sh_size / sizeof (eopt)) * sizeof (* iopt)));
9120 if (iopt == NULL)
9121 {
9122 error (_("Out of memory"));
9123 return 0;
9124 }
9125
9126 offset = cnt = 0;
9127 option = iopt;
9128
9129 while (offset < sect->sh_size)
9130 {
9131 Elf_External_Options * eoption;
9132
9133 eoption = (Elf_External_Options *) ((char *) eopt + offset);
9134
9135 option->kind = BYTE_GET (eoption->kind);
9136 option->size = BYTE_GET (eoption->size);
9137 option->section = BYTE_GET (eoption->section);
9138 option->info = BYTE_GET (eoption->info);
9139
9140 offset += option->size;
9141
9142 ++option;
9143 ++cnt;
9144 }
9145
9146 printf (_("\nSection '%s' contains %d entries:\n"),
9147 SECTION_NAME (sect), cnt);
9148
9149 option = iopt;
9150
9151 while (cnt-- > 0)
9152 {
9153 size_t len;
9154
9155 switch (option->kind)
9156 {
9157 case ODK_NULL:
9158 /* This shouldn't happen. */
9159 printf (" NULL %d %lx", option->section, option->info);
9160 break;
9161 case ODK_REGINFO:
9162 printf (" REGINFO ");
9163 if (elf_header.e_machine == EM_MIPS)
9164 {
9165 /* 32bit form. */
9166 Elf32_External_RegInfo * ereg;
9167 Elf32_RegInfo reginfo;
9168
9169 ereg = (Elf32_External_RegInfo *) (option + 1);
9170 reginfo.ri_gprmask = BYTE_GET (ereg->ri_gprmask);
9171 reginfo.ri_cprmask[0] = BYTE_GET (ereg->ri_cprmask[0]);
9172 reginfo.ri_cprmask[1] = BYTE_GET (ereg->ri_cprmask[1]);
9173 reginfo.ri_cprmask[2] = BYTE_GET (ereg->ri_cprmask[2]);
9174 reginfo.ri_cprmask[3] = BYTE_GET (ereg->ri_cprmask[3]);
9175 reginfo.ri_gp_value = BYTE_GET (ereg->ri_gp_value);
9176
9177 printf ("GPR %08lx GP 0x%lx\n",
9178 reginfo.ri_gprmask,
9179 (unsigned long) reginfo.ri_gp_value);
9180 printf (" CPR0 %08lx CPR1 %08lx CPR2 %08lx CPR3 %08lx\n",
9181 reginfo.ri_cprmask[0], reginfo.ri_cprmask[1],
9182 reginfo.ri_cprmask[2], reginfo.ri_cprmask[3]);
9183 }
9184 else
9185 {
9186 /* 64 bit form. */
9187 Elf64_External_RegInfo * ereg;
9188 Elf64_Internal_RegInfo reginfo;
9189
9190 ereg = (Elf64_External_RegInfo *) (option + 1);
9191 reginfo.ri_gprmask = BYTE_GET (ereg->ri_gprmask);
9192 reginfo.ri_cprmask[0] = BYTE_GET (ereg->ri_cprmask[0]);
9193 reginfo.ri_cprmask[1] = BYTE_GET (ereg->ri_cprmask[1]);
9194 reginfo.ri_cprmask[2] = BYTE_GET (ereg->ri_cprmask[2]);
9195 reginfo.ri_cprmask[3] = BYTE_GET (ereg->ri_cprmask[3]);
9196 reginfo.ri_gp_value = BYTE_GET8 (ereg->ri_gp_value);
9197
9198 printf ("GPR %08lx GP 0x",
9199 reginfo.ri_gprmask);
9200 printf_vma (reginfo.ri_gp_value);
9201 printf ("\n");
9202
9203 printf (" CPR0 %08lx CPR1 %08lx CPR2 %08lx CPR3 %08lx\n",
9204 reginfo.ri_cprmask[0], reginfo.ri_cprmask[1],
9205 reginfo.ri_cprmask[2], reginfo.ri_cprmask[3]);
9206 }
9207 ++option;
9208 continue;
9209 case ODK_EXCEPTIONS:
9210 fputs (" EXCEPTIONS fpe_min(", stdout);
9211 process_mips_fpe_exception (option->info & OEX_FPU_MIN);
9212 fputs (") fpe_max(", stdout);
9213 process_mips_fpe_exception ((option->info & OEX_FPU_MAX) >> 8);
9214 fputs (")", stdout);
9215
9216 if (option->info & OEX_PAGE0)
9217 fputs (" PAGE0", stdout);
9218 if (option->info & OEX_SMM)
9219 fputs (" SMM", stdout);
9220 if (option->info & OEX_FPDBUG)
9221 fputs (" FPDBUG", stdout);
9222 if (option->info & OEX_DISMISS)
9223 fputs (" DISMISS", stdout);
9224 break;
9225 case ODK_PAD:
9226 fputs (" PAD ", stdout);
9227 if (option->info & OPAD_PREFIX)
9228 fputs (" PREFIX", stdout);
9229 if (option->info & OPAD_POSTFIX)
9230 fputs (" POSTFIX", stdout);
9231 if (option->info & OPAD_SYMBOL)
9232 fputs (" SYMBOL", stdout);
9233 break;
9234 case ODK_HWPATCH:
9235 fputs (" HWPATCH ", stdout);
9236 if (option->info & OHW_R4KEOP)
9237 fputs (" R4KEOP", stdout);
9238 if (option->info & OHW_R8KPFETCH)
9239 fputs (" R8KPFETCH", stdout);
9240 if (option->info & OHW_R5KEOP)
9241 fputs (" R5KEOP", stdout);
9242 if (option->info & OHW_R5KCVTL)
9243 fputs (" R5KCVTL", stdout);
9244 break;
9245 case ODK_FILL:
9246 fputs (" FILL ", stdout);
9247 /* XXX Print content of info word? */
9248 break;
9249 case ODK_TAGS:
9250 fputs (" TAGS ", stdout);
9251 /* XXX Print content of info word? */
9252 break;
9253 case ODK_HWAND:
9254 fputs (" HWAND ", stdout);
9255 if (option->info & OHWA0_R4KEOP_CHECKED)
9256 fputs (" R4KEOP_CHECKED", stdout);
9257 if (option->info & OHWA0_R4KEOP_CLEAN)
9258 fputs (" R4KEOP_CLEAN", stdout);
9259 break;
9260 case ODK_HWOR:
9261 fputs (" HWOR ", stdout);
9262 if (option->info & OHWA0_R4KEOP_CHECKED)
9263 fputs (" R4KEOP_CHECKED", stdout);
9264 if (option->info & OHWA0_R4KEOP_CLEAN)
9265 fputs (" R4KEOP_CLEAN", stdout);
9266 break;
9267 case ODK_GP_GROUP:
9268 printf (" GP_GROUP %#06lx self-contained %#06lx",
9269 option->info & OGP_GROUP,
9270 (option->info & OGP_SELF) >> 16);
9271 break;
9272 case ODK_IDENT:
9273 printf (" IDENT %#06lx self-contained %#06lx",
9274 option->info & OGP_GROUP,
9275 (option->info & OGP_SELF) >> 16);
9276 break;
9277 default:
9278 /* This shouldn't happen. */
9279 printf (" %3d ??? %d %lx",
9280 option->kind, option->section, option->info);
9281 break;
9282 }
9283
9284 len = sizeof (* eopt);
9285 while (len < option->size)
9286 if (((char *) option)[len] >= ' '
9287 && ((char *) option)[len] < 0x7f)
9288 printf ("%c", ((char *) option)[len++]);
9289 else
9290 printf ("\\%03o", ((char *) option)[len++]);
9291
9292 fputs ("\n", stdout);
9293 ++option;
9294 }
9295
9296 free (eopt);
9297 }
9298 }
9299
9300 if (conflicts_offset != 0 && conflictsno != 0)
9301 {
9302 Elf32_Conflict * iconf;
9303 size_t cnt;
9304
9305 if (dynamic_symbols == NULL)
9306 {
9307 error (_("conflict list found without a dynamic symbol table"));
9308 return 0;
9309 }
9310
9311 iconf = (Elf32_Conflict *) malloc (conflictsno * sizeof (* iconf));
9312 if (iconf == NULL)
9313 {
9314 error (_("Out of memory"));
9315 return 0;
9316 }
9317
9318 if (is_32bit_elf)
9319 {
9320 Elf32_External_Conflict * econf32;
9321
9322 econf32 = ((Elf32_External_Conflict *)
9323 get_data (NULL, file, conflicts_offset,
9324 conflictsno * sizeof (* econf32),
9325 _("conflict")));
9326 if (!econf32)
9327 return 0;
9328
9329 for (cnt = 0; cnt < conflictsno; ++cnt)
9330 iconf[cnt] = BYTE_GET (econf32[cnt]);
9331
9332 free (econf32);
9333 }
9334 else
9335 {
9336 Elf64_External_Conflict * econf64;
9337
9338 econf64 = ((Elf64_External_Conflict *)
9339 get_data (NULL, file, conflicts_offset,
9340 conflictsno * sizeof (* econf64),
9341 _("conflict")));
9342 if (!econf64)
9343 return 0;
9344
9345 for (cnt = 0; cnt < conflictsno; ++cnt)
9346 iconf[cnt] = BYTE_GET (econf64[cnt]);
9347
9348 free (econf64);
9349 }
9350
9351 printf (_("\nSection '.conflict' contains %ld entries:\n"),
9352 (long) conflictsno);
9353 puts (_(" Num: Index Value Name"));
9354
9355 for (cnt = 0; cnt < conflictsno; ++cnt)
9356 {
9357 Elf_Internal_Sym * psym = & dynamic_symbols [iconf [cnt]];
9358
9359 printf ("%5lu: %8lu ", (unsigned long) cnt, iconf [cnt]);
9360 print_vma (psym->st_value, FULL_HEX);
9361 putchar (' ');
9362 print_symbol (25, dynamic_strings + psym->st_name);
9363 putchar ('\n');
9364 }
9365
9366 free (iconf);
9367 }
9368
9369 return 1;
9370 }
9371
9372 static const char *
9373 get_note_type (e_type)
9374 unsigned e_type;
9375 {
9376 static char buff[64];
9377
9378 switch (e_type)
9379 {
9380 case NT_PRSTATUS: return _("NT_PRSTATUS (prstatus structure)");
9381 case NT_FPREGSET: return _("NT_FPREGSET (floating point registers)");
9382 case NT_PRPSINFO: return _("NT_PRPSINFO (prpsinfo structure)");
9383 case NT_TASKSTRUCT: return _("NT_TASKSTRUCT (task structure)");
9384 case NT_PRXFPREG: return _("NT_PRXFPREG (user_xfpregs structure)");
9385 case NT_PSTATUS: return _("NT_PSTATUS (pstatus structure)");
9386 case NT_FPREGS: return _("NT_FPREGS (floating point registers)");
9387 case NT_PSINFO: return _("NT_PSINFO (psinfo structure)");
9388 case NT_LWPSTATUS: return _("NT_LWPSTATUS (lwpstatus_t structure)");
9389 case NT_LWPSINFO: return _("NT_LWPSINFO (lwpsinfo_t structure)");
9390 case NT_WIN32PSTATUS: return _("NT_WIN32PSTATUS (win32_pstatus structure)");
9391 default:
9392 sprintf (buff, _("Unknown note type: (0x%08x)"), e_type);
9393 return buff;
9394 }
9395 }
9396
9397 static const char *
9398 get_netbsd_elfcore_note_type (e_type)
9399 unsigned e_type;
9400 {
9401 static char buff[64];
9402
9403 if (e_type == NT_NETBSDCORE_PROCINFO)
9404 {
9405 /* NetBSD core "procinfo" structure. */
9406 return _("NetBSD procinfo structure");
9407 }
9408
9409 /* As of Jan 2002 there are no other machine-independent notes
9410 defined for NetBSD core files. If the note type is less
9411 than the start of the machine-dependent note types, we don't
9412 understand it. */
9413
9414 if (e_type < NT_NETBSDCORE_FIRSTMACH)
9415 {
9416 sprintf (buff, _("Unknown note type: (0x%08x)"), e_type);
9417 return buff;
9418 }
9419
9420 switch (elf_header.e_machine)
9421 {
9422 /* On the Alpha, SPARC (32-bit and 64-bit), PT_GETREGS == mach+0
9423 and PT_GETFPREGS == mach+2. */
9424
9425 case EM_OLD_ALPHA:
9426 case EM_ALPHA:
9427 case EM_SPARC:
9428 case EM_SPARC32PLUS:
9429 case EM_SPARCV9:
9430 switch (e_type)
9431 {
9432 case NT_NETBSDCORE_FIRSTMACH+0:
9433 return _("PT_GETREGS (reg structure)");
9434 case NT_NETBSDCORE_FIRSTMACH+2:
9435 return _("PT_GETFPREGS (fpreg structure)");
9436 default:
9437 break;
9438 }
9439 break;
9440
9441 /* On all other arch's, PT_GETREGS == mach+1 and
9442 PT_GETFPREGS == mach+3. */
9443 default:
9444 switch (e_type)
9445 {
9446 case NT_NETBSDCORE_FIRSTMACH+1:
9447 return _("PT_GETREGS (reg structure)");
9448 case NT_NETBSDCORE_FIRSTMACH+3:
9449 return _("PT_GETFPREGS (fpreg structure)");
9450 default:
9451 break;
9452 }
9453 }
9454
9455 sprintf (buff, _("PT_FIRSTMACH+%d"), e_type - NT_NETBSDCORE_FIRSTMACH);
9456 return buff;
9457 }
9458
9459 /* Note that by the ELF standard, the name field is already null byte
9460 terminated, and namesz includes the terminating null byte.
9461 I.E. the value of namesz for the name "FSF" is 4.
9462
9463 If the value of namesz is zero, there is no name present. */
9464 static int
9465 process_note (pnote)
9466 Elf32_Internal_Note * pnote;
9467 {
9468 const char *nt;
9469
9470 if (pnote->namesz == 0)
9471 {
9472 /* If there is no note name, then use the default set of
9473 note type strings. */
9474 nt = get_note_type (pnote->type);
9475 }
9476 else if (strncmp (pnote->namedata, "NetBSD-CORE", 11) == 0)
9477 {
9478 /* NetBSD-specific core file notes. */
9479 nt = get_netbsd_elfcore_note_type (pnote->type);
9480 }
9481 else
9482 {
9483 /* Don't recognize this note name; just use the default set of
9484 note type strings. */
9485 nt = get_note_type (pnote->type);
9486 }
9487
9488 printf (" %s\t\t0x%08lx\t%s\n",
9489 pnote->namesz ? pnote->namedata : "(NONE)",
9490 pnote->descsz, nt);
9491 return 1;
9492 }
9493
9494
9495 static int
9496 process_corefile_note_segment (file, offset, length)
9497 FILE * file;
9498 bfd_vma offset;
9499 bfd_vma length;
9500 {
9501 Elf_External_Note * pnotes;
9502 Elf_External_Note * external;
9503 int res = 1;
9504
9505 if (length <= 0)
9506 return 0;
9507
9508 pnotes = (Elf_External_Note *) get_data (NULL, file, offset, length,
9509 _("notes"));
9510 if (!pnotes)
9511 return 0;
9512
9513 external = pnotes;
9514
9515 printf (_("\nNotes at offset 0x%08lx with length 0x%08lx:\n"),
9516 (unsigned long) offset, (unsigned long) length);
9517 printf (_(" Owner\t\tData size\tDescription\n"));
9518
9519 while (external < (Elf_External_Note *)((char *) pnotes + length))
9520 {
9521 Elf_External_Note * next;
9522 Elf32_Internal_Note inote;
9523 char * temp = NULL;
9524
9525 inote.type = BYTE_GET (external->type);
9526 inote.namesz = BYTE_GET (external->namesz);
9527 inote.namedata = external->name;
9528 inote.descsz = BYTE_GET (external->descsz);
9529 inote.descdata = inote.namedata + align_power (inote.namesz, 2);
9530 inote.descpos = offset + (inote.descdata - (char *) pnotes);
9531
9532 next = (Elf_External_Note *)(inote.descdata + align_power (inote.descsz, 2));
9533
9534 if (((char *) next) > (((char *) pnotes) + length))
9535 {
9536 warn (_("corrupt note found at offset %x into core notes\n"),
9537 ((char *) external) - ((char *) pnotes));
9538 warn (_(" type: %x, namesize: %08lx, descsize: %08lx\n"),
9539 inote.type, inote.namesz, inote.descsz);
9540 break;
9541 }
9542
9543 external = next;
9544
9545 /* Verify that name is null terminated. It appears that at least
9546 one version of Linux (RedHat 6.0) generates corefiles that don't
9547 comply with the ELF spec by failing to include the null byte in
9548 namesz. */
9549 if (inote.namedata[inote.namesz] != '\0')
9550 {
9551 temp = malloc (inote.namesz + 1);
9552
9553 if (temp == NULL)
9554 {
9555 error (_("Out of memory\n"));
9556 res = 0;
9557 break;
9558 }
9559
9560 strncpy (temp, inote.namedata, inote.namesz);
9561 temp[inote.namesz] = 0;
9562
9563 /* warn (_("'%s' NOTE name not properly null terminated\n"), temp); */
9564 inote.namedata = temp;
9565 }
9566
9567 res &= process_note (& inote);
9568
9569 if (temp != NULL)
9570 {
9571 free (temp);
9572 temp = NULL;
9573 }
9574 }
9575
9576 free (pnotes);
9577
9578 return res;
9579 }
9580
9581 static int
9582 process_corefile_note_segments (file)
9583 FILE * file;
9584 {
9585 Elf_Internal_Phdr * program_headers;
9586 Elf_Internal_Phdr * segment;
9587 unsigned int i;
9588 int res = 1;
9589
9590 program_headers = (Elf_Internal_Phdr *) malloc
9591 (elf_header.e_phnum * sizeof (Elf_Internal_Phdr));
9592
9593 if (program_headers == NULL)
9594 {
9595 error (_("Out of memory\n"));
9596 return 0;
9597 }
9598
9599 if (is_32bit_elf)
9600 i = get_32bit_program_headers (file, program_headers);
9601 else
9602 i = get_64bit_program_headers (file, program_headers);
9603
9604 if (i == 0)
9605 {
9606 free (program_headers);
9607 return 0;
9608 }
9609
9610 for (i = 0, segment = program_headers;
9611 i < elf_header.e_phnum;
9612 i ++, segment ++)
9613 {
9614 if (segment->p_type == PT_NOTE)
9615 res &= process_corefile_note_segment (file,
9616 (bfd_vma) segment->p_offset,
9617 (bfd_vma) segment->p_filesz);
9618 }
9619
9620 free (program_headers);
9621
9622 return res;
9623 }
9624
9625 static int
9626 process_corefile_contents (file)
9627 FILE * file;
9628 {
9629 /* If we have not been asked to display the notes then do nothing. */
9630 if (! do_notes)
9631 return 1;
9632
9633 /* If file is not a core file then exit. */
9634 if (elf_header.e_type != ET_CORE)
9635 return 1;
9636
9637 /* No program headers means no NOTE segment. */
9638 if (elf_header.e_phnum == 0)
9639 {
9640 printf (_("No note segments present in the core file.\n"));
9641 return 1;
9642 }
9643
9644 return process_corefile_note_segments (file);
9645 }
9646
9647 static int
9648 process_arch_specific (file)
9649 FILE * file;
9650 {
9651 if (! do_arch)
9652 return 1;
9653
9654 switch (elf_header.e_machine)
9655 {
9656 case EM_MIPS:
9657 case EM_MIPS_RS3_LE:
9658 return process_mips_specific (file);
9659 break;
9660 default:
9661 break;
9662 }
9663 return 1;
9664 }
9665
9666 static int
9667 get_file_header (file)
9668 FILE * file;
9669 {
9670 /* Read in the identity array. */
9671 if (fread (elf_header.e_ident, EI_NIDENT, 1, file) != 1)
9672 return 0;
9673
9674 /* Determine how to read the rest of the header. */
9675 switch (elf_header.e_ident [EI_DATA])
9676 {
9677 default: /* fall through */
9678 case ELFDATANONE: /* fall through */
9679 case ELFDATA2LSB: byte_get = byte_get_little_endian; break;
9680 case ELFDATA2MSB: byte_get = byte_get_big_endian; break;
9681 }
9682
9683 /* For now we only support 32 bit and 64 bit ELF files. */
9684 is_32bit_elf = (elf_header.e_ident [EI_CLASS] != ELFCLASS64);
9685
9686 /* Read in the rest of the header. */
9687 if (is_32bit_elf)
9688 {
9689 Elf32_External_Ehdr ehdr32;
9690
9691 if (fread (ehdr32.e_type, sizeof (ehdr32) - EI_NIDENT, 1, file) != 1)
9692 return 0;
9693
9694 elf_header.e_type = BYTE_GET (ehdr32.e_type);
9695 elf_header.e_machine = BYTE_GET (ehdr32.e_machine);
9696 elf_header.e_version = BYTE_GET (ehdr32.e_version);
9697 elf_header.e_entry = BYTE_GET (ehdr32.e_entry);
9698 elf_header.e_phoff = BYTE_GET (ehdr32.e_phoff);
9699 elf_header.e_shoff = BYTE_GET (ehdr32.e_shoff);
9700 elf_header.e_flags = BYTE_GET (ehdr32.e_flags);
9701 elf_header.e_ehsize = BYTE_GET (ehdr32.e_ehsize);
9702 elf_header.e_phentsize = BYTE_GET (ehdr32.e_phentsize);
9703 elf_header.e_phnum = BYTE_GET (ehdr32.e_phnum);
9704 elf_header.e_shentsize = BYTE_GET (ehdr32.e_shentsize);
9705 elf_header.e_shnum = BYTE_GET (ehdr32.e_shnum);
9706 elf_header.e_shstrndx = BYTE_GET (ehdr32.e_shstrndx);
9707 }
9708 else
9709 {
9710 Elf64_External_Ehdr ehdr64;
9711
9712 /* If we have been compiled with sizeof (bfd_vma) == 4, then
9713 we will not be able to cope with the 64bit data found in
9714 64 ELF files. Detect this now and abort before we start
9715 overwritting things. */
9716 if (sizeof (bfd_vma) < 8)
9717 {
9718 error (_("This instance of readelf has been built without support for a\n\
9719 64 bit data type and so it cannot read 64 bit ELF files.\n"));
9720 return 0;
9721 }
9722
9723 if (fread (ehdr64.e_type, sizeof (ehdr64) - EI_NIDENT, 1, file) != 1)
9724 return 0;
9725
9726 elf_header.e_type = BYTE_GET (ehdr64.e_type);
9727 elf_header.e_machine = BYTE_GET (ehdr64.e_machine);
9728 elf_header.e_version = BYTE_GET (ehdr64.e_version);
9729 elf_header.e_entry = BYTE_GET8 (ehdr64.e_entry);
9730 elf_header.e_phoff = BYTE_GET8 (ehdr64.e_phoff);
9731 elf_header.e_shoff = BYTE_GET8 (ehdr64.e_shoff);
9732 elf_header.e_flags = BYTE_GET (ehdr64.e_flags);
9733 elf_header.e_ehsize = BYTE_GET (ehdr64.e_ehsize);
9734 elf_header.e_phentsize = BYTE_GET (ehdr64.e_phentsize);
9735 elf_header.e_phnum = BYTE_GET (ehdr64.e_phnum);
9736 elf_header.e_shentsize = BYTE_GET (ehdr64.e_shentsize);
9737 elf_header.e_shnum = BYTE_GET (ehdr64.e_shnum);
9738 elf_header.e_shstrndx = BYTE_GET (ehdr64.e_shstrndx);
9739 }
9740
9741 if (elf_header.e_shoff)
9742 {
9743 /* There may be some extensions in the first section header. Don't
9744 bomb if we can't read it. */
9745 if (is_32bit_elf)
9746 get_32bit_section_headers (file, 1);
9747 else
9748 get_64bit_section_headers (file, 1);
9749 }
9750
9751 return 1;
9752 }
9753
9754 static int
9755 process_file (file_name)
9756 char * file_name;
9757 {
9758 FILE * file;
9759 struct stat statbuf;
9760 unsigned int i;
9761
9762 if (stat (file_name, & statbuf) < 0)
9763 {
9764 error (_("Cannot stat input file %s.\n"), file_name);
9765 return 1;
9766 }
9767
9768 file = fopen (file_name, "rb");
9769 if (file == NULL)
9770 {
9771 error (_("Input file %s not found.\n"), file_name);
9772 return 1;
9773 }
9774
9775 if (! get_file_header (file))
9776 {
9777 error (_("%s: Failed to read file header\n"), file_name);
9778 fclose (file);
9779 return 1;
9780 }
9781
9782 /* Initialise per file variables. */
9783 for (i = NUM_ELEM (version_info); i--;)
9784 version_info[i] = 0;
9785
9786 for (i = NUM_ELEM (dynamic_info); i--;)
9787 dynamic_info[i] = 0;
9788
9789 /* Process the file. */
9790 if (show_name)
9791 printf (_("\nFile: %s\n"), file_name);
9792
9793 if (! process_file_header ())
9794 {
9795 fclose (file);
9796 return 1;
9797 }
9798
9799 process_section_headers (file);
9800
9801 process_program_headers (file);
9802
9803 process_dynamic_segment (file);
9804
9805 process_relocs (file);
9806
9807 process_unwind (file);
9808
9809 process_symbol_table (file);
9810
9811 process_syminfo (file);
9812
9813 process_version_sections (file);
9814
9815 process_section_contents (file);
9816
9817 process_corefile_contents (file);
9818
9819 process_arch_specific (file);
9820
9821 fclose (file);
9822
9823 if (section_headers)
9824 {
9825 free (section_headers);
9826 section_headers = NULL;
9827 }
9828
9829 if (string_table)
9830 {
9831 free (string_table);
9832 string_table = NULL;
9833 string_table_length = 0;
9834 }
9835
9836 if (dynamic_strings)
9837 {
9838 free (dynamic_strings);
9839 dynamic_strings = NULL;
9840 }
9841
9842 if (dynamic_symbols)
9843 {
9844 free (dynamic_symbols);
9845 dynamic_symbols = NULL;
9846 num_dynamic_syms = 0;
9847 }
9848
9849 if (dynamic_syminfo)
9850 {
9851 free (dynamic_syminfo);
9852 dynamic_syminfo = NULL;
9853 }
9854
9855 return 0;
9856 }
9857
9858 #ifdef SUPPORT_DISASSEMBLY
9859 /* Needed by the i386 disassembler. For extra credit, someone could
9860 fix this so that we insert symbolic addresses here, esp for GOT/PLT
9861 symbols. */
9862
9863 void
9864 print_address (unsigned int addr, FILE * outfile)
9865 {
9866 fprintf (outfile,"0x%8.8x", addr);
9867 }
9868
9869 /* Needed by the i386 disassembler. */
9870 void
9871 db_task_printsym (unsigned int addr)
9872 {
9873 print_address (addr, stderr);
9874 }
9875 #endif
9876
9877 int main PARAMS ((int, char **));
9878
9879 int
9880 main (argc, argv)
9881 int argc;
9882 char ** argv;
9883 {
9884 int err;
9885
9886 #if defined (HAVE_SETLOCALE) && defined (HAVE_LC_MESSAGES)
9887 setlocale (LC_MESSAGES, "");
9888 #endif
9889 #if defined (HAVE_SETLOCALE)
9890 setlocale (LC_CTYPE, "");
9891 #endif
9892 bindtextdomain (PACKAGE, LOCALEDIR);
9893 textdomain (PACKAGE);
9894
9895 parse_args (argc, argv);
9896
9897 if (optind < (argc - 1))
9898 show_name = 1;
9899
9900 err = 0;
9901 while (optind < argc)
9902 err |= process_file (argv [optind ++]);
9903
9904 if (dump_sects != NULL)
9905 free (dump_sects);
9906
9907 return err;
9908 }
This page took 0.237062 seconds and 4 git commands to generate.