1 /* readelf.c -- display contents of an ELF format file 2 Copyright 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007, 3 2008, 2009, 2010, 2011, 2012 4 Free Software Foundation, Inc. 5 6 Originally developed by Eric Youngdale <eric@andante.jic.com> 7 Modifications by Nick Clifton <nickc@redhat.com> 8 9 This file is part of GNU Binutils. 10 11 This program is free software; you can redistribute it and/or modify 12 it under the terms of the GNU General Public License as published by 13 the Free Software Foundation; either version 3 of the License, or 14 (at your option) any later version. 15 16 This program is distributed in the hope that it will be useful, 17 but WITHOUT ANY WARRANTY; without even the implied warranty of 18 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 19 GNU General Public License for more details. 20 21 You should have received a copy of the GNU General Public License 22 along with this program; if not, write to the Free Software 23 Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA 24 02110-1301, USA. */ 25 26 /* The difference between readelf and objdump: 27 28 Both programs are capable of displaying the contents of ELF format files, 29 so why does the binutils project have two file dumpers ? 30 31 The reason is that objdump sees an ELF file through a BFD filter of the 32 world; if BFD has a bug where, say, it disagrees about a machine constant 33 in e_flags, then the odds are good that it will remain internally 34 consistent. The linker sees it the BFD way, objdump sees it the BFD way, 35 GAS sees it the BFD way. There was need for a tool to go find out what 36 the file actually says. 37 38 This is why the readelf program does not link against the BFD library - it 39 exists as an independent program to help verify the correct working of BFD. 40 41 There is also the case that readelf can provide more information about an 42 ELF file than is provided by objdump. In particular it can display DWARF 43 debugging information which (at the moment) objdump cannot. */ 44 45 #include "sysdep.h" 46 #include <assert.h> 47 #include <time.h> 48 #ifdef HAVE_ZLIB_H 49 #include <zlib.h> 50 #endif 51 #ifdef HAVE_WCHAR_H 52 #include <wchar.h> 53 #endif 54 55 #if __GNUC__ >= 2 56 /* Define BFD64 here, even if our default architecture is 32 bit ELF 57 as this will allow us to read in and parse 64bit and 32bit ELF files. 58 Only do this if we believe that the compiler can support a 64 bit 59 data type. For now we only rely on GCC being able to do this. */ 60 #define BFD64 61 #endif 62 63 #include "bfd.h" 64 #include "bucomm.h" 65 #include "elfcomm.h" 66 #include "dwarf.h" 67 68 #include "elf/common.h" 69 #include "elf/external.h" 70 #include "elf/internal.h" 71 72 73 /* Included here, before RELOC_MACROS_GEN_FUNC is defined, so that 74 we can obtain the H8 reloc numbers. We need these for the 75 get_reloc_size() function. We include h8.h again after defining 76 RELOC_MACROS_GEN_FUNC so that we get the naming function as well. */ 77 78 #include "elf/h8.h" 79 #undef _ELF_H8_H 80 81 /* Undo the effects of #including reloc-macros.h. */ 82 83 #undef START_RELOC_NUMBERS 84 #undef RELOC_NUMBER 85 #undef FAKE_RELOC 86 #undef EMPTY_RELOC 87 #undef END_RELOC_NUMBERS 88 #undef _RELOC_MACROS_H 89 90 /* The following headers use the elf/reloc-macros.h file to 91 automatically generate relocation recognition functions 92 such as elf_mips_reloc_type() */ 93 94 #define RELOC_MACROS_GEN_FUNC 95 96 #include "elf/aarch64.h" 97 #include "elf/alpha.h" 98 #include "elf/arc.h" 99 #include "elf/arm.h" 100 #include "elf/avr.h" 101 #include "elf/bfin.h" 102 #include "elf/cr16.h" 103 #include "elf/cris.h" 104 #include "elf/crx.h" 105 #include "elf/d10v.h" 106 #include "elf/d30v.h" 107 #include "elf/dlx.h" 108 #include "elf/epiphany.h" 109 #include "elf/fr30.h" 110 #include "elf/frv.h" 111 #include "elf/h8.h" 112 #include "elf/hppa.h" 113 #include "elf/i386.h" 114 #include "elf/i370.h" 115 #include "elf/i860.h" 116 #include "elf/i960.h" 117 #include "elf/ia64.h" 118 #include "elf/ip2k.h" 119 #include "elf/lm32.h" 120 #include "elf/iq2000.h" 121 #include "elf/m32c.h" 122 #include "elf/m32r.h" 123 #include "elf/m68k.h" 124 #include "elf/m68hc11.h" 125 #include "elf/mcore.h" 126 #include "elf/mep.h" 127 #include "elf/microblaze.h" 128 #include "elf/mips.h" 129 #include "elf/riscv.h" 130 #include "elf/mmix.h" 131 #include "elf/mn10200.h" 132 #include "elf/mn10300.h" 133 #include "elf/moxie.h" 134 #include "elf/mt.h" 135 #include "elf/msp430.h" 136 #include "elf/or1k.h" 137 #include "elf/pj.h" 138 #include "elf/ppc.h" 139 #include "elf/ppc64.h" 140 #include "elf/rl78.h" 141 #include "elf/rx.h" 142 #include "elf/s390.h" 143 #include "elf/score.h" 144 #include "elf/sh.h" 145 #include "elf/sparc.h" 146 #include "elf/spu.h" 147 #include "elf/tic6x.h" 148 #include "elf/tilegx.h" 149 #include "elf/tilepro.h" 150 #include "elf/v850.h" 151 #include "elf/vax.h" 152 #include "elf/x86-64.h" 153 #include "elf/xc16x.h" 154 #include "elf/xgate.h" 155 #include "elf/xstormy16.h" 156 #include "elf/xtensa.h" 157 158 #include "getopt.h" 159 #include "libiberty.h" 160 #include "safe-ctype.h" 161 #include "filenames.h" 162 163 char * program_name = "readelf"; 164 static long archive_file_offset; 165 static unsigned long archive_file_size; 166 static unsigned long dynamic_addr; 167 static bfd_size_type dynamic_size; 168 static unsigned int dynamic_nent; 169 static char * dynamic_strings; 170 static unsigned long dynamic_strings_length; 171 static char * string_table; 172 static unsigned long string_table_length; 173 static unsigned long num_dynamic_syms; 174 static Elf_Internal_Sym * dynamic_symbols; 175 static Elf_Internal_Syminfo * dynamic_syminfo; 176 static unsigned long dynamic_syminfo_offset; 177 static unsigned int dynamic_syminfo_nent; 178 static char program_interpreter[PATH_MAX]; 179 static bfd_vma dynamic_info[DT_ENCODING]; 180 static bfd_vma dynamic_info_DT_GNU_HASH; 181 static bfd_vma version_info[16]; 182 static Elf_Internal_Ehdr elf_header; 183 static Elf_Internal_Shdr * section_headers; 184 static Elf_Internal_Phdr * program_headers; 185 static Elf_Internal_Dyn * dynamic_section; 186 static Elf_Internal_Shdr * symtab_shndx_hdr; 187 static int show_name; 188 static int do_special_files; 189 static int do_dynamic; 190 static int do_syms; 191 static int do_dyn_syms; 192 static int do_reloc; 193 static int do_sections; 194 static int do_section_groups; 195 static int do_section_details; 196 static int do_segments; 197 static int do_unwind; 198 static int do_using_dynamic; 199 static int do_header; 200 static int do_dump; 201 static int do_version; 202 static int do_histogram; 203 static int do_debugging; 204 static int do_arch; 205 static int do_notes; 206 static int do_archive_index; 207 static int is_32bit_elf; 208 209 struct group_list 210 { 211 struct group_list * next; 212 unsigned int section_index; 213 }; 214 215 struct group 216 { 217 struct group_list * root; 218 unsigned int group_index; 219 }; 220 221 static size_t group_count; 222 static struct group * section_groups; 223 static struct group ** section_headers_groups; 224 225 226 /* Flag bits indicating particular types of dump. */ 227 #define HEX_DUMP (1 << 0) /* The -x command line switch. */ 228 #define DISASS_DUMP (1 << 1) /* The -i command line switch. */ 229 #define DEBUG_DUMP (1 << 2) /* The -w command line switch. */ 230 #define STRING_DUMP (1 << 3) /* The -p command line switch. */ 231 #define RELOC_DUMP (1 << 4) /* The -R command line switch. */ 232 233 typedef unsigned char dump_type; 234 235 /* A linked list of the section names for which dumps were requested. */ 236 struct dump_list_entry 237 { 238 char * name; 239 dump_type type; 240 struct dump_list_entry * next; 241 }; 242 static struct dump_list_entry * dump_sects_byname; 243 244 /* A dynamic array of flags indicating for which sections a dump 245 has been requested via command line switches. */ 246 static dump_type * cmdline_dump_sects = NULL; 247 static unsigned int num_cmdline_dump_sects = 0; 248 249 /* A dynamic array of flags indicating for which sections a dump of 250 some kind has been requested. It is reset on a per-object file 251 basis and then initialised from the cmdline_dump_sects array, 252 the results of interpreting the -w switch, and the 253 dump_sects_byname list. */ 254 static dump_type * dump_sects = NULL; 255 static unsigned int num_dump_sects = 0; 256 257 258 /* How to print a vma value. */ 259 typedef enum print_mode 260 { 261 HEX, 262 DEC, 263 DEC_5, 264 UNSIGNED, 265 PREFIX_HEX, 266 FULL_HEX, 267 LONG_HEX 268 } 269 print_mode; 270 271 #define UNKNOWN -1 272 273 #define SECTION_NAME(X) \ 274 ((X) == NULL ? _("<none>") \ 275 : string_table == NULL ? _("<no-name>") \ 276 : ((X)->sh_name >= string_table_length ? _("<corrupt>") \ 277 : string_table + (X)->sh_name)) 278 279 #define DT_VERSIONTAGIDX(tag) (DT_VERNEEDNUM - (tag)) /* Reverse order! */ 280 281 #define GET_ELF_SYMBOLS(file, section, sym_count) \ 282 (is_32bit_elf ? get_32bit_elf_symbols (file, section, sym_count) \ 283 : get_64bit_elf_symbols (file, section, sym_count)) 284 285 #define VALID_DYNAMIC_NAME(offset) ((dynamic_strings != NULL) && (offset < dynamic_strings_length)) 286 /* GET_DYNAMIC_NAME asssumes that VALID_DYNAMIC_NAME has 287 already been called and verified that the string exists. */ 288 #define GET_DYNAMIC_NAME(offset) (dynamic_strings + offset) 289 290 #define REMOVE_ARCH_BITS(ADDR) \ 291 do \ 292 { \ 293 if (elf_header.e_machine == EM_ARM) \ 294 (ADDR) &= ~1; \ 295 } \ 296 while (0) 297 298 /* Retrieve NMEMB structures, each SIZE bytes long from FILE starting at OFFSET. 299 Put the retrieved data into VAR, if it is not NULL. Otherwise allocate a buffer 300 using malloc and fill that. In either case return the pointer to the start of 301 the retrieved data or NULL if something went wrong. If something does go wrong 302 emit an error message using REASON as part of the context. */ 303 304 static void * 305 get_data (void * var, FILE * file, long offset, size_t size, size_t nmemb, 306 const char * reason) 307 { 308 void * mvar; 309 310 if (size == 0 || nmemb == 0) 311 return NULL; 312 313 if (fseek (file, archive_file_offset + offset, SEEK_SET)) 314 { 315 error (_("Unable to seek to 0x%lx for %s\n"), 316 (unsigned long) archive_file_offset + offset, reason); 317 return NULL; 318 } 319 320 mvar = var; 321 if (mvar == NULL) 322 { 323 /* Check for overflow. */ 324 if (nmemb < (~(size_t) 0 - 1) / size) 325 /* + 1 so that we can '\0' terminate invalid string table sections. */ 326 mvar = malloc (size * nmemb + 1); 327 328 if (mvar == NULL) 329 { 330 error (_("Out of memory allocating 0x%lx bytes for %s\n"), 331 (unsigned long)(size * nmemb), reason); 332 return NULL; 333 } 334 335 ((char *) mvar)[size * nmemb] = '\0'; 336 } 337 338 if (fread (mvar, size, nmemb, file) != nmemb) 339 { 340 error (_("Unable to read in 0x%lx bytes of %s\n"), 341 (unsigned long)(size * nmemb), reason); 342 if (mvar != var) 343 free (mvar); 344 return NULL; 345 } 346 347 return mvar; 348 } 349 350 /* Print a VMA value. */ 351 352 static int 353 print_vma (bfd_vma vma, print_mode mode) 354 { 355 int nc = 0; 356 357 switch (mode) 358 { 359 case FULL_HEX: 360 nc = printf ("0x"); 361 /* Drop through. */ 362 363 case LONG_HEX: 364 #ifdef BFD64 365 if (is_32bit_elf) 366 return nc + printf ("%8.8" BFD_VMA_FMT "x", vma); 367 #endif 368 printf_vma (vma); 369 return nc + 16; 370 371 case DEC_5: 372 if (vma <= 99999) 373 return printf ("%5" BFD_VMA_FMT "d", vma); 374 /* Drop through. */ 375 376 case PREFIX_HEX: 377 nc = printf ("0x"); 378 /* Drop through. */ 379 380 case HEX: 381 return nc + printf ("%" BFD_VMA_FMT "x", vma); 382 383 case DEC: 384 return printf ("%" BFD_VMA_FMT "d", vma); 385 386 case UNSIGNED: 387 return printf ("%" BFD_VMA_FMT "u", vma); 388 } 389 return 0; 390 } 391 392 /* Display a symbol on stdout. Handles the display of control characters and 393 multibye characters (assuming the host environment supports them). 394 395 Display at most abs(WIDTH) characters, truncating as necessary, unless do_wide is true. 396 397 If WIDTH is negative then ensure that the output is at least (- WIDTH) characters, 398 padding as necessary. 399 400 Returns the number of emitted characters. */ 401 402 static unsigned int 403 print_symbol (int width, const char *symbol) 404 { 405 bfd_boolean extra_padding = FALSE; 406 int num_printed = 0; 407 #ifdef HAVE_MBSTATE_T 408 mbstate_t state; 409 #endif 410 int width_remaining; 411 412 if (width < 0) 413 { 414 /* Keep the width positive. This also helps. */ 415 width = - width; 416 extra_padding = TRUE; 417 } 418 419 if (do_wide) 420 /* Set the remaining width to a very large value. 421 This simplifies the code below. */ 422 width_remaining = INT_MAX; 423 else 424 width_remaining = width; 425 426 #ifdef HAVE_MBSTATE_T 427 /* Initialise the multibyte conversion state. */ 428 memset (& state, 0, sizeof (state)); 429 #endif 430 431 while (width_remaining) 432 { 433 size_t n; 434 const char c = *symbol++; 435 436 if (c == 0) 437 break; 438 439 /* Do not print control characters directly as they can affect terminal 440 settings. Such characters usually appear in the names generated 441 by the assembler for local labels. */ 442 if (ISCNTRL (c)) 443 { 444 if (width_remaining < 2) 445 break; 446 447 printf ("^%c", c + 0x40); 448 width_remaining -= 2; 449 num_printed += 2; 450 } 451 else if (ISPRINT (c)) 452 { 453 putchar (c); 454 width_remaining --; 455 num_printed ++; 456 } 457 else 458 { 459 #ifdef HAVE_MBSTATE_T 460 wchar_t w; 461 #endif 462 /* Let printf do the hard work of displaying multibyte characters. */ 463 printf ("%.1s", symbol - 1); 464 width_remaining --; 465 num_printed ++; 466 467 #ifdef HAVE_MBSTATE_T 468 /* Try to find out how many bytes made up the character that was 469 just printed. Advance the symbol pointer past the bytes that 470 were displayed. */ 471 n = mbrtowc (& w, symbol - 1, MB_CUR_MAX, & state); 472 #else 473 n = 1; 474 #endif 475 if (n != (size_t) -1 && n != (size_t) -2 && n > 0) 476 symbol += (n - 1); 477 } 478 } 479 480 if (extra_padding && num_printed < width) 481 { 482 /* Fill in the remaining spaces. */ 483 printf ("%-*s", width - num_printed, " "); 484 num_printed = width; 485 } 486 487 return num_printed; 488 } 489 490 /* Return a pointer to section NAME, or NULL if no such section exists. */ 491 492 static Elf_Internal_Shdr * 493 find_section (const char * name) 494 { 495 unsigned int i; 496 497 for (i = 0; i < elf_header.e_shnum; i++) 498 if (streq (SECTION_NAME (section_headers + i), name)) 499 return section_headers + i; 500 501 return NULL; 502 } 503 504 /* Return a pointer to a section containing ADDR, or NULL if no such 505 section exists. */ 506 507 static Elf_Internal_Shdr * 508 find_section_by_address (bfd_vma addr) 509 { 510 unsigned int i; 511 512 for (i = 0; i < elf_header.e_shnum; i++) 513 { 514 Elf_Internal_Shdr *sec = section_headers + i; 515 if (addr >= sec->sh_addr && addr < sec->sh_addr + sec->sh_size) 516 return sec; 517 } 518 519 return NULL; 520 } 521 522 /* Read an unsigned LEB128 encoded value from p. Set *PLEN to the number of 523 bytes read. */ 524 525 static unsigned long 526 read_uleb128 (unsigned char *data, unsigned int *length_return) 527 { 528 return read_leb128 (data, length_return, 0); 529 } 530 531 /* Return true if the current file is for IA-64 machine and OpenVMS ABI. 532 This OS has so many departures from the ELF standard that we test it at 533 many places. */ 534 535 static inline int 536 is_ia64_vms (void) 537 { 538 return elf_header.e_machine == EM_IA_64 539 && elf_header.e_ident[EI_OSABI] == ELFOSABI_OPENVMS; 540 } 541 542 /* Guess the relocation size commonly used by the specific machines. */ 543 544 static int 545 guess_is_rela (unsigned int e_machine) 546 { 547 switch (e_machine) 548 { 549 /* Targets that use REL relocations. */ 550 case EM_386: 551 case EM_486: 552 case EM_960: 553 case EM_ARM: 554 case EM_D10V: 555 case EM_CYGNUS_D10V: 556 case EM_DLX: 557 case EM_MIPS: 558 case EM_MIPS_RS3_LE: 559 case EM_CYGNUS_M32R: 560 case EM_OR1K: 561 case EM_SCORE: 562 case EM_XGATE: 563 return FALSE; 564 565 /* Targets that use RELA relocations. */ 566 case EM_68K: 567 case EM_860: 568 case EM_AARCH64: 569 case EM_ADAPTEVA_EPIPHANY: 570 case EM_ALPHA: 571 case EM_ALTERA_NIOS2: 572 case EM_AVR: 573 case EM_AVR_OLD: 574 case EM_BLACKFIN: 575 case EM_CR16: 576 case EM_CRIS: 577 case EM_CRX: 578 case EM_D30V: 579 case EM_CYGNUS_D30V: 580 case EM_FR30: 581 case EM_CYGNUS_FR30: 582 case EM_CYGNUS_FRV: 583 case EM_H8S: 584 case EM_H8_300: 585 case EM_H8_300H: 586 case EM_IA_64: 587 case EM_IP2K: 588 case EM_IP2K_OLD: 589 case EM_IQ2000: 590 case EM_LATTICEMICO32: 591 case EM_M32C_OLD: 592 case EM_M32C: 593 case EM_M32R: 594 case EM_MCORE: 595 case EM_CYGNUS_MEP: 596 case EM_MMIX: 597 case EM_MN10200: 598 case EM_CYGNUS_MN10200: 599 case EM_MN10300: 600 case EM_CYGNUS_MN10300: 601 case EM_MOXIE: 602 case EM_MSP430: 603 case EM_MSP430_OLD: 604 case EM_MT: 605 case EM_NIOS32: 606 case EM_PPC64: 607 case EM_PPC: 608 case EM_RISCV: 609 case EM_RL78: 610 case EM_RX: 611 case EM_S390: 612 case EM_S390_OLD: 613 case EM_SH: 614 case EM_SPARC: 615 case EM_SPARC32PLUS: 616 case EM_SPARCV9: 617 case EM_SPU: 618 case EM_TI_C6000: 619 case EM_TILEGX: 620 case EM_TILEPRO: 621 case EM_V850: 622 case EM_CYGNUS_V850: 623 case EM_VAX: 624 case EM_X86_64: 625 case EM_L1OM: 626 case EM_K1OM: 627 case EM_XSTORMY16: 628 case EM_XTENSA: 629 case EM_XTENSA_OLD: 630 case EM_MICROBLAZE: 631 case EM_MICROBLAZE_OLD: 632 return TRUE; 633 634 case EM_68HC05: 635 case EM_68HC08: 636 case EM_68HC11: 637 case EM_68HC16: 638 case EM_FX66: 639 case EM_ME16: 640 case EM_MMA: 641 case EM_NCPU: 642 case EM_NDR1: 643 case EM_PCP: 644 case EM_ST100: 645 case EM_ST19: 646 case EM_ST7: 647 case EM_ST9PLUS: 648 case EM_STARCORE: 649 case EM_SVX: 650 case EM_TINYJ: 651 default: 652 warn (_("Don't know about relocations on this machine architecture\n")); 653 return FALSE; 654 } 655 } 656 657 static int 658 slurp_rela_relocs (FILE * file, 659 unsigned long rel_offset, 660 unsigned long rel_size, 661 Elf_Internal_Rela ** relasp, 662 unsigned long * nrelasp) 663 { 664 Elf_Internal_Rela * relas; 665 unsigned long nrelas; 666 unsigned int i; 667 668 if (is_32bit_elf) 669 { 670 Elf32_External_Rela * erelas; 671 672 erelas = (Elf32_External_Rela *) get_data (NULL, file, rel_offset, 1, 673 rel_size, _("32-bit relocation data")); 674 if (!erelas) 675 return 0; 676 677 nrelas = rel_size / sizeof (Elf32_External_Rela); 678 679 relas = (Elf_Internal_Rela *) cmalloc (nrelas, 680 sizeof (Elf_Internal_Rela)); 681 682 if (relas == NULL) 683 { 684 free (erelas); 685 error (_("out of memory parsing relocs\n")); 686 return 0; 687 } 688 689 for (i = 0; i < nrelas; i++) 690 { 691 relas[i].r_offset = BYTE_GET (erelas[i].r_offset); 692 relas[i].r_info = BYTE_GET (erelas[i].r_info); 693 relas[i].r_addend = BYTE_GET_SIGNED (erelas[i].r_addend); 694 } 695 696 free (erelas); 697 } 698 else 699 { 700 Elf64_External_Rela * erelas; 701 702 erelas = (Elf64_External_Rela *) get_data (NULL, file, rel_offset, 1, 703 rel_size, _("64-bit relocation data")); 704 if (!erelas) 705 return 0; 706 707 nrelas = rel_size / sizeof (Elf64_External_Rela); 708 709 relas = (Elf_Internal_Rela *) cmalloc (nrelas, 710 sizeof (Elf_Internal_Rela)); 711 712 if (relas == NULL) 713 { 714 free (erelas); 715 error (_("out of memory parsing relocs\n")); 716 return 0; 717 } 718 719 for (i = 0; i < nrelas; i++) 720 { 721 relas[i].r_offset = BYTE_GET (erelas[i].r_offset); 722 relas[i].r_info = BYTE_GET (erelas[i].r_info); 723 relas[i].r_addend = BYTE_GET_SIGNED (erelas[i].r_addend); 724 725 /* The #ifdef BFD64 below is to prevent a compile time 726 warning. We know that if we do not have a 64 bit data 727 type that we will never execute this code anyway. */ 728 #ifdef BFD64 729 if (elf_header.e_machine == EM_MIPS 730 && elf_header.e_ident[EI_DATA] != ELFDATA2MSB) 731 { 732 /* In little-endian objects, r_info isn't really a 733 64-bit little-endian value: it has a 32-bit 734 little-endian symbol index followed by four 735 individual byte fields. Reorder INFO 736 accordingly. */ 737 bfd_vma inf = relas[i].r_info; 738 inf = (((inf & 0xffffffff) << 32) 739 | ((inf >> 56) & 0xff) 740 | ((inf >> 40) & 0xff00) 741 | ((inf >> 24) & 0xff0000) 742 | ((inf >> 8) & 0xff000000)); 743 relas[i].r_info = inf; 744 } 745 #endif /* BFD64 */ 746 } 747 748 free (erelas); 749 } 750 *relasp = relas; 751 *nrelasp = nrelas; 752 return 1; 753 } 754 755 static int 756 slurp_rel_relocs (FILE * file, 757 unsigned long rel_offset, 758 unsigned long rel_size, 759 Elf_Internal_Rela ** relsp, 760 unsigned long * nrelsp) 761 { 762 Elf_Internal_Rela * rels; 763 unsigned long nrels; 764 unsigned int i; 765 766 if (is_32bit_elf) 767 { 768 Elf32_External_Rel * erels; 769 770 erels = (Elf32_External_Rel *) get_data (NULL, file, rel_offset, 1, 771 rel_size, _("32-bit relocation data")); 772 if (!erels) 773 return 0; 774 775 nrels = rel_size / sizeof (Elf32_External_Rel); 776 777 rels = (Elf_Internal_Rela *) cmalloc (nrels, sizeof (Elf_Internal_Rela)); 778 779 if (rels == NULL) 780 { 781 free (erels); 782 error (_("out of memory parsing relocs\n")); 783 return 0; 784 } 785 786 for (i = 0; i < nrels; i++) 787 { 788 rels[i].r_offset = BYTE_GET (erels[i].r_offset); 789 rels[i].r_info = BYTE_GET (erels[i].r_info); 790 rels[i].r_addend = 0; 791 } 792 793 free (erels); 794 } 795 else 796 { 797 Elf64_External_Rel * erels; 798 799 erels = (Elf64_External_Rel *) get_data (NULL, file, rel_offset, 1, 800 rel_size, _("64-bit relocation data")); 801 if (!erels) 802 return 0; 803 804 nrels = rel_size / sizeof (Elf64_External_Rel); 805 806 rels = (Elf_Internal_Rela *) cmalloc (nrels, sizeof (Elf_Internal_Rela)); 807 808 if (rels == NULL) 809 { 810 free (erels); 811 error (_("out of memory parsing relocs\n")); 812 return 0; 813 } 814 815 for (i = 0; i < nrels; i++) 816 { 817 rels[i].r_offset = BYTE_GET (erels[i].r_offset); 818 rels[i].r_info = BYTE_GET (erels[i].r_info); 819 rels[i].r_addend = 0; 820 821 /* The #ifdef BFD64 below is to prevent a compile time 822 warning. We know that if we do not have a 64 bit data 823 type that we will never execute this code anyway. */ 824 #ifdef BFD64 825 if (elf_header.e_machine == EM_MIPS 826 && elf_header.e_ident[EI_DATA] != ELFDATA2MSB) 827 { 828 /* In little-endian objects, r_info isn't really a 829 64-bit little-endian value: it has a 32-bit 830 little-endian symbol index followed by four 831 individual byte fields. Reorder INFO 832 accordingly. */ 833 bfd_vma inf = rels[i].r_info; 834 inf = (((inf & 0xffffffff) << 32) 835 | ((inf >> 56) & 0xff) 836 | ((inf >> 40) & 0xff00) 837 | ((inf >> 24) & 0xff0000) 838 | ((inf >> 8) & 0xff000000)); 839 rels[i].r_info = inf; 840 } 841 #endif /* BFD64 */ 842 } 843 844 free (erels); 845 } 846 *relsp = rels; 847 *nrelsp = nrels; 848 return 1; 849 } 850 851 /* Returns the reloc type extracted from the reloc info field. */ 852 853 static unsigned int 854 get_reloc_type (bfd_vma reloc_info) 855 { 856 if (is_32bit_elf) 857 return ELF32_R_TYPE (reloc_info); 858 859 switch (elf_header.e_machine) 860 { 861 case EM_MIPS: 862 /* Note: We assume that reloc_info has already been adjusted for us. */ 863 return ELF64_MIPS_R_TYPE (reloc_info); 864 865 case EM_SPARCV9: 866 return ELF64_R_TYPE_ID (reloc_info); 867 868 default: 869 return ELF64_R_TYPE (reloc_info); 870 } 871 } 872 873 /* Return the symbol index extracted from the reloc info field. */ 874 875 static bfd_vma 876 get_reloc_symindex (bfd_vma reloc_info) 877 { 878 return is_32bit_elf ? ELF32_R_SYM (reloc_info) : ELF64_R_SYM (reloc_info); 879 } 880 881 /* Display the contents of the relocation data found at the specified 882 offset. */ 883 884 static void 885 dump_relocations (FILE * file, 886 unsigned long rel_offset, 887 unsigned long rel_size, 888 Elf_Internal_Sym * symtab, 889 unsigned long nsyms, 890 char * strtab, 891 unsigned long strtablen, 892 int is_rela) 893 { 894 unsigned int i; 895 Elf_Internal_Rela * rels; 896 897 if (is_rela == UNKNOWN) 898 is_rela = guess_is_rela (elf_header.e_machine); 899 900 if (is_rela) 901 { 902 if (!slurp_rela_relocs (file, rel_offset, rel_size, &rels, &rel_size)) 903 return; 904 } 905 else 906 { 907 if (!slurp_rel_relocs (file, rel_offset, rel_size, &rels, &rel_size)) 908 return; 909 } 910 911 if (is_32bit_elf) 912 { 913 if (is_rela) 914 { 915 if (do_wide) 916 printf (_(" Offset Info Type Sym. Value Symbol's Name + Addend\n")); 917 else 918 printf (_(" Offset Info Type Sym.Value Sym. Name + Addend\n")); 919 } 920 else 921 { 922 if (do_wide) 923 printf (_(" Offset Info Type Sym. Value Symbol's Name\n")); 924 else 925 printf (_(" Offset Info Type Sym.Value Sym. Name\n")); 926 } 927 } 928 else 929 { 930 if (is_rela) 931 { 932 if (do_wide) 933 printf (_(" Offset Info Type Symbol's Value Symbol's Name + Addend\n")); 934 else 935 printf (_(" Offset Info Type Sym. Value Sym. Name + Addend\n")); 936 } 937 else 938 { 939 if (do_wide) 940 printf (_(" Offset Info Type Symbol's Value Symbol's Name\n")); 941 else 942 printf (_(" Offset Info Type Sym. Value Sym. Name\n")); 943 } 944 } 945 946 for (i = 0; i < rel_size; i++) 947 { 948 const char * rtype; 949 bfd_vma offset; 950 bfd_vma inf; 951 bfd_vma symtab_index; 952 bfd_vma type; 953 954 offset = rels[i].r_offset; 955 inf = rels[i].r_info; 956 957 type = get_reloc_type (inf); 958 symtab_index = get_reloc_symindex (inf); 959 960 if (is_32bit_elf) 961 { 962 printf ("%8.8lx %8.8lx ", 963 (unsigned long) offset & 0xffffffff, 964 (unsigned long) inf & 0xffffffff); 965 } 966 else 967 { 968 #if BFD_HOST_64BIT_LONG 969 printf (do_wide 970 ? "%16.16lx %16.16lx " 971 : "%12.12lx %12.12lx ", 972 offset, inf); 973 #elif BFD_HOST_64BIT_LONG_LONG 974 #ifndef __MSVCRT__ 975 printf (do_wide 976 ? "%16.16llx %16.16llx " 977 : "%12.12llx %12.12llx ", 978 offset, inf); 979 #else 980 printf (do_wide 981 ? "%16.16I64x %16.16I64x " 982 : "%12.12I64x %12.12I64x ", 983 offset, inf); 984 #endif 985 #else 986 printf (do_wide 987 ? "%8.8lx%8.8lx %8.8lx%8.8lx " 988 : "%4.4lx%8.8lx %4.4lx%8.8lx ", 989 _bfd_int64_high (offset), 990 _bfd_int64_low (offset), 991 _bfd_int64_high (inf), 992 _bfd_int64_low (inf)); 993 #endif 994 } 995 996 switch (elf_header.e_machine) 997 { 998 default: 999 rtype = NULL; 1000 break; 1001 1002 case EM_AARCH64: 1003 rtype = elf_aarch64_reloc_type (type); 1004 break; 1005 1006 case EM_M32R: 1007 case EM_CYGNUS_M32R: 1008 rtype = elf_m32r_reloc_type (type); 1009 break; 1010 1011 case EM_386: 1012 case EM_486: 1013 rtype = elf_i386_reloc_type (type); 1014 break; 1015 1016 case EM_68HC11: 1017 case EM_68HC12: 1018 rtype = elf_m68hc11_reloc_type (type); 1019 break; 1020 1021 case EM_68K: 1022 rtype = elf_m68k_reloc_type (type); 1023 break; 1024 1025 case EM_960: 1026 rtype = elf_i960_reloc_type (type); 1027 break; 1028 1029 case EM_AVR: 1030 case EM_AVR_OLD: 1031 rtype = elf_avr_reloc_type (type); 1032 break; 1033 1034 case EM_OLD_SPARCV9: 1035 case EM_SPARC32PLUS: 1036 case EM_SPARCV9: 1037 case EM_SPARC: 1038 rtype = elf_sparc_reloc_type (type); 1039 break; 1040 1041 case EM_SPU: 1042 rtype = elf_spu_reloc_type (type); 1043 break; 1044 1045 case EM_V850: 1046 case EM_CYGNUS_V850: 1047 rtype = v850_reloc_type (type); 1048 break; 1049 1050 case EM_D10V: 1051 case EM_CYGNUS_D10V: 1052 rtype = elf_d10v_reloc_type (type); 1053 break; 1054 1055 case EM_D30V: 1056 case EM_CYGNUS_D30V: 1057 rtype = elf_d30v_reloc_type (type); 1058 break; 1059 1060 case EM_DLX: 1061 rtype = elf_dlx_reloc_type (type); 1062 break; 1063 1064 case EM_SH: 1065 rtype = elf_sh_reloc_type (type); 1066 break; 1067 1068 case EM_MN10300: 1069 case EM_CYGNUS_MN10300: 1070 rtype = elf_mn10300_reloc_type (type); 1071 break; 1072 1073 case EM_MN10200: 1074 case EM_CYGNUS_MN10200: 1075 rtype = elf_mn10200_reloc_type (type); 1076 break; 1077 1078 case EM_FR30: 1079 case EM_CYGNUS_FR30: 1080 rtype = elf_fr30_reloc_type (type); 1081 break; 1082 1083 case EM_CYGNUS_FRV: 1084 rtype = elf_frv_reloc_type (type); 1085 break; 1086 1087 case EM_MCORE: 1088 rtype = elf_mcore_reloc_type (type); 1089 break; 1090 1091 case EM_MMIX: 1092 rtype = elf_mmix_reloc_type (type); 1093 break; 1094 1095 case EM_MOXIE: 1096 rtype = elf_moxie_reloc_type (type); 1097 break; 1098 1099 case EM_MSP430: 1100 case EM_MSP430_OLD: 1101 rtype = elf_msp430_reloc_type (type); 1102 break; 1103 1104 case EM_PPC: 1105 rtype = elf_ppc_reloc_type (type); 1106 break; 1107 1108 case EM_PPC64: 1109 rtype = elf_ppc64_reloc_type (type); 1110 break; 1111 1112 case EM_MIPS: 1113 case EM_MIPS_RS3_LE: 1114 rtype = elf_mips_reloc_type (type); 1115 break; 1116 1117 case EM_ALPHA: 1118 rtype = elf_alpha_reloc_type (type); 1119 break; 1120 1121 case EM_ARM: 1122 rtype = elf_arm_reloc_type (type); 1123 break; 1124 1125 case EM_ARC: 1126 rtype = elf_arc_reloc_type (type); 1127 break; 1128 1129 case EM_PARISC: 1130 rtype = elf_hppa_reloc_type (type); 1131 break; 1132 1133 case EM_H8_300: 1134 case EM_H8_300H: 1135 case EM_H8S: 1136 rtype = elf_h8_reloc_type (type); 1137 break; 1138 1139 case EM_OR1K: 1140 rtype = elf_or1k_reloc_type (type); 1141 break; 1142 1143 case EM_PJ: 1144 case EM_PJ_OLD: 1145 rtype = elf_pj_reloc_type (type); 1146 break; 1147 case EM_IA_64: 1148 rtype = elf_ia64_reloc_type (type); 1149 break; 1150 1151 case EM_CRIS: 1152 rtype = elf_cris_reloc_type (type); 1153 break; 1154 1155 case EM_860: 1156 rtype = elf_i860_reloc_type (type); 1157 break; 1158 1159 case EM_X86_64: 1160 case EM_L1OM: 1161 case EM_K1OM: 1162 rtype = elf_x86_64_reloc_type (type); 1163 break; 1164 1165 case EM_S370: 1166 rtype = i370_reloc_type (type); 1167 break; 1168 1169 case EM_S390_OLD: 1170 case EM_S390: 1171 rtype = elf_s390_reloc_type (type); 1172 break; 1173 1174 case EM_SCORE: 1175 rtype = elf_score_reloc_type (type); 1176 break; 1177 1178 case EM_XSTORMY16: 1179 rtype = elf_xstormy16_reloc_type (type); 1180 break; 1181 1182 case EM_CRX: 1183 rtype = elf_crx_reloc_type (type); 1184 break; 1185 1186 case EM_VAX: 1187 rtype = elf_vax_reloc_type (type); 1188 break; 1189 1190 case EM_ADAPTEVA_EPIPHANY: 1191 rtype = elf_epiphany_reloc_type (type); 1192 break; 1193 1194 case EM_IP2K: 1195 case EM_IP2K_OLD: 1196 rtype = elf_ip2k_reloc_type (type); 1197 break; 1198 1199 case EM_IQ2000: 1200 rtype = elf_iq2000_reloc_type (type); 1201 break; 1202 1203 case EM_XTENSA_OLD: 1204 case EM_XTENSA: 1205 rtype = elf_xtensa_reloc_type (type); 1206 break; 1207 1208 case EM_LATTICEMICO32: 1209 rtype = elf_lm32_reloc_type (type); 1210 break; 1211 1212 case EM_M32C_OLD: 1213 case EM_M32C: 1214 rtype = elf_m32c_reloc_type (type); 1215 break; 1216 1217 case EM_MT: 1218 rtype = elf_mt_reloc_type (type); 1219 break; 1220 1221 case EM_BLACKFIN: 1222 rtype = elf_bfin_reloc_type (type); 1223 break; 1224 1225 case EM_CYGNUS_MEP: 1226 rtype = elf_mep_reloc_type (type); 1227 break; 1228 1229 case EM_CR16: 1230 rtype = elf_cr16_reloc_type (type); 1231 break; 1232 1233 case EM_MICROBLAZE: 1234 case EM_MICROBLAZE_OLD: 1235 rtype = elf_microblaze_reloc_type (type); 1236 break; 1237 1238 case EM_RISCV: 1239 rtype = elf_riscv_reloc_type (type); 1240 break; 1241 1242 case EM_RL78: 1243 rtype = elf_rl78_reloc_type (type); 1244 break; 1245 1246 case EM_RX: 1247 rtype = elf_rx_reloc_type (type); 1248 break; 1249 1250 case EM_XC16X: 1251 case EM_C166: 1252 rtype = elf_xc16x_reloc_type (type); 1253 break; 1254 1255 case EM_TI_C6000: 1256 rtype = elf_tic6x_reloc_type (type); 1257 break; 1258 1259 case EM_TILEGX: 1260 rtype = elf_tilegx_reloc_type (type); 1261 break; 1262 1263 case EM_TILEPRO: 1264 rtype = elf_tilepro_reloc_type (type); 1265 break; 1266 1267 case EM_XGATE: 1268 rtype = elf_xgate_reloc_type (type); 1269 break; 1270 } 1271 1272 if (rtype == NULL) 1273 printf (_("unrecognized: %-7lx"), (unsigned long) type & 0xffffffff); 1274 else 1275 printf (do_wide ? "%-22.22s" : "%-17.17s", rtype); 1276 1277 if (elf_header.e_machine == EM_ALPHA 1278 && rtype != NULL 1279 && streq (rtype, "R_ALPHA_LITUSE") 1280 && is_rela) 1281 { 1282 switch (rels[i].r_addend) 1283 { 1284 case LITUSE_ALPHA_ADDR: rtype = "ADDR"; break; 1285 case LITUSE_ALPHA_BASE: rtype = "BASE"; break; 1286 case LITUSE_ALPHA_BYTOFF: rtype = "BYTOFF"; break; 1287 case LITUSE_ALPHA_JSR: rtype = "JSR"; break; 1288 case LITUSE_ALPHA_TLSGD: rtype = "TLSGD"; break; 1289 case LITUSE_ALPHA_TLSLDM: rtype = "TLSLDM"; break; 1290 case LITUSE_ALPHA_JSRDIRECT: rtype = "JSRDIRECT"; break; 1291 default: rtype = NULL; 1292 } 1293 if (rtype) 1294 printf (" (%s)", rtype); 1295 else 1296 { 1297 putchar (' '); 1298 printf (_("<unknown addend: %lx>"), 1299 (unsigned long) rels[i].r_addend); 1300 } 1301 } 1302 else if (symtab_index) 1303 { 1304 if (symtab == NULL || symtab_index >= nsyms) 1305 printf (_(" bad symbol index: %08lx"), (unsigned long) symtab_index); 1306 else 1307 { 1308 Elf_Internal_Sym * psym; 1309 1310 psym = symtab + symtab_index; 1311 1312 printf (" "); 1313 1314 if (ELF_ST_TYPE (psym->st_info) == STT_GNU_IFUNC) 1315 { 1316 const char * name; 1317 unsigned int len; 1318 unsigned int width = is_32bit_elf ? 8 : 14; 1319 1320 /* Relocations against GNU_IFUNC symbols do not use the value 1321 of the symbol as the address to relocate against. Instead 1322 they invoke the function named by the symbol and use its 1323 result as the address for relocation. 1324 1325 To indicate this to the user, do not display the value of 1326 the symbol in the "Symbols's Value" field. Instead show 1327 its name followed by () as a hint that the symbol is 1328 invoked. */ 1329 1330 if (strtab == NULL 1331 || psym->st_name == 0 1332 || psym->st_name >= strtablen) 1333 name = "??"; 1334 else 1335 name = strtab + psym->st_name; 1336 1337 len = print_symbol (width, name); 1338 printf ("()%-*s", len <= width ? (width + 1) - len : 1, " "); 1339 } 1340 else 1341 { 1342 print_vma (psym->st_value, LONG_HEX); 1343 1344 printf (is_32bit_elf ? " " : " "); 1345 } 1346 1347 if (psym->st_name == 0) 1348 { 1349 const char * sec_name = "<null>"; 1350 char name_buf[40]; 1351 1352 if (ELF_ST_TYPE (psym->st_info) == STT_SECTION) 1353 { 1354 if (psym->st_shndx < elf_header.e_shnum) 1355 sec_name 1356 = SECTION_NAME (section_headers + psym->st_shndx); 1357 else if (psym->st_shndx == SHN_ABS) 1358 sec_name = "ABS"; 1359 else if (psym->st_shndx == SHN_COMMON) 1360 sec_name = "COMMON"; 1361 else if ((elf_header.e_machine == EM_MIPS 1362 && psym->st_shndx == SHN_MIPS_SCOMMON) 1363 || (elf_header.e_machine == EM_TI_C6000 1364 && psym->st_shndx == SHN_TIC6X_SCOMMON)) 1365 sec_name = "SCOMMON"; 1366 else if (elf_header.e_machine == EM_MIPS 1367 && psym->st_shndx == SHN_MIPS_SUNDEFINED) 1368 sec_name = "SUNDEF"; 1369 else if ((elf_header.e_machine == EM_X86_64 1370 || elf_header.e_machine == EM_L1OM 1371 || elf_header.e_machine == EM_K1OM) 1372 && psym->st_shndx == SHN_X86_64_LCOMMON) 1373 sec_name = "LARGE_COMMON"; 1374 else if (elf_header.e_machine == EM_IA_64 1375 && elf_header.e_ident[EI_OSABI] == ELFOSABI_HPUX 1376 && psym->st_shndx == SHN_IA_64_ANSI_COMMON) 1377 sec_name = "ANSI_COM"; 1378 else if (is_ia64_vms () 1379 && psym->st_shndx == SHN_IA_64_VMS_SYMVEC) 1380 sec_name = "VMS_SYMVEC"; 1381 else 1382 { 1383 sprintf (name_buf, "<section 0x%x>", 1384 (unsigned int) psym->st_shndx); 1385 sec_name = name_buf; 1386 } 1387 } 1388 print_symbol (22, sec_name); 1389 } 1390 else if (strtab == NULL) 1391 printf (_("<string table index: %3ld>"), psym->st_name); 1392 else if (psym->st_name >= strtablen) 1393 printf (_("<corrupt string table index: %3ld>"), psym->st_name); 1394 else 1395 print_symbol (22, strtab + psym->st_name); 1396 1397 if (is_rela) 1398 { 1399 bfd_signed_vma off = rels[i].r_addend; 1400 1401 if (off < 0) 1402 printf (" - %" BFD_VMA_FMT "x", - off); 1403 else 1404 printf (" + %" BFD_VMA_FMT "x", off); 1405 } 1406 } 1407 } 1408 else if (is_rela) 1409 { 1410 bfd_signed_vma off = rels[i].r_addend; 1411 1412 printf ("%*c", is_32bit_elf ? 12 : 20, ' '); 1413 if (off < 0) 1414 printf ("-%" BFD_VMA_FMT "x", - off); 1415 else 1416 printf ("%" BFD_VMA_FMT "x", off); 1417 } 1418 1419 if (elf_header.e_machine == EM_SPARCV9 1420 && rtype != NULL 1421 && streq (rtype, "R_SPARC_OLO10")) 1422 printf (" + %lx", (unsigned long) ELF64_R_TYPE_DATA (inf)); 1423 1424 putchar ('\n'); 1425 1426 #ifdef BFD64 1427 if (! is_32bit_elf && elf_header.e_machine == EM_MIPS) 1428 { 1429 bfd_vma type2 = ELF64_MIPS_R_TYPE2 (inf); 1430 bfd_vma type3 = ELF64_MIPS_R_TYPE3 (inf); 1431 const char * rtype2 = elf_mips_reloc_type (type2); 1432 const char * rtype3 = elf_mips_reloc_type (type3); 1433 1434 printf (" Type2: "); 1435 1436 if (rtype2 == NULL) 1437 printf (_("unrecognized: %-7lx"), 1438 (unsigned long) type2 & 0xffffffff); 1439 else 1440 printf ("%-17.17s", rtype2); 1441 1442 printf ("\n Type3: "); 1443 1444 if (rtype3 == NULL) 1445 printf (_("unrecognized: %-7lx"), 1446 (unsigned long) type3 & 0xffffffff); 1447 else 1448 printf ("%-17.17s", rtype3); 1449 1450 putchar ('\n'); 1451 } 1452 #endif /* BFD64 */ 1453 } 1454 1455 free (rels); 1456 } 1457 1458 static const char * 1459 get_mips_dynamic_type (unsigned long type) 1460 { 1461 switch (type) 1462 { 1463 case DT_MIPS_RLD_VERSION: return "MIPS_RLD_VERSION"; 1464 case DT_MIPS_TIME_STAMP: return "MIPS_TIME_STAMP"; 1465 case DT_MIPS_ICHECKSUM: return "MIPS_ICHECKSUM"; 1466 case DT_MIPS_IVERSION: return "MIPS_IVERSION"; 1467 case DT_MIPS_FLAGS: return "MIPS_FLAGS"; 1468 case DT_MIPS_BASE_ADDRESS: return "MIPS_BASE_ADDRESS"; 1469 case DT_MIPS_MSYM: return "MIPS_MSYM"; 1470 case DT_MIPS_CONFLICT: return "MIPS_CONFLICT"; 1471 case DT_MIPS_LIBLIST: return "MIPS_LIBLIST"; 1472 case DT_MIPS_LOCAL_GOTNO: return "MIPS_LOCAL_GOTNO"; 1473 case DT_MIPS_CONFLICTNO: return "MIPS_CONFLICTNO"; 1474 case DT_MIPS_LIBLISTNO: return "MIPS_LIBLISTNO"; 1475 case DT_MIPS_SYMTABNO: return "MIPS_SYMTABNO"; 1476 case DT_MIPS_UNREFEXTNO: return "MIPS_UNREFEXTNO"; 1477 case DT_MIPS_GOTSYM: return "MIPS_GOTSYM"; 1478 case DT_MIPS_HIPAGENO: return "MIPS_HIPAGENO"; 1479 case DT_MIPS_RLD_MAP: return "MIPS_RLD_MAP"; 1480 case DT_MIPS_DELTA_CLASS: return "MIPS_DELTA_CLASS"; 1481 case DT_MIPS_DELTA_CLASS_NO: return "MIPS_DELTA_CLASS_NO"; 1482 case DT_MIPS_DELTA_INSTANCE: return "MIPS_DELTA_INSTANCE"; 1483 case DT_MIPS_DELTA_INSTANCE_NO: return "MIPS_DELTA_INSTANCE_NO"; 1484 case DT_MIPS_DELTA_RELOC: return "MIPS_DELTA_RELOC"; 1485 case DT_MIPS_DELTA_RELOC_NO: return "MIPS_DELTA_RELOC_NO"; 1486 case DT_MIPS_DELTA_SYM: return "MIPS_DELTA_SYM"; 1487 case DT_MIPS_DELTA_SYM_NO: return "MIPS_DELTA_SYM_NO"; 1488 case DT_MIPS_DELTA_CLASSSYM: return "MIPS_DELTA_CLASSSYM"; 1489 case DT_MIPS_DELTA_CLASSSYM_NO: return "MIPS_DELTA_CLASSSYM_NO"; 1490 case DT_MIPS_CXX_FLAGS: return "MIPS_CXX_FLAGS"; 1491 case DT_MIPS_PIXIE_INIT: return "MIPS_PIXIE_INIT"; 1492 case DT_MIPS_SYMBOL_LIB: return "MIPS_SYMBOL_LIB"; 1493 case DT_MIPS_LOCALPAGE_GOTIDX: return "MIPS_LOCALPAGE_GOTIDX"; 1494 case DT_MIPS_LOCAL_GOTIDX: return "MIPS_LOCAL_GOTIDX"; 1495 case DT_MIPS_HIDDEN_GOTIDX: return "MIPS_HIDDEN_GOTIDX"; 1496 case DT_MIPS_PROTECTED_GOTIDX: return "MIPS_PROTECTED_GOTIDX"; 1497 case DT_MIPS_OPTIONS: return "MIPS_OPTIONS"; 1498 case DT_MIPS_INTERFACE: return "MIPS_INTERFACE"; 1499 case DT_MIPS_DYNSTR_ALIGN: return "MIPS_DYNSTR_ALIGN"; 1500 case DT_MIPS_INTERFACE_SIZE: return "MIPS_INTERFACE_SIZE"; 1501 case DT_MIPS_RLD_TEXT_RESOLVE_ADDR: return "MIPS_RLD_TEXT_RESOLVE_ADDR"; 1502 case DT_MIPS_PERF_SUFFIX: return "MIPS_PERF_SUFFIX"; 1503 case DT_MIPS_COMPACT_SIZE: return "MIPS_COMPACT_SIZE"; 1504 case DT_MIPS_GP_VALUE: return "MIPS_GP_VALUE"; 1505 case DT_MIPS_AUX_DYNAMIC: return "MIPS_AUX_DYNAMIC"; 1506 case DT_MIPS_PLTGOT: return "MIPS_PLTGOT"; 1507 case DT_MIPS_RWPLT: return "MIPS_RWPLT"; 1508 default: 1509 return NULL; 1510 } 1511 } 1512 1513 static const char * 1514 get_sparc64_dynamic_type (unsigned long type) 1515 { 1516 switch (type) 1517 { 1518 case DT_SPARC_REGISTER: return "SPARC_REGISTER"; 1519 default: 1520 return NULL; 1521 } 1522 } 1523 1524 static const char * 1525 get_ppc_dynamic_type (unsigned long type) 1526 { 1527 switch (type) 1528 { 1529 case DT_PPC_GOT: return "PPC_GOT"; 1530 case DT_PPC_TLSOPT: return "PPC_TLSOPT"; 1531 default: 1532 return NULL; 1533 } 1534 } 1535 1536 static const char * 1537 get_ppc64_dynamic_type (unsigned long type) 1538 { 1539 switch (type) 1540 { 1541 case DT_PPC64_GLINK: return "PPC64_GLINK"; 1542 case DT_PPC64_OPD: return "PPC64_OPD"; 1543 case DT_PPC64_OPDSZ: return "PPC64_OPDSZ"; 1544 case DT_PPC64_TLSOPT: return "PPC64_TLSOPT"; 1545 default: 1546 return NULL; 1547 } 1548 } 1549 1550 static const char * 1551 get_parisc_dynamic_type (unsigned long type) 1552 { 1553 switch (type) 1554 { 1555 case DT_HP_LOAD_MAP: return "HP_LOAD_MAP"; 1556 case DT_HP_DLD_FLAGS: return "HP_DLD_FLAGS"; 1557 case DT_HP_DLD_HOOK: return "HP_DLD_HOOK"; 1558 case DT_HP_UX10_INIT: return "HP_UX10_INIT"; 1559 case DT_HP_UX10_INITSZ: return "HP_UX10_INITSZ"; 1560 case DT_HP_PREINIT: return "HP_PREINIT"; 1561 case DT_HP_PREINITSZ: return "HP_PREINITSZ"; 1562 case DT_HP_NEEDED: return "HP_NEEDED"; 1563 case DT_HP_TIME_STAMP: return "HP_TIME_STAMP"; 1564 case DT_HP_CHECKSUM: return "HP_CHECKSUM"; 1565 case DT_HP_GST_SIZE: return "HP_GST_SIZE"; 1566 case DT_HP_GST_VERSION: return "HP_GST_VERSION"; 1567 case DT_HP_GST_HASHVAL: return "HP_GST_HASHVAL"; 1568 case DT_HP_EPLTREL: return "HP_GST_EPLTREL"; 1569 case DT_HP_EPLTRELSZ: return "HP_GST_EPLTRELSZ"; 1570 case DT_HP_FILTERED: return "HP_FILTERED"; 1571 case DT_HP_FILTER_TLS: return "HP_FILTER_TLS"; 1572 case DT_HP_COMPAT_FILTERED: return "HP_COMPAT_FILTERED"; 1573 case DT_HP_LAZYLOAD: return "HP_LAZYLOAD"; 1574 case DT_HP_BIND_NOW_COUNT: return "HP_BIND_NOW_COUNT"; 1575 case DT_PLT: return "PLT"; 1576 case DT_PLT_SIZE: return "PLT_SIZE"; 1577 case DT_DLT: return "DLT"; 1578 case DT_DLT_SIZE: return "DLT_SIZE"; 1579 default: 1580 return NULL; 1581 } 1582 } 1583 1584 static const char * 1585 get_ia64_dynamic_type (unsigned long type) 1586 { 1587 switch (type) 1588 { 1589 case DT_IA_64_PLT_RESERVE: return "IA_64_PLT_RESERVE"; 1590 case DT_IA_64_VMS_SUBTYPE: return "VMS_SUBTYPE"; 1591 case DT_IA_64_VMS_IMGIOCNT: return "VMS_IMGIOCNT"; 1592 case DT_IA_64_VMS_LNKFLAGS: return "VMS_LNKFLAGS"; 1593 case DT_IA_64_VMS_VIR_MEM_BLK_SIZ: return "VMS_VIR_MEM_BLK_SIZ"; 1594 case DT_IA_64_VMS_IDENT: return "VMS_IDENT"; 1595 case DT_IA_64_VMS_NEEDED_IDENT: return "VMS_NEEDED_IDENT"; 1596 case DT_IA_64_VMS_IMG_RELA_CNT: return "VMS_IMG_RELA_CNT"; 1597 case DT_IA_64_VMS_SEG_RELA_CNT: return "VMS_SEG_RELA_CNT"; 1598 case DT_IA_64_VMS_FIXUP_RELA_CNT: return "VMS_FIXUP_RELA_CNT"; 1599 case DT_IA_64_VMS_FIXUP_NEEDED: return "VMS_FIXUP_NEEDED"; 1600 case DT_IA_64_VMS_SYMVEC_CNT: return "VMS_SYMVEC_CNT"; 1601 case DT_IA_64_VMS_XLATED: return "VMS_XLATED"; 1602 case DT_IA_64_VMS_STACKSIZE: return "VMS_STACKSIZE"; 1603 case DT_IA_64_VMS_UNWINDSZ: return "VMS_UNWINDSZ"; 1604 case DT_IA_64_VMS_UNWIND_CODSEG: return "VMS_UNWIND_CODSEG"; 1605 case DT_IA_64_VMS_UNWIND_INFOSEG: return "VMS_UNWIND_INFOSEG"; 1606 case DT_IA_64_VMS_LINKTIME: return "VMS_LINKTIME"; 1607 case DT_IA_64_VMS_SEG_NO: return "VMS_SEG_NO"; 1608 case DT_IA_64_VMS_SYMVEC_OFFSET: return "VMS_SYMVEC_OFFSET"; 1609 case DT_IA_64_VMS_SYMVEC_SEG: return "VMS_SYMVEC_SEG"; 1610 case DT_IA_64_VMS_UNWIND_OFFSET: return "VMS_UNWIND_OFFSET"; 1611 case DT_IA_64_VMS_UNWIND_SEG: return "VMS_UNWIND_SEG"; 1612 case DT_IA_64_VMS_STRTAB_OFFSET: return "VMS_STRTAB_OFFSET"; 1613 case DT_IA_64_VMS_SYSVER_OFFSET: return "VMS_SYSVER_OFFSET"; 1614 case DT_IA_64_VMS_IMG_RELA_OFF: return "VMS_IMG_RELA_OFF"; 1615 case DT_IA_64_VMS_SEG_RELA_OFF: return "VMS_SEG_RELA_OFF"; 1616 case DT_IA_64_VMS_FIXUP_RELA_OFF: return "VMS_FIXUP_RELA_OFF"; 1617 case DT_IA_64_VMS_PLTGOT_OFFSET: return "VMS_PLTGOT_OFFSET"; 1618 case DT_IA_64_VMS_PLTGOT_SEG: return "VMS_PLTGOT_SEG"; 1619 case DT_IA_64_VMS_FPMODE: return "VMS_FPMODE"; 1620 default: 1621 return NULL; 1622 } 1623 } 1624 1625 static const char * 1626 get_alpha_dynamic_type (unsigned long type) 1627 { 1628 switch (type) 1629 { 1630 case DT_ALPHA_PLTRO: return "ALPHA_PLTRO"; 1631 default: 1632 return NULL; 1633 } 1634 } 1635 1636 static const char * 1637 get_score_dynamic_type (unsigned long type) 1638 { 1639 switch (type) 1640 { 1641 case DT_SCORE_BASE_ADDRESS: return "SCORE_BASE_ADDRESS"; 1642 case DT_SCORE_LOCAL_GOTNO: return "SCORE_LOCAL_GOTNO"; 1643 case DT_SCORE_SYMTABNO: return "SCORE_SYMTABNO"; 1644 case DT_SCORE_GOTSYM: return "SCORE_GOTSYM"; 1645 case DT_SCORE_UNREFEXTNO: return "SCORE_UNREFEXTNO"; 1646 case DT_SCORE_HIPAGENO: return "SCORE_HIPAGENO"; 1647 default: 1648 return NULL; 1649 } 1650 } 1651 1652 static const char * 1653 get_tic6x_dynamic_type (unsigned long type) 1654 { 1655 switch (type) 1656 { 1657 case DT_C6000_GSYM_OFFSET: return "C6000_GSYM_OFFSET"; 1658 case DT_C6000_GSTR_OFFSET: return "C6000_GSTR_OFFSET"; 1659 case DT_C6000_DSBT_BASE: return "C6000_DSBT_BASE"; 1660 case DT_C6000_DSBT_SIZE: return "C6000_DSBT_SIZE"; 1661 case DT_C6000_PREEMPTMAP: return "C6000_PREEMPTMAP"; 1662 case DT_C6000_DSBT_INDEX: return "C6000_DSBT_INDEX"; 1663 default: 1664 return NULL; 1665 } 1666 } 1667 1668 static const char * 1669 get_dynamic_type (unsigned long type) 1670 { 1671 static char buff[64]; 1672 1673 switch (type) 1674 { 1675 case DT_NULL: return "NULL"; 1676 case DT_NEEDED: return "NEEDED"; 1677 case DT_PLTRELSZ: return "PLTRELSZ"; 1678 case DT_PLTGOT: return "PLTGOT"; 1679 case DT_HASH: return "HASH"; 1680 case DT_STRTAB: return "STRTAB"; 1681 case DT_SYMTAB: return "SYMTAB"; 1682 case DT_RELA: return "RELA"; 1683 case DT_RELASZ: return "RELASZ"; 1684 case DT_RELAENT: return "RELAENT"; 1685 case DT_STRSZ: return "STRSZ"; 1686 case DT_SYMENT: return "SYMENT"; 1687 case DT_INIT: return "INIT"; 1688 case DT_FINI: return "FINI"; 1689 case DT_SONAME: return "SONAME"; 1690 case DT_RPATH: return "RPATH"; 1691 case DT_SYMBOLIC: return "SYMBOLIC"; 1692 case DT_REL: return "REL"; 1693 case DT_RELSZ: return "RELSZ"; 1694 case DT_RELENT: return "RELENT"; 1695 case DT_PLTREL: return "PLTREL"; 1696 case DT_DEBUG: return "DEBUG"; 1697 case DT_TEXTREL: return "TEXTREL"; 1698 case DT_JMPREL: return "JMPREL"; 1699 case DT_BIND_NOW: return "BIND_NOW"; 1700 case DT_INIT_ARRAY: return "INIT_ARRAY"; 1701 case DT_FINI_ARRAY: return "FINI_ARRAY"; 1702 case DT_INIT_ARRAYSZ: return "INIT_ARRAYSZ"; 1703 case DT_FINI_ARRAYSZ: return "FINI_ARRAYSZ"; 1704 case DT_RUNPATH: return "RUNPATH"; 1705 case DT_FLAGS: return "FLAGS"; 1706 1707 case DT_PREINIT_ARRAY: return "PREINIT_ARRAY"; 1708 case DT_PREINIT_ARRAYSZ: return "PREINIT_ARRAYSZ"; 1709 1710 case DT_CHECKSUM: return "CHECKSUM"; 1711 case DT_PLTPADSZ: return "PLTPADSZ"; 1712 case DT_MOVEENT: return "MOVEENT"; 1713 case DT_MOVESZ: return "MOVESZ"; 1714 case DT_FEATURE: return "FEATURE"; 1715 case DT_POSFLAG_1: return "POSFLAG_1"; 1716 case DT_SYMINSZ: return "SYMINSZ"; 1717 case DT_SYMINENT: return "SYMINENT"; /* aka VALRNGHI */ 1718 1719 case DT_ADDRRNGLO: return "ADDRRNGLO"; 1720 case DT_CONFIG: return "CONFIG"; 1721 case DT_DEPAUDIT: return "DEPAUDIT"; 1722 case DT_AUDIT: return "AUDIT"; 1723 case DT_PLTPAD: return "PLTPAD"; 1724 case DT_MOVETAB: return "MOVETAB"; 1725 case DT_SYMINFO: return "SYMINFO"; /* aka ADDRRNGHI */ 1726 1727 case DT_VERSYM: return "VERSYM"; 1728 1729 case DT_TLSDESC_GOT: return "TLSDESC_GOT"; 1730 case DT_TLSDESC_PLT: return "TLSDESC_PLT"; 1731 case DT_RELACOUNT: return "RELACOUNT"; 1732 case DT_RELCOUNT: return "RELCOUNT"; 1733 case DT_FLAGS_1: return "FLAGS_1"; 1734 case DT_VERDEF: return "VERDEF"; 1735 case DT_VERDEFNUM: return "VERDEFNUM"; 1736 case DT_VERNEED: return "VERNEED"; 1737 case DT_VERNEEDNUM: return "VERNEEDNUM"; 1738 1739 case DT_AUXILIARY: return "AUXILIARY"; 1740 case DT_USED: return "USED"; 1741 case DT_FILTER: return "FILTER"; 1742 1743 case DT_GNU_PRELINKED: return "GNU_PRELINKED"; 1744 case DT_GNU_CONFLICT: return "GNU_CONFLICT"; 1745 case DT_GNU_CONFLICTSZ: return "GNU_CONFLICTSZ"; 1746 case DT_GNU_LIBLIST: return "GNU_LIBLIST"; 1747 case DT_GNU_LIBLISTSZ: return "GNU_LIBLISTSZ"; 1748 case DT_GNU_HASH: return "GNU_HASH"; 1749 1750 default: 1751 if ((type >= DT_LOPROC) && (type <= DT_HIPROC)) 1752 { 1753 const char * result; 1754 1755 switch (elf_header.e_machine) 1756 { 1757 case EM_MIPS: 1758 case EM_MIPS_RS3_LE: 1759 result = get_mips_dynamic_type (type); 1760 break; 1761 case EM_SPARCV9: 1762 result = get_sparc64_dynamic_type (type); 1763 break; 1764 case EM_PPC: 1765 result = get_ppc_dynamic_type (type); 1766 break; 1767 case EM_PPC64: 1768 result = get_ppc64_dynamic_type (type); 1769 break; 1770 case EM_IA_64: 1771 result = get_ia64_dynamic_type (type); 1772 break; 1773 case EM_ALPHA: 1774 result = get_alpha_dynamic_type (type); 1775 break; 1776 case EM_SCORE: 1777 result = get_score_dynamic_type (type); 1778 break; 1779 case EM_TI_C6000: 1780 result = get_tic6x_dynamic_type (type); 1781 break; 1782 default: 1783 result = NULL; 1784 break; 1785 } 1786 1787 if (result != NULL) 1788 return result; 1789 1790 snprintf (buff, sizeof (buff), _("Processor Specific: %lx"), type); 1791 } 1792 else if (((type >= DT_LOOS) && (type <= DT_HIOS)) 1793 || (elf_header.e_machine == EM_PARISC 1794 && (type >= OLD_DT_LOOS) && (type <= OLD_DT_HIOS))) 1795 { 1796 const char * result; 1797 1798 switch (elf_header.e_machine) 1799 { 1800 case EM_PARISC: 1801 result = get_parisc_dynamic_type (type); 1802 break; 1803 case EM_IA_64: 1804 result = get_ia64_dynamic_type (type); 1805 break; 1806 default: 1807 result = NULL; 1808 break; 1809 } 1810 1811 if (result != NULL) 1812 return result; 1813 1814 snprintf (buff, sizeof (buff), _("Operating System specific: %lx"), 1815 type); 1816 } 1817 else 1818 snprintf (buff, sizeof (buff), _("<unknown>: %lx"), type); 1819 1820 return buff; 1821 } 1822 } 1823 1824 static char * 1825 get_file_type (unsigned e_type) 1826 { 1827 static char buff[32]; 1828 1829 switch (e_type) 1830 { 1831 case ET_NONE: return _("NONE (None)"); 1832 case ET_REL: return _("REL (Relocatable file)"); 1833 case ET_EXEC: return _("EXEC (Executable file)"); 1834 case ET_DYN: return _("DYN (Shared object file)"); 1835 case ET_CORE: return _("CORE (Core file)"); 1836 1837 default: 1838 if ((e_type >= ET_LOPROC) && (e_type <= ET_HIPROC)) 1839 snprintf (buff, sizeof (buff), _("Processor Specific: (%x)"), e_type); 1840 else if ((e_type >= ET_LOOS) && (e_type <= ET_HIOS)) 1841 snprintf (buff, sizeof (buff), _("OS Specific: (%x)"), e_type); 1842 else 1843 snprintf (buff, sizeof (buff), _("<unknown>: %x"), e_type); 1844 return buff; 1845 } 1846 } 1847 1848 static char * 1849 get_machine_name (unsigned e_machine) 1850 { 1851 static char buff[64]; /* XXX */ 1852 1853 switch (e_machine) 1854 { 1855 case EM_NONE: return _("None"); 1856 case EM_AARCH64: return "AArch64"; 1857 case EM_M32: return "WE32100"; 1858 case EM_SPARC: return "Sparc"; 1859 case EM_SPU: return "SPU"; 1860 case EM_386: return "Intel 80386"; 1861 case EM_68K: return "MC68000"; 1862 case EM_88K: return "MC88000"; 1863 case EM_486: return "Intel 80486"; 1864 case EM_860: return "Intel 80860"; 1865 case EM_MIPS: return "MIPS R3000"; 1866 case EM_S370: return "IBM System/370"; 1867 case EM_MIPS_RS3_LE: return "MIPS R4000 big-endian"; 1868 case EM_OLD_SPARCV9: return "Sparc v9 (old)"; 1869 case EM_PARISC: return "HPPA"; 1870 case EM_PPC_OLD: return "Power PC (old)"; 1871 case EM_SPARC32PLUS: return "Sparc v8+" ; 1872 case EM_960: return "Intel 90860"; 1873 case EM_PPC: return "PowerPC"; 1874 case EM_PPC64: return "PowerPC64"; 1875 case EM_V800: return "NEC V800"; 1876 case EM_FR20: return "Fujitsu FR20"; 1877 case EM_RH32: return "TRW RH32"; 1878 case EM_MCORE: return "MCORE"; 1879 case EM_ARM: return "ARM"; 1880 case EM_OLD_ALPHA: return "Digital Alpha (old)"; 1881 case EM_SH: return "Renesas / SuperH SH"; 1882 case EM_SPARCV9: return "Sparc v9"; 1883 case EM_TRICORE: return "Siemens Tricore"; 1884 case EM_ARC: return "ARC"; 1885 case EM_H8_300: return "Renesas H8/300"; 1886 case EM_H8_300H: return "Renesas H8/300H"; 1887 case EM_H8S: return "Renesas H8S"; 1888 case EM_H8_500: return "Renesas H8/500"; 1889 case EM_IA_64: return "Intel IA-64"; 1890 case EM_MIPS_X: return "Stanford MIPS-X"; 1891 case EM_COLDFIRE: return "Motorola Coldfire"; 1892 case EM_ALPHA: return "Alpha"; 1893 case EM_CYGNUS_D10V: 1894 case EM_D10V: return "d10v"; 1895 case EM_CYGNUS_D30V: 1896 case EM_D30V: return "d30v"; 1897 case EM_CYGNUS_M32R: 1898 case EM_M32R: return "Renesas M32R (formerly Mitsubishi M32r)"; 1899 case EM_CYGNUS_V850: 1900 case EM_V850: return "Renesas V850"; 1901 case EM_CYGNUS_MN10300: 1902 case EM_MN10300: return "mn10300"; 1903 case EM_CYGNUS_MN10200: 1904 case EM_MN10200: return "mn10200"; 1905 case EM_MOXIE: return "Moxie"; 1906 case EM_CYGNUS_FR30: 1907 case EM_FR30: return "Fujitsu FR30"; 1908 case EM_CYGNUS_FRV: return "Fujitsu FR-V"; 1909 case EM_PJ_OLD: 1910 case EM_PJ: return "picoJava"; 1911 case EM_MMA: return "Fujitsu Multimedia Accelerator"; 1912 case EM_PCP: return "Siemens PCP"; 1913 case EM_NCPU: return "Sony nCPU embedded RISC processor"; 1914 case EM_NDR1: return "Denso NDR1 microprocesspr"; 1915 case EM_STARCORE: return "Motorola Star*Core processor"; 1916 case EM_ME16: return "Toyota ME16 processor"; 1917 case EM_ST100: return "STMicroelectronics ST100 processor"; 1918 case EM_TINYJ: return "Advanced Logic Corp. TinyJ embedded processor"; 1919 case EM_PDSP: return "Sony DSP processor"; 1920 case EM_PDP10: return "Digital Equipment Corp. PDP-10"; 1921 case EM_PDP11: return "Digital Equipment Corp. PDP-11"; 1922 case EM_FX66: return "Siemens FX66 microcontroller"; 1923 case EM_ST9PLUS: return "STMicroelectronics ST9+ 8/16 bit microcontroller"; 1924 case EM_ST7: return "STMicroelectronics ST7 8-bit microcontroller"; 1925 case EM_68HC16: return "Motorola MC68HC16 Microcontroller"; 1926 case EM_68HC12: return "Motorola MC68HC12 Microcontroller"; 1927 case EM_68HC11: return "Motorola MC68HC11 Microcontroller"; 1928 case EM_68HC08: return "Motorola MC68HC08 Microcontroller"; 1929 case EM_68HC05: return "Motorola MC68HC05 Microcontroller"; 1930 case EM_SVX: return "Silicon Graphics SVx"; 1931 case EM_ST19: return "STMicroelectronics ST19 8-bit microcontroller"; 1932 case EM_VAX: return "Digital VAX"; 1933 case EM_AVR_OLD: 1934 case EM_AVR: return "Atmel AVR 8-bit microcontroller"; 1935 case EM_CRIS: return "Axis Communications 32-bit embedded processor"; 1936 case EM_JAVELIN: return "Infineon Technologies 32-bit embedded cpu"; 1937 case EM_FIREPATH: return "Element 14 64-bit DSP processor"; 1938 case EM_ZSP: return "LSI Logic's 16-bit DSP processor"; 1939 case EM_MMIX: return "Donald Knuth's educational 64-bit processor"; 1940 case EM_HUANY: return "Harvard Universitys's machine-independent object format"; 1941 case EM_PRISM: return "Vitesse Prism"; 1942 case EM_X86_64: return "Advanced Micro Devices X86-64"; 1943 case EM_L1OM: return "Intel L1OM"; 1944 case EM_K1OM: return "Intel K1OM"; 1945 case EM_S390_OLD: 1946 case EM_S390: return "IBM S/390"; 1947 case EM_SCORE: return "SUNPLUS S+Core"; 1948 case EM_XSTORMY16: return "Sanyo XStormy16 CPU core"; 1949 case EM_OR1K: return "OpenRISC"; 1950 case EM_ARC_A5: return "ARC International ARCompact processor"; 1951 case EM_CRX: return "National Semiconductor CRX microprocessor"; 1952 case EM_ADAPTEVA_EPIPHANY: return "Adapteva EPIPHANY"; 1953 case EM_DLX: return "OpenDLX"; 1954 case EM_IP2K_OLD: 1955 case EM_IP2K: return "Ubicom IP2xxx 8-bit microcontrollers"; 1956 case EM_IQ2000: return "Vitesse IQ2000"; 1957 case EM_XTENSA_OLD: 1958 case EM_XTENSA: return "Tensilica Xtensa Processor"; 1959 case EM_VIDEOCORE: return "Alphamosaic VideoCore processor"; 1960 case EM_TMM_GPP: return "Thompson Multimedia General Purpose Processor"; 1961 case EM_NS32K: return "National Semiconductor 32000 series"; 1962 case EM_TPC: return "Tenor Network TPC processor"; 1963 case EM_ST200: return "STMicroelectronics ST200 microcontroller"; 1964 case EM_MAX: return "MAX Processor"; 1965 case EM_CR: return "National Semiconductor CompactRISC"; 1966 case EM_F2MC16: return "Fujitsu F2MC16"; 1967 case EM_MSP430: return "Texas Instruments msp430 microcontroller"; 1968 case EM_LATTICEMICO32: return "Lattice Mico32"; 1969 case EM_M32C_OLD: 1970 case EM_M32C: return "Renesas M32c"; 1971 case EM_MT: return "Morpho Techologies MT processor"; 1972 case EM_BLACKFIN: return "Analog Devices Blackfin"; 1973 case EM_SE_C33: return "S1C33 Family of Seiko Epson processors"; 1974 case EM_SEP: return "Sharp embedded microprocessor"; 1975 case EM_ARCA: return "Arca RISC microprocessor"; 1976 case EM_UNICORE: return "Unicore"; 1977 case EM_EXCESS: return "eXcess 16/32/64-bit configurable embedded CPU"; 1978 case EM_DXP: return "Icera Semiconductor Inc. Deep Execution Processor"; 1979 case EM_NIOS32: return "Altera Nios"; 1980 case EM_ALTERA_NIOS2: return "Altera Nios II"; 1981 case EM_C166: 1982 case EM_XC16X: return "Infineon Technologies xc16x"; 1983 case EM_M16C: return "Renesas M16C series microprocessors"; 1984 case EM_DSPIC30F: return "Microchip Technology dsPIC30F Digital Signal Controller"; 1985 case EM_CE: return "Freescale Communication Engine RISC core"; 1986 case EM_TSK3000: return "Altium TSK3000 core"; 1987 case EM_RS08: return "Freescale RS08 embedded processor"; 1988 case EM_ECOG2: return "Cyan Technology eCOG2 microprocessor"; 1989 case EM_DSP24: return "New Japan Radio (NJR) 24-bit DSP Processor"; 1990 case EM_VIDEOCORE3: return "Broadcom VideoCore III processor"; 1991 case EM_SE_C17: return "Seiko Epson C17 family"; 1992 case EM_TI_C6000: return "Texas Instruments TMS320C6000 DSP family"; 1993 case EM_TI_C2000: return "Texas Instruments TMS320C2000 DSP family"; 1994 case EM_TI_C5500: return "Texas Instruments TMS320C55x DSP family"; 1995 case EM_MMDSP_PLUS: return "STMicroelectronics 64bit VLIW Data Signal Processor"; 1996 case EM_CYPRESS_M8C: return "Cypress M8C microprocessor"; 1997 case EM_R32C: return "Renesas R32C series microprocessors"; 1998 case EM_TRIMEDIA: return "NXP Semiconductors TriMedia architecture family"; 1999 case EM_QDSP6: return "QUALCOMM DSP6 Processor"; 2000 case EM_8051: return "Intel 8051 and variants"; 2001 case EM_STXP7X: return "STMicroelectronics STxP7x family"; 2002 case EM_NDS32: return "Andes Technology compact code size embedded RISC processor family"; 2003 case EM_ECOG1X: return "Cyan Technology eCOG1X family"; 2004 case EM_MAXQ30: return "Dallas Semiconductor MAXQ30 Core microcontrollers"; 2005 case EM_XIMO16: return "New Japan Radio (NJR) 16-bit DSP Processor"; 2006 case EM_MANIK: return "M2000 Reconfigurable RISC Microprocessor"; 2007 case EM_CRAYNV2: return "Cray Inc. NV2 vector architecture"; 2008 case EM_CYGNUS_MEP: return "Toshiba MeP Media Engine"; 2009 case EM_CR16: 2010 case EM_MICROBLAZE: 2011 case EM_MICROBLAZE_OLD: return "Xilinx MicroBlaze"; 2012 case EM_RISCV: return "RISC-V"; 2013 case EM_RL78: return "Renesas RL78"; 2014 case EM_RX: return "Renesas RX"; 2015 case EM_METAG: return "Imagination Technologies META processor architecture"; 2016 case EM_MCST_ELBRUS: return "MCST Elbrus general purpose hardware architecture"; 2017 case EM_ECOG16: return "Cyan Technology eCOG16 family"; 2018 case EM_ETPU: return "Freescale Extended Time Processing Unit"; 2019 case EM_SLE9X: return "Infineon Technologies SLE9X core"; 2020 case EM_AVR32: return "Atmel Corporation 32-bit microprocessor family"; 2021 case EM_STM8: return "STMicroeletronics STM8 8-bit microcontroller"; 2022 case EM_TILE64: return "Tilera TILE64 multicore architecture family"; 2023 case EM_TILEPRO: return "Tilera TILEPro multicore architecture family"; 2024 case EM_TILEGX: return "Tilera TILE-Gx multicore architecture family"; 2025 case EM_CUDA: return "NVIDIA CUDA architecture"; 2026 case EM_XGATE: return "Motorola XGATE embedded processor"; 2027 default: 2028 snprintf (buff, sizeof (buff), _("<unknown>: 0x%x"), e_machine); 2029 return buff; 2030 } 2031 } 2032 2033 static void 2034 decode_ARM_machine_flags (unsigned e_flags, char buf[]) 2035 { 2036 unsigned eabi; 2037 int unknown = 0; 2038 2039 eabi = EF_ARM_EABI_VERSION (e_flags); 2040 e_flags &= ~ EF_ARM_EABIMASK; 2041 2042 /* Handle "generic" ARM flags. */ 2043 if (e_flags & EF_ARM_RELEXEC) 2044 { 2045 strcat (buf, ", relocatable executable"); 2046 e_flags &= ~ EF_ARM_RELEXEC; 2047 } 2048 2049 if (e_flags & EF_ARM_HASENTRY) 2050 { 2051 strcat (buf, ", has entry point"); 2052 e_flags &= ~ EF_ARM_HASENTRY; 2053 } 2054 2055 /* Now handle EABI specific flags. */ 2056 switch (eabi) 2057 { 2058 default: 2059 strcat (buf, ", <unrecognized EABI>"); 2060 if (e_flags) 2061 unknown = 1; 2062 break; 2063 2064 case EF_ARM_EABI_VER1: 2065 strcat (buf, ", Version1 EABI"); 2066 while (e_flags) 2067 { 2068 unsigned flag; 2069 2070 /* Process flags one bit at a time. */ 2071 flag = e_flags & - e_flags; 2072 e_flags &= ~ flag; 2073 2074 switch (flag) 2075 { 2076 case EF_ARM_SYMSARESORTED: /* Conflicts with EF_ARM_INTERWORK. */ 2077 strcat (buf, ", sorted symbol tables"); 2078 break; 2079 2080 default: 2081 unknown = 1; 2082 break; 2083 } 2084 } 2085 break; 2086 2087 case EF_ARM_EABI_VER2: 2088 strcat (buf, ", Version2 EABI"); 2089 while (e_flags) 2090 { 2091 unsigned flag; 2092 2093 /* Process flags one bit at a time. */ 2094 flag = e_flags & - e_flags; 2095 e_flags &= ~ flag; 2096 2097 switch (flag) 2098 { 2099 case EF_ARM_SYMSARESORTED: /* Conflicts with EF_ARM_INTERWORK. */ 2100 strcat (buf, ", sorted symbol tables"); 2101 break; 2102 2103 case EF_ARM_DYNSYMSUSESEGIDX: 2104 strcat (buf, ", dynamic symbols use segment index"); 2105 break; 2106 2107 case EF_ARM_MAPSYMSFIRST: 2108 strcat (buf, ", mapping symbols precede others"); 2109 break; 2110 2111 default: 2112 unknown = 1; 2113 break; 2114 } 2115 } 2116 break; 2117 2118 case EF_ARM_EABI_VER3: 2119 strcat (buf, ", Version3 EABI"); 2120 break; 2121 2122 case EF_ARM_EABI_VER4: 2123 strcat (buf, ", Version4 EABI"); 2124 goto eabi; 2125 2126 case EF_ARM_EABI_VER5: 2127 strcat (buf, ", Version5 EABI"); 2128 eabi: 2129 while (e_flags) 2130 { 2131 unsigned flag; 2132 2133 /* Process flags one bit at a time. */ 2134 flag = e_flags & - e_flags; 2135 e_flags &= ~ flag; 2136 2137 switch (flag) 2138 { 2139 case EF_ARM_BE8: 2140 strcat (buf, ", BE8"); 2141 break; 2142 2143 case EF_ARM_LE8: 2144 strcat (buf, ", LE8"); 2145 break; 2146 2147 default: 2148 unknown = 1; 2149 break; 2150 } 2151 } 2152 break; 2153 2154 case EF_ARM_EABI_UNKNOWN: 2155 strcat (buf, ", GNU EABI"); 2156 while (e_flags) 2157 { 2158 unsigned flag; 2159 2160 /* Process flags one bit at a time. */ 2161 flag = e_flags & - e_flags; 2162 e_flags &= ~ flag; 2163 2164 switch (flag) 2165 { 2166 case EF_ARM_INTERWORK: 2167 strcat (buf, ", interworking enabled"); 2168 break; 2169 2170 case EF_ARM_APCS_26: 2171 strcat (buf, ", uses APCS/26"); 2172 break; 2173 2174 case EF_ARM_APCS_FLOAT: 2175 strcat (buf, ", uses APCS/float"); 2176 break; 2177 2178 case EF_ARM_PIC: 2179 strcat (buf, ", position independent"); 2180 break; 2181 2182 case EF_ARM_ALIGN8: 2183 strcat (buf, ", 8 bit structure alignment"); 2184 break; 2185 2186 case EF_ARM_NEW_ABI: 2187 strcat (buf, ", uses new ABI"); 2188 break; 2189 2190 case EF_ARM_OLD_ABI: 2191 strcat (buf, ", uses old ABI"); 2192 break; 2193 2194 case EF_ARM_SOFT_FLOAT: 2195 strcat (buf, ", software FP"); 2196 break; 2197 2198 case EF_ARM_VFP_FLOAT: 2199 strcat (buf, ", VFP"); 2200 break; 2201 2202 case EF_ARM_MAVERICK_FLOAT: 2203 strcat (buf, ", Maverick FP"); 2204 break; 2205 2206 default: 2207 unknown = 1; 2208 break; 2209 } 2210 } 2211 } 2212 2213 if (unknown) 2214 strcat (buf,_(", <unknown>")); 2215 } 2216 2217 static char * 2218 get_machine_flags (unsigned e_flags, unsigned e_machine) 2219 { 2220 static char buf[1024]; 2221 2222 buf[0] = '\0'; 2223 2224 if (e_flags) 2225 { 2226 switch (e_machine) 2227 { 2228 default: 2229 break; 2230 2231 case EM_ARM: 2232 decode_ARM_machine_flags (e_flags, buf); 2233 break; 2234 2235 case EM_BLACKFIN: 2236 if (e_flags & EF_BFIN_PIC) 2237 strcat (buf, ", PIC"); 2238 2239 if (e_flags & EF_BFIN_FDPIC) 2240 strcat (buf, ", FDPIC"); 2241 2242 if (e_flags & EF_BFIN_CODE_IN_L1) 2243 strcat (buf, ", code in L1"); 2244 2245 if (e_flags & EF_BFIN_DATA_IN_L1) 2246 strcat (buf, ", data in L1"); 2247 2248 break; 2249 2250 case EM_CYGNUS_FRV: 2251 switch (e_flags & EF_FRV_CPU_MASK) 2252 { 2253 case EF_FRV_CPU_GENERIC: 2254 break; 2255 2256 default: 2257 strcat (buf, ", fr???"); 2258 break; 2259 2260 case EF_FRV_CPU_FR300: 2261 strcat (buf, ", fr300"); 2262 break; 2263 2264 case EF_FRV_CPU_FR400: 2265 strcat (buf, ", fr400"); 2266 break; 2267 case EF_FRV_CPU_FR405: 2268 strcat (buf, ", fr405"); 2269 break; 2270 2271 case EF_FRV_CPU_FR450: 2272 strcat (buf, ", fr450"); 2273 break; 2274 2275 case EF_FRV_CPU_FR500: 2276 strcat (buf, ", fr500"); 2277 break; 2278 case EF_FRV_CPU_FR550: 2279 strcat (buf, ", fr550"); 2280 break; 2281 2282 case EF_FRV_CPU_SIMPLE: 2283 strcat (buf, ", simple"); 2284 break; 2285 case EF_FRV_CPU_TOMCAT: 2286 strcat (buf, ", tomcat"); 2287 break; 2288 } 2289 break; 2290 2291 case EM_68K: 2292 if ((e_flags & EF_M68K_ARCH_MASK) == EF_M68K_M68000) 2293 strcat (buf, ", m68000"); 2294 else if ((e_flags & EF_M68K_ARCH_MASK) == EF_M68K_CPU32) 2295 strcat (buf, ", cpu32"); 2296 else if ((e_flags & EF_M68K_ARCH_MASK) == EF_M68K_FIDO) 2297 strcat (buf, ", fido_a"); 2298 else 2299 { 2300 char const * isa = _("unknown"); 2301 char const * mac = _("unknown mac"); 2302 char const * additional = NULL; 2303 2304 switch (e_flags & EF_M68K_CF_ISA_MASK) 2305 { 2306 case EF_M68K_CF_ISA_A_NODIV: 2307 isa = "A"; 2308 additional = ", nodiv"; 2309 break; 2310 case EF_M68K_CF_ISA_A: 2311 isa = "A"; 2312 break; 2313 case EF_M68K_CF_ISA_A_PLUS: 2314 isa = "A+"; 2315 break; 2316 case EF_M68K_CF_ISA_B_NOUSP: 2317 isa = "B"; 2318 additional = ", nousp"; 2319 break; 2320 case EF_M68K_CF_ISA_B: 2321 isa = "B"; 2322 break; 2323 case EF_M68K_CF_ISA_C: 2324 isa = "C"; 2325 break; 2326 case EF_M68K_CF_ISA_C_NODIV: 2327 isa = "C"; 2328 additional = ", nodiv"; 2329 break; 2330 } 2331 strcat (buf, ", cf, isa "); 2332 strcat (buf, isa); 2333 if (additional) 2334 strcat (buf, additional); 2335 if (e_flags & EF_M68K_CF_FLOAT) 2336 strcat (buf, ", float"); 2337 switch (e_flags & EF_M68K_CF_MAC_MASK) 2338 { 2339 case 0: 2340 mac = NULL; 2341 break; 2342 case EF_M68K_CF_MAC: 2343 mac = "mac"; 2344 break; 2345 case EF_M68K_CF_EMAC: 2346 mac = "emac"; 2347 break; 2348 case EF_M68K_CF_EMAC_B: 2349 mac = "emac_b"; 2350 break; 2351 } 2352 if (mac) 2353 { 2354 strcat (buf, ", "); 2355 strcat (buf, mac); 2356 } 2357 } 2358 break; 2359 2360 case EM_PPC: 2361 if (e_flags & EF_PPC_EMB) 2362 strcat (buf, ", emb"); 2363 2364 if (e_flags & EF_PPC_RELOCATABLE) 2365 strcat (buf, _(", relocatable")); 2366 2367 if (e_flags & EF_PPC_RELOCATABLE_LIB) 2368 strcat (buf, _(", relocatable-lib")); 2369 break; 2370 2371 case EM_V850: 2372 case EM_CYGNUS_V850: 2373 switch (e_flags & EF_V850_ARCH) 2374 { 2375 case E_V850E2V3_ARCH: 2376 strcat (buf, ", v850e2v3"); 2377 break; 2378 case E_V850E2_ARCH: 2379 strcat (buf, ", v850e2"); 2380 break; 2381 case E_V850E1_ARCH: 2382 strcat (buf, ", v850e1"); 2383 break; 2384 case E_V850E_ARCH: 2385 strcat (buf, ", v850e"); 2386 break; 2387 case E_V850_ARCH: 2388 strcat (buf, ", v850"); 2389 break; 2390 default: 2391 strcat (buf, _(", unknown v850 architecture variant")); 2392 break; 2393 } 2394 break; 2395 2396 case EM_M32R: 2397 case EM_CYGNUS_M32R: 2398 if ((e_flags & EF_M32R_ARCH) == E_M32R_ARCH) 2399 strcat (buf, ", m32r"); 2400 break; 2401 2402 case EM_MIPS: 2403 case EM_MIPS_RS3_LE: 2404 if (e_flags & EF_MIPS_NOREORDER) 2405 strcat (buf, ", noreorder"); 2406 2407 if (e_flags & EF_MIPS_PIC) 2408 strcat (buf, ", pic"); 2409 2410 if (e_flags & EF_MIPS_CPIC) 2411 strcat (buf, ", cpic"); 2412 2413 if (e_flags & EF_MIPS_UCODE) 2414 strcat (buf, ", ugen_reserved"); 2415 2416 if (e_flags & EF_MIPS_ABI2) 2417 strcat (buf, ", abi2"); 2418 2419 if (e_flags & EF_MIPS_OPTIONS_FIRST) 2420 strcat (buf, ", odk first"); 2421 2422 if (e_flags & EF_MIPS_32BITMODE) 2423 strcat (buf, ", 32bitmode"); 2424 2425 switch ((e_flags & EF_MIPS_MACH)) 2426 { 2427 case E_MIPS_MACH_3900: strcat (buf, ", 3900"); break; 2428 case E_MIPS_MACH_4010: strcat (buf, ", 4010"); break; 2429 case E_MIPS_MACH_4100: strcat (buf, ", 4100"); break; 2430 case E_MIPS_MACH_4111: strcat (buf, ", 4111"); break; 2431 case E_MIPS_MACH_4120: strcat (buf, ", 4120"); break; 2432 case E_MIPS_MACH_4650: strcat (buf, ", 4650"); break; 2433 case E_MIPS_MACH_5400: strcat (buf, ", 5400"); break; 2434 case E_MIPS_MACH_5500: strcat (buf, ", 5500"); break; 2435 case E_MIPS_MACH_SB1: strcat (buf, ", sb1"); break; 2436 case E_MIPS_MACH_9000: strcat (buf, ", 9000"); break; 2437 case E_MIPS_MACH_LS2E: strcat (buf, ", loongson-2e"); break; 2438 case E_MIPS_MACH_LS2F: strcat (buf, ", loongson-2f"); break; 2439 case E_MIPS_MACH_LS3A: strcat (buf, ", loongson-3a"); break; 2440 case E_MIPS_MACH_OCTEON: strcat (buf, ", octeon"); break; 2441 case E_MIPS_MACH_OCTEON2: strcat (buf, ", octeon2"); break; 2442 case E_MIPS_MACH_XLR: strcat (buf, ", xlr"); break; 2443 case 0: 2444 /* We simply ignore the field in this case to avoid confusion: 2445 MIPS ELF does not specify EF_MIPS_MACH, it is a GNU 2446 extension. */ 2447 break; 2448 default: strcat (buf, _(", unknown CPU")); break; 2449 } 2450 2451 switch ((e_flags & EF_MIPS_ABI)) 2452 { 2453 case E_MIPS_ABI_O32: strcat (buf, ", o32"); break; 2454 case E_MIPS_ABI_O64: strcat (buf, ", o64"); break; 2455 case E_MIPS_ABI_EABI32: strcat (buf, ", eabi32"); break; 2456 case E_MIPS_ABI_EABI64: strcat (buf, ", eabi64"); break; 2457 case 0: 2458 /* We simply ignore the field in this case to avoid confusion: 2459 MIPS ELF does not specify EF_MIPS_ABI, it is a GNU extension. 2460 This means it is likely to be an o32 file, but not for 2461 sure. */ 2462 break; 2463 default: strcat (buf, _(", unknown ABI")); break; 2464 } 2465 2466 if (e_flags & EF_MIPS_ARCH_ASE_MDMX) 2467 strcat (buf, ", mdmx"); 2468 2469 if (e_flags & EF_MIPS_ARCH_ASE_M16) 2470 strcat (buf, ", mips16"); 2471 2472 if (e_flags & EF_MIPS_ARCH_ASE_MICROMIPS) 2473 strcat (buf, ", micromips"); 2474 2475 switch ((e_flags & EF_MIPS_ARCH)) 2476 { 2477 case E_MIPS_ARCH_1: strcat (buf, ", mips1"); break; 2478 case E_MIPS_ARCH_2: strcat (buf, ", mips2"); break; 2479 case E_MIPS_ARCH_3: strcat (buf, ", mips3"); break; 2480 case E_MIPS_ARCH_4: strcat (buf, ", mips4"); break; 2481 case E_MIPS_ARCH_5: strcat (buf, ", mips5"); break; 2482 case E_MIPS_ARCH_32: strcat (buf, ", mips32"); break; 2483 case E_MIPS_ARCH_32R2: strcat (buf, ", mips32r2"); break; 2484 case E_MIPS_ARCH_64: strcat (buf, ", mips64"); break; 2485 case E_MIPS_ARCH_64R2: strcat (buf, ", mips64r2"); break; 2486 default: strcat (buf, _(", unknown ISA")); break; 2487 } 2488 2489 if (e_flags & EF_SH_PIC) 2490 strcat (buf, ", pic"); 2491 2492 if (e_flags & EF_SH_FDPIC) 2493 strcat (buf, ", fdpic"); 2494 break; 2495 2496 case EM_RISCV: 2497 { 2498 unsigned int riscv_extension = EF_GET_RISCV_EXT(e_flags); 2499 strcat (buf, ", "); 2500 strcat (buf, riscv_elf_flag_to_name (riscv_extension)); 2501 } 2502 break; 2503 2504 case EM_SH: 2505 switch ((e_flags & EF_SH_MACH_MASK)) 2506 { 2507 case EF_SH1: strcat (buf, ", sh1"); break; 2508 case EF_SH2: strcat (buf, ", sh2"); break; 2509 case EF_SH3: strcat (buf, ", sh3"); break; 2510 case EF_SH_DSP: strcat (buf, ", sh-dsp"); break; 2511 case EF_SH3_DSP: strcat (buf, ", sh3-dsp"); break; 2512 case EF_SH4AL_DSP: strcat (buf, ", sh4al-dsp"); break; 2513 case EF_SH3E: strcat (buf, ", sh3e"); break; 2514 case EF_SH4: strcat (buf, ", sh4"); break; 2515 case EF_SH5: strcat (buf, ", sh5"); break; 2516 case EF_SH2E: strcat (buf, ", sh2e"); break; 2517 case EF_SH4A: strcat (buf, ", sh4a"); break; 2518 case EF_SH2A: strcat (buf, ", sh2a"); break; 2519 case EF_SH4_NOFPU: strcat (buf, ", sh4-nofpu"); break; 2520 case EF_SH4A_NOFPU: strcat (buf, ", sh4a-nofpu"); break; 2521 case EF_SH2A_NOFPU: strcat (buf, ", sh2a-nofpu"); break; 2522 case EF_SH3_NOMMU: strcat (buf, ", sh3-nommu"); break; 2523 case EF_SH4_NOMMU_NOFPU: strcat (buf, ", sh4-nommu-nofpu"); break; 2524 case EF_SH2A_SH4_NOFPU: strcat (buf, ", sh2a-nofpu-or-sh4-nommu-nofpu"); break; 2525 case EF_SH2A_SH3_NOFPU: strcat (buf, ", sh2a-nofpu-or-sh3-nommu"); break; 2526 case EF_SH2A_SH4: strcat (buf, ", sh2a-or-sh4"); break; 2527 case EF_SH2A_SH3E: strcat (buf, ", sh2a-or-sh3e"); break; 2528 default: strcat (buf, _(", unknown ISA")); break; 2529 } 2530 2531 break; 2532 2533 case EM_SPARCV9: 2534 if (e_flags & EF_SPARC_32PLUS) 2535 strcat (buf, ", v8+"); 2536 2537 if (e_flags & EF_SPARC_SUN_US1) 2538 strcat (buf, ", ultrasparcI"); 2539 2540 if (e_flags & EF_SPARC_SUN_US3) 2541 strcat (buf, ", ultrasparcIII"); 2542 2543 if (e_flags & EF_SPARC_HAL_R1) 2544 strcat (buf, ", halr1"); 2545 2546 if (e_flags & EF_SPARC_LEDATA) 2547 strcat (buf, ", ledata"); 2548 2549 if ((e_flags & EF_SPARCV9_MM) == EF_SPARCV9_TSO) 2550 strcat (buf, ", tso"); 2551 2552 if ((e_flags & EF_SPARCV9_MM) == EF_SPARCV9_PSO) 2553 strcat (buf, ", pso"); 2554 2555 if ((e_flags & EF_SPARCV9_MM) == EF_SPARCV9_RMO) 2556 strcat (buf, ", rmo"); 2557 break; 2558 2559 case EM_PARISC: 2560 switch (e_flags & EF_PARISC_ARCH) 2561 { 2562 case EFA_PARISC_1_0: 2563 strcpy (buf, ", PA-RISC 1.0"); 2564 break; 2565 case EFA_PARISC_1_1: 2566 strcpy (buf, ", PA-RISC 1.1"); 2567 break; 2568 case EFA_PARISC_2_0: 2569 strcpy (buf, ", PA-RISC 2.0"); 2570 break; 2571 default: 2572 break; 2573 } 2574 if (e_flags & EF_PARISC_TRAPNIL) 2575 strcat (buf, ", trapnil"); 2576 if (e_flags & EF_PARISC_EXT) 2577 strcat (buf, ", ext"); 2578 if (e_flags & EF_PARISC_LSB) 2579 strcat (buf, ", lsb"); 2580 if (e_flags & EF_PARISC_WIDE) 2581 strcat (buf, ", wide"); 2582 if (e_flags & EF_PARISC_NO_KABP) 2583 strcat (buf, ", no kabp"); 2584 if (e_flags & EF_PARISC_LAZYSWAP) 2585 strcat (buf, ", lazyswap"); 2586 break; 2587 2588 case EM_PJ: 2589 case EM_PJ_OLD: 2590 if ((e_flags & EF_PICOJAVA_NEWCALLS) == EF_PICOJAVA_NEWCALLS) 2591 strcat (buf, ", new calling convention"); 2592 2593 if ((e_flags & EF_PICOJAVA_GNUCALLS) == EF_PICOJAVA_GNUCALLS) 2594 strcat (buf, ", gnu calling convention"); 2595 break; 2596 2597 case EM_IA_64: 2598 if ((e_flags & EF_IA_64_ABI64)) 2599 strcat (buf, ", 64-bit"); 2600 else 2601 strcat (buf, ", 32-bit"); 2602 if ((e_flags & EF_IA_64_REDUCEDFP)) 2603 strcat (buf, ", reduced fp model"); 2604 if ((e_flags & EF_IA_64_NOFUNCDESC_CONS_GP)) 2605 strcat (buf, ", no function descriptors, constant gp"); 2606 else if ((e_flags & EF_IA_64_CONS_GP)) 2607 strcat (buf, ", constant gp"); 2608 if ((e_flags & EF_IA_64_ABSOLUTE)) 2609 strcat (buf, ", absolute"); 2610 if (elf_header.e_ident[EI_OSABI] == ELFOSABI_OPENVMS) 2611 { 2612 if ((e_flags & EF_IA_64_VMS_LINKAGES)) 2613 strcat (buf, ", vms_linkages"); 2614 switch ((e_flags & EF_IA_64_VMS_COMCOD)) 2615 { 2616 case EF_IA_64_VMS_COMCOD_SUCCESS: 2617 break; 2618 case EF_IA_64_VMS_COMCOD_WARNING: 2619 strcat (buf, ", warning"); 2620 break; 2621 case EF_IA_64_VMS_COMCOD_ERROR: 2622 strcat (buf, ", error"); 2623 break; 2624 case EF_IA_64_VMS_COMCOD_ABORT: 2625 strcat (buf, ", abort"); 2626 break; 2627 default: 2628 abort (); 2629 } 2630 } 2631 break; 2632 2633 case EM_VAX: 2634 if ((e_flags & EF_VAX_NONPIC)) 2635 strcat (buf, ", non-PIC"); 2636 if ((e_flags & EF_VAX_DFLOAT)) 2637 strcat (buf, ", D-Float"); 2638 if ((e_flags & EF_VAX_GFLOAT)) 2639 strcat (buf, ", G-Float"); 2640 break; 2641 2642 case EM_RX: 2643 if (e_flags & E_FLAG_RX_64BIT_DOUBLES) 2644 strcat (buf, ", 64-bit doubles"); 2645 if (e_flags & E_FLAG_RX_DSP) 2646 strcat (buf, ", dsp"); 2647 if (e_flags & E_FLAG_RX_PID) 2648 strcat (buf, ", pid"); 2649 break; 2650 2651 case EM_S390: 2652 if (e_flags & EF_S390_HIGH_GPRS) 2653 strcat (buf, ", highgprs"); 2654 break; 2655 2656 case EM_TI_C6000: 2657 if ((e_flags & EF_C6000_REL)) 2658 strcat (buf, ", relocatable module"); 2659 break; 2660 } 2661 } 2662 2663 return buf; 2664 } 2665 2666 static const char * 2667 get_osabi_name (unsigned int osabi) 2668 { 2669 static char buff[32]; 2670 2671 switch (osabi) 2672 { 2673 case ELFOSABI_NONE: return "UNIX - System V"; 2674 case ELFOSABI_HPUX: return "UNIX - HP-UX"; 2675 case ELFOSABI_NETBSD: return "UNIX - NetBSD"; 2676 case ELFOSABI_GNU: return "UNIX - GNU"; 2677 case ELFOSABI_SOLARIS: return "UNIX - Solaris"; 2678 case ELFOSABI_AIX: return "UNIX - AIX"; 2679 case ELFOSABI_IRIX: return "UNIX - IRIX"; 2680 case ELFOSABI_FREEBSD: return "UNIX - FreeBSD"; 2681 case ELFOSABI_TRU64: return "UNIX - TRU64"; 2682 case ELFOSABI_MODESTO: return "Novell - Modesto"; 2683 case ELFOSABI_OPENBSD: return "UNIX - OpenBSD"; 2684 case ELFOSABI_OPENVMS: return "VMS - OpenVMS"; 2685 case ELFOSABI_NSK: return "HP - Non-Stop Kernel"; 2686 case ELFOSABI_AROS: return "AROS"; 2687 case ELFOSABI_FENIXOS: return "FenixOS"; 2688 default: 2689 if (osabi >= 64) 2690 switch (elf_header.e_machine) 2691 { 2692 case EM_ARM: 2693 switch (osabi) 2694 { 2695 case ELFOSABI_ARM: return "ARM"; 2696 default: 2697 break; 2698 } 2699 break; 2700 2701 case EM_MSP430: 2702 case EM_MSP430_OLD: 2703 switch (osabi) 2704 { 2705 case ELFOSABI_STANDALONE: return _("Standalone App"); 2706 default: 2707 break; 2708 } 2709 break; 2710 2711 case EM_TI_C6000: 2712 switch (osabi) 2713 { 2714 case ELFOSABI_C6000_ELFABI: return _("Bare-metal C6000"); 2715 case ELFOSABI_C6000_LINUX: return "Linux C6000"; 2716 default: 2717 break; 2718 } 2719 break; 2720 2721 default: 2722 break; 2723 } 2724 snprintf (buff, sizeof (buff), _("<unknown: %x>"), osabi); 2725 return buff; 2726 } 2727 } 2728 2729 static const char * 2730 get_aarch64_segment_type (unsigned long type) 2731 { 2732 switch (type) 2733 { 2734 case PT_AARCH64_ARCHEXT: 2735 return "AARCH64_ARCHEXT"; 2736 default: 2737 break; 2738 } 2739 2740 return NULL; 2741 } 2742 2743 static const char * 2744 get_arm_segment_type (unsigned long type) 2745 { 2746 switch (type) 2747 { 2748 case PT_ARM_EXIDX: 2749 return "EXIDX"; 2750 default: 2751 break; 2752 } 2753 2754 return NULL; 2755 } 2756 2757 static const char * 2758 get_mips_segment_type (unsigned long type) 2759 { 2760 switch (type) 2761 { 2762 case PT_MIPS_REGINFO: 2763 return "REGINFO"; 2764 case PT_MIPS_RTPROC: 2765 return "RTPROC"; 2766 case PT_MIPS_OPTIONS: 2767 return "OPTIONS"; 2768 default: 2769 break; 2770 } 2771 2772 return NULL; 2773 } 2774 2775 static const char * 2776 get_parisc_segment_type (unsigned long type) 2777 { 2778 switch (type) 2779 { 2780 case PT_HP_TLS: return "HP_TLS"; 2781 case PT_HP_CORE_NONE: return "HP_CORE_NONE"; 2782 case PT_HP_CORE_VERSION: return "HP_CORE_VERSION"; 2783 case PT_HP_CORE_KERNEL: return "HP_CORE_KERNEL"; 2784 case PT_HP_CORE_COMM: return "HP_CORE_COMM"; 2785 case PT_HP_CORE_PROC: return "HP_CORE_PROC"; 2786 case PT_HP_CORE_LOADABLE: return "HP_CORE_LOADABLE"; 2787 case PT_HP_CORE_STACK: return "HP_CORE_STACK"; 2788 case PT_HP_CORE_SHM: return "HP_CORE_SHM"; 2789 case PT_HP_CORE_MMF: return "HP_CORE_MMF"; 2790 case PT_HP_PARALLEL: return "HP_PARALLEL"; 2791 case PT_HP_FASTBIND: return "HP_FASTBIND"; 2792 case PT_HP_OPT_ANNOT: return "HP_OPT_ANNOT"; 2793 case PT_HP_HSL_ANNOT: return "HP_HSL_ANNOT"; 2794 case PT_HP_STACK: return "HP_STACK"; 2795 case PT_HP_CORE_UTSNAME: return "HP_CORE_UTSNAME"; 2796 case PT_PARISC_ARCHEXT: return "PARISC_ARCHEXT"; 2797 case PT_PARISC_UNWIND: return "PARISC_UNWIND"; 2798 case PT_PARISC_WEAKORDER: return "PARISC_WEAKORDER"; 2799 default: 2800 break; 2801 } 2802 2803 return NULL; 2804 } 2805 2806 static const char * 2807 get_ia64_segment_type (unsigned long type) 2808 { 2809 switch (type) 2810 { 2811 case PT_IA_64_ARCHEXT: return "IA_64_ARCHEXT"; 2812 case PT_IA_64_UNWIND: return "IA_64_UNWIND"; 2813 case PT_HP_TLS: return "HP_TLS"; 2814 case PT_IA_64_HP_OPT_ANOT: return "HP_OPT_ANNOT"; 2815 case PT_IA_64_HP_HSL_ANOT: return "HP_HSL_ANNOT"; 2816 case PT_IA_64_HP_STACK: return "HP_STACK"; 2817 default: 2818 break; 2819 } 2820 2821 return NULL; 2822 } 2823 2824 static const char * 2825 get_tic6x_segment_type (unsigned long type) 2826 { 2827 switch (type) 2828 { 2829 case PT_C6000_PHATTR: return "C6000_PHATTR"; 2830 default: 2831 break; 2832 } 2833 2834 return NULL; 2835 } 2836 2837 static const char * 2838 get_segment_type (unsigned long p_type) 2839 { 2840 static char buff[32]; 2841 2842 switch (p_type) 2843 { 2844 case PT_NULL: return "NULL"; 2845 case PT_LOAD: return "LOAD"; 2846 case PT_DYNAMIC: return "DYNAMIC"; 2847 case PT_INTERP: return "INTERP"; 2848 case PT_NOTE: return "NOTE"; 2849 case PT_SHLIB: return "SHLIB"; 2850 case PT_PHDR: return "PHDR"; 2851 case PT_TLS: return "TLS"; 2852 2853 case PT_GNU_EH_FRAME: 2854 return "GNU_EH_FRAME"; 2855 case PT_GNU_STACK: return "GNU_STACK"; 2856 case PT_GNU_RELRO: return "GNU_RELRO"; 2857 2858 default: 2859 if ((p_type >= PT_LOPROC) && (p_type <= PT_HIPROC)) 2860 { 2861 const char * result; 2862 2863 switch (elf_header.e_machine) 2864 { 2865 case EM_AARCH64: 2866 result = get_aarch64_segment_type (p_type); 2867 break; 2868 case EM_ARM: 2869 result = get_arm_segment_type (p_type); 2870 break; 2871 case EM_MIPS: 2872 case EM_MIPS_RS3_LE: 2873 result = get_mips_segment_type (p_type); 2874 break; 2875 case EM_PARISC: 2876 result = get_parisc_segment_type (p_type); 2877 break; 2878 case EM_IA_64: 2879 result = get_ia64_segment_type (p_type); 2880 break; 2881 case EM_TI_C6000: 2882 result = get_tic6x_segment_type (p_type); 2883 break; 2884 default: 2885 result = NULL; 2886 break; 2887 } 2888 2889 if (result != NULL) 2890 return result; 2891 2892 sprintf (buff, "LOPROC+%lx", p_type - PT_LOPROC); 2893 } 2894 else if ((p_type >= PT_LOOS) && (p_type <= PT_HIOS)) 2895 { 2896 const char * result; 2897 2898 switch (elf_header.e_machine) 2899 { 2900 case EM_PARISC: 2901 result = get_parisc_segment_type (p_type); 2902 break; 2903 case EM_IA_64: 2904 result = get_ia64_segment_type (p_type); 2905 break; 2906 default: 2907 result = NULL; 2908 break; 2909 } 2910 2911 if (result != NULL) 2912 return result; 2913 2914 sprintf (buff, "LOOS+%lx", p_type - PT_LOOS); 2915 } 2916 else 2917 snprintf (buff, sizeof (buff), _("<unknown>: %lx"), p_type); 2918 2919 return buff; 2920 } 2921 } 2922 2923 static const char * 2924 get_mips_section_type_name (unsigned int sh_type) 2925 { 2926 switch (sh_type) 2927 { 2928 case SHT_MIPS_LIBLIST: return "MIPS_LIBLIST"; 2929 case SHT_MIPS_MSYM: return "MIPS_MSYM"; 2930 case SHT_MIPS_CONFLICT: return "MIPS_CONFLICT"; 2931 case SHT_MIPS_GPTAB: return "MIPS_GPTAB"; 2932 case SHT_MIPS_UCODE: return "MIPS_UCODE"; 2933 case SHT_MIPS_DEBUG: return "MIPS_DEBUG"; 2934 case SHT_MIPS_REGINFO: return "MIPS_REGINFO"; 2935 case SHT_MIPS_PACKAGE: return "MIPS_PACKAGE"; 2936 case SHT_MIPS_PACKSYM: return "MIPS_PACKSYM"; 2937 case SHT_MIPS_RELD: return "MIPS_RELD"; 2938 case SHT_MIPS_IFACE: return "MIPS_IFACE"; 2939 case SHT_MIPS_CONTENT: return "MIPS_CONTENT"; 2940 case SHT_MIPS_OPTIONS: return "MIPS_OPTIONS"; 2941 case SHT_MIPS_SHDR: return "MIPS_SHDR"; 2942 case SHT_MIPS_FDESC: return "MIPS_FDESC"; 2943 case SHT_MIPS_EXTSYM: return "MIPS_EXTSYM"; 2944 case SHT_MIPS_DENSE: return "MIPS_DENSE"; 2945 case SHT_MIPS_PDESC: return "MIPS_PDESC"; 2946 case SHT_MIPS_LOCSYM: return "MIPS_LOCSYM"; 2947 case SHT_MIPS_AUXSYM: return "MIPS_AUXSYM"; 2948 case SHT_MIPS_OPTSYM: return "MIPS_OPTSYM"; 2949 case SHT_MIPS_LOCSTR: return "MIPS_LOCSTR"; 2950 case SHT_MIPS_LINE: return "MIPS_LINE"; 2951 case SHT_MIPS_RFDESC: return "MIPS_RFDESC"; 2952 case SHT_MIPS_DELTASYM: return "MIPS_DELTASYM"; 2953 case SHT_MIPS_DELTAINST: return "MIPS_DELTAINST"; 2954 case SHT_MIPS_DELTACLASS: return "MIPS_DELTACLASS"; 2955 case SHT_MIPS_DWARF: return "MIPS_DWARF"; 2956 case SHT_MIPS_DELTADECL: return "MIPS_DELTADECL"; 2957 case SHT_MIPS_SYMBOL_LIB: return "MIPS_SYMBOL_LIB"; 2958 case SHT_MIPS_EVENTS: return "MIPS_EVENTS"; 2959 case SHT_MIPS_TRANSLATE: return "MIPS_TRANSLATE"; 2960 case SHT_MIPS_PIXIE: return "MIPS_PIXIE"; 2961 case SHT_MIPS_XLATE: return "MIPS_XLATE"; 2962 case SHT_MIPS_XLATE_DEBUG: return "MIPS_XLATE_DEBUG"; 2963 case SHT_MIPS_WHIRL: return "MIPS_WHIRL"; 2964 case SHT_MIPS_EH_REGION: return "MIPS_EH_REGION"; 2965 case SHT_MIPS_XLATE_OLD: return "MIPS_XLATE_OLD"; 2966 case SHT_MIPS_PDR_EXCEPTION: return "MIPS_PDR_EXCEPTION"; 2967 default: 2968 break; 2969 } 2970 return NULL; 2971 } 2972 2973 static const char * 2974 get_parisc_section_type_name (unsigned int sh_type) 2975 { 2976 switch (sh_type) 2977 { 2978 case SHT_PARISC_EXT: return "PARISC_EXT"; 2979 case SHT_PARISC_UNWIND: return "PARISC_UNWIND"; 2980 case SHT_PARISC_DOC: return "PARISC_DOC"; 2981 case SHT_PARISC_ANNOT: return "PARISC_ANNOT"; 2982 case SHT_PARISC_SYMEXTN: return "PARISC_SYMEXTN"; 2983 case SHT_PARISC_STUBS: return "PARISC_STUBS"; 2984 case SHT_PARISC_DLKM: return "PARISC_DLKM"; 2985 default: 2986 break; 2987 } 2988 return NULL; 2989 } 2990 2991 static const char * 2992 get_ia64_section_type_name (unsigned int sh_type) 2993 { 2994 /* If the top 8 bits are 0x78 the next 8 are the os/abi ID. */ 2995 if ((sh_type & 0xFF000000) == SHT_IA_64_LOPSREG) 2996 return get_osabi_name ((sh_type & 0x00FF0000) >> 16); 2997 2998 switch (sh_type) 2999 { 3000 case SHT_IA_64_EXT: return "IA_64_EXT"; 3001 case SHT_IA_64_UNWIND: return "IA_64_UNWIND"; 3002 case SHT_IA_64_PRIORITY_INIT: return "IA_64_PRIORITY_INIT"; 3003 case SHT_IA_64_VMS_TRACE: return "VMS_TRACE"; 3004 case SHT_IA_64_VMS_TIE_SIGNATURES: return "VMS_TIE_SIGNATURES"; 3005 case SHT_IA_64_VMS_DEBUG: return "VMS_DEBUG"; 3006 case SHT_IA_64_VMS_DEBUG_STR: return "VMS_DEBUG_STR"; 3007 case SHT_IA_64_VMS_LINKAGES: return "VMS_LINKAGES"; 3008 case SHT_IA_64_VMS_SYMBOL_VECTOR: return "VMS_SYMBOL_VECTOR"; 3009 case SHT_IA_64_VMS_FIXUP: return "VMS_FIXUP"; 3010 default: 3011 break; 3012 } 3013 return NULL; 3014 } 3015 3016 static const char * 3017 get_x86_64_section_type_name (unsigned int sh_type) 3018 { 3019 switch (sh_type) 3020 { 3021 case SHT_X86_64_UNWIND: return "X86_64_UNWIND"; 3022 default: 3023 break; 3024 } 3025 return NULL; 3026 } 3027 3028 static const char * 3029 get_aarch64_section_type_name (unsigned int sh_type) 3030 { 3031 switch (sh_type) 3032 { 3033 case SHT_AARCH64_ATTRIBUTES: 3034 return "AARCH64_ATTRIBUTES"; 3035 default: 3036 break; 3037 } 3038 return NULL; 3039 } 3040 3041 static const char * 3042 get_arm_section_type_name (unsigned int sh_type) 3043 { 3044 switch (sh_type) 3045 { 3046 case SHT_ARM_EXIDX: return "ARM_EXIDX"; 3047 case SHT_ARM_PREEMPTMAP: return "ARM_PREEMPTMAP"; 3048 case SHT_ARM_ATTRIBUTES: return "ARM_ATTRIBUTES"; 3049 case SHT_ARM_DEBUGOVERLAY: return "ARM_DEBUGOVERLAY"; 3050 case SHT_ARM_OVERLAYSECTION: return "ARM_OVERLAYSECTION"; 3051 default: 3052 break; 3053 } 3054 return NULL; 3055 } 3056 3057 static const char * 3058 get_tic6x_section_type_name (unsigned int sh_type) 3059 { 3060 switch (sh_type) 3061 { 3062 case SHT_C6000_UNWIND: 3063 return "C6000_UNWIND"; 3064 case SHT_C6000_PREEMPTMAP: 3065 return "C6000_PREEMPTMAP"; 3066 case SHT_C6000_ATTRIBUTES: 3067 return "C6000_ATTRIBUTES"; 3068 case SHT_TI_ICODE: 3069 return "TI_ICODE"; 3070 case SHT_TI_XREF: 3071 return "TI_XREF"; 3072 case SHT_TI_HANDLER: 3073 return "TI_HANDLER"; 3074 case SHT_TI_INITINFO: 3075 return "TI_INITINFO"; 3076 case SHT_TI_PHATTRS: 3077 return "TI_PHATTRS"; 3078 default: 3079 break; 3080 } 3081 return NULL; 3082 } 3083 3084 static const char * 3085 get_section_type_name (unsigned int sh_type) 3086 { 3087 static char buff[32]; 3088 3089 switch (sh_type) 3090 { 3091 case SHT_NULL: return "NULL"; 3092 case SHT_PROGBITS: return "PROGBITS"; 3093 case SHT_SYMTAB: return "SYMTAB"; 3094 case SHT_STRTAB: return "STRTAB"; 3095 case SHT_RELA: return "RELA"; 3096 case SHT_HASH: return "HASH"; 3097 case SHT_DYNAMIC: return "DYNAMIC"; 3098 case SHT_NOTE: return "NOTE"; 3099 case SHT_NOBITS: return "NOBITS"; 3100 case SHT_REL: return "REL"; 3101 case SHT_SHLIB: return "SHLIB"; 3102 case SHT_DYNSYM: return "DYNSYM"; 3103 case SHT_INIT_ARRAY: return "INIT_ARRAY"; 3104 case SHT_FINI_ARRAY: return "FINI_ARRAY"; 3105 case SHT_PREINIT_ARRAY: return "PREINIT_ARRAY"; 3106 case SHT_GNU_HASH: return "GNU_HASH"; 3107 case SHT_GROUP: return "GROUP"; 3108 case SHT_SYMTAB_SHNDX: return "SYMTAB SECTION INDICIES"; 3109 case SHT_GNU_verdef: return "VERDEF"; 3110 case SHT_GNU_verneed: return "VERNEED"; 3111 case SHT_GNU_versym: return "VERSYM"; 3112 case 0x6ffffff0: return "VERSYM"; 3113 case 0x6ffffffc: return "VERDEF"; 3114 case 0x7ffffffd: return "AUXILIARY"; 3115 case 0x7fffffff: return "FILTER"; 3116 case SHT_GNU_LIBLIST: return "GNU_LIBLIST"; 3117 3118 default: 3119 if ((sh_type >= SHT_LOPROC) && (sh_type <= SHT_HIPROC)) 3120 { 3121 const char * result; 3122 3123 switch (elf_header.e_machine) 3124 { 3125 case EM_MIPS: 3126 case EM_MIPS_RS3_LE: 3127 result = get_mips_section_type_name (sh_type); 3128 break; 3129 case EM_PARISC: 3130 result = get_parisc_section_type_name (sh_type); 3131 break; 3132 case EM_IA_64: 3133 result = get_ia64_section_type_name (sh_type); 3134 break; 3135 case EM_X86_64: 3136 case EM_L1OM: 3137 case EM_K1OM: 3138 result = get_x86_64_section_type_name (sh_type); 3139 break; 3140 case EM_AARCH64: 3141 result = get_aarch64_section_type_name (sh_type); 3142 break; 3143 case EM_ARM: 3144 result = get_arm_section_type_name (sh_type); 3145 break; 3146 case EM_TI_C6000: 3147 result = get_tic6x_section_type_name (sh_type); 3148 break; 3149 default: 3150 result = NULL; 3151 break; 3152 } 3153 3154 if (result != NULL) 3155 return result; 3156 3157 sprintf (buff, "LOPROC+%x", sh_type - SHT_LOPROC); 3158 } 3159 else if ((sh_type >= SHT_LOOS) && (sh_type <= SHT_HIOS)) 3160 { 3161 const char * result; 3162 3163 switch (elf_header.e_machine) 3164 { 3165 case EM_IA_64: 3166 result = get_ia64_section_type_name (sh_type); 3167 break; 3168 default: 3169 result = NULL; 3170 break; 3171 } 3172 3173 if (result != NULL) 3174 return result; 3175 3176 sprintf (buff, "LOOS+%x", sh_type - SHT_LOOS); 3177 } 3178 else if ((sh_type >= SHT_LOUSER) && (sh_type <= SHT_HIUSER)) 3179 sprintf (buff, "LOUSER+%x", sh_type - SHT_LOUSER); 3180 else 3181 /* This message is probably going to be displayed in a 15 3182 character wide field, so put the hex value first. */ 3183 snprintf (buff, sizeof (buff), _("%08x: <unknown>"), sh_type); 3184 3185 return buff; 3186 } 3187 } 3188 3189 #define OPTION_DEBUG_DUMP 512 3190 #define OPTION_DYN_SYMS 513 3191 #define OPTION_DWARF_DEPTH 514 3192 #define OPTION_DWARF_START 515 3193 #define OPTION_DWARF_CHECK 516 3194 3195 static struct option options[] = 3196 { 3197 {"all", no_argument, 0, 'a'}, 3198 {"file-header", no_argument, 0, 'h'}, 3199 {"program-headers", no_argument, 0, 'l'}, 3200 {"headers", no_argument, 0, 'e'}, 3201 {"histogram", no_argument, 0, 'I'}, 3202 {"segments", no_argument, 0, 'l'}, 3203 {"sections", no_argument, 0, 'S'}, 3204 {"section-headers", no_argument, 0, 'S'}, 3205 {"section-groups", no_argument, 0, 'g'}, 3206 {"section-details", no_argument, 0, 't'}, 3207 {"full-section-name",no_argument, 0, 'N'}, 3208 {"symbols", no_argument, 0, 's'}, 3209 {"syms", no_argument, 0, 's'}, 3210 {"dyn-syms", no_argument, 0, OPTION_DYN_SYMS}, 3211 {"relocs", no_argument, 0, 'r'}, 3212 {"notes", no_argument, 0, 'n'}, 3213 {"dynamic", no_argument, 0, 'd'}, 3214 {"special-files", no_argument, 0, 'f'}, 3215 {"arch-specific", no_argument, 0, 'A'}, 3216 {"version-info", no_argument, 0, 'V'}, 3217 {"use-dynamic", no_argument, 0, 'D'}, 3218 {"unwind", no_argument, 0, 'u'}, 3219 {"archive-index", no_argument, 0, 'c'}, 3220 {"hex-dump", required_argument, 0, 'x'}, 3221 {"relocated-dump", required_argument, 0, 'R'}, 3222 {"string-dump", required_argument, 0, 'p'}, 3223 #ifdef SUPPORT_DISASSEMBLY 3224 {"instruction-dump", required_argument, 0, 'i'}, 3225 #endif 3226 {"debug-dump", optional_argument, 0, OPTION_DEBUG_DUMP}, 3227 3228 {"dwarf-depth", required_argument, 0, OPTION_DWARF_DEPTH}, 3229 {"dwarf-start", required_argument, 0, OPTION_DWARF_START}, 3230 {"dwarf-check", no_argument, 0, OPTION_DWARF_CHECK}, 3231 3232 {"version", no_argument, 0, 'v'}, 3233 {"wide", no_argument, 0, 'W'}, 3234 {"help", no_argument, 0, 'H'}, 3235 {0, no_argument, 0, 0} 3236 }; 3237 3238 static void 3239 usage (FILE * stream) 3240 { 3241 fprintf (stream, _("Usage: readelf <option(s)> elf-file(s)\n")); 3242 fprintf (stream, _(" Display information about the contents of ELF format files\n")); 3243 fprintf (stream, _(" Options are:\n\ 3244 -a --all Equivalent to: -h -l -S -s -r -d -V -A -I\n\ 3245 -h --file-header Display the ELF file header\n\ 3246 -l --program-headers Display the program headers\n\ 3247 --segments An alias for --program-headers\n\ 3248 -S --section-headers Display the sections' header\n\ 3249 --sections An alias for --section-headers\n\ 3250 -g --section-groups Display the section groups\n\ 3251 -t --section-details Display the section details\n\ 3252 -e --headers Equivalent to: -h -l -S\n\ 3253 -s --syms Display the symbol table\n\ 3254 --symbols An alias for --syms\n\ 3255 --dyn-syms Display the dynamic symbol table\n\ 3256 -n --notes Display the core notes (if present)\n\ 3257 -r --relocs Display the relocations (if present)\n\ 3258 -u --unwind Display the unwind info (if present)\n\ 3259 -d --dynamic Display the dynamic section (if present)\n\ 3260 -f --special-files Process non-plain files too\n\ 3261 -V --version-info Display the version sections (if present)\n\ 3262 -A --arch-specific Display architecture specific information (if any)\n\ 3263 -c --archive-index Display the symbol/file index in an archive\n\ 3264 -D --use-dynamic Use the dynamic section info when displaying symbols\n\ 3265 -x --hex-dump=<number|name>\n\ 3266 Dump the contents of section <number|name> as bytes\n\ 3267 -p --string-dump=<number|name>\n\ 3268 Dump the contents of section <number|name> as strings\n\ 3269 -R --relocated-dump=<number|name>\n\ 3270 Dump the contents of section <number|name> as relocated bytes\n\ 3271 -w[lLiaprmfFsoRt] or\n\ 3272 --debug-dump[=rawline,=decodedline,=info,=abbrev,=pubnames,=aranges,=macro,=frames,\n\ 3273 =frames-interp,=str,=loc,=Ranges,=pubtypes,\n\ 3274 =gdb_index,=trace_info,=trace_abbrev,=trace_aranges]\n\ 3275 Display the contents of DWARF2 debug sections\n")); 3276 fprintf (stream, _("\ 3277 --dwarf-depth=N Do not display DIEs at depth N or greater\n\ 3278 --dwarf-start=N Display DIEs starting with N, at the same depth\n\ 3279 or deeper\n")); 3280 #ifdef SUPPORT_DISASSEMBLY 3281 fprintf (stream, _("\ 3282 -i --instruction-dump=<number|name>\n\ 3283 Disassemble the contents of section <number|name>\n")); 3284 #endif 3285 fprintf (stream, _("\ 3286 -I --histogram Display histogram of bucket list lengths\n\ 3287 -W --wide Allow output width to exceed 80 characters\n\ 3288 @<file> Read options from <file>\n\ 3289 -H --help Display this information\n\ 3290 -v --version Display the version number of readelf\n")); 3291 3292 if (REPORT_BUGS_TO[0] && stream == stdout) 3293 fprintf (stdout, _("Report bugs to %s\n"), REPORT_BUGS_TO); 3294 3295 exit (stream == stdout ? 0 : 1); 3296 } 3297 3298 /* Record the fact that the user wants the contents of section number 3299 SECTION to be displayed using the method(s) encoded as flags bits 3300 in TYPE. Note, TYPE can be zero if we are creating the array for 3301 the first time. */ 3302 3303 static void 3304 request_dump_bynumber (unsigned int section, dump_type type) 3305 { 3306 if (section >= num_dump_sects) 3307 { 3308 dump_type * new_dump_sects; 3309 3310 new_dump_sects = (dump_type *) calloc (section + 1, 3311 sizeof (* dump_sects)); 3312 3313 if (new_dump_sects == NULL) 3314 error (_("Out of memory allocating dump request table.\n")); 3315 else 3316 { 3317 /* Copy current flag settings. */ 3318 memcpy (new_dump_sects, dump_sects, num_dump_sects * sizeof (* dump_sects)); 3319 3320 free (dump_sects); 3321 3322 dump_sects = new_dump_sects; 3323 num_dump_sects = section + 1; 3324 } 3325 } 3326 3327 if (dump_sects) 3328 dump_sects[section] |= type; 3329 3330 return; 3331 } 3332 3333 /* Request a dump by section name. */ 3334 3335 static void 3336 request_dump_byname (const char * section, dump_type type) 3337 { 3338 struct dump_list_entry * new_request; 3339 3340 new_request = (struct dump_list_entry *) 3341 malloc (sizeof (struct dump_list_entry)); 3342 if (!new_request) 3343 error (_("Out of memory allocating dump request table.\n")); 3344 3345 new_request->name = strdup (section); 3346 if (!new_request->name) 3347 error (_("Out of memory allocating dump request table.\n")); 3348 3349 new_request->type = type; 3350 3351 new_request->next = dump_sects_byname; 3352 dump_sects_byname = new_request; 3353 } 3354 3355 static inline void 3356 request_dump (dump_type type) 3357 { 3358 int section; 3359 char * cp; 3360 3361 do_dump++; 3362 section = strtoul (optarg, & cp, 0); 3363 3364 if (! *cp && section >= 0) 3365 request_dump_bynumber (section, type); 3366 else 3367 request_dump_byname (optarg, type); 3368 } 3369 3370 3371 static void 3372 parse_args (int argc, char ** argv) 3373 { 3374 int c; 3375 3376 if (argc < 2) 3377 usage (stderr); 3378 3379 while ((c = getopt_long 3380 (argc, argv, "ADHINR:SVWacdefghi:lnp:rstuvw::x:", options, NULL)) != EOF) 3381 { 3382 switch (c) 3383 { 3384 case 0: 3385 /* Long options. */ 3386 break; 3387 case 'H': 3388 usage (stdout); 3389 break; 3390 3391 case 'a': 3392 do_syms++; 3393 do_reloc++; 3394 do_unwind++; 3395 do_dynamic++; 3396 do_header++; 3397 do_sections++; 3398 do_section_groups++; 3399 do_segments++; 3400 do_version++; 3401 do_histogram++; 3402 do_arch++; 3403 do_notes++; 3404 break; 3405 case 'g': 3406 do_section_groups++; 3407 break; 3408 case 't': 3409 case 'N': 3410 do_sections++; 3411 do_section_details++; 3412 break; 3413 case 'e': 3414 do_header++; 3415 do_sections++; 3416 do_segments++; 3417 break; 3418 case 'A': 3419 do_arch++; 3420 break; 3421 case 'D': 3422 do_using_dynamic++; 3423 break; 3424 case 'r': 3425 do_reloc++; 3426 break; 3427 case 'u': 3428 do_unwind++; 3429 break; 3430 case 'f': 3431 do_special_files++; 3432 break; 3433 case 'h': 3434 do_header++; 3435 break; 3436 case 'l': 3437 do_segments++; 3438 break; 3439 case 's': 3440 do_syms++; 3441 break; 3442 case 'S': 3443 do_sections++; 3444 break; 3445 case 'd': 3446 do_dynamic++; 3447 break; 3448 case 'I': 3449 do_histogram++; 3450 break; 3451 case 'n': 3452 do_notes++; 3453 break; 3454 case 'c': 3455 do_archive_index++; 3456 break; 3457 case 'x': 3458 request_dump (HEX_DUMP); 3459 break; 3460 case 'p': 3461 request_dump (STRING_DUMP); 3462 break; 3463 case 'R': 3464 request_dump (RELOC_DUMP); 3465 break; 3466 case 'w': 3467 do_dump++; 3468 if (optarg == 0) 3469 { 3470 do_debugging = 1; 3471 dwarf_select_sections_all (); 3472 } 3473 else 3474 { 3475 do_debugging = 0; 3476 dwarf_select_sections_by_letters (optarg); 3477 } 3478 break; 3479 case OPTION_DEBUG_DUMP: 3480 do_dump++; 3481 if (optarg == 0) 3482 do_debugging = 1; 3483 else 3484 { 3485 do_debugging = 0; 3486 dwarf_select_sections_by_names (optarg); 3487 } 3488 break; 3489 case OPTION_DWARF_DEPTH: 3490 { 3491 char *cp; 3492 3493 dwarf_cutoff_level = strtoul (optarg, & cp, 0); 3494 } 3495 break; 3496 case OPTION_DWARF_START: 3497 { 3498 char *cp; 3499 3500 dwarf_start_die = strtoul (optarg, & cp, 0); 3501 } 3502 break; 3503 case OPTION_DWARF_CHECK: 3504 dwarf_check = 1; 3505 break; 3506 case OPTION_DYN_SYMS: 3507 do_dyn_syms++; 3508 break; 3509 #ifdef SUPPORT_DISASSEMBLY 3510 case 'i': 3511 request_dump (DISASS_DUMP); 3512 break; 3513 #endif 3514 case 'v': 3515 print_version (program_name); 3516 break; 3517 case 'V': 3518 do_version++; 3519 break; 3520 case 'W': 3521 do_wide++; 3522 break; 3523 default: 3524 /* xgettext:c-format */ 3525 error (_("Invalid option '-%c'\n"), c); 3526 /* Drop through. */ 3527 case '?': 3528 usage (stderr); 3529 } 3530 } 3531 3532 if (!do_dynamic && !do_syms && !do_reloc && !do_unwind && !do_sections 3533 && !do_segments && !do_header && !do_dump && !do_version 3534 && !do_histogram && !do_debugging && !do_arch && !do_notes 3535 && !do_section_groups && !do_archive_index 3536 && !do_dyn_syms) 3537 usage (stderr); 3538 else if (argc < 3) 3539 { 3540 warn (_("Nothing to do.\n")); 3541 usage (stderr); 3542 } 3543 } 3544 3545 static const char * 3546 get_elf_class (unsigned int elf_class) 3547 { 3548 static char buff[32]; 3549 3550 switch (elf_class) 3551 { 3552 case ELFCLASSNONE: return _("none"); 3553 case ELFCLASS32: return "ELF32"; 3554 case ELFCLASS64: return "ELF64"; 3555 default: 3556 snprintf (buff, sizeof (buff), _("<unknown: %x>"), elf_class); 3557 return buff; 3558 } 3559 } 3560 3561 static const char * 3562 get_data_encoding (unsigned int encoding) 3563 { 3564 static char buff[32]; 3565 3566 switch (encoding) 3567 { 3568 case ELFDATANONE: return _("none"); 3569 case ELFDATA2LSB: return _("2's complement, little endian"); 3570 case ELFDATA2MSB: return _("2's complement, big endian"); 3571 default: 3572 snprintf (buff, sizeof (buff), _("<unknown: %x>"), encoding); 3573 return buff; 3574 } 3575 } 3576 3577 /* Decode the data held in 'elf_header'. */ 3578 3579 static int 3580 process_file_header (void) 3581 { 3582 if ( elf_header.e_ident[EI_MAG0] != ELFMAG0 3583 || elf_header.e_ident[EI_MAG1] != ELFMAG1 3584 || elf_header.e_ident[EI_MAG2] != ELFMAG2 3585 || elf_header.e_ident[EI_MAG3] != ELFMAG3) 3586 { 3587 error 3588 (_("Not an ELF file - it has the wrong magic bytes at the start\n")); 3589 return 0; 3590 } 3591 3592 init_dwarf_regnames (elf_header.e_machine); 3593 3594 if (do_header) 3595 { 3596 int i; 3597 3598 printf (_("ELF Header:\n")); 3599 printf (_(" Magic: ")); 3600 for (i = 0; i < EI_NIDENT; i++) 3601 printf ("%2.2x ", elf_header.e_ident[i]); 3602 printf ("\n"); 3603 printf (_(" Class: %s\n"), 3604 get_elf_class (elf_header.e_ident[EI_CLASS])); 3605 printf (_(" Data: %s\n"), 3606 get_data_encoding (elf_header.e_ident[EI_DATA])); 3607 printf (_(" Version: %d %s\n"), 3608 elf_header.e_ident[EI_VERSION], 3609 (elf_header.e_ident[EI_VERSION] == EV_CURRENT 3610 ? "(current)" 3611 : (elf_header.e_ident[EI_VERSION] != EV_NONE 3612 ? _("<unknown: %lx>") 3613 : ""))); 3614 printf (_(" OS/ABI: %s\n"), 3615 get_osabi_name (elf_header.e_ident[EI_OSABI])); 3616 printf (_(" ABI Version: %d\n"), 3617 elf_header.e_ident[EI_ABIVERSION]); 3618 printf (_(" Type: %s\n"), 3619 get_file_type (elf_header.e_type)); 3620 printf (_(" Machine: %s\n"), 3621 get_machine_name (elf_header.e_machine)); 3622 printf (_(" Version: 0x%lx\n"), 3623 (unsigned long) elf_header.e_version); 3624 3625 printf (_(" Entry point address: ")); 3626 print_vma ((bfd_vma) elf_header.e_entry, PREFIX_HEX); 3627 printf (_("\n Start of program headers: ")); 3628 print_vma ((bfd_vma) elf_header.e_phoff, DEC); 3629 printf (_(" (bytes into file)\n Start of section headers: ")); 3630 print_vma ((bfd_vma) elf_header.e_shoff, DEC); 3631 printf (_(" (bytes into file)\n")); 3632 3633 printf (_(" Flags: 0x%lx%s\n"), 3634 (unsigned long) elf_header.e_flags, 3635 get_machine_flags (elf_header.e_flags, elf_header.e_machine)); 3636 printf (_(" Size of this header: %ld (bytes)\n"), 3637 (long) elf_header.e_ehsize); 3638 printf (_(" Size of program headers: %ld (bytes)\n"), 3639 (long) elf_header.e_phentsize); 3640 printf (_(" Number of program headers: %ld"), 3641 (long) elf_header.e_phnum); 3642 if (section_headers != NULL 3643 && elf_header.e_phnum == PN_XNUM 3644 && section_headers[0].sh_info != 0) 3645 printf (" (%ld)", (long) section_headers[0].sh_info); 3646 putc ('\n', stdout); 3647 printf (_(" Size of section headers: %ld (bytes)\n"), 3648 (long) elf_header.e_shentsize); 3649 printf (_(" Number of section headers: %ld"), 3650 (long) elf_header.e_shnum); 3651 if (section_headers != NULL && elf_header.e_shnum == SHN_UNDEF) 3652 printf (" (%ld)", (long) section_headers[0].sh_size); 3653 putc ('\n', stdout); 3654 printf (_(" Section header string table index: %ld"), 3655 (long) elf_header.e_shstrndx); 3656 if (section_headers != NULL 3657 && elf_header.e_shstrndx == (SHN_XINDEX & 0xffff)) 3658 printf (" (%u)", section_headers[0].sh_link); 3659 else if (elf_header.e_shstrndx != SHN_UNDEF 3660 && elf_header.e_shstrndx >= elf_header.e_shnum) 3661 printf (_(" <corrupt: out of range>")); 3662 putc ('\n', stdout); 3663 } 3664 3665 if (section_headers != NULL) 3666 { 3667 if (elf_header.e_phnum == PN_XNUM 3668 && section_headers[0].sh_info != 0) 3669 elf_header.e_phnum = section_headers[0].sh_info; 3670 if (elf_header.e_shnum == SHN_UNDEF) 3671 elf_header.e_shnum = section_headers[0].sh_size; 3672 if (elf_header.e_shstrndx == (SHN_XINDEX & 0xffff)) 3673 elf_header.e_shstrndx = section_headers[0].sh_link; 3674 else if (elf_header.e_shstrndx >= elf_header.e_shnum) 3675 elf_header.e_shstrndx = SHN_UNDEF; 3676 free (section_headers); 3677 section_headers = NULL; 3678 } 3679 3680 return 1; 3681 } 3682 3683 3684 static int 3685 get_32bit_program_headers (FILE * file, Elf_Internal_Phdr * pheaders) 3686 { 3687 Elf32_External_Phdr * phdrs; 3688 Elf32_External_Phdr * external; 3689 Elf_Internal_Phdr * internal; 3690 unsigned int i; 3691 3692 phdrs = (Elf32_External_Phdr *) get_data (NULL, file, elf_header.e_phoff, 3693 elf_header.e_phentsize, 3694 elf_header.e_phnum, 3695 _("program headers")); 3696 if (!phdrs) 3697 return 0; 3698 3699 for (i = 0, internal = pheaders, external = phdrs; 3700 i < elf_header.e_phnum; 3701 i++, internal++, external++) 3702 { 3703 internal->p_type = BYTE_GET (external->p_type); 3704 internal->p_offset = BYTE_GET (external->p_offset); 3705 internal->p_vaddr = BYTE_GET (external->p_vaddr); 3706 internal->p_paddr = BYTE_GET (external->p_paddr); 3707 internal->p_filesz = BYTE_GET (external->p_filesz); 3708 internal->p_memsz = BYTE_GET (external->p_memsz); 3709 internal->p_flags = BYTE_GET (external->p_flags); 3710 internal->p_align = BYTE_GET (external->p_align); 3711 } 3712 3713 free (phdrs); 3714 3715 return 1; 3716 } 3717 3718 static int 3719 get_64bit_program_headers (FILE * file, Elf_Internal_Phdr * pheaders) 3720 { 3721 Elf64_External_Phdr * phdrs; 3722 Elf64_External_Phdr * external; 3723 Elf_Internal_Phdr * internal; 3724 unsigned int i; 3725 3726 phdrs = (Elf64_External_Phdr *) get_data (NULL, file, elf_header.e_phoff, 3727 elf_header.e_phentsize, 3728 elf_header.e_phnum, 3729 _("program headers")); 3730 if (!phdrs) 3731 return 0; 3732 3733 for (i = 0, internal = pheaders, external = phdrs; 3734 i < elf_header.e_phnum; 3735 i++, internal++, external++) 3736 { 3737 internal->p_type = BYTE_GET (external->p_type); 3738 internal->p_flags = BYTE_GET (external->p_flags); 3739 internal->p_offset = BYTE_GET (external->p_offset); 3740 internal->p_vaddr = BYTE_GET (external->p_vaddr); 3741 internal->p_paddr = BYTE_GET (external->p_paddr); 3742 internal->p_filesz = BYTE_GET (external->p_filesz); 3743 internal->p_memsz = BYTE_GET (external->p_memsz); 3744 internal->p_align = BYTE_GET (external->p_align); 3745 } 3746 3747 free (phdrs); 3748 3749 return 1; 3750 } 3751 3752 /* Returns 1 if the program headers were read into `program_headers'. */ 3753 3754 static int 3755 get_program_headers (FILE * file) 3756 { 3757 Elf_Internal_Phdr * phdrs; 3758 3759 /* Check cache of prior read. */ 3760 if (program_headers != NULL) 3761 return 1; 3762 3763 phdrs = (Elf_Internal_Phdr *) cmalloc (elf_header.e_phnum, 3764 sizeof (Elf_Internal_Phdr)); 3765 3766 if (phdrs == NULL) 3767 { 3768 error (_("Out of memory\n")); 3769 return 0; 3770 } 3771 3772 if (is_32bit_elf 3773 ? get_32bit_program_headers (file, phdrs) 3774 : get_64bit_program_headers (file, phdrs)) 3775 { 3776 program_headers = phdrs; 3777 return 1; 3778 } 3779 3780 free (phdrs); 3781 return 0; 3782 } 3783 3784 /* Returns 1 if the program headers were loaded. */ 3785 3786 static int 3787 process_program_headers (FILE * file) 3788 { 3789 Elf_Internal_Phdr * segment; 3790 unsigned int i; 3791 3792 if (elf_header.e_phnum == 0) 3793 { 3794 /* PR binutils/12467. */ 3795 if (elf_header.e_phoff != 0) 3796 warn (_("possibly corrupt ELF header - it has a non-zero program" 3797 " header offset, but no program headers")); 3798 else if (do_segments) 3799 printf (_("\nThere are no program headers in this file.\n")); 3800 return 0; 3801 } 3802 3803 if (do_segments && !do_header) 3804 { 3805 printf (_("\nElf file type is %s\n"), get_file_type (elf_header.e_type)); 3806 printf (_("Entry point ")); 3807 print_vma ((bfd_vma) elf_header.e_entry, PREFIX_HEX); 3808 printf (_("\nThere are %d program headers, starting at offset "), 3809 elf_header.e_phnum); 3810 print_vma ((bfd_vma) elf_header.e_phoff, DEC); 3811 printf ("\n"); 3812 } 3813 3814 if (! get_program_headers (file)) 3815 return 0; 3816 3817 if (do_segments) 3818 { 3819 if (elf_header.e_phnum > 1) 3820 printf (_("\nProgram Headers:\n")); 3821 else 3822 printf (_("\nProgram Header:\n")); 3823 3824 if (is_32bit_elf) 3825 printf 3826 (_(" Type Offset VirtAddr PhysAddr FileSiz MemSiz Flg Align\n")); 3827 else if (do_wide) 3828 printf 3829 (_(" Type Offset VirtAddr PhysAddr FileSiz MemSiz Flg Align\n")); 3830 else 3831 { 3832 printf 3833 (_(" Type Offset VirtAddr PhysAddr\n")); 3834 printf 3835 (_(" FileSiz MemSiz Flags Align\n")); 3836 } 3837 } 3838 3839 dynamic_addr = 0; 3840 dynamic_size = 0; 3841 3842 for (i = 0, segment = program_headers; 3843 i < elf_header.e_phnum; 3844 i++, segment++) 3845 { 3846 if (do_segments) 3847 { 3848 printf (" %-14.14s ", get_segment_type (segment->p_type)); 3849 3850 if (is_32bit_elf) 3851 { 3852 printf ("0x%6.6lx ", (unsigned long) segment->p_offset); 3853 printf ("0x%8.8lx ", (unsigned long) segment->p_vaddr); 3854 printf ("0x%8.8lx ", (unsigned long) segment->p_paddr); 3855 printf ("0x%5.5lx ", (unsigned long) segment->p_filesz); 3856 printf ("0x%5.5lx ", (unsigned long) segment->p_memsz); 3857 printf ("%c%c%c ", 3858 (segment->p_flags & PF_R ? 'R' : ' '), 3859 (segment->p_flags & PF_W ? 'W' : ' '), 3860 (segment->p_flags & PF_X ? 'E' : ' ')); 3861 printf ("%#lx", (unsigned long) segment->p_align); 3862 } 3863 else if (do_wide) 3864 { 3865 if ((unsigned long) segment->p_offset == segment->p_offset) 3866 printf ("0x%6.6lx ", (unsigned long) segment->p_offset); 3867 else 3868 { 3869 print_vma (segment->p_offset, FULL_HEX); 3870 putchar (' '); 3871 } 3872 3873 print_vma (segment->p_vaddr, FULL_HEX); 3874 putchar (' '); 3875 print_vma (segment->p_paddr, FULL_HEX); 3876 putchar (' '); 3877 3878 if ((unsigned long) segment->p_filesz == segment->p_filesz) 3879 printf ("0x%6.6lx ", (unsigned long) segment->p_filesz); 3880 else 3881 { 3882 print_vma (segment->p_filesz, FULL_HEX); 3883 putchar (' '); 3884 } 3885 3886 if ((unsigned long) segment->p_memsz == segment->p_memsz) 3887 printf ("0x%6.6lx", (unsigned long) segment->p_memsz); 3888 else 3889 { 3890 print_vma (segment->p_memsz, FULL_HEX); 3891 } 3892 3893 printf (" %c%c%c ", 3894 (segment->p_flags & PF_R ? 'R' : ' '), 3895 (segment->p_flags & PF_W ? 'W' : ' '), 3896 (segment->p_flags & PF_X ? 'E' : ' ')); 3897 3898 if ((unsigned long) segment->p_align == segment->p_align) 3899 printf ("%#lx", (unsigned long) segment->p_align); 3900 else 3901 { 3902 print_vma (segment->p_align, PREFIX_HEX); 3903 } 3904 } 3905 else 3906 { 3907 print_vma (segment->p_offset, FULL_HEX); 3908 putchar (' '); 3909 print_vma (segment->p_vaddr, FULL_HEX); 3910 putchar (' '); 3911 print_vma (segment->p_paddr, FULL_HEX); 3912 printf ("\n "); 3913 print_vma (segment->p_filesz, FULL_HEX); 3914 putchar (' '); 3915 print_vma (segment->p_memsz, FULL_HEX); 3916 printf (" %c%c%c ", 3917 (segment->p_flags & PF_R ? 'R' : ' '), 3918 (segment->p_flags & PF_W ? 'W' : ' '), 3919 (segment->p_flags & PF_X ? 'E' : ' ')); 3920 print_vma (segment->p_align, HEX); 3921 } 3922 } 3923 3924 switch (segment->p_type) 3925 { 3926 case PT_DYNAMIC: 3927 if (dynamic_addr) 3928 error (_("more than one dynamic segment\n")); 3929 3930 /* By default, assume that the .dynamic section is the first 3931 section in the DYNAMIC segment. */ 3932 dynamic_addr = segment->p_offset; 3933 dynamic_size = segment->p_filesz; 3934 3935 /* Try to locate the .dynamic section. If there is 3936 a section header table, we can easily locate it. */ 3937 if (section_headers != NULL) 3938 { 3939 Elf_Internal_Shdr * sec; 3940 3941 sec = find_section (".dynamic"); 3942 if (sec == NULL || sec->sh_size == 0) 3943 { 3944 /* A corresponding .dynamic section is expected, but on 3945 IA-64/OpenVMS it is OK for it to be missing. */ 3946 if (!is_ia64_vms ()) 3947 error (_("no .dynamic section in the dynamic segment\n")); 3948 break; 3949 } 3950 3951 if (sec->sh_type == SHT_NOBITS) 3952 { 3953 dynamic_size = 0; 3954 break; 3955 } 3956 3957 dynamic_addr = sec->sh_offset; 3958 dynamic_size = sec->sh_size; 3959 3960 if (dynamic_addr < segment->p_offset 3961 || dynamic_addr > segment->p_offset + segment->p_filesz) 3962 warn (_("the .dynamic section is not contained" 3963 " within the dynamic segment\n")); 3964 else if (dynamic_addr > segment->p_offset) 3965 warn (_("the .dynamic section is not the first section" 3966 " in the dynamic segment.\n")); 3967 } 3968 break; 3969 3970 case PT_INTERP: 3971 if (fseek (file, archive_file_offset + (long) segment->p_offset, 3972 SEEK_SET)) 3973 error (_("Unable to find program interpreter name\n")); 3974 else 3975 { 3976 char fmt [32]; 3977 int ret = snprintf (fmt, sizeof (fmt), "%%%ds", PATH_MAX); 3978 3979 if (ret >= (int) sizeof (fmt) || ret < 0) 3980 error (_("Internal error: failed to create format string to display program interpreter\n")); 3981 3982 program_interpreter[0] = 0; 3983 if (fscanf (file, fmt, program_interpreter) <= 0) 3984 error (_("Unable to read program interpreter name\n")); 3985 3986 if (do_segments) 3987 printf (_("\n [Requesting program interpreter: %s]"), 3988 program_interpreter); 3989 } 3990 break; 3991 } 3992 3993 if (do_segments) 3994 putc ('\n', stdout); 3995 } 3996 3997 if (do_segments && section_headers != NULL && string_table != NULL) 3998 { 3999 printf (_("\n Section to Segment mapping:\n")); 4000 printf (_(" Segment Sections...\n")); 4001 4002 for (i = 0; i < elf_header.e_phnum; i++) 4003 { 4004 unsigned int j; 4005 Elf_Internal_Shdr * section; 4006 4007 segment = program_headers + i; 4008 section = section_headers + 1; 4009 4010 printf (" %2.2d ", i); 4011 4012 for (j = 1; j < elf_header.e_shnum; j++, section++) 4013 { 4014 if (!ELF_TBSS_SPECIAL (section, segment) 4015 && ELF_SECTION_IN_SEGMENT_STRICT (section, segment)) 4016 printf ("%s ", SECTION_NAME (section)); 4017 } 4018 4019 putc ('\n',stdout); 4020 } 4021 } 4022 4023 return 1; 4024 } 4025 4026 4027 /* Find the file offset corresponding to VMA by using the program headers. */ 4028 4029 static long 4030 offset_from_vma (FILE * file, bfd_vma vma, bfd_size_type size) 4031 { 4032 Elf_Internal_Phdr * seg; 4033 4034 if (! get_program_headers (file)) 4035 { 4036 warn (_("Cannot interpret virtual addresses without program headers.\n")); 4037 return (long) vma; 4038 } 4039 4040 for (seg = program_headers; 4041 seg < program_headers + elf_header.e_phnum; 4042 ++seg) 4043 { 4044 if (seg->p_type != PT_LOAD) 4045 continue; 4046 4047 if (vma >= (seg->p_vaddr & -seg->p_align) 4048 && vma + size <= seg->p_vaddr + seg->p_filesz) 4049 return vma - seg->p_vaddr + seg->p_offset; 4050 } 4051 4052 warn (_("Virtual address 0x%lx not located in any PT_LOAD segment.\n"), 4053 (unsigned long) vma); 4054 return (long) vma; 4055 } 4056 4057 4058 static int 4059 get_32bit_section_headers (FILE * file, unsigned int num) 4060 { 4061 Elf32_External_Shdr * shdrs; 4062 Elf_Internal_Shdr * internal; 4063 unsigned int i; 4064 4065 shdrs = (Elf32_External_Shdr *) get_data (NULL, file, elf_header.e_shoff, 4066 elf_header.e_shentsize, num, 4067 _("section headers")); 4068 if (!shdrs) 4069 return 0; 4070 4071 section_headers = (Elf_Internal_Shdr *) cmalloc (num, 4072 sizeof (Elf_Internal_Shdr)); 4073 4074 if (section_headers == NULL) 4075 { 4076 error (_("Out of memory\n")); 4077 return 0; 4078 } 4079 4080 for (i = 0, internal = section_headers; 4081 i < num; 4082 i++, internal++) 4083 { 4084 internal->sh_name = BYTE_GET (shdrs[i].sh_name); 4085 internal->sh_type = BYTE_GET (shdrs[i].sh_type); 4086 internal->sh_flags = BYTE_GET (shdrs[i].sh_flags); 4087 internal->sh_addr = BYTE_GET (shdrs[i].sh_addr); 4088 internal->sh_offset = BYTE_GET (shdrs[i].sh_offset); 4089 internal->sh_size = BYTE_GET (shdrs[i].sh_size); 4090 internal->sh_link = BYTE_GET (shdrs[i].sh_link); 4091 internal->sh_info = BYTE_GET (shdrs[i].sh_info); 4092 internal->sh_addralign = BYTE_GET (shdrs[i].sh_addralign); 4093 internal->sh_entsize = BYTE_GET (shdrs[i].sh_entsize); 4094 } 4095 4096 free (shdrs); 4097 4098 return 1; 4099 } 4100 4101 static int 4102 get_64bit_section_headers (FILE * file, unsigned int num) 4103 { 4104 Elf64_External_Shdr * shdrs; 4105 Elf_Internal_Shdr * internal; 4106 unsigned int i; 4107 4108 shdrs = (Elf64_External_Shdr *) get_data (NULL, file, elf_header.e_shoff, 4109 elf_header.e_shentsize, num, 4110 _("section headers")); 4111 if (!shdrs) 4112 return 0; 4113 4114 section_headers = (Elf_Internal_Shdr *) cmalloc (num, 4115 sizeof (Elf_Internal_Shdr)); 4116 4117 if (section_headers == NULL) 4118 { 4119 error (_("Out of memory\n")); 4120 return 0; 4121 } 4122 4123 for (i = 0, internal = section_headers; 4124 i < num; 4125 i++, internal++) 4126 { 4127 internal->sh_name = BYTE_GET (shdrs[i].sh_name); 4128 internal->sh_type = BYTE_GET (shdrs[i].sh_type); 4129 internal->sh_flags = BYTE_GET (shdrs[i].sh_flags); 4130 internal->sh_addr = BYTE_GET (shdrs[i].sh_addr); 4131 internal->sh_size = BYTE_GET (shdrs[i].sh_size); 4132 internal->sh_entsize = BYTE_GET (shdrs[i].sh_entsize); 4133 internal->sh_link = BYTE_GET (shdrs[i].sh_link); 4134 internal->sh_info = BYTE_GET (shdrs[i].sh_info); 4135 internal->sh_offset = BYTE_GET (shdrs[i].sh_offset); 4136 internal->sh_addralign = BYTE_GET (shdrs[i].sh_addralign); 4137 } 4138 4139 free (shdrs); 4140 4141 return 1; 4142 } 4143 4144 static Elf_Internal_Sym * 4145 get_32bit_elf_symbols (FILE * file, 4146 Elf_Internal_Shdr * section, 4147 unsigned long * num_syms_return) 4148 { 4149 unsigned long number = 0; 4150 Elf32_External_Sym * esyms = NULL; 4151 Elf_External_Sym_Shndx * shndx = NULL; 4152 Elf_Internal_Sym * isyms = NULL; 4153 Elf_Internal_Sym * psym; 4154 unsigned int j; 4155 4156 /* Run some sanity checks first. */ 4157 if (section->sh_entsize == 0) 4158 { 4159 error (_("sh_entsize is zero\n")); 4160 goto exit_point; 4161 } 4162 4163 number = section->sh_size / section->sh_entsize; 4164 4165 if (number * sizeof (Elf32_External_Sym) > section->sh_size + 1) 4166 { 4167 error (_("Invalid sh_entsize\n")); 4168 goto exit_point; 4169 } 4170 4171 esyms = (Elf32_External_Sym *) get_data (NULL, file, section->sh_offset, 1, 4172 section->sh_size, _("symbols")); 4173 if (esyms == NULL) 4174 goto exit_point; 4175 4176 shndx = NULL; 4177 if (symtab_shndx_hdr != NULL 4178 && (symtab_shndx_hdr->sh_link 4179 == (unsigned long) (section - section_headers))) 4180 { 4181 shndx = (Elf_External_Sym_Shndx *) get_data (NULL, file, 4182 symtab_shndx_hdr->sh_offset, 4183 1, symtab_shndx_hdr->sh_size, 4184 _("symbol table section indicies")); 4185 if (shndx == NULL) 4186 goto exit_point; 4187 } 4188 4189 isyms = (Elf_Internal_Sym *) cmalloc (number, sizeof (Elf_Internal_Sym)); 4190 4191 if (isyms == NULL) 4192 { 4193 error (_("Out of memory\n")); 4194 goto exit_point; 4195 } 4196 4197 for (j = 0, psym = isyms; j < number; j++, psym++) 4198 { 4199 psym->st_name = BYTE_GET (esyms[j].st_name); 4200 psym->st_value = BYTE_GET (esyms[j].st_value); 4201 psym->st_size = BYTE_GET (esyms[j].st_size); 4202 psym->st_shndx = BYTE_GET (esyms[j].st_shndx); 4203 if (psym->st_shndx == (SHN_XINDEX & 0xffff) && shndx != NULL) 4204 psym->st_shndx 4205 = byte_get ((unsigned char *) &shndx[j], sizeof (shndx[j])); 4206 else if (psym->st_shndx >= (SHN_LORESERVE & 0xffff)) 4207 psym->st_shndx += SHN_LORESERVE - (SHN_LORESERVE & 0xffff); 4208 psym->st_info = BYTE_GET (esyms[j].st_info); 4209 psym->st_other = BYTE_GET (esyms[j].st_other); 4210 } 4211 4212 exit_point: 4213 if (shndx != NULL) 4214 free (shndx); 4215 if (esyms != NULL) 4216 free (esyms); 4217 4218 if (num_syms_return != NULL) 4219 * num_syms_return = isyms == NULL ? 0 : number; 4220 4221 return isyms; 4222 } 4223 4224 static Elf_Internal_Sym * 4225 get_64bit_elf_symbols (FILE * file, 4226 Elf_Internal_Shdr * section, 4227 unsigned long * num_syms_return) 4228 { 4229 unsigned long number = 0; 4230 Elf64_External_Sym * esyms = NULL; 4231 Elf_External_Sym_Shndx * shndx = NULL; 4232 Elf_Internal_Sym * isyms = NULL; 4233 Elf_Internal_Sym * psym; 4234 unsigned int j; 4235 4236 /* Run some sanity checks first. */ 4237 if (section->sh_entsize == 0) 4238 { 4239 error (_("sh_entsize is zero\n")); 4240 goto exit_point; 4241 } 4242 4243 number = section->sh_size / section->sh_entsize; 4244 4245 if (number * sizeof (Elf64_External_Sym) > section->sh_size + 1) 4246 { 4247 error (_("Invalid sh_entsize\n")); 4248 goto exit_point; 4249 } 4250 4251 esyms = (Elf64_External_Sym *) get_data (NULL, file, section->sh_offset, 1, 4252 section->sh_size, _("symbols")); 4253 if (!esyms) 4254 goto exit_point; 4255 4256 if (symtab_shndx_hdr != NULL 4257 && (symtab_shndx_hdr->sh_link 4258 == (unsigned long) (section - section_headers))) 4259 { 4260 shndx = (Elf_External_Sym_Shndx *) get_data (NULL, file, 4261 symtab_shndx_hdr->sh_offset, 4262 1, symtab_shndx_hdr->sh_size, 4263 _("symbol table section indicies")); 4264 if (shndx == NULL) 4265 goto exit_point; 4266 } 4267 4268 isyms = (Elf_Internal_Sym *) cmalloc (number, sizeof (Elf_Internal_Sym)); 4269 4270 if (isyms == NULL) 4271 { 4272 error (_("Out of memory\n")); 4273 goto exit_point; 4274 } 4275 4276 for (j = 0, psym = isyms; j < number; j++, psym++) 4277 { 4278 psym->st_name = BYTE_GET (esyms[j].st_name); 4279 psym->st_info = BYTE_GET (esyms[j].st_info); 4280 psym->st_other = BYTE_GET (esyms[j].st_other); 4281 psym->st_shndx = BYTE_GET (esyms[j].st_shndx); 4282 4283 if (psym->st_shndx == (SHN_XINDEX & 0xffff) && shndx != NULL) 4284 psym->st_shndx 4285 = byte_get ((unsigned char *) &shndx[j], sizeof (shndx[j])); 4286 else if (psym->st_shndx >= (SHN_LORESERVE & 0xffff)) 4287 psym->st_shndx += SHN_LORESERVE - (SHN_LORESERVE & 0xffff); 4288 4289 psym->st_value = BYTE_GET (esyms[j].st_value); 4290 psym->st_size = BYTE_GET (esyms[j].st_size); 4291 } 4292 4293 exit_point: 4294 if (shndx != NULL) 4295 free (shndx); 4296 if (esyms != NULL) 4297 free (esyms); 4298 4299 if (num_syms_return != NULL) 4300 * num_syms_return = isyms == NULL ? 0 : number; 4301 4302 return isyms; 4303 } 4304 4305 static const char * 4306 get_elf_section_flags (bfd_vma sh_flags) 4307 { 4308 static char buff[1024]; 4309 char * p = buff; 4310 int field_size = is_32bit_elf ? 8 : 16; 4311 int sindex; 4312 int size = sizeof (buff) - (field_size + 4 + 1); 4313 bfd_vma os_flags = 0; 4314 bfd_vma proc_flags = 0; 4315 bfd_vma unknown_flags = 0; 4316 static const struct 4317 { 4318 const char * str; 4319 int len; 4320 } 4321 flags [] = 4322 { 4323 /* 0 */ { STRING_COMMA_LEN ("WRITE") }, 4324 /* 1 */ { STRING_COMMA_LEN ("ALLOC") }, 4325 /* 2 */ { STRING_COMMA_LEN ("EXEC") }, 4326 /* 3 */ { STRING_COMMA_LEN ("MERGE") }, 4327 /* 4 */ { STRING_COMMA_LEN ("STRINGS") }, 4328 /* 5 */ { STRING_COMMA_LEN ("INFO LINK") }, 4329 /* 6 */ { STRING_COMMA_LEN ("LINK ORDER") }, 4330 /* 7 */ { STRING_COMMA_LEN ("OS NONCONF") }, 4331 /* 8 */ { STRING_COMMA_LEN ("GROUP") }, 4332 /* 9 */ { STRING_COMMA_LEN ("TLS") }, 4333 /* IA-64 specific. */ 4334 /* 10 */ { STRING_COMMA_LEN ("SHORT") }, 4335 /* 11 */ { STRING_COMMA_LEN ("NORECOV") }, 4336 /* IA-64 OpenVMS specific. */ 4337 /* 12 */ { STRING_COMMA_LEN ("VMS_GLOBAL") }, 4338 /* 13 */ { STRING_COMMA_LEN ("VMS_OVERLAID") }, 4339 /* 14 */ { STRING_COMMA_LEN ("VMS_SHARED") }, 4340 /* 15 */ { STRING_COMMA_LEN ("VMS_VECTOR") }, 4341 /* 16 */ { STRING_COMMA_LEN ("VMS_ALLOC_64BIT") }, 4342 /* 17 */ { STRING_COMMA_LEN ("VMS_PROTECTED") }, 4343 /* Generic. */ 4344 /* 18 */ { STRING_COMMA_LEN ("EXCLUDE") }, 4345 /* SPARC specific. */ 4346 /* 19 */ { STRING_COMMA_LEN ("ORDERED") } 4347 }; 4348 4349 if (do_section_details) 4350 { 4351 sprintf (buff, "[%*.*lx]: ", 4352 field_size, field_size, (unsigned long) sh_flags); 4353 p += field_size + 4; 4354 } 4355 4356 while (sh_flags) 4357 { 4358 bfd_vma flag; 4359 4360 flag = sh_flags & - sh_flags; 4361 sh_flags &= ~ flag; 4362 4363 if (do_section_details) 4364 { 4365 switch (flag) 4366 { 4367 case SHF_WRITE: sindex = 0; break; 4368 case SHF_ALLOC: sindex = 1; break; 4369 case SHF_EXECINSTR: sindex = 2; break; 4370 case SHF_MERGE: sindex = 3; break; 4371 case SHF_STRINGS: sindex = 4; break; 4372 case SHF_INFO_LINK: sindex = 5; break; 4373 case SHF_LINK_ORDER: sindex = 6; break; 4374 case SHF_OS_NONCONFORMING: sindex = 7; break; 4375 case SHF_GROUP: sindex = 8; break; 4376 case SHF_TLS: sindex = 9; break; 4377 case SHF_EXCLUDE: sindex = 18; break; 4378 4379 default: 4380 sindex = -1; 4381 switch (elf_header.e_machine) 4382 { 4383 case EM_IA_64: 4384 if (flag == SHF_IA_64_SHORT) 4385 sindex = 10; 4386 else if (flag == SHF_IA_64_NORECOV) 4387 sindex = 11; 4388 #ifdef BFD64 4389 else if (elf_header.e_ident[EI_OSABI] == ELFOSABI_OPENVMS) 4390 switch (flag) 4391 { 4392 case SHF_IA_64_VMS_GLOBAL: sindex = 12; break; 4393 case SHF_IA_64_VMS_OVERLAID: sindex = 13; break; 4394 case SHF_IA_64_VMS_SHARED: sindex = 14; break; 4395 case SHF_IA_64_VMS_VECTOR: sindex = 15; break; 4396 case SHF_IA_64_VMS_ALLOC_64BIT: sindex = 16; break; 4397 case SHF_IA_64_VMS_PROTECTED: sindex = 17; break; 4398 default: break; 4399 } 4400 #endif 4401 break; 4402 4403 case EM_386: 4404 case EM_486: 4405 case EM_X86_64: 4406 case EM_L1OM: 4407 case EM_K1OM: 4408 case EM_OLD_SPARCV9: 4409 case EM_SPARC32PLUS: 4410 case EM_SPARCV9: 4411 case EM_SPARC: 4412 if (flag == SHF_ORDERED) 4413 sindex = 19; 4414 break; 4415 default: 4416 break; 4417 } 4418 } 4419 4420 if (sindex != -1) 4421 { 4422 if (p != buff + field_size + 4) 4423 { 4424 if (size < (10 + 2)) 4425 abort (); 4426 size -= 2; 4427 *p++ = ','; 4428 *p++ = ' '; 4429 } 4430 4431 size -= flags [sindex].len; 4432 p = stpcpy (p, flags [sindex].str); 4433 } 4434 else if (flag & SHF_MASKOS) 4435 os_flags |= flag; 4436 else if (flag & SHF_MASKPROC) 4437 proc_flags |= flag; 4438 else 4439 unknown_flags |= flag; 4440 } 4441 else 4442 { 4443 switch (flag) 4444 { 4445 case SHF_WRITE: *p = 'W'; break; 4446 case SHF_ALLOC: *p = 'A'; break; 4447 case SHF_EXECINSTR: *p = 'X'; break; 4448 case SHF_MERGE: *p = 'M'; break; 4449 case SHF_STRINGS: *p = 'S'; break; 4450 case SHF_INFO_LINK: *p = 'I'; break; 4451 case SHF_LINK_ORDER: *p = 'L'; break; 4452 case SHF_OS_NONCONFORMING: *p = 'O'; break; 4453 case SHF_GROUP: *p = 'G'; break; 4454 case SHF_TLS: *p = 'T'; break; 4455 case SHF_EXCLUDE: *p = 'E'; break; 4456 4457 default: 4458 if ((elf_header.e_machine == EM_X86_64 4459 || elf_header.e_machine == EM_L1OM 4460 || elf_header.e_machine == EM_K1OM) 4461 && flag == SHF_X86_64_LARGE) 4462 *p = 'l'; 4463 else if (flag & SHF_MASKOS) 4464 { 4465 *p = 'o'; 4466 sh_flags &= ~ SHF_MASKOS; 4467 } 4468 else if (flag & SHF_MASKPROC) 4469 { 4470 *p = 'p'; 4471 sh_flags &= ~ SHF_MASKPROC; 4472 } 4473 else 4474 *p = 'x'; 4475 break; 4476 } 4477 p++; 4478 } 4479 } 4480 4481 if (do_section_details) 4482 { 4483 if (os_flags) 4484 { 4485 size -= 5 + field_size; 4486 if (p != buff + field_size + 4) 4487 { 4488 if (size < (2 + 1)) 4489 abort (); 4490 size -= 2; 4491 *p++ = ','; 4492 *p++ = ' '; 4493 } 4494 sprintf (p, "OS (%*.*lx)", field_size, field_size, 4495 (unsigned long) os_flags); 4496 p += 5 + field_size; 4497 } 4498 if (proc_flags) 4499 { 4500 size -= 7 + field_size; 4501 if (p != buff + field_size + 4) 4502 { 4503 if (size < (2 + 1)) 4504 abort (); 4505 size -= 2; 4506 *p++ = ','; 4507 *p++ = ' '; 4508 } 4509 sprintf (p, "PROC (%*.*lx)", field_size, field_size, 4510 (unsigned long) proc_flags); 4511 p += 7 + field_size; 4512 } 4513 if (unknown_flags) 4514 { 4515 size -= 10 + field_size; 4516 if (p != buff + field_size + 4) 4517 { 4518 if (size < (2 + 1)) 4519 abort (); 4520 size -= 2; 4521 *p++ = ','; 4522 *p++ = ' '; 4523 } 4524 sprintf (p, _("UNKNOWN (%*.*lx)"), field_size, field_size, 4525 (unsigned long) unknown_flags); 4526 p += 10 + field_size; 4527 } 4528 } 4529 4530 *p = '\0'; 4531 return buff; 4532 } 4533 4534 static int 4535 process_section_headers (FILE * file) 4536 { 4537 Elf_Internal_Shdr * section; 4538 unsigned int i; 4539 4540 section_headers = NULL; 4541 4542 if (elf_header.e_shnum == 0) 4543 { 4544 /* PR binutils/12467. */ 4545 if (elf_header.e_shoff != 0) 4546 warn (_("possibly corrupt ELF file header - it has a non-zero" 4547 " section header offset, but no section headers\n")); 4548 else if (do_sections) 4549 printf (_("\nThere are no sections in this file.\n")); 4550 4551 return 1; 4552 } 4553 4554 if (do_sections && !do_header) 4555 printf (_("There are %d section headers, starting at offset 0x%lx:\n"), 4556 elf_header.e_shnum, (unsigned long) elf_header.e_shoff); 4557 4558 if (is_32bit_elf) 4559 { 4560 if (! get_32bit_section_headers (file, elf_header.e_shnum)) 4561 return 0; 4562 } 4563 else if (! get_64bit_section_headers (file, elf_header.e_shnum)) 4564 return 0; 4565 4566 /* Read in the string table, so that we have names to display. */ 4567 if (elf_header.e_shstrndx != SHN_UNDEF 4568 && elf_header.e_shstrndx < elf_header.e_shnum) 4569 { 4570 section = section_headers + elf_header.e_shstrndx; 4571 4572 if (section->sh_size != 0) 4573 { 4574 string_table = (char *) get_data (NULL, file, section->sh_offset, 4575 1, section->sh_size, 4576 _("string table")); 4577 4578 string_table_length = string_table != NULL ? section->sh_size : 0; 4579 } 4580 } 4581 4582 /* Scan the sections for the dynamic symbol table 4583 and dynamic string table and debug sections. */ 4584 dynamic_symbols = NULL; 4585 dynamic_strings = NULL; 4586 dynamic_syminfo = NULL; 4587 symtab_shndx_hdr = NULL; 4588 4589 eh_addr_size = is_32bit_elf ? 4 : 8; 4590 switch (elf_header.e_machine) 4591 { 4592 case EM_MIPS: 4593 case EM_MIPS_RS3_LE: 4594 /* The 64-bit MIPS EABI uses a combination of 32-bit ELF and 64-bit 4595 FDE addresses. However, the ABI also has a semi-official ILP32 4596 variant for which the normal FDE address size rules apply. 4597 4598 GCC 4.0 marks EABI64 objects with a dummy .gcc_compiled_longXX 4599 section, where XX is the size of longs in bits. Unfortunately, 4600 earlier compilers provided no way of distinguishing ILP32 objects 4601 from LP64 objects, so if there's any doubt, we should assume that 4602 the official LP64 form is being used. */ 4603 if ((elf_header.e_flags & EF_MIPS_ABI) == E_MIPS_ABI_EABI64 4604 && find_section (".gcc_compiled_long32") == NULL) 4605 eh_addr_size = 8; 4606 break; 4607 4608 case EM_H8_300: 4609 case EM_H8_300H: 4610 switch (elf_header.e_flags & EF_H8_MACH) 4611 { 4612 case E_H8_MACH_H8300: 4613 case E_H8_MACH_H8300HN: 4614 case E_H8_MACH_H8300SN: 4615 case E_H8_MACH_H8300SXN: 4616 eh_addr_size = 2; 4617 break; 4618 case E_H8_MACH_H8300H: 4619 case E_H8_MACH_H8300S: 4620 case E_H8_MACH_H8300SX: 4621 eh_addr_size = 4; 4622 break; 4623 } 4624 break; 4625 4626 case EM_M32C_OLD: 4627 case EM_M32C: 4628 switch (elf_header.e_flags & EF_M32C_CPU_MASK) 4629 { 4630 case EF_M32C_CPU_M16C: 4631 eh_addr_size = 2; 4632 break; 4633 } 4634 break; 4635 } 4636 4637 #define CHECK_ENTSIZE_VALUES(section, i, size32, size64) \ 4638 do \ 4639 { \ 4640 size_t expected_entsize \ 4641 = is_32bit_elf ? size32 : size64; \ 4642 if (section->sh_entsize != expected_entsize) \ 4643 error (_("Section %d has invalid sh_entsize %lx (expected %lx)\n"), \ 4644 i, (unsigned long int) section->sh_entsize, \ 4645 (unsigned long int) expected_entsize); \ 4646 section->sh_entsize = expected_entsize; \ 4647 } \ 4648 while (0) 4649 #define CHECK_ENTSIZE(section, i, type) \ 4650 CHECK_ENTSIZE_VALUES (section, i, sizeof (Elf32_External_##type), \ 4651 sizeof (Elf64_External_##type)) 4652 4653 for (i = 0, section = section_headers; 4654 i < elf_header.e_shnum; 4655 i++, section++) 4656 { 4657 char * name = SECTION_NAME (section); 4658 4659 if (section->sh_type == SHT_DYNSYM) 4660 { 4661 if (dynamic_symbols != NULL) 4662 { 4663 error (_("File contains multiple dynamic symbol tables\n")); 4664 continue; 4665 } 4666 4667 CHECK_ENTSIZE (section, i, Sym); 4668 dynamic_symbols = GET_ELF_SYMBOLS (file, section, & num_dynamic_syms); 4669 } 4670 else if (section->sh_type == SHT_STRTAB 4671 && streq (name, ".dynstr")) 4672 { 4673 if (dynamic_strings != NULL) 4674 { 4675 error (_("File contains multiple dynamic string tables\n")); 4676 continue; 4677 } 4678 4679 dynamic_strings = (char *) get_data (NULL, file, section->sh_offset, 4680 1, section->sh_size, 4681 _("dynamic strings")); 4682 dynamic_strings_length = dynamic_strings == NULL ? 0 : section->sh_size; 4683 } 4684 else if (section->sh_type == SHT_SYMTAB_SHNDX) 4685 { 4686 if (symtab_shndx_hdr != NULL) 4687 { 4688 error (_("File contains multiple symtab shndx tables\n")); 4689 continue; 4690 } 4691 symtab_shndx_hdr = section; 4692 } 4693 else if (section->sh_type == SHT_SYMTAB) 4694 CHECK_ENTSIZE (section, i, Sym); 4695 else if (section->sh_type == SHT_GROUP) 4696 CHECK_ENTSIZE_VALUES (section, i, GRP_ENTRY_SIZE, GRP_ENTRY_SIZE); 4697 else if (section->sh_type == SHT_REL) 4698 CHECK_ENTSIZE (section, i, Rel); 4699 else if (section->sh_type == SHT_RELA) 4700 CHECK_ENTSIZE (section, i, Rela); 4701 else if ((do_debugging || do_debug_info || do_debug_abbrevs 4702 || do_debug_lines || do_debug_pubnames || do_debug_pubtypes 4703 || do_debug_aranges || do_debug_frames || do_debug_macinfo 4704 || do_debug_str || do_debug_loc || do_debug_ranges) 4705 && (const_strneq (name, ".debug_") 4706 || const_strneq (name, ".zdebug_"))) 4707 { 4708 if (name[1] == 'z') 4709 name += sizeof (".zdebug_") - 1; 4710 else 4711 name += sizeof (".debug_") - 1; 4712 4713 if (do_debugging 4714 || (do_debug_info && const_strneq (name, "info")) 4715 || (do_debug_info && const_strneq (name, "types")) 4716 || (do_debug_abbrevs && const_strneq (name, "abbrev")) 4717 || (do_debug_lines && const_strneq (name, "line")) 4718 || (do_debug_pubnames && const_strneq (name, "pubnames")) 4719 || (do_debug_pubtypes && const_strneq (name, "pubtypes")) 4720 || (do_debug_aranges && const_strneq (name, "aranges")) 4721 || (do_debug_ranges && const_strneq (name, "ranges")) 4722 || (do_debug_frames && const_strneq (name, "frame")) 4723 || (do_debug_macinfo && const_strneq (name, "macinfo")) 4724 || (do_debug_macinfo && const_strneq (name, "macro")) 4725 || (do_debug_str && const_strneq (name, "str")) 4726 || (do_debug_loc && const_strneq (name, "loc")) 4727 ) 4728 request_dump_bynumber (i, DEBUG_DUMP); 4729 } 4730 /* Linkonce section to be combined with .debug_info at link time. */ 4731 else if ((do_debugging || do_debug_info) 4732 && const_strneq (name, ".gnu.linkonce.wi.")) 4733 request_dump_bynumber (i, DEBUG_DUMP); 4734 else if (do_debug_frames && streq (name, ".eh_frame")) 4735 request_dump_bynumber (i, DEBUG_DUMP); 4736 else if (do_gdb_index && streq (name, ".gdb_index")) 4737 request_dump_bynumber (i, DEBUG_DUMP); 4738 /* Trace sections for Itanium VMS. */ 4739 else if ((do_debugging || do_trace_info || do_trace_abbrevs 4740 || do_trace_aranges) 4741 && const_strneq (name, ".trace_")) 4742 { 4743 name += sizeof (".trace_") - 1; 4744 4745 if (do_debugging 4746 || (do_trace_info && streq (name, "info")) 4747 || (do_trace_abbrevs && streq (name, "abbrev")) 4748 || (do_trace_aranges && streq (name, "aranges")) 4749 ) 4750 request_dump_bynumber (i, DEBUG_DUMP); 4751 } 4752 4753 } 4754 4755 if (! do_sections) 4756 return 1; 4757 4758 if (elf_header.e_shnum > 1) 4759 printf (_("\nSection Headers:\n")); 4760 else 4761 printf (_("\nSection Header:\n")); 4762 4763 if (is_32bit_elf) 4764 { 4765 if (do_section_details) 4766 { 4767 printf (_(" [Nr] Name\n")); 4768 printf (_(" Type Addr Off Size ES Lk Inf Al\n")); 4769 } 4770 else 4771 printf 4772 (_(" [Nr] Name Type Addr Off Size ES Flg Lk Inf Al\n")); 4773 } 4774 else if (do_wide) 4775 { 4776 if (do_section_details) 4777 { 4778 printf (_(" [Nr] Name\n")); 4779 printf (_(" Type Address Off Size ES Lk Inf Al\n")); 4780 } 4781 else 4782 printf 4783 (_(" [Nr] Name Type Address Off Size ES Flg Lk Inf Al\n")); 4784 } 4785 else 4786 { 4787 if (do_section_details) 4788 { 4789 printf (_(" [Nr] Name\n")); 4790 printf (_(" Type Address Offset Link\n")); 4791 printf (_(" Size EntSize Info Align\n")); 4792 } 4793 else 4794 { 4795 printf (_(" [Nr] Name Type Address Offset\n")); 4796 printf (_(" Size EntSize Flags Link Info Align\n")); 4797 } 4798 } 4799 4800 if (do_section_details) 4801 printf (_(" Flags\n")); 4802 4803 for (i = 0, section = section_headers; 4804 i < elf_header.e_shnum; 4805 i++, section++) 4806 { 4807 printf (" [%2u] ", i); 4808 if (do_section_details) 4809 { 4810 print_symbol (INT_MAX, SECTION_NAME (section)); 4811 printf ("\n "); 4812 } 4813 else 4814 { 4815 print_symbol (-17, SECTION_NAME (section)); 4816 } 4817 4818 printf (do_wide ? " %-15s " : " %-15.15s ", 4819 get_section_type_name (section->sh_type)); 4820 4821 if (is_32bit_elf) 4822 { 4823 const char * link_too_big = NULL; 4824 4825 print_vma (section->sh_addr, LONG_HEX); 4826 4827 printf ( " %6.6lx %6.6lx %2.2lx", 4828 (unsigned long) section->sh_offset, 4829 (unsigned long) section->sh_size, 4830 (unsigned long) section->sh_entsize); 4831 4832 if (do_section_details) 4833 fputs (" ", stdout); 4834 else 4835 printf (" %3s ", get_elf_section_flags (section->sh_flags)); 4836 4837 if (section->sh_link >= elf_header.e_shnum) 4838 { 4839 link_too_big = ""; 4840 /* The sh_link value is out of range. Normally this indicates 4841 an error but it can have special values in Solaris binaries. */ 4842 switch (elf_header.e_machine) 4843 { 4844 case EM_386: 4845 case EM_486: 4846 case EM_X86_64: 4847 case EM_L1OM: 4848 case EM_K1OM: 4849 case EM_OLD_SPARCV9: 4850 case EM_SPARC32PLUS: 4851 case EM_SPARCV9: 4852 case EM_SPARC: 4853 if (section->sh_link == (SHN_BEFORE & 0xffff)) 4854 link_too_big = "BEFORE"; 4855 else if (section->sh_link == (SHN_AFTER & 0xffff)) 4856 link_too_big = "AFTER"; 4857 break; 4858 default: 4859 break; 4860 } 4861 } 4862 4863 if (do_section_details) 4864 { 4865 if (link_too_big != NULL && * link_too_big) 4866 printf ("<%s> ", link_too_big); 4867 else 4868 printf ("%2u ", section->sh_link); 4869 printf ("%3u %2lu\n", section->sh_info, 4870 (unsigned long) section->sh_addralign); 4871 } 4872 else 4873 printf ("%2u %3u %2lu\n", 4874 section->sh_link, 4875 section->sh_info, 4876 (unsigned long) section->sh_addralign); 4877 4878 if (link_too_big && ! * link_too_big) 4879 warn (_("section %u: sh_link value of %u is larger than the number of sections\n"), 4880 i, section->sh_link); 4881 } 4882 else if (do_wide) 4883 { 4884 print_vma (section->sh_addr, LONG_HEX); 4885 4886 if ((long) section->sh_offset == section->sh_offset) 4887 printf (" %6.6lx", (unsigned long) section->sh_offset); 4888 else 4889 { 4890 putchar (' '); 4891 print_vma (section->sh_offset, LONG_HEX); 4892 } 4893 4894 if ((unsigned long) section->sh_size == section->sh_size) 4895 printf (" %6.6lx", (unsigned long) section->sh_size); 4896 else 4897 { 4898 putchar (' '); 4899 print_vma (section->sh_size, LONG_HEX); 4900 } 4901 4902 if ((unsigned long) section->sh_entsize == section->sh_entsize) 4903 printf (" %2.2lx", (unsigned long) section->sh_entsize); 4904 else 4905 { 4906 putchar (' '); 4907 print_vma (section->sh_entsize, LONG_HEX); 4908 } 4909 4910 if (do_section_details) 4911 fputs (" ", stdout); 4912 else 4913 printf (" %3s ", get_elf_section_flags (section->sh_flags)); 4914 4915 printf ("%2u %3u ", section->sh_link, section->sh_info); 4916 4917 if ((unsigned long) section->sh_addralign == section->sh_addralign) 4918 printf ("%2lu\n", (unsigned long) section->sh_addralign); 4919 else 4920 { 4921 print_vma (section->sh_addralign, DEC); 4922 putchar ('\n'); 4923 } 4924 } 4925 else if (do_section_details) 4926 { 4927 printf (" %-15.15s ", 4928 get_section_type_name (section->sh_type)); 4929 print_vma (section->sh_addr, LONG_HEX); 4930 if ((long) section->sh_offset == section->sh_offset) 4931 printf (" %16.16lx", (unsigned long) section->sh_offset); 4932 else 4933 { 4934 printf (" "); 4935 print_vma (section->sh_offset, LONG_HEX); 4936 } 4937 printf (" %u\n ", section->sh_link); 4938 print_vma (section->sh_size, LONG_HEX); 4939 putchar (' '); 4940 print_vma (section->sh_entsize, LONG_HEX); 4941 4942 printf (" %-16u %lu\n", 4943 section->sh_info, 4944 (unsigned long) section->sh_addralign); 4945 } 4946 else 4947 { 4948 putchar (' '); 4949 print_vma (section->sh_addr, LONG_HEX); 4950 if ((long) section->sh_offset == section->sh_offset) 4951 printf (" %8.8lx", (unsigned long) section->sh_offset); 4952 else 4953 { 4954 printf (" "); 4955 print_vma (section->sh_offset, LONG_HEX); 4956 } 4957 printf ("\n "); 4958 print_vma (section->sh_size, LONG_HEX); 4959 printf (" "); 4960 print_vma (section->sh_entsize, LONG_HEX); 4961 4962 printf (" %3s ", get_elf_section_flags (section->sh_flags)); 4963 4964 printf (" %2u %3u %lu\n", 4965 section->sh_link, 4966 section->sh_info, 4967 (unsigned long) section->sh_addralign); 4968 } 4969 4970 if (do_section_details) 4971 printf (" %s\n", get_elf_section_flags (section->sh_flags)); 4972 } 4973 4974 if (!do_section_details) 4975 { 4976 if (elf_header.e_machine == EM_X86_64 4977 || elf_header.e_machine == EM_L1OM 4978 || elf_header.e_machine == EM_K1OM) 4979 printf (_("Key to Flags:\n\ 4980 W (write), A (alloc), X (execute), M (merge), S (strings), l (large)\n\ 4981 I (info), L (link order), G (group), T (TLS), E (exclude), x (unknown)\n\ 4982 O (extra OS processing required) o (OS specific), p (processor specific)\n")); 4983 else 4984 printf (_("Key to Flags:\n\ 4985 W (write), A (alloc), X (execute), M (merge), S (strings)\n\ 4986 I (info), L (link order), G (group), T (TLS), E (exclude), x (unknown)\n\ 4987 O (extra OS processing required) o (OS specific), p (processor specific)\n")); 4988 } 4989 4990 return 1; 4991 } 4992 4993 static const char * 4994 get_group_flags (unsigned int flags) 4995 { 4996 static char buff[32]; 4997 switch (flags) 4998 { 4999 case 0: 5000 return ""; 5001 5002 case GRP_COMDAT: 5003 return "COMDAT "; 5004 5005 default: 5006 snprintf (buff, sizeof (buff), _("[<unknown>: 0x%x] "), flags); 5007 break; 5008 } 5009 return buff; 5010 } 5011 5012 static int 5013 process_section_groups (FILE * file) 5014 { 5015 Elf_Internal_Shdr * section; 5016 unsigned int i; 5017 struct group * group; 5018 Elf_Internal_Shdr * symtab_sec; 5019 Elf_Internal_Shdr * strtab_sec; 5020 Elf_Internal_Sym * symtab; 5021 unsigned long num_syms; 5022 char * strtab; 5023 size_t strtab_size; 5024 5025 /* Don't process section groups unless needed. */ 5026 if (!do_unwind && !do_section_groups) 5027 return 1; 5028 5029 if (elf_header.e_shnum == 0) 5030 { 5031 if (do_section_groups) 5032 printf (_("\nThere are no sections to group in this file.\n")); 5033 5034 return 1; 5035 } 5036 5037 if (section_headers == NULL) 5038 { 5039 error (_("Section headers are not available!\n")); 5040 /* PR 13622: This can happen with a corrupt ELF header. */ 5041 return 0; 5042 } 5043 5044 section_headers_groups = (struct group **) calloc (elf_header.e_shnum, 5045 sizeof (struct group *)); 5046 5047 if (section_headers_groups == NULL) 5048 { 5049 error (_("Out of memory\n")); 5050 return 0; 5051 } 5052 5053 /* Scan the sections for the group section. */ 5054 group_count = 0; 5055 for (i = 0, section = section_headers; 5056 i < elf_header.e_shnum; 5057 i++, section++) 5058 if (section->sh_type == SHT_GROUP) 5059 group_count++; 5060 5061 if (group_count == 0) 5062 { 5063 if (do_section_groups) 5064 printf (_("\nThere are no section groups in this file.\n")); 5065 5066 return 1; 5067 } 5068 5069 section_groups = (struct group *) calloc (group_count, sizeof (struct group)); 5070 5071 if (section_groups == NULL) 5072 { 5073 error (_("Out of memory\n")); 5074 return 0; 5075 } 5076 5077 symtab_sec = NULL; 5078 strtab_sec = NULL; 5079 symtab = NULL; 5080 num_syms = 0; 5081 strtab = NULL; 5082 strtab_size = 0; 5083 for (i = 0, section = section_headers, group = section_groups; 5084 i < elf_header.e_shnum; 5085 i++, section++) 5086 { 5087 if (section->sh_type == SHT_GROUP) 5088 { 5089 char * name = SECTION_NAME (section); 5090 char * group_name; 5091 unsigned char * start; 5092 unsigned char * indices; 5093 unsigned int entry, j, size; 5094 Elf_Internal_Shdr * sec; 5095 Elf_Internal_Sym * sym; 5096 5097 /* Get the symbol table. */ 5098 if (section->sh_link >= elf_header.e_shnum 5099 || ((sec = section_headers + section->sh_link)->sh_type 5100 != SHT_SYMTAB)) 5101 { 5102 error (_("Bad sh_link in group section `%s'\n"), name); 5103 continue; 5104 } 5105 5106 if (symtab_sec != sec) 5107 { 5108 symtab_sec = sec; 5109 if (symtab) 5110 free (symtab); 5111 symtab = GET_ELF_SYMBOLS (file, symtab_sec, & num_syms); 5112 } 5113 5114 if (symtab == NULL) 5115 { 5116 error (_("Corrupt header in group section `%s'\n"), name); 5117 continue; 5118 } 5119 5120 if (section->sh_info >= num_syms) 5121 { 5122 error (_("Bad sh_info in group section `%s'\n"), name); 5123 continue; 5124 } 5125 5126 sym = symtab + section->sh_info; 5127 5128 if (ELF_ST_TYPE (sym->st_info) == STT_SECTION) 5129 { 5130 if (sym->st_shndx == 0 5131 || sym->st_shndx >= elf_header.e_shnum) 5132 { 5133 error (_("Bad sh_info in group section `%s'\n"), name); 5134 continue; 5135 } 5136 5137 group_name = SECTION_NAME (section_headers + sym->st_shndx); 5138 strtab_sec = NULL; 5139 if (strtab) 5140 free (strtab); 5141 strtab = NULL; 5142 strtab_size = 0; 5143 } 5144 else 5145 { 5146 /* Get the string table. */ 5147 if (symtab_sec->sh_link >= elf_header.e_shnum) 5148 { 5149 strtab_sec = NULL; 5150 if (strtab) 5151 free (strtab); 5152 strtab = NULL; 5153 strtab_size = 0; 5154 } 5155 else if (strtab_sec 5156 != (sec = section_headers + symtab_sec->sh_link)) 5157 { 5158 strtab_sec = sec; 5159 if (strtab) 5160 free (strtab); 5161 strtab = (char *) get_data (NULL, file, strtab_sec->sh_offset, 5162 1, strtab_sec->sh_size, 5163 _("string table")); 5164 strtab_size = strtab != NULL ? strtab_sec->sh_size : 0; 5165 } 5166 group_name = sym->st_name < strtab_size 5167 ? strtab + sym->st_name : _("<corrupt>"); 5168 } 5169 5170 start = (unsigned char *) get_data (NULL, file, section->sh_offset, 5171 1, section->sh_size, 5172 _("section data")); 5173 if (start == NULL) 5174 continue; 5175 5176 indices = start; 5177 size = (section->sh_size / section->sh_entsize) - 1; 5178 entry = byte_get (indices, 4); 5179 indices += 4; 5180 5181 if (do_section_groups) 5182 { 5183 printf (_("\n%sgroup section [%5u] `%s' [%s] contains %u sections:\n"), 5184 get_group_flags (entry), i, name, group_name, size); 5185 5186 printf (_(" [Index] Name\n")); 5187 } 5188 5189 group->group_index = i; 5190 5191 for (j = 0; j < size; j++) 5192 { 5193 struct group_list * g; 5194 5195 entry = byte_get (indices, 4); 5196 indices += 4; 5197 5198 if (entry >= elf_header.e_shnum) 5199 { 5200 error (_("section [%5u] in group section [%5u] > maximum section [%5u]\n"), 5201 entry, i, elf_header.e_shnum - 1); 5202 continue; 5203 } 5204 5205 if (section_headers_groups [entry] != NULL) 5206 { 5207 if (entry) 5208 { 5209 error (_("section [%5u] in group section [%5u] already in group section [%5u]\n"), 5210 entry, i, 5211 section_headers_groups [entry]->group_index); 5212 continue; 5213 } 5214 else 5215 { 5216 /* Intel C/C++ compiler may put section 0 in a 5217 section group. We just warn it the first time 5218 and ignore it afterwards. */ 5219 static int warned = 0; 5220 if (!warned) 5221 { 5222 error (_("section 0 in group section [%5u]\n"), 5223 section_headers_groups [entry]->group_index); 5224 warned++; 5225 } 5226 } 5227 } 5228 5229 section_headers_groups [entry] = group; 5230 5231 if (do_section_groups) 5232 { 5233 sec = section_headers + entry; 5234 printf (" [%5u] %s\n", entry, SECTION_NAME (sec)); 5235 } 5236 5237 g = (struct group_list *) xmalloc (sizeof (struct group_list)); 5238 g->section_index = entry; 5239 g->next = group->root; 5240 group->root = g; 5241 } 5242 5243 if (start) 5244 free (start); 5245 5246 group++; 5247 } 5248 } 5249 5250 if (symtab) 5251 free (symtab); 5252 if (strtab) 5253 free (strtab); 5254 return 1; 5255 } 5256 5257 /* Data used to display dynamic fixups. */ 5258 5259 struct ia64_vms_dynfixup 5260 { 5261 bfd_vma needed_ident; /* Library ident number. */ 5262 bfd_vma needed; /* Index in the dstrtab of the library name. */ 5263 bfd_vma fixup_needed; /* Index of the library. */ 5264 bfd_vma fixup_rela_cnt; /* Number of fixups. */ 5265 bfd_vma fixup_rela_off; /* Fixups offset in the dynamic segment. */ 5266 }; 5267 5268 /* Data used to display dynamic relocations. */ 5269 5270 struct ia64_vms_dynimgrela 5271 { 5272 bfd_vma img_rela_cnt; /* Number of relocations. */ 5273 bfd_vma img_rela_off; /* Reloc offset in the dynamic segment. */ 5274 }; 5275 5276 /* Display IA-64 OpenVMS dynamic fixups (used to dynamically link a shared 5277 library). */ 5278 5279 static void 5280 dump_ia64_vms_dynamic_fixups (FILE *file, struct ia64_vms_dynfixup *fixup, 5281 const char *strtab, unsigned int strtab_sz) 5282 { 5283 Elf64_External_VMS_IMAGE_FIXUP *imfs; 5284 long i; 5285 const char *lib_name; 5286 5287 imfs = get_data (NULL, file, dynamic_addr + fixup->fixup_rela_off, 5288 1, fixup->fixup_rela_cnt * sizeof (*imfs), 5289 _("dynamic section image fixups")); 5290 if (!imfs) 5291 return; 5292 5293 if (fixup->needed < strtab_sz) 5294 lib_name = strtab + fixup->needed; 5295 else 5296 { 5297 warn ("corrupt library name index of 0x%lx found in dynamic entry", 5298 (unsigned long) fixup->needed); 5299 lib_name = "???"; 5300 } 5301 printf (_("\nImage fixups for needed library #%d: %s - ident: %lx\n"), 5302 (int) fixup->fixup_needed, lib_name, (long) fixup->needed_ident); 5303 printf 5304 (_("Seg Offset Type SymVec DataType\n")); 5305 5306 for (i = 0; i < (long) fixup->fixup_rela_cnt; i++) 5307 { 5308 unsigned int type; 5309 const char *rtype; 5310 5311 printf ("%3u ", (unsigned) BYTE_GET (imfs [i].fixup_seg)); 5312 printf_vma ((bfd_vma) BYTE_GET (imfs [i].fixup_offset)); 5313 type = BYTE_GET (imfs [i].type); 5314 rtype = elf_ia64_reloc_type (type); 5315 if (rtype == NULL) 5316 printf (" 0x%08x ", type); 5317 else 5318 printf (" %-32s ", rtype); 5319 printf ("%6u ", (unsigned) BYTE_GET (imfs [i].symvec_index)); 5320 printf ("0x%08x\n", (unsigned) BYTE_GET (imfs [i].data_type)); 5321 } 5322 5323 free (imfs); 5324 } 5325 5326 /* Display IA-64 OpenVMS dynamic relocations (used to relocate an image). */ 5327 5328 static void 5329 dump_ia64_vms_dynamic_relocs (FILE *file, struct ia64_vms_dynimgrela *imgrela) 5330 { 5331 Elf64_External_VMS_IMAGE_RELA *imrs; 5332 long i; 5333 5334 imrs = get_data (NULL, file, dynamic_addr + imgrela->img_rela_off, 5335 1, imgrela->img_rela_cnt * sizeof (*imrs), 5336 _("dynamic section image relocations")); 5337 if (!imrs) 5338 return; 5339 5340 printf (_("\nImage relocs\n")); 5341 printf 5342 (_("Seg Offset Type Addend Seg Sym Off\n")); 5343 5344 for (i = 0; i < (long) imgrela->img_rela_cnt; i++) 5345 { 5346 unsigned int type; 5347 const char *rtype; 5348 5349 printf ("%3u ", (unsigned) BYTE_GET (imrs [i].rela_seg)); 5350 printf ("%08" BFD_VMA_FMT "x ", 5351 (bfd_vma) BYTE_GET (imrs [i].rela_offset)); 5352 type = BYTE_GET (imrs [i].type); 5353 rtype = elf_ia64_reloc_type (type); 5354 if (rtype == NULL) 5355 printf ("0x%08x ", type); 5356 else 5357 printf ("%-31s ", rtype); 5358 print_vma (BYTE_GET (imrs [i].addend), FULL_HEX); 5359 printf ("%3u ", (unsigned) BYTE_GET (imrs [i].sym_seg)); 5360 printf ("%08" BFD_VMA_FMT "x\n", 5361 (bfd_vma) BYTE_GET (imrs [i].sym_offset)); 5362 } 5363 5364 free (imrs); 5365 } 5366 5367 /* Display IA-64 OpenVMS dynamic relocations and fixups. */ 5368 5369 static int 5370 process_ia64_vms_dynamic_relocs (FILE *file) 5371 { 5372 struct ia64_vms_dynfixup fixup; 5373 struct ia64_vms_dynimgrela imgrela; 5374 Elf_Internal_Dyn *entry; 5375 int res = 0; 5376 bfd_vma strtab_off = 0; 5377 bfd_vma strtab_sz = 0; 5378 char *strtab = NULL; 5379 5380 memset (&fixup, 0, sizeof (fixup)); 5381 memset (&imgrela, 0, sizeof (imgrela)); 5382 5383 /* Note: the order of the entries is specified by the OpenVMS specs. */ 5384 for (entry = dynamic_section; 5385 entry < dynamic_section + dynamic_nent; 5386 entry++) 5387 { 5388 switch (entry->d_tag) 5389 { 5390 case DT_IA_64_VMS_STRTAB_OFFSET: 5391 strtab_off = entry->d_un.d_val; 5392 break; 5393 case DT_STRSZ: 5394 strtab_sz = entry->d_un.d_val; 5395 if (strtab == NULL) 5396 strtab = get_data (NULL, file, dynamic_addr + strtab_off, 5397 1, strtab_sz, _("dynamic string section")); 5398 break; 5399 5400 case DT_IA_64_VMS_NEEDED_IDENT: 5401 fixup.needed_ident = entry->d_un.d_val; 5402 break; 5403 case DT_NEEDED: 5404 fixup.needed = entry->d_un.d_val; 5405 break; 5406 case DT_IA_64_VMS_FIXUP_NEEDED: 5407 fixup.fixup_needed = entry->d_un.d_val; 5408 break; 5409 case DT_IA_64_VMS_FIXUP_RELA_CNT: 5410 fixup.fixup_rela_cnt = entry->d_un.d_val; 5411 break; 5412 case DT_IA_64_VMS_FIXUP_RELA_OFF: 5413 fixup.fixup_rela_off = entry->d_un.d_val; 5414 res++; 5415 dump_ia64_vms_dynamic_fixups (file, &fixup, strtab, strtab_sz); 5416 break; 5417 5418 case DT_IA_64_VMS_IMG_RELA_CNT: 5419 imgrela.img_rela_cnt = entry->d_un.d_val; 5420 break; 5421 case DT_IA_64_VMS_IMG_RELA_OFF: 5422 imgrela.img_rela_off = entry->d_un.d_val; 5423 res++; 5424 dump_ia64_vms_dynamic_relocs (file, &imgrela); 5425 break; 5426 5427 default: 5428 break; 5429 } 5430 } 5431 5432 if (strtab != NULL) 5433 free (strtab); 5434 5435 return res; 5436 } 5437 5438 static struct 5439 { 5440 const char * name; 5441 int reloc; 5442 int size; 5443 int rela; 5444 } dynamic_relocations [] = 5445 { 5446 { "REL", DT_REL, DT_RELSZ, FALSE }, 5447 { "RELA", DT_RELA, DT_RELASZ, TRUE }, 5448 { "PLT", DT_JMPREL, DT_PLTRELSZ, UNKNOWN } 5449 }; 5450 5451 /* Process the reloc section. */ 5452 5453 static int 5454 process_relocs (FILE * file) 5455 { 5456 unsigned long rel_size; 5457 unsigned long rel_offset; 5458 5459 5460 if (!do_reloc) 5461 return 1; 5462 5463 if (do_using_dynamic) 5464 { 5465 int is_rela; 5466 const char * name; 5467 int has_dynamic_reloc; 5468 unsigned int i; 5469 5470 has_dynamic_reloc = 0; 5471 5472 for (i = 0; i < ARRAY_SIZE (dynamic_relocations); i++) 5473 { 5474 is_rela = dynamic_relocations [i].rela; 5475 name = dynamic_relocations [i].name; 5476 rel_size = dynamic_info [dynamic_relocations [i].size]; 5477 rel_offset = dynamic_info [dynamic_relocations [i].reloc]; 5478 5479 has_dynamic_reloc |= rel_size; 5480 5481 if (is_rela == UNKNOWN) 5482 { 5483 if (dynamic_relocations [i].reloc == DT_JMPREL) 5484 switch (dynamic_info[DT_PLTREL]) 5485 { 5486 case DT_REL: 5487 is_rela = FALSE; 5488 break; 5489 case DT_RELA: 5490 is_rela = TRUE; 5491 break; 5492 } 5493 } 5494 5495 if (rel_size) 5496 { 5497 printf 5498 (_("\n'%s' relocation section at offset 0x%lx contains %ld bytes:\n"), 5499 name, rel_offset, rel_size); 5500 5501 dump_relocations (file, 5502 offset_from_vma (file, rel_offset, rel_size), 5503 rel_size, 5504 dynamic_symbols, num_dynamic_syms, 5505 dynamic_strings, dynamic_strings_length, is_rela); 5506 } 5507 } 5508 5509 if (is_ia64_vms ()) 5510 has_dynamic_reloc |= process_ia64_vms_dynamic_relocs (file); 5511 5512 if (! has_dynamic_reloc) 5513 printf (_("\nThere are no dynamic relocations in this file.\n")); 5514 } 5515 else 5516 { 5517 Elf_Internal_Shdr * section; 5518 unsigned long i; 5519 int found = 0; 5520 5521 for (i = 0, section = section_headers; 5522 i < elf_header.e_shnum; 5523 i++, section++) 5524 { 5525 if ( section->sh_type != SHT_RELA 5526 && section->sh_type != SHT_REL) 5527 continue; 5528 5529 rel_offset = section->sh_offset; 5530 rel_size = section->sh_size; 5531 5532 if (rel_size) 5533 { 5534 Elf_Internal_Shdr * strsec; 5535 int is_rela; 5536 5537 printf (_("\nRelocation section ")); 5538 5539 if (string_table == NULL) 5540 printf ("%d", section->sh_name); 5541 else 5542 printf ("'%s'", SECTION_NAME (section)); 5543 5544 printf (_(" at offset 0x%lx contains %lu entries:\n"), 5545 rel_offset, (unsigned long) (rel_size / section->sh_entsize)); 5546 5547 is_rela = section->sh_type == SHT_RELA; 5548 5549 if (section->sh_link != 0 5550 && section->sh_link < elf_header.e_shnum) 5551 { 5552 Elf_Internal_Shdr * symsec; 5553 Elf_Internal_Sym * symtab; 5554 unsigned long nsyms; 5555 unsigned long strtablen = 0; 5556 char * strtab = NULL; 5557 5558 symsec = section_headers + section->sh_link; 5559 if (symsec->sh_type != SHT_SYMTAB 5560 && symsec->sh_type != SHT_DYNSYM) 5561 continue; 5562 5563 symtab = GET_ELF_SYMBOLS (file, symsec, & nsyms); 5564 5565 if (symtab == NULL) 5566 continue; 5567 5568 if (symsec->sh_link != 0 5569 && symsec->sh_link < elf_header.e_shnum) 5570 { 5571 strsec = section_headers + symsec->sh_link; 5572 5573 strtab = (char *) get_data (NULL, file, strsec->sh_offset, 5574 1, strsec->sh_size, 5575 _("string table")); 5576 strtablen = strtab == NULL ? 0 : strsec->sh_size; 5577 } 5578 5579 dump_relocations (file, rel_offset, rel_size, 5580 symtab, nsyms, strtab, strtablen, is_rela); 5581 if (strtab) 5582 free (strtab); 5583 free (symtab); 5584 } 5585 else 5586 dump_relocations (file, rel_offset, rel_size, 5587 NULL, 0, NULL, 0, is_rela); 5588 5589 found = 1; 5590 } 5591 } 5592 5593 if (! found) 5594 printf (_("\nThere are no relocations in this file.\n")); 5595 } 5596 5597 return 1; 5598 } 5599 5600 /* Process the unwind section. */ 5601 5602 #include "unwind-ia64.h" 5603 5604 /* An absolute address consists of a section and an offset. If the 5605 section is NULL, the offset itself is the address, otherwise, the 5606 address equals to LOAD_ADDRESS(section) + offset. */ 5607 5608 struct absaddr 5609 { 5610 unsigned short section; 5611 bfd_vma offset; 5612 }; 5613 5614 #define ABSADDR(a) \ 5615 ((a).section \ 5616 ? section_headers [(a).section].sh_addr + (a).offset \ 5617 : (a).offset) 5618 5619 struct ia64_unw_table_entry 5620 { 5621 struct absaddr start; 5622 struct absaddr end; 5623 struct absaddr info; 5624 }; 5625 5626 struct ia64_unw_aux_info 5627 { 5628 5629 struct ia64_unw_table_entry *table; /* Unwind table. */ 5630 unsigned long table_len; /* Length of unwind table. */ 5631 unsigned char * info; /* Unwind info. */ 5632 unsigned long info_size; /* Size of unwind info. */ 5633 bfd_vma info_addr; /* starting address of unwind info. */ 5634 bfd_vma seg_base; /* Starting address of segment. */ 5635 Elf_Internal_Sym * symtab; /* The symbol table. */ 5636 unsigned long nsyms; /* Number of symbols. */ 5637 char * strtab; /* The string table. */ 5638 unsigned long strtab_size; /* Size of string table. */ 5639 }; 5640 5641 static void 5642 find_symbol_for_address (Elf_Internal_Sym * symtab, 5643 unsigned long nsyms, 5644 const char * strtab, 5645 unsigned long strtab_size, 5646 struct absaddr addr, 5647 const char ** symname, 5648 bfd_vma * offset) 5649 { 5650 bfd_vma dist = 0x100000; 5651 Elf_Internal_Sym * sym; 5652 Elf_Internal_Sym * best = NULL; 5653 unsigned long i; 5654 5655 REMOVE_ARCH_BITS (addr.offset); 5656 5657 for (i = 0, sym = symtab; i < nsyms; ++i, ++sym) 5658 { 5659 bfd_vma value = sym->st_value; 5660 5661 REMOVE_ARCH_BITS (value); 5662 5663 if (ELF_ST_TYPE (sym->st_info) == STT_FUNC 5664 && sym->st_name != 0 5665 && (addr.section == SHN_UNDEF || addr.section == sym->st_shndx) 5666 && addr.offset >= value 5667 && addr.offset - value < dist) 5668 { 5669 best = sym; 5670 dist = addr.offset - value; 5671 if (!dist) 5672 break; 5673 } 5674 } 5675 5676 if (best) 5677 { 5678 *symname = (best->st_name >= strtab_size 5679 ? _("<corrupt>") : strtab + best->st_name); 5680 *offset = dist; 5681 return; 5682 } 5683 5684 *symname = NULL; 5685 *offset = addr.offset; 5686 } 5687 5688 static void 5689 dump_ia64_unwind (struct ia64_unw_aux_info * aux) 5690 { 5691 struct ia64_unw_table_entry * tp; 5692 int in_body; 5693 5694 for (tp = aux->table; tp < aux->table + aux->table_len; ++tp) 5695 { 5696 bfd_vma stamp; 5697 bfd_vma offset; 5698 const unsigned char * dp; 5699 const unsigned char * head; 5700 const char * procname; 5701 5702 find_symbol_for_address (aux->symtab, aux->nsyms, aux->strtab, 5703 aux->strtab_size, tp->start, &procname, &offset); 5704 5705 fputs ("\n<", stdout); 5706 5707 if (procname) 5708 { 5709 fputs (procname, stdout); 5710 5711 if (offset) 5712 printf ("+%lx", (unsigned long) offset); 5713 } 5714 5715 fputs (">: [", stdout); 5716 print_vma (tp->start.offset, PREFIX_HEX); 5717 fputc ('-', stdout); 5718 print_vma (tp->end.offset, PREFIX_HEX); 5719 printf ("], info at +0x%lx\n", 5720 (unsigned long) (tp->info.offset - aux->seg_base)); 5721 5722 head = aux->info + (ABSADDR (tp->info) - aux->info_addr); 5723 stamp = byte_get ((unsigned char *) head, sizeof (stamp)); 5724 5725 printf (" v%u, flags=0x%lx (%s%s), len=%lu bytes\n", 5726 (unsigned) UNW_VER (stamp), 5727 (unsigned long) ((stamp & UNW_FLAG_MASK) >> 32), 5728 UNW_FLAG_EHANDLER (stamp) ? " ehandler" : "", 5729 UNW_FLAG_UHANDLER (stamp) ? " uhandler" : "", 5730 (unsigned long) (eh_addr_size * UNW_LENGTH (stamp))); 5731 5732 if (UNW_VER (stamp) != 1) 5733 { 5734 printf (_("\tUnknown version.\n")); 5735 continue; 5736 } 5737 5738 in_body = 0; 5739 for (dp = head + 8; dp < head + 8 + eh_addr_size * UNW_LENGTH (stamp);) 5740 dp = unw_decode (dp, in_body, & in_body); 5741 } 5742 } 5743 5744 static int 5745 slurp_ia64_unwind_table (FILE * file, 5746 struct ia64_unw_aux_info * aux, 5747 Elf_Internal_Shdr * sec) 5748 { 5749 unsigned long size, nrelas, i; 5750 Elf_Internal_Phdr * seg; 5751 struct ia64_unw_table_entry * tep; 5752 Elf_Internal_Shdr * relsec; 5753 Elf_Internal_Rela * rela; 5754 Elf_Internal_Rela * rp; 5755 unsigned char * table; 5756 unsigned char * tp; 5757 Elf_Internal_Sym * sym; 5758 const char * relname; 5759 5760 /* First, find the starting address of the segment that includes 5761 this section: */ 5762 5763 if (elf_header.e_phnum) 5764 { 5765 if (! get_program_headers (file)) 5766 return 0; 5767 5768 for (seg = program_headers; 5769 seg < program_headers + elf_header.e_phnum; 5770 ++seg) 5771 { 5772 if (seg->p_type != PT_LOAD) 5773 continue; 5774 5775 if (sec->sh_addr >= seg->p_vaddr 5776 && (sec->sh_addr + sec->sh_size <= seg->p_vaddr + seg->p_memsz)) 5777 { 5778 aux->seg_base = seg->p_vaddr; 5779 break; 5780 } 5781 } 5782 } 5783 5784 /* Second, build the unwind table from the contents of the unwind section: */ 5785 size = sec->sh_size; 5786 table = (unsigned char *) get_data (NULL, file, sec->sh_offset, 1, size, 5787 _("unwind table")); 5788 if (!table) 5789 return 0; 5790 5791 aux->table = (struct ia64_unw_table_entry *) 5792 xcmalloc (size / (3 * eh_addr_size), sizeof (aux->table[0])); 5793 tep = aux->table; 5794 for (tp = table; tp < table + size; ++tep) 5795 { 5796 tep->start.section = SHN_UNDEF; 5797 tep->end.section = SHN_UNDEF; 5798 tep->info.section = SHN_UNDEF; 5799 tep->start.offset = byte_get (tp, eh_addr_size); tp += eh_addr_size; 5800 tep->end.offset = byte_get (tp, eh_addr_size); tp += eh_addr_size; 5801 tep->info.offset = byte_get (tp, eh_addr_size); tp += eh_addr_size; 5802 tep->start.offset += aux->seg_base; 5803 tep->end.offset += aux->seg_base; 5804 tep->info.offset += aux->seg_base; 5805 } 5806 free (table); 5807 5808 /* Third, apply any relocations to the unwind table: */ 5809 for (relsec = section_headers; 5810 relsec < section_headers + elf_header.e_shnum; 5811 ++relsec) 5812 { 5813 if (relsec->sh_type != SHT_RELA 5814 || relsec->sh_info >= elf_header.e_shnum 5815 || section_headers + relsec->sh_info != sec) 5816 continue; 5817 5818 if (!slurp_rela_relocs (file, relsec->sh_offset, relsec->sh_size, 5819 & rela, & nrelas)) 5820 return 0; 5821 5822 for (rp = rela; rp < rela + nrelas; ++rp) 5823 { 5824 relname = elf_ia64_reloc_type (get_reloc_type (rp->r_info)); 5825 sym = aux->symtab + get_reloc_symindex (rp->r_info); 5826 5827 if (! const_strneq (relname, "R_IA64_SEGREL")) 5828 { 5829 warn (_("Skipping unexpected relocation type %s\n"), relname); 5830 continue; 5831 } 5832 5833 i = rp->r_offset / (3 * eh_addr_size); 5834 5835 switch (rp->r_offset/eh_addr_size % 3) 5836 { 5837 case 0: 5838 aux->table[i].start.section = sym->st_shndx; 5839 aux->table[i].start.offset = rp->r_addend + sym->st_value; 5840 break; 5841 case 1: 5842 aux->table[i].end.section = sym->st_shndx; 5843 aux->table[i].end.offset = rp->r_addend + sym->st_value; 5844 break; 5845 case 2: 5846 aux->table[i].info.section = sym->st_shndx; 5847 aux->table[i].info.offset = rp->r_addend + sym->st_value; 5848 break; 5849 default: 5850 break; 5851 } 5852 } 5853 5854 free (rela); 5855 } 5856 5857 aux->table_len = size / (3 * eh_addr_size); 5858 return 1; 5859 } 5860 5861 static void 5862 ia64_process_unwind (FILE * file) 5863 { 5864 Elf_Internal_Shdr * sec; 5865 Elf_Internal_Shdr * unwsec = NULL; 5866 Elf_Internal_Shdr * strsec; 5867 unsigned long i, unwcount = 0, unwstart = 0; 5868 struct ia64_unw_aux_info aux; 5869 5870 memset (& aux, 0, sizeof (aux)); 5871 5872 for (i = 0, sec = section_headers; i < elf_header.e_shnum; ++i, ++sec) 5873 { 5874 if (sec->sh_type == SHT_SYMTAB 5875 && sec->sh_link < elf_header.e_shnum) 5876 { 5877 aux.symtab = GET_ELF_SYMBOLS (file, sec, & aux.nsyms); 5878 5879 strsec = section_headers + sec->sh_link; 5880 assert (aux.strtab == NULL); 5881 aux.strtab = (char *) get_data (NULL, file, strsec->sh_offset, 5882 1, strsec->sh_size, 5883 _("string table")); 5884 aux.strtab_size = aux.strtab != NULL ? strsec->sh_size : 0; 5885 } 5886 else if (sec->sh_type == SHT_IA_64_UNWIND) 5887 unwcount++; 5888 } 5889 5890 if (!unwcount) 5891 printf (_("\nThere are no unwind sections in this file.\n")); 5892 5893 while (unwcount-- > 0) 5894 { 5895 char * suffix; 5896 size_t len, len2; 5897 5898 for (i = unwstart, sec = section_headers + unwstart; 5899 i < elf_header.e_shnum; ++i, ++sec) 5900 if (sec->sh_type == SHT_IA_64_UNWIND) 5901 { 5902 unwsec = sec; 5903 break; 5904 } 5905 5906 unwstart = i + 1; 5907 len = sizeof (ELF_STRING_ia64_unwind_once) - 1; 5908 5909 if ((unwsec->sh_flags & SHF_GROUP) != 0) 5910 { 5911 /* We need to find which section group it is in. */ 5912 struct group_list * g = section_headers_groups [i]->root; 5913 5914 for (; g != NULL; g = g->next) 5915 { 5916 sec = section_headers + g->section_index; 5917 5918 if (streq (SECTION_NAME (sec), ELF_STRING_ia64_unwind_info)) 5919 break; 5920 } 5921 5922 if (g == NULL) 5923 i = elf_header.e_shnum; 5924 } 5925 else if (strneq (SECTION_NAME (unwsec), ELF_STRING_ia64_unwind_once, len)) 5926 { 5927 /* .gnu.linkonce.ia64unw.FOO -> .gnu.linkonce.ia64unwi.FOO. */ 5928 len2 = sizeof (ELF_STRING_ia64_unwind_info_once) - 1; 5929 suffix = SECTION_NAME (unwsec) + len; 5930 for (i = 0, sec = section_headers; i < elf_header.e_shnum; 5931 ++i, ++sec) 5932 if (strneq (SECTION_NAME (sec), ELF_STRING_ia64_unwind_info_once, len2) 5933 && streq (SECTION_NAME (sec) + len2, suffix)) 5934 break; 5935 } 5936 else 5937 { 5938 /* .IA_64.unwindFOO -> .IA_64.unwind_infoFOO 5939 .IA_64.unwind or BAR -> .IA_64.unwind_info. */ 5940 len = sizeof (ELF_STRING_ia64_unwind) - 1; 5941 len2 = sizeof (ELF_STRING_ia64_unwind_info) - 1; 5942 suffix = ""; 5943 if (strneq (SECTION_NAME (unwsec), ELF_STRING_ia64_unwind, len)) 5944 suffix = SECTION_NAME (unwsec) + len; 5945 for (i = 0, sec = section_headers; i < elf_header.e_shnum; 5946 ++i, ++sec) 5947 if (strneq (SECTION_NAME (sec), ELF_STRING_ia64_unwind_info, len2) 5948 && streq (SECTION_NAME (sec) + len2, suffix)) 5949 break; 5950 } 5951 5952 if (i == elf_header.e_shnum) 5953 { 5954 printf (_("\nCould not find unwind info section for ")); 5955 5956 if (string_table == NULL) 5957 printf ("%d", unwsec->sh_name); 5958 else 5959 printf (_("'%s'"), SECTION_NAME (unwsec)); 5960 } 5961 else 5962 { 5963 aux.info_addr = sec->sh_addr; 5964 aux.info = (unsigned char *) get_data (NULL, file, sec->sh_offset, 1, 5965 sec->sh_size, 5966 _("unwind info")); 5967 aux.info_size = aux.info == NULL ? 0 : sec->sh_size; 5968 5969 printf (_("\nUnwind section ")); 5970 5971 if (string_table == NULL) 5972 printf ("%d", unwsec->sh_name); 5973 else 5974 printf (_("'%s'"), SECTION_NAME (unwsec)); 5975 5976 printf (_(" at offset 0x%lx contains %lu entries:\n"), 5977 (unsigned long) unwsec->sh_offset, 5978 (unsigned long) (unwsec->sh_size / (3 * eh_addr_size))); 5979 5980 (void) slurp_ia64_unwind_table (file, & aux, unwsec); 5981 5982 if (aux.table_len > 0) 5983 dump_ia64_unwind (& aux); 5984 5985 if (aux.table) 5986 free ((char *) aux.table); 5987 if (aux.info) 5988 free ((char *) aux.info); 5989 aux.table = NULL; 5990 aux.info = NULL; 5991 } 5992 } 5993 5994 if (aux.symtab) 5995 free (aux.symtab); 5996 if (aux.strtab) 5997 free ((char *) aux.strtab); 5998 } 5999 6000 struct hppa_unw_table_entry 6001 { 6002 struct absaddr start; 6003 struct absaddr end; 6004 unsigned int Cannot_unwind:1; /* 0 */ 6005 unsigned int Millicode:1; /* 1 */ 6006 unsigned int Millicode_save_sr0:1; /* 2 */ 6007 unsigned int Region_description:2; /* 3..4 */ 6008 unsigned int reserved1:1; /* 5 */ 6009 unsigned int Entry_SR:1; /* 6 */ 6010 unsigned int Entry_FR:4; /* number saved */ /* 7..10 */ 6011 unsigned int Entry_GR:5; /* number saved */ /* 11..15 */ 6012 unsigned int Args_stored:1; /* 16 */ 6013 unsigned int Variable_Frame:1; /* 17 */ 6014 unsigned int Separate_Package_Body:1; /* 18 */ 6015 unsigned int Frame_Extension_Millicode:1; /* 19 */ 6016 unsigned int Stack_Overflow_Check:1; /* 20 */ 6017 unsigned int Two_Instruction_SP_Increment:1; /* 21 */ 6018 unsigned int Ada_Region:1; /* 22 */ 6019 unsigned int cxx_info:1; /* 23 */ 6020 unsigned int cxx_try_catch:1; /* 24 */ 6021 unsigned int sched_entry_seq:1; /* 25 */ 6022 unsigned int reserved2:1; /* 26 */ 6023 unsigned int Save_SP:1; /* 27 */ 6024 unsigned int Save_RP:1; /* 28 */ 6025 unsigned int Save_MRP_in_frame:1; /* 29 */ 6026 unsigned int extn_ptr_defined:1; /* 30 */ 6027 unsigned int Cleanup_defined:1; /* 31 */ 6028 6029 unsigned int MPE_XL_interrupt_marker:1; /* 0 */ 6030 unsigned int HP_UX_interrupt_marker:1; /* 1 */ 6031 unsigned int Large_frame:1; /* 2 */ 6032 unsigned int Pseudo_SP_Set:1; /* 3 */ 6033 unsigned int reserved4:1; /* 4 */ 6034 unsigned int Total_frame_size:27; /* 5..31 */ 6035 }; 6036 6037 struct hppa_unw_aux_info 6038 { 6039 struct hppa_unw_table_entry *table; /* Unwind table. */ 6040 unsigned long table_len; /* Length of unwind table. */ 6041 bfd_vma seg_base; /* Starting address of segment. */ 6042 Elf_Internal_Sym * symtab; /* The symbol table. */ 6043 unsigned long nsyms; /* Number of symbols. */ 6044 char * strtab; /* The string table. */ 6045 unsigned long strtab_size; /* Size of string table. */ 6046 }; 6047 6048 static void 6049 dump_hppa_unwind (struct hppa_unw_aux_info * aux) 6050 { 6051 struct hppa_unw_table_entry * tp; 6052 6053 for (tp = aux->table; tp < aux->table + aux->table_len; ++tp) 6054 { 6055 bfd_vma offset; 6056 const char * procname; 6057 6058 find_symbol_for_address (aux->symtab, aux->nsyms, aux->strtab, 6059 aux->strtab_size, tp->start, &procname, 6060 &offset); 6061 6062 fputs ("\n<", stdout); 6063 6064 if (procname) 6065 { 6066 fputs (procname, stdout); 6067 6068 if (offset) 6069 printf ("+%lx", (unsigned long) offset); 6070 } 6071 6072 fputs (">: [", stdout); 6073 print_vma (tp->start.offset, PREFIX_HEX); 6074 fputc ('-', stdout); 6075 print_vma (tp->end.offset, PREFIX_HEX); 6076 printf ("]\n\t"); 6077 6078 #define PF(_m) if (tp->_m) printf (#_m " "); 6079 #define PV(_m) if (tp->_m) printf (#_m "=%d ", tp->_m); 6080 PF(Cannot_unwind); 6081 PF(Millicode); 6082 PF(Millicode_save_sr0); 6083 /* PV(Region_description); */ 6084 PF(Entry_SR); 6085 PV(Entry_FR); 6086 PV(Entry_GR); 6087 PF(Args_stored); 6088 PF(Variable_Frame); 6089 PF(Separate_Package_Body); 6090 PF(Frame_Extension_Millicode); 6091 PF(Stack_Overflow_Check); 6092 PF(Two_Instruction_SP_Increment); 6093 PF(Ada_Region); 6094 PF(cxx_info); 6095 PF(cxx_try_catch); 6096 PF(sched_entry_seq); 6097 PF(Save_SP); 6098 PF(Save_RP); 6099 PF(Save_MRP_in_frame); 6100 PF(extn_ptr_defined); 6101 PF(Cleanup_defined); 6102 PF(MPE_XL_interrupt_marker); 6103 PF(HP_UX_interrupt_marker); 6104 PF(Large_frame); 6105 PF(Pseudo_SP_Set); 6106 PV(Total_frame_size); 6107 #undef PF 6108 #undef PV 6109 } 6110 6111 printf ("\n"); 6112 } 6113 6114 static int 6115 slurp_hppa_unwind_table (FILE * file, 6116 struct hppa_unw_aux_info * aux, 6117 Elf_Internal_Shdr * sec) 6118 { 6119 unsigned long size, unw_ent_size, nentries, nrelas, i; 6120 Elf_Internal_Phdr * seg; 6121 struct hppa_unw_table_entry * tep; 6122 Elf_Internal_Shdr * relsec; 6123 Elf_Internal_Rela * rela; 6124 Elf_Internal_Rela * rp; 6125 unsigned char * table; 6126 unsigned char * tp; 6127 Elf_Internal_Sym * sym; 6128 const char * relname; 6129 6130 /* First, find the starting address of the segment that includes 6131 this section. */ 6132 6133 if (elf_header.e_phnum) 6134 { 6135 if (! get_program_headers (file)) 6136 return 0; 6137 6138 for (seg = program_headers; 6139 seg < program_headers + elf_header.e_phnum; 6140 ++seg) 6141 { 6142 if (seg->p_type != PT_LOAD) 6143 continue; 6144 6145 if (sec->sh_addr >= seg->p_vaddr 6146 && (sec->sh_addr + sec->sh_size <= seg->p_vaddr + seg->p_memsz)) 6147 { 6148 aux->seg_base = seg->p_vaddr; 6149 break; 6150 } 6151 } 6152 } 6153 6154 /* Second, build the unwind table from the contents of the unwind 6155 section. */ 6156 size = sec->sh_size; 6157 table = (unsigned char *) get_data (NULL, file, sec->sh_offset, 1, size, 6158 _("unwind table")); 6159 if (!table) 6160 return 0; 6161 6162 unw_ent_size = 16; 6163 nentries = size / unw_ent_size; 6164 size = unw_ent_size * nentries; 6165 6166 tep = aux->table = (struct hppa_unw_table_entry *) 6167 xcmalloc (nentries, sizeof (aux->table[0])); 6168 6169 for (tp = table; tp < table + size; tp += unw_ent_size, ++tep) 6170 { 6171 unsigned int tmp1, tmp2; 6172 6173 tep->start.section = SHN_UNDEF; 6174 tep->end.section = SHN_UNDEF; 6175 6176 tep->start.offset = byte_get ((unsigned char *) tp + 0, 4); 6177 tep->end.offset = byte_get ((unsigned char *) tp + 4, 4); 6178 tmp1 = byte_get ((unsigned char *) tp + 8, 4); 6179 tmp2 = byte_get ((unsigned char *) tp + 12, 4); 6180 6181 tep->start.offset += aux->seg_base; 6182 tep->end.offset += aux->seg_base; 6183 6184 tep->Cannot_unwind = (tmp1 >> 31) & 0x1; 6185 tep->Millicode = (tmp1 >> 30) & 0x1; 6186 tep->Millicode_save_sr0 = (tmp1 >> 29) & 0x1; 6187 tep->Region_description = (tmp1 >> 27) & 0x3; 6188 tep->reserved1 = (tmp1 >> 26) & 0x1; 6189 tep->Entry_SR = (tmp1 >> 25) & 0x1; 6190 tep->Entry_FR = (tmp1 >> 21) & 0xf; 6191 tep->Entry_GR = (tmp1 >> 16) & 0x1f; 6192 tep->Args_stored = (tmp1 >> 15) & 0x1; 6193 tep->Variable_Frame = (tmp1 >> 14) & 0x1; 6194 tep->Separate_Package_Body = (tmp1 >> 13) & 0x1; 6195 tep->Frame_Extension_Millicode = (tmp1 >> 12) & 0x1; 6196 tep->Stack_Overflow_Check = (tmp1 >> 11) & 0x1; 6197 tep->Two_Instruction_SP_Increment = (tmp1 >> 10) & 0x1; 6198 tep->Ada_Region = (tmp1 >> 9) & 0x1; 6199 tep->cxx_info = (tmp1 >> 8) & 0x1; 6200 tep->cxx_try_catch = (tmp1 >> 7) & 0x1; 6201 tep->sched_entry_seq = (tmp1 >> 6) & 0x1; 6202 tep->reserved2 = (tmp1 >> 5) & 0x1; 6203 tep->Save_SP = (tmp1 >> 4) & 0x1; 6204 tep->Save_RP = (tmp1 >> 3) & 0x1; 6205 tep->Save_MRP_in_frame = (tmp1 >> 2) & 0x1; 6206 tep->extn_ptr_defined = (tmp1 >> 1) & 0x1; 6207 tep->Cleanup_defined = tmp1 & 0x1; 6208 6209 tep->MPE_XL_interrupt_marker = (tmp2 >> 31) & 0x1; 6210 tep->HP_UX_interrupt_marker = (tmp2 >> 30) & 0x1; 6211 tep->Large_frame = (tmp2 >> 29) & 0x1; 6212 tep->Pseudo_SP_Set = (tmp2 >> 28) & 0x1; 6213 tep->reserved4 = (tmp2 >> 27) & 0x1; 6214 tep->Total_frame_size = tmp2 & 0x7ffffff; 6215 } 6216 free (table); 6217 6218 /* Third, apply any relocations to the unwind table. */ 6219 for (relsec = section_headers; 6220 relsec < section_headers + elf_header.e_shnum; 6221 ++relsec) 6222 { 6223 if (relsec->sh_type != SHT_RELA 6224 || relsec->sh_info >= elf_header.e_shnum 6225 || section_headers + relsec->sh_info != sec) 6226 continue; 6227 6228 if (!slurp_rela_relocs (file, relsec->sh_offset, relsec->sh_size, 6229 & rela, & nrelas)) 6230 return 0; 6231 6232 for (rp = rela; rp < rela + nrelas; ++rp) 6233 { 6234 relname = elf_hppa_reloc_type (get_reloc_type (rp->r_info)); 6235 sym = aux->symtab + get_reloc_symindex (rp->r_info); 6236 6237 /* R_PARISC_SEGREL32 or R_PARISC_SEGREL64. */ 6238 if (! const_strneq (relname, "R_PARISC_SEGREL")) 6239 { 6240 warn (_("Skipping unexpected relocation type %s\n"), relname); 6241 continue; 6242 } 6243 6244 i = rp->r_offset / unw_ent_size; 6245 6246 switch ((rp->r_offset % unw_ent_size) / eh_addr_size) 6247 { 6248 case 0: 6249 aux->table[i].start.section = sym->st_shndx; 6250 aux->table[i].start.offset = sym->st_value + rp->r_addend; 6251 break; 6252 case 1: 6253 aux->table[i].end.section = sym->st_shndx; 6254 aux->table[i].end.offset = sym->st_value + rp->r_addend; 6255 break; 6256 default: 6257 break; 6258 } 6259 } 6260 6261 free (rela); 6262 } 6263 6264 aux->table_len = nentries; 6265 6266 return 1; 6267 } 6268 6269 static void 6270 hppa_process_unwind (FILE * file) 6271 { 6272 struct hppa_unw_aux_info aux; 6273 Elf_Internal_Shdr * unwsec = NULL; 6274 Elf_Internal_Shdr * strsec; 6275 Elf_Internal_Shdr * sec; 6276 unsigned long i; 6277 6278 if (string_table == NULL) 6279 return; 6280 6281 memset (& aux, 0, sizeof (aux)); 6282 6283 for (i = 0, sec = section_headers; i < elf_header.e_shnum; ++i, ++sec) 6284 { 6285 if (sec->sh_type == SHT_SYMTAB 6286 && sec->sh_link < elf_header.e_shnum) 6287 { 6288 aux.symtab = GET_ELF_SYMBOLS (file, sec, & aux.nsyms); 6289 6290 strsec = section_headers + sec->sh_link; 6291 assert (aux.strtab == NULL); 6292 aux.strtab = (char *) get_data (NULL, file, strsec->sh_offset, 6293 1, strsec->sh_size, 6294 _("string table")); 6295 aux.strtab_size = aux.strtab != NULL ? strsec->sh_size : 0; 6296 } 6297 else if (streq (SECTION_NAME (sec), ".PARISC.unwind")) 6298 unwsec = sec; 6299 } 6300 6301 if (!unwsec) 6302 printf (_("\nThere are no unwind sections in this file.\n")); 6303 6304 for (i = 0, sec = section_headers; i < elf_header.e_shnum; ++i, ++sec) 6305 { 6306 if (streq (SECTION_NAME (sec), ".PARISC.unwind")) 6307 { 6308 printf (_("\nUnwind section ")); 6309 printf (_("'%s'"), SECTION_NAME (sec)); 6310 6311 printf (_(" at offset 0x%lx contains %lu entries:\n"), 6312 (unsigned long) sec->sh_offset, 6313 (unsigned long) (sec->sh_size / (2 * eh_addr_size + 8))); 6314 6315 slurp_hppa_unwind_table (file, &aux, sec); 6316 if (aux.table_len > 0) 6317 dump_hppa_unwind (&aux); 6318 6319 if (aux.table) 6320 free ((char *) aux.table); 6321 aux.table = NULL; 6322 } 6323 } 6324 6325 if (aux.symtab) 6326 free (aux.symtab); 6327 if (aux.strtab) 6328 free ((char *) aux.strtab); 6329 } 6330 6331 struct arm_section 6332 { 6333 unsigned char * data; /* The unwind data. */ 6334 Elf_Internal_Shdr * sec; /* The cached unwind section header. */ 6335 Elf_Internal_Rela * rela; /* The cached relocations for this section. */ 6336 unsigned long nrelas; /* The number of relocations. */ 6337 unsigned int rel_type; /* REL or RELA ? */ 6338 Elf_Internal_Rela * next_rela; /* Cyclic pointer to the next reloc to process. */ 6339 }; 6340 6341 struct arm_unw_aux_info 6342 { 6343 FILE * file; /* The file containing the unwind sections. */ 6344 Elf_Internal_Sym * symtab; /* The file's symbol table. */ 6345 unsigned long nsyms; /* Number of symbols. */ 6346 char * strtab; /* The file's string table. */ 6347 unsigned long strtab_size; /* Size of string table. */ 6348 }; 6349 6350 static const char * 6351 arm_print_vma_and_name (struct arm_unw_aux_info *aux, 6352 bfd_vma fn, struct absaddr addr) 6353 { 6354 const char *procname; 6355 bfd_vma sym_offset; 6356 6357 if (addr.section == SHN_UNDEF) 6358 addr.offset = fn; 6359 6360 find_symbol_for_address (aux->symtab, aux->nsyms, aux->strtab, 6361 aux->strtab_size, addr, &procname, 6362 &sym_offset); 6363 6364 print_vma (fn, PREFIX_HEX); 6365 6366 if (procname) 6367 { 6368 fputs (" <", stdout); 6369 fputs (procname, stdout); 6370 6371 if (sym_offset) 6372 printf ("+0x%lx", (unsigned long) sym_offset); 6373 fputc ('>', stdout); 6374 } 6375 6376 return procname; 6377 } 6378 6379 static void 6380 arm_free_section (struct arm_section *arm_sec) 6381 { 6382 if (arm_sec->data != NULL) 6383 free (arm_sec->data); 6384 6385 if (arm_sec->rela != NULL) 6386 free (arm_sec->rela); 6387 } 6388 6389 /* 1) If SEC does not match the one cached in ARM_SEC, then free the current 6390 cached section and install SEC instead. 6391 2) Locate the 32-bit word at WORD_OFFSET in unwind section SEC 6392 and return its valued in * WORDP, relocating if necessary. 6393 3) Update the NEXT_RELA field in ARM_SEC and store the section index and 6394 relocation's offset in ADDR. 6395 4) If SYM_NAME is non-NULL and a relocation was applied, record the offset 6396 into the string table of the symbol associated with the reloc. If no 6397 reloc was applied store -1 there. 6398 5) Return TRUE upon success, FALSE otherwise. */ 6399 6400 static bfd_boolean 6401 get_unwind_section_word (struct arm_unw_aux_info * aux, 6402 struct arm_section * arm_sec, 6403 Elf_Internal_Shdr * sec, 6404 bfd_vma word_offset, 6405 unsigned int * wordp, 6406 struct absaddr * addr, 6407 bfd_vma * sym_name) 6408 { 6409 Elf_Internal_Rela *rp; 6410 Elf_Internal_Sym *sym; 6411 const char * relname; 6412 unsigned int word; 6413 bfd_boolean wrapped; 6414 6415 addr->section = SHN_UNDEF; 6416 addr->offset = 0; 6417 6418 if (sym_name != NULL) 6419 *sym_name = (bfd_vma) -1; 6420 6421 /* If necessary, update the section cache. */ 6422 if (sec != arm_sec->sec) 6423 { 6424 Elf_Internal_Shdr *relsec; 6425 6426 arm_free_section (arm_sec); 6427 6428 arm_sec->sec = sec; 6429 arm_sec->data = get_data (NULL, aux->file, sec->sh_offset, 1, 6430 sec->sh_size, _("unwind data")); 6431 arm_sec->rela = NULL; 6432 arm_sec->nrelas = 0; 6433 6434 for (relsec = section_headers; 6435 relsec < section_headers + elf_header.e_shnum; 6436 ++relsec) 6437 { 6438 if (relsec->sh_info >= elf_header.e_shnum 6439 || section_headers + relsec->sh_info != sec) 6440 continue; 6441 6442 arm_sec->rel_type = relsec->sh_type; 6443 if (relsec->sh_type == SHT_REL) 6444 { 6445 if (!slurp_rel_relocs (aux->file, relsec->sh_offset, 6446 relsec->sh_size, 6447 & arm_sec->rela, & arm_sec->nrelas)) 6448 return FALSE; 6449 break; 6450 } 6451 else if (relsec->sh_type == SHT_RELA) 6452 { 6453 if (!slurp_rela_relocs (aux->file, relsec->sh_offset, 6454 relsec->sh_size, 6455 & arm_sec->rela, & arm_sec->nrelas)) 6456 return FALSE; 6457 break; 6458 } 6459 else 6460 warn (_("unexpected relocation type (%d) for section %d"), 6461 relsec->sh_type, relsec->sh_info); 6462 } 6463 6464 arm_sec->next_rela = arm_sec->rela; 6465 } 6466 6467 /* If there is no unwind data we can do nothing. */ 6468 if (arm_sec->data == NULL) 6469 return FALSE; 6470 6471 /* Get the word at the required offset. */ 6472 word = byte_get (arm_sec->data + word_offset, 4); 6473 6474 /* Look through the relocs to find the one that applies to the provided offset. */ 6475 wrapped = FALSE; 6476 for (rp = arm_sec->next_rela; rp != arm_sec->rela + arm_sec->nrelas; rp++) 6477 { 6478 bfd_vma prelval, offset; 6479 6480 if (rp->r_offset > word_offset && !wrapped) 6481 { 6482 rp = arm_sec->rela; 6483 wrapped = TRUE; 6484 } 6485 if (rp->r_offset > word_offset) 6486 break; 6487 6488 if (rp->r_offset & 3) 6489 { 6490 warn (_("Skipping unexpected relocation at offset 0x%lx\n"), 6491 (unsigned long) rp->r_offset); 6492 continue; 6493 } 6494 6495 if (rp->r_offset < word_offset) 6496 continue; 6497 6498 sym = aux->symtab + ELF32_R_SYM (rp->r_info); 6499 6500 if (arm_sec->rel_type == SHT_REL) 6501 { 6502 offset = word & 0x7fffffff; 6503 if (offset & 0x40000000) 6504 offset |= ~ (bfd_vma) 0x7fffffff; 6505 } 6506 else if (arm_sec->rel_type == SHT_RELA) 6507 offset = rp->r_addend; 6508 else 6509 abort (); 6510 6511 offset += sym->st_value; 6512 prelval = offset - (arm_sec->sec->sh_addr + rp->r_offset); 6513 6514 /* Check that we are processing the expected reloc type. */ 6515 if (elf_header.e_machine == EM_ARM) 6516 { 6517 relname = elf_arm_reloc_type (ELF32_R_TYPE (rp->r_info)); 6518 6519 if (streq (relname, "R_ARM_NONE")) 6520 continue; 6521 6522 if (! streq (relname, "R_ARM_PREL31")) 6523 { 6524 warn (_("Skipping unexpected relocation type %s\n"), relname); 6525 continue; 6526 } 6527 } 6528 else if (elf_header.e_machine == EM_TI_C6000) 6529 { 6530 relname = elf_tic6x_reloc_type (ELF32_R_TYPE (rp->r_info)); 6531 6532 if (streq (relname, "R_C6000_NONE")) 6533 continue; 6534 6535 if (! streq (relname, "R_C6000_PREL31")) 6536 { 6537 warn (_("Skipping unexpected relocation type %s\n"), relname); 6538 continue; 6539 } 6540 6541 prelval >>= 1; 6542 } 6543 else 6544 /* This function currently only supports ARM and TI unwinders. */ 6545 abort (); 6546 6547 word = (word & ~ (bfd_vma) 0x7fffffff) | (prelval & 0x7fffffff); 6548 addr->section = sym->st_shndx; 6549 addr->offset = offset; 6550 if (sym_name) 6551 * sym_name = sym->st_name; 6552 break; 6553 } 6554 6555 *wordp = word; 6556 arm_sec->next_rela = rp; 6557 6558 return TRUE; 6559 } 6560 6561 static const char *tic6x_unwind_regnames[16] = 6562 { 6563 "A15", "B15", "B14", "B13", "B12", "B11", "B10", "B3", 6564 "A14", "A13", "A12", "A11", "A10", 6565 "[invalid reg 13]", "[invalid reg 14]", "[invalid reg 15]" 6566 }; 6567 6568 static void 6569 decode_tic6x_unwind_regmask (unsigned int mask) 6570 { 6571 int i; 6572 6573 for (i = 12; mask; mask >>= 1, i--) 6574 { 6575 if (mask & 1) 6576 { 6577 fputs (tic6x_unwind_regnames[i], stdout); 6578 if (mask > 1) 6579 fputs (", ", stdout); 6580 } 6581 } 6582 } 6583 6584 #define ADVANCE \ 6585 if (remaining == 0 && more_words) \ 6586 { \ 6587 data_offset += 4; \ 6588 if (! get_unwind_section_word (aux, data_arm_sec, data_sec, \ 6589 data_offset, & word, & addr, NULL)) \ 6590 return; \ 6591 remaining = 4; \ 6592 more_words--; \ 6593 } \ 6594 6595 #define GET_OP(OP) \ 6596 ADVANCE; \ 6597 if (remaining) \ 6598 { \ 6599 remaining--; \ 6600 (OP) = word >> 24; \ 6601 word <<= 8; \ 6602 } \ 6603 else \ 6604 { \ 6605 printf (_("[Truncated opcode]\n")); \ 6606 return; \ 6607 } \ 6608 printf ("0x%02x ", OP) 6609 6610 static void 6611 decode_arm_unwind_bytecode (struct arm_unw_aux_info *aux, 6612 unsigned int word, unsigned int remaining, 6613 unsigned int more_words, 6614 bfd_vma data_offset, Elf_Internal_Shdr *data_sec, 6615 struct arm_section *data_arm_sec) 6616 { 6617 struct absaddr addr; 6618 6619 /* Decode the unwinding instructions. */ 6620 while (1) 6621 { 6622 unsigned int op, op2; 6623 6624 ADVANCE; 6625 if (remaining == 0) 6626 break; 6627 remaining--; 6628 op = word >> 24; 6629 word <<= 8; 6630 6631 printf (" 0x%02x ", op); 6632 6633 if ((op & 0xc0) == 0x00) 6634 { 6635 int offset = ((op & 0x3f) << 2) + 4; 6636 6637 printf (" vsp = vsp + %d", offset); 6638 } 6639 else if ((op & 0xc0) == 0x40) 6640 { 6641 int offset = ((op & 0x3f) << 2) + 4; 6642 6643 printf (" vsp = vsp - %d", offset); 6644 } 6645 else if ((op & 0xf0) == 0x80) 6646 { 6647 GET_OP (op2); 6648 if (op == 0x80 && op2 == 0) 6649 printf (_("Refuse to unwind")); 6650 else 6651 { 6652 unsigned int mask = ((op & 0x0f) << 8) | op2; 6653 int first = 1; 6654 int i; 6655 6656 printf ("pop {"); 6657 for (i = 0; i < 12; i++) 6658 if (mask & (1 << i)) 6659 { 6660 if (first) 6661 first = 0; 6662 else 6663 printf (", "); 6664 printf ("r%d", 4 + i); 6665 } 6666 printf ("}"); 6667 } 6668 } 6669 else if ((op & 0xf0) == 0x90) 6670 { 6671 if (op == 0x9d || op == 0x9f) 6672 printf (_(" [Reserved]")); 6673 else 6674 printf (" vsp = r%d", op & 0x0f); 6675 } 6676 else if ((op & 0xf0) == 0xa0) 6677 { 6678 int end = 4 + (op & 0x07); 6679 int first = 1; 6680 int i; 6681 6682 printf (" pop {"); 6683 for (i = 4; i <= end; i++) 6684 { 6685 if (first) 6686 first = 0; 6687 else 6688 printf (", "); 6689 printf ("r%d", i); 6690 } 6691 if (op & 0x08) 6692 { 6693 if (!first) 6694 printf (", "); 6695 printf ("r14"); 6696 } 6697 printf ("}"); 6698 } 6699 else if (op == 0xb0) 6700 printf (_(" finish")); 6701 else if (op == 0xb1) 6702 { 6703 GET_OP (op2); 6704 if (op2 == 0 || (op2 & 0xf0) != 0) 6705 printf (_("[Spare]")); 6706 else 6707 { 6708 unsigned int mask = op2 & 0x0f; 6709 int first = 1; 6710 int i; 6711 6712 printf ("pop {"); 6713 for (i = 0; i < 12; i++) 6714 if (mask & (1 << i)) 6715 { 6716 if (first) 6717 first = 0; 6718 else 6719 printf (", "); 6720 printf ("r%d", i); 6721 } 6722 printf ("}"); 6723 } 6724 } 6725 else if (op == 0xb2) 6726 { 6727 unsigned char buf[9]; 6728 unsigned int i, len; 6729 unsigned long offset; 6730 6731 for (i = 0; i < sizeof (buf); i++) 6732 { 6733 GET_OP (buf[i]); 6734 if ((buf[i] & 0x80) == 0) 6735 break; 6736 } 6737 assert (i < sizeof (buf)); 6738 offset = read_uleb128 (buf, &len); 6739 assert (len == i + 1); 6740 offset = offset * 4 + 0x204; 6741 printf ("vsp = vsp + %ld", offset); 6742 } 6743 else if (op == 0xb3 || op == 0xc8 || op == 0xc9) 6744 { 6745 unsigned int first, last; 6746 6747 GET_OP (op2); 6748 first = op2 >> 4; 6749 last = op2 & 0x0f; 6750 if (op == 0xc8) 6751 first = first + 16; 6752 printf ("pop {D%d", first); 6753 if (last) 6754 printf ("-D%d", first + last); 6755 printf ("}"); 6756 } 6757 else if ((op & 0xf8) == 0xb8 || (op & 0xf8) == 0xd0) 6758 { 6759 unsigned int count = op & 0x07; 6760 6761 printf ("pop {D8"); 6762 if (count) 6763 printf ("-D%d", 8 + count); 6764 printf ("}"); 6765 } 6766 else if (op >= 0xc0 && op <= 0xc5) 6767 { 6768 unsigned int count = op & 0x07; 6769 6770 printf (" pop {wR10"); 6771 if (count) 6772 printf ("-wR%d", 10 + count); 6773 printf ("}"); 6774 } 6775 else if (op == 0xc6) 6776 { 6777 unsigned int first, last; 6778 6779 GET_OP (op2); 6780 first = op2 >> 4; 6781 last = op2 & 0x0f; 6782 printf ("pop {wR%d", first); 6783 if (last) 6784 printf ("-wR%d", first + last); 6785 printf ("}"); 6786 } 6787 else if (op == 0xc7) 6788 { 6789 GET_OP (op2); 6790 if (op2 == 0 || (op2 & 0xf0) != 0) 6791 printf (_("[Spare]")); 6792 else 6793 { 6794 unsigned int mask = op2 & 0x0f; 6795 int first = 1; 6796 int i; 6797 6798 printf ("pop {"); 6799 for (i = 0; i < 4; i++) 6800 if (mask & (1 << i)) 6801 { 6802 if (first) 6803 first = 0; 6804 else 6805 printf (", "); 6806 printf ("wCGR%d", i); 6807 } 6808 printf ("}"); 6809 } 6810 } 6811 else 6812 printf (_(" [unsupported opcode]")); 6813 printf ("\n"); 6814 } 6815 } 6816 6817 static void 6818 decode_tic6x_unwind_bytecode (struct arm_unw_aux_info *aux, 6819 unsigned int word, unsigned int remaining, 6820 unsigned int more_words, 6821 bfd_vma data_offset, Elf_Internal_Shdr *data_sec, 6822 struct arm_section *data_arm_sec) 6823 { 6824 struct absaddr addr; 6825 6826 /* Decode the unwinding instructions. */ 6827 while (1) 6828 { 6829 unsigned int op, op2; 6830 6831 ADVANCE; 6832 if (remaining == 0) 6833 break; 6834 remaining--; 6835 op = word >> 24; 6836 word <<= 8; 6837 6838 printf (" 0x%02x ", op); 6839 6840 if ((op & 0xc0) == 0x00) 6841 { 6842 int offset = ((op & 0x3f) << 3) + 8; 6843 printf (" sp = sp + %d", offset); 6844 } 6845 else if ((op & 0xc0) == 0x80) 6846 { 6847 GET_OP (op2); 6848 if (op == 0x80 && op2 == 0) 6849 printf (_("Refuse to unwind")); 6850 else 6851 { 6852 unsigned int mask = ((op & 0x1f) << 8) | op2; 6853 if (op & 0x20) 6854 printf ("pop compact {"); 6855 else 6856 printf ("pop {"); 6857 6858 decode_tic6x_unwind_regmask (mask); 6859 printf("}"); 6860 } 6861 } 6862 else if ((op & 0xf0) == 0xc0) 6863 { 6864 unsigned int reg; 6865 unsigned int nregs; 6866 unsigned int i; 6867 const char *name; 6868 struct 6869 { 6870 unsigned int offset; 6871 unsigned int reg; 6872 } regpos[16]; 6873 6874 /* Scan entire instruction first so that GET_OP output is not 6875 interleaved with disassembly. */ 6876 nregs = 0; 6877 for (i = 0; nregs < (op & 0xf); i++) 6878 { 6879 GET_OP (op2); 6880 reg = op2 >> 4; 6881 if (reg != 0xf) 6882 { 6883 regpos[nregs].offset = i * 2; 6884 regpos[nregs].reg = reg; 6885 nregs++; 6886 } 6887 6888 reg = op2 & 0xf; 6889 if (reg != 0xf) 6890 { 6891 regpos[nregs].offset = i * 2 + 1; 6892 regpos[nregs].reg = reg; 6893 nregs++; 6894 } 6895 } 6896 6897 printf (_("pop frame {")); 6898 reg = nregs - 1; 6899 for (i = i * 2; i > 0; i--) 6900 { 6901 if (regpos[reg].offset == i - 1) 6902 { 6903 name = tic6x_unwind_regnames[regpos[reg].reg]; 6904 if (reg > 0) 6905 reg--; 6906 } 6907 else 6908 name = _("[pad]"); 6909 6910 fputs (name, stdout); 6911 if (i > 1) 6912 printf (", "); 6913 } 6914 6915 printf ("}"); 6916 } 6917 else if (op == 0xd0) 6918 printf (" MOV FP, SP"); 6919 else if (op == 0xd1) 6920 printf (" __c6xabi_pop_rts"); 6921 else if (op == 0xd2) 6922 { 6923 unsigned char buf[9]; 6924 unsigned int i, len; 6925 unsigned long offset; 6926 6927 for (i = 0; i < sizeof (buf); i++) 6928 { 6929 GET_OP (buf[i]); 6930 if ((buf[i] & 0x80) == 0) 6931 break; 6932 } 6933 assert (i < sizeof (buf)); 6934 offset = read_uleb128 (buf, &len); 6935 assert (len == i + 1); 6936 offset = offset * 8 + 0x408; 6937 printf (_("sp = sp + %ld"), offset); 6938 } 6939 else if ((op & 0xf0) == 0xe0) 6940 { 6941 if ((op & 0x0f) == 7) 6942 printf (" RETURN"); 6943 else 6944 printf (" MV %s, B3", tic6x_unwind_regnames[op & 0x0f]); 6945 } 6946 else 6947 { 6948 printf (_(" [unsupported opcode]")); 6949 } 6950 putchar ('\n'); 6951 } 6952 } 6953 6954 static bfd_vma 6955 arm_expand_prel31 (bfd_vma word, bfd_vma where) 6956 { 6957 bfd_vma offset; 6958 6959 offset = word & 0x7fffffff; 6960 if (offset & 0x40000000) 6961 offset |= ~ (bfd_vma) 0x7fffffff; 6962 6963 if (elf_header.e_machine == EM_TI_C6000) 6964 offset <<= 1; 6965 6966 return offset + where; 6967 } 6968 6969 static void 6970 decode_arm_unwind (struct arm_unw_aux_info * aux, 6971 unsigned int word, 6972 unsigned int remaining, 6973 bfd_vma data_offset, 6974 Elf_Internal_Shdr * data_sec, 6975 struct arm_section * data_arm_sec) 6976 { 6977 int per_index; 6978 unsigned int more_words = 0; 6979 struct absaddr addr; 6980 bfd_vma sym_name = (bfd_vma) -1; 6981 6982 if (remaining == 0) 6983 { 6984 /* Fetch the first word. 6985 Note - when decoding an object file the address extracted 6986 here will always be 0. So we also pass in the sym_name 6987 parameter so that we can find the symbol associated with 6988 the personality routine. */ 6989 if (! get_unwind_section_word (aux, data_arm_sec, data_sec, data_offset, 6990 & word, & addr, & sym_name)) 6991 return; 6992 6993 remaining = 4; 6994 } 6995 else 6996 { 6997 addr.section = SHN_UNDEF; 6998 addr.offset = 0; 6999 } 7000 7001 if ((word & 0x80000000) == 0) 7002 { 7003 /* Expand prel31 for personality routine. */ 7004 bfd_vma fn; 7005 const char *procname; 7006 7007 fn = arm_expand_prel31 (word, data_sec->sh_addr + data_offset); 7008 printf (_(" Personality routine: ")); 7009 if (fn == 0 7010 && addr.section == SHN_UNDEF && addr.offset == 0 7011 && sym_name != (bfd_vma) -1 && sym_name < aux->strtab_size) 7012 { 7013 procname = aux->strtab + sym_name; 7014 print_vma (fn, PREFIX_HEX); 7015 if (procname) 7016 { 7017 fputs (" <", stdout); 7018 fputs (procname, stdout); 7019 fputc ('>', stdout); 7020 } 7021 } 7022 else 7023 procname = arm_print_vma_and_name (aux, fn, addr); 7024 fputc ('\n', stdout); 7025 7026 /* The GCC personality routines use the standard compact 7027 encoding, starting with one byte giving the number of 7028 words. */ 7029 if (procname != NULL 7030 && (const_strneq (procname, "__gcc_personality_v0") 7031 || const_strneq (procname, "__gxx_personality_v0") 7032 || const_strneq (procname, "__gcj_personality_v0") 7033 || const_strneq (procname, "__gnu_objc_personality_v0"))) 7034 { 7035 remaining = 0; 7036 more_words = 1; 7037 ADVANCE; 7038 if (!remaining) 7039 { 7040 printf (_(" [Truncated data]\n")); 7041 return; 7042 } 7043 more_words = word >> 24; 7044 word <<= 8; 7045 remaining--; 7046 per_index = -1; 7047 } 7048 else 7049 return; 7050 } 7051 else 7052 { 7053 /* ARM EHABI Section 6.3: 7054 7055 An exception-handling table entry for the compact model looks like: 7056 7057 31 30-28 27-24 23-0 7058 -- ----- ----- ---- 7059 1 0 index Data for personalityRoutine[index] */ 7060 7061 if (elf_header.e_machine == EM_ARM 7062 && (word & 0x70000000)) 7063 warn (_("Corrupt ARM compact model table entry: %x \n"), word); 7064 7065 per_index = (word >> 24) & 0x7f; 7066 printf (_(" Compact model index: %d\n"), per_index); 7067 if (per_index == 0) 7068 { 7069 more_words = 0; 7070 word <<= 8; 7071 remaining--; 7072 } 7073 else if (per_index < 3) 7074 { 7075 more_words = (word >> 16) & 0xff; 7076 word <<= 16; 7077 remaining -= 2; 7078 } 7079 } 7080 7081 switch (elf_header.e_machine) 7082 { 7083 case EM_ARM: 7084 if (per_index < 3) 7085 { 7086 decode_arm_unwind_bytecode (aux, word, remaining, more_words, 7087 data_offset, data_sec, data_arm_sec); 7088 } 7089 else 7090 { 7091 warn (_("Unknown ARM compact model index encountered\n")); 7092 printf (_(" [reserved]\n")); 7093 } 7094 break; 7095 7096 case EM_TI_C6000: 7097 if (per_index < 3) 7098 { 7099 decode_tic6x_unwind_bytecode (aux, word, remaining, more_words, 7100 data_offset, data_sec, data_arm_sec); 7101 } 7102 else if (per_index < 5) 7103 { 7104 if (((word >> 17) & 0x7f) == 0x7f) 7105 printf (_(" Restore stack from frame pointer\n")); 7106 else 7107 printf (_(" Stack increment %d\n"), (word >> 14) & 0x1fc); 7108 printf (_(" Registers restored: ")); 7109 if (per_index == 4) 7110 printf (" (compact) "); 7111 decode_tic6x_unwind_regmask ((word >> 4) & 0x1fff); 7112 putchar ('\n'); 7113 printf (_(" Return register: %s\n"), 7114 tic6x_unwind_regnames[word & 0xf]); 7115 } 7116 else 7117 printf (_(" [reserved (%d)]\n"), per_index); 7118 break; 7119 7120 default: 7121 error (_("Unsupported architecture type %d encountered when decoding unwind table"), 7122 elf_header.e_machine); 7123 } 7124 7125 /* Decode the descriptors. Not implemented. */ 7126 } 7127 7128 static void 7129 dump_arm_unwind (struct arm_unw_aux_info *aux, Elf_Internal_Shdr *exidx_sec) 7130 { 7131 struct arm_section exidx_arm_sec, extab_arm_sec; 7132 unsigned int i, exidx_len; 7133 7134 memset (&exidx_arm_sec, 0, sizeof (exidx_arm_sec)); 7135 memset (&extab_arm_sec, 0, sizeof (extab_arm_sec)); 7136 exidx_len = exidx_sec->sh_size / 8; 7137 7138 for (i = 0; i < exidx_len; i++) 7139 { 7140 unsigned int exidx_fn, exidx_entry; 7141 struct absaddr fn_addr, entry_addr; 7142 bfd_vma fn; 7143 7144 fputc ('\n', stdout); 7145 7146 if (! get_unwind_section_word (aux, & exidx_arm_sec, exidx_sec, 7147 8 * i, & exidx_fn, & fn_addr, NULL) 7148 || ! get_unwind_section_word (aux, & exidx_arm_sec, exidx_sec, 7149 8 * i + 4, & exidx_entry, & entry_addr, NULL)) 7150 { 7151 arm_free_section (& exidx_arm_sec); 7152 arm_free_section (& extab_arm_sec); 7153 return; 7154 } 7155 7156 /* ARM EHABI, Section 5: 7157 An index table entry consists of 2 words. 7158 The first word contains a prel31 offset to the start of a function, with bit 31 clear. */ 7159 if (exidx_fn & 0x80000000) 7160 warn (_("corrupt index table entry: %x\n"), exidx_fn); 7161 7162 fn = arm_expand_prel31 (exidx_fn, exidx_sec->sh_addr + 8 * i); 7163 7164 arm_print_vma_and_name (aux, fn, fn_addr); 7165 fputs (": ", stdout); 7166 7167 if (exidx_entry == 1) 7168 { 7169 print_vma (exidx_entry, PREFIX_HEX); 7170 fputs (" [cantunwind]\n", stdout); 7171 } 7172 else if (exidx_entry & 0x80000000) 7173 { 7174 print_vma (exidx_entry, PREFIX_HEX); 7175 fputc ('\n', stdout); 7176 decode_arm_unwind (aux, exidx_entry, 4, 0, NULL, NULL); 7177 } 7178 else 7179 { 7180 bfd_vma table, table_offset = 0; 7181 Elf_Internal_Shdr *table_sec; 7182 7183 fputs ("@", stdout); 7184 table = arm_expand_prel31 (exidx_entry, exidx_sec->sh_addr + 8 * i + 4); 7185 print_vma (table, PREFIX_HEX); 7186 printf ("\n"); 7187 7188 /* Locate the matching .ARM.extab. */ 7189 if (entry_addr.section != SHN_UNDEF 7190 && entry_addr.section < elf_header.e_shnum) 7191 { 7192 table_sec = section_headers + entry_addr.section; 7193 table_offset = entry_addr.offset; 7194 } 7195 else 7196 { 7197 table_sec = find_section_by_address (table); 7198 if (table_sec != NULL) 7199 table_offset = table - table_sec->sh_addr; 7200 } 7201 if (table_sec == NULL) 7202 { 7203 warn (_("Could not locate .ARM.extab section containing 0x%lx.\n"), 7204 (unsigned long) table); 7205 continue; 7206 } 7207 decode_arm_unwind (aux, 0, 0, table_offset, table_sec, 7208 &extab_arm_sec); 7209 } 7210 } 7211 7212 printf ("\n"); 7213 7214 arm_free_section (&exidx_arm_sec); 7215 arm_free_section (&extab_arm_sec); 7216 } 7217 7218 /* Used for both ARM and C6X unwinding tables. */ 7219 7220 static void 7221 arm_process_unwind (FILE *file) 7222 { 7223 struct arm_unw_aux_info aux; 7224 Elf_Internal_Shdr *unwsec = NULL; 7225 Elf_Internal_Shdr *strsec; 7226 Elf_Internal_Shdr *sec; 7227 unsigned long i; 7228 unsigned int sec_type; 7229 7230 switch (elf_header.e_machine) 7231 { 7232 case EM_ARM: 7233 sec_type = SHT_ARM_EXIDX; 7234 break; 7235 7236 case EM_TI_C6000: 7237 sec_type = SHT_C6000_UNWIND; 7238 break; 7239 7240 default: 7241 error (_("Unsupported architecture type %d encountered when processing unwind table"), 7242 elf_header.e_machine); 7243 return; 7244 } 7245 7246 if (string_table == NULL) 7247 return; 7248 7249 memset (& aux, 0, sizeof (aux)); 7250 aux.file = file; 7251 7252 for (i = 0, sec = section_headers; i < elf_header.e_shnum; ++i, ++sec) 7253 { 7254 if (sec->sh_type == SHT_SYMTAB && sec->sh_link < elf_header.e_shnum) 7255 { 7256 aux.symtab = GET_ELF_SYMBOLS (file, sec, & aux.nsyms); 7257 7258 strsec = section_headers + sec->sh_link; 7259 assert (aux.strtab == NULL); 7260 aux.strtab = get_data (NULL, file, strsec->sh_offset, 7261 1, strsec->sh_size, _("string table")); 7262 aux.strtab_size = aux.strtab != NULL ? strsec->sh_size : 0; 7263 } 7264 else if (sec->sh_type == sec_type) 7265 unwsec = sec; 7266 } 7267 7268 if (unwsec == NULL) 7269 printf (_("\nThere are no unwind sections in this file.\n")); 7270 else 7271 for (i = 0, sec = section_headers; i < elf_header.e_shnum; ++i, ++sec) 7272 { 7273 if (sec->sh_type == sec_type) 7274 { 7275 printf (_("\nUnwind table index '%s' at offset 0x%lx contains %lu entries:\n"), 7276 SECTION_NAME (sec), 7277 (unsigned long) sec->sh_offset, 7278 (unsigned long) (sec->sh_size / (2 * eh_addr_size))); 7279 7280 dump_arm_unwind (&aux, sec); 7281 } 7282 } 7283 7284 if (aux.symtab) 7285 free (aux.symtab); 7286 if (aux.strtab) 7287 free ((char *) aux.strtab); 7288 } 7289 7290 static void 7291 process_unwind (FILE * file) 7292 { 7293 struct unwind_handler 7294 { 7295 int machtype; 7296 void (* handler)(FILE *); 7297 } handlers[] = 7298 { 7299 { EM_ARM, arm_process_unwind }, 7300 { EM_IA_64, ia64_process_unwind }, 7301 { EM_PARISC, hppa_process_unwind }, 7302 { EM_TI_C6000, arm_process_unwind }, 7303 { 0, 0 } 7304 }; 7305 int i; 7306 7307 if (!do_unwind) 7308 return; 7309 7310 for (i = 0; handlers[i].handler != NULL; i++) 7311 if (elf_header.e_machine == handlers[i].machtype) 7312 return handlers[i].handler (file); 7313 7314 printf (_("\nThe decoding of unwind sections for machine type %s is not currently supported.\n"), 7315 get_machine_name (elf_header.e_machine)); 7316 } 7317 7318 static void 7319 dynamic_section_mips_val (Elf_Internal_Dyn * entry) 7320 { 7321 switch (entry->d_tag) 7322 { 7323 case DT_MIPS_FLAGS: 7324 if (entry->d_un.d_val == 0) 7325 printf (_("NONE")); 7326 else 7327 { 7328 static const char * opts[] = 7329 { 7330 "QUICKSTART", "NOTPOT", "NO_LIBRARY_REPLACEMENT", 7331 "NO_MOVE", "SGI_ONLY", "GUARANTEE_INIT", "DELTA_C_PLUS_PLUS", 7332 "GUARANTEE_START_INIT", "PIXIE", "DEFAULT_DELAY_LOAD", 7333 "REQUICKSTART", "REQUICKSTARTED", "CORD", "NO_UNRES_UNDEF", 7334 "RLD_ORDER_SAFE" 7335 }; 7336 unsigned int cnt; 7337 int first = 1; 7338 7339 for (cnt = 0; cnt < ARRAY_SIZE (opts); ++cnt) 7340 if (entry->d_un.d_val & (1 << cnt)) 7341 { 7342 printf ("%s%s", first ? "" : " ", opts[cnt]); 7343 first = 0; 7344 } 7345 } 7346 break; 7347 7348 case DT_MIPS_IVERSION: 7349 if (VALID_DYNAMIC_NAME (entry->d_un.d_val)) 7350 printf (_("Interface Version: %s"), GET_DYNAMIC_NAME (entry->d_un.d_val)); 7351 else 7352 printf (_("<corrupt: %" BFD_VMA_FMT "d>"), entry->d_un.d_ptr); 7353 break; 7354 7355 case DT_MIPS_TIME_STAMP: 7356 { 7357 char timebuf[20]; 7358 struct tm * tmp; 7359 7360 time_t atime = entry->d_un.d_val; 7361 tmp = gmtime (&atime); 7362 snprintf (timebuf, sizeof (timebuf), "%04u-%02u-%02uT%02u:%02u:%02u", 7363 tmp->tm_year + 1900, tmp->tm_mon + 1, tmp->tm_mday, 7364 tmp->tm_hour, tmp->tm_min, tmp->tm_sec); 7365 printf (_("Time Stamp: %s"), timebuf); 7366 } 7367 break; 7368 7369 case DT_MIPS_RLD_VERSION: 7370 case DT_MIPS_LOCAL_GOTNO: 7371 case DT_MIPS_CONFLICTNO: 7372 case DT_MIPS_LIBLISTNO: 7373 case DT_MIPS_SYMTABNO: 7374 case DT_MIPS_UNREFEXTNO: 7375 case DT_MIPS_HIPAGENO: 7376 case DT_MIPS_DELTA_CLASS_NO: 7377 case DT_MIPS_DELTA_INSTANCE_NO: 7378 case DT_MIPS_DELTA_RELOC_NO: 7379 case DT_MIPS_DELTA_SYM_NO: 7380 case DT_MIPS_DELTA_CLASSSYM_NO: 7381 case DT_MIPS_COMPACT_SIZE: 7382 print_vma (entry->d_un.d_ptr, DEC); 7383 break; 7384 7385 default: 7386 print_vma (entry->d_un.d_ptr, PREFIX_HEX); 7387 } 7388 putchar ('\n'); 7389 } 7390 7391 static void 7392 dynamic_section_parisc_val (Elf_Internal_Dyn * entry) 7393 { 7394 switch (entry->d_tag) 7395 { 7396 case DT_HP_DLD_FLAGS: 7397 { 7398 static struct 7399 { 7400 long int bit; 7401 const char * str; 7402 } 7403 flags[] = 7404 { 7405 { DT_HP_DEBUG_PRIVATE, "HP_DEBUG_PRIVATE" }, 7406 { DT_HP_DEBUG_CALLBACK, "HP_DEBUG_CALLBACK" }, 7407 { DT_HP_DEBUG_CALLBACK_BOR, "HP_DEBUG_CALLBACK_BOR" }, 7408 { DT_HP_NO_ENVVAR, "HP_NO_ENVVAR" }, 7409 { DT_HP_BIND_NOW, "HP_BIND_NOW" }, 7410 { DT_HP_BIND_NONFATAL, "HP_BIND_NONFATAL" }, 7411 { DT_HP_BIND_VERBOSE, "HP_BIND_VERBOSE" }, 7412 { DT_HP_BIND_RESTRICTED, "HP_BIND_RESTRICTED" }, 7413 { DT_HP_BIND_SYMBOLIC, "HP_BIND_SYMBOLIC" }, 7414 { DT_HP_RPATH_FIRST, "HP_RPATH_FIRST" }, 7415 { DT_HP_BIND_DEPTH_FIRST, "HP_BIND_DEPTH_FIRST" }, 7416 { DT_HP_GST, "HP_GST" }, 7417 { DT_HP_SHLIB_FIXED, "HP_SHLIB_FIXED" }, 7418 { DT_HP_MERGE_SHLIB_SEG, "HP_MERGE_SHLIB_SEG" }, 7419 { DT_HP_NODELETE, "HP_NODELETE" }, 7420 { DT_HP_GROUP, "HP_GROUP" }, 7421 { DT_HP_PROTECT_LINKAGE_TABLE, "HP_PROTECT_LINKAGE_TABLE" } 7422 }; 7423 int first = 1; 7424 size_t cnt; 7425 bfd_vma val = entry->d_un.d_val; 7426 7427 for (cnt = 0; cnt < ARRAY_SIZE (flags); ++cnt) 7428 if (val & flags[cnt].bit) 7429 { 7430 if (! first) 7431 putchar (' '); 7432 fputs (flags[cnt].str, stdout); 7433 first = 0; 7434 val ^= flags[cnt].bit; 7435 } 7436 7437 if (val != 0 || first) 7438 { 7439 if (! first) 7440 putchar (' '); 7441 print_vma (val, HEX); 7442 } 7443 } 7444 break; 7445 7446 default: 7447 print_vma (entry->d_un.d_ptr, PREFIX_HEX); 7448 break; 7449 } 7450 putchar ('\n'); 7451 } 7452 7453 #ifdef BFD64 7454 7455 /* VMS vs Unix time offset and factor. */ 7456 7457 #define VMS_EPOCH_OFFSET 35067168000000000LL 7458 #define VMS_GRANULARITY_FACTOR 10000000 7459 7460 /* Display a VMS time in a human readable format. */ 7461 7462 static void 7463 print_vms_time (bfd_int64_t vmstime) 7464 { 7465 struct tm *tm; 7466 time_t unxtime; 7467 7468 unxtime = (vmstime - VMS_EPOCH_OFFSET) / VMS_GRANULARITY_FACTOR; 7469 tm = gmtime (&unxtime); 7470 printf ("%04u-%02u-%02uT%02u:%02u:%02u", 7471 tm->tm_year + 1900, tm->tm_mon + 1, tm->tm_mday, 7472 tm->tm_hour, tm->tm_min, tm->tm_sec); 7473 } 7474 #endif /* BFD64 */ 7475 7476 static void 7477 dynamic_section_ia64_val (Elf_Internal_Dyn * entry) 7478 { 7479 switch (entry->d_tag) 7480 { 7481 case DT_IA_64_PLT_RESERVE: 7482 /* First 3 slots reserved. */ 7483 print_vma (entry->d_un.d_ptr, PREFIX_HEX); 7484 printf (" -- "); 7485 print_vma (entry->d_un.d_ptr + (3 * 8), PREFIX_HEX); 7486 break; 7487 7488 case DT_IA_64_VMS_LINKTIME: 7489 #ifdef BFD64 7490 print_vms_time (entry->d_un.d_val); 7491 #endif 7492 break; 7493 7494 case DT_IA_64_VMS_LNKFLAGS: 7495 print_vma (entry->d_un.d_ptr, PREFIX_HEX); 7496 if (entry->d_un.d_val & VMS_LF_CALL_DEBUG) 7497 printf (" CALL_DEBUG"); 7498 if (entry->d_un.d_val & VMS_LF_NOP0BUFS) 7499 printf (" NOP0BUFS"); 7500 if (entry->d_un.d_val & VMS_LF_P0IMAGE) 7501 printf (" P0IMAGE"); 7502 if (entry->d_un.d_val & VMS_LF_MKTHREADS) 7503 printf (" MKTHREADS"); 7504 if (entry->d_un.d_val & VMS_LF_UPCALLS) 7505 printf (" UPCALLS"); 7506 if (entry->d_un.d_val & VMS_LF_IMGSTA) 7507 printf (" IMGSTA"); 7508 if (entry->d_un.d_val & VMS_LF_INITIALIZE) 7509 printf (" INITIALIZE"); 7510 if (entry->d_un.d_val & VMS_LF_MAIN) 7511 printf (" MAIN"); 7512 if (entry->d_un.d_val & VMS_LF_EXE_INIT) 7513 printf (" EXE_INIT"); 7514 if (entry->d_un.d_val & VMS_LF_TBK_IN_IMG) 7515 printf (" TBK_IN_IMG"); 7516 if (entry->d_un.d_val & VMS_LF_DBG_IN_IMG) 7517 printf (" DBG_IN_IMG"); 7518 if (entry->d_un.d_val & VMS_LF_TBK_IN_DSF) 7519 printf (" TBK_IN_DSF"); 7520 if (entry->d_un.d_val & VMS_LF_DBG_IN_DSF) 7521 printf (" DBG_IN_DSF"); 7522 if (entry->d_un.d_val & VMS_LF_SIGNATURES) 7523 printf (" SIGNATURES"); 7524 if (entry->d_un.d_val & VMS_LF_REL_SEG_OFF) 7525 printf (" REL_SEG_OFF"); 7526 break; 7527 7528 default: 7529 print_vma (entry->d_un.d_ptr, PREFIX_HEX); 7530 break; 7531 } 7532 putchar ('\n'); 7533 } 7534 7535 static int 7536 get_32bit_dynamic_section (FILE * file) 7537 { 7538 Elf32_External_Dyn * edyn; 7539 Elf32_External_Dyn * ext; 7540 Elf_Internal_Dyn * entry; 7541 7542 edyn = (Elf32_External_Dyn *) get_data (NULL, file, dynamic_addr, 1, 7543 dynamic_size, _("dynamic section")); 7544 if (!edyn) 7545 return 0; 7546 7547 /* SGI's ELF has more than one section in the DYNAMIC segment, and we 7548 might not have the luxury of section headers. Look for the DT_NULL 7549 terminator to determine the number of entries. */ 7550 for (ext = edyn, dynamic_nent = 0; 7551 (char *) ext < (char *) edyn + dynamic_size; 7552 ext++) 7553 { 7554 dynamic_nent++; 7555 if (BYTE_GET (ext->d_tag) == DT_NULL) 7556 break; 7557 } 7558 7559 dynamic_section = (Elf_Internal_Dyn *) cmalloc (dynamic_nent, 7560 sizeof (* entry)); 7561 if (dynamic_section == NULL) 7562 { 7563 error (_("Out of memory\n")); 7564 free (edyn); 7565 return 0; 7566 } 7567 7568 for (ext = edyn, entry = dynamic_section; 7569 entry < dynamic_section + dynamic_nent; 7570 ext++, entry++) 7571 { 7572 entry->d_tag = BYTE_GET (ext->d_tag); 7573 entry->d_un.d_val = BYTE_GET (ext->d_un.d_val); 7574 } 7575 7576 free (edyn); 7577 7578 return 1; 7579 } 7580 7581 static int 7582 get_64bit_dynamic_section (FILE * file) 7583 { 7584 Elf64_External_Dyn * edyn; 7585 Elf64_External_Dyn * ext; 7586 Elf_Internal_Dyn * entry; 7587 7588 edyn = (Elf64_External_Dyn *) get_data (NULL, file, dynamic_addr, 1, 7589 dynamic_size, _("dynamic section")); 7590 if (!edyn) 7591 return 0; 7592 7593 /* SGI's ELF has more than one section in the DYNAMIC segment, and we 7594 might not have the luxury of section headers. Look for the DT_NULL 7595 terminator to determine the number of entries. */ 7596 for (ext = edyn, dynamic_nent = 0; 7597 (char *) ext < (char *) edyn + dynamic_size; 7598 ext++) 7599 { 7600 dynamic_nent++; 7601 if (BYTE_GET (ext->d_tag) == DT_NULL) 7602 break; 7603 } 7604 7605 dynamic_section = (Elf_Internal_Dyn *) cmalloc (dynamic_nent, 7606 sizeof (* entry)); 7607 if (dynamic_section == NULL) 7608 { 7609 error (_("Out of memory\n")); 7610 free (edyn); 7611 return 0; 7612 } 7613 7614 for (ext = edyn, entry = dynamic_section; 7615 entry < dynamic_section + dynamic_nent; 7616 ext++, entry++) 7617 { 7618 entry->d_tag = BYTE_GET (ext->d_tag); 7619 entry->d_un.d_val = BYTE_GET (ext->d_un.d_val); 7620 } 7621 7622 free (edyn); 7623 7624 return 1; 7625 } 7626 7627 static void 7628 print_dynamic_flags (bfd_vma flags) 7629 { 7630 int first = 1; 7631 7632 while (flags) 7633 { 7634 bfd_vma flag; 7635 7636 flag = flags & - flags; 7637 flags &= ~ flag; 7638 7639 if (first) 7640 first = 0; 7641 else 7642 putc (' ', stdout); 7643 7644 switch (flag) 7645 { 7646 case DF_ORIGIN: fputs ("ORIGIN", stdout); break; 7647 case DF_SYMBOLIC: fputs ("SYMBOLIC", stdout); break; 7648 case DF_TEXTREL: fputs ("TEXTREL", stdout); break; 7649 case DF_BIND_NOW: fputs ("BIND_NOW", stdout); break; 7650 case DF_STATIC_TLS: fputs ("STATIC_TLS", stdout); break; 7651 default: fputs (_("unknown"), stdout); break; 7652 } 7653 } 7654 puts (""); 7655 } 7656 7657 /* Parse and display the contents of the dynamic section. */ 7658 7659 static int 7660 process_dynamic_section (FILE * file) 7661 { 7662 Elf_Internal_Dyn * entry; 7663 7664 if (dynamic_size == 0) 7665 { 7666 if (do_dynamic) 7667 printf (_("\nThere is no dynamic section in this file.\n")); 7668 7669 return 1; 7670 } 7671 7672 if (is_32bit_elf) 7673 { 7674 if (! get_32bit_dynamic_section (file)) 7675 return 0; 7676 } 7677 else if (! get_64bit_dynamic_section (file)) 7678 return 0; 7679 7680 /* Find the appropriate symbol table. */ 7681 if (dynamic_symbols == NULL) 7682 { 7683 for (entry = dynamic_section; 7684 entry < dynamic_section + dynamic_nent; 7685 ++entry) 7686 { 7687 Elf_Internal_Shdr section; 7688 7689 if (entry->d_tag != DT_SYMTAB) 7690 continue; 7691 7692 dynamic_info[DT_SYMTAB] = entry->d_un.d_val; 7693 7694 /* Since we do not know how big the symbol table is, 7695 we default to reading in the entire file (!) and 7696 processing that. This is overkill, I know, but it 7697 should work. */ 7698 section.sh_offset = offset_from_vma (file, entry->d_un.d_val, 0); 7699 7700 if (archive_file_offset != 0) 7701 section.sh_size = archive_file_size - section.sh_offset; 7702 else 7703 { 7704 if (fseek (file, 0, SEEK_END)) 7705 error (_("Unable to seek to end of file!\n")); 7706 7707 section.sh_size = ftell (file) - section.sh_offset; 7708 } 7709 7710 if (is_32bit_elf) 7711 section.sh_entsize = sizeof (Elf32_External_Sym); 7712 else 7713 section.sh_entsize = sizeof (Elf64_External_Sym); 7714 7715 dynamic_symbols = GET_ELF_SYMBOLS (file, §ion, & num_dynamic_syms); 7716 if (num_dynamic_syms < 1) 7717 { 7718 error (_("Unable to determine the number of symbols to load\n")); 7719 continue; 7720 } 7721 } 7722 } 7723 7724 /* Similarly find a string table. */ 7725 if (dynamic_strings == NULL) 7726 { 7727 for (entry = dynamic_section; 7728 entry < dynamic_section + dynamic_nent; 7729 ++entry) 7730 { 7731 unsigned long offset; 7732 long str_tab_len; 7733 7734 if (entry->d_tag != DT_STRTAB) 7735 continue; 7736 7737 dynamic_info[DT_STRTAB] = entry->d_un.d_val; 7738 7739 /* Since we do not know how big the string table is, 7740 we default to reading in the entire file (!) and 7741 processing that. This is overkill, I know, but it 7742 should work. */ 7743 7744 offset = offset_from_vma (file, entry->d_un.d_val, 0); 7745 7746 if (archive_file_offset != 0) 7747 str_tab_len = archive_file_size - offset; 7748 else 7749 { 7750 if (fseek (file, 0, SEEK_END)) 7751 error (_("Unable to seek to end of file\n")); 7752 str_tab_len = ftell (file) - offset; 7753 } 7754 7755 if (str_tab_len < 1) 7756 { 7757 error 7758 (_("Unable to determine the length of the dynamic string table\n")); 7759 continue; 7760 } 7761 7762 dynamic_strings = (char *) get_data (NULL, file, offset, 1, 7763 str_tab_len, 7764 _("dynamic string table")); 7765 dynamic_strings_length = dynamic_strings == NULL ? 0 : str_tab_len; 7766 break; 7767 } 7768 } 7769 7770 /* And find the syminfo section if available. */ 7771 if (dynamic_syminfo == NULL) 7772 { 7773 unsigned long syminsz = 0; 7774 7775 for (entry = dynamic_section; 7776 entry < dynamic_section + dynamic_nent; 7777 ++entry) 7778 { 7779 if (entry->d_tag == DT_SYMINENT) 7780 { 7781 /* Note: these braces are necessary to avoid a syntax 7782 error from the SunOS4 C compiler. */ 7783 assert (sizeof (Elf_External_Syminfo) == entry->d_un.d_val); 7784 } 7785 else if (entry->d_tag == DT_SYMINSZ) 7786 syminsz = entry->d_un.d_val; 7787 else if (entry->d_tag == DT_SYMINFO) 7788 dynamic_syminfo_offset = offset_from_vma (file, entry->d_un.d_val, 7789 syminsz); 7790 } 7791 7792 if (dynamic_syminfo_offset != 0 && syminsz != 0) 7793 { 7794 Elf_External_Syminfo * extsyminfo; 7795 Elf_External_Syminfo * extsym; 7796 Elf_Internal_Syminfo * syminfo; 7797 7798 /* There is a syminfo section. Read the data. */ 7799 extsyminfo = (Elf_External_Syminfo *) 7800 get_data (NULL, file, dynamic_syminfo_offset, 1, syminsz, 7801 _("symbol information")); 7802 if (!extsyminfo) 7803 return 0; 7804 7805 dynamic_syminfo = (Elf_Internal_Syminfo *) malloc (syminsz); 7806 if (dynamic_syminfo == NULL) 7807 { 7808 error (_("Out of memory\n")); 7809 return 0; 7810 } 7811 7812 dynamic_syminfo_nent = syminsz / sizeof (Elf_External_Syminfo); 7813 for (syminfo = dynamic_syminfo, extsym = extsyminfo; 7814 syminfo < dynamic_syminfo + dynamic_syminfo_nent; 7815 ++syminfo, ++extsym) 7816 { 7817 syminfo->si_boundto = BYTE_GET (extsym->si_boundto); 7818 syminfo->si_flags = BYTE_GET (extsym->si_flags); 7819 } 7820 7821 free (extsyminfo); 7822 } 7823 } 7824 7825 if (do_dynamic && dynamic_addr) 7826 printf (_("\nDynamic section at offset 0x%lx contains %u entries:\n"), 7827 dynamic_addr, dynamic_nent); 7828 if (do_dynamic) 7829 printf (_(" Tag Type Name/Value\n")); 7830 7831 for (entry = dynamic_section; 7832 entry < dynamic_section + dynamic_nent; 7833 entry++) 7834 { 7835 if (do_dynamic) 7836 { 7837 const char * dtype; 7838 7839 putchar (' '); 7840 print_vma (entry->d_tag, FULL_HEX); 7841 dtype = get_dynamic_type (entry->d_tag); 7842 printf (" (%s)%*s", dtype, 7843 ((is_32bit_elf ? 27 : 19) 7844 - (int) strlen (dtype)), 7845 " "); 7846 } 7847 7848 switch (entry->d_tag) 7849 { 7850 case DT_FLAGS: 7851 if (do_dynamic) 7852 print_dynamic_flags (entry->d_un.d_val); 7853 break; 7854 7855 case DT_AUXILIARY: 7856 case DT_FILTER: 7857 case DT_CONFIG: 7858 case DT_DEPAUDIT: 7859 case DT_AUDIT: 7860 if (do_dynamic) 7861 { 7862 switch (entry->d_tag) 7863 { 7864 case DT_AUXILIARY: 7865 printf (_("Auxiliary library")); 7866 break; 7867 7868 case DT_FILTER: 7869 printf (_("Filter library")); 7870 break; 7871 7872 case DT_CONFIG: 7873 printf (_("Configuration file")); 7874 break; 7875 7876 case DT_DEPAUDIT: 7877 printf (_("Dependency audit library")); 7878 break; 7879 7880 case DT_AUDIT: 7881 printf (_("Audit library")); 7882 break; 7883 } 7884 7885 if (VALID_DYNAMIC_NAME (entry->d_un.d_val)) 7886 printf (": [%s]\n", GET_DYNAMIC_NAME (entry->d_un.d_val)); 7887 else 7888 { 7889 printf (": "); 7890 print_vma (entry->d_un.d_val, PREFIX_HEX); 7891 putchar ('\n'); 7892 } 7893 } 7894 break; 7895 7896 case DT_FEATURE: 7897 if (do_dynamic) 7898 { 7899 printf (_("Flags:")); 7900 7901 if (entry->d_un.d_val == 0) 7902 printf (_(" None\n")); 7903 else 7904 { 7905 unsigned long int val = entry->d_un.d_val; 7906 7907 if (val & DTF_1_PARINIT) 7908 { 7909 printf (" PARINIT"); 7910 val ^= DTF_1_PARINIT; 7911 } 7912 if (val & DTF_1_CONFEXP) 7913 { 7914 printf (" CONFEXP"); 7915 val ^= DTF_1_CONFEXP; 7916 } 7917 if (val != 0) 7918 printf (" %lx", val); 7919 puts (""); 7920 } 7921 } 7922 break; 7923 7924 case DT_POSFLAG_1: 7925 if (do_dynamic) 7926 { 7927 printf (_("Flags:")); 7928 7929 if (entry->d_un.d_val == 0) 7930 printf (_(" None\n")); 7931 else 7932 { 7933 unsigned long int val = entry->d_un.d_val; 7934 7935 if (val & DF_P1_LAZYLOAD) 7936 { 7937 printf (" LAZYLOAD"); 7938 val ^= DF_P1_LAZYLOAD; 7939 } 7940 if (val & DF_P1_GROUPPERM) 7941 { 7942 printf (" GROUPPERM"); 7943 val ^= DF_P1_GROUPPERM; 7944 } 7945 if (val != 0) 7946 printf (" %lx", val); 7947 puts (""); 7948 } 7949 } 7950 break; 7951 7952 case DT_FLAGS_1: 7953 if (do_dynamic) 7954 { 7955 printf (_("Flags:")); 7956 if (entry->d_un.d_val == 0) 7957 printf (_(" None\n")); 7958 else 7959 { 7960 unsigned long int val = entry->d_un.d_val; 7961 7962 if (val & DF_1_NOW) 7963 { 7964 printf (" NOW"); 7965 val ^= DF_1_NOW; 7966 } 7967 if (val & DF_1_GLOBAL) 7968 { 7969 printf (" GLOBAL"); 7970 val ^= DF_1_GLOBAL; 7971 } 7972 if (val & DF_1_GROUP) 7973 { 7974 printf (" GROUP"); 7975 val ^= DF_1_GROUP; 7976 } 7977 if (val & DF_1_NODELETE) 7978 { 7979 printf (" NODELETE"); 7980 val ^= DF_1_NODELETE; 7981 } 7982 if (val & DF_1_LOADFLTR) 7983 { 7984 printf (" LOADFLTR"); 7985 val ^= DF_1_LOADFLTR; 7986 } 7987 if (val & DF_1_INITFIRST) 7988 { 7989 printf (" INITFIRST"); 7990 val ^= DF_1_INITFIRST; 7991 } 7992 if (val & DF_1_NOOPEN) 7993 { 7994 printf (" NOOPEN"); 7995 val ^= DF_1_NOOPEN; 7996 } 7997 if (val & DF_1_ORIGIN) 7998 { 7999 printf (" ORIGIN"); 8000 val ^= DF_1_ORIGIN; 8001 } 8002 if (val & DF_1_DIRECT) 8003 { 8004 printf (" DIRECT"); 8005 val ^= DF_1_DIRECT; 8006 } 8007 if (val & DF_1_TRANS) 8008 { 8009 printf (" TRANS"); 8010 val ^= DF_1_TRANS; 8011 } 8012 if (val & DF_1_INTERPOSE) 8013 { 8014 printf (" INTERPOSE"); 8015 val ^= DF_1_INTERPOSE; 8016 } 8017 if (val & DF_1_NODEFLIB) 8018 { 8019 printf (" NODEFLIB"); 8020 val ^= DF_1_NODEFLIB; 8021 } 8022 if (val & DF_1_NODUMP) 8023 { 8024 printf (" NODUMP"); 8025 val ^= DF_1_NODUMP; 8026 } 8027 if (val & DF_1_CONLFAT) 8028 { 8029 printf (" CONLFAT"); 8030 val ^= DF_1_CONLFAT; 8031 } 8032 if (val != 0) 8033 printf (" %lx", val); 8034 puts (""); 8035 } 8036 } 8037 break; 8038 8039 case DT_PLTREL: 8040 dynamic_info[entry->d_tag] = entry->d_un.d_val; 8041 if (do_dynamic) 8042 puts (get_dynamic_type (entry->d_un.d_val)); 8043 break; 8044 8045 case DT_NULL : 8046 case DT_NEEDED : 8047 case DT_PLTGOT : 8048 case DT_HASH : 8049 case DT_STRTAB : 8050 case DT_SYMTAB : 8051 case DT_RELA : 8052 case DT_INIT : 8053 case DT_FINI : 8054 case DT_SONAME : 8055 case DT_RPATH : 8056 case DT_SYMBOLIC: 8057 case DT_REL : 8058 case DT_DEBUG : 8059 case DT_TEXTREL : 8060 case DT_JMPREL : 8061 case DT_RUNPATH : 8062 dynamic_info[entry->d_tag] = entry->d_un.d_val; 8063 8064 if (do_dynamic) 8065 { 8066 char * name; 8067 8068 if (VALID_DYNAMIC_NAME (entry->d_un.d_val)) 8069 name = GET_DYNAMIC_NAME (entry->d_un.d_val); 8070 else 8071 name = NULL; 8072 8073 if (name) 8074 { 8075 switch (entry->d_tag) 8076 { 8077 case DT_NEEDED: 8078 printf (_("Shared library: [%s]"), name); 8079 8080 if (streq (name, program_interpreter)) 8081 printf (_(" program interpreter")); 8082 break; 8083 8084 case DT_SONAME: 8085 printf (_("Library soname: [%s]"), name); 8086 break; 8087 8088 case DT_RPATH: 8089 printf (_("Library rpath: [%s]"), name); 8090 break; 8091 8092 case DT_RUNPATH: 8093 printf (_("Library runpath: [%s]"), name); 8094 break; 8095 8096 default: 8097 print_vma (entry->d_un.d_val, PREFIX_HEX); 8098 break; 8099 } 8100 } 8101 else 8102 print_vma (entry->d_un.d_val, PREFIX_HEX); 8103 8104 putchar ('\n'); 8105 } 8106 break; 8107 8108 case DT_PLTRELSZ: 8109 case DT_RELASZ : 8110 case DT_STRSZ : 8111 case DT_RELSZ : 8112 case DT_RELAENT : 8113 case DT_SYMENT : 8114 case DT_RELENT : 8115 dynamic_info[entry->d_tag] = entry->d_un.d_val; 8116 case DT_PLTPADSZ: 8117 case DT_MOVEENT : 8118 case DT_MOVESZ : 8119 case DT_INIT_ARRAYSZ: 8120 case DT_FINI_ARRAYSZ: 8121 case DT_GNU_CONFLICTSZ: 8122 case DT_GNU_LIBLISTSZ: 8123 if (do_dynamic) 8124 { 8125 print_vma (entry->d_un.d_val, UNSIGNED); 8126 printf (_(" (bytes)\n")); 8127 } 8128 break; 8129 8130 case DT_VERDEFNUM: 8131 case DT_VERNEEDNUM: 8132 case DT_RELACOUNT: 8133 case DT_RELCOUNT: 8134 if (do_dynamic) 8135 { 8136 print_vma (entry->d_un.d_val, UNSIGNED); 8137 putchar ('\n'); 8138 } 8139 break; 8140 8141 case DT_SYMINSZ: 8142 case DT_SYMINENT: 8143 case DT_SYMINFO: 8144 case DT_USED: 8145 case DT_INIT_ARRAY: 8146 case DT_FINI_ARRAY: 8147 if (do_dynamic) 8148 { 8149 if (entry->d_tag == DT_USED 8150 && VALID_DYNAMIC_NAME (entry->d_un.d_val)) 8151 { 8152 char * name = GET_DYNAMIC_NAME (entry->d_un.d_val); 8153 8154 if (*name) 8155 { 8156 printf (_("Not needed object: [%s]\n"), name); 8157 break; 8158 } 8159 } 8160 8161 print_vma (entry->d_un.d_val, PREFIX_HEX); 8162 putchar ('\n'); 8163 } 8164 break; 8165 8166 case DT_BIND_NOW: 8167 /* The value of this entry is ignored. */ 8168 if (do_dynamic) 8169 putchar ('\n'); 8170 break; 8171 8172 case DT_GNU_PRELINKED: 8173 if (do_dynamic) 8174 { 8175 struct tm * tmp; 8176 time_t atime = entry->d_un.d_val; 8177 8178 tmp = gmtime (&atime); 8179 printf ("%04u-%02u-%02uT%02u:%02u:%02u\n", 8180 tmp->tm_year + 1900, tmp->tm_mon + 1, tmp->tm_mday, 8181 tmp->tm_hour, tmp->tm_min, tmp->tm_sec); 8182 8183 } 8184 break; 8185 8186 case DT_GNU_HASH: 8187 dynamic_info_DT_GNU_HASH = entry->d_un.d_val; 8188 if (do_dynamic) 8189 { 8190 print_vma (entry->d_un.d_val, PREFIX_HEX); 8191 putchar ('\n'); 8192 } 8193 break; 8194 8195 default: 8196 if ((entry->d_tag >= DT_VERSYM) && (entry->d_tag <= DT_VERNEEDNUM)) 8197 version_info[DT_VERSIONTAGIDX (entry->d_tag)] = 8198 entry->d_un.d_val; 8199 8200 if (do_dynamic) 8201 { 8202 switch (elf_header.e_machine) 8203 { 8204 case EM_MIPS: 8205 case EM_MIPS_RS3_LE: 8206 dynamic_section_mips_val (entry); 8207 break; 8208 case EM_PARISC: 8209 dynamic_section_parisc_val (entry); 8210 break; 8211 case EM_IA_64: 8212 dynamic_section_ia64_val (entry); 8213 break; 8214 default: 8215 print_vma (entry->d_un.d_val, PREFIX_HEX); 8216 putchar ('\n'); 8217 } 8218 } 8219 break; 8220 } 8221 } 8222 8223 return 1; 8224 } 8225 8226 static char * 8227 get_ver_flags (unsigned int flags) 8228 { 8229 static char buff[32]; 8230 8231 buff[0] = 0; 8232 8233 if (flags == 0) 8234 return _("none"); 8235 8236 if (flags & VER_FLG_BASE) 8237 strcat (buff, "BASE "); 8238 8239 if (flags & VER_FLG_WEAK) 8240 { 8241 if (flags & VER_FLG_BASE) 8242 strcat (buff, "| "); 8243 8244 strcat (buff, "WEAK "); 8245 } 8246 8247 if (flags & VER_FLG_INFO) 8248 { 8249 if (flags & (VER_FLG_BASE|VER_FLG_WEAK)) 8250 strcat (buff, "| "); 8251 8252 strcat (buff, "INFO "); 8253 } 8254 8255 if (flags & ~(VER_FLG_BASE | VER_FLG_WEAK | VER_FLG_INFO)) 8256 strcat (buff, _("| <unknown>")); 8257 8258 return buff; 8259 } 8260 8261 /* Display the contents of the version sections. */ 8262 8263 static int 8264 process_version_sections (FILE * file) 8265 { 8266 Elf_Internal_Shdr * section; 8267 unsigned i; 8268 int found = 0; 8269 8270 if (! do_version) 8271 return 1; 8272 8273 for (i = 0, section = section_headers; 8274 i < elf_header.e_shnum; 8275 i++, section++) 8276 { 8277 switch (section->sh_type) 8278 { 8279 case SHT_GNU_verdef: 8280 { 8281 Elf_External_Verdef * edefs; 8282 unsigned int idx; 8283 unsigned int cnt; 8284 char * endbuf; 8285 8286 found = 1; 8287 8288 printf 8289 (_("\nVersion definition section '%s' contains %u entries:\n"), 8290 SECTION_NAME (section), section->sh_info); 8291 8292 printf (_(" Addr: 0x")); 8293 printf_vma (section->sh_addr); 8294 printf (_(" Offset: %#08lx Link: %u (%s)\n"), 8295 (unsigned long) section->sh_offset, section->sh_link, 8296 section->sh_link < elf_header.e_shnum 8297 ? SECTION_NAME (section_headers + section->sh_link) 8298 : _("<corrupt>")); 8299 8300 edefs = (Elf_External_Verdef *) 8301 get_data (NULL, file, section->sh_offset, 1,section->sh_size, 8302 _("version definition section")); 8303 if (!edefs) 8304 break; 8305 endbuf = (char *) edefs + section->sh_size; 8306 8307 for (idx = cnt = 0; cnt < section->sh_info; ++cnt) 8308 { 8309 char * vstart; 8310 Elf_External_Verdef * edef; 8311 Elf_Internal_Verdef ent; 8312 Elf_External_Verdaux * eaux; 8313 Elf_Internal_Verdaux aux; 8314 int j; 8315 int isum; 8316 8317 /* Check for negative or very large indicies. */ 8318 if ((unsigned char *) edefs + idx < (unsigned char *) edefs) 8319 break; 8320 8321 vstart = ((char *) edefs) + idx; 8322 if (vstart + sizeof (*edef) > endbuf) 8323 break; 8324 8325 edef = (Elf_External_Verdef *) vstart; 8326 8327 ent.vd_version = BYTE_GET (edef->vd_version); 8328 ent.vd_flags = BYTE_GET (edef->vd_flags); 8329 ent.vd_ndx = BYTE_GET (edef->vd_ndx); 8330 ent.vd_cnt = BYTE_GET (edef->vd_cnt); 8331 ent.vd_hash = BYTE_GET (edef->vd_hash); 8332 ent.vd_aux = BYTE_GET (edef->vd_aux); 8333 ent.vd_next = BYTE_GET (edef->vd_next); 8334 8335 printf (_(" %#06x: Rev: %d Flags: %s"), 8336 idx, ent.vd_version, get_ver_flags (ent.vd_flags)); 8337 8338 printf (_(" Index: %d Cnt: %d "), 8339 ent.vd_ndx, ent.vd_cnt); 8340 8341 /* Check for overflow. */ 8342 if ((unsigned char *)(vstart + ent.vd_aux) < (unsigned char *) vstart 8343 || (unsigned char *)(vstart + ent.vd_aux) > (unsigned char *) endbuf) 8344 break; 8345 8346 vstart += ent.vd_aux; 8347 8348 eaux = (Elf_External_Verdaux *) vstart; 8349 8350 aux.vda_name = BYTE_GET (eaux->vda_name); 8351 aux.vda_next = BYTE_GET (eaux->vda_next); 8352 8353 if (VALID_DYNAMIC_NAME (aux.vda_name)) 8354 printf (_("Name: %s\n"), GET_DYNAMIC_NAME (aux.vda_name)); 8355 else 8356 printf (_("Name index: %ld\n"), aux.vda_name); 8357 8358 isum = idx + ent.vd_aux; 8359 8360 for (j = 1; j < ent.vd_cnt; j++) 8361 { 8362 /* Check for overflow. */ 8363 if ((unsigned char *)(vstart + aux.vda_next) < (unsigned char *) vstart 8364 || (unsigned char *)(vstart + aux.vda_next) > (unsigned char *) endbuf) 8365 break; 8366 8367 isum += aux.vda_next; 8368 vstart += aux.vda_next; 8369 8370 eaux = (Elf_External_Verdaux *) vstart; 8371 if (vstart + sizeof (*eaux) > endbuf) 8372 break; 8373 8374 aux.vda_name = BYTE_GET (eaux->vda_name); 8375 aux.vda_next = BYTE_GET (eaux->vda_next); 8376 8377 if (VALID_DYNAMIC_NAME (aux.vda_name)) 8378 printf (_(" %#06x: Parent %d: %s\n"), 8379 isum, j, GET_DYNAMIC_NAME (aux.vda_name)); 8380 else 8381 printf (_(" %#06x: Parent %d, name index: %ld\n"), 8382 isum, j, aux.vda_name); 8383 } 8384 8385 if (j < ent.vd_cnt) 8386 printf (_(" Version def aux past end of section\n")); 8387 8388 idx += ent.vd_next; 8389 } 8390 8391 if (cnt < section->sh_info) 8392 printf (_(" Version definition past end of section\n")); 8393 8394 free (edefs); 8395 } 8396 break; 8397 8398 case SHT_GNU_verneed: 8399 { 8400 Elf_External_Verneed * eneed; 8401 unsigned int idx; 8402 unsigned int cnt; 8403 char * endbuf; 8404 8405 found = 1; 8406 8407 printf (_("\nVersion needs section '%s' contains %u entries:\n"), 8408 SECTION_NAME (section), section->sh_info); 8409 8410 printf (_(" Addr: 0x")); 8411 printf_vma (section->sh_addr); 8412 printf (_(" Offset: %#08lx Link: %u (%s)\n"), 8413 (unsigned long) section->sh_offset, section->sh_link, 8414 section->sh_link < elf_header.e_shnum 8415 ? SECTION_NAME (section_headers + section->sh_link) 8416 : _("<corrupt>")); 8417 8418 eneed = (Elf_External_Verneed *) get_data (NULL, file, 8419 section->sh_offset, 1, 8420 section->sh_size, 8421 _("Version Needs section")); 8422 if (!eneed) 8423 break; 8424 endbuf = (char *) eneed + section->sh_size; 8425 8426 for (idx = cnt = 0; cnt < section->sh_info; ++cnt) 8427 { 8428 Elf_External_Verneed * entry; 8429 Elf_Internal_Verneed ent; 8430 int j; 8431 int isum; 8432 char * vstart; 8433 8434 if ((unsigned char *) eneed + idx < (unsigned char *) eneed) 8435 break; 8436 8437 vstart = ((char *) eneed) + idx; 8438 if (vstart + sizeof (*entry) > endbuf) 8439 break; 8440 8441 entry = (Elf_External_Verneed *) vstart; 8442 8443 ent.vn_version = BYTE_GET (entry->vn_version); 8444 ent.vn_cnt = BYTE_GET (entry->vn_cnt); 8445 ent.vn_file = BYTE_GET (entry->vn_file); 8446 ent.vn_aux = BYTE_GET (entry->vn_aux); 8447 ent.vn_next = BYTE_GET (entry->vn_next); 8448 8449 printf (_(" %#06x: Version: %d"), idx, ent.vn_version); 8450 8451 if (VALID_DYNAMIC_NAME (ent.vn_file)) 8452 printf (_(" File: %s"), GET_DYNAMIC_NAME (ent.vn_file)); 8453 else 8454 printf (_(" File: %lx"), ent.vn_file); 8455 8456 printf (_(" Cnt: %d\n"), ent.vn_cnt); 8457 8458 /* Check for overflow. */ 8459 if ((unsigned char *)(vstart + ent.vn_aux) < (unsigned char *) vstart 8460 || (unsigned char *)(vstart + ent.vn_aux) > (unsigned char *) endbuf) 8461 break; 8462 8463 vstart += ent.vn_aux; 8464 8465 for (j = 0, isum = idx + ent.vn_aux; j < ent.vn_cnt; ++j) 8466 { 8467 Elf_External_Vernaux * eaux; 8468 Elf_Internal_Vernaux aux; 8469 8470 if (vstart + sizeof (*eaux) > endbuf) 8471 break; 8472 eaux = (Elf_External_Vernaux *) vstart; 8473 8474 aux.vna_hash = BYTE_GET (eaux->vna_hash); 8475 aux.vna_flags = BYTE_GET (eaux->vna_flags); 8476 aux.vna_other = BYTE_GET (eaux->vna_other); 8477 aux.vna_name = BYTE_GET (eaux->vna_name); 8478 aux.vna_next = BYTE_GET (eaux->vna_next); 8479 8480 if (VALID_DYNAMIC_NAME (aux.vna_name)) 8481 printf (_(" %#06x: Name: %s"), 8482 isum, GET_DYNAMIC_NAME (aux.vna_name)); 8483 else 8484 printf (_(" %#06x: Name index: %lx"), 8485 isum, aux.vna_name); 8486 8487 printf (_(" Flags: %s Version: %d\n"), 8488 get_ver_flags (aux.vna_flags), aux.vna_other); 8489 8490 /* Check for overflow. */ 8491 if ((unsigned char *)(vstart + aux.vna_next) < (unsigned char *) vstart 8492 || (unsigned char *)(vstart + aux.vna_next) > (unsigned char *) endbuf) 8493 break; 8494 8495 isum += aux.vna_next; 8496 vstart += aux.vna_next; 8497 } 8498 8499 if (j < ent.vn_cnt) 8500 warn (_("Missing Version Needs auxillary information\n")); 8501 8502 idx += ent.vn_next; 8503 } 8504 8505 if (cnt < section->sh_info) 8506 warn (_("Missing Version Needs information\n")); 8507 8508 free (eneed); 8509 } 8510 break; 8511 8512 case SHT_GNU_versym: 8513 { 8514 Elf_Internal_Shdr * link_section; 8515 int total; 8516 int cnt; 8517 unsigned char * edata; 8518 unsigned short * data; 8519 char * strtab; 8520 Elf_Internal_Sym * symbols; 8521 Elf_Internal_Shdr * string_sec; 8522 unsigned long num_syms; 8523 long off; 8524 8525 if (section->sh_link >= elf_header.e_shnum) 8526 break; 8527 8528 link_section = section_headers + section->sh_link; 8529 total = section->sh_size / sizeof (Elf_External_Versym); 8530 8531 if (link_section->sh_link >= elf_header.e_shnum) 8532 break; 8533 8534 found = 1; 8535 8536 symbols = GET_ELF_SYMBOLS (file, link_section, & num_syms); 8537 if (symbols == NULL) 8538 break; 8539 8540 string_sec = section_headers + link_section->sh_link; 8541 8542 strtab = (char *) get_data (NULL, file, string_sec->sh_offset, 1, 8543 string_sec->sh_size, 8544 _("version string table")); 8545 if (!strtab) 8546 { 8547 free (symbols); 8548 break; 8549 } 8550 8551 printf (_("\nVersion symbols section '%s' contains %d entries:\n"), 8552 SECTION_NAME (section), total); 8553 8554 printf (_(" Addr: ")); 8555 printf_vma (section->sh_addr); 8556 printf (_(" Offset: %#08lx Link: %u (%s)\n"), 8557 (unsigned long) section->sh_offset, section->sh_link, 8558 SECTION_NAME (link_section)); 8559 8560 off = offset_from_vma (file, 8561 version_info[DT_VERSIONTAGIDX (DT_VERSYM)], 8562 total * sizeof (short)); 8563 edata = (unsigned char *) get_data (NULL, file, off, total, 8564 sizeof (short), 8565 _("version symbol data")); 8566 if (!edata) 8567 { 8568 free (strtab); 8569 free (symbols); 8570 break; 8571 } 8572 8573 data = (short unsigned int *) cmalloc (total, sizeof (short)); 8574 8575 for (cnt = total; cnt --;) 8576 data[cnt] = byte_get (edata + cnt * sizeof (short), 8577 sizeof (short)); 8578 8579 free (edata); 8580 8581 for (cnt = 0; cnt < total; cnt += 4) 8582 { 8583 int j, nn; 8584 int check_def, check_need; 8585 char * name; 8586 8587 printf (" %03x:", cnt); 8588 8589 for (j = 0; (j < 4) && (cnt + j) < total; ++j) 8590 switch (data[cnt + j]) 8591 { 8592 case 0: 8593 fputs (_(" 0 (*local*) "), stdout); 8594 break; 8595 8596 case 1: 8597 fputs (_(" 1 (*global*) "), stdout); 8598 break; 8599 8600 default: 8601 nn = printf ("%4x%c", data[cnt + j] & VERSYM_VERSION, 8602 data[cnt + j] & VERSYM_HIDDEN ? 'h' : ' '); 8603 8604 /* If this index value is greater than the size of the symbols 8605 array, break to avoid an out-of-bounds read. */ 8606 if ((unsigned long)(cnt + j) >= num_syms) 8607 { 8608 warn (_("invalid index into symbol array\n")); 8609 break; 8610 } 8611 8612 check_def = 1; 8613 check_need = 1; 8614 if (symbols[cnt + j].st_shndx >= elf_header.e_shnum 8615 || section_headers[symbols[cnt + j].st_shndx].sh_type 8616 != SHT_NOBITS) 8617 { 8618 if (symbols[cnt + j].st_shndx == SHN_UNDEF) 8619 check_def = 0; 8620 else 8621 check_need = 0; 8622 } 8623 8624 if (check_need 8625 && version_info[DT_VERSIONTAGIDX (DT_VERNEED)]) 8626 { 8627 Elf_Internal_Verneed ivn; 8628 unsigned long offset; 8629 8630 offset = offset_from_vma 8631 (file, version_info[DT_VERSIONTAGIDX (DT_VERNEED)], 8632 sizeof (Elf_External_Verneed)); 8633 8634 do 8635 { 8636 Elf_Internal_Vernaux ivna; 8637 Elf_External_Verneed evn; 8638 Elf_External_Vernaux evna; 8639 unsigned long a_off; 8640 8641 if (get_data (&evn, file, offset, sizeof (evn), 1, 8642 _("version need")) == NULL) 8643 break; 8644 8645 ivn.vn_aux = BYTE_GET (evn.vn_aux); 8646 ivn.vn_next = BYTE_GET (evn.vn_next); 8647 8648 a_off = offset + ivn.vn_aux; 8649 8650 do 8651 { 8652 if (get_data (&evna, file, a_off, sizeof (evna), 8653 1, _("version need aux (2)")) == NULL) 8654 { 8655 ivna.vna_next = 0; 8656 ivna.vna_other = 0; 8657 } 8658 else 8659 { 8660 ivna.vna_next = BYTE_GET (evna.vna_next); 8661 ivna.vna_other = BYTE_GET (evna.vna_other); 8662 } 8663 8664 a_off += ivna.vna_next; 8665 } 8666 while (ivna.vna_other != data[cnt + j] 8667 && ivna.vna_next != 0); 8668 8669 if (ivna.vna_other == data[cnt + j]) 8670 { 8671 ivna.vna_name = BYTE_GET (evna.vna_name); 8672 8673 if (ivna.vna_name >= string_sec->sh_size) 8674 name = _("*invalid*"); 8675 else 8676 name = strtab + ivna.vna_name; 8677 nn += printf ("(%s%-*s", 8678 name, 8679 12 - (int) strlen (name), 8680 ")"); 8681 check_def = 0; 8682 break; 8683 } 8684 8685 offset += ivn.vn_next; 8686 } 8687 while (ivn.vn_next); 8688 } 8689 8690 if (check_def && data[cnt + j] != 0x8001 8691 && version_info[DT_VERSIONTAGIDX (DT_VERDEF)]) 8692 { 8693 Elf_Internal_Verdef ivd; 8694 Elf_External_Verdef evd; 8695 unsigned long offset; 8696 8697 offset = offset_from_vma 8698 (file, version_info[DT_VERSIONTAGIDX (DT_VERDEF)], 8699 sizeof evd); 8700 8701 do 8702 { 8703 if (get_data (&evd, file, offset, sizeof (evd), 1, 8704 _("version def")) == NULL) 8705 { 8706 ivd.vd_next = 0; 8707 ivd.vd_ndx = 0; 8708 } 8709 else 8710 { 8711 ivd.vd_next = BYTE_GET (evd.vd_next); 8712 ivd.vd_ndx = BYTE_GET (evd.vd_ndx); 8713 } 8714 8715 offset += ivd.vd_next; 8716 } 8717 while (ivd.vd_ndx != (data[cnt + j] & VERSYM_VERSION) 8718 && ivd.vd_next != 0); 8719 8720 if (ivd.vd_ndx == (data[cnt + j] & VERSYM_VERSION)) 8721 { 8722 Elf_External_Verdaux evda; 8723 Elf_Internal_Verdaux ivda; 8724 8725 ivd.vd_aux = BYTE_GET (evd.vd_aux); 8726 8727 if (get_data (&evda, file, 8728 offset - ivd.vd_next + ivd.vd_aux, 8729 sizeof (evda), 1, 8730 _("version def aux")) == NULL) 8731 break; 8732 8733 ivda.vda_name = BYTE_GET (evda.vda_name); 8734 8735 if (ivda.vda_name >= string_sec->sh_size) 8736 name = _("*invalid*"); 8737 else 8738 name = strtab + ivda.vda_name; 8739 nn += printf ("(%s%-*s", 8740 name, 8741 12 - (int) strlen (name), 8742 ")"); 8743 } 8744 } 8745 8746 if (nn < 18) 8747 printf ("%*c", 18 - nn, ' '); 8748 } 8749 8750 putchar ('\n'); 8751 } 8752 8753 free (data); 8754 free (strtab); 8755 free (symbols); 8756 } 8757 break; 8758 8759 default: 8760 break; 8761 } 8762 } 8763 8764 if (! found) 8765 printf (_("\nNo version information found in this file.\n")); 8766 8767 return 1; 8768 } 8769 8770 static const char * 8771 get_symbol_binding (unsigned int binding) 8772 { 8773 static char buff[32]; 8774 8775 switch (binding) 8776 { 8777 case STB_LOCAL: return "LOCAL"; 8778 case STB_GLOBAL: return "GLOBAL"; 8779 case STB_WEAK: return "WEAK"; 8780 default: 8781 if (binding >= STB_LOPROC && binding <= STB_HIPROC) 8782 snprintf (buff, sizeof (buff), _("<processor specific>: %d"), 8783 binding); 8784 else if (binding >= STB_LOOS && binding <= STB_HIOS) 8785 { 8786 if (binding == STB_GNU_UNIQUE 8787 && (elf_header.e_ident[EI_OSABI] == ELFOSABI_GNU 8788 /* GNU is still using the default value 0. */ 8789 || elf_header.e_ident[EI_OSABI] == ELFOSABI_NONE)) 8790 return "UNIQUE"; 8791 snprintf (buff, sizeof (buff), _("<OS specific>: %d"), binding); 8792 } 8793 else 8794 snprintf (buff, sizeof (buff), _("<unknown>: %d"), binding); 8795 return buff; 8796 } 8797 } 8798 8799 static const char * 8800 get_symbol_type (unsigned int type) 8801 { 8802 static char buff[32]; 8803 8804 switch (type) 8805 { 8806 case STT_NOTYPE: return "NOTYPE"; 8807 case STT_OBJECT: return "OBJECT"; 8808 case STT_FUNC: return "FUNC"; 8809 case STT_SECTION: return "SECTION"; 8810 case STT_FILE: return "FILE"; 8811 case STT_COMMON: return "COMMON"; 8812 case STT_TLS: return "TLS"; 8813 case STT_RELC: return "RELC"; 8814 case STT_SRELC: return "SRELC"; 8815 default: 8816 if (type >= STT_LOPROC && type <= STT_HIPROC) 8817 { 8818 if (elf_header.e_machine == EM_ARM && type == STT_ARM_TFUNC) 8819 return "THUMB_FUNC"; 8820 8821 if (elf_header.e_machine == EM_SPARCV9 && type == STT_REGISTER) 8822 return "REGISTER"; 8823 8824 if (elf_header.e_machine == EM_PARISC && type == STT_PARISC_MILLI) 8825 return "PARISC_MILLI"; 8826 8827 snprintf (buff, sizeof (buff), _("<processor specific>: %d"), type); 8828 } 8829 else if (type >= STT_LOOS && type <= STT_HIOS) 8830 { 8831 if (elf_header.e_machine == EM_PARISC) 8832 { 8833 if (type == STT_HP_OPAQUE) 8834 return "HP_OPAQUE"; 8835 if (type == STT_HP_STUB) 8836 return "HP_STUB"; 8837 } 8838 8839 if (type == STT_GNU_IFUNC 8840 && (elf_header.e_ident[EI_OSABI] == ELFOSABI_GNU 8841 || elf_header.e_ident[EI_OSABI] == ELFOSABI_FREEBSD 8842 /* GNU is still using the default value 0. */ 8843 || elf_header.e_ident[EI_OSABI] == ELFOSABI_NONE)) 8844 return "IFUNC"; 8845 8846 snprintf (buff, sizeof (buff), _("<OS specific>: %d"), type); 8847 } 8848 else 8849 snprintf (buff, sizeof (buff), _("<unknown>: %d"), type); 8850 return buff; 8851 } 8852 } 8853 8854 static const char * 8855 get_symbol_visibility (unsigned int visibility) 8856 { 8857 switch (visibility) 8858 { 8859 case STV_DEFAULT: return "DEFAULT"; 8860 case STV_INTERNAL: return "INTERNAL"; 8861 case STV_HIDDEN: return "HIDDEN"; 8862 case STV_PROTECTED: return "PROTECTED"; 8863 default: abort (); 8864 } 8865 } 8866 8867 static const char * 8868 get_alpha_symbol_other (unsigned int other) 8869 { 8870 switch (other) 8871 { 8872 case STO_ALPHA_NOPV: 8873 return "NOPV"; 8874 case STO_ALPHA_STD_GPLOAD: 8875 return "STD GPLOAD"; 8876 default: 8877 return NULL; 8878 } 8879 } 8880 8881 static const char * 8882 get_mips_symbol_other (unsigned int other) 8883 { 8884 switch (other) 8885 { 8886 case STO_OPTIONAL: 8887 return "OPTIONAL"; 8888 case STO_MIPS_PLT: 8889 return "MIPS PLT"; 8890 case STO_MIPS_PIC: 8891 return "MIPS PIC"; 8892 case STO_MICROMIPS: 8893 return "MICROMIPS"; 8894 case STO_MICROMIPS | STO_MIPS_PIC: 8895 return "MICROMIPS, MIPS PIC"; 8896 case STO_MIPS16: 8897 return "MIPS16"; 8898 default: 8899 return NULL; 8900 } 8901 } 8902 8903 static const char * 8904 get_ia64_symbol_other (unsigned int other) 8905 { 8906 if (is_ia64_vms ()) 8907 { 8908 static char res[32]; 8909 8910 res[0] = 0; 8911 8912 /* Function types is for images and .STB files only. */ 8913 switch (elf_header.e_type) 8914 { 8915 case ET_DYN: 8916 case ET_EXEC: 8917 switch (VMS_ST_FUNC_TYPE (other)) 8918 { 8919 case VMS_SFT_CODE_ADDR: 8920 strcat (res, " CA"); 8921 break; 8922 case VMS_SFT_SYMV_IDX: 8923 strcat (res, " VEC"); 8924 break; 8925 case VMS_SFT_FD: 8926 strcat (res, " FD"); 8927 break; 8928 case VMS_SFT_RESERVE: 8929 strcat (res, " RSV"); 8930 break; 8931 default: 8932 abort (); 8933 } 8934 break; 8935 default: 8936 break; 8937 } 8938 switch (VMS_ST_LINKAGE (other)) 8939 { 8940 case VMS_STL_IGNORE: 8941 strcat (res, " IGN"); 8942 break; 8943 case VMS_STL_RESERVE: 8944 strcat (res, " RSV"); 8945 break; 8946 case VMS_STL_STD: 8947 strcat (res, " STD"); 8948 break; 8949 case VMS_STL_LNK: 8950 strcat (res, " LNK"); 8951 break; 8952 default: 8953 abort (); 8954 } 8955 8956 if (res[0] != 0) 8957 return res + 1; 8958 else 8959 return res; 8960 } 8961 return NULL; 8962 } 8963 8964 static const char * 8965 get_symbol_other (unsigned int other) 8966 { 8967 const char * result = NULL; 8968 static char buff [32]; 8969 8970 if (other == 0) 8971 return ""; 8972 8973 switch (elf_header.e_machine) 8974 { 8975 case EM_ALPHA: 8976 result = get_alpha_symbol_other (other); 8977 break; 8978 case EM_MIPS: 8979 result = get_mips_symbol_other (other); 8980 break; 8981 case EM_IA_64: 8982 result = get_ia64_symbol_other (other); 8983 break; 8984 default: 8985 break; 8986 } 8987 8988 if (result) 8989 return result; 8990 8991 snprintf (buff, sizeof buff, _("<other>: %x"), other); 8992 return buff; 8993 } 8994 8995 static const char * 8996 get_symbol_index_type (unsigned int type) 8997 { 8998 static char buff[32]; 8999 9000 switch (type) 9001 { 9002 case SHN_UNDEF: return "UND"; 9003 case SHN_ABS: return "ABS"; 9004 case SHN_COMMON: return "COM"; 9005 default: 9006 if (type == SHN_IA_64_ANSI_COMMON 9007 && elf_header.e_machine == EM_IA_64 9008 && elf_header.e_ident[EI_OSABI] == ELFOSABI_HPUX) 9009 return "ANSI_COM"; 9010 else if ((elf_header.e_machine == EM_X86_64 9011 || elf_header.e_machine == EM_L1OM 9012 || elf_header.e_machine == EM_K1OM) 9013 && type == SHN_X86_64_LCOMMON) 9014 return "LARGE_COM"; 9015 else if ((type == SHN_MIPS_SCOMMON 9016 && elf_header.e_machine == EM_MIPS) 9017 || (type == SHN_TIC6X_SCOMMON 9018 && elf_header.e_machine == EM_TI_C6000)) 9019 return "SCOM"; 9020 else if (type == SHN_MIPS_SUNDEFINED 9021 && elf_header.e_machine == EM_MIPS) 9022 return "SUND"; 9023 else if (type >= SHN_LOPROC && type <= SHN_HIPROC) 9024 sprintf (buff, "PRC[0x%04x]", type & 0xffff); 9025 else if (type >= SHN_LOOS && type <= SHN_HIOS) 9026 sprintf (buff, "OS [0x%04x]", type & 0xffff); 9027 else if (type >= SHN_LORESERVE) 9028 sprintf (buff, "RSV[0x%04x]", type & 0xffff); 9029 else if (type >= elf_header.e_shnum) 9030 sprintf (buff, "bad section index[%3d]", type); 9031 else 9032 sprintf (buff, "%3d", type); 9033 break; 9034 } 9035 9036 return buff; 9037 } 9038 9039 static bfd_vma * 9040 get_dynamic_data (FILE * file, unsigned int number, unsigned int ent_size) 9041 { 9042 unsigned char * e_data; 9043 bfd_vma * i_data; 9044 9045 e_data = (unsigned char *) cmalloc (number, ent_size); 9046 9047 if (e_data == NULL) 9048 { 9049 error (_("Out of memory\n")); 9050 return NULL; 9051 } 9052 9053 if (fread (e_data, ent_size, number, file) != number) 9054 { 9055 error (_("Unable to read in dynamic data\n")); 9056 return NULL; 9057 } 9058 9059 i_data = (bfd_vma *) cmalloc (number, sizeof (*i_data)); 9060 9061 if (i_data == NULL) 9062 { 9063 error (_("Out of memory\n")); 9064 free (e_data); 9065 return NULL; 9066 } 9067 9068 while (number--) 9069 i_data[number] = byte_get (e_data + number * ent_size, ent_size); 9070 9071 free (e_data); 9072 9073 return i_data; 9074 } 9075 9076 static void 9077 print_dynamic_symbol (bfd_vma si, unsigned long hn) 9078 { 9079 Elf_Internal_Sym * psym; 9080 int n; 9081 9082 psym = dynamic_symbols + si; 9083 9084 n = print_vma (si, DEC_5); 9085 if (n < 5) 9086 fputs (" " + n, stdout); 9087 printf (" %3lu: ", hn); 9088 print_vma (psym->st_value, LONG_HEX); 9089 putchar (' '); 9090 print_vma (psym->st_size, DEC_5); 9091 9092 printf (" %-7s", get_symbol_type (ELF_ST_TYPE (psym->st_info))); 9093 printf (" %-6s", get_symbol_binding (ELF_ST_BIND (psym->st_info))); 9094 printf (" %-7s", get_symbol_visibility (ELF_ST_VISIBILITY (psym->st_other))); 9095 /* Check to see if any other bits in the st_other field are set. 9096 Note - displaying this information disrupts the layout of the 9097 table being generated, but for the moment this case is very 9098 rare. */ 9099 if (psym->st_other ^ ELF_ST_VISIBILITY (psym->st_other)) 9100 printf (" [%s] ", get_symbol_other (psym->st_other ^ ELF_ST_VISIBILITY (psym->st_other))); 9101 printf (" %3.3s ", get_symbol_index_type (psym->st_shndx)); 9102 if (VALID_DYNAMIC_NAME (psym->st_name)) 9103 print_symbol (25, GET_DYNAMIC_NAME (psym->st_name)); 9104 else 9105 printf (_(" <corrupt: %14ld>"), psym->st_name); 9106 putchar ('\n'); 9107 } 9108 9109 /* Dump the symbol table. */ 9110 static int 9111 process_symbol_table (FILE * file) 9112 { 9113 Elf_Internal_Shdr * section; 9114 bfd_vma nbuckets = 0; 9115 bfd_vma nchains = 0; 9116 bfd_vma * buckets = NULL; 9117 bfd_vma * chains = NULL; 9118 bfd_vma ngnubuckets = 0; 9119 bfd_vma * gnubuckets = NULL; 9120 bfd_vma * gnuchains = NULL; 9121 bfd_vma gnusymidx = 0; 9122 9123 if (!do_syms && !do_dyn_syms && !do_histogram) 9124 return 1; 9125 9126 if (dynamic_info[DT_HASH] 9127 && (do_histogram 9128 || (do_using_dynamic 9129 && !do_dyn_syms 9130 && dynamic_strings != NULL))) 9131 { 9132 unsigned char nb[8]; 9133 unsigned char nc[8]; 9134 int hash_ent_size = 4; 9135 9136 if ((elf_header.e_machine == EM_ALPHA 9137 || elf_header.e_machine == EM_S390 9138 || elf_header.e_machine == EM_S390_OLD) 9139 && elf_header.e_ident[EI_CLASS] == ELFCLASS64) 9140 hash_ent_size = 8; 9141 9142 if (fseek (file, 9143 (archive_file_offset 9144 + offset_from_vma (file, dynamic_info[DT_HASH], 9145 sizeof nb + sizeof nc)), 9146 SEEK_SET)) 9147 { 9148 error (_("Unable to seek to start of dynamic information\n")); 9149 goto no_hash; 9150 } 9151 9152 if (fread (nb, hash_ent_size, 1, file) != 1) 9153 { 9154 error (_("Failed to read in number of buckets\n")); 9155 goto no_hash; 9156 } 9157 9158 if (fread (nc, hash_ent_size, 1, file) != 1) 9159 { 9160 error (_("Failed to read in number of chains\n")); 9161 goto no_hash; 9162 } 9163 9164 nbuckets = byte_get (nb, hash_ent_size); 9165 nchains = byte_get (nc, hash_ent_size); 9166 9167 buckets = get_dynamic_data (file, nbuckets, hash_ent_size); 9168 chains = get_dynamic_data (file, nchains, hash_ent_size); 9169 9170 no_hash: 9171 if (buckets == NULL || chains == NULL) 9172 { 9173 if (do_using_dynamic) 9174 return 0; 9175 free (buckets); 9176 free (chains); 9177 buckets = NULL; 9178 chains = NULL; 9179 nbuckets = 0; 9180 nchains = 0; 9181 } 9182 } 9183 9184 if (dynamic_info_DT_GNU_HASH 9185 && (do_histogram 9186 || (do_using_dynamic 9187 && !do_dyn_syms 9188 && dynamic_strings != NULL))) 9189 { 9190 unsigned char nb[16]; 9191 bfd_vma i, maxchain = 0xffffffff, bitmaskwords; 9192 bfd_vma buckets_vma; 9193 9194 if (fseek (file, 9195 (archive_file_offset 9196 + offset_from_vma (file, dynamic_info_DT_GNU_HASH, 9197 sizeof nb)), 9198 SEEK_SET)) 9199 { 9200 error (_("Unable to seek to start of dynamic information\n")); 9201 goto no_gnu_hash; 9202 } 9203 9204 if (fread (nb, 16, 1, file) != 1) 9205 { 9206 error (_("Failed to read in number of buckets\n")); 9207 goto no_gnu_hash; 9208 } 9209 9210 ngnubuckets = byte_get (nb, 4); 9211 gnusymidx = byte_get (nb + 4, 4); 9212 bitmaskwords = byte_get (nb + 8, 4); 9213 buckets_vma = dynamic_info_DT_GNU_HASH + 16; 9214 if (is_32bit_elf) 9215 buckets_vma += bitmaskwords * 4; 9216 else 9217 buckets_vma += bitmaskwords * 8; 9218 9219 if (fseek (file, 9220 (archive_file_offset 9221 + offset_from_vma (file, buckets_vma, 4)), 9222 SEEK_SET)) 9223 { 9224 error (_("Unable to seek to start of dynamic information\n")); 9225 goto no_gnu_hash; 9226 } 9227 9228 gnubuckets = get_dynamic_data (file, ngnubuckets, 4); 9229 9230 if (gnubuckets == NULL) 9231 goto no_gnu_hash; 9232 9233 for (i = 0; i < ngnubuckets; i++) 9234 if (gnubuckets[i] != 0) 9235 { 9236 if (gnubuckets[i] < gnusymidx) 9237 return 0; 9238 9239 if (maxchain == 0xffffffff || gnubuckets[i] > maxchain) 9240 maxchain = gnubuckets[i]; 9241 } 9242 9243 if (maxchain == 0xffffffff) 9244 goto no_gnu_hash; 9245 9246 maxchain -= gnusymidx; 9247 9248 if (fseek (file, 9249 (archive_file_offset 9250 + offset_from_vma (file, buckets_vma 9251 + 4 * (ngnubuckets + maxchain), 4)), 9252 SEEK_SET)) 9253 { 9254 error (_("Unable to seek to start of dynamic information\n")); 9255 goto no_gnu_hash; 9256 } 9257 9258 do 9259 { 9260 if (fread (nb, 4, 1, file) != 1) 9261 { 9262 error (_("Failed to determine last chain length\n")); 9263 goto no_gnu_hash; 9264 } 9265 9266 if (maxchain + 1 == 0) 9267 goto no_gnu_hash; 9268 9269 ++maxchain; 9270 } 9271 while ((byte_get (nb, 4) & 1) == 0); 9272 9273 if (fseek (file, 9274 (archive_file_offset 9275 + offset_from_vma (file, buckets_vma + 4 * ngnubuckets, 4)), 9276 SEEK_SET)) 9277 { 9278 error (_("Unable to seek to start of dynamic information\n")); 9279 goto no_gnu_hash; 9280 } 9281 9282 gnuchains = get_dynamic_data (file, maxchain, 4); 9283 9284 no_gnu_hash: 9285 if (gnuchains == NULL) 9286 { 9287 free (gnubuckets); 9288 gnubuckets = NULL; 9289 ngnubuckets = 0; 9290 if (do_using_dynamic) 9291 return 0; 9292 } 9293 } 9294 9295 if ((dynamic_info[DT_HASH] || dynamic_info_DT_GNU_HASH) 9296 && do_syms 9297 && do_using_dynamic 9298 && dynamic_strings != NULL) 9299 { 9300 unsigned long hn; 9301 9302 if (dynamic_info[DT_HASH]) 9303 { 9304 bfd_vma si; 9305 9306 printf (_("\nSymbol table for image:\n")); 9307 if (is_32bit_elf) 9308 printf (_(" Num Buc: Value Size Type Bind Vis Ndx Name\n")); 9309 else 9310 printf (_(" Num Buc: Value Size Type Bind Vis Ndx Name\n")); 9311 9312 for (hn = 0; hn < nbuckets; hn++) 9313 { 9314 if (! buckets[hn]) 9315 continue; 9316 9317 for (si = buckets[hn]; si < nchains && si > 0; si = chains[si]) 9318 print_dynamic_symbol (si, hn); 9319 } 9320 } 9321 9322 if (dynamic_info_DT_GNU_HASH) 9323 { 9324 printf (_("\nSymbol table of `.gnu.hash' for image:\n")); 9325 if (is_32bit_elf) 9326 printf (_(" Num Buc: Value Size Type Bind Vis Ndx Name\n")); 9327 else 9328 printf (_(" Num Buc: Value Size Type Bind Vis Ndx Name\n")); 9329 9330 for (hn = 0; hn < ngnubuckets; ++hn) 9331 if (gnubuckets[hn] != 0) 9332 { 9333 bfd_vma si = gnubuckets[hn]; 9334 bfd_vma off = si - gnusymidx; 9335 9336 do 9337 { 9338 print_dynamic_symbol (si, hn); 9339 si++; 9340 } 9341 while ((gnuchains[off++] & 1) == 0); 9342 } 9343 } 9344 } 9345 else if (do_dyn_syms || (do_syms && !do_using_dynamic)) 9346 { 9347 unsigned int i; 9348 9349 for (i = 0, section = section_headers; 9350 i < elf_header.e_shnum; 9351 i++, section++) 9352 { 9353 unsigned int si; 9354 char * strtab = NULL; 9355 unsigned long int strtab_size = 0; 9356 Elf_Internal_Sym * symtab; 9357 Elf_Internal_Sym * psym; 9358 unsigned long num_syms; 9359 9360 if ((section->sh_type != SHT_SYMTAB 9361 && section->sh_type != SHT_DYNSYM) 9362 || (!do_syms 9363 && section->sh_type == SHT_SYMTAB)) 9364 continue; 9365 9366 if (section->sh_entsize == 0) 9367 { 9368 printf (_("\nSymbol table '%s' has a sh_entsize of zero!\n"), 9369 SECTION_NAME (section)); 9370 continue; 9371 } 9372 9373 printf (_("\nSymbol table '%s' contains %lu entries:\n"), 9374 SECTION_NAME (section), 9375 (unsigned long) (section->sh_size / section->sh_entsize)); 9376 9377 if (is_32bit_elf) 9378 printf (_(" Num: Value Size Type Bind Vis Ndx Name\n")); 9379 else 9380 printf (_(" Num: Value Size Type Bind Vis Ndx Name\n")); 9381 9382 symtab = GET_ELF_SYMBOLS (file, section, & num_syms); 9383 if (symtab == NULL) 9384 continue; 9385 9386 if (section->sh_link == elf_header.e_shstrndx) 9387 { 9388 strtab = string_table; 9389 strtab_size = string_table_length; 9390 } 9391 else if (section->sh_link < elf_header.e_shnum) 9392 { 9393 Elf_Internal_Shdr * string_sec; 9394 9395 string_sec = section_headers + section->sh_link; 9396 9397 strtab = (char *) get_data (NULL, file, string_sec->sh_offset, 9398 1, string_sec->sh_size, 9399 _("string table")); 9400 strtab_size = strtab != NULL ? string_sec->sh_size : 0; 9401 } 9402 9403 for (si = 0, psym = symtab; si < num_syms; si++, psym++) 9404 { 9405 printf ("%6d: ", si); 9406 print_vma (psym->st_value, LONG_HEX); 9407 putchar (' '); 9408 print_vma (psym->st_size, DEC_5); 9409 printf (" %-7s", get_symbol_type (ELF_ST_TYPE (psym->st_info))); 9410 printf (" %-6s", get_symbol_binding (ELF_ST_BIND (psym->st_info))); 9411 printf (" %-7s", get_symbol_visibility (ELF_ST_VISIBILITY (psym->st_other))); 9412 /* Check to see if any other bits in the st_other field are set. 9413 Note - displaying this information disrupts the layout of the 9414 table being generated, but for the moment this case is very rare. */ 9415 if (psym->st_other ^ ELF_ST_VISIBILITY (psym->st_other)) 9416 printf (" [%s] ", get_symbol_other (psym->st_other ^ ELF_ST_VISIBILITY (psym->st_other))); 9417 printf (" %4s ", get_symbol_index_type (psym->st_shndx)); 9418 print_symbol (25, psym->st_name < strtab_size 9419 ? strtab + psym->st_name : _("<corrupt>")); 9420 9421 if (section->sh_type == SHT_DYNSYM 9422 && version_info[DT_VERSIONTAGIDX (DT_VERSYM)] != 0) 9423 { 9424 unsigned char data[2]; 9425 unsigned short vers_data; 9426 unsigned long offset; 9427 int is_nobits; 9428 int check_def; 9429 9430 offset = offset_from_vma 9431 (file, version_info[DT_VERSIONTAGIDX (DT_VERSYM)], 9432 sizeof data + si * sizeof (vers_data)); 9433 9434 if (get_data (&data, file, offset + si * sizeof (vers_data), 9435 sizeof (data), 1, _("version data")) == NULL) 9436 break; 9437 9438 vers_data = byte_get (data, 2); 9439 9440 is_nobits = (psym->st_shndx < elf_header.e_shnum 9441 && section_headers[psym->st_shndx].sh_type 9442 == SHT_NOBITS); 9443 9444 check_def = (psym->st_shndx != SHN_UNDEF); 9445 9446 if ((vers_data & VERSYM_HIDDEN) || vers_data > 1) 9447 { 9448 if (version_info[DT_VERSIONTAGIDX (DT_VERNEED)] 9449 && (is_nobits || ! check_def)) 9450 { 9451 Elf_External_Verneed evn; 9452 Elf_Internal_Verneed ivn; 9453 Elf_Internal_Vernaux ivna; 9454 9455 /* We must test both. */ 9456 offset = offset_from_vma 9457 (file, version_info[DT_VERSIONTAGIDX (DT_VERNEED)], 9458 sizeof evn); 9459 9460 do 9461 { 9462 unsigned long vna_off; 9463 9464 if (get_data (&evn, file, offset, sizeof (evn), 1, 9465 _("version need")) == NULL) 9466 { 9467 ivna.vna_next = 0; 9468 ivna.vna_other = 0; 9469 ivna.vna_name = 0; 9470 break; 9471 } 9472 9473 ivn.vn_aux = BYTE_GET (evn.vn_aux); 9474 ivn.vn_next = BYTE_GET (evn.vn_next); 9475 9476 vna_off = offset + ivn.vn_aux; 9477 9478 do 9479 { 9480 Elf_External_Vernaux evna; 9481 9482 if (get_data (&evna, file, vna_off, 9483 sizeof (evna), 1, 9484 _("version need aux (3)")) == NULL) 9485 { 9486 ivna.vna_next = 0; 9487 ivna.vna_other = 0; 9488 ivna.vna_name = 0; 9489 } 9490 else 9491 { 9492 ivna.vna_other = BYTE_GET (evna.vna_other); 9493 ivna.vna_next = BYTE_GET (evna.vna_next); 9494 ivna.vna_name = BYTE_GET (evna.vna_name); 9495 } 9496 9497 vna_off += ivna.vna_next; 9498 } 9499 while (ivna.vna_other != vers_data 9500 && ivna.vna_next != 0); 9501 9502 if (ivna.vna_other == vers_data) 9503 break; 9504 9505 offset += ivn.vn_next; 9506 } 9507 while (ivn.vn_next != 0); 9508 9509 if (ivna.vna_other == vers_data) 9510 { 9511 printf ("@%s (%d)", 9512 ivna.vna_name < strtab_size 9513 ? strtab + ivna.vna_name : _("<corrupt>"), 9514 ivna.vna_other); 9515 check_def = 0; 9516 } 9517 else if (! is_nobits) 9518 error (_("bad dynamic symbol\n")); 9519 else 9520 check_def = 1; 9521 } 9522 9523 if (check_def) 9524 { 9525 if (vers_data != 0x8001 9526 && version_info[DT_VERSIONTAGIDX (DT_VERDEF)]) 9527 { 9528 Elf_Internal_Verdef ivd; 9529 Elf_Internal_Verdaux ivda; 9530 Elf_External_Verdaux evda; 9531 unsigned long off; 9532 9533 off = offset_from_vma 9534 (file, 9535 version_info[DT_VERSIONTAGIDX (DT_VERDEF)], 9536 sizeof (Elf_External_Verdef)); 9537 9538 do 9539 { 9540 Elf_External_Verdef evd; 9541 9542 if (get_data (&evd, file, off, sizeof (evd), 9543 1, _("version def")) == NULL) 9544 { 9545 ivd.vd_ndx = 0; 9546 ivd.vd_aux = 0; 9547 ivd.vd_next = 0; 9548 } 9549 else 9550 { 9551 ivd.vd_ndx = BYTE_GET (evd.vd_ndx); 9552 ivd.vd_aux = BYTE_GET (evd.vd_aux); 9553 ivd.vd_next = BYTE_GET (evd.vd_next); 9554 } 9555 9556 off += ivd.vd_next; 9557 } 9558 while (ivd.vd_ndx != (vers_data & VERSYM_VERSION) 9559 && ivd.vd_next != 0); 9560 9561 off -= ivd.vd_next; 9562 off += ivd.vd_aux; 9563 9564 if (get_data (&evda, file, off, sizeof (evda), 9565 1, _("version def aux")) == NULL) 9566 break; 9567 9568 ivda.vda_name = BYTE_GET (evda.vda_name); 9569 9570 if (psym->st_name != ivda.vda_name) 9571 printf ((vers_data & VERSYM_HIDDEN) 9572 ? "@%s" : "@@%s", 9573 ivda.vda_name < strtab_size 9574 ? strtab + ivda.vda_name : _("<corrupt>")); 9575 } 9576 } 9577 } 9578 } 9579 9580 putchar ('\n'); 9581 } 9582 9583 free (symtab); 9584 if (strtab != string_table) 9585 free (strtab); 9586 } 9587 } 9588 else if (do_syms) 9589 printf 9590 (_("\nDynamic symbol information is not available for displaying symbols.\n")); 9591 9592 if (do_histogram && buckets != NULL) 9593 { 9594 unsigned long * lengths; 9595 unsigned long * counts; 9596 unsigned long hn; 9597 bfd_vma si; 9598 unsigned long maxlength = 0; 9599 unsigned long nzero_counts = 0; 9600 unsigned long nsyms = 0; 9601 9602 printf (_("\nHistogram for bucket list length (total of %lu buckets):\n"), 9603 (unsigned long) nbuckets); 9604 printf (_(" Length Number %% of total Coverage\n")); 9605 9606 lengths = (unsigned long *) calloc (nbuckets, sizeof (*lengths)); 9607 if (lengths == NULL) 9608 { 9609 error (_("Out of memory\n")); 9610 return 0; 9611 } 9612 for (hn = 0; hn < nbuckets; ++hn) 9613 { 9614 for (si = buckets[hn]; si > 0 && si < nchains; si = chains[si]) 9615 { 9616 ++nsyms; 9617 if (maxlength < ++lengths[hn]) 9618 ++maxlength; 9619 } 9620 } 9621 9622 counts = (unsigned long *) calloc (maxlength + 1, sizeof (*counts)); 9623 if (counts == NULL) 9624 { 9625 error (_("Out of memory\n")); 9626 return 0; 9627 } 9628 9629 for (hn = 0; hn < nbuckets; ++hn) 9630 ++counts[lengths[hn]]; 9631 9632 if (nbuckets > 0) 9633 { 9634 unsigned long i; 9635 printf (" 0 %-10lu (%5.1f%%)\n", 9636 counts[0], (counts[0] * 100.0) / nbuckets); 9637 for (i = 1; i <= maxlength; ++i) 9638 { 9639 nzero_counts += counts[i] * i; 9640 printf ("%7lu %-10lu (%5.1f%%) %5.1f%%\n", 9641 i, counts[i], (counts[i] * 100.0) / nbuckets, 9642 (nzero_counts * 100.0) / nsyms); 9643 } 9644 } 9645 9646 free (counts); 9647 free (lengths); 9648 } 9649 9650 if (buckets != NULL) 9651 { 9652 free (buckets); 9653 free (chains); 9654 } 9655 9656 if (do_histogram && gnubuckets != NULL) 9657 { 9658 unsigned long * lengths; 9659 unsigned long * counts; 9660 unsigned long hn; 9661 unsigned long maxlength = 0; 9662 unsigned long nzero_counts = 0; 9663 unsigned long nsyms = 0; 9664 9665 lengths = (unsigned long *) calloc (ngnubuckets, sizeof (*lengths)); 9666 if (lengths == NULL) 9667 { 9668 error (_("Out of memory\n")); 9669 return 0; 9670 } 9671 9672 printf (_("\nHistogram for `.gnu.hash' bucket list length (total of %lu buckets):\n"), 9673 (unsigned long) ngnubuckets); 9674 printf (_(" Length Number %% of total Coverage\n")); 9675 9676 for (hn = 0; hn < ngnubuckets; ++hn) 9677 if (gnubuckets[hn] != 0) 9678 { 9679 bfd_vma off, length = 1; 9680 9681 for (off = gnubuckets[hn] - gnusymidx; 9682 (gnuchains[off] & 1) == 0; ++off) 9683 ++length; 9684 lengths[hn] = length; 9685 if (length > maxlength) 9686 maxlength = length; 9687 nsyms += length; 9688 } 9689 9690 counts = (unsigned long *) calloc (maxlength + 1, sizeof (*counts)); 9691 if (counts == NULL) 9692 { 9693 error (_("Out of memory\n")); 9694 return 0; 9695 } 9696 9697 for (hn = 0; hn < ngnubuckets; ++hn) 9698 ++counts[lengths[hn]]; 9699 9700 if (ngnubuckets > 0) 9701 { 9702 unsigned long j; 9703 printf (" 0 %-10lu (%5.1f%%)\n", 9704 counts[0], (counts[0] * 100.0) / ngnubuckets); 9705 for (j = 1; j <= maxlength; ++j) 9706 { 9707 nzero_counts += counts[j] * j; 9708 printf ("%7lu %-10lu (%5.1f%%) %5.1f%%\n", 9709 j, counts[j], (counts[j] * 100.0) / ngnubuckets, 9710 (nzero_counts * 100.0) / nsyms); 9711 } 9712 } 9713 9714 free (counts); 9715 free (lengths); 9716 free (gnubuckets); 9717 free (gnuchains); 9718 } 9719 9720 return 1; 9721 } 9722 9723 static int 9724 process_syminfo (FILE * file ATTRIBUTE_UNUSED) 9725 { 9726 unsigned int i; 9727 9728 if (dynamic_syminfo == NULL 9729 || !do_dynamic) 9730 /* No syminfo, this is ok. */ 9731 return 1; 9732 9733 /* There better should be a dynamic symbol section. */ 9734 if (dynamic_symbols == NULL || dynamic_strings == NULL) 9735 return 0; 9736 9737 if (dynamic_addr) 9738 printf (_("\nDynamic info segment at offset 0x%lx contains %d entries:\n"), 9739 dynamic_syminfo_offset, dynamic_syminfo_nent); 9740 9741 printf (_(" Num: Name BoundTo Flags\n")); 9742 for (i = 0; i < dynamic_syminfo_nent; ++i) 9743 { 9744 unsigned short int flags = dynamic_syminfo[i].si_flags; 9745 9746 printf ("%4d: ", i); 9747 if (VALID_DYNAMIC_NAME (dynamic_symbols[i].st_name)) 9748 print_symbol (30, GET_DYNAMIC_NAME (dynamic_symbols[i].st_name)); 9749 else 9750 printf (_("<corrupt: %19ld>"), dynamic_symbols[i].st_name); 9751 putchar (' '); 9752 9753 switch (dynamic_syminfo[i].si_boundto) 9754 { 9755 case SYMINFO_BT_SELF: 9756 fputs ("SELF ", stdout); 9757 break; 9758 case SYMINFO_BT_PARENT: 9759 fputs ("PARENT ", stdout); 9760 break; 9761 default: 9762 if (dynamic_syminfo[i].si_boundto > 0 9763 && dynamic_syminfo[i].si_boundto < dynamic_nent 9764 && VALID_DYNAMIC_NAME (dynamic_section[dynamic_syminfo[i].si_boundto].d_un.d_val)) 9765 { 9766 print_symbol (10, GET_DYNAMIC_NAME (dynamic_section[dynamic_syminfo[i].si_boundto].d_un.d_val)); 9767 putchar (' ' ); 9768 } 9769 else 9770 printf ("%-10d ", dynamic_syminfo[i].si_boundto); 9771 break; 9772 } 9773 9774 if (flags & SYMINFO_FLG_DIRECT) 9775 printf (" DIRECT"); 9776 if (flags & SYMINFO_FLG_PASSTHRU) 9777 printf (" PASSTHRU"); 9778 if (flags & SYMINFO_FLG_COPY) 9779 printf (" COPY"); 9780 if (flags & SYMINFO_FLG_LAZYLOAD) 9781 printf (" LAZYLOAD"); 9782 9783 puts (""); 9784 } 9785 9786 return 1; 9787 } 9788 9789 /* Check to see if the given reloc needs to be handled in a target specific 9790 manner. If so then process the reloc and return TRUE otherwise return 9791 FALSE. */ 9792 9793 static bfd_boolean 9794 target_specific_reloc_handling (Elf_Internal_Rela * reloc, 9795 unsigned char * start, 9796 Elf_Internal_Sym * symtab) 9797 { 9798 unsigned int reloc_type = get_reloc_type (reloc->r_info); 9799 9800 switch (elf_header.e_machine) 9801 { 9802 case EM_MN10300: 9803 case EM_CYGNUS_MN10300: 9804 { 9805 static Elf_Internal_Sym * saved_sym = NULL; 9806 9807 switch (reloc_type) 9808 { 9809 case 34: /* R_MN10300_ALIGN */ 9810 return TRUE; 9811 case 33: /* R_MN10300_SYM_DIFF */ 9812 saved_sym = symtab + get_reloc_symindex (reloc->r_info); 9813 return TRUE; 9814 case 1: /* R_MN10300_32 */ 9815 case 2: /* R_MN10300_16 */ 9816 if (saved_sym != NULL) 9817 { 9818 bfd_vma value; 9819 9820 value = reloc->r_addend 9821 + (symtab[get_reloc_symindex (reloc->r_info)].st_value 9822 - saved_sym->st_value); 9823 9824 byte_put (start + reloc->r_offset, value, reloc_type == 1 ? 4 : 2); 9825 9826 saved_sym = NULL; 9827 return TRUE; 9828 } 9829 break; 9830 default: 9831 if (saved_sym != NULL) 9832 error (_("Unhandled MN10300 reloc type found after SYM_DIFF reloc")); 9833 break; 9834 } 9835 break; 9836 } 9837 } 9838 9839 return FALSE; 9840 } 9841 9842 /* Returns TRUE iff RELOC_TYPE is a 32-bit absolute RELA relocation used in 9843 DWARF debug sections. This is a target specific test. Note - we do not 9844 go through the whole including-target-headers-multiple-times route, (as 9845 we have already done with <elf/h8.h>) because this would become very 9846 messy and even then this function would have to contain target specific 9847 information (the names of the relocs instead of their numeric values). 9848 FIXME: This is not the correct way to solve this problem. The proper way 9849 is to have target specific reloc sizing and typing functions created by 9850 the reloc-macros.h header, in the same way that it already creates the 9851 reloc naming functions. */ 9852 9853 static bfd_boolean 9854 is_32bit_abs_reloc (unsigned int reloc_type) 9855 { 9856 switch (elf_header.e_machine) 9857 { 9858 case EM_386: 9859 case EM_486: 9860 return reloc_type == 1; /* R_386_32. */ 9861 case EM_68K: 9862 return reloc_type == 1; /* R_68K_32. */ 9863 case EM_860: 9864 return reloc_type == 1; /* R_860_32. */ 9865 case EM_960: 9866 return reloc_type == 2; /* R_960_32. */ 9867 case EM_AARCH64: 9868 return reloc_type == 258; /* R_AARCH64_ABS32 */ 9869 case EM_ALPHA: 9870 return reloc_type == 1; /* R_ALPHA_REFLONG. */ 9871 case EM_ARC: 9872 return reloc_type == 1; /* R_ARC_32. */ 9873 case EM_ARM: 9874 return reloc_type == 2; /* R_ARM_ABS32 */ 9875 case EM_AVR_OLD: 9876 case EM_AVR: 9877 return reloc_type == 1; 9878 case EM_ADAPTEVA_EPIPHANY: 9879 return reloc_type == 3; 9880 case EM_BLACKFIN: 9881 return reloc_type == 0x12; /* R_byte4_data. */ 9882 case EM_CRIS: 9883 return reloc_type == 3; /* R_CRIS_32. */ 9884 case EM_CR16: 9885 return reloc_type == 3; /* R_CR16_NUM32. */ 9886 case EM_CRX: 9887 return reloc_type == 15; /* R_CRX_NUM32. */ 9888 case EM_CYGNUS_FRV: 9889 return reloc_type == 1; 9890 case EM_CYGNUS_D10V: 9891 case EM_D10V: 9892 return reloc_type == 6; /* R_D10V_32. */ 9893 case EM_CYGNUS_D30V: 9894 case EM_D30V: 9895 return reloc_type == 12; /* R_D30V_32_NORMAL. */ 9896 case EM_DLX: 9897 return reloc_type == 3; /* R_DLX_RELOC_32. */ 9898 case EM_CYGNUS_FR30: 9899 case EM_FR30: 9900 return reloc_type == 3; /* R_FR30_32. */ 9901 case EM_H8S: 9902 case EM_H8_300: 9903 case EM_H8_300H: 9904 return reloc_type == 1; /* R_H8_DIR32. */ 9905 case EM_IA_64: 9906 return reloc_type == 0x65; /* R_IA64_SECREL32LSB. */ 9907 case EM_IP2K_OLD: 9908 case EM_IP2K: 9909 return reloc_type == 2; /* R_IP2K_32. */ 9910 case EM_IQ2000: 9911 return reloc_type == 2; /* R_IQ2000_32. */ 9912 case EM_LATTICEMICO32: 9913 return reloc_type == 3; /* R_LM32_32. */ 9914 case EM_M32C_OLD: 9915 case EM_M32C: 9916 return reloc_type == 3; /* R_M32C_32. */ 9917 case EM_M32R: 9918 return reloc_type == 34; /* R_M32R_32_RELA. */ 9919 case EM_MCORE: 9920 return reloc_type == 1; /* R_MCORE_ADDR32. */ 9921 case EM_CYGNUS_MEP: 9922 return reloc_type == 4; /* R_MEP_32. */ 9923 case EM_MICROBLAZE: 9924 return reloc_type == 1; /* R_MICROBLAZE_32. */ 9925 case EM_MIPS: 9926 return reloc_type == 2; /* R_MIPS_32. */ 9927 case EM_MMIX: 9928 return reloc_type == 4; /* R_MMIX_32. */ 9929 case EM_CYGNUS_MN10200: 9930 case EM_MN10200: 9931 return reloc_type == 1; /* R_MN10200_32. */ 9932 case EM_CYGNUS_MN10300: 9933 case EM_MN10300: 9934 return reloc_type == 1; /* R_MN10300_32. */ 9935 case EM_MOXIE: 9936 return reloc_type == 1; /* R_MOXIE_32. */ 9937 case EM_MSP430_OLD: 9938 case EM_MSP430: 9939 return reloc_type == 1; /* R_MSP43_32. */ 9940 case EM_MT: 9941 return reloc_type == 2; /* R_MT_32. */ 9942 case EM_ALTERA_NIOS2: 9943 case EM_NIOS32: 9944 return reloc_type == 1; /* R_NIOS_32. */ 9945 case EM_OR1K: 9946 return reloc_type == 1; /* R_OR1K_32. */ 9947 case EM_PARISC: 9948 return (reloc_type == 1 /* R_PARISC_DIR32. */ 9949 || reloc_type == 41); /* R_PARISC_SECREL32. */ 9950 case EM_PJ: 9951 case EM_PJ_OLD: 9952 return reloc_type == 1; /* R_PJ_DATA_DIR32. */ 9953 case EM_PPC64: 9954 return reloc_type == 1; /* R_PPC64_ADDR32. */ 9955 case EM_PPC: 9956 return reloc_type == 1; /* R_PPC_ADDR32. */ 9957 case EM_RISCV: 9958 return reloc_type == 1; /* R_RISCV_32. */ 9959 case EM_RL78: 9960 return reloc_type == 1; /* R_RL78_DIR32. */ 9961 case EM_RX: 9962 return reloc_type == 1; /* R_RX_DIR32. */ 9963 case EM_S370: 9964 return reloc_type == 1; /* R_I370_ADDR31. */ 9965 case EM_S390_OLD: 9966 case EM_S390: 9967 return reloc_type == 4; /* R_S390_32. */ 9968 case EM_SCORE: 9969 return reloc_type == 8; /* R_SCORE_ABS32. */ 9970 case EM_SH: 9971 return reloc_type == 1; /* R_SH_DIR32. */ 9972 case EM_SPARC32PLUS: 9973 case EM_SPARCV9: 9974 case EM_SPARC: 9975 return reloc_type == 3 /* R_SPARC_32. */ 9976 || reloc_type == 23; /* R_SPARC_UA32. */ 9977 case EM_SPU: 9978 return reloc_type == 6; /* R_SPU_ADDR32 */ 9979 case EM_TI_C6000: 9980 return reloc_type == 1; /* R_C6000_ABS32. */ 9981 case EM_TILEGX: 9982 return reloc_type == 2; /* R_TILEGX_32. */ 9983 case EM_TILEPRO: 9984 return reloc_type == 1; /* R_TILEPRO_32. */ 9985 case EM_CYGNUS_V850: 9986 case EM_V850: 9987 return reloc_type == 6; /* R_V850_ABS32. */ 9988 case EM_VAX: 9989 return reloc_type == 1; /* R_VAX_32. */ 9990 case EM_X86_64: 9991 case EM_L1OM: 9992 case EM_K1OM: 9993 return reloc_type == 10; /* R_X86_64_32. */ 9994 case EM_XC16X: 9995 case EM_C166: 9996 return reloc_type == 3; /* R_XC16C_ABS_32. */ 9997 case EM_XGATE: 9998 return reloc_type == 4; /* R_XGATE_32. */ 9999 case EM_XSTORMY16: 10000 return reloc_type == 1; /* R_XSTROMY16_32. */ 10001 case EM_XTENSA_OLD: 10002 case EM_XTENSA: 10003 return reloc_type == 1; /* R_XTENSA_32. */ 10004 default: 10005 error (_("Missing knowledge of 32-bit reloc types used in DWARF sections of machine number %d\n"), 10006 elf_header.e_machine); 10007 abort (); 10008 } 10009 } 10010 10011 /* Like is_32bit_abs_reloc except that it returns TRUE iff RELOC_TYPE is 10012 a 32-bit pc-relative RELA relocation used in DWARF debug sections. */ 10013 10014 static bfd_boolean 10015 is_32bit_pcrel_reloc (unsigned int reloc_type) 10016 { 10017 switch (elf_header.e_machine) 10018 { 10019 case EM_386: 10020 case EM_486: 10021 return reloc_type == 2; /* R_386_PC32. */ 10022 case EM_68K: 10023 return reloc_type == 4; /* R_68K_PC32. */ 10024 case EM_AARCH64: 10025 return reloc_type == 261; /* R_AARCH64_PREL32 */ 10026 case EM_ADAPTEVA_EPIPHANY: 10027 return reloc_type == 6; 10028 case EM_ALPHA: 10029 return reloc_type == 10; /* R_ALPHA_SREL32. */ 10030 case EM_ARM: 10031 return reloc_type == 3; /* R_ARM_REL32 */ 10032 case EM_MICROBLAZE: 10033 return reloc_type == 2; /* R_MICROBLAZE_32_PCREL. */ 10034 case EM_PARISC: 10035 return reloc_type == 9; /* R_PARISC_PCREL32. */ 10036 case EM_PPC: 10037 return reloc_type == 26; /* R_PPC_REL32. */ 10038 case EM_PPC64: 10039 return reloc_type == 26; /* R_PPC64_REL32. */ 10040 case EM_S390_OLD: 10041 case EM_S390: 10042 return reloc_type == 5; /* R_390_PC32. */ 10043 case EM_SH: 10044 return reloc_type == 2; /* R_SH_REL32. */ 10045 case EM_SPARC32PLUS: 10046 case EM_SPARCV9: 10047 case EM_SPARC: 10048 return reloc_type == 6; /* R_SPARC_DISP32. */ 10049 case EM_SPU: 10050 return reloc_type == 13; /* R_SPU_REL32. */ 10051 case EM_TILEGX: 10052 return reloc_type == 6; /* R_TILEGX_32_PCREL. */ 10053 case EM_TILEPRO: 10054 return reloc_type == 4; /* R_TILEPRO_32_PCREL. */ 10055 case EM_X86_64: 10056 case EM_L1OM: 10057 case EM_K1OM: 10058 return reloc_type == 2; /* R_X86_64_PC32. */ 10059 case EM_VAX: 10060 return reloc_type == 4; /* R_VAX_PCREL32. */ 10061 case EM_XTENSA_OLD: 10062 case EM_XTENSA: 10063 return reloc_type == 14; /* R_XTENSA_32_PCREL. */ 10064 default: 10065 /* Do not abort or issue an error message here. Not all targets use 10066 pc-relative 32-bit relocs in their DWARF debug information and we 10067 have already tested for target coverage in is_32bit_abs_reloc. A 10068 more helpful warning message will be generated by apply_relocations 10069 anyway, so just return. */ 10070 return FALSE; 10071 } 10072 } 10073 10074 /* Like is_32bit_abs_reloc except that it returns TRUE iff RELOC_TYPE is 10075 a 64-bit absolute RELA relocation used in DWARF debug sections. */ 10076 10077 static bfd_boolean 10078 is_64bit_abs_reloc (unsigned int reloc_type) 10079 { 10080 switch (elf_header.e_machine) 10081 { 10082 case EM_AARCH64: 10083 return reloc_type == 257; /* R_AARCH64_ABS64. */ 10084 case EM_ALPHA: 10085 return reloc_type == 2; /* R_ALPHA_REFQUAD. */ 10086 case EM_IA_64: 10087 return reloc_type == 0x27; /* R_IA64_DIR64LSB. */ 10088 case EM_PARISC: 10089 return reloc_type == 80; /* R_PARISC_DIR64. */ 10090 case EM_PPC64: 10091 return reloc_type == 38; /* R_PPC64_ADDR64. */ 10092 case EM_RISCV: 10093 return reloc_type == 2; /* R_RISCV_64. */ 10094 case EM_SPARC32PLUS: 10095 case EM_SPARCV9: 10096 case EM_SPARC: 10097 return reloc_type == 54; /* R_SPARC_UA64. */ 10098 case EM_X86_64: 10099 case EM_L1OM: 10100 case EM_K1OM: 10101 return reloc_type == 1; /* R_X86_64_64. */ 10102 case EM_S390_OLD: 10103 case EM_S390: 10104 return reloc_type == 22; /* R_S390_64. */ 10105 case EM_TILEGX: 10106 return reloc_type == 1; /* R_TILEGX_64. */ 10107 case EM_MIPS: 10108 return reloc_type == 18; /* R_MIPS_64. */ 10109 default: 10110 return FALSE; 10111 } 10112 } 10113 10114 /* Like is_32bit_pcrel_reloc except that it returns TRUE iff RELOC_TYPE is 10115 a 64-bit pc-relative RELA relocation used in DWARF debug sections. */ 10116 10117 static bfd_boolean 10118 is_64bit_pcrel_reloc (unsigned int reloc_type) 10119 { 10120 switch (elf_header.e_machine) 10121 { 10122 case EM_AARCH64: 10123 return reloc_type == 260; /* R_AARCH64_PREL64. */ 10124 case EM_ALPHA: 10125 return reloc_type == 11; /* R_ALPHA_SREL64. */ 10126 case EM_IA_64: 10127 return reloc_type == 0x4f; /* R_IA64_PCREL64LSB. */ 10128 case EM_PARISC: 10129 return reloc_type == 72; /* R_PARISC_PCREL64. */ 10130 case EM_PPC64: 10131 return reloc_type == 44; /* R_PPC64_REL64. */ 10132 case EM_SPARC32PLUS: 10133 case EM_SPARCV9: 10134 case EM_SPARC: 10135 return reloc_type == 46; /* R_SPARC_DISP64. */ 10136 case EM_X86_64: 10137 case EM_L1OM: 10138 case EM_K1OM: 10139 return reloc_type == 24; /* R_X86_64_PC64. */ 10140 case EM_S390_OLD: 10141 case EM_S390: 10142 return reloc_type == 23; /* R_S390_PC64. */ 10143 case EM_TILEGX: 10144 return reloc_type == 5; /* R_TILEGX_64_PCREL. */ 10145 default: 10146 return FALSE; 10147 } 10148 } 10149 10150 /* Like is_32bit_abs_reloc except that it returns TRUE iff RELOC_TYPE is 10151 a 24-bit absolute RELA relocation used in DWARF debug sections. */ 10152 10153 static bfd_boolean 10154 is_24bit_abs_reloc (unsigned int reloc_type) 10155 { 10156 switch (elf_header.e_machine) 10157 { 10158 case EM_CYGNUS_MN10200: 10159 case EM_MN10200: 10160 return reloc_type == 4; /* R_MN10200_24. */ 10161 default: 10162 return FALSE; 10163 } 10164 } 10165 10166 /* Like is_32bit_abs_reloc except that it returns TRUE iff RELOC_TYPE is 10167 a 16-bit absolute RELA relocation used in DWARF debug sections. */ 10168 10169 static bfd_boolean 10170 is_16bit_abs_reloc (unsigned int reloc_type) 10171 { 10172 switch (elf_header.e_machine) 10173 { 10174 case EM_AVR_OLD: 10175 case EM_AVR: 10176 return reloc_type == 4; /* R_AVR_16. */ 10177 case EM_ADAPTEVA_EPIPHANY: 10178 return reloc_type == 5; 10179 case EM_CYGNUS_D10V: 10180 case EM_D10V: 10181 return reloc_type == 3; /* R_D10V_16. */ 10182 case EM_H8S: 10183 case EM_H8_300: 10184 case EM_H8_300H: 10185 return reloc_type == R_H8_DIR16; 10186 case EM_IP2K_OLD: 10187 case EM_IP2K: 10188 return reloc_type == 1; /* R_IP2K_16. */ 10189 case EM_M32C_OLD: 10190 case EM_M32C: 10191 return reloc_type == 1; /* R_M32C_16 */ 10192 case EM_MSP430_OLD: 10193 case EM_MSP430: 10194 return reloc_type == 5; /* R_MSP430_16_BYTE. */ 10195 case EM_ALTERA_NIOS2: 10196 case EM_NIOS32: 10197 return reloc_type == 9; /* R_NIOS_16. */ 10198 case EM_TI_C6000: 10199 return reloc_type == 2; /* R_C6000_ABS16. */ 10200 case EM_XC16X: 10201 case EM_C166: 10202 return reloc_type == 2; /* R_XC16C_ABS_16. */ 10203 case EM_CYGNUS_MN10200: 10204 case EM_MN10200: 10205 return reloc_type == 2; /* R_MN10200_16. */ 10206 case EM_CYGNUS_MN10300: 10207 case EM_MN10300: 10208 return reloc_type == 2; /* R_MN10300_16. */ 10209 case EM_XGATE: 10210 return reloc_type == 3; /* R_XGATE_16. */ 10211 default: 10212 return FALSE; 10213 } 10214 } 10215 10216 /* Returns TRUE iff RELOC_TYPE is a NONE relocation used for discarded 10217 relocation entries (possibly formerly used for SHT_GROUP sections). */ 10218 10219 static bfd_boolean 10220 is_none_reloc (unsigned int reloc_type) 10221 { 10222 switch (elf_header.e_machine) 10223 { 10224 case EM_68K: /* R_68K_NONE. */ 10225 case EM_386: /* R_386_NONE. */ 10226 case EM_SPARC32PLUS: 10227 case EM_SPARCV9: 10228 case EM_SPARC: /* R_SPARC_NONE. */ 10229 case EM_MIPS: /* R_MIPS_NONE. */ 10230 case EM_PARISC: /* R_PARISC_NONE. */ 10231 case EM_ALPHA: /* R_ALPHA_NONE. */ 10232 case EM_ADAPTEVA_EPIPHANY: 10233 case EM_PPC: /* R_PPC_NONE. */ 10234 case EM_PPC64: /* R_PPC64_NONE. */ 10235 case EM_RISCV: /* R_RISCV_NONE. */ 10236 case EM_ARM: /* R_ARM_NONE. */ 10237 case EM_IA_64: /* R_IA64_NONE. */ 10238 case EM_SH: /* R_SH_NONE. */ 10239 case EM_S390_OLD: 10240 case EM_S390: /* R_390_NONE. */ 10241 case EM_CRIS: /* R_CRIS_NONE. */ 10242 case EM_X86_64: /* R_X86_64_NONE. */ 10243 case EM_L1OM: /* R_X86_64_NONE. */ 10244 case EM_K1OM: /* R_X86_64_NONE. */ 10245 case EM_MN10300: /* R_MN10300_NONE. */ 10246 case EM_MOXIE: /* R_MOXIE_NONE. */ 10247 case EM_M32R: /* R_M32R_NONE. */ 10248 case EM_TI_C6000:/* R_C6000_NONE. */ 10249 case EM_TILEGX: /* R_TILEGX_NONE. */ 10250 case EM_TILEPRO: /* R_TILEPRO_NONE. */ 10251 case EM_XC16X: 10252 case EM_C166: /* R_XC16X_NONE. */ 10253 return reloc_type == 0; 10254 case EM_AARCH64: 10255 return reloc_type == 0 || reloc_type == 256; 10256 case EM_XTENSA_OLD: 10257 case EM_XTENSA: 10258 return (reloc_type == 0 /* R_XTENSA_NONE. */ 10259 || reloc_type == 17 /* R_XTENSA_DIFF8. */ 10260 || reloc_type == 18 /* R_XTENSA_DIFF16. */ 10261 || reloc_type == 19 /* R_XTENSA_DIFF32. */); 10262 } 10263 return FALSE; 10264 } 10265 10266 /* Apply relocations to a section. 10267 Note: So far support has been added only for those relocations 10268 which can be found in debug sections. 10269 FIXME: Add support for more relocations ? */ 10270 10271 static void 10272 apply_relocations (void * file, 10273 Elf_Internal_Shdr * section, 10274 unsigned char * start) 10275 { 10276 Elf_Internal_Shdr * relsec; 10277 unsigned char * end = start + section->sh_size; 10278 10279 if (elf_header.e_type != ET_REL) 10280 return; 10281 10282 /* Find the reloc section associated with the section. */ 10283 for (relsec = section_headers; 10284 relsec < section_headers + elf_header.e_shnum; 10285 ++relsec) 10286 { 10287 bfd_boolean is_rela; 10288 unsigned long num_relocs; 10289 Elf_Internal_Rela * relocs; 10290 Elf_Internal_Rela * rp; 10291 Elf_Internal_Shdr * symsec; 10292 Elf_Internal_Sym * symtab; 10293 unsigned long num_syms; 10294 Elf_Internal_Sym * sym; 10295 10296 if ((relsec->sh_type != SHT_RELA && relsec->sh_type != SHT_REL) 10297 || relsec->sh_info >= elf_header.e_shnum 10298 || section_headers + relsec->sh_info != section 10299 || relsec->sh_size == 0 10300 || relsec->sh_link >= elf_header.e_shnum) 10301 continue; 10302 10303 is_rela = relsec->sh_type == SHT_RELA; 10304 10305 if (is_rela) 10306 { 10307 if (!slurp_rela_relocs ((FILE *) file, relsec->sh_offset, 10308 relsec->sh_size, & relocs, & num_relocs)) 10309 return; 10310 } 10311 else 10312 { 10313 if (!slurp_rel_relocs ((FILE *) file, relsec->sh_offset, 10314 relsec->sh_size, & relocs, & num_relocs)) 10315 return; 10316 } 10317 10318 /* SH uses RELA but uses in place value instead of the addend field. */ 10319 if (elf_header.e_machine == EM_SH) 10320 is_rela = FALSE; 10321 10322 symsec = section_headers + relsec->sh_link; 10323 symtab = GET_ELF_SYMBOLS ((FILE *) file, symsec, & num_syms); 10324 10325 for (rp = relocs; rp < relocs + num_relocs; ++rp) 10326 { 10327 bfd_vma addend; 10328 unsigned int reloc_type; 10329 unsigned int reloc_size; 10330 unsigned char * rloc; 10331 unsigned long sym_index; 10332 10333 reloc_type = get_reloc_type (rp->r_info); 10334 10335 if (target_specific_reloc_handling (rp, start, symtab)) 10336 continue; 10337 else if (is_none_reloc (reloc_type)) 10338 continue; 10339 else if (is_32bit_abs_reloc (reloc_type) 10340 || is_32bit_pcrel_reloc (reloc_type)) 10341 reloc_size = 4; 10342 else if (is_64bit_abs_reloc (reloc_type) 10343 || is_64bit_pcrel_reloc (reloc_type)) 10344 reloc_size = 8; 10345 else if (is_24bit_abs_reloc (reloc_type)) 10346 reloc_size = 3; 10347 else if (is_16bit_abs_reloc (reloc_type)) 10348 reloc_size = 2; 10349 else 10350 { 10351 warn (_("unable to apply unsupported reloc type %d to section %s\n"), 10352 reloc_type, SECTION_NAME (section)); 10353 continue; 10354 } 10355 10356 rloc = start + rp->r_offset; 10357 if ((rloc + reloc_size) > end) 10358 { 10359 warn (_("skipping invalid relocation offset 0x%lx in section %s\n"), 10360 (unsigned long) rp->r_offset, 10361 SECTION_NAME (section)); 10362 continue; 10363 } 10364 10365 sym_index = (unsigned long) get_reloc_symindex (rp->r_info); 10366 if (sym_index >= num_syms) 10367 { 10368 warn (_("skipping invalid relocation symbol index 0x%lx in section %s\n"), 10369 sym_index, SECTION_NAME (section)); 10370 continue; 10371 } 10372 sym = symtab + sym_index; 10373 10374 /* If the reloc has a symbol associated with it, 10375 make sure that it is of an appropriate type. 10376 10377 Relocations against symbols without type can happen. 10378 Gcc -feliminate-dwarf2-dups may generate symbols 10379 without type for debug info. 10380 10381 Icc generates relocations against function symbols 10382 instead of local labels. 10383 10384 Relocations against object symbols can happen, eg when 10385 referencing a global array. For an example of this see 10386 the _clz.o binary in libgcc.a. */ 10387 if (sym != symtab 10388 && ELF_ST_TYPE (sym->st_info) > STT_SECTION) 10389 { 10390 warn (_("skipping unexpected symbol type %s in %ld'th relocation in section %s\n"), 10391 get_symbol_type (ELF_ST_TYPE (sym->st_info)), 10392 (long int)(rp - relocs), 10393 SECTION_NAME (relsec)); 10394 continue; 10395 } 10396 10397 addend = 0; 10398 if (is_rela) 10399 addend += rp->r_addend; 10400 /* R_XTENSA_32, R_PJ_DATA_DIR32 and R_D30V_32_NORMAL are 10401 partial_inplace. */ 10402 if (!is_rela 10403 || (elf_header.e_machine == EM_XTENSA 10404 && reloc_type == 1) 10405 || ((elf_header.e_machine == EM_PJ 10406 || elf_header.e_machine == EM_PJ_OLD) 10407 && reloc_type == 1) 10408 || ((elf_header.e_machine == EM_D30V 10409 || elf_header.e_machine == EM_CYGNUS_D30V) 10410 && reloc_type == 12)) 10411 addend += byte_get (rloc, reloc_size); 10412 10413 if (is_32bit_pcrel_reloc (reloc_type) 10414 || is_64bit_pcrel_reloc (reloc_type)) 10415 { 10416 /* On HPPA, all pc-relative relocations are biased by 8. */ 10417 if (elf_header.e_machine == EM_PARISC) 10418 addend -= 8; 10419 byte_put (rloc, (addend + sym->st_value) - rp->r_offset, 10420 reloc_size); 10421 } 10422 else 10423 byte_put (rloc, addend + sym->st_value, reloc_size); 10424 } 10425 10426 free (symtab); 10427 free (relocs); 10428 break; 10429 } 10430 } 10431 10432 #ifdef SUPPORT_DISASSEMBLY 10433 static int 10434 disassemble_section (Elf_Internal_Shdr * section, FILE * file) 10435 { 10436 printf (_("\nAssembly dump of section %s\n"), 10437 SECTION_NAME (section)); 10438 10439 /* XXX -- to be done --- XXX */ 10440 10441 return 1; 10442 } 10443 #endif 10444 10445 /* Reads in the contents of SECTION from FILE, returning a pointer 10446 to a malloc'ed buffer or NULL if something went wrong. */ 10447 10448 static char * 10449 get_section_contents (Elf_Internal_Shdr * section, FILE * file) 10450 { 10451 bfd_size_type num_bytes; 10452 10453 num_bytes = section->sh_size; 10454 10455 if (num_bytes == 0 || section->sh_type == SHT_NOBITS) 10456 { 10457 printf (_("\nSection '%s' has no data to dump.\n"), 10458 SECTION_NAME (section)); 10459 return NULL; 10460 } 10461 10462 return (char *) get_data (NULL, file, section->sh_offset, 1, num_bytes, 10463 _("section contents")); 10464 } 10465 10466 10467 static void 10468 dump_section_as_strings (Elf_Internal_Shdr * section, FILE * file) 10469 { 10470 Elf_Internal_Shdr * relsec; 10471 bfd_size_type num_bytes; 10472 char * data; 10473 char * end; 10474 char * start; 10475 char * name = SECTION_NAME (section); 10476 bfd_boolean some_strings_shown; 10477 10478 start = get_section_contents (section, file); 10479 if (start == NULL) 10480 return; 10481 10482 printf (_("\nString dump of section '%s':\n"), name); 10483 10484 /* If the section being dumped has relocations against it the user might 10485 be expecting these relocations to have been applied. Check for this 10486 case and issue a warning message in order to avoid confusion. 10487 FIXME: Maybe we ought to have an option that dumps a section with 10488 relocs applied ? */ 10489 for (relsec = section_headers; 10490 relsec < section_headers + elf_header.e_shnum; 10491 ++relsec) 10492 { 10493 if ((relsec->sh_type != SHT_RELA && relsec->sh_type != SHT_REL) 10494 || relsec->sh_info >= elf_header.e_shnum 10495 || section_headers + relsec->sh_info != section 10496 || relsec->sh_size == 0 10497 || relsec->sh_link >= elf_header.e_shnum) 10498 continue; 10499 10500 printf (_(" Note: This section has relocations against it, but these have NOT been applied to this dump.\n")); 10501 break; 10502 } 10503 10504 num_bytes = section->sh_size; 10505 data = start; 10506 end = start + num_bytes; 10507 some_strings_shown = FALSE; 10508 10509 while (data < end) 10510 { 10511 while (!ISPRINT (* data)) 10512 if (++ data >= end) 10513 break; 10514 10515 if (data < end) 10516 { 10517 #ifndef __MSVCRT__ 10518 /* PR 11128: Use two separate invocations in order to work 10519 around bugs in the Solaris 8 implementation of printf. */ 10520 printf (" [%6tx] ", data - start); 10521 printf ("%s\n", data); 10522 #else 10523 printf (" [%6Ix] %s\n", (size_t) (data - start), data); 10524 #endif 10525 data += strlen (data); 10526 some_strings_shown = TRUE; 10527 } 10528 } 10529 10530 if (! some_strings_shown) 10531 printf (_(" No strings found in this section.")); 10532 10533 free (start); 10534 10535 putchar ('\n'); 10536 } 10537 10538 static void 10539 dump_section_as_bytes (Elf_Internal_Shdr * section, 10540 FILE * file, 10541 bfd_boolean relocate) 10542 { 10543 Elf_Internal_Shdr * relsec; 10544 bfd_size_type bytes; 10545 bfd_vma addr; 10546 unsigned char * data; 10547 unsigned char * start; 10548 10549 start = (unsigned char *) get_section_contents (section, file); 10550 if (start == NULL) 10551 return; 10552 10553 printf (_("\nHex dump of section '%s':\n"), SECTION_NAME (section)); 10554 10555 if (relocate) 10556 { 10557 apply_relocations (file, section, start); 10558 } 10559 else 10560 { 10561 /* If the section being dumped has relocations against it the user might 10562 be expecting these relocations to have been applied. Check for this 10563 case and issue a warning message in order to avoid confusion. 10564 FIXME: Maybe we ought to have an option that dumps a section with 10565 relocs applied ? */ 10566 for (relsec = section_headers; 10567 relsec < section_headers + elf_header.e_shnum; 10568 ++relsec) 10569 { 10570 if ((relsec->sh_type != SHT_RELA && relsec->sh_type != SHT_REL) 10571 || relsec->sh_info >= elf_header.e_shnum 10572 || section_headers + relsec->sh_info != section 10573 || relsec->sh_size == 0 10574 || relsec->sh_link >= elf_header.e_shnum) 10575 continue; 10576 10577 printf (_(" NOTE: This section has relocations against it, but these have NOT been applied to this dump.\n")); 10578 break; 10579 } 10580 } 10581 10582 addr = section->sh_addr; 10583 bytes = section->sh_size; 10584 data = start; 10585 10586 while (bytes) 10587 { 10588 int j; 10589 int k; 10590 int lbytes; 10591 10592 lbytes = (bytes > 16 ? 16 : bytes); 10593 10594 printf (" 0x%8.8lx ", (unsigned long) addr); 10595 10596 for (j = 0; j < 16; j++) 10597 { 10598 if (j < lbytes) 10599 printf ("%2.2x", data[j]); 10600 else 10601 printf (" "); 10602 10603 if ((j & 3) == 3) 10604 printf (" "); 10605 } 10606 10607 for (j = 0; j < lbytes; j++) 10608 { 10609 k = data[j]; 10610 if (k >= ' ' && k < 0x7f) 10611 printf ("%c", k); 10612 else 10613 printf ("."); 10614 } 10615 10616 putchar ('\n'); 10617 10618 data += lbytes; 10619 addr += lbytes; 10620 bytes -= lbytes; 10621 } 10622 10623 free (start); 10624 10625 putchar ('\n'); 10626 } 10627 10628 /* Uncompresses a section that was compressed using zlib, in place. */ 10629 10630 static int 10631 uncompress_section_contents (unsigned char **buffer ATTRIBUTE_UNUSED, 10632 dwarf_size_type *size ATTRIBUTE_UNUSED) 10633 { 10634 #ifndef HAVE_ZLIB_H 10635 return FALSE; 10636 #else 10637 dwarf_size_type compressed_size = *size; 10638 unsigned char * compressed_buffer = *buffer; 10639 dwarf_size_type uncompressed_size; 10640 unsigned char * uncompressed_buffer; 10641 z_stream strm; 10642 int rc; 10643 dwarf_size_type header_size = 12; 10644 10645 /* Read the zlib header. In this case, it should be "ZLIB" followed 10646 by the uncompressed section size, 8 bytes in big-endian order. */ 10647 if (compressed_size < header_size 10648 || ! streq ((char *) compressed_buffer, "ZLIB")) 10649 return 0; 10650 10651 uncompressed_size = compressed_buffer[4]; uncompressed_size <<= 8; 10652 uncompressed_size += compressed_buffer[5]; uncompressed_size <<= 8; 10653 uncompressed_size += compressed_buffer[6]; uncompressed_size <<= 8; 10654 uncompressed_size += compressed_buffer[7]; uncompressed_size <<= 8; 10655 uncompressed_size += compressed_buffer[8]; uncompressed_size <<= 8; 10656 uncompressed_size += compressed_buffer[9]; uncompressed_size <<= 8; 10657 uncompressed_size += compressed_buffer[10]; uncompressed_size <<= 8; 10658 uncompressed_size += compressed_buffer[11]; 10659 10660 /* It is possible the section consists of several compressed 10661 buffers concatenated together, so we uncompress in a loop. */ 10662 strm.zalloc = NULL; 10663 strm.zfree = NULL; 10664 strm.opaque = NULL; 10665 strm.avail_in = compressed_size - header_size; 10666 strm.next_in = (Bytef *) compressed_buffer + header_size; 10667 strm.avail_out = uncompressed_size; 10668 uncompressed_buffer = (unsigned char *) xmalloc (uncompressed_size); 10669 10670 rc = inflateInit (& strm); 10671 while (strm.avail_in > 0) 10672 { 10673 if (rc != Z_OK) 10674 goto fail; 10675 strm.next_out = ((Bytef *) uncompressed_buffer 10676 + (uncompressed_size - strm.avail_out)); 10677 rc = inflate (&strm, Z_FINISH); 10678 if (rc != Z_STREAM_END) 10679 goto fail; 10680 rc = inflateReset (& strm); 10681 } 10682 rc = inflateEnd (& strm); 10683 if (rc != Z_OK 10684 || strm.avail_out != 0) 10685 goto fail; 10686 10687 free (compressed_buffer); 10688 *buffer = uncompressed_buffer; 10689 *size = uncompressed_size; 10690 return 1; 10691 10692 fail: 10693 free (uncompressed_buffer); 10694 /* Indicate decompression failure. */ 10695 *buffer = NULL; 10696 return 0; 10697 #endif /* HAVE_ZLIB_H */ 10698 } 10699 10700 static int 10701 load_specific_debug_section (enum dwarf_section_display_enum debug, 10702 Elf_Internal_Shdr * sec, void * file) 10703 { 10704 struct dwarf_section * section = &debug_displays [debug].section; 10705 char buf [64]; 10706 10707 /* If it is already loaded, do nothing. */ 10708 if (section->start != NULL) 10709 return 1; 10710 10711 snprintf (buf, sizeof (buf), _("%s section data"), section->name); 10712 section->address = sec->sh_addr; 10713 section->start = (unsigned char *) get_data (NULL, (FILE *) file, 10714 sec->sh_offset, 1, 10715 sec->sh_size, buf); 10716 if (section->start == NULL) 10717 section->size = 0; 10718 else 10719 { 10720 section->size = sec->sh_size; 10721 if (uncompress_section_contents (§ion->start, §ion->size)) 10722 sec->sh_size = section->size; 10723 } 10724 10725 if (section->start == NULL) 10726 return 0; 10727 10728 if (debug_displays [debug].relocate) 10729 apply_relocations ((FILE *) file, sec, section->start); 10730 10731 return 1; 10732 } 10733 10734 int 10735 load_debug_section (enum dwarf_section_display_enum debug, void * file) 10736 { 10737 struct dwarf_section * section = &debug_displays [debug].section; 10738 Elf_Internal_Shdr * sec; 10739 10740 /* Locate the debug section. */ 10741 sec = find_section (section->uncompressed_name); 10742 if (sec != NULL) 10743 section->name = section->uncompressed_name; 10744 else 10745 { 10746 sec = find_section (section->compressed_name); 10747 if (sec != NULL) 10748 section->name = section->compressed_name; 10749 } 10750 if (sec == NULL) 10751 return 0; 10752 10753 return load_specific_debug_section (debug, sec, (FILE *) file); 10754 } 10755 10756 void 10757 free_debug_section (enum dwarf_section_display_enum debug) 10758 { 10759 struct dwarf_section * section = &debug_displays [debug].section; 10760 10761 if (section->start == NULL) 10762 return; 10763 10764 free ((char *) section->start); 10765 section->start = NULL; 10766 section->address = 0; 10767 section->size = 0; 10768 } 10769 10770 static int 10771 display_debug_section (Elf_Internal_Shdr * section, FILE * file) 10772 { 10773 char * name = SECTION_NAME (section); 10774 bfd_size_type length; 10775 int result = 1; 10776 int i; 10777 10778 length = section->sh_size; 10779 if (length == 0) 10780 { 10781 printf (_("\nSection '%s' has no debugging data.\n"), name); 10782 return 0; 10783 } 10784 if (section->sh_type == SHT_NOBITS) 10785 { 10786 /* There is no point in dumping the contents of a debugging section 10787 which has the NOBITS type - the bits in the file will be random. 10788 This can happen when a file containing a .eh_frame section is 10789 stripped with the --only-keep-debug command line option. */ 10790 printf (_("section '%s' has the NOBITS type - its contents are unreliable.\n"), name); 10791 return 0; 10792 } 10793 10794 if (const_strneq (name, ".gnu.linkonce.wi.")) 10795 name = ".debug_info"; 10796 10797 /* See if we know how to display the contents of this section. */ 10798 for (i = 0; i < max; i++) 10799 if (streq (debug_displays[i].section.uncompressed_name, name) 10800 || streq (debug_displays[i].section.compressed_name, name)) 10801 { 10802 struct dwarf_section * sec = &debug_displays [i].section; 10803 int secondary = (section != find_section (name)); 10804 10805 if (secondary) 10806 free_debug_section ((enum dwarf_section_display_enum) i); 10807 10808 if (streq (sec->uncompressed_name, name)) 10809 sec->name = sec->uncompressed_name; 10810 else 10811 sec->name = sec->compressed_name; 10812 if (load_specific_debug_section ((enum dwarf_section_display_enum) i, 10813 section, file)) 10814 { 10815 result &= debug_displays[i].display (sec, file); 10816 10817 if (secondary || (i != info && i != abbrev)) 10818 free_debug_section ((enum dwarf_section_display_enum) i); 10819 } 10820 10821 break; 10822 } 10823 10824 if (i == max) 10825 { 10826 printf (_("Unrecognized debug section: %s\n"), name); 10827 result = 0; 10828 } 10829 10830 return result; 10831 } 10832 10833 /* Set DUMP_SECTS for all sections where dumps were requested 10834 based on section name. */ 10835 10836 static void 10837 initialise_dumps_byname (void) 10838 { 10839 struct dump_list_entry * cur; 10840 10841 for (cur = dump_sects_byname; cur; cur = cur->next) 10842 { 10843 unsigned int i; 10844 int any; 10845 10846 for (i = 0, any = 0; i < elf_header.e_shnum; i++) 10847 if (streq (SECTION_NAME (section_headers + i), cur->name)) 10848 { 10849 request_dump_bynumber (i, cur->type); 10850 any = 1; 10851 } 10852 10853 if (!any) 10854 warn (_("Section '%s' was not dumped because it does not exist!\n"), 10855 cur->name); 10856 } 10857 } 10858 10859 static void 10860 process_section_contents (FILE * file) 10861 { 10862 Elf_Internal_Shdr * section; 10863 unsigned int i; 10864 10865 if (! do_dump) 10866 return; 10867 10868 initialise_dumps_byname (); 10869 10870 for (i = 0, section = section_headers; 10871 i < elf_header.e_shnum && i < num_dump_sects; 10872 i++, section++) 10873 { 10874 #ifdef SUPPORT_DISASSEMBLY 10875 if (dump_sects[i] & DISASS_DUMP) 10876 disassemble_section (section, file); 10877 #endif 10878 if (dump_sects[i] & HEX_DUMP) 10879 dump_section_as_bytes (section, file, FALSE); 10880 10881 if (dump_sects[i] & RELOC_DUMP) 10882 dump_section_as_bytes (section, file, TRUE); 10883 10884 if (dump_sects[i] & STRING_DUMP) 10885 dump_section_as_strings (section, file); 10886 10887 if (dump_sects[i] & DEBUG_DUMP) 10888 display_debug_section (section, file); 10889 } 10890 10891 /* Check to see if the user requested a 10892 dump of a section that does not exist. */ 10893 while (i++ < num_dump_sects) 10894 if (dump_sects[i]) 10895 warn (_("Section %d was not dumped because it does not exist!\n"), i); 10896 } 10897 10898 static void 10899 process_mips_fpe_exception (int mask) 10900 { 10901 if (mask) 10902 { 10903 int first = 1; 10904 if (mask & OEX_FPU_INEX) 10905 fputs ("INEX", stdout), first = 0; 10906 if (mask & OEX_FPU_UFLO) 10907 printf ("%sUFLO", first ? "" : "|"), first = 0; 10908 if (mask & OEX_FPU_OFLO) 10909 printf ("%sOFLO", first ? "" : "|"), first = 0; 10910 if (mask & OEX_FPU_DIV0) 10911 printf ("%sDIV0", first ? "" : "|"), first = 0; 10912 if (mask & OEX_FPU_INVAL) 10913 printf ("%sINVAL", first ? "" : "|"); 10914 } 10915 else 10916 fputs ("0", stdout); 10917 } 10918 10919 /* ARM EABI attributes section. */ 10920 typedef struct 10921 { 10922 int tag; 10923 const char * name; 10924 /* 0 = special, 1 = string, 2 = uleb123, > 0x80 == table lookup. */ 10925 int type; 10926 const char ** table; 10927 } arm_attr_public_tag; 10928 10929 static const char * arm_attr_tag_CPU_arch[] = 10930 {"Pre-v4", "v4", "v4T", "v5T", "v5TE", "v5TEJ", "v6", "v6KZ", "v6T2", 10931 "v6K", "v7", "v6-M", "v6S-M", "v7E-M", "v8"}; 10932 static const char * arm_attr_tag_ARM_ISA_use[] = {"No", "Yes"}; 10933 static const char * arm_attr_tag_THUMB_ISA_use[] = 10934 {"No", "Thumb-1", "Thumb-2"}; 10935 static const char * arm_attr_tag_FP_arch[] = 10936 {"No", "VFPv1", "VFPv2", "VFPv3", "VFPv3-D16", "VFPv4", "VFPv4-D16", 10937 "FP for ARMv8"}; 10938 static const char * arm_attr_tag_WMMX_arch[] = {"No", "WMMXv1", "WMMXv2"}; 10939 static const char * arm_attr_tag_Advanced_SIMD_arch[] = 10940 {"No", "NEONv1", "NEONv1 with Fused-MAC", "NEON for ARMv8"}; 10941 static const char * arm_attr_tag_PCS_config[] = 10942 {"None", "Bare platform", "Linux application", "Linux DSO", "PalmOS 2004", 10943 "PalmOS (reserved)", "SymbianOS 2004", "SymbianOS (reserved)"}; 10944 static const char * arm_attr_tag_ABI_PCS_R9_use[] = 10945 {"V6", "SB", "TLS", "Unused"}; 10946 static const char * arm_attr_tag_ABI_PCS_RW_data[] = 10947 {"Absolute", "PC-relative", "SB-relative", "None"}; 10948 static const char * arm_attr_tag_ABI_PCS_RO_data[] = 10949 {"Absolute", "PC-relative", "None"}; 10950 static const char * arm_attr_tag_ABI_PCS_GOT_use[] = 10951 {"None", "direct", "GOT-indirect"}; 10952 static const char * arm_attr_tag_ABI_PCS_wchar_t[] = 10953 {"None", "??? 1", "2", "??? 3", "4"}; 10954 static const char * arm_attr_tag_ABI_FP_rounding[] = {"Unused", "Needed"}; 10955 static const char * arm_attr_tag_ABI_FP_denormal[] = 10956 {"Unused", "Needed", "Sign only"}; 10957 static const char * arm_attr_tag_ABI_FP_exceptions[] = {"Unused", "Needed"}; 10958 static const char * arm_attr_tag_ABI_FP_user_exceptions[] = {"Unused", "Needed"}; 10959 static const char * arm_attr_tag_ABI_FP_number_model[] = 10960 {"Unused", "Finite", "RTABI", "IEEE 754"}; 10961 static const char * arm_attr_tag_ABI_enum_size[] = 10962 {"Unused", "small", "int", "forced to int"}; 10963 static const char * arm_attr_tag_ABI_HardFP_use[] = 10964 {"As Tag_FP_arch", "SP only", "DP only", "SP and DP"}; 10965 static const char * arm_attr_tag_ABI_VFP_args[] = 10966 {"AAPCS", "VFP registers", "custom"}; 10967 static const char * arm_attr_tag_ABI_WMMX_args[] = 10968 {"AAPCS", "WMMX registers", "custom"}; 10969 static const char * arm_attr_tag_ABI_optimization_goals[] = 10970 {"None", "Prefer Speed", "Aggressive Speed", "Prefer Size", 10971 "Aggressive Size", "Prefer Debug", "Aggressive Debug"}; 10972 static const char * arm_attr_tag_ABI_FP_optimization_goals[] = 10973 {"None", "Prefer Speed", "Aggressive Speed", "Prefer Size", 10974 "Aggressive Size", "Prefer Accuracy", "Aggressive Accuracy"}; 10975 static const char * arm_attr_tag_CPU_unaligned_access[] = {"None", "v6"}; 10976 static const char * arm_attr_tag_FP_HP_extension[] = 10977 {"Not Allowed", "Allowed"}; 10978 static const char * arm_attr_tag_ABI_FP_16bit_format[] = 10979 {"None", "IEEE 754", "Alternative Format"}; 10980 static const char * arm_attr_tag_MPextension_use[] = 10981 {"Not Allowed", "Allowed"}; 10982 static const char * arm_attr_tag_DIV_use[] = 10983 {"Allowed in Thumb-ISA, v7-R or v7-M", "Not allowed", 10984 "Allowed in v7-A with integer division extension"}; 10985 static const char * arm_attr_tag_T2EE_use[] = {"Not Allowed", "Allowed"}; 10986 static const char * arm_attr_tag_Virtualization_use[] = 10987 {"Not Allowed", "TrustZone", "Virtualization Extensions", 10988 "TrustZone and Virtualization Extensions"}; 10989 static const char * arm_attr_tag_MPextension_use_legacy[] = 10990 {"Not Allowed", "Allowed"}; 10991 10992 #define LOOKUP(id, name) \ 10993 {id, #name, 0x80 | ARRAY_SIZE(arm_attr_tag_##name), arm_attr_tag_##name} 10994 static arm_attr_public_tag arm_attr_public_tags[] = 10995 { 10996 {4, "CPU_raw_name", 1, NULL}, 10997 {5, "CPU_name", 1, NULL}, 10998 LOOKUP(6, CPU_arch), 10999 {7, "CPU_arch_profile", 0, NULL}, 11000 LOOKUP(8, ARM_ISA_use), 11001 LOOKUP(9, THUMB_ISA_use), 11002 LOOKUP(10, FP_arch), 11003 LOOKUP(11, WMMX_arch), 11004 LOOKUP(12, Advanced_SIMD_arch), 11005 LOOKUP(13, PCS_config), 11006 LOOKUP(14, ABI_PCS_R9_use), 11007 LOOKUP(15, ABI_PCS_RW_data), 11008 LOOKUP(16, ABI_PCS_RO_data), 11009 LOOKUP(17, ABI_PCS_GOT_use), 11010 LOOKUP(18, ABI_PCS_wchar_t), 11011 LOOKUP(19, ABI_FP_rounding), 11012 LOOKUP(20, ABI_FP_denormal), 11013 LOOKUP(21, ABI_FP_exceptions), 11014 LOOKUP(22, ABI_FP_user_exceptions), 11015 LOOKUP(23, ABI_FP_number_model), 11016 {24, "ABI_align_needed", 0, NULL}, 11017 {25, "ABI_align_preserved", 0, NULL}, 11018 LOOKUP(26, ABI_enum_size), 11019 LOOKUP(27, ABI_HardFP_use), 11020 LOOKUP(28, ABI_VFP_args), 11021 LOOKUP(29, ABI_WMMX_args), 11022 LOOKUP(30, ABI_optimization_goals), 11023 LOOKUP(31, ABI_FP_optimization_goals), 11024 {32, "compatibility", 0, NULL}, 11025 LOOKUP(34, CPU_unaligned_access), 11026 LOOKUP(36, FP_HP_extension), 11027 LOOKUP(38, ABI_FP_16bit_format), 11028 LOOKUP(42, MPextension_use), 11029 LOOKUP(44, DIV_use), 11030 {64, "nodefaults", 0, NULL}, 11031 {65, "also_compatible_with", 0, NULL}, 11032 LOOKUP(66, T2EE_use), 11033 {67, "conformance", 1, NULL}, 11034 LOOKUP(68, Virtualization_use), 11035 LOOKUP(70, MPextension_use_legacy) 11036 }; 11037 #undef LOOKUP 11038 11039 static unsigned char * 11040 display_arm_attribute (unsigned char * p) 11041 { 11042 int tag; 11043 unsigned int len; 11044 int val; 11045 arm_attr_public_tag * attr; 11046 unsigned i; 11047 int type; 11048 11049 tag = read_uleb128 (p, &len); 11050 p += len; 11051 attr = NULL; 11052 for (i = 0; i < ARRAY_SIZE (arm_attr_public_tags); i++) 11053 { 11054 if (arm_attr_public_tags[i].tag == tag) 11055 { 11056 attr = &arm_attr_public_tags[i]; 11057 break; 11058 } 11059 } 11060 11061 if (attr) 11062 { 11063 printf (" Tag_%s: ", attr->name); 11064 switch (attr->type) 11065 { 11066 case 0: 11067 switch (tag) 11068 { 11069 case 7: /* Tag_CPU_arch_profile. */ 11070 val = read_uleb128 (p, &len); 11071 p += len; 11072 switch (val) 11073 { 11074 case 0: printf (_("None\n")); break; 11075 case 'A': printf (_("Application\n")); break; 11076 case 'R': printf (_("Realtime\n")); break; 11077 case 'M': printf (_("Microcontroller\n")); break; 11078 case 'S': printf (_("Application or Realtime\n")); break; 11079 default: printf ("??? (%d)\n", val); break; 11080 } 11081 break; 11082 11083 case 24: /* Tag_align_needed. */ 11084 val = read_uleb128 (p, &len); 11085 p += len; 11086 switch (val) 11087 { 11088 case 0: printf (_("None\n")); break; 11089 case 1: printf (_("8-byte\n")); break; 11090 case 2: printf (_("4-byte\n")); break; 11091 case 3: printf ("??? 3\n"); break; 11092 default: 11093 if (val <= 12) 11094 printf (_("8-byte and up to %d-byte extended\n"), 11095 1 << val); 11096 else 11097 printf ("??? (%d)\n", val); 11098 break; 11099 } 11100 break; 11101 11102 case 25: /* Tag_align_preserved. */ 11103 val = read_uleb128 (p, &len); 11104 p += len; 11105 switch (val) 11106 { 11107 case 0: printf (_("None\n")); break; 11108 case 1: printf (_("8-byte, except leaf SP\n")); break; 11109 case 2: printf (_("8-byte\n")); break; 11110 case 3: printf ("??? 3\n"); break; 11111 default: 11112 if (val <= 12) 11113 printf (_("8-byte and up to %d-byte extended\n"), 11114 1 << val); 11115 else 11116 printf ("??? (%d)\n", val); 11117 break; 11118 } 11119 break; 11120 11121 case 32: /* Tag_compatibility. */ 11122 val = read_uleb128 (p, &len); 11123 p += len; 11124 printf (_("flag = %d, vendor = %s\n"), val, p); 11125 p += strlen ((char *) p) + 1; 11126 break; 11127 11128 case 64: /* Tag_nodefaults. */ 11129 p++; 11130 printf (_("True\n")); 11131 break; 11132 11133 case 65: /* Tag_also_compatible_with. */ 11134 val = read_uleb128 (p, &len); 11135 p += len; 11136 if (val == 6 /* Tag_CPU_arch. */) 11137 { 11138 val = read_uleb128 (p, &len); 11139 p += len; 11140 if ((unsigned int)val >= ARRAY_SIZE (arm_attr_tag_CPU_arch)) 11141 printf ("??? (%d)\n", val); 11142 else 11143 printf ("%s\n", arm_attr_tag_CPU_arch[val]); 11144 } 11145 else 11146 printf ("???\n"); 11147 while (*(p++) != '\0' /* NUL terminator. */); 11148 break; 11149 11150 default: 11151 abort (); 11152 } 11153 return p; 11154 11155 case 1: 11156 case 2: 11157 type = attr->type; 11158 break; 11159 11160 default: 11161 assert (attr->type & 0x80); 11162 val = read_uleb128 (p, &len); 11163 p += len; 11164 type = attr->type & 0x7f; 11165 if (val >= type) 11166 printf ("??? (%d)\n", val); 11167 else 11168 printf ("%s\n", attr->table[val]); 11169 return p; 11170 } 11171 } 11172 else 11173 { 11174 if (tag & 1) 11175 type = 1; /* String. */ 11176 else 11177 type = 2; /* uleb128. */ 11178 printf (" Tag_unknown_%d: ", tag); 11179 } 11180 11181 if (type == 1) 11182 { 11183 printf ("\"%s\"\n", p); 11184 p += strlen ((char *) p) + 1; 11185 } 11186 else 11187 { 11188 val = read_uleb128 (p, &len); 11189 p += len; 11190 printf ("%d (0x%x)\n", val, val); 11191 } 11192 11193 return p; 11194 } 11195 11196 static unsigned char * 11197 display_gnu_attribute (unsigned char * p, 11198 unsigned char * (* display_proc_gnu_attribute) (unsigned char *, int)) 11199 { 11200 int tag; 11201 unsigned int len; 11202 int val; 11203 int type; 11204 11205 tag = read_uleb128 (p, &len); 11206 p += len; 11207 11208 /* Tag_compatibility is the only generic GNU attribute defined at 11209 present. */ 11210 if (tag == 32) 11211 { 11212 val = read_uleb128 (p, &len); 11213 p += len; 11214 printf (_("flag = %d, vendor = %s\n"), val, p); 11215 p += strlen ((char *) p) + 1; 11216 return p; 11217 } 11218 11219 if ((tag & 2) == 0 && display_proc_gnu_attribute) 11220 return display_proc_gnu_attribute (p, tag); 11221 11222 if (tag & 1) 11223 type = 1; /* String. */ 11224 else 11225 type = 2; /* uleb128. */ 11226 printf (" Tag_unknown_%d: ", tag); 11227 11228 if (type == 1) 11229 { 11230 printf ("\"%s\"\n", p); 11231 p += strlen ((char *) p) + 1; 11232 } 11233 else 11234 { 11235 val = read_uleb128 (p, &len); 11236 p += len; 11237 printf ("%d (0x%x)\n", val, val); 11238 } 11239 11240 return p; 11241 } 11242 11243 static unsigned char * 11244 display_power_gnu_attribute (unsigned char * p, int tag) 11245 { 11246 int type; 11247 unsigned int len; 11248 int val; 11249 11250 if (tag == Tag_GNU_Power_ABI_FP) 11251 { 11252 val = read_uleb128 (p, &len); 11253 p += len; 11254 printf (" Tag_GNU_Power_ABI_FP: "); 11255 11256 switch (val) 11257 { 11258 case 0: 11259 printf (_("Hard or soft float\n")); 11260 break; 11261 case 1: 11262 printf (_("Hard float\n")); 11263 break; 11264 case 2: 11265 printf (_("Soft float\n")); 11266 break; 11267 case 3: 11268 printf (_("Single-precision hard float\n")); 11269 break; 11270 default: 11271 printf ("??? (%d)\n", val); 11272 break; 11273 } 11274 return p; 11275 } 11276 11277 if (tag == Tag_GNU_Power_ABI_Vector) 11278 { 11279 val = read_uleb128 (p, &len); 11280 p += len; 11281 printf (" Tag_GNU_Power_ABI_Vector: "); 11282 switch (val) 11283 { 11284 case 0: 11285 printf (_("Any\n")); 11286 break; 11287 case 1: 11288 printf (_("Generic\n")); 11289 break; 11290 case 2: 11291 printf ("AltiVec\n"); 11292 break; 11293 case 3: 11294 printf ("SPE\n"); 11295 break; 11296 default: 11297 printf ("??? (%d)\n", val); 11298 break; 11299 } 11300 return p; 11301 } 11302 11303 if (tag == Tag_GNU_Power_ABI_Struct_Return) 11304 { 11305 val = read_uleb128 (p, &len); 11306 p += len; 11307 printf (" Tag_GNU_Power_ABI_Struct_Return: "); 11308 switch (val) 11309 { 11310 case 0: 11311 printf (_("Any\n")); 11312 break; 11313 case 1: 11314 printf ("r3/r4\n"); 11315 break; 11316 case 2: 11317 printf (_("Memory\n")); 11318 break; 11319 default: 11320 printf ("??? (%d)\n", val); 11321 break; 11322 } 11323 return p; 11324 } 11325 11326 if (tag & 1) 11327 type = 1; /* String. */ 11328 else 11329 type = 2; /* uleb128. */ 11330 printf (" Tag_unknown_%d: ", tag); 11331 11332 if (type == 1) 11333 { 11334 printf ("\"%s\"\n", p); 11335 p += strlen ((char *) p) + 1; 11336 } 11337 else 11338 { 11339 val = read_uleb128 (p, &len); 11340 p += len; 11341 printf ("%d (0x%x)\n", val, val); 11342 } 11343 11344 return p; 11345 } 11346 11347 static void 11348 display_sparc_hwcaps (int mask) 11349 { 11350 if (mask) 11351 { 11352 int first = 1; 11353 if (mask & ELF_SPARC_HWCAP_MUL32) 11354 fputs ("mul32", stdout), first = 0; 11355 if (mask & ELF_SPARC_HWCAP_DIV32) 11356 printf ("%sdiv32", first ? "" : "|"), first = 0; 11357 if (mask & ELF_SPARC_HWCAP_FSMULD) 11358 printf ("%sfsmuld", first ? "" : "|"), first = 0; 11359 if (mask & ELF_SPARC_HWCAP_V8PLUS) 11360 printf ("%sv8plus", first ? "" : "|"), first = 0; 11361 if (mask & ELF_SPARC_HWCAP_POPC) 11362 printf ("%spopc", first ? "" : "|"), first = 0; 11363 if (mask & ELF_SPARC_HWCAP_VIS) 11364 printf ("%svis", first ? "" : "|"), first = 0; 11365 if (mask & ELF_SPARC_HWCAP_VIS2) 11366 printf ("%svis2", first ? "" : "|"), first = 0; 11367 if (mask & ELF_SPARC_HWCAP_ASI_BLK_INIT) 11368 printf ("%sASIBlkInit", first ? "" : "|"), first = 0; 11369 if (mask & ELF_SPARC_HWCAP_FMAF) 11370 printf ("%sfmaf", first ? "" : "|"), first = 0; 11371 if (mask & ELF_SPARC_HWCAP_VIS3) 11372 printf ("%svis3", first ? "" : "|"), first = 0; 11373 if (mask & ELF_SPARC_HWCAP_HPC) 11374 printf ("%shpc", first ? "" : "|"), first = 0; 11375 if (mask & ELF_SPARC_HWCAP_RANDOM) 11376 printf ("%srandom", first ? "" : "|"), first = 0; 11377 if (mask & ELF_SPARC_HWCAP_TRANS) 11378 printf ("%strans", first ? "" : "|"), first = 0; 11379 if (mask & ELF_SPARC_HWCAP_FJFMAU) 11380 printf ("%sfjfmau", first ? "" : "|"), first = 0; 11381 if (mask & ELF_SPARC_HWCAP_IMA) 11382 printf ("%sima", first ? "" : "|"), first = 0; 11383 if (mask & ELF_SPARC_HWCAP_ASI_CACHE_SPARING) 11384 printf ("%scspare", first ? "" : "|"), first = 0; 11385 } 11386 else 11387 fputc('0', stdout); 11388 fputc('\n', stdout); 11389 } 11390 11391 static unsigned char * 11392 display_sparc_gnu_attribute (unsigned char * p, int tag) 11393 { 11394 int type; 11395 unsigned int len; 11396 int val; 11397 11398 if (tag == Tag_GNU_Sparc_HWCAPS) 11399 { 11400 val = read_uleb128 (p, &len); 11401 p += len; 11402 printf (" Tag_GNU_Sparc_HWCAPS: "); 11403 11404 display_sparc_hwcaps (val); 11405 return p; 11406 } 11407 11408 if (tag & 1) 11409 type = 1; /* String. */ 11410 else 11411 type = 2; /* uleb128. */ 11412 printf (" Tag_unknown_%d: ", tag); 11413 11414 if (type == 1) 11415 { 11416 printf ("\"%s\"\n", p); 11417 p += strlen ((char *) p) + 1; 11418 } 11419 else 11420 { 11421 val = read_uleb128 (p, &len); 11422 p += len; 11423 printf ("%d (0x%x)\n", val, val); 11424 } 11425 11426 return p; 11427 } 11428 11429 static unsigned char * 11430 display_mips_gnu_attribute (unsigned char * p, int tag) 11431 { 11432 int type; 11433 unsigned int len; 11434 int val; 11435 11436 if (tag == Tag_GNU_MIPS_ABI_FP) 11437 { 11438 val = read_uleb128 (p, &len); 11439 p += len; 11440 printf (" Tag_GNU_MIPS_ABI_FP: "); 11441 11442 switch (val) 11443 { 11444 case 0: 11445 printf (_("Hard or soft float\n")); 11446 break; 11447 case 1: 11448 printf (_("Hard float (double precision)\n")); 11449 break; 11450 case 2: 11451 printf (_("Hard float (single precision)\n")); 11452 break; 11453 case 3: 11454 printf (_("Soft float\n")); 11455 break; 11456 case 4: 11457 printf (_("Hard float (MIPS32r2 64-bit FPU)\n")); 11458 break; 11459 default: 11460 printf ("??? (%d)\n", val); 11461 break; 11462 } 11463 return p; 11464 } 11465 11466 if (tag & 1) 11467 type = 1; /* String. */ 11468 else 11469 type = 2; /* uleb128. */ 11470 printf (" Tag_unknown_%d: ", tag); 11471 11472 if (type == 1) 11473 { 11474 printf ("\"%s\"\n", p); 11475 p += strlen ((char *) p) + 1; 11476 } 11477 else 11478 { 11479 val = read_uleb128 (p, &len); 11480 p += len; 11481 printf ("%d (0x%x)\n", val, val); 11482 } 11483 11484 return p; 11485 } 11486 11487 static unsigned char * 11488 display_tic6x_attribute (unsigned char * p) 11489 { 11490 int tag; 11491 unsigned int len; 11492 int val; 11493 11494 tag = read_uleb128 (p, &len); 11495 p += len; 11496 11497 switch (tag) 11498 { 11499 case Tag_ISA: 11500 val = read_uleb128 (p, &len); 11501 p += len; 11502 printf (" Tag_ISA: "); 11503 11504 switch (val) 11505 { 11506 case C6XABI_Tag_ISA_none: 11507 printf (_("None\n")); 11508 break; 11509 case C6XABI_Tag_ISA_C62X: 11510 printf ("C62x\n"); 11511 break; 11512 case C6XABI_Tag_ISA_C67X: 11513 printf ("C67x\n"); 11514 break; 11515 case C6XABI_Tag_ISA_C67XP: 11516 printf ("C67x+\n"); 11517 break; 11518 case C6XABI_Tag_ISA_C64X: 11519 printf ("C64x\n"); 11520 break; 11521 case C6XABI_Tag_ISA_C64XP: 11522 printf ("C64x+\n"); 11523 break; 11524 case C6XABI_Tag_ISA_C674X: 11525 printf ("C674x\n"); 11526 break; 11527 default: 11528 printf ("??? (%d)\n", val); 11529 break; 11530 } 11531 return p; 11532 11533 case Tag_ABI_wchar_t: 11534 val = read_uleb128 (p, &len); 11535 p += len; 11536 printf (" Tag_ABI_wchar_t: "); 11537 switch (val) 11538 { 11539 case 0: 11540 printf (_("Not used\n")); 11541 break; 11542 case 1: 11543 printf (_("2 bytes\n")); 11544 break; 11545 case 2: 11546 printf (_("4 bytes\n")); 11547 break; 11548 default: 11549 printf ("??? (%d)\n", val); 11550 break; 11551 } 11552 return p; 11553 11554 case Tag_ABI_stack_align_needed: 11555 val = read_uleb128 (p, &len); 11556 p += len; 11557 printf (" Tag_ABI_stack_align_needed: "); 11558 switch (val) 11559 { 11560 case 0: 11561 printf (_("8-byte\n")); 11562 break; 11563 case 1: 11564 printf (_("16-byte\n")); 11565 break; 11566 default: 11567 printf ("??? (%d)\n", val); 11568 break; 11569 } 11570 return p; 11571 11572 case Tag_ABI_stack_align_preserved: 11573 val = read_uleb128 (p, &len); 11574 p += len; 11575 printf (" Tag_ABI_stack_align_preserved: "); 11576 switch (val) 11577 { 11578 case 0: 11579 printf (_("8-byte\n")); 11580 break; 11581 case 1: 11582 printf (_("16-byte\n")); 11583 break; 11584 default: 11585 printf ("??? (%d)\n", val); 11586 break; 11587 } 11588 return p; 11589 11590 case Tag_ABI_DSBT: 11591 val = read_uleb128 (p, &len); 11592 p += len; 11593 printf (" Tag_ABI_DSBT: "); 11594 switch (val) 11595 { 11596 case 0: 11597 printf (_("DSBT addressing not used\n")); 11598 break; 11599 case 1: 11600 printf (_("DSBT addressing used\n")); 11601 break; 11602 default: 11603 printf ("??? (%d)\n", val); 11604 break; 11605 } 11606 return p; 11607 11608 case Tag_ABI_PID: 11609 val = read_uleb128 (p, &len); 11610 p += len; 11611 printf (" Tag_ABI_PID: "); 11612 switch (val) 11613 { 11614 case 0: 11615 printf (_("Data addressing position-dependent\n")); 11616 break; 11617 case 1: 11618 printf (_("Data addressing position-independent, GOT near DP\n")); 11619 break; 11620 case 2: 11621 printf (_("Data addressing position-independent, GOT far from DP\n")); 11622 break; 11623 default: 11624 printf ("??? (%d)\n", val); 11625 break; 11626 } 11627 return p; 11628 11629 case Tag_ABI_PIC: 11630 val = read_uleb128 (p, &len); 11631 p += len; 11632 printf (" Tag_ABI_PIC: "); 11633 switch (val) 11634 { 11635 case 0: 11636 printf (_("Code addressing position-dependent\n")); 11637 break; 11638 case 1: 11639 printf (_("Code addressing position-independent\n")); 11640 break; 11641 default: 11642 printf ("??? (%d)\n", val); 11643 break; 11644 } 11645 return p; 11646 11647 case Tag_ABI_array_object_alignment: 11648 val = read_uleb128 (p, &len); 11649 p += len; 11650 printf (" Tag_ABI_array_object_alignment: "); 11651 switch (val) 11652 { 11653 case 0: 11654 printf (_("8-byte\n")); 11655 break; 11656 case 1: 11657 printf (_("4-byte\n")); 11658 break; 11659 case 2: 11660 printf (_("16-byte\n")); 11661 break; 11662 default: 11663 printf ("??? (%d)\n", val); 11664 break; 11665 } 11666 return p; 11667 11668 case Tag_ABI_array_object_align_expected: 11669 val = read_uleb128 (p, &len); 11670 p += len; 11671 printf (" Tag_ABI_array_object_align_expected: "); 11672 switch (val) 11673 { 11674 case 0: 11675 printf (_("8-byte\n")); 11676 break; 11677 case 1: 11678 printf (_("4-byte\n")); 11679 break; 11680 case 2: 11681 printf (_("16-byte\n")); 11682 break; 11683 default: 11684 printf ("??? (%d)\n", val); 11685 break; 11686 } 11687 return p; 11688 11689 case Tag_ABI_compatibility: 11690 val = read_uleb128 (p, &len); 11691 p += len; 11692 printf (" Tag_ABI_compatibility: "); 11693 printf (_("flag = %d, vendor = %s\n"), val, p); 11694 p += strlen ((char *) p) + 1; 11695 return p; 11696 11697 case Tag_ABI_conformance: 11698 printf (" Tag_ABI_conformance: "); 11699 printf ("\"%s\"\n", p); 11700 p += strlen ((char *) p) + 1; 11701 return p; 11702 } 11703 11704 printf (" Tag_unknown_%d: ", tag); 11705 11706 if (tag & 1) 11707 { 11708 printf ("\"%s\"\n", p); 11709 p += strlen ((char *) p) + 1; 11710 } 11711 else 11712 { 11713 val = read_uleb128 (p, &len); 11714 p += len; 11715 printf ("%d (0x%x)\n", val, val); 11716 } 11717 11718 return p; 11719 } 11720 11721 static int 11722 process_attributes (FILE * file, 11723 const char * public_name, 11724 unsigned int proc_type, 11725 unsigned char * (* display_pub_attribute) (unsigned char *), 11726 unsigned char * (* display_proc_gnu_attribute) (unsigned char *, int)) 11727 { 11728 Elf_Internal_Shdr * sect; 11729 unsigned char * contents; 11730 unsigned char * p; 11731 unsigned char * end; 11732 bfd_vma section_len; 11733 bfd_vma len; 11734 unsigned i; 11735 11736 /* Find the section header so that we get the size. */ 11737 for (i = 0, sect = section_headers; 11738 i < elf_header.e_shnum; 11739 i++, sect++) 11740 { 11741 if (sect->sh_type != proc_type && sect->sh_type != SHT_GNU_ATTRIBUTES) 11742 continue; 11743 11744 contents = (unsigned char *) get_data (NULL, file, sect->sh_offset, 1, 11745 sect->sh_size, _("attributes")); 11746 if (contents == NULL) 11747 continue; 11748 11749 p = contents; 11750 if (*p == 'A') 11751 { 11752 len = sect->sh_size - 1; 11753 p++; 11754 11755 while (len > 0) 11756 { 11757 int namelen; 11758 bfd_boolean public_section; 11759 bfd_boolean gnu_section; 11760 11761 section_len = byte_get (p, 4); 11762 p += 4; 11763 11764 if (section_len > len) 11765 { 11766 printf (_("ERROR: Bad section length (%d > %d)\n"), 11767 (int) section_len, (int) len); 11768 section_len = len; 11769 } 11770 11771 len -= section_len; 11772 printf (_("Attribute Section: %s\n"), p); 11773 11774 if (public_name && streq ((char *) p, public_name)) 11775 public_section = TRUE; 11776 else 11777 public_section = FALSE; 11778 11779 if (streq ((char *) p, "gnu")) 11780 gnu_section = TRUE; 11781 else 11782 gnu_section = FALSE; 11783 11784 namelen = strlen ((char *) p) + 1; 11785 p += namelen; 11786 section_len -= namelen + 4; 11787 11788 while (section_len > 0) 11789 { 11790 int tag = *(p++); 11791 int val; 11792 bfd_vma size; 11793 11794 size = byte_get (p, 4); 11795 if (size > section_len) 11796 { 11797 printf (_("ERROR: Bad subsection length (%d > %d)\n"), 11798 (int) size, (int) section_len); 11799 size = section_len; 11800 } 11801 11802 section_len -= size; 11803 end = p + size - 1; 11804 p += 4; 11805 11806 switch (tag) 11807 { 11808 case 1: 11809 printf (_("File Attributes\n")); 11810 break; 11811 case 2: 11812 printf (_("Section Attributes:")); 11813 goto do_numlist; 11814 case 3: 11815 printf (_("Symbol Attributes:")); 11816 do_numlist: 11817 for (;;) 11818 { 11819 unsigned int j; 11820 11821 val = read_uleb128 (p, &j); 11822 p += j; 11823 if (val == 0) 11824 break; 11825 printf (" %d", val); 11826 } 11827 printf ("\n"); 11828 break; 11829 default: 11830 printf (_("Unknown tag: %d\n"), tag); 11831 public_section = FALSE; 11832 break; 11833 } 11834 11835 if (public_section) 11836 { 11837 while (p < end) 11838 p = display_pub_attribute (p); 11839 } 11840 else if (gnu_section) 11841 { 11842 while (p < end) 11843 p = display_gnu_attribute (p, 11844 display_proc_gnu_attribute); 11845 } 11846 else 11847 { 11848 /* ??? Do something sensible, like dump hex. */ 11849 printf (_(" Unknown section contexts\n")); 11850 p = end; 11851 } 11852 } 11853 } 11854 } 11855 else 11856 printf (_("Unknown format '%c'\n"), *p); 11857 11858 free (contents); 11859 } 11860 return 1; 11861 } 11862 11863 static int 11864 process_arm_specific (FILE * file) 11865 { 11866 return process_attributes (file, "aeabi", SHT_ARM_ATTRIBUTES, 11867 display_arm_attribute, NULL); 11868 } 11869 11870 static int 11871 process_power_specific (FILE * file) 11872 { 11873 return process_attributes (file, NULL, SHT_GNU_ATTRIBUTES, NULL, 11874 display_power_gnu_attribute); 11875 } 11876 11877 static int 11878 process_sparc_specific (FILE * file) 11879 { 11880 return process_attributes (file, NULL, SHT_GNU_ATTRIBUTES, NULL, 11881 display_sparc_gnu_attribute); 11882 } 11883 11884 static int 11885 process_tic6x_specific (FILE * file) 11886 { 11887 return process_attributes (file, "c6xabi", SHT_C6000_ATTRIBUTES, 11888 display_tic6x_attribute, NULL); 11889 } 11890 11891 /* DATA points to the contents of a MIPS GOT that starts at VMA PLTGOT. 11892 Print the Address, Access and Initial fields of an entry at VMA ADDR 11893 and return the VMA of the next entry. */ 11894 11895 static bfd_vma 11896 print_mips_got_entry (unsigned char * data, bfd_vma pltgot, bfd_vma addr) 11897 { 11898 printf (" "); 11899 print_vma (addr, LONG_HEX); 11900 printf (" "); 11901 if (addr < pltgot + 0xfff0) 11902 printf ("%6d(gp)", (int) (addr - pltgot - 0x7ff0)); 11903 else 11904 printf ("%10s", ""); 11905 printf (" "); 11906 if (data == NULL) 11907 printf ("%*s", is_32bit_elf ? 8 : 16, _("<unknown>")); 11908 else 11909 { 11910 bfd_vma entry; 11911 11912 entry = byte_get (data + addr - pltgot, is_32bit_elf ? 4 : 8); 11913 print_vma (entry, LONG_HEX); 11914 } 11915 return addr + (is_32bit_elf ? 4 : 8); 11916 } 11917 11918 /* DATA points to the contents of a MIPS PLT GOT that starts at VMA 11919 PLTGOT. Print the Address and Initial fields of an entry at VMA 11920 ADDR and return the VMA of the next entry. */ 11921 11922 static bfd_vma 11923 print_mips_pltgot_entry (unsigned char * data, bfd_vma pltgot, bfd_vma addr) 11924 { 11925 printf (" "); 11926 print_vma (addr, LONG_HEX); 11927 printf (" "); 11928 if (data == NULL) 11929 printf ("%*s", is_32bit_elf ? 8 : 16, _("<unknown>")); 11930 else 11931 { 11932 bfd_vma entry; 11933 11934 entry = byte_get (data + addr - pltgot, is_32bit_elf ? 4 : 8); 11935 print_vma (entry, LONG_HEX); 11936 } 11937 return addr + (is_32bit_elf ? 4 : 8); 11938 } 11939 11940 static int 11941 process_mips_specific (FILE * file) 11942 { 11943 Elf_Internal_Dyn * entry; 11944 size_t liblist_offset = 0; 11945 size_t liblistno = 0; 11946 size_t conflictsno = 0; 11947 size_t options_offset = 0; 11948 size_t conflicts_offset = 0; 11949 size_t pltrelsz = 0; 11950 size_t pltrel = 0; 11951 bfd_vma pltgot = 0; 11952 bfd_vma mips_pltgot = 0; 11953 bfd_vma jmprel = 0; 11954 bfd_vma local_gotno = 0; 11955 bfd_vma gotsym = 0; 11956 bfd_vma symtabno = 0; 11957 11958 process_attributes (file, NULL, SHT_GNU_ATTRIBUTES, NULL, 11959 display_mips_gnu_attribute); 11960 11961 /* We have a lot of special sections. Thanks SGI! */ 11962 if (dynamic_section == NULL) 11963 /* No information available. */ 11964 return 0; 11965 11966 for (entry = dynamic_section; entry->d_tag != DT_NULL; ++entry) 11967 switch (entry->d_tag) 11968 { 11969 case DT_MIPS_LIBLIST: 11970 liblist_offset 11971 = offset_from_vma (file, entry->d_un.d_val, 11972 liblistno * sizeof (Elf32_External_Lib)); 11973 break; 11974 case DT_MIPS_LIBLISTNO: 11975 liblistno = entry->d_un.d_val; 11976 break; 11977 case DT_MIPS_OPTIONS: 11978 options_offset = offset_from_vma (file, entry->d_un.d_val, 0); 11979 break; 11980 case DT_MIPS_CONFLICT: 11981 conflicts_offset 11982 = offset_from_vma (file, entry->d_un.d_val, 11983 conflictsno * sizeof (Elf32_External_Conflict)); 11984 break; 11985 case DT_MIPS_CONFLICTNO: 11986 conflictsno = entry->d_un.d_val; 11987 break; 11988 case DT_PLTGOT: 11989 pltgot = entry->d_un.d_ptr; 11990 break; 11991 case DT_MIPS_LOCAL_GOTNO: 11992 local_gotno = entry->d_un.d_val; 11993 break; 11994 case DT_MIPS_GOTSYM: 11995 gotsym = entry->d_un.d_val; 11996 break; 11997 case DT_MIPS_SYMTABNO: 11998 symtabno = entry->d_un.d_val; 11999 break; 12000 case DT_MIPS_PLTGOT: 12001 mips_pltgot = entry->d_un.d_ptr; 12002 break; 12003 case DT_PLTREL: 12004 pltrel = entry->d_un.d_val; 12005 break; 12006 case DT_PLTRELSZ: 12007 pltrelsz = entry->d_un.d_val; 12008 break; 12009 case DT_JMPREL: 12010 jmprel = entry->d_un.d_ptr; 12011 break; 12012 default: 12013 break; 12014 } 12015 12016 if (liblist_offset != 0 && liblistno != 0 && do_dynamic) 12017 { 12018 Elf32_External_Lib * elib; 12019 size_t cnt; 12020 12021 elib = (Elf32_External_Lib *) get_data (NULL, file, liblist_offset, 12022 liblistno, 12023 sizeof (Elf32_External_Lib), 12024 _("liblist section data")); 12025 if (elib) 12026 { 12027 printf (_("\nSection '.liblist' contains %lu entries:\n"), 12028 (unsigned long) liblistno); 12029 fputs (_(" Library Time Stamp Checksum Version Flags\n"), 12030 stdout); 12031 12032 for (cnt = 0; cnt < liblistno; ++cnt) 12033 { 12034 Elf32_Lib liblist; 12035 time_t atime; 12036 char timebuf[20]; 12037 struct tm * tmp; 12038 12039 liblist.l_name = BYTE_GET (elib[cnt].l_name); 12040 atime = BYTE_GET (elib[cnt].l_time_stamp); 12041 liblist.l_checksum = BYTE_GET (elib[cnt].l_checksum); 12042 liblist.l_version = BYTE_GET (elib[cnt].l_version); 12043 liblist.l_flags = BYTE_GET (elib[cnt].l_flags); 12044 12045 tmp = gmtime (&atime); 12046 snprintf (timebuf, sizeof (timebuf), 12047 "%04u-%02u-%02uT%02u:%02u:%02u", 12048 tmp->tm_year + 1900, tmp->tm_mon + 1, tmp->tm_mday, 12049 tmp->tm_hour, tmp->tm_min, tmp->tm_sec); 12050 12051 printf ("%3lu: ", (unsigned long) cnt); 12052 if (VALID_DYNAMIC_NAME (liblist.l_name)) 12053 print_symbol (20, GET_DYNAMIC_NAME (liblist.l_name)); 12054 else 12055 printf (_("<corrupt: %9ld>"), liblist.l_name); 12056 printf (" %s %#10lx %-7ld", timebuf, liblist.l_checksum, 12057 liblist.l_version); 12058 12059 if (liblist.l_flags == 0) 12060 puts (_(" NONE")); 12061 else 12062 { 12063 static const struct 12064 { 12065 const char * name; 12066 int bit; 12067 } 12068 l_flags_vals[] = 12069 { 12070 { " EXACT_MATCH", LL_EXACT_MATCH }, 12071 { " IGNORE_INT_VER", LL_IGNORE_INT_VER }, 12072 { " REQUIRE_MINOR", LL_REQUIRE_MINOR }, 12073 { " EXPORTS", LL_EXPORTS }, 12074 { " DELAY_LOAD", LL_DELAY_LOAD }, 12075 { " DELTA", LL_DELTA } 12076 }; 12077 int flags = liblist.l_flags; 12078 size_t fcnt; 12079 12080 for (fcnt = 0; fcnt < ARRAY_SIZE (l_flags_vals); ++fcnt) 12081 if ((flags & l_flags_vals[fcnt].bit) != 0) 12082 { 12083 fputs (l_flags_vals[fcnt].name, stdout); 12084 flags ^= l_flags_vals[fcnt].bit; 12085 } 12086 if (flags != 0) 12087 printf (" %#x", (unsigned int) flags); 12088 12089 puts (""); 12090 } 12091 } 12092 12093 free (elib); 12094 } 12095 } 12096 12097 if (options_offset != 0) 12098 { 12099 Elf_External_Options * eopt; 12100 Elf_Internal_Shdr * sect = section_headers; 12101 Elf_Internal_Options * iopt; 12102 Elf_Internal_Options * option; 12103 size_t offset; 12104 int cnt; 12105 12106 /* Find the section header so that we get the size. */ 12107 while (sect->sh_type != SHT_MIPS_OPTIONS) 12108 ++sect; 12109 12110 eopt = (Elf_External_Options *) get_data (NULL, file, options_offset, 1, 12111 sect->sh_size, _("options")); 12112 if (eopt) 12113 { 12114 iopt = (Elf_Internal_Options *) 12115 cmalloc ((sect->sh_size / sizeof (eopt)), sizeof (* iopt)); 12116 if (iopt == NULL) 12117 { 12118 error (_("Out of memory\n")); 12119 return 0; 12120 } 12121 12122 offset = cnt = 0; 12123 option = iopt; 12124 12125 while (offset < sect->sh_size) 12126 { 12127 Elf_External_Options * eoption; 12128 12129 eoption = (Elf_External_Options *) ((char *) eopt + offset); 12130 12131 option->kind = BYTE_GET (eoption->kind); 12132 option->size = BYTE_GET (eoption->size); 12133 option->section = BYTE_GET (eoption->section); 12134 option->info = BYTE_GET (eoption->info); 12135 12136 offset += option->size; 12137 12138 ++option; 12139 ++cnt; 12140 } 12141 12142 printf (_("\nSection '%s' contains %d entries:\n"), 12143 SECTION_NAME (sect), cnt); 12144 12145 option = iopt; 12146 12147 while (cnt-- > 0) 12148 { 12149 size_t len; 12150 12151 switch (option->kind) 12152 { 12153 case ODK_NULL: 12154 /* This shouldn't happen. */ 12155 printf (" NULL %d %lx", option->section, option->info); 12156 break; 12157 case ODK_REGINFO: 12158 printf (" REGINFO "); 12159 if (elf_header.e_machine == EM_MIPS) 12160 { 12161 /* 32bit form. */ 12162 Elf32_External_RegInfo * ereg; 12163 Elf32_RegInfo reginfo; 12164 12165 ereg = (Elf32_External_RegInfo *) (option + 1); 12166 reginfo.ri_gprmask = BYTE_GET (ereg->ri_gprmask); 12167 reginfo.ri_cprmask[0] = BYTE_GET (ereg->ri_cprmask[0]); 12168 reginfo.ri_cprmask[1] = BYTE_GET (ereg->ri_cprmask[1]); 12169 reginfo.ri_cprmask[2] = BYTE_GET (ereg->ri_cprmask[2]); 12170 reginfo.ri_cprmask[3] = BYTE_GET (ereg->ri_cprmask[3]); 12171 reginfo.ri_gp_value = BYTE_GET (ereg->ri_gp_value); 12172 12173 printf ("GPR %08lx GP 0x%lx\n", 12174 reginfo.ri_gprmask, 12175 (unsigned long) reginfo.ri_gp_value); 12176 printf (" CPR0 %08lx CPR1 %08lx CPR2 %08lx CPR3 %08lx\n", 12177 reginfo.ri_cprmask[0], reginfo.ri_cprmask[1], 12178 reginfo.ri_cprmask[2], reginfo.ri_cprmask[3]); 12179 } 12180 else 12181 { 12182 /* 64 bit form. */ 12183 Elf64_External_RegInfo * ereg; 12184 Elf64_Internal_RegInfo reginfo; 12185 12186 ereg = (Elf64_External_RegInfo *) (option + 1); 12187 reginfo.ri_gprmask = BYTE_GET (ereg->ri_gprmask); 12188 reginfo.ri_cprmask[0] = BYTE_GET (ereg->ri_cprmask[0]); 12189 reginfo.ri_cprmask[1] = BYTE_GET (ereg->ri_cprmask[1]); 12190 reginfo.ri_cprmask[2] = BYTE_GET (ereg->ri_cprmask[2]); 12191 reginfo.ri_cprmask[3] = BYTE_GET (ereg->ri_cprmask[3]); 12192 reginfo.ri_gp_value = BYTE_GET (ereg->ri_gp_value); 12193 12194 printf ("GPR %08lx GP 0x", 12195 reginfo.ri_gprmask); 12196 printf_vma (reginfo.ri_gp_value); 12197 printf ("\n"); 12198 12199 printf (" CPR0 %08lx CPR1 %08lx CPR2 %08lx CPR3 %08lx\n", 12200 reginfo.ri_cprmask[0], reginfo.ri_cprmask[1], 12201 reginfo.ri_cprmask[2], reginfo.ri_cprmask[3]); 12202 } 12203 ++option; 12204 continue; 12205 case ODK_EXCEPTIONS: 12206 fputs (" EXCEPTIONS fpe_min(", stdout); 12207 process_mips_fpe_exception (option->info & OEX_FPU_MIN); 12208 fputs (") fpe_max(", stdout); 12209 process_mips_fpe_exception ((option->info & OEX_FPU_MAX) >> 8); 12210 fputs (")", stdout); 12211 12212 if (option->info & OEX_PAGE0) 12213 fputs (" PAGE0", stdout); 12214 if (option->info & OEX_SMM) 12215 fputs (" SMM", stdout); 12216 if (option->info & OEX_FPDBUG) 12217 fputs (" FPDBUG", stdout); 12218 if (option->info & OEX_DISMISS) 12219 fputs (" DISMISS", stdout); 12220 break; 12221 case ODK_PAD: 12222 fputs (" PAD ", stdout); 12223 if (option->info & OPAD_PREFIX) 12224 fputs (" PREFIX", stdout); 12225 if (option->info & OPAD_POSTFIX) 12226 fputs (" POSTFIX", stdout); 12227 if (option->info & OPAD_SYMBOL) 12228 fputs (" SYMBOL", stdout); 12229 break; 12230 case ODK_HWPATCH: 12231 fputs (" HWPATCH ", stdout); 12232 if (option->info & OHW_R4KEOP) 12233 fputs (" R4KEOP", stdout); 12234 if (option->info & OHW_R8KPFETCH) 12235 fputs (" R8KPFETCH", stdout); 12236 if (option->info & OHW_R5KEOP) 12237 fputs (" R5KEOP", stdout); 12238 if (option->info & OHW_R5KCVTL) 12239 fputs (" R5KCVTL", stdout); 12240 break; 12241 case ODK_FILL: 12242 fputs (" FILL ", stdout); 12243 /* XXX Print content of info word? */ 12244 break; 12245 case ODK_TAGS: 12246 fputs (" TAGS ", stdout); 12247 /* XXX Print content of info word? */ 12248 break; 12249 case ODK_HWAND: 12250 fputs (" HWAND ", stdout); 12251 if (option->info & OHWA0_R4KEOP_CHECKED) 12252 fputs (" R4KEOP_CHECKED", stdout); 12253 if (option->info & OHWA0_R4KEOP_CLEAN) 12254 fputs (" R4KEOP_CLEAN", stdout); 12255 break; 12256 case ODK_HWOR: 12257 fputs (" HWOR ", stdout); 12258 if (option->info & OHWA0_R4KEOP_CHECKED) 12259 fputs (" R4KEOP_CHECKED", stdout); 12260 if (option->info & OHWA0_R4KEOP_CLEAN) 12261 fputs (" R4KEOP_CLEAN", stdout); 12262 break; 12263 case ODK_GP_GROUP: 12264 printf (" GP_GROUP %#06lx self-contained %#06lx", 12265 option->info & OGP_GROUP, 12266 (option->info & OGP_SELF) >> 16); 12267 break; 12268 case ODK_IDENT: 12269 printf (" IDENT %#06lx self-contained %#06lx", 12270 option->info & OGP_GROUP, 12271 (option->info & OGP_SELF) >> 16); 12272 break; 12273 default: 12274 /* This shouldn't happen. */ 12275 printf (" %3d ??? %d %lx", 12276 option->kind, option->section, option->info); 12277 break; 12278 } 12279 12280 len = sizeof (* eopt); 12281 while (len < option->size) 12282 if (((char *) option)[len] >= ' ' 12283 && ((char *) option)[len] < 0x7f) 12284 printf ("%c", ((char *) option)[len++]); 12285 else 12286 printf ("\\%03o", ((char *) option)[len++]); 12287 12288 fputs ("\n", stdout); 12289 ++option; 12290 } 12291 12292 free (eopt); 12293 } 12294 } 12295 12296 if (conflicts_offset != 0 && conflictsno != 0) 12297 { 12298 Elf32_Conflict * iconf; 12299 size_t cnt; 12300 12301 if (dynamic_symbols == NULL) 12302 { 12303 error (_("conflict list found without a dynamic symbol table\n")); 12304 return 0; 12305 } 12306 12307 iconf = (Elf32_Conflict *) cmalloc (conflictsno, sizeof (* iconf)); 12308 if (iconf == NULL) 12309 { 12310 error (_("Out of memory\n")); 12311 return 0; 12312 } 12313 12314 if (is_32bit_elf) 12315 { 12316 Elf32_External_Conflict * econf32; 12317 12318 econf32 = (Elf32_External_Conflict *) 12319 get_data (NULL, file, conflicts_offset, conflictsno, 12320 sizeof (* econf32), _("conflict")); 12321 if (!econf32) 12322 return 0; 12323 12324 for (cnt = 0; cnt < conflictsno; ++cnt) 12325 iconf[cnt] = BYTE_GET (econf32[cnt]); 12326 12327 free (econf32); 12328 } 12329 else 12330 { 12331 Elf64_External_Conflict * econf64; 12332 12333 econf64 = (Elf64_External_Conflict *) 12334 get_data (NULL, file, conflicts_offset, conflictsno, 12335 sizeof (* econf64), _("conflict")); 12336 if (!econf64) 12337 return 0; 12338 12339 for (cnt = 0; cnt < conflictsno; ++cnt) 12340 iconf[cnt] = BYTE_GET (econf64[cnt]); 12341 12342 free (econf64); 12343 } 12344 12345 printf (_("\nSection '.conflict' contains %lu entries:\n"), 12346 (unsigned long) conflictsno); 12347 puts (_(" Num: Index Value Name")); 12348 12349 for (cnt = 0; cnt < conflictsno; ++cnt) 12350 { 12351 Elf_Internal_Sym * psym = & dynamic_symbols[iconf[cnt]]; 12352 12353 printf ("%5lu: %8lu ", (unsigned long) cnt, iconf[cnt]); 12354 print_vma (psym->st_value, FULL_HEX); 12355 putchar (' '); 12356 if (VALID_DYNAMIC_NAME (psym->st_name)) 12357 print_symbol (25, GET_DYNAMIC_NAME (psym->st_name)); 12358 else 12359 printf (_("<corrupt: %14ld>"), psym->st_name); 12360 putchar ('\n'); 12361 } 12362 12363 free (iconf); 12364 } 12365 12366 if (pltgot != 0 && local_gotno != 0) 12367 { 12368 bfd_vma ent, local_end, global_end; 12369 size_t i, offset; 12370 unsigned char * data; 12371 int addr_size; 12372 12373 ent = pltgot; 12374 addr_size = (is_32bit_elf ? 4 : 8); 12375 local_end = pltgot + local_gotno * addr_size; 12376 global_end = local_end + (symtabno - gotsym) * addr_size; 12377 12378 offset = offset_from_vma (file, pltgot, global_end - pltgot); 12379 data = (unsigned char *) get_data (NULL, file, offset, 12380 global_end - pltgot, 1, 12381 _("Global Offset Table data")); 12382 if (data == NULL) 12383 return 0; 12384 12385 printf (_("\nPrimary GOT:\n")); 12386 printf (_(" Canonical gp value: ")); 12387 print_vma (pltgot + 0x7ff0, LONG_HEX); 12388 printf ("\n\n"); 12389 12390 printf (_(" Reserved entries:\n")); 12391 printf (_(" %*s %10s %*s Purpose\n"), 12392 addr_size * 2, _("Address"), _("Access"), 12393 addr_size * 2, _("Initial")); 12394 ent = print_mips_got_entry (data, pltgot, ent); 12395 printf (_(" Lazy resolver\n")); 12396 if (data 12397 && (byte_get (data + ent - pltgot, addr_size) 12398 >> (addr_size * 8 - 1)) != 0) 12399 { 12400 ent = print_mips_got_entry (data, pltgot, ent); 12401 printf (_(" Module pointer (GNU extension)\n")); 12402 } 12403 printf ("\n"); 12404 12405 if (ent < local_end) 12406 { 12407 printf (_(" Local entries:\n")); 12408 printf (" %*s %10s %*s\n", 12409 addr_size * 2, _("Address"), _("Access"), 12410 addr_size * 2, _("Initial")); 12411 while (ent < local_end) 12412 { 12413 ent = print_mips_got_entry (data, pltgot, ent); 12414 printf ("\n"); 12415 } 12416 printf ("\n"); 12417 } 12418 12419 if (gotsym < symtabno) 12420 { 12421 int sym_width; 12422 12423 printf (_(" Global entries:\n")); 12424 printf (" %*s %10s %*s %*s %-7s %3s %s\n", 12425 addr_size * 2, _("Address"), 12426 _("Access"), 12427 addr_size * 2, _("Initial"), 12428 addr_size * 2, _("Sym.Val."), 12429 _("Type"), 12430 /* Note for translators: "Ndx" = abbreviated form of "Index". */ 12431 _("Ndx"), _("Name")); 12432 12433 sym_width = (is_32bit_elf ? 80 : 160) - 28 - addr_size * 6 - 1; 12434 for (i = gotsym; i < symtabno; i++) 12435 { 12436 Elf_Internal_Sym * psym; 12437 12438 psym = dynamic_symbols + i; 12439 ent = print_mips_got_entry (data, pltgot, ent); 12440 printf (" "); 12441 print_vma (psym->st_value, LONG_HEX); 12442 printf (" %-7s %3s ", 12443 get_symbol_type (ELF_ST_TYPE (psym->st_info)), 12444 get_symbol_index_type (psym->st_shndx)); 12445 if (VALID_DYNAMIC_NAME (psym->st_name)) 12446 print_symbol (sym_width, GET_DYNAMIC_NAME (psym->st_name)); 12447 else 12448 printf (_("<corrupt: %14ld>"), psym->st_name); 12449 printf ("\n"); 12450 } 12451 printf ("\n"); 12452 } 12453 12454 if (data) 12455 free (data); 12456 } 12457 12458 if (mips_pltgot != 0 && jmprel != 0 && pltrel != 0 && pltrelsz != 0) 12459 { 12460 bfd_vma ent, end; 12461 size_t offset, rel_offset; 12462 unsigned long count, i; 12463 unsigned char * data; 12464 int addr_size, sym_width; 12465 Elf_Internal_Rela * rels; 12466 12467 rel_offset = offset_from_vma (file, jmprel, pltrelsz); 12468 if (pltrel == DT_RELA) 12469 { 12470 if (!slurp_rela_relocs (file, rel_offset, pltrelsz, &rels, &count)) 12471 return 0; 12472 } 12473 else 12474 { 12475 if (!slurp_rel_relocs (file, rel_offset, pltrelsz, &rels, &count)) 12476 return 0; 12477 } 12478 12479 ent = mips_pltgot; 12480 addr_size = (is_32bit_elf ? 4 : 8); 12481 end = mips_pltgot + (2 + count) * addr_size; 12482 12483 offset = offset_from_vma (file, mips_pltgot, end - mips_pltgot); 12484 data = (unsigned char *) get_data (NULL, file, offset, end - mips_pltgot, 12485 1, _("Procedure Linkage Table data")); 12486 if (data == NULL) 12487 return 0; 12488 12489 printf ("\nPLT GOT:\n\n"); 12490 printf (_(" Reserved entries:\n")); 12491 printf (_(" %*s %*s Purpose\n"), 12492 addr_size * 2, _("Address"), addr_size * 2, _("Initial")); 12493 ent = print_mips_pltgot_entry (data, mips_pltgot, ent); 12494 printf (_(" PLT lazy resolver\n")); 12495 ent = print_mips_pltgot_entry (data, mips_pltgot, ent); 12496 printf (_(" Module pointer\n")); 12497 printf ("\n"); 12498 12499 printf (_(" Entries:\n")); 12500 printf (" %*s %*s %*s %-7s %3s %s\n", 12501 addr_size * 2, _("Address"), 12502 addr_size * 2, _("Initial"), 12503 addr_size * 2, _("Sym.Val."), _("Type"), _("Ndx"), _("Name")); 12504 sym_width = (is_32bit_elf ? 80 : 160) - 17 - addr_size * 6 - 1; 12505 for (i = 0; i < count; i++) 12506 { 12507 Elf_Internal_Sym * psym; 12508 12509 psym = dynamic_symbols + get_reloc_symindex (rels[i].r_info); 12510 ent = print_mips_pltgot_entry (data, mips_pltgot, ent); 12511 printf (" "); 12512 print_vma (psym->st_value, LONG_HEX); 12513 printf (" %-7s %3s ", 12514 get_symbol_type (ELF_ST_TYPE (psym->st_info)), 12515 get_symbol_index_type (psym->st_shndx)); 12516 if (VALID_DYNAMIC_NAME (psym->st_name)) 12517 print_symbol (sym_width, GET_DYNAMIC_NAME (psym->st_name)); 12518 else 12519 printf (_("<corrupt: %14ld>"), psym->st_name); 12520 printf ("\n"); 12521 } 12522 printf ("\n"); 12523 12524 if (data) 12525 free (data); 12526 free (rels); 12527 } 12528 12529 return 1; 12530 } 12531 12532 static int 12533 process_gnu_liblist (FILE * file) 12534 { 12535 Elf_Internal_Shdr * section; 12536 Elf_Internal_Shdr * string_sec; 12537 Elf32_External_Lib * elib; 12538 char * strtab; 12539 size_t strtab_size; 12540 size_t cnt; 12541 unsigned i; 12542 12543 if (! do_arch) 12544 return 0; 12545 12546 for (i = 0, section = section_headers; 12547 i < elf_header.e_shnum; 12548 i++, section++) 12549 { 12550 switch (section->sh_type) 12551 { 12552 case SHT_GNU_LIBLIST: 12553 if (section->sh_link >= elf_header.e_shnum) 12554 break; 12555 12556 elib = (Elf32_External_Lib *) 12557 get_data (NULL, file, section->sh_offset, 1, section->sh_size, 12558 _("liblist section data")); 12559 12560 if (elib == NULL) 12561 break; 12562 string_sec = section_headers + section->sh_link; 12563 12564 strtab = (char *) get_data (NULL, file, string_sec->sh_offset, 1, 12565 string_sec->sh_size, 12566 _("liblist string table")); 12567 if (strtab == NULL 12568 || section->sh_entsize != sizeof (Elf32_External_Lib)) 12569 { 12570 free (elib); 12571 free (strtab); 12572 break; 12573 } 12574 strtab_size = string_sec->sh_size; 12575 12576 printf (_("\nLibrary list section '%s' contains %lu entries:\n"), 12577 SECTION_NAME (section), 12578 (unsigned long) (section->sh_size / sizeof (Elf32_External_Lib))); 12579 12580 puts (_(" Library Time Stamp Checksum Version Flags")); 12581 12582 for (cnt = 0; cnt < section->sh_size / sizeof (Elf32_External_Lib); 12583 ++cnt) 12584 { 12585 Elf32_Lib liblist; 12586 time_t atime; 12587 char timebuf[20]; 12588 struct tm * tmp; 12589 12590 liblist.l_name = BYTE_GET (elib[cnt].l_name); 12591 atime = BYTE_GET (elib[cnt].l_time_stamp); 12592 liblist.l_checksum = BYTE_GET (elib[cnt].l_checksum); 12593 liblist.l_version = BYTE_GET (elib[cnt].l_version); 12594 liblist.l_flags = BYTE_GET (elib[cnt].l_flags); 12595 12596 tmp = gmtime (&atime); 12597 snprintf (timebuf, sizeof (timebuf), 12598 "%04u-%02u-%02uT%02u:%02u:%02u", 12599 tmp->tm_year + 1900, tmp->tm_mon + 1, tmp->tm_mday, 12600 tmp->tm_hour, tmp->tm_min, tmp->tm_sec); 12601 12602 printf ("%3lu: ", (unsigned long) cnt); 12603 if (do_wide) 12604 printf ("%-20s", liblist.l_name < strtab_size 12605 ? strtab + liblist.l_name : _("<corrupt>")); 12606 else 12607 printf ("%-20.20s", liblist.l_name < strtab_size 12608 ? strtab + liblist.l_name : _("<corrupt>")); 12609 printf (" %s %#010lx %-7ld %-7ld\n", timebuf, liblist.l_checksum, 12610 liblist.l_version, liblist.l_flags); 12611 } 12612 12613 free (elib); 12614 free (strtab); 12615 } 12616 } 12617 12618 return 1; 12619 } 12620 12621 static const char * 12622 get_note_type (unsigned e_type) 12623 { 12624 static char buff[64]; 12625 12626 if (elf_header.e_type == ET_CORE) 12627 switch (e_type) 12628 { 12629 case NT_AUXV: 12630 return _("NT_AUXV (auxiliary vector)"); 12631 case NT_PRSTATUS: 12632 return _("NT_PRSTATUS (prstatus structure)"); 12633 case NT_FPREGSET: 12634 return _("NT_FPREGSET (floating point registers)"); 12635 case NT_PRPSINFO: 12636 return _("NT_PRPSINFO (prpsinfo structure)"); 12637 case NT_TASKSTRUCT: 12638 return _("NT_TASKSTRUCT (task structure)"); 12639 case NT_PRXFPREG: 12640 return _("NT_PRXFPREG (user_xfpregs structure)"); 12641 case NT_PPC_VMX: 12642 return _("NT_PPC_VMX (ppc Altivec registers)"); 12643 case NT_PPC_VSX: 12644 return _("NT_PPC_VSX (ppc VSX registers)"); 12645 case NT_X86_XSTATE: 12646 return _("NT_X86_XSTATE (x86 XSAVE extended state)"); 12647 case NT_S390_HIGH_GPRS: 12648 return _("NT_S390_HIGH_GPRS (s390 upper register halves)"); 12649 case NT_S390_TIMER: 12650 return _("NT_S390_TIMER (s390 timer register)"); 12651 case NT_S390_TODCMP: 12652 return _("NT_S390_TODCMP (s390 TOD comparator register)"); 12653 case NT_S390_TODPREG: 12654 return _("NT_S390_TODPREG (s390 TOD programmable register)"); 12655 case NT_S390_CTRS: 12656 return _("NT_S390_CTRS (s390 control registers)"); 12657 case NT_S390_PREFIX: 12658 return _("NT_S390_PREFIX (s390 prefix register)"); 12659 case NT_ARM_VFP: 12660 return _("NT_ARM_VFP (arm VFP registers)"); 12661 case NT_PSTATUS: 12662 return _("NT_PSTATUS (pstatus structure)"); 12663 case NT_FPREGS: 12664 return _("NT_FPREGS (floating point registers)"); 12665 case NT_PSINFO: 12666 return _("NT_PSINFO (psinfo structure)"); 12667 case NT_LWPSTATUS: 12668 return _("NT_LWPSTATUS (lwpstatus_t structure)"); 12669 case NT_LWPSINFO: 12670 return _("NT_LWPSINFO (lwpsinfo_t structure)"); 12671 case NT_WIN32PSTATUS: 12672 return _("NT_WIN32PSTATUS (win32_pstatus structure)"); 12673 default: 12674 break; 12675 } 12676 else 12677 switch (e_type) 12678 { 12679 case NT_VERSION: 12680 return _("NT_VERSION (version)"); 12681 case NT_ARCH: 12682 return _("NT_ARCH (architecture)"); 12683 default: 12684 break; 12685 } 12686 12687 snprintf (buff, sizeof (buff), _("Unknown note type: (0x%08x)"), e_type); 12688 return buff; 12689 } 12690 12691 static const char * 12692 get_gnu_elf_note_type (unsigned e_type) 12693 { 12694 static char buff[64]; 12695 12696 switch (e_type) 12697 { 12698 case NT_GNU_ABI_TAG: 12699 return _("NT_GNU_ABI_TAG (ABI version tag)"); 12700 case NT_GNU_HWCAP: 12701 return _("NT_GNU_HWCAP (DSO-supplied software HWCAP info)"); 12702 case NT_GNU_BUILD_ID: 12703 return _("NT_GNU_BUILD_ID (unique build ID bitstring)"); 12704 case NT_GNU_GOLD_VERSION: 12705 return _("NT_GNU_GOLD_VERSION (gold version)"); 12706 default: 12707 break; 12708 } 12709 12710 snprintf (buff, sizeof (buff), _("Unknown note type: (0x%08x)"), e_type); 12711 return buff; 12712 } 12713 12714 static int 12715 process_netbsd_elf_note (Elf_Internal_Note * pnote) 12716 { 12717 unsigned int version; 12718 12719 switch (pnote->type) 12720 { 12721 case NT_NETBSD_IDENT: 12722 version = byte_get((unsigned char *)pnote->descdata, sizeof(version)); 12723 if ((version / 10000) % 100) 12724 printf (" NetBSD\t0x%08lx\tIDENT %u (%u.%u%s%c)\n", pnote->descsz, 12725 version, version / 100000000, (version / 1000000) % 100, 12726 (version / 10000) % 100 > 26 ? "Z" : "", 12727 'A' + (version / 10000) % 26); 12728 else 12729 printf (" NetBSD\t\t0x%08lx\tIDENT %u (%u.%u.%u)\n", pnote->descsz, 12730 version, version / 100000000, (version / 1000000) % 100, 12731 (version / 100) % 100); 12732 return 1; 12733 case NT_NETBSD_MARCH: 12734 printf (" NetBSD\t\t0x%08lx\tMARCH <%s>\n", pnote->descsz, 12735 pnote->descdata); 12736 return 1; 12737 case NT_NETBSD_PAX: 12738 version = byte_get((unsigned char *)pnote->descdata, sizeof(version)); 12739 printf (" NetBSD\t\t0x%08lx\tPaX <%s%s%s%s%s%s>\n", pnote->descsz, 12740 ((version & NT_NETBSD_PAX_MPROTECT) ? "+mprotect" : ""), 12741 ((version & NT_NETBSD_PAX_NOMPROTECT) ? "-mprotect" : ""), 12742 ((version & NT_NETBSD_PAX_GUARD) ? "+guard" : ""), 12743 ((version & NT_NETBSD_PAX_NOGUARD) ? "-guard" : ""), 12744 ((version & NT_NETBSD_PAX_ASLR) ? "+ASLR" : ""), 12745 ((version & NT_NETBSD_PAX_NOASLR) ? "-ASLR" : "")); 12746 return 1; 12747 default: 12748 break; 12749 } 12750 12751 printf (" NetBSD\t0x%08lx\tUnknown note type: (0x%08lx)\n", pnote->descsz, 12752 pnote->type); 12753 return 1; 12754 } 12755 12756 static int 12757 print_gnu_note (Elf_Internal_Note *pnote) 12758 { 12759 switch (pnote->type) 12760 { 12761 case NT_GNU_BUILD_ID: 12762 { 12763 unsigned long i; 12764 12765 printf (_(" Build ID: ")); 12766 for (i = 0; i < pnote->descsz; ++i) 12767 printf ("%02x", pnote->descdata[i] & 0xff); 12768 printf ("\n"); 12769 } 12770 break; 12771 12772 case NT_GNU_ABI_TAG: 12773 { 12774 unsigned long os, major, minor, subminor; 12775 const char *osname; 12776 12777 os = byte_get ((unsigned char *) pnote->descdata, 4); 12778 major = byte_get ((unsigned char *) pnote->descdata + 4, 4); 12779 minor = byte_get ((unsigned char *) pnote->descdata + 8, 4); 12780 subminor = byte_get ((unsigned char *) pnote->descdata + 12, 4); 12781 12782 switch (os) 12783 { 12784 case GNU_ABI_TAG_LINUX: 12785 osname = "Linux"; 12786 break; 12787 case GNU_ABI_TAG_HURD: 12788 osname = "Hurd"; 12789 break; 12790 case GNU_ABI_TAG_SOLARIS: 12791 osname = "Solaris"; 12792 break; 12793 case GNU_ABI_TAG_FREEBSD: 12794 osname = "FreeBSD"; 12795 break; 12796 case GNU_ABI_TAG_NETBSD: 12797 osname = "NetBSD"; 12798 break; 12799 default: 12800 osname = "Unknown"; 12801 break; 12802 } 12803 12804 printf (_(" OS: %s, ABI: %ld.%ld.%ld\n"), osname, 12805 major, minor, subminor); 12806 } 12807 break; 12808 } 12809 12810 return 1; 12811 } 12812 12813 static const char * 12814 get_netbsd_elfcore_note_type (unsigned e_type) 12815 { 12816 static char buff[64]; 12817 12818 if (e_type == NT_NETBSDCORE_PROCINFO) 12819 { 12820 /* NetBSD core "procinfo" structure. */ 12821 return _("NetBSD procinfo structure"); 12822 } 12823 12824 /* As of Jan 2002 there are no other machine-independent notes 12825 defined for NetBSD core files. If the note type is less 12826 than the start of the machine-dependent note types, we don't 12827 understand it. */ 12828 12829 if (e_type < NT_NETBSDCORE_FIRSTMACH) 12830 { 12831 snprintf (buff, sizeof (buff), _("Unknown note type: (0x%08x)"), e_type); 12832 return buff; 12833 } 12834 12835 switch (elf_header.e_machine) 12836 { 12837 /* On the Alpha, SPARC (32-bit and 64-bit), PT_GETREGS == mach+0 12838 and PT_GETFPREGS == mach+2. */ 12839 12840 case EM_OLD_ALPHA: 12841 case EM_ALPHA: 12842 case EM_SPARC: 12843 case EM_SPARC32PLUS: 12844 case EM_SPARCV9: 12845 switch (e_type) 12846 { 12847 case NT_NETBSDCORE_FIRSTMACH + 0: 12848 return _("PT_GETREGS (reg structure)"); 12849 case NT_NETBSDCORE_FIRSTMACH + 2: 12850 return _("PT_GETFPREGS (fpreg structure)"); 12851 default: 12852 break; 12853 } 12854 break; 12855 12856 /* On SuperH, PT_GETREGS == mach+3 and PT_GETFPREGS == mach+5. 12857 There's also old PT___GETREGS40 == mach + 1 for old reg 12858 structure which lacks GBR. */ 12859 case EM_SH: 12860 switch (e_type) 12861 { 12862 case NT_NETBSDCORE_FIRSTMACH + 1: 12863 return _("PT___GETREGS40 (old reg structure)"); 12864 case NT_NETBSDCORE_FIRSTMACH + 3: 12865 return _("PT_GETREGS (reg structure)"); 12866 case NT_NETBSDCORE_FIRSTMACH + 5: 12867 return _("PT_GETFPREGS (fpreg structure)"); 12868 default: 12869 break; 12870 } 12871 break; 12872 12873 /* On all other arch's, PT_GETREGS == mach+1 and 12874 PT_GETFPREGS == mach+3. */ 12875 default: 12876 switch (e_type) 12877 { 12878 case NT_NETBSDCORE_FIRSTMACH + 1: 12879 return _("PT_GETREGS (reg structure)"); 12880 case NT_NETBSDCORE_FIRSTMACH + 3: 12881 return _("PT_GETFPREGS (fpreg structure)"); 12882 default: 12883 break; 12884 } 12885 } 12886 12887 snprintf (buff, sizeof (buff), "PT_FIRSTMACH+%d", 12888 e_type - NT_NETBSDCORE_FIRSTMACH); 12889 return buff; 12890 } 12891 12892 static const char * 12893 get_stapsdt_note_type (unsigned e_type) 12894 { 12895 static char buff[64]; 12896 12897 switch (e_type) 12898 { 12899 case NT_STAPSDT: 12900 return _("NT_STAPSDT (SystemTap probe descriptors)"); 12901 12902 default: 12903 break; 12904 } 12905 12906 snprintf (buff, sizeof (buff), _("Unknown note type: (0x%08x)"), e_type); 12907 return buff; 12908 } 12909 12910 static int 12911 print_stapsdt_note (Elf_Internal_Note *pnote) 12912 { 12913 int addr_size = is_32bit_elf ? 4 : 8; 12914 char *data = pnote->descdata; 12915 char *data_end = pnote->descdata + pnote->descsz; 12916 bfd_vma pc, base_addr, semaphore; 12917 char *provider, *probe, *arg_fmt; 12918 12919 pc = byte_get ((unsigned char *) data, addr_size); 12920 data += addr_size; 12921 base_addr = byte_get ((unsigned char *) data, addr_size); 12922 data += addr_size; 12923 semaphore = byte_get ((unsigned char *) data, addr_size); 12924 data += addr_size; 12925 12926 provider = data; 12927 data += strlen (data) + 1; 12928 probe = data; 12929 data += strlen (data) + 1; 12930 arg_fmt = data; 12931 data += strlen (data) + 1; 12932 12933 printf (_(" Provider: %s\n"), provider); 12934 printf (_(" Name: %s\n"), probe); 12935 printf (_(" Location: ")); 12936 print_vma (pc, FULL_HEX); 12937 printf (_(", Base: ")); 12938 print_vma (base_addr, FULL_HEX); 12939 printf (_(", Semaphore: ")); 12940 print_vma (semaphore, FULL_HEX); 12941 printf ("\n"); 12942 printf (_(" Arguments: %s\n"), arg_fmt); 12943 12944 return data == data_end; 12945 } 12946 12947 static const char * 12948 get_ia64_vms_note_type (unsigned e_type) 12949 { 12950 static char buff[64]; 12951 12952 switch (e_type) 12953 { 12954 case NT_VMS_MHD: 12955 return _("NT_VMS_MHD (module header)"); 12956 case NT_VMS_LNM: 12957 return _("NT_VMS_LNM (language name)"); 12958 case NT_VMS_SRC: 12959 return _("NT_VMS_SRC (source files)"); 12960 case NT_VMS_TITLE: 12961 return "NT_VMS_TITLE"; 12962 case NT_VMS_EIDC: 12963 return _("NT_VMS_EIDC (consistency check)"); 12964 case NT_VMS_FPMODE: 12965 return _("NT_VMS_FPMODE (FP mode)"); 12966 case NT_VMS_LINKTIME: 12967 return "NT_VMS_LINKTIME"; 12968 case NT_VMS_IMGNAM: 12969 return _("NT_VMS_IMGNAM (image name)"); 12970 case NT_VMS_IMGID: 12971 return _("NT_VMS_IMGID (image id)"); 12972 case NT_VMS_LINKID: 12973 return _("NT_VMS_LINKID (link id)"); 12974 case NT_VMS_IMGBID: 12975 return _("NT_VMS_IMGBID (build id)"); 12976 case NT_VMS_GSTNAM: 12977 return _("NT_VMS_GSTNAM (sym table name)"); 12978 case NT_VMS_ORIG_DYN: 12979 return "NT_VMS_ORIG_DYN"; 12980 case NT_VMS_PATCHTIME: 12981 return "NT_VMS_PATCHTIME"; 12982 default: 12983 snprintf (buff, sizeof (buff), _("Unknown note type: (0x%08x)"), e_type); 12984 return buff; 12985 } 12986 } 12987 12988 static int 12989 print_ia64_vms_note (Elf_Internal_Note * pnote) 12990 { 12991 switch (pnote->type) 12992 { 12993 case NT_VMS_MHD: 12994 if (pnote->descsz > 36) 12995 { 12996 size_t l = strlen (pnote->descdata + 34); 12997 printf (_(" Creation date : %.17s\n"), pnote->descdata); 12998 printf (_(" Last patch date: %.17s\n"), pnote->descdata + 17); 12999 printf (_(" Module name : %s\n"), pnote->descdata + 34); 13000 printf (_(" Module version : %s\n"), pnote->descdata + 34 + l + 1); 13001 } 13002 else 13003 printf (_(" Invalid size\n")); 13004 break; 13005 case NT_VMS_LNM: 13006 printf (_(" Language: %s\n"), pnote->descdata); 13007 break; 13008 #ifdef BFD64 13009 case NT_VMS_FPMODE: 13010 printf (_(" Floating Point mode: ")); 13011 printf ("0x%016" BFD_VMA_FMT "x\n", 13012 (bfd_vma)byte_get ((unsigned char *)pnote->descdata, 8)); 13013 break; 13014 case NT_VMS_LINKTIME: 13015 printf (_(" Link time: ")); 13016 print_vms_time 13017 ((bfd_int64_t) byte_get ((unsigned char *)pnote->descdata, 8)); 13018 printf ("\n"); 13019 break; 13020 case NT_VMS_PATCHTIME: 13021 printf (_(" Patch time: ")); 13022 print_vms_time 13023 ((bfd_int64_t) byte_get ((unsigned char *)pnote->descdata, 8)); 13024 printf ("\n"); 13025 break; 13026 case NT_VMS_ORIG_DYN: 13027 printf (_(" Major id: %u, minor id: %u\n"), 13028 (unsigned) byte_get ((unsigned char *)pnote->descdata, 4), 13029 (unsigned) byte_get ((unsigned char *)pnote->descdata + 4, 4)); 13030 printf (_(" Last modified : ")); 13031 print_vms_time 13032 ((bfd_int64_t) byte_get ((unsigned char *)pnote->descdata + 8, 8)); 13033 printf (_("\n Link flags : ")); 13034 printf ("0x%016" BFD_VMA_FMT "x\n", 13035 (bfd_vma)byte_get ((unsigned char *)pnote->descdata + 16, 8)); 13036 printf (_(" Header flags: 0x%08x\n"), 13037 (unsigned)byte_get ((unsigned char *)pnote->descdata + 24, 4)); 13038 printf (_(" Image id : %s\n"), pnote->descdata + 32); 13039 break; 13040 #endif 13041 case NT_VMS_IMGNAM: 13042 printf (_(" Image name: %s\n"), pnote->descdata); 13043 break; 13044 case NT_VMS_GSTNAM: 13045 printf (_(" Global symbol table name: %s\n"), pnote->descdata); 13046 break; 13047 case NT_VMS_IMGID: 13048 printf (_(" Image id: %s\n"), pnote->descdata); 13049 break; 13050 case NT_VMS_LINKID: 13051 printf (_(" Linker id: %s\n"), pnote->descdata); 13052 break; 13053 default: 13054 break; 13055 } 13056 return 1; 13057 } 13058 13059 /* Note that by the ELF standard, the name field is already null byte 13060 terminated, and namesz includes the terminating null byte. 13061 I.E. the value of namesz for the name "FSF" is 4. 13062 13063 If the value of namesz is zero, there is no name present. */ 13064 static int 13065 process_note (Elf_Internal_Note * pnote) 13066 { 13067 const char * name = pnote->namesz ? pnote->namedata : "(NONE)"; 13068 const char * nt; 13069 13070 if (pnote->namesz == 0) 13071 /* If there is no note name, then use the default set of 13072 note type strings. */ 13073 nt = get_note_type (pnote->type); 13074 13075 else if (const_strneq (pnote->namedata, "GNU")) 13076 /* GNU-specific object file notes. */ 13077 nt = get_gnu_elf_note_type (pnote->type); 13078 13079 else if (const_strneq (pnote->namedata, "NetBSD")) 13080 /* NetBSD-specific core file notes. */ 13081 return process_netbsd_elf_note (pnote); 13082 13083 else if (const_strneq (pnote->namedata, "PaX")) 13084 /* NetBSD-specific core file notes. */ 13085 return process_netbsd_elf_note (pnote); 13086 13087 else if (const_strneq (pnote->namedata, "NetBSD-CORE")) 13088 /* NetBSD-specific core file notes. */ 13089 nt = get_netbsd_elfcore_note_type (pnote->type); 13090 13091 else if (strneq (pnote->namedata, "SPU/", 4)) 13092 { 13093 /* SPU-specific core file notes. */ 13094 nt = pnote->namedata + 4; 13095 name = "SPU"; 13096 } 13097 13098 else if (const_strneq (pnote->namedata, "IPF/VMS")) 13099 /* VMS/ia64-specific file notes. */ 13100 nt = get_ia64_vms_note_type (pnote->type); 13101 13102 else if (const_strneq (pnote->namedata, "stapsdt")) 13103 nt = get_stapsdt_note_type (pnote->type); 13104 13105 else 13106 /* Don't recognize this note name; just use the default set of 13107 note type strings. */ 13108 nt = get_note_type (pnote->type); 13109 13110 printf (" %-20s 0x%08lx\t%s\n", name, pnote->descsz, nt); 13111 13112 if (const_strneq (pnote->namedata, "IPF/VMS")) 13113 return print_ia64_vms_note (pnote); 13114 else if (const_strneq (pnote->namedata, "GNU")) 13115 return print_gnu_note (pnote); 13116 else if (const_strneq (pnote->namedata, "stapsdt")) 13117 return print_stapsdt_note (pnote); 13118 else 13119 return 1; 13120 } 13121 13122 13123 static int 13124 process_corefile_note_segment (FILE * file, bfd_vma offset, bfd_vma length) 13125 { 13126 Elf_External_Note * pnotes; 13127 Elf_External_Note * external; 13128 int res = 1; 13129 13130 if (length <= 0) 13131 return 0; 13132 13133 pnotes = (Elf_External_Note *) get_data (NULL, file, offset, 1, length, 13134 _("notes")); 13135 if (pnotes == NULL) 13136 return 0; 13137 13138 external = pnotes; 13139 13140 printf (_("\nNotes at offset 0x%08lx with length 0x%08lx:\n"), 13141 (unsigned long) offset, (unsigned long) length); 13142 printf (_(" %-20s %10s\tDescription\n"), _("Owner"), _("Data size")); 13143 13144 while (external < (Elf_External_Note *) ((char *) pnotes + length)) 13145 { 13146 Elf_External_Note * next; 13147 Elf_Internal_Note inote; 13148 char * temp = NULL; 13149 13150 if (!is_ia64_vms ()) 13151 { 13152 inote.type = BYTE_GET (external->type); 13153 inote.namesz = BYTE_GET (external->namesz); 13154 inote.namedata = external->name; 13155 inote.descsz = BYTE_GET (external->descsz); 13156 inote.descdata = inote.namedata + align_power (inote.namesz, 2); 13157 inote.descpos = offset + (inote.descdata - (char *) pnotes); 13158 13159 next = (Elf_External_Note *) (inote.descdata + align_power (inote.descsz, 2)); 13160 } 13161 else 13162 { 13163 Elf64_External_VMS_Note *vms_external; 13164 13165 vms_external = (Elf64_External_VMS_Note *)external; 13166 inote.type = BYTE_GET (vms_external->type); 13167 inote.namesz = BYTE_GET (vms_external->namesz); 13168 inote.namedata = vms_external->name; 13169 inote.descsz = BYTE_GET (vms_external->descsz); 13170 inote.descdata = inote.namedata + align_power (inote.namesz, 3); 13171 inote.descpos = offset + (inote.descdata - (char *) pnotes); 13172 13173 next = (Elf_External_Note *) 13174 (inote.descdata + align_power (inote.descsz, 3)); 13175 } 13176 13177 if ( ((char *) next > ((char *) pnotes) + length) 13178 || ((char *) next < (char *) pnotes)) 13179 { 13180 warn (_("corrupt note found at offset %lx into core notes\n"), 13181 (unsigned long) ((char *) external - (char *) pnotes)); 13182 warn (_(" type: %lx, namesize: %08lx, descsize: %08lx\n"), 13183 inote.type, inote.namesz, inote.descsz); 13184 break; 13185 } 13186 13187 external = next; 13188 13189 /* Prevent out-of-bounds indexing. */ 13190 if (inote.namedata + inote.namesz > (char *) pnotes + length 13191 || inote.namedata + inote.namesz < inote.namedata) 13192 { 13193 warn (_("corrupt note found at offset %lx into core notes\n"), 13194 (unsigned long) ((char *) external - (char *) pnotes)); 13195 warn (_(" type: %lx, namesize: %08lx, descsize: %08lx\n"), 13196 inote.type, inote.namesz, inote.descsz); 13197 break; 13198 } 13199 13200 /* Verify that name is null terminated. It appears that at least 13201 one version of Linux (RedHat 6.0) generates corefiles that don't 13202 comply with the ELF spec by failing to include the null byte in 13203 namesz. */ 13204 if (inote.namedata[inote.namesz - 1] != '\0') 13205 { 13206 temp = (char *) malloc (inote.namesz + 1); 13207 13208 if (temp == NULL) 13209 { 13210 error (_("Out of memory\n")); 13211 res = 0; 13212 break; 13213 } 13214 13215 strncpy (temp, inote.namedata, inote.namesz); 13216 temp[inote.namesz] = 0; 13217 13218 /* warn (_("'%s' NOTE name not properly null terminated\n"), temp); */ 13219 inote.namedata = temp; 13220 } 13221 13222 res &= process_note (& inote); 13223 13224 if (temp != NULL) 13225 { 13226 free (temp); 13227 temp = NULL; 13228 } 13229 } 13230 13231 free (pnotes); 13232 13233 return res; 13234 } 13235 13236 static int 13237 process_corefile_note_segments (FILE * file) 13238 { 13239 Elf_Internal_Phdr * segment; 13240 unsigned int i; 13241 int res = 1; 13242 13243 if (! get_program_headers (file)) 13244 return 0; 13245 13246 for (i = 0, segment = program_headers; 13247 i < elf_header.e_phnum; 13248 i++, segment++) 13249 { 13250 if (segment->p_type == PT_NOTE) 13251 res &= process_corefile_note_segment (file, 13252 (bfd_vma) segment->p_offset, 13253 (bfd_vma) segment->p_filesz); 13254 } 13255 13256 return res; 13257 } 13258 13259 static int 13260 process_note_sections (FILE * file) 13261 { 13262 Elf_Internal_Shdr * section; 13263 unsigned long i; 13264 int res = 1; 13265 13266 for (i = 0, section = section_headers; 13267 i < elf_header.e_shnum && section != NULL; 13268 i++, section++) 13269 if (section->sh_type == SHT_NOTE) 13270 res &= process_corefile_note_segment (file, 13271 (bfd_vma) section->sh_offset, 13272 (bfd_vma) section->sh_size); 13273 13274 return res; 13275 } 13276 13277 static int 13278 process_notes (FILE * file) 13279 { 13280 /* If we have not been asked to display the notes then do nothing. */ 13281 if (! do_notes) 13282 return 1; 13283 13284 if (elf_header.e_type != ET_CORE) 13285 return process_note_sections (file); 13286 13287 /* No program headers means no NOTE segment. */ 13288 if (elf_header.e_phnum > 0) 13289 return process_corefile_note_segments (file); 13290 13291 printf (_("No note segments present in the core file.\n")); 13292 return 1; 13293 } 13294 13295 static int 13296 process_arch_specific (FILE * file) 13297 { 13298 if (! do_arch) 13299 return 1; 13300 13301 switch (elf_header.e_machine) 13302 { 13303 case EM_ARM: 13304 return process_arm_specific (file); 13305 case EM_MIPS: 13306 case EM_MIPS_RS3_LE: 13307 return process_mips_specific (file); 13308 break; 13309 case EM_PPC: 13310 return process_power_specific (file); 13311 break; 13312 case EM_SPARC: 13313 case EM_SPARC32PLUS: 13314 case EM_SPARCV9: 13315 return process_sparc_specific (file); 13316 break; 13317 case EM_TI_C6000: 13318 return process_tic6x_specific (file); 13319 break; 13320 default: 13321 break; 13322 } 13323 return 1; 13324 } 13325 13326 static int 13327 get_file_header (FILE * file) 13328 { 13329 /* Read in the identity array. */ 13330 if (fread (elf_header.e_ident, EI_NIDENT, 1, file) != 1) 13331 return 0; 13332 13333 /* Determine how to read the rest of the header. */ 13334 switch (elf_header.e_ident[EI_DATA]) 13335 { 13336 default: /* fall through */ 13337 case ELFDATANONE: /* fall through */ 13338 case ELFDATA2LSB: 13339 byte_get = byte_get_little_endian; 13340 byte_put = byte_put_little_endian; 13341 break; 13342 case ELFDATA2MSB: 13343 byte_get = byte_get_big_endian; 13344 byte_put = byte_put_big_endian; 13345 break; 13346 } 13347 13348 /* For now we only support 32 bit and 64 bit ELF files. */ 13349 is_32bit_elf = (elf_header.e_ident[EI_CLASS] != ELFCLASS64); 13350 13351 /* Read in the rest of the header. */ 13352 if (is_32bit_elf) 13353 { 13354 Elf32_External_Ehdr ehdr32; 13355 13356 if (fread (ehdr32.e_type, sizeof (ehdr32) - EI_NIDENT, 1, file) != 1) 13357 return 0; 13358 13359 elf_header.e_type = BYTE_GET (ehdr32.e_type); 13360 elf_header.e_machine = BYTE_GET (ehdr32.e_machine); 13361 elf_header.e_version = BYTE_GET (ehdr32.e_version); 13362 elf_header.e_entry = BYTE_GET (ehdr32.e_entry); 13363 elf_header.e_phoff = BYTE_GET (ehdr32.e_phoff); 13364 elf_header.e_shoff = BYTE_GET (ehdr32.e_shoff); 13365 elf_header.e_flags = BYTE_GET (ehdr32.e_flags); 13366 elf_header.e_ehsize = BYTE_GET (ehdr32.e_ehsize); 13367 elf_header.e_phentsize = BYTE_GET (ehdr32.e_phentsize); 13368 elf_header.e_phnum = BYTE_GET (ehdr32.e_phnum); 13369 elf_header.e_shentsize = BYTE_GET (ehdr32.e_shentsize); 13370 elf_header.e_shnum = BYTE_GET (ehdr32.e_shnum); 13371 elf_header.e_shstrndx = BYTE_GET (ehdr32.e_shstrndx); 13372 } 13373 else 13374 { 13375 Elf64_External_Ehdr ehdr64; 13376 13377 /* If we have been compiled with sizeof (bfd_vma) == 4, then 13378 we will not be able to cope with the 64bit data found in 13379 64 ELF files. Detect this now and abort before we start 13380 overwriting things. */ 13381 if (sizeof (bfd_vma) < 8) 13382 { 13383 error (_("This instance of readelf has been built without support for a\n\ 13384 64 bit data type and so it cannot read 64 bit ELF files.\n")); 13385 return 0; 13386 } 13387 13388 if (fread (ehdr64.e_type, sizeof (ehdr64) - EI_NIDENT, 1, file) != 1) 13389 return 0; 13390 13391 elf_header.e_type = BYTE_GET (ehdr64.e_type); 13392 elf_header.e_machine = BYTE_GET (ehdr64.e_machine); 13393 elf_header.e_version = BYTE_GET (ehdr64.e_version); 13394 elf_header.e_entry = BYTE_GET (ehdr64.e_entry); 13395 elf_header.e_phoff = BYTE_GET (ehdr64.e_phoff); 13396 elf_header.e_shoff = BYTE_GET (ehdr64.e_shoff); 13397 elf_header.e_flags = BYTE_GET (ehdr64.e_flags); 13398 elf_header.e_ehsize = BYTE_GET (ehdr64.e_ehsize); 13399 elf_header.e_phentsize = BYTE_GET (ehdr64.e_phentsize); 13400 elf_header.e_phnum = BYTE_GET (ehdr64.e_phnum); 13401 elf_header.e_shentsize = BYTE_GET (ehdr64.e_shentsize); 13402 elf_header.e_shnum = BYTE_GET (ehdr64.e_shnum); 13403 elf_header.e_shstrndx = BYTE_GET (ehdr64.e_shstrndx); 13404 } 13405 13406 if (elf_header.e_shoff) 13407 { 13408 /* There may be some extensions in the first section header. Don't 13409 bomb if we can't read it. */ 13410 if (is_32bit_elf) 13411 get_32bit_section_headers (file, 1); 13412 else 13413 get_64bit_section_headers (file, 1); 13414 } 13415 13416 return 1; 13417 } 13418 13419 /* Process one ELF object file according to the command line options. 13420 This file may actually be stored in an archive. The file is 13421 positioned at the start of the ELF object. */ 13422 13423 static int 13424 process_object (char * file_name, FILE * file) 13425 { 13426 unsigned int i; 13427 13428 if (! get_file_header (file)) 13429 { 13430 error (_("%s: Failed to read file header\n"), file_name); 13431 return 1; 13432 } 13433 13434 /* Initialise per file variables. */ 13435 for (i = ARRAY_SIZE (version_info); i--;) 13436 version_info[i] = 0; 13437 13438 for (i = ARRAY_SIZE (dynamic_info); i--;) 13439 dynamic_info[i] = 0; 13440 dynamic_info_DT_GNU_HASH = 0; 13441 13442 /* Process the file. */ 13443 if (show_name) 13444 printf (_("\nFile: %s\n"), file_name); 13445 13446 /* Initialise the dump_sects array from the cmdline_dump_sects array. 13447 Note we do this even if cmdline_dump_sects is empty because we 13448 must make sure that the dump_sets array is zeroed out before each 13449 object file is processed. */ 13450 if (num_dump_sects > num_cmdline_dump_sects) 13451 memset (dump_sects, 0, num_dump_sects * sizeof (* dump_sects)); 13452 13453 if (num_cmdline_dump_sects > 0) 13454 { 13455 if (num_dump_sects == 0) 13456 /* A sneaky way of allocating the dump_sects array. */ 13457 request_dump_bynumber (num_cmdline_dump_sects, 0); 13458 13459 assert (num_dump_sects >= num_cmdline_dump_sects); 13460 memcpy (dump_sects, cmdline_dump_sects, 13461 num_cmdline_dump_sects * sizeof (* dump_sects)); 13462 } 13463 13464 if (! process_file_header ()) 13465 return 1; 13466 13467 if (! process_section_headers (file)) 13468 { 13469 /* Without loaded section headers we cannot process lots of 13470 things. */ 13471 do_unwind = do_version = do_dump = do_arch = 0; 13472 13473 if (! do_using_dynamic) 13474 do_syms = do_dyn_syms = do_reloc = 0; 13475 } 13476 13477 if (! process_section_groups (file)) 13478 { 13479 /* Without loaded section groups we cannot process unwind. */ 13480 do_unwind = 0; 13481 } 13482 13483 if (process_program_headers (file)) 13484 process_dynamic_section (file); 13485 13486 process_relocs (file); 13487 13488 process_unwind (file); 13489 13490 process_symbol_table (file); 13491 13492 process_syminfo (file); 13493 13494 process_version_sections (file); 13495 13496 process_section_contents (file); 13497 13498 process_notes (file); 13499 13500 process_gnu_liblist (file); 13501 13502 process_arch_specific (file); 13503 13504 if (program_headers) 13505 { 13506 free (program_headers); 13507 program_headers = NULL; 13508 } 13509 13510 if (section_headers) 13511 { 13512 free (section_headers); 13513 section_headers = NULL; 13514 } 13515 13516 if (string_table) 13517 { 13518 free (string_table); 13519 string_table = NULL; 13520 string_table_length = 0; 13521 } 13522 13523 if (dynamic_strings) 13524 { 13525 free (dynamic_strings); 13526 dynamic_strings = NULL; 13527 dynamic_strings_length = 0; 13528 } 13529 13530 if (dynamic_symbols) 13531 { 13532 free (dynamic_symbols); 13533 dynamic_symbols = NULL; 13534 num_dynamic_syms = 0; 13535 } 13536 13537 if (dynamic_syminfo) 13538 { 13539 free (dynamic_syminfo); 13540 dynamic_syminfo = NULL; 13541 } 13542 13543 if (dynamic_section) 13544 { 13545 free (dynamic_section); 13546 dynamic_section = NULL; 13547 } 13548 13549 if (section_headers_groups) 13550 { 13551 free (section_headers_groups); 13552 section_headers_groups = NULL; 13553 } 13554 13555 if (section_groups) 13556 { 13557 struct group_list * g; 13558 struct group_list * next; 13559 13560 for (i = 0; i < group_count; i++) 13561 { 13562 for (g = section_groups [i].root; g != NULL; g = next) 13563 { 13564 next = g->next; 13565 free (g); 13566 } 13567 } 13568 13569 free (section_groups); 13570 section_groups = NULL; 13571 } 13572 13573 free_debug_memory (); 13574 13575 return 0; 13576 } 13577 13578 /* Process an ELF archive. 13579 On entry the file is positioned just after the ARMAG string. */ 13580 13581 static int 13582 process_archive (char * file_name, FILE * file, bfd_boolean is_thin_archive) 13583 { 13584 struct archive_info arch; 13585 struct archive_info nested_arch; 13586 size_t got; 13587 int ret; 13588 13589 show_name = 1; 13590 13591 /* The ARCH structure is used to hold information about this archive. */ 13592 arch.file_name = NULL; 13593 arch.file = NULL; 13594 arch.index_array = NULL; 13595 arch.sym_table = NULL; 13596 arch.longnames = NULL; 13597 13598 /* The NESTED_ARCH structure is used as a single-item cache of information 13599 about a nested archive (when members of a thin archive reside within 13600 another regular archive file). */ 13601 nested_arch.file_name = NULL; 13602 nested_arch.file = NULL; 13603 nested_arch.index_array = NULL; 13604 nested_arch.sym_table = NULL; 13605 nested_arch.longnames = NULL; 13606 13607 if (setup_archive (&arch, file_name, file, is_thin_archive, do_archive_index) != 0) 13608 { 13609 ret = 1; 13610 goto out; 13611 } 13612 13613 if (do_archive_index) 13614 { 13615 if (arch.sym_table == NULL) 13616 error (_("%s: unable to dump the index as none was found\n"), file_name); 13617 else 13618 { 13619 unsigned int i, l; 13620 unsigned long current_pos; 13621 13622 printf (_("Index of archive %s: (%ld entries, 0x%lx bytes in the symbol table)\n"), 13623 file_name, (long) arch.index_num, arch.sym_size); 13624 current_pos = ftell (file); 13625 13626 for (i = l = 0; i < arch.index_num; i++) 13627 { 13628 if ((i == 0) || ((i > 0) && (arch.index_array[i] != arch.index_array[i - 1]))) 13629 { 13630 char * member_name; 13631 13632 member_name = get_archive_member_name_at (&arch, arch.index_array[i], &nested_arch); 13633 13634 if (member_name != NULL) 13635 { 13636 char * qualified_name = make_qualified_name (&arch, &nested_arch, member_name); 13637 13638 if (qualified_name != NULL) 13639 { 13640 printf (_("Contents of binary %s at offset "), qualified_name); 13641 (void) print_vma (arch.index_array[i], PREFIX_HEX); 13642 putchar ('\n'); 13643 free (qualified_name); 13644 } 13645 } 13646 } 13647 13648 if (l >= arch.sym_size) 13649 { 13650 error (_("%s: end of the symbol table reached before the end of the index\n"), 13651 file_name); 13652 break; 13653 } 13654 printf ("\t%s\n", arch.sym_table + l); 13655 l += strlen (arch.sym_table + l) + 1; 13656 } 13657 13658 if (arch.uses_64bit_indicies) 13659 l = (l + 7) & ~ 7; 13660 else 13661 l += l & 1; 13662 13663 if (l < arch.sym_size) 13664 error (_("%s: %ld bytes remain in the symbol table, but without corresponding entries in the index table\n"), 13665 file_name, arch.sym_size - l); 13666 13667 if (fseek (file, current_pos, SEEK_SET) != 0) 13668 { 13669 error (_("%s: failed to seek back to start of object files in the archive\n"), file_name); 13670 ret = 1; 13671 goto out; 13672 } 13673 } 13674 13675 if (!do_dynamic && !do_syms && !do_reloc && !do_unwind && !do_sections 13676 && !do_segments && !do_header && !do_dump && !do_version 13677 && !do_histogram && !do_debugging && !do_arch && !do_notes 13678 && !do_section_groups && !do_dyn_syms) 13679 { 13680 ret = 0; /* Archive index only. */ 13681 goto out; 13682 } 13683 } 13684 13685 ret = 0; 13686 13687 while (1) 13688 { 13689 char * name; 13690 size_t namelen; 13691 char * qualified_name; 13692 13693 /* Read the next archive header. */ 13694 if (fseek (file, arch.next_arhdr_offset, SEEK_SET) != 0) 13695 { 13696 error (_("%s: failed to seek to next archive header\n"), file_name); 13697 return 1; 13698 } 13699 got = fread (&arch.arhdr, 1, sizeof arch.arhdr, file); 13700 if (got != sizeof arch.arhdr) 13701 { 13702 if (got == 0) 13703 break; 13704 error (_("%s: failed to read archive header\n"), file_name); 13705 ret = 1; 13706 break; 13707 } 13708 if (memcmp (arch.arhdr.ar_fmag, ARFMAG, 2) != 0) 13709 { 13710 error (_("%s: did not find a valid archive header\n"), arch.file_name); 13711 ret = 1; 13712 break; 13713 } 13714 13715 arch.next_arhdr_offset += sizeof arch.arhdr; 13716 13717 archive_file_size = strtoul (arch.arhdr.ar_size, NULL, 10); 13718 if (archive_file_size & 01) 13719 ++archive_file_size; 13720 13721 name = get_archive_member_name (&arch, &nested_arch); 13722 if (name == NULL) 13723 { 13724 error (_("%s: bad archive file name\n"), file_name); 13725 ret = 1; 13726 break; 13727 } 13728 namelen = strlen (name); 13729 13730 qualified_name = make_qualified_name (&arch, &nested_arch, name); 13731 if (qualified_name == NULL) 13732 { 13733 error (_("%s: bad archive file name\n"), file_name); 13734 ret = 1; 13735 break; 13736 } 13737 13738 if (is_thin_archive && arch.nested_member_origin == 0) 13739 { 13740 /* This is a proxy for an external member of a thin archive. */ 13741 FILE * member_file; 13742 char * member_file_name = adjust_relative_path (file_name, name, namelen); 13743 if (member_file_name == NULL) 13744 { 13745 ret = 1; 13746 break; 13747 } 13748 13749 member_file = fopen (member_file_name, "rb"); 13750 if (member_file == NULL) 13751 { 13752 error (_("Input file '%s' is not readable.\n"), member_file_name); 13753 free (member_file_name); 13754 ret = 1; 13755 break; 13756 } 13757 13758 archive_file_offset = arch.nested_member_origin; 13759 13760 ret |= process_object (qualified_name, member_file); 13761 13762 fclose (member_file); 13763 free (member_file_name); 13764 } 13765 else if (is_thin_archive) 13766 { 13767 /* This is a proxy for a member of a nested archive. */ 13768 archive_file_offset = arch.nested_member_origin + sizeof arch.arhdr; 13769 13770 /* The nested archive file will have been opened and setup by 13771 get_archive_member_name. */ 13772 if (fseek (nested_arch.file, archive_file_offset, SEEK_SET) != 0) 13773 { 13774 error (_("%s: failed to seek to archive member.\n"), nested_arch.file_name); 13775 ret = 1; 13776 break; 13777 } 13778 13779 ret |= process_object (qualified_name, nested_arch.file); 13780 } 13781 else 13782 { 13783 archive_file_offset = arch.next_arhdr_offset; 13784 arch.next_arhdr_offset += archive_file_size; 13785 13786 ret |= process_object (qualified_name, file); 13787 } 13788 13789 if (dump_sects != NULL) 13790 { 13791 free (dump_sects); 13792 dump_sects = NULL; 13793 num_dump_sects = 0; 13794 } 13795 13796 free (qualified_name); 13797 } 13798 13799 out: 13800 if (nested_arch.file != NULL) 13801 fclose (nested_arch.file); 13802 release_archive (&nested_arch); 13803 release_archive (&arch); 13804 13805 return ret; 13806 } 13807 13808 static int 13809 process_file (char * file_name) 13810 { 13811 FILE * file; 13812 struct stat statbuf; 13813 char armag[SARMAG]; 13814 int ret; 13815 13816 if (stat (file_name, &statbuf) < 0) 13817 { 13818 if (errno == ENOENT) 13819 error (_("'%s': No such file\n"), file_name); 13820 else 13821 error (_("Could not locate '%s'. System error message: %s\n"), 13822 file_name, strerror (errno)); 13823 return 1; 13824 } 13825 13826 if (!do_special_files && ! S_ISREG (statbuf.st_mode)) 13827 { 13828 error (_("'%s' is not an ordinary file\n"), file_name); 13829 return 1; 13830 } 13831 13832 file = fopen (file_name, "rb"); 13833 if (file == NULL) 13834 { 13835 error (_("Input file '%s' is not readable.\n"), file_name); 13836 return 1; 13837 } 13838 13839 if (fread (armag, SARMAG, 1, file) != 1) 13840 { 13841 error (_("%s: Failed to read file's magic number\n"), file_name); 13842 fclose (file); 13843 return 1; 13844 } 13845 13846 if (memcmp (armag, ARMAG, SARMAG) == 0) 13847 ret = process_archive (file_name, file, FALSE); 13848 else if (memcmp (armag, ARMAGT, SARMAG) == 0) 13849 ret = process_archive (file_name, file, TRUE); 13850 else 13851 { 13852 if (do_archive_index) 13853 error (_("File %s is not an archive so its index cannot be displayed.\n"), 13854 file_name); 13855 13856 rewind (file); 13857 archive_file_size = archive_file_offset = 0; 13858 ret = process_object (file_name, file); 13859 } 13860 13861 fclose (file); 13862 13863 return ret; 13864 } 13865 13866 #ifdef SUPPORT_DISASSEMBLY 13867 /* Needed by the i386 disassembler. For extra credit, someone could 13868 fix this so that we insert symbolic addresses here, esp for GOT/PLT 13869 symbols. */ 13870 13871 void 13872 print_address (unsigned int addr, FILE * outfile) 13873 { 13874 fprintf (outfile,"0x%8.8x", addr); 13875 } 13876 13877 /* Needed by the i386 disassembler. */ 13878 void 13879 db_task_printsym (unsigned int addr) 13880 { 13881 print_address (addr, stderr); 13882 } 13883 #endif 13884 13885 int 13886 main (int argc, char ** argv) 13887 { 13888 int err; 13889 13890 #if defined (HAVE_SETLOCALE) && defined (HAVE_LC_MESSAGES) 13891 setlocale (LC_MESSAGES, ""); 13892 #endif 13893 #if defined (HAVE_SETLOCALE) 13894 setlocale (LC_CTYPE, ""); 13895 #endif 13896 bindtextdomain (PACKAGE, LOCALEDIR); 13897 textdomain (PACKAGE); 13898 13899 expandargv (&argc, &argv); 13900 13901 parse_args (argc, argv); 13902 13903 if (num_dump_sects > 0) 13904 { 13905 /* Make a copy of the dump_sects array. */ 13906 cmdline_dump_sects = (dump_type *) 13907 malloc (num_dump_sects * sizeof (* dump_sects)); 13908 if (cmdline_dump_sects == NULL) 13909 error (_("Out of memory allocating dump request table.\n")); 13910 else 13911 { 13912 memcpy (cmdline_dump_sects, dump_sects, 13913 num_dump_sects * sizeof (* dump_sects)); 13914 num_cmdline_dump_sects = num_dump_sects; 13915 } 13916 } 13917 13918 if (optind < (argc - 1)) 13919 show_name = 1; 13920 13921 err = 0; 13922 while (optind < argc) 13923 err |= process_file (argv[optind++]); 13924 13925 if (dump_sects != NULL) 13926 free (dump_sects); 13927 if (cmdline_dump_sects != NULL) 13928 free (cmdline_dump_sects); 13929 13930 return err; 13931 } 13932