Changeset 1973 for binutils/trunk/bfd/pei-x86_64.c
- Timestamp:
- Feb 6, 2017, 1:00:00 PM (8 years ago)
- Location:
- binutils/trunk
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
binutils/trunk ¶
-
Property svn:mergeinfo
set to
/binutils/vendor/current merged eligible
-
Property svn:mergeinfo
set to
-
TabularUnified binutils/trunk/bfd/pei-x86_64.c ¶
r970 r1973 1 1 /* BFD back-end for Intel 386 PE IMAGE COFF files. 2 Copyright (C) 2006-201 4Free Software Foundation, Inc.2 Copyright (C) 2006-2016 Free Software Foundation, Inc. 3 3 4 4 This file is part of BFD, the Binary File Descriptor library. … … 116 116 ui->SizeOfBlock = ui->sizeofUnwindCodes + 4; 117 117 ui->rawUnwindCodes = &ex_dta[4]; 118 118 119 ex_dta += ui->SizeOfBlock; 119 120 switch (ui->Flags) … … 277 278 break; 278 279 default: 279 /* Already caught by the previous scan. */ 280 abort (); 280 /* PR 17512: file: 2245-7442-0.004. */ 281 fprintf (file, _("Unknown: %x"), PEX64_UNWCODE_CODE (dta[1])); 282 break; 281 283 } 282 284 if (unexpected) … … 318 320 bfd_vma end_addr; 319 321 bfd_vma addr = rf->rva_UnwindData; 322 bfd_size_type sec_size = xdata_section->rawsize > 0 ? xdata_section->rawsize : xdata_section->size; 320 323 struct pex64_unwind_info ui; 321 324 … … 323 326 addr -= vaddr; 324 327 328 /* PR 17512: file: 2245-7442-0.004. */ 329 if (addr >= sec_size) 330 { 331 fprintf (file, _("warning: xdata section corrupt\n")); 332 return; 333 } 334 325 335 if (endx) 326 end_addr = endx[0] - vaddr; 336 { 337 end_addr = endx[0] - vaddr; 338 /* PR 17512: file: 2245-7442-0.004. */ 339 if (end_addr > sec_size) 340 { 341 fprintf (file, _("warning: xdata section corrupt")); 342 end_addr = sec_size; 343 } 344 } 327 345 else 328 end_addr = (xdata_section->rawsize != 0 ? 329 xdata_section->rawsize : xdata_section->size); 330 346 end_addr = sec_size; 331 347 332 348 pex64_get_unwind_info (abfd, &ui, &xdata[addr]); … … 381 397 : pex_regs[(unsigned int) ui.FrameRegister]); 382 398 383 pex64_xdata_print_uwd_codes (file, abfd, &ui, rf); 399 /* PR 17512: file: 2245-7442-0.004. */ 400 if (ui.CountOfCodes * 2 + ui.rawUnwindCodes > xdata + xdata_section->size) 401 fprintf (file, _("Too many unwind codes (%ld)\n"), (long) ui.CountOfCodes); 402 else 403 pex64_xdata_print_uwd_codes (file, abfd, &ui, rf); 384 404 385 405 switch (ui.Flags) … … 440 460 441 461 static bfd_boolean 442 pex64_bfd_print_pdata (bfd *abfd, void *vfile)462 pex64_bfd_print_pdata_section (bfd *abfd, void *vfile, asection *pdata_section) 443 463 { 444 464 FILE *file = (FILE *) vfile; 445 465 bfd_byte *pdata = NULL; 446 466 bfd_byte *xdata = NULL; 447 asection *pdata_section = bfd_get_section_by_name (abfd, ".pdata"); 448 asection *xdata_section; 467 asection *xdata_section = NULL; 449 468 bfd_vma xdata_base; 450 469 bfd_size_type i; 470 bfd_size_type datasize; 451 471 bfd_size_type stop; 452 bfd_vma prev_beginaddress = 0;453 bfd_vma prev_unwinddata_rva = 0;472 bfd_vma prev_beginaddress = (bfd_vma) -1; 473 bfd_vma prev_unwinddata_rva = (bfd_vma) -1; 454 474 bfd_vma imagebase; 455 475 int onaline = PDATA_ROW_SIZE; … … 457 477 bfd_vma *xdata_arr = NULL; 458 478 int xdata_arr_cnt; 479 bfd_boolean virt_size_is_zero = FALSE; 459 480 460 481 /* Sanity checks. */ … … 467 488 if ((stop % onaline) != 0) 468 489 fprintf (file, 469 _("warning: .pdata section size (%ld) is not a multiple of %d\n"), 470 (long) stop, onaline); 490 _("Warning: %s section size (%ld) is not a multiple of %d\n"), 491 pdata_section->name, (long) stop, onaline); 492 493 datasize = pdata_section->size; 494 if (datasize == 0) 495 { 496 if (stop) 497 fprintf (file, _("Warning: %s section size is zero\n"), 498 pdata_section->name); 499 return TRUE; 500 } 501 502 /* virt_size might be zero for objects. */ 503 if (stop == 0 && strcmp (abfd->xvec->name, "pe-x86-64") == 0) 504 { 505 stop = (datasize / onaline) * onaline; 506 virt_size_is_zero = TRUE; 507 } 508 else if (datasize < stop) 509 { 510 fprintf (file, 511 _("Warning: %s section size (%ld) is smaller than virtual size (%ld)\n"), 512 pdata_section->name, (unsigned long) datasize, 513 (unsigned long) stop); 514 /* Be sure not to read passed datasize. */ 515 stop = datasize / onaline; 516 } 471 517 472 518 /* Display functions table. */ 473 519 fprintf (file, 474 _("\nThe Function Table (interpreted .pdata section contents)\n")); 520 _("\nThe Function Table (interpreted %s section contents)\n"), 521 pdata_section->name); 475 522 476 523 fprintf (file, _("vma:\t\t\tBeginAddress\t EndAddress\t UnwindData\n")); … … 483 530 xdata_arr_cnt = 0; 484 531 485 imagebase = pe_data (abfd)->pe_opthdr.ImageBase; 532 if (strcmp (abfd->xvec->name, "pei-x86-64") == 0) 533 imagebase = pe_data (abfd)->pe_opthdr.ImageBase; 534 else 535 imagebase = 0; 486 536 487 537 for (i = 0; i < stop; i += onaline) … … 491 541 if (i + PDATA_ROW_SIZE > stop) 492 542 break; 543 493 544 pex64_get_runtime_function (abfd, &rf, &pdata[i]); 494 545 … … 529 580 fprintf (file, " has negative unwind address\n"); 530 581 } 531 if (rf.rva_UnwindData && !PEX64_IS_RUNTIME_FUNCTION_CHAINED (&rf)) 532 xdata_arr[xdata_arr_cnt++] = rf.rva_UnwindData; 582 else if ((rf.rva_UnwindData && !PEX64_IS_RUNTIME_FUNCTION_CHAINED (&rf)) 583 || virt_size_is_zero) 584 xdata_arr[xdata_arr_cnt++] = rf.rva_UnwindData; 533 585 } 534 586 … … 546 598 /* Find the section containing the unwind data (.xdata). */ 547 599 xdata_base = xdata_arr[0]; 548 xdata_section = pex64_get_section_by_rva (abfd, xdata_base, ".rdata"); 549 550 if (!xdata_section) 551 xdata_section = pex64_get_section_by_rva (abfd, xdata_base, ".data"); 600 /* For sections with long names, first look for the same 601 section name, replacing .pdata by .xdata prefix. */ 602 if (strcmp (pdata_section->name, ".pdata") != 0) 603 { 604 size_t len = strlen (pdata_section->name); 605 char *xdata_name = xmalloc (len + 1); 606 607 xdata_name = memcpy (xdata_name, pdata_section->name, len + 1); 608 /* Transform .pdata prefix into .xdata prefix. */ 609 if (len > 1) 610 xdata_name [1] = 'x'; 611 xdata_section = pex64_get_section_by_rva (abfd, xdata_base, 612 xdata_name); 613 free (xdata_name); 614 } 615 /* Second, try the .xdata section itself. */ 552 616 if (!xdata_section) 553 617 xdata_section = pex64_get_section_by_rva (abfd, xdata_base, ".xdata"); 554 if (!xdata_section) 618 /* Otherwise, if xdata_base is non zero, search also inside 619 other standard sections. */ 620 if (!xdata_section && xdata_base) 621 xdata_section = pex64_get_section_by_rva (abfd, xdata_base, ".rdata"); 622 if (!xdata_section && xdata_base) 623 xdata_section = pex64_get_section_by_rva (abfd, xdata_base, ".data"); 624 if (!xdata_section && xdata_base) 555 625 xdata_section = pex64_get_section_by_rva (abfd, xdata_base, ".pdata"); 556 if (!xdata_section )626 if (!xdata_section && xdata_base) 557 627 xdata_section = pex64_get_section_by_rva (abfd, xdata_base, ".text"); 628 /* Transfer xdata section into xdata array. */ 558 629 if (!xdata_section 559 630 || !bfd_malloc_and_get_section (abfd, xdata_section, &xdata)) 560 631 goto done; 561 632 633 /* Avoid "also used "... ouput for single unwind info 634 in object file. */ 635 prev_unwinddata_rva = (bfd_vma) -1; 636 562 637 /* Do dump of pdata related xdata. */ 563 638 for (i = 0; i < stop; i += onaline) … … 567 642 if (i + PDATA_ROW_SIZE > stop) 568 643 break; 644 569 645 pex64_get_runtime_function (abfd, &rf, &pdata[i]); 570 646 … … 574 650 break; 575 651 if (i == 0) 576 fprintf (file, "\nDump of .xdata\n");652 fprintf (file, _("\nDump of %s\n"), xdata_section->name); 577 653 578 654 fputc (' ', file); … … 597 673 fputc ('\n', file); 598 674 599 if (rf.rva_UnwindData != 0 )675 if (rf.rva_UnwindData != 0 || virt_size_is_zero) 600 676 { 601 677 if (PEX64_IS_RUNTIME_FUNCTION_CHAINED (&rf)) … … 636 712 while (p[0] <= rf.rva_UnwindData) 637 713 ++p; 714 638 715 if (p[0] == ~((bfd_vma) 0)) 639 716 p = NULL; … … 652 729 } 653 730 731 /* Static counter of number of found pdata sections. */ 732 static bfd_boolean pdata_count; 733 734 /* Functionn prototype. */ 735 bfd_boolean pex64_bfd_print_pdata (bfd *, void *); 736 737 /* Helper function for bfd_map_over_section. */ 738 static void 739 pex64_print_all_pdata_sections (bfd *abfd, asection *pdata, void *obj) 740 { 741 if (CONST_STRNEQ (pdata->name, ".pdata")) 742 { 743 if (pex64_bfd_print_pdata_section (abfd, obj, pdata)) 744 pdata_count++; 745 } 746 } 747 748 bfd_boolean 749 pex64_bfd_print_pdata (bfd *abfd, void *vfile) 750 { 751 asection *pdata_section = bfd_get_section_by_name (abfd, ".pdata"); 752 753 if (pdata_section) 754 return pex64_bfd_print_pdata_section (abfd, vfile, pdata_section); 755 756 pdata_count = 0; 757 bfd_map_over_sections (abfd, pex64_print_all_pdata_sections, vfile); 758 return (pdata_count > 0); 759 } 760 654 761 #define bfd_pe_print_pdata pex64_bfd_print_pdata 762 #define bfd_coff_std_swap_table bfd_coff_pei_swap_table 655 763 656 764 #include "coff-x86_64.c"
Note:
See TracChangeset
for help on using the changeset viewer.