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