* objdump.c: Remove unnecessary prototypes.

(disassemble_bytes): Add rel_offset parameter.  Simplify reloc skipping
	code, and print relocs when dump_dynamic_reloc_info.
	(disassemble_data): Read and handle dynamic relocs.  Correct reloc
	skip code.  Formatting.
	(dump_bfd): Don't dump dynamic relocs when disassembling.
This commit is contained in:
Alan Modra 2003-07-30 03:54:15 +00:00
parent 8a1cb15917
commit fd7bb956ee
2 changed files with 85 additions and 108 deletions

View file

@ -1,3 +1,12 @@
2003-07-30 Alan Modra <amodra@bigpond.net.au>
* objdump.c: Remove unnecessary prototypes.
(disassemble_bytes): Add rel_offset parameter. Simplify reloc skipping
code, and print relocs when dump_dynamic_reloc_info.
(disassemble_data): Read and handle dynamic relocs. Correct reloc
skip code. Formatting.
(dump_bfd): Don't dump dynamic relocs when disassembling.
2003-07-29 Ben Elliston <bje@wasabisystems.com> 2003-07-29 Ben Elliston <bje@wasabisystems.com>
* MAINTAINERS: Remove self as M88k maintainer. Future M88k * MAINTAINERS: Remove self as M88k maintainer. Future M88k

View file

