From 771f27334601b9044d963fd1a69d3f67fe9bc6e1 Mon Sep 17 00:00:00 2001 From: bebbo Date: Mon, 20 Mar 2017 10:53:30 +0100 Subject: [PATCH] @B display correct symbols for .data/.bss refs. If a reloc is present it is used to lookup the correct symbol. --- binutils/configure | 2 +- binutils/configure.in | 2 +- binutils/objdump.c | 26 +++++++++++++++++++++++--- include/dis-asm.h | 7 +++++++ opcodes/m68k-dis.c | 28 ++++++++++++++++++++++------ 5 files changed, 54 insertions(+), 11 deletions(-) mode change 100755 => 100644 binutils/configure diff --git a/binutils/configure b/binutils/configure old mode 100755 new mode 100644 index 34e6d85..7489365 --- a/binutils/configure +++ b/binutils/configure @@ -9167,7 +9167,7 @@ do DLLTOOL_DEFS="$DLLTOOL_DEFS -DDLLTOOL_ARM" BUILD_WINDRES='$(WINDRES_PROG)$(EXEEXT)' ;; - arm*-* | xscale-* | strongarm-* | d10v-*) + arm*-* | xscale-* | strongarm-* | d10v-* | m68*-*-amiga*) OBJDUMP_DEFS="-DDISASSEMBLER_NEEDS_RELOCS" ;; i[3-6]86-*-pe* | i[3-6]86-*-cygwin* | i[3-6]86-*-mingw32** | i[3-6]86-*-netbsdpe*) diff --git a/binutils/configure.in b/binutils/configure.in index 965f468..7df40dd 100644 --- a/binutils/configure.in +++ b/binutils/configure.in @@ -245,7 +245,7 @@ changequote([,])dnl DLLTOOL_DEFS="$DLLTOOL_DEFS -DDLLTOOL_ARM" BUILD_WINDRES='$(WINDRES_PROG)$(EXEEXT)' ;; - arm*-* | xscale-* | strongarm-* | d10v-*) + arm*-* | xscale-* | strongarm-* | d10v-* | m68*-*-amiga*) OBJDUMP_DEFS="-DDISASSEMBLER_NEEDS_RELOCS" ;; changequote(,)dnl diff --git a/binutils/objdump.c b/binutils/objdump.c index 288bebb..f192357 100644 --- a/binutils/objdump.c +++ b/binutils/objdump.c @@ -1314,16 +1314,36 @@ disassemble_bytes (info, disassemble_fn, insns, data, info->bytes_per_line = 0; info->bytes_per_chunk = 0; +#ifdef DISASSEMBLER_NEEDS_RELOCS + /* SBF: workaround for the issue below: + * move relppp until current insn is reached + * and put the relp pointer into the info structure. + * Now the implementation may judge by itself if the flag is correct. + * The pointer is also used to display the correct symbol name. + * For now only used in m68k-ds.c + * */ + while ((*relppp) < relppend + && (**relppp)->address < (bfd_vma)addr_offset) + ++(*relppp); + + if (*relppp < relppend) + info->relp = **relppp; + else +#endif + info->relp = 0; + #ifdef DISASSEMBLER_NEEDS_RELOCS /* FIXME: This is wrong. It tests the number of octets - in the last instruction, not the current one. */ + in the last instruction, not the current one. + SBF: read above. */ + if (*relppp < relppend && (**relppp)->address >= addr_offset && (**relppp)->address <= addr_offset + octets / opb) - info->flags = INSN_HAS_RELOC; + info->flags = INSN_HAS_RELOC; else #endif - info->flags = 0; + info->flags = 0; octets = (*disassemble_fn) (section->vma + addr_offset, info); info->fprintf_func = (fprintf_ftype) fprintf; diff --git a/include/dis-asm.h b/include/dis-asm.h index 1676069..e600e21 100644 --- a/include/dis-asm.h +++ b/include/dis-asm.h @@ -98,6 +98,10 @@ typedef struct disassemble_info { The bottom 16 bits are for the internal use of the disassembler. */ unsigned long flags; #define INSN_HAS_RELOC 0x80000000 + + /* Used if DISASSEMBLER_NEEDS_RELOCS is defined. */ + arelent *relp; + PTR private_data; /* Function used to get bytes to disassemble. MEMADDR is the @@ -281,6 +285,9 @@ extern void perror_memory PARAMS ((int, bfd_vma, struct disassemble_info *)); extern void generic_print_address PARAMS ((bfd_vma, struct disassemble_info *)); +extern asection * generic_get_section_for_reloc +PARAMS((bfd_vma, struct disassemble_info *)); + /* Always true. */ extern int generic_symbol_at_address PARAMS ((bfd_vma, struct disassemble_info *)); diff --git a/opcodes/m68k-dis.c b/opcodes/m68k-dis.c index 87f6891..effbef7 100644 --- a/opcodes/m68k-dis.c +++ b/opcodes/m68k-dis.c @@ -823,13 +823,29 @@ print_insn_arg (d, buffer, p0, addr, info) switch (val & 7) { case 0: - val = NEXTWORD (p); - (*info->print_address_func) (val, info); - break; - case 1: - uval = NEXTULONG (p); - (*info->print_address_func) (uval, info); + uval = (val & 7) ? NEXTULONG(p) : (unsigned int) NEXTWORD(p); + + if (info->relp) + { + if (info->relp->address <= addr + (p - p0) + && info->relp->sym_ptr_ptr && *info->relp->sym_ptr_ptr) + { + /* Swap section with the correct one. */ + struct objdump_disasm_info *aux = + (struct objdump_disasm_info *) info->application_data; + asection * text = aux->sec; + aux->sec = bfd_get_section (*info->relp->sym_ptr_ptr); + (*info->print_address_func) (uval, info); + + /* restore section to .text */ + aux->sec = text; + } + else + (*info->fprintf_func) (info->stream, "%d", uval); + } + else + (*info->print_address_func) (uval, info); break; case 2: