2007-03-24 Paul Brook <paul@codesourcery.com>
[binutils-gdb.git] / binutils / objdump.c
index 513308e01dcb5e993133a87487e1928117812ee5..0177b99e5ca14030e7705b35592551782f8c2288 100644 (file)
@@ -1,6 +1,6 @@
 /* objdump.c -- dump information about an object file.
    Copyright 1990, 1991, 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999,
-   2000, 2001, 2002, 2003, 2004, 2005
+   2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007
    Free Software Foundation, Inc.
 
    This file is part of GNU Binutils.
@@ -49,7 +49,6 @@
    supplied by the disassembler() function.  */
 
 #include "bfd.h"
-#include "bfdver.h"
 #include "progress.h"
 #include "bucomm.h"
 #include "dwarf.h"
 #define        BYTES_IN_WORD   32
 #include "aout/aout64.h"
 
-#if !HAVE_DECL_FPRINTF
-/* This is needed by init_disassemble_info().  */
-extern int fprintf (FILE *, const char *, ...);
-#endif
-
 /* Exit status.  */
 static int exit_status = 0;
 
@@ -130,9 +124,7 @@ struct objdump_disasm_info
   arelent **         dynrelbuf;
   long               dynrelcount;
   disassembler_ftype disassemble_fn;
-#ifdef DISASSEMBLER_NEEDS_RELOCS
   arelent *          reloc;
-#endif
 };
 
 /* Architecture to disassemble for, or default if NULL.  */
@@ -196,6 +188,7 @@ usage (FILE *stream, int status)
   -T, --dynamic-syms       Display the contents of the dynamic symbol table\n\
   -r, --reloc              Display the relocation entries in the file\n\
   -R, --dynamic-reloc      Display the dynamic relocation entries in the file\n\
+  @<file>                  Read options from <file>\n\
   -v, --version            Display this program's version number\n\
   -i, --info               List object formats and architectures supported\n\
   -H, --help               Display this information\n\
@@ -231,7 +224,7 @@ usage (FILE *stream, int status)
 
       disassembler_usage (stream);
     }
-  if (status == 0)
+  if (REPORT_BUGS_TO[0] && status == 0)
     fprintf (stream, _("Report bugs to %s.\n"), REPORT_BUGS_TO);
   exit (status);
 }
