Skip to content

Instantly share code, notes, and snippets.

@mansr
Created November 17, 2015 15:36
Show Gist options
  • Save mansr/7fb23e2cfb169e786050 to your computer and use it in GitHub Desktop.
Save mansr/7fb23e2cfb169e786050 to your computer and use it in GitHub Desktop.
--- binutils/objdump.c.orig 2015-07-21 09:20:58.000000000 +0100
+++ binutils/objdump.c 2015-11-17 14:47:35.047522396 +0000
@@ -104,8 +104,8 @@
static bfd_boolean formats_info; /* -i */
static int wide_output; /* -w */
static int insn_width; /* --insn-width */
-static bfd_vma start_address = (bfd_vma) -1; /* --start-address */
-static bfd_vma stop_address = (bfd_vma) -1; /* --stop-address */
+static bfd_vma arg_start_address = (bfd_vma) -1; /* --start-address */
+static bfd_vma arg_stop_address = (bfd_vma) -1; /* --stop-address */
static int dump_debugging; /* --debugging */
static int dump_debugging_tags; /* --debugging-tags */
static int suppress_bfd_header;
@@ -184,6 +184,10 @@
static bfd_boolean is_relocatable = FALSE;
+static bfd_vma sign_adjust = 0;
+static bfd_vma start_address = (bfd_vma) -1;
+static bfd_vma stop_address = (bfd_vma) -1;
+
/* Handlers for -P/--private. */
static const struct objdump_private_desc * const objdump_private_vectors[] =
{
@@ -357,6 +361,12 @@
exit_status = 1;
}
+static bfd_vma
+adjust_sign (bfd_vma addr)
+{
+ return addr = ((addr & ((sign_adjust << 1) - 1)) ^ sign_adjust) - sign_adjust;
+}
+
/* Returns TRUE if the specified section should be dumped. */
static bfd_boolean
@@ -1885,8 +1895,6 @@
static void
disassemble_section (bfd *abfd, asection *section, void *inf)
{
- const struct elf_backend_data * bed;
- bfd_vma sign_adjust = 0;
struct disassemble_info * pinfo = (struct disassemble_info *) inf;
struct objdump_disasm_info * paux;
unsigned int opb = pinfo->octets_per_byte;
@@ -2003,14 +2011,6 @@
&place);
paux->require_sec = FALSE;
- /* PR 9774: If the target used signed addresses then we must make
- sure that we sign extend the value that we calculate for 'addr'
- in the loop below. */
- if (bfd_get_flavour (abfd) == bfd_target_elf_flavour
- && (bed = get_elf_backend_data (abfd)) != NULL
- && bed->sign_extend_vma)
- sign_adjust = (bfd_vma) 1 << (bed->s->arch_size - 1);
-
/* Disassemble a block of instructions up to the address associated with
the symbol we have just found. Then print the symbol and find the
next symbol on. Repeat until we have disassembled the entire section
@@ -2022,8 +2022,7 @@
unsigned long nextstop_offset;
bfd_boolean insns;
- addr = section->vma + addr_offset;
- addr = ((addr & ((sign_adjust << 1) - 1)) ^ sign_adjust) - sign_adjust;
+ addr = adjust_sign (section->vma + addr_offset);
if (sym != NULL && bfd_asymbol_value (sym) <= addr)
{
@@ -3442,6 +3441,7 @@
display_file (char *filename, char *target)
{
bfd *file;
+ const struct elf_backend_data * bed;
if (get_file_size (filename) < 1)
{
@@ -3456,6 +3456,19 @@
return;
}
+ /* PR 9774: If the target used signed addresses then we must make
+ sure that we sign extend the value that we calculate for 'addr'
+ in the loop below. */
+ if (bfd_get_flavour (file) == bfd_target_elf_flavour
+ && (bed = get_elf_backend_data (file)) != NULL
+ && bed->sign_extend_vma)
+ sign_adjust = (bfd_vma) 1 << (bed->s->arch_size - 1);
+ else
+ sign_adjust = 0;
+
+ start_address = adjust_sign (arg_start_address);
+ stop_address = adjust_sign (arg_stop_address);
+
display_any_bfd (file, 0);
bfd_close (file);
@@ -3542,13 +3555,13 @@
adjust_section_vma = parse_vma (optarg, "--adjust-vma");
break;
case OPTION_START_ADDRESS:
- start_address = parse_vma (optarg, "--start-address");
- if ((stop_address != (bfd_vma) -1) && stop_address <= start_address)
+ arg_start_address = parse_vma (optarg, "--start-address");
+ if ((arg_stop_address != (bfd_vma) -1) && arg_stop_address <= arg_start_address)
fatal (_("error: the start address should be before the end address"));
break;
case OPTION_STOP_ADDRESS:
- stop_address = parse_vma (optarg, "--stop-address");
- if ((start_address != (bfd_vma) -1) && stop_address <= start_address)
+ arg_stop_address = parse_vma (optarg, "--stop-address");
+ if ((arg_start_address != (bfd_vma) -1) && arg_stop_address <= arg_start_address)
fatal (_("error: the stop address should be after the start address"));
break;
case OPTION_PREFIX:
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment