]> git.ipfire.org Git - thirdparty/binutils-gdb.git/blobdiff - binutils/readelf.c
* readelf.c (get_ppc_dynamic_type): New function for DT_PPC_GLINK.
[thirdparty/binutils-gdb.git] / binutils / readelf.c
index e607e0f72d36716409341aa34b74811edf54bb01..9b83f08229cbed15a73b5abe2c2782ddee5c91a1 100644 (file)
@@ -19,8 +19,8 @@
 
    You should have received a copy of the GNU General Public License
    along with this program; if not, write to the Free Software
-   Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
-   02111-1307, USA.  */
+   Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA
+   02110-1301, USA.  */
 \f
 /* The difference between readelf and objdump:
 
 #include "libiberty.h"
 
 char *program_name = "readelf";
-long archive_file_offset;
-unsigned long archive_file_size;
-unsigned long dynamic_addr;
-bfd_size_type dynamic_size;
-unsigned int dynamic_nent;
-char *dynamic_strings;
-unsigned long dynamic_strings_length;
-char *string_table;
-unsigned long string_table_length;
-unsigned long num_dynamic_syms;
-Elf_Internal_Sym *dynamic_symbols;
-Elf_Internal_Syminfo *dynamic_syminfo;
-unsigned long dynamic_syminfo_offset;
-unsigned int dynamic_syminfo_nent;
-char program_interpreter[64];
-bfd_vma dynamic_info[DT_JMPREL + 1];
-bfd_vma version_info[16];
-Elf_Internal_Ehdr elf_header;
-Elf_Internal_Shdr *section_headers;
-Elf_Internal_Phdr *program_headers;
-Elf_Internal_Dyn *dynamic_section;
-Elf_Internal_Shdr *symtab_shndx_hdr;
-int show_name;
-int do_dynamic;
-int do_syms;
-int do_reloc;
-int do_sections;
-int do_section_groups;
-int do_segments;
-int do_unwind;
-int do_using_dynamic;
-int do_header;
-int do_dump;
-int do_version;
-int do_wide;
-int do_histogram;
-int do_debugging;
-int do_debug_info;
-int do_debug_abbrevs;
-int do_debug_lines;
-int do_debug_pubnames;
-int do_debug_aranges;
-int do_debug_ranges;
-int do_debug_frames;
-int do_debug_frames_interp;
-int do_debug_macinfo;
-int do_debug_str;
-int do_debug_loc;
-int do_arch;
-int do_notes;
-int is_32bit_elf;
-int have_frame_base;
-int need_base_address;
-bfd_vma eh_addr_size;
+static long archive_file_offset;
+static unsigned long archive_file_size;
+static unsigned long dynamic_addr;
+static bfd_size_type dynamic_size;
+static unsigned int dynamic_nent;
+static char *dynamic_strings;
+static unsigned long dynamic_strings_length;
+static char *string_table;
+static unsigned long string_table_length;
+static unsigned long num_dynamic_syms;
+static Elf_Internal_Sym *dynamic_symbols;
+static Elf_Internal_Syminfo *dynamic_syminfo;
+static unsigned long dynamic_syminfo_offset;
+static unsigned int dynamic_syminfo_nent;
+static char program_interpreter[64];
+static bfd_vma dynamic_info[DT_JMPREL + 1];
+static bfd_vma version_info[16];
+static Elf_Internal_Ehdr elf_header;
+static Elf_Internal_Shdr *section_headers;
+static Elf_Internal_Phdr *program_headers;
+static Elf_Internal_Dyn *dynamic_section;
+static Elf_Internal_Shdr *symtab_shndx_hdr;
+static int show_name;
+static int do_dynamic;
+static int do_syms;
+static int do_reloc;
+static int do_sections;
+static int do_section_groups;
+static int do_full_section_name;
+static int do_segments;
+static int do_unwind;
+static int do_using_dynamic;
+static int do_header;
+static int do_dump;
+static int do_version;
+static int do_wide;
+static int do_histogram;
+static int do_debugging;
+static int do_debug_info;
+static int do_debug_abbrevs;
+static int do_debug_lines;
+static int do_debug_pubnames;
+static int do_debug_aranges;
+static int do_debug_ranges;
+static int do_debug_frames;
+static int do_debug_frames_interp;
+static int do_debug_macinfo;
+static int do_debug_str;
+static int do_debug_loc;
+static int do_arch;
+static int do_notes;
+static int is_32bit_elf;
+static int have_frame_base;
+static int need_base_address;
+static bfd_vma eh_addr_size;
 
 struct group_list
 {
@@ -184,10 +185,9 @@ struct group
   unsigned int group_index;
 };
 
-struct group *section_groups;
-size_t group_count;
-
-struct group **section_headers_groups;
+static size_t group_count;
+static struct group *section_groups;
+static struct group **section_headers_groups;
 
 /* A dynamic array of flags indicating for which sections a hex dump
    has been requested (via the -x switch) and/or a disassembly dump
@@ -248,20 +248,6 @@ static void (*byte_put) (unsigned char *, bfd_vma, int);
 
 #define BYTE_GET(field)        byte_get (field, sizeof (field))
 
-/* If we can support a 64 bit data type then BFD64 should be defined
-   and sizeof (bfd_vma) == 8.  In this case when translating from an
-   external 8 byte field to an internal field, we can assume that the
-   internal field is also 8 bytes wide and so we can extract all the data.
-   If, however, BFD64 is not defined, then we must assume that the
-   internal data structure only has 4 byte wide fields that are the
-   equivalent of the 8 byte wide external counterparts, and so we must
-   truncate the data.  */
-#ifdef  BFD64
-#define BYTE_GET8(field)       byte_get (field, -8)
-#else
-#define BYTE_GET8(field)       byte_get (field, 8)
-#endif
-
 #define NUM_ELEM(array)        (sizeof (array) / sizeof ((array)[0]))
 
 #define GET_ELF_SYMBOLS(file, section)                 \
@@ -365,11 +351,6 @@ byte_get_little_endian (unsigned char *field, int size)
 
 #ifdef BFD64
     case 8:
-    case -8:
-      /* This is a special case, generated by the BYTE_GET8 macro.
-        It means that we are loading an 8 byte value from a field
-        in an external structure into an 8 byte value in a field
-        in an internal structure.  */
       return  ((bfd_vma) (field[0]))
        |    (((bfd_vma) (field[1])) << 8)
        |    (((bfd_vma) (field[2])) << 16)
@@ -399,7 +380,6 @@ byte_get_signed (unsigned char *field, int size)
     case 4:
       return (x ^ 0x80000000) - 0x80000000;
     case 8:
-    case -8:
       return x;
     default:
       abort ();
@@ -434,8 +414,60 @@ byte_put_little_endian (unsigned char *field, bfd_vma value, int size)
     }
 }
 
+#if defined BFD64 && !BFD_HOST_64BIT_LONG
+static int
+print_dec_vma (bfd_vma vma, int is_signed)
+{
+  char buf[40];
+  char *bufp = buf;
+  int nc = 0;
+
+  if (is_signed && (bfd_signed_vma) vma < 0)
+    {
+      vma = -vma;
+      putchar ('-');
+      nc = 1;
+    }
+
+  do
+    {
+      *bufp++ = '0' + vma % 10;
+      vma /= 10;
+    }
+  while (vma != 0);
+  nc += bufp - buf;
+
+  while (bufp > buf)
+    putchar (*--bufp);
+  return nc;
+}
+
+static int
+print_hex_vma (bfd_vma vma)
+{
+  char buf[32];
+  char *bufp = buf;
+  int nc;
+
+  do
+    {
+      char digit = '0' + (vma & 0x0f);
+      if (digit > '9')
+       digit += 'a' - '0' - 10;
+      *bufp++ = digit;
+      vma >>= 4;
+    }
+  while (vma != 0);
+  nc = bufp - buf;
+
+  while (bufp > buf)
+    putchar (*--bufp);
+  return nc;
+}
+#endif
+
 /* Print a VMA value.  */
