diff -Nrup a/binutils/doc/binutils.texi b/binutils/doc/binutils.texi --- a/binutils/doc/binutils.texi 2013-02-27 13:28:03.000000000 -0700 +++ b/binutils/doc/binutils.texi 2015-06-23 09:44:23.938269022 -0600 @@ -1957,6 +1957,15 @@ expected to contain instructions. Like @option{-d}, but disassemble the contents of all sections, not just those expected to contain instructions. +This option also has a subtle effect on the disassembly of +instructions in code sections. When option @option{-d} is in effect +objdump will assume that any symbols present in a code section occur +on the boundary between instructions and it will refuse to disassemble +across such a boundary. When option @option{-D} is in effect however +this assumption is supressed. This means that it is possible for the +output of @option{-d} and @option{-D} to differ if, for example, data +is stored in code sections. + If the target is an ARM architecture this switch also has the effect of forcing the disassembler to decode pieces of data found in code sections as if they were instructions. diff -Nrup a/binutils/objdump.c b/binutils/objdump.c --- a/binutils/objdump.c 2015-06-23 07:38:21.000000000 -0600 +++ b/binutils/objdump.c 2015-06-23 09:44:23.939269001 -0600 @@ -1667,7 +1667,18 @@ disassemble_bytes (struct disassemble_in } } + if (! disassemble_all + && (section->flags & (SEC_CODE | SEC_HAS_CONTENTS)) + == (SEC_CODE | SEC_HAS_CONTENTS)) + /* Set a stop_vma so that the disassembler will not read + beyond the next symbol. We assume that symbols appear on + the boundaries between instructions. We only do this when + disassembling code of course, and when -D is in effect. */ + inf->stop_vma = section->vma + stop_offset; + octets = (*disassemble_fn) (section->vma + addr_offset, inf); + + inf->stop_vma = 0; inf->fprintf_func = (fprintf_ftype) fprintf; inf->stream = stdout; if (insn_width == 0 && inf->bytes_per_line != 0) @@ -1893,7 +1904,7 @@ disassemble_section (bfd *abfd, asection arelent ** rel_pp = NULL; arelent ** rel_ppstart = NULL; arelent ** rel_ppend; - unsigned long stop_offset; + bfd_vma stop_offset; asymbol * sym = NULL; long place = 0; long rel_count; @@ -2015,7 +2026,7 @@ disassemble_section (bfd *abfd, asection { bfd_vma addr; asymbol *nextsym; - unsigned long nextstop_offset; + bfd_vma nextstop_offset; bfd_boolean insns; addr = section->vma + addr_offset; @@ -2703,9 +2714,9 @@ dump_section (bfd *abfd, asection *secti { bfd_byte *data = 0; bfd_size_type datasize; - bfd_size_type addr_offset; - bfd_size_type start_offset; - bfd_size_type stop_offset; + bfd_vma addr_offset; + bfd_vma start_offset; + bfd_vma stop_offset; unsigned int opb = bfd_octets_per_byte (abfd); /* Bytes per line. */ const int onaline = 16; diff -Nrup a/gas/testsuite/gas/arm/backslash-at.d b/gas/testsuite/gas/arm/backslash-at.d --- a/gas/testsuite/gas/arm/backslash-at.d 2013-02-27 13:28:03.000000000 -0700 +++ b/gas/testsuite/gas/arm/backslash-at.d 2015-06-23 09:51:10.167721356 -0600 @@ -5,13 +5,13 @@ Disassembly of section .text: 0+000 <.*>.*615c.* -0+002 e3a00000 mov r0, #0 -0+006 e3a00000 mov r0, #0 -0+00a e3a00000 mov r0, #0 -0+00e e3a00001 mov r0, #1 -0+012 e3a00001 mov r0, #1 -0+016 e3a00001 mov r0, #1 -0+01a e3a00002 mov r0, #2 -0+01e e3a00002 mov r0, #2 -0+022 e3a00002 mov r0, #2 +0+004 e3a00000 mov r0, #0 +0+008 e3a00000 mov r0, #0 +0+00c e3a00000 mov r0, #0 +0+010 e3a00001 mov r0, #1 +0+014 e3a00001 mov r0, #1 +0+018 e3a00001 mov r0, #1 +0+01c e3a00002 mov r0, #2 +0+020 e3a00002 mov r0, #2 +0+024 e3a00002 mov r0, #2 #... Binary files a/gas/testsuite/gas/arm/.backslash-at.d.rej.swp and b/gas/testsuite/gas/arm/.backslash-at.d.rej.swp differ diff -Nrup a/gas/testsuite/gas/arm/backslash-at.s b/gas/testsuite/gas/arm/backslash-at.s --- a/gas/testsuite/gas/arm/backslash-at.s 2013-02-27 13:28:03.000000000 -0700 +++ b/gas/testsuite/gas/arm/backslash-at.s 2015-06-23 09:44:23.939269001 -0600 @@ -6,9 +6,10 @@ mov r0, #\@ @comment .endm -.byte '\\ -.byte '\a - + .byte '\\ + .byte '\a + .byte 0 + .byte 0 foo: bar bar diff -Nrup a/gas/testsuite/gas/i386/ilp32/x86-64-opcode-inval.d b/gas/testsuite/gas/i386/ilp32/x86-64-opcode-inval.d --- a/gas/testsuite/gas/i386/ilp32/x86-64-opcode-inval.d 2013-02-27 13:28:03.000000000 -0700 +++ b/gas/testsuite/gas/i386/ilp32/x86-64-opcode-inval.d 2015-06-23 09:44:23.940268980 -0600 @@ -12,26 +12,26 @@ Disassembly of section .text: 0+1 : [ ]*[a-f0-9]+: d5 \(bad\) -[ ]*[a-f0-9]+: 0a d5 or %ch,%dl +[ ]*[a-f0-9]+: 0a .byte 0xa 0+3 : [ ]*[a-f0-9]+: d5 \(bad\) -[ ]*[a-f0-9]+: 02 d4 add %ah,%dl +[ ]*[a-f0-9]+: 02 .byte 0x2 0+5 : [ ]*[a-f0-9]+: d4 \(bad\) -[ ]*[a-f0-9]+: 0a d4 or %ah,%dl +[ ]*[a-f0-9]+: 0a .byte 0xa 0+7 : [ ]*[a-f0-9]+: d4 \(bad\) -[ ]*[a-f0-9]+: 02 3f add \(%rdi\),%bh +[ ]*[a-f0-9]+: 02 .byte 0x2 0+9 : [ ]*[a-f0-9]+: 3f \(bad\) 0+a : -[ ]*[a-f0-9]+: 62 \(bad\) -[ ]*[a-f0-9]+: 10 27 adc %ah,\(%rdi\) +[ ]*[a-f0-9]+: 62 .byte 0x62 +[ ]*[a-f0-9]+: 10 .byte 0x10 0+c : [ ]*[a-f0-9]+: 27 \(bad\) diff -Nrup a/gas/testsuite/gas/i386/ilp32/x86-64-opcode-inval-intel.d b/gas/testsuite/gas/i386/ilp32/x86-64-opcode-inval-intel.d --- a/gas/testsuite/gas/i386/ilp32/x86-64-opcode-inval-intel.d 2013-02-27 13:28:03.000000000 -0700 +++ b/gas/testsuite/gas/i386/ilp32/x86-64-opcode-inval-intel.d 2015-06-23 09:44:23.939269001 -0600 @@ -12,26 +12,26 @@ Disassembly of section .text: 0+1 : [ ]*[a-f0-9]+: d5 \(bad\) -[ ]*[a-f0-9]+: 0a d5 or dl,ch +[ ]*[a-f0-9]+: 0a .byte 0xa 0+3 : [ ]*[a-f0-9]+: d5 \(bad\) -[ ]*[a-f0-9]+: 02 d4 add dl,ah +[ ]*[a-f0-9]+: 02 .byte 0x2 0+5 : [ ]*[a-f0-9]+: d4 \(bad\) -[ ]*[a-f0-9]+: 0a d4 or dl,ah +[ ]*[a-f0-9]+: 0a .byte 0xa 0+7 : [ ]*[a-f0-9]+: d4 \(bad\) -[ ]*[a-f0-9]+: 02 3f add bh,BYTE PTR \[rdi\] +[ ]*[a-f0-9]+: 02 .byte 0x2 0+9 : [ ]*[a-f0-9]+: 3f \(bad\) 0+a : -[ ]*[a-f0-9]+: 62 \(bad\) -[ ]*[a-f0-9]+: 10 27 adc BYTE PTR \[rdi\],ah +[ ]*[a-f0-9]+: 62 .byte 0x62 +[ ]*[a-f0-9]+: 10 .byte 0x10 0+c : [ ]*[a-f0-9]+: 27 \(bad\) diff -Nrup a/gas/testsuite/gas/i386/x86-64-opcode-inval.d b/gas/testsuite/gas/i386/x86-64-opcode-inval.d --- a/gas/testsuite/gas/i386/x86-64-opcode-inval.d 2013-02-27 13:28:03.000000000 -0700 +++ b/gas/testsuite/gas/i386/x86-64-opcode-inval.d 2015-06-23 09:44:23.940268980 -0600 @@ -11,26 +11,26 @@ Disassembly of section .text: 0+1 : [ ]*[a-f0-9]+: d5 \(bad\) -[ ]*[a-f0-9]+: 0a d5 or %ch,%dl +[ ]*[a-f0-9]+: 0a .byte 0xa 0+3 : [ ]*[a-f0-9]+: d5 \(bad\) -[ ]*[a-f0-9]+: 02 d4 add %ah,%dl +[ ]*[a-f0-9]+: 02 .byte 0x2 0+5 : [ ]*[a-f0-9]+: d4 \(bad\) -[ ]*[a-f0-9]+: 0a d4 or %ah,%dl +[ ]*[a-f0-9]+: 0a .byte 0xa 0+7 : [ ]*[a-f0-9]+: d4 \(bad\) -[ ]*[a-f0-9]+: 02 3f add \(%rdi\),%bh +[ ]*[a-f0-9]+: 02 .byte 0x2 0+9 : [ ]*[a-f0-9]+: 3f \(bad\) 0+a : -[ ]*[a-f0-9]+: 62 \(bad\) -[ ]*[a-f0-9]+: 10 27 adc %ah,\(%rdi\) +[ ]*[a-f0-9]+: 62 .byte 0x62 +[ ]*[a-f0-9]+: 10 .byte 0x10 0+c : [ ]*[a-f0-9]+: 27 \(bad\) diff -Nrup a/gas/testsuite/gas/i386/x86-64-opcode-inval-intel.d b/gas/testsuite/gas/i386/x86-64-opcode-inval-intel.d --- a/gas/testsuite/gas/i386/x86-64-opcode-inval-intel.d 2013-02-27 13:28:03.000000000 -0700 +++ b/gas/testsuite/gas/i386/x86-64-opcode-inval-intel.d 2015-06-23 09:44:23.940268980 -0600 @@ -12,26 +12,26 @@ Disassembly of section .text: 0+1 : [ ]*[a-f0-9]+: d5 \(bad\) -[ ]*[a-f0-9]+: 0a d5 or dl,ch +[ ]*[a-f0-9]+: 0a .byte 0xa 0+3 : [ ]*[a-f0-9]+: d5 \(bad\) -[ ]*[a-f0-9]+: 02 d4 add dl,ah +[ ]*[a-f0-9]+: 02 .byte 0x2 0+5 : [ ]*[a-f0-9]+: d4 \(bad\) -[ ]*[a-f0-9]+: 0a d4 or dl,ah +[ ]*[a-f0-9]+: 0a .byte 0xa 0+7 : [ ]*[a-f0-9]+: d4 \(bad\) -[ ]*[a-f0-9]+: 02 3f add bh,BYTE PTR \[rdi\] +[ ]*[a-f0-9]+: 02 .byte 0x2 0+9 : [ ]*[a-f0-9]+: 3f \(bad\) 0+a : -[ ]*[a-f0-9]+: 62 \(bad\) -[ ]*[a-f0-9]+: 10 27 adc BYTE PTR \[rdi\],ah +[ ]*[a-f0-9]+: 62 .byte 0x62 +[ ]*[a-f0-9]+: 10 .byte 0x10 0+c : [ ]*[a-f0-9]+: 27 \(bad\) diff -Nrup a/include/dis-asm.h b/include/dis-asm.h --- a/include/dis-asm.h 2013-02-27 13:28:03.000000000 -0700 +++ b/include/dis-asm.h 2015-06-23 09:44:23.940268980 -0600 @@ -213,6 +213,14 @@ typedef struct disassemble_info /* Command line options specific to the target disassembler. */ char * disassembler_options; + /* If non-zero then try not disassemble beyond this address, even if + there are values left in the buffer. This address is the address + of the nearest symbol forwards from the start of the disassembly, + and it is assumed that it lies on the boundary between instructions. + If an instruction spans this address then this is an error in the + file being disassembled. */ + bfd_vma stop_vma; + } disassemble_info; diff -Nrup a/opcodes/dis-buf.c b/opcodes/dis-buf.c --- a/opcodes/dis-buf.c 2013-02-27 13:28:03.000000000 -0700 +++ b/opcodes/dis-buf.c 2015-06-23 09:44:23.941268959 -0600 @@ -39,7 +39,9 @@ buffer_read_memory (bfd_vma memaddr, if (memaddr < info->buffer_vma || memaddr - info->buffer_vma > max_addr_offset - || memaddr - info->buffer_vma + end_addr_offset > max_addr_offset) + || memaddr - info->buffer_vma + end_addr_offset > max_addr_offset + || (info->stop_vma && (memaddr >= info->stop_vma + || memaddr + end_addr_offset > info->stop_vma))) /* Out of bounds. Use EIO because GDB uses it. */ return EIO; memcpy (myaddr, info->buffer + octets, length); diff -Nrup a/opcodes/mcore-dis.c b/opcodes/mcore-dis.c --- a/opcodes/mcore-dis.c 2013-02-27 13:28:03.000000000 -0700 +++ b/opcodes/mcore-dis.c 2015-06-23 09:44:23.941268959 -0600 @@ -89,9 +89,8 @@ static const char *crname[] = { static const unsigned isiz[] = { 2, 0, 1, 0 }; int -print_insn_mcore (memaddr, info) - bfd_vma memaddr; - struct disassemble_info *info; +print_insn_mcore (bfd_vma memaddr, + struct disassemble_info *info) { unsigned char ibytes[4]; fprintf_ftype print_func = info->fprintf_func; @@ -234,6 +233,9 @@ print_insn_mcore (memaddr, info) val = (memaddr + 2 + ((inst & 0xFF) << 2)) & 0xFFFFFFFC; + /* We are not reading an instruction, so allow + reads to extend beyond the next symbol. */ + info->stop_vma = 0; status = info->read_memory_func (val, ibytes, 4, info); if (status != 0) { @@ -264,6 +266,9 @@ print_insn_mcore (memaddr, info) val = (memaddr + 2 + ((inst & 0xFF) << 2)) & 0xFFFFFFFC; + /* We are not reading an instruction, so allow + reads to extend beyond the next symbol. */ + info->stop_vma = 0; status = info->read_memory_func (val, ibytes, 4, info); if (status != 0) { diff -Nrup a/opcodes/sh-dis.c b/opcodes/sh-dis.c --- a/opcodes/sh-dis.c 2013-02-27 13:28:03.000000000 -0700 +++ b/opcodes/sh-dis.c 2015-06-23 09:44:23.941268959 -0600 @@ -906,6 +906,8 @@ print_insn_sh (bfd_vma memaddr, struct d size = 2; else size = 4; + /* Not reading an instruction - disable stop_vma. */ + info->stop_vma = 0; status = info->read_memory_func (disp_pc_addr, bytes, size, info); if (status == 0) { diff -Nrup a/opcodes/tic6x-dis.c b/opcodes/tic6x-dis.c --- a/opcodes/tic6x-dis.c 2013-02-27 13:28:03.000000000 -0700 +++ b/opcodes/tic6x-dis.c 2015-06-23 09:44:23.941268959 -0600 @@ -178,6 +178,9 @@ print_insn_tic6x (bfd_vma addr, struct d fp_offset = addr & 0x1f; fp_addr = addr - fp_offset; + /* Read in a block of instructions. Since there might be a + symbol in the middle of this block, disable stop_vma. */ + info->stop_vma = 0; status = info->read_memory_func (fp_addr, fp, 32, info); if (status) { diff -Nrup a/opcodes/vax-dis.c b/opcodes/vax-dis.c --- a/opcodes/vax-dis.c 2013-02-27 13:28:03.000000000 -0700 +++ b/opcodes/vax-dis.c 2015-06-23 09:44:23.941268959 -0600 @@ -403,7 +403,8 @@ print_insn_vax (bfd_vma memaddr, disasse argp = NULL; /* Check if the info buffer has more than one byte left since the last opcode might be a single byte with no argument data. */ - if (info->buffer_length - (memaddr - info->buffer_vma) > 1) + if (info->buffer_length - (memaddr - info->buffer_vma) > 1 + && (info->stop_vma == 0 || memaddr < (info->stop_vma - 1))) { FETCH_DATA (info, buffer + 2); }