PATCH: binutils/1179: -adjust-vma with negative number causes objdump -S to fail

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

PATCH: binutils/1179: -adjust-vma with negative number causes objdump -S to fail

H.J. Lu-27
I didn't try to support -adjust-vma for non-relocatable files. Without
relocation information, it is tricky to get the debug info right. I
am not sure if it is worth the effort. We also have to adjust it for
debug info. This patch works on ELF/i386.


H.J.
----
bfd/

2005-08-08  H.J. Lu  <[hidden email]>

        PR binutils/1179
        * dwarf2.c (dwarf2_debug): Add dwarf_abbrev_vma,
        dwarf_line_vma, dwarf_str_vma and dwarf_ranges_vma.
        (read_indirect_string): Adjust for dwarf_str_vma.
        (read_abbrevs): Adjust for dwarf_abbrev_vma.
        (decode_line_info): Adjust dwarf_line_vma.
        (read_debug_ranges): Adjust for dwarf_ranges_vma.
        (read_rangelist): Likewise.

binutils/

2005-08-08  H.J. Lu  <[hidden email]>

        PR binutils/1179
        * objdump.c (disassemble_bytes): Don't adjust
        adjust_section_vma.
        (dump_bfd): Disallow adjust_section_vma for non-relocatable
        files.

--- binutils/bfd/dwarf2.c.adjust 2005-07-10 10:11:11.000000000 -0700
+++ binutils/bfd/dwarf2.c 2005-08-08 08:46:20.000000000 -0700
@@ -101,24 +101,36 @@ struct dwarf2_debug
   /* Length of the loaded .debug_abbrev section.  */
   unsigned long dwarf_abbrev_size;
 
+  /* Address of the loaded .debug_abbrev section.  */
+  bfd_vma dwarf_abbrev_vma;
+
   /* Buffer for decode_line_info.  */
   bfd_byte *dwarf_line_buffer;
 
   /* Length of the loaded .debug_line section.  */
   unsigned long dwarf_line_size;
 
+  /* Address of the loaded .debug_line section.  */
+  bfd_vma dwarf_line_vma;
+
   /* Pointer to the .debug_str section loaded into memory.  */
   bfd_byte *dwarf_str_buffer;
 
   /* Length of the loaded .debug_str section.  */
   unsigned long dwarf_str_size;
 
+  /* Address of the loaded .debug_str section.  */
+  bfd_vma dwarf_str_vma;
+
   /* Pointer to the .debug_ranges section loaded into memory. */
   bfd_byte *dwarf_ranges_buffer;
 
   /* Length of the loaded .debug_ranges section. */
   unsigned long dwarf_ranges_size;
 
+  /* Address of the loaded .debug_ranges section.  */
+  bfd_vma dwarf_ranges_vma;
+
   /* If the most recent call to bfd_find_nearest_line was given an
      address in an inlined function, preserve a pointer into the
      calling chain for subsequent calls to bfd_find_inliner_info to
@@ -319,6 +331,7 @@ read_indirect_string (struct comp_unit*
 
       sz = msec->rawsize ? msec->rawsize : msec->size;
       stash->dwarf_str_size = sz;
+      stash->dwarf_str_vma = msec->vma;
       stash->dwarf_str_buffer = bfd_alloc (abfd, sz);
       if (! stash->dwarf_str_buffer)
  return NULL;
@@ -328,6 +341,8 @@ read_indirect_string (struct comp_unit*
  return NULL;
     }
 
+  offset -= stash->dwarf_str_vma;
+
   if (offset >= stash->dwarf_str_size)
     {
       (*_bfd_error_handler) (_("Dwarf Error: DW_FORM_strp offset (%lu) greater than or equal to .debug_str size (%lu)."),
@@ -429,6 +444,7 @@ read_abbrevs (bfd *abfd, bfd_uint64_t of
  }
 
       stash->dwarf_abbrev_size = msec->size;
+      stash->dwarf_abbrev_vma = msec->vma;
       stash->dwarf_abbrev_buffer
  = bfd_simple_get_relocated_section_contents (abfd, msec, NULL,
      stash->syms);
@@ -436,6 +452,8 @@ read_abbrevs (bfd *abfd, bfd_uint64_t of
   return 0;
     }
 
+  offset -= stash->dwarf_abbrev_vma;
+
   if (offset >= stash->dwarf_abbrev_size)
     {
       (*_bfd_error_handler) (_("Dwarf Error: Abbrev offset (%lu) greater than or equal to .debug_abbrev size (%lu)."),
@@ -951,6 +969,7 @@ decode_line_info (struct comp_unit *unit
  }
 
       stash->dwarf_line_size = msec->size;
+      stash->dwarf_line_vma = msec->vma;
       stash->dwarf_line_buffer
  = bfd_simple_get_relocated_section_contents (abfd, msec, NULL,
      stash->syms);
@@ -960,7 +979,8 @@ decode_line_info (struct comp_unit *unit
 
   /* It is possible to get a bad value for the line_offset.  Validate
      it here so that we won't get a segfault below.  */
-  if (unit->line_offset >= stash->dwarf_line_size)
+  if ((unit->line_offset - stash->dwarf_line_vma)
+      >= stash->dwarf_line_size)
     {
       (*_bfd_error_handler) (_("Dwarf Error: Line offset (%lu) greater than or equal to .debug_line size (%lu)."),
      unit->line_offset, stash->dwarf_line_size);
@@ -983,7 +1003,8 @@ decode_line_info (struct comp_unit *unit
   table->last_line = NULL;
   table->lcl_head = NULL;
 
-  line_ptr = stash->dwarf_line_buffer + unit->line_offset;
+  line_ptr = stash->dwarf_line_buffer + (unit->line_offset
+ - stash->dwarf_line_vma);
 
   /* Read in the prologue.  */
   lh.total_length = read_4_bytes (abfd, line_ptr);
@@ -1386,6 +1407,7 @@ read_debug_ranges (struct comp_unit *uni
  }
 
       stash->dwarf_ranges_size = msec->size;
+      stash->dwarf_ranges_vma = msec->vma;
       stash->dwarf_ranges_buffer
  = bfd_simple_get_relocated_section_contents (abfd, msec, NULL,
      stash->syms);
@@ -1599,7 +1621,8 @@ read_rangelist (struct comp_unit *unit,
       if (! read_debug_ranges (unit))
  return;
     }
-  ranges_ptr = unit->stash->dwarf_ranges_buffer + offset;
+  ranges_ptr = (unit->stash->dwarf_ranges_buffer
+ + (offset - unit->stash->dwarf_ranges_vma));
     
   for (;;)
     {
--- binutils/binutils/objdump.c.adjust 2005-07-07 19:45:03.000000000 -0700
+++ binutils/binutils/objdump.c 2005-08-08 08:55:49.000000000 -0700
@@ -1355,10 +1355,7 @@ disassemble_bytes (struct disassemble_in
   done_dot = FALSE;
 
   if (with_line_numbers || with_source_code)
-    /* The line number tables will refer to unadjusted
-       section VMAs, so we must undo any VMA modifications
-       when calling show_line.  */
-    show_line (aux->abfd, section, addr_offset - adjust_section_vma);
+    show_line (aux->abfd, section, addr_offset);
 
   if (! prefix_addresses)
     {
@@ -2616,7 +2613,17 @@ dump_bfd (bfd *abfd)
      the BFD information is a hack.  However, we must do it, or
      bfd_find_nearest_line will not do the right thing.  */
   if (adjust_section_vma != 0)
-    bfd_map_over_sections (abfd, adjust_addresses, NULL);
+    {
+      if (abfd->flags & HAS_RELOC)
+ bfd_map_over_sections (abfd, adjust_addresses, NULL);
+      else if (with_line_numbers || with_source_code)
+ {
+  non_fatal (_("%s: not a relocatable file. Can't adjust section address"),
+     bfd_get_filename (abfd));
+  exit_status = 1;
+  return;
+ }
+    }
 
   if (! dump_debugging_tags)
     printf (_("\n%s:     file format %s\n"), bfd_get_filename (abfd),
Reply | Threaded
Open this post in threaded view
|

Re: PATCH: binutils/1179: -adjust-vma with negative number causes objdump -S to fail

H.J. Lu-27
On Mon, Aug 08, 2005 at 09:03:37AM -0700, H. J. Lu wrote:
> I didn't try to support -adjust-vma for non-relocatable files. Without
> relocation information, it is tricky to get the debug info right. I
> am not sure if it is worth the effort. We also have to adjust it for
> debug info. This patch works on ELF/i386.
>
>

Here is an updated patch. We shouldn't adjust vma for debugging
sections since they aren't loaded at all. We don't adjust lma for
DSO and executable so that we can use

sec->vma - (sec->vma - sec->lma) = sec->lma

to find the load bias.


H.J.
----
bfd/

2005-08-08  H.J. Lu  <[hidden email]>

        PR binutils/1179
        * dwarf2.c (_bfd_dwarf2_find_nearest_line): Use section lma
        instead of vma.
        (_bfd_dwarf2_find_line): Likewise.

binutils/

2005-08-08  H.J. Lu  <[hidden email]>

        PR binutils/1179
        * objdump.c (disassemble_bytes): Don't adjust
        adjust_section_vma.
        (adjust_addresses): Don't adjust vma for debugging section.
        Adjust lma only for relocatable files.
        (dump_bfd): Tell adjust_addresses if it is a relocatable file.

--- binutils/bfd/dwarf2.c.adjust 2005-07-10 10:14:06.000000000 -0700
+++ binutils/bfd/dwarf2.c 2005-08-08 11:00:13.252485417 -0700
@@ -2175,9 +2175,9 @@ _bfd_dwarf2_find_nearest_line (bfd *abfd
   stash = *pinfo;
   addr = offset;
   if (section->output_section)
-    addr += section->output_section->vma + section->output_offset;
+    addr += section->output_section->lma + section->output_offset;
   else
-    addr += section->vma;
+    addr += section->lma;
   *filename_ptr = NULL;
   *functionname_ptr = NULL;
   *linenumber_ptr = 0;
@@ -2384,9 +2384,9 @@ _bfd_dwarf2_find_line (bfd *abfd,
 
   addr = symbol->value;
   if (section->output_section)
-    addr += section->output_section->vma + section->output_offset;
+    addr += section->output_section->lma + section->output_offset;
   else
-    addr += section->vma;
+    addr += section->lma;
 
   *filename_ptr = NULL;
   stash = *pinfo;
--- binutils/binutils/objdump.c.adjust 2005-07-08 08:42:24.000000000 -0700
+++ binutils/binutils/objdump.c 2005-08-08 11:02:54.401983613 -0700
@@ -1355,10 +1355,7 @@ disassemble_bytes (struct disassemble_in
   done_dot = FALSE;
 
   if (with_line_numbers || with_source_code)
-    /* The line number tables will refer to unadjusted
-       section VMAs, so we must undo any VMA modifications
-       when calling show_line.  */
-    show_line (aux->abfd, section, addr_offset - adjust_section_vma);
+    show_line (aux->abfd, section, addr_offset);
 
   if (! prefix_addresses)
     {
@@ -2601,10 +2598,15 @@ add_include_path (const char *path)
 static void
 adjust_addresses (bfd *abfd ATTRIBUTE_UNUSED,
   asection *section,
-  void *dummy ATTRIBUTE_UNUSED)
+  void *arg)
 {
-  section->vma += adjust_section_vma;
-  section->lma += adjust_section_vma;
+  if ((section->flags & SEC_DEBUGGING) == 0)
+    {
+      bfd_boolean *has_reloc_p = (bfd_boolean *) arg;
+      section->vma += adjust_section_vma;
+      if (*has_reloc_p)
+ section->lma += adjust_section_vma;
+    }
 }
 
 /* Dump selected contents of ABFD.  */
@@ -2616,7 +2618,10 @@ dump_bfd (bfd *abfd)
      the BFD information is a hack.  However, we must do it, or
      bfd_find_nearest_line will not do the right thing.  */
   if (adjust_section_vma != 0)
-    bfd_map_over_sections (abfd, adjust_addresses, NULL);
+    {
+      bfd_boolean has_reloc = (abfd->flags & HAS_RELOC);
+      bfd_map_over_sections (abfd, adjust_addresses, &has_reloc);
+    }
 
   if (! dump_debugging_tags)
     printf (_("\n%s:     file format %s\n"), bfd_get_filename (abfd),
Reply | Threaded
Open this post in threaded view
|

Re: PATCH: binutils/1179: -adjust-vma with negative number causes objdump -S to fail

Nick Clifton
Hi H. J.

> bfd/
> 2005-08-08  H.J. Lu  <[hidden email]>
>
> PR binutils/1179
> * dwarf2.c (_bfd_dwarf2_find_nearest_line): Use section lma
> instead of vma.
> (_bfd_dwarf2_find_line): Likewise.
>
> binutils/
> 2005-08-08  H.J. Lu  <[hidden email]>
>
> PR binutils/1179
> * objdump.c (disassemble_bytes): Don't adjust
> adjust_section_vma.
> (adjust_addresses): Don't adjust vma for debugging section.
> Adjust lma only for relocatable files.
> (dump_bfd): Tell adjust_addresses if it is a relocatable file.

Approved - please apply.

Cheers
   Nick