-static void
+static int
 print_vma (bfd_vma vma, print_mode mode)
 {
 #ifdef BFD64
@@ -445,106 +477,85 @@ print_vma (bfd_vma vma, print_mode mode)
       switch (mode)
        {
        case FULL_HEX:
-         printf ("0x");
-         /* Drop through.  */
+         return printf ("0x%8.8lx", (unsigned long) vma);
+
        case LONG_HEX:
-         printf ("%8.8lx", (unsigned long) vma);
-         break;
+         return printf ("%8.8lx", (unsigned long) vma);
 
        case DEC_5:
          if (vma <= 99999)
-           {
-             printf ("%5ld", (long) vma);
-             break;
-           }
+           return printf ("%5ld", (long) vma);
          /* Drop through.  */
+
        case PREFIX_HEX:
-         printf ("0x");
-         /* Drop through.  */
+         return printf ("0x%lx", (unsigned long) vma);
+
        case HEX:
-         printf ("%lx", (unsigned long) vma);
-         break;
+         return printf ("%lx", (unsigned long) vma);
 
        case DEC:
-         printf ("%ld", (unsigned long) vma);
-         break;
+         return printf ("%ld", (unsigned long) vma);
 
        case UNSIGNED:
-         printf ("%lu", (unsigned long) vma);
-         break;
+         return printf ("%lu", (unsigned long) vma);
        }
     }
 #ifdef BFD64
   else
     {
+      int nc = 0;
+
       switch (mode)
        {
        case FULL_HEX:
-         printf ("0x");
+         nc = printf ("0x");
          /* Drop through.  */
 
        case LONG_HEX:
          printf_vma (vma);
-         break;
+         return nc + 16;
 
        case PREFIX_HEX:
-         printf ("0x");
+         nc = printf ("0x");
          /* Drop through.  */
 
        case HEX:
 #if BFD_HOST_64BIT_LONG
-         printf ("%lx", vma);
+         return nc + printf ("%lx", vma);
 #else
-         if (_bfd_int64_high (vma))
-           printf ("%lx%8.8lx", _bfd_int64_high (vma), _bfd_int64_low (vma));
-         else
-           printf ("%lx", _bfd_int64_low (vma));
+         return nc + print_hex_vma (vma);
 #endif
-         break;
 
        case DEC:
 #if BFD_HOST_64BIT_LONG
-         printf ("%ld", vma);
+         return printf ("%ld", vma);
 #else
-         if (_bfd_int64_high (vma))
-           /* ugg */
-           printf ("++%ld", _bfd_int64_low (vma));
-         else
-           printf ("%ld", _bfd_int64_low (vma));
+         return print_dec_vma (vma, 1);
 #endif
-         break;
 
        case DEC_5:
 #if BFD_HOST_64BIT_LONG
          if (vma <= 99999)
-           printf ("%5ld", vma);
+           return printf ("%5ld", vma);
          else
-           printf ("%#lx", vma);
+           return printf ("%#lx", vma);
 #else
-         if (_bfd_int64_high (vma))
-           /* ugg */
-           printf ("++%ld", _bfd_int64_low (vma));
-         else if (vma <= 99999)
-           printf ("%5ld", _bfd_int64_low (vma));
+         if (vma <= 99999)
+           return printf ("%5ld", _bfd_int64_low (vma));
          else
-           printf ("%#lx", _bfd_int64_low (vma));
+           return print_hex_vma (vma);
 #endif
-         break;
 
        case UNSIGNED:
 #if BFD_HOST_64BIT_LONG
-         printf ("%lu", vma);
+         return printf ("%lu", vma);
 #else
-         if (_bfd_int64_high (vma))
-           /* ugg */
-           printf ("++%lu", _bfd_int64_low (vma));
-         else
-           printf ("%lu", _bfd_int64_low (vma));
+         return print_dec_vma (vma, 0);
 #endif
-         break;
        }
     }
 #endif
+  return 0;
 }
 
 /* Display a symbol on stdout.  If do_wide is not true then
@@ -575,27 +586,21 @@ byte_get_big_endian (unsigned char *field, int size)
     case 2:
       return ((unsigned int) (field[1])) | (((int) (field[0])) << 8);
 
+#ifndef BFD64
+    case 8:
+      /* Although we are extracing data from an 8 byte wide field,
+        we are returning only 4 bytes of data.  */
+      field += 4;
+      /* Fall thru */
+#endif
     case 4:
       return ((unsigned long) (field[3]))
        |   (((unsigned long) (field[2])) << 8)
        |   (((unsigned long) (field[1])) << 16)
        |   (((unsigned long) (field[0])) << 24);
 
-#ifndef BFD64
-    case 8:
-      /* Although we are extracing data from an 8 byte wide field,
-        we are returning only 4 bytes of data.  */
-      return ((unsigned long) (field[7]))
-       |   (((unsigned long) (field[6])) << 8)
-       |   (((unsigned long) (field[5])) << 16)
-       |   (((unsigned long) (field[4])) << 24);
-#else
+#ifdef BFD64
     case 8:
-    case -8:
-      /* This is a special case, generated by the BYTE_GET8 macro.
-        It means that we are loading an 8 byte value from a field
-        in an external structure into an 8 byte value in a field
-        in an internal structure.  */
       return ((bfd_vma) (field[7]))
        |   (((bfd_vma) (field[6])) << 8)
        |   (((bfd_vma) (field[5])) << 16)
@@ -807,9 +812,9 @@ slurp_rela_relocs (FILE *file,
 
       for (i = 0; i < nrelas; i++)
        {
-         relas[i].r_offset = BYTE_GET8 (erelas[i].r_offset);
-         relas[i].r_info   = BYTE_GET8 (erelas[i].r_info);
-         relas[i].r_addend = BYTE_GET8 (erelas[i].r_addend);
+         relas[i].r_offset = BYTE_GET (erelas[i].r_offset);
+         relas[i].r_info   = BYTE_GET (erelas[i].r_info);
+         relas[i].r_addend = BYTE_GET (erelas[i].r_addend);
        }
 
       free (erelas);
@@ -877,8 +882,8 @@ slurp_rel_relocs (FILE *file,
 
       for (i = 0; i < nrels; i++)
        {
-         rels[i].r_offset = BYTE_GET8 (erels[i].r_offset);
-         rels[i].r_info   = BYTE_GET8 (erels[i].r_info);
+         rels[i].r_offset = BYTE_GET (erels[i].r_offset);
+         rels[i].r_info   = BYTE_GET (erels[i].r_info);
          rels[i].r_addend = 0;
        }
 
@@ -1407,6 +1412,17 @@ get_sparc64_dynamic_type (unsigned long type)
     }
 }
 
+static const char *
+get_ppc_dynamic_type (unsigned long type)
+{
+  switch (type)
+    {
+    case DT_PPC_GLINK: return "PPC_GLINK";
+    default:
+      return NULL;
+    }
+}
+
 static const char *
 get_ppc64_dynamic_type (unsigned long type)
 {
@@ -1457,7 +1473,7 @@ get_ia64_dynamic_type (unsigned long type)
 static const char *
 get_dynamic_type (unsigned long type)
 {
-  static char buff[32];
+  static char buff[64];
 
   switch (type)
     {
@@ -1547,6 +1563,9 @@ get_dynamic_type (unsigned long type)
            case EM_SPARCV9:
              result = get_sparc64_dynamic_type (type);
              break;
+           case EM_PPC:
+             result = get_ppc_dynamic_type (type);
+             break;
            case EM_PPC64:
              result = get_ppc64_dynamic_type (type);
              break;
@@ -1561,7 +1580,7 @@ get_dynamic_type (unsigned long type)
          if (result != NULL)
            return result;
 
-         sprintf (buff, _("Processor Specific: %lx"), type);
+         snprintf (buff, sizeof (buff), _("Processor Specific: %lx"), type);
        }
       else if ((type >= DT_LOOS) && (type <= DT_HIOS))
        {
@@ -1580,10 +1599,11 @@ get_dynamic_type (unsigned long type)
          if (result != NULL)
            return result;
 
-         sprintf (buff, _("Operating System specific: %lx"), type);
+         snprintf (buff, sizeof (buff), _("Operating System specific: %lx"),
+                   type);
        }
       else
-       sprintf (buff, _("<unknown>: %lx"), type);
+       snprintf (buff, sizeof (buff), _("<unknown>: %lx"), type);
 
       return buff;
     }
@@ -1604,11 +1624,11 @@ get_file_type (unsigned e_type)
 
     default:
       if ((e_type >= ET_LOPROC) && (e_type <= ET_HIPROC))
-       sprintf (buff, _("Processor Specific: (%x)"), e_type);
+       snprintf (buff, sizeof (buff), _("Processor Specific: (%x)"), e_type);
       else if ((e_type >= ET_LOOS) && (e_type <= ET_HIOS))
-       sprintf (buff, _("OS Specific: (%x)"), e_type);
+       snprintf (buff, sizeof (buff), _("OS Specific: (%x)"), e_type);
       else
-       sprintf (buff, _("<unknown>: %x"), e_type);
+       snprintf (buff, sizeof (buff), _("<unknown>: %x"), e_type);
       return buff;
     }
 }
@@ -1715,7 +1735,7 @@ get_machine_name (unsigned e_machine)
     case EM_XTENSA_OLD:
     case EM_XTENSA:            return "Tensilica Xtensa Processor";
     default:
-      sprintf (buff, _("<unknown>: %x"), e_machine);
+      snprintf (buff, sizeof (buff), _("<unknown>: %x"), e_machine);
       return buff;
     }
 }
@@ -2223,11 +2243,25 @@ get_osabi_name (unsigned int osabi)
     case ELFOSABI_STANDALONE:  return _("Standalone App");
     case ELFOSABI_ARM:         return "ARM";
     default:
-      sprintf (buff, _("<unknown: %x>"), osabi);
+      snprintf (buff, sizeof (buff), _("<unknown: %x>"), osabi);
       return buff;
     }
 }
 
+static const char *
+get_arm_segment_type (unsigned long type)
+{
+  switch (type)
+    {
+    case PT_ARM_EXIDX:
+      return "EXIDX";
+    default:
+      break;
+    }
+
+  return NULL;
+}
+
 static const char *
 get_mips_segment_type (unsigned long type)
 {
@@ -2318,6 +2352,9 @@ get_segment_type (unsigned long p_type)
 
          switch (elf_header.e_machine)
            {
+           case EM_ARM:
+             result = get_arm_segment_type (p_type);
+             break;
            case EM_MIPS:
            case EM_MIPS_RS3_LE:
              result = get_mips_segment_type (p_type);
@@ -2361,7 +2398,7 @@ get_segment_type (unsigned long p_type)
          sprintf (buff, "LOOS+%lx", p_type - PT_LOOS);
        }
       else
-       sprintf (buff, _("<unknown>: %lx"), p_type);
+       snprintf (buff, sizeof (buff), _("<unknown>: %lx"), p_type);
 
       return buff;
     }
@@ -2545,7 +2582,7 @@ get_section_type_name (unsigned int sh_type)
       else if ((sh_type >= SHT_LOUSER) && (sh_type <= SHT_HIUSER))
        sprintf (buff, "LOUSER+%x", sh_type - SHT_LOUSER);
       else
-       sprintf (buff, _("<unknown>: %x"), sh_type);
+       snprintf (buff, sizeof (buff), _("<unknown>: %x"), sh_type);
 
       return buff;
     }
@@ -2553,7 +2590,7 @@ get_section_type_name (unsigned int sh_type)
 
 #define OPTION_DEBUG_DUMP      512
 
-struct option options[] =
+static struct option options[] =
 {
   {"all",             no_argument, 0, 'a'},
   {"file-header",      no_argument, 0, 'h'},
@@ -2564,6 +2601,7 @@ struct option options[] =
   {"sections",        no_argument, 0, 'S'},
   {"section-headers",  no_argument, 0, 'S'},
   {"section-groups",   no_argument, 0, 'g'},
+  {"full-section-name",no_argument, 0, 'N'},
   {"symbols",         no_argument, 0, 's'},
   {"syms",            no_argument, 0, 's'},
   {"relocs",          no_argument, 0, 'r'},
@@ -2598,6 +2636,8 @@ usage (void)
   -S --section-headers   Display the sections' header\n\
      --sections          An alias for --section-headers\n\
   -g --section-groups    Display the section groups\n\
+  -N --full-section-name\n\
+                         Display the full section name\n\
   -e --headers           Equivalent to: -h -l -S\n\
   -s --syms              Display the symbol table\n\
       --symbols          An alias for --syms\n\
@@ -2670,7 +2710,7 @@ parse_args (int argc, char **argv)
     usage ();
 
   while ((c = getopt_long
-         (argc, argv, "ersuahnldSDAIgw::x:i:vVWH", options, NULL)) != EOF)
+         (argc, argv, "ersuahnldSDAINgw::x:i:vVWH", options, NULL)) != EOF)
     {
       char *cp;
       int section;
@@ -2701,6 +2741,9 @@ parse_args (int argc, char **argv)
        case 'g':
          do_section_groups++;
          break;
+       case 'N':
+         do_full_section_name++;
+         break;
        case 'e':
          do_header++;
          do_sections++;
@@ -2943,7 +2986,7 @@ get_elf_class (unsigned int elf_class)
     case ELFCLASS32:   return "ELF32";
     case ELFCLASS64:   return "ELF64";
     default:
-      sprintf (buff, _("<unknown: %x>"), elf_class);
+      snprintf (buff, sizeof (buff), _("<unknown: %x>"), elf_class);
       return buff;
     }
 }
@@ -2959,7 +3002,7 @@ get_data_encoding (unsigned int encoding)
     case ELFDATA2LSB: return _("2's complement, little endian");
     case ELFDATA2MSB: return _("2's complement, big endian");
     default:
-      sprintf (buff, _("<unknown: %x>"), encoding);
+      snprintf (buff, sizeof (buff), _("<unknown: %x>"), encoding);
       return buff;
     }
 }
@@ -3108,12 +3151,12 @@ get_64bit_program_headers (FILE *file, Elf_Internal_Phdr *program_headers)
     {
       internal->p_type   = BYTE_GET (external->p_type);
       internal->p_flags  = BYTE_GET (external->p_flags);
-      internal->p_offset = BYTE_GET8 (external->p_offset);
-      internal->p_vaddr  = BYTE_GET8 (external->p_vaddr);
-      internal->p_paddr  = BYTE_GET8 (external->p_paddr);
-      internal->p_filesz = BYTE_GET8 (external->p_filesz);
-      internal->p_memsz  = BYTE_GET8 (external->p_memsz);
-      internal->p_align  = BYTE_GET8 (external->p_align);
+      internal->p_offset = BYTE_GET (external->p_offset);
+      internal->p_vaddr  = BYTE_GET (external->p_vaddr);
+      internal->p_paddr  = BYTE_GET (external->p_paddr);
+      internal->p_filesz = BYTE_GET (external->p_filesz);
+      internal->p_memsz  = BYTE_GET (external->p_memsz);
+      internal->p_align  = BYTE_GET (external->p_align);
     }
 
   free (phdrs);
