1 /* readelf.c -- display contents of an ELF format file 2 Copyright (C) 1998-2020 Free Software Foundation, Inc. 3 4 Originally developed by Eric Youngdale <eric@andante.jic.com> 5 Modifications by Nick Clifton <nickc@redhat.com> 6 7 This file is part of GNU Binutils. 8 9 This program is free software; you can redistribute it and/or modify 10 it under the terms of the GNU General Public License as published by 11 the Free Software Foundation; either version 3 of the License, or 12 (at your option) any later version. 13 14 This program is distributed in the hope that it will be useful, 15 but WITHOUT ANY WARRANTY; without even the implied warranty of 16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 17 GNU General Public License for more details. 18 19 You should have received a copy of the GNU General Public License 20 along with this program; if not, write to the Free Software 21 Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA 22 02110-1301, USA. */ 23 24 /* The difference between readelf and objdump: 25 26 Both programs are capable of displaying the contents of ELF format files, 27 so why does the binutils project have two file dumpers ? 28 29 The reason is that objdump sees an ELF file through a BFD filter of the 30 world; if BFD has a bug where, say, it disagrees about a machine constant 31 in e_flags, then the odds are good that it will remain internally 32 consistent. The linker sees it the BFD way, objdump sees it the BFD way, 33 GAS sees it the BFD way. There was need for a tool to go find out what 34 the file actually says. 35 36 This is why the readelf program does not link against the BFD library - it 37 exists as an independent program to help verify the correct working of BFD. 38 39 There is also the case that readelf can provide more information about an 40 ELF file than is provided by objdump. In particular it can display DWARF 41 debugging information which (at the moment) objdump cannot. */ 42 43 #include "sysdep.h" 44 #include <assert.h> 45 #include <time.h> 46 #include <zlib.h> 47 #ifdef HAVE_WCHAR_H 48 #include <wchar.h> 49 #endif 50 51 #if __GNUC__ >= 2 52 /* Define BFD64 here, even if our default architecture is 32 bit ELF 53 as this will allow us to read in and parse 64bit and 32bit ELF files. 54 Only do this if we believe that the compiler can support a 64 bit 55 data type. For now we only rely on GCC being able to do this. */ 56 #define BFD64 57 #endif 58 59 #include "bfd.h" 60 #include "bucomm.h" 61 #include "elfcomm.h" 62 #include "dwarf.h" 63 #include "ctf-api.h" 64 65 #include "elf/common.h" 66 #include "elf/external.h" 67 #include "elf/internal.h" 68 69 70 /* Included here, before RELOC_MACROS_GEN_FUNC is defined, so that 71 we can obtain the H8 reloc numbers. We need these for the 72 get_reloc_size() function. We include h8.h again after defining 73 RELOC_MACROS_GEN_FUNC so that we get the naming function as well. */ 74 75 #include "elf/h8.h" 76 #undef _ELF_H8_H 77 78 /* Undo the effects of #including reloc-macros.h. */ 79 80 #undef START_RELOC_NUMBERS 81 #undef RELOC_NUMBER 82 #undef FAKE_RELOC 83 #undef EMPTY_RELOC 84 #undef END_RELOC_NUMBERS 85 #undef _RELOC_MACROS_H 86 87 /* The following headers use the elf/reloc-macros.h file to 88 automatically generate relocation recognition functions 89 such as elf_mips_reloc_type() */ 90 91 #define RELOC_MACROS_GEN_FUNC 92 93 #include "elf/aarch64.h" 94 #include "elf/alpha.h" 95 #include "elf/arc.h" 96 #include "elf/arm.h" 97 #include "elf/avr.h" 98 #include "elf/bfin.h" 99 #include "elf/cr16.h" 100 #include "elf/cris.h" 101 #include "elf/crx.h" 102 #include "elf/csky.h" 103 #include "elf/d10v.h" 104 #include "elf/d30v.h" 105 #include "elf/dlx.h" 106 #include "elf/bpf.h" 107 #include "elf/epiphany.h" 108 #include "elf/fr30.h" 109 #include "elf/frv.h" 110 #include "elf/ft32.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/s12z.h" 126 #include "elf/mcore.h" 127 #include "elf/mep.h" 128 #include "elf/metag.h" 129 #include "elf/microblaze.h" 130 #include "elf/mips.h" 131 #include "elf/mmix.h" 132 #include "elf/mn10200.h" 133 #include "elf/mn10300.h" 134 #include "elf/moxie.h" 135 #include "elf/mt.h" 136 #include "elf/msp430.h" 137 #include "elf/nds32.h" 138 #include "elf/nfp.h" 139 #include "elf/nios2.h" 140 #include "elf/or1k.h" 141 #include "elf/pj.h" 142 #include "elf/ppc.h" 143 #include "elf/ppc64.h" 144 #include "elf/pru.h" 145 #include "elf/riscv.h" 146 #include "elf/rl78.h" 147 #include "elf/rx.h" 148 #include "elf/s390.h" 149 #include "elf/score.h" 150 #include "elf/sh.h" 151 #include "elf/sparc.h" 152 #include "elf/spu.h" 153 #include "elf/tic6x.h" 154 #include "elf/tilegx.h" 155 #include "elf/tilepro.h" 156 #include "elf/v850.h" 157 #include "elf/vax.h" 158 #include "elf/visium.h" 159 #include "elf/wasm32.h" 160 #include "elf/x86-64.h" 161 #include "elf/xc16x.h" 162 #include "elf/xgate.h" 163 #include "elf/xstormy16.h" 164 #include "elf/xtensa.h" 165 #include "elf/z80.h" 166 167 #include "getopt.h" 168 #include "libiberty.h" 169 #include "safe-ctype.h" 170 #include "filenames.h" 171 172 #ifndef offsetof 173 #define offsetof(TYPE, MEMBER) ((size_t) &(((TYPE *) 0)->MEMBER)) 174 #endif 175 176 typedef struct elf_section_list 177 { 178 Elf_Internal_Shdr * hdr; 179 struct elf_section_list * next; 180 } elf_section_list; 181 182 /* Flag bits indicating particular types of dump. */ 183 #define HEX_DUMP (1 << 0) /* The -x command line switch. */ 184 #define DISASS_DUMP (1 << 1) /* The -i command line switch. */ 185 #define DEBUG_DUMP (1 << 2) /* The -w command line switch. */ 186 #define STRING_DUMP (1 << 3) /* The -p command line switch. */ 187 #define RELOC_DUMP (1 << 4) /* The -R command line switch. */ 188 #define CTF_DUMP (1 << 5) /* The --ctf command line switch. */ 189 190 typedef unsigned char dump_type; 191 192 /* A linked list of the section names for which dumps were requested. */ 193 struct dump_list_entry 194 { 195 char * name; 196 dump_type type; 197 struct dump_list_entry * next; 198 }; 199 200 typedef struct filedata 201 { 202 const char * file_name; 203 FILE * handle; 204 bfd_size_type file_size; 205 Elf_Internal_Ehdr file_header; 206 Elf_Internal_Shdr * section_headers; 207 Elf_Internal_Phdr * program_headers; 208 char * string_table; 209 unsigned long string_table_length; 210 /* A dynamic array of flags indicating for which sections a dump of 211 some kind has been requested. It is reset on a per-object file 212 basis and then initialised from the cmdline_dump_sects array, 213 the results of interpreting the -w switch, and the 214 dump_sects_byname list. */ 215 dump_type * dump_sects; 216 unsigned int num_dump_sects; 217 } Filedata; 218 219 char * program_name = "readelf"; 220 221 static unsigned long archive_file_offset; 222 static unsigned long archive_file_size; 223 static unsigned long dynamic_addr; 224 static bfd_size_type dynamic_size; 225 static size_t dynamic_nent; 226 static char * dynamic_strings; 227 static unsigned long dynamic_strings_length; 228 static unsigned long num_dynamic_syms; 229 static Elf_Internal_Sym * dynamic_symbols; 230 static Elf_Internal_Syminfo * dynamic_syminfo; 231 static unsigned long dynamic_syminfo_offset; 232 static unsigned int dynamic_syminfo_nent; 233 static char program_interpreter[PATH_MAX]; 234 static bfd_vma dynamic_info[DT_ENCODING]; 235 static bfd_vma dynamic_info_DT_GNU_HASH; 236 static bfd_vma dynamic_info_DT_MIPS_XHASH; 237 static bfd_vma version_info[16]; 238 static Elf_Internal_Dyn * dynamic_section; 239 static elf_section_list * symtab_shndx_list; 240 static bfd_boolean show_name = FALSE; 241 static bfd_boolean do_special_files = FALSE; 242 static bfd_boolean do_dynamic = FALSE; 243 static bfd_boolean do_syms = FALSE; 244 static bfd_boolean do_dyn_syms = FALSE; 245 static bfd_boolean do_reloc = FALSE; 246 static bfd_boolean do_sections = FALSE; 247 static bfd_boolean do_section_groups = FALSE; 248 static bfd_boolean do_section_details = FALSE; 249 static bfd_boolean do_segments = FALSE; 250 static bfd_boolean do_unwind = FALSE; 251 static bfd_boolean do_using_dynamic = FALSE; 252 static bfd_boolean do_header = FALSE; 253 static bfd_boolean do_dump = FALSE; 254 static bfd_boolean do_version = FALSE; 255 static bfd_boolean do_histogram = FALSE; 256 static bfd_boolean do_debugging = FALSE; 257 static bfd_boolean do_ctf = FALSE; 258 static bfd_boolean do_arch = FALSE; 259 static bfd_boolean do_notes = FALSE; 260 static bfd_boolean do_archive_index = FALSE; 261 static bfd_boolean is_32bit_elf = FALSE; 262 static bfd_boolean decompress_dumps = FALSE; 263 264 static char *dump_ctf_parent_name; 265 static char *dump_ctf_symtab_name; 266 static char *dump_ctf_strtab_name; 267 268 struct group_list 269 { 270 struct group_list * next; 271 unsigned int section_index; 272 }; 273 274 struct group 275 { 276 struct group_list * root; 277 unsigned int group_index; 278 }; 279 280 static size_t group_count; 281 static struct group * section_groups; 282 static struct group ** section_headers_groups; 283 284 /* A dynamic array of flags indicating for which sections a dump 285 has been requested via command line switches. */ 286 static Filedata cmdline; 287 288 static struct dump_list_entry * dump_sects_byname; 289 290 /* How to print a vma value. */ 291 typedef enum print_mode 292 { 293 HEX, 294 DEC, 295 DEC_5, 296 UNSIGNED, 297 PREFIX_HEX, 298 FULL_HEX, 299 LONG_HEX 300 } 301 print_mode; 302 303 /* Versioned symbol info. */ 304 enum versioned_symbol_info 305 { 306 symbol_undefined, 307 symbol_hidden, 308 symbol_public 309 }; 310 311 static const char * get_symbol_version_string 312 (Filedata *, bfd_boolean, const char *, unsigned long, unsigned, 313 Elf_Internal_Sym *, enum versioned_symbol_info *, unsigned short *); 314 315 #define UNKNOWN -1 316 317 #define SECTION_NAME(X) \ 318 ((X) == NULL ? _("<none>") \ 319 : filedata->string_table == NULL ? _("<no-strings>") \ 320 : ((X)->sh_name >= filedata->string_table_length ? _("<corrupt>") \ 321 : filedata->string_table + (X)->sh_name)) 322 323 #define DT_VERSIONTAGIDX(tag) (DT_VERNEEDNUM - (tag)) /* Reverse order! */ 324 325 #define GET_ELF_SYMBOLS(file, section, sym_count) \ 326 (is_32bit_elf ? get_32bit_elf_symbols (file, section, sym_count) \ 327 : get_64bit_elf_symbols (file, section, sym_count)) 328 329 #define VALID_DYNAMIC_NAME(offset) ((dynamic_strings != NULL) && (offset < dynamic_strings_length)) 330 /* GET_DYNAMIC_NAME asssumes that VALID_DYNAMIC_NAME has 331 already been called and verified that the string exists. */ 332 #define GET_DYNAMIC_NAME(offset) (dynamic_strings + offset) 333 334 #define REMOVE_ARCH_BITS(ADDR) \ 335 do \ 336 { \ 337 if (filedata->file_header.e_machine == EM_ARM) \ 338 (ADDR) &= ~1; \ 339 } \ 340 while (0) 341 342 /* Get the correct GNU hash section name. */ 343 #define GNU_HASH_SECTION_NAME \ 344 dynamic_info_DT_MIPS_XHASH ? ".MIPS.xhash" : ".gnu.hash" 345 346 /* Print a BFD_VMA to an internal buffer, for use in error messages. 347 BFD_FMA_FMT can't be used in translated strings. */ 348 349 static const char * 350 bfd_vmatoa (char *fmtch, bfd_vma value) 351 { 352 /* bfd_vmatoa is used more then once in a printf call for output. 353 Cycle through an array of buffers. */ 354 static int buf_pos = 0; 355 static struct bfd_vmatoa_buf 356 { 357 char place[64]; 358 } buf[4]; 359 char *ret; 360 char fmt[32]; 361 362 ret = buf[buf_pos++].place; 363 buf_pos %= ARRAY_SIZE (buf); 364 365 sprintf (fmt, "%%%s%s", BFD_VMA_FMT, fmtch); 366 snprintf (ret, sizeof (buf[0].place), fmt, value); 367 return ret; 368 } 369 370 /* Retrieve NMEMB structures, each SIZE bytes long from FILEDATA starting at 371 OFFSET + the offset of the current archive member, if we are examining an 372 archive. Put the retrieved data into VAR, if it is not NULL. Otherwise 373 allocate a buffer using malloc and fill that. In either case return the 374 pointer to the start of the retrieved data or NULL if something went wrong. 375 If something does go wrong and REASON is not NULL then emit an error 376 message using REASON as part of the context. */ 377 378 static void * 379 get_data (void * var, 380 Filedata * filedata, 381 unsigned long offset, 382 bfd_size_type size, 383 bfd_size_type nmemb, 384 const char * reason) 385 { 386 void * mvar; 387 bfd_size_type amt = size * nmemb; 388 389 if (size == 0 || nmemb == 0) 390 return NULL; 391 392 /* If the size_t type is smaller than the bfd_size_type, eg because 393 you are building a 32-bit tool on a 64-bit host, then make sure 394 that when the sizes are cast to (size_t) no information is lost. */ 395 if ((size_t) size != size 396 || (size_t) nmemb != nmemb 397 || (size_t) amt != amt) 398 { 399 if (reason) 400 error (_("Size truncation prevents reading %s" 401 " elements of size %s for %s\n"), 402 bfd_vmatoa ("u", nmemb), bfd_vmatoa ("u", size), reason); 403 return NULL; 404 } 405 406 /* Check for size overflow. */ 407 if (amt / size != nmemb || (size_t) amt + 1 == 0) 408 { 409 if (reason) 410 error (_("Size overflow prevents reading %s" 411 " elements of size %s for %s\n"), 412 bfd_vmatoa ("u", nmemb), bfd_vmatoa ("u", size), reason); 413 return NULL; 414 } 415 416 /* Be kind to memory checkers (eg valgrind, address sanitizer) by not 417 attempting to allocate memory when the read is bound to fail. */ 418 if (archive_file_offset > filedata->file_size 419 || offset > filedata->file_size - archive_file_offset 420 || amt > filedata->file_size - archive_file_offset - offset) 421 { 422 if (reason) 423 error (_("Reading %s bytes extends past end of file for %s\n"), 424 bfd_vmatoa ("u", amt), reason); 425 return NULL; 426 } 427 428 if (fseek (filedata->handle, archive_file_offset + offset, SEEK_SET)) 429 { 430 if (reason) 431 error (_("Unable to seek to 0x%lx for %s\n"), 432 archive_file_offset + offset, reason); 433 return NULL; 434 } 435 436 mvar = var; 437 if (mvar == NULL) 438 { 439 /* + 1 so that we can '\0' terminate invalid string table sections. */ 440 mvar = malloc ((size_t) amt + 1); 441 442 if (mvar == NULL) 443 { 444 if (reason) 445 error (_("Out of memory allocating %s bytes for %s\n"), 446 bfd_vmatoa ("u", amt), reason); 447 return NULL; 448 } 449 450 ((char *) mvar)[amt] = '\0'; 451 } 452 453 if (fread (mvar, (size_t) size, (size_t) nmemb, filedata->handle) != nmemb) 454 { 455 if (reason) 456 error (_("Unable to read in %s bytes of %s\n"), 457 bfd_vmatoa ("u", amt), reason); 458 if (mvar != var) 459 free (mvar); 460 return NULL; 461 } 462 463 return mvar; 464 } 465 466 /* Print a VMA value in the MODE specified. 467 Returns the number of characters displayed. */ 468 469 static unsigned int 470 print_vma (bfd_vma vma, print_mode mode) 471 { 472 unsigned int nc = 0; 473 474 switch (mode) 475 { 476 case FULL_HEX: 477 nc = printf ("0x"); 478 /* Fall through. */ 479 case LONG_HEX: 480 #ifdef BFD64 481 if (is_32bit_elf) 482 return nc + printf ("%8.8" BFD_VMA_FMT "x", vma); 483 #endif 484 printf_vma (vma); 485 return nc + 16; 486 487 case DEC_5: 488 if (vma <= 99999) 489 return printf ("%5" BFD_VMA_FMT "d", vma); 490 /* Fall through. */ 491 case PREFIX_HEX: 492 nc = printf ("0x"); 493 /* Fall through. */ 494 case HEX: 495 return nc + printf ("%" BFD_VMA_FMT "x", vma); 496 497 case DEC: 498 return printf ("%" BFD_VMA_FMT "d", vma); 499 500 case UNSIGNED: 501 return printf ("%" BFD_VMA_FMT "u", vma); 502 503 default: 504 /* FIXME: Report unrecognised mode ? */ 505 return 0; 506 } 507 } 508 509 /* Display a symbol on stdout. Handles the display of control characters and 510 multibye characters (assuming the host environment supports them). 511 512 Display at most abs(WIDTH) characters, truncating as necessary, unless do_wide is true. 513 514 If WIDTH is negative then ensure that the output is at least (- WIDTH) characters, 515 padding as necessary. 516 517 Returns the number of emitted characters. */ 518 519 static unsigned int 520 print_symbol (signed int width, const char *symbol) 521 { 522 bfd_boolean extra_padding = FALSE; 523 signed int num_printed = 0; 524 #ifdef HAVE_MBSTATE_T 525 mbstate_t state; 526 #endif 527 unsigned int width_remaining; 528 529 if (width < 0) 530 { 531 /* Keep the width positive. This helps the code below. */ 532 width = - width; 533 extra_padding = TRUE; 534 } 535 else if (width == 0) 536 return 0; 537 538 if (do_wide) 539 /* Set the remaining width to a very large value. 540 This simplifies the code below. */ 541 width_remaining = INT_MAX; 542 else 543 width_remaining = width; 544 545 #ifdef HAVE_MBSTATE_T 546 /* Initialise the multibyte conversion state. */ 547 memset (& state, 0, sizeof (state)); 548 #endif 549 550 while (width_remaining) 551 { 552 size_t n; 553 const char c = *symbol++; 554 555 if (c == 0) 556 break; 557 558 /* Do not print control characters directly as they can affect terminal 559 settings. Such characters usually appear in the names generated 560 by the assembler for local labels. */ 561 if (ISCNTRL (c)) 562 { 563 if (width_remaining < 2) 564 break; 565 566 printf ("^%c", c + 0x40); 567 width_remaining -= 2; 568 num_printed += 2; 569 } 570 else if (ISPRINT (c)) 571 { 572 putchar (c); 573 width_remaining --; 574 num_printed ++; 575 } 576 else 577 { 578 #ifdef HAVE_MBSTATE_T 579 wchar_t w; 580 #endif 581 /* Let printf do the hard work of displaying multibyte characters. */ 582 printf ("%.1s", symbol - 1); 583 width_remaining --; 584 num_printed ++; 585 586 #ifdef HAVE_MBSTATE_T 587 /* Try to find out how many bytes made up the character that was 588 just printed. Advance the symbol pointer past the bytes that 589 were displayed. */ 590 n = mbrtowc (& w, symbol - 1, MB_CUR_MAX, & state); 591 #else 592 n = 1; 593 #endif 594 if (n != (size_t) -1 && n != (size_t) -2 && n > 0) 595 symbol += (n - 1); 596 } 597 } 598 599 if (extra_padding && num_printed < width) 600 { 601 /* Fill in the remaining spaces. */ 602 printf ("%-*s", width - num_printed, " "); 603 num_printed = width; 604 } 605 606 return num_printed; 607 } 608 609 /* Returns a pointer to a static buffer containing a printable version of 610 the given section's name. Like print_symbol, except that it does not try 611 to print multibyte characters, it just interprets them as hex values. */ 612 613 static const char * 614 printable_section_name (Filedata * filedata, const Elf_Internal_Shdr * sec) 615 { 616 #define MAX_PRINT_SEC_NAME_LEN 128 617 static char sec_name_buf [MAX_PRINT_SEC_NAME_LEN + 1]; 618 const char * name = SECTION_NAME (sec); 619 char * buf = sec_name_buf; 620 char c; 621 unsigned int remaining = MAX_PRINT_SEC_NAME_LEN; 622 623 while ((c = * name ++) != 0) 624 { 625 if (ISCNTRL (c)) 626 { 627 if (remaining < 2) 628 break; 629 630 * buf ++ = '^'; 631 * buf ++ = c + 0x40; 632 remaining -= 2; 633 } 634 else if (ISPRINT (c)) 635 { 636 * buf ++ = c; 637 remaining -= 1; 638 } 639 else 640 { 641 static char hex[17] = "0123456789ABCDEF"; 642 643 if (remaining < 4) 644 break; 645 * buf ++ = '<'; 646 * buf ++ = hex[(c & 0xf0) >> 4]; 647 * buf ++ = hex[c & 0x0f]; 648 * buf ++ = '>'; 649 remaining -= 4; 650 } 651 652 if (remaining == 0) 653 break; 654 } 655 656 * buf = 0; 657 return sec_name_buf; 658 } 659 660 static const char * 661 printable_section_name_from_index (Filedata * filedata, unsigned long ndx) 662 { 663 if (ndx >= filedata->file_header.e_shnum) 664 return _("<corrupt>"); 665 666 return printable_section_name (filedata, filedata->section_headers + ndx); 667 } 668 669 /* Return a pointer to section NAME, or NULL if no such section exists. */ 670 671 static Elf_Internal_Shdr * 672 find_section (Filedata * filedata, const char * name) 673 { 674 unsigned int i; 675 676 if (filedata->section_headers == NULL) 677 return NULL; 678 679 for (i = 0; i < filedata->file_header.e_shnum; i++) 680 if (streq (SECTION_NAME (filedata->section_headers + i), name)) 681 return filedata->section_headers + i; 682 683 return NULL; 684 } 685 686 /* Return a pointer to a section containing ADDR, or NULL if no such 687 section exists. */ 688 689 static Elf_Internal_Shdr * 690 find_section_by_address (Filedata * filedata, bfd_vma addr) 691 { 692 unsigned int i; 693 694 if (filedata->section_headers == NULL) 695 return NULL; 696 697 for (i = 0; i < filedata->file_header.e_shnum; i++) 698 { 699 Elf_Internal_Shdr *sec = filedata->section_headers + i; 700 701 if (addr >= sec->sh_addr && addr < sec->sh_addr + sec->sh_size) 702 return sec; 703 } 704 705 return NULL; 706 } 707 708 static Elf_Internal_Shdr * 709 find_section_by_type (Filedata * filedata, unsigned int type) 710 { 711 unsigned int i; 712 713 if (filedata->section_headers == NULL) 714 return NULL; 715 716 for (i = 0; i < filedata->file_header.e_shnum; i++) 717 { 718 Elf_Internal_Shdr *sec = filedata->section_headers + i; 719 720 if (sec->sh_type == type) 721 return sec; 722 } 723 724 return NULL; 725 } 726 727 /* Return a pointer to section NAME, or NULL if no such section exists, 728 restricted to the list of sections given in SET. */ 729 730 static Elf_Internal_Shdr * 731 find_section_in_set (Filedata * filedata, const char * name, unsigned int * set) 732 { 733 unsigned int i; 734 735 if (filedata->section_headers == NULL) 736 return NULL; 737 738 if (set != NULL) 739 { 740 while ((i = *set++) > 0) 741 { 742 /* See PR 21156 for a reproducer. */ 743 if (i >= filedata->file_header.e_shnum) 744 continue; /* FIXME: Should we issue an error message ? */ 745 746 if (streq (SECTION_NAME (filedata->section_headers + i), name)) 747 return filedata->section_headers + i; 748 } 749 } 750 751 return find_section (filedata, name); 752 } 753 754 /* Return TRUE if the current file is for IA-64 machine and OpenVMS ABI. 755 This OS has so many departures from the ELF standard that we test it at 756 many places. */ 757 758 static inline bfd_boolean 759 is_ia64_vms (Filedata * filedata) 760 { 761 return filedata->file_header.e_machine == EM_IA_64 762 && filedata->file_header.e_ident[EI_OSABI] == ELFOSABI_OPENVMS; 763 } 764 765 /* Guess the relocation size commonly used by the specific machines. */ 766 767 static bfd_boolean 768 guess_is_rela (unsigned int e_machine) 769 { 770 switch (e_machine) 771 { 772 /* Targets that use REL relocations. */ 773 case EM_386: 774 case EM_IAMCU: 775 case EM_960: 776 case EM_ARM: 777 case EM_D10V: 778 case EM_CYGNUS_D10V: 779 case EM_DLX: 780 case EM_MIPS: 781 case EM_MIPS_RS3_LE: 782 case EM_CYGNUS_M32R: 783 case EM_SCORE: 784 case EM_XGATE: 785 case EM_NFP: 786 case EM_BPF: 787 return FALSE; 788 789 /* Targets that use RELA relocations. */ 790 case EM_68K: 791 case EM_860: 792 case EM_AARCH64: 793 case EM_ADAPTEVA_EPIPHANY: 794 case EM_ALPHA: 795 case EM_ALTERA_NIOS2: 796 case EM_ARC: 797 case EM_ARC_COMPACT: 798 case EM_ARC_COMPACT2: 799 case EM_AVR: 800 case EM_AVR_OLD: 801 case EM_BLACKFIN: 802 case EM_CR16: 803 case EM_CRIS: 804 case EM_CRX: 805 case EM_CSKY: 806 case EM_D30V: 807 case EM_CYGNUS_D30V: 808 case EM_FR30: 809 case EM_FT32: 810 case EM_CYGNUS_FR30: 811 case EM_CYGNUS_FRV: 812 case EM_H8S: 813 case EM_H8_300: 814 case EM_H8_300H: 815 case EM_IA_64: 816 case EM_IP2K: 817 case EM_IP2K_OLD: 818 case EM_IQ2000: 819 case EM_LATTICEMICO32: 820 case EM_M32C_OLD: 821 case EM_M32C: 822 case EM_M32R: 823 case EM_MCORE: 824 case EM_CYGNUS_MEP: 825 case EM_METAG: 826 case EM_MMIX: 827 case EM_MN10200: 828 case EM_CYGNUS_MN10200: 829 case EM_MN10300: 830 case EM_CYGNUS_MN10300: 831 case EM_MOXIE: 832 case EM_MSP430: 833 case EM_MSP430_OLD: 834 case EM_MT: 835 case EM_NDS32: 836 case EM_NIOS32: 837 case EM_OR1K: 838 case EM_PPC64: 839 case EM_PPC: 840 case EM_TI_PRU: 841 case EM_RISCV: 842 case EM_RL78: 843 case EM_RX: 844 case EM_S390: 845 case EM_S390_OLD: 846 case EM_SH: 847 case EM_SPARC: 848 case EM_SPARC32PLUS: 849 case EM_SPARCV9: 850 case EM_SPU: 851 case EM_TI_C6000: 852 case EM_TILEGX: 853 case EM_TILEPRO: 854 case EM_V800: 855 case EM_V850: 856 case EM_CYGNUS_V850: 857 case EM_VAX: 858 case EM_VISIUM: 859 case EM_X86_64: 860 case EM_L1OM: 861 case EM_K1OM: 862 case EM_XSTORMY16: 863 case EM_XTENSA: 864 case EM_XTENSA_OLD: 865 case EM_MICROBLAZE: 866 case EM_MICROBLAZE_OLD: 867 case EM_WEBASSEMBLY: 868 return TRUE; 869 870 case EM_68HC05: 871 case EM_68HC08: 872 case EM_68HC11: 873 case EM_68HC16: 874 case EM_FX66: 875 case EM_ME16: 876 case EM_MMA: 877 case EM_NCPU: 878 case EM_NDR1: 879 case EM_PCP: 880 case EM_ST100: 881 case EM_ST19: 882 case EM_ST7: 883 case EM_ST9PLUS: 884 case EM_STARCORE: 885 case EM_SVX: 886 case EM_TINYJ: 887 default: 888 warn (_("Don't know about relocations on this machine architecture\n")); 889 return FALSE; 890 } 891 } 892 893 /* Load RELA type relocations from FILEDATA at REL_OFFSET extending for REL_SIZE bytes. 894 Returns TRUE upon success, FALSE otherwise. If successful then a 895 pointer to a malloc'ed buffer containing the relocs is placed in *RELASP, 896 and the number of relocs loaded is placed in *NRELASP. It is the caller's 897 responsibility to free the allocated buffer. */ 898 899 static bfd_boolean 900 slurp_rela_relocs (Filedata * filedata, 901 unsigned long rel_offset, 902 unsigned long rel_size, 903 Elf_Internal_Rela ** relasp, 904 unsigned long * nrelasp) 905 { 906 Elf_Internal_Rela * relas; 907 size_t nrelas; 908 unsigned int i; 909 910 if (is_32bit_elf) 911 { 912 Elf32_External_Rela * erelas; 913 914 erelas = (Elf32_External_Rela *) get_data (NULL, filedata, rel_offset, 1, 915 rel_size, _("32-bit relocation data")); 916 if (!erelas) 917 return FALSE; 918 919 nrelas = rel_size / sizeof (Elf32_External_Rela); 920 921 relas = (Elf_Internal_Rela *) cmalloc (nrelas, 922 sizeof (Elf_Internal_Rela)); 923 924 if (relas == NULL) 925 { 926 free (erelas); 927 error (_("out of memory parsing relocs\n")); 928 return FALSE; 929 } 930 931 for (i = 0; i < nrelas; i++) 932 { 933 relas[i].r_offset = BYTE_GET (erelas[i].r_offset); 934 relas[i].r_info = BYTE_GET (erelas[i].r_info); 935 relas[i].r_addend = BYTE_GET_SIGNED (erelas[i].r_addend); 936 } 937 938 free (erelas); 939 } 940 else 941 { 942 Elf64_External_Rela * erelas; 943 944 erelas = (Elf64_External_Rela *) get_data (NULL, filedata, rel_offset, 1, 945 rel_size, _("64-bit relocation data")); 946 if (!erelas) 947 return FALSE; 948 949 nrelas = rel_size / sizeof (Elf64_External_Rela); 950 951 relas = (Elf_Internal_Rela *) cmalloc (nrelas, 952 sizeof (Elf_Internal_Rela)); 953 954 if (relas == NULL) 955 { 956 free (erelas); 957 error (_("out of memory parsing relocs\n")); 958 return FALSE; 959 } 960 961 for (i = 0; i < nrelas; i++) 962 { 963 relas[i].r_offset = BYTE_GET (erelas[i].r_offset); 964 relas[i].r_info = BYTE_GET (erelas[i].r_info); 965 relas[i].r_addend = BYTE_GET_SIGNED (erelas[i].r_addend); 966 967 /* The #ifdef BFD64 below is to prevent a compile time 968 warning. We know that if we do not have a 64 bit data 969 type that we will never execute this code anyway. */ 970 #ifdef BFD64 971 if (filedata->file_header.e_machine == EM_MIPS 972 && filedata->file_header.e_ident[EI_DATA] != ELFDATA2MSB) 973 { 974 /* In little-endian objects, r_info isn't really a 975 64-bit little-endian value: it has a 32-bit 976 little-endian symbol index followed by four 977 individual byte fields. Reorder INFO 978 accordingly. */ 979 bfd_vma inf = relas[i].r_info; 980 inf = (((inf & 0xffffffff) << 32) 981 | ((inf >> 56) & 0xff) 982 | ((inf >> 40) & 0xff00) 983 | ((inf >> 24) & 0xff0000) 984 | ((inf >> 8) & 0xff000000)); 985 relas[i].r_info = inf; 986 } 987 #endif /* BFD64 */ 988 } 989 990 free (erelas); 991 } 992 993 *relasp = relas; 994 *nrelasp = nrelas; 995 return TRUE; 996 } 997 998 /* Load REL type relocations from FILEDATA at REL_OFFSET extending for REL_SIZE bytes. 999 Returns TRUE upon success, FALSE otherwise. If successful then a 1000 pointer to a malloc'ed buffer containing the relocs is placed in *RELSP, 1001 and the number of relocs loaded is placed in *NRELSP. It is the caller's 1002 responsibility to free the allocated buffer. */ 1003 1004 static bfd_boolean 1005 slurp_rel_relocs (Filedata * filedata, 1006 unsigned long rel_offset, 1007 unsigned long rel_size, 1008 Elf_Internal_Rela ** relsp, 1009 unsigned long * nrelsp) 1010 { 1011 Elf_Internal_Rela * rels; 1012 size_t nrels; 1013 unsigned int i; 1014 1015 if (is_32bit_elf) 1016 { 1017 Elf32_External_Rel * erels; 1018 1019 erels = (Elf32_External_Rel *) get_data (NULL, filedata, rel_offset, 1, 1020 rel_size, _("32-bit relocation data")); 1021 if (!erels) 1022 return FALSE; 1023 1024 nrels = rel_size / sizeof (Elf32_External_Rel); 1025 1026 rels = (Elf_Internal_Rela *) cmalloc (nrels, sizeof (Elf_Internal_Rela)); 1027 1028 if (rels == NULL) 1029 { 1030 free (erels); 1031 error (_("out of memory parsing relocs\n")); 1032 return FALSE; 1033 } 1034 1035 for (i = 0; i < nrels; i++) 1036 { 1037 rels[i].r_offset = BYTE_GET (erels[i].r_offset); 1038 rels[i].r_info = BYTE_GET (erels[i].r_info); 1039 rels[i].r_addend = 0; 1040 } 1041 1042 free (erels); 1043 } 1044 else 1045 { 1046 Elf64_External_Rel * erels; 1047 1048 erels = (Elf64_External_Rel *) get_data (NULL, filedata, rel_offset, 1, 1049 rel_size, _("64-bit relocation data")); 1050 if (!erels) 1051 return FALSE; 1052 1053 nrels = rel_size / sizeof (Elf64_External_Rel); 1054 1055 rels = (Elf_Internal_Rela *) cmalloc (nrels, sizeof (Elf_Internal_Rela)); 1056 1057 if (rels == NULL) 1058 { 1059 free (erels); 1060 error (_("out of memory parsing relocs\n")); 1061 return FALSE; 1062 } 1063 1064 for (i = 0; i < nrels; i++) 1065 { 1066 rels[i].r_offset = BYTE_GET (erels[i].r_offset); 1067 rels[i].r_info = BYTE_GET (erels[i].r_info); 1068 rels[i].r_addend = 0; 1069 1070 /* The #ifdef BFD64 below is to prevent a compile time 1071 warning. We know that if we do not have a 64 bit data 1072 type that we will never execute this code anyway. */ 1073 #ifdef BFD64 1074 if (filedata->file_header.e_machine == EM_MIPS 1075 && filedata->file_header.e_ident[EI_DATA] != ELFDATA2MSB) 1076 { 1077 /* In little-endian objects, r_info isn't really a 1078 64-bit little-endian value: it has a 32-bit 1079 little-endian symbol index followed by four 1080 individual byte fields. Reorder INFO 1081 accordingly. */ 1082 bfd_vma inf = rels[i].r_info; 1083 inf = (((inf & 0xffffffff) << 32) 1084 | ((inf >> 56) & 0xff) 1085 | ((inf >> 40) & 0xff00) 1086 | ((inf >> 24) & 0xff0000) 1087 | ((inf >> 8) & 0xff000000)); 1088 rels[i].r_info = inf; 1089 } 1090 #endif /* BFD64 */ 1091 } 1092 1093 free (erels); 1094 } 1095 1096 *relsp = rels; 1097 *nrelsp = nrels; 1098 return TRUE; 1099 } 1100 1101 /* Returns the reloc type extracted from the reloc info field. */ 1102 1103 static unsigned int 1104 get_reloc_type (Filedata * filedata, bfd_vma reloc_info) 1105 { 1106 if (is_32bit_elf) 1107 return ELF32_R_TYPE (reloc_info); 1108 1109 switch (filedata->file_header.e_machine) 1110 { 1111 case EM_MIPS: 1112 /* Note: We assume that reloc_info has already been adjusted for us. */ 1113 return ELF64_MIPS_R_TYPE (reloc_info); 1114 1115 case EM_SPARCV9: 1116 return ELF64_R_TYPE_ID (reloc_info); 1117 1118 default: 1119 return ELF64_R_TYPE (reloc_info); 1120 } 1121 } 1122 1123 /* Return the symbol index extracted from the reloc info field. */ 1124 1125 static bfd_vma 1126 get_reloc_symindex (bfd_vma reloc_info) 1127 { 1128 return is_32bit_elf ? ELF32_R_SYM (reloc_info) : ELF64_R_SYM (reloc_info); 1129 } 1130 1131 static inline bfd_boolean 1132 uses_msp430x_relocs (Filedata * filedata) 1133 { 1134 return 1135 filedata->file_header.e_machine == EM_MSP430 /* Paranoia. */ 1136 /* GCC uses osabi == ELFOSBI_STANDALONE. */ 1137 && (((filedata->file_header.e_flags & EF_MSP430_MACH) == E_MSP430_MACH_MSP430X) 1138 /* TI compiler uses ELFOSABI_NONE. */ 1139 || (filedata->file_header.e_ident[EI_OSABI] == ELFOSABI_NONE)); 1140 } 1141 1142 /* Display the contents of the relocation data found at the specified 1143 offset. */ 1144 1145 static bfd_boolean 1146 dump_relocations (Filedata * filedata, 1147 unsigned long rel_offset, 1148 unsigned long rel_size, 1149 Elf_Internal_Sym * symtab, 1150 unsigned long nsyms, 1151 char * strtab, 1152 unsigned long strtablen, 1153 int is_rela, 1154 bfd_boolean is_dynsym) 1155 { 1156 unsigned long i; 1157 Elf_Internal_Rela * rels; 1158 bfd_boolean res = TRUE; 1159 1160 if (is_rela == UNKNOWN) 1161 is_rela = guess_is_rela (filedata->file_header.e_machine); 1162 1163 if (is_rela) 1164 { 1165 if (!slurp_rela_relocs (filedata, rel_offset, rel_size, &rels, &rel_size)) 1166 return FALSE; 1167 } 1168 else 1169 { 1170 if (!slurp_rel_relocs (filedata, rel_offset, rel_size, &rels, &rel_size)) 1171 return FALSE; 1172 } 1173 1174 if (is_32bit_elf) 1175 { 1176 if (is_rela) 1177 { 1178 if (do_wide) 1179 printf (_(" Offset Info Type Sym. Value Symbol's Name + Addend\n")); 1180 else 1181 printf (_(" Offset Info Type Sym.Value Sym. Name + Addend\n")); 1182 } 1183 else 1184 { 1185 if (do_wide) 1186 printf (_(" Offset Info Type Sym. Value Symbol's Name\n")); 1187 else 1188 printf (_(" Offset Info Type Sym.Value Sym. Name\n")); 1189 } 1190 } 1191 else 1192 { 1193 if (is_rela) 1194 { 1195 if (do_wide) 1196 printf (_(" Offset Info Type Symbol's Value Symbol's Name + Addend\n")); 1197 else 1198 printf (_(" Offset Info Type Sym. Value Sym. Name + Addend\n")); 1199 } 1200 else 1201 { 1202 if (do_wide) 1203 printf (_(" Offset Info Type Symbol's Value Symbol's Name\n")); 1204 else 1205 printf (_(" Offset Info Type Sym. Value Sym. Name\n")); 1206 } 1207 } 1208 1209 for (i = 0; i < rel_size; i++) 1210 { 1211 const char * rtype; 1212 bfd_vma offset; 1213 bfd_vma inf; 1214 bfd_vma symtab_index; 1215 bfd_vma type; 1216 1217 offset = rels[i].r_offset; 1218 inf = rels[i].r_info; 1219 1220 type = get_reloc_type (filedata, inf); 1221 symtab_index = get_reloc_symindex (inf); 1222 1223 if (is_32bit_elf) 1224 { 1225 printf ("%8.8lx %8.8lx ", 1226 (unsigned long) offset & 0xffffffff, 1227 (unsigned long) inf & 0xffffffff); 1228 } 1229 else 1230 { 1231 #if BFD_HOST_64BIT_LONG 1232 printf (do_wide 1233 ? "%16.16lx %16.16lx " 1234 : "%12.12lx %12.12lx ", 1235 offset, inf); 1236 #elif BFD_HOST_64BIT_LONG_LONG 1237 #ifndef __MSVCRT__ 1238 printf (do_wide 1239 ? "%16.16llx %16.16llx " 1240 : "%12.12llx %12.12llx ", 1241 offset, inf); 1242 #else 1243 printf (do_wide 1244 ? "%16.16I64x %16.16I64x " 1245 : "%12.12I64x %12.12I64x ", 1246 offset, inf); 1247 #endif 1248 #else 1249 printf (do_wide 1250 ? "%8.8lx%8.8lx %8.8lx%8.8lx " 1251 : "%4.4lx%8.8lx %4.4lx%8.8lx ", 1252 _bfd_int64_high (offset), 1253 _bfd_int64_low (offset), 1254 _bfd_int64_high (inf), 1255 _bfd_int64_low (inf)); 1256 #endif 1257 } 1258 1259 switch (filedata->file_header.e_machine) 1260 { 1261 default: 1262 rtype = NULL; 1263 break; 1264 1265 case EM_AARCH64: 1266 rtype = elf_aarch64_reloc_type (type); 1267 break; 1268 1269 case EM_M32R: 1270 case EM_CYGNUS_M32R: 1271 rtype = elf_m32r_reloc_type (type); 1272 break; 1273 1274 case EM_386: 1275 case EM_IAMCU: 1276 rtype = elf_i386_reloc_type (type); 1277 break; 1278 1279 case EM_68HC11: 1280 case EM_68HC12: 1281 rtype = elf_m68hc11_reloc_type (type); 1282 break; 1283 1284 case EM_S12Z: 1285 rtype = elf_s12z_reloc_type (type); 1286 break; 1287 1288 case EM_68K: 1289 rtype = elf_m68k_reloc_type (type); 1290 break; 1291 1292 case EM_960: 1293 rtype = elf_i960_reloc_type (type); 1294 break; 1295 1296 case EM_AVR: 1297 case EM_AVR_OLD: 1298 rtype = elf_avr_reloc_type (type); 1299 break; 1300 1301 case EM_OLD_SPARCV9: 1302 case EM_SPARC32PLUS: 1303 case EM_SPARCV9: 1304 case EM_SPARC: 1305 rtype = elf_sparc_reloc_type (type); 1306 break; 1307 1308 case EM_SPU: 1309 rtype = elf_spu_reloc_type (type); 1310 break; 1311 1312 case EM_V800: 1313 rtype = v800_reloc_type (type); 1314 break; 1315 case EM_V850: 1316 case EM_CYGNUS_V850: 1317 rtype = v850_reloc_type (type); 1318 break; 1319 1320 case EM_D10V: 1321 case EM_CYGNUS_D10V: 1322 rtype = elf_d10v_reloc_type (type); 1323 break; 1324 1325 case EM_D30V: 1326 case EM_CYGNUS_D30V: 1327 rtype = elf_d30v_reloc_type (type); 1328 break; 1329 1330 case EM_DLX: 1331 rtype = elf_dlx_reloc_type (type); 1332 break; 1333 1334 case EM_SH: 1335 rtype = elf_sh_reloc_type (type); 1336 break; 1337 1338 case EM_MN10300: 1339 case EM_CYGNUS_MN10300: 1340 rtype = elf_mn10300_reloc_type (type); 1341 break; 1342 1343 case EM_MN10200: 1344 case EM_CYGNUS_MN10200: 1345 rtype = elf_mn10200_reloc_type (type); 1346 break; 1347 1348 case EM_FR30: 1349 case EM_CYGNUS_FR30: 1350 rtype = elf_fr30_reloc_type (type); 1351 break; 1352 1353 case EM_CYGNUS_FRV: 1354 rtype = elf_frv_reloc_type (type); 1355 break; 1356 1357 case EM_CSKY: 1358 rtype = elf_csky_reloc_type (type); 1359 break; 1360 1361 case EM_FT32: 1362 rtype = elf_ft32_reloc_type (type); 1363 break; 1364 1365 case EM_MCORE: 1366 rtype = elf_mcore_reloc_type (type); 1367 break; 1368 1369 case EM_MMIX: 1370 rtype = elf_mmix_reloc_type (type); 1371 break; 1372 1373 case EM_MOXIE: 1374 rtype = elf_moxie_reloc_type (type); 1375 break; 1376 1377 case EM_MSP430: 1378 if (uses_msp430x_relocs (filedata)) 1379 { 1380 rtype = elf_msp430x_reloc_type (type); 1381 break; 1382 } 1383 /* Fall through. */ 1384 case EM_MSP430_OLD: 1385 rtype = elf_msp430_reloc_type (type); 1386 break; 1387 1388 case EM_NDS32: 1389 rtype = elf_nds32_reloc_type (type); 1390 break; 1391 1392 case EM_PPC: 1393 rtype = elf_ppc_reloc_type (type); 1394 break; 1395 1396 case EM_PPC64: 1397 rtype = elf_ppc64_reloc_type (type); 1398 break; 1399 1400 case EM_MIPS: 1401 case EM_MIPS_RS3_LE: 1402 rtype = elf_mips_reloc_type (type); 1403 break; 1404 1405 case EM_RISCV: 1406 rtype = elf_riscv_reloc_type (type); 1407 break; 1408 1409 case EM_ALPHA: 1410 rtype = elf_alpha_reloc_type (type); 1411 break; 1412 1413 case EM_ARM: 1414 rtype = elf_arm_reloc_type (type); 1415 break; 1416 1417 case EM_ARC: 1418 case EM_ARC_COMPACT: 1419 case EM_ARC_COMPACT2: 1420 rtype = elf_arc_reloc_type (type); 1421 break; 1422 1423 case EM_PARISC: 1424 rtype = elf_hppa_reloc_type (type); 1425 break; 1426 1427 case EM_H8_300: 1428 case EM_H8_300H: 1429 case EM_H8S: 1430 rtype = elf_h8_reloc_type (type); 1431 break; 1432 1433 case EM_OR1K: 1434 rtype = elf_or1k_reloc_type (type); 1435 break; 1436 1437 case EM_PJ: 1438 case EM_PJ_OLD: 1439 rtype = elf_pj_reloc_type (type); 1440 break; 1441 case EM_IA_64: 1442 rtype = elf_ia64_reloc_type (type); 1443 break; 1444 1445 case EM_CRIS: 1446 rtype = elf_cris_reloc_type (type); 1447 break; 1448 1449 case EM_860: 1450 rtype = elf_i860_reloc_type (type); 1451 break; 1452 1453 case EM_X86_64: 1454 case EM_L1OM: 1455 case EM_K1OM: 1456 rtype = elf_x86_64_reloc_type (type); 1457 break; 1458 1459 case EM_S370: 1460 rtype = i370_reloc_type (type); 1461 break; 1462 1463 case EM_S390_OLD: 1464 case EM_S390: 1465 rtype = elf_s390_reloc_type (type); 1466 break; 1467 1468 case EM_SCORE: 1469 rtype = elf_score_reloc_type (type); 1470 break; 1471 1472 case EM_XSTORMY16: 1473 rtype = elf_xstormy16_reloc_type (type); 1474 break; 1475 1476 case EM_CRX: 1477 rtype = elf_crx_reloc_type (type); 1478 break; 1479 1480 case EM_VAX: 1481 rtype = elf_vax_reloc_type (type); 1482 break; 1483 1484 case EM_VISIUM: 1485 rtype = elf_visium_reloc_type (type); 1486 break; 1487 1488 case EM_BPF: 1489 rtype = elf_bpf_reloc_type (type); 1490 break; 1491 1492 case EM_ADAPTEVA_EPIPHANY: 1493 rtype = elf_epiphany_reloc_type (type); 1494 break; 1495 1496 case EM_IP2K: 1497 case EM_IP2K_OLD: 1498 rtype = elf_ip2k_reloc_type (type); 1499 break; 1500 1501 case EM_IQ2000: 1502 rtype = elf_iq2000_reloc_type (type); 1503 break; 1504 1505 case EM_XTENSA_OLD: 1506 case EM_XTENSA: 1507 rtype = elf_xtensa_reloc_type (type); 1508 break; 1509 1510 case EM_LATTICEMICO32: 1511 rtype = elf_lm32_reloc_type (type); 1512 break; 1513 1514 case EM_M32C_OLD: 1515 case EM_M32C: 1516 rtype = elf_m32c_reloc_type (type); 1517 break; 1518 1519 case EM_MT: 1520 rtype = elf_mt_reloc_type (type); 1521 break; 1522 1523 case EM_BLACKFIN: 1524 rtype = elf_bfin_reloc_type (type); 1525 break; 1526 1527 case EM_CYGNUS_MEP: 1528 rtype = elf_mep_reloc_type (type); 1529 break; 1530 1531 case EM_CR16: 1532 rtype = elf_cr16_reloc_type (type); 1533 break; 1534 1535 case EM_MICROBLAZE: 1536 case EM_MICROBLAZE_OLD: 1537 rtype = elf_microblaze_reloc_type (type); 1538 break; 1539 1540 case EM_RL78: 1541 rtype = elf_rl78_reloc_type (type); 1542 break; 1543 1544 case EM_RX: 1545 rtype = elf_rx_reloc_type (type); 1546 break; 1547 1548 case EM_METAG: 1549 rtype = elf_metag_reloc_type (type); 1550 break; 1551 1552 case EM_XC16X: 1553 case EM_C166: 1554 rtype = elf_xc16x_reloc_type (type); 1555 break; 1556 1557 case EM_TI_C6000: 1558 rtype = elf_tic6x_reloc_type (type); 1559 break; 1560 1561 case EM_TILEGX: 1562 rtype = elf_tilegx_reloc_type (type); 1563 break; 1564 1565 case EM_TILEPRO: 1566 rtype = elf_tilepro_reloc_type (type); 1567 break; 1568 1569 case EM_WEBASSEMBLY: 1570 rtype = elf_wasm32_reloc_type (type); 1571 break; 1572 1573 case EM_XGATE: 1574 rtype = elf_xgate_reloc_type (type); 1575 break; 1576 1577 case EM_ALTERA_NIOS2: 1578 rtype = elf_nios2_reloc_type (type); 1579 break; 1580 1581 case EM_TI_PRU: 1582 rtype = elf_pru_reloc_type (type); 1583 break; 1584 1585 case EM_NFP: 1586 if (EF_NFP_MACH (filedata->file_header.e_flags) == E_NFP_MACH_3200) 1587 rtype = elf_nfp3200_reloc_type (type); 1588 else 1589 rtype = elf_nfp_reloc_type (type); 1590 break; 1591 1592 case EM_Z80: 1593 rtype = elf_z80_reloc_type (type); 1594 break; 1595 } 1596 1597 if (rtype == NULL) 1598 printf (_("unrecognized: %-7lx"), (unsigned long) type & 0xffffffff); 1599 else 1600 printf (do_wide ? "%-22s" : "%-17.17s", rtype); 1601 1602 if (filedata->file_header.e_machine == EM_ALPHA 1603 && rtype != NULL 1604 && streq (rtype, "R_ALPHA_LITUSE") 1605 && is_rela) 1606 { 1607 switch (rels[i].r_addend) 1608 { 1609 case LITUSE_ALPHA_ADDR: rtype = "ADDR"; break; 1610 case LITUSE_ALPHA_BASE: rtype = "BASE"; break; 1611 case LITUSE_ALPHA_BYTOFF: rtype = "BYTOFF"; break; 1612 case LITUSE_ALPHA_JSR: rtype = "JSR"; break; 1613 case LITUSE_ALPHA_TLSGD: rtype = "TLSGD"; break; 1614 case LITUSE_ALPHA_TLSLDM: rtype = "TLSLDM"; break; 1615 case LITUSE_ALPHA_JSRDIRECT: rtype = "JSRDIRECT"; break; 1616 default: rtype = NULL; 1617 } 1618 1619 if (rtype) 1620 printf (" (%s)", rtype); 1621 else 1622 { 1623 putchar (' '); 1624 printf (_("<unknown addend: %lx>"), 1625 (unsigned long) rels[i].r_addend); 1626 res = FALSE; 1627 } 1628 } 1629 else if (symtab_index) 1630 { 1631 if (symtab == NULL || symtab_index >= nsyms) 1632 { 1633 error (_(" bad symbol index: %08lx in reloc"), (unsigned long) symtab_index); 1634 res = FALSE; 1635 } 1636 else 1637 { 1638 Elf_Internal_Sym * psym; 1639 const char * version_string; 1640 enum versioned_symbol_info sym_info; 1641 unsigned short vna_other; 1642 1643 psym = symtab + symtab_index; 1644 1645 version_string 1646 = get_symbol_version_string (filedata, is_dynsym, 1647 strtab, strtablen, 1648 symtab_index, 1649 psym, 1650 &sym_info, 1651 &vna_other); 1652 1653 printf (" "); 1654 1655 if (ELF_ST_TYPE (psym->st_info) == STT_GNU_IFUNC) 1656 { 1657 const char * name; 1658 unsigned int len; 1659 unsigned int width = is_32bit_elf ? 8 : 14; 1660 1661 /* Relocations against GNU_IFUNC symbols do not use the value 1662 of the symbol as the address to relocate against. Instead 1663 they invoke the function named by the symbol and use its 1664 result as the address for relocation. 1665 1666 To indicate this to the user, do not display the value of 1667 the symbol in the "Symbols's Value" field. Instead show 1668 its name followed by () as a hint that the symbol is 1669 invoked. */ 1670 1671 if (strtab == NULL 1672 || psym->st_name == 0 1673 || psym->st_name >= strtablen) 1674 name = "??"; 1675 else 1676 name = strtab + psym->st_name; 1677 1678 len = print_symbol (width, name); 1679 if (version_string) 1680 printf (sym_info == symbol_public ? "@@%s" : "@%s", 1681 version_string); 1682 printf ("()%-*s", len <= width ? (width + 1) - len : 1, " "); 1683 } 1684 else 1685 { 1686 print_vma (psym->st_value, LONG_HEX); 1687 1688 printf (is_32bit_elf ? " " : " "); 1689 } 1690 1691 if (psym->st_name == 0) 1692 { 1693 const char * sec_name = "<null>"; 1694 char name_buf[40]; 1695 1696 if (ELF_ST_TYPE (psym->st_info) == STT_SECTION) 1697 { 1698 if (psym->st_shndx < filedata->file_header.e_shnum) 1699 sec_name = SECTION_NAME (filedata->section_headers + psym->st_shndx); 1700 else if (psym->st_shndx == SHN_ABS) 1701 sec_name = "ABS"; 1702 else if (psym->st_shndx == SHN_COMMON) 1703 sec_name = "COMMON"; 1704 else if ((filedata->file_header.e_machine == EM_MIPS 1705 && psym->st_shndx == SHN_MIPS_SCOMMON) 1706 || (filedata->file_header.e_machine == EM_TI_C6000 1707 && psym->st_shndx == SHN_TIC6X_SCOMMON)) 1708 sec_name = "SCOMMON"; 1709 else if (filedata->file_header.e_machine == EM_MIPS 1710 && psym->st_shndx == SHN_MIPS_SUNDEFINED) 1711 sec_name = "SUNDEF"; 1712 else if ((filedata->file_header.e_machine == EM_X86_64 1713 || filedata->file_header.e_machine == EM_L1OM 1714 || filedata->file_header.e_machine == EM_K1OM) 1715 && psym->st_shndx == SHN_X86_64_LCOMMON) 1716 sec_name = "LARGE_COMMON"; 1717 else if (filedata->file_header.e_machine == EM_IA_64 1718 && filedata->file_header.e_ident[EI_OSABI] == ELFOSABI_HPUX 1719 && psym->st_shndx == SHN_IA_64_ANSI_COMMON) 1720 sec_name = "ANSI_COM"; 1721 else if (is_ia64_vms (filedata) 1722 && psym->st_shndx == SHN_IA_64_VMS_SYMVEC) 1723 sec_name = "VMS_SYMVEC"; 1724 else 1725 { 1726 sprintf (name_buf, "<section 0x%x>", 1727 (unsigned int) psym->st_shndx); 1728 sec_name = name_buf; 1729 } 1730 } 1731 print_symbol (22, sec_name); 1732 } 1733 else if (strtab == NULL) 1734 printf (_("<string table index: %3ld>"), psym->st_name); 1735 else if (psym->st_name >= strtablen) 1736 { 1737 error (_("<corrupt string table index: %3ld>"), psym->st_name); 1738 res = FALSE; 1739 } 1740 else 1741 { 1742 print_symbol (22, strtab + psym->st_name); 1743 if (version_string) 1744 printf (sym_info == symbol_public ? "@@%s" : "@%s", 1745 version_string); 1746 } 1747 1748 if (is_rela) 1749 { 1750 bfd_vma off = rels[i].r_addend; 1751 1752 if ((bfd_signed_vma) off < 0) 1753 printf (" - %" BFD_VMA_FMT "x", - off); 1754 else 1755 printf (" + %" BFD_VMA_FMT "x", off); 1756 } 1757 } 1758 } 1759 else if (is_rela) 1760 { 1761 bfd_vma off = rels[i].r_addend; 1762 1763 printf ("%*c", is_32bit_elf ? 12 : 20, ' '); 1764 if ((bfd_signed_vma) off < 0) 1765 printf ("-%" BFD_VMA_FMT "x", - off); 1766 else 1767 printf ("%" BFD_VMA_FMT "x", off); 1768 } 1769 1770 if (filedata->file_header.e_machine == EM_SPARCV9 1771 && rtype != NULL 1772 && streq (rtype, "R_SPARC_OLO10")) 1773 printf (" + %lx", (unsigned long) ELF64_R_TYPE_DATA (inf)); 1774 1775 putchar ('\n'); 1776 1777 #ifdef BFD64 1778 if (! is_32bit_elf && filedata->file_header.e_machine == EM_MIPS) 1779 { 1780 bfd_vma type2 = ELF64_MIPS_R_TYPE2 (inf); 1781 bfd_vma type3 = ELF64_MIPS_R_TYPE3 (inf); 1782 const char * rtype2 = elf_mips_reloc_type (type2); 1783 const char * rtype3 = elf_mips_reloc_type (type3); 1784 1785 printf (" Type2: "); 1786 1787 if (rtype2 == NULL) 1788 printf (_("unrecognized: %-7lx"), 1789 (unsigned long) type2 & 0xffffffff); 1790 else 1791 printf ("%-17.17s", rtype2); 1792 1793 printf ("\n Type3: "); 1794 1795 if (rtype3 == NULL) 1796 printf (_("unrecognized: %-7lx"), 1797 (unsigned long) type3 & 0xffffffff); 1798 else 1799 printf ("%-17.17s", rtype3); 1800 1801 putchar ('\n'); 1802 } 1803 #endif /* BFD64 */ 1804 } 1805 1806 free (rels); 1807 1808 return res; 1809 } 1810 1811 static const char * 1812 get_aarch64_dynamic_type (unsigned long type) 1813 { 1814 switch (type) 1815 { 1816 case DT_AARCH64_BTI_PLT: return "AARCH64_BTI_PLT"; 1817 case DT_AARCH64_PAC_PLT: return "AARCH64_PAC_PLT"; 1818 case DT_AARCH64_VARIANT_PCS: return "AARCH64_VARIANT_PCS"; 1819 default: 1820 return NULL; 1821 } 1822 } 1823 1824 static const char * 1825 get_mips_dynamic_type (unsigned long type) 1826 { 1827 switch (type) 1828 { 1829 case DT_MIPS_RLD_VERSION: return "MIPS_RLD_VERSION"; 1830 case DT_MIPS_TIME_STAMP: return "MIPS_TIME_STAMP"; 1831 case DT_MIPS_ICHECKSUM: return "MIPS_ICHECKSUM"; 1832 case DT_MIPS_IVERSION: return "MIPS_IVERSION"; 1833 case DT_MIPS_FLAGS: return "MIPS_FLAGS"; 1834 case DT_MIPS_BASE_ADDRESS: return "MIPS_BASE_ADDRESS"; 1835 case DT_MIPS_MSYM: return "MIPS_MSYM"; 1836 case DT_MIPS_CONFLICT: return "MIPS_CONFLICT"; 1837 case DT_MIPS_LIBLIST: return "MIPS_LIBLIST"; 1838 case DT_MIPS_LOCAL_GOTNO: return "MIPS_LOCAL_GOTNO"; 1839 case DT_MIPS_CONFLICTNO: return "MIPS_CONFLICTNO"; 1840 case DT_MIPS_LIBLISTNO: return "MIPS_LIBLISTNO"; 1841 case DT_MIPS_SYMTABNO: return "MIPS_SYMTABNO"; 1842 case DT_MIPS_UNREFEXTNO: return "MIPS_UNREFEXTNO"; 1843 case DT_MIPS_GOTSYM: return "MIPS_GOTSYM"; 1844 case DT_MIPS_HIPAGENO: return "MIPS_HIPAGENO"; 1845 case DT_MIPS_RLD_MAP: return "MIPS_RLD_MAP"; 1846 case DT_MIPS_RLD_MAP_REL: return "MIPS_RLD_MAP_REL"; 1847 case DT_MIPS_DELTA_CLASS: return "MIPS_DELTA_CLASS"; 1848 case DT_MIPS_DELTA_CLASS_NO: return "MIPS_DELTA_CLASS_NO"; 1849 case DT_MIPS_DELTA_INSTANCE: return "MIPS_DELTA_INSTANCE"; 1850 case DT_MIPS_DELTA_INSTANCE_NO: return "MIPS_DELTA_INSTANCE_NO"; 1851 case DT_MIPS_DELTA_RELOC: return "MIPS_DELTA_RELOC"; 1852 case DT_MIPS_DELTA_RELOC_NO: return "MIPS_DELTA_RELOC_NO"; 1853 case DT_MIPS_DELTA_SYM: return "MIPS_DELTA_SYM"; 1854 case DT_MIPS_DELTA_SYM_NO: return "MIPS_DELTA_SYM_NO"; 1855 case DT_MIPS_DELTA_CLASSSYM: return "MIPS_DELTA_CLASSSYM"; 1856 case DT_MIPS_DELTA_CLASSSYM_NO: return "MIPS_DELTA_CLASSSYM_NO"; 1857 case DT_MIPS_CXX_FLAGS: return "MIPS_CXX_FLAGS"; 1858 case DT_MIPS_PIXIE_INIT: return "MIPS_PIXIE_INIT"; 1859 case DT_MIPS_SYMBOL_LIB: return "MIPS_SYMBOL_LIB"; 1860 case DT_MIPS_LOCALPAGE_GOTIDX: return "MIPS_LOCALPAGE_GOTIDX"; 1861 case DT_MIPS_LOCAL_GOTIDX: return "MIPS_LOCAL_GOTIDX"; 1862 case DT_MIPS_HIDDEN_GOTIDX: return "MIPS_HIDDEN_GOTIDX"; 1863 case DT_MIPS_PROTECTED_GOTIDX: return "MIPS_PROTECTED_GOTIDX"; 1864 case DT_MIPS_OPTIONS: return "MIPS_OPTIONS"; 1865 case DT_MIPS_INTERFACE: return "MIPS_INTERFACE"; 1866 case DT_MIPS_DYNSTR_ALIGN: return "MIPS_DYNSTR_ALIGN"; 1867 case DT_MIPS_INTERFACE_SIZE: return "MIPS_INTERFACE_SIZE"; 1868 case DT_MIPS_RLD_TEXT_RESOLVE_ADDR: return "MIPS_RLD_TEXT_RESOLVE_ADDR"; 1869 case DT_MIPS_PERF_SUFFIX: return "MIPS_PERF_SUFFIX"; 1870 case DT_MIPS_COMPACT_SIZE: return "MIPS_COMPACT_SIZE"; 1871 case DT_MIPS_GP_VALUE: return "MIPS_GP_VALUE"; 1872 case DT_MIPS_AUX_DYNAMIC: return "MIPS_AUX_DYNAMIC"; 1873 case DT_MIPS_PLTGOT: return "MIPS_PLTGOT"; 1874 case DT_MIPS_RWPLT: return "MIPS_RWPLT"; 1875 case DT_MIPS_XHASH: return "MIPS_XHASH"; 1876 default: 1877 return NULL; 1878 } 1879 } 1880 1881 static const char * 1882 get_sparc64_dynamic_type (unsigned long type) 1883 { 1884 switch (type) 1885 { 1886 case DT_SPARC_REGISTER: return "SPARC_REGISTER"; 1887 default: 1888 return NULL; 1889 } 1890 } 1891 1892 static const char * 1893 get_ppc_dynamic_type (unsigned long type) 1894 { 1895 switch (type) 1896 { 1897 case DT_PPC_GOT: return "PPC_GOT"; 1898 case DT_PPC_OPT: return "PPC_OPT"; 1899 default: 1900 return NULL; 1901 } 1902 } 1903 1904 static const char * 1905 get_ppc64_dynamic_type (unsigned long type) 1906 { 1907 switch (type) 1908 { 1909 case DT_PPC64_GLINK: return "PPC64_GLINK"; 1910 case DT_PPC64_OPD: return "PPC64_OPD"; 1911 case DT_PPC64_OPDSZ: return "PPC64_OPDSZ"; 1912 case DT_PPC64_OPT: return "PPC64_OPT"; 1913 default: 1914 return NULL; 1915 } 1916 } 1917 1918 static const char * 1919 get_parisc_dynamic_type (unsigned long type) 1920 { 1921 switch (type) 1922 { 1923 case DT_HP_LOAD_MAP: return "HP_LOAD_MAP"; 1924 case DT_HP_DLD_FLAGS: return "HP_DLD_FLAGS"; 1925 case DT_HP_DLD_HOOK: return "HP_DLD_HOOK"; 1926 case DT_HP_UX10_INIT: return "HP_UX10_INIT"; 1927 case DT_HP_UX10_INITSZ: return "HP_UX10_INITSZ"; 1928 case DT_HP_PREINIT: return "HP_PREINIT"; 1929 case DT_HP_PREINITSZ: return "HP_PREINITSZ"; 1930 case DT_HP_NEEDED: return "HP_NEEDED"; 1931 case DT_HP_TIME_STAMP: return "HP_TIME_STAMP"; 1932 case DT_HP_CHECKSUM: return "HP_CHECKSUM"; 1933 case DT_HP_GST_SIZE: return "HP_GST_SIZE"; 1934 case DT_HP_GST_VERSION: return "HP_GST_VERSION"; 1935 case DT_HP_GST_HASHVAL: return "HP_GST_HASHVAL"; 1936 case DT_HP_EPLTREL: return "HP_GST_EPLTREL"; 1937 case DT_HP_EPLTRELSZ: return "HP_GST_EPLTRELSZ"; 1938 case DT_HP_FILTERED: return "HP_FILTERED"; 1939 case DT_HP_FILTER_TLS: return "HP_FILTER_TLS"; 1940 case DT_HP_COMPAT_FILTERED: return "HP_COMPAT_FILTERED"; 1941 case DT_HP_LAZYLOAD: return "HP_LAZYLOAD"; 1942 case DT_HP_BIND_NOW_COUNT: return "HP_BIND_NOW_COUNT"; 1943 case DT_PLT: return "PLT"; 1944 case DT_PLT_SIZE: return "PLT_SIZE"; 1945 case DT_DLT: return "DLT"; 1946 case DT_DLT_SIZE: return "DLT_SIZE"; 1947 default: 1948 return NULL; 1949 } 1950 } 1951 1952 static const char * 1953 get_ia64_dynamic_type (unsigned long type) 1954 { 1955 switch (type) 1956 { 1957 case DT_IA_64_PLT_RESERVE: return "IA_64_PLT_RESERVE"; 1958 case DT_IA_64_VMS_SUBTYPE: return "VMS_SUBTYPE"; 1959 case DT_IA_64_VMS_IMGIOCNT: return "VMS_IMGIOCNT"; 1960 case DT_IA_64_VMS_LNKFLAGS: return "VMS_LNKFLAGS"; 1961 case DT_IA_64_VMS_VIR_MEM_BLK_SIZ: return "VMS_VIR_MEM_BLK_SIZ"; 1962 case DT_IA_64_VMS_IDENT: return "VMS_IDENT"; 1963 case DT_IA_64_VMS_NEEDED_IDENT: return "VMS_NEEDED_IDENT"; 1964 case DT_IA_64_VMS_IMG_RELA_CNT: return "VMS_IMG_RELA_CNT"; 1965 case DT_IA_64_VMS_SEG_RELA_CNT: return "VMS_SEG_RELA_CNT"; 1966 case DT_IA_64_VMS_FIXUP_RELA_CNT: return "VMS_FIXUP_RELA_CNT"; 1967 case DT_IA_64_VMS_FIXUP_NEEDED: return "VMS_FIXUP_NEEDED"; 1968 case DT_IA_64_VMS_SYMVEC_CNT: return "VMS_SYMVEC_CNT"; 1969 case DT_IA_64_VMS_XLATED: return "VMS_XLATED"; 1970 case DT_IA_64_VMS_STACKSIZE: return "VMS_STACKSIZE"; 1971 case DT_IA_64_VMS_UNWINDSZ: return "VMS_UNWINDSZ"; 1972 case DT_IA_64_VMS_UNWIND_CODSEG: return "VMS_UNWIND_CODSEG"; 1973 case DT_IA_64_VMS_UNWIND_INFOSEG: return "VMS_UNWIND_INFOSEG"; 1974 case DT_IA_64_VMS_LINKTIME: return "VMS_LINKTIME"; 1975 case DT_IA_64_VMS_SEG_NO: return "VMS_SEG_NO"; 1976 case DT_IA_64_VMS_SYMVEC_OFFSET: return "VMS_SYMVEC_OFFSET"; 1977 case DT_IA_64_VMS_SYMVEC_SEG: return "VMS_SYMVEC_SEG"; 1978 case DT_IA_64_VMS_UNWIND_OFFSET: return "VMS_UNWIND_OFFSET"; 1979 case DT_IA_64_VMS_UNWIND_SEG: return "VMS_UNWIND_SEG"; 1980 case DT_IA_64_VMS_STRTAB_OFFSET: return "VMS_STRTAB_OFFSET"; 1981 case DT_IA_64_VMS_SYSVER_OFFSET: return "VMS_SYSVER_OFFSET"; 1982 case DT_IA_64_VMS_IMG_RELA_OFF: return "VMS_IMG_RELA_OFF"; 1983 case DT_IA_64_VMS_SEG_RELA_OFF: return "VMS_SEG_RELA_OFF"; 1984 case DT_IA_64_VMS_FIXUP_RELA_OFF: return "VMS_FIXUP_RELA_OFF"; 1985 case DT_IA_64_VMS_PLTGOT_OFFSET: return "VMS_PLTGOT_OFFSET"; 1986 case DT_IA_64_VMS_PLTGOT_SEG: return "VMS_PLTGOT_SEG"; 1987 case DT_IA_64_VMS_FPMODE: return "VMS_FPMODE"; 1988 default: 1989 return NULL; 1990 } 1991 } 1992 1993 static const char * 1994 get_solaris_section_type (unsigned long type) 1995 { 1996 switch (type) 1997 { 1998 case 0x6fffffee: return "SUNW_ancillary"; 1999 case 0x6fffffef: return "SUNW_capchain"; 2000 case 0x6ffffff0: return "SUNW_capinfo"; 2001 case 0x6ffffff1: return "SUNW_symsort"; 2002 case 0x6ffffff2: return "SUNW_tlssort"; 2003 case 0x6ffffff3: return "SUNW_LDYNSYM"; 2004 case 0x6ffffff4: return "SUNW_dof"; 2005 case 0x6ffffff5: return "SUNW_cap"; 2006 case 0x6ffffff6: return "SUNW_SIGNATURE"; 2007 case 0x6ffffff7: return "SUNW_ANNOTATE"; 2008 case 0x6ffffff8: return "SUNW_DEBUGSTR"; 2009 case 0x6ffffff9: return "SUNW_DEBUG"; 2010 case 0x6ffffffa: return "SUNW_move"; 2011 case 0x6ffffffb: return "SUNW_COMDAT"; 2012 case 0x6ffffffc: return "SUNW_syminfo"; 2013 case 0x6ffffffd: return "SUNW_verdef"; 2014 case 0x6ffffffe: return "SUNW_verneed"; 2015 case 0x6fffffff: return "SUNW_versym"; 2016 case 0x70000000: return "SPARC_GOTDATA"; 2017 default: return NULL; 2018 } 2019 } 2020 2021 static const char * 2022 get_alpha_dynamic_type (unsigned long type) 2023 { 2024 switch (type) 2025 { 2026 case DT_ALPHA_PLTRO: return "ALPHA_PLTRO"; 2027 default: return NULL; 2028 } 2029 } 2030 2031 static const char * 2032 get_score_dynamic_type (unsigned long type) 2033 { 2034 switch (type) 2035 { 2036 case DT_SCORE_BASE_ADDRESS: return "SCORE_BASE_ADDRESS"; 2037 case DT_SCORE_LOCAL_GOTNO: return "SCORE_LOCAL_GOTNO"; 2038 case DT_SCORE_SYMTABNO: return "SCORE_SYMTABNO"; 2039 case DT_SCORE_GOTSYM: return "SCORE_GOTSYM"; 2040 case DT_SCORE_UNREFEXTNO: return "SCORE_UNREFEXTNO"; 2041 case DT_SCORE_HIPAGENO: return "SCORE_HIPAGENO"; 2042 default: return NULL; 2043 } 2044 } 2045 2046 static const char * 2047 get_tic6x_dynamic_type (unsigned long type) 2048 { 2049 switch (type) 2050 { 2051 case DT_C6000_GSYM_OFFSET: return "C6000_GSYM_OFFSET"; 2052 case DT_C6000_GSTR_OFFSET: return "C6000_GSTR_OFFSET"; 2053 case DT_C6000_DSBT_BASE: return "C6000_DSBT_BASE"; 2054 case DT_C6000_DSBT_SIZE: return "C6000_DSBT_SIZE"; 2055 case DT_C6000_PREEMPTMAP: return "C6000_PREEMPTMAP"; 2056 case DT_C6000_DSBT_INDEX: return "C6000_DSBT_INDEX"; 2057 default: return NULL; 2058 } 2059 } 2060 2061 static const char * 2062 get_nios2_dynamic_type (unsigned long type) 2063 { 2064 switch (type) 2065 { 2066 case DT_NIOS2_GP: return "NIOS2_GP"; 2067 default: return NULL; 2068 } 2069 } 2070 2071 static const char * 2072 get_solaris_dynamic_type (unsigned long type) 2073 { 2074 switch (type) 2075 { 2076 case 0x6000000d: return "SUNW_AUXILIARY"; 2077 case 0x6000000e: return "SUNW_RTLDINF"; 2078 case 0x6000000f: return "SUNW_FILTER"; 2079 case 0x60000010: return "SUNW_CAP"; 2080 case 0x60000011: return "SUNW_SYMTAB"; 2081 case 0x60000012: return "SUNW_SYMSZ"; 2082 case 0x60000013: return "SUNW_SORTENT"; 2083 case 0x60000014: return "SUNW_SYMSORT"; 2084 case 0x60000015: return "SUNW_SYMSORTSZ"; 2085 case 0x60000016: return "SUNW_TLSSORT"; 2086 case 0x60000017: return "SUNW_TLSSORTSZ"; 2087 case 0x60000018: return "SUNW_CAPINFO"; 2088 case 0x60000019: return "SUNW_STRPAD"; 2089 case 0x6000001a: return "SUNW_CAPCHAIN"; 2090 case 0x6000001b: return "SUNW_LDMACH"; 2091 case 0x6000001d: return "SUNW_CAPCHAINENT"; 2092 case 0x6000001f: return "SUNW_CAPCHAINSZ"; 2093 case 0x60000021: return "SUNW_PARENT"; 2094 case 0x60000023: return "SUNW_ASLR"; 2095 case 0x60000025: return "SUNW_RELAX"; 2096 case 0x60000029: return "SUNW_NXHEAP"; 2097 case 0x6000002b: return "SUNW_NXSTACK"; 2098 2099 case 0x70000001: return "SPARC_REGISTER"; 2100 case 0x7ffffffd: return "AUXILIARY"; 2101 case 0x7ffffffe: return "USED"; 2102 case 0x7fffffff: return "FILTER"; 2103 2104 default: return NULL; 2105 } 2106 } 2107 2108 static const char * 2109 get_dynamic_type (Filedata * filedata, unsigned long type) 2110 { 2111 static char buff[64]; 2112 2113 switch (type) 2114 { 2115 case DT_NULL: return "NULL"; 2116 case DT_NEEDED: return "NEEDED"; 2117 case DT_PLTRELSZ: return "PLTRELSZ"; 2118 case DT_PLTGOT: return "PLTGOT"; 2119 case DT_HASH: return "HASH"; 2120 case DT_STRTAB: return "STRTAB"; 2121 case DT_SYMTAB: return "SYMTAB"; 2122 case DT_RELA: return "RELA"; 2123 case DT_RELASZ: return "RELASZ"; 2124 case DT_RELAENT: return "RELAENT"; 2125 case DT_STRSZ: return "STRSZ"; 2126 case DT_SYMENT: return "SYMENT"; 2127 case DT_INIT: return "INIT"; 2128 case DT_FINI: return "FINI"; 2129 case DT_SONAME: return "SONAME"; 2130 case DT_RPATH: return "RPATH"; 2131 case DT_SYMBOLIC: return "SYMBOLIC"; 2132 case DT_REL: return "REL"; 2133 case DT_RELSZ: return "RELSZ"; 2134 case DT_RELENT: return "RELENT"; 2135 case DT_PLTREL: return "PLTREL"; 2136 case DT_DEBUG: return "DEBUG"; 2137 case DT_TEXTREL: return "TEXTREL"; 2138 case DT_JMPREL: return "JMPREL"; 2139 case DT_BIND_NOW: return "BIND_NOW"; 2140 case DT_INIT_ARRAY: return "INIT_ARRAY"; 2141 case DT_FINI_ARRAY: return "FINI_ARRAY"; 2142 case DT_INIT_ARRAYSZ: return "INIT_ARRAYSZ"; 2143 case DT_FINI_ARRAYSZ: return "FINI_ARRAYSZ"; 2144 case DT_RUNPATH: return "RUNPATH"; 2145 case DT_FLAGS: return "FLAGS"; 2146 2147 case DT_PREINIT_ARRAY: return "PREINIT_ARRAY"; 2148 case DT_PREINIT_ARRAYSZ: return "PREINIT_ARRAYSZ"; 2149 case DT_SYMTAB_SHNDX: return "SYMTAB_SHNDX"; 2150 2151 case DT_CHECKSUM: return "CHECKSUM"; 2152 case DT_PLTPADSZ: return "PLTPADSZ"; 2153 case DT_MOVEENT: return "MOVEENT"; 2154 case DT_MOVESZ: return "MOVESZ"; 2155 case DT_FEATURE: return "FEATURE"; 2156 case DT_POSFLAG_1: return "POSFLAG_1"; 2157 case DT_SYMINSZ: return "SYMINSZ"; 2158 case DT_SYMINENT: return "SYMINENT"; /* aka VALRNGHI */ 2159 2160 case DT_ADDRRNGLO: return "ADDRRNGLO"; 2161 case DT_CONFIG: return "CONFIG"; 2162 case DT_DEPAUDIT: return "DEPAUDIT"; 2163 case DT_AUDIT: return "AUDIT"; 2164 case DT_PLTPAD: return "PLTPAD"; 2165 case DT_MOVETAB: return "MOVETAB"; 2166 case DT_SYMINFO: return "SYMINFO"; /* aka ADDRRNGHI */ 2167 2168 case DT_VERSYM: return "VERSYM"; 2169 2170 case DT_TLSDESC_GOT: return "TLSDESC_GOT"; 2171 case DT_TLSDESC_PLT: return "TLSDESC_PLT"; 2172 case DT_RELACOUNT: return "RELACOUNT"; 2173 case DT_RELCOUNT: return "RELCOUNT"; 2174 case DT_FLAGS_1: return "FLAGS_1"; 2175 case DT_VERDEF: return "VERDEF"; 2176 case DT_VERDEFNUM: return "VERDEFNUM"; 2177 case DT_VERNEED: return "VERNEED"; 2178 case DT_VERNEEDNUM: return "VERNEEDNUM"; 2179 2180 case DT_AUXILIARY: return "AUXILIARY"; 2181 case DT_USED: return "USED"; 2182 case DT_FILTER: return "FILTER"; 2183 2184 case DT_GNU_PRELINKED: return "GNU_PRELINKED"; 2185 case DT_GNU_CONFLICT: return "GNU_CONFLICT"; 2186 case DT_GNU_CONFLICTSZ: return "GNU_CONFLICTSZ"; 2187 case DT_GNU_LIBLIST: return "GNU_LIBLIST"; 2188 case DT_GNU_LIBLISTSZ: return "GNU_LIBLISTSZ"; 2189 case DT_GNU_HASH: return "GNU_HASH"; 2190 2191 default: 2192 if ((type >= DT_LOPROC) && (type <= DT_HIPROC)) 2193 { 2194 const char * result; 2195 2196 switch (filedata->file_header.e_machine) 2197 { 2198 case EM_AARCH64: 2199 result = get_aarch64_dynamic_type (type); 2200 break; 2201 case EM_MIPS: 2202 case EM_MIPS_RS3_LE: 2203 result = get_mips_dynamic_type (type); 2204 break; 2205 case EM_SPARCV9: 2206 result = get_sparc64_dynamic_type (type); 2207 break; 2208 case EM_PPC: 2209 result = get_ppc_dynamic_type (type); 2210 break; 2211 case EM_PPC64: 2212 result = get_ppc64_dynamic_type (type); 2213 break; 2214 case EM_IA_64: 2215 result = get_ia64_dynamic_type (type); 2216 break; 2217 case EM_ALPHA: 2218 result = get_alpha_dynamic_type (type); 2219 break; 2220 case EM_SCORE: 2221 result = get_score_dynamic_type (type); 2222 break; 2223 case EM_TI_C6000: 2224 result = get_tic6x_dynamic_type (type); 2225 break; 2226 case EM_ALTERA_NIOS2: 2227 result = get_nios2_dynamic_type (type); 2228 break; 2229 default: 2230 if (filedata->file_header.e_ident[EI_OSABI] == ELFOSABI_SOLARIS) 2231 result = get_solaris_dynamic_type (type); 2232 else 2233 result = NULL; 2234 break; 2235 } 2236 2237 if (result != NULL) 2238 return result; 2239 2240 snprintf (buff, sizeof (buff), _("Processor Specific: %lx"), type); 2241 } 2242 else if (((type >= DT_LOOS) && (type <= DT_HIOS)) 2243 || (filedata->file_header.e_machine == EM_PARISC 2244 && (type >= OLD_DT_LOOS) && (type <= OLD_DT_HIOS))) 2245 { 2246 const char * result; 2247 2248 switch (filedata->file_header.e_machine) 2249 { 2250 case EM_PARISC: 2251 result = get_parisc_dynamic_type (type); 2252 break; 2253 case EM_IA_64: 2254 result = get_ia64_dynamic_type (type); 2255 break; 2256 default: 2257 if (filedata->file_header.e_ident[EI_OSABI] == ELFOSABI_SOLARIS) 2258 result = get_solaris_dynamic_type (type); 2259 else 2260 result = NULL; 2261 break; 2262 } 2263 2264 if (result != NULL) 2265 return result; 2266 2267 snprintf (buff, sizeof (buff), _("Operating System specific: %lx"), 2268 type); 2269 } 2270 else 2271 snprintf (buff, sizeof (buff), _("<unknown>: %lx"), type); 2272 2273 return buff; 2274 } 2275 } 2276 2277 static char * 2278 get_file_type (unsigned e_type) 2279 { 2280 static char buff[32]; 2281 2282 switch (e_type) 2283 { 2284 case ET_NONE: return _("NONE (None)"); 2285 case ET_REL: return _("REL (Relocatable file)"); 2286 case ET_EXEC: return _("EXEC (Executable file)"); 2287 case ET_DYN: return _("DYN (Shared object file)"); 2288 case ET_CORE: return _("CORE (Core file)"); 2289 2290 default: 2291 if ((e_type >= ET_LOPROC) && (e_type <= ET_HIPROC)) 2292 snprintf (buff, sizeof (buff), _("Processor Specific: (%x)"), e_type); 2293 else if ((e_type >= ET_LOOS) && (e_type <= ET_HIOS)) 2294 snprintf (buff, sizeof (buff), _("OS Specific: (%x)"), e_type); 2295 else 2296 snprintf (buff, sizeof (buff), _("<unknown>: %x"), e_type); 2297 return buff; 2298 } 2299 } 2300 2301 static char * 2302 get_machine_name (unsigned e_machine) 2303 { 2304 static char buff[64]; /* XXX */ 2305 2306 switch (e_machine) 2307 { 2308 /* Please keep this switch table sorted by increasing EM_ value. */ 2309 /* 0 */ 2310 case EM_NONE: return _("None"); 2311 case EM_M32: return "WE32100"; 2312 case EM_SPARC: return "Sparc"; 2313 case EM_386: return "Intel 80386"; 2314 case EM_68K: return "MC68000"; 2315 case EM_88K: return "MC88000"; 2316 case EM_IAMCU: return "Intel MCU"; 2317 case EM_860: return "Intel 80860"; 2318 case EM_MIPS: return "MIPS R3000"; 2319 case EM_S370: return "IBM System/370"; 2320 /* 10 */ 2321 case EM_MIPS_RS3_LE: return "MIPS R4000 big-endian"; 2322 case EM_OLD_SPARCV9: return "Sparc v9 (old)"; 2323 case EM_PARISC: return "HPPA"; 2324 case EM_VPP550: return "Fujitsu VPP500"; 2325 case EM_SPARC32PLUS: return "Sparc v8+" ; 2326 case EM_960: return "Intel 80960"; 2327 case EM_PPC: return "PowerPC"; 2328 /* 20 */ 2329 case EM_PPC64: return "PowerPC64"; 2330 case EM_S390_OLD: 2331 case EM_S390: return "IBM S/390"; 2332 case EM_SPU: return "SPU"; 2333 /* 30 */ 2334 case EM_V800: return "Renesas V850 (using RH850 ABI)"; 2335 case EM_FR20: return "Fujitsu FR20"; 2336 case EM_RH32: return "TRW RH32"; 2337 case EM_MCORE: return "MCORE"; 2338 /* 40 */ 2339 case EM_ARM: return "ARM"; 2340 case EM_OLD_ALPHA: return "Digital Alpha (old)"; 2341 case EM_SH: return "Renesas / SuperH SH"; 2342 case EM_SPARCV9: return "Sparc v9"; 2343 case EM_TRICORE: return "Siemens Tricore"; 2344 case EM_ARC: return "ARC"; 2345 case EM_H8_300: return "Renesas H8/300"; 2346 case EM_H8_300H: return "Renesas H8/300H"; 2347 case EM_H8S: return "Renesas H8S"; 2348 case EM_H8_500: return "Renesas H8/500"; 2349 /* 50 */ 2350 case EM_IA_64: return "Intel IA-64"; 2351 case EM_MIPS_X: return "Stanford MIPS-X"; 2352 case EM_COLDFIRE: return "Motorola Coldfire"; 2353 case EM_68HC12: return "Motorola MC68HC12 Microcontroller"; 2354 case EM_MMA: return "Fujitsu Multimedia Accelerator"; 2355 case EM_PCP: return "Siemens PCP"; 2356 case EM_NCPU: return "Sony nCPU embedded RISC processor"; 2357 case EM_NDR1: return "Denso NDR1 microprocesspr"; 2358 case EM_STARCORE: return "Motorola Star*Core processor"; 2359 case EM_ME16: return "Toyota ME16 processor"; 2360 /* 60 */ 2361 case EM_ST100: return "STMicroelectronics ST100 processor"; 2362 case EM_TINYJ: return "Advanced Logic Corp. TinyJ embedded processor"; 2363 case EM_X86_64: return "Advanced Micro Devices X86-64"; 2364 case EM_PDSP: return "Sony DSP processor"; 2365 case EM_PDP10: return "Digital Equipment Corp. PDP-10"; 2366 case EM_PDP11: return "Digital Equipment Corp. PDP-11"; 2367 case EM_FX66: return "Siemens FX66 microcontroller"; 2368 case EM_ST9PLUS: return "STMicroelectronics ST9+ 8/16 bit microcontroller"; 2369 case EM_ST7: return "STMicroelectronics ST7 8-bit microcontroller"; 2370 case EM_68HC16: return "Motorola MC68HC16 Microcontroller"; 2371 /* 70 */ 2372 case EM_68HC11: return "Motorola MC68HC11 Microcontroller"; 2373 case EM_68HC08: return "Motorola MC68HC08 Microcontroller"; 2374 case EM_68HC05: return "Motorola MC68HC05 Microcontroller"; 2375 case EM_SVX: return "Silicon Graphics SVx"; 2376 case EM_ST19: return "STMicroelectronics ST19 8-bit microcontroller"; 2377 case EM_VAX: return "Digital VAX"; 2378 case EM_CRIS: return "Axis Communications 32-bit embedded processor"; 2379 case EM_JAVELIN: return "Infineon Technologies 32-bit embedded cpu"; 2380 case EM_FIREPATH: return "Element 14 64-bit DSP processor"; 2381 case EM_ZSP: return "LSI Logic's 16-bit DSP processor"; 2382 /* 80 */ 2383 case EM_MMIX: return "Donald Knuth's educational 64-bit processor"; 2384 case EM_HUANY: return "Harvard Universitys's machine-independent object format"; 2385 case EM_PRISM: return "Vitesse Prism"; 2386 case EM_AVR_OLD: 2387 case EM_AVR: return "Atmel AVR 8-bit microcontroller"; 2388 case EM_CYGNUS_FR30: 2389 case EM_FR30: return "Fujitsu FR30"; 2390 case EM_CYGNUS_D10V: 2391 case EM_D10V: return "d10v"; 2392 case EM_CYGNUS_D30V: 2393 case EM_D30V: return "d30v"; 2394 case EM_CYGNUS_V850: 2395 case EM_V850: return "Renesas V850"; 2396 case EM_CYGNUS_M32R: 2397 case EM_M32R: return "Renesas M32R (formerly Mitsubishi M32r)"; 2398 case EM_CYGNUS_MN10300: 2399 case EM_MN10300: return "mn10300"; 2400 /* 90 */ 2401 case EM_CYGNUS_MN10200: 2402 case EM_MN10200: return "mn10200"; 2403 case EM_PJ: return "picoJava"; 2404 case EM_OR1K: return "OpenRISC 1000"; 2405 case EM_ARC_COMPACT: return "ARCompact"; 2406 case EM_XTENSA_OLD: 2407 case EM_XTENSA: return "Tensilica Xtensa Processor"; 2408 case EM_VIDEOCORE: return "Alphamosaic VideoCore processor"; 2409 case EM_TMM_GPP: return "Thompson Multimedia General Purpose Processor"; 2410 case EM_NS32K: return "National Semiconductor 32000 series"; 2411 case EM_TPC: return "Tenor Network TPC processor"; 2412 case EM_SNP1K: return "Trebia SNP 1000 processor"; 2413 /* 100 */ 2414 case EM_ST200: return "STMicroelectronics ST200 microcontroller"; 2415 case EM_IP2K_OLD: 2416 case EM_IP2K: return "Ubicom IP2xxx 8-bit microcontrollers"; 2417 case EM_MAX: return "MAX Processor"; 2418 case EM_CR: return "National Semiconductor CompactRISC"; 2419 case EM_F2MC16: return "Fujitsu F2MC16"; 2420 case EM_MSP430: return "Texas Instruments msp430 microcontroller"; 2421 case EM_BLACKFIN: return "Analog Devices Blackfin"; 2422 case EM_SE_C33: return "S1C33 Family of Seiko Epson processors"; 2423 case EM_SEP: return "Sharp embedded microprocessor"; 2424 case EM_ARCA: return "Arca RISC microprocessor"; 2425 /* 110 */ 2426 case EM_UNICORE: return "Unicore"; 2427 case EM_EXCESS: return "eXcess 16/32/64-bit configurable embedded CPU"; 2428 case EM_DXP: return "Icera Semiconductor Inc. Deep Execution Processor"; 2429 case EM_ALTERA_NIOS2: return "Altera Nios II"; 2430 case EM_CRX: return "National Semiconductor CRX microprocessor"; 2431 case EM_XGATE: return "Motorola XGATE embedded processor"; 2432 case EM_C166: 2433 case EM_XC16X: return "Infineon Technologies xc16x"; 2434 case EM_M16C: return "Renesas M16C series microprocessors"; 2435 case EM_DSPIC30F: return "Microchip Technology dsPIC30F Digital Signal Controller"; 2436 case EM_CE: return "Freescale Communication Engine RISC core"; 2437 /* 120 */ 2438 case EM_M32C: return "Renesas M32c"; 2439 /* 130 */ 2440 case EM_TSK3000: return "Altium TSK3000 core"; 2441 case EM_RS08: return "Freescale RS08 embedded processor"; 2442 case EM_ECOG2: return "Cyan Technology eCOG2 microprocessor"; 2443 case EM_SCORE: return "SUNPLUS S+Core"; 2444 case EM_DSP24: return "New Japan Radio (NJR) 24-bit DSP Processor"; 2445 case EM_VIDEOCORE3: return "Broadcom VideoCore III processor"; 2446 case EM_LATTICEMICO32: return "Lattice Mico32"; 2447 case EM_SE_C17: return "Seiko Epson C17 family"; 2448 /* 140 */ 2449 case EM_TI_C6000: return "Texas Instruments TMS320C6000 DSP family"; 2450 case EM_TI_C2000: return "Texas Instruments TMS320C2000 DSP family"; 2451 case EM_TI_C5500: return "Texas Instruments TMS320C55x DSP family"; 2452 case EM_TI_PRU: return "TI PRU I/O processor"; 2453 /* 160 */ 2454 case EM_MMDSP_PLUS: return "STMicroelectronics 64bit VLIW Data Signal Processor"; 2455 case EM_CYPRESS_M8C: return "Cypress M8C microprocessor"; 2456 case EM_R32C: return "Renesas R32C series microprocessors"; 2457 case EM_TRIMEDIA: return "NXP Semiconductors TriMedia architecture family"; 2458 case EM_QDSP6: return "QUALCOMM DSP6 Processor"; 2459 case EM_8051: return "Intel 8051 and variants"; 2460 case EM_STXP7X: return "STMicroelectronics STxP7x family"; 2461 case EM_NDS32: return "Andes Technology compact code size embedded RISC processor family"; 2462 case EM_ECOG1X: return "Cyan Technology eCOG1X family"; 2463 case EM_MAXQ30: return "Dallas Semiconductor MAXQ30 Core microcontrollers"; 2464 /* 170 */ 2465 case EM_XIMO16: return "New Japan Radio (NJR) 16-bit DSP Processor"; 2466 case EM_MANIK: return "M2000 Reconfigurable RISC Microprocessor"; 2467 case EM_CRAYNV2: return "Cray Inc. NV2 vector architecture"; 2468 case EM_RX: return "Renesas RX"; 2469 case EM_METAG: return "Imagination Technologies Meta processor architecture"; 2470 case EM_MCST_ELBRUS: return "MCST Elbrus general purpose hardware architecture"; 2471 case EM_ECOG16: return "Cyan Technology eCOG16 family"; 2472 case EM_CR16: 2473 case EM_MICROBLAZE: 2474 case EM_MICROBLAZE_OLD: return "Xilinx MicroBlaze"; 2475 case EM_ETPU: return "Freescale Extended Time Processing Unit"; 2476 case EM_SLE9X: return "Infineon Technologies SLE9X core"; 2477 /* 180 */ 2478 case EM_L1OM: return "Intel L1OM"; 2479 case EM_K1OM: return "Intel K1OM"; 2480 case EM_INTEL182: return "Intel (reserved)"; 2481 case EM_AARCH64: return "AArch64"; 2482 case EM_ARM184: return "ARM (reserved)"; 2483 case EM_AVR32: return "Atmel Corporation 32-bit microprocessor"; 2484 case EM_STM8: return "STMicroeletronics STM8 8-bit microcontroller"; 2485 case EM_TILE64: return "Tilera TILE64 multicore architecture family"; 2486 case EM_TILEPRO: return "Tilera TILEPro multicore architecture family"; 2487 /* 190 */ 2488 case EM_CUDA: return "NVIDIA CUDA architecture"; 2489 case EM_TILEGX: return "Tilera TILE-Gx multicore architecture family"; 2490 case EM_CLOUDSHIELD: return "CloudShield architecture family"; 2491 case EM_COREA_1ST: return "KIPO-KAIST Core-A 1st generation processor family"; 2492 case EM_COREA_2ND: return "KIPO-KAIST Core-A 2nd generation processor family"; 2493 case EM_ARC_COMPACT2: return "ARCv2"; 2494 case EM_OPEN8: return "Open8 8-bit RISC soft processor core"; 2495 case EM_RL78: return "Renesas RL78"; 2496 case EM_VIDEOCORE5: return "Broadcom VideoCore V processor"; 2497 case EM_78K0R: return "Renesas 78K0R"; 2498 /* 200 */ 2499 case EM_56800EX: return "Freescale 56800EX Digital Signal Controller (DSC)"; 2500 case EM_BA1: return "Beyond BA1 CPU architecture"; 2501 case EM_BA2: return "Beyond BA2 CPU architecture"; 2502 case EM_XCORE: return "XMOS xCORE processor family"; 2503 case EM_MCHP_PIC: return "Microchip 8-bit PIC(r) family"; 2504 /* 210 */ 2505 case EM_KM32: return "KM211 KM32 32-bit processor"; 2506 case EM_KMX32: return "KM211 KMX32 32-bit processor"; 2507 case EM_KMX16: return "KM211 KMX16 16-bit processor"; 2508 case EM_KMX8: return "KM211 KMX8 8-bit processor"; 2509 case EM_KVARC: return "KM211 KVARC processor"; 2510 case EM_CDP: return "Paneve CDP architecture family"; 2511 case EM_COGE: return "Cognitive Smart Memory Processor"; 2512 case EM_COOL: return "Bluechip Systems CoolEngine"; 2513 case EM_NORC: return "Nanoradio Optimized RISC"; 2514 case EM_CSR_KALIMBA: return "CSR Kalimba architecture family"; 2515 /* 220 */ 2516 case EM_Z80: return "Zilog Z80"; 2517 case EM_VISIUM: return "CDS VISIUMcore processor"; 2518 case EM_FT32: return "FTDI Chip FT32"; 2519 case EM_MOXIE: return "Moxie"; 2520 case EM_AMDGPU: return "AMD GPU"; 2521 case EM_RISCV: return "RISC-V"; 2522 case EM_LANAI: return "Lanai 32-bit processor"; 2523 case EM_BPF: return "Linux BPF"; 2524 case EM_NFP: return "Netronome Flow Processor"; 2525 2526 /* Large numbers... */ 2527 case EM_MT: return "Morpho Techologies MT processor"; 2528 case EM_ALPHA: return "Alpha"; 2529 case EM_WEBASSEMBLY: return "Web Assembly"; 2530 case EM_DLX: return "OpenDLX"; 2531 case EM_XSTORMY16: return "Sanyo XStormy16 CPU core"; 2532 case EM_IQ2000: return "Vitesse IQ2000"; 2533 case EM_M32C_OLD: 2534 case EM_NIOS32: return "Altera Nios"; 2535 case EM_CYGNUS_MEP: return "Toshiba MeP Media Engine"; 2536 case EM_ADAPTEVA_EPIPHANY: return "Adapteva EPIPHANY"; 2537 case EM_CYGNUS_FRV: return "Fujitsu FR-V"; 2538 case EM_S12Z: return "Freescale S12Z"; 2539 case EM_CSKY: return "C-SKY"; 2540 2541 default: 2542 snprintf (buff, sizeof (buff), _("<unknown>: 0x%x"), e_machine); 2543 return buff; 2544 } 2545 } 2546 2547 static void 2548 decode_ARC_machine_flags (unsigned e_flags, unsigned e_machine, char buf[]) 2549 { 2550 /* ARC has two machine types EM_ARC_COMPACT and EM_ARC_COMPACT2. Some 2551 other compilers don't a specific architecture type in the e_flags, and 2552 instead use EM_ARC_COMPACT for old ARC600, ARC601, and ARC700 2553 architectures, and switch to EM_ARC_COMPACT2 for newer ARCEM and ARCHS 2554 architectures. 2555 2556 Th GNU tools follows this use of EM_ARC_COMPACT and EM_ARC_COMPACT2, 2557 but also sets a specific architecture type in the e_flags field. 2558 2559 However, when decoding the flags we don't worry if we see an 2560 unexpected pairing, for example EM_ARC_COMPACT machine type, with 2561 ARCEM architecture type. */ 2562 2563 switch (e_flags & EF_ARC_MACH_MSK) 2564 { 2565 /* We only expect these to occur for EM_ARC_COMPACT2. */ 2566 case EF_ARC_CPU_ARCV2EM: 2567 strcat (buf, ", ARC EM"); 2568 break; 2569 case EF_ARC_CPU_ARCV2HS: 2570 strcat (buf, ", ARC HS"); 2571 break; 2572 2573 /* We only expect these to occur for EM_ARC_COMPACT. */ 2574 case E_ARC_MACH_ARC600: 2575 strcat (buf, ", ARC600"); 2576 break; 2577 case E_ARC_MACH_ARC601: 2578 strcat (buf, ", ARC601"); 2579 break; 2580 case E_ARC_MACH_ARC700: 2581 strcat (buf, ", ARC700"); 2582 break; 2583 2584 /* The only times we should end up here are (a) A corrupt ELF, (b) A 2585 new ELF with new architecture being read by an old version of 2586 readelf, or (c) An ELF built with non-GNU compiler that does not 2587 set the architecture in the e_flags. */ 2588 default: 2589 if (e_machine == EM_ARC_COMPACT) 2590 strcat (buf, ", Unknown ARCompact"); 2591 else 2592 strcat (buf, ", Unknown ARC"); 2593 break; 2594 } 2595 2596 switch (e_flags & EF_ARC_OSABI_MSK) 2597 { 2598 case E_ARC_OSABI_ORIG: 2599 strcat (buf, ", (ABI:legacy)"); 2600 break; 2601 case E_ARC_OSABI_V2: 2602 strcat (buf, ", (ABI:v2)"); 2603 break; 2604 /* Only upstream 3.9+ kernels will support ARCv2 ISA. */ 2605 case E_ARC_OSABI_V3: 2606 strcat (buf, ", v3 no-legacy-syscalls ABI"); 2607 break; 2608 case E_ARC_OSABI_V4: 2609 strcat (buf, ", v4 ABI"); 2610 break; 2611 default: 2612 strcat (buf, ", unrecognised ARC OSABI flag"); 2613 break; 2614 } 2615 } 2616 2617 static void 2618 decode_ARM_machine_flags (unsigned e_flags, char buf[]) 2619 { 2620 unsigned eabi; 2621 bfd_boolean unknown = FALSE; 2622 2623 eabi = EF_ARM_EABI_VERSION (e_flags); 2624 e_flags &= ~ EF_ARM_EABIMASK; 2625 2626 /* Handle "generic" ARM flags. */ 2627 if (e_flags & EF_ARM_RELEXEC) 2628 { 2629 strcat (buf, ", relocatable executable"); 2630 e_flags &= ~ EF_ARM_RELEXEC; 2631 } 2632 2633 if (e_flags & EF_ARM_PIC) 2634 { 2635 strcat (buf, ", position independent"); 2636 e_flags &= ~ EF_ARM_PIC; 2637 } 2638 2639 /* Now handle EABI specific flags. */ 2640 switch (eabi) 2641 { 2642 default: 2643 strcat (buf, ", <unrecognized EABI>"); 2644 if (e_flags) 2645 unknown = TRUE; 2646 break; 2647 2648 case EF_ARM_EABI_VER1: 2649 strcat (buf, ", Version1 EABI"); 2650 while (e_flags) 2651 { 2652 unsigned flag; 2653 2654 /* Process flags one bit at a time. */ 2655 flag = e_flags & - e_flags; 2656 e_flags &= ~ flag; 2657 2658 switch (flag) 2659 { 2660 case EF_ARM_SYMSARESORTED: /* Conflicts with EF_ARM_INTERWORK. */ 2661 strcat (buf, ", sorted symbol tables"); 2662 break; 2663 2664 default: 2665 unknown = TRUE; 2666 break; 2667 } 2668 } 2669 break; 2670 2671 case EF_ARM_EABI_VER2: 2672 strcat (buf, ", Version2 EABI"); 2673 while (e_flags) 2674 { 2675 unsigned flag; 2676 2677 /* Process flags one bit at a time. */ 2678 flag = e_flags & - e_flags; 2679 e_flags &= ~ flag; 2680 2681 switch (flag) 2682 { 2683 case EF_ARM_SYMSARESORTED: /* Conflicts with EF_ARM_INTERWORK. */ 2684 strcat (buf, ", sorted symbol tables"); 2685 break; 2686 2687 case EF_ARM_DYNSYMSUSESEGIDX: 2688 strcat (buf, ", dynamic symbols use segment index"); 2689 break; 2690 2691 case EF_ARM_MAPSYMSFIRST: 2692 strcat (buf, ", mapping symbols precede others"); 2693 break; 2694 2695 default: 2696 unknown = TRUE; 2697 break; 2698 } 2699 } 2700 break; 2701 2702 case EF_ARM_EABI_VER3: 2703 strcat (buf, ", Version3 EABI"); 2704 break; 2705 2706 case EF_ARM_EABI_VER4: 2707 strcat (buf, ", Version4 EABI"); 2708 while (e_flags) 2709 { 2710 unsigned flag; 2711 2712 /* Process flags one bit at a time. */ 2713 flag = e_flags & - e_flags; 2714 e_flags &= ~ flag; 2715 2716 switch (flag) 2717 { 2718 case EF_ARM_BE8: 2719 strcat (buf, ", BE8"); 2720 break; 2721 2722 case EF_ARM_LE8: 2723 strcat (buf, ", LE8"); 2724 break; 2725 2726 default: 2727 unknown = TRUE; 2728 break; 2729 } 2730 } 2731 break; 2732 2733 case EF_ARM_EABI_VER5: 2734 strcat (buf, ", Version5 EABI"); 2735 while (e_flags) 2736 { 2737 unsigned flag; 2738 2739 /* Process flags one bit at a time. */ 2740 flag = e_flags & - e_flags; 2741 e_flags &= ~ flag; 2742 2743 switch (flag) 2744 { 2745 case EF_ARM_BE8: 2746 strcat (buf, ", BE8"); 2747 break; 2748 2749 case EF_ARM_LE8: 2750 strcat (buf, ", LE8"); 2751 break; 2752 2753 case EF_ARM_ABI_FLOAT_SOFT: /* Conflicts with EF_ARM_SOFT_FLOAT. */ 2754 strcat (buf, ", soft-float ABI"); 2755 break; 2756 2757 case EF_ARM_ABI_FLOAT_HARD: /* Conflicts with EF_ARM_VFP_FLOAT. */ 2758 strcat (buf, ", hard-float ABI"); 2759 break; 2760 2761 default: 2762 unknown = TRUE; 2763 break; 2764 } 2765 } 2766 break; 2767 2768 case EF_ARM_EABI_UNKNOWN: 2769 strcat (buf, ", GNU EABI"); 2770 while (e_flags) 2771 { 2772 unsigned flag; 2773 2774 /* Process flags one bit at a time. */ 2775 flag = e_flags & - e_flags; 2776 e_flags &= ~ flag; 2777 2778 switch (flag) 2779 { 2780 case EF_ARM_INTERWORK: 2781 strcat (buf, ", interworking enabled"); 2782 break; 2783 2784 case EF_ARM_APCS_26: 2785 strcat (buf, ", uses APCS/26"); 2786 break; 2787 2788 case EF_ARM_APCS_FLOAT: 2789 strcat (buf, ", uses APCS/float"); 2790 break; 2791 2792 case EF_ARM_PIC: 2793 strcat (buf, ", position independent"); 2794 break; 2795 2796 case EF_ARM_ALIGN8: 2797 strcat (buf, ", 8 bit structure alignment"); 2798 break; 2799 2800 case EF_ARM_NEW_ABI: 2801 strcat (buf, ", uses new ABI"); 2802 break; 2803 2804 case EF_ARM_OLD_ABI: 2805 strcat (buf, ", uses old ABI"); 2806 break; 2807 2808 case EF_ARM_SOFT_FLOAT: 2809 strcat (buf, ", software FP"); 2810 break; 2811 2812 case EF_ARM_VFP_FLOAT: 2813 strcat (buf, ", VFP"); 2814 break; 2815 2816 case EF_ARM_MAVERICK_FLOAT: 2817 strcat (buf, ", Maverick FP"); 2818 break; 2819 2820 default: 2821 unknown = TRUE; 2822 break; 2823 } 2824 } 2825 } 2826 2827 if (unknown) 2828 strcat (buf,_(", <unknown>")); 2829 } 2830 2831 static void 2832 decode_AVR_machine_flags (unsigned e_flags, char buf[], size_t size) 2833 { 2834 --size; /* Leave space for null terminator. */ 2835 2836 switch (e_flags & EF_AVR_MACH) 2837 { 2838 case E_AVR_MACH_AVR1: 2839 strncat (buf, ", avr:1", size); 2840 break; 2841 case E_AVR_MACH_AVR2: 2842 strncat (buf, ", avr:2", size); 2843 break; 2844 case E_AVR_MACH_AVR25: 2845 strncat (buf, ", avr:25", size); 2846 break; 2847 case E_AVR_MACH_AVR3: 2848 strncat (buf, ", avr:3", size); 2849 break; 2850 case E_AVR_MACH_AVR31: 2851 strncat (buf, ", avr:31", size); 2852 break; 2853 case E_AVR_MACH_AVR35: 2854 strncat (buf, ", avr:35", size); 2855 break; 2856 case E_AVR_MACH_AVR4: 2857 strncat (buf, ", avr:4", size); 2858 break; 2859 case E_AVR_MACH_AVR5: 2860 strncat (buf, ", avr:5", size); 2861 break; 2862 case E_AVR_MACH_AVR51: 2863 strncat (buf, ", avr:51", size); 2864 break; 2865 case E_AVR_MACH_AVR6: 2866 strncat (buf, ", avr:6", size); 2867 break; 2868 case E_AVR_MACH_AVRTINY: 2869 strncat (buf, ", avr:100", size); 2870 break; 2871 case E_AVR_MACH_XMEGA1: 2872 strncat (buf, ", avr:101", size); 2873 break; 2874 case E_AVR_MACH_XMEGA2: 2875 strncat (buf, ", avr:102", size); 2876 break; 2877 case E_AVR_MACH_XMEGA3: 2878 strncat (buf, ", avr:103", size); 2879 break; 2880 case E_AVR_MACH_XMEGA4: 2881 strncat (buf, ", avr:104", size); 2882 break; 2883 case E_AVR_MACH_XMEGA5: 2884 strncat (buf, ", avr:105", size); 2885 break; 2886 case E_AVR_MACH_XMEGA6: 2887 strncat (buf, ", avr:106", size); 2888 break; 2889 case E_AVR_MACH_XMEGA7: 2890 strncat (buf, ", avr:107", size); 2891 break; 2892 default: 2893 strncat (buf, ", avr:<unknown>", size); 2894 break; 2895 } 2896 2897 size -= strlen (buf); 2898 if (e_flags & EF_AVR_LINKRELAX_PREPARED) 2899 strncat (buf, ", link-relax", size); 2900 } 2901 2902 static void 2903 decode_NDS32_machine_flags (unsigned e_flags, char buf[], size_t size) 2904 { 2905 unsigned abi; 2906 unsigned arch; 2907 unsigned config; 2908 unsigned version; 2909 bfd_boolean has_fpu = FALSE; 2910 unsigned int r = 0; 2911 2912 static const char *ABI_STRINGS[] = 2913 { 2914 "ABI v0", /* use r5 as return register; only used in N1213HC */ 2915 "ABI v1", /* use r0 as return register */ 2916 "ABI v2", /* use r0 as return register and don't reserve 24 bytes for arguments */ 2917 "ABI v2fp", /* for FPU */ 2918 "AABI", 2919 "ABI2 FP+" 2920 }; 2921 static const char *VER_STRINGS[] = 2922 { 2923 "Andes ELF V1.3 or older", 2924 "Andes ELF V1.3.1", 2925 "Andes ELF V1.4" 2926 }; 2927 static const char *ARCH_STRINGS[] = 2928 { 2929 "", 2930 "Andes Star v1.0", 2931 "Andes Star v2.0", 2932 "Andes Star v3.0", 2933 "Andes Star v3.0m" 2934 }; 2935 2936 abi = EF_NDS_ABI & e_flags; 2937 arch = EF_NDS_ARCH & e_flags; 2938 config = EF_NDS_INST & e_flags; 2939 version = EF_NDS32_ELF_VERSION & e_flags; 2940 2941 memset (buf, 0, size); 2942 2943 switch (abi) 2944 { 2945 case E_NDS_ABI_V0: 2946 case E_NDS_ABI_V1: 2947 case E_NDS_ABI_V2: 2948 case E_NDS_ABI_V2FP: 2949 case E_NDS_ABI_AABI: 2950 case E_NDS_ABI_V2FP_PLUS: 2951 /* In case there are holes in the array. */ 2952 r += snprintf (buf + r, size - r, ", %s", ABI_STRINGS[abi >> EF_NDS_ABI_SHIFT]); 2953 break; 2954 2955 default: 2956 r += snprintf (buf + r, size - r, ", <unrecognized ABI>"); 2957 break; 2958 } 2959 2960 switch (version) 2961 { 2962 case E_NDS32_ELF_VER_1_2: 2963 case E_NDS32_ELF_VER_1_3: 2964 case E_NDS32_ELF_VER_1_4: 2965 r += snprintf (buf + r, size - r, ", %s", VER_STRINGS[version >> EF_NDS32_ELF_VERSION_SHIFT]); 2966 break; 2967 2968 default: 2969 r += snprintf (buf + r, size - r, ", <unrecognized ELF version number>"); 2970 break; 2971 } 2972 2973 if (E_NDS_ABI_V0 == abi) 2974 { 2975 /* OLD ABI; only used in N1213HC, has performance extension 1. */ 2976 r += snprintf (buf + r, size - r, ", Andes Star v1.0, N1213HC, MAC, PERF1"); 2977 if (arch == E_NDS_ARCH_STAR_V1_0) 2978 r += snprintf (buf + r, size -r, ", 16b"); /* has 16-bit instructions */ 2979 return; 2980 } 2981 2982 switch (arch) 2983 { 2984 case E_NDS_ARCH_STAR_V1_0: 2985 case E_NDS_ARCH_STAR_V2_0: 2986 case E_NDS_ARCH_STAR_V3_0: 2987 case E_NDS_ARCH_STAR_V3_M: 2988 r += snprintf (buf + r, size - r, ", %s", ARCH_STRINGS[arch >> EF_NDS_ARCH_SHIFT]); 2989 break; 2990 2991 default: 2992 r += snprintf (buf + r, size - r, ", <unrecognized architecture>"); 2993 /* ARCH version determines how the e_flags are interpreted. 2994 If it is unknown, we cannot proceed. */ 2995 return; 2996 } 2997 2998 /* Newer ABI; Now handle architecture specific flags. */ 2999 if (arch == E_NDS_ARCH_STAR_V1_0) 3000 { 3001 if (config & E_NDS32_HAS_MFUSR_PC_INST) 3002 r += snprintf (buf + r, size -r, ", MFUSR_PC"); 3003 3004 if (!(config & E_NDS32_HAS_NO_MAC_INST)) 3005 r += snprintf (buf + r, size -r, ", MAC"); 3006 3007 if (config & E_NDS32_HAS_DIV_INST) 3008 r += snprintf (buf + r, size -r, ", DIV"); 3009 3010 if (config & E_NDS32_HAS_16BIT_INST) 3011 r += snprintf (buf + r, size -r, ", 16b"); 3012 } 3013 else 3014 { 3015 if (config & E_NDS32_HAS_MFUSR_PC_INST) 3016 { 3017 if (version <= E_NDS32_ELF_VER_1_3) 3018 r += snprintf (buf + r, size -r, ", [B8]"); 3019 else 3020 r += snprintf (buf + r, size -r, ", EX9"); 3021 } 3022 3023 if (config & E_NDS32_HAS_MAC_DX_INST) 3024 r += snprintf (buf + r, size -r, ", MAC_DX"); 3025 3026 if (config & E_NDS32_HAS_DIV_DX_INST) 3027 r += snprintf (buf + r, size -r, ", DIV_DX"); 3028 3029 if (config & E_NDS32_HAS_16BIT_INST) 3030 { 3031 if (version <= E_NDS32_ELF_VER_1_3) 3032 r += snprintf (buf + r, size -r, ", 16b"); 3033 else 3034 r += snprintf (buf + r, size -r, ", IFC"); 3035 } 3036 } 3037 3038 if (config & E_NDS32_HAS_EXT_INST) 3039 r += snprintf (buf + r, size -r, ", PERF1"); 3040 3041 if (config & E_NDS32_HAS_EXT2_INST) 3042 r += snprintf (buf + r, size -r, ", PERF2"); 3043 3044 if (config & E_NDS32_HAS_FPU_INST) 3045 { 3046 has_fpu = TRUE; 3047 r += snprintf (buf + r, size -r, ", FPU_SP"); 3048 } 3049 3050 if (config & E_NDS32_HAS_FPU_DP_INST) 3051 { 3052 has_fpu = TRUE; 3053 r += snprintf (buf + r, size -r, ", FPU_DP"); 3054 } 3055 3056 if (config & E_NDS32_HAS_FPU_MAC_INST) 3057 { 3058 has_fpu = TRUE; 3059 r += snprintf (buf + r, size -r, ", FPU_MAC"); 3060 } 3061 3062 if (has_fpu) 3063 { 3064 switch ((config & E_NDS32_FPU_REG_CONF) >> E_NDS32_FPU_REG_CONF_SHIFT) 3065 { 3066 case E_NDS32_FPU_REG_8SP_4DP: 3067 r += snprintf (buf + r, size -r, ", FPU_REG:8/4"); 3068 break; 3069 case E_NDS32_FPU_REG_16SP_8DP: 3070 r += snprintf (buf + r, size -r, ", FPU_REG:16/8"); 3071 break; 3072 case E_NDS32_FPU_REG_32SP_16DP: 3073 r += snprintf (buf + r, size -r, ", FPU_REG:32/16"); 3074 break; 3075 case E_NDS32_FPU_REG_32SP_32DP: 3076 r += snprintf (buf + r, size -r, ", FPU_REG:32/32"); 3077 break; 3078 } 3079 } 3080 3081 if (config & E_NDS32_HAS_AUDIO_INST) 3082 r += snprintf (buf + r, size -r, ", AUDIO"); 3083 3084 if (config & E_NDS32_HAS_STRING_INST) 3085 r += snprintf (buf + r, size -r, ", STR"); 3086 3087 if (config & E_NDS32_HAS_REDUCED_REGS) 3088 r += snprintf (buf + r, size -r, ", 16REG"); 3089 3090 if (config & E_NDS32_HAS_VIDEO_INST) 3091 { 3092 if (version <= E_NDS32_ELF_VER_1_3) 3093 r += snprintf (buf + r, size -r, ", VIDEO"); 3094 else 3095 r += snprintf (buf + r, size -r, ", SATURATION"); 3096 } 3097 3098 if (config & E_NDS32_HAS_ENCRIPT_INST) 3099 r += snprintf (buf + r, size -r, ", ENCRP"); 3100 3101 if (config & E_NDS32_HAS_L2C_INST) 3102 r += snprintf (buf + r, size -r, ", L2C"); 3103 } 3104 3105 static char * 3106 get_machine_flags (Filedata * filedata, unsigned e_flags, unsigned e_machine) 3107 { 3108 static char buf[1024]; 3109 3110 buf[0] = '\0'; 3111 3112 if (e_flags) 3113 { 3114 switch (e_machine) 3115 { 3116 default: 3117 break; 3118 3119 case EM_ARC_COMPACT2: 3120 case EM_ARC_COMPACT: 3121 decode_ARC_machine_flags (e_flags, e_machine, buf); 3122 break; 3123 3124 case EM_ARM: 3125 decode_ARM_machine_flags (e_flags, buf); 3126 break; 3127 3128 case EM_AVR: 3129 decode_AVR_machine_flags (e_flags, buf, sizeof buf); 3130 break; 3131 3132 case EM_BLACKFIN: 3133 if (e_flags & EF_BFIN_PIC) 3134 strcat (buf, ", PIC"); 3135 3136 if (e_flags & EF_BFIN_FDPIC) 3137 strcat (buf, ", FDPIC"); 3138 3139 if (e_flags & EF_BFIN_CODE_IN_L1) 3140 strcat (buf, ", code in L1"); 3141 3142 if (e_flags & EF_BFIN_DATA_IN_L1) 3143 strcat (buf, ", data in L1"); 3144 3145 break; 3146 3147 case EM_CYGNUS_FRV: 3148 switch (e_flags & EF_FRV_CPU_MASK) 3149 { 3150 case EF_FRV_CPU_GENERIC: 3151 break; 3152 3153 default: 3154 strcat (buf, ", fr???"); 3155 break; 3156 3157 case EF_FRV_CPU_FR300: 3158 strcat (buf, ", fr300"); 3159 break; 3160 3161 case EF_FRV_CPU_FR400: 3162 strcat (buf, ", fr400"); 3163 break; 3164 case EF_FRV_CPU_FR405: 3165 strcat (buf, ", fr405"); 3166 break; 3167 3168 case EF_FRV_CPU_FR450: 3169 strcat (buf, ", fr450"); 3170 break; 3171 3172 case EF_FRV_CPU_FR500: 3173 strcat (buf, ", fr500"); 3174 break; 3175 case EF_FRV_CPU_FR550: 3176 strcat (buf, ", fr550"); 3177 break; 3178 3179 case EF_FRV_CPU_SIMPLE: 3180 strcat (buf, ", simple"); 3181 break; 3182 case EF_FRV_CPU_TOMCAT: 3183 strcat (buf, ", tomcat"); 3184 break; 3185 } 3186 break; 3187 3188 case EM_68K: 3189 if ((e_flags & EF_M68K_ARCH_MASK) == EF_M68K_M68000) 3190 strcat (buf, ", m68000"); 3191 else if ((e_flags & EF_M68K_ARCH_MASK) == EF_M68K_CPU32) 3192 strcat (buf, ", cpu32"); 3193 else if ((e_flags & EF_M68K_ARCH_MASK) == EF_M68K_FIDO) 3194 strcat (buf, ", fido_a"); 3195 else 3196 { 3197 char const * isa = _("unknown"); 3198 char const * mac = _("unknown mac"); 3199 char const * additional = NULL; 3200 3201 switch (e_flags & EF_M68K_CF_ISA_MASK) 3202 { 3203 case EF_M68K_CF_ISA_A_NODIV: 3204 isa = "A"; 3205 additional = ", nodiv"; 3206 break; 3207 case EF_M68K_CF_ISA_A: 3208 isa = "A"; 3209 break; 3210 case EF_M68K_CF_ISA_A_PLUS: 3211 isa = "A+"; 3212 break; 3213 case EF_M68K_CF_ISA_B_NOUSP: 3214 isa = "B"; 3215 additional = ", nousp"; 3216 break; 3217 case EF_M68K_CF_ISA_B: 3218 isa = "B"; 3219 break; 3220 case EF_M68K_CF_ISA_C: 3221 isa = "C"; 3222 break; 3223 case EF_M68K_CF_ISA_C_NODIV: 3224 isa = "C"; 3225 additional = ", nodiv"; 3226 break; 3227 } 3228 strcat (buf, ", cf, isa "); 3229 strcat (buf, isa); 3230 if (additional) 3231 strcat (buf, additional); 3232 if (e_flags & EF_M68K_CF_FLOAT) 3233 strcat (buf, ", float"); 3234 switch (e_flags & EF_M68K_CF_MAC_MASK) 3235 { 3236 case 0: 3237 mac = NULL; 3238 break; 3239 case EF_M68K_CF_MAC: 3240 mac = "mac"; 3241 break; 3242 case EF_M68K_CF_EMAC: 3243 mac = "emac"; 3244 break; 3245 case EF_M68K_CF_EMAC_B: 3246 mac = "emac_b"; 3247 break; 3248 } 3249 if (mac) 3250 { 3251 strcat (buf, ", "); 3252 strcat (buf, mac); 3253 } 3254 } 3255 break; 3256 3257 case EM_CYGNUS_MEP: 3258 switch (e_flags & EF_MEP_CPU_MASK) 3259 { 3260 case EF_MEP_CPU_MEP: strcat (buf, ", generic MeP"); break; 3261 case EF_MEP_CPU_C2: strcat (buf, ", MeP C2"); break; 3262 case EF_MEP_CPU_C3: strcat (buf, ", MeP C3"); break; 3263 case EF_MEP_CPU_C4: strcat (buf, ", MeP C4"); break; 3264 case EF_MEP_CPU_C5: strcat (buf, ", MeP C5"); break; 3265 case EF_MEP_CPU_H1: strcat (buf, ", MeP H1"); break; 3266 default: strcat (buf, _(", <unknown MeP cpu type>")); break; 3267 } 3268 3269 switch (e_flags & EF_MEP_COP_MASK) 3270 { 3271 case EF_MEP_COP_NONE: break; 3272 case EF_MEP_COP_AVC: strcat (buf, ", AVC coprocessor"); break; 3273 case EF_MEP_COP_AVC2: strcat (buf, ", AVC2 coprocessor"); break; 3274 case EF_MEP_COP_FMAX: strcat (buf, ", FMAX coprocessor"); break; 3275 case EF_MEP_COP_IVC2: strcat (buf, ", IVC2 coprocessor"); break; 3276 default: strcat (buf, _("<unknown MeP copro type>")); break; 3277 } 3278 3279 if (e_flags & EF_MEP_LIBRARY) 3280 strcat (buf, ", Built for Library"); 3281 3282 if (e_flags & EF_MEP_INDEX_MASK) 3283 sprintf (buf + strlen (buf), ", Configuration Index: %#x", 3284 e_flags & EF_MEP_INDEX_MASK); 3285 3286 if (e_flags & ~ EF_MEP_ALL_FLAGS) 3287 sprintf (buf + strlen (buf), _(", unknown flags bits: %#x"), 3288 e_flags & ~ EF_MEP_ALL_FLAGS); 3289 break; 3290 3291 case EM_PPC: 3292 if (e_flags & EF_PPC_EMB) 3293 strcat (buf, ", emb"); 3294 3295 if (e_flags & EF_PPC_RELOCATABLE) 3296 strcat (buf, _(", relocatable")); 3297 3298 if (e_flags & EF_PPC_RELOCATABLE_LIB) 3299 strcat (buf, _(", relocatable-lib")); 3300 break; 3301 3302 case EM_PPC64: 3303 if (e_flags & EF_PPC64_ABI) 3304 { 3305 char abi[] = ", abiv0"; 3306 3307 abi[6] += e_flags & EF_PPC64_ABI; 3308 strcat (buf, abi); 3309 } 3310 break; 3311 3312 case EM_V800: 3313 if ((e_flags & EF_RH850_ABI) == EF_RH850_ABI) 3314 strcat (buf, ", RH850 ABI"); 3315 3316 if (e_flags & EF_V800_850E3) 3317 strcat (buf, ", V3 architecture"); 3318 3319 if ((e_flags & (EF_RH850_FPU_DOUBLE | EF_RH850_FPU_SINGLE)) == 0) 3320 strcat (buf, ", FPU not used"); 3321 3322 if ((e_flags & (EF_RH850_REGMODE22 | EF_RH850_REGMODE32)) == 0) 3323 strcat (buf, ", regmode: COMMON"); 3324 3325 if ((e_flags & (EF_RH850_GP_FIX | EF_RH850_GP_NOFIX)) == 0) 3326 strcat (buf, ", r4 not used"); 3327 3328 if ((e_flags & (EF_RH850_EP_FIX | EF_RH850_EP_NOFIX)) == 0) 3329 strcat (buf, ", r30 not used"); 3330 3331 if ((e_flags & (EF_RH850_TP_FIX | EF_RH850_TP_NOFIX)) == 0) 3332 strcat (buf, ", r5 not used"); 3333 3334 if ((e_flags & (EF_RH850_REG2_RESERVE | EF_RH850_REG2_NORESERVE)) == 0) 3335 strcat (buf, ", r2 not used"); 3336 3337 for (e_flags &= 0xFFFF; e_flags; e_flags &= ~ (e_flags & - e_flags)) 3338 { 3339 switch (e_flags & - e_flags) 3340 { 3341 case EF_RH850_FPU_DOUBLE: strcat (buf, ", double precision FPU"); break; 3342 case EF_RH850_FPU_SINGLE: strcat (buf, ", single precision FPU"); break; 3343 case EF_RH850_REGMODE22: strcat (buf, ", regmode:22"); break; 3344 case EF_RH850_REGMODE32: strcat (buf, ", regmode:23"); break; 3345 case EF_RH850_GP_FIX: strcat (buf, ", r4 fixed"); break; 3346 case EF_RH850_GP_NOFIX: strcat (buf, ", r4 free"); break; 3347 case EF_RH850_EP_FIX: strcat (buf, ", r30 fixed"); break; 3348 case EF_RH850_EP_NOFIX: strcat (buf, ", r30 free"); break; 3349 case EF_RH850_TP_FIX: strcat (buf, ", r5 fixed"); break; 3350 case EF_RH850_TP_NOFIX: strcat (buf, ", r5 free"); break; 3351 case EF_RH850_REG2_RESERVE: strcat (buf, ", r2 fixed"); break; 3352 case EF_RH850_REG2_NORESERVE: strcat (buf, ", r2 free"); break; 3353 default: break; 3354 } 3355 } 3356 break; 3357 3358 case EM_V850: 3359 case EM_CYGNUS_V850: 3360 switch (e_flags & EF_V850_ARCH) 3361 { 3362 case E_V850E3V5_ARCH: 3363 strcat (buf, ", v850e3v5"); 3364 break; 3365 case E_V850E2V3_ARCH: 3366 strcat (buf, ", v850e2v3"); 3367 break; 3368 case E_V850E2_ARCH: 3369 strcat (buf, ", v850e2"); 3370 break; 3371 case E_V850E1_ARCH: 3372 strcat (buf, ", v850e1"); 3373 break; 3374 case E_V850E_ARCH: 3375 strcat (buf, ", v850e"); 3376 break; 3377 case E_V850_ARCH: 3378 strcat (buf, ", v850"); 3379 break; 3380 default: 3381 strcat (buf, _(", unknown v850 architecture variant")); 3382 break; 3383 } 3384 break; 3385 3386 case EM_M32R: 3387 case EM_CYGNUS_M32R: 3388 if ((e_flags & EF_M32R_ARCH) == E_M32R_ARCH) 3389 strcat (buf, ", m32r"); 3390 break; 3391 3392 case EM_MIPS: 3393 case EM_MIPS_RS3_LE: 3394 if (e_flags & EF_MIPS_NOREORDER) 3395 strcat (buf, ", noreorder"); 3396 3397 if (e_flags & EF_MIPS_PIC) 3398 strcat (buf, ", pic"); 3399 3400 if (e_flags & EF_MIPS_CPIC) 3401 strcat (buf, ", cpic"); 3402 3403 if (e_flags & EF_MIPS_UCODE) 3404 strcat (buf, ", ugen_reserved"); 3405 3406 if (e_flags & EF_MIPS_ABI2) 3407 strcat (buf, ", abi2"); 3408 3409 if (e_flags & EF_MIPS_OPTIONS_FIRST) 3410 strcat (buf, ", odk first"); 3411 3412 if (e_flags & EF_MIPS_32BITMODE) 3413 strcat (buf, ", 32bitmode"); 3414 3415 if (e_flags & EF_MIPS_NAN2008) 3416 strcat (buf, ", nan2008"); 3417 3418 if (e_flags & EF_MIPS_FP64) 3419 strcat (buf, ", fp64"); 3420 3421 switch ((e_flags & EF_MIPS_MACH)) 3422 { 3423 case E_MIPS_MACH_3900: strcat (buf, ", 3900"); break; 3424 case E_MIPS_MACH_4010: strcat (buf, ", 4010"); break; 3425 case E_MIPS_MACH_4100: strcat (buf, ", 4100"); break; 3426 case E_MIPS_MACH_4111: strcat (buf, ", 4111"); break; 3427 case E_MIPS_MACH_4120: strcat (buf, ", 4120"); break; 3428 case E_MIPS_MACH_4650: strcat (buf, ", 4650"); break; 3429 case E_MIPS_MACH_5400: strcat (buf, ", 5400"); break; 3430 case E_MIPS_MACH_5500: strcat (buf, ", 5500"); break; 3431 case E_MIPS_MACH_5900: strcat (buf, ", 5900"); break; 3432 case E_MIPS_MACH_SB1: strcat (buf, ", sb1"); break; 3433 case E_MIPS_MACH_9000: strcat (buf, ", 9000"); break; 3434 case E_MIPS_MACH_LS2E: strcat (buf, ", loongson-2e"); break; 3435 case E_MIPS_MACH_LS2F: strcat (buf, ", loongson-2f"); break; 3436 case E_MIPS_MACH_GS464: strcat (buf, ", gs464"); break; 3437 case E_MIPS_MACH_GS464E: strcat (buf, ", gs464e"); break; 3438 case E_MIPS_MACH_GS264E: strcat (buf, ", gs264e"); break; 3439 case E_MIPS_MACH_OCTEON: strcat (buf, ", octeon"); break; 3440 case E_MIPS_MACH_OCTEON2: strcat (buf, ", octeon2"); break; 3441 case E_MIPS_MACH_OCTEON3: strcat (buf, ", octeon3"); break; 3442 case E_MIPS_MACH_XLR: strcat (buf, ", xlr"); break; 3443 case E_MIPS_MACH_IAMR2: strcat (buf, ", interaptiv-mr2"); break; 3444 case 0: 3445 /* We simply ignore the field in this case to avoid confusion: 3446 MIPS ELF does not specify EF_MIPS_MACH, it is a GNU 3447 extension. */ 3448 break; 3449 default: strcat (buf, _(", unknown CPU")); break; 3450 } 3451 3452 switch ((e_flags & EF_MIPS_ABI)) 3453 { 3454 case E_MIPS_ABI_O32: strcat (buf, ", o32"); break; 3455 case E_MIPS_ABI_O64: strcat (buf, ", o64"); break; 3456 case E_MIPS_ABI_EABI32: strcat (buf, ", eabi32"); break; 3457 case E_MIPS_ABI_EABI64: strcat (buf, ", eabi64"); break; 3458 case 0: 3459 /* We simply ignore the field in this case to avoid confusion: 3460 MIPS ELF does not specify EF_MIPS_ABI, it is a GNU extension. 3461 This means it is likely to be an o32 file, but not for 3462 sure. */ 3463 break; 3464 default: strcat (buf, _(", unknown ABI")); break; 3465 } 3466 3467 if (e_flags & EF_MIPS_ARCH_ASE_MDMX) 3468 strcat (buf, ", mdmx"); 3469 3470 if (e_flags & EF_MIPS_ARCH_ASE_M16) 3471 strcat (buf, ", mips16"); 3472 3473 if (e_flags & EF_MIPS_ARCH_ASE_MICROMIPS) 3474 strcat (buf, ", micromips"); 3475 3476 switch ((e_flags & EF_MIPS_ARCH)) 3477 { 3478 case E_MIPS_ARCH_1: strcat (buf, ", mips1"); break; 3479 case E_MIPS_ARCH_2: strcat (buf, ", mips2"); break; 3480 case E_MIPS_ARCH_3: strcat (buf, ", mips3"); break; 3481 case E_MIPS_ARCH_4: strcat (buf, ", mips4"); break; 3482 case E_MIPS_ARCH_5: strcat (buf, ", mips5"); break; 3483 case E_MIPS_ARCH_32: strcat (buf, ", mips32"); break; 3484 case E_MIPS_ARCH_32R2: strcat (buf, ", mips32r2"); break; 3485 case E_MIPS_ARCH_32R6: strcat (buf, ", mips32r6"); break; 3486 case E_MIPS_ARCH_64: strcat (buf, ", mips64"); break; 3487 case E_MIPS_ARCH_64R2: strcat (buf, ", mips64r2"); break; 3488 case E_MIPS_ARCH_64R6: strcat (buf, ", mips64r6"); break; 3489 default: strcat (buf, _(", unknown ISA")); break; 3490 } 3491 break; 3492 3493 case EM_NDS32: 3494 decode_NDS32_machine_flags (e_flags, buf, sizeof buf); 3495 break; 3496 3497 case EM_NFP: 3498 switch (EF_NFP_MACH (e_flags)) 3499 { 3500 case E_NFP_MACH_3200: 3501 strcat (buf, ", NFP-32xx"); 3502 break; 3503 case E_NFP_MACH_6000: 3504 strcat (buf, ", NFP-6xxx"); 3505 break; 3506 } 3507 break; 3508 3509 case EM_RISCV: 3510 if (e_flags & EF_RISCV_RVC) 3511 strcat (buf, ", RVC"); 3512 3513 if (e_flags & EF_RISCV_RVE) 3514 strcat (buf, ", RVE"); 3515 3516 switch (e_flags & EF_RISCV_FLOAT_ABI) 3517 { 3518 case EF_RISCV_FLOAT_ABI_SOFT: 3519 strcat (buf, ", soft-float ABI"); 3520 break; 3521 3522 case EF_RISCV_FLOAT_ABI_SINGLE: 3523 strcat (buf, ", single-float ABI"); 3524 break; 3525 3526 case EF_RISCV_FLOAT_ABI_DOUBLE: 3527 strcat (buf, ", double-float ABI"); 3528 break; 3529 3530 case EF_RISCV_FLOAT_ABI_QUAD: 3531 strcat (buf, ", quad-float ABI"); 3532 break; 3533 } 3534 break; 3535 3536 case EM_SH: 3537 switch ((e_flags & EF_SH_MACH_MASK)) 3538 { 3539 case EF_SH1: strcat (buf, ", sh1"); break; 3540 case EF_SH2: strcat (buf, ", sh2"); break; 3541 case EF_SH3: strcat (buf, ", sh3"); break; 3542 case EF_SH_DSP: strcat (buf, ", sh-dsp"); break; 3543 case EF_SH3_DSP: strcat (buf, ", sh3-dsp"); break; 3544 case EF_SH4AL_DSP: strcat (buf, ", sh4al-dsp"); break; 3545 case EF_SH3E: strcat (buf, ", sh3e"); break; 3546 case EF_SH4: strcat (buf, ", sh4"); break; 3547 case EF_SH5: strcat (buf, ", sh5"); break; 3548 case EF_SH2E: strcat (buf, ", sh2e"); break; 3549 case EF_SH4A: strcat (buf, ", sh4a"); break; 3550 case EF_SH2A: strcat (buf, ", sh2a"); break; 3551 case EF_SH4_NOFPU: strcat (buf, ", sh4-nofpu"); break; 3552 case EF_SH4A_NOFPU: strcat (buf, ", sh4a-nofpu"); break; 3553 case EF_SH2A_NOFPU: strcat (buf, ", sh2a-nofpu"); break; 3554 case EF_SH3_NOMMU: strcat (buf, ", sh3-nommu"); break; 3555 case EF_SH4_NOMMU_NOFPU: strcat (buf, ", sh4-nommu-nofpu"); break; 3556 case EF_SH2A_SH4_NOFPU: strcat (buf, ", sh2a-nofpu-or-sh4-nommu-nofpu"); break; 3557 case EF_SH2A_SH3_NOFPU: strcat (buf, ", sh2a-nofpu-or-sh3-nommu"); break; 3558 case EF_SH2A_SH4: strcat (buf, ", sh2a-or-sh4"); break; 3559 case EF_SH2A_SH3E: strcat (buf, ", sh2a-or-sh3e"); break; 3560 default: strcat (buf, _(", unknown ISA")); break; 3561 } 3562 3563 if (e_flags & EF_SH_PIC) 3564 strcat (buf, ", pic"); 3565 3566 if (e_flags & EF_SH_FDPIC) 3567 strcat (buf, ", fdpic"); 3568 break; 3569 3570 case EM_OR1K: 3571 if (e_flags & EF_OR1K_NODELAY) 3572 strcat (buf, ", no delay"); 3573 break; 3574 3575 case EM_SPARCV9: 3576 if (e_flags & EF_SPARC_32PLUS) 3577 strcat (buf, ", v8+"); 3578 3579 if (e_flags & EF_SPARC_SUN_US1) 3580 strcat (buf, ", ultrasparcI"); 3581 3582 if (e_flags & EF_SPARC_SUN_US3) 3583 strcat (buf, ", ultrasparcIII"); 3584 3585 if (e_flags & EF_SPARC_HAL_R1) 3586 strcat (buf, ", halr1"); 3587 3588 if (e_flags & EF_SPARC_LEDATA) 3589 strcat (buf, ", ledata"); 3590 3591 if ((e_flags & EF_SPARCV9_MM) == EF_SPARCV9_TSO) 3592 strcat (buf, ", tso"); 3593 3594 if ((e_flags & EF_SPARCV9_MM) == EF_SPARCV9_PSO) 3595 strcat (buf, ", pso"); 3596 3597 if ((e_flags & EF_SPARCV9_MM) == EF_SPARCV9_RMO) 3598 strcat (buf, ", rmo"); 3599 break; 3600 3601 case EM_PARISC: 3602 switch (e_flags & EF_PARISC_ARCH) 3603 { 3604 case EFA_PARISC_1_0: 3605 strcpy (buf, ", PA-RISC 1.0"); 3606 break; 3607 case EFA_PARISC_1_1: 3608 strcpy (buf, ", PA-RISC 1.1"); 3609 break; 3610 case EFA_PARISC_2_0: 3611 strcpy (buf, ", PA-RISC 2.0"); 3612 break; 3613 default: 3614 break; 3615 } 3616 if (e_flags & EF_PARISC_TRAPNIL) 3617 strcat (buf, ", trapnil"); 3618 if (e_flags & EF_PARISC_EXT) 3619 strcat (buf, ", ext"); 3620 if (e_flags & EF_PARISC_LSB) 3621 strcat (buf, ", lsb"); 3622 if (e_flags & EF_PARISC_WIDE) 3623 strcat (buf, ", wide"); 3624 if (e_flags & EF_PARISC_NO_KABP) 3625 strcat (buf, ", no kabp"); 3626 if (e_flags & EF_PARISC_LAZYSWAP) 3627 strcat (buf, ", lazyswap"); 3628 break; 3629 3630 case EM_PJ: 3631 case EM_PJ_OLD: 3632 if ((e_flags & EF_PICOJAVA_NEWCALLS) == EF_PICOJAVA_NEWCALLS) 3633 strcat (buf, ", new calling convention"); 3634 3635 if ((e_flags & EF_PICOJAVA_GNUCALLS) == EF_PICOJAVA_GNUCALLS) 3636 strcat (buf, ", gnu calling convention"); 3637 break; 3638 3639 case EM_IA_64: 3640 if ((e_flags & EF_IA_64_ABI64)) 3641 strcat (buf, ", 64-bit"); 3642 else 3643 strcat (buf, ", 32-bit"); 3644 if ((e_flags & EF_IA_64_REDUCEDFP)) 3645 strcat (buf, ", reduced fp model"); 3646 if ((e_flags & EF_IA_64_NOFUNCDESC_CONS_GP)) 3647 strcat (buf, ", no function descriptors, constant gp"); 3648 else if ((e_flags & EF_IA_64_CONS_GP)) 3649 strcat (buf, ", constant gp"); 3650 if ((e_flags & EF_IA_64_ABSOLUTE)) 3651 strcat (buf, ", absolute"); 3652 if (filedata->file_header.e_ident[EI_OSABI] == ELFOSABI_OPENVMS) 3653 { 3654 if ((e_flags & EF_IA_64_VMS_LINKAGES)) 3655 strcat (buf, ", vms_linkages"); 3656 switch ((e_flags & EF_IA_64_VMS_COMCOD)) 3657 { 3658 case EF_IA_64_VMS_COMCOD_SUCCESS: 3659 break; 3660 case EF_IA_64_VMS_COMCOD_WARNING: 3661 strcat (buf, ", warning"); 3662 break; 3663 case EF_IA_64_VMS_COMCOD_ERROR: 3664 strcat (buf, ", error"); 3665 break; 3666 case EF_IA_64_VMS_COMCOD_ABORT: 3667 strcat (buf, ", abort"); 3668 break; 3669 default: 3670 warn (_("Unrecognised IA64 VMS Command Code: %x\n"), 3671 e_flags & EF_IA_64_VMS_COMCOD); 3672 strcat (buf, ", <unknown>"); 3673 } 3674 } 3675 break; 3676 3677 case EM_VAX: 3678 if ((e_flags & EF_VAX_NONPIC)) 3679 strcat (buf, ", non-PIC"); 3680 if ((e_flags & EF_VAX_DFLOAT)) 3681 strcat (buf, ", D-Float"); 3682 if ((e_flags & EF_VAX_GFLOAT)) 3683 strcat (buf, ", G-Float"); 3684 break; 3685 3686 case EM_VISIUM: 3687 if (e_flags & EF_VISIUM_ARCH_MCM) 3688 strcat (buf, ", mcm"); 3689 else if (e_flags & EF_VISIUM_ARCH_MCM24) 3690 strcat (buf, ", mcm24"); 3691 if (e_flags & EF_VISIUM_ARCH_GR6) 3692 strcat (buf, ", gr6"); 3693 break; 3694 3695 case EM_RL78: 3696 switch (e_flags & E_FLAG_RL78_CPU_MASK) 3697 { 3698 case E_FLAG_RL78_ANY_CPU: break; 3699 case E_FLAG_RL78_G10: strcat (buf, ", G10"); break; 3700 case E_FLAG_RL78_G13: strcat (buf, ", G13"); break; 3701 case E_FLAG_RL78_G14: strcat (buf, ", G14"); break; 3702 } 3703 if (e_flags & E_FLAG_RL78_64BIT_DOUBLES) 3704 strcat (buf, ", 64-bit doubles"); 3705 break; 3706 3707 case EM_RX: 3708 if (e_flags & E_FLAG_RX_64BIT_DOUBLES) 3709 strcat (buf, ", 64-bit doubles"); 3710 if (e_flags & E_FLAG_RX_DSP) 3711 strcat (buf, ", dsp"); 3712 if (e_flags & E_FLAG_RX_PID) 3713 strcat (buf, ", pid"); 3714 if (e_flags & E_FLAG_RX_ABI) 3715 strcat (buf, ", RX ABI"); 3716 if (e_flags & E_FLAG_RX_SINSNS_SET) 3717 strcat (buf, e_flags & E_FLAG_RX_SINSNS_YES 3718 ? ", uses String instructions" : ", bans String instructions"); 3719 if (e_flags & E_FLAG_RX_V2) 3720 strcat (buf, ", V2"); 3721 if (e_flags & E_FLAG_RX_V3) 3722 strcat (buf, ", V3"); 3723 break; 3724 3725 case EM_S390: 3726 if (e_flags & EF_S390_HIGH_GPRS) 3727 strcat (buf, ", highgprs"); 3728 break; 3729 3730 case EM_TI_C6000: 3731 if ((e_flags & EF_C6000_REL)) 3732 strcat (buf, ", relocatable module"); 3733 break; 3734 3735 case EM_MSP430: 3736 strcat (buf, _(": architecture variant: ")); 3737 switch (e_flags & EF_MSP430_MACH) 3738 { 3739 case E_MSP430_MACH_MSP430x11: strcat (buf, "MSP430x11"); break; 3740 case E_MSP430_MACH_MSP430x11x1 : strcat (buf, "MSP430x11x1 "); break; 3741 case E_MSP430_MACH_MSP430x12: strcat (buf, "MSP430x12"); break; 3742 case E_MSP430_MACH_MSP430x13: strcat (buf, "MSP430x13"); break; 3743 case E_MSP430_MACH_MSP430x14: strcat (buf, "MSP430x14"); break; 3744 case E_MSP430_MACH_MSP430x15: strcat (buf, "MSP430x15"); break; 3745 case E_MSP430_MACH_MSP430x16: strcat (buf, "MSP430x16"); break; 3746 case E_MSP430_MACH_MSP430x31: strcat (buf, "MSP430x31"); break; 3747 case E_MSP430_MACH_MSP430x32: strcat (buf, "MSP430x32"); break; 3748 case E_MSP430_MACH_MSP430x33: strcat (buf, "MSP430x33"); break; 3749 case E_MSP430_MACH_MSP430x41: strcat (buf, "MSP430x41"); break; 3750 case E_MSP430_MACH_MSP430x42: strcat (buf, "MSP430x42"); break; 3751 case E_MSP430_MACH_MSP430x43: strcat (buf, "MSP430x43"); break; 3752 case E_MSP430_MACH_MSP430x44: strcat (buf, "MSP430x44"); break; 3753 case E_MSP430_MACH_MSP430X : strcat (buf, "MSP430X"); break; 3754 default: 3755 strcat (buf, _(": unknown")); break; 3756 } 3757 3758 if (e_flags & ~ EF_MSP430_MACH) 3759 strcat (buf, _(": unknown extra flag bits also present")); 3760 break; 3761 3762 case EM_Z80: 3763 switch (e_flags & EF_Z80_MACH_MSK) 3764 { 3765 case EF_Z80_MACH_Z80: strcat (buf, ", Z80"); break; 3766 case EF_Z80_MACH_Z180: strcat (buf, ", Z180"); break; 3767 case EF_Z80_MACH_R800: strcat (buf, ", R800"); break; 3768 case EF_Z80_MACH_EZ80_Z80: strcat (buf, ", EZ80"); break; 3769 case EF_Z80_MACH_EZ80_ADL: strcat (buf, ", EZ80, ADL"); break; 3770 case EF_Z80_MACH_GBZ80: strcat (buf, ", GBZ80"); break; 3771 default: 3772 strcat (buf, _(", unknown")); break; 3773 } 3774 break; 3775 } 3776 } 3777 3778 return buf; 3779 } 3780 3781 static const char * 3782 get_osabi_name (Filedata * filedata, unsigned int osabi) 3783 { 3784 static char buff[32]; 3785 3786 switch (osabi) 3787 { 3788 case ELFOSABI_NONE: return "UNIX - System V"; 3789 case ELFOSABI_HPUX: return "UNIX - HP-UX"; 3790 case ELFOSABI_NETBSD: return "UNIX - NetBSD"; 3791 case ELFOSABI_GNU: return "UNIX - GNU"; 3792 case ELFOSABI_SOLARIS: return "UNIX - Solaris"; 3793 case ELFOSABI_AIX: return "UNIX - AIX"; 3794 case ELFOSABI_IRIX: return "UNIX - IRIX"; 3795 case ELFOSABI_FREEBSD: return "UNIX - FreeBSD"; 3796 case ELFOSABI_TRU64: return "UNIX - TRU64"; 3797 case ELFOSABI_MODESTO: return "Novell - Modesto"; 3798 case ELFOSABI_OPENBSD: return "UNIX - OpenBSD"; 3799 case ELFOSABI_OPENVMS: return "VMS - OpenVMS"; 3800 case ELFOSABI_NSK: return "HP - Non-Stop Kernel"; 3801 case ELFOSABI_AROS: return "AROS"; 3802 case ELFOSABI_FENIXOS: return "FenixOS"; 3803 case ELFOSABI_CLOUDABI: return "Nuxi CloudABI"; 3804 case ELFOSABI_OPENVOS: return "Stratus Technologies OpenVOS"; 3805 default: 3806 if (osabi >= 64) 3807 switch (filedata->file_header.e_machine) 3808 { 3809 case EM_ARM: 3810 switch (osabi) 3811 { 3812 case ELFOSABI_ARM: return "ARM"; 3813 case ELFOSABI_ARM_FDPIC: return "ARM FDPIC"; 3814 default: 3815 break; 3816 } 3817 break; 3818 3819 case EM_MSP430: 3820 case EM_MSP430_OLD: 3821 case EM_VISIUM: 3822 switch (osabi) 3823 { 3824 case ELFOSABI_STANDALONE: return _("Standalone App"); 3825 default: 3826 break; 3827 } 3828 break; 3829 3830 case EM_TI_C6000: 3831 switch (osabi) 3832 { 3833 case ELFOSABI_C6000_ELFABI: return _("Bare-metal C6000"); 3834 case ELFOSABI_C6000_LINUX: return "Linux C6000"; 3835 default: 3836 break; 3837 } 3838 break; 3839 3840 default: 3841 break; 3842 } 3843 snprintf (buff, sizeof (buff), _("<unknown: %x>"), osabi); 3844 return buff; 3845 } 3846 } 3847 3848 static const char * 3849 get_aarch64_segment_type (unsigned long type) 3850 { 3851 switch (type) 3852 { 3853 case PT_AARCH64_ARCHEXT: return "AARCH64_ARCHEXT"; 3854 default: return NULL; 3855 } 3856 } 3857 3858 static const char * 3859 get_arm_segment_type (unsigned long type) 3860 { 3861 switch (type) 3862 { 3863 case PT_ARM_EXIDX: return "EXIDX"; 3864 default: return NULL; 3865 } 3866 } 3867 3868 static const char * 3869 get_s390_segment_type (unsigned long type) 3870 { 3871 switch (type) 3872 { 3873 case PT_S390_PGSTE: return "S390_PGSTE"; 3874 default: return NULL; 3875 } 3876 } 3877 3878 static const char * 3879 get_mips_segment_type (unsigned long type) 3880 { 3881 switch (type) 3882 { 3883 case PT_MIPS_REGINFO: return "REGINFO"; 3884 case PT_MIPS_RTPROC: return "RTPROC"; 3885 case PT_MIPS_OPTIONS: return "OPTIONS"; 3886 case PT_MIPS_ABIFLAGS: return "ABIFLAGS"; 3887 default: return NULL; 3888 } 3889 } 3890 3891 static const char * 3892 get_parisc_segment_type (unsigned long type) 3893 { 3894 switch (type) 3895 { 3896 case PT_PARISC_ARCHEXT: return "PARISC_ARCHEXT"; 3897 case PT_PARISC_UNWIND: return "PARISC_UNWIND"; 3898 case PT_PARISC_WEAKORDER: return "PARISC_WEAKORDER"; 3899 default: return NULL; 3900 } 3901 } 3902 3903 static const char * 3904 get_ia64_segment_type (unsigned long type) 3905 { 3906 switch (type) 3907 { 3908 case PT_IA_64_ARCHEXT: return "IA_64_ARCHEXT"; 3909 case PT_IA_64_UNWIND: return "IA_64_UNWIND"; 3910 default: return NULL; 3911 } 3912 } 3913 3914 static const char * 3915 get_tic6x_segment_type (unsigned long type) 3916 { 3917 switch (type) 3918 { 3919 case PT_C6000_PHATTR: return "C6000_PHATTR"; 3920 default: return NULL; 3921 } 3922 } 3923 3924 static const char * 3925 get_hpux_segment_type (unsigned long type, unsigned e_machine) 3926 { 3927 if (e_machine == EM_PARISC) 3928 switch (type) 3929 { 3930 case PT_HP_TLS: return "HP_TLS"; 3931 case PT_HP_CORE_NONE: return "HP_CORE_NONE"; 3932 case PT_HP_CORE_VERSION: return "HP_CORE_VERSION"; 3933 case PT_HP_CORE_KERNEL: return "HP_CORE_KERNEL"; 3934 case PT_HP_CORE_COMM: return "HP_CORE_COMM"; 3935 case PT_HP_CORE_PROC: return "HP_CORE_PROC"; 3936 case PT_HP_CORE_LOADABLE: return "HP_CORE_LOADABLE"; 3937 case PT_HP_CORE_STACK: return "HP_CORE_STACK"; 3938 case PT_HP_CORE_SHM: return "HP_CORE_SHM"; 3939 case PT_HP_CORE_MMF: return "HP_CORE_MMF"; 3940 case PT_HP_PARALLEL: return "HP_PARALLEL"; 3941 case PT_HP_FASTBIND: return "HP_FASTBIND"; 3942 case PT_HP_OPT_ANNOT: return "HP_OPT_ANNOT"; 3943 case PT_HP_HSL_ANNOT: return "HP_HSL_ANNOT"; 3944 case PT_HP_STACK: return "HP_STACK"; 3945 case PT_HP_CORE_UTSNAME: return "HP_CORE_UTSNAME"; 3946 default: return NULL; 3947 } 3948 3949 if (e_machine == EM_IA_64) 3950 switch (type) 3951 { 3952 case PT_HP_TLS: return "HP_TLS"; 3953 case PT_IA_64_HP_OPT_ANOT: return "HP_OPT_ANNOT"; 3954 case PT_IA_64_HP_HSL_ANOT: return "HP_HSL_ANNOT"; 3955 case PT_IA_64_HP_STACK: return "HP_STACK"; 3956 default: return NULL; 3957 } 3958 3959 return NULL; 3960 } 3961 3962 static const char * 3963 get_solaris_segment_type (unsigned long type) 3964 { 3965 switch (type) 3966 { 3967 case 0x6464e550: return "PT_SUNW_UNWIND"; 3968 case 0x6474e550: return "PT_SUNW_EH_FRAME"; 3969 case 0x6ffffff7: return "PT_LOSUNW"; 3970 case 0x6ffffffa: return "PT_SUNWBSS"; 3971 case 0x6ffffffb: return "PT_SUNWSTACK"; 3972 case 0x6ffffffc: return "PT_SUNWDTRACE"; 3973 case 0x6ffffffd: return "PT_SUNWCAP"; 3974 case 0x6fffffff: return "PT_HISUNW"; 3975 default: return NULL; 3976 } 3977 } 3978 3979 static const char * 3980 get_segment_type (Filedata * filedata, unsigned long p_type) 3981 { 3982 static char buff[32]; 3983 3984 switch (p_type) 3985 { 3986 case PT_NULL: return "NULL"; 3987 case PT_LOAD: return "LOAD"; 3988 case PT_DYNAMIC: return "DYNAMIC"; 3989 case PT_INTERP: return "INTERP"; 3990 case PT_NOTE: return "NOTE"; 3991 case PT_SHLIB: return "SHLIB"; 3992 case PT_PHDR: return "PHDR"; 3993 case PT_TLS: return "TLS"; 3994 case PT_GNU_EH_FRAME: return "GNU_EH_FRAME"; 3995 case PT_GNU_STACK: return "GNU_STACK"; 3996 case PT_GNU_RELRO: return "GNU_RELRO"; 3997 case PT_GNU_PROPERTY: return "GNU_PROPERTY"; 3998 3999 default: 4000 if ((p_type >= PT_LOPROC) && (p_type <= PT_HIPROC)) 4001 { 4002 const char * result; 4003 4004 switch (filedata->file_header.e_machine) 4005 { 4006 case EM_AARCH64: 4007 result = get_aarch64_segment_type (p_type); 4008 break; 4009 case EM_ARM: 4010 result = get_arm_segment_type (p_type); 4011 break; 4012 case EM_MIPS: 4013 case EM_MIPS_RS3_LE: 4014 result = get_mips_segment_type (p_type); 4015 break; 4016 case EM_PARISC: 4017 result = get_parisc_segment_type (p_type); 4018 break; 4019 case EM_IA_64: 4020 result = get_ia64_segment_type (p_type); 4021 break; 4022 case EM_TI_C6000: 4023 result = get_tic6x_segment_type (p_type); 4024 break; 4025 case EM_S390: 4026 case EM_S390_OLD: 4027 result = get_s390_segment_type (p_type); 4028 break; 4029 default: 4030 result = NULL; 4031 break; 4032 } 4033 4034 if (result != NULL) 4035 return result; 4036 4037 sprintf (buff, "LOPROC+%#lx", p_type - PT_LOPROC); 4038 } 4039 else if ((p_type >= PT_LOOS) && (p_type <= PT_HIOS)) 4040 { 4041 const char * result = NULL; 4042 4043 switch (filedata->file_header.e_ident[EI_OSABI]) 4044 { 4045 case ELFOSABI_GNU: 4046 case ELFOSABI_FREEBSD: 4047 if (p_type >= PT_GNU_MBIND_LO && p_type <= PT_GNU_MBIND_HI) 4048 { 4049 sprintf (buff, "GNU_MBIND+%#lx", p_type - PT_GNU_MBIND_LO); 4050 result = buff; 4051 } 4052 break; 4053 case ELFOSABI_HPUX: 4054 result = get_hpux_segment_type (p_type, 4055 filedata->file_header.e_machine); 4056 break; 4057 case ELFOSABI_SOLARIS: 4058 result = get_solaris_segment_type (p_type); 4059 break; 4060 default: 4061 break; 4062 } 4063 if (result != NULL) 4064 return result; 4065 4066 sprintf (buff, "LOOS+%#lx", p_type - PT_LOOS); 4067 } 4068 else 4069 snprintf (buff, sizeof (buff), _("<unknown>: %lx"), p_type); 4070 4071 return buff; 4072 } 4073 } 4074 4075 static const char * 4076 get_arc_section_type_name (unsigned int sh_type) 4077 { 4078 switch (sh_type) 4079 { 4080 case SHT_ARC_ATTRIBUTES: return "ARC_ATTRIBUTES"; 4081 default: 4082 break; 4083 } 4084 return NULL; 4085 } 4086 4087 static const char * 4088 get_mips_section_type_name (unsigned int sh_type) 4089 { 4090 switch (sh_type) 4091 { 4092 case SHT_MIPS_LIBLIST: return "MIPS_LIBLIST"; 4093 case SHT_MIPS_MSYM: return "MIPS_MSYM"; 4094 case SHT_MIPS_CONFLICT: return "MIPS_CONFLICT"; 4095 case SHT_MIPS_GPTAB: return "MIPS_GPTAB"; 4096 case SHT_MIPS_UCODE: return "MIPS_UCODE"; 4097 case SHT_MIPS_DEBUG: return "MIPS_DEBUG"; 4098 case SHT_MIPS_REGINFO: return "MIPS_REGINFO"; 4099 case SHT_MIPS_PACKAGE: return "MIPS_PACKAGE"; 4100 case SHT_MIPS_PACKSYM: return "MIPS_PACKSYM"; 4101 case SHT_MIPS_RELD: return "MIPS_RELD"; 4102 case SHT_MIPS_IFACE: return "MIPS_IFACE"; 4103 case SHT_MIPS_CONTENT: return "MIPS_CONTENT"; 4104 case SHT_MIPS_OPTIONS: return "MIPS_OPTIONS"; 4105 case SHT_MIPS_SHDR: return "MIPS_SHDR"; 4106 case SHT_MIPS_FDESC: return "MIPS_FDESC"; 4107 case SHT_MIPS_EXTSYM: return "MIPS_EXTSYM"; 4108 case SHT_MIPS_DENSE: return "MIPS_DENSE"; 4109 case SHT_MIPS_PDESC: return "MIPS_PDESC"; 4110 case SHT_MIPS_LOCSYM: return "MIPS_LOCSYM"; 4111 case SHT_MIPS_AUXSYM: return "MIPS_AUXSYM"; 4112 case SHT_MIPS_OPTSYM: return "MIPS_OPTSYM"; 4113 case SHT_MIPS_LOCSTR: return "MIPS_LOCSTR"; 4114 case SHT_MIPS_LINE: return "MIPS_LINE"; 4115 case SHT_MIPS_RFDESC: return "MIPS_RFDESC"; 4116 case SHT_MIPS_DELTASYM: return "MIPS_DELTASYM"; 4117 case SHT_MIPS_DELTAINST: return "MIPS_DELTAINST"; 4118 case SHT_MIPS_DELTACLASS: return "MIPS_DELTACLASS"; 4119 case SHT_MIPS_DWARF: return "MIPS_DWARF"; 4120 case SHT_MIPS_DELTADECL: return "MIPS_DELTADECL"; 4121 case SHT_MIPS_SYMBOL_LIB: return "MIPS_SYMBOL_LIB"; 4122 case SHT_MIPS_EVENTS: return "MIPS_EVENTS"; 4123 case SHT_MIPS_TRANSLATE: return "MIPS_TRANSLATE"; 4124 case SHT_MIPS_PIXIE: return "MIPS_PIXIE"; 4125 case SHT_MIPS_XLATE: return "MIPS_XLATE"; 4126 case SHT_MIPS_XLATE_DEBUG: return "MIPS_XLATE_DEBUG"; 4127 case SHT_MIPS_WHIRL: return "MIPS_WHIRL"; 4128 case SHT_MIPS_EH_REGION: return "MIPS_EH_REGION"; 4129 case SHT_MIPS_XLATE_OLD: return "MIPS_XLATE_OLD"; 4130 case SHT_MIPS_PDR_EXCEPTION: return "MIPS_PDR_EXCEPTION"; 4131 case SHT_MIPS_ABIFLAGS: return "MIPS_ABIFLAGS"; 4132 case SHT_MIPS_XHASH: return "MIPS_XHASH"; 4133 default: 4134 break; 4135 } 4136 return NULL; 4137 } 4138 4139 static const char * 4140 get_parisc_section_type_name (unsigned int sh_type) 4141 { 4142 switch (sh_type) 4143 { 4144 case SHT_PARISC_EXT: return "PARISC_EXT"; 4145 case SHT_PARISC_UNWIND: return "PARISC_UNWIND"; 4146 case SHT_PARISC_DOC: return "PARISC_DOC"; 4147 case SHT_PARISC_ANNOT: return "PARISC_ANNOT"; 4148 case SHT_PARISC_SYMEXTN: return "PARISC_SYMEXTN"; 4149 case SHT_PARISC_STUBS: return "PARISC_STUBS"; 4150 case SHT_PARISC_DLKM: return "PARISC_DLKM"; 4151 default: return NULL; 4152 } 4153 } 4154 4155 static const char * 4156 get_ia64_section_type_name (Filedata * filedata, unsigned int sh_type) 4157 { 4158 /* If the top 8 bits are 0x78 the next 8 are the os/abi ID. */ 4159 if ((sh_type & 0xFF000000) == SHT_IA_64_LOPSREG) 4160 return get_osabi_name (filedata, (sh_type & 0x00FF0000) >> 16); 4161 4162 switch (sh_type) 4163 { 4164 case SHT_IA_64_EXT: return "IA_64_EXT"; 4165 case SHT_IA_64_UNWIND: return "IA_64_UNWIND"; 4166 case SHT_IA_64_PRIORITY_INIT: return "IA_64_PRIORITY_INIT"; 4167 case SHT_IA_64_VMS_TRACE: return "VMS_TRACE"; 4168 case SHT_IA_64_VMS_TIE_SIGNATURES: return "VMS_TIE_SIGNATURES"; 4169 case SHT_IA_64_VMS_DEBUG: return "VMS_DEBUG"; 4170 case SHT_IA_64_VMS_DEBUG_STR: return "VMS_DEBUG_STR"; 4171 case SHT_IA_64_VMS_LINKAGES: return "VMS_LINKAGES"; 4172 case SHT_IA_64_VMS_SYMBOL_VECTOR: return "VMS_SYMBOL_VECTOR"; 4173 case SHT_IA_64_VMS_FIXUP: return "VMS_FIXUP"; 4174 default: 4175 break; 4176 } 4177 return NULL; 4178 } 4179 4180 static const char * 4181 get_x86_64_section_type_name (unsigned int sh_type) 4182 { 4183 switch (sh_type) 4184 { 4185 case SHT_X86_64_UNWIND: return "X86_64_UNWIND"; 4186 default: return NULL; 4187 } 4188 } 4189 4190 static const char * 4191 get_aarch64_section_type_name (unsigned int sh_type) 4192 { 4193 switch (sh_type) 4194 { 4195 case SHT_AARCH64_ATTRIBUTES: return "AARCH64_ATTRIBUTES"; 4196 default: return NULL; 4197 } 4198 } 4199 4200 static const char * 4201 get_arm_section_type_name (unsigned int sh_type) 4202 { 4203 switch (sh_type) 4204 { 4205 case SHT_ARM_EXIDX: return "ARM_EXIDX"; 4206 case SHT_ARM_PREEMPTMAP: return "ARM_PREEMPTMAP"; 4207 case SHT_ARM_ATTRIBUTES: return "ARM_ATTRIBUTES"; 4208 case SHT_ARM_DEBUGOVERLAY: return "ARM_DEBUGOVERLAY"; 4209 case SHT_ARM_OVERLAYSECTION: return "ARM_OVERLAYSECTION"; 4210 default: return NULL; 4211 } 4212 } 4213 4214 static const char * 4215 get_tic6x_section_type_name (unsigned int sh_type) 4216 { 4217 switch (sh_type) 4218 { 4219 case SHT_C6000_UNWIND: return "C6000_UNWIND"; 4220 case SHT_C6000_PREEMPTMAP: return "C6000_PREEMPTMAP"; 4221 case SHT_C6000_ATTRIBUTES: return "C6000_ATTRIBUTES"; 4222 case SHT_TI_ICODE: return "TI_ICODE"; 4223 case SHT_TI_XREF: return "TI_XREF"; 4224 case SHT_TI_HANDLER: return "TI_HANDLER"; 4225 case SHT_TI_INITINFO: return "TI_INITINFO"; 4226 case SHT_TI_PHATTRS: return "TI_PHATTRS"; 4227 default: return NULL; 4228 } 4229 } 4230 4231 static const char * 4232 get_msp430x_section_type_name (unsigned int sh_type) 4233 { 4234 switch (sh_type) 4235 { 4236 case SHT_MSP430_SEC_FLAGS: return "MSP430_SEC_FLAGS"; 4237 case SHT_MSP430_SYM_ALIASES: return "MSP430_SYM_ALIASES"; 4238 case SHT_MSP430_ATTRIBUTES: return "MSP430_ATTRIBUTES"; 4239 default: return NULL; 4240 } 4241 } 4242 4243 static const char * 4244 get_nfp_section_type_name (unsigned int sh_type) 4245 { 4246 switch (sh_type) 4247 { 4248 case SHT_NFP_MECONFIG: return "NFP_MECONFIG"; 4249 case SHT_NFP_INITREG: return "NFP_INITREG"; 4250 case SHT_NFP_UDEBUG: return "NFP_UDEBUG"; 4251 default: return NULL; 4252 } 4253 } 4254 4255 static const char * 4256 get_v850_section_type_name (unsigned int sh_type) 4257 { 4258 switch (sh_type) 4259 { 4260 case SHT_V850_SCOMMON: return "V850 Small Common"; 4261 case SHT_V850_TCOMMON: return "V850 Tiny Common"; 4262 case SHT_V850_ZCOMMON: return "V850 Zero Common"; 4263 case SHT_RENESAS_IOP: return "RENESAS IOP"; 4264 case SHT_RENESAS_INFO: return "RENESAS INFO"; 4265 default: return NULL; 4266 } 4267 } 4268 4269 static const char * 4270 get_riscv_section_type_name (unsigned int sh_type) 4271 { 4272 switch (sh_type) 4273 { 4274 case SHT_RISCV_ATTRIBUTES: return "RISCV_ATTRIBUTES"; 4275 default: return NULL; 4276 } 4277 } 4278 4279 static const char * 4280 get_section_type_name (Filedata * filedata, unsigned int sh_type) 4281 { 4282 static char buff[32]; 4283 const char * result; 4284 4285 switch (sh_type) 4286 { 4287 case SHT_NULL: return "NULL"; 4288 case SHT_PROGBITS: return "PROGBITS"; 4289 case SHT_SYMTAB: return "SYMTAB"; 4290 case SHT_STRTAB: return "STRTAB"; 4291 case SHT_RELA: return "RELA"; 4292 case SHT_HASH: return "HASH"; 4293 case SHT_DYNAMIC: return "DYNAMIC"; 4294 case SHT_NOTE: return "NOTE"; 4295 case SHT_NOBITS: return "NOBITS"; 4296 case SHT_REL: return "REL"; 4297 case SHT_SHLIB: return "SHLIB"; 4298 case SHT_DYNSYM: return "DYNSYM"; 4299 case SHT_INIT_ARRAY: return "INIT_ARRAY"; 4300 case SHT_FINI_ARRAY: return "FINI_ARRAY"; 4301 case SHT_PREINIT_ARRAY: return "PREINIT_ARRAY"; 4302 case SHT_GNU_HASH: return "GNU_HASH"; 4303 case SHT_GROUP: return "GROUP"; 4304 case SHT_SYMTAB_SHNDX: return "SYMTAB SECTION INDICES"; 4305 case SHT_GNU_verdef: return "VERDEF"; 4306 case SHT_GNU_verneed: return "VERNEED"; 4307 case SHT_GNU_versym: return "VERSYM"; 4308 case 0x6ffffff0: return "VERSYM"; 4309 case 0x6ffffffc: return "VERDEF"; 4310 case 0x7ffffffd: return "AUXILIARY"; 4311 case 0x7fffffff: return "FILTER"; 4312 case SHT_GNU_LIBLIST: return "GNU_LIBLIST"; 4313 4314 default: 4315 if ((sh_type >= SHT_LOPROC) && (sh_type <= SHT_HIPROC)) 4316 { 4317 switch (filedata->file_header.e_machine) 4318 { 4319 case EM_ARC: 4320 case EM_ARC_COMPACT: 4321 case EM_ARC_COMPACT2: 4322 result = get_arc_section_type_name (sh_type); 4323 break; 4324 case EM_MIPS: 4325 case EM_MIPS_RS3_LE: 4326 result = get_mips_section_type_name (sh_type); 4327 break; 4328 case EM_PARISC: 4329 result = get_parisc_section_type_name (sh_type); 4330 break; 4331 case EM_IA_64: 4332 result = get_ia64_section_type_name (filedata, sh_type); 4333 break; 4334 case EM_X86_64: 4335 case EM_L1OM: 4336 case EM_K1OM: 4337 result = get_x86_64_section_type_name (sh_type); 4338 break; 4339 case EM_AARCH64: 4340 result = get_aarch64_section_type_name (sh_type); 4341 break; 4342 case EM_ARM: 4343 result = get_arm_section_type_name (sh_type); 4344 break; 4345 case EM_TI_C6000: 4346 result = get_tic6x_section_type_name (sh_type); 4347 break; 4348 case EM_MSP430: 4349 result = get_msp430x_section_type_name (sh_type); 4350 break; 4351 case EM_NFP: 4352 result = get_nfp_section_type_name (sh_type); 4353 break; 4354 case EM_V800: 4355 case EM_V850: 4356 case EM_CYGNUS_V850: 4357 result = get_v850_section_type_name (sh_type); 4358 break; 4359 case EM_RISCV: 4360 result = get_riscv_section_type_name (sh_type); 4361 break; 4362 default: 4363 result = NULL; 4364 break; 4365 } 4366 4367 if (result != NULL) 4368 return result; 4369 4370 sprintf (buff, "LOPROC+%#x", sh_type - SHT_LOPROC); 4371 } 4372 else if ((sh_type >= SHT_LOOS) && (sh_type <= SHT_HIOS)) 4373 { 4374 switch (filedata->file_header.e_machine) 4375 { 4376 case EM_IA_64: 4377 result = get_ia64_section_type_name (filedata, sh_type); 4378 break; 4379 default: 4380 if (filedata->file_header.e_ident[EI_OSABI] == ELFOSABI_SOLARIS) 4381 result = get_solaris_section_type (sh_type); 4382 else 4383 { 4384 switch (sh_type) 4385 { 4386 case SHT_GNU_INCREMENTAL_INPUTS: result = "GNU_INCREMENTAL_INPUTS"; break; 4387 case SHT_GNU_ATTRIBUTES: result = "GNU_ATTRIBUTES"; break; 4388 case SHT_GNU_HASH: result = "GNU_HASH"; break; 4389 case SHT_GNU_LIBLIST: result = "GNU_LIBLIST"; break; 4390 default: 4391 result = NULL; 4392 break; 4393 } 4394 } 4395 break; 4396 } 4397 4398 if (result != NULL) 4399 return result; 4400 4401 sprintf (buff, "LOOS+%#x", sh_type - SHT_LOOS); 4402 } 4403 else if ((sh_type >= SHT_LOUSER) && (sh_type <= SHT_HIUSER)) 4404 { 4405 switch (filedata->file_header.e_machine) 4406 { 4407 case EM_V800: 4408 case EM_V850: 4409 case EM_CYGNUS_V850: 4410 result = get_v850_section_type_name (sh_type); 4411 break; 4412 default: 4413 result = NULL; 4414 break; 4415 } 4416 4417 if (result != NULL) 4418 return result; 4419 4420 sprintf (buff, "LOUSER+%#x", sh_type - SHT_LOUSER); 4421 } 4422 else 4423 /* This message is probably going to be displayed in a 15 4424 character wide field, so put the hex value first. */ 4425 snprintf (buff, sizeof (buff), _("%08x: <unknown>"), sh_type); 4426 4427 return buff; 4428 } 4429 } 4430 4431 #define OPTION_DEBUG_DUMP 512 4432 #define OPTION_DYN_SYMS 513 4433 #define OPTION_DWARF_DEPTH 514 4434 #define OPTION_DWARF_START 515 4435 #define OPTION_DWARF_CHECK 516 4436 #define OPTION_CTF_DUMP 517 4437 #define OPTION_CTF_PARENT 518 4438 #define OPTION_CTF_SYMBOLS 519 4439 #define OPTION_CTF_STRINGS 520 4440 4441 static struct option options[] = 4442 { 4443 {"all", no_argument, 0, 'a'}, 4444 {"file-header", no_argument, 0, 'h'}, 4445 {"program-headers", no_argument, 0, 'l'}, 4446 {"headers", no_argument, 0, 'e'}, 4447 {"histogram", no_argument, 0, 'I'}, 4448 {"segments", no_argument, 0, 'l'}, 4449 {"sections", no_argument, 0, 'S'}, 4450 {"section-headers", no_argument, 0, 'S'}, 4451 {"section-groups", no_argument, 0, 'g'}, 4452 {"section-details", no_argument, 0, 't'}, 4453 {"full-section-name",no_argument, 0, 'N'}, 4454 {"symbols", no_argument, 0, 's'}, 4455 {"syms", no_argument, 0, 's'}, 4456 {"dyn-syms", no_argument, 0, OPTION_DYN_SYMS}, 4457 {"relocs", no_argument, 0, 'r'}, 4458 {"notes", no_argument, 0, 'n'}, 4459 {"dynamic", no_argument, 0, 'd'}, 4460 {"special-files", no_argument, 0, 'f'}, 4461 {"arch-specific", no_argument, 0, 'A'}, 4462 {"version-info", no_argument, 0, 'V'}, 4463 {"use-dynamic", no_argument, 0, 'D'}, 4464 {"unwind", no_argument, 0, 'u'}, 4465 {"archive-index", no_argument, 0, 'c'}, 4466 {"hex-dump", required_argument, 0, 'x'}, 4467 {"relocated-dump", required_argument, 0, 'R'}, 4468 {"string-dump", required_argument, 0, 'p'}, 4469 {"decompress", no_argument, 0, 'z'}, 4470 #ifdef SUPPORT_DISASSEMBLY 4471 {"instruction-dump", required_argument, 0, 'i'}, 4472 #endif 4473 {"debug-dump", optional_argument, 0, OPTION_DEBUG_DUMP}, 4474 4475 {"dwarf-depth", required_argument, 0, OPTION_DWARF_DEPTH}, 4476 {"dwarf-start", required_argument, 0, OPTION_DWARF_START}, 4477 {"dwarf-check", no_argument, 0, OPTION_DWARF_CHECK}, 4478 4479 {"ctf", required_argument, 0, OPTION_CTF_DUMP}, 4480 4481 {"ctf-symbols", required_argument, 0, OPTION_CTF_SYMBOLS}, 4482 {"ctf-strings", required_argument, 0, OPTION_CTF_STRINGS}, 4483 {"ctf-parent", required_argument, 0, OPTION_CTF_PARENT}, 4484 4485 {"version", no_argument, 0, 'v'}, 4486 {"wide", no_argument, 0, 'W'}, 4487 {"help", no_argument, 0, 'H'}, 4488 {0, no_argument, 0, 0} 4489 }; 4490 4491 static void 4492 usage (FILE * stream) 4493 { 4494 fprintf (stream, _("Usage: readelf <option(s)> elf-file(s)\n")); 4495 fprintf (stream, _(" Display information about the contents of ELF format files\n")); 4496 fprintf (stream, _(" Options are:\n\ 4497 -a --all Equivalent to: -h -l -S -s -r -d -V -A -I\n\ 4498 -h --file-header Display the ELF file header\n\ 4499 -l --program-headers Display the program headers\n\ 4500 --segments An alias for --program-headers\n\ 4501 -S --section-headers Display the sections' header\n\ 4502 --sections An alias for --section-headers\n\ 4503 -g --section-groups Display the section groups\n\ 4504 -t --section-details Display the section details\n\ 4505 -e --headers Equivalent to: -h -l -S\n\ 4506 -s --syms Display the symbol table\n\ 4507 --symbols An alias for --syms\n\ 4508 --dyn-syms Display the dynamic symbol table\n\ 4509 -n --notes Display the core notes (if present)\n\ 4510 -r --relocs Display the relocations (if present)\n\ 4511 -u --unwind Display the unwind info (if present)\n\ 4512 -d --dynamic Display the dynamic section (if present)\n\ 4513 -f --special-files Process non-plain files too\n\ 4514 -V --version-info Display the version sections (if present)\n\ 4515 -A --arch-specific Display architecture specific information (if any)\n\ 4516 -c --archive-index Display the symbol/file index in an archive\n\ 4517 -D --use-dynamic Use the dynamic section info when displaying symbols\n\ 4518 -x --hex-dump=<number|name>\n\ 4519 Dump the contents of section <number|name> as bytes\n\ 4520 -p --string-dump=<number|name>\n\ 4521 Dump the contents of section <number|name> as strings\n\ 4522 -R --relocated-dump=<number|name>\n\ 4523 Dump the contents of section <number|name> as relocated bytes\n\ 4524 -z --decompress Decompress section before dumping it\n\ 4525 -w[lLiaprmfFsoRtUuTgAckK] or\n\ 4526 --debug-dump[=rawline,=decodedline,=info,=abbrev,=pubnames,=aranges,=macro,=frames,\n\ 4527 =frames-interp,=str,=loc,=Ranges,=pubtypes,\n\ 4528 =gdb_index,=trace_info,=trace_abbrev,=trace_aranges,\n\ 4529 =addr,=cu_index,=links,=follow-links]\n\ 4530 Display the contents of DWARF debug sections\n")); 4531 fprintf (stream, _("\ 4532 --dwarf-depth=N Do not display DIEs at depth N or greater\n\ 4533 --dwarf-start=N Display DIEs starting with N, at the same depth\n\ 4534 or deeper\n")); 4535 fprintf (stream, _("\ 4536 --ctf=<number|name> Display CTF info from section <number|name>\n\ 4537 --ctf-parent=<number|name>\n\ 4538 Use section <number|name> as the CTF parent\n\n\ 4539 --ctf-symbols=<number|name>\n\ 4540 Use section <number|name> as the CTF external symtab\n\n\ 4541 --ctf-strings=<number|name>\n\ 4542 Use section <number|name> as the CTF external strtab\n\n")); 4543 4544 #ifdef SUPPORT_DISASSEMBLY 4545 fprintf (stream, _("\ 4546 -i --instruction-dump=<number|name>\n\ 4547 Disassemble the contents of section <number|name>\n")); 4548 #endif 4549 fprintf (stream, _("\ 4550 -I --histogram Display histogram of bucket list lengths\n\ 4551 -W --wide Allow output width to exceed 80 characters\n\ 4552 @<file> Read options from <file>\n\ 4553 -H --help Display this information\n\ 4554 -v --version Display the version number of readelf\n")); 4555 4556 if (REPORT_BUGS_TO[0] && stream == stdout) 4557 fprintf (stdout, _("Report bugs to %s\n"), REPORT_BUGS_TO); 4558 4559 exit (stream == stdout ? 0 : 1); 4560 } 4561 4562 /* Record the fact that the user wants the contents of section number 4563 SECTION to be displayed using the method(s) encoded as flags bits 4564 in TYPE. Note, TYPE can be zero if we are creating the array for 4565 the first time. */ 4566 4567 static void 4568 request_dump_bynumber (Filedata * filedata, unsigned int section, dump_type type) 4569 { 4570 if (section >= filedata->num_dump_sects) 4571 { 4572 dump_type * new_dump_sects; 4573 4574 new_dump_sects = (dump_type *) calloc (section + 1, 4575 sizeof (* new_dump_sects)); 4576 4577 if (new_dump_sects == NULL) 4578 error (_("Out of memory allocating dump request table.\n")); 4579 else 4580 { 4581 if (filedata->dump_sects) 4582 { 4583 /* Copy current flag settings. */ 4584 memcpy (new_dump_sects, filedata->dump_sects, 4585 filedata->num_dump_sects * sizeof (* new_dump_sects)); 4586 4587 free (filedata->dump_sects); 4588 } 4589 4590 filedata->dump_sects = new_dump_sects; 4591 filedata->num_dump_sects = section + 1; 4592 } 4593 } 4594 4595 if (filedata->dump_sects) 4596 filedata->dump_sects[section] |= type; 4597 } 4598 4599 /* Request a dump by section name. */ 4600 4601 static void 4602 request_dump_byname (const char * section, dump_type type) 4603 { 4604 struct dump_list_entry * new_request; 4605 4606 new_request = (struct dump_list_entry *) 4607 malloc (sizeof (struct dump_list_entry)); 4608 if (!new_request) 4609 error (_("Out of memory allocating dump request table.\n")); 4610 4611 new_request->name = strdup (section); 4612 if (!new_request->name) 4613 error (_("Out of memory allocating dump request table.\n")); 4614 4615 new_request->type = type; 4616 4617 new_request->next = dump_sects_byname; 4618 dump_sects_byname = new_request; 4619 } 4620 4621 static inline void 4622 request_dump (Filedata * filedata, dump_type type) 4623 { 4624 int section; 4625 char * cp; 4626 4627 do_dump++; 4628 section = strtoul (optarg, & cp, 0); 4629 4630 if (! *cp && section >= 0) 4631 request_dump_bynumber (filedata, section, type); 4632 else 4633 request_dump_byname (optarg, type); 4634 } 4635 4636 static void 4637 parse_args (Filedata * filedata, int argc, char ** argv) 4638 { 4639 int c; 4640 4641 if (argc < 2) 4642 usage (stderr); 4643 4644 while ((c = getopt_long 4645 (argc, argv, "ADHINR:SVWacdefghi:lnp:rstuvw::x:z", options, NULL)) != EOF) 4646 { 4647 switch (c) 4648 { 4649 case 0: 4650 /* Long options. */ 4651 break; 4652 case 'H': 4653 usage (stdout); 4654 break; 4655 4656 case 'a': 4657 do_syms = TRUE; 4658 do_reloc = TRUE; 4659 do_unwind = TRUE; 4660 do_dynamic = TRUE; 4661 do_header = TRUE; 4662 do_sections = TRUE; 4663 do_section_groups = TRUE; 4664 do_segments = TRUE; 4665 do_version = TRUE; 4666 do_histogram = TRUE; 4667 do_arch = TRUE; 4668 do_notes = TRUE; 4669 break; 4670 case 'g': 4671 do_section_groups = TRUE; 4672 break; 4673 case 't': 4674 case 'N': 4675 do_sections = TRUE; 4676 do_section_details = TRUE; 4677 break; 4678 case 'e': 4679 do_header = TRUE; 4680 do_sections = TRUE; 4681 do_segments = TRUE; 4682 break; 4683 case 'A': 4684 do_arch = TRUE; 4685 break; 4686 case 'D': 4687 do_using_dynamic = TRUE; 4688 break; 4689 case 'r': 4690 do_reloc = TRUE; 4691 break; 4692 case 'u': 4693 do_unwind = TRUE; 4694 break; 4695 case 'f': 4696 do_special_files++; 4697 break; 4698 case 'h': 4699 do_header = TRUE; 4700 break; 4701 case 'l': 4702 do_segments = TRUE; 4703 break; 4704 case 's': 4705 do_syms = TRUE; 4706 break; 4707 case 'S': 4708 do_sections = TRUE; 4709 break; 4710 case 'd': 4711 do_dynamic = TRUE; 4712 break; 4713 case 'I': 4714 do_histogram = TRUE; 4715 break; 4716 case 'n': 4717 do_notes = TRUE; 4718 break; 4719 case 'c': 4720 do_archive_index = TRUE; 4721 break; 4722 case 'x': 4723 request_dump (filedata, HEX_DUMP); 4724 break; 4725 case 'p': 4726 request_dump (filedata, STRING_DUMP); 4727 break; 4728 case 'R': 4729 request_dump (filedata, RELOC_DUMP); 4730 break; 4731 case 'z': 4732 decompress_dumps = TRUE; 4733 break; 4734 case 'w': 4735 do_dump = TRUE; 4736 if (optarg == 0) 4737 { 4738 do_debugging = TRUE; 4739 dwarf_select_sections_all (); 4740 } 4741 else 4742 { 4743 do_debugging = FALSE; 4744 dwarf_select_sections_by_letters (optarg); 4745 } 4746 break; 4747 case OPTION_DEBUG_DUMP: 4748 do_dump = TRUE; 4749 if (optarg == 0) 4750 do_debugging = TRUE; 4751 else 4752 { 4753 do_debugging = FALSE; 4754 dwarf_select_sections_by_names (optarg); 4755 } 4756 break; 4757 case OPTION_DWARF_DEPTH: 4758 { 4759 char *cp; 4760 4761 dwarf_cutoff_level = strtoul (optarg, & cp, 0); 4762 } 4763 break; 4764 case OPTION_DWARF_START: 4765 { 4766 char *cp; 4767 4768 dwarf_start_die = strtoul (optarg, & cp, 0); 4769 } 4770 break; 4771 case OPTION_DWARF_CHECK: 4772 dwarf_check = TRUE; 4773 break; 4774 case OPTION_CTF_DUMP: 4775 do_ctf = TRUE; 4776 request_dump (filedata, CTF_DUMP); 4777 break; 4778 case OPTION_CTF_SYMBOLS: 4779 dump_ctf_symtab_name = strdup (optarg); 4780 break; 4781 case OPTION_CTF_STRINGS: 4782 dump_ctf_strtab_name = strdup (optarg); 4783 break; 4784 case OPTION_CTF_PARENT: 4785 dump_ctf_parent_name = strdup (optarg); 4786 break; 4787 case OPTION_DYN_SYMS: 4788 do_dyn_syms = TRUE; 4789 break; 4790 #ifdef SUPPORT_DISASSEMBLY 4791 case 'i': 4792 request_dump (filedata, DISASS_DUMP); 4793 break; 4794 #endif 4795 case 'v': 4796 print_version (program_name); 4797 break; 4798 case 'V': 4799 do_version = TRUE; 4800 break; 4801 case 'W': 4802 do_wide = TRUE; 4803 break; 4804 default: 4805 /* xgettext:c-format */ 4806 error (_("Invalid option '-%c'\n"), c); 4807 /* Fall through. */ 4808 case '?': 4809 usage (stderr); 4810 } 4811 } 4812 4813 if (!do_dynamic && !do_syms && !do_reloc && !do_unwind && !do_sections 4814 && !do_segments && !do_header && !do_dump && !do_version 4815 && !do_histogram && !do_debugging && !do_arch && !do_notes 4816 && !do_section_groups && !do_archive_index 4817 && !do_dyn_syms) 4818 usage (stderr); 4819 } 4820 4821 static const char * 4822 get_elf_class (unsigned int elf_class) 4823 { 4824 static char buff[32]; 4825 4826 switch (elf_class) 4827 { 4828 case ELFCLASSNONE: return _("none"); 4829 case ELFCLASS32: return "ELF32"; 4830 case ELFCLASS64: return "ELF64"; 4831 default: 4832 snprintf (buff, sizeof (buff), _("<unknown: %x>"), elf_class); 4833 return buff; 4834 } 4835 } 4836 4837 static const char * 4838 get_data_encoding (unsigned int encoding) 4839 { 4840 static char buff[32]; 4841 4842 switch (encoding) 4843 { 4844 case ELFDATANONE: return _("none"); 4845 case ELFDATA2LSB: return _("2's complement, little endian"); 4846 case ELFDATA2MSB: return _("2's complement, big endian"); 4847 default: 4848 snprintf (buff, sizeof (buff), _("<unknown: %x>"), encoding); 4849 return buff; 4850 } 4851 } 4852 4853 /* Decode the data held in 'filedata->file_header'. */ 4854 4855 static bfd_boolean 4856 process_file_header (Filedata * filedata) 4857 { 4858 Elf_Internal_Ehdr * header = & filedata->file_header; 4859 4860 if ( header->e_ident[EI_MAG0] != ELFMAG0 4861 || header->e_ident[EI_MAG1] != ELFMAG1 4862 || header->e_ident[EI_MAG2] != ELFMAG2 4863 || header->e_ident[EI_MAG3] != ELFMAG3) 4864 { 4865 error 4866 (_("Not an ELF file - it has the wrong magic bytes at the start\n")); 4867 return FALSE; 4868 } 4869 4870 init_dwarf_regnames_by_elf_machine_code (header->e_machine); 4871 4872 if (do_header) 4873 { 4874 unsigned i; 4875 4876 printf (_("ELF Header:\n")); 4877 printf (_(" Magic: ")); 4878 for (i = 0; i < EI_NIDENT; i++) 4879 printf ("%2.2x ", header->e_ident[i]); 4880 printf ("\n"); 4881 printf (_(" Class: %s\n"), 4882 get_elf_class (header->e_ident[EI_CLASS])); 4883 printf (_(" Data: %s\n"), 4884 get_data_encoding (header->e_ident[EI_DATA])); 4885 printf (_(" Version: %d%s\n"), 4886 header->e_ident[EI_VERSION], 4887 (header->e_ident[EI_VERSION] == EV_CURRENT 4888 ? _(" (current)") 4889 : (header->e_ident[EI_VERSION] != EV_NONE 4890 ? _(" <unknown>") 4891 : ""))); 4892 printf (_(" OS/ABI: %s\n"), 4893 get_osabi_name (filedata, header->e_ident[EI_OSABI])); 4894 printf (_(" ABI Version: %d\n"), 4895 header->e_ident[EI_ABIVERSION]); 4896 printf (_(" Type: %s\n"), 4897 get_file_type (header->e_type)); 4898 printf (_(" Machine: %s\n"), 4899 get_machine_name (header->e_machine)); 4900 printf (_(" Version: 0x%lx\n"), 4901 header->e_version); 4902 4903 printf (_(" Entry point address: ")); 4904 print_vma (header->e_entry, PREFIX_HEX); 4905 printf (_("\n Start of program headers: ")); 4906 print_vma (header->e_phoff, DEC); 4907 printf (_(" (bytes into file)\n Start of section headers: ")); 4908 print_vma (header->e_shoff, DEC); 4909 printf (_(" (bytes into file)\n")); 4910 4911 printf (_(" Flags: 0x%lx%s\n"), 4912 header->e_flags, 4913 get_machine_flags (filedata, header->e_flags, header->e_machine)); 4914 printf (_(" Size of this header: %u (bytes)\n"), 4915 header->e_ehsize); 4916 printf (_(" Size of program headers: %u (bytes)\n"), 4917 header->e_phentsize); 4918 printf (_(" Number of program headers: %u"), 4919 header->e_phnum); 4920 if (filedata->section_headers != NULL 4921 && header->e_phnum == PN_XNUM 4922 && filedata->section_headers[0].sh_info != 0) 4923 { 4924 header->e_phnum = filedata->section_headers[0].sh_info; 4925 printf (" (%u)", header->e_phnum); 4926 } 4927 putc ('\n', stdout); 4928 printf (_(" Size of section headers: %u (bytes)\n"), 4929 header->e_shentsize); 4930 printf (_(" Number of section headers: %u"), 4931 header->e_shnum); 4932 if (filedata->section_headers != NULL && header->e_shnum == SHN_UNDEF) 4933 { 4934 header->e_shnum = filedata->section_headers[0].sh_size; 4935 printf (" (%u)", header->e_shnum); 4936 } 4937 putc ('\n', stdout); 4938 printf (_(" Section header string table index: %u"), 4939 header->e_shstrndx); 4940 if (filedata->section_headers != NULL 4941 && header->e_shstrndx == (SHN_XINDEX & 0xffff)) 4942 { 4943 header->e_shstrndx = filedata->section_headers[0].sh_link; 4944 printf (" (%u)", header->e_shstrndx); 4945 } 4946 if (header->e_shstrndx != SHN_UNDEF 4947 && header->e_shstrndx >= header->e_shnum) 4948 { 4949 header->e_shstrndx = SHN_UNDEF; 4950 printf (_(" <corrupt: out of range>")); 4951 } 4952 putc ('\n', stdout); 4953 } 4954 4955 if (filedata->section_headers != NULL) 4956 { 4957 if (header->e_phnum == PN_XNUM 4958 && filedata->section_headers[0].sh_info != 0) 4959 header->e_phnum = filedata->section_headers[0].sh_info; 4960 if (header->e_shnum == SHN_UNDEF) 4961 header->e_shnum = filedata->section_headers[0].sh_size; 4962 if (header->e_shstrndx == (SHN_XINDEX & 0xffff)) 4963 header->e_shstrndx = filedata->section_headers[0].sh_link; 4964 if (header->e_shstrndx >= header->e_shnum) 4965 header->e_shstrndx = SHN_UNDEF; 4966 free (filedata->section_headers); 4967 filedata->section_headers = NULL; 4968 } 4969 4970 return TRUE; 4971 } 4972 4973 /* Read in the program headers from FILEDATA and store them in PHEADERS. 4974 Returns TRUE upon success, FALSE otherwise. Loads 32-bit headers. */ 4975 4976 static bfd_boolean 4977 get_32bit_program_headers (Filedata * filedata, Elf_Internal_Phdr * pheaders) 4978 { 4979 Elf32_External_Phdr * phdrs; 4980 Elf32_External_Phdr * external; 4981 Elf_Internal_Phdr * internal; 4982 unsigned int i; 4983 unsigned int size = filedata->file_header.e_phentsize; 4984 unsigned int num = filedata->file_header.e_phnum; 4985 4986 /* PR binutils/17531: Cope with unexpected section header sizes. */ 4987 if (size == 0 || num == 0) 4988 return FALSE; 4989 if (size < sizeof * phdrs) 4990 { 4991 error (_("The e_phentsize field in the ELF header is less than the size of an ELF program header\n")); 4992 return FALSE; 4993 } 4994 if (size > sizeof * phdrs) 4995 warn (_("The e_phentsize field in the ELF header is larger than the size of an ELF program header\n")); 4996 4997 phdrs = (Elf32_External_Phdr *) get_data (NULL, filedata, filedata->file_header.e_phoff, 4998 size, num, _("program headers")); 4999 if (phdrs == NULL) 5000 return FALSE; 5001 5002 for (i = 0, internal = pheaders, external = phdrs; 5003 i < filedata->file_header.e_phnum; 5004 i++, internal++, external++) 5005 { 5006 internal->p_type = BYTE_GET (external->p_type); 5007 internal->p_offset = BYTE_GET (external->p_offset); 5008 internal->p_vaddr = BYTE_GET (external->p_vaddr); 5009 internal->p_paddr = BYTE_GET (external->p_paddr); 5010 internal->p_filesz = BYTE_GET (external->p_filesz); 5011 internal->p_memsz = BYTE_GET (external->p_memsz); 5012 internal->p_flags = BYTE_GET (external->p_flags); 5013 internal->p_align = BYTE_GET (external->p_align); 5014 } 5015 5016 free (phdrs); 5017 return TRUE; 5018 } 5019 5020 /* Read in the program headers from FILEDATA and store them in PHEADERS. 5021 Returns TRUE upon success, FALSE otherwise. Loads 64-bit headers. */ 5022 5023 static bfd_boolean 5024 get_64bit_program_headers (Filedata * filedata, Elf_Internal_Phdr * pheaders) 5025 { 5026 Elf64_External_Phdr * phdrs; 5027 Elf64_External_Phdr * external; 5028 Elf_Internal_Phdr * internal; 5029 unsigned int i; 5030 unsigned int size = filedata->file_header.e_phentsize; 5031 unsigned int num = filedata->file_header.e_phnum; 5032 5033 /* PR binutils/17531: Cope with unexpected section header sizes. */ 5034 if (size == 0 || num == 0) 5035 return FALSE; 5036 if (size < sizeof * phdrs) 5037 { 5038 error (_("The e_phentsize field in the ELF header is less than the size of an ELF program header\n")); 5039 return FALSE; 5040 } 5041 if (size > sizeof * phdrs) 5042 warn (_("The e_phentsize field in the ELF header is larger than the size of an ELF program header\n")); 5043 5044 phdrs = (Elf64_External_Phdr *) get_data (NULL, filedata, filedata->file_header.e_phoff, 5045 size, num, _("program headers")); 5046 if (!phdrs) 5047 return FALSE; 5048 5049 for (i = 0, internal = pheaders, external = phdrs; 5050 i < filedata->file_header.e_phnum; 5051 i++, internal++, external++) 5052 { 5053 internal->p_type = BYTE_GET (external->p_type); 5054 internal->p_flags = BYTE_GET (external->p_flags); 5055 internal->p_offset = BYTE_GET (external->p_offset); 5056 internal->p_vaddr = BYTE_GET (external->p_vaddr); 5057 internal->p_paddr = BYTE_GET (external->p_paddr); 5058 internal->p_filesz = BYTE_GET (external->p_filesz); 5059 internal->p_memsz = BYTE_GET (external->p_memsz); 5060 internal->p_align = BYTE_GET (external->p_align); 5061 } 5062 5063 free (phdrs); 5064 return TRUE; 5065 } 5066 5067 /* Returns TRUE if the program headers were read into `program_headers'. */ 5068 5069 static bfd_boolean 5070 get_program_headers (Filedata * filedata) 5071 { 5072 Elf_Internal_Phdr * phdrs; 5073 5074 /* Check cache of prior read. */ 5075 if (filedata->program_headers != NULL) 5076 return TRUE; 5077 5078 /* Be kind to memory checkers by looking for 5079 e_phnum values which we know must be invalid. */ 5080 if (filedata->file_header.e_phnum 5081 * (is_32bit_elf ? sizeof (Elf32_External_Phdr) : sizeof (Elf64_External_Phdr)) 5082 >= filedata->file_size) 5083 { 5084 error (_("Too many program headers - %#x - the file is not that big\n"), 5085 filedata->file_header.e_phnum); 5086 return FALSE; 5087 } 5088 5089 phdrs = (Elf_Internal_Phdr *) cmalloc (filedata->file_header.e_phnum, 5090 sizeof (Elf_Internal_Phdr)); 5091 if (phdrs == NULL) 5092 { 5093 error (_("Out of memory reading %u program headers\n"), 5094 filedata->file_header.e_phnum); 5095 return FALSE; 5096 } 5097 5098 if (is_32bit_elf 5099 ? get_32bit_program_headers (filedata, phdrs) 5100 : get_64bit_program_headers (filedata, phdrs)) 5101 { 5102 filedata->program_headers = phdrs; 5103 return TRUE; 5104 } 5105 5106 free (phdrs); 5107 return FALSE; 5108 } 5109 5110 /* Returns TRUE if the program headers were loaded. */ 5111 5112 static bfd_boolean 5113 process_program_headers (Filedata * filedata) 5114 { 5115 Elf_Internal_Phdr * segment; 5116 unsigned int i; 5117 Elf_Internal_Phdr * previous_load = NULL; 5118 5119 dynamic_addr = 0; 5120 dynamic_size = 0; 5121 5122 if (filedata->file_header.e_phnum == 0) 5123 { 5124 /* PR binutils/12467. */ 5125 if (filedata->file_header.e_phoff != 0) 5126 { 5127 warn (_("possibly corrupt ELF header - it has a non-zero program" 5128 " header offset, but no program headers\n")); 5129 return FALSE; 5130 } 5131 else if (do_segments) 5132 printf (_("\nThere are no program headers in this file.\n")); 5133 return TRUE; 5134 } 5135 5136 if (do_segments && !do_header) 5137 { 5138 printf (_("\nElf file type is %s\n"), get_file_type (filedata->file_header.e_type)); 5139 printf (_("Entry point 0x%s\n"), bfd_vmatoa ("x", filedata->file_header.e_entry)); 5140 printf (ngettext ("There is %d program header, starting at offset %s\n", 5141 "There are %d program headers, starting at offset %s\n", 5142 filedata->file_header.e_phnum), 5143 filedata->file_header.e_phnum, 5144 bfd_vmatoa ("u", filedata->file_header.e_phoff)); 5145 } 5146 5147 if (! get_program_headers (filedata)) 5148 return TRUE; 5149 5150 if (do_segments) 5151 { 5152 if (filedata->file_header.e_phnum > 1) 5153 printf (_("\nProgram Headers:\n")); 5154 else 5155 printf (_("\nProgram Header:\n")); 5156 5157 if (is_32bit_elf) 5158 printf 5159 (_(" Type Offset VirtAddr PhysAddr FileSiz MemSiz Flg Align\n")); 5160 else if (do_wide) 5161 printf 5162 (_(" Type Offset VirtAddr PhysAddr FileSiz MemSiz Flg Align\n")); 5163 else 5164 { 5165 printf 5166 (_(" Type Offset VirtAddr PhysAddr\n")); 5167 printf 5168 (_(" FileSiz MemSiz Flags Align\n")); 5169 } 5170 } 5171 5172 for (i = 0, segment = filedata->program_headers; 5173 i < filedata->file_header.e_phnum; 5174 i++, segment++) 5175 { 5176 if (do_segments) 5177 { 5178 printf (" %-14.14s ", get_segment_type (filedata, segment->p_type)); 5179 5180 if (is_32bit_elf) 5181 { 5182 printf ("0x%6.6lx ", (unsigned long) segment->p_offset); 5183 printf ("0x%8.8lx ", (unsigned long) segment->p_vaddr); 5184 printf ("0x%8.8lx ", (unsigned long) segment->p_paddr); 5185 printf ("0x%5.5lx ", (unsigned long) segment->p_filesz); 5186 printf ("0x%5.5lx ", (unsigned long) segment->p_memsz); 5187 printf ("%c%c%c ", 5188 (segment->p_flags & PF_R ? 'R' : ' '), 5189 (segment->p_flags & PF_W ? 'W' : ' '), 5190 (segment->p_flags & PF_X ? 'E' : ' ')); 5191 printf ("%#lx", (unsigned long) segment->p_align); 5192 } 5193 else if (do_wide) 5194 { 5195 if ((unsigned long) segment->p_offset == segment->p_offset) 5196 printf ("0x%6.6lx ", (unsigned long) segment->p_offset); 5197 else 5198 { 5199 print_vma (segment->p_offset, FULL_HEX); 5200 putchar (' '); 5201 } 5202 5203 print_vma (segment->p_vaddr, FULL_HEX); 5204 putchar (' '); 5205 print_vma (segment->p_paddr, FULL_HEX); 5206 putchar (' '); 5207 5208 if ((unsigned long) segment->p_filesz == segment->p_filesz) 5209 printf ("0x%6.6lx ", (unsigned long) segment->p_filesz); 5210 else 5211 { 5212 print_vma (segment->p_filesz, FULL_HEX); 5213 putchar (' '); 5214 } 5215 5216 if ((unsigned long) segment->p_memsz == segment->p_memsz) 5217 printf ("0x%6.6lx", (unsigned long) segment->p_memsz); 5218 else 5219 { 5220 print_vma (segment->p_memsz, FULL_HEX); 5221 } 5222 5223 printf (" %c%c%c ", 5224 (segment->p_flags & PF_R ? 'R' : ' '), 5225 (segment->p_flags & PF_W ? 'W' : ' '), 5226 (segment->p_flags & PF_X ? 'E' : ' ')); 5227 5228 if ((unsigned long) segment->p_align == segment->p_align) 5229 printf ("%#lx", (unsigned long) segment->p_align); 5230 else 5231 { 5232 print_vma (segment->p_align, PREFIX_HEX); 5233 } 5234 } 5235 else 5236 { 5237 print_vma (segment->p_offset, FULL_HEX); 5238 putchar (' '); 5239 print_vma (segment->p_vaddr, FULL_HEX); 5240 putchar (' '); 5241 print_vma (segment->p_paddr, FULL_HEX); 5242 printf ("\n "); 5243 print_vma (segment->p_filesz, FULL_HEX); 5244 putchar (' '); 5245 print_vma (segment->p_memsz, FULL_HEX); 5246 printf (" %c%c%c ", 5247 (segment->p_flags & PF_R ? 'R' : ' '), 5248 (segment->p_flags & PF_W ? 'W' : ' '), 5249 (segment->p_flags & PF_X ? 'E' : ' ')); 5250 print_vma (segment->p_align, PREFIX_HEX); 5251 } 5252 5253 putc ('\n', stdout); 5254 } 5255 5256 switch (segment->p_type) 5257 { 5258 case PT_LOAD: 5259 #if 0 /* Do not warn about out of order PT_LOAD segments. Although officially 5260 required by the ELF standard, several programs, including the Linux 5261 kernel, make use of non-ordered segments. */ 5262 if (previous_load 5263 && previous_load->p_vaddr > segment->p_vaddr) 5264 error (_("LOAD segments must be sorted in order of increasing VirtAddr\n")); 5265 #endif 5266 if (segment->p_memsz < segment->p_filesz) 5267 error (_("the segment's file size is larger than its memory size\n")); 5268 previous_load = segment; 5269 break; 5270 5271 case PT_PHDR: 5272 /* PR 20815 - Verify that the program header is loaded into memory. */ 5273 if (i > 0 && previous_load != NULL) 5274 error (_("the PHDR segment must occur before any LOAD segment\n")); 5275 if (filedata->file_header.e_machine != EM_PARISC) 5276 { 5277 unsigned int j; 5278 5279 for (j = 1; j < filedata->file_header.e_phnum; j++) 5280 { 5281 Elf_Internal_Phdr *load = filedata->program_headers + j; 5282 if (load->p_type == PT_LOAD 5283 && load->p_offset <= segment->p_offset 5284 && (load->p_offset + load->p_filesz 5285 >= segment->p_offset + segment->p_filesz) 5286 && load->p_vaddr <= segment->p_vaddr 5287 && (load->p_vaddr + load->p_filesz 5288 >= segment->p_vaddr + segment->p_filesz)) 5289 break; 5290 } 5291 if (j == filedata->file_header.e_phnum) 5292 error (_("the PHDR segment is not covered by a LOAD segment\n")); 5293 } 5294 break; 5295 5296 case PT_DYNAMIC: 5297 if (dynamic_addr) 5298 error (_("more than one dynamic segment\n")); 5299 5300 /* By default, assume that the .dynamic section is the first 5301 section in the DYNAMIC segment. */ 5302 dynamic_addr = segment->p_offset; 5303 dynamic_size = segment->p_filesz; 5304 5305 /* Try to locate the .dynamic section. If there is 5306 a section header table, we can easily locate it. */ 5307 if (filedata->section_headers != NULL) 5308 { 5309 Elf_Internal_Shdr * sec; 5310 5311 sec = find_section (filedata, ".dynamic"); 5312 if (sec == NULL || sec->sh_size == 0) 5313 { 5314 /* A corresponding .dynamic section is expected, but on 5315 IA-64/OpenVMS it is OK for it to be missing. */ 5316 if (!is_ia64_vms (filedata)) 5317 error (_("no .dynamic section in the dynamic segment\n")); 5318 break; 5319 } 5320 5321 if (sec->sh_type == SHT_NOBITS) 5322 { 5323 dynamic_size = 0; 5324 break; 5325 } 5326 5327 dynamic_addr = sec->sh_offset; 5328 dynamic_size = sec->sh_size; 5329 5330 if (dynamic_addr < segment->p_offset 5331 || dynamic_addr > segment->p_offset + segment->p_filesz) 5332 warn (_("the .dynamic section is not contained" 5333 " within the dynamic segment\n")); 5334 else if (dynamic_addr > segment->p_offset) 5335 warn (_("the .dynamic section is not the first section" 5336 " in the dynamic segment.\n")); 5337 } 5338 5339 /* PR binutils/17512: Avoid corrupt dynamic section info in the 5340 segment. Check this after matching against the section headers 5341 so we don't warn on debuginfo file (which have NOBITS .dynamic 5342 sections). */ 5343 if (dynamic_addr > filedata->file_size 5344 || dynamic_size > filedata->file_size - dynamic_addr) 5345 { 5346 error (_("the dynamic segment offset + size exceeds the size of the file\n")); 5347 dynamic_addr = dynamic_size = 0; 5348 } 5349 break; 5350 5351 case PT_INTERP: 5352 if (fseek (filedata->handle, archive_file_offset + (long) segment->p_offset, 5353 SEEK_SET)) 5354 error (_("Unable to find program interpreter name\n")); 5355 else 5356 { 5357 char fmt [32]; 5358 int ret = snprintf (fmt, sizeof (fmt), "%%%ds", PATH_MAX - 1); 5359 5360 if (ret >= (int) sizeof (fmt) || ret < 0) 5361 error (_("Internal error: failed to create format string to display program interpreter\n")); 5362 5363 program_interpreter[0] = 0; 5364 if (fscanf (filedata->handle, fmt, program_interpreter) <= 0) 5365 error (_("Unable to read program interpreter name\n")); 5366 5367 if (do_segments) 5368 printf (_(" [Requesting program interpreter: %s]\n"), 5369 program_interpreter); 5370 } 5371 break; 5372 } 5373 } 5374 5375 if (do_segments 5376 && filedata->section_headers != NULL 5377 && filedata->string_table != NULL) 5378 { 5379 printf (_("\n Section to Segment mapping:\n")); 5380 printf (_(" Segment Sections...\n")); 5381 5382 for (i = 0; i < filedata->file_header.e_phnum; i++) 5383 { 5384 unsigned int j; 5385 Elf_Internal_Shdr * section; 5386 5387 segment = filedata->program_headers + i; 5388 section = filedata->section_headers + 1; 5389 5390 printf (" %2.2d ", i); 5391 5392 for (j = 1; j < filedata->file_header.e_shnum; j++, section++) 5393 { 5394 if (!ELF_TBSS_SPECIAL (section, segment) 5395 && ELF_SECTION_IN_SEGMENT_STRICT (section, segment)) 5396 printf ("%s ", printable_section_name (filedata, section)); 5397 } 5398 5399 putc ('\n',stdout); 5400 } 5401 } 5402 5403 return TRUE; 5404 } 5405 5406 5407 /* Find the file offset corresponding to VMA by using the program headers. */ 5408 5409 static long 5410 offset_from_vma (Filedata * filedata, bfd_vma vma, bfd_size_type size) 5411 { 5412 Elf_Internal_Phdr * seg; 5413 5414 if (! get_program_headers (filedata)) 5415 { 5416 warn (_("Cannot interpret virtual addresses without program headers.\n")); 5417 return (long) vma; 5418 } 5419 5420 for (seg = filedata->program_headers; 5421 seg < filedata->program_headers + filedata->file_header.e_phnum; 5422 ++seg) 5423 { 5424 if (seg->p_type != PT_LOAD) 5425 continue; 5426 5427 if (vma >= (seg->p_vaddr & -seg->p_align) 5428 && vma + size <= seg->p_vaddr + seg->p_filesz) 5429 return vma - seg->p_vaddr + seg->p_offset; 5430 } 5431 5432 warn (_("Virtual address 0x%lx not located in any PT_LOAD segment.\n"), 5433 (unsigned long) vma); 5434 return (long) vma; 5435 } 5436 5437 5438 /* Allocate memory and load the sections headers into FILEDATA->filedata->section_headers. 5439 If PROBE is true, this is just a probe and we do not generate any error 5440 messages if the load fails. */ 5441 5442 static bfd_boolean 5443 get_32bit_section_headers (Filedata * filedata, bfd_boolean probe) 5444 { 5445 Elf32_External_Shdr * shdrs; 5446 Elf_Internal_Shdr * internal; 5447 unsigned int i; 5448 unsigned int size = filedata->file_header.e_shentsize; 5449 unsigned int num = probe ? 1 : filedata->file_header.e_shnum; 5450 5451 /* PR binutils/17531: Cope with unexpected section header sizes. */ 5452 if (size == 0 || num == 0) 5453 return FALSE; 5454 if (size < sizeof * shdrs) 5455 { 5456 if (! probe) 5457 error (_("The e_shentsize field in the ELF header is less than the size of an ELF section header\n")); 5458 return FALSE; 5459 } 5460 if (!probe && size > sizeof * shdrs) 5461 warn (_("The e_shentsize field in the ELF header is larger than the size of an ELF section header\n")); 5462 5463 shdrs = (Elf32_External_Shdr *) get_data (NULL, filedata, filedata->file_header.e_shoff, 5464 size, num, 5465 probe ? NULL : _("section headers")); 5466 if (shdrs == NULL) 5467 return FALSE; 5468 5469 free (filedata->section_headers); 5470 filedata->section_headers = (Elf_Internal_Shdr *) 5471 cmalloc (num, sizeof (Elf_Internal_Shdr)); 5472 if (filedata->section_headers == NULL) 5473 { 5474 if (!probe) 5475 error (_("Out of memory reading %u section headers\n"), num); 5476 free (shdrs); 5477 return FALSE; 5478 } 5479 5480 for (i = 0, internal = filedata->section_headers; 5481 i < num; 5482 i++, internal++) 5483 { 5484 internal->sh_name = BYTE_GET (shdrs[i].sh_name); 5485 internal->sh_type = BYTE_GET (shdrs[i].sh_type); 5486 internal->sh_flags = BYTE_GET (shdrs[i].sh_flags); 5487 internal->sh_addr = BYTE_GET (shdrs[i].sh_addr); 5488 internal->sh_offset = BYTE_GET (shdrs[i].sh_offset); 5489 internal->sh_size = BYTE_GET (shdrs[i].sh_size); 5490 internal->sh_link = BYTE_GET (shdrs[i].sh_link); 5491 internal->sh_info = BYTE_GET (shdrs[i].sh_info); 5492 internal->sh_addralign = BYTE_GET (shdrs[i].sh_addralign); 5493 internal->sh_entsize = BYTE_GET (shdrs[i].sh_entsize); 5494 if (!probe && internal->sh_link > num) 5495 warn (_("Section %u has an out of range sh_link value of %u\n"), i, internal->sh_link); 5496 if (!probe && internal->sh_flags & SHF_INFO_LINK && internal->sh_info > num) 5497 warn (_("Section %u has an out of range sh_info value of %u\n"), i, internal->sh_info); 5498 } 5499 5500 free (shdrs); 5501 return TRUE; 5502 } 5503 5504 /* Like get_32bit_section_headers, except that it fetches 64-bit headers. */ 5505 5506 static bfd_boolean 5507 get_64bit_section_headers (Filedata * filedata, bfd_boolean probe) 5508 { 5509 Elf64_External_Shdr * shdrs; 5510 Elf_Internal_Shdr * internal; 5511 unsigned int i; 5512 unsigned int size = filedata->file_header.e_shentsize; 5513 unsigned int num = probe ? 1 : filedata->file_header.e_shnum; 5514 5515 /* PR binutils/17531: Cope with unexpected section header sizes. */ 5516 if (size == 0 || num == 0) 5517 return FALSE; 5518 5519 if (size < sizeof * shdrs) 5520 { 5521 if (! probe) 5522 error (_("The e_shentsize field in the ELF header is less than the size of an ELF section header\n")); 5523 return FALSE; 5524 } 5525 5526 if (! probe && size > sizeof * shdrs) 5527 warn (_("The e_shentsize field in the ELF header is larger than the size of an ELF section header\n")); 5528 5529 shdrs = (Elf64_External_Shdr *) get_data (NULL, filedata, 5530 filedata->file_header.e_shoff, 5531 size, num, 5532 probe ? NULL : _("section headers")); 5533 if (shdrs == NULL) 5534 return FALSE; 5535 5536 free (filedata->section_headers); 5537 filedata->section_headers = (Elf_Internal_Shdr *) 5538 cmalloc (num, sizeof (Elf_Internal_Shdr)); 5539 if (filedata->section_headers == NULL) 5540 { 5541 if (! probe) 5542 error (_("Out of memory reading %u section headers\n"), num); 5543 free (shdrs); 5544 return FALSE; 5545 } 5546 5547 for (i = 0, internal = filedata->section_headers; 5548 i < num; 5549 i++, internal++) 5550 { 5551 internal->sh_name = BYTE_GET (shdrs[i].sh_name); 5552 internal->sh_type = BYTE_GET (shdrs[i].sh_type); 5553 internal->sh_flags = BYTE_GET (shdrs[i].sh_flags); 5554 internal->sh_addr = BYTE_GET (shdrs[i].sh_addr); 5555 internal->sh_size = BYTE_GET (shdrs[i].sh_size); 5556 internal->sh_entsize = BYTE_GET (shdrs[i].sh_entsize); 5557 internal->sh_link = BYTE_GET (shdrs[i].sh_link); 5558 internal->sh_info = BYTE_GET (shdrs[i].sh_info); 5559 internal->sh_offset = BYTE_GET (shdrs[i].sh_offset); 5560 internal->sh_addralign = BYTE_GET (shdrs[i].sh_addralign); 5561 if (!probe && internal->sh_link > num) 5562 warn (_("Section %u has an out of range sh_link value of %u\n"), i, internal->sh_link); 5563 if (!probe && internal->sh_flags & SHF_INFO_LINK && internal->sh_info > num) 5564 warn (_("Section %u has an out of range sh_info value of %u\n"), i, internal->sh_info); 5565 } 5566 5567 free (shdrs); 5568 return TRUE; 5569 } 5570 5571 static Elf_Internal_Sym * 5572 get_32bit_elf_symbols (Filedata * filedata, 5573 Elf_Internal_Shdr * section, 5574 unsigned long * num_syms_return) 5575 { 5576 unsigned long number = 0; 5577 Elf32_External_Sym * esyms = NULL; 5578 Elf_External_Sym_Shndx * shndx = NULL; 5579 Elf_Internal_Sym * isyms = NULL; 5580 Elf_Internal_Sym * psym; 5581 unsigned int j; 5582 elf_section_list * entry; 5583 5584 if (section->sh_size == 0) 5585 { 5586 if (num_syms_return != NULL) 5587 * num_syms_return = 0; 5588 return NULL; 5589 } 5590 5591 /* Run some sanity checks first. */ 5592 if (section->sh_entsize == 0 || section->sh_entsize > section->sh_size) 5593 { 5594 error (_("Section %s has an invalid sh_entsize of 0x%lx\n"), 5595 printable_section_name (filedata, section), 5596 (unsigned long) section->sh_entsize); 5597 goto exit_point; 5598 } 5599 5600 if (section->sh_size > filedata->file_size) 5601 { 5602 error (_("Section %s has an invalid sh_size of 0x%lx\n"), 5603 printable_section_name (filedata, section), 5604 (unsigned long) section->sh_size); 5605 goto exit_point; 5606 } 5607 5608 number = section->sh_size / section->sh_entsize; 5609 5610 if (number * sizeof (Elf32_External_Sym) > section->sh_size + 1) 5611 { 5612 error (_("Size (0x%lx) of section %s is not a multiple of its sh_entsize (0x%lx)\n"), 5613 (unsigned long) section->sh_size, 5614 printable_section_name (filedata, section), 5615 (unsigned long) section->sh_entsize); 5616 goto exit_point; 5617 } 5618 5619 esyms = (Elf32_External_Sym *) get_data (NULL, filedata, section->sh_offset, 1, 5620 section->sh_size, _("symbols")); 5621 if (esyms == NULL) 5622 goto exit_point; 5623 5624 shndx = NULL; 5625 for (entry = symtab_shndx_list; entry != NULL; entry = entry->next) 5626 { 5627 if (entry->hdr->sh_link != (unsigned long) (section - filedata->section_headers)) 5628 continue; 5629 5630 if (shndx != NULL) 5631 { 5632 error (_("Multiple symbol table index sections associated with the same symbol section\n")); 5633 free (shndx); 5634 } 5635 5636 shndx = (Elf_External_Sym_Shndx *) get_data (NULL, filedata, 5637 entry->hdr->sh_offset, 5638 1, entry->hdr->sh_size, 5639 _("symbol table section indices")); 5640 if (shndx == NULL) 5641 goto exit_point; 5642 5643 /* PR17531: file: heap-buffer-overflow */ 5644 if (entry->hdr->sh_size / sizeof (Elf_External_Sym_Shndx) < number) 5645 { 5646 error (_("Index section %s has an sh_size of 0x%lx - expected 0x%lx\n"), 5647 printable_section_name (filedata, entry->hdr), 5648 (unsigned long) entry->hdr->sh_size, 5649 (unsigned long) section->sh_size); 5650 goto exit_point; 5651 } 5652 } 5653 5654 isyms = (Elf_Internal_Sym *) cmalloc (number, sizeof (Elf_Internal_Sym)); 5655 5656 if (isyms == NULL) 5657 { 5658 error (_("Out of memory reading %lu symbols\n"), 5659 (unsigned long) number); 5660 goto exit_point; 5661 } 5662 5663 for (j = 0, psym = isyms; j < number; j++, psym++) 5664 { 5665 psym->st_name = BYTE_GET (esyms[j].st_name); 5666 psym->st_value = BYTE_GET (esyms[j].st_value); 5667 psym->st_size = BYTE_GET (esyms[j].st_size); 5668 psym->st_shndx = BYTE_GET (esyms[j].st_shndx); 5669 if (psym->st_shndx == (SHN_XINDEX & 0xffff) && shndx != NULL) 5670 psym->st_shndx 5671 = byte_get ((unsigned char *) &shndx[j], sizeof (shndx[j])); 5672 else if (psym->st_shndx >= (SHN_LORESERVE & 0xffff)) 5673 psym->st_shndx += SHN_LORESERVE - (SHN_LORESERVE & 0xffff); 5674 psym->st_info = BYTE_GET (esyms[j].st_info); 5675 psym->st_other = BYTE_GET (esyms[j].st_other); 5676 } 5677 5678 exit_point: 5679 free (shndx); 5680 free (esyms); 5681 5682 if (num_syms_return != NULL) 5683 * num_syms_return = isyms == NULL ? 0 : number; 5684 5685 return isyms; 5686 } 5687 5688 static Elf_Internal_Sym * 5689 get_64bit_elf_symbols (Filedata * filedata, 5690 Elf_Internal_Shdr * section, 5691 unsigned long * num_syms_return) 5692 { 5693 unsigned long number = 0; 5694 Elf64_External_Sym * esyms = NULL; 5695 Elf_External_Sym_Shndx * shndx = NULL; 5696 Elf_Internal_Sym * isyms = NULL; 5697 Elf_Internal_Sym * psym; 5698 unsigned int j; 5699 elf_section_list * entry; 5700 5701 if (section->sh_size == 0) 5702 { 5703 if (num_syms_return != NULL) 5704 * num_syms_return = 0; 5705 return NULL; 5706 } 5707 5708 /* Run some sanity checks first. */ 5709 if (section->sh_entsize == 0 || section->sh_entsize > section->sh_size) 5710 { 5711 error (_("Section %s has an invalid sh_entsize of 0x%lx\n"), 5712 printable_section_name (filedata, section), 5713 (unsigned long) section->sh_entsize); 5714 goto exit_point; 5715 } 5716 5717 if (section->sh_size > filedata->file_size) 5718 { 5719 error (_("Section %s has an invalid sh_size of 0x%lx\n"), 5720 printable_section_name (filedata, section), 5721 (unsigned long) section->sh_size); 5722 goto exit_point; 5723 } 5724 5725 number = section->sh_size / section->sh_entsize; 5726 5727 if (number * sizeof (Elf64_External_Sym) > section->sh_size + 1) 5728 { 5729 error (_("Size (0x%lx) of section %s is not a multiple of its sh_entsize (0x%lx)\n"), 5730 (unsigned long) section->sh_size, 5731 printable_section_name (filedata, section), 5732 (unsigned long) section->sh_entsize); 5733 goto exit_point; 5734 } 5735 5736 esyms = (Elf64_External_Sym *) get_data (NULL, filedata, section->sh_offset, 1, 5737 section->sh_size, _("symbols")); 5738 if (!esyms) 5739 goto exit_point; 5740 5741 shndx = NULL; 5742 for (entry = symtab_shndx_list; entry != NULL; entry = entry->next) 5743 { 5744 if (entry->hdr->sh_link != (unsigned long) (section - filedata->section_headers)) 5745 continue; 5746 5747 if (shndx != NULL) 5748 { 5749 error (_("Multiple symbol table index sections associated with the same symbol section\n")); 5750 free (shndx); 5751 } 5752 5753 shndx = (Elf_External_Sym_Shndx *) get_data (NULL, filedata, 5754 entry->hdr->sh_offset, 5755 1, entry->hdr->sh_size, 5756 _("symbol table section indices")); 5757 if (shndx == NULL) 5758 goto exit_point; 5759 5760 /* PR17531: file: heap-buffer-overflow */ 5761 if (entry->hdr->sh_size / sizeof (Elf_External_Sym_Shndx) < number) 5762 { 5763 error (_("Index section %s has an sh_size of 0x%lx - expected 0x%lx\n"), 5764 printable_section_name (filedata, entry->hdr), 5765 (unsigned long) entry->hdr->sh_size, 5766 (unsigned long) section->sh_size); 5767 goto exit_point; 5768 } 5769 } 5770 5771 isyms = (Elf_Internal_Sym *) cmalloc (number, sizeof (Elf_Internal_Sym)); 5772 5773 if (isyms == NULL) 5774 { 5775 error (_("Out of memory reading %lu symbols\n"), 5776 (unsigned long) number); 5777 goto exit_point; 5778 } 5779 5780 for (j = 0, psym = isyms; j < number; j++, psym++) 5781 { 5782 psym->st_name = BYTE_GET (esyms[j].st_name); 5783 psym->st_info = BYTE_GET (esyms[j].st_info); 5784 psym->st_other = BYTE_GET (esyms[j].st_other); 5785 psym->st_shndx = BYTE_GET (esyms[j].st_shndx); 5786 5787 if (psym->st_shndx == (SHN_XINDEX & 0xffff) && shndx != NULL) 5788 psym->st_shndx 5789 = byte_get ((unsigned char *) &shndx[j], sizeof (shndx[j])); 5790 else if (psym->st_shndx >= (SHN_LORESERVE & 0xffff)) 5791 psym->st_shndx += SHN_LORESERVE - (SHN_LORESERVE & 0xffff); 5792 5793 psym->st_value = BYTE_GET (esyms[j].st_value); 5794 psym->st_size = BYTE_GET (esyms[j].st_size); 5795 } 5796 5797 exit_point: 5798 free (shndx); 5799 free (esyms); 5800 5801 if (num_syms_return != NULL) 5802 * num_syms_return = isyms == NULL ? 0 : number; 5803 5804 return isyms; 5805 } 5806 5807 static const char * 5808 get_elf_section_flags (Filedata * filedata, bfd_vma sh_flags) 5809 { 5810 static char buff[1024]; 5811 char * p = buff; 5812 unsigned int field_size = is_32bit_elf ? 8 : 16; 5813 signed int sindex; 5814 unsigned int size = sizeof (buff) - (field_size + 4 + 1); 5815 bfd_vma os_flags = 0; 5816 bfd_vma proc_flags = 0; 5817 bfd_vma unknown_flags = 0; 5818 static const struct 5819 { 5820 const char * str; 5821 unsigned int len; 5822 } 5823 flags [] = 5824 { 5825 /* 0 */ { STRING_COMMA_LEN ("WRITE") }, 5826 /* 1 */ { STRING_COMMA_LEN ("ALLOC") }, 5827 /* 2 */ { STRING_COMMA_LEN ("EXEC") }, 5828 /* 3 */ { STRING_COMMA_LEN ("MERGE") }, 5829 /* 4 */ { STRING_COMMA_LEN ("STRINGS") }, 5830 /* 5 */ { STRING_COMMA_LEN ("INFO LINK") }, 5831 /* 6 */ { STRING_COMMA_LEN ("LINK ORDER") }, 5832 /* 7 */ { STRING_COMMA_LEN ("OS NONCONF") }, 5833 /* 8 */ { STRING_COMMA_LEN ("GROUP") }, 5834 /* 9 */ { STRING_COMMA_LEN ("TLS") }, 5835 /* IA-64 specific. */ 5836 /* 10 */ { STRING_COMMA_LEN ("SHORT") }, 5837 /* 11 */ { STRING_COMMA_LEN ("NORECOV") }, 5838 /* IA-64 OpenVMS specific. */ 5839 /* 12 */ { STRING_COMMA_LEN ("VMS_GLOBAL") }, 5840 /* 13 */ { STRING_COMMA_LEN ("VMS_OVERLAID") }, 5841 /* 14 */ { STRING_COMMA_LEN ("VMS_SHARED") }, 5842 /* 15 */ { STRING_COMMA_LEN ("VMS_VECTOR") }, 5843 /* 16 */ { STRING_COMMA_LEN ("VMS_ALLOC_64BIT") }, 5844 /* 17 */ { STRING_COMMA_LEN ("VMS_PROTECTED") }, 5845 /* Generic. */ 5846 /* 18 */ { STRING_COMMA_LEN ("EXCLUDE") }, 5847 /* SPARC specific. */ 5848 /* 19 */ { STRING_COMMA_LEN ("ORDERED") }, 5849 /* 20 */ { STRING_COMMA_LEN ("COMPRESSED") }, 5850 /* ARM specific. */ 5851 /* 21 */ { STRING_COMMA_LEN ("ENTRYSECT") }, 5852 /* 22 */ { STRING_COMMA_LEN ("ARM_PURECODE") }, 5853 /* 23 */ { STRING_COMMA_LEN ("COMDEF") }, 5854 /* GNU specific. */ 5855 /* 24 */ { STRING_COMMA_LEN ("GNU_MBIND") }, 5856 /* VLE specific. */ 5857 /* 25 */ { STRING_COMMA_LEN ("VLE") }, 5858 }; 5859 5860 if (do_section_details) 5861 { 5862 sprintf (buff, "[%*.*lx]: ", 5863 field_size, field_size, (unsigned long) sh_flags); 5864 p += field_size + 4; 5865 } 5866 5867 while (sh_flags) 5868 { 5869 bfd_vma flag; 5870 5871 flag = sh_flags & - sh_flags; 5872 sh_flags &= ~ flag; 5873 5874 if (do_section_details) 5875 { 5876 switch (flag) 5877 { 5878 case SHF_WRITE: sindex = 0; break; 5879 case SHF_ALLOC: sindex = 1; break; 5880 case SHF_EXECINSTR: sindex = 2; break; 5881 case SHF_MERGE: sindex = 3; break; 5882 case SHF_STRINGS: sindex = 4; break; 5883 case SHF_INFO_LINK: sindex = 5; break; 5884 case SHF_LINK_ORDER: sindex = 6; break; 5885 case SHF_OS_NONCONFORMING: sindex = 7; break; 5886 case SHF_GROUP: sindex = 8; break; 5887 case SHF_TLS: sindex = 9; break; 5888 case SHF_EXCLUDE: sindex = 18; break; 5889 case SHF_COMPRESSED: sindex = 20; break; 5890 case SHF_GNU_MBIND: sindex = 24; break; 5891 5892 default: 5893 sindex = -1; 5894 switch (filedata->file_header.e_machine) 5895 { 5896 case EM_IA_64: 5897 if (flag == SHF_IA_64_SHORT) 5898 sindex = 10; 5899 else if (flag == SHF_IA_64_NORECOV) 5900 sindex = 11; 5901 #ifdef BFD64 5902 else if (filedata->file_header.e_ident[EI_OSABI] == ELFOSABI_OPENVMS) 5903 switch (flag) 5904 { 5905 case SHF_IA_64_VMS_GLOBAL: sindex = 12; break; 5906 case SHF_IA_64_VMS_OVERLAID: sindex = 13; break; 5907 case SHF_IA_64_VMS_SHARED: sindex = 14; break; 5908 case SHF_IA_64_VMS_VECTOR: sindex = 15; break; 5909 case SHF_IA_64_VMS_ALLOC_64BIT: sindex = 16; break; 5910 case SHF_IA_64_VMS_PROTECTED: sindex = 17; break; 5911 default: break; 5912 } 5913 #endif 5914 break; 5915 5916 case EM_386: 5917 case EM_IAMCU: 5918 case EM_X86_64: 5919 case EM_L1OM: 5920 case EM_K1OM: 5921 case EM_OLD_SPARCV9: 5922 case EM_SPARC32PLUS: 5923 case EM_SPARCV9: 5924 case EM_SPARC: 5925 if (flag == SHF_ORDERED) 5926 sindex = 19; 5927 break; 5928 5929 case EM_ARM: 5930 switch (flag) 5931 { 5932 case SHF_ENTRYSECT: sindex = 21; break; 5933 case SHF_ARM_PURECODE: sindex = 22; break; 5934 case SHF_COMDEF: sindex = 23; break; 5935 default: break; 5936 } 5937 break; 5938 case EM_PPC: 5939 if (flag == SHF_PPC_VLE) 5940 sindex = 25; 5941 break; 5942 5943 default: 5944 break; 5945 } 5946 } 5947 5948 if (sindex != -1) 5949 { 5950 if (p != buff + field_size + 4) 5951 { 5952 if (size < (10 + 2)) 5953 { 5954 warn (_("Internal error: not enough buffer room for section flag info")); 5955 return _("<unknown>"); 5956 } 5957 size -= 2; 5958 *p++ = ','; 5959 *p++ = ' '; 5960 } 5961 5962 size -= flags [sindex].len; 5963 p = stpcpy (p, flags [sindex].str); 5964 } 5965 else if (flag & SHF_MASKOS) 5966 os_flags |= flag; 5967 else if (flag & SHF_MASKPROC) 5968 proc_flags |= flag; 5969 else 5970 unknown_flags |= flag; 5971 } 5972 else 5973 { 5974 switch (flag) 5975 { 5976 case SHF_WRITE: *p = 'W'; break; 5977 case SHF_ALLOC: *p = 'A'; break; 5978 case SHF_EXECINSTR: *p = 'X'; break; 5979 case SHF_MERGE: *p = 'M'; break; 5980 case SHF_STRINGS: *p = 'S'; break; 5981 case SHF_INFO_LINK: *p = 'I'; break; 5982 case SHF_LINK_ORDER: *p = 'L'; break; 5983 case SHF_OS_NONCONFORMING: *p = 'O'; break; 5984 case SHF_GROUP: *p = 'G'; break; 5985 case SHF_TLS: *p = 'T'; break; 5986 case SHF_EXCLUDE: *p = 'E'; break; 5987 case SHF_COMPRESSED: *p = 'C'; break; 5988 case SHF_GNU_MBIND: *p = 'D'; break; 5989 5990 default: 5991 if ((filedata->file_header.e_machine == EM_X86_64 5992 || filedata->file_header.e_machine == EM_L1OM 5993 || filedata->file_header.e_machine == EM_K1OM) 5994 && flag == SHF_X86_64_LARGE) 5995 *p = 'l'; 5996 else if (filedata->file_header.e_machine == EM_ARM 5997 && flag == SHF_ARM_PURECODE) 5998 *p = 'y'; 5999 else if (filedata->file_header.e_machine == EM_PPC 6000 && flag == SHF_PPC_VLE) 6001 *p = 'v'; 6002 else if (flag & SHF_MASKOS) 6003 { 6004 *p = 'o'; 6005 sh_flags &= ~ SHF_MASKOS; 6006 } 6007 else if (flag & SHF_MASKPROC) 6008 { 6009 *p = 'p'; 6010 sh_flags &= ~ SHF_MASKPROC; 6011 } 6012 else 6013 *p = 'x'; 6014 break; 6015 } 6016 p++; 6017 } 6018 } 6019 6020 if (do_section_details) 6021 { 6022 if (os_flags) 6023 { 6024 size -= 5 + field_size; 6025 if (p != buff + field_size + 4) 6026 { 6027 if (size < (2 + 1)) 6028 { 6029 warn (_("Internal error: not enough buffer room for section flag info")); 6030 return _("<unknown>"); 6031 } 6032 size -= 2; 6033 *p++ = ','; 6034 *p++ = ' '; 6035 } 6036 sprintf (p, "OS (%*.*lx)", field_size, field_size, 6037 (unsigned long) os_flags); 6038 p += 5 + field_size; 6039 } 6040 if (proc_flags) 6041 { 6042 size -= 7 + field_size; 6043 if (p != buff + field_size + 4) 6044 { 6045 if (size < (2 + 1)) 6046 { 6047 warn (_("Internal error: not enough buffer room for section flag info")); 6048 return _("<unknown>"); 6049 } 6050 size -= 2; 6051 *p++ = ','; 6052 *p++ = ' '; 6053 } 6054 sprintf (p, "PROC (%*.*lx)", field_size, field_size, 6055 (unsigned long) proc_flags); 6056 p += 7 + field_size; 6057 } 6058 if (unknown_flags) 6059 { 6060 size -= 10 + field_size; 6061 if (p != buff + field_size + 4) 6062 { 6063 if (size < (2 + 1)) 6064 { 6065 warn (_("Internal error: not enough buffer room for section flag info")); 6066 return _("<unknown>"); 6067 } 6068 size -= 2; 6069 *p++ = ','; 6070 *p++ = ' '; 6071 } 6072 sprintf (p, _("UNKNOWN (%*.*lx)"), field_size, field_size, 6073 (unsigned long) unknown_flags); 6074 p += 10 + field_size; 6075 } 6076 } 6077 6078 *p = '\0'; 6079 return buff; 6080 } 6081 6082 static unsigned int 6083 get_compression_header (Elf_Internal_Chdr *chdr, unsigned char *buf, bfd_size_type size) 6084 { 6085 if (is_32bit_elf) 6086 { 6087 Elf32_External_Chdr *echdr = (Elf32_External_Chdr *) buf; 6088 6089 if (size < sizeof (* echdr)) 6090 { 6091 error (_("Compressed section is too small even for a compression header\n")); 6092 return 0; 6093 } 6094 6095 chdr->ch_type = BYTE_GET (echdr->ch_type); 6096 chdr->ch_size = BYTE_GET (echdr->ch_size); 6097 chdr->ch_addralign = BYTE_GET (echdr->ch_addralign); 6098 return sizeof (*echdr); 6099 } 6100 else 6101 { 6102 Elf64_External_Chdr *echdr = (Elf64_External_Chdr *) buf; 6103 6104 if (size < sizeof (* echdr)) 6105 { 6106 error (_("Compressed section is too small even for a compression header\n")); 6107 return 0; 6108 } 6109 6110 chdr->ch_type = BYTE_GET (echdr->ch_type); 6111 chdr->ch_size = BYTE_GET (echdr->ch_size); 6112 chdr->ch_addralign = BYTE_GET (echdr->ch_addralign); 6113 return sizeof (*echdr); 6114 } 6115 } 6116 6117 static bfd_boolean 6118 process_section_headers (Filedata * filedata) 6119 { 6120 Elf_Internal_Shdr * section; 6121 unsigned int i; 6122 6123 filedata->section_headers = NULL; 6124 6125 if (filedata->file_header.e_shnum == 0) 6126 { 6127 /* PR binutils/12467. */ 6128 if (filedata->file_header.e_shoff != 0) 6129 { 6130 warn (_("possibly corrupt ELF file header - it has a non-zero" 6131 " section header offset, but no section headers\n")); 6132 return FALSE; 6133 } 6134 else if (do_sections) 6135 printf (_("\nThere are no sections in this file.\n")); 6136 6137 return TRUE; 6138 } 6139 6140 if (do_sections && !do_header) 6141 printf (ngettext ("There is %d section header, " 6142 "starting at offset 0x%lx:\n", 6143 "There are %d section headers, " 6144 "starting at offset 0x%lx:\n", 6145 filedata->file_header.e_shnum), 6146 filedata->file_header.e_shnum, 6147 (unsigned long) filedata->file_header.e_shoff); 6148 6149 if (is_32bit_elf) 6150 { 6151 if (! get_32bit_section_headers (filedata, FALSE)) 6152 return FALSE; 6153 } 6154 else 6155 { 6156 if (! get_64bit_section_headers (filedata, FALSE)) 6157 return FALSE; 6158 } 6159 6160 /* Read in the string table, so that we have names to display. */ 6161 if (filedata->file_header.e_shstrndx != SHN_UNDEF 6162 && filedata->file_header.e_shstrndx < filedata->file_header.e_shnum) 6163 { 6164 section = filedata->section_headers + filedata->file_header.e_shstrndx; 6165 6166 if (section->sh_size != 0) 6167 { 6168 filedata->string_table = (char *) get_data (NULL, filedata, section->sh_offset, 6169 1, section->sh_size, 6170 _("string table")); 6171 6172 filedata->string_table_length = filedata->string_table != NULL ? section->sh_size : 0; 6173 } 6174 } 6175 6176 /* Scan the sections for the dynamic symbol table 6177 and dynamic string table and debug sections. */ 6178 dynamic_symbols = NULL; 6179 dynamic_strings = NULL; 6180 dynamic_syminfo = NULL; 6181 symtab_shndx_list = NULL; 6182 6183 eh_addr_size = is_32bit_elf ? 4 : 8; 6184 switch (filedata->file_header.e_machine) 6185 { 6186 case EM_MIPS: 6187 case EM_MIPS_RS3_LE: 6188 /* The 64-bit MIPS EABI uses a combination of 32-bit ELF and 64-bit 6189 FDE addresses. However, the ABI also has a semi-official ILP32 6190 variant for which the normal FDE address size rules apply. 6191 6192 GCC 4.0 marks EABI64 objects with a dummy .gcc_compiled_longXX 6193 section, where XX is the size of longs in bits. Unfortunately, 6194 earlier compilers provided no way of distinguishing ILP32 objects 6195 from LP64 objects, so if there's any doubt, we should assume that 6196 the official LP64 form is being used. */ 6197 if ((filedata->file_header.e_flags & EF_MIPS_ABI) == E_MIPS_ABI_EABI64 6198 && find_section (filedata, ".gcc_compiled_long32") == NULL) 6199 eh_addr_size = 8; 6200 break; 6201 6202 case EM_H8_300: 6203 case EM_H8_300H: 6204 switch (filedata->file_header.e_flags & EF_H8_MACH) 6205 { 6206 case E_H8_MACH_H8300: 6207 case E_H8_MACH_H8300HN: 6208 case E_H8_MACH_H8300SN: 6209 case E_H8_MACH_H8300SXN: 6210 eh_addr_size = 2; 6211 break; 6212 case E_H8_MACH_H8300H: 6213 case E_H8_MACH_H8300S: 6214 case E_H8_MACH_H8300SX: 6215 eh_addr_size = 4; 6216 break; 6217 } 6218 break; 6219 6220 case EM_M32C_OLD: 6221 case EM_M32C: 6222 switch (filedata->file_header.e_flags & EF_M32C_CPU_MASK) 6223 { 6224 case EF_M32C_CPU_M16C: 6225 eh_addr_size = 2; 6226 break; 6227 } 6228 break; 6229 } 6230 6231 #define CHECK_ENTSIZE_VALUES(section, i, size32, size64) \ 6232 do \ 6233 { \ 6234 bfd_size_type expected_entsize = is_32bit_elf ? size32 : size64; \ 6235 if (section->sh_entsize != expected_entsize) \ 6236 { \ 6237 char buf[40]; \ 6238 sprintf_vma (buf, section->sh_entsize); \ 6239 /* Note: coded this way so that there is a single string for \ 6240 translation. */ \ 6241 error (_("Section %d has invalid sh_entsize of %s\n"), i, buf); \ 6242 error (_("(Using the expected size of %u for the rest of this dump)\n"), \ 6243 (unsigned) expected_entsize); \ 6244 section->sh_entsize = expected_entsize; \ 6245 } \ 6246 } \ 6247 while (0) 6248 6249 #define CHECK_ENTSIZE(section, i, type) \ 6250 CHECK_ENTSIZE_VALUES (section, i, sizeof (Elf32_External_##type), \ 6251 sizeof (Elf64_External_##type)) 6252 6253 for (i = 0, section = filedata->section_headers; 6254 i < filedata->file_header.e_shnum; 6255 i++, section++) 6256 { 6257 char * name = SECTION_NAME (section); 6258 6259 if (section->sh_type == SHT_DYNSYM) 6260 { 6261 if (dynamic_symbols != NULL) 6262 { 6263 error (_("File contains multiple dynamic symbol tables\n")); 6264 continue; 6265 } 6266 6267 CHECK_ENTSIZE (section, i, Sym); 6268 dynamic_symbols = GET_ELF_SYMBOLS (filedata, section, & num_dynamic_syms); 6269 } 6270 else if (section->sh_type == SHT_STRTAB 6271 && streq (name, ".dynstr")) 6272 { 6273 if (dynamic_strings != NULL) 6274 { 6275 error (_("File contains multiple dynamic string tables\n")); 6276 continue; 6277 } 6278 6279 dynamic_strings = (char *) get_data (NULL, filedata, section->sh_offset, 6280 1, section->sh_size, 6281 _("dynamic strings")); 6282 dynamic_strings_length = dynamic_strings == NULL ? 0 : section->sh_size; 6283 } 6284 else if (section->sh_type == SHT_SYMTAB_SHNDX) 6285 { 6286 elf_section_list * entry = xmalloc (sizeof * entry); 6287 6288 entry->hdr = section; 6289 entry->next = symtab_shndx_list; 6290 symtab_shndx_list = entry; 6291 } 6292 else if (section->sh_type == SHT_SYMTAB) 6293 CHECK_ENTSIZE (section, i, Sym); 6294 else if (section->sh_type == SHT_GROUP) 6295 CHECK_ENTSIZE_VALUES (section, i, GRP_ENTRY_SIZE, GRP_ENTRY_SIZE); 6296 else if (section->sh_type == SHT_REL) 6297 CHECK_ENTSIZE (section, i, Rel); 6298 else if (section->sh_type == SHT_RELA) 6299 CHECK_ENTSIZE (section, i, Rela); 6300 else if ((do_debugging || do_debug_info || do_debug_abbrevs 6301 || do_debug_lines || do_debug_pubnames || do_debug_pubtypes 6302 || do_debug_aranges || do_debug_frames || do_debug_macinfo 6303 || do_debug_str || do_debug_loc || do_debug_ranges 6304 || do_debug_addr || do_debug_cu_index || do_debug_links) 6305 && (const_strneq (name, ".debug_") 6306 || const_strneq (name, ".zdebug_"))) 6307 { 6308 if (name[1] == 'z') 6309 name += sizeof (".zdebug_") - 1; 6310 else 6311 name += sizeof (".debug_") - 1; 6312 6313 if (do_debugging 6314 || (do_debug_info && const_strneq (name, "info")) 6315 || (do_debug_info && const_strneq (name, "types")) 6316 || (do_debug_abbrevs && const_strneq (name, "abbrev")) 6317 || (do_debug_lines && strcmp (name, "line") == 0) 6318 || (do_debug_lines && const_strneq (name, "line.")) 6319 || (do_debug_pubnames && const_strneq (name, "pubnames")) 6320 || (do_debug_pubtypes && const_strneq (name, "pubtypes")) 6321 || (do_debug_pubnames && const_strneq (name, "gnu_pubnames")) 6322 || (do_debug_pubtypes && const_strneq (name, "gnu_pubtypes")) 6323 || (do_debug_aranges && const_strneq (name, "aranges")) 6324 || (do_debug_ranges && const_strneq (name, "ranges")) 6325 || (do_debug_ranges && const_strneq (name, "rnglists")) 6326 || (do_debug_frames && const_strneq (name, "frame")) 6327 || (do_debug_macinfo && const_strneq (name, "macinfo")) 6328 || (do_debug_macinfo && const_strneq (name, "macro")) 6329 || (do_debug_str && const_strneq (name, "str")) 6330 || (do_debug_loc && const_strneq (name, "loc")) 6331 || (do_debug_loc && const_strneq (name, "loclists")) 6332 || (do_debug_addr && const_strneq (name, "addr")) 6333 || (do_debug_cu_index && const_strneq (name, "cu_index")) 6334 || (do_debug_cu_index && const_strneq (name, "tu_index")) 6335 ) 6336 request_dump_bynumber (filedata, i, DEBUG_DUMP); 6337 } 6338 /* Linkonce section to be combined with .debug_info at link time. */ 6339 else if ((do_debugging || do_debug_info) 6340 && const_strneq (name, ".gnu.linkonce.wi.")) 6341 request_dump_bynumber (filedata, i, DEBUG_DUMP); 6342 else if (do_debug_frames && streq (name, ".eh_frame")) 6343 request_dump_bynumber (filedata, i, DEBUG_DUMP); 6344 else if (do_gdb_index && (streq (name, ".gdb_index") 6345 || streq (name, ".debug_names"))) 6346 request_dump_bynumber (filedata, i, DEBUG_DUMP); 6347 /* Trace sections for Itanium VMS. */ 6348 else if ((do_debugging || do_trace_info || do_trace_abbrevs 6349 || do_trace_aranges) 6350 && const_strneq (name, ".trace_")) 6351 { 6352 name += sizeof (".trace_") - 1; 6353 6354 if (do_debugging 6355 || (do_trace_info && streq (name, "info")) 6356 || (do_trace_abbrevs && streq (name, "abbrev")) 6357 || (do_trace_aranges && streq (name, "aranges")) 6358 ) 6359 request_dump_bynumber (filedata, i, DEBUG_DUMP); 6360 } 6361 else if ((do_debugging || do_debug_links) 6362 && (const_strneq (name, ".gnu_debuglink") 6363 || const_strneq (name, ".gnu_debugaltlink"))) 6364 request_dump_bynumber (filedata, i, DEBUG_DUMP); 6365 } 6366 6367 if (! do_sections) 6368 return TRUE; 6369 6370 if (filedata->file_header.e_shnum > 1) 6371 printf (_("\nSection Headers:\n")); 6372 else 6373 printf (_("\nSection Header:\n")); 6374 6375 if (is_32bit_elf) 6376 { 6377 if (do_section_details) 6378 { 6379 printf (_(" [Nr] Name\n")); 6380 printf (_(" Type Addr Off Size ES Lk Inf Al\n")); 6381 } 6382 else 6383 printf 6384 (_(" [Nr] Name Type Addr Off Size ES Flg Lk Inf Al\n")); 6385 } 6386 else if (do_wide) 6387 { 6388 if (do_section_details) 6389 { 6390 printf (_(" [Nr] Name\n")); 6391 printf (_(" Type Address Off Size ES Lk Inf Al\n")); 6392 } 6393 else 6394 printf 6395 (_(" [Nr] Name Type Address Off Size ES Flg Lk Inf Al\n")); 6396 } 6397 else 6398 { 6399 if (do_section_details) 6400 { 6401 printf (_(" [Nr] Name\n")); 6402 printf (_(" Type Address Offset Link\n")); 6403 printf (_(" Size EntSize Info Align\n")); 6404 } 6405 else 6406 { 6407 printf (_(" [Nr] Name Type Address Offset\n")); 6408 printf (_(" Size EntSize Flags Link Info Align\n")); 6409 } 6410 } 6411 6412 if (do_section_details) 6413 printf (_(" Flags\n")); 6414 6415 for (i = 0, section = filedata->section_headers; 6416 i < filedata->file_header.e_shnum; 6417 i++, section++) 6418 { 6419 /* Run some sanity checks on the section header. */ 6420 6421 /* Check the sh_link field. */ 6422 switch (section->sh_type) 6423 { 6424 case SHT_REL: 6425 case SHT_RELA: 6426 if (section->sh_link == 0 6427 && (filedata->file_header.e_type == ET_EXEC 6428 || filedata->file_header.e_type == ET_DYN)) 6429 /* A dynamic relocation section where all entries use a 6430 zero symbol index need not specify a symtab section. */ 6431 break; 6432 /* Fall through. */ 6433 case SHT_SYMTAB_SHNDX: 6434 case SHT_GROUP: 6435 case SHT_HASH: 6436 case SHT_GNU_HASH: 6437 case SHT_GNU_versym: 6438 if (section->sh_link == 0 6439 || section->sh_link >= filedata->file_header.e_shnum 6440 || (filedata->section_headers[section->sh_link].sh_type != SHT_SYMTAB 6441 && filedata->section_headers[section->sh_link].sh_type != SHT_DYNSYM)) 6442 warn (_("[%2u]: Link field (%u) should index a symtab section.\n"), 6443 i, section->sh_link); 6444 break; 6445 6446 case SHT_DYNAMIC: 6447 case SHT_SYMTAB: 6448 case SHT_DYNSYM: 6449 case SHT_GNU_verneed: 6450 case SHT_GNU_verdef: 6451 case SHT_GNU_LIBLIST: 6452 if (section->sh_link == 0 6453 || section->sh_link >= filedata->file_header.e_shnum 6454 || filedata->section_headers[section->sh_link].sh_type != SHT_STRTAB) 6455 warn (_("[%2u]: Link field (%u) should index a string section.\n"), 6456 i, section->sh_link); 6457 break; 6458 6459 case SHT_INIT_ARRAY: 6460 case SHT_FINI_ARRAY: 6461 case SHT_PREINIT_ARRAY: 6462 if (section->sh_type < SHT_LOOS && section->sh_link != 0) 6463 warn (_("[%2u]: Unexpected value (%u) in link field.\n"), 6464 i, section->sh_link); 6465 break; 6466 6467 default: 6468 /* FIXME: Add support for target specific section types. */ 6469 #if 0 /* Currently we do not check other section types as there are too 6470 many special cases. Stab sections for example have a type 6471 of SHT_PROGBITS but an sh_link field that links to the .stabstr 6472 section. */ 6473 if (section->sh_type < SHT_LOOS && section->sh_link != 0) 6474 warn (_("[%2u]: Unexpected value (%u) in link field.\n"), 6475 i, section->sh_link); 6476 #endif 6477 break; 6478 } 6479 6480 /* Check the sh_info field. */ 6481 switch (section->sh_type) 6482 { 6483 case SHT_REL: 6484 case SHT_RELA: 6485 if (section->sh_info == 0 6486 && (filedata->file_header.e_type == ET_EXEC 6487 || filedata->file_header.e_type == ET_DYN)) 6488 /* Dynamic relocations apply to segments, so they do not 6489 need to specify the section they relocate. */ 6490 break; 6491 if (section->sh_info == 0 6492 || section->sh_info >= filedata->file_header.e_shnum 6493 || (filedata->section_headers[section->sh_info].sh_type != SHT_PROGBITS 6494 && filedata->section_headers[section->sh_info].sh_type != SHT_NOBITS 6495 && filedata->section_headers[section->sh_info].sh_type != SHT_NOTE 6496 && filedata->section_headers[section->sh_info].sh_type != SHT_INIT_ARRAY 6497 && filedata->section_headers[section->sh_info].sh_type != SHT_FINI_ARRAY 6498 && filedata->section_headers[section->sh_info].sh_type != SHT_PREINIT_ARRAY 6499 /* FIXME: Are other section types valid ? */ 6500 && filedata->section_headers[section->sh_info].sh_type < SHT_LOOS)) 6501 warn (_("[%2u]: Info field (%u) should index a relocatable section.\n"), 6502 i, section->sh_info); 6503 break; 6504 6505 case SHT_DYNAMIC: 6506 case SHT_HASH: 6507 case SHT_SYMTAB_SHNDX: 6508 case SHT_INIT_ARRAY: 6509 case SHT_FINI_ARRAY: 6510 case SHT_PREINIT_ARRAY: 6511 if (section->sh_info != 0) 6512 warn (_("[%2u]: Unexpected value (%u) in info field.\n"), 6513 i, section->sh_info); 6514 break; 6515 6516 case SHT_GROUP: 6517 case SHT_SYMTAB: 6518 case SHT_DYNSYM: 6519 /* A symbol index - we assume that it is valid. */ 6520 break; 6521 6522 default: 6523 /* FIXME: Add support for target specific section types. */ 6524 if (section->sh_type == SHT_NOBITS) 6525 /* NOBITS section headers with non-zero sh_info fields can be 6526 created when a binary is stripped of everything but its debug 6527 information. The stripped sections have their headers 6528 preserved but their types set to SHT_NOBITS. So do not check 6529 this type of section. */ 6530 ; 6531 else if (section->sh_flags & SHF_INFO_LINK) 6532 { 6533 if (section->sh_info < 1 || section->sh_info >= filedata->file_header.e_shnum) 6534 warn (_("[%2u]: Expected link to another section in info field"), i); 6535 } 6536 else if (section->sh_type < SHT_LOOS 6537 && (section->sh_flags & SHF_GNU_MBIND) == 0 6538 && section->sh_info != 0) 6539 warn (_("[%2u]: Unexpected value (%u) in info field.\n"), 6540 i, section->sh_info); 6541 break; 6542 } 6543 6544 /* Check the sh_size field. */ 6545 if (section->sh_size > filedata->file_size 6546 && section->sh_type != SHT_NOBITS 6547 && section->sh_type != SHT_NULL 6548 && section->sh_type < SHT_LOOS) 6549 warn (_("Size of section %u is larger than the entire file!\n"), i); 6550 6551 printf (" [%2u] ", i); 6552 if (do_section_details) 6553 printf ("%s\n ", printable_section_name (filedata, section)); 6554 else 6555 print_symbol (-17, SECTION_NAME (section)); 6556 6557 printf (do_wide ? " %-15s " : " %-15.15s ", 6558 get_section_type_name (filedata, section->sh_type)); 6559 6560 if (is_32bit_elf) 6561 { 6562 const char * link_too_big = NULL; 6563 6564 print_vma (section->sh_addr, LONG_HEX); 6565 6566 printf ( " %6.6lx %6.6lx %2.2lx", 6567 (unsigned long) section->sh_offset, 6568 (unsigned long) section->sh_size, 6569 (unsigned long) section->sh_entsize); 6570 6571 if (do_section_details) 6572 fputs (" ", stdout); 6573 else 6574 printf (" %3s ", get_elf_section_flags (filedata, section->sh_flags)); 6575 6576 if (section->sh_link >= filedata->file_header.e_shnum) 6577 { 6578 link_too_big = ""; 6579 /* The sh_link value is out of range. Normally this indicates 6580 an error but it can have special values in Solaris binaries. */ 6581 switch (filedata->file_header.e_machine) 6582 { 6583 case EM_386: 6584 case EM_IAMCU: 6585 case EM_X86_64: 6586 case EM_L1OM: 6587 case EM_K1OM: 6588 case EM_OLD_SPARCV9: 6589 case EM_SPARC32PLUS: 6590 case EM_SPARCV9: 6591 case EM_SPARC: 6592 if (section->sh_link == (SHN_BEFORE & 0xffff)) 6593 link_too_big = "BEFORE"; 6594 else if (section->sh_link == (SHN_AFTER & 0xffff)) 6595 link_too_big = "AFTER"; 6596 break; 6597 default: 6598 break; 6599 } 6600 } 6601 6602 if (do_section_details) 6603 { 6604 if (link_too_big != NULL && * link_too_big) 6605 printf ("<%s> ", link_too_big); 6606 else 6607 printf ("%2u ", section->sh_link); 6608 printf ("%3u %2lu\n", section->sh_info, 6609 (unsigned long) section->sh_addralign); 6610 } 6611 else 6612 printf ("%2u %3u %2lu\n", 6613 section->sh_link, 6614 section->sh_info, 6615 (unsigned long) section->sh_addralign); 6616 6617 if (link_too_big && ! * link_too_big) 6618 warn (_("section %u: sh_link value of %u is larger than the number of sections\n"), 6619 i, section->sh_link); 6620 } 6621 else if (do_wide) 6622 { 6623 print_vma (section->sh_addr, LONG_HEX); 6624 6625 if ((long) section->sh_offset == section->sh_offset) 6626 printf (" %6.6lx", (unsigned long) section->sh_offset); 6627 else 6628 { 6629 putchar (' '); 6630 print_vma (section->sh_offset, LONG_HEX); 6631 } 6632 6633 if ((unsigned long) section->sh_size == section->sh_size) 6634 printf (" %6.6lx", (unsigned long) section->sh_size); 6635 else 6636 { 6637 putchar (' '); 6638 print_vma (section->sh_size, LONG_HEX); 6639 } 6640 6641 if ((unsigned long) section->sh_entsize == section->sh_entsize) 6642 printf (" %2.2lx", (unsigned long) section->sh_entsize); 6643 else 6644 { 6645 putchar (' '); 6646 print_vma (section->sh_entsize, LONG_HEX); 6647 } 6648 6649 if (do_section_details) 6650 fputs (" ", stdout); 6651 else 6652 printf (" %3s ", get_elf_section_flags (filedata, section->sh_flags)); 6653 6654 printf ("%2u %3u ", section->sh_link, section->sh_info); 6655 6656 if ((unsigned long) section->sh_addralign == section->sh_addralign) 6657 printf ("%2lu\n", (unsigned long) section->sh_addralign); 6658 else 6659 { 6660 print_vma (section->sh_addralign, DEC); 6661 putchar ('\n'); 6662 } 6663 } 6664 else if (do_section_details) 6665 { 6666 putchar (' '); 6667 print_vma (section->sh_addr, LONG_HEX); 6668 if ((long) section->sh_offset == section->sh_offset) 6669 printf (" %16.16lx", (unsigned long) section->sh_offset); 6670 else 6671 { 6672 printf (" "); 6673 print_vma (section->sh_offset, LONG_HEX); 6674 } 6675 printf (" %u\n ", section->sh_link); 6676 print_vma (section->sh_size, LONG_HEX); 6677 putchar (' '); 6678 print_vma (section->sh_entsize, LONG_HEX); 6679 6680 printf (" %-16u %lu\n", 6681 section->sh_info, 6682 (unsigned long) section->sh_addralign); 6683 } 6684 else 6685 { 6686 putchar (' '); 6687 print_vma (section->sh_addr, LONG_HEX); 6688 if ((long) section->sh_offset == section->sh_offset) 6689 printf (" %8.8lx", (unsigned long) section->sh_offset); 6690 else 6691 { 6692 printf (" "); 6693 print_vma (section->sh_offset, LONG_HEX); 6694 } 6695 printf ("\n "); 6696 print_vma (section->sh_size, LONG_HEX); 6697 printf (" "); 6698 print_vma (section->sh_entsize, LONG_HEX); 6699 6700 printf (" %3s ", get_elf_section_flags (filedata, section->sh_flags)); 6701 6702 printf (" %2u %3u %lu\n", 6703 section->sh_link, 6704 section->sh_info, 6705 (unsigned long) section->sh_addralign); 6706 } 6707 6708 if (do_section_details) 6709 { 6710 printf (" %s\n", get_elf_section_flags (filedata, section->sh_flags)); 6711 if ((section->sh_flags & SHF_COMPRESSED) != 0) 6712 { 6713 /* Minimum section size is 12 bytes for 32-bit compression 6714 header + 12 bytes for compressed data header. */ 6715 unsigned char buf[24]; 6716 6717 assert (sizeof (buf) >= sizeof (Elf64_External_Chdr)); 6718 if (get_data (&buf, filedata, section->sh_offset, 1, 6719 sizeof (buf), _("compression header"))) 6720 { 6721 Elf_Internal_Chdr chdr; 6722 6723 (void) get_compression_header (&chdr, buf, sizeof (buf)); 6724 6725 if (chdr.ch_type == ELFCOMPRESS_ZLIB) 6726 printf (" ZLIB, "); 6727 else 6728 printf (_(" [<unknown>: 0x%x], "), 6729 chdr.ch_type); 6730 print_vma (chdr.ch_size, LONG_HEX); 6731 printf (", %lu\n", (unsigned long) chdr.ch_addralign); 6732 } 6733 } 6734 } 6735 } 6736 6737 if (!do_section_details) 6738 { 6739 /* The ordering of the letters shown here matches the ordering of the 6740 corresponding SHF_xxx values, and hence the order in which these 6741 letters will be displayed to the user. */ 6742 printf (_("Key to Flags:\n\ 6743 W (write), A (alloc), X (execute), M (merge), S (strings), I (info),\n\ 6744 L (link order), O (extra OS processing required), G (group), T (TLS),\n\ 6745 C (compressed), x (unknown), o (OS specific), E (exclude),\n ")); 6746 if (filedata->file_header.e_machine == EM_X86_64 6747 || filedata->file_header.e_machine == EM_L1OM 6748 || filedata->file_header.e_machine == EM_K1OM) 6749 printf (_("l (large), ")); 6750 else if (filedata->file_header.e_machine == EM_ARM) 6751 printf (_("y (purecode), ")); 6752 else if (filedata->file_header.e_machine == EM_PPC) 6753 printf (_("v (VLE), ")); 6754 printf ("p (processor specific)\n"); 6755 } 6756 6757 return TRUE; 6758 } 6759 6760 static const char * 6761 get_group_flags (unsigned int flags) 6762 { 6763 static char buff[128]; 6764 6765 if (flags == 0) 6766 return ""; 6767 else if (flags == GRP_COMDAT) 6768 return "COMDAT "; 6769 6770 snprintf (buff, 14, _("[0x%x: "), flags); 6771 6772 flags &= ~ GRP_COMDAT; 6773 if (flags & GRP_MASKOS) 6774 { 6775 strcat (buff, "<OS specific>"); 6776 flags &= ~ GRP_MASKOS; 6777 } 6778 6779 if (flags & GRP_MASKPROC) 6780 { 6781 strcat (buff, "<PROC specific>"); 6782 flags &= ~ GRP_MASKPROC; 6783 } 6784 6785 if (flags) 6786 strcat (buff, "<unknown>"); 6787 6788 strcat (buff, "]"); 6789 return buff; 6790 } 6791 6792 static bfd_boolean 6793 process_section_groups (Filedata * filedata) 6794 { 6795 Elf_Internal_Shdr * section; 6796 unsigned int i; 6797 struct group * group; 6798 Elf_Internal_Shdr * symtab_sec; 6799 Elf_Internal_Shdr * strtab_sec; 6800 Elf_Internal_Sym * symtab; 6801 unsigned long num_syms; 6802 char * strtab; 6803 size_t strtab_size; 6804 6805 /* Don't process section groups unless needed. */ 6806 if (!do_unwind && !do_section_groups) 6807 return TRUE; 6808 6809 if (filedata->file_header.e_shnum == 0) 6810 { 6811 if (do_section_groups) 6812 printf (_("\nThere are no sections to group in this file.\n")); 6813 6814 return TRUE; 6815 } 6816 6817 if (filedata->section_headers == NULL) 6818 { 6819 error (_("Section headers are not available!\n")); 6820 /* PR 13622: This can happen with a corrupt ELF header. */ 6821 return FALSE; 6822 } 6823 6824 section_headers_groups = (struct group **) calloc (filedata->file_header.e_shnum, 6825 sizeof (struct group *)); 6826 6827 if (section_headers_groups == NULL) 6828 { 6829 error (_("Out of memory reading %u section group headers\n"), 6830 filedata->file_header.e_shnum); 6831 return FALSE; 6832 } 6833 6834 /* Scan the sections for the group section. */ 6835 group_count = 0; 6836 for (i = 0, section = filedata->section_headers; 6837 i < filedata->file_header.e_shnum; 6838 i++, section++) 6839 if (section->sh_type == SHT_GROUP) 6840 group_count++; 6841 6842 if (group_count == 0) 6843 { 6844 if (do_section_groups) 6845 printf (_("\nThere are no section groups in this file.\n")); 6846 6847 return TRUE; 6848 } 6849 6850 section_groups = (struct group *) calloc (group_count, sizeof (struct group)); 6851 6852 if (section_groups == NULL) 6853 { 6854 error (_("Out of memory reading %lu groups\n"), 6855 (unsigned long) group_count); 6856 return FALSE; 6857 } 6858 6859 symtab_sec = NULL; 6860 strtab_sec = NULL; 6861 symtab = NULL; 6862 num_syms = 0; 6863 strtab = NULL; 6864 strtab_size = 0; 6865 for (i = 0, section = filedata->section_headers, group = section_groups; 6866 i < filedata->file_header.e_shnum; 6867 i++, section++) 6868 { 6869 if (section->sh_type == SHT_GROUP) 6870 { 6871 const char * name = printable_section_name (filedata, section); 6872 const char * group_name; 6873 unsigned char * start; 6874 unsigned char * indices; 6875 unsigned int entry, j, size; 6876 Elf_Internal_Shdr * sec; 6877 Elf_Internal_Sym * sym; 6878 6879 /* Get the symbol table. */ 6880 if (section->sh_link >= filedata->file_header.e_shnum 6881 || ((sec = filedata->section_headers + section->sh_link)->sh_type 6882 != SHT_SYMTAB)) 6883 { 6884 error (_("Bad sh_link in group section `%s'\n"), name); 6885 continue; 6886 } 6887 6888 if (symtab_sec != sec) 6889 { 6890 symtab_sec = sec; 6891 if (symtab) 6892 free (symtab); 6893 symtab = GET_ELF_SYMBOLS (filedata, symtab_sec, & num_syms); 6894 } 6895 6896 if (symtab == NULL) 6897 { 6898 error (_("Corrupt header in group section `%s'\n"), name); 6899 continue; 6900 } 6901 6902 if (section->sh_info >= num_syms) 6903 { 6904 error (_("Bad sh_info in group section `%s'\n"), name); 6905 continue; 6906 } 6907 6908 sym = symtab + section->sh_info; 6909 6910 if (ELF_ST_TYPE (sym->st_info) == STT_SECTION) 6911 { 6912 if (sym->st_shndx == 0 6913 || sym->st_shndx >= filedata->file_header.e_shnum) 6914 { 6915 error (_("Bad sh_info in group section `%s'\n"), name); 6916 continue; 6917 } 6918 6919 group_name = SECTION_NAME (filedata->section_headers + sym->st_shndx); 6920 strtab_sec = NULL; 6921 if (strtab) 6922 free (strtab); 6923 strtab = NULL; 6924 strtab_size = 0; 6925 } 6926 else 6927 { 6928 /* Get the string table. */ 6929 if (symtab_sec->sh_link >= filedata->file_header.e_shnum) 6930 { 6931 strtab_sec = NULL; 6932 if (strtab) 6933 free (strtab); 6934 strtab = NULL; 6935 strtab_size = 0; 6936 } 6937 else if (strtab_sec 6938 != (sec = filedata->section_headers + symtab_sec->sh_link)) 6939 { 6940 strtab_sec = sec; 6941 if (strtab) 6942 free (strtab); 6943 6944 strtab = (char *) get_data (NULL, filedata, strtab_sec->sh_offset, 6945 1, strtab_sec->sh_size, 6946 _("string table")); 6947 strtab_size = strtab != NULL ? strtab_sec->sh_size : 0; 6948 } 6949 group_name = sym->st_name < strtab_size 6950 ? strtab + sym->st_name : _("<corrupt>"); 6951 } 6952 6953 /* PR 17531: file: loop. */ 6954 if (section->sh_entsize > section->sh_size) 6955 { 6956 error (_("Section %s has sh_entsize (0x%lx) which is larger than its size (0x%lx)\n"), 6957 printable_section_name (filedata, section), 6958 (unsigned long) section->sh_entsize, 6959 (unsigned long) section->sh_size); 6960 continue; 6961 } 6962 6963 start = (unsigned char *) get_data (NULL, filedata, section->sh_offset, 6964 1, section->sh_size, 6965 _("section data")); 6966 if (start == NULL) 6967 continue; 6968 6969 indices = start; 6970 size = (section->sh_size / section->sh_entsize) - 1; 6971 entry = byte_get (indices, 4); 6972 indices += 4; 6973 6974 if (do_section_groups) 6975 { 6976 printf (_("\n%sgroup section [%5u] `%s' [%s] contains %u sections:\n"), 6977 get_group_flags (entry), i, name, group_name, size); 6978 6979 printf (_(" [Index] Name\n")); 6980 } 6981 6982 group->group_index = i; 6983 6984 for (j = 0; j < size; j++) 6985 { 6986 struct group_list * g; 6987 6988 entry = byte_get (indices, 4); 6989 indices += 4; 6990 6991 if (entry >= filedata->file_header.e_shnum) 6992 { 6993 static unsigned num_group_errors = 0; 6994 6995 if (num_group_errors ++ < 10) 6996 { 6997 error (_("section [%5u] in group section [%5u] > maximum section [%5u]\n"), 6998 entry, i, filedata->file_header.e_shnum - 1); 6999 if (num_group_errors == 10) 7000 warn (_("Further error messages about overlarge group section indices suppressed\n")); 7001 } 7002 continue; 7003 } 7004 7005 if (section_headers_groups [entry] != NULL) 7006 { 7007 if (entry) 7008 { 7009 static unsigned num_errs = 0; 7010 7011 if (num_errs ++ < 10) 7012 { 7013 error (_("section [%5u] in group section [%5u] already in group section [%5u]\n"), 7014 entry, i, 7015 section_headers_groups [entry]->group_index); 7016 if (num_errs == 10) 7017 warn (_("Further error messages about already contained group sections suppressed\n")); 7018 } 7019 continue; 7020 } 7021 else 7022 { 7023 /* Intel C/C++ compiler may put section 0 in a 7024 section group. We just warn it the first time 7025 and ignore it afterwards. */ 7026 static bfd_boolean warned = FALSE; 7027 if (!warned) 7028 { 7029 error (_("section 0 in group section [%5u]\n"), 7030 section_headers_groups [entry]->group_index); 7031 warned = TRUE; 7032 } 7033 } 7034 } 7035 7036 section_headers_groups [entry] = group; 7037 7038 if (do_section_groups) 7039 { 7040 sec = filedata->section_headers + entry; 7041 printf (" [%5u] %s\n", entry, printable_section_name (filedata, sec)); 7042 } 7043 7044 g = (struct group_list *) xmalloc (sizeof (struct group_list)); 7045 g->section_index = entry; 7046 g->next = group->root; 7047 group->root = g; 7048 } 7049 7050 if (start) 7051 free (start); 7052 7053 group++; 7054 } 7055 } 7056 7057 if (symtab) 7058 free (symtab); 7059 if (strtab) 7060 free (strtab); 7061 return TRUE; 7062 } 7063 7064 /* Data used to display dynamic fixups. */ 7065 7066 struct ia64_vms_dynfixup 7067 { 7068 bfd_vma needed_ident; /* Library ident number. */ 7069 bfd_vma needed; /* Index in the dstrtab of the library name. */ 7070 bfd_vma fixup_needed; /* Index of the library. */ 7071 bfd_vma fixup_rela_cnt; /* Number of fixups. */ 7072 bfd_vma fixup_rela_off; /* Fixups offset in the dynamic segment. */ 7073 }; 7074 7075 /* Data used to display dynamic relocations. */ 7076 7077 struct ia64_vms_dynimgrela 7078 { 7079 bfd_vma img_rela_cnt; /* Number of relocations. */ 7080 bfd_vma img_rela_off; /* Reloc offset in the dynamic segment. */ 7081 }; 7082 7083 /* Display IA-64 OpenVMS dynamic fixups (used to dynamically link a shared 7084 library). */ 7085 7086 static bfd_boolean 7087 dump_ia64_vms_dynamic_fixups (Filedata * filedata, 7088 struct ia64_vms_dynfixup * fixup, 7089 const char * strtab, 7090 unsigned int strtab_sz) 7091 { 7092 Elf64_External_VMS_IMAGE_FIXUP * imfs; 7093 long i; 7094 const char * lib_name; 7095 7096 imfs = get_data (NULL, filedata, dynamic_addr + fixup->fixup_rela_off, 7097 1, fixup->fixup_rela_cnt * sizeof (*imfs), 7098 _("dynamic section image fixups")); 7099 if (!imfs) 7100 return FALSE; 7101 7102 if (fixup->needed < strtab_sz) 7103 lib_name = strtab + fixup->needed; 7104 else 7105 { 7106 warn (_("corrupt library name index of 0x%lx found in dynamic entry"), 7107 (unsigned long) fixup->needed); 7108 lib_name = "???"; 7109 } 7110 printf (_("\nImage fixups for needed library #%d: %s - ident: %lx\n"), 7111 (int) fixup->fixup_needed, lib_name, (long) fixup->needed_ident); 7112 printf 7113 (_("Seg Offset Type SymVec DataType\n")); 7114 7115 for (i = 0; i < (long) fixup->fixup_rela_cnt; i++) 7116 { 7117 unsigned int type; 7118 const char *rtype; 7119 7120 printf ("%3u ", (unsigned) BYTE_GET (imfs [i].fixup_seg)); 7121 printf_vma ((bfd_vma) BYTE_GET (imfs [i].fixup_offset)); 7122 type = BYTE_GET (imfs [i].type); 7123 rtype = elf_ia64_reloc_type (type); 7124 if (rtype == NULL) 7125 printf (" 0x%08x ", type); 7126 else 7127 printf (" %-32s ", rtype); 7128 printf ("%6u ", (unsigned) BYTE_GET (imfs [i].symvec_index)); 7129 printf ("0x%08x\n", (unsigned) BYTE_GET (imfs [i].data_type)); 7130 } 7131 7132 free (imfs); 7133 return TRUE; 7134 } 7135 7136 /* Display IA-64 OpenVMS dynamic relocations (used to relocate an image). */ 7137 7138 static bfd_boolean 7139 dump_ia64_vms_dynamic_relocs (Filedata * filedata, struct ia64_vms_dynimgrela *imgrela) 7140 { 7141 Elf64_External_VMS_IMAGE_RELA *imrs; 7142 long i; 7143 7144 imrs = get_data (NULL, filedata, dynamic_addr + imgrela->img_rela_off, 7145 1, imgrela->img_rela_cnt * sizeof (*imrs), 7146 _("dynamic section image relocations")); 7147 if (!imrs) 7148 return FALSE; 7149 7150 printf (_("\nImage relocs\n")); 7151 printf 7152 (_("Seg Offset Type Addend Seg Sym Off\n")); 7153 7154 for (i = 0; i < (long) imgrela->img_rela_cnt; i++) 7155 { 7156 unsigned int type; 7157 const char *rtype; 7158 7159 printf ("%3u ", (unsigned) BYTE_GET (imrs [i].rela_seg)); 7160 printf ("%08" BFD_VMA_FMT "x ", 7161 (bfd_vma) BYTE_GET (imrs [i].rela_offset)); 7162 type = BYTE_GET (imrs [i].type); 7163 rtype = elf_ia64_reloc_type (type); 7164 if (rtype == NULL) 7165 printf ("0x%08x ", type); 7166 else 7167 printf ("%-31s ", rtype); 7168 print_vma (BYTE_GET (imrs [i].addend), FULL_HEX); 7169 printf ("%3u ", (unsigned) BYTE_GET (imrs [i].sym_seg)); 7170 printf ("%08" BFD_VMA_FMT "x\n", 7171 (bfd_vma) BYTE_GET (imrs [i].sym_offset)); 7172 } 7173 7174 free (imrs); 7175 return TRUE; 7176 } 7177 7178 /* Display IA-64 OpenVMS dynamic relocations and fixups. */ 7179 7180 static bfd_boolean 7181 process_ia64_vms_dynamic_relocs (Filedata * filedata) 7182 { 7183 struct ia64_vms_dynfixup fixup; 7184 struct ia64_vms_dynimgrela imgrela; 7185 Elf_Internal_Dyn *entry; 7186 bfd_vma strtab_off = 0; 7187 bfd_vma strtab_sz = 0; 7188 char *strtab = NULL; 7189 bfd_boolean res = TRUE; 7190 7191 memset (&fixup, 0, sizeof (fixup)); 7192 memset (&imgrela, 0, sizeof (imgrela)); 7193 7194 /* Note: the order of the entries is specified by the OpenVMS specs. */ 7195 for (entry = dynamic_section; 7196 entry < dynamic_section + dynamic_nent; 7197 entry++) 7198 { 7199 switch (entry->d_tag) 7200 { 7201 case DT_IA_64_VMS_STRTAB_OFFSET: 7202 strtab_off = entry->d_un.d_val; 7203 break; 7204 case DT_STRSZ: 7205 strtab_sz = entry->d_un.d_val; 7206 if (strtab == NULL) 7207 strtab = get_data (NULL, filedata, dynamic_addr + strtab_off, 7208 1, strtab_sz, _("dynamic string section")); 7209 break; 7210 7211 case DT_IA_64_VMS_NEEDED_IDENT: 7212 fixup.needed_ident = entry->d_un.d_val; 7213 break; 7214 case DT_NEEDED: 7215 fixup.needed = entry->d_un.d_val; 7216 break; 7217 case DT_IA_64_VMS_FIXUP_NEEDED: 7218 fixup.fixup_needed = entry->d_un.d_val; 7219 break; 7220 case DT_IA_64_VMS_FIXUP_RELA_CNT: 7221 fixup.fixup_rela_cnt = entry->d_un.d_val; 7222 break; 7223 case DT_IA_64_VMS_FIXUP_RELA_OFF: 7224 fixup.fixup_rela_off = entry->d_un.d_val; 7225 if (! dump_ia64_vms_dynamic_fixups (filedata, &fixup, strtab, strtab_sz)) 7226 res = FALSE; 7227 break; 7228 case DT_IA_64_VMS_IMG_RELA_CNT: 7229 imgrela.img_rela_cnt = entry->d_un.d_val; 7230 break; 7231 case DT_IA_64_VMS_IMG_RELA_OFF: 7232 imgrela.img_rela_off = entry->d_un.d_val; 7233 if (! dump_ia64_vms_dynamic_relocs (filedata, &imgrela)) 7234 res = FALSE; 7235 break; 7236 7237 default: 7238 break; 7239 } 7240 } 7241 7242 if (strtab != NULL) 7243 free (strtab); 7244 7245 return res; 7246 } 7247 7248 static struct 7249 { 7250 const char * name; 7251 int reloc; 7252 int size; 7253 int rela; 7254 } 7255 dynamic_relocations [] = 7256 { 7257 { "REL", DT_REL, DT_RELSZ, FALSE }, 7258 { "RELA", DT_RELA, DT_RELASZ, TRUE }, 7259 { "PLT", DT_JMPREL, DT_PLTRELSZ, UNKNOWN } 7260 }; 7261 7262 /* Process the reloc section. */ 7263 7264 static bfd_boolean 7265 process_relocs (Filedata * filedata) 7266 { 7267 unsigned long rel_size; 7268 unsigned long rel_offset; 7269 7270 if (!do_reloc) 7271 return TRUE; 7272 7273 if (do_using_dynamic) 7274 { 7275 int is_rela; 7276 const char * name; 7277 bfd_boolean has_dynamic_reloc; 7278 unsigned int i; 7279 7280 has_dynamic_reloc = FALSE; 7281 7282 for (i = 0; i < ARRAY_SIZE (dynamic_relocations); i++) 7283 { 7284 is_rela = dynamic_relocations [i].rela; 7285 name = dynamic_relocations [i].name; 7286 rel_size = dynamic_info [dynamic_relocations [i].size]; 7287 rel_offset = dynamic_info [dynamic_relocations [i].reloc]; 7288 7289 if (rel_size) 7290 has_dynamic_reloc = TRUE; 7291 7292 if (is_rela == UNKNOWN) 7293 { 7294 if (dynamic_relocations [i].reloc == DT_JMPREL) 7295 switch (dynamic_info[DT_PLTREL]) 7296 { 7297 case DT_REL: 7298 is_rela = FALSE; 7299 break; 7300 case DT_RELA: 7301 is_rela = TRUE; 7302 break; 7303 } 7304 } 7305 7306 if (rel_size) 7307 { 7308 printf 7309 (_("\n'%s' relocation section at offset 0x%lx contains %ld bytes:\n"), 7310 name, rel_offset, rel_size); 7311 7312 dump_relocations (filedata, 7313 offset_from_vma (filedata, rel_offset, rel_size), 7314 rel_size, 7315 dynamic_symbols, num_dynamic_syms, 7316 dynamic_strings, dynamic_strings_length, 7317 is_rela, TRUE /* is_dynamic */); 7318 } 7319 } 7320 7321 if (is_ia64_vms (filedata)) 7322 if (process_ia64_vms_dynamic_relocs (filedata)) 7323 has_dynamic_reloc = TRUE; 7324 7325 if (! has_dynamic_reloc) 7326 printf (_("\nThere are no dynamic relocations in this file.\n")); 7327 } 7328 else 7329 { 7330 Elf_Internal_Shdr * section; 7331 unsigned long i; 7332 bfd_boolean found = FALSE; 7333 7334 for (i = 0, section = filedata->section_headers; 7335 i < filedata->file_header.e_shnum; 7336 i++, section++) 7337 { 7338 if ( section->sh_type != SHT_RELA 7339 && section->sh_type != SHT_REL) 7340 continue; 7341 7342 rel_offset = section->sh_offset; 7343 rel_size = section->sh_size; 7344 7345 if (rel_size) 7346 { 7347 Elf_Internal_Shdr * strsec; 7348 int is_rela; 7349 unsigned long num_rela; 7350 7351 printf (_("\nRelocation section ")); 7352 7353 if (filedata->string_table == NULL) 7354 printf ("%d", section->sh_name); 7355 else 7356 printf ("'%s'", printable_section_name (filedata, section)); 7357 7358 num_rela = rel_size / section->sh_entsize; 7359 printf (ngettext (" at offset 0x%lx contains %lu entry:\n", 7360 " at offset 0x%lx contains %lu entries:\n", 7361 num_rela), 7362 rel_offset, num_rela); 7363 7364 is_rela = section->sh_type == SHT_RELA; 7365 7366 if (section->sh_link != 0 7367 && section->sh_link < filedata->file_header.e_shnum) 7368 { 7369 Elf_Internal_Shdr * symsec; 7370 Elf_Internal_Sym * symtab; 7371 unsigned long nsyms; 7372 unsigned long strtablen = 0; 7373 char * strtab = NULL; 7374 7375 symsec = filedata->section_headers + section->sh_link; 7376 if (symsec->sh_type != SHT_SYMTAB 7377 && symsec->sh_type != SHT_DYNSYM) 7378 continue; 7379 7380 symtab = GET_ELF_SYMBOLS (filedata, symsec, & nsyms); 7381 7382 if (symtab == NULL) 7383 continue; 7384 7385 if (symsec->sh_link != 0 7386 && symsec->sh_link < filedata->file_header.e_shnum) 7387 { 7388 strsec = filedata->section_headers + symsec->sh_link; 7389 7390 strtab = (char *) get_data (NULL, filedata, strsec->sh_offset, 7391 1, strsec->sh_size, 7392 _("string table")); 7393 strtablen = strtab == NULL ? 0 : strsec->sh_size; 7394 } 7395 7396 dump_relocations (filedata, rel_offset, rel_size, 7397 symtab, nsyms, strtab, strtablen, 7398 is_rela, 7399 symsec->sh_type == SHT_DYNSYM); 7400 if (strtab) 7401 free (strtab); 7402 free (symtab); 7403 } 7404 else 7405 dump_relocations (filedata, rel_offset, rel_size, 7406 NULL, 0, NULL, 0, is_rela, 7407 FALSE /* is_dynamic */); 7408 7409 found = TRUE; 7410 } 7411 } 7412 7413 if (! found) 7414 { 7415 /* Users sometimes forget the -D option, so try to be helpful. */ 7416 for (i = 0; i < ARRAY_SIZE (dynamic_relocations); i++) 7417 { 7418 if (dynamic_info [dynamic_relocations [i].size]) 7419 { 7420 printf (_("\nThere are no static relocations in this file.")); 7421 printf (_("\nTo see the dynamic relocations add --use-dynamic to the command line.\n")); 7422 7423 break; 7424 } 7425 } 7426 if (i == ARRAY_SIZE (dynamic_relocations)) 7427 printf (_("\nThere are no relocations in this file.\n")); 7428 } 7429 } 7430 7431 return TRUE; 7432 } 7433 7434 /* An absolute address consists of a section and an offset. If the 7435 section is NULL, the offset itself is the address, otherwise, the 7436 address equals to LOAD_ADDRESS(section) + offset. */ 7437 7438 struct absaddr 7439 { 7440 unsigned short section; 7441 bfd_vma offset; 7442 }; 7443 7444 /* Find the nearest symbol at or below ADDR. Returns the symbol 7445 name, if found, and the offset from the symbol to ADDR. */ 7446 7447 static void 7448 find_symbol_for_address (Filedata * filedata, 7449 Elf_Internal_Sym * symtab, 7450 unsigned long nsyms, 7451 const char * strtab, 7452 unsigned long strtab_size, 7453 struct absaddr addr, 7454 const char ** symname, 7455 bfd_vma * offset) 7456 { 7457 bfd_vma dist = 0x100000; 7458 Elf_Internal_Sym * sym; 7459 Elf_Internal_Sym * beg; 7460 Elf_Internal_Sym * end; 7461 Elf_Internal_Sym * best = NULL; 7462 7463 REMOVE_ARCH_BITS (addr.offset); 7464 beg = symtab; 7465 end = symtab + nsyms; 7466 7467 while (beg < end) 7468 { 7469 bfd_vma value; 7470 7471 sym = beg + (end - beg) / 2; 7472 7473 value = sym->st_value; 7474 REMOVE_ARCH_BITS (value); 7475 7476 if (sym->st_name != 0 7477 && (addr.section == SHN_UNDEF || addr.section == sym->st_shndx) 7478 && addr.offset >= value 7479 && addr.offset - value < dist) 7480 { 7481 best = sym; 7482 dist = addr.offset - value; 7483 if (!dist) 7484 break; 7485 } 7486 7487 if (addr.offset < value) 7488 end = sym; 7489 else 7490 beg = sym + 1; 7491 } 7492 7493 if (best) 7494 { 7495 *symname = (best->st_name >= strtab_size 7496 ? _("<corrupt>") : strtab + best->st_name); 7497 *offset = dist; 7498 return; 7499 } 7500 7501 *symname = NULL; 7502 *offset = addr.offset; 7503 } 7504 7505 static /* signed */ int 7506 symcmp (const void *p, const void *q) 7507 { 7508 Elf_Internal_Sym *sp = (Elf_Internal_Sym *) p; 7509 Elf_Internal_Sym *sq = (Elf_Internal_Sym *) q; 7510 7511 return sp->st_value > sq->st_value ? 1 : (sp->st_value < sq->st_value ? -1 : 0); 7512 } 7513 7514 /* Process the unwind section. */ 7515 7516 #include "unwind-ia64.h" 7517 7518 struct ia64_unw_table_entry 7519 { 7520 struct absaddr start; 7521 struct absaddr end; 7522 struct absaddr info; 7523 }; 7524 7525 struct ia64_unw_aux_info 7526 { 7527 struct ia64_unw_table_entry * table; /* Unwind table. */ 7528 unsigned long table_len; /* Length of unwind table. */ 7529 unsigned char * info; /* Unwind info. */ 7530 unsigned long info_size; /* Size of unwind info. */ 7531 bfd_vma info_addr; /* Starting address of unwind info. */ 7532 bfd_vma seg_base; /* Starting address of segment. */ 7533 Elf_Internal_Sym * symtab; /* The symbol table. */ 7534 unsigned long nsyms; /* Number of symbols. */ 7535 Elf_Internal_Sym * funtab; /* Sorted table of STT_FUNC symbols. */ 7536 unsigned long nfuns; /* Number of entries in funtab. */ 7537 char * strtab; /* The string table. */ 7538 unsigned long strtab_size; /* Size of string table. */ 7539 }; 7540 7541 static bfd_boolean 7542 dump_ia64_unwind (Filedata * filedata, struct ia64_unw_aux_info * aux) 7543 { 7544 struct ia64_unw_table_entry * tp; 7545 unsigned long j, nfuns; 7546 int in_body; 7547 bfd_boolean res = TRUE; 7548 7549 aux->funtab = xmalloc (aux->nsyms * sizeof (Elf_Internal_Sym)); 7550 for (nfuns = 0, j = 0; j < aux->nsyms; j++) 7551 if (aux->symtab[j].st_value && ELF_ST_TYPE (aux->symtab[j].st_info) == STT_FUNC) 7552 aux->funtab[nfuns++] = aux->symtab[j]; 7553 aux->nfuns = nfuns; 7554 qsort (aux->funtab, aux->nfuns, sizeof (Elf_Internal_Sym), symcmp); 7555 7556 for (tp = aux->table; tp < aux->table + aux->table_len; ++tp) 7557 { 7558 bfd_vma stamp; 7559 bfd_vma offset; 7560 const unsigned char * dp; 7561 const unsigned char * head; 7562 const unsigned char * end; 7563 const char * procname; 7564 7565 find_symbol_for_address (filedata, aux->funtab, aux->nfuns, aux->strtab, 7566 aux->strtab_size, tp->start, &procname, &offset); 7567 7568 fputs ("\n<", stdout); 7569 7570 if (procname) 7571 { 7572 fputs (procname, stdout); 7573 7574 if (offset) 7575 printf ("+%lx", (unsigned long) offset); 7576 } 7577 7578 fputs (">: [", stdout); 7579 print_vma (tp->start.offset, PREFIX_HEX); 7580 fputc ('-', stdout); 7581 print_vma (tp->end.offset, PREFIX_HEX); 7582 printf ("], info at +0x%lx\n", 7583 (unsigned long) (tp->info.offset - aux->seg_base)); 7584 7585 /* PR 17531: file: 86232b32. */ 7586 if (aux->info == NULL) 7587 continue; 7588 7589 offset = tp->info.offset; 7590 if (tp->info.section) 7591 { 7592 if (tp->info.section >= filedata->file_header.e_shnum) 7593 { 7594 warn (_("Invalid section %u in table entry %ld\n"), 7595 tp->info.section, (long) (tp - aux->table)); 7596 res = FALSE; 7597 continue; 7598 } 7599 offset += filedata->section_headers[tp->info.section].sh_addr; 7600 } 7601 offset -= aux->info_addr; 7602 /* PR 17531: file: 0997b4d1. */ 7603 if (offset >= aux->info_size 7604 || aux->info_size - offset < 8) 7605 { 7606 warn (_("Invalid offset %lx in table entry %ld\n"), 7607 (long) tp->info.offset, (long) (tp - aux->table)); 7608 res = FALSE; 7609 continue; 7610 } 7611 7612 head = aux->info + offset; 7613 stamp = byte_get ((unsigned char *) head, sizeof (stamp)); 7614 7615 printf (" v%u, flags=0x%lx (%s%s), len=%lu bytes\n", 7616 (unsigned) UNW_VER (stamp), 7617 (unsigned long) ((stamp & UNW_FLAG_MASK) >> 32), 7618 UNW_FLAG_EHANDLER (stamp) ? " ehandler" : "", 7619 UNW_FLAG_UHANDLER (stamp) ? " uhandler" : "", 7620 (unsigned long) (eh_addr_size * UNW_LENGTH (stamp))); 7621 7622 if (UNW_VER (stamp) != 1) 7623 { 7624 printf (_("\tUnknown version.\n")); 7625 continue; 7626 } 7627 7628 in_body = 0; 7629 end = head + 8 + eh_addr_size * UNW_LENGTH (stamp); 7630 /* PR 17531: file: 16ceda89. */ 7631 if (end > aux->info + aux->info_size) 7632 end = aux->info + aux->info_size; 7633 for (dp = head + 8; dp < end;) 7634 dp = unw_decode (dp, in_body, & in_body, end); 7635 } 7636 7637 free (aux->funtab); 7638 7639 return res; 7640 } 7641 7642 static bfd_boolean 7643 slurp_ia64_unwind_table (Filedata * filedata, 7644 struct ia64_unw_aux_info * aux, 7645 Elf_Internal_Shdr * sec) 7646 { 7647 unsigned long size, nrelas, i; 7648 Elf_Internal_Phdr * seg; 7649 struct ia64_unw_table_entry * tep; 7650 Elf_Internal_Shdr * relsec; 7651 Elf_Internal_Rela * rela; 7652 Elf_Internal_Rela * rp; 7653 unsigned char * table; 7654 unsigned char * tp; 7655 Elf_Internal_Sym * sym; 7656 const char * relname; 7657 7658 aux->table_len = 0; 7659 7660 /* First, find the starting address of the segment that includes 7661 this section: */ 7662 7663 if (filedata->file_header.e_phnum) 7664 { 7665 if (! get_program_headers (filedata)) 7666 return FALSE; 7667 7668 for (seg = filedata->program_headers; 7669 seg < filedata->program_headers + filedata->file_header.e_phnum; 7670 ++seg) 7671 { 7672 if (seg->p_type != PT_LOAD) 7673 continue; 7674 7675 if (sec->sh_addr >= seg->p_vaddr 7676 && (sec->sh_addr + sec->sh_size <= seg->p_vaddr + seg->p_memsz)) 7677 { 7678 aux->seg_base = seg->p_vaddr; 7679 break; 7680 } 7681 } 7682 } 7683 7684 /* Second, build the unwind table from the contents of the unwind section: */ 7685 size = sec->sh_size; 7686 table = (unsigned char *) get_data (NULL, filedata, sec->sh_offset, 1, size, 7687 _("unwind table")); 7688 if (!table) 7689 return FALSE; 7690 7691 aux->table_len = size / (3 * eh_addr_size); 7692 aux->table = (struct ia64_unw_table_entry *) 7693 xcmalloc (aux->table_len, sizeof (aux->table[0])); 7694 tep = aux->table; 7695 7696 for (tp = table; tp <= table + size - (3 * eh_addr_size); ++tep) 7697 { 7698 tep->start.section = SHN_UNDEF; 7699 tep->end.section = SHN_UNDEF; 7700 tep->info.section = SHN_UNDEF; 7701 tep->start.offset = byte_get (tp, eh_addr_size); tp += eh_addr_size; 7702 tep->end.offset = byte_get (tp, eh_addr_size); tp += eh_addr_size; 7703 tep->info.offset = byte_get (tp, eh_addr_size); tp += eh_addr_size; 7704 tep->start.offset += aux->seg_base; 7705 tep->end.offset += aux->seg_base; 7706 tep->info.offset += aux->seg_base; 7707 } 7708 free (table); 7709 7710 /* Third, apply any relocations to the unwind table: */ 7711 for (relsec = filedata->section_headers; 7712 relsec < filedata->section_headers + filedata->file_header.e_shnum; 7713 ++relsec) 7714 { 7715 if (relsec->sh_type != SHT_RELA 7716 || relsec->sh_info >= filedata->file_header.e_shnum 7717 || filedata->section_headers + relsec->sh_info != sec) 7718 continue; 7719 7720 if (!slurp_rela_relocs (filedata, relsec->sh_offset, relsec->sh_size, 7721 & rela, & nrelas)) 7722 { 7723 free (aux->table); 7724 aux->table = NULL; 7725 aux->table_len = 0; 7726 return FALSE; 7727 } 7728 7729 for (rp = rela; rp < rela + nrelas; ++rp) 7730 { 7731 unsigned int sym_ndx; 7732 unsigned int r_type = get_reloc_type (filedata, rp->r_info); 7733 relname = elf_ia64_reloc_type (r_type); 7734 7735 /* PR 17531: file: 9fa67536. */ 7736 if (relname == NULL) 7737 { 7738 warn (_("Skipping unknown relocation type: %u\n"), r_type); 7739 continue; 7740 } 7741 7742 if (! const_strneq (relname, "R_IA64_SEGREL")) 7743 { 7744 warn (_("Skipping unexpected relocation type: %s\n"), relname); 7745 continue; 7746 } 7747 7748 i = rp->r_offset / (3 * eh_addr_size); 7749 7750 /* PR 17531: file: 5bc8d9bf. */ 7751 if (i >= aux->table_len) 7752 { 7753 warn (_("Skipping reloc with overlarge offset: %lx\n"), i); 7754 continue; 7755 } 7756 7757 sym_ndx = get_reloc_symindex (rp->r_info); 7758 if (sym_ndx >= aux->nsyms) 7759 { 7760 warn (_("Skipping reloc with invalid symbol index: %u\n"), 7761 sym_ndx); 7762 continue; 7763 } 7764 sym = aux->symtab + sym_ndx; 7765 7766 switch (rp->r_offset / eh_addr_size % 3) 7767 { 7768 case 0: 7769 aux->table[i].start.section = sym->st_shndx; 7770 aux->table[i].start.offset = rp->r_addend + sym->st_value; 7771 break; 7772 case 1: 7773 aux->table[i].end.section = sym->st_shndx; 7774 aux->table[i].end.offset = rp->r_addend + sym->st_value; 7775 break; 7776 case 2: 7777 aux->table[i].info.section = sym->st_shndx; 7778 aux->table[i].info.offset = rp->r_addend + sym->st_value; 7779 break; 7780 default: 7781 break; 7782 } 7783 } 7784 7785 free (rela); 7786 } 7787 7788 return TRUE; 7789 } 7790 7791 static bfd_boolean 7792 ia64_process_unwind (Filedata * filedata) 7793 { 7794 Elf_Internal_Shdr * sec; 7795 Elf_Internal_Shdr * unwsec = NULL; 7796 Elf_Internal_Shdr * strsec; 7797 unsigned long i, unwcount = 0, unwstart = 0; 7798 struct ia64_unw_aux_info aux; 7799 bfd_boolean res = TRUE; 7800 7801 memset (& aux, 0, sizeof (aux)); 7802 7803 for (i = 0, sec = filedata->section_headers; i < filedata->file_header.e_shnum; ++i, ++sec) 7804 { 7805 if (sec->sh_type == SHT_SYMTAB 7806 && sec->sh_link < filedata->file_header.e_shnum) 7807 { 7808 aux.symtab = GET_ELF_SYMBOLS (filedata, sec, & aux.nsyms); 7809 7810 strsec = filedata->section_headers + sec->sh_link; 7811 if (aux.strtab != NULL) 7812 { 7813 error (_("Multiple auxillary string tables encountered\n")); 7814 free (aux.strtab); 7815 res = FALSE; 7816 } 7817 aux.strtab = (char *) get_data (NULL, filedata, strsec->sh_offset, 7818 1, strsec->sh_size, 7819 _("string table")); 7820 aux.strtab_size = aux.strtab != NULL ? strsec->sh_size : 0; 7821 } 7822 else if (sec->sh_type == SHT_IA_64_UNWIND) 7823 unwcount++; 7824 } 7825 7826 if (!unwcount) 7827 printf (_("\nThere are no unwind sections in this file.\n")); 7828 7829 while (unwcount-- > 0) 7830 { 7831 char * suffix; 7832 size_t len, len2; 7833 7834 for (i = unwstart, sec = filedata->section_headers + unwstart, unwsec = NULL; 7835 i < filedata->file_header.e_shnum; ++i, ++sec) 7836 if (sec->sh_type == SHT_IA_64_UNWIND) 7837 { 7838 unwsec = sec; 7839 break; 7840 } 7841 /* We have already counted the number of SHT_IA64_UNWIND 7842 sections so the loop above should never fail. */ 7843 assert (unwsec != NULL); 7844 7845 unwstart = i + 1; 7846 len = sizeof (ELF_STRING_ia64_unwind_once) - 1; 7847 7848 if ((unwsec->sh_flags & SHF_GROUP) != 0) 7849 { 7850 /* We need to find which section group it is in. */ 7851 struct group_list * g; 7852 7853 if (section_headers_groups == NULL 7854 || section_headers_groups [i] == NULL) 7855 i = filedata->file_header.e_shnum; 7856 else 7857 { 7858 g = section_headers_groups [i]->root; 7859 7860 for (; g != NULL; g = g->next) 7861 { 7862 sec = filedata->section_headers + g->section_index; 7863 7864 if (streq (SECTION_NAME (sec), ELF_STRING_ia64_unwind_info)) 7865 break; 7866 } 7867 7868 if (g == NULL) 7869 i = filedata->file_header.e_shnum; 7870 } 7871 } 7872 else if (strneq (SECTION_NAME (unwsec), ELF_STRING_ia64_unwind_once, len)) 7873 { 7874 /* .gnu.linkonce.ia64unw.FOO -> .gnu.linkonce.ia64unwi.FOO. */ 7875 len2 = sizeof (ELF_STRING_ia64_unwind_info_once) - 1; 7876 suffix = SECTION_NAME (unwsec) + len; 7877 for (i = 0, sec = filedata->section_headers; i < filedata->file_header.e_shnum; 7878 ++i, ++sec) 7879 if (strneq (SECTION_NAME (sec), ELF_STRING_ia64_unwind_info_once, len2) 7880 && streq (SECTION_NAME (sec) + len2, suffix)) 7881 break; 7882 } 7883 else 7884 { 7885 /* .IA_64.unwindFOO -> .IA_64.unwind_infoFOO 7886 .IA_64.unwind or BAR -> .IA_64.unwind_info. */ 7887 len = sizeof (ELF_STRING_ia64_unwind) - 1; 7888 len2 = sizeof (ELF_STRING_ia64_unwind_info) - 1; 7889 suffix = ""; 7890 if (strneq (SECTION_NAME (unwsec), ELF_STRING_ia64_unwind, len)) 7891 suffix = SECTION_NAME (unwsec) + len; 7892 for (i = 0, sec = filedata->section_headers; i < filedata->file_header.e_shnum; 7893 ++i, ++sec) 7894 if (strneq (SECTION_NAME (sec), ELF_STRING_ia64_unwind_info, len2) 7895 && streq (SECTION_NAME (sec) + len2, suffix)) 7896 break; 7897 } 7898 7899 if (i == filedata->file_header.e_shnum) 7900 { 7901 printf (_("\nCould not find unwind info section for ")); 7902 7903 if (filedata->string_table == NULL) 7904 printf ("%d", unwsec->sh_name); 7905 else 7906 printf ("'%s'", printable_section_name (filedata, unwsec)); 7907 } 7908 else 7909 { 7910 aux.info_addr = sec->sh_addr; 7911 aux.info = (unsigned char *) get_data (NULL, filedata, sec->sh_offset, 1, 7912 sec->sh_size, 7913 _("unwind info")); 7914 aux.info_size = aux.info == NULL ? 0 : sec->sh_size; 7915 7916 printf (_("\nUnwind section ")); 7917 7918 if (filedata->string_table == NULL) 7919 printf ("%d", unwsec->sh_name); 7920 else 7921 printf ("'%s'", printable_section_name (filedata, unwsec)); 7922 7923 printf (_(" at offset 0x%lx contains %lu entries:\n"), 7924 (unsigned long) unwsec->sh_offset, 7925 (unsigned long) (unwsec->sh_size / (3 * eh_addr_size))); 7926 7927 if (slurp_ia64_unwind_table (filedata, & aux, unwsec) 7928 && aux.table_len > 0) 7929 dump_ia64_unwind (filedata, & aux); 7930 7931 if (aux.table) 7932 free ((char *) aux.table); 7933 if (aux.info) 7934 free ((char *) aux.info); 7935 aux.table = NULL; 7936 aux.info = NULL; 7937 } 7938 } 7939 7940 if (aux.symtab) 7941 free (aux.symtab); 7942 if (aux.strtab) 7943 free ((char *) aux.strtab); 7944 7945 return res; 7946 } 7947 7948 struct hppa_unw_table_entry 7949 { 7950 struct absaddr start; 7951 struct absaddr end; 7952 unsigned int Cannot_unwind:1; /* 0 */ 7953 unsigned int Millicode:1; /* 1 */ 7954 unsigned int Millicode_save_sr0:1; /* 2 */ 7955 unsigned int Region_description:2; /* 3..4 */ 7956 unsigned int reserved1:1; /* 5 */ 7957 unsigned int Entry_SR:1; /* 6 */ 7958 unsigned int Entry_FR:4; /* Number saved 7..10 */ 7959 unsigned int Entry_GR:5; /* Number saved 11..15 */ 7960 unsigned int Args_stored:1; /* 16 */ 7961 unsigned int Variable_Frame:1; /* 17 */ 7962 unsigned int Separate_Package_Body:1; /* 18 */ 7963 unsigned int Frame_Extension_Millicode:1; /* 19 */ 7964 unsigned int Stack_Overflow_Check:1; /* 20 */ 7965 unsigned int Two_Instruction_SP_Increment:1; /* 21 */ 7966 unsigned int Ada_Region:1; /* 22 */ 7967 unsigned int cxx_info:1; /* 23 */ 7968 unsigned int cxx_try_catch:1; /* 24 */ 7969 unsigned int sched_entry_seq:1; /* 25 */ 7970 unsigned int reserved2:1; /* 26 */ 7971 unsigned int Save_SP:1; /* 27 */ 7972 unsigned int Save_RP:1; /* 28 */ 7973 unsigned int Save_MRP_in_frame:1; /* 29 */ 7974 unsigned int extn_ptr_defined:1; /* 30 */ 7975 unsigned int Cleanup_defined:1; /* 31 */ 7976 7977 unsigned int MPE_XL_interrupt_marker:1; /* 0 */ 7978 unsigned int HP_UX_interrupt_marker:1; /* 1 */ 7979 unsigned int Large_frame:1; /* 2 */ 7980 unsigned int Pseudo_SP_Set:1; /* 3 */ 7981 unsigned int reserved4:1; /* 4 */ 7982 unsigned int Total_frame_size:27; /* 5..31 */ 7983 }; 7984 7985 struct hppa_unw_aux_info 7986 { 7987 struct hppa_unw_table_entry * table; /* Unwind table. */ 7988 unsigned long table_len; /* Length of unwind table. */ 7989 bfd_vma seg_base; /* Starting address of segment. */ 7990 Elf_Internal_Sym * symtab; /* The symbol table. */ 7991 unsigned long nsyms; /* Number of symbols. */ 7992 Elf_Internal_Sym * funtab; /* Sorted table of STT_FUNC symbols. */ 7993 unsigned long nfuns; /* Number of entries in funtab. */ 7994 char * strtab; /* The string table. */ 7995 unsigned long strtab_size; /* Size of string table. */ 7996 }; 7997 7998 static bfd_boolean 7999 dump_hppa_unwind (Filedata * filedata, struct hppa_unw_aux_info * aux) 8000 { 8001 struct hppa_unw_table_entry * tp; 8002 unsigned long j, nfuns; 8003 bfd_boolean res = TRUE; 8004 8005 aux->funtab = xmalloc (aux->nsyms * sizeof (Elf_Internal_Sym)); 8006 for (nfuns = 0, j = 0; j < aux->nsyms; j++) 8007 if (aux->symtab[j].st_value && ELF_ST_TYPE (aux->symtab[j].st_info) == STT_FUNC) 8008 aux->funtab[nfuns++] = aux->symtab[j]; 8009 aux->nfuns = nfuns; 8010 qsort (aux->funtab, aux->nfuns, sizeof (Elf_Internal_Sym), symcmp); 8011 8012 for (tp = aux->table; tp < aux->table + aux->table_len; ++tp) 8013 { 8014 bfd_vma offset; 8015 const char * procname; 8016 8017 find_symbol_for_address (filedata, aux->funtab, aux->nfuns, aux->strtab, 8018 aux->strtab_size, tp->start, &procname, 8019 &offset); 8020 8021 fputs ("\n<", stdout); 8022 8023 if (procname) 8024 { 8025 fputs (procname, stdout); 8026 8027 if (offset) 8028 printf ("+%lx", (unsigned long) offset); 8029 } 8030 8031 fputs (">: [", stdout); 8032 print_vma (tp->start.offset, PREFIX_HEX); 8033 fputc ('-', stdout); 8034 print_vma (tp->end.offset, PREFIX_HEX); 8035 printf ("]\n\t"); 8036 8037 #define PF(_m) if (tp->_m) printf (#_m " "); 8038 #define PV(_m) if (tp->_m) printf (#_m "=%d ", tp->_m); 8039 PF(Cannot_unwind); 8040 PF(Millicode); 8041 PF(Millicode_save_sr0); 8042 /* PV(Region_description); */ 8043 PF(Entry_SR); 8044 PV(Entry_FR); 8045 PV(Entry_GR); 8046 PF(Args_stored); 8047 PF(Variable_Frame); 8048 PF(Separate_Package_Body); 8049 PF(Frame_Extension_Millicode); 8050 PF(Stack_Overflow_Check); 8051 PF(Two_Instruction_SP_Increment); 8052 PF(Ada_Region); 8053 PF(cxx_info); 8054 PF(cxx_try_catch); 8055 PF(sched_entry_seq); 8056 PF(Save_SP); 8057 PF(Save_RP); 8058 PF(Save_MRP_in_frame); 8059 PF(extn_ptr_defined); 8060 PF(Cleanup_defined); 8061 PF(MPE_XL_interrupt_marker); 8062 PF(HP_UX_interrupt_marker); 8063 PF(Large_frame); 8064 PF(Pseudo_SP_Set); 8065 PV(Total_frame_size); 8066 #undef PF 8067 #undef PV 8068 } 8069 8070 printf ("\n"); 8071 8072 free (aux->funtab); 8073 8074 return res; 8075 } 8076 8077 static bfd_boolean 8078 slurp_hppa_unwind_table (Filedata * filedata, 8079 struct hppa_unw_aux_info * aux, 8080 Elf_Internal_Shdr * sec) 8081 { 8082 unsigned long size, unw_ent_size, nentries, nrelas, i; 8083 Elf_Internal_Phdr * seg; 8084 struct hppa_unw_table_entry * tep; 8085 Elf_Internal_Shdr * relsec; 8086 Elf_Internal_Rela * rela; 8087 Elf_Internal_Rela * rp; 8088 unsigned char * table; 8089 unsigned char * tp; 8090 Elf_Internal_Sym * sym; 8091 const char * relname; 8092 8093 /* First, find the starting address of the segment that includes 8094 this section. */ 8095 if (filedata->file_header.e_phnum) 8096 { 8097 if (! get_program_headers (filedata)) 8098 return FALSE; 8099 8100 for (seg = filedata->program_headers; 8101 seg < filedata->program_headers + filedata->file_header.e_phnum; 8102 ++seg) 8103 { 8104 if (seg->p_type != PT_LOAD) 8105 continue; 8106 8107 if (sec->sh_addr >= seg->p_vaddr 8108 && (sec->sh_addr + sec->sh_size <= seg->p_vaddr + seg->p_memsz)) 8109 { 8110 aux->seg_base = seg->p_vaddr; 8111 break; 8112 } 8113 } 8114 } 8115 8116 /* Second, build the unwind table from the contents of the unwind 8117 section. */ 8118 size = sec->sh_size; 8119 table = (unsigned char *) get_data (NULL, filedata, sec->sh_offset, 1, size, 8120 _("unwind table")); 8121 if (!table) 8122 return FALSE; 8123 8124 unw_ent_size = 16; 8125 nentries = size / unw_ent_size; 8126 size = unw_ent_size * nentries; 8127 8128 tep = aux->table = (struct hppa_unw_table_entry *) 8129 xcmalloc (nentries, sizeof (aux->table[0])); 8130 8131 for (tp = table; tp < table + size; tp += unw_ent_size, ++tep) 8132 { 8133 unsigned int tmp1, tmp2; 8134 8135 tep->start.section = SHN_UNDEF; 8136 tep->end.section = SHN_UNDEF; 8137 8138 tep->start.offset = byte_get ((unsigned char *) tp + 0, 4); 8139 tep->end.offset = byte_get ((unsigned char *) tp + 4, 4); 8140 tmp1 = byte_get ((unsigned char *) tp + 8, 4); 8141 tmp2 = byte_get ((unsigned char *) tp + 12, 4); 8142 8143 tep->start.offset += aux->seg_base; 8144 tep->end.offset += aux->seg_base; 8145 8146 tep->Cannot_unwind = (tmp1 >> 31) & 0x1; 8147 tep->Millicode = (tmp1 >> 30) & 0x1; 8148 tep->Millicode_save_sr0 = (tmp1 >> 29) & 0x1; 8149 tep->Region_description = (tmp1 >> 27) & 0x3; 8150 tep->reserved1 = (tmp1 >> 26) & 0x1; 8151 tep->Entry_SR = (tmp1 >> 25) & 0x1; 8152 tep->Entry_FR = (tmp1 >> 21) & 0xf; 8153 tep->Entry_GR = (tmp1 >> 16) & 0x1f; 8154 tep->Args_stored = (tmp1 >> 15) & 0x1; 8155 tep->Variable_Frame = (tmp1 >> 14) & 0x1; 8156 tep->Separate_Package_Body = (tmp1 >> 13) & 0x1; 8157 tep->Frame_Extension_Millicode = (tmp1 >> 12) & 0x1; 8158 tep->Stack_Overflow_Check = (tmp1 >> 11) & 0x1; 8159 tep->Two_Instruction_SP_Increment = (tmp1 >> 10) & 0x1; 8160 tep->Ada_Region = (tmp1 >> 9) & 0x1; 8161 tep->cxx_info = (tmp1 >> 8) & 0x1; 8162 tep->cxx_try_catch = (tmp1 >> 7) & 0x1; 8163 tep->sched_entry_seq = (tmp1 >> 6) & 0x1; 8164 tep->reserved2 = (tmp1 >> 5) & 0x1; 8165 tep->Save_SP = (tmp1 >> 4) & 0x1; 8166 tep->Save_RP = (tmp1 >> 3) & 0x1; 8167 tep->Save_MRP_in_frame = (tmp1 >> 2) & 0x1; 8168 tep->extn_ptr_defined = (tmp1 >> 1) & 0x1; 8169 tep->Cleanup_defined = tmp1 & 0x1; 8170 8171 tep->MPE_XL_interrupt_marker = (tmp2 >> 31) & 0x1; 8172 tep->HP_UX_interrupt_marker = (tmp2 >> 30) & 0x1; 8173 tep->Large_frame = (tmp2 >> 29) & 0x1; 8174 tep->Pseudo_SP_Set = (tmp2 >> 28) & 0x1; 8175 tep->reserved4 = (tmp2 >> 27) & 0x1; 8176 tep->Total_frame_size = tmp2 & 0x7ffffff; 8177 } 8178 free (table); 8179 8180 /* Third, apply any relocations to the unwind table. */ 8181 for (relsec = filedata->section_headers; 8182 relsec < filedata->section_headers + filedata->file_header.e_shnum; 8183 ++relsec) 8184 { 8185 if (relsec->sh_type != SHT_RELA 8186 || relsec->sh_info >= filedata->file_header.e_shnum 8187 || filedata->section_headers + relsec->sh_info != sec) 8188 continue; 8189 8190 if (!slurp_rela_relocs (filedata, relsec->sh_offset, relsec->sh_size, 8191 & rela, & nrelas)) 8192 return FALSE; 8193 8194 for (rp = rela; rp < rela + nrelas; ++rp) 8195 { 8196 unsigned int sym_ndx; 8197 unsigned int r_type = get_reloc_type (filedata, rp->r_info); 8198 relname = elf_hppa_reloc_type (r_type); 8199 8200 if (relname == NULL) 8201 { 8202 warn (_("Skipping unknown relocation type: %u\n"), r_type); 8203 continue; 8204 } 8205 8206 /* R_PARISC_SEGREL32 or R_PARISC_SEGREL64. */ 8207 if (! const_strneq (relname, "R_PARISC_SEGREL")) 8208 { 8209 warn (_("Skipping unexpected relocation type: %s\n"), relname); 8210 continue; 8211 } 8212 8213 i = rp->r_offset / unw_ent_size; 8214 if (i >= aux->table_len) 8215 { 8216 warn (_("Skipping reloc with overlarge offset: %lx\n"), i); 8217 continue; 8218 } 8219 8220 sym_ndx = get_reloc_symindex (rp->r_info); 8221 if (sym_ndx >= aux->nsyms) 8222 { 8223 warn (_("Skipping reloc with invalid symbol index: %u\n"), 8224 sym_ndx); 8225 continue; 8226 } 8227 sym = aux->symtab + sym_ndx; 8228 8229 switch ((rp->r_offset % unw_ent_size) / 4) 8230 { 8231 case 0: 8232 aux->table[i].start.section = sym->st_shndx; 8233 aux->table[i].start.offset = sym->st_value + rp->r_addend; 8234 break; 8235 case 1: 8236 aux->table[i].end.section = sym->st_shndx; 8237 aux->table[i].end.offset = sym->st_value + rp->r_addend; 8238 break; 8239 default: 8240 break; 8241 } 8242 } 8243 8244 free (rela); 8245 } 8246 8247 aux->table_len = nentries; 8248 8249 return TRUE; 8250 } 8251 8252 static bfd_boolean 8253 hppa_process_unwind (Filedata * filedata) 8254 { 8255 struct hppa_unw_aux_info aux; 8256 Elf_Internal_Shdr * unwsec = NULL; 8257 Elf_Internal_Shdr * strsec; 8258 Elf_Internal_Shdr * sec; 8259 unsigned long i; 8260 bfd_boolean res = TRUE; 8261 8262 if (filedata->string_table == NULL) 8263 return FALSE; 8264 8265 memset (& aux, 0, sizeof (aux)); 8266 8267 for (i = 0, sec = filedata->section_headers; i < filedata->file_header.e_shnum; ++i, ++sec) 8268 { 8269 if (sec->sh_type == SHT_SYMTAB 8270 && sec->sh_link < filedata->file_header.e_shnum) 8271 { 8272 aux.symtab = GET_ELF_SYMBOLS (filedata, sec, & aux.nsyms); 8273 8274 strsec = filedata->section_headers + sec->sh_link; 8275 if (aux.strtab != NULL) 8276 { 8277 error (_("Multiple auxillary string tables encountered\n")); 8278 free (aux.strtab); 8279 res = FALSE; 8280 } 8281 aux.strtab = (char *) get_data (NULL, filedata, strsec->sh_offset, 8282 1, strsec->sh_size, 8283 _("string table")); 8284 aux.strtab_size = aux.strtab != NULL ? strsec->sh_size : 0; 8285 } 8286 else if (streq (SECTION_NAME (sec), ".PARISC.unwind")) 8287 unwsec = sec; 8288 } 8289 8290 if (!unwsec) 8291 printf (_("\nThere are no unwind sections in this file.\n")); 8292 8293 for (i = 0, sec = filedata->section_headers; i < filedata->file_header.e_shnum; ++i, ++sec) 8294 { 8295 if (streq (SECTION_NAME (sec), ".PARISC.unwind")) 8296 { 8297 unsigned long num_unwind = sec->sh_size / 16; 8298 8299 printf (ngettext ("\nUnwind section '%s' at offset 0x%lx " 8300 "contains %lu entry:\n", 8301 "\nUnwind section '%s' at offset 0x%lx " 8302 "contains %lu entries:\n", 8303 num_unwind), 8304 printable_section_name (filedata, sec), 8305 (unsigned long) sec->sh_offset, 8306 num_unwind); 8307 8308 if (! slurp_hppa_unwind_table (filedata, &aux, sec)) 8309 res = FALSE; 8310 8311 if (res && aux.table_len > 0) 8312 { 8313 if (! dump_hppa_unwind (filedata, &aux)) 8314 res = FALSE; 8315 } 8316 8317 if (aux.table) 8318 free ((char *) aux.table); 8319 aux.table = NULL; 8320 } 8321 } 8322 8323 if (aux.symtab) 8324 free (aux.symtab); 8325 if (aux.strtab) 8326 free ((char *) aux.strtab); 8327 8328 return res; 8329 } 8330 8331 struct arm_section 8332 { 8333 unsigned char * data; /* The unwind data. */ 8334 Elf_Internal_Shdr * sec; /* The cached unwind section header. */ 8335 Elf_Internal_Rela * rela; /* The cached relocations for this section. */ 8336 unsigned long nrelas; /* The number of relocations. */ 8337 unsigned int rel_type; /* REL or RELA ? */ 8338 Elf_Internal_Rela * next_rela; /* Cyclic pointer to the next reloc to process. */ 8339 }; 8340 8341 struct arm_unw_aux_info 8342 { 8343 Filedata * filedata; /* The file containing the unwind sections. */ 8344 Elf_Internal_Sym * symtab; /* The file's symbol table. */ 8345 unsigned long nsyms; /* Number of symbols. */ 8346 Elf_Internal_Sym * funtab; /* Sorted table of STT_FUNC symbols. */ 8347 unsigned long nfuns; /* Number of these symbols. */ 8348 char * strtab; /* The file's string table. */ 8349 unsigned long strtab_size; /* Size of string table. */ 8350 }; 8351 8352 static const char * 8353 arm_print_vma_and_name (Filedata * filedata, 8354 struct arm_unw_aux_info * aux, 8355 bfd_vma fn, 8356 struct absaddr addr) 8357 { 8358 const char *procname; 8359 bfd_vma sym_offset; 8360 8361 if (addr.section == SHN_UNDEF) 8362 addr.offset = fn; 8363 8364 find_symbol_for_address (filedata, aux->funtab, aux->nfuns, aux->strtab, 8365 aux->strtab_size, addr, &procname, 8366 &sym_offset); 8367 8368 print_vma (fn, PREFIX_HEX); 8369 8370 if (procname) 8371 { 8372 fputs (" <", stdout); 8373 fputs (procname, stdout); 8374 8375 if (sym_offset) 8376 printf ("+0x%lx", (unsigned long) sym_offset); 8377 fputc ('>', stdout); 8378 } 8379 8380 return procname; 8381 } 8382 8383 static void 8384 arm_free_section (struct arm_section *arm_sec) 8385 { 8386 if (arm_sec->data != NULL) 8387 free (arm_sec->data); 8388 8389 if (arm_sec->rela != NULL) 8390 free (arm_sec->rela); 8391 } 8392 8393 /* 1) If SEC does not match the one cached in ARM_SEC, then free the current 8394 cached section and install SEC instead. 8395 2) Locate the 32-bit word at WORD_OFFSET in unwind section SEC 8396 and return its valued in * WORDP, relocating if necessary. 8397 3) Update the NEXT_RELA field in ARM_SEC and store the section index and 8398 relocation's offset in ADDR. 8399 4) If SYM_NAME is non-NULL and a relocation was applied, record the offset 8400 into the string table of the symbol associated with the reloc. If no 8401 reloc was applied store -1 there. 8402 5) Return TRUE upon success, FALSE otherwise. */ 8403 8404 static bfd_boolean 8405 get_unwind_section_word (Filedata * filedata, 8406 struct arm_unw_aux_info * aux, 8407 struct arm_section * arm_sec, 8408 Elf_Internal_Shdr * sec, 8409 bfd_vma word_offset, 8410 unsigned int * wordp, 8411 struct absaddr * addr, 8412 bfd_vma * sym_name) 8413 { 8414 Elf_Internal_Rela *rp; 8415 Elf_Internal_Sym *sym; 8416 const char * relname; 8417 unsigned int word; 8418 bfd_boolean wrapped; 8419 8420 if (sec == NULL || arm_sec == NULL) 8421 return FALSE; 8422 8423 addr->section = SHN_UNDEF; 8424 addr->offset = 0; 8425 8426 if (sym_name != NULL) 8427 *sym_name = (bfd_vma) -1; 8428 8429 /* If necessary, update the section cache. */ 8430 if (sec != arm_sec->sec) 8431 { 8432 Elf_Internal_Shdr *relsec; 8433 8434 arm_free_section (arm_sec); 8435 8436 arm_sec->sec = sec; 8437 arm_sec->data = get_data (NULL, aux->filedata, sec->sh_offset, 1, 8438 sec->sh_size, _("unwind data")); 8439 arm_sec->rela = NULL; 8440 arm_sec->nrelas = 0; 8441 8442 for (relsec = filedata->section_headers; 8443 relsec < filedata->section_headers + filedata->file_header.e_shnum; 8444 ++relsec) 8445 { 8446 if (relsec->sh_info >= filedata->file_header.e_shnum 8447 || filedata->section_headers + relsec->sh_info != sec 8448 /* PR 15745: Check the section type as well. */ 8449 || (relsec->sh_type != SHT_REL 8450 && relsec->sh_type != SHT_RELA)) 8451 continue; 8452 8453 arm_sec->rel_type = relsec->sh_type; 8454 if (relsec->sh_type == SHT_REL) 8455 { 8456 if (!slurp_rel_relocs (aux->filedata, relsec->sh_offset, 8457 relsec->sh_size, 8458 & arm_sec->rela, & arm_sec->nrelas)) 8459 return FALSE; 8460 } 8461 else /* relsec->sh_type == SHT_RELA */ 8462 { 8463 if (!slurp_rela_relocs (aux->filedata, relsec->sh_offset, 8464 relsec->sh_size, 8465 & arm_sec->rela, & arm_sec->nrelas)) 8466 return FALSE; 8467 } 8468 break; 8469 } 8470 8471 arm_sec->next_rela = arm_sec->rela; 8472 } 8473 8474 /* If there is no unwind data we can do nothing. */ 8475 if (arm_sec->data == NULL) 8476 return FALSE; 8477 8478 /* If the offset is invalid then fail. */ 8479 if (/* PR 21343 *//* PR 18879 */ 8480 sec->sh_size < 4 8481 || word_offset > (sec->sh_size - 4) 8482 || ((bfd_signed_vma) word_offset) < 0) 8483 return FALSE; 8484 8485 /* Get the word at the required offset. */ 8486 word = byte_get (arm_sec->data + word_offset, 4); 8487 8488 /* PR 17531: file: id:000001,src:001266+003044,op:splice,rep:128. */ 8489 if (arm_sec->rela == NULL) 8490 { 8491 * wordp = word; 8492 return TRUE; 8493 } 8494 8495 /* Look through the relocs to find the one that applies to the provided offset. */ 8496 wrapped = FALSE; 8497 for (rp = arm_sec->next_rela; rp != arm_sec->rela + arm_sec->nrelas; rp++) 8498 { 8499 bfd_vma prelval, offset; 8500 8501 if (rp->r_offset > word_offset && !wrapped) 8502 { 8503 rp = arm_sec->rela; 8504 wrapped = TRUE; 8505 } 8506 if (rp->r_offset > word_offset) 8507 break; 8508 8509 if (rp->r_offset & 3) 8510 { 8511 warn (_("Skipping unexpected relocation at offset 0x%lx\n"), 8512 (unsigned long) rp->r_offset); 8513 continue; 8514 } 8515 8516 if (rp->r_offset < word_offset) 8517 continue; 8518 8519 /* PR 17531: file: 027-161405-0.004 */ 8520 if (aux->symtab == NULL) 8521 continue; 8522 8523 if (arm_sec->rel_type == SHT_REL) 8524 { 8525 offset = word & 0x7fffffff; 8526 if (offset & 0x40000000) 8527 offset |= ~ (bfd_vma) 0x7fffffff; 8528 } 8529 else if (arm_sec->rel_type == SHT_RELA) 8530 offset = rp->r_addend; 8531 else 8532 { 8533 error (_("Unknown section relocation type %d encountered\n"), 8534 arm_sec->rel_type); 8535 break; 8536 } 8537 8538 /* PR 17531 file: 027-1241568-0.004. */ 8539 if (ELF32_R_SYM (rp->r_info) >= aux->nsyms) 8540 { 8541 error (_("Bad symbol index in unwind relocation (%lu > %lu)\n"), 8542 (unsigned long) ELF32_R_SYM (rp->r_info), aux->nsyms); 8543 break; 8544 } 8545 8546 sym = aux->symtab + ELF32_R_SYM (rp->r_info); 8547 offset += sym->st_value; 8548 prelval = offset - (arm_sec->sec->sh_addr + rp->r_offset); 8549 8550 /* Check that we are processing the expected reloc type. */ 8551 if (filedata->file_header.e_machine == EM_ARM) 8552 { 8553 relname = elf_arm_reloc_type (ELF32_R_TYPE (rp->r_info)); 8554 if (relname == NULL) 8555 { 8556 warn (_("Skipping unknown ARM relocation type: %d\n"), 8557 (int) ELF32_R_TYPE (rp->r_info)); 8558 continue; 8559 } 8560 8561 if (streq (relname, "R_ARM_NONE")) 8562 continue; 8563 8564 if (! streq (relname, "R_ARM_PREL31")) 8565 { 8566 warn (_("Skipping unexpected ARM relocation type %s\n"), relname); 8567 continue; 8568 } 8569 } 8570 else if (filedata->file_header.e_machine == EM_TI_C6000) 8571 { 8572 relname = elf_tic6x_reloc_type (ELF32_R_TYPE (rp->r_info)); 8573 if (relname == NULL) 8574 { 8575 warn (_("Skipping unknown C6000 relocation type: %d\n"), 8576 (int) ELF32_R_TYPE (rp->r_info)); 8577 continue; 8578 } 8579 8580 if (streq (relname, "R_C6000_NONE")) 8581 continue; 8582 8583 if (! streq (relname, "R_C6000_PREL31")) 8584 { 8585 warn (_("Skipping unexpected C6000 relocation type %s\n"), relname); 8586 continue; 8587 } 8588 8589 prelval >>= 1; 8590 } 8591 else 8592 { 8593 /* This function currently only supports ARM and TI unwinders. */ 8594 warn (_("Only TI and ARM unwinders are currently supported\n")); 8595 break; 8596 } 8597 8598 word = (word & ~ (bfd_vma) 0x7fffffff) | (prelval & 0x7fffffff); 8599 addr->section = sym->st_shndx; 8600 addr->offset = offset; 8601 8602 if (sym_name) 8603 * sym_name = sym->st_name; 8604 break; 8605 } 8606 8607 *wordp = word; 8608 arm_sec->next_rela = rp; 8609 8610 return TRUE; 8611 } 8612 8613 static const char *tic6x_unwind_regnames[16] = 8614 { 8615 "A15", "B15", "B14", "B13", "B12", "B11", "B10", "B3", 8616 "A14", "A13", "A12", "A11", "A10", 8617 "[invalid reg 13]", "[invalid reg 14]", "[invalid reg 15]" 8618 }; 8619 8620 static void 8621 decode_tic6x_unwind_regmask (unsigned int mask) 8622 { 8623 int i; 8624 8625 for (i = 12; mask; mask >>= 1, i--) 8626 { 8627 if (mask & 1) 8628 { 8629 fputs (tic6x_unwind_regnames[i], stdout); 8630 if (mask > 1) 8631 fputs (", ", stdout); 8632 } 8633 } 8634 } 8635 8636 #define ADVANCE \ 8637 if (remaining == 0 && more_words) \ 8638 { \ 8639 data_offset += 4; \ 8640 if (! get_unwind_section_word (filedata, aux, data_arm_sec, data_sec, \ 8641 data_offset, & word, & addr, NULL)) \ 8642 return FALSE; \ 8643 remaining = 4; \ 8644 more_words--; \ 8645 } \ 8646 8647 #define GET_OP(OP) \ 8648 ADVANCE; \ 8649 if (remaining) \ 8650 { \ 8651 remaining--; \ 8652 (OP) = word >> 24; \ 8653 word <<= 8; \ 8654 } \ 8655 else \ 8656 { \ 8657 printf (_("[Truncated opcode]\n")); \ 8658 return FALSE; \ 8659 } \ 8660 printf ("0x%02x ", OP) 8661 8662 static bfd_boolean 8663 decode_arm_unwind_bytecode (Filedata * filedata, 8664 struct arm_unw_aux_info * aux, 8665 unsigned int word, 8666 unsigned int remaining, 8667 unsigned int more_words, 8668 bfd_vma data_offset, 8669 Elf_Internal_Shdr * data_sec, 8670 struct arm_section * data_arm_sec) 8671 { 8672 struct absaddr addr; 8673 bfd_boolean res = TRUE; 8674 8675 /* Decode the unwinding instructions. */ 8676 while (1) 8677 { 8678 unsigned int op, op2; 8679 8680 ADVANCE; 8681 if (remaining == 0) 8682 break; 8683 remaining--; 8684 op = word >> 24; 8685 word <<= 8; 8686 8687 printf (" 0x%02x ", op); 8688 8689 if ((op & 0xc0) == 0x00) 8690 { 8691 int offset = ((op & 0x3f) << 2) + 4; 8692 8693 printf (" vsp = vsp + %d", offset); 8694 } 8695 else if ((op & 0xc0) == 0x40) 8696 { 8697 int offset = ((op & 0x3f) << 2) + 4; 8698 8699 printf (" vsp = vsp - %d", offset); 8700 } 8701 else if ((op & 0xf0) == 0x80) 8702 { 8703 GET_OP (op2); 8704 if (op == 0x80 && op2 == 0) 8705 printf (_("Refuse to unwind")); 8706 else 8707 { 8708 unsigned int mask = ((op & 0x0f) << 8) | op2; 8709 bfd_boolean first = TRUE; 8710 int i; 8711 8712 printf ("pop {"); 8713 for (i = 0; i < 12; i++) 8714 if (mask & (1 << i)) 8715 { 8716 if (first) 8717 first = FALSE; 8718 else 8719 printf (", "); 8720 printf ("r%d", 4 + i); 8721 } 8722 printf ("}"); 8723 } 8724 } 8725 else if ((op & 0xf0) == 0x90) 8726 { 8727 if (op == 0x9d || op == 0x9f) 8728 printf (_(" [Reserved]")); 8729 else 8730 printf (" vsp = r%d", op & 0x0f); 8731 } 8732 else if ((op & 0xf0) == 0xa0) 8733 { 8734 int end = 4 + (op & 0x07); 8735 bfd_boolean first = TRUE; 8736 int i; 8737 8738 printf (" pop {"); 8739 for (i = 4; i <= end; i++) 8740 { 8741 if (first) 8742 first = FALSE; 8743 else 8744 printf (", "); 8745 printf ("r%d", i); 8746 } 8747 if (op & 0x08) 8748 { 8749 if (!first) 8750 printf (", "); 8751 printf ("r14"); 8752 } 8753 printf ("}"); 8754 } 8755 else if (op == 0xb0) 8756 printf (_(" finish")); 8757 else if (op == 0xb1) 8758 { 8759 GET_OP (op2); 8760 if (op2 == 0 || (op2 & 0xf0) != 0) 8761 printf (_("[Spare]")); 8762 else 8763 { 8764 unsigned int mask = op2 & 0x0f; 8765 bfd_boolean first = TRUE; 8766 int i; 8767 8768 printf ("pop {"); 8769 for (i = 0; i < 12; i++) 8770 if (mask & (1 << i)) 8771 { 8772 if (first) 8773 first = FALSE; 8774 else 8775 printf (", "); 8776 printf ("r%d", i); 8777 } 8778 printf ("}"); 8779 } 8780 } 8781 else if (op == 0xb2) 8782 { 8783 unsigned char buf[9]; 8784 unsigned int i, len; 8785 unsigned long offset; 8786 8787 for (i = 0; i < sizeof (buf); i++) 8788 { 8789 GET_OP (buf[i]); 8790 if ((buf[i] & 0x80) == 0) 8791 break; 8792 } 8793 if (i == sizeof (buf)) 8794 { 8795 error (_("corrupt change to vsp")); 8796 res = FALSE; 8797 } 8798 else 8799 { 8800 offset = read_leb128 (buf, buf + i + 1, FALSE, &len, NULL); 8801 assert (len == i + 1); 8802 offset = offset * 4 + 0x204; 8803 printf ("vsp = vsp + %ld", offset); 8804 } 8805 } 8806 else if (op == 0xb3 || op == 0xc8 || op == 0xc9) 8807 { 8808 unsigned int first, last; 8809 8810 GET_OP (op2); 8811 first = op2 >> 4; 8812 last = op2 & 0x0f; 8813 if (op == 0xc8) 8814 first = first + 16; 8815 printf ("pop {D%d", first); 8816 if (last) 8817 printf ("-D%d", first + last); 8818 printf ("}"); 8819 } 8820 else if ((op & 0xf8) == 0xb8 || (op & 0xf8) == 0xd0) 8821 { 8822 unsigned int count = op & 0x07; 8823 8824 printf ("pop {D8"); 8825 if (count) 8826 printf ("-D%d", 8 + count); 8827 printf ("}"); 8828 } 8829 else if (op >= 0xc0 && op <= 0xc5) 8830 { 8831 unsigned int count = op & 0x07; 8832 8833 printf (" pop {wR10"); 8834 if (count) 8835 printf ("-wR%d", 10 + count); 8836 printf ("}"); 8837 } 8838 else if (op == 0xc6) 8839 { 8840 unsigned int first, last; 8841 8842 GET_OP (op2); 8843 first = op2 >> 4; 8844 last = op2 & 0x0f; 8845 printf ("pop {wR%d", first); 8846 if (last) 8847 printf ("-wR%d", first + last); 8848 printf ("}"); 8849 } 8850 else if (op == 0xc7) 8851 { 8852 GET_OP (op2); 8853 if (op2 == 0 || (op2 & 0xf0) != 0) 8854 printf (_("[Spare]")); 8855 else 8856 { 8857 unsigned int mask = op2 & 0x0f; 8858 bfd_boolean first = TRUE; 8859 int i; 8860 8861 printf ("pop {"); 8862 for (i = 0; i < 4; i++) 8863 if (mask & (1 << i)) 8864 { 8865 if (first) 8866 first = FALSE; 8867 else 8868 printf (", "); 8869 printf ("wCGR%d", i); 8870 } 8871 printf ("}"); 8872 } 8873 } 8874 else 8875 { 8876 printf (_(" [unsupported opcode]")); 8877 res = FALSE; 8878 } 8879 8880 printf ("\n"); 8881 } 8882 8883 return res; 8884 } 8885 8886 static bfd_boolean 8887 decode_tic6x_unwind_bytecode (Filedata * filedata, 8888 struct arm_unw_aux_info * aux, 8889 unsigned int word, 8890 unsigned int remaining, 8891 unsigned int more_words, 8892 bfd_vma data_offset, 8893 Elf_Internal_Shdr * data_sec, 8894 struct arm_section * data_arm_sec) 8895 { 8896 struct absaddr addr; 8897 8898 /* Decode the unwinding instructions. */ 8899 while (1) 8900 { 8901 unsigned int op, op2; 8902 8903 ADVANCE; 8904 if (remaining == 0) 8905 break; 8906 remaining--; 8907 op = word >> 24; 8908 word <<= 8; 8909 8910 printf (" 0x%02x ", op); 8911 8912 if ((op & 0xc0) == 0x00) 8913 { 8914 int offset = ((op & 0x3f) << 3) + 8; 8915 printf (" sp = sp + %d", offset); 8916 } 8917 else if ((op & 0xc0) == 0x80) 8918 { 8919 GET_OP (op2); 8920 if (op == 0x80 && op2 == 0) 8921 printf (_("Refuse to unwind")); 8922 else 8923 { 8924 unsigned int mask = ((op & 0x1f) << 8) | op2; 8925 if (op & 0x20) 8926 printf ("pop compact {"); 8927 else 8928 printf ("pop {"); 8929 8930 decode_tic6x_unwind_regmask (mask); 8931 printf("}"); 8932 } 8933 } 8934 else if ((op & 0xf0) == 0xc0) 8935 { 8936 unsigned int reg; 8937 unsigned int nregs; 8938 unsigned int i; 8939 const char *name; 8940 struct 8941 { 8942 unsigned int offset; 8943 unsigned int reg; 8944 } regpos[16]; 8945 8946 /* Scan entire instruction first so that GET_OP output is not 8947 interleaved with disassembly. */ 8948 nregs = 0; 8949 for (i = 0; nregs < (op & 0xf); i++) 8950 { 8951 GET_OP (op2); 8952 reg = op2 >> 4; 8953 if (reg != 0xf) 8954 { 8955 regpos[nregs].offset = i * 2; 8956 regpos[nregs].reg = reg; 8957 nregs++; 8958 } 8959 8960 reg = op2 & 0xf; 8961 if (reg != 0xf) 8962 { 8963 regpos[nregs].offset = i * 2 + 1; 8964 regpos[nregs].reg = reg; 8965 nregs++; 8966 } 8967 } 8968 8969 printf (_("pop frame {")); 8970 if (nregs == 0) 8971 { 8972 printf (_("*corrupt* - no registers specified")); 8973 } 8974 else 8975 { 8976 reg = nregs - 1; 8977 for (i = i * 2; i > 0; i--) 8978 { 8979 if (regpos[reg].offset == i - 1) 8980 { 8981 name = tic6x_unwind_regnames[regpos[reg].reg]; 8982 if (reg > 0) 8983 reg--; 8984 } 8985 else 8986 name = _("[pad]"); 8987 8988 fputs (name, stdout); 8989 if (i > 1) 8990 printf (", "); 8991 } 8992 } 8993 8994 printf ("}"); 8995 } 8996 else if (op == 0xd0) 8997 printf (" MOV FP, SP"); 8998 else if (op == 0xd1) 8999 printf (" __c6xabi_pop_rts"); 9000 else if (op == 0xd2) 9001 { 9002 unsigned char buf[9]; 9003 unsigned int i, len; 9004 unsigned long offset; 9005 9006 for (i = 0; i < sizeof (buf); i++) 9007 { 9008 GET_OP (buf[i]); 9009 if ((buf[i] & 0x80) == 0) 9010 break; 9011 } 9012 /* PR 17531: file: id:000001,src:001906+004739,op:splice,rep:2. */ 9013 if (i == sizeof (buf)) 9014 { 9015 warn (_("Corrupt stack pointer adjustment detected\n")); 9016 return FALSE; 9017 } 9018 9019 offset = read_leb128 (buf, buf + i + 1, FALSE, &len, NULL); 9020 assert (len == i + 1); 9021 offset = offset * 8 + 0x408; 9022 printf (_("sp = sp + %ld"), offset); 9023 } 9024 else if ((op & 0xf0) == 0xe0) 9025 { 9026 if ((op & 0x0f) == 7) 9027 printf (" RETURN"); 9028 else 9029 printf (" MV %s, B3", tic6x_unwind_regnames[op & 0x0f]); 9030 } 9031 else 9032 { 9033 printf (_(" [unsupported opcode]")); 9034 } 9035 putchar ('\n'); 9036 } 9037 9038 return TRUE; 9039 } 9040 9041 static bfd_vma 9042 arm_expand_prel31 (Filedata * filedata, bfd_vma word, bfd_vma where) 9043 { 9044 bfd_vma offset; 9045 9046 offset = word & 0x7fffffff; 9047 if (offset & 0x40000000) 9048 offset |= ~ (bfd_vma) 0x7fffffff; 9049 9050 if (filedata->file_header.e_machine == EM_TI_C6000) 9051 offset <<= 1; 9052 9053 return offset + where; 9054 } 9055 9056 static bfd_boolean 9057 decode_arm_unwind (Filedata * filedata, 9058 struct arm_unw_aux_info * aux, 9059 unsigned int word, 9060 unsigned int remaining, 9061 bfd_vma data_offset, 9062 Elf_Internal_Shdr * data_sec, 9063 struct arm_section * data_arm_sec) 9064 { 9065 int per_index; 9066 unsigned int more_words = 0; 9067 struct absaddr addr; 9068 bfd_vma sym_name = (bfd_vma) -1; 9069 bfd_boolean res = TRUE; 9070 9071 if (remaining == 0) 9072 { 9073 /* Fetch the first word. 9074 Note - when decoding an object file the address extracted 9075 here will always be 0. So we also pass in the sym_name 9076 parameter so that we can find the symbol associated with 9077 the personality routine. */ 9078 if (! get_unwind_section_word (filedata, aux, data_arm_sec, data_sec, data_offset, 9079 & word, & addr, & sym_name)) 9080 return FALSE; 9081 9082 remaining = 4; 9083 } 9084 else 9085 { 9086 addr.section = SHN_UNDEF; 9087 addr.offset = 0; 9088 } 9089 9090 if ((word & 0x80000000) == 0) 9091 { 9092 /* Expand prel31 for personality routine. */ 9093 bfd_vma fn; 9094 const char *procname; 9095 9096 fn = arm_expand_prel31 (filedata, word, data_sec->sh_addr + data_offset); 9097 printf (_(" Personality routine: ")); 9098 if (fn == 0 9099 && addr.section == SHN_UNDEF && addr.offset == 0 9100 && sym_name != (bfd_vma) -1 && sym_name < aux->strtab_size) 9101 { 9102 procname = aux->strtab + sym_name; 9103 print_vma (fn, PREFIX_HEX); 9104 if (procname) 9105 { 9106 fputs (" <", stdout); 9107 fputs (procname, stdout); 9108 fputc ('>', stdout); 9109 } 9110 } 9111 else 9112 procname = arm_print_vma_and_name (filedata, aux, fn, addr); 9113 fputc ('\n', stdout); 9114 9115 /* The GCC personality routines use the standard compact 9116 encoding, starting with one byte giving the number of 9117 words. */ 9118 if (procname != NULL 9119 && (const_strneq (procname, "__gcc_personality_v0") 9120 || const_strneq (procname, "__gxx_personality_v0") 9121 || const_strneq (procname, "__gcj_personality_v0") 9122 || const_strneq (procname, "__gnu_objc_personality_v0"))) 9123 { 9124 remaining = 0; 9125 more_words = 1; 9126 ADVANCE; 9127 if (!remaining) 9128 { 9129 printf (_(" [Truncated data]\n")); 9130 return FALSE; 9131 } 9132 more_words = word >> 24; 9133 word <<= 8; 9134 remaining--; 9135 per_index = -1; 9136 } 9137 else 9138 return TRUE; 9139 } 9140 else 9141 { 9142 /* ARM EHABI Section 6.3: 9143 9144 An exception-handling table entry for the compact model looks like: 9145 9146 31 30-28 27-24 23-0 9147 -- ----- ----- ---- 9148 1 0 index Data for personalityRoutine[index] */ 9149 9150 if (filedata->file_header.e_machine == EM_ARM 9151 && (word & 0x70000000)) 9152 { 9153 warn (_("Corrupt ARM compact model table entry: %x \n"), word); 9154 res = FALSE; 9155 } 9156 9157 per_index = (word >> 24) & 0x7f; 9158 printf (_(" Compact model index: %d\n"), per_index); 9159 if (per_index == 0) 9160 { 9161 more_words = 0; 9162 word <<= 8; 9163 remaining--; 9164 } 9165 else if (per_index < 3) 9166 { 9167 more_words = (word >> 16) & 0xff; 9168 word <<= 16; 9169 remaining -= 2; 9170 } 9171 } 9172 9173 switch (filedata->file_header.e_machine) 9174 { 9175 case EM_ARM: 9176 if (per_index < 3) 9177 { 9178 if (! decode_arm_unwind_bytecode (filedata, aux, word, remaining, more_words, 9179 data_offset, data_sec, data_arm_sec)) 9180 res = FALSE; 9181 } 9182 else 9183 { 9184 warn (_("Unknown ARM compact model index encountered\n")); 9185 printf (_(" [reserved]\n")); 9186 res = FALSE; 9187 } 9188 break; 9189 9190 case EM_TI_C6000: 9191 if (per_index < 3) 9192 { 9193 if (! decode_tic6x_unwind_bytecode (filedata, aux, word, remaining, more_words, 9194 data_offset, data_sec, data_arm_sec)) 9195 res = FALSE; 9196 } 9197 else if (per_index < 5) 9198 { 9199 if (((word >> 17) & 0x7f) == 0x7f) 9200 printf (_(" Restore stack from frame pointer\n")); 9201 else 9202 printf (_(" Stack increment %d\n"), (word >> 14) & 0x1fc); 9203 printf (_(" Registers restored: ")); 9204 if (per_index == 4) 9205 printf (" (compact) "); 9206 decode_tic6x_unwind_regmask ((word >> 4) & 0x1fff); 9207 putchar ('\n'); 9208 printf (_(" Return register: %s\n"), 9209 tic6x_unwind_regnames[word & 0xf]); 9210 } 9211 else 9212 printf (_(" [reserved (%d)]\n"), per_index); 9213 break; 9214 9215 default: 9216 error (_("Unsupported architecture type %d encountered when decoding unwind table\n"), 9217 filedata->file_header.e_machine); 9218 res = FALSE; 9219 } 9220 9221 /* Decode the descriptors. Not implemented. */ 9222 9223 return res; 9224 } 9225 9226 static bfd_boolean 9227 dump_arm_unwind (Filedata * filedata, 9228 struct arm_unw_aux_info * aux, 9229 Elf_Internal_Shdr * exidx_sec) 9230 { 9231 struct arm_section exidx_arm_sec, extab_arm_sec; 9232 unsigned int i, exidx_len; 9233 unsigned long j, nfuns; 9234 bfd_boolean res = TRUE; 9235 9236 memset (&exidx_arm_sec, 0, sizeof (exidx_arm_sec)); 9237 memset (&extab_arm_sec, 0, sizeof (extab_arm_sec)); 9238 exidx_len = exidx_sec->sh_size / 8; 9239 9240 aux->funtab = xmalloc (aux->nsyms * sizeof (Elf_Internal_Sym)); 9241 for (nfuns = 0, j = 0; j < aux->nsyms; j++) 9242 if (aux->symtab[j].st_value && ELF_ST_TYPE (aux->symtab[j].st_info) == STT_FUNC) 9243 aux->funtab[nfuns++] = aux->symtab[j]; 9244 aux->nfuns = nfuns; 9245 qsort (aux->funtab, aux->nfuns, sizeof (Elf_Internal_Sym), symcmp); 9246 9247 for (i = 0; i < exidx_len; i++) 9248 { 9249 unsigned int exidx_fn, exidx_entry; 9250 struct absaddr fn_addr, entry_addr; 9251 bfd_vma fn; 9252 9253 fputc ('\n', stdout); 9254 9255 if (! get_unwind_section_word (filedata, aux, & exidx_arm_sec, exidx_sec, 9256 8 * i, & exidx_fn, & fn_addr, NULL) 9257 || ! get_unwind_section_word (filedata, aux, & exidx_arm_sec, exidx_sec, 9258 8 * i + 4, & exidx_entry, & entry_addr, NULL)) 9259 { 9260 free (aux->funtab); 9261 arm_free_section (& exidx_arm_sec); 9262 arm_free_section (& extab_arm_sec); 9263 return FALSE; 9264 } 9265 9266 /* ARM EHABI, Section 5: 9267 An index table entry consists of 2 words. 9268 The first word contains a prel31 offset to the start of a function, with bit 31 clear. */ 9269 if (exidx_fn & 0x80000000) 9270 { 9271 warn (_("corrupt index table entry: %x\n"), exidx_fn); 9272 res = FALSE; 9273 } 9274 9275 fn = arm_expand_prel31 (filedata, exidx_fn, exidx_sec->sh_addr + 8 * i); 9276 9277 arm_print_vma_and_name (filedata, aux, fn, fn_addr); 9278 fputs (": ", stdout); 9279 9280 if (exidx_entry == 1) 9281 { 9282 print_vma (exidx_entry, PREFIX_HEX); 9283 fputs (" [cantunwind]\n", stdout); 9284 } 9285 else if (exidx_entry & 0x80000000) 9286 { 9287 print_vma (exidx_entry, PREFIX_HEX); 9288 fputc ('\n', stdout); 9289 decode_arm_unwind (filedata, aux, exidx_entry, 4, 0, NULL, NULL); 9290 } 9291 else 9292 { 9293 bfd_vma table, table_offset = 0; 9294 Elf_Internal_Shdr *table_sec; 9295 9296 fputs ("@", stdout); 9297 table = arm_expand_prel31 (filedata, exidx_entry, exidx_sec->sh_addr + 8 * i + 4); 9298 print_vma (table, PREFIX_HEX); 9299 printf ("\n"); 9300 9301 /* Locate the matching .ARM.extab. */ 9302 if (entry_addr.section != SHN_UNDEF 9303 && entry_addr.section < filedata->file_header.e_shnum) 9304 { 9305 table_sec = filedata->section_headers + entry_addr.section; 9306 table_offset = entry_addr.offset; 9307 /* PR 18879 */ 9308 if (table_offset > table_sec->sh_size 9309 || ((bfd_signed_vma) table_offset) < 0) 9310 { 9311 warn (_("Unwind entry contains corrupt offset (0x%lx) into section %s\n"), 9312 (unsigned long) table_offset, 9313 printable_section_name (filedata, table_sec)); 9314 res = FALSE; 9315 continue; 9316 } 9317 } 9318 else 9319 { 9320 table_sec = find_section_by_address (filedata, table); 9321 if (table_sec != NULL) 9322 table_offset = table - table_sec->sh_addr; 9323 } 9324 9325 if (table_sec == NULL) 9326 { 9327 warn (_("Could not locate .ARM.extab section containing 0x%lx.\n"), 9328 (unsigned long) table); 9329 res = FALSE; 9330 continue; 9331 } 9332 9333 if (! decode_arm_unwind (filedata, aux, 0, 0, table_offset, table_sec, 9334 &extab_arm_sec)) 9335 res = FALSE; 9336 } 9337 } 9338 9339 printf ("\n"); 9340 9341 free (aux->funtab); 9342 arm_free_section (&exidx_arm_sec); 9343 arm_free_section (&extab_arm_sec); 9344 9345 return res; 9346 } 9347 9348 /* Used for both ARM and C6X unwinding tables. */ 9349 9350 static bfd_boolean 9351 arm_process_unwind (Filedata * filedata) 9352 { 9353 struct arm_unw_aux_info aux; 9354 Elf_Internal_Shdr *unwsec = NULL; 9355 Elf_Internal_Shdr *strsec; 9356 Elf_Internal_Shdr *sec; 9357 unsigned long i; 9358 unsigned int sec_type; 9359 bfd_boolean res = TRUE; 9360 9361 switch (filedata->file_header.e_machine) 9362 { 9363 case EM_ARM: 9364 sec_type = SHT_ARM_EXIDX; 9365 break; 9366 9367 case EM_TI_C6000: 9368 sec_type = SHT_C6000_UNWIND; 9369 break; 9370 9371 default: 9372 error (_("Unsupported architecture type %d encountered when processing unwind table\n"), 9373 filedata->file_header.e_machine); 9374 return FALSE; 9375 } 9376 9377 if (filedata->string_table == NULL) 9378 return FALSE; 9379 9380 memset (& aux, 0, sizeof (aux)); 9381 aux.filedata = filedata; 9382 9383 for (i = 0, sec = filedata->section_headers; i < filedata->file_header.e_shnum; ++i, ++sec) 9384 { 9385 if (sec->sh_type == SHT_SYMTAB && sec->sh_link < filedata->file_header.e_shnum) 9386 { 9387 aux.symtab = GET_ELF_SYMBOLS (filedata, sec, & aux.nsyms); 9388 9389 strsec = filedata->section_headers + sec->sh_link; 9390 9391 /* PR binutils/17531 file: 011-12666-0.004. */ 9392 if (aux.strtab != NULL) 9393 { 9394 error (_("Multiple string tables found in file.\n")); 9395 free (aux.strtab); 9396 res = FALSE; 9397 } 9398 aux.strtab = get_data (NULL, filedata, strsec->sh_offset, 9399 1, strsec->sh_size, _("string table")); 9400 aux.strtab_size = aux.strtab != NULL ? strsec->sh_size : 0; 9401 } 9402 else if (sec->sh_type == sec_type) 9403 unwsec = sec; 9404 } 9405 9406 if (unwsec == NULL) 9407 printf (_("\nThere are no unwind sections in this file.\n")); 9408 else 9409 for (i = 0, sec = filedata->section_headers; i < filedata->file_header.e_shnum; ++i, ++sec) 9410 { 9411 if (sec->sh_type == sec_type) 9412 { 9413 unsigned long num_unwind = sec->sh_size / (2 * eh_addr_size); 9414 printf (ngettext ("\nUnwind section '%s' at offset 0x%lx " 9415 "contains %lu entry:\n", 9416 "\nUnwind section '%s' at offset 0x%lx " 9417 "contains %lu entries:\n", 9418 num_unwind), 9419 printable_section_name (filedata, sec), 9420 (unsigned long) sec->sh_offset, 9421 num_unwind); 9422 9423 if (! dump_arm_unwind (filedata, &aux, sec)) 9424 res = FALSE; 9425 } 9426 } 9427 9428 if (aux.symtab) 9429 free (aux.symtab); 9430 if (aux.strtab) 9431 free ((char *) aux.strtab); 9432 9433 return res; 9434 } 9435 9436 static bfd_boolean 9437 process_unwind (Filedata * filedata) 9438 { 9439 struct unwind_handler 9440 { 9441 unsigned int machtype; 9442 bfd_boolean (* handler)(Filedata *); 9443 } handlers[] = 9444 { 9445 { EM_ARM, arm_process_unwind }, 9446 { EM_IA_64, ia64_process_unwind }, 9447 { EM_PARISC, hppa_process_unwind }, 9448 { EM_TI_C6000, arm_process_unwind }, 9449 { 0, NULL } 9450 }; 9451 int i; 9452 9453 if (!do_unwind) 9454 return TRUE; 9455 9456 for (i = 0; handlers[i].handler != NULL; i++) 9457 if (filedata->file_header.e_machine == handlers[i].machtype) 9458 return handlers[i].handler (filedata); 9459 9460 printf (_("\nThe decoding of unwind sections for machine type %s is not currently supported.\n"), 9461 get_machine_name (filedata->file_header.e_machine)); 9462 return TRUE; 9463 } 9464 9465 static void 9466 dynamic_section_aarch64_val (Elf_Internal_Dyn * entry) 9467 { 9468 switch (entry->d_tag) 9469 { 9470 case DT_AARCH64_BTI_PLT: 9471 case DT_AARCH64_PAC_PLT: 9472 break; 9473 default: 9474 print_vma (entry->d_un.d_ptr, PREFIX_HEX); 9475 break; 9476 } 9477 putchar ('\n'); 9478 } 9479 9480 static void 9481 dynamic_section_mips_val (Elf_Internal_Dyn * entry) 9482 { 9483 switch (entry->d_tag) 9484 { 9485 case DT_MIPS_FLAGS: 9486 if (entry->d_un.d_val == 0) 9487 printf (_("NONE")); 9488 else 9489 { 9490 static const char * opts[] = 9491 { 9492 "QUICKSTART", "NOTPOT", "NO_LIBRARY_REPLACEMENT", 9493 "NO_MOVE", "SGI_ONLY", "GUARANTEE_INIT", "DELTA_C_PLUS_PLUS", 9494 "GUARANTEE_START_INIT", "PIXIE", "DEFAULT_DELAY_LOAD", 9495 "REQUICKSTART", "REQUICKSTARTED", "CORD", "NO_UNRES_UNDEF", 9496 "RLD_ORDER_SAFE" 9497 }; 9498 unsigned int cnt; 9499 bfd_boolean first = TRUE; 9500 9501 for (cnt = 0; cnt < ARRAY_SIZE (opts); ++cnt) 9502 if (entry->d_un.d_val & (1 << cnt)) 9503 { 9504 printf ("%s%s", first ? "" : " ", opts[cnt]); 9505 first = FALSE; 9506 } 9507 } 9508 break; 9509 9510 case DT_MIPS_IVERSION: 9511 if (VALID_DYNAMIC_NAME (entry->d_un.d_val)) 9512 printf (_("Interface Version: %s"), GET_DYNAMIC_NAME (entry->d_un.d_val)); 9513 else 9514 { 9515 char buf[40]; 9516 sprintf_vma (buf, entry->d_un.d_ptr); 9517 /* Note: coded this way so that there is a single string for translation. */ 9518 printf (_("<corrupt: %s>"), buf); 9519 } 9520 break; 9521 9522 case DT_MIPS_TIME_STAMP: 9523 { 9524 char timebuf[128]; 9525 struct tm * tmp; 9526 time_t atime = entry->d_un.d_val; 9527 9528 tmp = gmtime (&atime); 9529 /* PR 17531: file: 6accc532. */ 9530 if (tmp == NULL) 9531 snprintf (timebuf, sizeof (timebuf), _("<corrupt>")); 9532 else 9533 snprintf (timebuf, sizeof (timebuf), "%04u-%02u-%02uT%02u:%02u:%02u", 9534 tmp->tm_year + 1900, tmp->tm_mon + 1, tmp->tm_mday, 9535 tmp->tm_hour, tmp->tm_min, tmp->tm_sec); 9536 printf (_("Time Stamp: %s"), timebuf); 9537 } 9538 break; 9539 9540 case DT_MIPS_RLD_VERSION: 9541 case DT_MIPS_LOCAL_GOTNO: 9542 case DT_MIPS_CONFLICTNO: 9543 case DT_MIPS_LIBLISTNO: 9544 case DT_MIPS_SYMTABNO: 9545 case DT_MIPS_UNREFEXTNO: 9546 case DT_MIPS_HIPAGENO: 9547 case DT_MIPS_DELTA_CLASS_NO: 9548 case DT_MIPS_DELTA_INSTANCE_NO: 9549 case DT_MIPS_DELTA_RELOC_NO: 9550 case DT_MIPS_DELTA_SYM_NO: 9551 case DT_MIPS_DELTA_CLASSSYM_NO: 9552 case DT_MIPS_COMPACT_SIZE: 9553 print_vma (entry->d_un.d_val, DEC); 9554 break; 9555 9556 case DT_MIPS_XHASH: 9557 dynamic_info_DT_MIPS_XHASH = entry->d_un.d_val; 9558 dynamic_info_DT_GNU_HASH = entry->d_un.d_val; 9559 /* Falls through. */ 9560 9561 default: 9562 print_vma (entry->d_un.d_ptr, PREFIX_HEX); 9563 } 9564 putchar ('\n'); 9565 } 9566 9567 static void 9568 dynamic_section_parisc_val (Elf_Internal_Dyn * entry) 9569 { 9570 switch (entry->d_tag) 9571 { 9572 case DT_HP_DLD_FLAGS: 9573 { 9574 static struct 9575 { 9576 long int bit; 9577 const char * str; 9578 } 9579 flags[] = 9580 { 9581 { DT_HP_DEBUG_PRIVATE, "HP_DEBUG_PRIVATE" }, 9582 { DT_HP_DEBUG_CALLBACK, "HP_DEBUG_CALLBACK" }, 9583 { DT_HP_DEBUG_CALLBACK_BOR, "HP_DEBUG_CALLBACK_BOR" }, 9584 { DT_HP_NO_ENVVAR, "HP_NO_ENVVAR" }, 9585 { DT_HP_BIND_NOW, "HP_BIND_NOW" }, 9586 { DT_HP_BIND_NONFATAL, "HP_BIND_NONFATAL" }, 9587 { DT_HP_BIND_VERBOSE, "HP_BIND_VERBOSE" }, 9588 { DT_HP_BIND_RESTRICTED, "HP_BIND_RESTRICTED" }, 9589 { DT_HP_BIND_SYMBOLIC, "HP_BIND_SYMBOLIC" }, 9590 { DT_HP_RPATH_FIRST, "HP_RPATH_FIRST" }, 9591 { DT_HP_BIND_DEPTH_FIRST, "HP_BIND_DEPTH_FIRST" }, 9592 { DT_HP_GST, "HP_GST" }, 9593 { DT_HP_SHLIB_FIXED, "HP_SHLIB_FIXED" }, 9594 { DT_HP_MERGE_SHLIB_SEG, "HP_MERGE_SHLIB_SEG" }, 9595 { DT_HP_NODELETE, "HP_NODELETE" }, 9596 { DT_HP_GROUP, "HP_GROUP" }, 9597 { DT_HP_PROTECT_LINKAGE_TABLE, "HP_PROTECT_LINKAGE_TABLE" } 9598 }; 9599 bfd_boolean first = TRUE; 9600 size_t cnt; 9601 bfd_vma val = entry->d_un.d_val; 9602 9603 for (cnt = 0; cnt < ARRAY_SIZE (flags); ++cnt) 9604 if (val & flags[cnt].bit) 9605 { 9606 if (! first) 9607 putchar (' '); 9608 fputs (flags[cnt].str, stdout); 9609 first = FALSE; 9610 val ^= flags[cnt].bit; 9611 } 9612 9613 if (val != 0 || first) 9614 { 9615 if (! first) 9616 putchar (' '); 9617 print_vma (val, HEX); 9618 } 9619 } 9620 break; 9621 9622 default: 9623 print_vma (entry->d_un.d_ptr, PREFIX_HEX); 9624 break; 9625 } 9626 putchar ('\n'); 9627 } 9628 9629 #ifdef BFD64 9630 9631 /* VMS vs Unix time offset and factor. */ 9632 9633 #define VMS_EPOCH_OFFSET 35067168000000000LL 9634 #define VMS_GRANULARITY_FACTOR 10000000 9635 9636 /* Display a VMS time in a human readable format. */ 9637 9638 static void 9639 print_vms_time (bfd_int64_t vmstime) 9640 { 9641 struct tm *tm; 9642 time_t unxtime; 9643 9644 unxtime = (vmstime - VMS_EPOCH_OFFSET) / VMS_GRANULARITY_FACTOR; 9645 tm = gmtime (&unxtime); 9646 printf ("%04u-%02u-%02uT%02u:%02u:%02u", 9647 tm->tm_year + 1900, tm->tm_mon + 1, tm->tm_mday, 9648 tm->tm_hour, tm->tm_min, tm->tm_sec); 9649 } 9650 #endif /* BFD64 */ 9651 9652 static void 9653 dynamic_section_ia64_val (Elf_Internal_Dyn * entry) 9654 { 9655 switch (entry->d_tag) 9656 { 9657 case DT_IA_64_PLT_RESERVE: 9658 /* First 3 slots reserved. */ 9659 print_vma (entry->d_un.d_ptr, PREFIX_HEX); 9660 printf (" -- "); 9661 print_vma (entry->d_un.d_ptr + (3 * 8), PREFIX_HEX); 9662 break; 9663 9664 case DT_IA_64_VMS_LINKTIME: 9665 #ifdef BFD64 9666 print_vms_time (entry->d_un.d_val); 9667 #endif 9668 break; 9669 9670 case DT_IA_64_VMS_LNKFLAGS: 9671 print_vma (entry->d_un.d_ptr, PREFIX_HEX); 9672 if (entry->d_un.d_val & VMS_LF_CALL_DEBUG) 9673 printf (" CALL_DEBUG"); 9674 if (entry->d_un.d_val & VMS_LF_NOP0BUFS) 9675 printf (" NOP0BUFS"); 9676 if (entry->d_un.d_val & VMS_LF_P0IMAGE) 9677 printf (" P0IMAGE"); 9678 if (entry->d_un.d_val & VMS_LF_MKTHREADS) 9679 printf (" MKTHREADS"); 9680 if (entry->d_un.d_val & VMS_LF_UPCALLS) 9681 printf (" UPCALLS"); 9682 if (entry->d_un.d_val & VMS_LF_IMGSTA) 9683 printf (" IMGSTA"); 9684 if (entry->d_un.d_val & VMS_LF_INITIALIZE) 9685 printf (" INITIALIZE"); 9686 if (entry->d_un.d_val & VMS_LF_MAIN) 9687 printf (" MAIN"); 9688 if (entry->d_un.d_val & VMS_LF_EXE_INIT) 9689 printf (" EXE_INIT"); 9690 if (entry->d_un.d_val & VMS_LF_TBK_IN_IMG) 9691 printf (" TBK_IN_IMG"); 9692 if (entry->d_un.d_val & VMS_LF_DBG_IN_IMG) 9693 printf (" DBG_IN_IMG"); 9694 if (entry->d_un.d_val & VMS_LF_TBK_IN_DSF) 9695 printf (" TBK_IN_DSF"); 9696 if (entry->d_un.d_val & VMS_LF_DBG_IN_DSF) 9697 printf (" DBG_IN_DSF"); 9698 if (entry->d_un.d_val & VMS_LF_SIGNATURES) 9699 printf (" SIGNATURES"); 9700 if (entry->d_un.d_val & VMS_LF_REL_SEG_OFF) 9701 printf (" REL_SEG_OFF"); 9702 break; 9703 9704 default: 9705 print_vma (entry->d_un.d_ptr, PREFIX_HEX); 9706 break; 9707 } 9708 putchar ('\n'); 9709 } 9710 9711 static bfd_boolean 9712 get_32bit_dynamic_section (Filedata * filedata) 9713 { 9714 Elf32_External_Dyn * edyn; 9715 Elf32_External_Dyn * ext; 9716 Elf_Internal_Dyn * entry; 9717 9718 edyn = (Elf32_External_Dyn *) get_data (NULL, filedata, dynamic_addr, 1, 9719 dynamic_size, _("dynamic section")); 9720 if (!edyn) 9721 return FALSE; 9722 9723 /* SGI's ELF has more than one section in the DYNAMIC segment, and we 9724 might not have the luxury of section headers. Look for the DT_NULL 9725 terminator to determine the number of entries. */ 9726 for (ext = edyn, dynamic_nent = 0; 9727 (char *) (ext + 1) <= (char *) edyn + dynamic_size; 9728 ext++) 9729 { 9730 dynamic_nent++; 9731 if (BYTE_GET (ext->d_tag) == DT_NULL) 9732 break; 9733 } 9734 9735 dynamic_section = (Elf_Internal_Dyn *) cmalloc (dynamic_nent, 9736 sizeof (* entry)); 9737 if (dynamic_section == NULL) 9738 { 9739 error (_("Out of memory allocating space for %lu dynamic entries\n"), 9740 (unsigned long) dynamic_nent); 9741 free (edyn); 9742 return FALSE; 9743 } 9744 9745 for (ext = edyn, entry = dynamic_section; 9746 entry < dynamic_section + dynamic_nent; 9747 ext++, entry++) 9748 { 9749 entry->d_tag = BYTE_GET (ext->d_tag); 9750 entry->d_un.d_val = BYTE_GET (ext->d_un.d_val); 9751 } 9752 9753 free (edyn); 9754 9755 return TRUE; 9756 } 9757 9758 static bfd_boolean 9759 get_64bit_dynamic_section (Filedata * filedata) 9760 { 9761 Elf64_External_Dyn * edyn; 9762 Elf64_External_Dyn * ext; 9763 Elf_Internal_Dyn * entry; 9764 9765 /* Read in the data. */ 9766 edyn = (Elf64_External_Dyn *) get_data (NULL, filedata, dynamic_addr, 1, 9767 dynamic_size, _("dynamic section")); 9768 if (!edyn) 9769 return FALSE; 9770 9771 /* SGI's ELF has more than one section in the DYNAMIC segment, and we 9772 might not have the luxury of section headers. Look for the DT_NULL 9773 terminator to determine the number of entries. */ 9774 for (ext = edyn, dynamic_nent = 0; 9775 /* PR 17533 file: 033-67080-0.004 - do not read past end of buffer. */ 9776 (char *) (ext + 1) <= (char *) edyn + dynamic_size; 9777 ext++) 9778 { 9779 dynamic_nent++; 9780 if (BYTE_GET (ext->d_tag) == DT_NULL) 9781 break; 9782 } 9783 9784 dynamic_section = (Elf_Internal_Dyn *) cmalloc (dynamic_nent, 9785 sizeof (* entry)); 9786 if (dynamic_section == NULL) 9787 { 9788 error (_("Out of memory allocating space for %lu dynamic entries\n"), 9789 (unsigned long) dynamic_nent); 9790 free (edyn); 9791 return FALSE; 9792 } 9793 9794 /* Convert from external to internal formats. */ 9795 for (ext = edyn, entry = dynamic_section; 9796 entry < dynamic_section + dynamic_nent; 9797 ext++, entry++) 9798 { 9799 entry->d_tag = BYTE_GET (ext->d_tag); 9800 entry->d_un.d_val = BYTE_GET (ext->d_un.d_val); 9801 } 9802 9803 free (edyn); 9804 9805 return TRUE; 9806 } 9807 9808 static void 9809 print_dynamic_flags (bfd_vma flags) 9810 { 9811 bfd_boolean first = TRUE; 9812 9813 while (flags) 9814 { 9815 bfd_vma flag; 9816 9817 flag = flags & - flags; 9818 flags &= ~ flag; 9819 9820 if (first) 9821 first = FALSE; 9822 else 9823 putc (' ', stdout); 9824 9825 switch (flag) 9826 { 9827 case DF_ORIGIN: fputs ("ORIGIN", stdout); break; 9828 case DF_SYMBOLIC: fputs ("SYMBOLIC", stdout); break; 9829 case DF_TEXTREL: fputs ("TEXTREL", stdout); break; 9830 case DF_BIND_NOW: fputs ("BIND_NOW", stdout); break; 9831 case DF_STATIC_TLS: fputs ("STATIC_TLS", stdout); break; 9832 default: fputs (_("unknown"), stdout); break; 9833 } 9834 } 9835 puts (""); 9836 } 9837 9838 /* Parse and display the contents of the dynamic section. */ 9839 9840 static bfd_boolean 9841 process_dynamic_section (Filedata * filedata) 9842 { 9843 Elf_Internal_Dyn * entry; 9844 9845 if (dynamic_size == 0) 9846 { 9847 if (do_dynamic) 9848 printf (_("\nThere is no dynamic section in this file.\n")); 9849 9850 return TRUE; 9851 } 9852 9853 if (is_32bit_elf) 9854 { 9855 if (! get_32bit_dynamic_section (filedata)) 9856 return FALSE; 9857 } 9858 else 9859 { 9860 if (! get_64bit_dynamic_section (filedata)) 9861 return FALSE; 9862 } 9863 9864 /* Find the appropriate symbol table. */ 9865 if (dynamic_symbols == NULL) 9866 { 9867 for (entry = dynamic_section; 9868 entry < dynamic_section + dynamic_nent; 9869 ++entry) 9870 { 9871 Elf_Internal_Shdr section; 9872 9873 if (entry->d_tag != DT_SYMTAB) 9874 continue; 9875 9876 dynamic_info[DT_SYMTAB] = entry->d_un.d_val; 9877 9878 /* Since we do not know how big the symbol table is, 9879 we default to reading in the entire file (!) and 9880 processing that. This is overkill, I know, but it 9881 should work. */ 9882 section.sh_offset = offset_from_vma (filedata, entry->d_un.d_val, 0); 9883 if ((bfd_size_type) section.sh_offset > filedata->file_size) 9884 { 9885 /* See PR 21379 for a reproducer. */ 9886 error (_("Invalid DT_SYMTAB entry: %lx"), (long) section.sh_offset); 9887 return FALSE; 9888 } 9889 9890 if (archive_file_offset != 0) 9891 section.sh_size = archive_file_size - section.sh_offset; 9892 else 9893 section.sh_size = filedata->file_size - section.sh_offset; 9894 9895 if (is_32bit_elf) 9896 section.sh_entsize = sizeof (Elf32_External_Sym); 9897 else 9898 section.sh_entsize = sizeof (Elf64_External_Sym); 9899 section.sh_name = filedata->string_table_length; 9900 9901 if (dynamic_symbols != NULL) 9902 { 9903 error (_("Multiple dynamic symbol table sections found\n")); 9904 free (dynamic_symbols); 9905 } 9906 dynamic_symbols = GET_ELF_SYMBOLS (filedata, §ion, & num_dynamic_syms); 9907 if (num_dynamic_syms < 1) 9908 { 9909 error (_("Unable to determine the number of symbols to load\n")); 9910 continue; 9911 } 9912 } 9913 } 9914 9915 /* Similarly find a string table. */ 9916 if (dynamic_strings == NULL) 9917 { 9918 for (entry = dynamic_section; 9919 entry < dynamic_section + dynamic_nent; 9920 ++entry) 9921 { 9922 unsigned long offset; 9923 long str_tab_len; 9924 9925 if (entry->d_tag != DT_STRTAB) 9926 continue; 9927 9928 dynamic_info[DT_STRTAB] = entry->d_un.d_val; 9929 9930 /* Since we do not know how big the string table is, 9931 we default to reading in the entire file (!) and 9932 processing that. This is overkill, I know, but it 9933 should work. */ 9934 9935 offset = offset_from_vma (filedata, entry->d_un.d_val, 0); 9936 9937 if (archive_file_offset != 0) 9938 str_tab_len = archive_file_size - offset; 9939 else 9940 str_tab_len = filedata->file_size - offset; 9941 9942 if (str_tab_len < 1) 9943 { 9944 error 9945 (_("Unable to determine the length of the dynamic string table\n")); 9946 continue; 9947 } 9948 9949 if (dynamic_strings != NULL) 9950 { 9951 error (_("Multiple dynamic string tables found\n")); 9952 free (dynamic_strings); 9953 } 9954 9955 dynamic_strings = (char *) get_data (NULL, filedata, offset, 1, 9956 str_tab_len, 9957 _("dynamic string table")); 9958 dynamic_strings_length = dynamic_strings == NULL ? 0 : str_tab_len; 9959 } 9960 } 9961 9962 /* And find the syminfo section if available. */ 9963 if (dynamic_syminfo == NULL) 9964 { 9965 unsigned long syminsz = 0; 9966 9967 for (entry = dynamic_section; 9968 entry < dynamic_section + dynamic_nent; 9969 ++entry) 9970 { 9971 if (entry->d_tag == DT_SYMINENT) 9972 { 9973 /* Note: these braces are necessary to avoid a syntax 9974 error from the SunOS4 C compiler. */ 9975 /* PR binutils/17531: A corrupt file can trigger this test. 9976 So do not use an assert, instead generate an error message. */ 9977 if (sizeof (Elf_External_Syminfo) != entry->d_un.d_val) 9978 error (_("Bad value (%d) for SYMINENT entry\n"), 9979 (int) entry->d_un.d_val); 9980 } 9981 else if (entry->d_tag == DT_SYMINSZ) 9982 syminsz = entry->d_un.d_val; 9983 else if (entry->d_tag == DT_SYMINFO) 9984 dynamic_syminfo_offset = offset_from_vma (filedata, entry->d_un.d_val, 9985 syminsz); 9986 } 9987 9988 if (dynamic_syminfo_offset != 0 && syminsz != 0) 9989 { 9990 Elf_External_Syminfo * extsyminfo; 9991 Elf_External_Syminfo * extsym; 9992 Elf_Internal_Syminfo * syminfo; 9993 9994 /* There is a syminfo section. Read the data. */ 9995 extsyminfo = (Elf_External_Syminfo *) 9996 get_data (NULL, filedata, dynamic_syminfo_offset, 1, syminsz, 9997 _("symbol information")); 9998 if (!extsyminfo) 9999 return FALSE; 10000 10001 if (dynamic_syminfo != NULL) 10002 { 10003 error (_("Multiple dynamic symbol information sections found\n")); 10004 free (dynamic_syminfo); 10005 } 10006 dynamic_syminfo = (Elf_Internal_Syminfo *) malloc (syminsz); 10007 if (dynamic_syminfo == NULL) 10008 { 10009 error (_("Out of memory allocating %lu byte for dynamic symbol info\n"), 10010 (unsigned long) syminsz); 10011 return FALSE; 10012 } 10013 10014 dynamic_syminfo_nent = syminsz / sizeof (Elf_External_Syminfo); 10015 for (syminfo = dynamic_syminfo, extsym = extsyminfo; 10016 syminfo < dynamic_syminfo + dynamic_syminfo_nent; 10017 ++syminfo, ++extsym) 10018 { 10019 syminfo->si_boundto = BYTE_GET (extsym->si_boundto); 10020 syminfo->si_flags = BYTE_GET (extsym->si_flags); 10021 } 10022 10023 free (extsyminfo); 10024 } 10025 } 10026 10027 if (do_dynamic && dynamic_addr) 10028 printf (ngettext ("\nDynamic section at offset 0x%lx " 10029 "contains %lu entry:\n", 10030 "\nDynamic section at offset 0x%lx " 10031 "contains %lu entries:\n", 10032 dynamic_nent), 10033 dynamic_addr, (unsigned long) dynamic_nent); 10034 if (do_dynamic) 10035 printf (_(" Tag Type Name/Value\n")); 10036 10037 for (entry = dynamic_section; 10038 entry < dynamic_section + dynamic_nent; 10039 entry++) 10040 { 10041 if (do_dynamic) 10042 { 10043 const char * dtype; 10044 10045 putchar (' '); 10046 print_vma (entry->d_tag, FULL_HEX); 10047 dtype = get_dynamic_type (filedata, entry->d_tag); 10048 printf (" (%s)%*s", dtype, 10049 ((is_32bit_elf ? 27 : 19) - (int) strlen (dtype)), " "); 10050 } 10051 10052 switch (entry->d_tag) 10053 { 10054 case DT_FLAGS: 10055 if (do_dynamic) 10056 print_dynamic_flags (entry->d_un.d_val); 10057 break; 10058 10059 case DT_AUXILIARY: 10060 case DT_FILTER: 10061 case DT_CONFIG: 10062 case DT_DEPAUDIT: 10063 case DT_AUDIT: 10064 if (do_dynamic) 10065 { 10066 switch (entry->d_tag) 10067 { 10068 case DT_AUXILIARY: 10069 printf (_("Auxiliary library")); 10070 break; 10071 10072 case DT_FILTER: 10073 printf (_("Filter library")); 10074 break; 10075 10076 case DT_CONFIG: 10077 printf (_("Configuration file")); 10078 break; 10079 10080 case DT_DEPAUDIT: 10081 printf (_("Dependency audit library")); 10082 break; 10083 10084 case DT_AUDIT: 10085 printf (_("Audit library")); 10086 break; 10087 } 10088 10089 if (VALID_DYNAMIC_NAME (entry->d_un.d_val)) 10090 printf (": [%s]\n", GET_DYNAMIC_NAME (entry->d_un.d_val)); 10091 else 10092 { 10093 printf (": "); 10094 print_vma (entry->d_un.d_val, PREFIX_HEX); 10095 putchar ('\n'); 10096 } 10097 } 10098 break; 10099 10100 case DT_FEATURE: 10101 if (do_dynamic) 10102 { 10103 printf (_("Flags:")); 10104 10105 if (entry->d_un.d_val == 0) 10106 printf (_(" None\n")); 10107 else 10108 { 10109 unsigned long int val = entry->d_un.d_val; 10110 10111 if (val & DTF_1_PARINIT) 10112 { 10113 printf (" PARINIT"); 10114 val ^= DTF_1_PARINIT; 10115 } 10116 if (val & DTF_1_CONFEXP) 10117 { 10118 printf (" CONFEXP"); 10119 val ^= DTF_1_CONFEXP; 10120 } 10121 if (val != 0) 10122 printf (" %lx", val); 10123 puts (""); 10124 } 10125 } 10126 break; 10127 10128 case DT_POSFLAG_1: 10129 if (do_dynamic) 10130 { 10131 printf (_("Flags:")); 10132 10133 if (entry->d_un.d_val == 0) 10134 printf (_(" None\n")); 10135 else 10136 { 10137 unsigned long int val = entry->d_un.d_val; 10138 10139 if (val & DF_P1_LAZYLOAD) 10140 { 10141 printf (" LAZYLOAD"); 10142 val ^= DF_P1_LAZYLOAD; 10143 } 10144 if (val & DF_P1_GROUPPERM) 10145 { 10146 printf (" GROUPPERM"); 10147 val ^= DF_P1_GROUPPERM; 10148 } 10149 if (val != 0) 10150 printf (" %lx", val); 10151 puts (""); 10152 } 10153 } 10154 break; 10155 10156 case DT_FLAGS_1: 10157 if (do_dynamic) 10158 { 10159 printf (_("Flags:")); 10160 if (entry->d_un.d_val == 0) 10161 printf (_(" None\n")); 10162 else 10163 { 10164 unsigned long int val = entry->d_un.d_val; 10165 10166 if (val & DF_1_NOW) 10167 { 10168 printf (" NOW"); 10169 val ^= DF_1_NOW; 10170 } 10171 if (val & DF_1_GLOBAL) 10172 { 10173 printf (" GLOBAL"); 10174 val ^= DF_1_GLOBAL; 10175 } 10176 if (val & DF_1_GROUP) 10177 { 10178 printf (" GROUP"); 10179 val ^= DF_1_GROUP; 10180 } 10181 if (val & DF_1_NODELETE) 10182 { 10183 printf (" NODELETE"); 10184 val ^= DF_1_NODELETE; 10185 } 10186 if (val & DF_1_LOADFLTR) 10187 { 10188 printf (" LOADFLTR"); 10189 val ^= DF_1_LOADFLTR; 10190 } 10191 if (val & DF_1_INITFIRST) 10192 { 10193 printf (" INITFIRST"); 10194 val ^= DF_1_INITFIRST; 10195 } 10196 if (val & DF_1_NOOPEN) 10197 { 10198 printf (" NOOPEN"); 10199 val ^= DF_1_NOOPEN; 10200 } 10201 if (val & DF_1_ORIGIN) 10202 { 10203 printf (" ORIGIN"); 10204 val ^= DF_1_ORIGIN; 10205 } 10206 if (val & DF_1_DIRECT) 10207 { 10208 printf (" DIRECT"); 10209 val ^= DF_1_DIRECT; 10210 } 10211 if (val & DF_1_TRANS) 10212 { 10213 printf (" TRANS"); 10214 val ^= DF_1_TRANS; 10215 } 10216 if (val & DF_1_INTERPOSE) 10217 { 10218 printf (" INTERPOSE"); 10219 val ^= DF_1_INTERPOSE; 10220 } 10221 if (val & DF_1_NODEFLIB) 10222 { 10223 printf (" NODEFLIB"); 10224 val ^= DF_1_NODEFLIB; 10225 } 10226 if (val & DF_1_NODUMP) 10227 { 10228 printf (" NODUMP"); 10229 val ^= DF_1_NODUMP; 10230 } 10231 if (val & DF_1_CONFALT) 10232 { 10233 printf (" CONFALT"); 10234 val ^= DF_1_CONFALT; 10235 } 10236 if (val & DF_1_ENDFILTEE) 10237 { 10238 printf (" ENDFILTEE"); 10239 val ^= DF_1_ENDFILTEE; 10240 } 10241 if (val & DF_1_DISPRELDNE) 10242 { 10243 printf (" DISPRELDNE"); 10244 val ^= DF_1_DISPRELDNE; 10245 } 10246 if (val & DF_1_DISPRELPND) 10247 { 10248 printf (" DISPRELPND"); 10249 val ^= DF_1_DISPRELPND; 10250 } 10251 if (val & DF_1_NODIRECT) 10252 { 10253 printf (" NODIRECT"); 10254 val ^= DF_1_NODIRECT; 10255 } 10256 if (val & DF_1_IGNMULDEF) 10257 { 10258 printf (" IGNMULDEF"); 10259 val ^= DF_1_IGNMULDEF; 10260 } 10261 if (val & DF_1_NOKSYMS) 10262 { 10263 printf (" NOKSYMS"); 10264 val ^= DF_1_NOKSYMS; 10265 } 10266 if (val & DF_1_NOHDR) 10267 { 10268 printf (" NOHDR"); 10269 val ^= DF_1_NOHDR; 10270 } 10271 if (val & DF_1_EDITED) 10272 { 10273 printf (" EDITED"); 10274 val ^= DF_1_EDITED; 10275 } 10276 if (val & DF_1_NORELOC) 10277 { 10278 printf (" NORELOC"); 10279 val ^= DF_1_NORELOC; 10280 } 10281 if (val & DF_1_SYMINTPOSE) 10282 { 10283 printf (" SYMINTPOSE"); 10284 val ^= DF_1_SYMINTPOSE; 10285 } 10286 if (val & DF_1_GLOBAUDIT) 10287 { 10288 printf (" GLOBAUDIT"); 10289 val ^= DF_1_GLOBAUDIT; 10290 } 10291 if (val & DF_1_SINGLETON) 10292 { 10293 printf (" SINGLETON"); 10294 val ^= DF_1_SINGLETON; 10295 } 10296 if (val & DF_1_STUB) 10297 { 10298 printf (" STUB"); 10299 val ^= DF_1_STUB; 10300 } 10301 if (val & DF_1_PIE) 10302 { 10303 printf (" PIE"); 10304 val ^= DF_1_PIE; 10305 } 10306 if (val & DF_1_KMOD) 10307 { 10308 printf (" KMOD"); 10309 val ^= DF_1_KMOD; 10310 } 10311 if (val & DF_1_WEAKFILTER) 10312 { 10313 printf (" WEAKFILTER"); 10314 val ^= DF_1_WEAKFILTER; 10315 } 10316 if (val & DF_1_NOCOMMON) 10317 { 10318 printf (" NOCOMMON"); 10319 val ^= DF_1_NOCOMMON; 10320 } 10321 if (val != 0) 10322 printf (" %lx", val); 10323 puts (""); 10324 } 10325 } 10326 break; 10327 10328 case DT_PLTREL: 10329 dynamic_info[entry->d_tag] = entry->d_un.d_val; 10330 if (do_dynamic) 10331 puts (get_dynamic_type (filedata, entry->d_un.d_val)); 10332 break; 10333 10334 case DT_NULL : 10335 case DT_NEEDED : 10336 case DT_PLTGOT : 10337 case DT_HASH : 10338 case DT_STRTAB : 10339 case DT_SYMTAB : 10340 case DT_RELA : 10341 case DT_INIT : 10342 case DT_FINI : 10343 case DT_SONAME : 10344 case DT_RPATH : 10345 case DT_SYMBOLIC: 10346 case DT_REL : 10347 case DT_DEBUG : 10348 case DT_TEXTREL : 10349 case DT_JMPREL : 10350 case DT_RUNPATH : 10351 dynamic_info[entry->d_tag] = entry->d_un.d_val; 10352 10353 if (do_dynamic) 10354 { 10355 char * name; 10356 10357 if (VALID_DYNAMIC_NAME (entry->d_un.d_val)) 10358 name = GET_DYNAMIC_NAME (entry->d_un.d_val); 10359 else 10360 name = NULL; 10361 10362 if (name) 10363 { 10364 switch (entry->d_tag) 10365 { 10366 case DT_NEEDED: 10367 printf (_("Shared library: [%s]"), name); 10368 10369 if (streq (name, program_interpreter)) 10370 printf (_(" program interpreter")); 10371 break; 10372 10373 case DT_SONAME: 10374 printf (_("Library soname: [%s]"), name); 10375 break; 10376 10377 case DT_RPATH: 10378 printf (_("Library rpath: [%s]"), name); 10379 break; 10380 10381 case DT_RUNPATH: 10382 printf (_("Library runpath: [%s]"), name); 10383 break; 10384 10385 default: 10386 print_vma (entry->d_un.d_val, PREFIX_HEX); 10387 break; 10388 } 10389 } 10390 else 10391 print_vma (entry->d_un.d_val, PREFIX_HEX); 10392 10393 putchar ('\n'); 10394 } 10395 break; 10396 10397 case DT_PLTRELSZ: 10398 case DT_RELASZ : 10399 case DT_STRSZ : 10400 case DT_RELSZ : 10401 case DT_RELAENT : 10402 case DT_SYMENT : 10403 case DT_RELENT : 10404 dynamic_info[entry->d_tag] = entry->d_un.d_val; 10405 /* Fall through. */ 10406 case DT_PLTPADSZ: 10407 case DT_MOVEENT : 10408 case DT_MOVESZ : 10409 case DT_INIT_ARRAYSZ: 10410 case DT_FINI_ARRAYSZ: 10411 case DT_GNU_CONFLICTSZ: 10412 case DT_GNU_LIBLISTSZ: 10413 if (do_dynamic) 10414 { 10415 print_vma (entry->d_un.d_val, UNSIGNED); 10416 printf (_(" (bytes)\n")); 10417 } 10418 break; 10419 10420 case DT_VERDEFNUM: 10421 case DT_VERNEEDNUM: 10422 case DT_RELACOUNT: 10423 case DT_RELCOUNT: 10424 if (do_dynamic) 10425 { 10426 print_vma (entry->d_un.d_val, UNSIGNED); 10427 putchar ('\n'); 10428 } 10429 break; 10430 10431 case DT_SYMINSZ: 10432 case DT_SYMINENT: 10433 case DT_SYMINFO: 10434 case DT_USED: 10435 case DT_INIT_ARRAY: 10436 case DT_FINI_ARRAY: 10437 if (do_dynamic) 10438 { 10439 if (entry->d_tag == DT_USED 10440 && VALID_DYNAMIC_NAME (entry->d_un.d_val)) 10441 { 10442 char * name = GET_DYNAMIC_NAME (entry->d_un.d_val); 10443 10444 if (*name) 10445 { 10446 printf (_("Not needed object: [%s]\n"), name); 10447 break; 10448 } 10449 } 10450 10451 print_vma (entry->d_un.d_val, PREFIX_HEX); 10452 putchar ('\n'); 10453 } 10454 break; 10455 10456 case DT_BIND_NOW: 10457 /* The value of this entry is ignored. */ 10458 if (do_dynamic) 10459 putchar ('\n'); 10460 break; 10461 10462 case DT_GNU_PRELINKED: 10463 if (do_dynamic) 10464 { 10465 struct tm * tmp; 10466 time_t atime = entry->d_un.d_val; 10467 10468 tmp = gmtime (&atime); 10469 /* PR 17533 file: 041-1244816-0.004. */ 10470 if (tmp == NULL) 10471 printf (_("<corrupt time val: %lx"), 10472 (unsigned long) atime); 10473 else 10474 printf ("%04u-%02u-%02uT%02u:%02u:%02u\n", 10475 tmp->tm_year + 1900, tmp->tm_mon + 1, tmp->tm_mday, 10476 tmp->tm_hour, tmp->tm_min, tmp->tm_sec); 10477 10478 } 10479 break; 10480 10481 case DT_GNU_HASH: 10482 dynamic_info_DT_GNU_HASH = entry->d_un.d_val; 10483 if (do_dynamic) 10484 { 10485 print_vma (entry->d_un.d_val, PREFIX_HEX); 10486 putchar ('\n'); 10487 } 10488 break; 10489 10490 default: 10491 if ((entry->d_tag >= DT_VERSYM) && (entry->d_tag <= DT_VERNEEDNUM)) 10492 version_info[DT_VERSIONTAGIDX (entry->d_tag)] = 10493 entry->d_un.d_val; 10494 10495 if (do_dynamic) 10496 { 10497 switch (filedata->file_header.e_machine) 10498 { 10499 case EM_AARCH64: 10500 dynamic_section_aarch64_val (entry); 10501 break; 10502 case EM_MIPS: 10503 case EM_MIPS_RS3_LE: 10504 dynamic_section_mips_val (entry); 10505 break; 10506 case EM_PARISC: 10507 dynamic_section_parisc_val (entry); 10508 break; 10509 case EM_IA_64: 10510 dynamic_section_ia64_val (entry); 10511 break; 10512 default: 10513 print_vma (entry->d_un.d_val, PREFIX_HEX); 10514 putchar ('\n'); 10515 } 10516 } 10517 break; 10518 } 10519 } 10520 10521 return TRUE; 10522 } 10523 10524 static char * 10525 get_ver_flags (unsigned int flags) 10526 { 10527 static char buff[128]; 10528 10529 buff[0] = 0; 10530 10531 if (flags == 0) 10532 return _("none"); 10533 10534 if (flags & VER_FLG_BASE) 10535 strcat (buff, "BASE"); 10536 10537 if (flags & VER_FLG_WEAK) 10538 { 10539 if (flags & VER_FLG_BASE) 10540 strcat (buff, " | "); 10541 10542 strcat (buff, "WEAK"); 10543 } 10544 10545 if (flags & VER_FLG_INFO) 10546 { 10547 if (flags & (VER_FLG_BASE|VER_FLG_WEAK)) 10548 strcat (buff, " | "); 10549 10550 strcat (buff, "INFO"); 10551 } 10552 10553 if (flags & ~(VER_FLG_BASE | VER_FLG_WEAK | VER_FLG_INFO)) 10554 { 10555 if (flags & (VER_FLG_BASE | VER_FLG_WEAK | VER_FLG_INFO)) 10556 strcat (buff, " | "); 10557 10558 strcat (buff, _("<unknown>")); 10559 } 10560 10561 return buff; 10562 } 10563 10564 /* Display the contents of the version sections. */ 10565 10566 static bfd_boolean 10567 process_version_sections (Filedata * filedata) 10568 { 10569 Elf_Internal_Shdr * section; 10570 unsigned i; 10571 bfd_boolean found = FALSE; 10572 10573 if (! do_version) 10574 return TRUE; 10575 10576 for (i = 0, section = filedata->section_headers; 10577 i < filedata->file_header.e_shnum; 10578 i++, section++) 10579 { 10580 switch (section->sh_type) 10581 { 10582 case SHT_GNU_verdef: 10583 { 10584 Elf_External_Verdef * edefs; 10585 unsigned long idx; 10586 unsigned long cnt; 10587 char * endbuf; 10588 10589 found = TRUE; 10590 10591 printf (ngettext ("\nVersion definition section '%s' " 10592 "contains %u entry:\n", 10593 "\nVersion definition section '%s' " 10594 "contains %u entries:\n", 10595 section->sh_info), 10596 printable_section_name (filedata, section), 10597 section->sh_info); 10598 10599 printf (_(" Addr: 0x")); 10600 printf_vma (section->sh_addr); 10601 printf (_(" Offset: %#08lx Link: %u (%s)\n"), 10602 (unsigned long) section->sh_offset, section->sh_link, 10603 printable_section_name_from_index (filedata, section->sh_link)); 10604 10605 edefs = (Elf_External_Verdef *) 10606 get_data (NULL, filedata, section->sh_offset, 1,section->sh_size, 10607 _("version definition section")); 10608 if (!edefs) 10609 break; 10610 endbuf = (char *) edefs + section->sh_size; 10611 10612 for (idx = cnt = 0; cnt < section->sh_info; ++cnt) 10613 { 10614 char * vstart; 10615 Elf_External_Verdef * edef; 10616 Elf_Internal_Verdef ent; 10617 Elf_External_Verdaux * eaux; 10618 Elf_Internal_Verdaux aux; 10619 unsigned long isum; 10620 int j; 10621 10622 vstart = ((char *) edefs) + idx; 10623 if (vstart + sizeof (*edef) > endbuf) 10624 break; 10625 10626 edef = (Elf_External_Verdef *) vstart; 10627 10628 ent.vd_version = BYTE_GET (edef->vd_version); 10629 ent.vd_flags = BYTE_GET (edef->vd_flags); 10630 ent.vd_ndx = BYTE_GET (edef->vd_ndx); 10631 ent.vd_cnt = BYTE_GET (edef->vd_cnt); 10632 ent.vd_hash = BYTE_GET (edef->vd_hash); 10633 ent.vd_aux = BYTE_GET (edef->vd_aux); 10634 ent.vd_next = BYTE_GET (edef->vd_next); 10635 10636 printf (_(" %#06lx: Rev: %d Flags: %s"), 10637 idx, ent.vd_version, get_ver_flags (ent.vd_flags)); 10638 10639 printf (_(" Index: %d Cnt: %d "), 10640 ent.vd_ndx, ent.vd_cnt); 10641 10642 /* Check for overflow. */ 10643 if (ent.vd_aux > (size_t) (endbuf - vstart)) 10644 break; 10645 10646 vstart += ent.vd_aux; 10647 10648 if (vstart + sizeof (*eaux) > endbuf) 10649 break; 10650 eaux = (Elf_External_Verdaux *) vstart; 10651 10652 aux.vda_name = BYTE_GET (eaux->vda_name); 10653 aux.vda_next = BYTE_GET (eaux->vda_next); 10654 10655 if (VALID_DYNAMIC_NAME (aux.vda_name)) 10656 printf (_("Name: %s\n"), GET_DYNAMIC_NAME (aux.vda_name)); 10657 else 10658 printf (_("Name index: %ld\n"), aux.vda_name); 10659 10660 isum = idx + ent.vd_aux; 10661 10662 for (j = 1; j < ent.vd_cnt; j++) 10663 { 10664 if (aux.vda_next < sizeof (*eaux) 10665 && !(j == ent.vd_cnt - 1 && aux.vda_next == 0)) 10666 { 10667 warn (_("Invalid vda_next field of %lx\n"), 10668 aux.vda_next); 10669 j = ent.vd_cnt; 10670 break; 10671 } 10672 /* Check for overflow. */ 10673 if (aux.vda_next > (size_t) (endbuf - vstart)) 10674 break; 10675 10676 isum += aux.vda_next; 10677 vstart += aux.vda_next; 10678 10679 if (vstart + sizeof (*eaux) > endbuf) 10680 break; 10681 eaux = (Elf_External_Verdaux *) vstart; 10682 10683 aux.vda_name = BYTE_GET (eaux->vda_name); 10684 aux.vda_next = BYTE_GET (eaux->vda_next); 10685 10686 if (VALID_DYNAMIC_NAME (aux.vda_name)) 10687 printf (_(" %#06lx: Parent %d: %s\n"), 10688 isum, j, GET_DYNAMIC_NAME (aux.vda_name)); 10689 else 10690 printf (_(" %#06lx: Parent %d, name index: %ld\n"), 10691 isum, j, aux.vda_name); 10692 } 10693 10694 if (j < ent.vd_cnt) 10695 printf (_(" Version def aux past end of section\n")); 10696 10697 /* PR 17531: 10698 file: id:000001,src:000172+005151,op:splice,rep:2. */ 10699 if (ent.vd_next < sizeof (*edef) 10700 && !(cnt == section->sh_info - 1 && ent.vd_next == 0)) 10701 { 10702 warn (_("Invalid vd_next field of %lx\n"), ent.vd_next); 10703 cnt = section->sh_info; 10704 break; 10705 } 10706 if (ent.vd_next > (size_t) (endbuf - ((char *) edefs + idx))) 10707 break; 10708 10709 idx += ent.vd_next; 10710 } 10711 10712 if (cnt < section->sh_info) 10713 printf (_(" Version definition past end of section\n")); 10714 10715 free (edefs); 10716 } 10717 break; 10718 10719 case SHT_GNU_verneed: 10720 { 10721 Elf_External_Verneed * eneed; 10722 unsigned long idx; 10723 unsigned long cnt; 10724 char * endbuf; 10725 10726 found = TRUE; 10727 10728 printf (ngettext ("\nVersion needs section '%s' " 10729 "contains %u entry:\n", 10730 "\nVersion needs section '%s' " 10731 "contains %u entries:\n", 10732 section->sh_info), 10733 printable_section_name (filedata, section), section->sh_info); 10734 10735 printf (_(" Addr: 0x")); 10736 printf_vma (section->sh_addr); 10737 printf (_(" Offset: %#08lx Link: %u (%s)\n"), 10738 (unsigned long) section->sh_offset, section->sh_link, 10739 printable_section_name_from_index (filedata, section->sh_link)); 10740 10741 eneed = (Elf_External_Verneed *) get_data (NULL, filedata, 10742 section->sh_offset, 1, 10743 section->sh_size, 10744 _("Version Needs section")); 10745 if (!eneed) 10746 break; 10747 endbuf = (char *) eneed + section->sh_size; 10748 10749 for (idx = cnt = 0; cnt < section->sh_info; ++cnt) 10750 { 10751 Elf_External_Verneed * entry; 10752 Elf_Internal_Verneed ent; 10753 unsigned long isum; 10754 int j; 10755 char * vstart; 10756 10757 vstart = ((char *) eneed) + idx; 10758 if (vstart + sizeof (*entry) > endbuf) 10759 break; 10760 10761 entry = (Elf_External_Verneed *) vstart; 10762 10763 ent.vn_version = BYTE_GET (entry->vn_version); 10764 ent.vn_cnt = BYTE_GET (entry->vn_cnt); 10765 ent.vn_file = BYTE_GET (entry->vn_file); 10766 ent.vn_aux = BYTE_GET (entry->vn_aux); 10767 ent.vn_next = BYTE_GET (entry->vn_next); 10768 10769 printf (_(" %#06lx: Version: %d"), idx, ent.vn_version); 10770 10771 if (VALID_DYNAMIC_NAME (ent.vn_file)) 10772 printf (_(" File: %s"), GET_DYNAMIC_NAME (ent.vn_file)); 10773 else 10774 printf (_(" File: %lx"), ent.vn_file); 10775 10776 printf (_(" Cnt: %d\n"), ent.vn_cnt); 10777 10778 /* Check for overflow. */ 10779 if (ent.vn_aux > (size_t) (endbuf - vstart)) 10780 break; 10781 vstart += ent.vn_aux; 10782 10783 for (j = 0, isum = idx + ent.vn_aux; j < ent.vn_cnt; ++j) 10784 { 10785 Elf_External_Vernaux * eaux; 10786 Elf_Internal_Vernaux aux; 10787 10788 if (vstart + sizeof (*eaux) > endbuf) 10789 break; 10790 eaux = (Elf_External_Vernaux *) vstart; 10791 10792 aux.vna_hash = BYTE_GET (eaux->vna_hash); 10793 aux.vna_flags = BYTE_GET (eaux->vna_flags); 10794 aux.vna_other = BYTE_GET (eaux->vna_other); 10795 aux.vna_name = BYTE_GET (eaux->vna_name); 10796 aux.vna_next = BYTE_GET (eaux->vna_next); 10797 10798 if (VALID_DYNAMIC_NAME (aux.vna_name)) 10799 printf (_(" %#06lx: Name: %s"), 10800 isum, GET_DYNAMIC_NAME (aux.vna_name)); 10801 else 10802 printf (_(" %#06lx: Name index: %lx"), 10803 isum, aux.vna_name); 10804 10805 printf (_(" Flags: %s Version: %d\n"), 10806 get_ver_flags (aux.vna_flags), aux.vna_other); 10807 10808 if (aux.vna_next < sizeof (*eaux) 10809 && !(j == ent.vn_cnt - 1 && aux.vna_next == 0)) 10810 { 10811 warn (_("Invalid vna_next field of %lx\n"), 10812 aux.vna_next); 10813 j = ent.vn_cnt; 10814 break; 10815 } 10816 /* Check for overflow. */ 10817 if (aux.vna_next > (size_t) (endbuf - vstart)) 10818 break; 10819 isum += aux.vna_next; 10820 vstart += aux.vna_next; 10821 } 10822 10823 if (j < ent.vn_cnt) 10824 warn (_("Missing Version Needs auxillary information\n")); 10825 10826 if (ent.vn_next < sizeof (*entry) 10827 && !(cnt == section->sh_info - 1 && ent.vn_next == 0)) 10828 { 10829 warn (_("Invalid vn_next field of %lx\n"), ent.vn_next); 10830 cnt = section->sh_info; 10831 break; 10832 } 10833 if (ent.vn_next > (size_t) (endbuf - ((char *) eneed + idx))) 10834 break; 10835 idx += ent.vn_next; 10836 } 10837 10838 if (cnt < section->sh_info) 10839 warn (_("Missing Version Needs information\n")); 10840 10841 free (eneed); 10842 } 10843 break; 10844 10845 case SHT_GNU_versym: 10846 { 10847 Elf_Internal_Shdr * link_section; 10848 size_t total; 10849 unsigned int cnt; 10850 unsigned char * edata; 10851 unsigned short * data; 10852 char * strtab; 10853 Elf_Internal_Sym * symbols; 10854 Elf_Internal_Shdr * string_sec; 10855 unsigned long num_syms; 10856 long off; 10857 10858 if (section->sh_link >= filedata->file_header.e_shnum) 10859 break; 10860 10861 link_section = filedata->section_headers + section->sh_link; 10862 total = section->sh_size / sizeof (Elf_External_Versym); 10863 10864 if (link_section->sh_link >= filedata->file_header.e_shnum) 10865 break; 10866 10867 found = TRUE; 10868 10869 symbols = GET_ELF_SYMBOLS (filedata, link_section, & num_syms); 10870 if (symbols == NULL) 10871 break; 10872 10873 string_sec = filedata->section_headers + link_section->sh_link; 10874 10875 strtab = (char *) get_data (NULL, filedata, string_sec->sh_offset, 1, 10876 string_sec->sh_size, 10877 _("version string table")); 10878 if (!strtab) 10879 { 10880 free (symbols); 10881 break; 10882 } 10883 10884 printf (ngettext ("\nVersion symbols section '%s' " 10885 "contains %lu entry:\n", 10886 "\nVersion symbols section '%s' " 10887 "contains %lu entries:\n", 10888 total), 10889 printable_section_name (filedata, section), (unsigned long) total); 10890 10891 printf (_(" Addr: 0x")); 10892 printf_vma (section->sh_addr); 10893 printf (_(" Offset: %#08lx Link: %u (%s)\n"), 10894 (unsigned long) section->sh_offset, section->sh_link, 10895 printable_section_name (filedata, link_section)); 10896 10897 off = offset_from_vma (filedata, 10898 version_info[DT_VERSIONTAGIDX (DT_VERSYM)], 10899 total * sizeof (short)); 10900 edata = (unsigned char *) get_data (NULL, filedata, off, total, 10901 sizeof (short), 10902 _("version symbol data")); 10903 if (!edata) 10904 { 10905 free (strtab); 10906 free (symbols); 10907 break; 10908 } 10909 10910 data = (short unsigned int *) cmalloc (total, sizeof (short)); 10911 10912 for (cnt = total; cnt --;) 10913 data[cnt] = byte_get (edata + cnt * sizeof (short), 10914 sizeof (short)); 10915 10916 free (edata); 10917 10918 for (cnt = 0; cnt < total; cnt += 4) 10919 { 10920 int j, nn; 10921 char *name; 10922 char *invalid = _("*invalid*"); 10923 10924 printf (" %03x:", cnt); 10925 10926 for (j = 0; (j < 4) && (cnt + j) < total; ++j) 10927 switch (data[cnt + j]) 10928 { 10929 case 0: 10930 fputs (_(" 0 (*local*) "), stdout); 10931 break; 10932 10933 case 1: 10934 fputs (_(" 1 (*global*) "), stdout); 10935 break; 10936 10937 default: 10938 nn = printf ("%4x%c", data[cnt + j] & VERSYM_VERSION, 10939 data[cnt + j] & VERSYM_HIDDEN ? 'h' : ' '); 10940 10941 /* If this index value is greater than the size of the symbols 10942 array, break to avoid an out-of-bounds read. */ 10943 if ((unsigned long)(cnt + j) >= num_syms) 10944 { 10945 warn (_("invalid index into symbol array\n")); 10946 break; 10947 } 10948 10949 name = NULL; 10950 if (version_info[DT_VERSIONTAGIDX (DT_VERNEED)]) 10951 { 10952 Elf_Internal_Verneed ivn; 10953 unsigned long offset; 10954 10955 offset = offset_from_vma 10956 (filedata, version_info[DT_VERSIONTAGIDX (DT_VERNEED)], 10957 sizeof (Elf_External_Verneed)); 10958 10959 do 10960 { 10961 Elf_Internal_Vernaux ivna; 10962 Elf_External_Verneed evn; 10963 Elf_External_Vernaux evna; 10964 unsigned long a_off; 10965 10966 if (get_data (&evn, filedata, offset, sizeof (evn), 1, 10967 _("version need")) == NULL) 10968 break; 10969 10970 ivn.vn_aux = BYTE_GET (evn.vn_aux); 10971 ivn.vn_next = BYTE_GET (evn.vn_next); 10972 10973 a_off = offset + ivn.vn_aux; 10974 10975 do 10976 { 10977 if (get_data (&evna, filedata, a_off, sizeof (evna), 10978 1, _("version need aux (2)")) == NULL) 10979 { 10980 ivna.vna_next = 0; 10981 ivna.vna_other = 0; 10982 } 10983 else 10984 { 10985 ivna.vna_next = BYTE_GET (evna.vna_next); 10986 ivna.vna_other = BYTE_GET (evna.vna_other); 10987 } 10988 10989 a_off += ivna.vna_next; 10990 } 10991 while (ivna.vna_other != data[cnt + j] 10992 && ivna.vna_next != 0); 10993 10994 if (ivna.vna_other == data[cnt + j]) 10995 { 10996 ivna.vna_name = BYTE_GET (evna.vna_name); 10997 10998 if (ivna.vna_name >= string_sec->sh_size) 10999 name = invalid; 11000 else 11001 name = strtab + ivna.vna_name; 11002 break; 11003 } 11004 11005 offset += ivn.vn_next; 11006 } 11007 while (ivn.vn_next); 11008 } 11009 11010 if (data[cnt + j] != 0x8001 11011 && version_info[DT_VERSIONTAGIDX (DT_VERDEF)]) 11012 { 11013 Elf_Internal_Verdef ivd; 11014 Elf_External_Verdef evd; 11015 unsigned long offset; 11016 11017 offset = offset_from_vma 11018 (filedata, version_info[DT_VERSIONTAGIDX (DT_VERDEF)], 11019 sizeof evd); 11020 11021 do 11022 { 11023 if (get_data (&evd, filedata, offset, sizeof (evd), 1, 11024 _("version def")) == NULL) 11025 { 11026 ivd.vd_next = 0; 11027 /* PR 17531: file: 046-1082287-0.004. */ 11028 ivd.vd_ndx = (data[cnt + j] & VERSYM_VERSION) + 1; 11029 break; 11030 } 11031 else 11032 { 11033 ivd.vd_next = BYTE_GET (evd.vd_next); 11034 ivd.vd_ndx = BYTE_GET (evd.vd_ndx); 11035 } 11036 11037 offset += ivd.vd_next; 11038 } 11039 while (ivd.vd_ndx != (data[cnt + j] & VERSYM_VERSION) 11040 && ivd.vd_next != 0); 11041 11042 if (ivd.vd_ndx == (data[cnt + j] & VERSYM_VERSION)) 11043 { 11044 Elf_External_Verdaux evda; 11045 Elf_Internal_Verdaux ivda; 11046 11047 ivd.vd_aux = BYTE_GET (evd.vd_aux); 11048 11049 if (get_data (&evda, filedata, 11050 offset - ivd.vd_next + ivd.vd_aux, 11051 sizeof (evda), 1, 11052 _("version def aux")) == NULL) 11053 break; 11054 11055 ivda.vda_name = BYTE_GET (evda.vda_name); 11056 11057 if (ivda.vda_name >= string_sec->sh_size) 11058 name = invalid; 11059 else if (name != NULL && name != invalid) 11060 name = _("*both*"); 11061 else 11062 name = strtab + ivda.vda_name; 11063 } 11064 } 11065 if (name != NULL) 11066 nn += printf ("(%s%-*s", 11067 name, 11068 12 - (int) strlen (name), 11069 ")"); 11070 11071 if (nn < 18) 11072 printf ("%*c", 18 - nn, ' '); 11073 } 11074 11075 putchar ('\n'); 11076 } 11077 11078 free (data); 11079 free (strtab); 11080 free (symbols); 11081 } 11082 break; 11083 11084 default: 11085 break; 11086 } 11087 } 11088 11089 if (! found) 11090 printf (_("\nNo version information found in this file.\n")); 11091 11092 return TRUE; 11093 } 11094 11095 static const char * 11096 get_symbol_binding (Filedata * filedata, unsigned int binding) 11097 { 11098 static char buff[32]; 11099 11100 switch (binding) 11101 { 11102 case STB_LOCAL: return "LOCAL"; 11103 case STB_GLOBAL: return "GLOBAL"; 11104 case STB_WEAK: return "WEAK"; 11105 default: 11106 if (binding >= STB_LOPROC && binding <= STB_HIPROC) 11107 snprintf (buff, sizeof (buff), _("<processor specific>: %d"), 11108 binding); 11109 else if (binding >= STB_LOOS && binding <= STB_HIOS) 11110 { 11111 if (binding == STB_GNU_UNIQUE 11112 && filedata->file_header.e_ident[EI_OSABI] == ELFOSABI_GNU) 11113 return "UNIQUE"; 11114 snprintf (buff, sizeof (buff), _("<OS specific>: %d"), binding); 11115 } 11116 else 11117 snprintf (buff, sizeof (buff), _("<unknown>: %d"), binding); 11118 return buff; 11119 } 11120 } 11121 11122 static const char * 11123 get_symbol_type (Filedata * filedata, unsigned int type) 11124 { 11125 static char buff[32]; 11126 11127 switch (type) 11128 { 11129 case STT_NOTYPE: return "NOTYPE"; 11130 case STT_OBJECT: return "OBJECT"; 11131 case STT_FUNC: return "FUNC"; 11132 case STT_SECTION: return "SECTION"; 11133 case STT_FILE: return "FILE"; 11134 case STT_COMMON: return "COMMON"; 11135 case STT_TLS: return "TLS"; 11136 case STT_RELC: return "RELC"; 11137 case STT_SRELC: return "SRELC"; 11138 default: 11139 if (type >= STT_LOPROC && type <= STT_HIPROC) 11140 { 11141 if (filedata->file_header.e_machine == EM_ARM && type == STT_ARM_TFUNC) 11142 return "THUMB_FUNC"; 11143 11144 if (filedata->file_header.e_machine == EM_SPARCV9 && type == STT_REGISTER) 11145 return "REGISTER"; 11146 11147 if (filedata->file_header.e_machine == EM_PARISC && type == STT_PARISC_MILLI) 11148 return "PARISC_MILLI"; 11149 11150 snprintf (buff, sizeof (buff), _("<processor specific>: %d"), type); 11151 } 11152 else if (type >= STT_LOOS && type <= STT_HIOS) 11153 { 11154 if (filedata->file_header.e_machine == EM_PARISC) 11155 { 11156 if (type == STT_HP_OPAQUE) 11157 return "HP_OPAQUE"; 11158 if (type == STT_HP_STUB) 11159 return "HP_STUB"; 11160 } 11161 11162 if (type == STT_GNU_IFUNC 11163 && (filedata->file_header.e_ident[EI_OSABI] == ELFOSABI_GNU 11164 || filedata->file_header.e_ident[EI_OSABI] == ELFOSABI_FREEBSD)) 11165 return "IFUNC"; 11166 11167 snprintf (buff, sizeof (buff), _("<OS specific>: %d"), type); 11168 } 11169 else 11170 snprintf (buff, sizeof (buff), _("<unknown>: %d"), type); 11171 return buff; 11172 } 11173 } 11174 11175 static const char * 11176 get_symbol_visibility (unsigned int visibility) 11177 { 11178 switch (visibility) 11179 { 11180 case STV_DEFAULT: return "DEFAULT"; 11181 case STV_INTERNAL: return "INTERNAL"; 11182 case STV_HIDDEN: return "HIDDEN"; 11183 case STV_PROTECTED: return "PROTECTED"; 11184 default: 11185 error (_("Unrecognized visibility value: %u"), visibility); 11186 return _("<unknown>"); 11187 } 11188 } 11189 11190 static const char * 11191 get_alpha_symbol_other (unsigned int other) 11192 { 11193 switch (other) 11194 { 11195 case STO_ALPHA_NOPV: return "NOPV"; 11196 case STO_ALPHA_STD_GPLOAD: return "STD GPLOAD"; 11197 default: 11198 error (_("Unrecognized alpah specific other value: %u"), other); 11199 return _("<unknown>"); 11200 } 11201 } 11202 11203 static const char * 11204 get_solaris_symbol_visibility (unsigned int visibility) 11205 { 11206 switch (visibility) 11207 { 11208 case 4: return "EXPORTED"; 11209 case 5: return "SINGLETON"; 11210 case 6: return "ELIMINATE"; 11211 default: return get_symbol_visibility (visibility); 11212 } 11213 } 11214 11215 static const char * 11216 get_aarch64_symbol_other (unsigned int other) 11217 { 11218 static char buf[32]; 11219 11220 if (other & STO_AARCH64_VARIANT_PCS) 11221 { 11222 other &= ~STO_AARCH64_VARIANT_PCS; 11223 if (other == 0) 11224 return "VARIANT_PCS"; 11225 snprintf (buf, sizeof buf, "VARIANT_PCS | %x", other); 11226 return buf; 11227 } 11228 return NULL; 11229 } 11230 11231 static const char * 11232 get_mips_symbol_other (unsigned int other) 11233 { 11234 switch (other) 11235 { 11236 case STO_OPTIONAL: return "OPTIONAL"; 11237 case STO_MIPS_PLT: return "MIPS PLT"; 11238 case STO_MIPS_PIC: return "MIPS PIC"; 11239 case STO_MICROMIPS: return "MICROMIPS"; 11240 case STO_MICROMIPS | STO_MIPS_PIC: return "MICROMIPS, MIPS PIC"; 11241 case STO_MIPS16: return "MIPS16"; 11242 default: return NULL; 11243 } 11244 } 11245 11246 static const char * 11247 get_ia64_symbol_other (Filedata * filedata, unsigned int other) 11248 { 11249 if (is_ia64_vms (filedata)) 11250 { 11251 static char res[32]; 11252 11253 res[0] = 0; 11254 11255 /* Function types is for images and .STB files only. */ 11256 switch (filedata->file_header.e_type) 11257 { 11258 case ET_DYN: 11259 case ET_EXEC: 11260 switch (VMS_ST_FUNC_TYPE (other)) 11261 { 11262 case VMS_SFT_CODE_ADDR: 11263 strcat (res, " CA"); 11264 break; 11265 case VMS_SFT_SYMV_IDX: 11266 strcat (res, " VEC"); 11267 break; 11268 case VMS_SFT_FD: 11269 strcat (res, " FD"); 11270 break; 11271 case VMS_SFT_RESERVE: 11272 strcat (res, " RSV"); 11273 break; 11274 default: 11275 warn (_("Unrecognized IA64 VMS ST Function type: %d\n"), 11276 VMS_ST_FUNC_TYPE (other)); 11277 strcat (res, " <unknown>"); 11278 break; 11279 } 11280 break; 11281 default: 11282 break; 11283 } 11284 switch (VMS_ST_LINKAGE (other)) 11285 { 11286 case VMS_STL_IGNORE: 11287 strcat (res, " IGN"); 11288 break; 11289 case VMS_STL_RESERVE: 11290 strcat (res, " RSV"); 11291 break; 11292 case VMS_STL_STD: 11293 strcat (res, " STD"); 11294 break; 11295 case VMS_STL_LNK: 11296 strcat (res, " LNK"); 11297 break; 11298 default: 11299 warn (_("Unrecognized IA64 VMS ST Linkage: %d\n"), 11300 VMS_ST_LINKAGE (other)); 11301 strcat (res, " <unknown>"); 11302 break; 11303 } 11304 11305 if (res[0] != 0) 11306 return res + 1; 11307 else 11308 return res; 11309 } 11310 return NULL; 11311 } 11312 11313 static const char * 11314 get_ppc64_symbol_other (unsigned int other) 11315 { 11316 if ((other & ~STO_PPC64_LOCAL_MASK) != 0) 11317 return NULL; 11318 11319 other >>= STO_PPC64_LOCAL_BIT; 11320 if (other <= 6) 11321 { 11322 static char buf[32]; 11323 if (other >= 2) 11324 other = ppc64_decode_local_entry (other); 11325 snprintf (buf, sizeof buf, _("<localentry>: %d"), other); 11326 return buf; 11327 } 11328 return NULL; 11329 } 11330 11331 static const char * 11332 get_symbol_other (Filedata * filedata, unsigned int other) 11333 { 11334 const char * result = NULL; 11335 static char buff [32]; 11336 11337 if (other == 0) 11338 return ""; 11339 11340 switch (filedata->file_header.e_machine) 11341 { 11342 case EM_ALPHA: 11343 result = get_alpha_symbol_other (other); 11344 break; 11345 case EM_AARCH64: 11346 result = get_aarch64_symbol_other (other); 11347 break; 11348 case EM_MIPS: 11349 result = get_mips_symbol_other (other); 11350 break; 11351 case EM_IA_64: 11352 result = get_ia64_symbol_other (filedata, other); 11353 break; 11354 case EM_PPC64: 11355 result = get_ppc64_symbol_other (other); 11356 break; 11357 default: 11358 result = NULL; 11359 break; 11360 } 11361 11362 if (result) 11363 return result; 11364 11365 snprintf (buff, sizeof buff, _("<other>: %x"), other); 11366 return buff; 11367 } 11368 11369 static const char * 11370 get_symbol_index_type (Filedata * filedata, unsigned int type) 11371 { 11372 static char buff[32]; 11373 11374 switch (type) 11375 { 11376 case SHN_UNDEF: return "UND"; 11377 case SHN_ABS: return "ABS"; 11378 case SHN_COMMON: return "COM"; 11379 default: 11380 if (type == SHN_IA_64_ANSI_COMMON 11381 && filedata->file_header.e_machine == EM_IA_64 11382 && filedata->file_header.e_ident[EI_OSABI] == ELFOSABI_HPUX) 11383 return "ANSI_COM"; 11384 else if ((filedata->file_header.e_machine == EM_X86_64 11385 || filedata->file_header.e_machine == EM_L1OM 11386 || filedata->file_header.e_machine == EM_K1OM) 11387 && type == SHN_X86_64_LCOMMON) 11388 return "LARGE_COM"; 11389 else if ((type == SHN_MIPS_SCOMMON 11390 && filedata->file_header.e_machine == EM_MIPS) 11391 || (type == SHN_TIC6X_SCOMMON 11392 && filedata->file_header.e_machine == EM_TI_C6000)) 11393 return "SCOM"; 11394 else if (type == SHN_MIPS_SUNDEFINED 11395 && filedata->file_header.e_machine == EM_MIPS) 11396 return "SUND"; 11397 else if (type >= SHN_LOPROC && type <= SHN_HIPROC) 11398 sprintf (buff, "PRC[0x%04x]", type & 0xffff); 11399 else if (type >= SHN_LOOS && type <= SHN_HIOS) 11400 sprintf (buff, "OS [0x%04x]", type & 0xffff); 11401 else if (type >= SHN_LORESERVE) 11402 sprintf (buff, "RSV[0x%04x]", type & 0xffff); 11403 else if (type >= filedata->file_header.e_shnum) 11404 sprintf (buff, _("bad section index[%3d]"), type); 11405 else 11406 sprintf (buff, "%3d", type); 11407 break; 11408 } 11409 11410 return buff; 11411 } 11412 11413 static bfd_vma * 11414 get_dynamic_data (Filedata * filedata, bfd_size_type number, unsigned int ent_size) 11415 { 11416 unsigned char * e_data; 11417 bfd_vma * i_data; 11418 11419 /* If the size_t type is smaller than the bfd_size_type, eg because 11420 you are building a 32-bit tool on a 64-bit host, then make sure 11421 that when (number) is cast to (size_t) no information is lost. */ 11422 if (sizeof (size_t) < sizeof (bfd_size_type) 11423 && (bfd_size_type) ((size_t) number) != number) 11424 { 11425 error (_("Size truncation prevents reading %s elements of size %u\n"), 11426 bfd_vmatoa ("u", number), ent_size); 11427 return NULL; 11428 } 11429 11430 /* Be kind to memory chekers (eg valgrind, address sanitizer) by not 11431 attempting to allocate memory when the read is bound to fail. */ 11432 if (ent_size * number > filedata->file_size) 11433 { 11434 error (_("Invalid number of dynamic entries: %s\n"), 11435 bfd_vmatoa ("u", number)); 11436 return NULL; 11437 } 11438 11439 e_data = (unsigned char *) cmalloc ((size_t) number, ent_size); 11440 if (e_data == NULL) 11441 { 11442 error (_("Out of memory reading %s dynamic entries\n"), 11443 bfd_vmatoa ("u", number)); 11444 return NULL; 11445 } 11446 11447 if (fread (e_data, ent_size, (size_t) number, filedata->handle) != number) 11448 { 11449 error (_("Unable to read in %s bytes of dynamic data\n"), 11450 bfd_vmatoa ("u", number * ent_size)); 11451 free (e_data); 11452 return NULL; 11453 } 11454 11455 i_data = (bfd_vma *) cmalloc ((size_t) number, sizeof (*i_data)); 11456 if (i_data == NULL) 11457 { 11458 error (_("Out of memory allocating space for %s dynamic entries\n"), 11459 bfd_vmatoa ("u", number)); 11460 free (e_data); 11461 return NULL; 11462 } 11463 11464 while (number--) 11465 i_data[number] = byte_get (e_data + number * ent_size, ent_size); 11466 11467 free (e_data); 11468 11469 return i_data; 11470 } 11471 11472 static void 11473 print_dynamic_symbol (Filedata * filedata, bfd_vma si, unsigned long hn) 11474 { 11475 Elf_Internal_Sym * psym; 11476 int n; 11477 11478 n = print_vma (si, DEC_5); 11479 if (n < 5) 11480 fputs (&" "[n], stdout); 11481 printf (" %3lu: ", hn); 11482 11483 if (dynamic_symbols == NULL || si >= num_dynamic_syms) 11484 { 11485 printf (_("<No info available for dynamic symbol number %lu>\n"), 11486 (unsigned long) si); 11487 return; 11488 } 11489 11490 psym = dynamic_symbols + si; 11491 print_vma (psym->st_value, LONG_HEX); 11492 putchar (' '); 11493 print_vma (psym->st_size, DEC_5); 11494 11495 printf (" %-7s", get_symbol_type (filedata, ELF_ST_TYPE (psym->st_info))); 11496 printf (" %-6s", get_symbol_binding (filedata, ELF_ST_BIND (psym->st_info))); 11497 11498 if (filedata->file_header.e_ident[EI_OSABI] == ELFOSABI_SOLARIS) 11499 printf (" %-7s", get_solaris_symbol_visibility (psym->st_other)); 11500 else 11501 { 11502 unsigned int vis = ELF_ST_VISIBILITY (psym->st_other); 11503 11504 printf (" %-7s", get_symbol_visibility (vis)); 11505 /* Check to see if any other bits in the st_other field are set. 11506 Note - displaying this information disrupts the layout of the 11507 table being generated, but for the moment this case is very 11508 rare. */ 11509 if (psym->st_other ^ vis) 11510 printf (" [%s] ", get_symbol_other (filedata, psym->st_other ^ vis)); 11511 } 11512 11513 printf (" %3.3s ", get_symbol_index_type (filedata, psym->st_shndx)); 11514 if (VALID_DYNAMIC_NAME (psym->st_name)) 11515 print_symbol (25, GET_DYNAMIC_NAME (psym->st_name)); 11516 else 11517 printf (_(" <corrupt: %14ld>"), psym->st_name); 11518 putchar ('\n'); 11519 } 11520 11521 static const char * 11522 get_symbol_version_string (Filedata * filedata, 11523 bfd_boolean is_dynsym, 11524 const char * strtab, 11525 unsigned long int strtab_size, 11526 unsigned int si, 11527 Elf_Internal_Sym * psym, 11528 enum versioned_symbol_info * sym_info, 11529 unsigned short * vna_other) 11530 { 11531 unsigned char data[2]; 11532 unsigned short vers_data; 11533 unsigned long offset; 11534 unsigned short max_vd_ndx; 11535 11536 if (!is_dynsym 11537 || version_info[DT_VERSIONTAGIDX (DT_VERSYM)] == 0) 11538 return NULL; 11539 11540 offset = offset_from_vma (filedata, version_info[DT_VERSIONTAGIDX (DT_VERSYM)], 11541 sizeof data + si * sizeof (vers_data)); 11542 11543 if (get_data (&data, filedata, offset + si * sizeof (vers_data), 11544 sizeof (data), 1, _("version data")) == NULL) 11545 return NULL; 11546 11547 vers_data = byte_get (data, 2); 11548 11549 if ((vers_data & VERSYM_HIDDEN) == 0 && vers_data == 0) 11550 return NULL; 11551 11552 *sym_info = (vers_data & VERSYM_HIDDEN) != 0 ? symbol_hidden : symbol_public; 11553 max_vd_ndx = 0; 11554 11555 /* Usually we'd only see verdef for defined symbols, and verneed for 11556 undefined symbols. However, symbols defined by the linker in 11557 .dynbss for variables copied from a shared library in order to 11558 avoid text relocations are defined yet have verneed. We could 11559 use a heuristic to detect the special case, for example, check 11560 for verneed first on symbols defined in SHT_NOBITS sections, but 11561 it is simpler and more reliable to just look for both verdef and 11562 verneed. .dynbss might not be mapped to a SHT_NOBITS section. */ 11563 11564 if (psym->st_shndx != SHN_UNDEF 11565 && vers_data != 0x8001 11566 && version_info[DT_VERSIONTAGIDX (DT_VERDEF)]) 11567 { 11568 Elf_Internal_Verdef ivd; 11569 Elf_Internal_Verdaux ivda; 11570 Elf_External_Verdaux evda; 11571 unsigned long off; 11572 11573 off = offset_from_vma (filedata, 11574 version_info[DT_VERSIONTAGIDX (DT_VERDEF)], 11575 sizeof (Elf_External_Verdef)); 11576 11577 do 11578 { 11579 Elf_External_Verdef evd; 11580 11581 if (get_data (&evd, filedata, off, sizeof (evd), 1, 11582 _("version def")) == NULL) 11583 { 11584 ivd.vd_ndx = 0; 11585 ivd.vd_aux = 0; 11586 ivd.vd_next = 0; 11587 ivd.vd_flags = 0; 11588 } 11589 else 11590 { 11591 ivd.vd_ndx = BYTE_GET (evd.vd_ndx); 11592 ivd.vd_aux = BYTE_GET (evd.vd_aux); 11593 ivd.vd_next = BYTE_GET (evd.vd_next); 11594 ivd.vd_flags = BYTE_GET (evd.vd_flags); 11595 } 11596 11597 if ((ivd.vd_ndx & VERSYM_VERSION) > max_vd_ndx) 11598 max_vd_ndx = ivd.vd_ndx & VERSYM_VERSION; 11599 11600 off += ivd.vd_next; 11601 } 11602 while (ivd.vd_ndx != (vers_data & VERSYM_VERSION) && ivd.vd_next != 0); 11603 11604 if (ivd.vd_ndx == (vers_data & VERSYM_VERSION)) 11605 { 11606 if (ivd.vd_ndx == 1 && ivd.vd_flags == VER_FLG_BASE) 11607 return NULL; 11608 11609 off -= ivd.vd_next; 11610 off += ivd.vd_aux; 11611 11612 if (get_data (&evda, filedata, off, sizeof (evda), 1, 11613 _("version def aux")) != NULL) 11614 { 11615 ivda.vda_name = BYTE_GET (evda.vda_name); 11616 11617 if (psym->st_name != ivda.vda_name) 11618 return (ivda.vda_name < strtab_size 11619 ? strtab + ivda.vda_name : _("<corrupt>")); 11620 } 11621 } 11622 } 11623 11624 if (version_info[DT_VERSIONTAGIDX (DT_VERNEED)]) 11625 { 11626 Elf_External_Verneed evn; 11627 Elf_Internal_Verneed ivn; 11628 Elf_Internal_Vernaux ivna; 11629 11630 offset = offset_from_vma (filedata, 11631 version_info[DT_VERSIONTAGIDX (DT_VERNEED)], 11632 sizeof evn); 11633 do 11634 { 11635 unsigned long vna_off; 11636 11637 if (get_data (&evn, filedata, offset, sizeof (evn), 1, 11638 _("version need")) == NULL) 11639 { 11640 ivna.vna_next = 0; 11641 ivna.vna_other = 0; 11642 ivna.vna_name = 0; 11643 break; 11644 } 11645 11646 ivn.vn_aux = BYTE_GET (evn.vn_aux); 11647 ivn.vn_next = BYTE_GET (evn.vn_next); 11648 11649 vna_off = offset + ivn.vn_aux; 11650 11651 do 11652 { 11653 Elf_External_Vernaux evna; 11654 11655 if (get_data (&evna, filedata, vna_off, sizeof (evna), 1, 11656 _("version need aux (3)")) == NULL) 11657 { 11658 ivna.vna_next = 0; 11659 ivna.vna_other = 0; 11660 ivna.vna_name = 0; 11661 } 11662 else 11663 { 11664 ivna.vna_other = BYTE_GET (evna.vna_other); 11665 ivna.vna_next = BYTE_GET (evna.vna_next); 11666 ivna.vna_name = BYTE_GET (evna.vna_name); 11667 } 11668 11669 vna_off += ivna.vna_next; 11670 } 11671 while (ivna.vna_other != vers_data && ivna.vna_next != 0); 11672 11673 if (ivna.vna_other == vers_data) 11674 break; 11675 11676 offset += ivn.vn_next; 11677 } 11678 while (ivn.vn_next != 0); 11679 11680 if (ivna.vna_other == vers_data) 11681 { 11682 *sym_info = symbol_undefined; 11683 *vna_other = ivna.vna_other; 11684 return (ivna.vna_name < strtab_size 11685 ? strtab + ivna.vna_name : _("<corrupt>")); 11686 } 11687 else if ((max_vd_ndx || (vers_data & VERSYM_VERSION) != 1) 11688 && (vers_data & VERSYM_VERSION) > max_vd_ndx) 11689 return _("<corrupt>"); 11690 } 11691 return NULL; 11692 } 11693 11694 /* Dump the symbol table. */ 11695 static bfd_boolean 11696 process_symbol_table (Filedata * filedata) 11697 { 11698 Elf_Internal_Shdr * section; 11699 bfd_size_type nbuckets = 0; 11700 bfd_size_type nchains = 0; 11701 bfd_vma * buckets = NULL; 11702 bfd_vma * chains = NULL; 11703 bfd_vma ngnubuckets = 0; 11704 bfd_vma * gnubuckets = NULL; 11705 bfd_vma * gnuchains = NULL; 11706 bfd_vma * mipsxlat = NULL; 11707 bfd_vma gnusymidx = 0; 11708 bfd_size_type ngnuchains = 0; 11709 11710 if (!do_syms && !do_dyn_syms && !do_histogram) 11711 return TRUE; 11712 11713 if (dynamic_info[DT_HASH] 11714 && (do_histogram 11715 || (do_using_dynamic 11716 && !do_dyn_syms 11717 && dynamic_strings != NULL))) 11718 { 11719 unsigned char nb[8]; 11720 unsigned char nc[8]; 11721 unsigned int hash_ent_size = 4; 11722 11723 if ((filedata->file_header.e_machine == EM_ALPHA 11724 || filedata->file_header.e_machine == EM_S390 11725 || filedata->file_header.e_machine == EM_S390_OLD) 11726 && filedata->file_header.e_ident[EI_CLASS] == ELFCLASS64) 11727 hash_ent_size = 8; 11728 11729 if (fseek (filedata->handle, 11730 (archive_file_offset 11731 + offset_from_vma (filedata, dynamic_info[DT_HASH], 11732 sizeof nb + sizeof nc)), 11733 SEEK_SET)) 11734 { 11735 error (_("Unable to seek to start of dynamic information\n")); 11736 goto no_hash; 11737 } 11738 11739 if (fread (nb, hash_ent_size, 1, filedata->handle) != 1) 11740 { 11741 error (_("Failed to read in number of buckets\n")); 11742 goto no_hash; 11743 } 11744 11745 if (fread (nc, hash_ent_size, 1, filedata->handle) != 1) 11746 { 11747 error (_("Failed to read in number of chains\n")); 11748 goto no_hash; 11749 } 11750 11751 nbuckets = byte_get (nb, hash_ent_size); 11752 nchains = byte_get (nc, hash_ent_size); 11753 11754 buckets = get_dynamic_data (filedata, nbuckets, hash_ent_size); 11755 chains = get_dynamic_data (filedata, nchains, hash_ent_size); 11756 11757 no_hash: 11758 if (buckets == NULL || chains == NULL) 11759 { 11760 if (do_using_dynamic) 11761 return FALSE; 11762 free (buckets); 11763 free (chains); 11764 buckets = NULL; 11765 chains = NULL; 11766 nbuckets = 0; 11767 nchains = 0; 11768 } 11769 } 11770 11771 if (dynamic_info_DT_GNU_HASH 11772 && (do_histogram 11773 || (do_using_dynamic 11774 && !do_dyn_syms 11775 && dynamic_strings != NULL))) 11776 { 11777 unsigned char nb[16]; 11778 bfd_vma i, maxchain = 0xffffffff, bitmaskwords; 11779 bfd_vma buckets_vma; 11780 11781 if (fseek (filedata->handle, 11782 (archive_file_offset 11783 + offset_from_vma (filedata, dynamic_info_DT_GNU_HASH, 11784 sizeof nb)), 11785 SEEK_SET)) 11786 { 11787 error (_("Unable to seek to start of dynamic information\n")); 11788 goto no_gnu_hash; 11789 } 11790 11791 if (fread (nb, 16, 1, filedata->handle) != 1) 11792 { 11793 error (_("Failed to read in number of buckets\n")); 11794 goto no_gnu_hash; 11795 } 11796 11797 ngnubuckets = byte_get (nb, 4); 11798 gnusymidx = byte_get (nb + 4, 4); 11799 bitmaskwords = byte_get (nb + 8, 4); 11800 buckets_vma = dynamic_info_DT_GNU_HASH + 16; 11801 if (is_32bit_elf) 11802 buckets_vma += bitmaskwords * 4; 11803 else 11804 buckets_vma += bitmaskwords * 8; 11805 11806 if (fseek (filedata->handle, 11807 (archive_file_offset 11808 + offset_from_vma (filedata, buckets_vma, 4)), 11809 SEEK_SET)) 11810 { 11811 error (_("Unable to seek to start of dynamic information\n")); 11812 goto no_gnu_hash; 11813 } 11814 11815 gnubuckets = get_dynamic_data (filedata, ngnubuckets, 4); 11816 11817 if (gnubuckets == NULL) 11818 goto no_gnu_hash; 11819 11820 for (i = 0; i < ngnubuckets; i++) 11821 if (gnubuckets[i] != 0) 11822 { 11823 if (gnubuckets[i] < gnusymidx) 11824 return FALSE; 11825 11826 if (maxchain == 0xffffffff || gnubuckets[i] > maxchain) 11827 maxchain = gnubuckets[i]; 11828 } 11829 11830 if (maxchain == 0xffffffff) 11831 goto no_gnu_hash; 11832 11833 maxchain -= gnusymidx; 11834 11835 if (fseek (filedata->handle, 11836 (archive_file_offset 11837 + offset_from_vma (filedata, buckets_vma 11838 + 4 * (ngnubuckets + maxchain), 4)), 11839 SEEK_SET)) 11840 { 11841 error (_("Unable to seek to start of dynamic information\n")); 11842 goto no_gnu_hash; 11843 } 11844 11845 do 11846 { 11847 if (fread (nb, 4, 1, filedata->handle) != 1) 11848 { 11849 error (_("Failed to determine last chain length\n")); 11850 goto no_gnu_hash; 11851 } 11852 11853 if (maxchain + 1 == 0) 11854 goto no_gnu_hash; 11855 11856 ++maxchain; 11857 } 11858 while ((byte_get (nb, 4) & 1) == 0); 11859 11860 if (fseek (filedata->handle, 11861 (archive_file_offset 11862 + offset_from_vma (filedata, buckets_vma + 4 * ngnubuckets, 4)), 11863 SEEK_SET)) 11864 { 11865 error (_("Unable to seek to start of dynamic information\n")); 11866 goto no_gnu_hash; 11867 } 11868 11869 gnuchains = get_dynamic_data (filedata, maxchain, 4); 11870 ngnuchains = maxchain; 11871 11872 if (gnuchains == NULL) 11873 goto no_gnu_hash; 11874 11875 if (dynamic_info_DT_MIPS_XHASH) 11876 { 11877 if (fseek (filedata->handle, 11878 (archive_file_offset 11879 + offset_from_vma (filedata, (buckets_vma 11880 + 4 * (ngnubuckets 11881 + maxchain)), 4)), 11882 SEEK_SET)) 11883 { 11884 error (_("Unable to seek to start of dynamic information\n")); 11885 goto no_gnu_hash; 11886 } 11887 11888 mipsxlat = get_dynamic_data (filedata, maxchain, 4); 11889 } 11890 11891 no_gnu_hash: 11892 if (dynamic_info_DT_MIPS_XHASH && mipsxlat == NULL) 11893 { 11894 free (gnuchains); 11895 gnuchains = NULL; 11896 } 11897 if (gnuchains == NULL) 11898 { 11899 free (gnubuckets); 11900 gnubuckets = NULL; 11901 ngnubuckets = 0; 11902 if (do_using_dynamic) 11903 return FALSE; 11904 } 11905 } 11906 11907 if ((dynamic_info[DT_HASH] || dynamic_info_DT_GNU_HASH) 11908 && do_syms 11909 && do_using_dynamic 11910 && dynamic_strings != NULL 11911 && dynamic_symbols != NULL) 11912 { 11913 unsigned long hn; 11914 11915 if (dynamic_info[DT_HASH]) 11916 { 11917 bfd_vma si; 11918 char *visited; 11919 11920 printf (_("\nSymbol table for image:\n")); 11921 if (is_32bit_elf) 11922 printf (_(" Num Buc: Value Size Type Bind Vis Ndx Name\n")); 11923 else 11924 printf (_(" Num Buc: Value Size Type Bind Vis Ndx Name\n")); 11925 11926 visited = xcmalloc (nchains, 1); 11927 memset (visited, 0, nchains); 11928 for (hn = 0; hn < nbuckets; hn++) 11929 { 11930 for (si = buckets[hn]; si > 0; si = chains[si]) 11931 { 11932 print_dynamic_symbol (filedata, si, hn); 11933 if (si >= nchains || visited[si]) 11934 { 11935 error (_("histogram chain is corrupt\n")); 11936 break; 11937 } 11938 visited[si] = 1; 11939 } 11940 } 11941 free (visited); 11942 } 11943 11944 if (dynamic_info_DT_GNU_HASH) 11945 { 11946 printf (_("\nSymbol table of `%s' for image:\n"), 11947 GNU_HASH_SECTION_NAME); 11948 if (is_32bit_elf) 11949 printf (_(" Num Buc: Value Size Type Bind Vis Ndx Name\n")); 11950 else 11951 printf (_(" Num Buc: Value Size Type Bind Vis Ndx Name\n")); 11952 11953 for (hn = 0; hn < ngnubuckets; ++hn) 11954 if (gnubuckets[hn] != 0) 11955 { 11956 bfd_vma si = gnubuckets[hn]; 11957 bfd_vma off = si - gnusymidx; 11958 11959 do 11960 { 11961 if (dynamic_info_DT_MIPS_XHASH) 11962 print_dynamic_symbol (filedata, mipsxlat[off], hn); 11963 else 11964 print_dynamic_symbol (filedata, si, hn); 11965 si++; 11966 } 11967 while (off < ngnuchains && (gnuchains[off++] & 1) == 0); 11968 } 11969 } 11970 } 11971 else if ((do_dyn_syms || (do_syms && !do_using_dynamic)) 11972 && filedata->section_headers != NULL) 11973 { 11974 unsigned int i; 11975 11976 for (i = 0, section = filedata->section_headers; 11977 i < filedata->file_header.e_shnum; 11978 i++, section++) 11979 { 11980 unsigned int si; 11981 char * strtab = NULL; 11982 unsigned long int strtab_size = 0; 11983 Elf_Internal_Sym * symtab; 11984 Elf_Internal_Sym * psym; 11985 unsigned long num_syms; 11986 11987 if ((section->sh_type != SHT_SYMTAB 11988 && section->sh_type != SHT_DYNSYM) 11989 || (!do_syms 11990 && section->sh_type == SHT_SYMTAB)) 11991 continue; 11992 11993 if (section->sh_entsize == 0) 11994 { 11995 printf (_("\nSymbol table '%s' has a sh_entsize of zero!\n"), 11996 printable_section_name (filedata, section)); 11997 continue; 11998 } 11999 12000 num_syms = section->sh_size / section->sh_entsize; 12001 printf (ngettext ("\nSymbol table '%s' contains %lu entry:\n", 12002 "\nSymbol table '%s' contains %lu entries:\n", 12003 num_syms), 12004 printable_section_name (filedata, section), 12005 num_syms); 12006 12007 if (is_32bit_elf) 12008 printf (_(" Num: Value Size Type Bind Vis Ndx Name\n")); 12009 else 12010 printf (_(" Num: Value Size Type Bind Vis Ndx Name\n")); 12011 12012 symtab = GET_ELF_SYMBOLS (filedata, section, & num_syms); 12013 if (symtab == NULL) 12014 continue; 12015 12016 if (section->sh_link == filedata->file_header.e_shstrndx) 12017 { 12018 strtab = filedata->string_table; 12019 strtab_size = filedata->string_table_length; 12020 } 12021 else if (section->sh_link < filedata->file_header.e_shnum) 12022 { 12023 Elf_Internal_Shdr * string_sec; 12024 12025 string_sec = filedata->section_headers + section->sh_link; 12026 12027 strtab = (char *) get_data (NULL, filedata, string_sec->sh_offset, 12028 1, string_sec->sh_size, 12029 _("string table")); 12030 strtab_size = strtab != NULL ? string_sec->sh_size : 0; 12031 } 12032 12033 for (si = 0, psym = symtab; si < num_syms; si++, psym++) 12034 { 12035 const char *version_string; 12036 enum versioned_symbol_info sym_info; 12037 unsigned short vna_other; 12038 12039 printf ("%6d: ", si); 12040 print_vma (psym->st_value, LONG_HEX); 12041 putchar (' '); 12042 print_vma (psym->st_size, DEC_5); 12043 printf (" %-7s", get_symbol_type (filedata, ELF_ST_TYPE (psym->st_info))); 12044 printf (" %-6s", get_symbol_binding (filedata, ELF_ST_BIND (psym->st_info))); 12045 if (filedata->file_header.e_ident[EI_OSABI] == ELFOSABI_SOLARIS) 12046 printf (" %-7s", get_solaris_symbol_visibility (psym->st_other)); 12047 else 12048 { 12049 unsigned int vis = ELF_ST_VISIBILITY (psym->st_other); 12050 12051 printf (" %-7s", get_symbol_visibility (vis)); 12052 /* Check to see if any other bits in the st_other field are set. 12053 Note - displaying this information disrupts the layout of the 12054 table being generated, but for the moment this case is very rare. */ 12055 if (psym->st_other ^ vis) 12056 printf (" [%s] ", get_symbol_other (filedata, psym->st_other ^ vis)); 12057 } 12058 printf (" %4s ", get_symbol_index_type (filedata, psym->st_shndx)); 12059 print_symbol (25, psym->st_name < strtab_size 12060 ? strtab + psym->st_name : _("<corrupt>")); 12061 12062 version_string 12063 = get_symbol_version_string (filedata, 12064 section->sh_type == SHT_DYNSYM, 12065 strtab, strtab_size, si, 12066 psym, &sym_info, &vna_other); 12067 if (version_string) 12068 { 12069 if (sym_info == symbol_undefined) 12070 printf ("@%s (%d)", version_string, vna_other); 12071 else 12072 printf (sym_info == symbol_hidden ? "@%s" : "@@%s", 12073 version_string); 12074 } 12075 12076 putchar ('\n'); 12077 12078 if (ELF_ST_BIND (psym->st_info) == STB_LOCAL 12079 && si >= section->sh_info 12080 /* Irix 5 and 6 MIPS binaries are known to ignore this requirement. */ 12081 && filedata->file_header.e_machine != EM_MIPS 12082 /* Solaris binaries have been found to violate this requirement as 12083 well. Not sure if this is a bug or an ABI requirement. */ 12084 && filedata->file_header.e_ident[EI_OSABI] != ELFOSABI_SOLARIS) 12085 warn (_("local symbol %u found at index >= %s's sh_info value of %u\n"), 12086 si, printable_section_name (filedata, section), section->sh_info); 12087 } 12088 12089 free (symtab); 12090 if (strtab != filedata->string_table) 12091 free (strtab); 12092 } 12093 } 12094 else if (do_syms) 12095 printf 12096 (_("\nDynamic symbol information is not available for displaying symbols.\n")); 12097 12098 if (do_histogram && buckets != NULL) 12099 { 12100 unsigned long * lengths; 12101 unsigned long * counts; 12102 unsigned long hn; 12103 bfd_vma si; 12104 unsigned long maxlength = 0; 12105 unsigned long nzero_counts = 0; 12106 unsigned long nsyms = 0; 12107 char *visited; 12108 12109 printf (ngettext ("\nHistogram for bucket list length " 12110 "(total of %lu bucket):\n", 12111 "\nHistogram for bucket list length " 12112 "(total of %lu buckets):\n", 12113 (unsigned long) nbuckets), 12114 (unsigned long) nbuckets); 12115 12116 lengths = (unsigned long *) calloc (nbuckets, sizeof (*lengths)); 12117 if (lengths == NULL) 12118 { 12119 error (_("Out of memory allocating space for histogram buckets\n")); 12120 return FALSE; 12121 } 12122 visited = xcmalloc (nchains, 1); 12123 memset (visited, 0, nchains); 12124 12125 printf (_(" Length Number %% of total Coverage\n")); 12126 for (hn = 0; hn < nbuckets; ++hn) 12127 { 12128 for (si = buckets[hn]; si > 0; si = chains[si]) 12129 { 12130 ++nsyms; 12131 if (maxlength < ++lengths[hn]) 12132 ++maxlength; 12133 if (si >= nchains || visited[si]) 12134 { 12135 error (_("histogram chain is corrupt\n")); 12136 break; 12137 } 12138 visited[si] = 1; 12139 } 12140 } 12141 free (visited); 12142 12143 counts = (unsigned long *) calloc (maxlength + 1, sizeof (*counts)); 12144 if (counts == NULL) 12145 { 12146 free (lengths); 12147 error (_("Out of memory allocating space for histogram counts\n")); 12148 return FALSE; 12149 } 12150 12151 for (hn = 0; hn < nbuckets; ++hn) 12152 ++counts[lengths[hn]]; 12153 12154 if (nbuckets > 0) 12155 { 12156 unsigned long i; 12157 printf (" 0 %-10lu (%5.1f%%)\n", 12158 counts[0], (counts[0] * 100.0) / nbuckets); 12159 for (i = 1; i <= maxlength; ++i) 12160 { 12161 nzero_counts += counts[i] * i; 12162 printf ("%7lu %-10lu (%5.1f%%) %5.1f%%\n", 12163 i, counts[i], (counts[i] * 100.0) / nbuckets, 12164 (nzero_counts * 100.0) / nsyms); 12165 } 12166 } 12167 12168 free (counts); 12169 free (lengths); 12170 } 12171 12172 if (buckets != NULL) 12173 { 12174 free (buckets); 12175 free (chains); 12176 } 12177 12178 if (do_histogram && gnubuckets != NULL) 12179 { 12180 unsigned long * lengths; 12181 unsigned long * counts; 12182 unsigned long hn; 12183 unsigned long maxlength = 0; 12184 unsigned long nzero_counts = 0; 12185 unsigned long nsyms = 0; 12186 12187 printf (ngettext ("\nHistogram for `%s' bucket list length " 12188 "(total of %lu bucket):\n", 12189 "\nHistogram for `%s' bucket list length " 12190 "(total of %lu buckets):\n", 12191 (unsigned long) ngnubuckets), 12192 GNU_HASH_SECTION_NAME, 12193 (unsigned long) ngnubuckets); 12194 12195 lengths = (unsigned long *) calloc (ngnubuckets, sizeof (*lengths)); 12196 if (lengths == NULL) 12197 { 12198 error (_("Out of memory allocating space for gnu histogram buckets\n")); 12199 return FALSE; 12200 } 12201 12202 printf (_(" Length Number %% of total Coverage\n")); 12203 12204 for (hn = 0; hn < ngnubuckets; ++hn) 12205 if (gnubuckets[hn] != 0) 12206 { 12207 bfd_vma off, length = 1; 12208 12209 for (off = gnubuckets[hn] - gnusymidx; 12210 /* PR 17531 file: 010-77222-0.004. */ 12211 off < ngnuchains && (gnuchains[off] & 1) == 0; 12212 ++off) 12213 ++length; 12214 lengths[hn] = length; 12215 if (length > maxlength) 12216 maxlength = length; 12217 nsyms += length; 12218 } 12219 12220 counts = (unsigned long *) calloc (maxlength + 1, sizeof (*counts)); 12221 if (counts == NULL) 12222 { 12223 free (lengths); 12224 error (_("Out of memory allocating space for gnu histogram counts\n")); 12225 return FALSE; 12226 } 12227 12228 for (hn = 0; hn < ngnubuckets; ++hn) 12229 ++counts[lengths[hn]]; 12230 12231 if (ngnubuckets > 0) 12232 { 12233 unsigned long j; 12234 printf (" 0 %-10lu (%5.1f%%)\n", 12235 counts[0], (counts[0] * 100.0) / ngnubuckets); 12236 for (j = 1; j <= maxlength; ++j) 12237 { 12238 nzero_counts += counts[j] * j; 12239 printf ("%7lu %-10lu (%5.1f%%) %5.1f%%\n", 12240 j, counts[j], (counts[j] * 100.0) / ngnubuckets, 12241 (nzero_counts * 100.0) / nsyms); 12242 } 12243 } 12244 12245 free (counts); 12246 free (lengths); 12247 free (gnubuckets); 12248 free (gnuchains); 12249 free (mipsxlat); 12250 } 12251 12252 return TRUE; 12253 } 12254 12255 static bfd_boolean 12256 process_syminfo (Filedata * filedata ATTRIBUTE_UNUSED) 12257 { 12258 unsigned int i; 12259 12260 if (dynamic_syminfo == NULL 12261 || !do_dynamic) 12262 /* No syminfo, this is ok. */ 12263 return TRUE; 12264 12265 /* There better should be a dynamic symbol section. */ 12266 if (dynamic_symbols == NULL || dynamic_strings == NULL) 12267 return FALSE; 12268 12269 if (dynamic_addr) 12270 printf (ngettext ("\nDynamic info segment at offset 0x%lx " 12271 "contains %d entry:\n", 12272 "\nDynamic info segment at offset 0x%lx " 12273 "contains %d entries:\n", 12274 dynamic_syminfo_nent), 12275 dynamic_syminfo_offset, dynamic_syminfo_nent); 12276 12277 printf (_(" Num: Name BoundTo Flags\n")); 12278 for (i = 0; i < dynamic_syminfo_nent; ++i) 12279 { 12280 unsigned short int flags = dynamic_syminfo[i].si_flags; 12281 12282 printf ("%4d: ", i); 12283 if (i >= num_dynamic_syms) 12284 printf (_("<corrupt index>")); 12285 else if (VALID_DYNAMIC_NAME (dynamic_symbols[i].st_name)) 12286 print_symbol (30, GET_DYNAMIC_NAME (dynamic_symbols[i].st_name)); 12287 else 12288 printf (_("<corrupt: %19ld>"), dynamic_symbols[i].st_name); 12289 putchar (' '); 12290 12291 switch (dynamic_syminfo[i].si_boundto) 12292 { 12293 case SYMINFO_BT_SELF: 12294 fputs ("SELF ", stdout); 12295 break; 12296 case SYMINFO_BT_PARENT: 12297 fputs ("PARENT ", stdout); 12298 break; 12299 default: 12300 if (dynamic_syminfo[i].si_boundto > 0 12301 && dynamic_syminfo[i].si_boundto < dynamic_nent 12302 && VALID_DYNAMIC_NAME (dynamic_section[dynamic_syminfo[i].si_boundto].d_un.d_val)) 12303 { 12304 print_symbol (10, GET_DYNAMIC_NAME (dynamic_section[dynamic_syminfo[i].si_boundto].d_un.d_val)); 12305 putchar (' ' ); 12306 } 12307 else 12308 printf ("%-10d ", dynamic_syminfo[i].si_boundto); 12309 break; 12310 } 12311 12312 if (flags & SYMINFO_FLG_DIRECT) 12313 printf (" DIRECT"); 12314 if (flags & SYMINFO_FLG_PASSTHRU) 12315 printf (" PASSTHRU"); 12316 if (flags & SYMINFO_FLG_COPY) 12317 printf (" COPY"); 12318 if (flags & SYMINFO_FLG_LAZYLOAD) 12319 printf (" LAZYLOAD"); 12320 12321 puts (""); 12322 } 12323 12324 return TRUE; 12325 } 12326 12327 /* A macro which evaluates to TRUE if the region ADDR .. ADDR + NELEM 12328 is contained by the region START .. END. The types of ADDR, START 12329 and END should all be the same. Note both ADDR + NELEM and END 12330 point to just beyond the end of the regions that are being tested. */ 12331 #define IN_RANGE(START,END,ADDR,NELEM) \ 12332 (((ADDR) >= (START)) && ((ADDR) < (END)) && ((ADDR) + (NELEM) <= (END))) 12333 12334 /* Check to see if the given reloc needs to be handled in a target specific 12335 manner. If so then process the reloc and return TRUE otherwise return 12336 FALSE. 12337 12338 If called with reloc == NULL, then this is a signal that reloc processing 12339 for the current section has finished, and any saved state should be 12340 discarded. */ 12341 12342 static bfd_boolean 12343 target_specific_reloc_handling (Filedata * filedata, 12344 Elf_Internal_Rela * reloc, 12345 unsigned char * start, 12346 unsigned char * end, 12347 Elf_Internal_Sym * symtab, 12348 unsigned long num_syms) 12349 { 12350 unsigned int reloc_type = 0; 12351 unsigned long sym_index = 0; 12352 12353 if (reloc) 12354 { 12355 reloc_type = get_reloc_type (filedata, reloc->r_info); 12356 sym_index = get_reloc_symindex (reloc->r_info); 12357 } 12358 12359 switch (filedata->file_header.e_machine) 12360 { 12361 case EM_MSP430: 12362 case EM_MSP430_OLD: 12363 { 12364 static Elf_Internal_Sym * saved_sym = NULL; 12365 12366 if (reloc == NULL) 12367 { 12368 saved_sym = NULL; 12369 return TRUE; 12370 } 12371 12372 switch (reloc_type) 12373 { 12374 case 10: /* R_MSP430_SYM_DIFF */ 12375 if (uses_msp430x_relocs (filedata)) 12376 break; 12377 /* Fall through. */ 12378 case 21: /* R_MSP430X_SYM_DIFF */ 12379 /* PR 21139. */ 12380 if (sym_index >= num_syms) 12381 error (_("MSP430 SYM_DIFF reloc contains invalid symbol index %lu\n"), 12382 sym_index); 12383 else 12384 saved_sym = symtab + sym_index; 12385 return TRUE; 12386 12387 case 1: /* R_MSP430_32 or R_MSP430_ABS32 */ 12388 case 3: /* R_MSP430_16 or R_MSP430_ABS8 */ 12389 goto handle_sym_diff; 12390 12391 case 5: /* R_MSP430_16_BYTE */ 12392 case 9: /* R_MSP430_8 */ 12393 if (uses_msp430x_relocs (filedata)) 12394 break; 12395 goto handle_sym_diff; 12396 12397 case 2: /* R_MSP430_ABS16 */ 12398 case 15: /* R_MSP430X_ABS16 */ 12399 if (! uses_msp430x_relocs (filedata)) 12400 break; 12401 goto handle_sym_diff; 12402 12403 handle_sym_diff: 12404 if (saved_sym != NULL) 12405 { 12406 int reloc_size = reloc_type == 1 ? 4 : 2; 12407 bfd_vma value; 12408 12409 if (sym_index >= num_syms) 12410 error (_("MSP430 reloc contains invalid symbol index %lu\n"), 12411 sym_index); 12412 else 12413 { 12414 value = reloc->r_addend + (symtab[sym_index].st_value 12415 - saved_sym->st_value); 12416 12417 if (IN_RANGE (start, end, start + reloc->r_offset, reloc_size)) 12418 byte_put (start + reloc->r_offset, value, reloc_size); 12419 else 12420 /* PR 21137 */ 12421 error (_("MSP430 sym diff reloc contains invalid offset: 0x%lx\n"), 12422 (long) reloc->r_offset); 12423 } 12424 12425 saved_sym = NULL; 12426 return TRUE; 12427 } 12428 break; 12429 12430 default: 12431 if (saved_sym != NULL) 12432 error (_("Unhandled MSP430 reloc type found after SYM_DIFF reloc\n")); 12433 break; 12434 } 12435 break; 12436 } 12437 12438 case EM_MN10300: 12439 case EM_CYGNUS_MN10300: 12440 { 12441 static Elf_Internal_Sym * saved_sym = NULL; 12442 12443 if (reloc == NULL) 12444 { 12445 saved_sym = NULL; 12446 return TRUE; 12447 } 12448 12449 switch (reloc_type) 12450 { 12451 case 34: /* R_MN10300_ALIGN */ 12452 return TRUE; 12453 case 33: /* R_MN10300_SYM_DIFF */ 12454 if (sym_index >= num_syms) 12455 error (_("MN10300_SYM_DIFF reloc contains invalid symbol index %lu\n"), 12456 sym_index); 12457 else 12458 saved_sym = symtab + sym_index; 12459 return TRUE; 12460 12461 case 1: /* R_MN10300_32 */ 12462 case 2: /* R_MN10300_16 */ 12463 if (saved_sym != NULL) 12464 { 12465 int reloc_size = reloc_type == 1 ? 4 : 2; 12466 bfd_vma value; 12467 12468 if (sym_index >= num_syms) 12469 error (_("MN10300 reloc contains invalid symbol index %lu\n"), 12470 sym_index); 12471 else 12472 { 12473 value = reloc->r_addend + (symtab[sym_index].st_value 12474 - saved_sym->st_value); 12475 12476 if (IN_RANGE (start, end, start + reloc->r_offset, reloc_size)) 12477 byte_put (start + reloc->r_offset, value, reloc_size); 12478 else 12479 error (_("MN10300 sym diff reloc contains invalid offset: 0x%lx\n"), 12480 (long) reloc->r_offset); 12481 } 12482 12483 saved_sym = NULL; 12484 return TRUE; 12485 } 12486 break; 12487 default: 12488 if (saved_sym != NULL) 12489 error (_("Unhandled MN10300 reloc type found after SYM_DIFF reloc\n")); 12490 break; 12491 } 12492 break; 12493 } 12494 12495 case EM_RL78: 12496 { 12497 static bfd_vma saved_sym1 = 0; 12498 static bfd_vma saved_sym2 = 0; 12499 static bfd_vma value; 12500 12501 if (reloc == NULL) 12502 { 12503 saved_sym1 = saved_sym2 = 0; 12504 return TRUE; 12505 } 12506 12507 switch (reloc_type) 12508 { 12509 case 0x80: /* R_RL78_SYM. */ 12510 saved_sym1 = saved_sym2; 12511 if (sym_index >= num_syms) 12512 error (_("RL78_SYM reloc contains invalid symbol index %lu\n"), 12513 sym_index); 12514 else 12515 { 12516 saved_sym2 = symtab[sym_index].st_value; 12517 saved_sym2 += reloc->r_addend; 12518 } 12519 return TRUE; 12520 12521 case 0x83: /* R_RL78_OPsub. */ 12522 value = saved_sym1 - saved_sym2; 12523 saved_sym2 = saved_sym1 = 0; 12524 return TRUE; 12525 break; 12526 12527 case 0x41: /* R_RL78_ABS32. */ 12528 if (IN_RANGE (start, end, start + reloc->r_offset, 4)) 12529 byte_put (start + reloc->r_offset, value, 4); 12530 else 12531 error (_("RL78 sym diff reloc contains invalid offset: 0x%lx\n"), 12532 (long) reloc->r_offset); 12533 value = 0; 12534 return TRUE; 12535 12536 case 0x43: /* R_RL78_ABS16. */ 12537 if (IN_RANGE (start, end, start + reloc->r_offset, 2)) 12538 byte_put (start + reloc->r_offset, value, 2); 12539 else 12540 error (_("RL78 sym diff reloc contains invalid offset: 0x%lx\n"), 12541 (long) reloc->r_offset); 12542 value = 0; 12543 return TRUE; 12544 12545 default: 12546 break; 12547 } 12548 break; 12549 } 12550 } 12551 12552 return FALSE; 12553 } 12554 12555 /* Returns TRUE iff RELOC_TYPE is a 32-bit absolute RELA relocation used in 12556 DWARF debug sections. This is a target specific test. Note - we do not 12557 go through the whole including-target-headers-multiple-times route, (as 12558 we have already done with <elf/h8.h>) because this would become very 12559 messy and even then this function would have to contain target specific 12560 information (the names of the relocs instead of their numeric values). 12561 FIXME: This is not the correct way to solve this problem. The proper way 12562 is to have target specific reloc sizing and typing functions created by 12563 the reloc-macros.h header, in the same way that it already creates the 12564 reloc naming functions. */ 12565 12566 static bfd_boolean 12567 is_32bit_abs_reloc (Filedata * filedata, unsigned int reloc_type) 12568 { 12569 /* Please keep this table alpha-sorted for ease of visual lookup. */ 12570 switch (filedata->file_header.e_machine) 12571 { 12572 case EM_386: 12573 case EM_IAMCU: 12574 return reloc_type == 1; /* R_386_32. */ 12575 case EM_68K: 12576 return reloc_type == 1; /* R_68K_32. */ 12577 case EM_860: 12578 return reloc_type == 1; /* R_860_32. */ 12579 case EM_960: 12580 return reloc_type == 2; /* R_960_32. */ 12581 case EM_AARCH64: 12582 return (reloc_type == 258 12583 || reloc_type == 1); /* R_AARCH64_ABS32 || R_AARCH64_P32_ABS32 */ 12584 case EM_BPF: 12585 return reloc_type == 11; /* R_BPF_DATA_32 */ 12586 case EM_ADAPTEVA_EPIPHANY: 12587 return reloc_type == 3; 12588 case EM_ALPHA: 12589 return reloc_type == 1; /* R_ALPHA_REFLONG. */ 12590 case EM_ARC: 12591 return reloc_type == 1; /* R_ARC_32. */ 12592 case EM_ARC_COMPACT: 12593 case EM_ARC_COMPACT2: 12594 return reloc_type == 4; /* R_ARC_32. */ 12595 case EM_ARM: 12596 return reloc_type == 2; /* R_ARM_ABS32 */ 12597 case EM_AVR_OLD: 12598 case EM_AVR: 12599 return reloc_type == 1; 12600 case EM_BLACKFIN: 12601 return reloc_type == 0x12; /* R_byte4_data. */ 12602 case EM_CRIS: 12603 return reloc_type == 3; /* R_CRIS_32. */ 12604 case EM_CR16: 12605 return reloc_type == 3; /* R_CR16_NUM32. */ 12606 case EM_CRX: 12607 return reloc_type == 15; /* R_CRX_NUM32. */ 12608 case EM_CSKY: 12609 return reloc_type == 1; /* R_CKCORE_ADDR32. */ 12610 case EM_CYGNUS_FRV: 12611 return reloc_type == 1; 12612 case EM_CYGNUS_D10V: 12613 case EM_D10V: 12614 return reloc_type == 6; /* R_D10V_32. */ 12615 case EM_CYGNUS_D30V: 12616 case EM_D30V: 12617 return reloc_type == 12; /* R_D30V_32_NORMAL. */ 12618 case EM_DLX: 12619 return reloc_type == 3; /* R_DLX_RELOC_32. */ 12620 case EM_CYGNUS_FR30: 12621 case EM_FR30: 12622 return reloc_type == 3; /* R_FR30_32. */ 12623 case EM_FT32: 12624 return reloc_type == 1; /* R_FT32_32. */ 12625 case EM_H8S: 12626 case EM_H8_300: 12627 case EM_H8_300H: 12628 return reloc_type == 1; /* R_H8_DIR32. */ 12629 case EM_IA_64: 12630 return (reloc_type == 0x64 /* R_IA64_SECREL32MSB. */ 12631 || reloc_type == 0x65 /* R_IA64_SECREL32LSB. */ 12632 || reloc_type == 0x24 /* R_IA64_DIR32MSB. */ 12633 || reloc_type == 0x25 /* R_IA64_DIR32LSB. */); 12634 case EM_IP2K_OLD: 12635 case EM_IP2K: 12636 return reloc_type == 2; /* R_IP2K_32. */ 12637 case EM_IQ2000: 12638 return reloc_type == 2; /* R_IQ2000_32. */ 12639 case EM_LATTICEMICO32: 12640 return reloc_type == 3; /* R_LM32_32. */ 12641 case EM_M32C_OLD: 12642 case EM_M32C: 12643 return reloc_type == 3; /* R_M32C_32. */ 12644 case EM_M32R: 12645 return reloc_type == 34; /* R_M32R_32_RELA. */ 12646 case EM_68HC11: 12647 case EM_68HC12: 12648 return reloc_type == 6; /* R_M68HC11_32. */ 12649 case EM_S12Z: 12650 return reloc_type == 7 || /* R_S12Z_EXT32 */ 12651 reloc_type == 6; /* R_S12Z_CW32. */ 12652 case EM_MCORE: 12653 return reloc_type == 1; /* R_MCORE_ADDR32. */ 12654 case EM_CYGNUS_MEP: 12655 return reloc_type == 4; /* R_MEP_32. */ 12656 case EM_METAG: 12657 return reloc_type == 2; /* R_METAG_ADDR32. */ 12658 case EM_MICROBLAZE: 12659 return reloc_type == 1; /* R_MICROBLAZE_32. */ 12660 case EM_MIPS: 12661 return reloc_type == 2; /* R_MIPS_32. */ 12662 case EM_MMIX: 12663 return reloc_type == 4; /* R_MMIX_32. */ 12664 case EM_CYGNUS_MN10200: 12665 case EM_MN10200: 12666 return reloc_type == 1; /* R_MN10200_32. */ 12667 case EM_CYGNUS_MN10300: 12668 case EM_MN10300: 12669 return reloc_type == 1; /* R_MN10300_32. */ 12670 case EM_MOXIE: 12671 return reloc_type == 1; /* R_MOXIE_32. */ 12672 case EM_MSP430_OLD: 12673 case EM_MSP430: 12674 return reloc_type == 1; /* R_MSP430_32 or R_MSP320_ABS32. */ 12675 case EM_MT: 12676 return reloc_type == 2; /* R_MT_32. */ 12677 case EM_NDS32: 12678 return reloc_type == 20; /* R_NDS32_RELA. */ 12679 case EM_ALTERA_NIOS2: 12680 return reloc_type == 12; /* R_NIOS2_BFD_RELOC_32. */ 12681 case EM_NIOS32: 12682 return reloc_type == 1; /* R_NIOS_32. */ 12683 case EM_OR1K: 12684 return reloc_type == 1; /* R_OR1K_32. */ 12685 case EM_PARISC: 12686 return (reloc_type == 1 /* R_PARISC_DIR32. */ 12687 || reloc_type == 2 /* R_PARISC_DIR21L. */ 12688 || reloc_type == 41); /* R_PARISC_SECREL32. */ 12689 case EM_PJ: 12690 case EM_PJ_OLD: 12691 return reloc_type == 1; /* R_PJ_DATA_DIR32. */ 12692 case EM_PPC64: 12693 return reloc_type == 1; /* R_PPC64_ADDR32. */ 12694 case EM_PPC: 12695 return reloc_type == 1; /* R_PPC_ADDR32. */ 12696 case EM_TI_PRU: 12697 return reloc_type == 11; /* R_PRU_BFD_RELOC_32. */ 12698 case EM_RISCV: 12699 return reloc_type == 1; /* R_RISCV_32. */ 12700 case EM_RL78: 12701 return reloc_type == 1; /* R_RL78_DIR32. */ 12702 case EM_RX: 12703 return reloc_type == 1; /* R_RX_DIR32. */ 12704 case EM_S370: 12705 return reloc_type == 1; /* R_I370_ADDR31. */ 12706 case EM_S390_OLD: 12707 case EM_S390: 12708 return reloc_type == 4; /* R_S390_32. */ 12709 case EM_SCORE: 12710 return reloc_type == 8; /* R_SCORE_ABS32. */ 12711 case EM_SH: 12712 return reloc_type == 1; /* R_SH_DIR32. */ 12713 case EM_SPARC32PLUS: 12714 case EM_SPARCV9: 12715 case EM_SPARC: 12716 return reloc_type == 3 /* R_SPARC_32. */ 12717 || reloc_type == 23; /* R_SPARC_UA32. */ 12718 case EM_SPU: 12719 return reloc_type == 6; /* R_SPU_ADDR32 */ 12720 case EM_TI_C6000: 12721 return reloc_type == 1; /* R_C6000_ABS32. */ 12722 case EM_TILEGX: 12723 return reloc_type == 2; /* R_TILEGX_32. */ 12724 case EM_TILEPRO: 12725 return reloc_type == 1; /* R_TILEPRO_32. */ 12726 case EM_CYGNUS_V850: 12727 case EM_V850: 12728 return reloc_type == 6; /* R_V850_ABS32. */ 12729 case EM_V800: 12730 return reloc_type == 0x33; /* R_V810_WORD. */ 12731 case EM_VAX: 12732 return reloc_type == 1; /* R_VAX_32. */ 12733 case EM_VISIUM: 12734 return reloc_type == 3; /* R_VISIUM_32. */ 12735 case EM_WEBASSEMBLY: 12736 return reloc_type == 1; /* R_WASM32_32. */ 12737 case EM_X86_64: 12738 case EM_L1OM: 12739 case EM_K1OM: 12740 return reloc_type == 10; /* R_X86_64_32. */ 12741 case EM_XC16X: 12742 case EM_C166: 12743 return reloc_type == 3; /* R_XC16C_ABS_32. */ 12744 case EM_XGATE: 12745 return reloc_type == 4; /* R_XGATE_32. */ 12746 case EM_XSTORMY16: 12747 return reloc_type == 1; /* R_XSTROMY16_32. */ 12748 case EM_XTENSA_OLD: 12749 case EM_XTENSA: 12750 return reloc_type == 1; /* R_XTENSA_32. */ 12751 case EM_Z80: 12752 return reloc_type == 6; /* R_Z80_32. */ 12753 default: 12754 { 12755 static unsigned int prev_warn = 0; 12756 12757 /* Avoid repeating the same warning multiple times. */ 12758 if (prev_warn != filedata->file_header.e_machine) 12759 error (_("Missing knowledge of 32-bit reloc types used in DWARF sections of machine number %d\n"), 12760 filedata->file_header.e_machine); 12761 prev_warn = filedata->file_header.e_machine; 12762 return FALSE; 12763 } 12764 } 12765 } 12766 12767 /* Like is_32bit_abs_reloc except that it returns TRUE iff RELOC_TYPE is 12768 a 32-bit pc-relative RELA relocation used in DWARF debug sections. */ 12769 12770 static bfd_boolean 12771 is_32bit_pcrel_reloc (Filedata * filedata, unsigned int reloc_type) 12772 { 12773 switch (filedata->file_header.e_machine) 12774 /* Please keep this table alpha-sorted for ease of visual lookup. */ 12775 { 12776 case EM_386: 12777 case EM_IAMCU: 12778 return reloc_type == 2; /* R_386_PC32. */ 12779 case EM_68K: 12780 return reloc_type == 4; /* R_68K_PC32. */ 12781 case EM_AARCH64: 12782 return reloc_type == 261; /* R_AARCH64_PREL32 */ 12783 case EM_ADAPTEVA_EPIPHANY: 12784 return reloc_type == 6; 12785 case EM_ALPHA: 12786 return reloc_type == 10; /* R_ALPHA_SREL32. */ 12787 case EM_ARC_COMPACT: 12788 case EM_ARC_COMPACT2: 12789 return reloc_type == 49; /* R_ARC_32_PCREL. */ 12790 case EM_ARM: 12791 return reloc_type == 3; /* R_ARM_REL32 */ 12792 case EM_AVR_OLD: 12793 case EM_AVR: 12794 return reloc_type == 36; /* R_AVR_32_PCREL. */ 12795 case EM_MICROBLAZE: 12796 return reloc_type == 2; /* R_MICROBLAZE_32_PCREL. */ 12797 case EM_OR1K: 12798 return reloc_type == 9; /* R_OR1K_32_PCREL. */ 12799 case EM_PARISC: 12800 return reloc_type == 9; /* R_PARISC_PCREL32. */ 12801 case EM_PPC: 12802 return reloc_type == 26; /* R_PPC_REL32. */ 12803 case EM_PPC64: 12804 return reloc_type == 26; /* R_PPC64_REL32. */ 12805 case EM_RISCV: 12806 return reloc_type == 57; /* R_RISCV_32_PCREL. */ 12807 case EM_S390_OLD: 12808 case EM_S390: 12809 return reloc_type == 5; /* R_390_PC32. */ 12810 case EM_SH: 12811 return reloc_type == 2; /* R_SH_REL32. */ 12812 case EM_SPARC32PLUS: 12813 case EM_SPARCV9: 12814 case EM_SPARC: 12815 return reloc_type == 6; /* R_SPARC_DISP32. */ 12816 case EM_SPU: 12817 return reloc_type == 13; /* R_SPU_REL32. */ 12818 case EM_TILEGX: 12819 return reloc_type == 6; /* R_TILEGX_32_PCREL. */ 12820 case EM_TILEPRO: 12821 return reloc_type == 4; /* R_TILEPRO_32_PCREL. */ 12822 case EM_VISIUM: 12823 return reloc_type == 6; /* R_VISIUM_32_PCREL */ 12824 case EM_X86_64: 12825 case EM_L1OM: 12826 case EM_K1OM: 12827 return reloc_type == 2; /* R_X86_64_PC32. */ 12828 case EM_VAX: 12829 return reloc_type == 4; /* R_VAX_PCREL32. */ 12830 case EM_XTENSA_OLD: 12831 case EM_XTENSA: 12832 return reloc_type == 14; /* R_XTENSA_32_PCREL. */ 12833 default: 12834 /* Do not abort or issue an error message here. Not all targets use 12835 pc-relative 32-bit relocs in their DWARF debug information and we 12836 have already tested for target coverage in is_32bit_abs_reloc. A 12837 more helpful warning message will be generated by apply_relocations 12838 anyway, so just return. */ 12839 return FALSE; 12840 } 12841 } 12842 12843 /* Like is_32bit_abs_reloc except that it returns TRUE iff RELOC_TYPE is 12844 a 64-bit absolute RELA relocation used in DWARF debug sections. */ 12845 12846 static bfd_boolean 12847 is_64bit_abs_reloc (Filedata * filedata, unsigned int reloc_type) 12848 { 12849 switch (filedata->file_header.e_machine) 12850 { 12851 case EM_AARCH64: 12852 return reloc_type == 257; /* R_AARCH64_ABS64. */ 12853 case EM_ALPHA: 12854 return reloc_type == 2; /* R_ALPHA_REFQUAD. */ 12855 case EM_IA_64: 12856 return (reloc_type == 0x26 /* R_IA64_DIR64MSB. */ 12857 || reloc_type == 0x27 /* R_IA64_DIR64LSB. */); 12858 case EM_PARISC: 12859 return reloc_type == 80; /* R_PARISC_DIR64. */ 12860 case EM_PPC64: 12861 return reloc_type == 38; /* R_PPC64_ADDR64. */ 12862 case EM_RISCV: 12863 return reloc_type == 2; /* R_RISCV_64. */ 12864 case EM_SPARC32PLUS: 12865 case EM_SPARCV9: 12866 case EM_SPARC: 12867 return reloc_type == 32 /* R_SPARC_64. */ 12868 || reloc_type == 54; /* R_SPARC_UA64. */ 12869 case EM_X86_64: 12870 case EM_L1OM: 12871 case EM_K1OM: 12872 return reloc_type == 1; /* R_X86_64_64. */ 12873 case EM_S390_OLD: 12874 case EM_S390: 12875 return reloc_type == 22; /* R_S390_64. */ 12876 case EM_TILEGX: 12877 return reloc_type == 1; /* R_TILEGX_64. */ 12878 case EM_MIPS: 12879 return reloc_type == 18; /* R_MIPS_64. */ 12880 default: 12881 return FALSE; 12882 } 12883 } 12884 12885 /* Like is_32bit_pcrel_reloc except that it returns TRUE iff RELOC_TYPE is 12886 a 64-bit pc-relative RELA relocation used in DWARF debug sections. */ 12887 12888 static bfd_boolean 12889 is_64bit_pcrel_reloc (Filedata * filedata, unsigned int reloc_type) 12890 { 12891 switch (filedata->file_header.e_machine) 12892 { 12893 case EM_AARCH64: 12894 return reloc_type == 260; /* R_AARCH64_PREL64. */ 12895 case EM_ALPHA: 12896 return reloc_type == 11; /* R_ALPHA_SREL64. */ 12897 case EM_IA_64: 12898 return (reloc_type == 0x4e /* R_IA64_PCREL64MSB. */ 12899 || reloc_type == 0x4f /* R_IA64_PCREL64LSB. */); 12900 case EM_PARISC: 12901 return reloc_type == 72; /* R_PARISC_PCREL64. */ 12902 case EM_PPC64: 12903 return reloc_type == 44; /* R_PPC64_REL64. */ 12904 case EM_SPARC32PLUS: 12905 case EM_SPARCV9: 12906 case EM_SPARC: 12907 return reloc_type == 46; /* R_SPARC_DISP64. */ 12908 case EM_X86_64: 12909 case EM_L1OM: 12910 case EM_K1OM: 12911 return reloc_type == 24; /* R_X86_64_PC64. */ 12912 case EM_S390_OLD: 12913 case EM_S390: 12914 return reloc_type == 23; /* R_S390_PC64. */ 12915 case EM_TILEGX: 12916 return reloc_type == 5; /* R_TILEGX_64_PCREL. */ 12917 default: 12918 return FALSE; 12919 } 12920 } 12921 12922 /* Like is_32bit_abs_reloc except that it returns TRUE iff RELOC_TYPE is 12923 a 24-bit absolute RELA relocation used in DWARF debug sections. */ 12924 12925 static bfd_boolean 12926 is_24bit_abs_reloc (Filedata * filedata, unsigned int reloc_type) 12927 { 12928 switch (filedata->file_header.e_machine) 12929 { 12930 case EM_CYGNUS_MN10200: 12931 case EM_MN10200: 12932 return reloc_type == 4; /* R_MN10200_24. */ 12933 case EM_FT32: 12934 return reloc_type == 5; /* R_FT32_20. */ 12935 case EM_Z80: 12936 return reloc_type == 5; /* R_Z80_24. */ 12937 default: 12938 return FALSE; 12939 } 12940 } 12941 12942 /* Like is_32bit_abs_reloc except that it returns TRUE iff RELOC_TYPE is 12943 a 16-bit absolute RELA relocation used in DWARF debug sections. */ 12944 12945 static bfd_boolean 12946 is_16bit_abs_reloc (Filedata * filedata, unsigned int reloc_type) 12947 { 12948 /* Please keep this table alpha-sorted for ease of visual lookup. */ 12949 switch (filedata->file_header.e_machine) 12950 { 12951 case EM_ARC: 12952 case EM_ARC_COMPACT: 12953 case EM_ARC_COMPACT2: 12954 return reloc_type == 2; /* R_ARC_16. */ 12955 case EM_ADAPTEVA_EPIPHANY: 12956 return reloc_type == 5; 12957 case EM_AVR_OLD: 12958 case EM_AVR: 12959 return reloc_type == 4; /* R_AVR_16. */ 12960 case EM_CYGNUS_D10V: 12961 case EM_D10V: 12962 return reloc_type == 3; /* R_D10V_16. */ 12963 case EM_FT32: 12964 return reloc_type == 2; /* R_FT32_16. */ 12965 case EM_H8S: 12966 case EM_H8_300: 12967 case EM_H8_300H: 12968 return reloc_type == R_H8_DIR16; 12969 case EM_IP2K_OLD: 12970 case EM_IP2K: 12971 return reloc_type == 1; /* R_IP2K_16. */ 12972 case EM_M32C_OLD: 12973 case EM_M32C: 12974 return reloc_type == 1; /* R_M32C_16 */ 12975 case EM_CYGNUS_MN10200: 12976 case EM_MN10200: 12977 return reloc_type == 2; /* R_MN10200_16. */ 12978 case EM_CYGNUS_MN10300: 12979 case EM_MN10300: 12980 return reloc_type == 2; /* R_MN10300_16. */ 12981 case EM_MSP430: 12982 if (uses_msp430x_relocs (filedata)) 12983 return reloc_type == 2; /* R_MSP430_ABS16. */ 12984 /* Fall through. */ 12985 case EM_MSP430_OLD: 12986 return reloc_type == 5; /* R_MSP430_16_BYTE. */ 12987 case EM_NDS32: 12988 return reloc_type == 19; /* R_NDS32_RELA. */ 12989 case EM_ALTERA_NIOS2: 12990 return reloc_type == 13; /* R_NIOS2_BFD_RELOC_16. */ 12991 case EM_NIOS32: 12992 return reloc_type == 9; /* R_NIOS_16. */ 12993 case EM_OR1K: 12994 return reloc_type == 2; /* R_OR1K_16. */ 12995 case EM_RISCV: 12996 return reloc_type == 55; /* R_RISCV_SET16. */ 12997 case EM_TI_PRU: 12998 return reloc_type == 8; /* R_PRU_BFD_RELOC_16. */ 12999 case EM_TI_C6000: 13000 return reloc_type == 2; /* R_C6000_ABS16. */ 13001 case EM_VISIUM: 13002 return reloc_type == 2; /* R_VISIUM_16. */ 13003 case EM_XC16X: 13004 case EM_C166: 13005 return reloc_type == 2; /* R_XC16C_ABS_16. */ 13006 case EM_XGATE: 13007 return reloc_type == 3; /* R_XGATE_16. */ 13008 case EM_Z80: 13009 return reloc_type == 4; /* R_Z80_16. */ 13010 default: 13011 return FALSE; 13012 } 13013 } 13014 13015 /* Like is_32bit_abs_reloc except that it returns TRUE iff RELOC_TYPE is 13016 a 8-bit absolute RELA relocation used in DWARF debug sections. */ 13017 13018 static bfd_boolean 13019 is_8bit_abs_reloc (Filedata * filedata, unsigned int reloc_type) 13020 { 13021 switch (filedata->file_header.e_machine) 13022 { 13023 case EM_RISCV: 13024 return reloc_type == 54; /* R_RISCV_SET8. */ 13025 case EM_Z80: 13026 return reloc_type == 1; /* R_Z80_8. */ 13027 default: 13028 return FALSE; 13029 } 13030 } 13031 13032 /* Like is_32bit_abs_reloc except that it returns TRUE iff RELOC_TYPE is 13033 a 6-bit absolute RELA relocation used in DWARF debug sections. */ 13034 13035 static bfd_boolean 13036 is_6bit_abs_reloc (Filedata * filedata, unsigned int reloc_type) 13037 { 13038 switch (filedata->file_header.e_machine) 13039 { 13040 case EM_RISCV: 13041 return reloc_type == 53; /* R_RISCV_SET6. */ 13042 default: 13043 return FALSE; 13044 } 13045 } 13046 13047 /* Like is_32bit_abs_reloc except that it returns TRUE iff RELOC_TYPE is 13048 a 32-bit inplace add RELA relocation used in DWARF debug sections. */ 13049 13050 static bfd_boolean 13051 is_32bit_inplace_add_reloc (Filedata * filedata, unsigned int reloc_type) 13052 { 13053 /* Please keep this table alpha-sorted for ease of visual lookup. */ 13054 switch (filedata->file_header.e_machine) 13055 { 13056 case EM_RISCV: 13057 return reloc_type == 35; /* R_RISCV_ADD32. */ 13058 default: 13059 return FALSE; 13060 } 13061 } 13062 13063 /* Like is_32bit_abs_reloc except that it returns TRUE iff RELOC_TYPE is 13064 a 32-bit inplace sub RELA relocation used in DWARF debug sections. */ 13065 13066 static bfd_boolean 13067 is_32bit_inplace_sub_reloc (Filedata * filedata, unsigned int reloc_type) 13068 { 13069 /* Please keep this table alpha-sorted for ease of visual lookup. */ 13070 switch (filedata->file_header.e_machine) 13071 { 13072 case EM_RISCV: 13073 return reloc_type == 39; /* R_RISCV_SUB32. */ 13074 default: 13075 return FALSE; 13076 } 13077 } 13078 13079 /* Like is_32bit_abs_reloc except that it returns TRUE iff RELOC_TYPE is 13080 a 64-bit inplace add RELA relocation used in DWARF debug sections. */ 13081 13082 static bfd_boolean 13083 is_64bit_inplace_add_reloc (Filedata * filedata, unsigned int reloc_type) 13084 { 13085 /* Please keep this table alpha-sorted for ease of visual lookup. */ 13086 switch (filedata->file_header.e_machine) 13087 { 13088 case EM_RISCV: 13089 return reloc_type == 36; /* R_RISCV_ADD64. */ 13090 default: 13091 return FALSE; 13092 } 13093 } 13094 13095 /* Like is_32bit_abs_reloc except that it returns TRUE iff RELOC_TYPE is 13096 a 64-bit inplace sub RELA relocation used in DWARF debug sections. */ 13097 13098 static bfd_boolean 13099 is_64bit_inplace_sub_reloc (Filedata * filedata, unsigned int reloc_type) 13100 { 13101 /* Please keep this table alpha-sorted for ease of visual lookup. */ 13102 switch (filedata->file_header.e_machine) 13103 { 13104 case EM_RISCV: 13105 return reloc_type == 40; /* R_RISCV_SUB64. */ 13106 default: 13107 return FALSE; 13108 } 13109 } 13110 13111 /* Like is_32bit_abs_reloc except that it returns TRUE iff RELOC_TYPE is 13112 a 16-bit inplace add RELA relocation used in DWARF debug sections. */ 13113 13114 static bfd_boolean 13115 is_16bit_inplace_add_reloc (Filedata * filedata, unsigned int reloc_type) 13116 { 13117 /* Please keep this table alpha-sorted for ease of visual lookup. */ 13118 switch (filedata->file_header.e_machine) 13119 { 13120 case EM_RISCV: 13121 return reloc_type == 34; /* R_RISCV_ADD16. */ 13122 default: 13123 return FALSE; 13124 } 13125 } 13126 13127 /* Like is_32bit_abs_reloc except that it returns TRUE iff RELOC_TYPE is 13128 a 16-bit inplace sub RELA relocation used in DWARF debug sections. */ 13129 13130 static bfd_boolean 13131 is_16bit_inplace_sub_reloc (Filedata * filedata, unsigned int reloc_type) 13132 { 13133 /* Please keep this table alpha-sorted for ease of visual lookup. */ 13134 switch (filedata->file_header.e_machine) 13135 { 13136 case EM_RISCV: 13137 return reloc_type == 38; /* R_RISCV_SUB16. */ 13138 default: 13139 return FALSE; 13140 } 13141 } 13142 13143 /* Like is_32bit_abs_reloc except that it returns TRUE iff RELOC_TYPE is 13144 a 8-bit inplace add RELA relocation used in DWARF debug sections. */ 13145 13146 static bfd_boolean 13147 is_8bit_inplace_add_reloc (Filedata * filedata, unsigned int reloc_type) 13148 { 13149 /* Please keep this table alpha-sorted for ease of visual lookup. */ 13150 switch (filedata->file_header.e_machine) 13151 { 13152 case EM_RISCV: 13153 return reloc_type == 33; /* R_RISCV_ADD8. */ 13154 default: 13155 return FALSE; 13156 } 13157 } 13158 13159 /* Like is_32bit_abs_reloc except that it returns TRUE iff RELOC_TYPE is 13160 a 8-bit inplace sub RELA relocation used in DWARF debug sections. */ 13161 13162 static bfd_boolean 13163 is_8bit_inplace_sub_reloc (Filedata * filedata, unsigned int reloc_type) 13164 { 13165 /* Please keep this table alpha-sorted for ease of visual lookup. */ 13166 switch (filedata->file_header.e_machine) 13167 { 13168 case EM_RISCV: 13169 return reloc_type == 37; /* R_RISCV_SUB8. */ 13170 default: 13171 return FALSE; 13172 } 13173 } 13174 13175 /* Like is_32bit_abs_reloc except that it returns TRUE iff RELOC_TYPE is 13176 a 6-bit inplace sub RELA relocation used in DWARF debug sections. */ 13177 13178 static bfd_boolean 13179 is_6bit_inplace_sub_reloc (Filedata * filedata, unsigned int reloc_type) 13180 { 13181 switch (filedata->file_header.e_machine) 13182 { 13183 case EM_RISCV: 13184 return reloc_type == 52; /* R_RISCV_SUB6. */ 13185 default: 13186 return FALSE; 13187 } 13188 } 13189 13190 /* Returns TRUE iff RELOC_TYPE is a NONE relocation used for discarded 13191 relocation entries (possibly formerly used for SHT_GROUP sections). */ 13192 13193 static bfd_boolean 13194 is_none_reloc (Filedata * filedata, unsigned int reloc_type) 13195 { 13196 switch (filedata->file_header.e_machine) 13197 { 13198 case EM_386: /* R_386_NONE. */ 13199 case EM_68K: /* R_68K_NONE. */ 13200 case EM_ADAPTEVA_EPIPHANY: 13201 case EM_ALPHA: /* R_ALPHA_NONE. */ 13202 case EM_ALTERA_NIOS2: /* R_NIOS2_NONE. */ 13203 case EM_ARC: /* R_ARC_NONE. */ 13204 case EM_ARC_COMPACT2: /* R_ARC_NONE. */ 13205 case EM_ARC_COMPACT: /* R_ARC_NONE. */ 13206 case EM_ARM: /* R_ARM_NONE. */ 13207 case EM_C166: /* R_XC16X_NONE. */ 13208 case EM_CRIS: /* R_CRIS_NONE. */ 13209 case EM_FT32: /* R_FT32_NONE. */ 13210 case EM_IA_64: /* R_IA64_NONE. */ 13211 case EM_K1OM: /* R_X86_64_NONE. */ 13212 case EM_L1OM: /* R_X86_64_NONE. */ 13213 case EM_M32R: /* R_M32R_NONE. */ 13214 case EM_MIPS: /* R_MIPS_NONE. */ 13215 case EM_MN10300: /* R_MN10300_NONE. */ 13216 case EM_MOXIE: /* R_MOXIE_NONE. */ 13217 case EM_NIOS32: /* R_NIOS_NONE. */ 13218 case EM_OR1K: /* R_OR1K_NONE. */ 13219 case EM_PARISC: /* R_PARISC_NONE. */ 13220 case EM_PPC64: /* R_PPC64_NONE. */ 13221 case EM_PPC: /* R_PPC_NONE. */ 13222 case EM_RISCV: /* R_RISCV_NONE. */ 13223 case EM_S390: /* R_390_NONE. */ 13224 case EM_S390_OLD: 13225 case EM_SH: /* R_SH_NONE. */ 13226 case EM_SPARC32PLUS: 13227 case EM_SPARC: /* R_SPARC_NONE. */ 13228 case EM_SPARCV9: 13229 case EM_TILEGX: /* R_TILEGX_NONE. */ 13230 case EM_TILEPRO: /* R_TILEPRO_NONE. */ 13231 case EM_TI_C6000:/* R_C6000_NONE. */ 13232 case EM_X86_64: /* R_X86_64_NONE. */ 13233 case EM_XC16X: 13234 case EM_Z80: /* R_Z80_NONE. */ 13235 case EM_WEBASSEMBLY: /* R_WASM32_NONE. */ 13236 return reloc_type == 0; 13237 13238 case EM_AARCH64: 13239 return reloc_type == 0 || reloc_type == 256; 13240 case EM_AVR_OLD: 13241 case EM_AVR: 13242 return (reloc_type == 0 /* R_AVR_NONE. */ 13243 || reloc_type == 30 /* R_AVR_DIFF8. */ 13244 || reloc_type == 31 /* R_AVR_DIFF16. */ 13245 || reloc_type == 32 /* R_AVR_DIFF32. */); 13246 case EM_METAG: 13247 return reloc_type == 3; /* R_METAG_NONE. */ 13248 case EM_NDS32: 13249 return (reloc_type == 0 /* R_XTENSA_NONE. */ 13250 || reloc_type == 204 /* R_NDS32_DIFF8. */ 13251 || reloc_type == 205 /* R_NDS32_DIFF16. */ 13252 || reloc_type == 206 /* R_NDS32_DIFF32. */ 13253 || reloc_type == 207 /* R_NDS32_ULEB128. */); 13254 case EM_TI_PRU: 13255 return (reloc_type == 0 /* R_PRU_NONE. */ 13256 || reloc_type == 65 /* R_PRU_DIFF8. */ 13257 || reloc_type == 66 /* R_PRU_DIFF16. */ 13258 || reloc_type == 67 /* R_PRU_DIFF32. */); 13259 case EM_XTENSA_OLD: 13260 case EM_XTENSA: 13261 return (reloc_type == 0 /* R_XTENSA_NONE. */ 13262 || reloc_type == 17 /* R_XTENSA_DIFF8. */ 13263 || reloc_type == 18 /* R_XTENSA_DIFF16. */ 13264 || reloc_type == 19 /* R_XTENSA_DIFF32. */); 13265 } 13266 return FALSE; 13267 } 13268 13269 /* Returns TRUE if there is a relocation against 13270 section NAME at OFFSET bytes. */ 13271 13272 bfd_boolean 13273 reloc_at (struct dwarf_section * dsec, dwarf_vma offset) 13274 { 13275 Elf_Internal_Rela * relocs; 13276 Elf_Internal_Rela * rp; 13277 13278 if (dsec == NULL || dsec->reloc_info == NULL) 13279 return FALSE; 13280 13281 relocs = (Elf_Internal_Rela *) dsec->reloc_info; 13282 13283 for (rp = relocs; rp < relocs + dsec->num_relocs; ++rp) 13284 if (rp->r_offset == offset) 13285 return TRUE; 13286 13287 return FALSE; 13288 } 13289 13290 /* Apply relocations to a section. 13291 Returns TRUE upon success, FALSE otherwise. 13292 If RELOCS_RETURN is non-NULL then it is set to point to the loaded relocs. 13293 It is then the caller's responsibility to free them. NUM_RELOCS_RETURN 13294 will be set to the number of relocs loaded. 13295 13296 Note: So far support has been added only for those relocations 13297 which can be found in debug sections. FIXME: Add support for 13298 more relocations ? */ 13299 13300 static bfd_boolean 13301 apply_relocations (Filedata * filedata, 13302 const Elf_Internal_Shdr * section, 13303 unsigned char * start, 13304 bfd_size_type size, 13305 void ** relocs_return, 13306 unsigned long * num_relocs_return) 13307 { 13308 Elf_Internal_Shdr * relsec; 13309 unsigned char * end = start + size; 13310 13311 if (relocs_return != NULL) 13312 { 13313 * (Elf_Internal_Rela **) relocs_return = NULL; 13314 * num_relocs_return = 0; 13315 } 13316 13317 if (filedata->file_header.e_type != ET_REL) 13318 /* No relocs to apply. */ 13319 return TRUE; 13320 13321 /* Find the reloc section associated with the section. */ 13322 for (relsec = filedata->section_headers; 13323 relsec < filedata->section_headers + filedata->file_header.e_shnum; 13324 ++relsec) 13325 { 13326 bfd_boolean is_rela; 13327 unsigned long num_relocs; 13328 Elf_Internal_Rela * relocs; 13329 Elf_Internal_Rela * rp; 13330 Elf_Internal_Shdr * symsec; 13331 Elf_Internal_Sym * symtab; 13332 unsigned long num_syms; 13333 Elf_Internal_Sym * sym; 13334 13335 if ((relsec->sh_type != SHT_RELA && relsec->sh_type != SHT_REL) 13336 || relsec->sh_info >= filedata->file_header.e_shnum 13337 || filedata->section_headers + relsec->sh_info != section 13338 || relsec->sh_size == 0 13339 || relsec->sh_link >= filedata->file_header.e_shnum) 13340 continue; 13341 13342 symsec = filedata->section_headers + relsec->sh_link; 13343 if (symsec->sh_type != SHT_SYMTAB 13344 && symsec->sh_type != SHT_DYNSYM) 13345 return FALSE; 13346 13347 is_rela = relsec->sh_type == SHT_RELA; 13348 13349 if (is_rela) 13350 { 13351 if (!slurp_rela_relocs (filedata, relsec->sh_offset, 13352 relsec->sh_size, & relocs, & num_relocs)) 13353 return FALSE; 13354 } 13355 else 13356 { 13357 if (!slurp_rel_relocs (filedata, relsec->sh_offset, 13358 relsec->sh_size, & relocs, & num_relocs)) 13359 return FALSE; 13360 } 13361 13362 /* SH uses RELA but uses in place value instead of the addend field. */ 13363 if (filedata->file_header.e_machine == EM_SH) 13364 is_rela = FALSE; 13365 13366 symtab = GET_ELF_SYMBOLS (filedata, symsec, & num_syms); 13367 13368 for (rp = relocs; rp < relocs + num_relocs; ++rp) 13369 { 13370 bfd_vma addend; 13371 unsigned int reloc_type; 13372 unsigned int reloc_size; 13373 bfd_boolean reloc_inplace = FALSE; 13374 bfd_boolean reloc_subtract = FALSE; 13375 unsigned char * rloc; 13376 unsigned long sym_index; 13377 13378 reloc_type = get_reloc_type (filedata, rp->r_info); 13379 13380 if (target_specific_reloc_handling (filedata, rp, start, end, symtab, num_syms)) 13381 continue; 13382 else if (is_none_reloc (filedata, reloc_type)) 13383 continue; 13384 else if (is_32bit_abs_reloc (filedata, reloc_type) 13385 || is_32bit_pcrel_reloc (filedata, reloc_type)) 13386 reloc_size = 4; 13387 else if (is_64bit_abs_reloc (filedata, reloc_type) 13388 || is_64bit_pcrel_reloc (filedata, reloc_type)) 13389 reloc_size = 8; 13390 else if (is_24bit_abs_reloc (filedata, reloc_type)) 13391 reloc_size = 3; 13392 else if (is_16bit_abs_reloc (filedata, reloc_type)) 13393 reloc_size = 2; 13394 else if (is_8bit_abs_reloc (filedata, reloc_type) 13395 || is_6bit_abs_reloc (filedata, reloc_type)) 13396 reloc_size = 1; 13397 else if ((reloc_subtract = is_32bit_inplace_sub_reloc (filedata, 13398 reloc_type)) 13399 || is_32bit_inplace_add_reloc (filedata, reloc_type)) 13400 { 13401 reloc_size = 4; 13402 reloc_inplace = TRUE; 13403 } 13404 else if ((reloc_subtract = is_64bit_inplace_sub_reloc (filedata, 13405 reloc_type)) 13406 || is_64bit_inplace_add_reloc (filedata, reloc_type)) 13407 { 13408 reloc_size = 8; 13409 reloc_inplace = TRUE; 13410 } 13411 else if ((reloc_subtract = is_16bit_inplace_sub_reloc (filedata, 13412 reloc_type)) 13413 || is_16bit_inplace_add_reloc (filedata, reloc_type)) 13414 { 13415 reloc_size = 2; 13416 reloc_inplace = TRUE; 13417 } 13418 else if ((reloc_subtract = is_8bit_inplace_sub_reloc (filedata, 13419 reloc_type)) 13420 || is_8bit_inplace_add_reloc (filedata, reloc_type)) 13421 { 13422 reloc_size = 1; 13423 reloc_inplace = TRUE; 13424 } 13425 else if ((reloc_subtract = is_6bit_inplace_sub_reloc (filedata, 13426 reloc_type))) 13427 { 13428 reloc_size = 1; 13429 reloc_inplace = TRUE; 13430 } 13431 else 13432 { 13433 static unsigned int prev_reloc = 0; 13434 13435 if (reloc_type != prev_reloc) 13436 warn (_("unable to apply unsupported reloc type %d to section %s\n"), 13437 reloc_type, printable_section_name (filedata, section)); 13438 prev_reloc = reloc_type; 13439 continue; 13440 } 13441 13442 rloc = start + rp->r_offset; 13443 if (!IN_RANGE (start, end, rloc, reloc_size)) 13444 { 13445 warn (_("skipping invalid relocation offset 0x%lx in section %s\n"), 13446 (unsigned long) rp->r_offset, 13447 printable_section_name (filedata, section)); 13448 continue; 13449 } 13450 13451 sym_index = (unsigned long) get_reloc_symindex (rp->r_info); 13452 if (sym_index >= num_syms) 13453 { 13454 warn (_("skipping invalid relocation symbol index 0x%lx in section %s\n"), 13455 sym_index, printable_section_name (filedata, section)); 13456 continue; 13457 } 13458 sym = symtab + sym_index; 13459 13460 /* If the reloc has a symbol associated with it, 13461 make sure that it is of an appropriate type. 13462 13463 Relocations against symbols without type can happen. 13464 Gcc -feliminate-dwarf2-dups may generate symbols 13465 without type for debug info. 13466 13467 Icc generates relocations against function symbols 13468 instead of local labels. 13469 13470 Relocations against object symbols can happen, eg when 13471 referencing a global array. For an example of this see 13472 the _clz.o binary in libgcc.a. */ 13473 if (sym != symtab 13474 && ELF_ST_TYPE (sym->st_info) != STT_COMMON 13475 && ELF_ST_TYPE (sym->st_info) > STT_SECTION) 13476 { 13477 warn (_("skipping unexpected symbol type %s in section %s relocation %ld\n"), 13478 get_symbol_type (filedata, ELF_ST_TYPE (sym->st_info)), 13479 printable_section_name (filedata, relsec), 13480 (long int)(rp - relocs)); 13481 continue; 13482 } 13483 13484 addend = 0; 13485 if (is_rela) 13486 addend += rp->r_addend; 13487 /* R_XTENSA_32, R_PJ_DATA_DIR32 and R_D30V_32_NORMAL are 13488 partial_inplace. */ 13489 if (!is_rela 13490 || (filedata->file_header.e_machine == EM_XTENSA 13491 && reloc_type == 1) 13492 || ((filedata->file_header.e_machine == EM_PJ 13493 || filedata->file_header.e_machine == EM_PJ_OLD) 13494 && reloc_type == 1) 13495 || ((filedata->file_header.e_machine == EM_D30V 13496 || filedata->file_header.e_machine == EM_CYGNUS_D30V) 13497 && reloc_type == 12) 13498 || reloc_inplace) 13499 { 13500 if (is_6bit_inplace_sub_reloc (filedata, reloc_type)) 13501 addend += byte_get (rloc, reloc_size) & 0x3f; 13502 else 13503 addend += byte_get (rloc, reloc_size); 13504 } 13505 13506 if (is_32bit_pcrel_reloc (filedata, reloc_type) 13507 || is_64bit_pcrel_reloc (filedata, reloc_type)) 13508 { 13509 /* On HPPA, all pc-relative relocations are biased by 8. */ 13510 if (filedata->file_header.e_machine == EM_PARISC) 13511 addend -= 8; 13512 byte_put (rloc, (addend + sym->st_value) - rp->r_offset, 13513 reloc_size); 13514 } 13515 else if (is_6bit_abs_reloc (filedata, reloc_type) 13516 || is_6bit_inplace_sub_reloc (filedata, reloc_type)) 13517 { 13518 if (reloc_subtract) 13519 addend -= sym->st_value; 13520 else 13521 addend += sym->st_value; 13522 addend = (addend & 0x3f) | (byte_get (rloc, reloc_size) & 0xc0); 13523 byte_put (rloc, addend, reloc_size); 13524 } 13525 else if (reloc_subtract) 13526 byte_put (rloc, addend - sym->st_value, reloc_size); 13527 else 13528 byte_put (rloc, addend + sym->st_value, reloc_size); 13529 } 13530 13531 free (symtab); 13532 /* Let the target specific reloc processing code know that 13533 we have finished with these relocs. */ 13534 target_specific_reloc_handling (filedata, NULL, NULL, NULL, NULL, 0); 13535 13536 if (relocs_return) 13537 { 13538 * (Elf_Internal_Rela **) relocs_return = relocs; 13539 * num_relocs_return = num_relocs; 13540 } 13541 else 13542 free (relocs); 13543 13544 break; 13545 } 13546 13547 return TRUE; 13548 } 13549 13550 #ifdef SUPPORT_DISASSEMBLY 13551 static bfd_boolean 13552 disassemble_section (Elf_Internal_Shdr * section, Filedata * filedata) 13553 { 13554 printf (_("\nAssembly dump of section %s\n"), printable_section_name (filedata, section)); 13555 13556 /* FIXME: XXX -- to be done --- XXX */ 13557 13558 return TRUE; 13559 } 13560 #endif 13561 13562 /* Reads in the contents of SECTION from FILE, returning a pointer 13563 to a malloc'ed buffer or NULL if something went wrong. */ 13564 13565 static char * 13566 get_section_contents (Elf_Internal_Shdr * section, Filedata * filedata) 13567 { 13568 bfd_size_type num_bytes = section->sh_size; 13569 13570 if (num_bytes == 0 || section->sh_type == SHT_NOBITS) 13571 { 13572 printf (_("Section '%s' has no data to dump.\n"), 13573 printable_section_name (filedata, section)); 13574 return NULL; 13575 } 13576 13577 return (char *) get_data (NULL, filedata, section->sh_offset, 1, num_bytes, 13578 _("section contents")); 13579 } 13580 13581 /* Uncompresses a section that was compressed using zlib, in place. */ 13582 13583 static bfd_boolean 13584 uncompress_section_contents (unsigned char ** buffer, 13585 dwarf_size_type uncompressed_size, 13586 dwarf_size_type * size) 13587 { 13588 dwarf_size_type compressed_size = *size; 13589 unsigned char * compressed_buffer = *buffer; 13590 unsigned char * uncompressed_buffer; 13591 z_stream strm; 13592 int rc; 13593 13594 /* It is possible the section consists of several compressed 13595 buffers concatenated together, so we uncompress in a loop. */ 13596 /* PR 18313: The state field in the z_stream structure is supposed 13597 to be invisible to the user (ie us), but some compilers will 13598 still complain about it being used without initialisation. So 13599 we first zero the entire z_stream structure and then set the fields 13600 that we need. */ 13601 memset (& strm, 0, sizeof strm); 13602 strm.avail_in = compressed_size; 13603 strm.next_in = (Bytef *) compressed_buffer; 13604 strm.avail_out = uncompressed_size; 13605 uncompressed_buffer = (unsigned char *) xmalloc (uncompressed_size); 13606 13607 rc = inflateInit (& strm); 13608 while (strm.avail_in > 0) 13609 { 13610 if (rc != Z_OK) 13611 goto fail; 13612 strm.next_out = ((Bytef *) uncompressed_buffer 13613 + (uncompressed_size - strm.avail_out)); 13614 rc = inflate (&strm, Z_FINISH); 13615 if (rc != Z_STREAM_END) 13616 goto fail; 13617 rc = inflateReset (& strm); 13618 } 13619 rc = inflateEnd (& strm); 13620 if (rc != Z_OK 13621 || strm.avail_out != 0) 13622 goto fail; 13623 13624 *buffer = uncompressed_buffer; 13625 *size = uncompressed_size; 13626 return TRUE; 13627 13628 fail: 13629 free (uncompressed_buffer); 13630 /* Indicate decompression failure. */ 13631 *buffer = NULL; 13632 return FALSE; 13633 } 13634 13635 static bfd_boolean 13636 dump_section_as_strings (Elf_Internal_Shdr * section, Filedata * filedata) 13637 { 13638 Elf_Internal_Shdr * relsec; 13639 bfd_size_type num_bytes; 13640 unsigned char * data; 13641 unsigned char * end; 13642 unsigned char * real_start; 13643 unsigned char * start; 13644 bfd_boolean some_strings_shown; 13645 13646 real_start = start = (unsigned char *) get_section_contents (section, filedata); 13647 if (start == NULL) 13648 /* PR 21820: Do not fail if the section was empty. */ 13649 return (section->sh_size == 0 || section->sh_type == SHT_NOBITS) ? TRUE : FALSE; 13650 13651 num_bytes = section->sh_size; 13652 13653 printf (_("\nString dump of section '%s':\n"), printable_section_name (filedata, section)); 13654 13655 if (decompress_dumps) 13656 { 13657 dwarf_size_type new_size = num_bytes; 13658 dwarf_size_type uncompressed_size = 0; 13659 13660 if ((section->sh_flags & SHF_COMPRESSED) != 0) 13661 { 13662 Elf_Internal_Chdr chdr; 13663 unsigned int compression_header_size 13664 = get_compression_header (& chdr, (unsigned char *) start, 13665 num_bytes); 13666 13667 if (chdr.ch_type != ELFCOMPRESS_ZLIB) 13668 { 13669 warn (_("section '%s' has unsupported compress type: %d\n"), 13670 printable_section_name (filedata, section), chdr.ch_type); 13671 return FALSE; 13672 } 13673 uncompressed_size = chdr.ch_size; 13674 start += compression_header_size; 13675 new_size -= compression_header_size; 13676 } 13677 else if (new_size > 12 && streq ((char *) start, "ZLIB")) 13678 { 13679 /* Read the zlib header. In this case, it should be "ZLIB" 13680 followed by the uncompressed section size, 8 bytes in 13681 big-endian order. */ 13682 uncompressed_size = start[4]; uncompressed_size <<= 8; 13683 uncompressed_size += start[5]; uncompressed_size <<= 8; 13684 uncompressed_size += start[6]; uncompressed_size <<= 8; 13685 uncompressed_size += start[7]; uncompressed_size <<= 8; 13686 uncompressed_size += start[8]; uncompressed_size <<= 8; 13687 uncompressed_size += start[9]; uncompressed_size <<= 8; 13688 uncompressed_size += start[10]; uncompressed_size <<= 8; 13689 uncompressed_size += start[11]; 13690 start += 12; 13691 new_size -= 12; 13692 } 13693 13694 if (uncompressed_size) 13695 { 13696 if (uncompress_section_contents (& start, 13697 uncompressed_size, & new_size)) 13698 num_bytes = new_size; 13699 else 13700 { 13701 error (_("Unable to decompress section %s\n"), 13702 printable_section_name (filedata, section)); 13703 return FALSE; 13704 } 13705 } 13706 else 13707 start = real_start; 13708 } 13709 13710 /* If the section being dumped has relocations against it the user might 13711 be expecting these relocations to have been applied. Check for this 13712 case and issue a warning message in order to avoid confusion. 13713 FIXME: Maybe we ought to have an option that dumps a section with 13714 relocs applied ? */ 13715 for (relsec = filedata->section_headers; 13716 relsec < filedata->section_headers + filedata->file_header.e_shnum; 13717 ++relsec) 13718 { 13719 if ((relsec->sh_type != SHT_RELA && relsec->sh_type != SHT_REL) 13720 || relsec->sh_info >= filedata->file_header.e_shnum 13721 || filedata->section_headers + relsec->sh_info != section 13722 || relsec->sh_size == 0 13723 || relsec->sh_link >= filedata->file_header.e_shnum) 13724 continue; 13725 13726 printf (_(" Note: This section has relocations against it, but these have NOT been applied to this dump.\n")); 13727 break; 13728 } 13729 13730 data = start; 13731 end = start + num_bytes; 13732 some_strings_shown = FALSE; 13733 13734 while (data < end) 13735 { 13736 while (!ISPRINT (* data)) 13737 if (++ data >= end) 13738 break; 13739 13740 if (data < end) 13741 { 13742 size_t maxlen = end - data; 13743 13744 #ifndef __MSVCRT__ 13745 /* PR 11128: Use two separate invocations in order to work 13746 around bugs in the Solaris 8 implementation of printf. */ 13747 printf (" [%6tx] ", data - start); 13748 #else 13749 printf (" [%6Ix] ", (size_t) (data - start)); 13750 #endif 13751 if (maxlen > 0) 13752 { 13753 print_symbol ((int) maxlen, (const char *) data); 13754 putchar ('\n'); 13755 data += strnlen ((const char *) data, maxlen); 13756 } 13757 else 13758 { 13759 printf (_("<corrupt>\n")); 13760 data = end; 13761 } 13762 some_strings_shown = TRUE; 13763 } 13764 } 13765 13766 if (! some_strings_shown) 13767 printf (_(" No strings found in this section.")); 13768 13769 free (real_start); 13770 13771 putchar ('\n'); 13772 return TRUE; 13773 } 13774 13775 static bfd_boolean 13776 dump_section_as_bytes (Elf_Internal_Shdr * section, 13777 Filedata * filedata, 13778 bfd_boolean relocate) 13779 { 13780 Elf_Internal_Shdr * relsec; 13781 bfd_size_type bytes; 13782 bfd_size_type section_size; 13783 bfd_vma addr; 13784 unsigned char * data; 13785 unsigned char * real_start; 13786 unsigned char * start; 13787 13788 real_start = start = (unsigned char *) get_section_contents (section, filedata); 13789 if (start == NULL) 13790 /* PR 21820: Do not fail if the section was empty. */ 13791 return (section->sh_size == 0 || section->sh_type == SHT_NOBITS) ? TRUE : FALSE; 13792 13793 section_size = section->sh_size; 13794 13795 printf (_("\nHex dump of section '%s':\n"), printable_section_name (filedata, section)); 13796 13797 if (decompress_dumps) 13798 { 13799 dwarf_size_type new_size = section_size; 13800 dwarf_size_type uncompressed_size = 0; 13801 13802 if ((section->sh_flags & SHF_COMPRESSED) != 0) 13803 { 13804 Elf_Internal_Chdr chdr; 13805 unsigned int compression_header_size 13806 = get_compression_header (& chdr, start, section_size); 13807 13808 if (chdr.ch_type != ELFCOMPRESS_ZLIB) 13809 { 13810 warn (_("section '%s' has unsupported compress type: %d\n"), 13811 printable_section_name (filedata, section), chdr.ch_type); 13812 return FALSE; 13813 } 13814 uncompressed_size = chdr.ch_size; 13815 start += compression_header_size; 13816 new_size -= compression_header_size; 13817 } 13818 else if (new_size > 12 && streq ((char *) start, "ZLIB")) 13819 { 13820 /* Read the zlib header. In this case, it should be "ZLIB" 13821 followed by the uncompressed section size, 8 bytes in 13822 big-endian order. */ 13823 uncompressed_size = start[4]; uncompressed_size <<= 8; 13824 uncompressed_size += start[5]; uncompressed_size <<= 8; 13825 uncompressed_size += start[6]; uncompressed_size <<= 8; 13826 uncompressed_size += start[7]; uncompressed_size <<= 8; 13827 uncompressed_size += start[8]; uncompressed_size <<= 8; 13828 uncompressed_size += start[9]; uncompressed_size <<= 8; 13829 uncompressed_size += start[10]; uncompressed_size <<= 8; 13830 uncompressed_size += start[11]; 13831 start += 12; 13832 new_size -= 12; 13833 } 13834 13835 if (uncompressed_size) 13836 { 13837 if (uncompress_section_contents (& start, uncompressed_size, 13838 & new_size)) 13839 { 13840 section_size = new_size; 13841 } 13842 else 13843 { 13844 error (_("Unable to decompress section %s\n"), 13845 printable_section_name (filedata, section)); 13846 /* FIXME: Print the section anyway ? */ 13847 return FALSE; 13848 } 13849 } 13850 else 13851 start = real_start; 13852 } 13853 13854 if (relocate) 13855 { 13856 if (! apply_relocations (filedata, section, start, section_size, NULL, NULL)) 13857 return FALSE; 13858 } 13859 else 13860 { 13861 /* If the section being dumped has relocations against it the user might 13862 be expecting these relocations to have been applied. Check for this 13863 case and issue a warning message in order to avoid confusion. 13864 FIXME: Maybe we ought to have an option that dumps a section with 13865 relocs applied ? */ 13866 for (relsec = filedata->section_headers; 13867 relsec < filedata->section_headers + filedata->file_header.e_shnum; 13868 ++relsec) 13869 { 13870 if ((relsec->sh_type != SHT_RELA && relsec->sh_type != SHT_REL) 13871 || relsec->sh_info >= filedata->file_header.e_shnum 13872 || filedata->section_headers + relsec->sh_info != section 13873 || relsec->sh_size == 0 13874 || relsec->sh_link >= filedata->file_header.e_shnum) 13875 continue; 13876 13877 printf (_(" NOTE: This section has relocations against it, but these have NOT been applied to this dump.\n")); 13878 break; 13879 } 13880 } 13881 13882 addr = section->sh_addr; 13883 bytes = section_size; 13884 data = start; 13885 13886 while (bytes) 13887 { 13888 int j; 13889 int k; 13890 int lbytes; 13891 13892 lbytes = (bytes > 16 ? 16 : bytes); 13893 13894 printf (" 0x%8.8lx ", (unsigned long) addr); 13895 13896 for (j = 0; j < 16; j++) 13897 { 13898 if (j < lbytes) 13899 printf ("%2.2x", data[j]); 13900 else 13901 printf (" "); 13902 13903 if ((j & 3) == 3) 13904 printf (" "); 13905 } 13906 13907 for (j = 0; j < lbytes; j++) 13908 { 13909 k = data[j]; 13910 if (k >= ' ' && k < 0x7f) 13911 printf ("%c", k); 13912 else 13913 printf ("."); 13914 } 13915 13916 putchar ('\n'); 13917 13918 data += lbytes; 13919 addr += lbytes; 13920 bytes -= lbytes; 13921 } 13922 13923 free (real_start); 13924 13925 putchar ('\n'); 13926 return TRUE; 13927 } 13928 13929 static ctf_sect_t * 13930 shdr_to_ctf_sect (ctf_sect_t *buf, Elf_Internal_Shdr *shdr, Filedata *filedata) 13931 { 13932 buf->cts_name = SECTION_NAME (shdr); 13933 buf->cts_size = shdr->sh_size; 13934 buf->cts_entsize = shdr->sh_entsize; 13935 13936 return buf; 13937 } 13938 13939 /* Formatting callback function passed to ctf_dump. Returns either the pointer 13940 it is passed, or a pointer to newly-allocated storage, in which case 13941 dump_ctf() will free it when it no longer needs it. */ 13942 13943 static char *dump_ctf_indent_lines (ctf_sect_names_t sect ATTRIBUTE_UNUSED, 13944 char *s, void *arg) 13945 { 13946 const char *blanks = arg; 13947 char *new_s; 13948 13949 if (asprintf (&new_s, "%s%s", blanks, s) < 0) 13950 return s; 13951 return new_s; 13952 } 13953 13954 static bfd_boolean 13955 dump_section_as_ctf (Elf_Internal_Shdr * section, Filedata * filedata) 13956 { 13957 Elf_Internal_Shdr * parent_sec = NULL; 13958 Elf_Internal_Shdr * symtab_sec = NULL; 13959 Elf_Internal_Shdr * strtab_sec = NULL; 13960 void * data = NULL; 13961 void * symdata = NULL; 13962 void * strdata = NULL; 13963 void * parentdata = NULL; 13964 ctf_sect_t ctfsect, symsect, strsect, parentsect; 13965 ctf_sect_t * symsectp = NULL; 13966 ctf_sect_t * strsectp = NULL; 13967 ctf_file_t * ctf = NULL; 13968 ctf_file_t * parent = NULL; 13969 13970 const char *things[] = {"Header", "Labels", "Data objects", 13971 "Function objects", "Variables", "Types", "Strings", 13972 ""}; 13973 const char **thing; 13974 int err; 13975 bfd_boolean ret = FALSE; 13976 size_t i; 13977 13978 shdr_to_ctf_sect (&ctfsect, section, filedata); 13979 data = get_section_contents (section, filedata); 13980 ctfsect.cts_data = data; 13981 13982 if (!dump_ctf_symtab_name) 13983 dump_ctf_symtab_name = strdup (".symtab"); 13984 13985 if (!dump_ctf_strtab_name) 13986 dump_ctf_strtab_name = strdup (".strtab"); 13987 13988 if (dump_ctf_symtab_name && dump_ctf_symtab_name[0] != 0) 13989 { 13990 if ((symtab_sec = find_section (filedata, dump_ctf_symtab_name)) == NULL) 13991 { 13992 error (_("No symbol section named %s\n"), dump_ctf_symtab_name); 13993 goto fail; 13994 } 13995 if ((symdata = (void *) get_data (NULL, filedata, 13996 symtab_sec->sh_offset, 1, 13997 symtab_sec->sh_size, 13998 _("symbols"))) == NULL) 13999 goto fail; 14000 symsectp = shdr_to_ctf_sect (&symsect, symtab_sec, filedata); 14001 symsect.cts_data = symdata; 14002 } 14003 if (dump_ctf_strtab_name && dump_ctf_symtab_name[0] != 0) 14004 { 14005 if ((strtab_sec = find_section (filedata, dump_ctf_strtab_name)) == NULL) 14006 { 14007 error (_("No string table section named %s\n"), 14008 dump_ctf_strtab_name); 14009 goto fail; 14010 } 14011 if ((strdata = (void *) get_data (NULL, filedata, 14012 strtab_sec->sh_offset, 1, 14013 strtab_sec->sh_size, 14014 _("strings"))) == NULL) 14015 goto fail; 14016 strsectp = shdr_to_ctf_sect (&strsect, strtab_sec, filedata); 14017 strsect.cts_data = strdata; 14018 } 14019 if (dump_ctf_parent_name) 14020 { 14021 if ((parent_sec = find_section (filedata, dump_ctf_parent_name)) == NULL) 14022 { 14023 error (_("No CTF parent section named %s\n"), dump_ctf_parent_name); 14024 goto fail; 14025 } 14026 if ((parentdata = (void *) get_data (NULL, filedata, 14027 parent_sec->sh_offset, 1, 14028 parent_sec->sh_size, 14029 _("CTF parent"))) == NULL) 14030 goto fail; 14031 shdr_to_ctf_sect (&parentsect, parent_sec, filedata); 14032 parentsect.cts_data = parentdata; 14033 } 14034 14035 /* Load the CTF file and dump it. */ 14036 14037 if ((ctf = ctf_bufopen (&ctfsect, symsectp, strsectp, &err)) == NULL) 14038 { 14039 error (_("CTF open failure: %s\n"), ctf_errmsg (err)); 14040 goto fail; 14041 } 14042 14043 if (parentdata) 14044 { 14045 if ((parent = ctf_bufopen (&parentsect, symsectp, strsectp, &err)) == NULL) 14046 { 14047 error (_("CTF open failure: %s\n"), ctf_errmsg (err)); 14048 goto fail; 14049 } 14050 14051 ctf_import (ctf, parent); 14052 } 14053 14054 ret = TRUE; 14055 14056 printf (_("\nDump of CTF section '%s':\n"), 14057 printable_section_name (filedata, section)); 14058 14059 for (i = 0, thing = things; *thing[0]; thing++, i++) 14060 { 14061 ctf_dump_state_t *s = NULL; 14062 char *item; 14063 14064 printf ("\n %s:\n", *thing); 14065 while ((item = ctf_dump (ctf, &s, i, dump_ctf_indent_lines, 14066 (void *) " ")) != NULL) 14067 { 14068 printf ("%s\n", item); 14069 free (item); 14070 } 14071 14072 if (ctf_errno (ctf)) 14073 { 14074 error (_("Iteration failed: %s, %s\n"), *thing, 14075 ctf_errmsg (ctf_errno (ctf))); 14076 ret = FALSE; 14077 } 14078 } 14079 14080 fail: 14081 ctf_file_close (ctf); 14082 ctf_file_close (parent); 14083 free (parentdata); 14084 free (data); 14085 free (symdata); 14086 free (strdata); 14087 return ret; 14088 } 14089 14090 static bfd_boolean 14091 load_specific_debug_section (enum dwarf_section_display_enum debug, 14092 const Elf_Internal_Shdr * sec, 14093 void * data) 14094 { 14095 struct dwarf_section * section = &debug_displays [debug].section; 14096 char buf [64]; 14097 Filedata * filedata = (Filedata *) data; 14098 14099 if (section->start != NULL) 14100 { 14101 /* If it is already loaded, do nothing. */ 14102 if (streq (section->filename, filedata->file_name)) 14103 return TRUE; 14104 free (section->start); 14105 } 14106 14107 snprintf (buf, sizeof (buf), _("%s section data"), section->name); 14108 section->address = sec->sh_addr; 14109 section->user_data = NULL; 14110 section->filename = filedata->file_name; 14111 section->start = (unsigned char *) get_data (NULL, filedata, 14112 sec->sh_offset, 1, 14113 sec->sh_size, buf); 14114 if (section->start == NULL) 14115 section->size = 0; 14116 else 14117 { 14118 unsigned char *start = section->start; 14119 dwarf_size_type size = sec->sh_size; 14120 dwarf_size_type uncompressed_size = 0; 14121 14122 if ((sec->sh_flags & SHF_COMPRESSED) != 0) 14123 { 14124 Elf_Internal_Chdr chdr; 14125 unsigned int compression_header_size; 14126 14127 if (size < (is_32bit_elf 14128 ? sizeof (Elf32_External_Chdr) 14129 : sizeof (Elf64_External_Chdr))) 14130 { 14131 warn (_("compressed section %s is too small to contain a compression header"), 14132 section->name); 14133 return FALSE; 14134 } 14135 14136 compression_header_size = get_compression_header (&chdr, start, size); 14137 14138 if (chdr.ch_type != ELFCOMPRESS_ZLIB) 14139 { 14140 warn (_("section '%s' has unsupported compress type: %d\n"), 14141 section->name, chdr.ch_type); 14142 return FALSE; 14143 } 14144 uncompressed_size = chdr.ch_size; 14145 start += compression_header_size; 14146 size -= compression_header_size; 14147 } 14148 else if (size > 12 && streq ((char *) start, "ZLIB")) 14149 { 14150 /* Read the zlib header. In this case, it should be "ZLIB" 14151 followed by the uncompressed section size, 8 bytes in 14152 big-endian order. */ 14153 uncompressed_size = start[4]; uncompressed_size <<= 8; 14154 uncompressed_size += start[5]; uncompressed_size <<= 8; 14155 uncompressed_size += start[6]; uncompressed_size <<= 8; 14156 uncompressed_size += start[7]; uncompressed_size <<= 8; 14157 uncompressed_size += start[8]; uncompressed_size <<= 8; 14158 uncompressed_size += start[9]; uncompressed_size <<= 8; 14159 uncompressed_size += start[10]; uncompressed_size <<= 8; 14160 uncompressed_size += start[11]; 14161 start += 12; 14162 size -= 12; 14163 } 14164 14165 if (uncompressed_size) 14166 { 14167 if (uncompress_section_contents (&start, uncompressed_size, 14168 &size)) 14169 { 14170 /* Free the compressed buffer, update the section buffer 14171 and the section size if uncompress is successful. */ 14172 free (section->start); 14173 section->start = start; 14174 } 14175 else 14176 { 14177 error (_("Unable to decompress section %s\n"), 14178 printable_section_name (filedata, sec)); 14179 return FALSE; 14180 } 14181 } 14182 14183 section->size = size; 14184 } 14185 14186 if (section->start == NULL) 14187 return FALSE; 14188 14189 if (debug_displays [debug].relocate) 14190 { 14191 if (! apply_relocations (filedata, sec, section->start, section->size, 14192 & section->reloc_info, & section->num_relocs)) 14193 return FALSE; 14194 } 14195 else 14196 { 14197 section->reloc_info = NULL; 14198 section->num_relocs = 0; 14199 } 14200 14201 return TRUE; 14202 } 14203 14204 #if HAVE_LIBDEBUGINFOD 14205 /* Return a hex string representation of the build-id. */ 14206 unsigned char * 14207 get_build_id (void * data) 14208 { 14209 Filedata * filedata = (Filedata *)data; 14210 Elf_Internal_Shdr * shdr; 14211 unsigned long i; 14212 14213 /* Iterate through notes to find note.gnu.build-id. */ 14214 for (i = 0, shdr = filedata->section_headers; 14215 i < filedata->file_header.e_shnum && shdr != NULL; 14216 i++, shdr++) 14217 { 14218 if (shdr->sh_type != SHT_NOTE) 14219 continue; 14220 14221 char * next; 14222 char * end; 14223 size_t data_remaining; 14224 size_t min_notesz; 14225 Elf_External_Note * enote; 14226 Elf_Internal_Note inote; 14227 14228 bfd_vma offset = shdr->sh_offset; 14229 bfd_vma align = shdr->sh_addralign; 14230 bfd_vma length = shdr->sh_size; 14231 14232 enote = (Elf_External_Note *) get_section_contents (shdr, filedata); 14233 if (enote == NULL) 14234 continue; 14235 14236 if (align < 4) 14237 align = 4; 14238 else if (align != 4 && align != 8) 14239 continue; 14240 14241 end = (char *) enote + length; 14242 data_remaining = end - (char *) enote; 14243 14244 if (!is_ia64_vms (filedata)) 14245 { 14246 min_notesz = offsetof (Elf_External_Note, name); 14247 if (data_remaining < min_notesz) 14248 { 14249 warn (ngettext ("debuginfod: Corrupt note: only %ld byte remains, " 14250 "not enough for a full note\n", 14251 "Corrupt note: only %ld bytes remain, " 14252 "not enough for a full note\n", 14253 data_remaining), 14254 (long) data_remaining); 14255 break; 14256 } 14257 data_remaining -= min_notesz; 14258 14259 inote.type = BYTE_GET (enote->type); 14260 inote.namesz = BYTE_GET (enote->namesz); 14261 inote.namedata = enote->name; 14262 inote.descsz = BYTE_GET (enote->descsz); 14263 inote.descdata = ((char *) enote 14264 + ELF_NOTE_DESC_OFFSET (inote.namesz, align)); 14265 inote.descpos = offset + (inote.descdata - (char *) enote); 14266 next = ((char *) enote 14267 + ELF_NOTE_NEXT_OFFSET (inote.namesz, inote.descsz, align)); 14268 } 14269 else 14270 { 14271 Elf64_External_VMS_Note *vms_enote; 14272 14273 /* PR binutils/15191 14274 Make sure that there is enough data to read. */ 14275 min_notesz = offsetof (Elf64_External_VMS_Note, name); 14276 if (data_remaining < min_notesz) 14277 { 14278 warn (ngettext ("debuginfod: Corrupt note: only %ld byte remains, " 14279 "not enough for a full note\n", 14280 "Corrupt note: only %ld bytes remain, " 14281 "not enough for a full note\n", 14282 data_remaining), 14283 (long) data_remaining); 14284 break; 14285 } 14286 data_remaining -= min_notesz; 14287 14288 vms_enote = (Elf64_External_VMS_Note *) enote; 14289 inote.type = BYTE_GET (vms_enote->type); 14290 inote.namesz = BYTE_GET (vms_enote->namesz); 14291 inote.namedata = vms_enote->name; 14292 inote.descsz = BYTE_GET (vms_enote->descsz); 14293 inote.descdata = inote.namedata + align_power (inote.namesz, 3); 14294 inote.descpos = offset + (inote.descdata - (char *) enote); 14295 next = inote.descdata + align_power (inote.descsz, 3); 14296 } 14297 14298 /* Skip malformed notes. */ 14299 if ((size_t) (inote.descdata - inote.namedata) < inote.namesz 14300 || (size_t) (inote.descdata - inote.namedata) > data_remaining 14301 || (size_t) (next - inote.descdata) < inote.descsz 14302 || ((size_t) (next - inote.descdata) 14303 > data_remaining - (size_t) (inote.descdata - inote.namedata))) 14304 { 14305 warn (_("debuginfod: note with invalid namesz and/or descsz found\n")); 14306 warn (_(" type: 0x%lx, namesize: 0x%08lx, descsize: 0x%08lx, alignment: %u\n"), 14307 inote.type, inote.namesz, inote.descsz, (int) align); 14308 continue; 14309 } 14310 14311 /* Check if this is the build-id note. If so then convert the build-id 14312 bytes to a hex string. */ 14313 if (inote.namesz > 0 14314 && const_strneq (inote.namedata, "GNU") 14315 && inote.type == NT_GNU_BUILD_ID) 14316 { 14317 unsigned long j; 14318 char * build_id; 14319 14320 build_id = malloc (inote.descsz * 2 + 1); 14321 if (build_id == NULL) 14322 return NULL; 14323 14324 for (j = 0; j < inote.descsz; ++j) 14325 sprintf (build_id + (j * 2), "%02x", inote.descdata[j] & 0xff); 14326 build_id[inote.descsz * 2] = '\0'; 14327 14328 return (unsigned char *)build_id; 14329 } 14330 } 14331 14332 return NULL; 14333 } 14334 #endif /* HAVE_LIBDEBUGINFOD */ 14335 14336 /* If this is not NULL, load_debug_section will only look for sections 14337 within the list of sections given here. */ 14338 static unsigned int * section_subset = NULL; 14339 14340 bfd_boolean 14341 load_debug_section (enum dwarf_section_display_enum debug, void * data) 14342 { 14343 struct dwarf_section * section = &debug_displays [debug].section; 14344 Elf_Internal_Shdr * sec; 14345 Filedata * filedata = (Filedata *) data; 14346 14347 /* Without section headers we cannot find any sections. */ 14348 if (filedata->section_headers == NULL) 14349 return FALSE; 14350 14351 if (filedata->string_table == NULL 14352 && filedata->file_header.e_shstrndx != SHN_UNDEF 14353 && filedata->file_header.e_shstrndx < filedata->file_header.e_shnum) 14354 { 14355 Elf_Internal_Shdr * strs; 14356 14357 /* Read in the string table, so that we have section names to scan. */ 14358 strs = filedata->section_headers + filedata->file_header.e_shstrndx; 14359 14360 if (strs != NULL && strs->sh_size != 0) 14361 { 14362 filedata->string_table 14363 = (char *) get_data (NULL, filedata, strs->sh_offset, 14364 1, strs->sh_size, _("string table")); 14365 14366 filedata->string_table_length 14367 = filedata->string_table != NULL ? strs->sh_size : 0; 14368 } 14369 } 14370 14371 /* Locate the debug section. */ 14372 sec = find_section_in_set (filedata, section->uncompressed_name, section_subset); 14373 if (sec != NULL) 14374 section->name = section->uncompressed_name; 14375 else 14376 { 14377 sec = find_section_in_set (filedata, section->compressed_name, section_subset); 14378 if (sec != NULL) 14379 section->name = section->compressed_name; 14380 } 14381 if (sec == NULL) 14382 return FALSE; 14383 14384 /* If we're loading from a subset of sections, and we've loaded 14385 a section matching this name before, it's likely that it's a 14386 different one. */ 14387 if (section_subset != NULL) 14388 free_debug_section (debug); 14389 14390 return load_specific_debug_section (debug, sec, data); 14391 } 14392 14393 void 14394 free_debug_section (enum dwarf_section_display_enum debug) 14395 { 14396 struct dwarf_section * section = &debug_displays [debug].section; 14397 14398 if (section->start == NULL) 14399 return; 14400 14401 free ((char *) section->start); 14402 section->start = NULL; 14403 section->address = 0; 14404 section->size = 0; 14405 14406 if (section->reloc_info != NULL) 14407 { 14408 free (section->reloc_info); 14409 section->reloc_info = NULL; 14410 section->num_relocs = 0; 14411 } 14412 } 14413 14414 static bfd_boolean 14415 display_debug_section (int shndx, Elf_Internal_Shdr * section, Filedata * filedata) 14416 { 14417 char * name = SECTION_NAME (section); 14418 const char * print_name = printable_section_name (filedata, section); 14419 bfd_size_type length; 14420 bfd_boolean result = TRUE; 14421 int i; 14422 14423 length = section->sh_size; 14424 if (length == 0) 14425 { 14426 printf (_("\nSection '%s' has no debugging data.\n"), print_name); 14427 return TRUE; 14428 } 14429 if (section->sh_type == SHT_NOBITS) 14430 { 14431 /* There is no point in dumping the contents of a debugging section 14432 which has the NOBITS type - the bits in the file will be random. 14433 This can happen when a file containing a .eh_frame section is 14434 stripped with the --only-keep-debug command line option. */ 14435 printf (_("section '%s' has the NOBITS type - its contents are unreliable.\n"), 14436 print_name); 14437 return FALSE; 14438 } 14439 14440 if (const_strneq (name, ".gnu.linkonce.wi.")) 14441 name = ".debug_info"; 14442 14443 /* See if we know how to display the contents of this section. */ 14444 for (i = 0; i < max; i++) 14445 { 14446 enum dwarf_section_display_enum id = (enum dwarf_section_display_enum) i; 14447 struct dwarf_section_display * display = debug_displays + i; 14448 struct dwarf_section * sec = & display->section; 14449 14450 if (streq (sec->uncompressed_name, name) 14451 || (id == line && const_strneq (name, ".debug_line.")) 14452 || streq (sec->compressed_name, name)) 14453 { 14454 bfd_boolean secondary = (section != find_section (filedata, name)); 14455 14456 if (secondary) 14457 free_debug_section (id); 14458 14459 if (i == line && const_strneq (name, ".debug_line.")) 14460 sec->name = name; 14461 else if (streq (sec->uncompressed_name, name)) 14462 sec->name = sec->uncompressed_name; 14463 else 14464 sec->name = sec->compressed_name; 14465 14466 if (load_specific_debug_section (id, section, filedata)) 14467 { 14468 /* If this debug section is part of a CU/TU set in a .dwp file, 14469 restrict load_debug_section to the sections in that set. */ 14470 section_subset = find_cu_tu_set (filedata, shndx); 14471 14472 result &= display->display (sec, filedata); 14473 14474 section_subset = NULL; 14475 14476 if (secondary || (id != info && id != abbrev)) 14477 free_debug_section (id); 14478 } 14479 break; 14480 } 14481 } 14482 14483 if (i == max) 14484 { 14485 printf (_("Unrecognized debug section: %s\n"), print_name); 14486 result = FALSE; 14487 } 14488 14489 return result; 14490 } 14491 14492 /* Set DUMP_SECTS for all sections where dumps were requested 14493 based on section name. */ 14494 14495 static void 14496 initialise_dumps_byname (Filedata * filedata) 14497 { 14498 struct dump_list_entry * cur; 14499 14500 for (cur = dump_sects_byname; cur; cur = cur->next) 14501 { 14502 unsigned int i; 14503 bfd_boolean any = FALSE; 14504 14505 for (i = 0; i < filedata->file_header.e_shnum; i++) 14506 if (streq (SECTION_NAME (filedata->section_headers + i), cur->name)) 14507 { 14508 request_dump_bynumber (filedata, i, cur->type); 14509 any = TRUE; 14510 } 14511 14512 if (!any) 14513 warn (_("Section '%s' was not dumped because it does not exist!\n"), 14514 cur->name); 14515 } 14516 } 14517 14518 static bfd_boolean 14519 process_section_contents (Filedata * filedata) 14520 { 14521 Elf_Internal_Shdr * section; 14522 unsigned int i; 14523 bfd_boolean res = TRUE; 14524 14525 if (! do_dump) 14526 return TRUE; 14527 14528 initialise_dumps_byname (filedata); 14529 14530 for (i = 0, section = filedata->section_headers; 14531 i < filedata->file_header.e_shnum && i < filedata->num_dump_sects; 14532 i++, section++) 14533 { 14534 dump_type dump = filedata->dump_sects[i]; 14535 14536 #ifdef SUPPORT_DISASSEMBLY 14537 if (dump & DISASS_DUMP) 14538 { 14539 if (! disassemble_section (section, filedata)) 14540 res = FALSE; 14541 } 14542 #endif 14543 if (dump & HEX_DUMP) 14544 { 14545 if (! dump_section_as_bytes (section, filedata, FALSE)) 14546 res = FALSE; 14547 } 14548 14549 if (dump & RELOC_DUMP) 14550 { 14551 if (! dump_section_as_bytes (section, filedata, TRUE)) 14552 res = FALSE; 14553 } 14554 14555 if (dump & STRING_DUMP) 14556 { 14557 if (! dump_section_as_strings (section, filedata)) 14558 res = FALSE; 14559 } 14560 14561 if (dump & DEBUG_DUMP) 14562 { 14563 if (! display_debug_section (i, section, filedata)) 14564 res = FALSE; 14565 } 14566 14567 if (dump & CTF_DUMP) 14568 { 14569 if (! dump_section_as_ctf (section, filedata)) 14570 res = FALSE; 14571 } 14572 } 14573 14574 /* Check to see if the user requested a 14575 dump of a section that does not exist. */ 14576 while (i < filedata->num_dump_sects) 14577 { 14578 if (filedata->dump_sects[i]) 14579 { 14580 warn (_("Section %d was not dumped because it does not exist!\n"), i); 14581 res = FALSE; 14582 } 14583 i++; 14584 } 14585 14586 return res; 14587 } 14588 14589 static void 14590 process_mips_fpe_exception (int mask) 14591 { 14592 if (mask) 14593 { 14594 bfd_boolean first = TRUE; 14595 14596 if (mask & OEX_FPU_INEX) 14597 fputs ("INEX", stdout), first = FALSE; 14598 if (mask & OEX_FPU_UFLO) 14599 printf ("%sUFLO", first ? "" : "|"), first = FALSE; 14600 if (mask & OEX_FPU_OFLO) 14601 printf ("%sOFLO", first ? "" : "|"), first = FALSE; 14602 if (mask & OEX_FPU_DIV0) 14603 printf ("%sDIV0", first ? "" : "|"), first = FALSE; 14604 if (mask & OEX_FPU_INVAL) 14605 printf ("%sINVAL", first ? "" : "|"); 14606 } 14607 else 14608 fputs ("0", stdout); 14609 } 14610 14611 /* Display's the value of TAG at location P. If TAG is 14612 greater than 0 it is assumed to be an unknown tag, and 14613 a message is printed to this effect. Otherwise it is 14614 assumed that a message has already been printed. 14615 14616 If the bottom bit of TAG is set it assumed to have a 14617 string value, otherwise it is assumed to have an integer 14618 value. 14619 14620 Returns an updated P pointing to the first unread byte 14621 beyond the end of TAG's value. 14622 14623 Reads at or beyond END will not be made. */ 14624 14625 static unsigned char * 14626 display_tag_value (signed int tag, 14627 unsigned char * p, 14628 const unsigned char * const end) 14629 { 14630 unsigned long val; 14631 14632 if (tag > 0) 14633 printf (" Tag_unknown_%d: ", tag); 14634 14635 if (p >= end) 14636 { 14637 warn (_("<corrupt tag>\n")); 14638 } 14639 else if (tag & 1) 14640 { 14641 /* PR 17531 file: 027-19978-0.004. */ 14642 size_t maxlen = (end - p) - 1; 14643 14644 putchar ('"'); 14645 if (maxlen > 0) 14646 { 14647 print_symbol ((int) maxlen, (const char *) p); 14648 p += strnlen ((char *) p, maxlen) + 1; 14649 } 14650 else 14651 { 14652 printf (_("<corrupt string tag>")); 14653 p = (unsigned char *) end; 14654 } 14655 printf ("\"\n"); 14656 } 14657 else 14658 { 14659 READ_ULEB (val, p, end); 14660 printf ("%ld (0x%lx)\n", val, val); 14661 } 14662 14663 assert (p <= end); 14664 return p; 14665 } 14666 14667 /* ARC ABI attributes section. */ 14668 14669 static unsigned char * 14670 display_arc_attribute (unsigned char * p, 14671 const unsigned char * const end) 14672 { 14673 unsigned int tag; 14674 unsigned int val; 14675 14676 READ_ULEB (tag, p, end); 14677 14678 switch (tag) 14679 { 14680 case Tag_ARC_PCS_config: 14681 READ_ULEB (val, p, end); 14682 printf (" Tag_ARC_PCS_config: "); 14683 switch (val) 14684 { 14685 case 0: 14686 printf (_("Absent/Non standard\n")); 14687 break; 14688 case 1: 14689 printf (_("Bare metal/mwdt\n")); 14690 break; 14691 case 2: 14692 printf (_("Bare metal/newlib\n")); 14693 break; 14694 case 3: 14695 printf (_("Linux/uclibc\n")); 14696 break; 14697 case 4: 14698 printf (_("Linux/glibc\n")); 14699 break; 14700 default: 14701 printf (_("Unknown\n")); 14702 break; 14703 } 14704 break; 14705 14706 case Tag_ARC_CPU_base: 14707 READ_ULEB (val, p, end); 14708 printf (" Tag_ARC_CPU_base: "); 14709 switch (val) 14710 { 14711 default: 14712 case TAG_CPU_NONE: 14713 printf (_("Absent\n")); 14714 break; 14715 case TAG_CPU_ARC6xx: 14716 printf ("ARC6xx\n"); 14717 break; 14718 case TAG_CPU_ARC7xx: 14719 printf ("ARC7xx\n"); 14720 break; 14721 case TAG_CPU_ARCEM: 14722 printf ("ARCEM\n"); 14723 break; 14724 case TAG_CPU_ARCHS: 14725 printf ("ARCHS\n"); 14726 break; 14727 } 14728 break; 14729 14730 case Tag_ARC_CPU_variation: 14731 READ_ULEB (val, p, end); 14732 printf (" Tag_ARC_CPU_variation: "); 14733 switch (val) 14734 { 14735 default: 14736 if (val > 0 && val < 16) 14737 printf ("Core%d\n", val); 14738 else 14739 printf ("Unknown\n"); 14740 break; 14741 14742 case 0: 14743 printf (_("Absent\n")); 14744 break; 14745 } 14746 break; 14747 14748 case Tag_ARC_CPU_name: 14749 printf (" Tag_ARC_CPU_name: "); 14750 p = display_tag_value (-1, p, end); 14751 break; 14752 14753 case Tag_ARC_ABI_rf16: 14754 READ_ULEB (val, p, end); 14755 printf (" Tag_ARC_ABI_rf16: %s\n", val ? _("yes") : _("no")); 14756 break; 14757 14758 case Tag_ARC_ABI_osver: 14759 READ_ULEB (val, p, end); 14760 printf (" Tag_ARC_ABI_osver: v%d\n", val); 14761 break; 14762 14763 case Tag_ARC_ABI_pic: 14764 case Tag_ARC_ABI_sda: 14765 READ_ULEB (val, p, end); 14766 printf (tag == Tag_ARC_ABI_sda ? " Tag_ARC_ABI_sda: " 14767 : " Tag_ARC_ABI_pic: "); 14768 switch (val) 14769 { 14770 case 0: 14771 printf (_("Absent\n")); 14772 break; 14773 case 1: 14774 printf ("MWDT\n"); 14775 break; 14776 case 2: 14777 printf ("GNU\n"); 14778 break; 14779 default: 14780 printf (_("Unknown\n")); 14781 break; 14782 } 14783 break; 14784 14785 case Tag_ARC_ABI_tls: 14786 READ_ULEB (val, p, end); 14787 printf (" Tag_ARC_ABI_tls: %s\n", val ? "r25": "none"); 14788 break; 14789 14790 case Tag_ARC_ABI_enumsize: 14791 READ_ULEB (val, p, end); 14792 printf (" Tag_ARC_ABI_enumsize: %s\n", val ? _("default") : 14793 _("smallest")); 14794 break; 14795 14796 case Tag_ARC_ABI_exceptions: 14797 READ_ULEB (val, p, end); 14798 printf (" Tag_ARC_ABI_exceptions: %s\n", val ? _("OPTFP") 14799 : _("default")); 14800 break; 14801 14802 case Tag_ARC_ABI_double_size: 14803 READ_ULEB (val, p, end); 14804 printf (" Tag_ARC_ABI_double_size: %d\n", val); 14805 break; 14806 14807 case Tag_ARC_ISA_config: 14808 printf (" Tag_ARC_ISA_config: "); 14809 p = display_tag_value (-1, p, end); 14810 break; 14811 14812 case Tag_ARC_ISA_apex: 14813 printf (" Tag_ARC_ISA_apex: "); 14814 p = display_tag_value (-1, p, end); 14815 break; 14816 14817 case Tag_ARC_ISA_mpy_option: 14818 READ_ULEB (val, p, end); 14819 printf (" Tag_ARC_ISA_mpy_option: %d\n", val); 14820 break; 14821 14822 case Tag_ARC_ATR_version: 14823 READ_ULEB (val, p, end); 14824 printf (" Tag_ARC_ATR_version: %d\n", val); 14825 break; 14826 14827 default: 14828 return display_tag_value (tag & 1, p, end); 14829 } 14830 14831 return p; 14832 } 14833 14834 /* ARM EABI attributes section. */ 14835 typedef struct 14836 { 14837 unsigned int tag; 14838 const char * name; 14839 /* 0 = special, 1 = string, 2 = uleb123, > 0x80 == table lookup. */ 14840 unsigned int type; 14841 const char ** table; 14842 } arm_attr_public_tag; 14843 14844 static const char * arm_attr_tag_CPU_arch[] = 14845 {"Pre-v4", "v4", "v4T", "v5T", "v5TE", "v5TEJ", "v6", "v6KZ", "v6T2", 14846 "v6K", "v7", "v6-M", "v6S-M", "v7E-M", "v8", "v8-R", "v8-M.baseline", 14847 "v8-M.mainline", "", "", "", "v8.1-M.mainline"}; 14848 static const char * arm_attr_tag_ARM_ISA_use[] = {"No", "Yes"}; 14849 static const char * arm_attr_tag_THUMB_ISA_use[] = 14850 {"No", "Thumb-1", "Thumb-2", "Yes"}; 14851 static const char * arm_attr_tag_FP_arch[] = 14852 {"No", "VFPv1", "VFPv2", "VFPv3", "VFPv3-D16", "VFPv4", "VFPv4-D16", 14853 "FP for ARMv8", "FPv5/FP-D16 for ARMv8"}; 14854 static const char * arm_attr_tag_WMMX_arch[] = {"No", "WMMXv1", "WMMXv2"}; 14855 static const char * arm_attr_tag_Advanced_SIMD_arch[] = 14856 {"No", "NEONv1", "NEONv1 with Fused-MAC", "NEON for ARMv8", 14857 "NEON for ARMv8.1"}; 14858 static const char * arm_attr_tag_PCS_config[] = 14859 {"None", "Bare platform", "Linux application", "Linux DSO", "PalmOS 2004", 14860 "PalmOS (reserved)", "SymbianOS 2004", "SymbianOS (reserved)"}; 14861 static const char * arm_attr_tag_ABI_PCS_R9_use[] = 14862 {"V6", "SB", "TLS", "Unused"}; 14863 static const char * arm_attr_tag_ABI_PCS_RW_data[] = 14864 {"Absolute", "PC-relative", "SB-relative", "None"}; 14865 static const char * arm_attr_tag_ABI_PCS_RO_data[] = 14866 {"Absolute", "PC-relative", "None"}; 14867 static const char * arm_attr_tag_ABI_PCS_GOT_use[] = 14868 {"None", "direct", "GOT-indirect"}; 14869 static const char * arm_attr_tag_ABI_PCS_wchar_t[] = 14870 {"None", "??? 1", "2", "??? 3", "4"}; 14871 static const char * arm_attr_tag_ABI_FP_rounding[] = {"Unused", "Needed"}; 14872 static const char * arm_attr_tag_ABI_FP_denormal[] = 14873 {"Unused", "Needed", "Sign only"}; 14874 static const char * arm_attr_tag_ABI_FP_exceptions[] = {"Unused", "Needed"}; 14875 static const char * arm_attr_tag_ABI_FP_user_exceptions[] = {"Unused", "Needed"}; 14876 static const char * arm_attr_tag_ABI_FP_number_model[] = 14877 {"Unused", "Finite", "RTABI", "IEEE 754"}; 14878 static const char * arm_attr_tag_ABI_enum_size[] = 14879 {"Unused", "small", "int", "forced to int"}; 14880 static const char * arm_attr_tag_ABI_HardFP_use[] = 14881 {"As Tag_FP_arch", "SP only", "Reserved", "Deprecated"}; 14882 static const char * arm_attr_tag_ABI_VFP_args[] = 14883 {"AAPCS", "VFP registers", "custom", "compatible"}; 14884 static const char * arm_attr_tag_ABI_WMMX_args[] = 14885 {"AAPCS", "WMMX registers", "custom"}; 14886 static const char * arm_attr_tag_ABI_optimization_goals[] = 14887 {"None", "Prefer Speed", "Aggressive Speed", "Prefer Size", 14888 "Aggressive Size", "Prefer Debug", "Aggressive Debug"}; 14889 static const char * arm_attr_tag_ABI_FP_optimization_goals[] = 14890 {"None", "Prefer Speed", "Aggressive Speed", "Prefer Size", 14891 "Aggressive Size", "Prefer Accuracy", "Aggressive Accuracy"}; 14892 static const char * arm_attr_tag_CPU_unaligned_access[] = {"None", "v6"}; 14893 static const char * arm_attr_tag_FP_HP_extension[] = 14894 {"Not Allowed", "Allowed"}; 14895 static const char * arm_attr_tag_ABI_FP_16bit_format[] = 14896 {"None", "IEEE 754", "Alternative Format"}; 14897 static const char * arm_attr_tag_DSP_extension[] = 14898 {"Follow architecture", "Allowed"}; 14899 static const char * arm_attr_tag_MPextension_use[] = 14900 {"Not Allowed", "Allowed"}; 14901 static const char * arm_attr_tag_DIV_use[] = 14902 {"Allowed in Thumb-ISA, v7-R or v7-M", "Not allowed", 14903 "Allowed in v7-A with integer division extension"}; 14904 static const char * arm_attr_tag_T2EE_use[] = {"Not Allowed", "Allowed"}; 14905 static const char * arm_attr_tag_Virtualization_use[] = 14906 {"Not Allowed", "TrustZone", "Virtualization Extensions", 14907 "TrustZone and Virtualization Extensions"}; 14908 static const char * arm_attr_tag_MPextension_use_legacy[] = 14909 {"Not Allowed", "Allowed"}; 14910 14911 static const char * arm_attr_tag_MVE_arch[] = 14912 {"No MVE", "MVE Integer only", "MVE Integer and FP"}; 14913 14914 #define LOOKUP(id, name) \ 14915 {id, #name, 0x80 | ARRAY_SIZE(arm_attr_tag_##name), arm_attr_tag_##name} 14916 static arm_attr_public_tag arm_attr_public_tags[] = 14917 { 14918 {4, "CPU_raw_name", 1, NULL}, 14919 {5, "CPU_name", 1, NULL}, 14920 LOOKUP(6, CPU_arch), 14921 {7, "CPU_arch_profile", 0, NULL}, 14922 LOOKUP(8, ARM_ISA_use), 14923 LOOKUP(9, THUMB_ISA_use), 14924 LOOKUP(10, FP_arch), 14925 LOOKUP(11, WMMX_arch), 14926 LOOKUP(12, Advanced_SIMD_arch), 14927 LOOKUP(13, PCS_config), 14928 LOOKUP(14, ABI_PCS_R9_use), 14929 LOOKUP(15, ABI_PCS_RW_data), 14930 LOOKUP(16, ABI_PCS_RO_data), 14931 LOOKUP(17, ABI_PCS_GOT_use), 14932 LOOKUP(18, ABI_PCS_wchar_t), 14933 LOOKUP(19, ABI_FP_rounding), 14934 LOOKUP(20, ABI_FP_denormal), 14935 LOOKUP(21, ABI_FP_exceptions), 14936 LOOKUP(22, ABI_FP_user_exceptions), 14937 LOOKUP(23, ABI_FP_number_model), 14938 {24, "ABI_align_needed", 0, NULL}, 14939 {25, "ABI_align_preserved", 0, NULL}, 14940 LOOKUP(26, ABI_enum_size), 14941 LOOKUP(27, ABI_HardFP_use), 14942 LOOKUP(28, ABI_VFP_args), 14943 LOOKUP(29, ABI_WMMX_args), 14944 LOOKUP(30, ABI_optimization_goals), 14945 LOOKUP(31, ABI_FP_optimization_goals), 14946 {32, "compatibility", 0, NULL}, 14947 LOOKUP(34, CPU_unaligned_access), 14948 LOOKUP(36, FP_HP_extension), 14949 LOOKUP(38, ABI_FP_16bit_format), 14950 LOOKUP(42, MPextension_use), 14951 LOOKUP(44, DIV_use), 14952 LOOKUP(46, DSP_extension), 14953 LOOKUP(48, MVE_arch), 14954 {64, "nodefaults", 0, NULL}, 14955 {65, "also_compatible_with", 0, NULL}, 14956 LOOKUP(66, T2EE_use), 14957 {67, "conformance", 1, NULL}, 14958 LOOKUP(68, Virtualization_use), 14959 LOOKUP(70, MPextension_use_legacy) 14960 }; 14961 #undef LOOKUP 14962 14963 static unsigned char * 14964 display_arm_attribute (unsigned char * p, 14965 const unsigned char * const end) 14966 { 14967 unsigned int tag; 14968 unsigned int val; 14969 arm_attr_public_tag * attr; 14970 unsigned i; 14971 unsigned int type; 14972 14973 READ_ULEB (tag, p, end); 14974 attr = NULL; 14975 for (i = 0; i < ARRAY_SIZE (arm_attr_public_tags); i++) 14976 { 14977 if (arm_attr_public_tags[i].tag == tag) 14978 { 14979 attr = &arm_attr_public_tags[i]; 14980 break; 14981 } 14982 } 14983 14984 if (attr) 14985 { 14986 printf (" Tag_%s: ", attr->name); 14987 switch (attr->type) 14988 { 14989 case 0: 14990 switch (tag) 14991 { 14992 case 7: /* Tag_CPU_arch_profile. */ 14993 READ_ULEB (val, p, end); 14994 switch (val) 14995 { 14996 case 0: printf (_("None\n")); break; 14997 case 'A': printf (_("Application\n")); break; 14998 case 'R': printf (_("Realtime\n")); break; 14999 case 'M': printf (_("Microcontroller\n")); break; 15000 case 'S': printf (_("Application or Realtime\n")); break; 15001 default: printf ("??? (%d)\n", val); break; 15002 } 15003 break; 15004 15005 case 24: /* Tag_align_needed. */ 15006 READ_ULEB (val, p, end); 15007 switch (val) 15008 { 15009 case 0: printf (_("None\n")); break; 15010 case 1: printf (_("8-byte\n")); break; 15011 case 2: printf (_("4-byte\n")); break; 15012 case 3: printf ("??? 3\n"); break; 15013 default: 15014 if (val <= 12) 15015 printf (_("8-byte and up to %d-byte extended\n"), 15016 1 << val); 15017 else 15018 printf ("??? (%d)\n", val); 15019 break; 15020 } 15021 break; 15022 15023 case 25: /* Tag_align_preserved. */ 15024 READ_ULEB (val, p, end); 15025 switch (val) 15026 { 15027 case 0: printf (_("None\n")); break; 15028 case 1: printf (_("8-byte, except leaf SP\n")); break; 15029 case 2: printf (_("8-byte\n")); break; 15030 case 3: printf ("??? 3\n"); break; 15031 default: 15032 if (val <= 12) 15033 printf (_("8-byte and up to %d-byte extended\n"), 15034 1 << val); 15035 else 15036 printf ("??? (%d)\n", val); 15037 break; 15038 } 15039 break; 15040 15041 case 32: /* Tag_compatibility. */ 15042 { 15043 READ_ULEB (val, p, end); 15044 printf (_("flag = %d, vendor = "), val); 15045 if (p < end - 1) 15046 { 15047 size_t maxlen = (end - p) - 1; 15048 15049 print_symbol ((int) maxlen, (const char *) p); 15050 p += strnlen ((char *) p, maxlen) + 1; 15051 } 15052 else 15053 { 15054 printf (_("<corrupt>")); 15055 p = (unsigned char *) end; 15056 } 15057 putchar ('\n'); 15058 } 15059 break; 15060 15061 case 64: /* Tag_nodefaults. */ 15062 /* PR 17531: file: 001-505008-0.01. */ 15063 if (p < end) 15064 p++; 15065 printf (_("True\n")); 15066 break; 15067 15068 case 65: /* Tag_also_compatible_with. */ 15069 READ_ULEB (val, p, end); 15070 if (val == 6 /* Tag_CPU_arch. */) 15071 { 15072 READ_ULEB (val, p, end); 15073 if ((unsigned int) val >= ARRAY_SIZE (arm_attr_tag_CPU_arch)) 15074 printf ("??? (%d)\n", val); 15075 else 15076 printf ("%s\n", arm_attr_tag_CPU_arch[val]); 15077 } 15078 else 15079 printf ("???\n"); 15080 while (p < end && *(p++) != '\0' /* NUL terminator. */) 15081 ; 15082 break; 15083 15084 default: 15085 printf (_("<unknown: %d>\n"), tag); 15086 break; 15087 } 15088 return p; 15089 15090 case 1: 15091 return display_tag_value (-1, p, end); 15092 case 2: 15093 return display_tag_value (0, p, end); 15094 15095 default: 15096 assert (attr->type & 0x80); 15097 READ_ULEB (val, p, end); 15098 type = attr->type & 0x7f; 15099 if (val >= type) 15100 printf ("??? (%d)\n", val); 15101 else 15102 printf ("%s\n", attr->table[val]); 15103 return p; 15104 } 15105 } 15106 15107 return display_tag_value (tag, p, end); 15108 } 15109 15110 static unsigned char * 15111 display_gnu_attribute (unsigned char * p, 15112 unsigned char * (* display_proc_gnu_attribute) (unsigned char *, unsigned int, const unsigned char * const), 15113 const unsigned char * const end) 15114 { 15115 unsigned int tag; 15116 unsigned int val; 15117 15118 READ_ULEB (tag, p, end); 15119 15120 /* Tag_compatibility is the only generic GNU attribute defined at 15121 present. */ 15122 if (tag == 32) 15123 { 15124 READ_ULEB (val, p, end); 15125 15126 printf (_("flag = %d, vendor = "), val); 15127 if (p == end) 15128 { 15129 printf (_("<corrupt>\n")); 15130 warn (_("corrupt vendor attribute\n")); 15131 } 15132 else 15133 { 15134 if (p < end - 1) 15135 { 15136 size_t maxlen = (end - p) - 1; 15137 15138 print_symbol ((int) maxlen, (const char *) p); 15139 p += strnlen ((char *) p, maxlen) + 1; 15140 } 15141 else 15142 { 15143 printf (_("<corrupt>")); 15144 p = (unsigned char *) end; 15145 } 15146 putchar ('\n'); 15147 } 15148 return p; 15149 } 15150 15151 if ((tag & 2) == 0 && display_proc_gnu_attribute) 15152 return display_proc_gnu_attribute (p, tag, end); 15153 15154 return display_tag_value (tag, p, end); 15155 } 15156 15157 static unsigned char * 15158 display_power_gnu_attribute (unsigned char * p, 15159 unsigned int tag, 15160 const unsigned char * const end) 15161 { 15162 unsigned int val; 15163 15164 if (tag == Tag_GNU_Power_ABI_FP) 15165 { 15166 printf (" Tag_GNU_Power_ABI_FP: "); 15167 if (p == end) 15168 { 15169 printf (_("<corrupt>\n")); 15170 return p; 15171 } 15172 READ_ULEB (val, p, end); 15173 15174 if (val > 15) 15175 printf ("(%#x), ", val); 15176 15177 switch (val & 3) 15178 { 15179 case 0: 15180 printf (_("unspecified hard/soft float, ")); 15181 break; 15182 case 1: 15183 printf (_("hard float, ")); 15184 break; 15185 case 2: 15186 printf (_("soft float, ")); 15187 break; 15188 case 3: 15189 printf (_("single-precision hard float, ")); 15190 break; 15191 } 15192 15193 switch (val & 0xC) 15194 { 15195 case 0: 15196 printf (_("unspecified long double\n")); 15197 break; 15198 case 4: 15199 printf (_("128-bit IBM long double\n")); 15200 break; 15201 case 8: 15202 printf (_("64-bit long double\n")); 15203 break; 15204 case 12: 15205 printf (_("128-bit IEEE long double\n")); 15206 break; 15207 } 15208 return p; 15209 } 15210 15211 if (tag == Tag_GNU_Power_ABI_Vector) 15212 { 15213 printf (" Tag_GNU_Power_ABI_Vector: "); 15214 if (p == end) 15215 { 15216 printf (_("<corrupt>\n")); 15217 return p; 15218 } 15219 READ_ULEB (val, p, end); 15220 15221 if (val > 3) 15222 printf ("(%#x), ", val); 15223 15224 switch (val & 3) 15225 { 15226 case 0: 15227 printf (_("unspecified\n")); 15228 break; 15229 case 1: 15230 printf (_("generic\n")); 15231 break; 15232 case 2: 15233 printf ("AltiVec\n"); 15234 break; 15235 case 3: 15236 printf ("SPE\n"); 15237 break; 15238 } 15239 return p; 15240 } 15241 15242 if (tag == Tag_GNU_Power_ABI_Struct_Return) 15243 { 15244 printf (" Tag_GNU_Power_ABI_Struct_Return: "); 15245 if (p == end) 15246 { 15247 printf (_("<corrupt>\n")); 15248 return p; 15249 } 15250 READ_ULEB (val, p, end); 15251 15252 if (val > 2) 15253 printf ("(%#x), ", val); 15254 15255 switch (val & 3) 15256 { 15257 case 0: 15258 printf (_("unspecified\n")); 15259 break; 15260 case 1: 15261 printf ("r3/r4\n"); 15262 break; 15263 case 2: 15264 printf (_("memory\n")); 15265 break; 15266 case 3: 15267 printf ("???\n"); 15268 break; 15269 } 15270 return p; 15271 } 15272 15273 return display_tag_value (tag & 1, p, end); 15274 } 15275 15276 static unsigned char * 15277 display_s390_gnu_attribute (unsigned char * p, 15278 unsigned int tag, 15279 const unsigned char * const end) 15280 { 15281 unsigned int val; 15282 15283 if (tag == Tag_GNU_S390_ABI_Vector) 15284 { 15285 printf (" Tag_GNU_S390_ABI_Vector: "); 15286 READ_ULEB (val, p, end); 15287 15288 switch (val) 15289 { 15290 case 0: 15291 printf (_("any\n")); 15292 break; 15293 case 1: 15294 printf (_("software\n")); 15295 break; 15296 case 2: 15297 printf (_("hardware\n")); 15298 break; 15299 default: 15300 printf ("??? (%d)\n", val); 15301 break; 15302 } 15303 return p; 15304 } 15305 15306 return display_tag_value (tag & 1, p, end); 15307 } 15308 15309 static void 15310 display_sparc_hwcaps (unsigned int mask) 15311 { 15312 if (mask) 15313 { 15314 bfd_boolean first = TRUE; 15315 15316 if (mask & ELF_SPARC_HWCAP_MUL32) 15317 fputs ("mul32", stdout), first = FALSE; 15318 if (mask & ELF_SPARC_HWCAP_DIV32) 15319 printf ("%sdiv32", first ? "" : "|"), first = FALSE; 15320 if (mask & ELF_SPARC_HWCAP_FSMULD) 15321 printf ("%sfsmuld", first ? "" : "|"), first = FALSE; 15322 if (mask & ELF_SPARC_HWCAP_V8PLUS) 15323 printf ("%sv8plus", first ? "" : "|"), first = FALSE; 15324 if (mask & ELF_SPARC_HWCAP_POPC) 15325 printf ("%spopc", first ? "" : "|"), first = FALSE; 15326 if (mask & ELF_SPARC_HWCAP_VIS) 15327 printf ("%svis", first ? "" : "|"), first = FALSE; 15328 if (mask & ELF_SPARC_HWCAP_VIS2) 15329 printf ("%svis2", first ? "" : "|"), first = FALSE; 15330 if (mask & ELF_SPARC_HWCAP_ASI_BLK_INIT) 15331 printf ("%sASIBlkInit", first ? "" : "|"), first = FALSE; 15332 if (mask & ELF_SPARC_HWCAP_FMAF) 15333 printf ("%sfmaf", first ? "" : "|"), first = FALSE; 15334 if (mask & ELF_SPARC_HWCAP_VIS3) 15335 printf ("%svis3", first ? "" : "|"), first = FALSE; 15336 if (mask & ELF_SPARC_HWCAP_HPC) 15337 printf ("%shpc", first ? "" : "|"), first = FALSE; 15338 if (mask & ELF_SPARC_HWCAP_RANDOM) 15339 printf ("%srandom", first ? "" : "|"), first = FALSE; 15340 if (mask & ELF_SPARC_HWCAP_TRANS) 15341 printf ("%strans", first ? "" : "|"), first = FALSE; 15342 if (mask & ELF_SPARC_HWCAP_FJFMAU) 15343 printf ("%sfjfmau", first ? "" : "|"), first = FALSE; 15344 if (mask & ELF_SPARC_HWCAP_IMA) 15345 printf ("%sima", first ? "" : "|"), first = FALSE; 15346 if (mask & ELF_SPARC_HWCAP_ASI_CACHE_SPARING) 15347 printf ("%scspare", first ? "" : "|"), first = FALSE; 15348 } 15349 else 15350 fputc ('0', stdout); 15351 fputc ('\n', stdout); 15352 } 15353 15354 static void 15355 display_sparc_hwcaps2 (unsigned int mask) 15356 { 15357 if (mask) 15358 { 15359 bfd_boolean first = TRUE; 15360 15361 if (mask & ELF_SPARC_HWCAP2_FJATHPLUS) 15362 fputs ("fjathplus", stdout), first = FALSE; 15363 if (mask & ELF_SPARC_HWCAP2_VIS3B) 15364 printf ("%svis3b", first ? "" : "|"), first = FALSE; 15365 if (mask & ELF_SPARC_HWCAP2_ADP) 15366 printf ("%sadp", first ? "" : "|"), first = FALSE; 15367 if (mask & ELF_SPARC_HWCAP2_SPARC5) 15368 printf ("%ssparc5", first ? "" : "|"), first = FALSE; 15369 if (mask & ELF_SPARC_HWCAP2_MWAIT) 15370 printf ("%smwait", first ? "" : "|"), first = FALSE; 15371 if (mask & ELF_SPARC_HWCAP2_XMPMUL) 15372 printf ("%sxmpmul", first ? "" : "|"), first = FALSE; 15373 if (mask & ELF_SPARC_HWCAP2_XMONT) 15374 printf ("%sxmont2", first ? "" : "|"), first = FALSE; 15375 if (mask & ELF_SPARC_HWCAP2_NSEC) 15376 printf ("%snsec", first ? "" : "|"), first = FALSE; 15377 if (mask & ELF_SPARC_HWCAP2_FJATHHPC) 15378 printf ("%sfjathhpc", first ? "" : "|"), first = FALSE; 15379 if (mask & ELF_SPARC_HWCAP2_FJDES) 15380 printf ("%sfjdes", first ? "" : "|"), first = FALSE; 15381 if (mask & ELF_SPARC_HWCAP2_FJAES) 15382 printf ("%sfjaes", first ? "" : "|"), first = FALSE; 15383 } 15384 else 15385 fputc ('0', stdout); 15386 fputc ('\n', stdout); 15387 } 15388 15389 static unsigned char * 15390 display_sparc_gnu_attribute (unsigned char * p, 15391 unsigned int tag, 15392 const unsigned char * const end) 15393 { 15394 unsigned int val; 15395 15396 if (tag == Tag_GNU_Sparc_HWCAPS) 15397 { 15398 READ_ULEB (val, p, end); 15399 printf (" Tag_GNU_Sparc_HWCAPS: "); 15400 display_sparc_hwcaps (val); 15401 return p; 15402 } 15403 if (tag == Tag_GNU_Sparc_HWCAPS2) 15404 { 15405 READ_ULEB (val, p, end); 15406 printf (" Tag_GNU_Sparc_HWCAPS2: "); 15407 display_sparc_hwcaps2 (val); 15408 return p; 15409 } 15410 15411 return display_tag_value (tag, p, end); 15412 } 15413 15414 static void 15415 print_mips_fp_abi_value (unsigned int val) 15416 { 15417 switch (val) 15418 { 15419 case Val_GNU_MIPS_ABI_FP_ANY: 15420 printf (_("Hard or soft float\n")); 15421 break; 15422 case Val_GNU_MIPS_ABI_FP_DOUBLE: 15423 printf (_("Hard float (double precision)\n")); 15424 break; 15425 case Val_GNU_MIPS_ABI_FP_SINGLE: 15426 printf (_("Hard float (single precision)\n")); 15427 break; 15428 case Val_GNU_MIPS_ABI_FP_SOFT: 15429 printf (_("Soft float\n")); 15430 break; 15431 case Val_GNU_MIPS_ABI_FP_OLD_64: 15432 printf (_("Hard float (MIPS32r2 64-bit FPU 12 callee-saved)\n")); 15433 break; 15434 case Val_GNU_MIPS_ABI_FP_XX: 15435 printf (_("Hard float (32-bit CPU, Any FPU)\n")); 15436 break; 15437 case Val_GNU_MIPS_ABI_FP_64: 15438 printf (_("Hard float (32-bit CPU, 64-bit FPU)\n")); 15439 break; 15440 case Val_GNU_MIPS_ABI_FP_64A: 15441 printf (_("Hard float compat (32-bit CPU, 64-bit FPU)\n")); 15442 break; 15443 case Val_GNU_MIPS_ABI_FP_NAN2008: 15444 printf (_("NaN 2008 compatibility\n")); 15445 break; 15446 default: 15447 printf ("??? (%d)\n", val); 15448 break; 15449 } 15450 } 15451 15452 static unsigned char * 15453 display_mips_gnu_attribute (unsigned char * p, 15454 unsigned int tag, 15455 const unsigned char * const end) 15456 { 15457 if (tag == Tag_GNU_MIPS_ABI_FP) 15458 { 15459 unsigned int val; 15460 15461 printf (" Tag_GNU_MIPS_ABI_FP: "); 15462 READ_ULEB (val, p, end); 15463 print_mips_fp_abi_value (val); 15464 return p; 15465 } 15466 15467 if (tag == Tag_GNU_MIPS_ABI_MSA) 15468 { 15469 unsigned int val; 15470 15471 printf (" Tag_GNU_MIPS_ABI_MSA: "); 15472 READ_ULEB (val, p, end); 15473 15474 switch (val) 15475 { 15476 case Val_GNU_MIPS_ABI_MSA_ANY: 15477 printf (_("Any MSA or not\n")); 15478 break; 15479 case Val_GNU_MIPS_ABI_MSA_128: 15480 printf (_("128-bit MSA\n")); 15481 break; 15482 default: 15483 printf ("??? (%d)\n", val); 15484 break; 15485 } 15486 return p; 15487 } 15488 15489 return display_tag_value (tag & 1, p, end); 15490 } 15491 15492 static unsigned char * 15493 display_tic6x_attribute (unsigned char * p, 15494 const unsigned char * const end) 15495 { 15496 unsigned int tag; 15497 unsigned int val; 15498 15499 READ_ULEB (tag, p, end); 15500 15501 switch (tag) 15502 { 15503 case Tag_ISA: 15504 printf (" Tag_ISA: "); 15505 READ_ULEB (val, p, end); 15506 15507 switch (val) 15508 { 15509 case C6XABI_Tag_ISA_none: 15510 printf (_("None\n")); 15511 break; 15512 case C6XABI_Tag_ISA_C62X: 15513 printf ("C62x\n"); 15514 break; 15515 case C6XABI_Tag_ISA_C67X: 15516 printf ("C67x\n"); 15517 break; 15518 case C6XABI_Tag_ISA_C67XP: 15519 printf ("C67x+\n"); 15520 break; 15521 case C6XABI_Tag_ISA_C64X: 15522 printf ("C64x\n"); 15523 break; 15524 case C6XABI_Tag_ISA_C64XP: 15525 printf ("C64x+\n"); 15526 break; 15527 case C6XABI_Tag_ISA_C674X: 15528 printf ("C674x\n"); 15529 break; 15530 default: 15531 printf ("??? (%d)\n", val); 15532 break; 15533 } 15534 return p; 15535 15536 case Tag_ABI_wchar_t: 15537 printf (" Tag_ABI_wchar_t: "); 15538 READ_ULEB (val, p, end); 15539 switch (val) 15540 { 15541 case 0: 15542 printf (_("Not used\n")); 15543 break; 15544 case 1: 15545 printf (_("2 bytes\n")); 15546 break; 15547 case 2: 15548 printf (_("4 bytes\n")); 15549 break; 15550 default: 15551 printf ("??? (%d)\n", val); 15552 break; 15553 } 15554 return p; 15555 15556 case Tag_ABI_stack_align_needed: 15557 printf (" Tag_ABI_stack_align_needed: "); 15558 READ_ULEB (val, p, end); 15559 switch (val) 15560 { 15561 case 0: 15562 printf (_("8-byte\n")); 15563 break; 15564 case 1: 15565 printf (_("16-byte\n")); 15566 break; 15567 default: 15568 printf ("??? (%d)\n", val); 15569 break; 15570 } 15571 return p; 15572 15573 case Tag_ABI_stack_align_preserved: 15574 READ_ULEB (val, p, end); 15575 printf (" Tag_ABI_stack_align_preserved: "); 15576 switch (val) 15577 { 15578 case 0: 15579 printf (_("8-byte\n")); 15580 break; 15581 case 1: 15582 printf (_("16-byte\n")); 15583 break; 15584 default: 15585 printf ("??? (%d)\n", val); 15586 break; 15587 } 15588 return p; 15589 15590 case Tag_ABI_DSBT: 15591 READ_ULEB (val, p, end); 15592 printf (" Tag_ABI_DSBT: "); 15593 switch (val) 15594 { 15595 case 0: 15596 printf (_("DSBT addressing not used\n")); 15597 break; 15598 case 1: 15599 printf (_("DSBT addressing used\n")); 15600 break; 15601 default: 15602 printf ("??? (%d)\n", val); 15603 break; 15604 } 15605 return p; 15606 15607 case Tag_ABI_PID: 15608 READ_ULEB (val, p, end); 15609 printf (" Tag_ABI_PID: "); 15610 switch (val) 15611 { 15612 case 0: 15613 printf (_("Data addressing position-dependent\n")); 15614 break; 15615 case 1: 15616 printf (_("Data addressing position-independent, GOT near DP\n")); 15617 break; 15618 case 2: 15619 printf (_("Data addressing position-independent, GOT far from DP\n")); 15620 break; 15621 default: 15622 printf ("??? (%d)\n", val); 15623 break; 15624 } 15625 return p; 15626 15627 case Tag_ABI_PIC: 15628 READ_ULEB (val, p, end); 15629 printf (" Tag_ABI_PIC: "); 15630 switch (val) 15631 { 15632 case 0: 15633 printf (_("Code addressing position-dependent\n")); 15634 break; 15635 case 1: 15636 printf (_("Code addressing position-independent\n")); 15637 break; 15638 default: 15639 printf ("??? (%d)\n", val); 15640 break; 15641 } 15642 return p; 15643 15644 case Tag_ABI_array_object_alignment: 15645 READ_ULEB (val, p, end); 15646 printf (" Tag_ABI_array_object_alignment: "); 15647 switch (val) 15648 { 15649 case 0: 15650 printf (_("8-byte\n")); 15651 break; 15652 case 1: 15653 printf (_("4-byte\n")); 15654 break; 15655 case 2: 15656 printf (_("16-byte\n")); 15657 break; 15658 default: 15659 printf ("??? (%d)\n", val); 15660 break; 15661 } 15662 return p; 15663 15664 case Tag_ABI_array_object_align_expected: 15665 READ_ULEB (val, p, end); 15666 printf (" Tag_ABI_array_object_align_expected: "); 15667 switch (val) 15668 { 15669 case 0: 15670 printf (_("8-byte\n")); 15671 break; 15672 case 1: 15673 printf (_("4-byte\n")); 15674 break; 15675 case 2: 15676 printf (_("16-byte\n")); 15677 break; 15678 default: 15679 printf ("??? (%d)\n", val); 15680 break; 15681 } 15682 return p; 15683 15684 case Tag_ABI_compatibility: 15685 { 15686 READ_ULEB (val, p, end); 15687 printf (" Tag_ABI_compatibility: "); 15688 printf (_("flag = %d, vendor = "), val); 15689 if (p < end - 1) 15690 { 15691 size_t maxlen = (end - p) - 1; 15692 15693 print_symbol ((int) maxlen, (const char *) p); 15694 p += strnlen ((char *) p, maxlen) + 1; 15695 } 15696 else 15697 { 15698 printf (_("<corrupt>")); 15699 p = (unsigned char *) end; 15700 } 15701 putchar ('\n'); 15702 return p; 15703 } 15704 15705 case Tag_ABI_conformance: 15706 { 15707 printf (" Tag_ABI_conformance: \""); 15708 if (p < end - 1) 15709 { 15710 size_t maxlen = (end - p) - 1; 15711 15712 print_symbol ((int) maxlen, (const char *) p); 15713 p += strnlen ((char *) p, maxlen) + 1; 15714 } 15715 else 15716 { 15717 printf (_("<corrupt>")); 15718 p = (unsigned char *) end; 15719 } 15720 printf ("\"\n"); 15721 return p; 15722 } 15723 } 15724 15725 return display_tag_value (tag, p, end); 15726 } 15727 15728 static void 15729 display_raw_attribute (unsigned char * p, unsigned char const * const end) 15730 { 15731 unsigned long addr = 0; 15732 size_t bytes = end - p; 15733 15734 assert (end >= p); 15735 while (bytes) 15736 { 15737 int j; 15738 int k; 15739 int lbytes = (bytes > 16 ? 16 : bytes); 15740 15741 printf (" 0x%8.8lx ", addr); 15742 15743 for (j = 0; j < 16; j++) 15744 { 15745 if (j < lbytes) 15746 printf ("%2.2x", p[j]); 15747 else 15748 printf (" "); 15749 15750 if ((j & 3) == 3) 15751 printf (" "); 15752 } 15753 15754 for (j = 0; j < lbytes; j++) 15755 { 15756 k = p[j]; 15757 if (k >= ' ' && k < 0x7f) 15758 printf ("%c", k); 15759 else 15760 printf ("."); 15761 } 15762 15763 putchar ('\n'); 15764 15765 p += lbytes; 15766 bytes -= lbytes; 15767 addr += lbytes; 15768 } 15769 15770 putchar ('\n'); 15771 } 15772 15773 static unsigned char * 15774 display_msp430x_attribute (unsigned char * p, 15775 const unsigned char * const end) 15776 { 15777 unsigned int val; 15778 unsigned int tag; 15779 15780 READ_ULEB (tag, p, end); 15781 15782 switch (tag) 15783 { 15784 case OFBA_MSPABI_Tag_ISA: 15785 printf (" Tag_ISA: "); 15786 READ_ULEB (val, p, end); 15787 switch (val) 15788 { 15789 case 0: printf (_("None\n")); break; 15790 case 1: printf (_("MSP430\n")); break; 15791 case 2: printf (_("MSP430X\n")); break; 15792 default: printf ("??? (%d)\n", val); break; 15793 } 15794 break; 15795 15796 case OFBA_MSPABI_Tag_Code_Model: 15797 printf (" Tag_Code_Model: "); 15798 READ_ULEB (val, p, end); 15799 switch (val) 15800 { 15801 case 0: printf (_("None\n")); break; 15802 case 1: printf (_("Small\n")); break; 15803 case 2: printf (_("Large\n")); break; 15804 default: printf ("??? (%d)\n", val); break; 15805 } 15806 break; 15807 15808 case OFBA_MSPABI_Tag_Data_Model: 15809 printf (" Tag_Data_Model: "); 15810 READ_ULEB (val, p, end); 15811 switch (val) 15812 { 15813 case 0: printf (_("None\n")); break; 15814 case 1: printf (_("Small\n")); break; 15815 case 2: printf (_("Large\n")); break; 15816 case 3: printf (_("Restricted Large\n")); break; 15817 default: printf ("??? (%d)\n", val); break; 15818 } 15819 break; 15820 15821 default: 15822 printf (_(" <unknown tag %d>: "), tag); 15823 15824 if (tag & 1) 15825 { 15826 putchar ('"'); 15827 if (p < end - 1) 15828 { 15829 size_t maxlen = (end - p) - 1; 15830 15831 print_symbol ((int) maxlen, (const char *) p); 15832 p += strnlen ((char *) p, maxlen) + 1; 15833 } 15834 else 15835 { 15836 printf (_("<corrupt>")); 15837 p = (unsigned char *) end; 15838 } 15839 printf ("\"\n"); 15840 } 15841 else 15842 { 15843 READ_ULEB (val, p, end); 15844 printf ("%d (0x%x)\n", val, val); 15845 } 15846 break; 15847 } 15848 15849 assert (p <= end); 15850 return p; 15851 } 15852 15853 static unsigned char * 15854 display_msp430_gnu_attribute (unsigned char * p, 15855 unsigned int tag, 15856 const unsigned char * const end) 15857 { 15858 if (tag == Tag_GNU_MSP430_Data_Region) 15859 { 15860 unsigned int val; 15861 15862 printf (" Tag_GNU_MSP430_Data_Region: "); 15863 READ_ULEB (val, p, end); 15864 15865 switch (val) 15866 { 15867 case Val_GNU_MSP430_Data_Region_Any: 15868 printf (_("Any Region\n")); 15869 break; 15870 case Val_GNU_MSP430_Data_Region_Lower: 15871 printf (_("Lower Region Only\n")); 15872 break; 15873 default: 15874 printf ("??? (%u)\n", val); 15875 } 15876 return p; 15877 } 15878 return display_tag_value (tag & 1, p, end); 15879 } 15880 15881 struct riscv_attr_tag_t { 15882 const char *name; 15883 unsigned int tag; 15884 }; 15885 15886 static struct riscv_attr_tag_t riscv_attr_tag[] = 15887 { 15888 #define T(tag) {"Tag_RISCV_" #tag, Tag_RISCV_##tag} 15889 T(arch), 15890 T(priv_spec), 15891 T(priv_spec_minor), 15892 T(priv_spec_revision), 15893 T(unaligned_access), 15894 T(stack_align), 15895 #undef T 15896 }; 15897 15898 static unsigned char * 15899 display_riscv_attribute (unsigned char *p, 15900 const unsigned char * const end) 15901 { 15902 unsigned int val; 15903 unsigned int tag; 15904 struct riscv_attr_tag_t *attr = NULL; 15905 unsigned i; 15906 15907 READ_ULEB (tag, p, end); 15908 15909 /* Find the name of attribute. */ 15910 for (i = 0; i < ARRAY_SIZE (riscv_attr_tag); i++) 15911 { 15912 if (riscv_attr_tag[i].tag == tag) 15913 { 15914 attr = &riscv_attr_tag[i]; 15915 break; 15916 } 15917 } 15918 15919 if (attr) 15920 printf (" %s: ", attr->name); 15921 else 15922 return display_tag_value (tag, p, end); 15923 15924 switch (tag) 15925 { 15926 case Tag_RISCV_priv_spec: 15927 case Tag_RISCV_priv_spec_minor: 15928 case Tag_RISCV_priv_spec_revision: 15929 READ_ULEB (val, p, end); 15930 printf (_("%u\n"), val); 15931 break; 15932 case Tag_RISCV_unaligned_access: 15933 READ_ULEB (val, p, end); 15934 switch (val) 15935 { 15936 case 0: 15937 printf (_("No unaligned access\n")); 15938 break; 15939 case 1: 15940 printf (_("Unaligned access\n")); 15941 break; 15942 } 15943 break; 15944 case Tag_RISCV_stack_align: 15945 READ_ULEB (val, p, end); 15946 printf (_("%u-bytes\n"), val); 15947 break; 15948 case Tag_RISCV_arch: 15949 p = display_tag_value (-1, p, end); 15950 break; 15951 default: 15952 return display_tag_value (tag, p, end); 15953 } 15954 15955 return p; 15956 } 15957 15958 static bfd_boolean 15959 process_attributes (Filedata * filedata, 15960 const char * public_name, 15961 unsigned int proc_type, 15962 unsigned char * (* display_pub_attribute) (unsigned char *, const unsigned char * const), 15963 unsigned char * (* display_proc_gnu_attribute) (unsigned char *, unsigned int, const unsigned char * const)) 15964 { 15965 Elf_Internal_Shdr * sect; 15966 unsigned i; 15967 bfd_boolean res = TRUE; 15968 15969 /* Find the section header so that we get the size. */ 15970 for (i = 0, sect = filedata->section_headers; 15971 i < filedata->file_header.e_shnum; 15972 i++, sect++) 15973 { 15974 unsigned char * contents; 15975 unsigned char * p; 15976 15977 if (sect->sh_type != proc_type && sect->sh_type != SHT_GNU_ATTRIBUTES) 15978 continue; 15979 15980 contents = (unsigned char *) get_data (NULL, filedata, sect->sh_offset, 1, 15981 sect->sh_size, _("attributes")); 15982 if (contents == NULL) 15983 { 15984 res = FALSE; 15985 continue; 15986 } 15987 15988 p = contents; 15989 /* The first character is the version of the attributes. 15990 Currently only version 1, (aka 'A') is recognised here. */ 15991 if (*p != 'A') 15992 { 15993 printf (_("Unknown attributes version '%c'(%d) - expecting 'A'\n"), *p, *p); 15994 res = FALSE; 15995 } 15996 else 15997 { 15998 bfd_vma section_len; 15999 16000 section_len = sect->sh_size - 1; 16001 p++; 16002 16003 while (section_len > 0) 16004 { 16005 bfd_vma attr_len; 16006 unsigned int namelen; 16007 bfd_boolean public_section; 16008 bfd_boolean gnu_section; 16009 16010 if (section_len <= 4) 16011 { 16012 error (_("Tag section ends prematurely\n")); 16013 res = FALSE; 16014 break; 16015 } 16016 attr_len = byte_get (p, 4); 16017 p += 4; 16018 16019 if (attr_len > section_len) 16020 { 16021 error (_("Bad attribute length (%u > %u)\n"), 16022 (unsigned) attr_len, (unsigned) section_len); 16023 attr_len = section_len; 16024 res = FALSE; 16025 } 16026 /* PR 17531: file: 001-101425-0.004 */ 16027 else if (attr_len < 5) 16028 { 16029 error (_("Attribute length of %u is too small\n"), (unsigned) attr_len); 16030 res = FALSE; 16031 break; 16032 } 16033 16034 section_len -= attr_len; 16035 attr_len -= 4; 16036 16037 namelen = strnlen ((char *) p, attr_len) + 1; 16038 if (namelen == 0 || namelen >= attr_len) 16039 { 16040 error (_("Corrupt attribute section name\n")); 16041 res = FALSE; 16042 break; 16043 } 16044 16045 printf (_("Attribute Section: ")); 16046 print_symbol (INT_MAX, (const char *) p); 16047 putchar ('\n'); 16048 16049 if (public_name && streq ((char *) p, public_name)) 16050 public_section = TRUE; 16051 else 16052 public_section = FALSE; 16053 16054 if (streq ((char *) p, "gnu")) 16055 gnu_section = TRUE; 16056 else 16057 gnu_section = FALSE; 16058 16059 p += namelen; 16060 attr_len -= namelen; 16061 16062 while (attr_len > 0 && p < contents + sect->sh_size) 16063 { 16064 int tag; 16065 unsigned int val; 16066 bfd_vma size; 16067 unsigned char * end; 16068 16069 /* PR binutils/17531: Safe handling of corrupt files. */ 16070 if (attr_len < 6) 16071 { 16072 error (_("Unused bytes at end of section\n")); 16073 res = FALSE; 16074 section_len = 0; 16075 break; 16076 } 16077 16078 tag = *(p++); 16079 size = byte_get (p, 4); 16080 if (size > attr_len) 16081 { 16082 error (_("Bad subsection length (%u > %u)\n"), 16083 (unsigned) size, (unsigned) attr_len); 16084 res = FALSE; 16085 size = attr_len; 16086 } 16087 /* PR binutils/17531: Safe handling of corrupt files. */ 16088 if (size < 6) 16089 { 16090 error (_("Bad subsection length (%u < 6)\n"), 16091 (unsigned) size); 16092 res = FALSE; 16093 section_len = 0; 16094 break; 16095 } 16096 16097 attr_len -= size; 16098 end = p + size - 1; 16099 assert (end <= contents + sect->sh_size); 16100 p += 4; 16101 16102 switch (tag) 16103 { 16104 case 1: 16105 printf (_("File Attributes\n")); 16106 break; 16107 case 2: 16108 printf (_("Section Attributes:")); 16109 goto do_numlist; 16110 case 3: 16111 printf (_("Symbol Attributes:")); 16112 /* Fall through. */ 16113 do_numlist: 16114 for (;;) 16115 { 16116 READ_ULEB (val, p, end); 16117 if (val == 0) 16118 break; 16119 printf (" %d", val); 16120 } 16121 printf ("\n"); 16122 break; 16123 default: 16124 printf (_("Unknown tag: %d\n"), tag); 16125 public_section = FALSE; 16126 break; 16127 } 16128 16129 if (public_section && display_pub_attribute != NULL) 16130 { 16131 while (p < end) 16132 p = display_pub_attribute (p, end); 16133 assert (p == end); 16134 } 16135 else if (gnu_section && display_proc_gnu_attribute != NULL) 16136 { 16137 while (p < end) 16138 p = display_gnu_attribute (p, 16139 display_proc_gnu_attribute, 16140 end); 16141 assert (p == end); 16142 } 16143 else if (p < end) 16144 { 16145 printf (_(" Unknown attribute:\n")); 16146 display_raw_attribute (p, end); 16147 p = end; 16148 } 16149 else 16150 attr_len = 0; 16151 } 16152 } 16153 } 16154 16155 free (contents); 16156 } 16157 16158 return res; 16159 } 16160 16161 /* DATA points to the contents of a MIPS GOT that starts at VMA PLTGOT. 16162 Print the Address, Access and Initial fields of an entry at VMA ADDR 16163 and return the VMA of the next entry, or -1 if there was a problem. 16164 Does not read from DATA_END or beyond. */ 16165 16166 static bfd_vma 16167 print_mips_got_entry (unsigned char * data, bfd_vma pltgot, bfd_vma addr, 16168 unsigned char * data_end) 16169 { 16170 printf (" "); 16171 print_vma (addr, LONG_HEX); 16172 printf (" "); 16173 if (addr < pltgot + 0xfff0) 16174 printf ("%6d(gp)", (int) (addr - pltgot - 0x7ff0)); 16175 else 16176 printf ("%10s", ""); 16177 printf (" "); 16178 if (data == NULL) 16179 printf ("%*s", is_32bit_elf ? 8 : 16, _("<unknown>")); 16180 else 16181 { 16182 bfd_vma entry; 16183 unsigned char * from = data + addr - pltgot; 16184 16185 if (from + (is_32bit_elf ? 4 : 8) > data_end) 16186 { 16187 warn (_("MIPS GOT entry extends beyond the end of available data\n")); 16188 printf ("%*s", is_32bit_elf ? 8 : 16, _("<corrupt>")); 16189 return (bfd_vma) -1; 16190 } 16191 else 16192 { 16193 entry = byte_get (data + addr - pltgot, is_32bit_elf ? 4 : 8); 16194 print_vma (entry, LONG_HEX); 16195 } 16196 } 16197 return addr + (is_32bit_elf ? 4 : 8); 16198 } 16199 16200 /* DATA points to the contents of a MIPS PLT GOT that starts at VMA 16201 PLTGOT. Print the Address and Initial fields of an entry at VMA 16202 ADDR and return the VMA of the next entry. */ 16203 16204 static bfd_vma 16205 print_mips_pltgot_entry (unsigned char * data, bfd_vma pltgot, bfd_vma addr) 16206 { 16207 printf (" "); 16208 print_vma (addr, LONG_HEX); 16209 printf (" "); 16210 if (data == NULL) 16211 printf ("%*s", is_32bit_elf ? 8 : 16, _("<unknown>")); 16212 else 16213 { 16214 bfd_vma entry; 16215 16216 entry = byte_get (data + addr - pltgot, is_32bit_elf ? 4 : 8); 16217 print_vma (entry, LONG_HEX); 16218 } 16219 return addr + (is_32bit_elf ? 4 : 8); 16220 } 16221 16222 static void 16223 print_mips_ases (unsigned int mask) 16224 { 16225 if (mask & AFL_ASE_DSP) 16226 fputs ("\n\tDSP ASE", stdout); 16227 if (mask & AFL_ASE_DSPR2) 16228 fputs ("\n\tDSP R2 ASE", stdout); 16229 if (mask & AFL_ASE_DSPR3) 16230 fputs ("\n\tDSP R3 ASE", stdout); 16231 if (mask & AFL_ASE_EVA) 16232 fputs ("\n\tEnhanced VA Scheme", stdout); 16233 if (mask & AFL_ASE_MCU) 16234 fputs ("\n\tMCU (MicroController) ASE", stdout); 16235 if (mask & AFL_ASE_MDMX) 16236 fputs ("\n\tMDMX ASE", stdout); 16237 if (mask & AFL_ASE_MIPS3D) 16238 fputs ("\n\tMIPS-3D ASE", stdout); 16239 if (mask & AFL_ASE_MT) 16240 fputs ("\n\tMT ASE", stdout); 16241 if (mask & AFL_ASE_SMARTMIPS) 16242 fputs ("\n\tSmartMIPS ASE", stdout); 16243 if (mask & AFL_ASE_VIRT) 16244 fputs ("\n\tVZ ASE", stdout); 16245 if (mask & AFL_ASE_MSA) 16246 fputs ("\n\tMSA ASE", stdout); 16247 if (mask & AFL_ASE_MIPS16) 16248 fputs ("\n\tMIPS16 ASE", stdout); 16249 if (mask & AFL_ASE_MICROMIPS) 16250 fputs ("\n\tMICROMIPS ASE", stdout); 16251 if (mask & AFL_ASE_XPA) 16252 fputs ("\n\tXPA ASE", stdout); 16253 if (mask & AFL_ASE_MIPS16E2) 16254 fputs ("\n\tMIPS16e2 ASE", stdout); 16255 if (mask & AFL_ASE_CRC) 16256 fputs ("\n\tCRC ASE", stdout); 16257 if (mask & AFL_ASE_GINV) 16258 fputs ("\n\tGINV ASE", stdout); 16259 if (mask & AFL_ASE_LOONGSON_MMI) 16260 fputs ("\n\tLoongson MMI ASE", stdout); 16261 if (mask & AFL_ASE_LOONGSON_CAM) 16262 fputs ("\n\tLoongson CAM ASE", stdout); 16263 if (mask & AFL_ASE_LOONGSON_EXT) 16264 fputs ("\n\tLoongson EXT ASE", stdout); 16265 if (mask & AFL_ASE_LOONGSON_EXT2) 16266 fputs ("\n\tLoongson EXT2 ASE", stdout); 16267 if (mask == 0) 16268 fprintf (stdout, "\n\t%s", _("None")); 16269 else if ((mask & ~AFL_ASE_MASK) != 0) 16270 fprintf (stdout, "\n\t%s (%x)", _("Unknown"), mask & ~AFL_ASE_MASK); 16271 } 16272 16273 static void 16274 print_mips_isa_ext (unsigned int isa_ext) 16275 { 16276 switch (isa_ext) 16277 { 16278 case 0: 16279 fputs (_("None"), stdout); 16280 break; 16281 case AFL_EXT_XLR: 16282 fputs ("RMI XLR", stdout); 16283 break; 16284 case AFL_EXT_OCTEON3: 16285 fputs ("Cavium Networks Octeon3", stdout); 16286 break; 16287 case AFL_EXT_OCTEON2: 16288 fputs ("Cavium Networks Octeon2", stdout); 16289 break; 16290 case AFL_EXT_OCTEONP: 16291 fputs ("Cavium Networks OcteonP", stdout); 16292 break; 16293 case AFL_EXT_OCTEON: 16294 fputs ("Cavium Networks Octeon", stdout); 16295 break; 16296 case AFL_EXT_5900: 16297 fputs ("Toshiba R5900", stdout); 16298 break; 16299 case AFL_EXT_4650: 16300 fputs ("MIPS R4650", stdout); 16301 break; 16302 case AFL_EXT_4010: 16303 fputs ("LSI R4010", stdout); 16304 break; 16305 case AFL_EXT_4100: 16306 fputs ("NEC VR4100", stdout); 16307 break; 16308 case AFL_EXT_3900: 16309 fputs ("Toshiba R3900", stdout); 16310 break; 16311 case AFL_EXT_10000: 16312 fputs ("MIPS R10000", stdout); 16313 break; 16314 case AFL_EXT_SB1: 16315 fputs ("Broadcom SB-1", stdout); 16316 break; 16317 case AFL_EXT_4111: 16318 fputs ("NEC VR4111/VR4181", stdout); 16319 break; 16320 case AFL_EXT_4120: 16321 fputs ("NEC VR4120", stdout); 16322 break; 16323 case AFL_EXT_5400: 16324 fputs ("NEC VR5400", stdout); 16325 break; 16326 case AFL_EXT_5500: 16327 fputs ("NEC VR5500", stdout); 16328 break; 16329 case AFL_EXT_LOONGSON_2E: 16330 fputs ("ST Microelectronics Loongson 2E", stdout); 16331 break; 16332 case AFL_EXT_LOONGSON_2F: 16333 fputs ("ST Microelectronics Loongson 2F", stdout); 16334 break; 16335 case AFL_EXT_INTERAPTIV_MR2: 16336 fputs ("Imagination interAptiv MR2", stdout); 16337 break; 16338 default: 16339 fprintf (stdout, "%s (%d)", _("Unknown"), isa_ext); 16340 } 16341 } 16342 16343 static signed int 16344 get_mips_reg_size (int reg_size) 16345 { 16346 return (reg_size == AFL_REG_NONE) ? 0 16347 : (reg_size == AFL_REG_32) ? 32 16348 : (reg_size == AFL_REG_64) ? 64 16349 : (reg_size == AFL_REG_128) ? 128 16350 : -1; 16351 } 16352 16353 static bfd_boolean 16354 process_mips_specific (Filedata * filedata) 16355 { 16356 Elf_Internal_Dyn * entry; 16357 Elf_Internal_Shdr *sect = NULL; 16358 size_t liblist_offset = 0; 16359 size_t liblistno = 0; 16360 size_t conflictsno = 0; 16361 size_t options_offset = 0; 16362 size_t conflicts_offset = 0; 16363 size_t pltrelsz = 0; 16364 size_t pltrel = 0; 16365 bfd_vma pltgot = 0; 16366 bfd_vma mips_pltgot = 0; 16367 bfd_vma jmprel = 0; 16368 bfd_vma local_gotno = 0; 16369 bfd_vma gotsym = 0; 16370 bfd_vma symtabno = 0; 16371 bfd_boolean res = TRUE; 16372 16373 if (! process_attributes (filedata, NULL, SHT_GNU_ATTRIBUTES, NULL, 16374 display_mips_gnu_attribute)) 16375 res = FALSE; 16376 16377 sect = find_section (filedata, ".MIPS.abiflags"); 16378 16379 if (sect != NULL) 16380 { 16381 Elf_External_ABIFlags_v0 *abiflags_ext; 16382 Elf_Internal_ABIFlags_v0 abiflags_in; 16383 16384 if (sizeof (Elf_External_ABIFlags_v0) != sect->sh_size) 16385 { 16386 error (_("Corrupt MIPS ABI Flags section.\n")); 16387 res = FALSE; 16388 } 16389 else 16390 { 16391 abiflags_ext = get_data (NULL, filedata, sect->sh_offset, 1, 16392 sect->sh_size, _("MIPS ABI Flags section")); 16393 if (abiflags_ext) 16394 { 16395 abiflags_in.version = BYTE_GET (abiflags_ext->version); 16396 abiflags_in.isa_level = BYTE_GET (abiflags_ext->isa_level); 16397 abiflags_in.isa_rev = BYTE_GET (abiflags_ext->isa_rev); 16398 abiflags_in.gpr_size = BYTE_GET (abiflags_ext->gpr_size); 16399 abiflags_in.cpr1_size = BYTE_GET (abiflags_ext->cpr1_size); 16400 abiflags_in.cpr2_size = BYTE_GET (abiflags_ext->cpr2_size); 16401 abiflags_in.fp_abi = BYTE_GET (abiflags_ext->fp_abi); 16402 abiflags_in.isa_ext = BYTE_GET (abiflags_ext->isa_ext); 16403 abiflags_in.ases = BYTE_GET (abiflags_ext->ases); 16404 abiflags_in.flags1 = BYTE_GET (abiflags_ext->flags1); 16405 abiflags_in.flags2 = BYTE_GET (abiflags_ext->flags2); 16406 16407 printf ("\nMIPS ABI Flags Version: %d\n", abiflags_in.version); 16408 printf ("\nISA: MIPS%d", abiflags_in.isa_level); 16409 if (abiflags_in.isa_rev > 1) 16410 printf ("r%d", abiflags_in.isa_rev); 16411 printf ("\nGPR size: %d", 16412 get_mips_reg_size (abiflags_in.gpr_size)); 16413 printf ("\nCPR1 size: %d", 16414 get_mips_reg_size (abiflags_in.cpr1_size)); 16415 printf ("\nCPR2 size: %d", 16416 get_mips_reg_size (abiflags_in.cpr2_size)); 16417 fputs ("\nFP ABI: ", stdout); 16418 print_mips_fp_abi_value (abiflags_in.fp_abi); 16419 fputs ("ISA Extension: ", stdout); 16420 print_mips_isa_ext (abiflags_in.isa_ext); 16421 fputs ("\nASEs:", stdout); 16422 print_mips_ases (abiflags_in.ases); 16423 printf ("\nFLAGS 1: %8.8lx", abiflags_in.flags1); 16424 printf ("\nFLAGS 2: %8.8lx", abiflags_in.flags2); 16425 fputc ('\n', stdout); 16426 free (abiflags_ext); 16427 } 16428 } 16429 } 16430 16431 /* We have a lot of special sections. Thanks SGI! */ 16432 if (dynamic_section == NULL) 16433 { 16434 /* No dynamic information available. See if there is static GOT. */ 16435 sect = find_section (filedata, ".got"); 16436 if (sect != NULL) 16437 { 16438 unsigned char *data_end; 16439 unsigned char *data; 16440 bfd_vma ent, end; 16441 int addr_size; 16442 16443 pltgot = sect->sh_addr; 16444 16445 ent = pltgot; 16446 addr_size = (is_32bit_elf ? 4 : 8); 16447 end = pltgot + sect->sh_size; 16448 16449 data = (unsigned char *) get_data (NULL, filedata, sect->sh_offset, 16450 end - pltgot, 1, 16451 _("Global Offset Table data")); 16452 /* PR 12855: Null data is handled gracefully throughout. */ 16453 data_end = data + (end - pltgot); 16454 16455 printf (_("\nStatic GOT:\n")); 16456 printf (_(" Canonical gp value: ")); 16457 print_vma (ent + 0x7ff0, LONG_HEX); 16458 printf ("\n\n"); 16459 16460 /* In a dynamic binary GOT[0] is reserved for the dynamic 16461 loader to store the lazy resolver pointer, however in 16462 a static binary it may well have been omitted and GOT 16463 reduced to a table of addresses. 16464 PR 21344: Check for the entry being fully available 16465 before fetching it. */ 16466 if (data 16467 && data + ent - pltgot + addr_size <= data_end 16468 && byte_get (data + ent - pltgot, addr_size) == 0) 16469 { 16470 printf (_(" Reserved entries:\n")); 16471 printf (_(" %*s %10s %*s\n"), 16472 addr_size * 2, _("Address"), _("Access"), 16473 addr_size * 2, _("Value")); 16474 ent = print_mips_got_entry (data, pltgot, ent, data_end); 16475 printf ("\n"); 16476 if (ent == (bfd_vma) -1) 16477 goto sgot_print_fail; 16478 16479 /* Check for the MSB of GOT[1] being set, identifying a 16480 GNU object. This entry will be used by some runtime 16481 loaders, to store the module pointer. Otherwise this 16482 is an ordinary local entry. 16483 PR 21344: Check for the entry being fully available 16484 before fetching it. */ 16485 if (data 16486 && data + ent - pltgot + addr_size <= data_end 16487 && (byte_get (data + ent - pltgot, addr_size) 16488 >> (addr_size * 8 - 1)) != 0) 16489 { 16490 ent = print_mips_got_entry (data, pltgot, ent, data_end); 16491 printf ("\n"); 16492 if (ent == (bfd_vma) -1) 16493 goto sgot_print_fail; 16494 } 16495 printf ("\n"); 16496 } 16497 16498 if (data != NULL && ent < end) 16499 { 16500 printf (_(" Local entries:\n")); 16501 printf (" %*s %10s %*s\n", 16502 addr_size * 2, _("Address"), _("Access"), 16503 addr_size * 2, _("Value")); 16504 while (ent < end) 16505 { 16506 ent = print_mips_got_entry (data, pltgot, ent, data_end); 16507 printf ("\n"); 16508 if (ent == (bfd_vma) -1) 16509 goto sgot_print_fail; 16510 } 16511 printf ("\n"); 16512 } 16513 16514 sgot_print_fail: 16515 if (data) 16516 free (data); 16517 } 16518 return res; 16519 } 16520 16521 for (entry = dynamic_section; 16522 /* PR 17531 file: 012-50589-0.004. */ 16523 entry < dynamic_section + dynamic_nent && entry->d_tag != DT_NULL; 16524 ++entry) 16525 switch (entry->d_tag) 16526 { 16527 case DT_MIPS_LIBLIST: 16528 liblist_offset 16529 = offset_from_vma (filedata, entry->d_un.d_val, 16530 liblistno * sizeof (Elf32_External_Lib)); 16531 break; 16532 case DT_MIPS_LIBLISTNO: 16533 liblistno = entry->d_un.d_val; 16534 break; 16535 case DT_MIPS_OPTIONS: 16536 options_offset = offset_from_vma (filedata, entry->d_un.d_val, 0); 16537 break; 16538 case DT_MIPS_CONFLICT: 16539 conflicts_offset 16540 = offset_from_vma (filedata, entry->d_un.d_val, 16541 conflictsno * sizeof (Elf32_External_Conflict)); 16542 break; 16543 case DT_MIPS_CONFLICTNO: 16544 conflictsno = entry->d_un.d_val; 16545 break; 16546 case DT_PLTGOT: 16547 pltgot = entry->d_un.d_ptr; 16548 break; 16549 case DT_MIPS_LOCAL_GOTNO: 16550 local_gotno = entry->d_un.d_val; 16551 break; 16552 case DT_MIPS_GOTSYM: 16553 gotsym = entry->d_un.d_val; 16554 break; 16555 case DT_MIPS_SYMTABNO: 16556 symtabno = entry->d_un.d_val; 16557 break; 16558 case DT_MIPS_PLTGOT: 16559 mips_pltgot = entry->d_un.d_ptr; 16560 break; 16561 case DT_PLTREL: 16562 pltrel = entry->d_un.d_val; 16563 break; 16564 case DT_PLTRELSZ: 16565 pltrelsz = entry->d_un.d_val; 16566 break; 16567 case DT_JMPREL: 16568 jmprel = entry->d_un.d_ptr; 16569 break; 16570 default: 16571 break; 16572 } 16573 16574 if (liblist_offset != 0 && liblistno != 0 && do_dynamic) 16575 { 16576 Elf32_External_Lib * elib; 16577 size_t cnt; 16578 16579 elib = (Elf32_External_Lib *) get_data (NULL, filedata, liblist_offset, 16580 liblistno, 16581 sizeof (Elf32_External_Lib), 16582 _("liblist section data")); 16583 if (elib) 16584 { 16585 printf (ngettext ("\nSection '.liblist' contains %lu entry:\n", 16586 "\nSection '.liblist' contains %lu entries:\n", 16587 (unsigned long) liblistno), 16588 (unsigned long) liblistno); 16589 fputs (_(" Library Time Stamp Checksum Version Flags\n"), 16590 stdout); 16591 16592 for (cnt = 0; cnt < liblistno; ++cnt) 16593 { 16594 Elf32_Lib liblist; 16595 time_t atime; 16596 char timebuf[128]; 16597 struct tm * tmp; 16598 16599 liblist.l_name = BYTE_GET (elib[cnt].l_name); 16600 atime = BYTE_GET (elib[cnt].l_time_stamp); 16601 liblist.l_checksum = BYTE_GET (elib[cnt].l_checksum); 16602 liblist.l_version = BYTE_GET (elib[cnt].l_version); 16603 liblist.l_flags = BYTE_GET (elib[cnt].l_flags); 16604 16605 tmp = gmtime (&atime); 16606 snprintf (timebuf, sizeof (timebuf), 16607 "%04u-%02u-%02uT%02u:%02u:%02u", 16608 tmp->tm_year + 1900, tmp->tm_mon + 1, tmp->tm_mday, 16609 tmp->tm_hour, tmp->tm_min, tmp->tm_sec); 16610 16611 printf ("%3lu: ", (unsigned long) cnt); 16612 if (VALID_DYNAMIC_NAME (liblist.l_name)) 16613 print_symbol (20, GET_DYNAMIC_NAME (liblist.l_name)); 16614 else 16615 printf (_("<corrupt: %9ld>"), liblist.l_name); 16616 printf (" %s %#10lx %-7ld", timebuf, liblist.l_checksum, 16617 liblist.l_version); 16618 16619 if (liblist.l_flags == 0) 16620 puts (_(" NONE")); 16621 else 16622 { 16623 static const struct 16624 { 16625 const char * name; 16626 int bit; 16627 } 16628 l_flags_vals[] = 16629 { 16630 { " EXACT_MATCH", LL_EXACT_MATCH }, 16631 { " IGNORE_INT_VER", LL_IGNORE_INT_VER }, 16632 { " REQUIRE_MINOR", LL_REQUIRE_MINOR }, 16633 { " EXPORTS", LL_EXPORTS }, 16634 { " DELAY_LOAD", LL_DELAY_LOAD }, 16635 { " DELTA", LL_DELTA } 16636 }; 16637 int flags = liblist.l_flags; 16638 size_t fcnt; 16639 16640 for (fcnt = 0; fcnt < ARRAY_SIZE (l_flags_vals); ++fcnt) 16641 if ((flags & l_flags_vals[fcnt].bit) != 0) 16642 { 16643 fputs (l_flags_vals[fcnt].name, stdout); 16644 flags ^= l_flags_vals[fcnt].bit; 16645 } 16646 if (flags != 0) 16647 printf (" %#x", (unsigned int) flags); 16648 16649 puts (""); 16650 } 16651 } 16652 16653 free (elib); 16654 } 16655 else 16656 res = FALSE; 16657 } 16658 16659 if (options_offset != 0) 16660 { 16661 Elf_External_Options * eopt; 16662 size_t offset; 16663 int cnt; 16664 sect = filedata->section_headers; 16665 16666 /* Find the section header so that we get the size. */ 16667 sect = find_section_by_type (filedata, SHT_MIPS_OPTIONS); 16668 /* PR 17533 file: 012-277276-0.004. */ 16669 if (sect == NULL) 16670 { 16671 error (_("No MIPS_OPTIONS header found\n")); 16672 return FALSE; 16673 } 16674 /* PR 24243 */ 16675 if (sect->sh_size < sizeof (* eopt)) 16676 { 16677 error (_("The MIPS options section is too small.\n")); 16678 return FALSE; 16679 } 16680 16681 eopt = (Elf_External_Options *) get_data (NULL, filedata, options_offset, 1, 16682 sect->sh_size, _("options")); 16683 if (eopt) 16684 { 16685 Elf_Internal_Options * iopt; 16686 Elf_Internal_Options * option; 16687 Elf_Internal_Options * iopt_end; 16688 16689 iopt = (Elf_Internal_Options *) 16690 cmalloc ((sect->sh_size / sizeof (eopt)), sizeof (* iopt)); 16691 if (iopt == NULL) 16692 { 16693 error (_("Out of memory allocating space for MIPS options\n")); 16694 return FALSE; 16695 } 16696 16697 offset = cnt = 0; 16698 option = iopt; 16699 iopt_end = iopt + (sect->sh_size / sizeof (eopt)); 16700 16701 while (offset <= sect->sh_size - sizeof (* eopt)) 16702 { 16703 Elf_External_Options * eoption; 16704 16705 eoption = (Elf_External_Options *) ((char *) eopt + offset); 16706 16707 option->kind = BYTE_GET (eoption->kind); 16708 option->size = BYTE_GET (eoption->size); 16709 option->section = BYTE_GET (eoption->section); 16710 option->info = BYTE_GET (eoption->info); 16711 16712 /* PR 17531: file: ffa0fa3b. */ 16713 if (option->size < sizeof (* eopt) 16714 || offset + option->size > sect->sh_size) 16715 { 16716 error (_("Invalid size (%u) for MIPS option\n"), option->size); 16717 return FALSE; 16718 } 16719 offset += option->size; 16720 16721 ++option; 16722 ++cnt; 16723 } 16724 16725 printf (ngettext ("\nSection '%s' contains %d entry:\n", 16726 "\nSection '%s' contains %d entries:\n", 16727 cnt), 16728 printable_section_name (filedata, sect), cnt); 16729 16730 option = iopt; 16731 offset = 0; 16732 16733 while (cnt-- > 0) 16734 { 16735 size_t len; 16736 16737 switch (option->kind) 16738 { 16739 case ODK_NULL: 16740 /* This shouldn't happen. */ 16741 printf (" NULL %d %lx", option->section, option->info); 16742 break; 16743 16744 case ODK_REGINFO: 16745 printf (" REGINFO "); 16746 if (filedata->file_header.e_machine == EM_MIPS) 16747 { 16748 Elf32_External_RegInfo * ereg; 16749 Elf32_RegInfo reginfo; 16750 16751 /* 32bit form. */ 16752 if (option + 2 > iopt_end) 16753 { 16754 printf (_("<corrupt>\n")); 16755 error (_("Truncated MIPS REGINFO option\n")); 16756 cnt = 0; 16757 break; 16758 } 16759 16760 ereg = (Elf32_External_RegInfo *) (option + 1); 16761 16762 reginfo.ri_gprmask = BYTE_GET (ereg->ri_gprmask); 16763 reginfo.ri_cprmask[0] = BYTE_GET (ereg->ri_cprmask[0]); 16764 reginfo.ri_cprmask[1] = BYTE_GET (ereg->ri_cprmask[1]); 16765 reginfo.ri_cprmask[2] = BYTE_GET (ereg->ri_cprmask[2]); 16766 reginfo.ri_cprmask[3] = BYTE_GET (ereg->ri_cprmask[3]); 16767 reginfo.ri_gp_value = BYTE_GET (ereg->ri_gp_value); 16768 16769 printf ("GPR %08lx GP 0x%lx\n", 16770 reginfo.ri_gprmask, 16771 (unsigned long) reginfo.ri_gp_value); 16772 printf (" CPR0 %08lx CPR1 %08lx CPR2 %08lx CPR3 %08lx\n", 16773 reginfo.ri_cprmask[0], reginfo.ri_cprmask[1], 16774 reginfo.ri_cprmask[2], reginfo.ri_cprmask[3]); 16775 } 16776 else 16777 { 16778 /* 64 bit form. */ 16779 Elf64_External_RegInfo * ereg; 16780 Elf64_Internal_RegInfo reginfo; 16781 16782 if (option + 2 > iopt_end) 16783 { 16784 printf (_("<corrupt>\n")); 16785 error (_("Truncated MIPS REGINFO option\n")); 16786 cnt = 0; 16787 break; 16788 } 16789 16790 ereg = (Elf64_External_RegInfo *) (option + 1); 16791 reginfo.ri_gprmask = BYTE_GET (ereg->ri_gprmask); 16792 reginfo.ri_cprmask[0] = BYTE_GET (ereg->ri_cprmask[0]); 16793 reginfo.ri_cprmask[1] = BYTE_GET (ereg->ri_cprmask[1]); 16794 reginfo.ri_cprmask[2] = BYTE_GET (ereg->ri_cprmask[2]); 16795 reginfo.ri_cprmask[3] = BYTE_GET (ereg->ri_cprmask[3]); 16796 reginfo.ri_gp_value = BYTE_GET (ereg->ri_gp_value); 16797 16798 printf ("GPR %08lx GP 0x", 16799 reginfo.ri_gprmask); 16800 printf_vma (reginfo.ri_gp_value); 16801 printf ("\n"); 16802 16803 printf (" CPR0 %08lx CPR1 %08lx CPR2 %08lx CPR3 %08lx\n", 16804 reginfo.ri_cprmask[0], reginfo.ri_cprmask[1], 16805 reginfo.ri_cprmask[2], reginfo.ri_cprmask[3]); 16806 } 16807 ++option; 16808 continue; 16809 16810 case ODK_EXCEPTIONS: 16811 fputs (" EXCEPTIONS fpe_min(", stdout); 16812 process_mips_fpe_exception (option->info & OEX_FPU_MIN); 16813 fputs (") fpe_max(", stdout); 16814 process_mips_fpe_exception ((option->info & OEX_FPU_MAX) >> 8); 16815 fputs (")", stdout); 16816 16817 if (option->info & OEX_PAGE0) 16818 fputs (" PAGE0", stdout); 16819 if (option->info & OEX_SMM) 16820 fputs (" SMM", stdout); 16821 if (option->info & OEX_FPDBUG) 16822 fputs (" FPDBUG", stdout); 16823 if (option->info & OEX_DISMISS) 16824 fputs (" DISMISS", stdout); 16825 break; 16826 16827 case ODK_PAD: 16828 fputs (" PAD ", stdout); 16829 if (option->info & OPAD_PREFIX) 16830 fputs (" PREFIX", stdout); 16831 if (option->info & OPAD_POSTFIX) 16832 fputs (" POSTFIX", stdout); 16833 if (option->info & OPAD_SYMBOL) 16834 fputs (" SYMBOL", stdout); 16835 break; 16836 16837 case ODK_HWPATCH: 16838 fputs (" HWPATCH ", stdout); 16839 if (option->info & OHW_R4KEOP) 16840 fputs (" R4KEOP", stdout); 16841 if (option->info & OHW_R8KPFETCH) 16842 fputs (" R8KPFETCH", stdout); 16843 if (option->info & OHW_R5KEOP) 16844 fputs (" R5KEOP", stdout); 16845 if (option->info & OHW_R5KCVTL) 16846 fputs (" R5KCVTL", stdout); 16847 break; 16848 16849 case ODK_FILL: 16850 fputs (" FILL ", stdout); 16851 /* XXX Print content of info word? */ 16852 break; 16853 16854 case ODK_TAGS: 16855 fputs (" TAGS ", stdout); 16856 /* XXX Print content of info word? */ 16857 break; 16858 16859 case ODK_HWAND: 16860 fputs (" HWAND ", stdout); 16861 if (option->info & OHWA0_R4KEOP_CHECKED) 16862 fputs (" R4KEOP_CHECKED", stdout); 16863 if (option->info & OHWA0_R4KEOP_CLEAN) 16864 fputs (" R4KEOP_CLEAN", stdout); 16865 break; 16866 16867 case ODK_HWOR: 16868 fputs (" HWOR ", stdout); 16869 if (option->info & OHWA0_R4KEOP_CHECKED) 16870 fputs (" R4KEOP_CHECKED", stdout); 16871 if (option->info & OHWA0_R4KEOP_CLEAN) 16872 fputs (" R4KEOP_CLEAN", stdout); 16873 break; 16874 16875 case ODK_GP_GROUP: 16876 printf (" GP_GROUP %#06lx self-contained %#06lx", 16877 option->info & OGP_GROUP, 16878 (option->info & OGP_SELF) >> 16); 16879 break; 16880 16881 case ODK_IDENT: 16882 printf (" IDENT %#06lx self-contained %#06lx", 16883 option->info & OGP_GROUP, 16884 (option->info & OGP_SELF) >> 16); 16885 break; 16886 16887 default: 16888 /* This shouldn't happen. */ 16889 printf (" %3d ??? %d %lx", 16890 option->kind, option->section, option->info); 16891 break; 16892 } 16893 16894 len = sizeof (* eopt); 16895 while (len < option->size) 16896 { 16897 unsigned char datum = * ((unsigned char *) eopt + offset + len); 16898 16899 if (ISPRINT (datum)) 16900 printf ("%c", datum); 16901 else 16902 printf ("\\%03o", datum); 16903 len ++; 16904 } 16905 fputs ("\n", stdout); 16906 16907 offset += option->size; 16908 ++option; 16909 } 16910 16911 free (eopt); 16912 } 16913 else 16914 res = FALSE; 16915 } 16916 16917 if (conflicts_offset != 0 && conflictsno != 0) 16918 { 16919 Elf32_Conflict * iconf; 16920 size_t cnt; 16921 16922 if (dynamic_symbols == NULL) 16923 { 16924 error (_("conflict list found without a dynamic symbol table\n")); 16925 return FALSE; 16926 } 16927 16928 /* PR 21345 - print a slightly more helpful error message 16929 if we are sure that the cmalloc will fail. */ 16930 if (conflictsno * sizeof (* iconf) > filedata->file_size) 16931 { 16932 error (_("Overlarge number of conflicts detected: %lx\n"), 16933 (long) conflictsno); 16934 return FALSE; 16935 } 16936 16937 iconf = (Elf32_Conflict *) cmalloc (conflictsno, sizeof (* iconf)); 16938 if (iconf == NULL) 16939 { 16940 error (_("Out of memory allocating space for dynamic conflicts\n")); 16941 return FALSE; 16942 } 16943 16944 if (is_32bit_elf) 16945 { 16946 Elf32_External_Conflict * econf32; 16947 16948 econf32 = (Elf32_External_Conflict *) 16949 get_data (NULL, filedata, conflicts_offset, conflictsno, 16950 sizeof (* econf32), _("conflict")); 16951 if (!econf32) 16952 return FALSE; 16953 16954 for (cnt = 0; cnt < conflictsno; ++cnt) 16955 iconf[cnt] = BYTE_GET (econf32[cnt]); 16956 16957 free (econf32); 16958 } 16959 else 16960 { 16961 Elf64_External_Conflict * econf64; 16962 16963 econf64 = (Elf64_External_Conflict *) 16964 get_data (NULL, filedata, conflicts_offset, conflictsno, 16965 sizeof (* econf64), _("conflict")); 16966 if (!econf64) 16967 return FALSE; 16968 16969 for (cnt = 0; cnt < conflictsno; ++cnt) 16970 iconf[cnt] = BYTE_GET (econf64[cnt]); 16971 16972 free (econf64); 16973 } 16974 16975 printf (ngettext ("\nSection '.conflict' contains %lu entry:\n", 16976 "\nSection '.conflict' contains %lu entries:\n", 16977 (unsigned long) conflictsno), 16978 (unsigned long) conflictsno); 16979 puts (_(" Num: Index Value Name")); 16980 16981 for (cnt = 0; cnt < conflictsno; ++cnt) 16982 { 16983 printf ("%5lu: %8lu ", (unsigned long) cnt, iconf[cnt]); 16984 16985 if (iconf[cnt] >= num_dynamic_syms) 16986 printf (_("<corrupt symbol index>")); 16987 else 16988 { 16989 Elf_Internal_Sym * psym; 16990 16991 psym = & dynamic_symbols[iconf[cnt]]; 16992 print_vma (psym->st_value, FULL_HEX); 16993 putchar (' '); 16994 if (VALID_DYNAMIC_NAME (psym->st_name)) 16995 print_symbol (25, GET_DYNAMIC_NAME (psym->st_name)); 16996 else 16997 printf (_("<corrupt: %14ld>"), psym->st_name); 16998 } 16999 putchar ('\n'); 17000 } 17001 17002 free (iconf); 17003 } 17004 17005 if (pltgot != 0 && local_gotno != 0) 17006 { 17007 bfd_vma ent, local_end, global_end; 17008 size_t i, offset; 17009 unsigned char * data; 17010 unsigned char * data_end; 17011 int addr_size; 17012 17013 ent = pltgot; 17014 addr_size = (is_32bit_elf ? 4 : 8); 17015 local_end = pltgot + local_gotno * addr_size; 17016 17017 /* PR binutils/17533 file: 012-111227-0.004 */ 17018 if (symtabno < gotsym) 17019 { 17020 error (_("The GOT symbol offset (%lu) is greater than the symbol table size (%lu)\n"), 17021 (unsigned long) gotsym, (unsigned long) symtabno); 17022 return FALSE; 17023 } 17024 17025 global_end = local_end + (symtabno - gotsym) * addr_size; 17026 /* PR 17531: file: 54c91a34. */ 17027 if (global_end < local_end) 17028 { 17029 error (_("Too many GOT symbols: %lu\n"), (unsigned long) symtabno); 17030 return FALSE; 17031 } 17032 17033 offset = offset_from_vma (filedata, pltgot, global_end - pltgot); 17034 data = (unsigned char *) get_data (NULL, filedata, offset, 17035 global_end - pltgot, 1, 17036 _("Global Offset Table data")); 17037 /* PR 12855: Null data is handled gracefully throughout. */ 17038 data_end = data + (global_end - pltgot); 17039 17040 printf (_("\nPrimary GOT:\n")); 17041 printf (_(" Canonical gp value: ")); 17042 print_vma (pltgot + 0x7ff0, LONG_HEX); 17043 printf ("\n\n"); 17044 17045 printf (_(" Reserved entries:\n")); 17046 printf (_(" %*s %10s %*s Purpose\n"), 17047 addr_size * 2, _("Address"), _("Access"), 17048 addr_size * 2, _("Initial")); 17049 ent = print_mips_got_entry (data, pltgot, ent, data_end); 17050 printf (_(" Lazy resolver\n")); 17051 if (ent == (bfd_vma) -1) 17052 goto got_print_fail; 17053 17054 /* Check for the MSB of GOT[1] being set, denoting a GNU object. 17055 This entry will be used by some runtime loaders, to store the 17056 module pointer. Otherwise this is an ordinary local entry. 17057 PR 21344: Check for the entry being fully available before 17058 fetching it. */ 17059 if (data 17060 && data + ent - pltgot + addr_size <= data_end 17061 && (byte_get (data + ent - pltgot, addr_size) 17062 >> (addr_size * 8 - 1)) != 0) 17063 { 17064 ent = print_mips_got_entry (data, pltgot, ent, data_end); 17065 printf (_(" Module pointer (GNU extension)\n")); 17066 if (ent == (bfd_vma) -1) 17067 goto got_print_fail; 17068 } 17069 printf ("\n"); 17070 17071 if (data != NULL && ent < local_end) 17072 { 17073 printf (_(" Local entries:\n")); 17074 printf (" %*s %10s %*s\n", 17075 addr_size * 2, _("Address"), _("Access"), 17076 addr_size * 2, _("Initial")); 17077 while (ent < local_end) 17078 { 17079 ent = print_mips_got_entry (data, pltgot, ent, data_end); 17080 printf ("\n"); 17081 if (ent == (bfd_vma) -1) 17082 goto got_print_fail; 17083 } 17084 printf ("\n"); 17085 } 17086 17087 if (data != NULL && gotsym < symtabno) 17088 { 17089 int sym_width; 17090 17091 printf (_(" Global entries:\n")); 17092 printf (" %*s %10s %*s %*s %-7s %3s %s\n", 17093 addr_size * 2, _("Address"), 17094 _("Access"), 17095 addr_size * 2, _("Initial"), 17096 addr_size * 2, _("Sym.Val."), 17097 _("Type"), 17098 /* Note for translators: "Ndx" = abbreviated form of "Index". */ 17099 _("Ndx"), _("Name")); 17100 17101 sym_width = (is_32bit_elf ? 80 : 160) - 28 - addr_size * 6 - 1; 17102 17103 for (i = gotsym; i < symtabno; i++) 17104 { 17105 ent = print_mips_got_entry (data, pltgot, ent, data_end); 17106 printf (" "); 17107 17108 if (dynamic_symbols == NULL) 17109 printf (_("<no dynamic symbols>")); 17110 else if (i < num_dynamic_syms) 17111 { 17112 Elf_Internal_Sym * psym = dynamic_symbols + i; 17113 17114 print_vma (psym->st_value, LONG_HEX); 17115 printf (" %-7s %3s ", 17116 get_symbol_type (filedata, ELF_ST_TYPE (psym->st_info)), 17117 get_symbol_index_type (filedata, psym->st_shndx)); 17118 17119 if (VALID_DYNAMIC_NAME (psym->st_name)) 17120 print_symbol (sym_width, GET_DYNAMIC_NAME (psym->st_name)); 17121 else 17122 printf (_("<corrupt: %14ld>"), psym->st_name); 17123 } 17124 else 17125 printf (_("<symbol index %lu exceeds number of dynamic symbols>"), 17126 (unsigned long) i); 17127 17128 printf ("\n"); 17129 if (ent == (bfd_vma) -1) 17130 break; 17131 } 17132 printf ("\n"); 17133 } 17134 17135 got_print_fail: 17136 if (data) 17137 free (data); 17138 } 17139 17140 if (mips_pltgot != 0 && jmprel != 0 && pltrel != 0 && pltrelsz != 0) 17141 { 17142 bfd_vma ent, end; 17143 size_t offset, rel_offset; 17144 unsigned long count, i; 17145 unsigned char * data; 17146 int addr_size, sym_width; 17147 Elf_Internal_Rela * rels; 17148 17149 rel_offset = offset_from_vma (filedata, jmprel, pltrelsz); 17150 if (pltrel == DT_RELA) 17151 { 17152 if (!slurp_rela_relocs (filedata, rel_offset, pltrelsz, &rels, &count)) 17153 return FALSE; 17154 } 17155 else 17156 { 17157 if (!slurp_rel_relocs (filedata, rel_offset, pltrelsz, &rels, &count)) 17158 return FALSE; 17159 } 17160 17161 ent = mips_pltgot; 17162 addr_size = (is_32bit_elf ? 4 : 8); 17163 end = mips_pltgot + (2 + count) * addr_size; 17164 17165 offset = offset_from_vma (filedata, mips_pltgot, end - mips_pltgot); 17166 data = (unsigned char *) get_data (NULL, filedata, offset, end - mips_pltgot, 17167 1, _("Procedure Linkage Table data")); 17168 if (data == NULL) 17169 return FALSE; 17170 17171 printf ("\nPLT GOT:\n\n"); 17172 printf (_(" Reserved entries:\n")); 17173 printf (_(" %*s %*s Purpose\n"), 17174 addr_size * 2, _("Address"), addr_size * 2, _("Initial")); 17175 ent = print_mips_pltgot_entry (data, mips_pltgot, ent); 17176 printf (_(" PLT lazy resolver\n")); 17177 ent = print_mips_pltgot_entry (data, mips_pltgot, ent); 17178 printf (_(" Module pointer\n")); 17179 printf ("\n"); 17180 17181 printf (_(" Entries:\n")); 17182 printf (" %*s %*s %*s %-7s %3s %s\n", 17183 addr_size * 2, _("Address"), 17184 addr_size * 2, _("Initial"), 17185 addr_size * 2, _("Sym.Val."), _("Type"), _("Ndx"), _("Name")); 17186 sym_width = (is_32bit_elf ? 80 : 160) - 17 - addr_size * 6 - 1; 17187 for (i = 0; i < count; i++) 17188 { 17189 unsigned long idx = get_reloc_symindex (rels[i].r_info); 17190 17191 ent = print_mips_pltgot_entry (data, mips_pltgot, ent); 17192 printf (" "); 17193 17194 if (idx >= num_dynamic_syms) 17195 printf (_("<corrupt symbol index: %lu>"), idx); 17196 else 17197 { 17198 Elf_Internal_Sym * psym = dynamic_symbols + idx; 17199 17200 print_vma (psym->st_value, LONG_HEX); 17201 printf (" %-7s %3s ", 17202 get_symbol_type (filedata, ELF_ST_TYPE (psym->st_info)), 17203 get_symbol_index_type (filedata, psym->st_shndx)); 17204 if (VALID_DYNAMIC_NAME (psym->st_name)) 17205 print_symbol (sym_width, GET_DYNAMIC_NAME (psym->st_name)); 17206 else 17207 printf (_("<corrupt: %14ld>"), psym->st_name); 17208 } 17209 printf ("\n"); 17210 } 17211 printf ("\n"); 17212 17213 if (data) 17214 free (data); 17215 free (rels); 17216 } 17217 17218 return res; 17219 } 17220 17221 static bfd_boolean 17222 process_nds32_specific (Filedata * filedata) 17223 { 17224 Elf_Internal_Shdr *sect = NULL; 17225 17226 sect = find_section (filedata, ".nds32_e_flags"); 17227 if (sect != NULL) 17228 { 17229 unsigned int *flag; 17230 17231 printf ("\nNDS32 elf flags section:\n"); 17232 flag = get_data (NULL, filedata, sect->sh_offset, 1, 17233 sect->sh_size, _("NDS32 elf flags section")); 17234 17235 if (! flag) 17236 return FALSE; 17237 17238 switch ((*flag) & 0x3) 17239 { 17240 case 0: 17241 printf ("(VEC_SIZE):\tNo entry.\n"); 17242 break; 17243 case 1: 17244 printf ("(VEC_SIZE):\t4 bytes\n"); 17245 break; 17246 case 2: 17247 printf ("(VEC_SIZE):\t16 bytes\n"); 17248 break; 17249 case 3: 17250 printf ("(VEC_SIZE):\treserved\n"); 17251 break; 17252 } 17253 } 17254 17255 return TRUE; 17256 } 17257 17258 static bfd_boolean 17259 process_gnu_liblist (Filedata * filedata) 17260 { 17261 Elf_Internal_Shdr * section; 17262 Elf_Internal_Shdr * string_sec; 17263 Elf32_External_Lib * elib; 17264 char * strtab; 17265 size_t strtab_size; 17266 size_t cnt; 17267 unsigned long num_liblist; 17268 unsigned i; 17269 bfd_boolean res = TRUE; 17270 17271 if (! do_arch) 17272 return TRUE; 17273 17274 for (i = 0, section = filedata->section_headers; 17275 i < filedata->file_header.e_shnum; 17276 i++, section++) 17277 { 17278 switch (section->sh_type) 17279 { 17280 case SHT_GNU_LIBLIST: 17281 if (section->sh_link >= filedata->file_header.e_shnum) 17282 break; 17283 17284 elib = (Elf32_External_Lib *) 17285 get_data (NULL, filedata, section->sh_offset, 1, section->sh_size, 17286 _("liblist section data")); 17287 17288 if (elib == NULL) 17289 { 17290 res = FALSE; 17291 break; 17292 } 17293 17294 string_sec = filedata->section_headers + section->sh_link; 17295 strtab = (char *) get_data (NULL, filedata, string_sec->sh_offset, 1, 17296 string_sec->sh_size, 17297 _("liblist string table")); 17298 if (strtab == NULL 17299 || section->sh_entsize != sizeof (Elf32_External_Lib)) 17300 { 17301 free (elib); 17302 free (strtab); 17303 res = FALSE; 17304 break; 17305 } 17306 strtab_size = string_sec->sh_size; 17307 17308 num_liblist = section->sh_size / sizeof (Elf32_External_Lib); 17309 printf (ngettext ("\nLibrary list section '%s' contains %lu entries:\n", 17310 "\nLibrary list section '%s' contains %lu entries:\n", 17311 num_liblist), 17312 printable_section_name (filedata, section), 17313 num_liblist); 17314 17315 puts (_(" Library Time Stamp Checksum Version Flags")); 17316 17317 for (cnt = 0; cnt < section->sh_size / sizeof (Elf32_External_Lib); 17318 ++cnt) 17319 { 17320 Elf32_Lib liblist; 17321 time_t atime; 17322 char timebuf[128]; 17323 struct tm * tmp; 17324 17325 liblist.l_name = BYTE_GET (elib[cnt].l_name); 17326 atime = BYTE_GET (elib[cnt].l_time_stamp); 17327 liblist.l_checksum = BYTE_GET (elib[cnt].l_checksum); 17328 liblist.l_version = BYTE_GET (elib[cnt].l_version); 17329 liblist.l_flags = BYTE_GET (elib[cnt].l_flags); 17330 17331 tmp = gmtime (&atime); 17332 snprintf (timebuf, sizeof (timebuf), 17333 "%04u-%02u-%02uT%02u:%02u:%02u", 17334 tmp->tm_year + 1900, tmp->tm_mon + 1, tmp->tm_mday, 17335 tmp->tm_hour, tmp->tm_min, tmp->tm_sec); 17336 17337 printf ("%3lu: ", (unsigned long) cnt); 17338 if (do_wide) 17339 printf ("%-20s", liblist.l_name < strtab_size 17340 ? strtab + liblist.l_name : _("<corrupt>")); 17341 else 17342 printf ("%-20.20s", liblist.l_name < strtab_size 17343 ? strtab + liblist.l_name : _("<corrupt>")); 17344 printf (" %s %#010lx %-7ld %-7ld\n", timebuf, liblist.l_checksum, 17345 liblist.l_version, liblist.l_flags); 17346 } 17347 17348 free (elib); 17349 free (strtab); 17350 } 17351 } 17352 17353 return res; 17354 } 17355 17356 static const char * 17357 get_note_type (Filedata * filedata, unsigned e_type) 17358 { 17359 static char buff[64]; 17360 17361 if (filedata->file_header.e_type == ET_CORE) 17362 switch (e_type) 17363 { 17364 case NT_AUXV: 17365 return _("NT_AUXV (auxiliary vector)"); 17366 case NT_PRSTATUS: 17367 return _("NT_PRSTATUS (prstatus structure)"); 17368 case NT_FPREGSET: 17369 return _("NT_FPREGSET (floating point registers)"); 17370 case NT_PRPSINFO: 17371 return _("NT_PRPSINFO (prpsinfo structure)"); 17372 case NT_TASKSTRUCT: 17373 return _("NT_TASKSTRUCT (task structure)"); 17374 case NT_PRXFPREG: 17375 return _("NT_PRXFPREG (user_xfpregs structure)"); 17376 case NT_PPC_VMX: 17377 return _("NT_PPC_VMX (ppc Altivec registers)"); 17378 case NT_PPC_VSX: 17379 return _("NT_PPC_VSX (ppc VSX registers)"); 17380 case NT_PPC_TAR: 17381 return _("NT_PPC_TAR (ppc TAR register)"); 17382 case NT_PPC_PPR: 17383 return _("NT_PPC_PPR (ppc PPR register)"); 17384 case NT_PPC_DSCR: 17385 return _("NT_PPC_DSCR (ppc DSCR register)"); 17386 case NT_PPC_EBB: 17387 return _("NT_PPC_EBB (ppc EBB registers)"); 17388 case NT_PPC_PMU: 17389 return _("NT_PPC_PMU (ppc PMU registers)"); 17390 case NT_PPC_TM_CGPR: 17391 return _("NT_PPC_TM_CGPR (ppc checkpointed GPR registers)"); 17392 case NT_PPC_TM_CFPR: 17393 return _("NT_PPC_TM_CFPR (ppc checkpointed floating point registers)"); 17394 case NT_PPC_TM_CVMX: 17395 return _("NT_PPC_TM_CVMX (ppc checkpointed Altivec registers)"); 17396 case NT_PPC_TM_CVSX: 17397 return _("NT_PPC_TM_CVSX (ppc checkpointed VSX registers)"); 17398 case NT_PPC_TM_SPR: 17399 return _("NT_PPC_TM_SPR (ppc TM special purpose registers)"); 17400 case NT_PPC_TM_CTAR: 17401 return _("NT_PPC_TM_CTAR (ppc checkpointed TAR register)"); 17402 case NT_PPC_TM_CPPR: 17403 return _("NT_PPC_TM_CPPR (ppc checkpointed PPR register)"); 17404 case NT_PPC_TM_CDSCR: 17405 return _("NT_PPC_TM_CDSCR (ppc checkpointed DSCR register)"); 17406 case NT_386_TLS: 17407 return _("NT_386_TLS (x86 TLS information)"); 17408 case NT_386_IOPERM: 17409 return _("NT_386_IOPERM (x86 I/O permissions)"); 17410 case NT_X86_XSTATE: 17411 return _("NT_X86_XSTATE (x86 XSAVE extended state)"); 17412 case NT_S390_HIGH_GPRS: 17413 return _("NT_S390_HIGH_GPRS (s390 upper register halves)"); 17414 case NT_S390_TIMER: 17415 return _("NT_S390_TIMER (s390 timer register)"); 17416 case NT_S390_TODCMP: 17417 return _("NT_S390_TODCMP (s390 TOD comparator register)"); 17418 case NT_S390_TODPREG: 17419 return _("NT_S390_TODPREG (s390 TOD programmable register)"); 17420 case NT_S390_CTRS: 17421 return _("NT_S390_CTRS (s390 control registers)"); 17422 case NT_S390_PREFIX: 17423 return _("NT_S390_PREFIX (s390 prefix register)"); 17424 case NT_S390_LAST_BREAK: 17425 return _("NT_S390_LAST_BREAK (s390 last breaking event address)"); 17426 case NT_S390_SYSTEM_CALL: 17427 return _("NT_S390_SYSTEM_CALL (s390 system call restart data)"); 17428 case NT_S390_TDB: 17429 return _("NT_S390_TDB (s390 transaction diagnostic block)"); 17430 case NT_S390_VXRS_LOW: 17431 return _("NT_S390_VXRS_LOW (s390 vector registers 0-15 upper half)"); 17432 case NT_S390_VXRS_HIGH: 17433 return _("NT_S390_VXRS_HIGH (s390 vector registers 16-31)"); 17434 case NT_S390_GS_CB: 17435 return _("NT_S390_GS_CB (s390 guarded-storage registers)"); 17436 case NT_S390_GS_BC: 17437 return _("NT_S390_GS_BC (s390 guarded-storage broadcast control)"); 17438 case NT_ARM_VFP: 17439 return _("NT_ARM_VFP (arm VFP registers)"); 17440 case NT_ARM_TLS: 17441 return _("NT_ARM_TLS (AArch TLS registers)"); 17442 case NT_ARM_HW_BREAK: 17443 return _("NT_ARM_HW_BREAK (AArch hardware breakpoint registers)"); 17444 case NT_ARM_HW_WATCH: 17445 return _("NT_ARM_HW_WATCH (AArch hardware watchpoint registers)"); 17446 case NT_PSTATUS: 17447 return _("NT_PSTATUS (pstatus structure)"); 17448 case NT_FPREGS: 17449 return _("NT_FPREGS (floating point registers)"); 17450 case NT_PSINFO: 17451 return _("NT_PSINFO (psinfo structure)"); 17452 case NT_LWPSTATUS: 17453 return _("NT_LWPSTATUS (lwpstatus_t structure)"); 17454 case NT_LWPSINFO: 17455 return _("NT_LWPSINFO (lwpsinfo_t structure)"); 17456 case NT_WIN32PSTATUS: 17457 return _("NT_WIN32PSTATUS (win32_pstatus structure)"); 17458 case NT_SIGINFO: 17459 return _("NT_SIGINFO (siginfo_t data)"); 17460 case NT_FILE: 17461 return _("NT_FILE (mapped files)"); 17462 default: 17463 break; 17464 } 17465 else 17466 switch (e_type) 17467 { 17468 case NT_VERSION: 17469 return _("NT_VERSION (version)"); 17470 case NT_ARCH: 17471 return _("NT_ARCH (architecture)"); 17472 case NT_GNU_BUILD_ATTRIBUTE_OPEN: 17473 return _("OPEN"); 17474 case NT_GNU_BUILD_ATTRIBUTE_FUNC: 17475 return _("func"); 17476 default: 17477 break; 17478 } 17479 17480 snprintf (buff, sizeof (buff), _("Unknown note type: (0x%08x)"), e_type); 17481 return buff; 17482 } 17483 17484 static bfd_boolean 17485 print_core_note (Elf_Internal_Note *pnote) 17486 { 17487 unsigned int addr_size = is_32bit_elf ? 4 : 8; 17488 bfd_vma count, page_size; 17489 unsigned char *descdata, *filenames, *descend; 17490 17491 if (pnote->type != NT_FILE) 17492 { 17493 if (do_wide) 17494 printf ("\n"); 17495 return TRUE; 17496 } 17497 17498 #ifndef BFD64 17499 if (!is_32bit_elf) 17500 { 17501 printf (_(" Cannot decode 64-bit note in 32-bit build\n")); 17502 /* Still "successful". */ 17503 return TRUE; 17504 } 17505 #endif 17506 17507 if (pnote->descsz < 2 * addr_size) 17508 { 17509 error (_(" Malformed note - too short for header\n")); 17510 return FALSE; 17511 } 17512 17513 descdata = (unsigned char *) pnote->descdata; 17514 descend = descdata + pnote->descsz; 17515 17516 if (descdata[pnote->descsz - 1] != '\0') 17517 { 17518 error (_(" Malformed note - does not end with \\0\n")); 17519 return FALSE; 17520 } 17521 17522 count = byte_get (descdata, addr_size); 17523 descdata += addr_size; 17524 17525 page_size = byte_get (descdata, addr_size); 17526 descdata += addr_size; 17527 17528 if (count > ((bfd_vma) -1 - 2 * addr_size) / (3 * addr_size) 17529 || pnote->descsz < 2 * addr_size + count * 3 * addr_size) 17530 { 17531 error (_(" Malformed note - too short for supplied file count\n")); 17532 return FALSE; 17533 } 17534 17535 printf (_(" Page size: ")); 17536 print_vma (page_size, DEC); 17537 printf ("\n"); 17538 17539 printf (_(" %*s%*s%*s\n"), 17540 (int) (2 + 2 * addr_size), _("Start"), 17541 (int) (4 + 2 * addr_size), _("End"), 17542 (int) (4 + 2 * addr_size), _("Page Offset")); 17543 filenames = descdata + count * 3 * addr_size; 17544 while (count-- > 0) 17545 { 17546 bfd_vma start, end, file_ofs; 17547 17548 if (filenames == descend) 17549 { 17550 error (_(" Malformed note - filenames end too early\n")); 17551 return FALSE; 17552 } 17553 17554 start = byte_get (descdata, addr_size); 17555 descdata += addr_size; 17556 end = byte_get (descdata, addr_size); 17557 descdata += addr_size; 17558 file_ofs = byte_get (descdata, addr_size); 17559 descdata += addr_size; 17560 17561 printf (" "); 17562 print_vma (start, FULL_HEX); 17563 printf (" "); 17564 print_vma (end, FULL_HEX); 17565 printf (" "); 17566 print_vma (file_ofs, FULL_HEX); 17567 printf ("\n %s\n", filenames); 17568 17569 filenames += 1 + strlen ((char *) filenames); 17570 } 17571 17572 return TRUE; 17573 } 17574 17575 static const char * 17576 get_gnu_elf_note_type (unsigned e_type) 17577 { 17578 /* NB/ Keep this switch statement in sync with print_gnu_note (). */ 17579 switch (e_type) 17580 { 17581 case NT_GNU_ABI_TAG: 17582 return _("NT_GNU_ABI_TAG (ABI version tag)"); 17583 case NT_GNU_HWCAP: 17584 return _("NT_GNU_HWCAP (DSO-supplied software HWCAP info)"); 17585 case NT_GNU_BUILD_ID: 17586 return _("NT_GNU_BUILD_ID (unique build ID bitstring)"); 17587 case NT_GNU_GOLD_VERSION: 17588 return _("NT_GNU_GOLD_VERSION (gold version)"); 17589 case NT_GNU_PROPERTY_TYPE_0: 17590 return _("NT_GNU_PROPERTY_TYPE_0"); 17591 case NT_GNU_BUILD_ATTRIBUTE_OPEN: 17592 return _("NT_GNU_BUILD_ATTRIBUTE_OPEN"); 17593 case NT_GNU_BUILD_ATTRIBUTE_FUNC: 17594 return _("NT_GNU_BUILD_ATTRIBUTE_FUNC"); 17595 default: 17596 { 17597 static char buff[64]; 17598 17599 snprintf (buff, sizeof (buff), _("Unknown note type: (0x%08x)"), e_type); 17600 return buff; 17601 } 17602 } 17603 } 17604 17605 static void 17606 decode_x86_compat_isa (unsigned int bitmask) 17607 { 17608 while (bitmask) 17609 { 17610 unsigned int bit = bitmask & (- bitmask); 17611 17612 bitmask &= ~ bit; 17613 switch (bit) 17614 { 17615 case GNU_PROPERTY_X86_COMPAT_ISA_1_486: 17616 printf ("i486"); 17617 break; 17618 case GNU_PROPERTY_X86_COMPAT_ISA_1_586: 17619 printf ("586"); 17620 break; 17621 case GNU_PROPERTY_X86_COMPAT_ISA_1_686: 17622 printf ("686"); 17623 break; 17624 case GNU_PROPERTY_X86_COMPAT_ISA_1_SSE: 17625 printf ("SSE"); 17626 break; 17627 case GNU_PROPERTY_X86_COMPAT_ISA_1_SSE2: 17628 printf ("SSE2"); 17629 break; 17630 case GNU_PROPERTY_X86_COMPAT_ISA_1_SSE3: 17631 printf ("SSE3"); 17632 break; 17633 case GNU_PROPERTY_X86_COMPAT_ISA_1_SSSE3: 17634 printf ("SSSE3"); 17635 break; 17636 case GNU_PROPERTY_X86_COMPAT_ISA_1_SSE4_1: 17637 printf ("SSE4_1"); 17638 break; 17639 case GNU_PROPERTY_X86_COMPAT_ISA_1_SSE4_2: 17640 printf ("SSE4_2"); 17641 break; 17642 case GNU_PROPERTY_X86_COMPAT_ISA_1_AVX: 17643 printf ("AVX"); 17644 break; 17645 case GNU_PROPERTY_X86_COMPAT_ISA_1_AVX2: 17646 printf ("AVX2"); 17647 break; 17648 case GNU_PROPERTY_X86_COMPAT_ISA_1_AVX512F: 17649 printf ("AVX512F"); 17650 break; 17651 case GNU_PROPERTY_X86_COMPAT_ISA_1_AVX512CD: 17652 printf ("AVX512CD"); 17653 break; 17654 case GNU_PROPERTY_X86_COMPAT_ISA_1_AVX512ER: 17655 printf ("AVX512ER"); 17656 break; 17657 case GNU_PROPERTY_X86_COMPAT_ISA_1_AVX512PF: 17658 printf ("AVX512PF"); 17659 break; 17660 case GNU_PROPERTY_X86_COMPAT_ISA_1_AVX512VL: 17661 printf ("AVX512VL"); 17662 break; 17663 case GNU_PROPERTY_X86_COMPAT_ISA_1_AVX512DQ: 17664 printf ("AVX512DQ"); 17665 break; 17666 case GNU_PROPERTY_X86_COMPAT_ISA_1_AVX512BW: 17667 printf ("AVX512BW"); 17668 break; 17669 default: 17670 printf (_("<unknown: %x>"), bit); 17671 break; 17672 } 17673 if (bitmask) 17674 printf (", "); 17675 } 17676 } 17677 17678 static void 17679 decode_x86_isa (unsigned int bitmask) 17680 { 17681 if (!bitmask) 17682 { 17683 printf (_("<None>")); 17684 return; 17685 } 17686 17687 while (bitmask) 17688 { 17689 unsigned int bit = bitmask & (- bitmask); 17690 17691 bitmask &= ~ bit; 17692 switch (bit) 17693 { 17694 case GNU_PROPERTY_X86_ISA_1_CMOV: 17695 printf ("CMOV"); 17696 break; 17697 case GNU_PROPERTY_X86_ISA_1_SSE: 17698 printf ("SSE"); 17699 break; 17700 case GNU_PROPERTY_X86_ISA_1_SSE2: 17701 printf ("SSE2"); 17702 break; 17703 case GNU_PROPERTY_X86_ISA_1_SSE3: 17704 printf ("SSE3"); 17705 break; 17706 case GNU_PROPERTY_X86_ISA_1_SSSE3: 17707 printf ("SSSE3"); 17708 break; 17709 case GNU_PROPERTY_X86_ISA_1_SSE4_1: 17710 printf ("SSE4_1"); 17711 break; 17712 case GNU_PROPERTY_X86_ISA_1_SSE4_2: 17713 printf ("SSE4_2"); 17714 break; 17715 case GNU_PROPERTY_X86_ISA_1_AVX: 17716 printf ("AVX"); 17717 break; 17718 case GNU_PROPERTY_X86_ISA_1_AVX2: 17719 printf ("AVX2"); 17720 break; 17721 case GNU_PROPERTY_X86_ISA_1_FMA: 17722 printf ("FMA"); 17723 break; 17724 case GNU_PROPERTY_X86_ISA_1_AVX512F: 17725 printf ("AVX512F"); 17726 break; 17727 case GNU_PROPERTY_X86_ISA_1_AVX512CD: 17728 printf ("AVX512CD"); 17729 break; 17730 case GNU_PROPERTY_X86_ISA_1_AVX512ER: 17731 printf ("AVX512ER"); 17732 break; 17733 case GNU_PROPERTY_X86_ISA_1_AVX512PF: 17734 printf ("AVX512PF"); 17735 break; 17736 case GNU_PROPERTY_X86_ISA_1_AVX512VL: 17737 printf ("AVX512VL"); 17738 break; 17739 case GNU_PROPERTY_X86_ISA_1_AVX512DQ: 17740 printf ("AVX512DQ"); 17741 break; 17742 case GNU_PROPERTY_X86_ISA_1_AVX512BW: 17743 printf ("AVX512BW"); 17744 break; 17745 case GNU_PROPERTY_X86_ISA_1_AVX512_4FMAPS: 17746 printf ("AVX512_4FMAPS"); 17747 break; 17748 case GNU_PROPERTY_X86_ISA_1_AVX512_4VNNIW: 17749 printf ("AVX512_4VNNIW"); 17750 break; 17751 case GNU_PROPERTY_X86_ISA_1_AVX512_BITALG: 17752 printf ("AVX512_BITALG"); 17753 break; 17754 case GNU_PROPERTY_X86_ISA_1_AVX512_IFMA: 17755 printf ("AVX512_IFMA"); 17756 break; 17757 case GNU_PROPERTY_X86_ISA_1_AVX512_VBMI: 17758 printf ("AVX512_VBMI"); 17759 break; 17760 case GNU_PROPERTY_X86_ISA_1_AVX512_VBMI2: 17761 printf ("AVX512_VBMI2"); 17762 break; 17763 case GNU_PROPERTY_X86_ISA_1_AVX512_VNNI: 17764 printf ("AVX512_VNNI"); 17765 break; 17766 case GNU_PROPERTY_X86_ISA_1_AVX512_BF16: 17767 printf ("AVX512_BF16"); 17768 break; 17769 default: 17770 printf (_("<unknown: %x>"), bit); 17771 break; 17772 } 17773 if (bitmask) 17774 printf (", "); 17775 } 17776 } 17777 17778 static void 17779 decode_x86_feature_1 (unsigned int bitmask) 17780 { 17781 if (!bitmask) 17782 { 17783 printf (_("<None>")); 17784 return; 17785 } 17786 17787 while (bitmask) 17788 { 17789 unsigned int bit = bitmask & (- bitmask); 17790 17791 bitmask &= ~ bit; 17792 switch (bit) 17793 { 17794 case GNU_PROPERTY_X86_FEATURE_1_IBT: 17795 printf ("IBT"); 17796 break; 17797 case GNU_PROPERTY_X86_FEATURE_1_SHSTK: 17798 printf ("SHSTK"); 17799 break; 17800 default: 17801 printf (_("<unknown: %x>"), bit); 17802 break; 17803 } 17804 if (bitmask) 17805 printf (", "); 17806 } 17807 } 17808 17809 static void 17810 decode_x86_feature_2 (unsigned int bitmask) 17811 { 17812 if (!bitmask) 17813 { 17814 printf (_("<None>")); 17815 return; 17816 } 17817 17818 while (bitmask) 17819 { 17820 unsigned int bit = bitmask & (- bitmask); 17821 17822 bitmask &= ~ bit; 17823 switch (bit) 17824 { 17825 case GNU_PROPERTY_X86_FEATURE_2_X86: 17826 printf ("x86"); 17827 break; 17828 case GNU_PROPERTY_X86_FEATURE_2_X87: 17829 printf ("x87"); 17830 break; 17831 case GNU_PROPERTY_X86_FEATURE_2_MMX: 17832 printf ("MMX"); 17833 break; 17834 case GNU_PROPERTY_X86_FEATURE_2_XMM: 17835 printf ("XMM"); 17836 break; 17837 case GNU_PROPERTY_X86_FEATURE_2_YMM: 17838 printf ("YMM"); 17839 break; 17840 case GNU_PROPERTY_X86_FEATURE_2_ZMM: 17841 printf ("ZMM"); 17842 break; 17843 case GNU_PROPERTY_X86_FEATURE_2_FXSR: 17844 printf ("FXSR"); 17845 break; 17846 case GNU_PROPERTY_X86_FEATURE_2_XSAVE: 17847 printf ("XSAVE"); 17848 break; 17849 case GNU_PROPERTY_X86_FEATURE_2_XSAVEOPT: 17850 printf ("XSAVEOPT"); 17851 break; 17852 case GNU_PROPERTY_X86_FEATURE_2_XSAVEC: 17853 printf ("XSAVEC"); 17854 break; 17855 default: 17856 printf (_("<unknown: %x>"), bit); 17857 break; 17858 } 17859 if (bitmask) 17860 printf (", "); 17861 } 17862 } 17863 17864 static void 17865 decode_aarch64_feature_1_and (unsigned int bitmask) 17866 { 17867 while (bitmask) 17868 { 17869 unsigned int bit = bitmask & (- bitmask); 17870 17871 bitmask &= ~ bit; 17872 switch (bit) 17873 { 17874 case GNU_PROPERTY_AARCH64_FEATURE_1_BTI: 17875 printf ("BTI"); 17876 break; 17877 17878 case GNU_PROPERTY_AARCH64_FEATURE_1_PAC: 17879 printf ("PAC"); 17880 break; 17881 17882 default: 17883 printf (_("<unknown: %x>"), bit); 17884 break; 17885 } 17886 if (bitmask) 17887 printf (", "); 17888 } 17889 } 17890 17891 static void 17892 print_gnu_property_note (Filedata * filedata, Elf_Internal_Note * pnote) 17893 { 17894 unsigned char * ptr = (unsigned char *) pnote->descdata; 17895 unsigned char * ptr_end = ptr + pnote->descsz; 17896 unsigned int size = is_32bit_elf ? 4 : 8; 17897 17898 printf (_(" Properties: ")); 17899 17900 if (pnote->descsz < 8 || (pnote->descsz % size) != 0) 17901 { 17902 printf (_("<corrupt GNU_PROPERTY_TYPE, size = %#lx>\n"), pnote->descsz); 17903 return; 17904 } 17905 17906 while (ptr < ptr_end) 17907 { 17908 unsigned int j; 17909 unsigned int type; 17910 unsigned int datasz; 17911 17912 if ((size_t) (ptr_end - ptr) < 8) 17913 { 17914 printf (_("<corrupt descsz: %#lx>\n"), pnote->descsz); 17915 break; 17916 } 17917 17918 type = byte_get (ptr, 4); 17919 datasz = byte_get (ptr + 4, 4); 17920 17921 ptr += 8; 17922 17923 if (datasz > (size_t) (ptr_end - ptr)) 17924 { 17925 printf (_("<corrupt type (%#x) datasz: %#x>\n"), 17926 type, datasz); 17927 break; 17928 } 17929 17930 if (type >= GNU_PROPERTY_LOPROC && type <= GNU_PROPERTY_HIPROC) 17931 { 17932 if (filedata->file_header.e_machine == EM_X86_64 17933 || filedata->file_header.e_machine == EM_IAMCU 17934 || filedata->file_header.e_machine == EM_386) 17935 { 17936 unsigned int bitmask; 17937 17938 if (datasz == 4) 17939 bitmask = byte_get (ptr, 4); 17940 else 17941 bitmask = 0; 17942 17943 switch (type) 17944 { 17945 case GNU_PROPERTY_X86_ISA_1_USED: 17946 if (datasz != 4) 17947 printf (_("x86 ISA used: <corrupt length: %#x> "), 17948 datasz); 17949 else 17950 { 17951 printf ("x86 ISA used: "); 17952 decode_x86_isa (bitmask); 17953 } 17954 goto next; 17955 17956 case GNU_PROPERTY_X86_ISA_1_NEEDED: 17957 if (datasz != 4) 17958 printf (_("x86 ISA needed: <corrupt length: %#x> "), 17959 datasz); 17960 else 17961 { 17962 printf ("x86 ISA needed: "); 17963 decode_x86_isa (bitmask); 17964 } 17965 goto next; 17966 17967 case GNU_PROPERTY_X86_FEATURE_1_AND: 17968 if (datasz != 4) 17969 printf (_("x86 feature: <corrupt length: %#x> "), 17970 datasz); 17971 else 17972 { 17973 printf ("x86 feature: "); 17974 decode_x86_feature_1 (bitmask); 17975 } 17976 goto next; 17977 17978 case GNU_PROPERTY_X86_FEATURE_2_USED: 17979 if (datasz != 4) 17980 printf (_("x86 feature used: <corrupt length: %#x> "), 17981 datasz); 17982 else 17983 { 17984 printf ("x86 feature used: "); 17985 decode_x86_feature_2 (bitmask); 17986 } 17987 goto next; 17988 17989 case GNU_PROPERTY_X86_FEATURE_2_NEEDED: 17990 if (datasz != 4) 17991 printf (_("x86 feature needed: <corrupt length: %#x> "), datasz); 17992 else 17993 { 17994 printf ("x86 feature needed: "); 17995 decode_x86_feature_2 (bitmask); 17996 } 17997 goto next; 17998 17999 case GNU_PROPERTY_X86_COMPAT_ISA_1_USED: 18000 if (datasz != 4) 18001 printf (_("x86 ISA used: <corrupt length: %#x> "), 18002 datasz); 18003 else 18004 { 18005 printf ("x86 ISA used: "); 18006 decode_x86_compat_isa (bitmask); 18007 } 18008 goto next; 18009 18010 case GNU_PROPERTY_X86_COMPAT_ISA_1_NEEDED: 18011 if (datasz != 4) 18012 printf (_("x86 ISA needed: <corrupt length: %#x> "), 18013 datasz); 18014 else 18015 { 18016 printf ("x86 ISA needed: "); 18017 decode_x86_compat_isa (bitmask); 18018 } 18019 goto next; 18020 18021 default: 18022 break; 18023 } 18024 } 18025 else if (filedata->file_header.e_machine == EM_AARCH64) 18026 { 18027 if (type == GNU_PROPERTY_AARCH64_FEATURE_1_AND) 18028 { 18029 printf ("AArch64 feature: "); 18030 if (datasz != 4) 18031 printf (_("<corrupt length: %#x> "), datasz); 18032 else 18033 decode_aarch64_feature_1_and (byte_get (ptr, 4)); 18034 goto next; 18035 } 18036 } 18037 } 18038 else 18039 { 18040 switch (type) 18041 { 18042 case GNU_PROPERTY_STACK_SIZE: 18043 printf (_("stack size: ")); 18044 if (datasz != size) 18045 printf (_("<corrupt length: %#x> "), datasz); 18046 else 18047 printf ("%#lx", (unsigned long) byte_get (ptr, size)); 18048 goto next; 18049 18050 case GNU_PROPERTY_NO_COPY_ON_PROTECTED: 18051 printf ("no copy on protected "); 18052 if (datasz) 18053 printf (_("<corrupt length: %#x> "), datasz); 18054 goto next; 18055 18056 default: 18057 break; 18058 } 18059 } 18060 18061 if (type < GNU_PROPERTY_LOPROC) 18062 printf (_("<unknown type %#x data: "), type); 18063 else if (type < GNU_PROPERTY_LOUSER) 18064 printf (_("<procesor-specific type %#x data: "), type); 18065 else 18066 printf (_("<application-specific type %#x data: "), type); 18067 for (j = 0; j < datasz; ++j) 18068 printf ("%02x ", ptr[j] & 0xff); 18069 printf (">"); 18070 18071 next: 18072 ptr += ((datasz + (size - 1)) & ~ (size - 1)); 18073 if (ptr == ptr_end) 18074 break; 18075 18076 if (do_wide) 18077 printf (", "); 18078 else 18079 printf ("\n\t"); 18080 } 18081 18082 printf ("\n"); 18083 } 18084 18085 static bfd_boolean 18086 print_gnu_note (Filedata * filedata, Elf_Internal_Note *pnote) 18087 { 18088 /* NB/ Keep this switch statement in sync with get_gnu_elf_note_type (). */ 18089 switch (pnote->type) 18090 { 18091 case NT_GNU_BUILD_ID: 18092 { 18093 unsigned long i; 18094 18095 printf (_(" Build ID: ")); 18096 for (i = 0; i < pnote->descsz; ++i) 18097 printf ("%02x", pnote->descdata[i] & 0xff); 18098 printf ("\n"); 18099 } 18100 break; 18101 18102 case NT_GNU_ABI_TAG: 18103 { 18104 unsigned long os, major, minor, subminor; 18105 const char *osname; 18106 18107 /* PR 17531: file: 030-599401-0.004. */ 18108 if (pnote->descsz < 16) 18109 { 18110 printf (_(" <corrupt GNU_ABI_TAG>\n")); 18111 break; 18112 } 18113 18114 os = byte_get ((unsigned char *) pnote->descdata, 4); 18115 major = byte_get ((unsigned char *) pnote->descdata + 4, 4); 18116 minor = byte_get ((unsigned char *) pnote->descdata + 8, 4); 18117 subminor = byte_get ((unsigned char *) pnote->descdata + 12, 4); 18118 18119 switch (os) 18120 { 18121 case GNU_ABI_TAG_LINUX: 18122 osname = "Linux"; 18123 break; 18124 case GNU_ABI_TAG_HURD: 18125 osname = "Hurd"; 18126 break; 18127 case GNU_ABI_TAG_SOLARIS: 18128 osname = "Solaris"; 18129 break; 18130 case GNU_ABI_TAG_FREEBSD: 18131 osname = "FreeBSD"; 18132 break; 18133 case GNU_ABI_TAG_NETBSD: 18134 osname = "NetBSD"; 18135 break; 18136 case GNU_ABI_TAG_SYLLABLE: 18137 osname = "Syllable"; 18138 break; 18139 case GNU_ABI_TAG_NACL: 18140 osname = "NaCl"; 18141 break; 18142 default: 18143 osname = "Unknown"; 18144 break; 18145 } 18146 18147 printf (_(" OS: %s, ABI: %ld.%ld.%ld\n"), osname, 18148 major, minor, subminor); 18149 } 18150 break; 18151 18152 case NT_GNU_GOLD_VERSION: 18153 { 18154 unsigned long i; 18155 18156 printf (_(" Version: ")); 18157 for (i = 0; i < pnote->descsz && pnote->descdata[i] != '\0'; ++i) 18158 printf ("%c", pnote->descdata[i]); 18159 printf ("\n"); 18160 } 18161 break; 18162 18163 case NT_GNU_HWCAP: 18164 { 18165 unsigned long num_entries, mask; 18166 18167 /* Hardware capabilities information. Word 0 is the number of entries. 18168 Word 1 is a bitmask of enabled entries. The rest of the descriptor 18169 is a series of entries, where each entry is a single byte followed 18170 by a nul terminated string. The byte gives the bit number to test 18171 if enabled in the bitmask. */ 18172 printf (_(" Hardware Capabilities: ")); 18173 if (pnote->descsz < 8) 18174 { 18175 error (_("<corrupt GNU_HWCAP>\n")); 18176 return FALSE; 18177 } 18178 num_entries = byte_get ((unsigned char *) pnote->descdata, 4); 18179 mask = byte_get ((unsigned char *) pnote->descdata + 4, 4); 18180 printf (_("num entries: %ld, enabled mask: %lx\n"), num_entries, mask); 18181 /* FIXME: Add code to display the entries... */ 18182 } 18183 break; 18184 18185 case NT_GNU_PROPERTY_TYPE_0: 18186 print_gnu_property_note (filedata, pnote); 18187 break; 18188 18189 default: 18190 /* Handle unrecognised types. An error message should have already been 18191 created by get_gnu_elf_note_type(), so all that we need to do is to 18192 display the data. */ 18193 { 18194 unsigned long i; 18195 18196 printf (_(" Description data: ")); 18197 for (i = 0; i < pnote->descsz; ++i) 18198 printf ("%02x ", pnote->descdata[i] & 0xff); 18199 printf ("\n"); 18200 } 18201 break; 18202 } 18203 18204 return TRUE; 18205 } 18206 18207 static const char * 18208 get_v850_elf_note_type (enum v850_notes n_type) 18209 { 18210 static char buff[64]; 18211 18212 switch (n_type) 18213 { 18214 case V850_NOTE_ALIGNMENT: return _("Alignment of 8-byte objects"); 18215 case V850_NOTE_DATA_SIZE: return _("Sizeof double and long double"); 18216 case V850_NOTE_FPU_INFO: return _("Type of FPU support needed"); 18217 case V850_NOTE_SIMD_INFO: return _("Use of SIMD instructions"); 18218 case V850_NOTE_CACHE_INFO: return _("Use of cache"); 18219 case V850_NOTE_MMU_INFO: return _("Use of MMU"); 18220 default: 18221 snprintf (buff, sizeof (buff), _("Unknown note type: (0x%08x)"), n_type); 18222 return buff; 18223 } 18224 } 18225 18226 static bfd_boolean 18227 print_v850_note (Elf_Internal_Note * pnote) 18228 { 18229 unsigned int val; 18230 18231 if (pnote->descsz != 4) 18232 return FALSE; 18233 18234 val = byte_get ((unsigned char *) pnote->descdata, pnote->descsz); 18235 18236 if (val == 0) 18237 { 18238 printf (_("not set\n")); 18239 return TRUE; 18240 } 18241 18242 switch (pnote->type) 18243 { 18244 case V850_NOTE_ALIGNMENT: 18245 switch (val) 18246 { 18247 case EF_RH850_DATA_ALIGN4: printf (_("4-byte\n")); return TRUE; 18248 case EF_RH850_DATA_ALIGN8: printf (_("8-byte\n")); return TRUE; 18249 } 18250 break; 18251 18252 case V850_NOTE_DATA_SIZE: 18253 switch (val) 18254 { 18255 case EF_RH850_DOUBLE32: printf (_("4-bytes\n")); return TRUE; 18256 case EF_RH850_DOUBLE64: printf (_("8-bytes\n")); return TRUE; 18257 } 18258 break; 18259 18260 case V850_NOTE_FPU_INFO: 18261 switch (val) 18262 { 18263 case EF_RH850_FPU20: printf (_("FPU-2.0\n")); return TRUE; 18264 case EF_RH850_FPU30: printf (_("FPU-3.0\n")); return TRUE; 18265 } 18266 break; 18267 18268 case V850_NOTE_MMU_INFO: 18269 case V850_NOTE_CACHE_INFO: 18270 case V850_NOTE_SIMD_INFO: 18271 if (val == EF_RH850_SIMD) 18272 { 18273 printf (_("yes\n")); 18274 return TRUE; 18275 } 18276 break; 18277 18278 default: 18279 /* An 'unknown note type' message will already have been displayed. */ 18280 break; 18281 } 18282 18283 printf (_("unknown value: %x\n"), val); 18284 return FALSE; 18285 } 18286 18287 static bfd_boolean 18288 process_netbsd_elf_note (Elf_Internal_Note * pnote) 18289 { 18290 unsigned int version; 18291 18292 switch (pnote->type) 18293 { 18294 case NT_NETBSD_IDENT: 18295 version = byte_get((unsigned char *)pnote->descdata, sizeof(version)); 18296 if ((version / 10000) % 100) 18297 printf (" NetBSD\t0x%08lx\tIDENT %u (%u.%u%s%c)\n", pnote->descsz, 18298 version, version / 100000000, (version / 1000000) % 100, 18299 (version / 10000) % 100 > 26 ? "Z" : "", 18300 'A' + (version / 10000) % 26); 18301 else 18302 printf (" NetBSD\t\t0x%08lx\tIDENT %u (%u.%u.%u)\n", pnote->descsz, 18303 version, version / 100000000, (version / 1000000) % 100, 18304 (version / 100) % 100); 18305 return TRUE; 18306 18307 case NT_NETBSD_MARCH: 18308 printf (" NetBSD\t\t0x%08lx\tMARCH <%s>\n", pnote->descsz, 18309 pnote->descdata); 18310 return TRUE; 18311 18312 #ifdef NT_NETBSD_PAX 18313 case NT_NETBSD_PAX: 18314 version = byte_get ((unsigned char *) pnote->descdata, sizeof (version)); 18315 printf (" NetBSD\t\t0x%08lx\tPaX <%s%s%s%s%s%s>\n", pnote->descsz, 18316 ((version & NT_NETBSD_PAX_MPROTECT) ? "+mprotect" : ""), 18317 ((version & NT_NETBSD_PAX_NOMPROTECT) ? "-mprotect" : ""), 18318 ((version & NT_NETBSD_PAX_GUARD) ? "+guard" : ""), 18319 ((version & NT_NETBSD_PAX_NOGUARD) ? "-guard" : ""), 18320 ((version & NT_NETBSD_PAX_ASLR) ? "+ASLR" : ""), 18321 ((version & NT_NETBSD_PAX_NOASLR) ? "-ASLR" : "")); 18322 return TRUE; 18323 #endif 18324 18325 default: 18326 printf (" NetBSD\t0x%08lx\tUnknown note type: (0x%08lx)\n", pnote->descsz, 18327 pnote->type); 18328 return FALSE; 18329 } 18330 } 18331 18332 static const char * 18333 get_freebsd_elfcore_note_type (Filedata * filedata, unsigned e_type) 18334 { 18335 switch (e_type) 18336 { 18337 case NT_FREEBSD_THRMISC: 18338 return _("NT_THRMISC (thrmisc structure)"); 18339 case NT_FREEBSD_PROCSTAT_PROC: 18340 return _("NT_PROCSTAT_PROC (proc data)"); 18341 case NT_FREEBSD_PROCSTAT_FILES: 18342 return _("NT_PROCSTAT_FILES (files data)"); 18343 case NT_FREEBSD_PROCSTAT_VMMAP: 18344 return _("NT_PROCSTAT_VMMAP (vmmap data)"); 18345 case NT_FREEBSD_PROCSTAT_GROUPS: 18346 return _("NT_PROCSTAT_GROUPS (groups data)"); 18347 case NT_FREEBSD_PROCSTAT_UMASK: 18348 return _("NT_PROCSTAT_UMASK (umask data)"); 18349 case NT_FREEBSD_PROCSTAT_RLIMIT: 18350 return _("NT_PROCSTAT_RLIMIT (rlimit data)"); 18351 case NT_FREEBSD_PROCSTAT_OSREL: 18352 return _("NT_PROCSTAT_OSREL (osreldate data)"); 18353 case NT_FREEBSD_PROCSTAT_PSSTRINGS: 18354 return _("NT_PROCSTAT_PSSTRINGS (ps_strings data)"); 18355 case NT_FREEBSD_PROCSTAT_AUXV: 18356 return _("NT_PROCSTAT_AUXV (auxv data)"); 18357 case NT_FREEBSD_PTLWPINFO: 18358 return _("NT_PTLWPINFO (ptrace_lwpinfo structure)"); 18359 } 18360 return get_note_type (filedata, e_type); 18361 } 18362 18363 static const char * 18364 get_netbsd_elfcore_note_type (Filedata * filedata, unsigned e_type) 18365 { 18366 static char buff[64]; 18367 18368 switch (e_type) 18369 { 18370 case NT_NETBSDCORE_PROCINFO: 18371 /* NetBSD core "procinfo" structure. */ 18372 return _("NetBSD procinfo structure"); 18373 18374 #ifdef NT_NETBSDCORE_AUXV 18375 case NT_NETBSDCORE_AUXV: 18376 return _("NetBSD ELF auxiliary vector data"); 18377 #endif 18378 18379 default: 18380 /* As of Jan 2002 there are no other machine-independent notes 18381 defined for NetBSD core files. If the note type is less 18382 than the start of the machine-dependent note types, we don't 18383 understand it. */ 18384 18385 if (e_type < NT_NETBSDCORE_FIRSTMACH) 18386 { 18387 snprintf (buff, sizeof (buff), _("Unknown note type: (0x%08x)"), e_type); 18388 return buff; 18389 } 18390 break; 18391 } 18392 18393 switch (filedata->file_header.e_machine) 18394 { 18395 /* On the Alpha, SPARC (32-bit and 64-bit), PT_GETREGS == mach+0 18396 and PT_GETFPREGS == mach+2. */ 18397 18398 case EM_OLD_ALPHA: 18399 case EM_ALPHA: 18400 case EM_SPARC: 18401 case EM_SPARC32PLUS: 18402 case EM_SPARCV9: 18403 switch (e_type) 18404 { 18405 case NT_NETBSDCORE_FIRSTMACH + 0: 18406 return _("PT_GETREGS (reg structure)"); 18407 case NT_NETBSDCORE_FIRSTMACH + 2: 18408 return _("PT_GETFPREGS (fpreg structure)"); 18409 default: 18410 break; 18411 } 18412 break; 18413 18414 /* On SuperH, PT_GETREGS == mach+3 and PT_GETFPREGS == mach+5. 18415 There's also old PT___GETREGS40 == mach + 1 for old reg 18416 structure which lacks GBR. */ 18417 case EM_SH: 18418 switch (e_type) 18419 { 18420 case NT_NETBSDCORE_FIRSTMACH + 1: 18421 return _("PT___GETREGS40 (old reg structure)"); 18422 case NT_NETBSDCORE_FIRSTMACH + 3: 18423 return _("PT_GETREGS (reg structure)"); 18424 case NT_NETBSDCORE_FIRSTMACH + 5: 18425 return _("PT_GETFPREGS (fpreg structure)"); 18426 default: 18427 break; 18428 } 18429 break; 18430 18431 /* On all other arch's, PT_GETREGS == mach+1 and 18432 PT_GETFPREGS == mach+3. */ 18433 default: 18434 switch (e_type) 18435 { 18436 case NT_NETBSDCORE_FIRSTMACH + 1: 18437 return _("PT_GETREGS (reg structure)"); 18438 case NT_NETBSDCORE_FIRSTMACH + 3: 18439 return _("PT_GETFPREGS (fpreg structure)"); 18440 default: 18441 break; 18442 } 18443 } 18444 18445 snprintf (buff, sizeof (buff), "PT_FIRSTMACH+%d", 18446 e_type - NT_NETBSDCORE_FIRSTMACH); 18447 return buff; 18448 } 18449 18450 static const char * 18451 get_stapsdt_note_type (unsigned e_type) 18452 { 18453 static char buff[64]; 18454 18455 switch (e_type) 18456 { 18457 case NT_STAPSDT: 18458 return _("NT_STAPSDT (SystemTap probe descriptors)"); 18459 18460 default: 18461 break; 18462 } 18463 18464 snprintf (buff, sizeof (buff), _("Unknown note type: (0x%08x)"), e_type); 18465 return buff; 18466 } 18467 18468 static bfd_boolean 18469 print_stapsdt_note (Elf_Internal_Note *pnote) 18470 { 18471 size_t len, maxlen; 18472 unsigned long addr_size = is_32bit_elf ? 4 : 8; 18473 char *data = pnote->descdata; 18474 char *data_end = pnote->descdata + pnote->descsz; 18475 bfd_vma pc, base_addr, semaphore; 18476 char *provider, *probe, *arg_fmt; 18477 18478 if (pnote->descsz < (addr_size * 3)) 18479 goto stapdt_note_too_small; 18480 18481 pc = byte_get ((unsigned char *) data, addr_size); 18482 data += addr_size; 18483 18484 base_addr = byte_get ((unsigned char *) data, addr_size); 18485 data += addr_size; 18486 18487 semaphore = byte_get ((unsigned char *) data, addr_size); 18488 data += addr_size; 18489 18490 if (data >= data_end) 18491 goto stapdt_note_too_small; 18492 maxlen = data_end - data; 18493 len = strnlen (data, maxlen); 18494 if (len < maxlen) 18495 { 18496 provider = data; 18497 data += len + 1; 18498 } 18499 else 18500 goto stapdt_note_too_small; 18501 18502 if (data >= data_end) 18503 goto stapdt_note_too_small; 18504 maxlen = data_end - data; 18505 len = strnlen (data, maxlen); 18506 if (len < maxlen) 18507 { 18508 probe = data; 18509 data += len + 1; 18510 } 18511 else 18512 goto stapdt_note_too_small; 18513 18514 if (data >= data_end) 18515 goto stapdt_note_too_small; 18516 maxlen = data_end - data; 18517 len = strnlen (data, maxlen); 18518 if (len < maxlen) 18519 { 18520 arg_fmt = data; 18521 data += len + 1; 18522 } 18523 else 18524 goto stapdt_note_too_small; 18525 18526 printf (_(" Provider: %s\n"), provider); 18527 printf (_(" Name: %s\n"), probe); 18528 printf (_(" Location: ")); 18529 print_vma (pc, FULL_HEX); 18530 printf (_(", Base: ")); 18531 print_vma (base_addr, FULL_HEX); 18532 printf (_(", Semaphore: ")); 18533 print_vma (semaphore, FULL_HEX); 18534 printf ("\n"); 18535 printf (_(" Arguments: %s\n"), arg_fmt); 18536 18537 return data == data_end; 18538 18539 stapdt_note_too_small: 18540 printf (_(" <corrupt - note is too small>\n")); 18541 error (_("corrupt stapdt note - the data size is too small\n")); 18542 return FALSE; 18543 } 18544 18545 static const char * 18546 get_ia64_vms_note_type (unsigned e_type) 18547 { 18548 static char buff[64]; 18549 18550 switch (e_type) 18551 { 18552 case NT_VMS_MHD: 18553 return _("NT_VMS_MHD (module header)"); 18554 case NT_VMS_LNM: 18555 return _("NT_VMS_LNM (language name)"); 18556 case NT_VMS_SRC: 18557 return _("NT_VMS_SRC (source files)"); 18558 case NT_VMS_TITLE: 18559 return "NT_VMS_TITLE"; 18560 case NT_VMS_EIDC: 18561 return _("NT_VMS_EIDC (consistency check)"); 18562 case NT_VMS_FPMODE: 18563 return _("NT_VMS_FPMODE (FP mode)"); 18564 case NT_VMS_LINKTIME: 18565 return "NT_VMS_LINKTIME"; 18566 case NT_VMS_IMGNAM: 18567 return _("NT_VMS_IMGNAM (image name)"); 18568 case NT_VMS_IMGID: 18569 return _("NT_VMS_IMGID (image id)"); 18570 case NT_VMS_LINKID: 18571 return _("NT_VMS_LINKID (link id)"); 18572 case NT_VMS_IMGBID: 18573 return _("NT_VMS_IMGBID (build id)"); 18574 case NT_VMS_GSTNAM: 18575 return _("NT_VMS_GSTNAM (sym table name)"); 18576 case NT_VMS_ORIG_DYN: 18577 return "NT_VMS_ORIG_DYN"; 18578 case NT_VMS_PATCHTIME: 18579 return "NT_VMS_PATCHTIME"; 18580 default: 18581 snprintf (buff, sizeof (buff), _("Unknown note type: (0x%08x)"), e_type); 18582 return buff; 18583 } 18584 } 18585 18586 static bfd_boolean 18587 print_ia64_vms_note (Elf_Internal_Note * pnote) 18588 { 18589 int maxlen = pnote->descsz; 18590 18591 if (maxlen < 2 || (unsigned long) maxlen != pnote->descsz) 18592 goto desc_size_fail; 18593 18594 switch (pnote->type) 18595 { 18596 case NT_VMS_MHD: 18597 if (maxlen <= 36) 18598 goto desc_size_fail; 18599 18600 int l = (int) strnlen (pnote->descdata + 34, maxlen - 34); 18601 18602 printf (_(" Creation date : %.17s\n"), pnote->descdata); 18603 printf (_(" Last patch date: %.17s\n"), pnote->descdata + 17); 18604 if (l + 34 < maxlen) 18605 { 18606 printf (_(" Module name : %s\n"), pnote->descdata + 34); 18607 if (l + 35 < maxlen) 18608 printf (_(" Module version : %s\n"), pnote->descdata + 34 + l + 1); 18609 else 18610 printf (_(" Module version : <missing>\n")); 18611 } 18612 else 18613 { 18614 printf (_(" Module name : <missing>\n")); 18615 printf (_(" Module version : <missing>\n")); 18616 } 18617 break; 18618 18619 case NT_VMS_LNM: 18620 printf (_(" Language: %.*s\n"), maxlen, pnote->descdata); 18621 break; 18622 18623 #ifdef BFD64 18624 case NT_VMS_FPMODE: 18625 printf (_(" Floating Point mode: ")); 18626 if (maxlen < 8) 18627 goto desc_size_fail; 18628 /* FIXME: Generate an error if descsz > 8 ? */ 18629 18630 printf ("0x%016" BFD_VMA_FMT "x\n", 18631 (bfd_vma) byte_get ((unsigned char *)pnote->descdata, 8)); 18632 break; 18633 18634 case NT_VMS_LINKTIME: 18635 printf (_(" Link time: ")); 18636 if (maxlen < 8) 18637 goto desc_size_fail; 18638 /* FIXME: Generate an error if descsz > 8 ? */ 18639 18640 print_vms_time 18641 ((bfd_int64_t) byte_get ((unsigned char *)pnote->descdata, 8)); 18642 printf ("\n"); 18643 break; 18644 18645 case NT_VMS_PATCHTIME: 18646 printf (_(" Patch time: ")); 18647 if (maxlen < 8) 18648 goto desc_size_fail; 18649 /* FIXME: Generate an error if descsz > 8 ? */ 18650 18651 print_vms_time 18652 ((bfd_int64_t) byte_get ((unsigned char *)pnote->descdata, 8)); 18653 printf ("\n"); 18654 break; 18655 18656 case NT_VMS_ORIG_DYN: 18657 if (maxlen < 34) 18658 goto desc_size_fail; 18659 18660 printf (_(" Major id: %u, minor id: %u\n"), 18661 (unsigned) byte_get ((unsigned char *)pnote->descdata, 4), 18662 (unsigned) byte_get ((unsigned char *)pnote->descdata + 4, 4)); 18663 printf (_(" Last modified : ")); 18664 print_vms_time 18665 ((bfd_int64_t) byte_get ((unsigned char *)pnote->descdata + 8, 8)); 18666 printf (_("\n Link flags : ")); 18667 printf ("0x%016" BFD_VMA_FMT "x\n", 18668 (bfd_vma) byte_get ((unsigned char *)pnote->descdata + 16, 8)); 18669 printf (_(" Header flags: 0x%08x\n"), 18670 (unsigned) byte_get ((unsigned char *)pnote->descdata + 24, 4)); 18671 printf (_(" Image id : %.*s\n"), maxlen - 32, pnote->descdata + 32); 18672 break; 18673 #endif 18674 18675 case NT_VMS_IMGNAM: 18676 printf (_(" Image name: %.*s\n"), maxlen, pnote->descdata); 18677 break; 18678 18679 case NT_VMS_GSTNAM: 18680 printf (_(" Global symbol table name: %.*s\n"), maxlen, pnote->descdata); 18681 break; 18682 18683 case NT_VMS_IMGID: 18684 printf (_(" Image id: %.*s\n"), maxlen, pnote->descdata); 18685 break; 18686 18687 case NT_VMS_LINKID: 18688 printf (_(" Linker id: %.*s\n"), maxlen, pnote->descdata); 18689 break; 18690 18691 default: 18692 return FALSE; 18693 } 18694 18695 return TRUE; 18696 18697 desc_size_fail: 18698 printf (_(" <corrupt - data size is too small>\n")); 18699 error (_("corrupt IA64 note: data size is too small\n")); 18700 return FALSE; 18701 } 18702 18703 /* Find the symbol associated with a build attribute that is attached 18704 to address OFFSET. If PNAME is non-NULL then store the name of 18705 the symbol (if found) in the provided pointer, Returns NULL if a 18706 symbol could not be found. */ 18707 18708 static Elf_Internal_Sym * 18709 get_symbol_for_build_attribute (Filedata * filedata, 18710 unsigned long offset, 18711 bfd_boolean is_open_attr, 18712 const char ** pname) 18713 { 18714 static Filedata * saved_filedata = NULL; 18715 static char * strtab; 18716 static unsigned long strtablen; 18717 static Elf_Internal_Sym * symtab; 18718 static unsigned long nsyms; 18719 Elf_Internal_Sym * saved_sym = NULL; 18720 Elf_Internal_Sym * sym; 18721 18722 if (filedata->section_headers != NULL 18723 && (saved_filedata == NULL || filedata != saved_filedata)) 18724 { 18725 Elf_Internal_Shdr * symsec; 18726 18727 /* Load the symbol and string sections. */ 18728 for (symsec = filedata->section_headers; 18729 symsec < filedata->section_headers + filedata->file_header.e_shnum; 18730 symsec ++) 18731 { 18732 if (symsec->sh_type == SHT_SYMTAB) 18733 { 18734 symtab = GET_ELF_SYMBOLS (filedata, symsec, & nsyms); 18735 18736 if (symsec->sh_link < filedata->file_header.e_shnum) 18737 { 18738 Elf_Internal_Shdr * strtab_sec = filedata->section_headers + symsec->sh_link; 18739 18740 strtab = (char *) get_data (NULL, filedata, strtab_sec->sh_offset, 18741 1, strtab_sec->sh_size, 18742 _("string table")); 18743 strtablen = strtab != NULL ? strtab_sec->sh_size : 0; 18744 } 18745 } 18746 } 18747 saved_filedata = filedata; 18748 } 18749 18750 if (symtab == NULL || strtab == NULL) 18751 return NULL; 18752 18753 /* Find a symbol whose value matches offset. */ 18754 for (sym = symtab; sym < symtab + nsyms; sym ++) 18755 if (sym->st_value == offset) 18756 { 18757 if (sym->st_name >= strtablen) 18758 /* Huh ? This should not happen. */ 18759 continue; 18760 18761 if (strtab[sym->st_name] == 0) 18762 continue; 18763 18764 /* The AArch64 and ARM architectures define mapping symbols 18765 (eg $d, $x, $t) which we want to ignore. */ 18766 if (strtab[sym->st_name] == '$' 18767 && strtab[sym->st_name + 1] != 0 18768 && strtab[sym->st_name + 2] == 0) 18769 continue; 18770 18771 if (is_open_attr) 18772 { 18773 /* For OPEN attributes we prefer GLOBAL over LOCAL symbols 18774 and FILE or OBJECT symbols over NOTYPE symbols. We skip 18775 FUNC symbols entirely. */ 18776 switch (ELF_ST_TYPE (sym->st_info)) 18777 { 18778 case STT_OBJECT: 18779 case STT_FILE: 18780 saved_sym = sym; 18781 if (sym->st_size) 18782 { 18783 /* If the symbol has a size associated 18784 with it then we can stop searching. */ 18785 sym = symtab + nsyms; 18786 } 18787 continue; 18788 18789 case STT_FUNC: 18790 /* Ignore function symbols. */ 18791 continue; 18792 18793 default: 18794 break; 18795 } 18796 18797 switch (ELF_ST_BIND (sym->st_info)) 18798 { 18799 case STB_GLOBAL: 18800 if (saved_sym == NULL 18801 || ELF_ST_TYPE (saved_sym->st_info) != STT_OBJECT) 18802 saved_sym = sym; 18803 break; 18804 18805 case STB_LOCAL: 18806 if (saved_sym == NULL) 18807 saved_sym = sym; 18808 break; 18809 18810 default: 18811 break; 18812 } 18813 } 18814 else 18815 { 18816 if (ELF_ST_TYPE (sym->st_info) != STT_FUNC) 18817 continue; 18818 18819 saved_sym = sym; 18820 break; 18821 } 18822 } 18823 18824 if (saved_sym && pname) 18825 * pname = strtab + saved_sym->st_name; 18826 18827 return saved_sym; 18828 } 18829 18830 /* Returns true iff addr1 and addr2 are in the same section. */ 18831 18832 static bfd_boolean 18833 same_section (Filedata * filedata, unsigned long addr1, unsigned long addr2) 18834 { 18835 Elf_Internal_Shdr * a1; 18836 Elf_Internal_Shdr * a2; 18837 18838 a1 = find_section_by_address (filedata, addr1); 18839 a2 = find_section_by_address (filedata, addr2); 18840 18841 return a1 == a2 && a1 != NULL; 18842 } 18843 18844 static bfd_boolean 18845 print_gnu_build_attribute_description (Elf_Internal_Note * pnote, 18846 Filedata * filedata) 18847 { 18848 static unsigned long global_offset = 0; 18849 static unsigned long global_end = 0; 18850 static unsigned long func_offset = 0; 18851 static unsigned long func_end = 0; 18852 18853 Elf_Internal_Sym * sym; 18854 const char * name; 18855 unsigned long start; 18856 unsigned long end; 18857 bfd_boolean is_open_attr = pnote->type == NT_GNU_BUILD_ATTRIBUTE_OPEN; 18858 18859 switch (pnote->descsz) 18860 { 18861 case 0: 18862 /* A zero-length description means that the range of 18863 the previous note of the same type should be used. */ 18864 if (is_open_attr) 18865 { 18866 if (global_end > global_offset) 18867 printf (_(" Applies to region from %#lx to %#lx\n"), 18868 global_offset, global_end); 18869 else 18870 printf (_(" Applies to region from %#lx\n"), global_offset); 18871 } 18872 else 18873 { 18874 if (func_end > func_offset) 18875 printf (_(" Applies to region from %#lx to %#lx\n"), func_offset, func_end); 18876 else 18877 printf (_(" Applies to region from %#lx\n"), func_offset); 18878 } 18879 return TRUE; 18880 18881 case 4: 18882 start = byte_get ((unsigned char *) pnote->descdata, 4); 18883 end = 0; 18884 break; 18885 18886 case 8: 18887 if (is_32bit_elf) 18888 { 18889 /* FIXME: We should check that version 3+ notes are being used here... */ 18890 start = byte_get ((unsigned char *) pnote->descdata, 4); 18891 end = byte_get ((unsigned char *) pnote->descdata + 4, 4); 18892 } 18893 else 18894 { 18895 start = byte_get ((unsigned char *) pnote->descdata, 8); 18896 end = 0; 18897 } 18898 break; 18899 18900 case 16: 18901 start = byte_get ((unsigned char *) pnote->descdata, 8); 18902 end = byte_get ((unsigned char *) pnote->descdata + 8, 8); 18903 break; 18904 18905 default: 18906 error (_(" <invalid description size: %lx>\n"), pnote->descsz); 18907 printf (_(" <invalid descsz>")); 18908 return FALSE; 18909 } 18910 18911 name = NULL; 18912 sym = get_symbol_for_build_attribute (filedata, start, is_open_attr, & name); 18913 /* As of version 5 of the annobin plugin, filename symbols are biased by 2 18914 in order to avoid them being confused with the start address of the 18915 first function in the file... */ 18916 if (sym == NULL && is_open_attr) 18917 sym = get_symbol_for_build_attribute (filedata, start + 2, is_open_attr, 18918 & name); 18919 18920 if (end == 0 && sym != NULL && sym->st_size > 0) 18921 end = start + sym->st_size; 18922 18923 if (is_open_attr) 18924 { 18925 /* FIXME: Need to properly allow for section alignment. 18926 16 is just the alignment used on x86_64. */ 18927 if (global_end > 0 18928 && start > BFD_ALIGN (global_end, 16) 18929 /* Build notes are not guaranteed to be organised in order of 18930 increasing address, but we should find the all of the notes 18931 for one section in the same place. */ 18932 && same_section (filedata, start, global_end)) 18933 warn (_("Gap in build notes detected from %#lx to %#lx\n"), 18934 global_end + 1, start - 1); 18935 18936 printf (_(" Applies to region from %#lx"), start); 18937 global_offset = start; 18938 18939 if (end) 18940 { 18941 printf (_(" to %#lx"), end); 18942 global_end = end; 18943 } 18944 } 18945 else 18946 { 18947 printf (_(" Applies to region from %#lx"), start); 18948 func_offset = start; 18949 18950 if (end) 18951 { 18952 printf (_(" to %#lx"), end); 18953 func_end = end; 18954 } 18955 } 18956 18957 if (sym && name) 18958 printf (_(" (%s)"), name); 18959 18960 printf ("\n"); 18961 return TRUE; 18962 } 18963 18964 static bfd_boolean 18965 print_gnu_build_attribute_name (Elf_Internal_Note * pnote) 18966 { 18967 static const char string_expected [2] = { GNU_BUILD_ATTRIBUTE_TYPE_STRING, 0 }; 18968 static const char number_expected [2] = { GNU_BUILD_ATTRIBUTE_TYPE_NUMERIC, 0 }; 18969 static const char bool_expected [3] = { GNU_BUILD_ATTRIBUTE_TYPE_BOOL_TRUE, GNU_BUILD_ATTRIBUTE_TYPE_BOOL_FALSE, 0 }; 18970 char name_type; 18971 char name_attribute; 18972 const char * expected_types; 18973 const char * name = pnote->namedata; 18974 const char * text; 18975 signed int left; 18976 18977 if (name == NULL || pnote->namesz < 2) 18978 { 18979 error (_("corrupt name field in GNU build attribute note: size = %ld\n"), pnote->namesz); 18980 print_symbol (-20, _(" <corrupt name>")); 18981 return FALSE; 18982 } 18983 18984 if (do_wide) 18985 left = 28; 18986 else 18987 left = 20; 18988 18989 /* Version 2 of the spec adds a "GA" prefix to the name field. */ 18990 if (name[0] == 'G' && name[1] == 'A') 18991 { 18992 if (pnote->namesz < 4) 18993 { 18994 error (_("corrupt name field in GNU build attribute note: size = %ld\n"), pnote->namesz); 18995 print_symbol (-20, _(" <corrupt name>")); 18996 return FALSE; 18997 } 18998 18999 printf ("GA"); 19000 name += 2; 19001 left -= 2; 19002 } 19003 19004 switch ((name_type = * name)) 19005 { 19006 case GNU_BUILD_ATTRIBUTE_TYPE_NUMERIC: 19007 case GNU_BUILD_ATTRIBUTE_TYPE_STRING: 19008 case GNU_BUILD_ATTRIBUTE_TYPE_BOOL_TRUE: 19009 case GNU_BUILD_ATTRIBUTE_TYPE_BOOL_FALSE: 19010 printf ("%c", * name); 19011 left --; 19012 break; 19013 default: 19014 error (_("unrecognised attribute type in name field: %d\n"), name_type); 19015 print_symbol (-20, _("<unknown name type>")); 19016 return FALSE; 19017 } 19018 19019 ++ name; 19020 text = NULL; 19021 19022 switch ((name_attribute = * name)) 19023 { 19024 case GNU_BUILD_ATTRIBUTE_VERSION: 19025 text = _("<version>"); 19026 expected_types = string_expected; 19027 ++ name; 19028 break; 19029 case GNU_BUILD_ATTRIBUTE_STACK_PROT: 19030 text = _("<stack prot>"); 19031 expected_types = "!+*"; 19032 ++ name; 19033 break; 19034 case GNU_BUILD_ATTRIBUTE_RELRO: 19035 text = _("<relro>"); 19036 expected_types = bool_expected; 19037 ++ name; 19038 break; 19039 case GNU_BUILD_ATTRIBUTE_STACK_SIZE: 19040 text = _("<stack size>"); 19041 expected_types = number_expected; 19042 ++ name; 19043 break; 19044 case GNU_BUILD_ATTRIBUTE_TOOL: 19045 text = _("<tool>"); 19046 expected_types = string_expected; 19047 ++ name; 19048 break; 19049 case GNU_BUILD_ATTRIBUTE_ABI: 19050 text = _("<ABI>"); 19051 expected_types = "$*"; 19052 ++ name; 19053 break; 19054 case GNU_BUILD_ATTRIBUTE_PIC: 19055 text = _("<PIC>"); 19056 expected_types = number_expected; 19057 ++ name; 19058 break; 19059 case GNU_BUILD_ATTRIBUTE_SHORT_ENUM: 19060 text = _("<short enum>"); 19061 expected_types = bool_expected; 19062 ++ name; 19063 break; 19064 default: 19065 if (ISPRINT (* name)) 19066 { 19067 int len = strnlen (name, pnote->namesz - (name - pnote->namedata)) + 1; 19068 19069 if (len > left && ! do_wide) 19070 len = left; 19071 printf ("%.*s:", len, name); 19072 left -= len; 19073 name += len; 19074 } 19075 else 19076 { 19077 static char tmpbuf [128]; 19078 19079 error (_("unrecognised byte in name field: %d\n"), * name); 19080 sprintf (tmpbuf, _("<unknown:_%d>"), * name); 19081 text = tmpbuf; 19082 name ++; 19083 } 19084 expected_types = "*$!+"; 19085 break; 19086 } 19087 19088 if (text) 19089 left -= printf ("%s", text); 19090 19091 if (strchr (expected_types, name_type) == NULL) 19092 warn (_("attribute does not have an expected type (%c)\n"), name_type); 19093 19094 if ((unsigned long)(name - pnote->namedata) > pnote->namesz) 19095 { 19096 error (_("corrupt name field: namesz: %lu but parsing gets to %ld\n"), 19097 (unsigned long) pnote->namesz, 19098 (long) (name - pnote->namedata)); 19099 return FALSE; 19100 } 19101 19102 if (left < 1 && ! do_wide) 19103 return TRUE; 19104 19105 switch (name_type) 19106 { 19107 case GNU_BUILD_ATTRIBUTE_TYPE_NUMERIC: 19108 { 19109 unsigned int bytes; 19110 unsigned long long val = 0; 19111 unsigned int shift = 0; 19112 char * decoded = NULL; 19113 19114 bytes = pnote->namesz - (name - pnote->namedata); 19115 if (bytes > 0) 19116 /* The -1 is because the name field is always 0 terminated, and we 19117 want to be able to ensure that the shift in the while loop below 19118 will not overflow. */ 19119 -- bytes; 19120 19121 if (bytes > sizeof (val)) 19122 { 19123 error (_("corrupt numeric name field: too many bytes in the value: %x\n"), 19124 bytes); 19125 bytes = sizeof (val); 19126 } 19127 /* We do not bother to warn if bytes == 0 as this can 19128 happen with some early versions of the gcc plugin. */ 19129 19130 while (bytes --) 19131 { 19132 unsigned long byte = (* name ++) & 0xff; 19133 19134 val |= byte << shift; 19135 shift += 8; 19136 } 19137 19138 switch (name_attribute) 19139 { 19140 case GNU_BUILD_ATTRIBUTE_PIC: 19141 switch (val) 19142 { 19143 case 0: decoded = "static"; break; 19144 case 1: decoded = "pic"; break; 19145 case 2: decoded = "PIC"; break; 19146 case 3: decoded = "pie"; break; 19147 case 4: decoded = "PIE"; break; 19148 default: break; 19149 } 19150 break; 19151 case GNU_BUILD_ATTRIBUTE_STACK_PROT: 19152 switch (val) 19153 { 19154 /* Based upon the SPCT_FLAG_xxx enum values in gcc/cfgexpand.c. */ 19155 case 0: decoded = "off"; break; 19156 case 1: decoded = "on"; break; 19157 case 2: decoded = "all"; break; 19158 case 3: decoded = "strong"; break; 19159 case 4: decoded = "explicit"; break; 19160 default: break; 19161 } 19162 break; 19163 default: 19164 break; 19165 } 19166 19167 if (decoded != NULL) 19168 { 19169 print_symbol (-left, decoded); 19170 left = 0; 19171 } 19172 else if (val == 0) 19173 { 19174 printf ("0x0"); 19175 left -= 3; 19176 } 19177 else 19178 { 19179 if (do_wide) 19180 left -= printf ("0x%llx", val); 19181 else 19182 left -= printf ("0x%-.*llx", left, val); 19183 } 19184 } 19185 break; 19186 case GNU_BUILD_ATTRIBUTE_TYPE_STRING: 19187 left -= print_symbol (- left, name); 19188 break; 19189 case GNU_BUILD_ATTRIBUTE_TYPE_BOOL_TRUE: 19190 left -= print_symbol (- left, "true"); 19191 break; 19192 case GNU_BUILD_ATTRIBUTE_TYPE_BOOL_FALSE: 19193 left -= print_symbol (- left, "false"); 19194 break; 19195 } 19196 19197 if (do_wide && left > 0) 19198 printf ("%-*s", left, " "); 19199 19200 return TRUE; 19201 } 19202 19203 /* Note that by the ELF standard, the name field is already null byte 19204 terminated, and namesz includes the terminating null byte. 19205 I.E. the value of namesz for the name "FSF" is 4. 19206 19207 If the value of namesz is zero, there is no name present. */ 19208 19209 static bfd_boolean 19210 process_note (Elf_Internal_Note * pnote, 19211 Filedata * filedata) 19212 { 19213 const char * name = pnote->namesz ? pnote->namedata : "(NONE)"; 19214 const char * nt; 19215 19216 if (pnote->namesz == 0) 19217 /* If there is no note name, then use the default set of 19218 note type strings. */ 19219 nt = get_note_type (filedata, pnote->type); 19220 19221 else if (const_strneq (pnote->namedata, "GNU")) 19222 /* GNU-specific object file notes. */ 19223 nt = get_gnu_elf_note_type (pnote->type); 19224 19225 else if (const_strneq (pnote->namedata, "FreeBSD")) 19226 /* FreeBSD-specific core file notes. */ 19227 nt = get_freebsd_elfcore_note_type (filedata, pnote->type); 19228 19229 else if (const_strneq (pnote->namedata, "NetBSD-CORE")) 19230 /* NetBSD-specific core file notes. */ 19231 nt = get_netbsd_elfcore_note_type (filedata, pnote->type); 19232 19233 else if (const_strneq (pnote->namedata, "NetBSD")) 19234 /* NetBSD-specific core file notes. */ 19235 return process_netbsd_elf_note (pnote); 19236 19237 else if (const_strneq (pnote->namedata, "PaX")) 19238 /* NetBSD-specific core file notes. */ 19239 return process_netbsd_elf_note (pnote); 19240 19241 else if (strneq (pnote->namedata, "SPU/", 4)) 19242 { 19243 /* SPU-specific core file notes. */ 19244 nt = pnote->namedata + 4; 19245 name = "SPU"; 19246 } 19247 19248 else if (const_strneq (pnote->namedata, "IPF/VMS")) 19249 /* VMS/ia64-specific file notes. */ 19250 nt = get_ia64_vms_note_type (pnote->type); 19251 19252 else if (const_strneq (pnote->namedata, "stapsdt")) 19253 nt = get_stapsdt_note_type (pnote->type); 19254 19255 else 19256 /* Don't recognize this note name; just use the default set of 19257 note type strings. */ 19258 nt = get_note_type (filedata, pnote->type); 19259 19260 printf (" "); 19261 19262 if (((const_strneq (pnote->namedata, "GA") 19263 && strchr ("*$!+", pnote->namedata[2]) != NULL) 19264 || strchr ("*$!+", pnote->namedata[0]) != NULL) 19265 && (pnote->type == NT_GNU_BUILD_ATTRIBUTE_OPEN 19266 || pnote->type == NT_GNU_BUILD_ATTRIBUTE_FUNC)) 19267 print_gnu_build_attribute_name (pnote); 19268 else 19269 print_symbol (-20, name); 19270 19271 if (do_wide) 19272 printf (" 0x%08lx\t%s\t", pnote->descsz, nt); 19273 else 19274 printf (" 0x%08lx\t%s\n", pnote->descsz, nt); 19275 19276 if (const_strneq (pnote->namedata, "IPF/VMS")) 19277 return print_ia64_vms_note (pnote); 19278 else if (const_strneq (pnote->namedata, "GNU")) 19279 return print_gnu_note (filedata, pnote); 19280 else if (const_strneq (pnote->namedata, "stapsdt")) 19281 return print_stapsdt_note (pnote); 19282 else if (const_strneq (pnote->namedata, "CORE")) 19283 return print_core_note (pnote); 19284 else if (((const_strneq (pnote->namedata, "GA") 19285 && strchr ("*$!+", pnote->namedata[2]) != NULL) 19286 || strchr ("*$!+", pnote->namedata[0]) != NULL) 19287 && (pnote->type == NT_GNU_BUILD_ATTRIBUTE_OPEN 19288 || pnote->type == NT_GNU_BUILD_ATTRIBUTE_FUNC)) 19289 return print_gnu_build_attribute_description (pnote, filedata); 19290 19291 if (pnote->descsz) 19292 { 19293 unsigned long i; 19294 19295 printf (_(" description data: ")); 19296 for (i = 0; i < pnote->descsz; i++) 19297 printf ("%02x ", pnote->descdata[i] & 0xff); 19298 if (!do_wide) 19299 printf ("\n"); 19300 } 19301 19302 if (do_wide) 19303 printf ("\n"); 19304 19305 return TRUE; 19306 } 19307 19308 static bfd_boolean 19309 process_notes_at (Filedata * filedata, 19310 Elf_Internal_Shdr * section, 19311 bfd_vma offset, 19312 bfd_vma length, 19313 bfd_vma align) 19314 { 19315 Elf_External_Note * pnotes; 19316 Elf_External_Note * external; 19317 char * end; 19318 bfd_boolean res = TRUE; 19319 19320 if (length <= 0) 19321 return FALSE; 19322 19323 if (section) 19324 { 19325 pnotes = (Elf_External_Note *) get_section_contents (section, filedata); 19326 if (pnotes) 19327 { 19328 if (! apply_relocations (filedata, section, (unsigned char *) pnotes, length, NULL, NULL)) 19329 return FALSE; 19330 } 19331 } 19332 else 19333 pnotes = (Elf_External_Note *) get_data (NULL, filedata, offset, 1, length, 19334 _("notes")); 19335 19336 if (pnotes == NULL) 19337 return FALSE; 19338 19339 external = pnotes; 19340 19341 if (section) 19342 printf (_("\nDisplaying notes found in: %s\n"), printable_section_name (filedata, section)); 19343 else 19344 printf (_("\nDisplaying notes found at file offset 0x%08lx with length 0x%08lx:\n"), 19345 (unsigned long) offset, (unsigned long) length); 19346 19347 /* NB: Some note sections may have alignment value of 0 or 1. gABI 19348 specifies that notes should be aligned to 4 bytes in 32-bit 19349 objects and to 8 bytes in 64-bit objects. As a Linux extension, 19350 we also support 4 byte alignment in 64-bit objects. If section 19351 alignment is less than 4, we treate alignment as 4 bytes. */ 19352 if (align < 4) 19353 align = 4; 19354 else if (align != 4 && align != 8) 19355 { 19356 warn (_("Corrupt note: alignment %ld, expecting 4 or 8\n"), 19357 (long) align); 19358 free (pnotes); 19359 return FALSE; 19360 } 19361 19362 printf (_(" %-20s %-10s\tDescription\n"), _("Owner"), _("Data size")); 19363 19364 end = (char *) pnotes + length; 19365 while ((char *) external < end) 19366 { 19367 Elf_Internal_Note inote; 19368 size_t min_notesz; 19369 char * next; 19370 char * temp = NULL; 19371 size_t data_remaining = end - (char *) external; 19372 19373 if (!is_ia64_vms (filedata)) 19374 { 19375 /* PR binutils/15191 19376 Make sure that there is enough data to read. */ 19377 min_notesz = offsetof (Elf_External_Note, name); 19378 if (data_remaining < min_notesz) 19379 { 19380 warn (ngettext ("Corrupt note: only %ld byte remains, " 19381 "not enough for a full note\n", 19382 "Corrupt note: only %ld bytes remain, " 19383 "not enough for a full note\n", 19384 data_remaining), 19385 (long) data_remaining); 19386 break; 19387 } 19388 data_remaining -= min_notesz; 19389 19390 inote.type = BYTE_GET (external->type); 19391 inote.namesz = BYTE_GET (external->namesz); 19392 inote.namedata = external->name; 19393 inote.descsz = BYTE_GET (external->descsz); 19394 inote.descdata = ((char *) external 19395 + ELF_NOTE_DESC_OFFSET (inote.namesz, align)); 19396 inote.descpos = offset + (inote.descdata - (char *) pnotes); 19397 next = ((char *) external 19398 + ELF_NOTE_NEXT_OFFSET (inote.namesz, inote.descsz, align)); 19399 } 19400 else 19401 { 19402 Elf64_External_VMS_Note *vms_external; 19403 19404 /* PR binutils/15191 19405 Make sure that there is enough data to read. */ 19406 min_notesz = offsetof (Elf64_External_VMS_Note, name); 19407 if (data_remaining < min_notesz) 19408 { 19409 warn (ngettext ("Corrupt note: only %ld byte remains, " 19410 "not enough for a full note\n", 19411 "Corrupt note: only %ld bytes remain, " 19412 "not enough for a full note\n", 19413 data_remaining), 19414 (long) data_remaining); 19415 break; 19416 } 19417 data_remaining -= min_notesz; 19418 19419 vms_external = (Elf64_External_VMS_Note *) external; 19420 inote.type = BYTE_GET (vms_external->type); 19421 inote.namesz = BYTE_GET (vms_external->namesz); 19422 inote.namedata = vms_external->name; 19423 inote.descsz = BYTE_GET (vms_external->descsz); 19424 inote.descdata = inote.namedata + align_power (inote.namesz, 3); 19425 inote.descpos = offset + (inote.descdata - (char *) pnotes); 19426 next = inote.descdata + align_power (inote.descsz, 3); 19427 } 19428 19429 /* PR 17531: file: 3443835e. */ 19430 /* PR 17531: file: id:000000,sig:11,src:006986,op:havoc,rep:4. */ 19431 if ((size_t) (inote.descdata - inote.namedata) < inote.namesz 19432 || (size_t) (inote.descdata - inote.namedata) > data_remaining 19433 || (size_t) (next - inote.descdata) < inote.descsz 19434 || ((size_t) (next - inote.descdata) 19435 > data_remaining - (size_t) (inote.descdata - inote.namedata))) 19436 { 19437 warn (_("note with invalid namesz and/or descsz found at offset 0x%lx\n"), 19438 (unsigned long) ((char *) external - (char *) pnotes)); 19439 warn (_(" type: 0x%lx, namesize: 0x%08lx, descsize: 0x%08lx, alignment: %u\n"), 19440 inote.type, inote.namesz, inote.descsz, (int) align); 19441 break; 19442 } 19443 19444 external = (Elf_External_Note *) next; 19445 19446 /* Verify that name is null terminated. It appears that at least 19447 one version of Linux (RedHat 6.0) generates corefiles that don't 19448 comply with the ELF spec by failing to include the null byte in 19449 namesz. */ 19450 if (inote.namesz > 0 && inote.namedata[inote.namesz - 1] != '\0') 19451 { 19452 if ((size_t) (inote.descdata - inote.namedata) == inote.namesz) 19453 { 19454 temp = (char *) malloc (inote.namesz + 1); 19455 if (temp == NULL) 19456 { 19457 error (_("Out of memory allocating space for inote name\n")); 19458 res = FALSE; 19459 break; 19460 } 19461 19462 memcpy (temp, inote.namedata, inote.namesz); 19463 inote.namedata = temp; 19464 } 19465 inote.namedata[inote.namesz] = 0; 19466 } 19467 19468 if (! process_note (& inote, filedata)) 19469 res = FALSE; 19470 19471 if (temp != NULL) 19472 { 19473 free (temp); 19474 temp = NULL; 19475 } 19476 } 19477 19478 free (pnotes); 19479 19480 return res; 19481 } 19482 19483 static bfd_boolean 19484 process_corefile_note_segments (Filedata * filedata) 19485 { 19486 Elf_Internal_Phdr * segment; 19487 unsigned int i; 19488 bfd_boolean res = TRUE; 19489 19490 if (! get_program_headers (filedata)) 19491 return TRUE; 19492 19493 for (i = 0, segment = filedata->program_headers; 19494 i < filedata->file_header.e_phnum; 19495 i++, segment++) 19496 { 19497 if (segment->p_type == PT_NOTE) 19498 if (! process_notes_at (filedata, NULL, 19499 (bfd_vma) segment->p_offset, 19500 (bfd_vma) segment->p_filesz, 19501 (bfd_vma) segment->p_align)) 19502 res = FALSE; 19503 } 19504 19505 return res; 19506 } 19507 19508 static bfd_boolean 19509 process_v850_notes (Filedata * filedata, bfd_vma offset, bfd_vma length) 19510 { 19511 Elf_External_Note * pnotes; 19512 Elf_External_Note * external; 19513 char * end; 19514 bfd_boolean res = TRUE; 19515 19516 if (length <= 0) 19517 return FALSE; 19518 19519 pnotes = (Elf_External_Note *) get_data (NULL, filedata, offset, 1, length, 19520 _("v850 notes")); 19521 if (pnotes == NULL) 19522 return FALSE; 19523 19524 external = pnotes; 19525 end = (char*) pnotes + length; 19526 19527 printf (_("\nDisplaying contents of Renesas V850 notes section at offset 0x%lx with length 0x%lx:\n"), 19528 (unsigned long) offset, (unsigned long) length); 19529 19530 while ((char *) external + sizeof (Elf_External_Note) < end) 19531 { 19532 Elf_External_Note * next; 19533 Elf_Internal_Note inote; 19534 19535 inote.type = BYTE_GET (external->type); 19536 inote.namesz = BYTE_GET (external->namesz); 19537 inote.namedata = external->name; 19538 inote.descsz = BYTE_GET (external->descsz); 19539 inote.descdata = inote.namedata + align_power (inote.namesz, 2); 19540 inote.descpos = offset + (inote.descdata - (char *) pnotes); 19541 19542 if (inote.descdata < (char *) pnotes || inote.descdata >= end) 19543 { 19544 warn (_("Corrupt note: name size is too big: %lx\n"), inote.namesz); 19545 inote.descdata = inote.namedata; 19546 inote.namesz = 0; 19547 } 19548 19549 next = (Elf_External_Note *) (inote.descdata + align_power (inote.descsz, 2)); 19550 19551 if ( ((char *) next > end) 19552 || ((char *) next < (char *) pnotes)) 19553 { 19554 warn (_("corrupt descsz found in note at offset 0x%lx\n"), 19555 (unsigned long) ((char *) external - (char *) pnotes)); 19556 warn (_(" type: 0x%lx, namesize: 0x%lx, descsize: 0x%lx\n"), 19557 inote.type, inote.namesz, inote.descsz); 19558 break; 19559 } 19560 19561 external = next; 19562 19563 /* Prevent out-of-bounds indexing. */ 19564 if ( inote.namedata + inote.namesz > end 19565 || inote.namedata + inote.namesz < inote.namedata) 19566 { 19567 warn (_("corrupt namesz found in note at offset 0x%lx\n"), 19568 (unsigned long) ((char *) external - (char *) pnotes)); 19569 warn (_(" type: 0x%lx, namesize: 0x%lx, descsize: 0x%lx\n"), 19570 inote.type, inote.namesz, inote.descsz); 19571 break; 19572 } 19573 19574 printf (" %s: ", get_v850_elf_note_type (inote.type)); 19575 19576 if (! print_v850_note (& inote)) 19577 { 19578 res = FALSE; 19579 printf ("<corrupt sizes: namesz: %lx, descsz: %lx>\n", 19580 inote.namesz, inote.descsz); 19581 } 19582 } 19583 19584 free (pnotes); 19585 19586 return res; 19587 } 19588 19589 static bfd_boolean 19590 process_note_sections (Filedata * filedata) 19591 { 19592 Elf_Internal_Shdr * section; 19593 unsigned long i; 19594 unsigned int n = 0; 19595 bfd_boolean res = TRUE; 19596 19597 for (i = 0, section = filedata->section_headers; 19598 i < filedata->file_header.e_shnum && section != NULL; 19599 i++, section++) 19600 { 19601 if (section->sh_type == SHT_NOTE) 19602 { 19603 if (! process_notes_at (filedata, section, 19604 (bfd_vma) section->sh_offset, 19605 (bfd_vma) section->sh_size, 19606 (bfd_vma) section->sh_addralign)) 19607 res = FALSE; 19608 n++; 19609 } 19610 19611 if (( filedata->file_header.e_machine == EM_V800 19612 || filedata->file_header.e_machine == EM_V850 19613 || filedata->file_header.e_machine == EM_CYGNUS_V850) 19614 && section->sh_type == SHT_RENESAS_INFO) 19615 { 19616 if (! process_v850_notes (filedata, 19617 (bfd_vma) section->sh_offset, 19618 (bfd_vma) section->sh_size)) 19619 res = FALSE; 19620 n++; 19621 } 19622 } 19623 19624 if (n == 0) 19625 /* Try processing NOTE segments instead. */ 19626 return process_corefile_note_segments (filedata); 19627 19628 return res; 19629 } 19630 19631 static bfd_boolean 19632 process_notes (Filedata * filedata) 19633 { 19634 /* If we have not been asked to display the notes then do nothing. */ 19635 if (! do_notes) 19636 return TRUE; 19637 19638 if (filedata->file_header.e_type != ET_CORE) 19639 return process_note_sections (filedata); 19640 19641 /* No program headers means no NOTE segment. */ 19642 if (filedata->file_header.e_phnum > 0) 19643 return process_corefile_note_segments (filedata); 19644 19645 printf (_("No note segments present in the core file.\n")); 19646 return TRUE; 19647 } 19648 19649 static unsigned char * 19650 display_public_gnu_attributes (unsigned char * start, 19651 const unsigned char * const end) 19652 { 19653 printf (_(" Unknown GNU attribute: %s\n"), start); 19654 19655 start += strnlen ((char *) start, end - start); 19656 display_raw_attribute (start, end); 19657 19658 return (unsigned char *) end; 19659 } 19660 19661 static unsigned char * 19662 display_generic_attribute (unsigned char * start, 19663 unsigned int tag, 19664 const unsigned char * const end) 19665 { 19666 if (tag == 0) 19667 return (unsigned char *) end; 19668 19669 return display_tag_value (tag, start, end); 19670 } 19671 19672 static bfd_boolean 19673 process_arch_specific (Filedata * filedata) 19674 { 19675 if (! do_arch) 19676 return TRUE; 19677 19678 switch (filedata->file_header.e_machine) 19679 { 19680 case EM_ARC: 19681 case EM_ARC_COMPACT: 19682 case EM_ARC_COMPACT2: 19683 return process_attributes (filedata, "ARC", SHT_ARC_ATTRIBUTES, 19684 display_arc_attribute, 19685 display_generic_attribute); 19686 case EM_ARM: 19687 return process_attributes (filedata, "aeabi", SHT_ARM_ATTRIBUTES, 19688 display_arm_attribute, 19689 display_generic_attribute); 19690 19691 case EM_MIPS: 19692 case EM_MIPS_RS3_LE: 19693 return process_mips_specific (filedata); 19694 19695 case EM_MSP430: 19696 return process_attributes (filedata, "mspabi", SHT_MSP430_ATTRIBUTES, 19697 display_msp430x_attribute, 19698 display_msp430_gnu_attribute); 19699 19700 case EM_RISCV: 19701 return process_attributes (filedata, "riscv", SHT_RISCV_ATTRIBUTES, 19702 display_riscv_attribute, 19703 display_generic_attribute); 19704 19705 case EM_NDS32: 19706 return process_nds32_specific (filedata); 19707 19708 case EM_PPC: 19709 case EM_PPC64: 19710 return process_attributes (filedata, NULL, SHT_GNU_ATTRIBUTES, NULL, 19711 display_power_gnu_attribute); 19712 19713 case EM_S390: 19714 case EM_S390_OLD: 19715 return process_attributes (filedata, NULL, SHT_GNU_ATTRIBUTES, NULL, 19716 display_s390_gnu_attribute); 19717 19718 case EM_SPARC: 19719 case EM_SPARC32PLUS: 19720 case EM_SPARCV9: 19721 return process_attributes (filedata, NULL, SHT_GNU_ATTRIBUTES, NULL, 19722 display_sparc_gnu_attribute); 19723 19724 case EM_TI_C6000: 19725 return process_attributes (filedata, "c6xabi", SHT_C6000_ATTRIBUTES, 19726 display_tic6x_attribute, 19727 display_generic_attribute); 19728 19729 default: 19730 return process_attributes (filedata, "gnu", SHT_GNU_ATTRIBUTES, 19731 display_public_gnu_attributes, 19732 display_generic_attribute); 19733 } 19734 } 19735 19736 static bfd_boolean 19737 get_file_header (Filedata * filedata) 19738 { 19739 /* Read in the identity array. */ 19740 if (fread (filedata->file_header.e_ident, EI_NIDENT, 1, filedata->handle) != 1) 19741 return FALSE; 19742 19743 /* Determine how to read the rest of the header. */ 19744 switch (filedata->file_header.e_ident[EI_DATA]) 19745 { 19746 default: 19747 case ELFDATANONE: 19748 case ELFDATA2LSB: 19749 byte_get = byte_get_little_endian; 19750 byte_put = byte_put_little_endian; 19751 break; 19752 case ELFDATA2MSB: 19753 byte_get = byte_get_big_endian; 19754 byte_put = byte_put_big_endian; 19755 break; 19756 } 19757 19758 /* For now we only support 32 bit and 64 bit ELF files. */ 19759 is_32bit_elf = (filedata->file_header.e_ident[EI_CLASS] != ELFCLASS64); 19760 19761 /* Read in the rest of the header. */ 19762 if (is_32bit_elf) 19763 { 19764 Elf32_External_Ehdr ehdr32; 19765 19766 if (fread (ehdr32.e_type, sizeof (ehdr32) - EI_NIDENT, 1, filedata->handle) != 1) 19767 return FALSE; 19768 19769 filedata->file_header.e_type = BYTE_GET (ehdr32.e_type); 19770 filedata->file_header.e_machine = BYTE_GET (ehdr32.e_machine); 19771 filedata->file_header.e_version = BYTE_GET (ehdr32.e_version); 19772 filedata->file_header.e_entry = BYTE_GET (ehdr32.e_entry); 19773 filedata->file_header.e_phoff = BYTE_GET (ehdr32.e_phoff); 19774 filedata->file_header.e_shoff = BYTE_GET (ehdr32.e_shoff); 19775 filedata->file_header.e_flags = BYTE_GET (ehdr32.e_flags); 19776 filedata->file_header.e_ehsize = BYTE_GET (ehdr32.e_ehsize); 19777 filedata->file_header.e_phentsize = BYTE_GET (ehdr32.e_phentsize); 19778 filedata->file_header.e_phnum = BYTE_GET (ehdr32.e_phnum); 19779 filedata->file_header.e_shentsize = BYTE_GET (ehdr32.e_shentsize); 19780 filedata->file_header.e_shnum = BYTE_GET (ehdr32.e_shnum); 19781 filedata->file_header.e_shstrndx = BYTE_GET (ehdr32.e_shstrndx); 19782 } 19783 else 19784 { 19785 Elf64_External_Ehdr ehdr64; 19786 19787 /* If we have been compiled with sizeof (bfd_vma) == 4, then 19788 we will not be able to cope with the 64bit data found in 19789 64 ELF files. Detect this now and abort before we start 19790 overwriting things. */ 19791 if (sizeof (bfd_vma) < 8) 19792 { 19793 error (_("This instance of readelf has been built without support for a\n\ 19794 64 bit data type and so it cannot read 64 bit ELF files.\n")); 19795 return FALSE; 19796 } 19797 19798 if (fread (ehdr64.e_type, sizeof (ehdr64) - EI_NIDENT, 1, filedata->handle) != 1) 19799 return FALSE; 19800 19801 filedata->file_header.e_type = BYTE_GET (ehdr64.e_type); 19802 filedata->file_header.e_machine = BYTE_GET (ehdr64.e_machine); 19803 filedata->file_header.e_version = BYTE_GET (ehdr64.e_version); 19804 filedata->file_header.e_entry = BYTE_GET (ehdr64.e_entry); 19805 filedata->file_header.e_phoff = BYTE_GET (ehdr64.e_phoff); 19806 filedata->file_header.e_shoff = BYTE_GET (ehdr64.e_shoff); 19807 filedata->file_header.e_flags = BYTE_GET (ehdr64.e_flags); 19808 filedata->file_header.e_ehsize = BYTE_GET (ehdr64.e_ehsize); 19809 filedata->file_header.e_phentsize = BYTE_GET (ehdr64.e_phentsize); 19810 filedata->file_header.e_phnum = BYTE_GET (ehdr64.e_phnum); 19811 filedata->file_header.e_shentsize = BYTE_GET (ehdr64.e_shentsize); 19812 filedata->file_header.e_shnum = BYTE_GET (ehdr64.e_shnum); 19813 filedata->file_header.e_shstrndx = BYTE_GET (ehdr64.e_shstrndx); 19814 } 19815 19816 if (filedata->file_header.e_shoff) 19817 { 19818 /* There may be some extensions in the first section header. Don't 19819 bomb if we can't read it. */ 19820 if (is_32bit_elf) 19821 get_32bit_section_headers (filedata, TRUE); 19822 else 19823 get_64bit_section_headers (filedata, TRUE); 19824 } 19825 19826 return TRUE; 19827 } 19828 19829 static void 19830 close_file (Filedata * filedata) 19831 { 19832 if (filedata) 19833 { 19834 if (filedata->handle) 19835 fclose (filedata->handle); 19836 free (filedata); 19837 } 19838 } 19839 19840 void 19841 close_debug_file (void * data) 19842 { 19843 close_file ((Filedata *) data); 19844 } 19845 19846 static Filedata * 19847 open_file (const char * pathname) 19848 { 19849 struct stat statbuf; 19850 Filedata * filedata = NULL; 19851 19852 if (stat (pathname, & statbuf) < 0 19853 || ! S_ISREG (statbuf.st_mode)) 19854 goto fail; 19855 19856 filedata = calloc (1, sizeof * filedata); 19857 if (filedata == NULL) 19858 goto fail; 19859 19860 filedata->handle = fopen (pathname, "rb"); 19861 if (filedata->handle == NULL) 19862 goto fail; 19863 19864 filedata->file_size = (bfd_size_type) statbuf.st_size; 19865 filedata->file_name = pathname; 19866 19867 if (! get_file_header (filedata)) 19868 goto fail; 19869 19870 if (filedata->file_header.e_shoff) 19871 { 19872 bfd_boolean res; 19873 19874 /* Read the section headers again, this time for real. */ 19875 if (is_32bit_elf) 19876 res = get_32bit_section_headers (filedata, FALSE); 19877 else 19878 res = get_64bit_section_headers (filedata, FALSE); 19879 19880 if (!res) 19881 goto fail; 19882 } 19883 19884 return filedata; 19885 19886 fail: 19887 if (filedata) 19888 { 19889 if (filedata->handle) 19890 fclose (filedata->handle); 19891 free (filedata); 19892 } 19893 return NULL; 19894 } 19895 19896 void * 19897 open_debug_file (const char * pathname) 19898 { 19899 return open_file (pathname); 19900 } 19901 19902 /* Process one ELF object file according to the command line options. 19903 This file may actually be stored in an archive. The file is 19904 positioned at the start of the ELF object. Returns TRUE if no 19905 problems were encountered, FALSE otherwise. */ 19906 19907 static bfd_boolean 19908 process_object (Filedata * filedata) 19909 { 19910 bfd_boolean have_separate_files; 19911 unsigned int i; 19912 bfd_boolean res = TRUE; 19913 19914 if (! get_file_header (filedata)) 19915 { 19916 error (_("%s: Failed to read file header\n"), filedata->file_name); 19917 return FALSE; 19918 } 19919 19920 /* Initialise per file variables. */ 19921 for (i = ARRAY_SIZE (version_info); i--;) 19922 version_info[i] = 0; 19923 19924 for (i = ARRAY_SIZE (dynamic_info); i--;) 19925 dynamic_info[i] = 0; 19926 dynamic_info_DT_GNU_HASH = 0; 19927 dynamic_info_DT_MIPS_XHASH = 0; 19928 19929 /* Process the file. */ 19930 if (show_name) 19931 printf (_("\nFile: %s\n"), filedata->file_name); 19932 19933 /* Initialise the dump_sects array from the cmdline_dump_sects array. 19934 Note we do this even if cmdline_dump_sects is empty because we 19935 must make sure that the dump_sets array is zeroed out before each 19936 object file is processed. */ 19937 if (filedata->num_dump_sects > cmdline.num_dump_sects) 19938 memset (filedata->dump_sects, 0, filedata->num_dump_sects * sizeof (* filedata->dump_sects)); 19939 19940 if (cmdline.num_dump_sects > 0) 19941 { 19942 if (filedata->num_dump_sects == 0) 19943 /* A sneaky way of allocating the dump_sects array. */ 19944 request_dump_bynumber (filedata, cmdline.num_dump_sects, 0); 19945 19946 assert (filedata->num_dump_sects >= cmdline.num_dump_sects); 19947 memcpy (filedata->dump_sects, cmdline.dump_sects, 19948 cmdline.num_dump_sects * sizeof (* filedata->dump_sects)); 19949 } 19950 19951 if (! process_file_header (filedata)) 19952 return FALSE; 19953 19954 if (! process_section_headers (filedata)) 19955 { 19956 /* Without loaded section headers we cannot process lots of things. */ 19957 do_unwind = do_version = do_dump = do_arch = FALSE; 19958 19959 if (! do_using_dynamic) 19960 do_syms = do_dyn_syms = do_reloc = FALSE; 19961 } 19962 19963 if (! process_section_groups (filedata)) 19964 /* Without loaded section groups we cannot process unwind. */ 19965 do_unwind = FALSE; 19966 19967 if (process_program_headers (filedata)) 19968 process_dynamic_section (filedata); 19969 else 19970 res = FALSE; 19971 19972 if (! process_relocs (filedata)) 19973 res = FALSE; 19974 19975 if (! process_unwind (filedata)) 19976 res = FALSE; 19977 19978 if (! process_symbol_table (filedata)) 19979 res = FALSE; 19980 19981 if (! process_syminfo (filedata)) 19982 res = FALSE; 19983 19984 if (! process_version_sections (filedata)) 19985 res = FALSE; 19986 19987 if (filedata->file_header.e_shstrndx != SHN_UNDEF) 19988 have_separate_files = load_separate_debug_files (filedata, filedata->file_name); 19989 else 19990 have_separate_files = FALSE; 19991 19992 if (! process_section_contents (filedata)) 19993 res = FALSE; 19994 19995 if (have_separate_files) 19996 { 19997 separate_info * d; 19998 19999 for (d = first_separate_info; d != NULL; d = d->next) 20000 { 20001 if (! process_section_headers (d->handle)) 20002 res = FALSE; 20003 else if (! process_section_contents (d->handle)) 20004 res = FALSE; 20005 } 20006 20007 /* The file handles are closed by the call to free_debug_memory() below. */ 20008 } 20009 20010 if (! process_notes (filedata)) 20011 res = FALSE; 20012 20013 if (! process_gnu_liblist (filedata)) 20014 res = FALSE; 20015 20016 if (! process_arch_specific (filedata)) 20017 res = FALSE; 20018 20019 free (filedata->program_headers); 20020 filedata->program_headers = NULL; 20021 20022 free (filedata->section_headers); 20023 filedata->section_headers = NULL; 20024 20025 free (filedata->string_table); 20026 filedata->string_table = NULL; 20027 filedata->string_table_length = 0; 20028 20029 if (filedata->dump_sects != NULL) 20030 { 20031 free (filedata->dump_sects); 20032 filedata->dump_sects = NULL; 20033 filedata->num_dump_sects = 0; 20034 } 20035 20036 if (dynamic_strings) 20037 { 20038 free (dynamic_strings); 20039 dynamic_strings = NULL; 20040 dynamic_strings_length = 0; 20041 } 20042 20043 if (dynamic_symbols) 20044 { 20045 free (dynamic_symbols); 20046 dynamic_symbols = NULL; 20047 num_dynamic_syms = 0; 20048 } 20049 20050 if (dynamic_syminfo) 20051 { 20052 free (dynamic_syminfo); 20053 dynamic_syminfo = NULL; 20054 } 20055 20056 if (dynamic_section) 20057 { 20058 free (dynamic_section); 20059 dynamic_section = NULL; 20060 } 20061 20062 if (section_headers_groups) 20063 { 20064 free (section_headers_groups); 20065 section_headers_groups = NULL; 20066 } 20067 20068 if (section_groups) 20069 { 20070 struct group_list * g; 20071 struct group_list * next; 20072 20073 for (i = 0; i < group_count; i++) 20074 { 20075 for (g = section_groups [i].root; g != NULL; g = next) 20076 { 20077 next = g->next; 20078 free (g); 20079 } 20080 } 20081 20082 free (section_groups); 20083 section_groups = NULL; 20084 } 20085 20086 free_debug_memory (); 20087 20088 return res; 20089 } 20090 20091 /* Process an ELF archive. 20092 On entry the file is positioned just after the ARMAG string. 20093 Returns TRUE upon success, FALSE otherwise. */ 20094 20095 static bfd_boolean 20096 process_archive (Filedata * filedata, bfd_boolean is_thin_archive) 20097 { 20098 struct archive_info arch; 20099 struct archive_info nested_arch; 20100 size_t got; 20101 bfd_boolean ret = TRUE; 20102 20103 show_name = TRUE; 20104 20105 /* The ARCH structure is used to hold information about this archive. */ 20106 arch.file_name = NULL; 20107 arch.file = NULL; 20108 arch.index_array = NULL; 20109 arch.sym_table = NULL; 20110 arch.longnames = NULL; 20111 20112 /* The NESTED_ARCH structure is used as a single-item cache of information 20113 about a nested archive (when members of a thin archive reside within 20114 another regular archive file). */ 20115 nested_arch.file_name = NULL; 20116 nested_arch.file = NULL; 20117 nested_arch.index_array = NULL; 20118 nested_arch.sym_table = NULL; 20119 nested_arch.longnames = NULL; 20120 20121 if (setup_archive (&arch, filedata->file_name, filedata->handle, 20122 is_thin_archive, do_archive_index) != 0) 20123 { 20124 ret = FALSE; 20125 goto out; 20126 } 20127 20128 if (do_archive_index) 20129 { 20130 if (arch.sym_table == NULL) 20131 error (_("%s: unable to dump the index as none was found\n"), filedata->file_name); 20132 else 20133 { 20134 unsigned long i, l; 20135 unsigned long current_pos; 20136 20137 printf (_("Index of archive %s: (%lu entries, 0x%lx bytes in the symbol table)\n"), 20138 filedata->file_name, (unsigned long) arch.index_num, arch.sym_size); 20139 20140 current_pos = ftell (filedata->handle); 20141 20142 for (i = l = 0; i < arch.index_num; i++) 20143 { 20144 if ((i == 0) || ((i > 0) && (arch.index_array[i] != arch.index_array[i - 1]))) 20145 { 20146 char * member_name; 20147 20148 member_name = get_archive_member_name_at (&arch, arch.index_array[i], &nested_arch); 20149 20150 if (member_name != NULL) 20151 { 20152 char * qualified_name = make_qualified_name (&arch, &nested_arch, member_name); 20153 20154 if (qualified_name != NULL) 20155 { 20156 printf (_("Contents of binary %s at offset "), qualified_name); 20157 (void) print_vma (arch.index_array[i], PREFIX_HEX); 20158 putchar ('\n'); 20159 free (qualified_name); 20160 } 20161 } 20162 } 20163 20164 if (l >= arch.sym_size) 20165 { 20166 error (_("%s: end of the symbol table reached before the end of the index\n"), 20167 filedata->file_name); 20168 ret = FALSE; 20169 break; 20170 } 20171 /* PR 17531: file: 0b6630b2. */ 20172 printf ("\t%.*s\n", (int) (arch.sym_size - l), arch.sym_table + l); 20173 l += strnlen (arch.sym_table + l, arch.sym_size - l) + 1; 20174 } 20175 20176 if (arch.uses_64bit_indices) 20177 l = (l + 7) & ~ 7; 20178 else 20179 l += l & 1; 20180 20181 if (l < arch.sym_size) 20182 { 20183 error (ngettext ("%s: %ld byte remains in the symbol table, " 20184 "but without corresponding entries in " 20185 "the index table\n", 20186 "%s: %ld bytes remain in the symbol table, " 20187 "but without corresponding entries in " 20188 "the index table\n", 20189 arch.sym_size - l), 20190 filedata->file_name, arch.sym_size - l); 20191 ret = FALSE; 20192 } 20193 20194 if (fseek (filedata->handle, current_pos, SEEK_SET) != 0) 20195 { 20196 error (_("%s: failed to seek back to start of object files in the archive\n"), 20197 filedata->file_name); 20198 ret = FALSE; 20199 goto out; 20200 } 20201 } 20202 20203 if (!do_dynamic && !do_syms && !do_reloc && !do_unwind && !do_sections 20204 && !do_segments && !do_header && !do_dump && !do_version 20205 && !do_histogram && !do_debugging && !do_arch && !do_notes 20206 && !do_section_groups && !do_dyn_syms) 20207 { 20208 ret = TRUE; /* Archive index only. */ 20209 goto out; 20210 } 20211 } 20212 20213 while (1) 20214 { 20215 char * name; 20216 size_t namelen; 20217 char * qualified_name; 20218 20219 /* Read the next archive header. */ 20220 if (fseek (filedata->handle, arch.next_arhdr_offset, SEEK_SET) != 0) 20221 { 20222 error (_("%s: failed to seek to next archive header\n"), arch.file_name); 20223 return FALSE; 20224 } 20225 got = fread (&arch.arhdr, 1, sizeof arch.arhdr, filedata->handle); 20226 if (got != sizeof arch.arhdr) 20227 { 20228 if (got == 0) 20229 break; 20230 /* PR 24049 - we cannot use filedata->file_name as this will 20231 have already been freed. */ 20232 error (_("%s: failed to read archive header\n"), arch.file_name); 20233 20234 ret = FALSE; 20235 break; 20236 } 20237 if (memcmp (arch.arhdr.ar_fmag, ARFMAG, 2) != 0) 20238 { 20239 error (_("%s: did not find a valid archive header\n"), arch.file_name); 20240 ret = FALSE; 20241 break; 20242 } 20243 20244 arch.next_arhdr_offset += sizeof arch.arhdr; 20245 20246 archive_file_size = strtoul (arch.arhdr.ar_size, NULL, 10); 20247 if (archive_file_size & 01) 20248 ++archive_file_size; 20249 20250 name = get_archive_member_name (&arch, &nested_arch); 20251 if (name == NULL) 20252 { 20253 error (_("%s: bad archive file name\n"), arch.file_name); 20254 ret = FALSE; 20255 break; 20256 } 20257 namelen = strlen (name); 20258 20259 qualified_name = make_qualified_name (&arch, &nested_arch, name); 20260 if (qualified_name == NULL) 20261 { 20262 error (_("%s: bad archive file name\n"), arch.file_name); 20263 ret = FALSE; 20264 break; 20265 } 20266 20267 if (is_thin_archive && arch.nested_member_origin == 0) 20268 { 20269 /* This is a proxy for an external member of a thin archive. */ 20270 Filedata * member_filedata; 20271 char * member_file_name = adjust_relative_path 20272 (filedata->file_name, name, namelen); 20273 20274 if (member_file_name == NULL) 20275 { 20276 ret = FALSE; 20277 break; 20278 } 20279 20280 member_filedata = open_file (member_file_name); 20281 if (member_filedata == NULL) 20282 { 20283 error (_("Input file '%s' is not readable.\n"), member_file_name); 20284 free (member_file_name); 20285 ret = FALSE; 20286 break; 20287 } 20288 20289 archive_file_offset = arch.nested_member_origin; 20290 member_filedata->file_name = qualified_name; 20291 20292 if (! process_object (member_filedata)) 20293 ret = FALSE; 20294 20295 close_file (member_filedata); 20296 free (member_file_name); 20297 } 20298 else if (is_thin_archive) 20299 { 20300 Filedata thin_filedata; 20301 20302 memset (&thin_filedata, 0, sizeof (thin_filedata)); 20303 20304 /* PR 15140: Allow for corrupt thin archives. */ 20305 if (nested_arch.file == NULL) 20306 { 20307 error (_("%s: contains corrupt thin archive: %s\n"), 20308 qualified_name, name); 20309 ret = FALSE; 20310 break; 20311 } 20312 20313 /* This is a proxy for a member of a nested archive. */ 20314 archive_file_offset = arch.nested_member_origin + sizeof arch.arhdr; 20315 20316 /* The nested archive file will have been opened and setup by 20317 get_archive_member_name. */ 20318 if (fseek (nested_arch.file, archive_file_offset, SEEK_SET) != 0) 20319 { 20320 error (_("%s: failed to seek to archive member.\n"), nested_arch.file_name); 20321 ret = FALSE; 20322 break; 20323 } 20324 20325 thin_filedata.handle = nested_arch.file; 20326 thin_filedata.file_name = qualified_name; 20327 20328 if (! process_object (& thin_filedata)) 20329 ret = FALSE; 20330 } 20331 else 20332 { 20333 archive_file_offset = arch.next_arhdr_offset; 20334 arch.next_arhdr_offset += archive_file_size; 20335 20336 filedata->file_name = qualified_name; 20337 if (! process_object (filedata)) 20338 ret = FALSE; 20339 } 20340 20341 free (qualified_name); 20342 } 20343 20344 out: 20345 if (nested_arch.file != NULL) 20346 fclose (nested_arch.file); 20347 release_archive (&nested_arch); 20348 release_archive (&arch); 20349 20350 return ret; 20351 } 20352 20353 static bfd_boolean 20354 process_file (char * file_name) 20355 { 20356 Filedata * filedata = NULL; 20357 struct stat statbuf; 20358 char armag[SARMAG]; 20359 bfd_boolean ret = TRUE; 20360 20361 if (stat (file_name, &statbuf) < 0) 20362 { 20363 if (errno == ENOENT) 20364 error (_("'%s': No such file\n"), file_name); 20365 else 20366 error (_("Could not locate '%s'. System error message: %s\n"), 20367 file_name, strerror (errno)); 20368 return FALSE; 20369 } 20370 20371 if (!do_special_files && ! S_ISREG (statbuf.st_mode)) 20372 { 20373 error (_("'%s' is not an ordinary file\n"), file_name); 20374 return FALSE; 20375 } 20376 20377 filedata = calloc (1, sizeof * filedata); 20378 if (filedata == NULL) 20379 { 20380 error (_("Out of memory allocating file data structure\n")); 20381 return FALSE; 20382 } 20383 20384 filedata->file_name = file_name; 20385 filedata->handle = fopen (file_name, "rb"); 20386 if (filedata->handle == NULL) 20387 { 20388 error (_("Input file '%s' is not readable.\n"), file_name); 20389 free (filedata); 20390 return FALSE; 20391 } 20392 20393 if (fread (armag, SARMAG, 1, filedata->handle) != 1) 20394 { 20395 error (_("%s: Failed to read file's magic number\n"), file_name); 20396 fclose (filedata->handle); 20397 free (filedata); 20398 return FALSE; 20399 } 20400 20401 filedata->file_size = (bfd_size_type) statbuf.st_size; 20402 20403 if (memcmp (armag, ARMAG, SARMAG) == 0) 20404 { 20405 if (! process_archive (filedata, FALSE)) 20406 ret = FALSE; 20407 } 20408 else if (memcmp (armag, ARMAGT, SARMAG) == 0) 20409 { 20410 if ( ! process_archive (filedata, TRUE)) 20411 ret = FALSE; 20412 } 20413 else 20414 { 20415 if (do_archive_index) 20416 error (_("File %s is not an archive so its index cannot be displayed.\n"), 20417 file_name); 20418 20419 rewind (filedata->handle); 20420 archive_file_size = archive_file_offset = 0; 20421 20422 if (! process_object (filedata)) 20423 ret = FALSE; 20424 } 20425 20426 fclose (filedata->handle); 20427 free (filedata); 20428 20429 return ret; 20430 } 20431 20432 #ifdef SUPPORT_DISASSEMBLY 20433 /* Needed by the i386 disassembler. For extra credit, someone could 20434 fix this so that we insert symbolic addresses here, esp for GOT/PLT 20435 symbols. */ 20436 20437 void 20438 print_address (unsigned int addr, FILE * outfile) 20439 { 20440 fprintf (outfile,"0x%8.8x", addr); 20441 } 20442 20443 /* Needed by the i386 disassembler. */ 20444 20445 void 20446 db_task_printsym (unsigned int addr) 20447 { 20448 print_address (addr, stderr); 20449 } 20450 #endif 20451 20452 int 20453 main (int argc, char ** argv) 20454 { 20455 int err; 20456 20457 #if defined (HAVE_SETLOCALE) && defined (HAVE_LC_MESSAGES) 20458 setlocale (LC_MESSAGES, ""); 20459 #endif 20460 #if defined (HAVE_SETLOCALE) 20461 setlocale (LC_CTYPE, ""); 20462 #endif 20463 bindtextdomain (PACKAGE, LOCALEDIR); 20464 textdomain (PACKAGE); 20465 20466 expandargv (&argc, &argv); 20467 20468 cmdline.file_name = "<cmdline>"; 20469 parse_args (& cmdline, argc, argv); 20470 20471 if (optind < (argc - 1)) 20472 show_name = TRUE; 20473 else if (optind >= argc) 20474 { 20475 warn (_("Nothing to do.\n")); 20476 usage (stderr); 20477 } 20478 20479 err = FALSE; 20480 while (optind < argc) 20481 if (! process_file (argv[optind++])) 20482 err = TRUE; 20483 20484 if (cmdline.dump_sects != NULL) 20485 free (cmdline.dump_sects); 20486 20487 free (dump_ctf_symtab_name); 20488 free (dump_ctf_strtab_name); 20489 free (dump_ctf_parent_name); 20490 20491 return err ? EXIT_FAILURE : EXIT_SUCCESS; 20492 } 20493