Allows the binutils to cope with PE binaries where the section addresses have been...
authorNick Clifton <nickc@redhat.com>
Thu, 5 Mar 2015 12:14:26 +0000 (12:14 +0000)
committerNick Clifton <nickc@redhat.com>
Thu, 5 Mar 2015 12:14:26 +0000 (12:14 +0000)
PR binutils/18025
* coffgen.c (coff_find_nearest_line_with_names): If the dwarf2
lookup fails, check for an address bias in the dwarf info, and if
one exists, retry the lookup with the biased value.
* dwarf2.c (_bfd_dwarf2_find_symbol_bias): New function.
Determines if a bias exists bewteen the addresses of functions
based on DWARF information vs symbol table information.
* libbfd-in.h (_bfd_dwarf2_find_symbol_bias): Prototype.
* libbfd.h: Regenerate.

bfd/ChangeLog
bfd/coffgen.c
bfd/dwarf2.c
bfd/libbfd-in.h
bfd/libbfd.h

index db027526837d91c942cd2ba0ccf2c59775a1ebe4..3f8cc863ea76711c8d4ec5f03c80da7a28063550 100644 (file)
@@ -1,3 +1,15 @@
+2015-03-05  Nick Clifton  <nickc@redhat.com>
+
+       PR binutils/18025
+       * coffgen.c (coff_find_nearest_line_with_names): If the dwarf2
+       lookup fails, check for an address bias in the dwarf info, and if
+       one exists, retry the lookup with the biased value.
+       * dwarf2.c (_bfd_dwarf2_find_symbol_bias): New function.
+       Determines if a bias exists bewteen the addresses of functions
+       based on DWARF information vs symbol table information.
+       * libbfd-in.h (_bfd_dwarf2_find_symbol_bias): Prototype.
+       * libbfd.h: Regenerate.
+
 2015-03-04  Marcus Shawcroft  <marcus.shawcroft@arm.com>
 
        * elfxx-aarch64.c (decode_add_imm, decode_movw_imm)
index 83673d4846cb8eeac3e1c358b58deabe0f1b158e..5c664a49f2bbff0011db6d33b8695b93d21e1a01 100644 (file)
@@ -2245,6 +2245,26 @@ coff_find_nearest_line_with_names (bfd *abfd,
                                     &coff_data(abfd)->dwarf2_find_line_info))
     return TRUE;
 
+  /* If the DWARF lookup failed, but there is DWARF information available
+     then the problem might be that the file has been rebased.  This tool
+     changes the VMAs of all the sections, but it does not update the DWARF
+     information.  So try again, using a bias against the address sought.  */
+  if (coff_data (abfd)->dwarf2_find_line_info != NULL)
+    {
+      bfd_signed_vma bias;
+
+      bias = _bfd_dwarf2_find_symbol_bias (symbols,
+                                          & coff_data (abfd)->dwarf2_find_line_info);
+      
+      if (bias
+         && _bfd_dwarf2_find_nearest_line (abfd, symbols, NULL, section,
+                                           offset + bias,
+                                           filename_ptr, functionname_ptr,
+                                           line_ptr, NULL, debug_sections, 0,
+                                           &coff_data(abfd)->dwarf2_find_line_info))
+       return TRUE;
+    }
+
   *filename_ptr = 0;
   *functionname_ptr = 0;
   *line_ptr = 0;
index 0a5d1cec4dd49eb53efa6a995f17f6ad8895c795..cbd4cf64869f47a400151d7976b6b3525b212c5e 100644 (file)
@@ -3788,6 +3788,57 @@ _bfd_dwarf2_slurp_debug_info (bfd *abfd, bfd *debug_bfd,
   return TRUE;
 }
 
+/* Scan the debug information in PINFO looking for a DW_TAG_subprogram
+   abbrev with a DW_AT_low_pc attached to it.  Then lookup that same
+   symbol in SYMBOLS and return the difference between the low_pc and
+   the symbol's address.  Returns 0 if no suitable symbol could be found.  */
+
+bfd_signed_vma
+_bfd_dwarf2_find_symbol_bias (asymbol ** symbols, void ** pinfo)
+{
+  struct dwarf2_debug *stash;
+  struct comp_unit * unit;
+
+  stash = (struct dwarf2_debug *) *pinfo;
+
+  if (stash == NULL)
+    return 0;
+
+  for (unit = stash->all_comp_units; unit; unit = unit->next_unit)
+    {
+      struct funcinfo * func;
+
+      if (unit->function_table == NULL)
+       {
+         if (unit->line_table == NULL)
+           unit->line_table = decode_line_info (unit, stash);
+         if (unit->line_table != NULL)
+           scan_unit_for_symbols (unit);
+       }
+
+      for (func = unit->function_table; func != NULL; func = func->prev_func)
+       if (func->name && func->arange.low)
+         {
+           asymbol ** psym;
+
+           /* FIXME: Do we need to scan the aranges looking for the lowest pc value ?  */
+
+           for (psym = symbols; * psym != NULL; psym++)
+             {
+               asymbol * sym = * psym;
+
+               if (sym->flags & BSF_FUNCTION
+                   && sym->section != NULL
+                   && strcmp (sym->name, func->name) == 0)
+                 return ((bfd_signed_vma) func->arange.low) -
+                   ((bfd_signed_vma) (sym->value + sym->section->vma));
+             }
+         }
+    }
+
+  return 0;
+}
+
 /* Find the source code location of SYMBOL.  If SYMBOL is NULL
    then find the nearest source code location corresponding to
    the address SECTION + OFFSET.
index 7c661e34797c0d0c1b877f2ba50137df6af87c3f..06fa652e67aad8d4f73f0eb91fe1868b15fab9a7 100644 (file)
@@ -551,6 +551,10 @@ extern bfd_boolean _bfd_dwarf2_find_nearest_line
    const char **, const char **, unsigned int *, unsigned int *,
    const struct dwarf_debug_section *, unsigned int, void **);
 
+/* Find the bias between DWARF addresses and real addresses.  */
+extern bfd_signed_vma _bfd_dwarf2_find_symbol_bias
+  (asymbol **, void **);
+  
 /* Find inliner info after calling bfd_find_nearest_line. */
 extern bfd_boolean _bfd_dwarf2_find_inliner_info
   (bfd *, const char **, const char **, unsigned int *, void **);
index 2aafecfbb12bc995368666103f724e47157454f9..14600aa1aa062c3544536d1398f7b3808ff0b775 100644 (file)
@@ -556,6 +556,10 @@ extern bfd_boolean _bfd_dwarf2_find_nearest_line
    const char **, const char **, unsigned int *, unsigned int *,
    const struct dwarf_debug_section *, unsigned int, void **);
 
+/* Find the bias between DWARF addresses and real addresses.  */
+extern bfd_signed_vma _bfd_dwarf2_find_symbol_bias
+  (asymbol **, void **);
+  
 /* Find inliner info after calling bfd_find_nearest_line. */
 extern bfd_boolean _bfd_dwarf2_find_inliner_info
   (bfd *, const char **, const char **, unsigned int *, void **);
This page took 0.04147 seconds and 4 git commands to generate.