@@ -3488,10 +3531,10 @@ get_64bit_section_headers (FILE *file, unsigned int num)
     {
       internal->sh_name      = BYTE_GET (shdrs[i].sh_name);
       internal->sh_type      = BYTE_GET (shdrs[i].sh_type);
-      internal->sh_flags     = BYTE_GET8 (shdrs[i].sh_flags);
-      internal->sh_addr      = BYTE_GET8 (shdrs[i].sh_addr);
-      internal->sh_size      = BYTE_GET8 (shdrs[i].sh_size);
-      internal->sh_entsize   = BYTE_GET8 (shdrs[i].sh_entsize);
+      internal->sh_flags     = BYTE_GET (shdrs[i].sh_flags);
+      internal->sh_addr      = BYTE_GET (shdrs[i].sh_addr);
+      internal->sh_size      = BYTE_GET (shdrs[i].sh_size);
+      internal->sh_entsize   = BYTE_GET (shdrs[i].sh_entsize);
       internal->sh_link      = BYTE_GET (shdrs[i].sh_link);
       internal->sh_info      = BYTE_GET (shdrs[i].sh_info);
       internal->sh_offset    = BYTE_GET (shdrs[i].sh_offset);
@@ -3618,8 +3661,8 @@ get_64bit_elf_symbols (FILE *file, Elf_Internal_Shdr *section)
       if (psym->st_shndx == SHN_XINDEX && shndx != NULL)
        psym->st_shndx
          = byte_get ((unsigned char *) &shndx[j], sizeof (shndx[j]));
-      psym->st_value = BYTE_GET8 (esyms[j].st_value);
-      psym->st_size  = BYTE_GET8 (esyms[j].st_size);
+      psym->st_value = BYTE_GET (esyms[j].st_value);
+      psym->st_size  = BYTE_GET (esyms[j].st_size);
     }
 
   if (shndx)
@@ -3632,9 +3675,8 @@ get_64bit_elf_symbols (FILE *file, Elf_Internal_Shdr *section)
 static const char *
 get_elf_section_flags (bfd_vma sh_flags)
 {
-  static char buff[32];
-
-  *buff = 0;
+  static char buff[33];
+  char *p = buff;
 
   while (sh_flags)
     {
@@ -3645,34 +3687,36 @@ get_elf_section_flags (bfd_vma sh_flags)
 
       switch (flag)
        {
-       case SHF_WRITE:            strcat (buff, "W"); break;
-       case SHF_ALLOC:            strcat (buff, "A"); break;
-       case SHF_EXECINSTR:        strcat (buff, "X"); break;
-       case SHF_MERGE:            strcat (buff, "M"); break;
-       case SHF_STRINGS:          strcat (buff, "S"); break;
-       case SHF_INFO_LINK:        strcat (buff, "I"); break;
-       case SHF_LINK_ORDER:       strcat (buff, "L"); break;
-       case SHF_OS_NONCONFORMING: strcat (buff, "O"); break;
-       case SHF_GROUP:            strcat (buff, "G"); break;
-       case SHF_TLS:              strcat (buff, "T"); break;
+       case SHF_WRITE:            *p = 'W'; break;
+       case SHF_ALLOC:            *p = 'A'; break;
+       case SHF_EXECINSTR:        *p = 'X'; break;
+       case SHF_MERGE:            *p = 'M'; break;
+       case SHF_STRINGS:          *p = 'S'; break;
+       case SHF_INFO_LINK:        *p = 'I'; break;
+       case SHF_LINK_ORDER:       *p = 'L'; break;
+       case SHF_OS_NONCONFORMING: *p = 'O'; break;
+       case SHF_GROUP:            *p = 'G'; break;
+       case SHF_TLS:              *p = 'T'; break;
 
        default:
          if (flag & SHF_MASKOS)
            {
-             strcat (buff, "o");
+             *p = 'o';
              sh_flags &= ~ SHF_MASKOS;
            }
          else if (flag & SHF_MASKPROC)
            {
-             strcat (buff, "p");
+             *p = 'p';
              sh_flags &= ~ SHF_MASKPROC;
            }
          else
-           strcat (buff, "x");
+           *p = 'x';
          break;
        }
+      p++;
     }
 
+  *p = '\0';
   return buff;
 }
 
@@ -3823,25 +3867,60 @@ process_section_headers (FILE *file)
     printf (_("\nSection Header:\n"));
 
   if (is_32bit_elf)
-    printf
-      (_("  [Nr] Name              Type            Addr     Off    Size   ES Flg Lk Inf Al\n"));
+    {
+      if (do_full_section_name)
+       {
+         printf (_("  [Nr] Name\n"));
+         printf (_("       Type            Addr     Off    Size   ES Flg Lk Inf Al\n"));
+       }
+      else
+       printf
+         (_("  [Nr] Name              Type            Addr     Off    Size   ES Flg Lk Inf Al\n"));
+    }
   else if (do_wide)
-    printf
-      (_("  [Nr] Name              Type            Address          Off    Size   ES Flg Lk Inf Al\n"));
+    {
+      if (do_full_section_name)
+       {
+         printf (_("  [Nr] Name\n"));
+         printf (_("       Type            Address          Off    Size   ES Flg Lk Inf Al\n"));
+       }
+      else
+       printf
+         (_("  [Nr] Name              Type            Address          Off    Size   ES Flg Lk Inf Al\n"));
+    }
   else
     {
-      printf (_("  [Nr] Name              Type             Address           Offset\n"));
-      printf (_("       Size              EntSize          Flags  Link  Info  Align\n"));
+      if (do_full_section_name)
+       {
+         printf (_("  [Nr] Name\n"));
+         printf (_("       Flags             Type             Address           Offset\n"));
+         printf (_("       Size              EntSize          Link     Info     Align\n"));
+       }
+      else
+       {
+         printf (_("  [Nr] Name              Type             Address           Offset\n"));
+         printf (_("       Size              EntSize          Flags  Link  Info  Align\n"));
+       }
     }
 
   for (i = 0, section = section_headers;
        i < elf_header.e_shnum;
        i++, section++)
     {
-      printf ("  [%2u] %-17.17s %-15.15s ",
-             SECTION_HEADER_NUM (i),
-             SECTION_NAME (section),
-             get_section_type_name (section->sh_type));
+      if (do_full_section_name)
+       {
+         printf ("  [%2u] %s\n",
+                 SECTION_HEADER_NUM (i),
+                 SECTION_NAME (section));
+         if (is_32bit_elf || do_wide)
+           printf ("       %-15.15s ",
+                   get_section_type_name (section->sh_type));
+       }
+      else
+       printf ("  [%2u] %-17.17s %-15.15s ",
+               SECTION_HEADER_NUM (i),
+               SECTION_NAME (section),
+               get_section_type_name (section->sh_type));
 
       if (is_32bit_elf)
        {
@@ -3901,6 +3980,30 @@ process_section_headers (FILE *file)
              putchar ('\n');
            }
        }
