]>
git.ipfire.org Git - thirdparty/binutils-gdb.git/blob - binutils/readelf.c
1 /* readelf.c -- display contents of an ELF format file
2 Copyright (C) 1998 Free Software Foundation, Inc.
4 Originally developed by Eric Youngdale <eric@andante.jic.com>
5 Modifications by Nick Clifton <nickc@cygnus.com>
7 This file is part of GNU Binutils.
9 This program is free software; you can redistribute it and/or modify
10 it under the terms of the GNU General Public License as published by
11 the Free Software Foundation; either version 2 of the License, or
12 (at your option) any later version.
14 This program is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 GNU General Public License for more details.
19 You should have received a copy of the GNU General Public License
20 along with this program; if not, write to the Free Software
21 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
33 #ifdef ANSI_PROTOTYPES
39 unsigned int dynamic_addr
;
40 unsigned int dynamic_size
;
41 char * dynamic_strings
;
42 Elf_Sym
* dynamic_symbols
;
43 char program_interpreter
[64];
44 char * program_name
= "readelf";
45 int dynamic_info
[DT_JMPREL
+ 1];
46 int version_info
[16];
49 unsigned int rela_addr
;
50 unsigned int rela_size
;
52 Elf_Shdr
* section_headers
;
66 long int expected_endian
;
69 #define SECTION_NAME(X) (string_table + (X)->sh_name)
71 #define NUM_DUMP_SECTS 100
72 char dump_sects
[NUM_DUMP_SECTS
];
76 /* Forward declarations for dumb compilers. */
77 static char * get_dynamic_type
PARAMS ((unsigned long));
78 static char * get_i386_rel_type
PARAMS ((bfd_vma rtype
));
79 static char * get_m68k_rel_type
PARAMS ((bfd_vma rtype
));
80 static char * get_sparc_rel_type
PARAMS ((bfd_vma rtype
));
81 static char * get_m32r_rel_type
PARAMS ((bfd_vma rtype
));
82 static char * get_v850_rel_type
PARAMS ((bfd_vma rtype
));
83 static char * get_d10v_rel_type
PARAMS ((bfd_vma rtype
));
84 /* start-sanitize-d30v */
85 static char * get_d30v_rel_type
PARAMS ((bfd_vma rtype
));
86 /* end-sanitize-d30v */
87 static char * get_sh_rel_type
PARAMS ((bfd_vma rtype
));
88 static char * get_mn10300_rel_type
PARAMS ((bfd_vma rtype
));
89 static char * get_mn10200_rel_type
PARAMS ((bfd_vma rtype
));
90 static char * get_ppc_rel_type
PARAMS ((bfd_vma rtype
));
91 static void dump_relocations
92 PARAMS ((FILE *, unsigned long, unsigned long, Elf_Sym
*, char *));
93 static char * get_file_type
PARAMS ((unsigned e_type
));
94 static char * get_machine_name
PARAMS ((unsigned e_machine
));
95 static char * get_machine_data
PARAMS ((unsigned e_data
));
96 static char * get_machine_flags
PARAMS ((unsigned, unsigned e_machine
));
97 static char * get_segment_type
PARAMS ((unsigned long p_type
));
98 static char * get_section_type_name
PARAMS ((unsigned int sh_type
));
99 static char * get_symbol_binding
PARAMS ((unsigned int binding
));
100 static char * get_symbol_type
PARAMS ((unsigned int type
));
101 static void usage
PARAMS ((void));
102 static void parse_args
PARAMS ((int argc
, char ** argv
));
103 static int process_file_header
PARAMS ((void));
104 static void process_program_headers
PARAMS ((FILE *));
105 static void process_section_headers
PARAMS ((FILE *));
106 static void process_dynamic_segment
PARAMS ((FILE *));
107 static void process_symbol_table
PARAMS ((FILE *));
108 static void process_section_contents
PARAMS ((FILE *));
109 static void process_file
PARAMS ((char * file_name
));
110 static void process_relocs
PARAMS ((FILE *));
111 static void process_version_sections
PARAMS ((FILE *));
112 static char * get_ver_flags
PARAMS ((unsigned short flags
));
113 static char * get_symbol_index_type
PARAMS ((unsigned short type
));
115 #define NUM_ELEM(array) (sizeof (array) / sizeof ((array)[0]))
117 #define SWAP2(val) ( (((val) << 8) & (0xff << 8)) \
118 | (((val) >> 8) & (0xff << 0)))
120 #define SWAP4(val) ( (((val) << 24) & (0xff << 24)) \
121 | (((val) << 8) & (0xff << 16)) \
122 | (((val) >> 8) & (0xff << 8)) \
123 | (((val) >> 24) & (0xff << 0)))
125 /* Warning: This macro assumes 8 bits in a char,
126 and at least 16 bits in a short,
127 and at least 32 bits in a long. */
128 #define BYTE_SWAP(structure, field) \
129 if (sizeof ((structure).field) == 2) \
131 unsigned short val = (structure).field; \
132 (structure).field = SWAP2 (val); \
134 else if (sizeof ((structure).field) != 4) \
138 unsigned long val = (structure).field; \
139 (structure).field = SWAP4 (val); \
142 #define GET_DATA_ALLOC(offset, size, var, type, reason) \
143 if (fseek (file, offset, SEEK_SET)) \
145 error (_("Unable to seek to start of %s at %x\n"), reason, offset); \
149 var = (type) malloc (size); \
153 error (_("Out of memory allocating %d bytes for %s\n"), size, reason); \
157 if (fread (var, size, 1, file) != 1) \
159 error (_("Unable to read in %d bytes of %s\n"), size, reason); \
166 #define GET_DATA(offset, var, reason) \
167 if (fseek (file, offset, SEEK_SET)) \
169 error (_("Unable to seek to %x for %s\n"), offset, reason); \
172 else if (fread (& var, sizeof (var), 1, file) != 1) \
174 error (_("Unable to read data at %x for %s\n"), offset, reason); \
178 #ifdef ANSI_PROTOTYPES
180 error (const char * message
, ...)
184 fprintf (stderr
, _("%s: Error: "), program_name
);
185 va_start (args
, message
);
186 vfprintf (stderr
, message
, args
);
192 warn (const char * message
, ...)
196 fprintf (stderr
, _("%s: Warning: "), program_name
);
197 va_start (args
, message
);
198 vfprintf (stderr
, message
, args
);
209 fprintf (stderr
, _("%s: Error: "), program_name
);
211 message
= va_arg (args
, char *);
212 vfprintf (stderr
, message
, args
);
224 fprintf (stderr
, _("%s: Warning: "), program_name
);
226 message
= va_arg (args
, char *);
227 vfprintf (stderr
, message
, args
);
235 get_i386_rel_type (rtype
)
240 case 0: return "R_386_NONE";
241 case 1: return "R_386_32";
242 case 2: return "R_386_PC32";
243 case 3: return "R_386_GOT32";
244 case 4: return "R_386_PLT32";
245 case 5: return "R_386_COPY";
246 case 6: return "R_386_GLOB_DAT";
247 case 7: return "R_386_JMP_SLOT";
248 case 8: return "R_386_RELATIVE";
249 case 9: return "R_386_GOTOFF";
250 case 10: return "R_386_GOTPC";
251 case 20: return "R_386_16";
252 case 21: return "R_386_PC16";
253 case 22: return "R_386_PC8";
254 case 23: return "R_386_max";
255 default: return _("*INVALID*");
260 get_m68k_rel_type (rtype
)
265 case 0: return "R_68K_NONE";
266 case 1: return "R_68K_32";
267 case 2: return "R_68K_16";
268 case 3: return "R_68K_8";
269 case 4: return "R_68K_PC32";
270 case 5: return "R_68K_PC16";
271 case 6: return "R_68K_PC8";
272 case 7: return "R_68K_GOT32";
273 case 8: return "R_68K_GOT16";
274 case 9: return "R_68K_GOT8";
275 case 10: return "R_68K_GOT32O";
276 case 11: return "R_68K_GOT16O";
277 case 12: return "R_68K_GOT8O";
278 case 13: return "R_68K_PLT32";
279 case 14: return "R_68K_PLT16";
280 case 15: return "R_68K_PLT8";
281 case 16: return "R_68K_PLT32O";
282 case 17: return "R_68K_PLT16O";
283 case 18: return "R_68K_PLT8O";
284 case 19: return "R_68K_COPY";
285 case 20: return "R_68K_GLOB_DAT";
286 case 21: return "R_68K_JMP_SLOT";
287 case 22: return "R_68K_RELATIVE";
288 default: return _("*INVALID*");
294 get_sparc_rel_type (rtype
)
299 case 0: return "R_SPARC_NONE";
300 case 1: return "R_SPARC_8";
301 case 2: return "R_SPARC_16";
302 case 3: return "R_SPARC_32";
303 case 4: return "R_SPARC_DISP8";
304 case 5: return "R_SPARC_DISP16";
305 case 6: return "R_SPARC_DISP32";
306 case 7: return "R_SPARC_WDISP30";
307 case 8: return "R_SPARC_WDISP22";
308 case 9: return "R_SPARC_HI22";
309 case 10: return "R_SPARC_22";
310 case 11: return "R_SPARC_13";
311 case 12: return "R_SPARC_LO10";
312 case 13: return "R_SPARC_GOT10";
313 case 14: return "R_SPARC_GOT13";
314 case 15: return "R_SPARC_GOT22";
315 case 16: return "R_SPARC_PC10";
316 case 17: return "R_SPARC_PC22";
317 case 18: return "R_SPARC_WPLT30";
318 case 19: return "R_SPARC_COPY";
319 case 20: return "R_SPARC_GLOB_DAT";
320 case 21: return "R_SPARC_JMP_SLOT";
321 case 22: return "R_SPARC_RELATIVE";
322 case 23: return "R_SPARC_UA32";
323 case 24: return "R_SPARC_10";
324 case 25: return "R_SPARC_11";
325 case 26: return "R_SPARC_64";
326 case 27: return "R_SPARC_OLO10";
327 case 28: return "R_SPARC_HH22";
328 case 29: return "R_SPARC_HM10";
329 case 30: return "R_SPARC_LM22";
330 case 31: return "R_SPARC_PC_HH22";
331 case 32: return "R_SPARC_PC_HM10";
332 case 33: return "R_SPARC_PC_LM22";
333 case 34: return "R_SPARC_WDISP16";
334 case 35: return "R_SPARC_WDISP19";
335 case 36: return "R_SPARC_UNUSED_42";
336 case 37: return "R_SPARC_7";
337 case 38: return "R_SPARC_5";
338 case 39: return "R_SPARC_6";
339 case 40: return "R_SPARC_DISP64";
340 case 41: return "R_SPARC_PLT64";
341 case 42: return "R_SPARC_HIX22";
342 case 43: return "R_SPARC_LOX10";
343 case 44: return "R_SPARC_H44";
344 case 45: return "R_SPARC_M44";
345 case 46: return "R_SPARC_L44";
346 case 47: return "R_SPARC_REGISTER";
347 case 48: return "R_SPARC_UA64";
348 case 49: return "R_SPARC_UA16";
349 case 50: return "R_SPARC_32LE";
350 default: return _("*INVALID*");
356 get_m32r_rel_type (rtype
)
361 case 0: return "R_M32R_NONE";
362 case 1: return "R_M32R_16";
363 case 2: return "R_M32R_32";
364 case 3: return "R_M32R_24";
365 case 4: return "R_M32R_10_PCREL";
366 case 5: return "R_M32R_18_PCREL";
367 case 6: return "R_M32R_26_PCREL";
368 case 7: return "R_M32R_HI16_ULO";
369 case 8: return "R_M32R_HI16_SLO";
370 case 9: return "R_M32R_LO16";
371 case 10: return "R_M32R_SDA16";
372 default: return _("*INVALID*");
378 get_v850_rel_type (rtype
)
383 case 0: return "R_V850_NONE";
384 case 1: return "R_V850_9_PCREL";
385 case 2: return "R_V850_22_PCREL";
386 case 3: return "R_V850_HI16_S";
387 case 4: return "R_V850_HI16";
388 case 5: return "R_V850_LO16";
389 case 6: return "R_V850_32";
390 case 7: return "R_V850_16";
391 case 8: return "R_V850_8";
392 case 9: return "R_V850_SDA_16_16_OFFSET";
393 case 10: return "R_V850_SDA_15_16_OFFSET";
394 case 11: return "R_V850_ZDA_16_16_OFFSET";
395 case 12: return "R_V850_ZDA_15_16_OFFSET";
396 case 13: return "R_V850_TDA_6_8_OFFSET";
397 case 14: return "R_V850_TDA_7_8_OFFSET";
398 case 15: return "R_V850_TDA_7_7_OFFSET";
399 case 16: return "R_V850_TDA_16_16_OFFSET";
400 /* start-sanitize-v850e */
401 case 17: return "R_V850_TDA_4_5_OFFSET";
402 case 18: return "R_V850_TDA_4_4_OFFSET";
403 case 19: return "R_V850_SDA_16_16_SPLIT_OFFSET";
404 case 20: return "R_V850_ZDA_16_16_SPLIT_OFFSET";
405 case 21: return "R_V850_CALLT_6_7_OFFSET";
406 case 22: return "R_V850_CALLT_16_16_OFFSET";
407 /* end-sanitize-v850e */
408 default: return _("*INVALID*");
414 get_d10v_rel_type (rtype
)
419 case 0: return "R_D10V_NONE";
420 case 1: return "R_D10V_10_PCREL_R";
421 case 2: return "R_D10V_10_PCREL_L";
422 case 3: return "R_D10V_16";
423 case 4: return "R_D10V_18";
424 case 5: return "R_D10V_18_PCREL";
425 case 6: return "R_D10V_32";
426 default: return _("*INVALID*");
430 /* start-sanitize-d30v */
432 get_d30v_rel_type (rtype
)
437 case 0: return "R_D30V_NONE";
438 case 1: return "R_D30V_6";
439 case 2: return "R_D30V_9_PCREL";
440 case 3: return "R_D30V_9_PCREL_R";
441 case 4: return "R_D30V_15";
442 case 5: return "R_D30V_15_PCREL";
443 case 6: return "R_D30V_15_PCREL_R";
444 case 7: return "R_D30V_21";
445 case 8: return "R_D30V_21_PCREL";
446 case 9: return "R_D30V_21_PCREL_R";
447 case 10: return "R_D30V_32";
448 case 11: return "R_D30V_32_PCREL";
449 case 12: return "R_D30V_32_NORMAL";
450 default: return _("*INVALID*");
454 /* end-sanitize-d30v */
456 get_sh_rel_type (rtype
)
461 case 0: return "R_SH_NONE";
462 case 1: return "R_SH_DIR32";
463 case 2: return "R_SH_REL32";
464 case 3: return "R_SH_DIR8WPN";
465 case 4: return "R_SH_IND12W";
466 case 5: return "R_SH_DIR8WPL";
467 case 6: return "R_SH_DIR8WPZ";
468 case 7: return "R_SH_DIR8BP";
469 case 8: return "R_SH_DIR8W";
470 case 9: return "R_SH_DIR8L";
471 case 25: return "R_SH_SWITCH16";
472 case 26: return "R_SH_SWITCH32";
473 case 27: return "R_SH_USES";
474 case 28: return "R_SH_COUNT";
475 case 29: return "R_SH_ALIGN";
476 case 30: return "R_SH_CODE";
477 case 31: return "R_SH_DATA";
478 case 32: return "R_SH_LABEL";
479 default: return _("*INVALID*");
485 get_mn10300_rel_type (rtype
)
490 case 0: return "R_MN10300_NONE";
491 case 1: return "R_MN10300_32";
492 case 2: return "R_MN10300_16";
493 case 3: return "R_MN10300_8";
494 case 4: return "R_MN10300_PCREL32";
495 case 5: return "R_MN10300_PCREL16";
496 case 6: return "R_MN10300_PCREL8";
497 default: return _("*INVALID*");
503 get_mn10200_rel_type (rtype
)
508 case 0: return "R_MN10200_NONE";
509 case 1: return "R_MN10200_32";
510 case 2: return "R_MN10200_16";
511 case 3: return "R_MN10200_8";
512 case 4: return "R_MN10200_24";
513 case 5: return "R_MN10200_PCREL8";
514 case 6: return "R_MN10200_PCREL16";
515 case 7: return "R_MN10200_PCREL24";
516 default: return _("*INVALID*");
522 get_ppc_rel_type (rtype
)
527 case 0: return "R_PPC_NONE,";
528 case 1: return "R_PPC_ADDR32,";
529 case 2: return "R_PPC_ADDR24,";
530 case 3: return "R_PPC_ADDR16,";
531 case 4: return "R_PPC_ADDR16_LO,";
532 case 5: return "R_PPC_ADDR16_HI,";
533 case 6: return "R_PPC_ADDR16_HA,";
534 case 7: return "R_PPC_ADDR14,";
535 case 8: return "R_PPC_ADDR14_BRTAKEN,";
536 case 9: return "R_PPC_ADDR14_BRNTAKEN,";
537 case 10: return "R_PPC_REL24,";
538 case 11: return "R_PPC_REL14,";
539 case 12: return "R_PPC_REL14_BRTAKEN,";
540 case 13: return "R_PPC_REL14_BRNTAKEN,";
541 case 14: return "R_PPC_GOT16,";
542 case 15: return "R_PPC_GOT16_LO,";
543 case 16: return "R_PPC_GOT16_HI,";
544 case 17: return "R_PPC_GOT16_HA,";
545 case 18: return "R_PPC_PLT24,";
546 case 19: return "R_PPC_COPY,";
547 case 21: return "R_PPC_JMP_SLOT,";
548 case 22: return "R_PPC_RELATIVE,";
549 case 23: return "R_PPC_LOCAL24PC,";
550 case 24: return "R_PPC_UADDR32,";
551 case 25: return "R_PPC_UADDR16,";
552 case 26: return "R_PPC_REL32,";
553 case 27: return "R_PPC_PLT32,";
554 case 28: return "R_PPC_PLTREL32,";
555 case 29: return "R_PPC_PLT16_LO,";
556 case 30: return "R_PPC_PLT16_HI,";
557 case 31: return "R_PPC_PLT16_HA,";
558 case 32: return "R_PPC_SDAREL,";
559 case 33: return "R_PPC_SECTOFF,";
560 case 34: return "R_PPC_SECTOFF_LO,";
561 case 35: return "R_PPC_SECTOFF_HI,";
562 case 36: return "R_PPC_SECTOFF_HA,";
563 case 101: return "R_PPC_EMB_NADDR32,";
564 case 102: return "R_PPC_EMB_NADDR16,";
565 case 103: return "R_PPC_EMB_NADDR16_LO,";
566 case 104: return "R_PPC_EMB_NADDR16_HI,";
567 case 105: return "R_PPC_EMB_NADDR16_HA,";
568 case 106: return "R_PPC_EMB_SDAI16,";
569 case 107: return "R_PPC_EMB_SDA2I16,";
570 case 108: return "R_PPC_EMB_SDA2REL,";
571 case 109: return "R_PPC_EMB_SDA21,";
572 case 110: return "R_PPC_EMB_MRKREF,";
573 case 111: return "R_PPC_EMB_RELSEC16,";
574 case 112: return "R_PPC_EMB_RELST_LO,";
575 case 113: return "R_PPC_EMB_RELST_HI,";
576 case 114: return "R_PPC_EMB_RELST_HA,";
577 case 115: return "R_PPC_EMB_BIT_FLD,";
578 case 116: return "R_PPC_EMB_RELSDA,";
579 default: return _("*INVALID*");
584 /* Display the contents of the relocation data
585 found at the specified offset. */
587 dump_relocations (file
, rel_offset
, rel_size
, symtab
, strtab
)
589 unsigned long rel_offset
;
590 unsigned long rel_size
;
600 /* Compute number of relocations and read them in. */
601 switch (elf_header
.e_machine
)
607 GET_DATA_ALLOC (rel_offset
, rel_size
, rels
, Elf_Rel
*, "relocs");
609 rel_size
= rel_size
/ sizeof (Elf_Rel
);
613 for (i
= 0; i
< rel_size
; i
++)
615 BYTE_SWAP (rels
[i
], r_offset
);
616 BYTE_SWAP (rels
[i
], r_info
);
621 relas
= (Elf_Rela
*) rels
;
628 /* start-sanitize-d30v */
630 /* end-sanitize-d30v */
631 case EM_CYGNUS_MN10200
:
632 case EM_CYGNUS_MN10300
:
634 GET_DATA_ALLOC (rel_offset
, rel_size
, relas
, Elf_Rela
*, "relocs");
636 rel_size
= rel_size
/ sizeof (Elf_Rela
);
640 for (i
= 0; i
< rel_size
; i
++)
642 BYTE_SWAP (relas
[i
], r_offset
);
643 BYTE_SWAP (relas
[i
], r_info
);
644 BYTE_SWAP (relas
[i
], r_addend
);
649 rels
= (Elf_Rel
*) relas
;
653 warn (_("Don't know about relocations on this machine architecture\n"));
659 (_(" Offset Value Type Symbol's Value Symbol's Name Addend\n"));
662 (_(" Offset Value Type Symbol's Value Symbol's Name\n"));
664 for (i
= 0; i
< rel_size
; i
++)
673 offset
= relas
[i
].r_offset
;
674 info
= relas
[i
].r_info
;
678 offset
= rels
[i
].r_offset
;
679 info
= rels
[i
].r_info
;
682 printf (" %8.8lx %5.5lx ", offset
, info
);
684 switch (elf_header
.e_machine
)
691 rtype
= get_m32r_rel_type (ELF32_R_TYPE (info
));
696 rtype
= get_i386_rel_type (ELF32_R_TYPE (info
));
700 rtype
= get_m68k_rel_type (ELF32_R_TYPE (info
));
704 rtype
= get_sparc_rel_type (ELF32_R_TYPE (info
));
708 rtype
= get_v850_rel_type (ELF32_R_TYPE (info
));
712 rtype
= get_d10v_rel_type (ELF32_R_TYPE (info
));
715 /* start-sanitize-d30v */
717 rtype
= get_d30v_rel_type (ELF32_R_TYPE (info
));
720 /* end-sanitize-d30v */
722 rtype
= get_sh_rel_type (ELF32_R_TYPE (info
));
725 case EM_CYGNUS_MN10300
:
726 rtype
= get_mn10300_rel_type (ELF32_R_TYPE (info
));
729 case EM_CYGNUS_MN10200
:
730 rtype
= get_mn10200_rel_type (ELF32_R_TYPE (info
));
734 rtype
= get_ppc_rel_type (ELF32_R_TYPE (info
));
738 printf ("%-21.21s", rtype
);
740 symtab_index
= ELF32_R_SYM (info
);
742 if (symtab_index
&& symtab
!= NULL
)
746 psym
= symtab
+ symtab_index
;
748 printf (" %08lx ", psym
->st_value
);
750 if (psym
->st_name
== 0)
752 SECTION_NAME (section_headers
+ psym
->st_shndx
));
753 else if (strtab
== NULL
)
754 printf (_("<string table index %d>"), psym
->st_name
);
756 printf ("%-17.17s", strtab
+ psym
->st_name
);
759 printf (" + %lx", relas
[i
].r_addend
);
769 get_dynamic_type (type
)
772 static char buff
[32];
776 case DT_NULL
: return _("NULL");
777 case DT_NEEDED
: return _("NEEDED");
778 case DT_PLTRELSZ
: return _("PLTRELSZ");
779 case DT_PLTGOT
: return _("PLTGOT");
780 case DT_HASH
: return _("HASH");
781 case DT_STRTAB
: return _("STRTAB");
782 case DT_SYMTAB
: return _("SYMTAB");
783 case DT_RELA
: return _("RELA");
784 case DT_RELASZ
: return _("RELASZ");
785 case DT_RELAENT
: return _("RELAENT");
786 case DT_STRSZ
: return _("STRSZ");
787 case DT_SYMENT
: return _("SYMENT");
788 case DT_INIT
: return _("INIT");
789 case DT_FINI
: return _("FINI");
790 case DT_SONAME
: return _("SONAME");
791 case DT_RPATH
: return _("RPATH");
792 case DT_SYMBOLIC
: return _("SYMBOLIC");
793 case DT_REL
: return _("REL");
794 case DT_RELSZ
: return _("RELSZ");
795 case DT_RELENT
: return _("RELENT");
796 case DT_PLTREL
: return _("PLTREL");
797 case DT_DEBUG
: return _("DEBUG");
798 case DT_TEXTREL
: return _("TEXTREL");
799 case DT_JMPREL
: return _("JMPREL");
800 case DT_VERDEF
: return _("VERDEF");
801 case DT_VERDEFNUM
: return _("VERDEFNUM");
802 case DT_VERNEED
: return _("VERNEED");
803 case DT_VERNEEDNUM
: return _("VERNEEDNUM");
804 case DT_VERSYM
: return _("VERSYN");
805 case DT_AUXILIARY
: return _("AUXILARY");
806 case DT_FILTER
: return _("FILTER");
809 if ((type
>= DT_LOPROC
) && (type
<= DT_HIPROC
))
810 sprintf (buff
, _("Processor Specific: (%x)"), type
);
812 sprintf (buff
, _("<unknown>: %x"), type
);
818 get_file_type (e_type
)
821 static char buff
[32];
825 case ET_NONE
: return _("None");
826 case ET_REL
: return _("Relocatable file");
827 case ET_EXEC
: return _("Executable file");
828 case ET_DYN
: return _("Shared object file");
829 case ET_CORE
: return _("Core file");
832 if ((e_type
>= ET_LOPROC
) && (e_type
<= ET_HIPROC
))
833 sprintf (buff
, _("Processor Specific: (%x)"), e_type
);
835 sprintf (buff
, _("<unknown>: %x"), e_type
);
841 get_machine_name (e_machine
)
844 static char buff
[32];
848 case EM_NONE
: return _("None");
849 case EM_M32
: return "WE32100";
850 case EM_SPARC
: return "Sparc";
851 case EM_386
: return "80386";
852 case EM_68K
: return "MC68000";
853 case EM_88K
: return "MC88000";
854 case EM_486
: return "Intel 80486";
855 case EM_860
: return "Intel 80860";
856 case EM_MIPS
: return "MIPS R3000 big-endian";
857 case EM_S370
: return "Amdahl";
858 case EM_MIPS_RS4_BE
: return "MIPS R400 big-endian";
859 case EM_OLD_SPARCV9
: return "Sparc v9 (old)";
860 case EM_PARISC
: return "HPPA";
861 case EM_PPC_OLD
: return "Power PC (old)";
862 case EM_SPARC32PLUS
: return "Sparc v8+" ;
863 case EM_960
: return "Intel 90860";
864 case EM_PPC
: return "PowerPC";
865 case EM_V800
: return "NEC V800";
866 case EM_FR20
: return "Fujitsu FR20";
867 case EM_RH32
: return "TRW RH32";
868 case EM_MMA
: return "Fujitsu MMA";
869 case EM_ARM
: return "ARM";
870 case EM_OLD_ALPHA
: return "Digital Alpha (old)";
871 case EM_SH
: return "Hitachi SH";
872 case EM_SPARCV9
: return "Sparc v9";
873 case EM_ALPHA
: return "Alpha";
874 case EM_CYGNUS_D10V
: return "d10v";
875 /* start-sanitize-d30v */
876 case EM_CYGNUS_D30V
: return "d30v";
877 /* end-sanitize-d30v */
878 case EM_CYGNUS_M32R
: return "M32r";
879 case EM_CYGNUS_V850
: return "v850";
880 case EM_CYGNUS_MN10300
: return "mn10300";
881 case EM_CYGNUS_MN10200
: return "mn10200";
884 sprintf (buff
, _("<unknown>: %x"), e_machine
);
890 get_machine_flags (e_flags
, e_machine
)
894 static char buf
[1024];
905 if (e_flags
& EF_PPC_EMB
)
906 strcat (buf
, ", emb");
908 if (e_flags
& EF_PPC_RELOCATABLE
)
909 strcat (buf
, ", relocatable");
911 if (e_flags
& EF_PPC_RELOCATABLE_LIB
)
912 strcat (buf
, ", relocatable-lib");
916 if ((e_flags
& EF_M32R_ARCH
) == E_M32R_ARCH
)
917 strcat (buf
, ", m32r");
919 /* start-sanitize-m32rx */
921 if ((e_flags
& EF_M32R_ARCH
) == E_M32RX_ARCH
)
922 strcat (buf
, ", m32rx");
924 /* end-sanitize-m32rx */
929 if (e_flags
& EF_MIPS_NOREORDER
)
930 strcat (buf
, ", noreorder");
932 if (e_flags
& EF_MIPS_PIC
)
933 strcat (buf
, ", pic");
935 if (e_flags
& EF_MIPS_CPIC
)
936 strcat (buf
, ", cpic");
938 if (e_flags
& EF_MIPS_ABI2
)
939 strcat (buf
, ", abi2");
941 if ((e_flags
& EF_MIPS_ARCH
) == E_MIPS_ARCH_1
)
942 strcat (buf
, ", mips1");
944 if ((e_flags
& EF_MIPS_ARCH
) == E_MIPS_ARCH_2
)
945 strcat (buf
, ", mips2");
947 if ((e_flags
& EF_MIPS_ARCH
) == E_MIPS_ARCH_3
)
948 strcat (buf
, ", mips3");
950 if ((e_flags
& EF_MIPS_ARCH
) == E_MIPS_ARCH_4
)
951 strcat (buf
, ", mips4");
960 get_machine_data (e_data
)
963 static char buff
[32];
967 case ELFDATA2LSB
: return _("ELFDATA2LSB (little endian)");
968 case ELFDATA2MSB
: return _("ELFDATA2MSB (big endian)");
970 sprintf (buff
, _("<unknown>: %x"), e_data
);
976 get_segment_type (p_type
)
977 unsigned long p_type
;
979 static char buff
[32];
983 case PT_NULL
: return _("Unused");
984 case PT_LOAD
: return _("Loadable");
985 case PT_DYNAMIC
: return _("Dynamic link info");
986 case PT_INTERP
: return _("Interpreter");
987 case PT_NOTE
: return _("Auxillary Info");
988 case PT_SHLIB
: return _("Shared Library");
989 case PT_PHDR
: return _("Program Header");
992 if ((p_type
>= PT_LOPROC
) && (p_type
<= PT_HIPROC
))
993 return _("processor specific");
996 sprintf (buff
, _("<unknown>: %x"), p_type
);
1003 get_section_type_name (sh_type
)
1004 unsigned int sh_type
;
1006 static char buff
[32];
1010 case SHT_NULL
: return _("Unused");
1011 case SHT_PROGBITS
: return _("Program data");
1012 case SHT_SYMTAB
: return _("Symbol table");
1013 case SHT_STRTAB
: return _("String table");
1014 case SHT_RELA
: return _("Relocations");
1015 case SHT_HASH
: return _("Symbol hashes");
1016 case SHT_DYNAMIC
: return _("Dynamic info");
1017 case SHT_NOTE
: return _("Notes");
1018 case SHT_NOBITS
: return _("Space, no data");
1019 case SHT_REL
: return _("Relocations");
1020 case SHT_SHLIB
: return _("Shared lib info");
1021 case SHT_DYNSYM
: return _("Dynamic symbols");
1022 case SHT_GNU_verdef
: return _("Version definition");
1023 case SHT_GNU_verneed
: return _("Version needs");
1024 case SHT_GNU_versym
: return _("Version symbols");
1025 case 0x6ffffff0: return "VERSYM";
1026 case 0x6ffffffc: return "VERDEF";
1027 case 0x7ffffffd: return "AUXILIARY";
1028 case 0x7fffffff: return "FILTER";
1031 if ((sh_type
>= SHT_LOPROC
) && (sh_type
<= SHT_HIPROC
))
1032 sprintf (buff
, _("cpu defined (%d)"), sh_type
- SHT_LOPROC
);
1033 else if ((sh_type
>= SHT_LOUSER
) && (sh_type
<= SHT_HIUSER
))
1034 sprintf (buff
, _("app defined (%d)"), sh_type
- SHT_LOUSER
);
1036 sprintf (buff
, _("<unknown>: %x"), sh_type
);
1041 struct option options
[] =
1043 {"all", no_argument
, 0, 'a'},
1044 {"file-header", no_argument
, 0, 'h'},
1045 {"program-headers", no_argument
, 0, 'l'},
1046 {"headers", no_argument
, 0, 'e'},
1047 {"segments", no_argument
, 0, 'l'},
1048 {"sections", no_argument
, 0, 'S'},
1049 {"section-headers", no_argument
, 0, 'S'},
1050 {"symbols", no_argument
, 0, 's'},
1051 {"relocs", no_argument
, 0, 'r'},
1052 {"dynamic", no_argument
, 0, 'd'},
1053 {"version-info", no_argument
, 0, 'V'},
1054 {"use-dynamic", no_argument
, 0, 'D'},
1056 {"hex-dump", required_argument
, 0, 'x'},
1057 #ifdef SUPPORT_DISASSEMBLY
1058 {"instruction-dump", required_argument
, 0, 'i'},
1061 {"version", no_argument
, 0, 'v'},
1062 {"help", no_argument
, 0, 'H'},
1064 {0, no_argument
, 0, 0}
1070 fprintf (stdout
, _("Usage: readelf {options} elf-file(s)\n"));
1071 fprintf (stdout
, _(" Options are:\n"));
1072 fprintf (stdout
, _(" -a or --all Equivalent to: -h -l -S -s -r -d -V\n"));
1073 fprintf (stdout
, _(" -h or --file-header Display the ELF file header\n"));
1074 fprintf (stdout
, _(" -l or --program-headers or --segments\n"));
1075 fprintf (stdout
, _(" Display the program headers\n"));
1076 fprintf (stdout
, _(" -S or --section-headers or --sections\n"));
1077 fprintf (stdout
, _(" Display the sections' header\n"));
1078 fprintf (stdout
, _(" -e or --headers Equivalent to: -h -l -S\n"));
1079 fprintf (stdout
, _(" -s or --symbols Display the symbol table\n"));
1080 fprintf (stdout
, _(" -r or --relocs Display the relocations (if present)\n"));
1081 fprintf (stdout
, _(" -d or --dynamic Display the dynamic segment (if present)\n"));
1082 fprintf (stdout
, _(" -V or --version-info Display the version sections (if present)\n"));
1083 fprintf (stdout
, _(" -D or --use-dynamic Use the dynamic section info when displaying symbols\n"));
1084 fprintf (stdout
, _(" -x <number> or --hex-dump=<number>\n"));
1085 fprintf (stdout
, _(" Dump the contents of section <number>\n"));
1086 #ifdef SUPPORT_DISASSEMBLY
1087 fprintf (stdout
, _(" -i <number> or --instruction-dump=<number>\n"));
1088 fprintf (stdout
, _(" Disassemble the contents of section <number>\n"));
1090 fprintf (stdout
, _(" -v or --version Display the version number of readelf\n"));
1091 fprintf (stdout
, _(" -H or --help Display this information\n"));
1092 fprintf (stdout
, _("Report bugs to bug-gnu-utils@gnu.org\n"));
1098 parse_args (argc
, argv
)
1107 while ((c
= getopt_long
1108 (argc
, argv
, "ersahldSDx:i:vV", options
, NULL
)) != EOF
)
1134 do_using_dynamic
++;
1156 section
= strtoul (optarg
, & cp
, 0);
1157 if (! * cp
&& section
>= 0 && section
< NUM_DUMP_SECTS
)
1159 dump_sects
[section
] |= HEX_DUMP
;
1163 #ifdef SUPPORT_DISASSEMBLY
1166 section
= strtoul (optarg
, & cp
, 0);
1167 if (! * cp
&& section
>= 0 && section
< NUM_DUMP_SECTS
)
1169 dump_sects
[section
] |= DISASS_DUMP
;
1175 print_version (program_name
);
1182 /* xgettext:c-format */
1183 error (_("Invalid option '-%c'\n"), c
);
1190 if (!do_dynamic
&& !do_syms
&& !do_reloc
&& !do_sections
1191 && !do_segments
&& !do_header
&& !do_dump
&& !do_version
)
1195 warn (_("Nothing to do.\n"));
1200 /* Decode the data held in 'elf_header'. */
1202 process_file_header ()
1204 if ( elf_header
.e_ident
[EI_MAG0
] != ELFMAG0
1205 || elf_header
.e_ident
[EI_MAG1
] != ELFMAG1
1206 || elf_header
.e_ident
[EI_MAG2
] != ELFMAG2
1207 || elf_header
.e_ident
[EI_MAG3
] != ELFMAG3
)
1210 (_("Not an ELF file - it has the wrong magic bytes at the start\n"));
1214 if (elf_header
.e_ident
[EI_CLASS
] != ELFCLASS32
)
1216 error (_("Not a 32 bit ELF file\n"));
1220 if (elf_header
.e_ident
[EI_DATA
] != expected_endian
)
1224 BYTE_SWAP (elf_header
, e_type
);
1225 BYTE_SWAP (elf_header
, e_machine
);
1226 BYTE_SWAP (elf_header
, e_version
);
1227 BYTE_SWAP (elf_header
, e_entry
);
1228 BYTE_SWAP (elf_header
, e_phoff
);
1229 BYTE_SWAP (elf_header
, e_shoff
);
1230 BYTE_SWAP (elf_header
, e_flags
);
1231 BYTE_SWAP (elf_header
, e_ehsize
);
1232 BYTE_SWAP (elf_header
, e_phentsize
);
1233 BYTE_SWAP (elf_header
, e_phnum
);
1234 BYTE_SWAP (elf_header
, e_shentsize
);
1235 BYTE_SWAP (elf_header
, e_shnum
);
1236 BYTE_SWAP (elf_header
, e_shstrndx
);
1243 printf (_("ELF Header:\n"));
1244 printf (_(" Magic: "));
1245 for (i
= 0; i
< EI_NIDENT
; i
++)
1246 printf ("%2.2x ", elf_header
.e_ident
[i
]);
1248 printf (_(" Type: %s\n"),
1249 get_file_type (elf_header
.e_type
));
1250 printf (_(" Machine: %s\n"),
1251 get_machine_name (elf_header
.e_machine
));
1252 printf (_(" Version: 0x%lx\n"),
1253 (unsigned long) elf_header
.e_version
);
1255 printf (_(" Data: %s"),
1256 get_machine_data (elf_header
.e_ident
[EI_DATA
]));
1258 printf (_(" [byte swapping]"));
1261 printf (_(" Entry point address: 0x%lx\n"),
1262 (unsigned long) elf_header
.e_entry
);
1263 printf (_(" Start of program headers: %ld (bytes into file)\n"),
1264 (long) elf_header
.e_phoff
);
1265 printf (_(" Start of section headers: %ld (bytes into file)\n"),
1266 (long) elf_header
.e_shoff
);
1267 printf (_(" Flags: 0x%lx%s\n"),
1268 (unsigned long) elf_header
.e_flags
,
1269 get_machine_flags (elf_header
.e_flags
, elf_header
.e_machine
));
1270 printf (_(" Size of this header: %ld (bytes)\n"),
1271 (long) elf_header
.e_ehsize
);
1272 printf (_(" Size of program headers: %ld (bytes)\n"),
1273 (long) elf_header
.e_phentsize
);
1274 printf (_(" Number of program headers: %ld\n"),
1275 (long) elf_header
.e_phnum
);
1276 printf (_(" Size of section headers: %ld (bytes)\n"),
1277 (long) elf_header
.e_shentsize
);
1278 printf (_(" Number of section headers: %ld\n"),
1279 (long) elf_header
.e_shnum
);
1280 printf (_(" Section header string table index: %ld\n"),
1281 (long) elf_header
.e_shstrndx
);
1289 process_program_headers (file
)
1292 Elf_Phdr
* program_headers
;
1296 if (elf_header
.e_phnum
== 0)
1299 printf (_("\nThere are no program headers in this file.\n"));
1303 if (do_segments
&& !do_header
)
1305 printf (_("\nElf file is %s\n"), get_file_type (elf_header
.e_type
));
1306 printf (_("Entry point 0x%x\n"), elf_header
.e_entry
);
1307 printf (_("There are %d program headers, starting at offset %x:\n"),
1308 elf_header
.e_phnum
, elf_header
.e_phoff
);
1311 GET_DATA_ALLOC (elf_header
.e_phoff
, elf_header
.e_phentsize
* elf_header
.e_phnum
,
1312 program_headers
, Elf_Phdr
*, "program headers");
1316 for (i
= 0; i
< elf_header
.e_phnum
; i
++)
1318 BYTE_SWAP (program_headers
[i
], p_type
);
1319 BYTE_SWAP (program_headers
[i
], p_flags
);
1320 BYTE_SWAP (program_headers
[i
], p_offset
);
1321 BYTE_SWAP (program_headers
[i
], p_vaddr
);
1322 BYTE_SWAP (program_headers
[i
], p_paddr
);
1323 BYTE_SWAP (program_headers
[i
], p_filesz
);
1324 BYTE_SWAP (program_headers
[i
], p_memsz
);
1325 BYTE_SWAP (program_headers
[i
], p_align
);
1332 (_("\nProgram Header%s:\n"), elf_header
.e_phnum
> 1 ? "s" : "");
1334 (_(" Type Offset VirtAddr PhysAddr FileSiz MemSiz Flg Align\n"));
1340 for (i
= 0; i
< elf_header
.e_phnum
; i
++)
1342 segment
= program_headers
+ i
;
1346 printf (" %-16.16s ", get_segment_type (segment
->p_type
));
1347 printf ("0x%5.5lx ", segment
->p_offset
);
1348 printf ("0x%8.8lx ", segment
->p_vaddr
);
1349 printf ("0x%8.8lx ", segment
->p_paddr
);
1350 printf ("0x%5.5lx 0x%5.5lx ", segment
->p_filesz
, segment
->p_memsz
);
1352 (segment
->p_flags
& PF_R
? 'R' : ' '),
1353 (segment
->p_flags
& PF_W
? 'W' : ' '),
1354 (segment
->p_flags
& PF_X
? 'E' : ' '));
1355 printf ("%#lx", segment
->p_align
);
1358 switch (segment
->p_type
)
1362 loadaddr
= (segment
->p_vaddr
& 0xfffff000)
1363 - (segment
->p_offset
& 0xfffff000);
1368 error (_("more than one dynamic segment\n"));
1370 dynamic_addr
= segment
->p_offset
;
1371 dynamic_size
= segment
->p_filesz
;
1375 if (fseek (file
, segment
->p_offset
, SEEK_SET
))
1376 error (_("Unable to find program interpreter name\n"));
1379 program_interpreter
[0] = 0;
1380 fscanf (file
, "%63s", program_interpreter
);
1383 printf (_("\n [Requesting program interpreter: %s]"),
1384 program_interpreter
);
1390 putc ('\n', stdout
);
1399 if (do_segments
&& section_headers
!= NULL
)
1401 printf (_("\n Section to Segment mapping:\n"));
1402 printf (_(" Segment Sections...\n"));
1404 assert (string_table
!= NULL
);
1406 for (i
= 0; i
< elf_header
.e_phnum
; i
++)
1411 segment
= program_headers
+ i
;
1412 section
= section_headers
;
1414 printf (" %2.2d ", i
);
1416 for (j
= 0; j
< elf_header
.e_shnum
; j
++, section
++)
1418 if (section
->sh_size
> 0
1419 /* Compare allocated sections by VMA, unallocated
1420 sections by file offset. */
1421 && (section
->sh_flags
& SHF_ALLOC
1422 ? (section
->sh_addr
>= segment
->p_vaddr
1423 && section
->sh_addr
+ section
->sh_size
1424 <= segment
->p_vaddr
+ segment
->p_memsz
)
1425 : (section
->sh_offset
>= segment
->p_offset
1426 && (section
->sh_offset
+ section
->sh_size
1427 <= segment
->p_offset
+ segment
->p_filesz
))))
1428 printf ("%s ", SECTION_NAME (section
));
1435 free (program_headers
);
1440 process_section_headers (file
)
1446 if (elf_header
.e_shnum
== 0)
1449 printf (_("\nThere are no sections in this file.\n"));
1451 section_headers
= NULL
;
1455 if (do_sections
&& !do_header
)
1456 printf (_("There are %d section headers, starting at offset %x:\n"),
1457 elf_header
.e_shnum
, elf_header
.e_shoff
);
1459 GET_DATA_ALLOC (elf_header
.e_shoff
,
1460 elf_header
.e_shentsize
* elf_header
.e_shnum
,
1461 section_headers
, Elf_Shdr
*, "section headers");
1465 for (i
= 0; i
< elf_header
.e_shnum
; i
++)
1467 BYTE_SWAP (section_headers
[i
], sh_name
);
1468 BYTE_SWAP (section_headers
[i
], sh_type
);
1469 BYTE_SWAP (section_headers
[i
], sh_flags
);
1470 BYTE_SWAP (section_headers
[i
], sh_addr
);
1471 BYTE_SWAP (section_headers
[i
], sh_offset
);
1472 BYTE_SWAP (section_headers
[i
], sh_size
);
1473 BYTE_SWAP (section_headers
[i
], sh_link
);
1474 BYTE_SWAP (section_headers
[i
], sh_info
);
1475 BYTE_SWAP (section_headers
[i
], sh_addralign
);
1476 BYTE_SWAP (section_headers
[i
], sh_entsize
);
1480 /* Read in the string table, so that we have names to display. */
1481 section
= section_headers
+ elf_header
.e_shstrndx
;
1483 if (section
->sh_size
!= 0)
1485 unsigned long string_table_offset
;
1487 string_table_offset
= section
->sh_offset
;
1489 GET_DATA_ALLOC (section
->sh_offset
, section
->sh_size
,
1490 string_table
, char *, "string table");
1493 /* Scan the sections for the dynamic symbol table
1494 and dynamic string table. */
1495 dynamic_symbols
= NULL
;
1496 dynamic_strings
= NULL
;
1497 for (i
= 0, section
= section_headers
;
1498 i
< elf_header
.e_shnum
;
1501 if (section
->sh_type
== SHT_DYNSYM
)
1503 if (dynamic_symbols
!= NULL
)
1505 error (_("File contains multiple dynamic symbol tables\n"));
1509 GET_DATA_ALLOC (section
->sh_offset
, section
->sh_size
,
1510 dynamic_symbols
, Elf_Sym
*, "dynamic symbols");
1516 for (i
= 0, psym
= dynamic_symbols
;
1517 i
< section
->sh_size
/ section
->sh_entsize
;
1520 BYTE_SWAP (* psym
, st_name
);
1521 BYTE_SWAP (* psym
, st_value
);
1522 BYTE_SWAP (* psym
, st_size
);
1523 BYTE_SWAP (* psym
, st_shndx
);
1527 else if (section
->sh_type
== SHT_STRTAB
1528 && strcmp (SECTION_NAME (section
), ".dynstr") == 0)
1530 if (dynamic_strings
!= NULL
)
1532 error (_("File contains multiple dynamic string tables\n"));
1536 GET_DATA_ALLOC (section
->sh_offset
, section
->sh_size
,
1537 dynamic_strings
, char *, "dynamic strings");
1544 printf (_("\nSection Header%s:\n"), elf_header
.e_shnum
> 1 ? "s" : "");
1546 (_(" [Nr] Name Type Addr Off Size ES Flg Lk In Al\n"));
1548 for (i
= 0, section
= section_headers
;
1549 i
< elf_header
.e_shnum
;
1552 printf (" [%2d] %-17.17s", i
, SECTION_NAME (section
));
1554 printf (" %-15.15s ",get_section_type_name (section
->sh_type
));
1555 printf ( "%8.8lx %6.6lx %6.6lx %2.2lx",
1559 section
->sh_entsize
);
1561 printf (" %c%c%c %2ld %2lx %ld \n",
1562 (section
->sh_flags
& SHF_WRITE
? 'W' : ' '),
1563 (section
->sh_flags
& SHF_ALLOC
? 'A' : ' '),
1564 (section
->sh_flags
& SHF_EXECINSTR
? 'X' : ' '),
1567 section
->sh_addralign
);
1571 /* Process the reloc section. */
1573 process_relocs (file
)
1576 unsigned long rel_size
;
1577 unsigned long rel_offset
;
1583 if (do_using_dynamic
)
1588 if (dynamic_info
[DT_REL
])
1590 rel_offset
= dynamic_info
[DT_REL
];
1591 rel_size
= dynamic_info
[DT_RELSZ
];
1593 else if (dynamic_info
[DT_RELA
])
1595 rel_offset
= dynamic_info
[DT_RELA
];
1596 rel_size
= dynamic_info
[DT_RELASZ
];
1598 else if (dynamic_info
[DT_JMPREL
])
1600 rel_offset
= dynamic_info
[DT_JMPREL
];
1601 rel_size
= dynamic_info
[DT_PLTRELSZ
];
1606 printf (_("\nRelocation section at offset 0x%x contains %d bytes:\n"),
1607 rel_offset
, rel_size
);
1609 dump_relocations (file
, rel_offset
- loadaddr
, rel_size
,
1610 dynamic_symbols
, dynamic_strings
);
1613 printf (_("\nThere are no dynamic relocations in this file.\n"));
1621 assert (string_table
!= NULL
);
1623 for (i
= 0, section
= section_headers
;
1624 i
< elf_header
.e_shnum
;
1627 if ( section
->sh_type
!= SHT_RELA
1628 && section
->sh_type
!= SHT_REL
)
1631 rel_offset
= section
->sh_offset
;
1632 rel_size
= section
->sh_size
;
1641 printf (_("\nRelocation section '%s' at offset 0x%x contains %d entries:\n"),
1642 SECTION_NAME (section
), rel_offset
,
1643 rel_size
/ section
->sh_entsize
);
1645 symsec
= section_headers
+ section
->sh_link
;
1647 GET_DATA_ALLOC (symsec
->sh_offset
, symsec
->sh_size
, symtab
,
1648 Elf_Sym
*, "symbols");
1655 si
< symsec
->sh_size
/ symsec
->sh_entsize
;
1658 BYTE_SWAP (symtab
[si
], st_name
);
1659 BYTE_SWAP (symtab
[si
], st_value
);
1660 BYTE_SWAP (symtab
[si
], st_size
);
1661 BYTE_SWAP (symtab
[si
], st_shndx
);
1665 strsec
= section_headers
+ symsec
->sh_link
;
1667 GET_DATA_ALLOC (strsec
->sh_offset
, strsec
->sh_size
, strtab
,
1668 char *, "string table");
1670 dump_relocations (file
, rel_offset
, rel_size
, symtab
, strtab
);
1680 printf (_("\nThere are no relocations in this file.\n"));
1685 /* Parse the dynamic segment */
1687 process_dynamic_segment (file
)
1690 Elf_Dyn
* dynamic_segment
;
1694 if (dynamic_size
== 0)
1697 printf (_("\nThere is no dynamic segment in this file.\n"));
1702 GET_DATA_ALLOC (dynamic_addr
, dynamic_size
,
1703 dynamic_segment
, Elf_Dyn
*, "dynamic segment");
1705 dynamic_size
= dynamic_size
/ sizeof (Elf_Dyn
);
1709 for (i
= 0; i
< dynamic_size
; i
++)
1711 BYTE_SWAP (dynamic_segment
[i
], d_tag
);
1712 BYTE_SWAP (dynamic_segment
[i
], d_un
.d_val
);
1716 /* Find the appropriate symbol table. */
1717 if (dynamic_symbols
== NULL
)
1719 for (i
= 0, entry
= dynamic_segment
;
1723 unsigned long offset
;
1726 if (entry
->d_tag
!= DT_SYMTAB
)
1729 dynamic_info
[DT_SYMTAB
] = entry
->d_un
.d_val
;
1731 /* Since we do not know how big the symbol table is,
1732 we default to reading in the entire file (!) and
1733 processing that. This is overkill, I know, but it
1736 offset
= entry
->d_un
.d_val
- loadaddr
;
1737 if (fseek (file
, 0, SEEK_END
))
1738 error (_("Unable to seek to end of file!"));
1740 num_syms
= (ftell (file
) - offset
) / sizeof (Elf_Sym
);
1744 error (_("Unable to determine the number of symbols to load\n"));
1748 GET_DATA_ALLOC (offset
, num_syms
* sizeof (Elf_Sym
),
1749 dynamic_symbols
, Elf_Sym
*, "dynamic symbols");
1755 for (i
= 0, psym
= dynamic_symbols
;
1759 BYTE_SWAP (* psym
, st_name
);
1760 BYTE_SWAP (* psym
, st_value
);
1761 BYTE_SWAP (* psym
, st_size
);
1762 BYTE_SWAP (* psym
, st_shndx
);
1770 /* Similarly find a string table. */
1771 if (dynamic_strings
== NULL
)
1773 for (i
= 0, entry
= dynamic_segment
;
1777 unsigned long offset
;
1780 if (entry
->d_tag
!= DT_STRTAB
)
1783 dynamic_info
[DT_STRTAB
] = entry
->d_un
.d_val
;
1785 /* Since we do not know how big the string table is,
1786 we default to reading in the entire file (!) and
1787 processing that. This is overkill, I know, but it
1790 offset
= entry
->d_un
.d_val
- loadaddr
;
1791 if (fseek (file
, 0, SEEK_END
))
1792 error (_("Unable to seek to end of file\n"));
1793 str_tab_len
= ftell (file
) - offset
;
1795 if (str_tab_len
< 1)
1797 error (_("Unable to determine the length of the dynamic string table\n"));
1801 GET_DATA_ALLOC (offset
, str_tab_len
, dynamic_strings
, char *,
1802 "dynamic string table");
1808 if (do_dynamic
&& dynamic_addr
)
1809 printf (_("\nDynamic segement at offset 0x%x contains %d entries:\n"),
1810 dynamic_addr
, dynamic_size
);
1812 printf (_(" Tag Type Name/Value\n"));
1814 for (i
= 0, entry
= dynamic_segment
;
1819 printf (_(" 0x%-6.6x (%-11.11s) "),
1821 get_dynamic_type (entry
->d_tag
));
1823 switch (entry
->d_tag
)
1829 if (entry
->d_tag
== DT_AUXILIARY
)
1830 printf (_("Auxiliary library"));
1832 printf (_("Filter library"));
1834 if (dynamic_strings
)
1835 printf (": [%s]\n", dynamic_strings
+ entry
->d_un
.d_val
);
1837 printf (": %#lx\n", entry
->d_un
.d_val
);
1865 dynamic_info
[entry
->d_tag
] = entry
->d_un
.d_val
;
1871 if (dynamic_strings
== NULL
)
1874 name
= dynamic_strings
+ entry
->d_un
.d_val
;
1878 switch (entry
->d_tag
)
1881 printf (_("Shared library: [%s]"), name
);
1883 if (strcmp (name
, program_interpreter
))
1886 printf (_(" program interpreter\n"));
1890 printf (_("Library soname: [%s]\n"), name
);
1894 printf (_("Library rpath: [%s]\n"), name
);
1898 printf ("%#lx\n", entry
->d_un
.d_val
);
1902 printf ("%#lx\n", entry
->d_un
.d_val
);
1907 if ((entry
->d_tag
>= DT_VERSYM
) && (entry
->d_tag
<= DT_VERNEEDNUM
))
1909 version_info
[DT_VERSIONTAGIDX (entry
->d_tag
)] =
1913 printf ("%#lx\n", entry
->d_un
.d_ptr
);
1919 free (dynamic_segment
);
1923 get_ver_flags (unsigned short flags
)
1925 static char buff
[32];
1932 if (flags
& VER_FLG_BASE
)
1933 strcat (buff
, "BASE ");
1935 if (flags
& VER_FLG_WEAK
)
1937 if (flags
& VER_FLG_BASE
)
1938 strcat (buff
, "| ");
1940 strcat (buff
, "WEAK ");
1943 if (flags
& ~(VER_FLG_BASE
| VER_FLG_WEAK
))
1944 strcat (buff
, "| <unknown>");
1949 /* Display the contents of the version sections. */
1951 process_version_sections (file
)
1961 for (i
= 0, section
= section_headers
;
1962 i
< elf_header
.e_shnum
;
1965 switch (section
->sh_type
)
1967 case SHT_GNU_verdef
:
1969 Elf_Verdef
* verdef_section
;
1975 printf (_("\nVersion definition section '%s' contains %d entries:\n"),
1976 SECTION_NAME (section
), section
->sh_info
);
1978 printf (_(" Addr: %#08x Offset: %#08x Link: %x (%s)\n"),
1979 section
->sh_addr
, section
->sh_offset
, section
->sh_link
,
1980 SECTION_NAME (section_headers
+ section
->sh_link
));
1982 GET_DATA_ALLOC (section
->sh_offset
, section
->sh_size
,
1983 verdef_section
, Elf_Verdef
*,
1984 "version definition section");
1986 for (idx
= cnt
= 0; cnt
< section
->sh_info
; ++ cnt
)
1993 ent
= (Elf_Verdef
*) (((char *) verdef_section
) + idx
);
1997 BYTE_SWAP (* ent
, vd_version
);
1998 BYTE_SWAP (* ent
, vd_flags
);
1999 BYTE_SWAP (* ent
, vd_ndx
);
2000 BYTE_SWAP (* ent
, vd_cnt
);
2001 BYTE_SWAP (* ent
, vd_hash
);
2002 BYTE_SWAP (* ent
, vd_aux
);
2003 BYTE_SWAP (* ent
, vd_next
);
2006 printf (_(" %#06x: Rev: %d Flags: %s"),
2007 idx
, ent
->vd_version
, get_ver_flags (ent
->vd_flags
));
2009 printf (_(" Index: %d Cnt: %d "), ent
->vd_ndx
, ent
->vd_cnt
);
2011 aux
= (Elf_Verdaux
*) ((char *) ent
+ ent
->vd_aux
);
2015 BYTE_SWAP (* aux
, vda_name
);
2016 BYTE_SWAP (* aux
, vda_next
);
2019 if (dynamic_strings
)
2020 printf (_("Name: %s\n"), dynamic_strings
+ aux
->vda_name
);
2022 printf (_("Name index: %d\n"), aux
->vda_name
);
2025 isum
= idx
+ ent
->vd_aux
;
2027 while (j
< ent
->vd_cnt
)
2029 isum
+= aux
->vda_next
;
2031 aux
= (Elf_Verdaux
*)((char *) aux
+ aux
->vda_next
);
2035 BYTE_SWAP (* aux
, vda_name
);
2036 BYTE_SWAP (* aux
, vda_next
);
2039 if (dynamic_strings
)
2040 printf (_(" %#06x: Parent %d: %s\n"),
2041 isum
, j
, dynamic_strings
+ aux
->vda_name
);
2043 printf (_(" %#06x: Parent %d, name index: %d\n"),
2044 isum
, j
, aux
->vda_name
);
2049 idx
+= ent
->vd_next
;
2052 free (verdef_section
);
2056 case SHT_GNU_verneed
:
2058 Elf_Verneed
* verneed_section
;
2064 printf (_("\nVersion needs section '%s' contains %d entries:\n"),
2065 SECTION_NAME (section
), section
->sh_info
);
2067 printf (_(" Addr: %#08x Offset: %#08x Link to section: %d (%s)\n"),
2068 section
->sh_addr
, section
->sh_offset
, section
->sh_link
,
2069 SECTION_NAME (section_headers
+ section
->sh_link
));
2071 GET_DATA_ALLOC (section
->sh_offset
, section
->sh_size
,
2072 verneed_section
, Elf_Verneed
*,
2073 "version need section");
2075 for (idx
= cnt
= 0; cnt
< section
->sh_info
; ++cnt
)
2082 ent
= verneed_section
+ idx
/ sizeof (Elf_Verneed
);
2086 BYTE_SWAP (* ent
, vn_version
);
2087 BYTE_SWAP (* ent
, vn_cnt
);
2088 BYTE_SWAP (* ent
, vn_file
);
2089 BYTE_SWAP (* ent
, vn_aux
);
2090 BYTE_SWAP (* ent
, vn_next
);
2093 printf (_(" %#06x: Version: %d"), idx
, ent
->vn_version
);
2095 if (dynamic_strings
)
2096 printf (_(" File: %s"), dynamic_strings
+ ent
->vn_file
);
2098 printf (_(" File: %x"), ent
->vn_file
);
2100 printf (_(" Cnt: %d\n"), ent
->vn_cnt
);
2102 aux
= (Elf_Vernaux
*)((char *) ent
+ ent
->vn_aux
);
2104 for (j
= 0, isum
= idx
+ ent
->vn_aux
; j
< ent
->vn_cnt
; ++j
)
2108 BYTE_SWAP (* aux
, vna_hash
);
2109 BYTE_SWAP (* aux
, vna_flags
);
2110 BYTE_SWAP (* aux
, vna_other
);
2111 BYTE_SWAP (* aux
, vna_name
);
2112 BYTE_SWAP (* aux
, vna_next
);
2115 if (dynamic_strings
)
2116 printf (_(" %#06x: Name: %s"),
2117 isum
, dynamic_strings
+ aux
->vna_name
);
2119 printf (_(" %#06x: Name index: %x"),
2120 isum
, aux
->vna_name
);
2122 printf (_(" Flags: %s Version: %d\n"),
2123 get_ver_flags (aux
->vna_flags
), aux
->vna_other
);
2125 isum
+= aux
->vna_next
;
2126 aux
= (Elf_Vernaux
*)((char *) aux
+ aux
->vna_next
);
2129 idx
+= ent
->vn_next
;
2134 case SHT_GNU_versym
:
2136 Elf_Shdr
* link_section
= section_headers
+ section
->sh_link
;
2137 int total
= section
->sh_size
/ section
->sh_entsize
;
2142 Elf_Shdr
* string_sec
;
2146 GET_DATA_ALLOC (link_section
->sh_offset
, link_section
->sh_size
,
2147 symbols
, Elf_Sym
*, "version symbols section");
2153 for (k
= link_section
->sh_size
/ link_section
->sh_entsize
;
2156 BYTE_SWAP (symbols
[k
], st_name
);
2157 BYTE_SWAP (symbols
[k
], st_value
);
2158 BYTE_SWAP (symbols
[k
], st_size
);
2159 BYTE_SWAP (symbols
[k
], st_shndx
);
2163 string_sec
= section_headers
+ link_section
->sh_link
;
2165 GET_DATA_ALLOC (string_sec
->sh_offset
, string_sec
->sh_size
,
2166 strtab
, char *, "version string table");
2168 printf (_("\nVersion symbols section '%s' contains %d entries:\n"),
2169 SECTION_NAME (section
), total
);
2171 printf (_(" Addr: %#08x Offset: %#08x Link: %x (%s)\n"),
2172 section
->sh_addr
, section
->sh_offset
, section
->sh_link
,
2173 SECTION_NAME (link_section
));
2175 GET_DATA_ALLOC (version_info
[DT_VERSIONTAGIDX (DT_VERSYM
)] - loadaddr
,
2176 total
* sizeof (unsigned short), p
,
2177 unsigned short *, "version symbol data");
2182 for (k
= total
; k
--;)
2183 p
[k
] = SWAP2 (p
[k
]);
2186 for (cnt
= 0; cnt
< total
; cnt
+= 4)
2190 printf (" %03x:", cnt
);
2192 for (j
= 0; (j
< 4) && (cnt
+ j
) < total
; ++j
)
2196 printf (" 0 (*local*) ");
2200 printf (" 1 (*global*) ");
2204 nn
= printf ("%4x%c", p
[cnt
+ j
] & 0x7fff,
2205 p
[cnt
+ j
] & 0x8000 ? 'h' : ' ');
2207 if (symbols
[cnt
+ j
].st_shndx
< SHN_LORESERVE
2208 && section_headers
[symbols
[cnt
+ j
].st_shndx
].sh_type
2211 /* We must test both. */
2214 unsigned long offset
;
2216 offset
= version_info
[DT_VERSIONTAGIDX (DT_VERNEED
)]
2221 unsigned long vna_off
;
2223 GET_DATA (offset
, vn
, "version need");
2227 BYTE_SWAP (vn
, vn_aux
);
2228 BYTE_SWAP (vn
, vn_next
);
2231 vna_off
= offset
+ vn
.vn_aux
;
2235 GET_DATA (vna_off
, vna
,
2236 "version need aux (1)");
2240 BYTE_SWAP (vna
, vna_next
);
2241 BYTE_SWAP (vna
, vna_other
);
2244 vna_off
+= vna
.vna_next
;
2246 while (vna
.vna_other
!= p
[cnt
+ j
]
2247 && vna
.vna_next
!= 0);
2249 if (vna
.vna_other
== p
[cnt
+ j
])
2252 BYTE_SWAP (vna
, vna_name
);
2254 nn
+= printf ("(%11.11s)",
2255 strtab
+ vna
.vna_name
);
2258 else if (vn
.vn_next
== 0)
2260 if (p
[cnt
+ j
] != 0x8001)
2265 offset
= version_info
2266 [DT_VERSIONTAGIDX (DT_VERDEF
)]
2271 GET_DATA (offset
, vd
,
2272 "version definition");
2276 BYTE_SWAP (vd
, vd_next
);
2277 BYTE_SWAP (vd
, vd_ndx
);
2280 offset
+= vd
.vd_next
;
2282 while (vd
.vd_ndx
!= (p
[cnt
+ j
] & 0x7fff)
2283 && vd
.vd_next
!= 0);
2285 if (vd
.vd_ndx
== (p
[cnt
+ j
] & 0x7fff))
2288 BYTE_SWAP (vd
, vd_aux
);
2290 GET_DATA (offset
+ vd
.vd_aux
, vda
,
2291 "version definition aux");
2294 BYTE_SWAP (vda
, vda_name
);
2296 nn
+= printf ("(%11.11s)",
2297 strtab
+ vda
.vda_name
);
2304 offset
+= vn
.vn_next
;
2308 else if (symbols
[cnt
+ j
].st_shndx
== SHN_UNDEF
)
2312 unsigned long offset
;
2314 offset
= version_info
[DT_VERSIONTAGIDX (DT_VERNEED
)]
2319 unsigned long a_off
;
2321 GET_DATA (offset
, v
, "version need");
2325 BYTE_SWAP (v
, vn_aux
);
2326 BYTE_SWAP (v
, vn_next
);
2329 a_off
= offset
+ v
.vn_aux
;
2333 GET_DATA (a_off
, a
, "version need aux (2)");
2337 BYTE_SWAP (a
, vna_next
);
2338 BYTE_SWAP (a
, vna_other
);
2341 a_off
+= a
.vna_next
;
2343 while (a
.vna_other
!= p
[cnt
+ j
]
2344 && a
.vna_next
!= 0);
2346 if (a
.vna_other
== p
[cnt
+ j
])
2349 BYTE_SWAP (a
, vna_name
);
2351 nn
+= printf ("(%11.11s)",
2352 strtab
+ a
.vna_name
);
2357 offset
+= v
.vn_next
;
2363 if (p
[cnt
+ j
] != 0x8001)
2367 unsigned long offset
;
2369 offset
= version_info
2370 [DT_VERSIONTAGIDX (DT_VERDEF
)] - loadaddr
;
2374 GET_DATA (offset
, v
, "version def");
2378 BYTE_SWAP (v
, vd_next
);
2379 BYTE_SWAP (v
, vd_ndx
);
2382 offset
+= v
.vd_next
;
2384 while (v
.vd_ndx
!= (p
[cnt
+ j
] & 0x7fff)
2387 if (v
.vd_ndx
== (p
[cnt
+ j
] & 0x7fff))
2390 BYTE_SWAP (v
, vd_aux
);
2392 GET_DATA (offset
- v
.vd_next
+ v
.vd_aux
, a
,
2396 BYTE_SWAP (a
, vda_name
);
2398 nn
+= printf ("(%11.11s)",
2399 strtab
+ a
.vda_name
);
2405 printf ("%*c", 18 - nn
, ' ');
2422 printf (_("\nNo version information found in this file.\n"));
2426 get_symbol_binding (binding
)
2427 unsigned int binding
;
2429 static char buff
[32];
2433 case STB_LOCAL
: return _("LOCAL");
2434 case STB_GLOBAL
: return _("GLOBAL");
2435 case STB_WEAK
: return _("WEAK");
2437 if (binding
>= STB_LOPROC
&& binding
<= STB_HIPROC
)
2438 sprintf (buff
, _("<processor specific>: %d"), binding
);
2440 sprintf (buff
, _("<unknown>: %d"), binding
);
2446 get_symbol_type (type
)
2449 static char buff
[32];
2453 case STT_NOTYPE
: return _("NOTYPE");
2454 case STT_OBJECT
: return _("OBJECT");
2455 case STT_FUNC
: return _("FUNC");
2456 case STT_SECTION
: return _("SECTION");
2457 case STT_FILE
: return _("FILE");
2459 if (type
>= STT_LOPROC
&& type
<= STT_HIPROC
)
2460 sprintf (buff
, _("<processor specific>: %d"), type
);
2462 sprintf (buff
, _("<unknown>: %d"), type
);
2468 get_symbol_index_type (type
)
2469 unsigned short type
;
2473 case SHN_UNDEF
: return "UND";
2474 case SHN_ABS
: return "ABS";
2475 case SHN_COMMON
: return "COM";
2477 if (type
>= SHN_LOPROC
&& type
<= SHN_HIPROC
)
2479 else if (type
>= SHN_LORESERVE
&& type
<= SHN_HIRESERVE
)
2483 static char buff
[32];
2485 sprintf (buff
, "%3d", type
);
2492 /* Dump the symbol table */
2494 process_symbol_table (file
)
2502 if (dynamic_info
[DT_HASH
] && do_using_dynamic
&& dynamic_strings
!= NULL
)
2511 if (fseek (file
, dynamic_info
[DT_HASH
] - loadaddr
, SEEK_SET
))
2513 error (_("Unable to seek to start of dynamic information"));
2517 if (fread (& nbuckets
, sizeof (nbuckets
), 1, file
) != 1)
2519 error (_("Failed to read in number of buckets\n"));
2523 if (fread (& nchains
, sizeof (nchains
), 1, file
) != 1)
2525 error (_("Failed to read in number of chains\n"));
2531 nbuckets
= SWAP4 (nbuckets
);
2532 nchains
= SWAP4 (nchains
);
2535 buckets
= (int *) malloc (nbuckets
* sizeof (* buckets
));
2536 if (buckets
== NULL
)
2538 error (_("Failed to allocate space for buckets\n"));
2542 if (fread (buckets
, sizeof (* buckets
), nbuckets
, file
) != nbuckets
)
2544 error (_("Unable to read in buckets\n"));
2548 chains
= (int *) malloc (nchains
* sizeof (* chains
));
2551 error (_("Failed to allocate space for chains\n"));
2556 if (fread (chains
, sizeof (* chains
), nchains
, file
) != nchains
)
2558 error (_("Unable to read in chains!\n"));
2565 for (si
= nbuckets
; si
--;)
2566 buckets
[si
] = SWAP4 (buckets
[si
]);
2568 for (si
= nchains
; si
--;)
2569 chains
[si
] = SWAP4 (chains
[si
]);
2572 printf (_("\nSymbol table for image:\n"));
2573 printf (_(" Num Buc: Value Size Type Bind Ot Ndx Name\n"));
2575 for (hn
= 0; hn
< nbuckets
; hn
++)
2580 for (si
= buckets
[hn
]; si
; si
= chains
[si
])
2584 psym
= dynamic_symbols
+ si
;
2586 printf (" %3d %3d: %8lx %5ld %6s %6s %2d ", si
, hn
,
2589 get_symbol_type (ELF_ST_TYPE (psym
->st_info
)),
2590 get_symbol_binding (ELF_ST_BIND (psym
->st_info
)),
2593 printf ("%3.3s", get_symbol_index_type (psym
->st_shndx
));
2595 printf (" %s\n", dynamic_strings
+ psym
->st_name
);
2602 else if (!do_using_dynamic
)
2606 for (i
= 0, section
= section_headers
;
2607 i
< elf_header
.e_shnum
;
2616 if ( section
->sh_type
!= SHT_SYMTAB
2617 && section
->sh_type
!= SHT_DYNSYM
)
2620 printf (_("\nSymbol table '%s' contains %d entries:\n"),
2621 SECTION_NAME (section
),
2622 section
->sh_size
/ section
->sh_entsize
);
2623 printf (_(" Num: Value Size Type Bind Ot Ndx Name\n"));
2625 GET_DATA_ALLOC (section
->sh_offset
, section
->sh_size
, symtab
,
2626 Elf_Sym
*, "symbol section");
2630 for (si
= 0; si
< section
->sh_size
/ section
->sh_entsize
; si
++)
2632 BYTE_SWAP (symtab
[si
], st_name
);
2633 BYTE_SWAP (symtab
[si
], st_value
);
2634 BYTE_SWAP (symtab
[si
], st_size
);
2635 BYTE_SWAP (symtab
[si
], st_shndx
);
2639 if (section
->sh_link
== elf_header
.e_shstrndx
)
2640 strtab
= string_table
;
2643 Elf_Shdr
* string_sec
= section_headers
+ section
->sh_link
;
2645 GET_DATA_ALLOC (string_sec
->sh_offset
, string_sec
->sh_size
,
2646 strtab
, char *, "string table");
2649 for (si
= 0, psym
= symtab
;
2650 si
< section
->sh_size
/ section
->sh_entsize
;
2653 printf (" %3d: %8lx %5ld %-7s %-6s %2d ", si
,
2656 get_symbol_type (ELF_ST_TYPE (psym
->st_info
)),
2657 get_symbol_binding (ELF_ST_BIND (psym
->st_info
)),
2660 if (psym
->st_shndx
== 0)
2662 else if ((psym
->st_shndx
& 0xffff) == 0xfff1)
2664 else if ((psym
->st_shndx
& 0xffff) == 0xfff2)
2667 printf ("%3d", psym
->st_shndx
);
2669 printf (" %s", strtab
+ psym
->st_name
);
2671 if (section
->sh_type
== SHT_DYNSYM
&&
2672 version_info
[DT_VERSIONTAGIDX (DT_VERSYM
)] != 0)
2674 unsigned short vers_data
;
2675 unsigned long offset
;
2679 offset
= version_info
[DT_VERSIONTAGIDX (DT_VERSYM
)]
2682 GET_DATA (offset
+ si
* sizeof (vers_data
), vers_data
,
2686 vers_data
= SWAP2 (vers_data
);
2688 is_nobits
= psym
->st_shndx
< SHN_LORESERVE
?
2689 (section_headers
[psym
->st_shndx
].sh_type
== SHT_NOBITS
)
2692 check_def
= (psym
->st_shndx
!= SHN_UNDEF
);
2694 if ((vers_data
& 0x8000) || vers_data
> 1)
2696 if (is_nobits
|| ! check_def
)
2701 /* We must test both. */
2702 offset
= version_info
2703 [DT_VERSIONTAGIDX (DT_VERNEED
)] - loadaddr
;
2705 GET_DATA (offset
, vn
, "version need");
2709 BYTE_SWAP (vn
, vn_aux
);
2710 BYTE_SWAP (vn
, vn_next
);
2715 unsigned long vna_off
;
2717 vna_off
= offset
+ vn
.vn_aux
;
2721 GET_DATA (vna_off
, vna
,
2722 "version need aux (3)");
2726 BYTE_SWAP (vna
, vna_other
);
2727 BYTE_SWAP (vna
, vna_next
);
2730 vna_off
+= vna
.vna_next
;
2732 while (vna
.vna_other
!= vers_data
2733 && vna
.vna_next
!= 0);
2735 if (vna
.vna_other
== vers_data
)
2738 offset
+= vn
.vn_next
;
2740 while (vn
.vn_next
!= 0);
2742 if (vna
.vna_other
== vers_data
)
2744 strtab
+ vna
.vna_name
, vna
.vna_other
);
2745 else if (! is_nobits
)
2746 error (_("bad dynamic symbol"));
2753 if (vers_data
!= 0x8001)
2757 unsigned long offset
;
2760 version_info
[DT_VERSIONTAGIDX (DT_VERDEF
)]
2765 GET_DATA (offset
, vd
, "version def");
2769 BYTE_SWAP (vd
, vd_ndx
);
2770 BYTE_SWAP (vd
, vd_aux
);
2771 BYTE_SWAP (vd
, vd_next
);
2774 offset
+= vd
.vd_next
;
2776 while (vd
.vd_ndx
!= (vers_data
& 0x7fff)
2777 && vd
.vd_next
!= 0);
2779 offset
-= vd
.vd_next
;
2780 offset
+= vd
.vd_aux
;
2782 GET_DATA (offset
, vda
, "version def aux");
2785 BYTE_SWAP (vda
, vda_name
);
2787 if (psym
->st_name
!= vda
.vda_name
)
2788 printf ((vers_data
& 0x8000)
2790 strtab
+ vda
.vda_name
);
2800 if (strtab
!= string_table
)
2806 (_("\nDynamic symbol information is not available for displaying symbols.\n"));
2810 process_section_contents (file
)
2819 for (i
= 0, section
= section_headers
;
2820 i
< elf_header
.e_shnum
;
2823 #ifdef SUPPORT_DISASSEMBLY
2824 /* See if we need an assembly dump of this section */
2826 if ((i
< NUM_DUMP_SECTS
) && (dump_sects
[i
] & DISASS_DUMP
))
2828 printf (_("\nAssembly dump of section %s\n"),
2829 SECTION_NAME (section
));
2831 /* XXX -- to be done --- XXX */
2834 /* See if we need a hex dump of this section. */
2835 if ((i
< NUM_DUMP_SECTS
) && (dump_sects
[i
] & HEX_DUMP
))
2839 unsigned char * data
;
2842 printf (_("\nHex dump of section '%s':\n"), SECTION_NAME (section
));
2844 bytes
= section
->sh_size
;
2845 addr
= section
->sh_addr
;
2847 GET_DATA_ALLOC (section
->sh_offset
, bytes
, start
, char *,
2858 lbytes
= (bytes
> 16 ? 16 : bytes
);
2860 printf (" 0x%8.8x ", addr
);
2862 switch (elf_header
.e_ident
[EI_DATA
])
2865 for (j
= 15; j
>= 0; j
--)
2868 printf ("%2.2x", data
[j
]);
2878 for (j
= 0; j
< 16; j
++)
2881 printf ("%2.2x", data
[j
]);
2891 for (j
= 0; j
< lbytes
; j
++)
2894 if (k
>= ' ' && k
< 0x80)
2913 process_file (file_name
)
2917 struct stat statbuf
;
2920 if (stat (file_name
, & statbuf
) < 0)
2922 error (_("Cannot stat input file %s.\n"), file_name
);
2926 file
= fopen (file_name
, "rb");
2929 error (_("Input file %s not found.\n"), file_name
);
2933 if (fread (& elf_header
, sizeof (elf_header
), 1, file
) != 1)
2935 error (_("%s: Failed to read file header\n"), file_name
);
2940 /* Initialise per file variables. */
2943 for (i
= NUM_ELEM (version_info
); i
--;)
2944 version_info
[i
] = 0;
2946 for (i
= NUM_ELEM (dynamic_info
); i
--;)
2947 dynamic_info
[i
] = 0;
2950 /* Process the file. */
2952 printf (_("\nFile: %s\n"), file_name
);
2954 if (! process_file_header ())
2960 process_section_headers (file
);
2962 process_program_headers (file
);
2964 process_dynamic_segment (file
);
2966 process_relocs (file
);
2968 process_symbol_table (file
);
2970 process_version_sections (file
);
2972 process_section_contents (file
);
2976 if (section_headers
)
2978 free (section_headers
);
2979 section_headers
= NULL
;
2984 free (string_table
);
2985 string_table
= NULL
;
2988 if (dynamic_strings
)
2990 free (dynamic_strings
);
2991 dynamic_strings
= NULL
;
2994 if (dynamic_symbols
)
2996 free (dynamic_symbols
);
2997 dynamic_symbols
= NULL
;
3001 #ifdef SUPPORT_DISASSEMBLY
3002 /* Needed by the i386 disassembler. For extra credit, someone could
3003 fix this so that we insert symbolic addresses here, esp for GOT/PLT
3007 print_address (unsigned int addr
, FILE * outfile
)
3009 fprintf (outfile
,"0x%8.8x", addr
);
3012 /* Needed by the i386 disassembler. */
3014 db_task_printsym (unsigned int addr
)
3016 print_address (addr
, stderr
);
3025 parse_args (argc
, argv
);
3027 expected_endian
= 0x12345678;
3029 if (* ((char *) & expected_endian
) == 0x12)
3030 expected_endian
= ELFDATA2MSB
;
3032 expected_endian
= ELFDATA2LSB
;
3034 if (optind
< (argc
- 1))
3037 while (optind
< argc
)
3038 process_file (argv
[optind
++]);