Ignore:
Timestamp:
Feb 6, 2017, 1:00:00 PM (8 years ago)
Author:
Silvan Scherrer
Message:

binutils: update trunk to version 2.27

Location:
binutils/trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • binutils/trunk

  • TabularUnified binutils/trunk/bfd/pei-x86_64.c

    r970 r1973  
    11/* BFD back-end for Intel 386 PE IMAGE COFF files.
    2    Copyright (C) 2006-2014 Free Software Foundation, Inc.
     2   Copyright (C) 2006-2016 Free Software Foundation, Inc.
    33
    44   This file is part of BFD, the Binary File Descriptor library.
     
    116116  ui->SizeOfBlock = ui->sizeofUnwindCodes + 4;
    117117  ui->rawUnwindCodes = &ex_dta[4];
     118
    118119  ex_dta += ui->SizeOfBlock;
    119120  switch (ui->Flags)
     
    277278          break;
    278279        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;
    281283      }
    282284      if (unexpected)
     
    318320  bfd_vma end_addr;
    319321  bfd_vma addr = rf->rva_UnwindData;
     322  bfd_size_type sec_size = xdata_section->rawsize > 0 ? xdata_section->rawsize : xdata_section->size;
    320323  struct pex64_unwind_info ui;
    321324
     
    323326  addr -= vaddr;
    324327
     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
    325335  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    }
    327345  else
    328     end_addr = (xdata_section->rawsize != 0 ?
    329                 xdata_section->rawsize : xdata_section->size);
    330 
     346    end_addr = sec_size;
    331347
    332348  pex64_get_unwind_info (abfd, &ui, &xdata[addr]);
     
    381397           : pex_regs[(unsigned int) ui.FrameRegister]);
    382398
    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);
    384404
    385405  switch (ui.Flags)
     
    440460
    441461static bfd_boolean
    442 pex64_bfd_print_pdata (bfd *abfd, void *vfile)
     462pex64_bfd_print_pdata_section (bfd *abfd, void *vfile, asection *pdata_section)
    443463{
    444464  FILE *file = (FILE *) vfile;
    445465  bfd_byte *pdata = NULL;
    446466  bfd_byte *xdata = NULL;
    447   asection *pdata_section = bfd_get_section_by_name (abfd, ".pdata");
    448   asection *xdata_section;
     467  asection *xdata_section = NULL;
    449468  bfd_vma xdata_base;
    450469  bfd_size_type i;
     470  bfd_size_type datasize;
    451471  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;
    454474  bfd_vma imagebase;
    455475  int onaline = PDATA_ROW_SIZE;
     
    457477  bfd_vma *xdata_arr = NULL;
    458478  int xdata_arr_cnt;
     479  bfd_boolean virt_size_is_zero = FALSE;
    459480
    460481  /* Sanity checks.  */
     
    467488  if ((stop % onaline) != 0)
    468489    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      }
    471517
    472518  /* Display functions table.  */
    473519  fprintf (file,
    474            _("\nThe Function Table (interpreted .pdata section contents)\n"));
     520           _("\nThe Function Table (interpreted %s section contents)\n"),
     521           pdata_section->name);
    475522
    476523  fprintf (file, _("vma:\t\t\tBeginAddress\t EndAddress\t  UnwindData\n"));
     
    483530  xdata_arr_cnt = 0;
    484531
    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;
    486536
    487537  for (i = 0; i < stop; i += onaline)
     
    491541      if (i + PDATA_ROW_SIZE > stop)
    492542        break;
     543
    493544      pex64_get_runtime_function (abfd, &rf, &pdata[i]);
    494545
     
    529580          fprintf (file, "  has negative unwind address\n");
    530581        }
    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;
    533585    }
    534586
     
    546598  /* Find the section containing the unwind data (.xdata).  */
    547599  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.  */
    552616  if (!xdata_section)
    553617    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)
    555625    xdata_section = pex64_get_section_by_rva (abfd, xdata_base, ".pdata");
    556   if (!xdata_section)
     626  if (!xdata_section && xdata_base)
    557627    xdata_section = pex64_get_section_by_rva (abfd, xdata_base, ".text");
     628  /* Transfer xdata section into xdata array.  */
    558629  if (!xdata_section
    559630      || !bfd_malloc_and_get_section (abfd, xdata_section, &xdata))
    560631    goto done;
    561632
     633  /* Avoid "also used "... ouput for single unwind info
     634     in object file.  */
     635  prev_unwinddata_rva = (bfd_vma) -1;
     636
    562637  /* Do dump of pdata related xdata.  */
    563638  for (i = 0; i < stop; i += onaline)
     
    567642      if (i + PDATA_ROW_SIZE > stop)
    568643        break;
     644
    569645      pex64_get_runtime_function (abfd, &rf, &pdata[i]);
    570646
     
    574650        break;
    575651      if (i == 0)
    576         fprintf (file, "\nDump of .xdata\n");
     652        fprintf (file, _("\nDump of %s\n"), xdata_section->name);
    577653
    578654      fputc (' ', file);
     
    597673      fputc ('\n', file);
    598674
    599       if (rf.rva_UnwindData != 0)
     675      if (rf.rva_UnwindData != 0 || virt_size_is_zero)
    600676        {
    601677          if (PEX64_IS_RUNTIME_FUNCTION_CHAINED (&rf))
     
    636712              while (p[0] <= rf.rva_UnwindData)
    637713                ++p;
     714
    638715              if (p[0] == ~((bfd_vma) 0))
    639716                p = NULL;
     
    652729}
    653730
     731/* Static counter of number of found pdata sections.  */
     732static bfd_boolean pdata_count;
     733
     734/* Functionn prototype.  */
     735bfd_boolean pex64_bfd_print_pdata (bfd *, void *);
     736
     737/* Helper function for bfd_map_over_section.  */
     738static void
     739pex64_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
     748bfd_boolean
     749pex64_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
    654761#define bfd_pe_print_pdata   pex64_bfd_print_pdata
     762#define bfd_coff_std_swap_table bfd_coff_pei_swap_table
    655763
    656764#include "coff-x86_64.c"
Note: See TracChangeset for help on using the changeset viewer.