+      else if (do_full_section_name)
+       {
+         printf ("       %-15.15s   %-15.15s ",
+                 get_elf_section_flags (section->sh_flags),
+                 get_section_type_name (section->sh_type));
+         putchar (' ');
+         print_vma (section->sh_addr, LONG_HEX);
+         if ((long) section->sh_offset == section->sh_offset)
+           printf ("  %8.8lx", (unsigned long) section->sh_offset);
+         else
+           {
+             printf ("  ");
+             print_vma (section->sh_offset, LONG_HEX);
+           }
+         printf ("\n       ");
+         print_vma (section->sh_size, LONG_HEX);
+         printf ("  ");
+         print_vma (section->sh_entsize, LONG_HEX);
+
+         printf ("   %2ld      %3lu        %ld\n",
+                 (unsigned long) section->sh_link,
+                 (unsigned long) section->sh_info,
+                 (unsigned long) section->sh_addralign);
+       }
       else
        {
          putchar (' ');
@@ -3944,7 +4047,7 @@ get_group_flags (unsigned int flags)
       return "COMDAT";
 
    default:
-      sprintf (buff, _("[<unknown>: 0x%x]"), flags);
+      snprintf (buff, sizeof (buff), _("[<unknown>: 0x%x]"), flags);
       break;
     }
   return buff;
@@ -4022,7 +4125,8 @@ process_section_groups (FILE *file)
       if (section->sh_type == SHT_GROUP)
        {
          char *name = SECTION_NAME (section);
-         char *group_name, *start, *indices;
+         char *group_name;
+         unsigned char *start, *indices;
          unsigned int entry, j, size;
          Elf_Internal_Shdr *sec;
          Elf_Internal_Sym *sym;
@@ -4153,7 +4257,7 @@ process_section_groups (FILE *file)
   return 1;
 }
 
-struct
+static struct
 {
   const char *name;
   int reloc;
@@ -4410,7 +4514,7 @@ dump_ia64_unwind (struct ia64_unw_aux_info *aux)
              (unsigned long) (tp->info.offset - aux->seg_base));
 
       head = aux->info + (tp->info.offset - aux->info_addr);
-      stamp = BYTE_GET8 ((unsigned char *) head);
+      stamp = BYTE_GET ((unsigned char *) head);
 
       printf ("  v%u, flags=0x%lx (%s%s), len=%lu bytes\n",
              (unsigned) UNW_VER (stamp),
@@ -4490,9 +4594,9 @@ slurp_ia64_unwind_table (FILE *file,
        }
       else
        {
-         tep->start.offset = BYTE_GET8 ((unsigned char *) tp +  0);
-         tep->end.offset   = BYTE_GET8 ((unsigned char *) tp +  8);
-         tep->info.offset  = BYTE_GET8 ((unsigned char *) tp + 16);
+         tep->start.offset = BYTE_GET ((unsigned char *) tp +  0);
+         tep->end.offset   = BYTE_GET ((unsigned char *) tp +  8);
+         tep->info.offset  = BYTE_GET ((unsigned char *) tp + 16);
        }
       tep->start.offset += aux->seg_base;
       tep->end.offset   += aux->seg_base;
@@ -4875,8 +4979,8 @@ slurp_hppa_unwind_table (FILE *file,
        }
       else
        {
-         tep->start.offset = BYTE_GET8 ((unsigned char *) tp + 0);
-         tep->end.offset = BYTE_GET8 ((unsigned char *) tp + 8);
+         tep->start.offset = BYTE_GET ((unsigned char *) tp + 0);
+         tep->end.offset = BYTE_GET ((unsigned char *) tp + 8);
          tmp1 = byte_get ((unsigned char *) tp + 16, 4);
          tmp2 = byte_get ((unsigned char *) tp + 20, 4);
        }
@@ -5106,9 +5210,9 @@ dynamic_section_mips_val (Elf_Internal_Dyn *entry)
 
        time_t time = entry->d_un.d_val;
        tmp = gmtime (&time);
-       sprintf (timebuf, "%04u-%02u-%02uT%02u:%02u:%02u",
-                tmp->tm_year + 1900, tmp->tm_mon + 1, tmp->tm_mday,
-                tmp->tm_hour, tmp->tm_min, tmp->tm_sec);
+       snprintf (timebuf, sizeof (timebuf), "%04u-%02u-%02uT%02u:%02u:%02u",
+                 tmp->tm_year + 1900, tmp->tm_mon + 1, tmp->tm_mday,
+                 tmp->tm_hour, tmp->tm_min, tmp->tm_sec);
        printf ("Time Stamp: %s\n", timebuf);
       }
       break;
@@ -5273,7 +5377,7 @@ get_64bit_dynamic_section (FILE *file)
        ext++)
     {
       dynamic_nent++;
-      if (BYTE_GET8 (ext->d_tag) == DT_NULL)
+      if (BYTE_GET (ext->d_tag) == DT_NULL)
        break;
     }
 
@@ -5289,8 +5393,8 @@ get_64bit_dynamic_section (FILE *file)
        entry < dynamic_section + dynamic_nent;
        ext++, entry++)
     {
-      entry->d_tag      = BYTE_GET8 (ext->d_tag);
-      entry->d_un.d_val = BYTE_GET8 (ext->d_un.d_val);
+      entry->d_tag      = BYTE_GET (ext->d_tag);
+      entry->d_un.d_val = BYTE_GET (ext->d_un.d_val);
     }
 
   free (edyn);
@@ -5298,13 +5402,11 @@ get_64bit_dynamic_section (FILE *file)
   return 1;
 }
 
-static const char *
-get_dynamic_flags (bfd_vma flags)
+static void
+print_dynamic_flags (bfd_vma flags)
 {
-  static char buff[128];
-  char *p = buff;
+  int first = 1;
 
-  *p = '\0';
   while (flags)
     {
       bfd_vma flag;
@@ -5312,22 +5414,22 @@ get_dynamic_flags (bfd_vma flags)
       flag = flags & - flags;
       flags &= ~ flag;
 
-      if (p != buff)
-       *p++ = ' ';
+      if (first)
+       first = 0;
+      else
+       putc (' ', stdout);
 
       switch (flag)
        {
-       case DF_ORIGIN:         strcpy (p, "ORIGIN"); break;
-       case DF_SYMBOLIC:       strcpy (p, "SYMBOLIC"); break;
-       case DF_TEXTREL:        strcpy (p, "TEXTREL"); break;
-       case DF_BIND_NOW:       strcpy (p, "BIND_NOW"); break;
-       case DF_STATIC_TLS:     strcpy (p, "STATIC_TLS"); break;
-       default:                strcpy (p, "unknown"); break;
+       case DF_ORIGIN:         fputs ("ORIGIN", stdout); break;
+       case DF_SYMBOLIC:       fputs ("SYMBOLIC", stdout); break;
+       case DF_TEXTREL:        fputs ("TEXTREL", stdout); break;
+       case DF_BIND_NOW:       fputs ("BIND_NOW", stdout); break;
+       case DF_STATIC_TLS:     fputs ("STATIC_TLS", stdout); break;
+       default:                fputs ("unknown", stdout); break;
        }
-
-      p = strchr (p, '\0');
     }
-  return buff;
+  puts ("");
 }
 
 /* Parse and display the contents of the dynamic section.  */