@ -38,8 +38,7 @@
#ifdef NEED_DECLARATION_FPRINTF #ifdef NEED_DECLARATION_FPRINTF
/* This is needed by INIT_DISASSEMBLE_INFO. */ /* This is needed by INIT_DISASSEMBLE_INFO. */
extern int fprintf extern int fprintf (FILE *, const char *, ...);
(FILE *, const char *, ...);
#endif #endif
/* Exit status. */ /* Exit status. */
@ -119,76 +118,14 @@ static bfd_size_type stab_size;
static char *strtab; static char *strtab;
static bfd_size_type stabstr_size; static bfd_size_type stabstr_size;
/* Static declarations. */ /* Forward declarations. */
static void usage static void dump_data (bfd *);
(FILE *, int); static void dump_relocs (bfd *);
static void nonfatal static void dump_dynamic_relocs (bfd *);
(const char *); static void dump_reloc_set (bfd *, asection *, arelent **, long);
static void display_file static void dump_symbols (bfd *, bfd_boolean);
(char *, char *); static void dump_section_stabs (bfd *, char *, char *);
static void dump_section_header
(bfd *, asection *, void *);
static void dump_headers
(bfd *);
static void dump_data
(bfd *);
static void dump_relocs
(bfd *);
static void dump_dynamic_relocs
(bfd *);
static void dump_reloc_set
(bfd *, asection *, arelent **, long);
static void dump_symbols
(bfd *, bfd_boolean);
static void dump_bfd_header
(bfd *);
static void dump_bfd_private_header
(bfd *);
static void dump_bfd
(bfd *);
static void display_bfd
(bfd *);
static void objdump_print_value
(bfd_vma, struct disassemble_info *, bfd_boolean);
static void objdump_print_symname
(bfd *, struct disassemble_info *, asymbol *);
static asymbol *find_symbol_for_address
(bfd *, asection *, bfd_vma, bfd_boolean, long *);
static void objdump_print_addr_with_sym
(bfd *, asection *, asymbol *, bfd_vma,
struct disassemble_info *, bfd_boolean);
static void objdump_print_addr
(bfd_vma, struct disassemble_info *, bfd_boolean);
static void objdump_print_address
(bfd_vma, struct disassemble_info *);
static int objdump_symbol_at_address
(bfd_vma, struct disassemble_info *);
static void show_line
(bfd *, asection *, bfd_vma);
static void disassemble_bytes
(struct disassemble_info *, disassembler_ftype, bfd_boolean,
bfd_byte *, bfd_vma, bfd_vma, arelent ***, arelent **);
static void disassemble_data
(bfd *);
static asymbol ** slurp_symtab
(bfd *);
static asymbol ** slurp_dynamic_symtab
(bfd *);
static long remove_useless_symbols
(asymbol **, long);
static int compare_symbols
(const void *, const void *);
static int compare_relocs
(const void *, const void *);
static void dump_stabs
(bfd *);
static bfd_boolean read_section_stabs
(bfd *, const char *, const char *);
static void print_section_stabs
(bfd *, const char *, const char *);
static void dump_section_stabs
(bfd *, char *, char *);
static void static void
usage (FILE *stream, int status) usage (FILE *stream, int status)
@ -1161,6 +1098,7 @@ disassemble_bytes (struct disassemble_info * info,
bfd_byte * data, bfd_byte * data,
bfd_vma start_offset, bfd_vma start_offset,
bfd_vma stop_offset, bfd_vma stop_offset,
bfd_vma rel_offset,
arelent *** relppp, arelent *** relppp,
arelent ** relppend) arelent ** relppend)
{ {
@ -1284,8 +1222,9 @@ disassemble_bytes (struct disassemble_info * info,
/* FIXME: This is wrong. It tests the number of octets /* 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. */
if (*relppp < relppend if (*relppp < relppend
&& (**relppp)->address >= addr_offset && (**relppp)->address >= rel_offset + addr_offset
&& (**relppp)->address <= addr_offset + octets / opb) && ((**relppp)->address
< rel_offset + addr_offset + octets / opb))
info->flags = INSN_HAS_RELOC; info->flags = INSN_HAS_RELOC;
else else
#endif #endif
@ -1428,20 +1367,10 @@ disassemble_bytes (struct disassemble_info * info,
need_nl = TRUE; need_nl = TRUE;
} }
if ((section->flags & SEC_RELOC) != 0 while ((*relppp) < relppend
#ifndef DISASSEMBLER_NEEDS_RELOCS && (**relppp)->address < rel_offset + addr_offset + octets / opb)
&& dump_reloc_info
#endif
)
{ {
while ((*relppp) < relppend if (dump_reloc_info || dump_dynamic_reloc_info)
&& ((**relppp)->address >= (bfd_vma) addr_offset
&& (**relppp)->address < (bfd_vma) addr_offset + octets / opb))
#ifdef DISASSEMBLER_NEEDS_RELOCS
if (! dump_reloc_info)
++(*relppp);
else
#endif
{ {
arelent *q; arelent *q;
@ -1485,8 +1414,8 @@ disassemble_bytes (struct disassemble_info * info,
printf ("\n"); printf ("\n");
need_nl = FALSE; need_nl = FALSE;
++(*relppp);
} }
++(*relppp);
} }
if (need_nl) if (need_nl)
@ -1507,6 +1436,9 @@ disassemble_data (bfd *abfd)
struct objdump_disasm_info aux; struct objdump_disasm_info aux;
asection *section; asection *section;
unsigned int opb; unsigned int opb;
arelent **dynrelbuf = NULL;
long relcount = 0;
bfd_vma rel_offset;
print_files = NULL; print_files = NULL;
prev_functionname = NULL; prev_functionname = NULL;
@ -1576,6 +1508,25 @@ disassemble_data (bfd *abfd)
instead. */ instead. */
disasm_info.endian = BFD_ENDIAN_UNKNOWN; disasm_info.endian = BFD_ENDIAN_UNKNOWN;
if (dump_dynamic_reloc_info)
{
long relsize = bfd_get_dynamic_reloc_upper_bound (abfd);
if (relsize < 0)
bfd_fatal (bfd_get_filename (abfd));
if (relsize > 0)
{
dynrelbuf = (arelent **) xmalloc (relsize);
relcount = bfd_canonicalize_dynamic_reloc (abfd, dynrelbuf, dynsyms);
if (relcount < 0)
bfd_fatal (bfd_get_filename (abfd));
/* Sort the relocs by address. */
qsort (dynrelbuf, relcount, sizeof (arelent *), compare_relocs);
}
}
for (section = abfd->sections; for (section = abfd->sections;
section != (asection *) NULL; section != (asection *) NULL;
section = section->next) section = section->next)
@ -1589,8 +1540,8 @@ disassemble_data (bfd *abfd)
asymbol *sym = NULL; asymbol *sym = NULL;
long place = 0; long place = 0;
/* Sections that do not contain machine /* Sections that do not contain machine code are not normally
code are not normally disassembled. */ disassembled. */
if (! disassemble_all if (! disassemble_all
&& only == NULL && only == NULL
&& (section->flags & SEC_CODE) == 0) && (section->flags & SEC_CODE) == 0)
@ -1608,11 +1559,13 @@ disassemble_data (bfd *abfd)
continue; continue;
} }
if (dynrelbuf == NULL)
relcount = 0;
if ((section->flags & SEC_RELOC) != 0 if ((section->flags & SEC_RELOC) != 0
#ifndef DISASSEMBLER_NEEDS_RELOCS #ifndef DISASSEMBLER_NEEDS_RELOCS
&& dump_reloc_info && dump_reloc_info
#endif #endif
) && dynrelbuf == NULL)
{ {
long relsize; long relsize;
@ -1622,8 +1575,6 @@ disassemble_data (bfd *abfd)
if (relsize > 0) if (relsize > 0)
{ {
long relcount;
relbuf = (arelent **) xmalloc (relsize); relbuf = (arelent **) xmalloc (relsize);
relcount = bfd_canonicalize_reloc (abfd, section, relbuf, syms); relcount = bfd_canonicalize_reloc (abfd, section, relbuf, syms);
if (relcount < 0) if (relcount < 0)
@ -1631,16 +1582,6 @@ disassemble_data (bfd *abfd)
/* Sort the relocs by address. */ /* Sort the relocs by address. */
qsort (relbuf, relcount, sizeof (arelent *), compare_relocs); qsort (relbuf, relcount, sizeof (arelent *), compare_relocs);
relpp = relbuf;
relppend = relpp + relcount;
/* Skip over the relocs belonging to addresses below the
start address. */
if (start_address != (bfd_vma) -1)
while (relpp < relppend
&& (*relpp)->address < start_address)
++relpp;
} }
} }
@ -1666,6 +1607,27 @@ disassemble_data (bfd *abfd)
else else
addr_offset = start_address - disasm_info.buffer_vma; addr_offset = start_address - disasm_info.buffer_vma;
if (dynrelbuf)
{
relpp = dynrelbuf;
/* Dynamic reloc addresses are absolute, non-dynamic are
section relative. REL_OFFSET specifies the reloc address
corresponnding to the start of this section. */
rel_offset = disasm_info.buffer_vma;
}
else
{
relpp = relbuf;
rel_offset = 0;
}
relppend = relpp + relcount;
/* Skip over the relocs belonging to addresses below the
start address. */
while (relpp < relppend
&& (*relpp)->address < rel_offset + addr_offset)
++relpp;
if (stop_address == (bfd_vma) -1) if (stop_address == (bfd_vma) -1)
stop_offset = datasize / opb; stop_offset = datasize / opb;
else else
@ -1687,14 +1649,15 @@ disassemble_data (bfd *abfd)
unsigned long nextstop_offset; unsigned long nextstop_offset;
bfd_boolean insns; bfd_boolean insns;
if (sym != NULL && bfd_asymbol_value (sym) <= section->vma + addr_offset) if (sym != NULL
&& bfd_asymbol_value (sym) <= section->vma + addr_offset)
{ {
int x; int x;
for (x = place; for (x = place;
(x < sorted_symcount (x < sorted_symcount
&& bfd_asymbol_value (sorted_syms[x]) && (bfd_asymbol_value (sorted_syms[x])
<= section->vma + addr_offset); <= section->vma + addr_offset));
++x) ++x)
continue; continue;
@ -1736,7 +1699,8 @@ disassemble_data (bfd *abfd)
nextsym = sorted_syms[place]; nextsym = sorted_syms[place];
} }
if (sym != NULL && bfd_asymbol_value (sym) > section->vma + addr_offset) if (sym != NULL
&& bfd_asymbol_value (sym) > section->vma + addr_offset)
{ {
nextstop_offset = bfd_asymbol_value (sym) - section->vma; nextstop_offset = bfd_asymbol_value (sym) - section->vma;
if (nextstop_offset > stop_offset) if (nextstop_offset > stop_offset)
@ -1768,7 +1732,8 @@ disassemble_data (bfd *abfd)
insns = FALSE; insns = FALSE;
disassemble_bytes (&disasm_info, disassemble_fn, insns, data, disassemble_bytes (&disasm_info, disassemble_fn, insns, data,
addr_offset, nextstop_offset, &relpp, relppend); addr_offset, nextstop_offset,
rel_offset, &relpp, relppend);
addr_offset = nextstop_offset; addr_offset = nextstop_offset;
sym = nextsym; sym = nextsym;
@ -1779,6 +1744,9 @@ disassemble_data (bfd *abfd)
if (relbuf != NULL) if (relbuf != NULL)
free (relbuf); free (relbuf);
} }
if (dynrelbuf != NULL)
free (dynrelbuf);
free (sorted_syms); free (sorted_syms);
} }
@ -2052,7 +2020,7 @@ dump_bfd (bfd *abfd)
dump_stabs (abfd); dump_stabs (abfd);
if (dump_reloc_info && ! disassemble) if (dump_reloc_info && ! disassemble)
dump_relocs (abfd); dump_relocs (abfd);
if (dump_dynamic_reloc_info) if (dump_dynamic_reloc_info && ! disassemble)
dump_dynamic_relocs (abfd); dump_dynamic_relocs (abfd);
if (dump_section_contents) if (dump_section_contents)
dump_data (abfd); dump_data (abfd);