Sign-extend start and stop address inputs to objdump
[deliverable/binutils-gdb.git] / binutils / objdump.c
index 644638c321e4dec358c533efbb428ce9f701cc1e..05d503e5148512db7a8f6ba6e8539db3828f6d08 100644 (file)
@@ -3749,11 +3749,25 @@ adjust_addresses (bfd *abfd ATTRIBUTE_UNUSED,
     }
 }
 
+/* Return the sign-extended form of an ARCH_SIZE sized VMA.  */
+
+static bfd_vma
+sign_extend_address (bfd *abfd ATTRIBUTE_UNUSED,
+                    bfd_vma vma,
+                    unsigned arch_size)
+{
+  bfd_vma mask;
+  mask = (bfd_vma) 1 << (arch_size - 1);
+  return (((vma & ((mask << 1) - 1)) ^ mask) - mask);
+}
+
 /* Dump selected contents of ABFD.  */
 
 static void
 dump_bfd (bfd *abfd, bfd_boolean is_mainfile)
 {
+  const struct elf_backend_data * bed;
+
   if (bfd_big_endian (abfd))
     byte_get = byte_get_big_endian;
   else if (bfd_little_endian (abfd))
@@ -3784,6 +3798,18 @@ dump_bfd (bfd *abfd, bfd_boolean is_mainfile)
        }
     }
 
+  /* Adjust user-specified start and stop limits for targets that use
+     signed addresses.  */
+  if (bfd_get_flavour (abfd) == bfd_target_elf_flavour
+      && (bed = get_elf_backend_data (abfd)) != NULL
+      && bed->sign_extend_vma)
+    {
+      start_address = sign_extend_address (abfd, start_address,
+                                          bed->s->arch_size);
+      stop_address = sign_extend_address (abfd, stop_address,
+                                         bed->s->arch_size);
+    }
+
   /* If we are adjusting section VMA's, change them all now.  Changing
      the BFD information is a hack.  However, we must do it, or
      bfd_find_nearest_line will not do the right thing.  */
This page took 0.027399 seconds and 4 git commands to generate.