@@ -5524,7 +5626,7 @@ process_dynamic_section (FILE *file)
        {
        case DT_FLAGS:
          if (do_dynamic)
-           puts (get_dynamic_flags (entry->d_un.d_val));
+           print_dynamic_flags (entry->d_un.d_val);
          break;
 
        case DT_AUXILIARY:
@@ -6333,11 +6435,12 @@ get_symbol_binding (unsigned int binding)
     case STB_WEAK:     return "WEAK";
     default:
       if (binding >= STB_LOPROC && binding <= STB_HIPROC)
-       sprintf (buff, _("<processor specific>: %d"), binding);
+       snprintf (buff, sizeof (buff), _("<processor specific>: %d"),
+                 binding);
       else if (binding >= STB_LOOS && binding <= STB_HIOS)
-       sprintf (buff, _("<OS specific>: %d"), binding);
+       snprintf (buff, sizeof (buff), _("<OS specific>: %d"), binding);
       else
-       sprintf (buff, _("<unknown>: %d"), binding);
+       snprintf (buff, sizeof (buff), _("<unknown>: %d"), binding);
       return buff;
     }
 }
@@ -6368,7 +6471,7 @@ get_symbol_type (unsigned int type)
          if (elf_header.e_machine == EM_PARISC && type == STT_PARISC_MILLI)
            return "PARISC_MILLI";
 
-         sprintf (buff, _("<processor specific>: %d"), type);
+         snprintf (buff, sizeof (buff), _("<processor specific>: %d"), type);
        }
       else if (type >= STT_LOOS && type <= STT_HIOS)
        {
@@ -6380,10 +6483,10 @@ get_symbol_type (unsigned int type)
                return "HP_STUB";
            }
 
-         sprintf (buff, _("<OS specific>: %d"), type);
+         snprintf (buff, sizeof (buff), _("<OS specific>: %d"), type);
        }
       else
-       sprintf (buff, _("<unknown>: %d"), type);
+       snprintf (buff, sizeof (buff), _("<unknown>: %d"), type);
       return buff;
     }
 }
@@ -6430,13 +6533,13 @@ get_symbol_index_type (unsigned int type)
   return buff;
 }
 
