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