@@ -865,9 +858,7 @@ objdump_print_addr (bfd_vma vma,
 {
   struct objdump_disasm_info *aux;
   asymbol *sym = NULL; /* Initialize to avoid compiler warning.  */
-#ifdef DISASSEMBLER_NEEDS_RELOCS
   bfd_boolean skip_find = FALSE;
-#endif
 
   if (sorted_symcount < 1)
     {
@@ -878,7 +869,6 @@ objdump_print_addr (bfd_vma vma,
 
   aux = (struct objdump_disasm_info *) info->application_data;
 
-#ifdef DISASSEMBLER_NEEDS_RELOCS
   if (aux->reloc != NULL
       && aux->reloc->sym_ptr_ptr != NULL
       && * aux->reloc->sym_ptr_ptr != NULL)
@@ -893,7 +883,6 @@ objdump_print_addr (bfd_vma vma,
     }
 
   if (!skip_find)
-#endif
     sym = find_symbol_for_address (vma, info, NULL);
 
   objdump_print_addr_with_sym (aux->abfd, aux->sec, sym, vma, info,
@@ -909,7 +898,7 @@ objdump_print_address (bfd_vma vma, struct disassemble_info *info)
   objdump_print_addr (vma, info, ! prefix_addresses);
 }
 
-/* Determine of the given address has a symbol associated with it.  */
+/* Determine if the given address has a symbol associated with it.  */
 
 static int
 objdump_symbol_at_address (bfd_vma vma, struct disassemble_info * info)
@@ -1318,12 +1307,10 @@ disassemble_bytes (struct disassemble_info * info,
     {
       bfd_vma z;
       bfd_boolean need_nl = FALSE;
-#ifdef DISASSEMBLER_NEEDS_RELOCS
       int previous_octets;
 
       /* Remember the length of the previous instruction.  */
       previous_octets = octets;
-#endif
       octets = 0;
 
       /* If we see more than SKIP_ZEROES octets of zeroes, we just
@@ -1388,8 +1375,8 @@ disassemble_bytes (struct disassemble_info * info,
              info->bytes_per_chunk = 0;
              info->flags = 0;
 
-#ifdef DISASSEMBLER_NEEDS_RELOCS
-             if (*relppp < relppend)
+             if (info->disassembler_needs_relocs
+                 && *relppp < relppend)
                {
                  bfd_signed_vma distance_to_rel;
 
@@ -1419,7 +1406,7 @@ disassemble_bytes (struct disassemble_info * info,
                  else
                    aux->reloc = NULL;
                }
-#endif
+
              octets = (*disassemble_fn) (section->vma + addr_offset, info);
              info->fprintf_func = (fprintf_ftype) fprintf;
              info->stream = stdout;
@@ -1671,10 +1658,7 @@ disassemble_section (bfd *abfd, asection *section, void *info)
       rel_offset = 0;
 
       if ((section->flags & SEC_RELOC) != 0
-#ifndef DISASSEMBLER_NEEDS_RELOCS
-         && dump_reloc_info
-#endif
-         )
+         && (dump_reloc_info || pinfo->disassembler_needs_relocs))
        {
          long relsize;
 
@@ -1763,11 +1747,13 @@ disassemble_section (bfd *abfd, asection *section, void *info)
 
          pinfo->symbols = sorted_syms + place;
          pinfo->num_symbols = x - place;
+         pinfo->symtab_pos = place;
        }
       else
        {
          pinfo->symbols = NULL;
          pinfo->num_symbols = 0;
+         pinfo->symtab_pos = -1;
        }
 
       if (! prefix_addresses)
@@ -1881,9 +1867,7 @@ disassemble_data (bfd *abfd)
   aux.require_sec = FALSE;
   aux.dynrelbuf = NULL;
   aux.dynrelcount = 0;
-#ifdef DISASSEMBLER_NEEDS_RELOCS
   aux.reloc = NULL;
-#endif
 
   disasm_info.print_address_func = objdump_print_address;
   disasm_info.symbol_at_address_func = objdump_symbol_at_address;
@@ -1925,6 +1909,7 @@ disassemble_data (bfd *abfd)
   disasm_info.octets_per_byte = bfd_octets_per_byte (abfd);
   disasm_info.skip_zeroes = DEFAULT_SKIP_ZEROES;
   disasm_info.skip_zeroes_at_end = DEFAULT_SKIP_ZEROES_AT_END;
+  disasm_info.disassembler_needs_relocs = FALSE;
 
   if (bfd_big_endian (abfd))
     disasm_info.display_endian = disasm_info.endian = BFD_ENDIAN_BIG;
@@ -1961,6 +1946,8 @@ disassemble_data (bfd *abfd)
                 compare_relocs);
        }
     }
+  disasm_info.symtab = sorted_syms;
+  disasm_info.symtab_size = sorted_symcount;
 
   bfd_map_over_sections (abfd, disassemble_section, & disasm_info);
 
@@ -2031,7 +2018,7 @@ dump_dwarf_section (bfd *abfd, asection *section,
   const char *match;
   enum dwarf_section_display_enum i;
 
-  if (strncmp (name, ".gnu.linkonce.wi.", 17) == 0)
+  if (CONST_STRNEQ (name, ".gnu.linkonce.wi."))
     match = ".debug_info";
   else
     match = name;
@@ -2918,7 +2905,10 @@ display_file (char *filename, char *target)
   bfd *arfile = NULL;
 
   if (get_file_size (filename) < 1)
-    return;
+    {
+      exit_status = 1;
+      return;
+    }
 
   file = bfd_openr (filename, target);
   if (file == NULL)
@@ -2983,6 +2973,8 @@ main (int argc, char **argv)
 
   START_PROGRESS (program_name, 0);
 
+  expandargv (&argc, &argv);
+
   bfd_init ();
   set_default_bfd_target ();