-static int *
-get_dynamic_data (FILE *file, unsigned int number)
+static bfd_vma *
+get_dynamic_data (FILE *file, unsigned int number, unsigned int ent_size)
 {
   unsigned char *e_data;
-  int *i_data;
+  bfd_vma *i_data;
 
-  e_data = malloc (number * 4);
+  e_data = malloc (number * ent_size);
 
   if (e_data == NULL)
     {
@@ -6444,7 +6547,7 @@ get_dynamic_data (FILE *file, unsigned int number)
       return NULL;
     }
 
-  if (fread (e_data, 4, number, file) != number)
+  if (fread (e_data, ent_size, number, file) != number)
     {
       error (_("Unable to read in dynamic data\n"));
       return NULL;
@@ -6460,7 +6563,7 @@ get_dynamic_data (FILE *file, unsigned int number)
     }
 
   while (number--)
-    i_data[number] = byte_get (e_data + number * 4, 4);
+    i_data[number] = byte_get (e_data + number * ent_size, ent_size);
 
   free (e_data);
 
@@ -6472,12 +6575,10 @@ static int
 process_symbol_table (FILE *file)
 {
   Elf_Internal_Shdr *section;
-  unsigned char nb[4];
-  unsigned char nc[4];
-  int nbuckets = 0;
-  int nchains = 0;
-  int *buckets = NULL;
-  int *chains = NULL;
+  bfd_vma nbuckets = 0;
+  bfd_vma nchains = 0;
+  bfd_vma *buckets = NULL;
+  bfd_vma *chains = NULL;
 
   if (! do_syms && !do_histogram)
     return 1;
@@ -6485,6 +6586,16 @@ process_symbol_table (FILE *file)
   if (dynamic_info[DT_HASH] && ((do_using_dynamic && dynamic_strings != NULL)
                                || do_histogram))
     {
+      unsigned char nb[8];
+      unsigned char nc[8];
+      int hash_ent_size = 4;
+
+      if ((elf_header.e_machine == EM_ALPHA
+          || elf_header.e_machine == EM_S390
+          || elf_header.e_machine == EM_S390_OLD)
+         && elf_header.e_ident[EI_CLASS] == ELFCLASS64)
+       hash_ent_size = 8;
+
       if (fseek (file,
                 (archive_file_offset
                  + offset_from_vma (file, dynamic_info[DT_HASH],
@@ -6495,23 +6606,23 @@ process_symbol_table (FILE *file)
          return 0;
        }
 
-      if (fread (nb, sizeof (nb), 1, file) != 1)
+      if (fread (nb, hash_ent_size, 1, file) != 1)
        {
          error (_("Failed to read in number of buckets\n"));
          return 0;
        }
 
-      if (fread (nc, sizeof (nc), 1, file) != 1)
+      if (fread (nc, hash_ent_size, 1, file) != 1)
        {
          error (_("Failed to read in number of chains\n"));
          return 0;
        }
 
-      nbuckets = byte_get (nb, 4);
-      nchains  = byte_get (nc, 4);
+      nbuckets = byte_get (nb, hash_ent_size);
+      nchains  = byte_get (nc, hash_ent_size);
 
-      buckets = get_dynamic_data (file, nbuckets);
-      chains  = get_dynamic_data (file, nchains);
+      buckets = get_dynamic_data (file, nbuckets, hash_ent_size);
+      chains  = get_dynamic_data (file, nchains, hash_ent_size);
 
       if (buckets == NULL || chains == NULL)
        return 0;
@@ -6520,8 +6631,8 @@ process_symbol_table (FILE *file)
   if (do_syms
       && dynamic_info[DT_HASH] && do_using_dynamic && dynamic_strings != NULL)
     {
-      int hn;
-      int si;
+      unsigned long hn;
+      bfd_vma si;
 
       printf (_("\nSymbol table for image:\n"));
       if (is_32bit_elf)
@@ -6537,12 +6648,16 @@ process_symbol_table (FILE *file)
          for (si = buckets[hn]; si < nchains && si > 0; si = chains[si])
            {
              Elf_Internal_Sym *psym;
+             int n;
 
              psym = dynamic_symbols + si;
 
-             printf ("  %3d %3d: ", si, hn);
+             n = print_vma (si, DEC_5);
+             if (n < 5)
+               fputs ("     " + n, stdout);
+             printf (" %3lu: ", hn);
              print_vma (psym->st_value, LONG_HEX);
-             putchar (' ' );
+             putchar (' ');
              print_vma (psym->st_size, DEC_5);
 
              printf ("  %6s", get_symbol_type (ELF_ST_TYPE (psym->st_info)));
@@ -6760,19 +6875,19 @@ process_symbol_table (FILE *file)
 
   if (do_histogram && buckets != NULL)
     {
-      int *lengths;
-      int *counts;
-      int hn;
-      int si;
-      int maxlength = 0;
-      int nzero_counts = 0;
-      int nsyms = 0;
+      unsigned long *lengths;
+      unsigned long *counts;
+      unsigned long hn;
+      bfd_vma si;
+      unsigned long maxlength = 0;
+      unsigned long nzero_counts = 0;
+      unsigned long nsyms = 0;
 
-      printf (_("\nHistogram for bucket list length (total of %d buckets):\n"),
-             nbuckets);
+      printf (_("\nHistogram for bucket list length (total of %lu buckets):\n"),
+             (unsigned long) nbuckets);
       printf (_(" Length  Number     %% of total  Coverage\n"));
 
-      lengths = calloc (nbuckets, sizeof (int));
+      lengths = calloc (nbuckets, sizeof (*lengths));
       if (lengths == NULL)
        {
          error (_("Out of memory"));
@@ -6780,9 +6895,6 @@ process_symbol_table (FILE *file)
        }
       for (hn = 0; hn < nbuckets; ++hn)
        {
-         if (! buckets[hn])
-           continue;
-
          for (si = buckets[hn]; si > 0 && si < nchains; si = chains[si])
            {
              ++nsyms;
@@ -6791,7 +6903,7 @@ process_symbol_table (FILE *file)
            }
        }
 
-      counts = calloc (maxlength + 1, sizeof (int));
+      counts = calloc (maxlength + 1, sizeof (*counts));
       if (counts == NULL)
        {
          error (_("Out of memory"));
@@ -6803,13 +6915,14 @@ process_symbol_table (FILE *file)
 
       if (nbuckets > 0)
        {
-         printf ("      0  %-10d (%5.1f%%)\n",
+         unsigned long i;
+         printf ("      0  %-10lu (%5.1f%%)\n",
                  counts[0], (counts[0] * 100.0) / nbuckets);
-         for (si = 1; si <= maxlength; ++si)
+         for (i = 1; i <= maxlength; ++i)
            {
-             nzero_counts += counts[si] * si;
-             printf ("%7d  %-10d (%5.1f%%)    %5.1f%%\n",
-                     si, counts[si], (counts[si] * 100.0) / nbuckets,
+             nzero_counts += counts[i] * i;
+             printf ("%7lu  %-10lu (%5.1f%%)    %5.1f%%\n",
+                     i, counts[i], (counts[i] * 100.0) / nbuckets,
                      (nzero_counts * 100.0) / nsyms);
            }
        }
@@ -6996,7 +7109,7 @@ dump_section (Elf_Internal_Shdr *section, FILE *file)
 
 
 static unsigned long int
-read_leb128 (unsigned char *data, int *length_return, int sign)
+read_leb128 (unsigned char *data, unsigned int *length_return, int sign)
 {
   unsigned long int result = 0;
   unsigned int num_read = 0;
@@ -7060,7 +7173,7 @@ static int
 process_extended_line_op (unsigned char *data, int is_stmt, int pointer_size)
 {
   unsigned char op_code;
-  int bytes_read;
+  unsigned int bytes_read;
   unsigned int len;
   unsigned char *name;
   unsigned long adr;
@@ -7287,7 +7400,7 @@ debug_apply_rela_addends (FILE *file,
                     example of this see the _clz.o binary in libgcc.a.  */
                  && ELF32_ST_TYPE (sym->st_info) != STT_OBJECT)
                {
-                 warn (_("%s: skipping unexpected symbol type %s in relocation in section .rela%s\n"),
+                 warn (_("skipping unexpected symbol type %s in relocation in section .rela%s\n"),
                        get_symbol_type (ELF32_ST_TYPE (sym->st_info)),
                        SECTION_NAME (section));
                  continue;
@@ -7295,6 +7408,18 @@ debug_apply_rela_addends (FILE *file,
            }
          else
            {
+             /* In MIPS little-endian objects, r_info isn't really a
+                64-bit little-endian value: it has a 32-bit little-endian
+                symbol index followed by four individual byte fields.
+                Reorder INFO accordingly.  */
+             if (elf_header.e_machine == EM_MIPS
+                 && elf_header.e_ident[EI_DATA] != ELFDATA2MSB)
+               rp->r_info = (((rp->r_info & 0xffffffff) << 32)
+                             | ((rp->r_info >> 56) & 0xff)
+                             | ((rp->r_info >> 40) & 0xff00)
+                             | ((rp->r_info >> 24) & 0xff0000)
+                             | ((rp->r_info >> 8) & 0xff000000));
+
              sym = symtab + ELF64_R_SYM (rp->r_info);
 
              if (ELF64_R_SYM (rp->r_info) != 0
@@ -7430,7 +7555,7 @@ process_abbrev_section (unsigned char *start, unsigned char *end)
 
   while (start < end)
     {
-      int bytes_read;
+      unsigned int bytes_read;
       unsigned long entry;
       unsigned long tag;
       unsigned long attribute;
@@ -7545,7 +7670,7 @@ get_TAG_name (unsigned long tag)
       {
        static char buffer[100];
 
-       sprintf (buffer, _("Unknown TAG value: %lx"), tag);
+       snprintf (buffer, sizeof (buffer), _("Unknown TAG value: %lx"), tag);
        return buffer;
       }
     }
@@ -7581,7 +7706,7 @@ get_FORM_name (unsigned long form)
       {
        static char buffer[100];
 
-       sprintf (buffer, _("Unknown FORM value: %lx"), form);
+       snprintf (buffer, sizeof (buffer), _("Unknown FORM value: %lx"), form);
        return buffer;
       }
     }
@@ -7605,7 +7730,7 @@ decode_location_expression (unsigned char * data,
                            unsigned long cu_offset)
 {
   unsigned op;
-  int bytes_read;
+  unsigned int bytes_read;
   unsigned long uvalue;
   unsigned char *end = data + length;
   int need_frame_base = 0;
@@ -7975,7 +8100,7 @@ read_and_display_attr_value (unsigned long attribute,
 {
   unsigned long uvalue = 0;
   unsigned char *block_start = NULL;
-  int bytes_read;
+  unsigned int bytes_read;
 
   switch (form)
     {
@@ -8514,7 +8639,8 @@ get_AT_name (unsigned long attribute)
       {
        static char buffer[100];
 
-       sprintf (buffer, _("Unknown AT value: %lx"), attribute);
+       snprintf (buffer, sizeof (buffer), _("Unknown AT value: %lx"),
+                 attribute);
        return buffer;
       }
     }
@@ -8714,7 +8840,7 @@ process_debug_info (Elf_Internal_Shdr *section, unsigned char *start,
       level = 0;
       while (tags < start)
        {
-         int bytes_read;
+         unsigned int bytes_read;
          unsigned long abbrev_number;
          abbrev_entry *entry;
          abbrev_attr *attr;
@@ -9016,7 +9142,7 @@ display_debug_lines (Elf_Internal_Shdr *section,
          while (*data != 0)
            {
              unsigned char *name;
-             int bytes_read;
+             unsigned int bytes_read;
 
              printf (_("  %d\t"), ++state_machine_regs.last_file_entry);
              name = data;
@@ -9043,7 +9169,7 @@ display_debug_lines (Elf_Internal_Shdr *section,
        {
          unsigned char op_code;
          int adv;
-         int bytes_read;
+         unsigned int bytes_read;
 
          op_code = *data++;
 
@@ -9291,7 +9417,7 @@ display_debug_macinfo (Elf_Internal_Shdr *section,
        case DW_MACINFO_define:
          lineno = read_leb128 (curr, & bytes_read, 0);
          curr += bytes_read;
-         string = curr;
+         string = (char *) curr;
          curr += strlen (string) + 1;
          printf (_(" DW_MACINFO_define - lineno : %d macro : %s\n"),
                  lineno, string);
@@ -9300,7 +9426,7 @@ display_debug_macinfo (Elf_Internal_Shdr *section,
        case DW_MACINFO_undef:
          lineno = read_leb128 (curr, & bytes_read, 0);
          curr += bytes_read;
-         string = curr;
+         string = (char *) curr;
          curr += strlen (string) + 1;
          printf (_(" DW_MACINFO_undef - lineno : %d macro : %s\n"),
                  lineno, string);
@@ -9312,7 +9438,7 @@ display_debug_macinfo (Elf_Internal_Shdr *section,
 
            constant = read_leb128 (curr, & bytes_read, 0);
            curr += bytes_read;
-           string = curr;
+           string = (char *) curr;
            curr += strlen (string) + 1;
            printf (_(" DW_MACINFO_vendor_ext - constant : %d string : %s\n"),
                    constant, string);
@@ -9815,7 +9941,10 @@ display_debug_ranges (Elf_Internal_Shdr *section,
              start += pointer_size;
 
              if (begin == 0 && end == 0)
-               break;
+               {
+                 printf (_("    %8.8lx <End of list>\n"), offset);
+                 break;
+               }
 
              /* Check base address specifiers.  */
              if (begin == -1UL && end != -1UL)
@@ -9836,7 +9965,6 @@ display_debug_ranges (Elf_Internal_Shdr *section,
 
              putchar ('\n');
            }
-         fputs (_("  <End of list>\n"), stdout);
        }
     }
   putchar ('\n');
@@ -9991,7 +10119,7 @@ display_debug_frames (Elf_Internal_Shdr *section,
   Frame_Chunk *remembered_state = 0;
   Frame_Chunk *rs;
   int is_eh = streq (SECTION_NAME (section), ".eh_frame");
-  int length_return;
+  unsigned int length_return;
   int max_regs = 0;
 
   printf (_("The section %s contains:\n"), SECTION_NAME (section));
@@ -10059,8 +10187,8 @@ display_debug_frames (Elf_Internal_Shdr *section,
 
          version = *start++;
 
-         fc->augmentation = start;
-         start = strchr (start, '\0') + 1;
+         fc->augmentation = (char *) start;
+         start = (unsigned char *) strchr ((char *) start, '\0') + 1;
 
          if (fc->augmentation[0] == 'z')
            {
@@ -10136,7 +10264,7 @@ display_debug_frames (Elf_Internal_Shdr *section,
          if (augmentation_data_len)
            {
              unsigned char *p, *q;
-             p = fc->augmentation + 1;
+             p = (unsigned char *) fc->augmentation + 1;
              q = augmentation_data;
 
              while (1)
@@ -10594,6 +10722,7 @@ display_debug_frames (Elf_Internal_Shdr *section,
            case DW_CFA_def_cfa_sf:
              fc->cfa_reg = LEB ();
              fc->cfa_offset = SLEB ();
+             fc->cfa_offset = fc->cfa_offset * fc->data_factor;
              fc->cfa_exp = 0;
              if (! do_debug_frames_interp)
                printf ("  DW_CFA_def_cfa_sf: r%d ofs %d\n",
@@ -10602,6 +10731,7 @@ display_debug_frames (Elf_Internal_Shdr *section,
 
            case DW_CFA_def_cfa_offset_sf:
              fc->cfa_offset = SLEB ();
+             fc->cfa_offset = fc->cfa_offset * fc->data_factor;
              if (! do_debug_frames_interp)
                printf ("  DW_CFA_def_cfa_offset_sf: %d\n", fc->cfa_offset);
              break;
@@ -10673,7 +10803,7 @@ display_debug_not_supported (Elf_Internal_Shdr *section,
 
 /* A structure containing the name of a debug section
    and a pointer to a function that can decode it.  */
-struct
+static struct
 {
   const char *const name;
   int (*display) (Elf_Internal_Shdr *, unsigned char *, FILE *);
@@ -10871,9 +11001,10 @@ process_mips_specific (FILE *file)
              liblist.l_flags = BYTE_GET (elib[cnt].l_flags);
 
              tmp = gmtime (&time);
-             sprintf (timebuf, "%04u-%02u-%02uT%02u:%02u:%02u",
-                      tmp->tm_year + 1900, tmp->tm_mon + 1, tmp->tm_mday,
-                      tmp->tm_hour, tmp->tm_min, tmp->tm_sec);
+             snprintf (timebuf, sizeof (timebuf),
+                       "%04u-%02u-%02uT%02u:%02u:%02u",
+                       tmp->tm_year + 1900, tmp->tm_mon + 1, tmp->tm_mday,
+                       tmp->tm_hour, tmp->tm_min, tmp->tm_sec);
 
              printf ("%3lu: ", (unsigned long) cnt);
              if (VALID_DYNAMIC_NAME (liblist.l_name))
@@ -11017,7 +11148,7 @@ process_mips_specific (FILE *file)
                      reginfo.ri_cprmask[1] = BYTE_GET (ereg->ri_cprmask[1]);
                      reginfo.ri_cprmask[2] = BYTE_GET (ereg->ri_cprmask[2]);
                      reginfo.ri_cprmask[3] = BYTE_GET (ereg->ri_cprmask[3]);
-                     reginfo.ri_gp_value   = BYTE_GET8 (ereg->ri_gp_value);
+                     reginfo.ri_gp_value   = BYTE_GET (ereg->ri_gp_value);
 
                      printf ("GPR %08lx  GP 0x",
                              reginfo.ri_gprmask);
@@ -11249,9 +11380,10 @@ process_gnu_liblist (FILE *file)
              liblist.l_flags = BYTE_GET (elib[cnt].l_flags);
 
              tmp = gmtime (&time);
-             sprintf (timebuf, "%04u-%02u-%02uT%02u:%02u:%02u",
-                      tmp->tm_year + 1900, tmp->tm_mon + 1, tmp->tm_mday,
-                      tmp->tm_hour, tmp->tm_min, tmp->tm_sec);
+             snprintf (timebuf, sizeof (timebuf),
+                       "%04u-%02u-%02uT%02u:%02u:%02u",
+                       tmp->tm_year + 1900, tmp->tm_mon + 1, tmp->tm_mday,
+                       tmp->tm_hour, tmp->tm_min, tmp->tm_sec);
 
              printf ("%3lu: ", (unsigned long) cnt);
              if (do_wide)
@@ -11315,7 +11447,7 @@ get_note_type (unsigned e_type)
        break;
       }
 
-  sprintf (buff, _("Unknown note type: (0x%08x)"), e_type);
+  snprintf (buff, sizeof (buff), _("Unknown note type: (0x%08x)"), e_type);
   return buff;
 }
 
@@ -11337,7 +11469,7 @@ get_netbsd_elfcore_note_type (unsigned e_type)
 
   if (e_type < NT_NETBSDCORE_FIRSTMACH)
     {
-      sprintf (buff, _("Unknown note type: (0x%08x)"), e_type);
+      snprintf (buff, sizeof (buff), _("Unknown note type: (0x%08x)"), e_type);
       return buff;
     }
 
@@ -11376,7 +11508,8 @@ get_netbsd_elfcore_note_type (unsigned e_type)
        }
     }
 
-  sprintf (buff, _("PT_FIRSTMACH+%d"), e_type - NT_NETBSDCORE_FIRSTMACH);
+  snprintf (buff, sizeof (buff), _("PT_FIRSTMACH+%d"),
+           e_type - NT_NETBSDCORE_FIRSTMACH);
   return buff;
 }
 
@@ -11638,9 +11771,9 @@ get_file_header (FILE *file)
       elf_header.e_type      = BYTE_GET (ehdr64.e_type);
       elf_header.e_machine   = BYTE_GET (ehdr64.e_machine);
       elf_header.e_version   = BYTE_GET (ehdr64.e_version);
-      elf_header.e_entry     = BYTE_GET8 (ehdr64.e_entry);
-      elf_header.e_phoff     = BYTE_GET8 (ehdr64.e_phoff);
-      elf_header.e_shoff     = BYTE_GET8 (ehdr64.e_shoff);
+      elf_header.e_entry     = BYTE_GET (ehdr64.e_entry);
+      elf_header.e_phoff     = BYTE_GET (ehdr64.e_phoff);
+      elf_header.e_shoff     = BYTE_GET (ehdr64.e_shoff);
       elf_header.e_flags     = BYTE_GET (ehdr64.e_flags);
       elf_header.e_ehsize    = BYTE_GET (ehdr64.e_ehsize);
       elf_header.e_phentsize = BYTE_GET (ehdr64.e_phentsize);