include/elf/
[deliverable/binutils-gdb.git] / binutils / readelf.c
index e51e8b013ca0ee9f405ab8230623d81e355e9994..ae13b3ebc1d7c6c8344f5122431b4a0d090006cb 100644 (file)
@@ -1,6 +1,6 @@
 /* readelf.c -- display contents of an ELF format file
-   Copyright 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007
-   Free Software Foundation, Inc.
+   Copyright 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007,
+   2008  Free Software Foundation, Inc.
 
    Originally developed by Eric Youngdale <eric@andante.jic.com>
    Modifications by Nick Clifton <nickc@redhat.com>
@@ -276,22 +276,6 @@ static void (*byte_put) (unsigned char *, bfd_vma, int);
   : ((X)->sh_name >= string_table_length ? "<corrupt>" \
   : string_table + (X)->sh_name))
 
-/* Given st_shndx I, map to section_headers index.  */
-#define SECTION_HEADER_INDEX(I)                                \
-  ((I) < SHN_LORESERVE                                 \
-   ? (I)                                               \
-   : ((I) <= SHN_HIRESERVE                             \
-      ? 0                                              \
-      : (I) - (SHN_HIRESERVE + 1 - SHN_LORESERVE)))
-
-/* Reverse of the above.  */
-#define SECTION_HEADER_NUM(N)                          \
-  ((N) < SHN_LORESERVE                                 \
-   ? (N)                                               \
-   : (N) + (SHN_HIRESERVE + 1 - SHN_LORESERVE))
-
-#define SECTION_HEADER(I) (section_headers + SECTION_HEADER_INDEX (I))
-
 #define DT_VERSIONTAGIDX(tag)  (DT_VERNEEDNUM - (tag)) /* Reverse order!  */
 
 #define BYTE_GET(field)        byte_get (field, sizeof (field))
@@ -493,7 +477,11 @@ print_vma (bfd_vma vma, print_mode mode)
 #if BFD_HOST_64BIT_LONG
          return nc + printf ("%lx", vma);
 #elif BFD_HOST_64BIT_LONG_LONG
+#ifndef __MSVCRT__
          return nc + printf ("%llx", vma);
+#else
+         return nc + printf ("%I64x", vma);
+#endif
 #else
          return nc + print_hex_vma (vma);
 #endif
@@ -502,7 +490,11 @@ print_vma (bfd_vma vma, print_mode mode)
 #if BFD_HOST_64BIT_LONG
          return printf ("%ld", vma);
 #elif BFD_HOST_64BIT_LONG_LONG
+#ifndef __MSVCRT__
          return printf ("%lld", vma);
+#else
+         return printf ("%I64d", vma);
+#endif
 #else
          return print_dec_vma (vma, 1);
 #endif
@@ -514,10 +506,17 @@ print_vma (bfd_vma vma, print_mode mode)
          else
            return printf ("%#lx", vma);
 #elif BFD_HOST_64BIT_LONG_LONG
+#ifndef __MSVCRT__
          if (vma <= 99999)
            return printf ("%5lld", vma);
          else
            return printf ("%#llx", vma);
+#else
+         if (vma <= 99999)
+           return printf ("%5I64d", vma);
+         else
+           return printf ("%#I64x", vma);
+#endif
 #else
          if (vma <= 99999)
            return printf ("%5ld", _bfd_int64_low (vma));
@@ -529,7 +528,11 @@ print_vma (bfd_vma vma, print_mode mode)
 #if BFD_HOST_64BIT_LONG
          return printf ("%lu", vma);
 #elif BFD_HOST_64BIT_LONG_LONG
+#ifndef __MSVCRT__
          return printf ("%llu", vma);
+#else
+         return printf ("%I64u", vma);
+#endif
 #else
          return print_dec_vma (vma, 0);
 #endif
@@ -605,7 +608,7 @@ find_section (const char *name)
 /* Guess the relocation size commonly used by the specific machines.  */
 
 static int
-guess_is_rela (unsigned long e_machine)
+guess_is_rela (unsigned int e_machine)
 {
   switch (e_machine)
     {
@@ -846,10 +849,40 @@ slurp_rel_relocs (FILE *file,
   return 1;
 }
 
+/* Returns the reloc type extracted from the reloc info field.  */
+
+static unsigned int
+get_reloc_type (bfd_vma reloc_info)
+{
+  if (is_32bit_elf)
+    return ELF32_R_TYPE (reloc_info);
+
+  switch (elf_header.e_machine)
+    {
+    case EM_MIPS:
+      /* Note: We assume that reloc_info has already been adjusted for us.  */
+      return ELF64_MIPS_R_TYPE (reloc_info);
+
+    case EM_SPARCV9:
+      return ELF64_R_TYPE_ID (reloc_info);
+
+    default:
+      return ELF64_R_TYPE (reloc_info);
+    }
+}
+
+/* Return the symbol index extracted from the reloc info field.  */
+
+static bfd_vma
+get_reloc_symindex (bfd_vma reloc_info)
+{
+  return is_32bit_elf ? ELF32_R_SYM (reloc_info) : ELF64_R_SYM (reloc_info);
+}
+
 /* Display the contents of the relocation data found at the specified
    offset.  */
 
-static int
+static void
 dump_relocations (FILE *file,
                  unsigned long rel_offset,
                  unsigned long rel_size,
@@ -869,12 +902,12 @@ dump_relocations (FILE *file,
   if (is_rela)
     {
       if (!slurp_rela_relocs (file, rel_offset, rel_size, &rels, &rel_size))
-       return 0;
+       return;
     }
   else
     {
       if (!slurp_rel_relocs (file, rel_offset, rel_size, &rels, &rel_size))
-       return 0;
+       return;
     }
 
   if (is_32bit_elf)
@@ -915,53 +948,36 @@ dump_relocations (FILE *file,
   for (i = 0; i < rel_size; i++)
     {
       const char *rtype;
-      const char *rtype2 = NULL;
-      const char *rtype3 = NULL;
       bfd_vma offset;
       bfd_vma info;
       bfd_vma symtab_index;
       bfd_vma type;
-      bfd_vma type2 = 0;
-      bfd_vma type3 = 0;
 
       offset = rels[i].r_offset;
       info   = rels[i].r_info;
 
-      if (is_32bit_elf)
+      /* The #ifdef BFD64 below is to prevent a compile time warning.
+        We know that if we do not have a 64 bit data type that we
+        will never execute this code anyway.  */
+#ifdef BFD64
+      if (!is_32bit_elf
+         && elf_header.e_machine == EM_MIPS
+         && elf_header.e_ident[EI_DATA] != ELFDATA2MSB)
        {
-         type         = ELF32_R_TYPE (info);
-         symtab_index = ELF32_R_SYM  (info);
+         /* In 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.  */
+         info = (((info & 0xffffffff) << 32)
+                 | ((info >> 56) & 0xff)
+                 | ((info >> 40) & 0xff00)
+                 | ((info >> 24) & 0xff0000)
+                 | ((info >> 8) & 0xff000000));
        }
-      else
-       {
-         /* The #ifdef BFD64 below is to prevent a compile time warning.
-            We know that if we do not have a 64 bit data type that we
-            will never execute this code anyway.  */
-#ifdef BFD64
-         if (elf_header.e_machine == EM_MIPS)
-           {
-             /* In 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_ident[EI_DATA] != ELFDATA2MSB)
-               info = (((info & 0xffffffff) << 32)
-                       | ((info >> 56) & 0xff)
-                       | ((info >> 40) & 0xff00)
-                       | ((info >> 24) & 0xff0000)
-                       | ((info >> 8) & 0xff000000));
-             type  = ELF64_MIPS_R_TYPE (info);
-             type2 = ELF64_MIPS_R_TYPE2 (info);
-             type3 = ELF64_MIPS_R_TYPE3 (info);
-           }
-         else if (elf_header.e_machine == EM_SPARCV9)
-           type = ELF64_R_TYPE_ID (info);
-         else
-           type = ELF64_R_TYPE (info);
+#endif /* BFD64 */
 
-         symtab_index = ELF64_R_SYM  (info);
-#endif
-       }
+      type = get_reloc_type (info);
+      symtab_index = get_reloc_symindex  (info);
 
       if (is_32bit_elf)
        {
@@ -977,10 +993,17 @@ dump_relocations (FILE *file,
                  : "%12.12lx  %12.12lx ",
                  offset, info);
 #elif BFD_HOST_64BIT_LONG_LONG
+#ifndef __MSVCRT__
          printf (do_wide
                  ? "%16.16llx  %16.16llx "
                  : "%12.12llx  %12.12llx ",
                  offset, info);
+#else
+         printf (do_wide
+                 ? "%16.16I64x  %16.16I64x "
+                 : "%12.12I64x  %12.12I64x ",
+                 offset, info);
+#endif
 #else
          printf (do_wide
                  ? "%8.8lx%8.8lx  %8.8lx%8.8lx "
@@ -1103,11 +1126,6 @@ dump_relocations (FILE *file,
        case EM_MIPS:
        case EM_MIPS_RS3_LE:
          rtype = elf_mips_reloc_type (type);
-         if (!is_32bit_elf)
-           {
-             rtype2 = elf_mips_reloc_type (type2);
-             rtype3 = elf_mips_reloc_type (type3);
-           }
          break;
 
        case EM_ALPHA:
@@ -1268,16 +1286,9 @@ dump_relocations (FILE *file,
 
                  if (ELF_ST_TYPE (psym->st_info) == STT_SECTION)
                    {
-                     bfd_vma sec_index = (bfd_vma) -1;
-
-                     if (psym->st_shndx < SHN_LORESERVE)
-                       sec_index = psym->st_shndx;
-                     else if (psym->st_shndx > SHN_HIRESERVE)
-                       sec_index = psym->st_shndx - (SHN_HIRESERVE + 1
-                                                     - SHN_LORESERVE);
-
-                     if (sec_index != (bfd_vma) -1)
-                       sec_name = SECTION_NAME (section_headers + sec_index);
+                     if (psym->st_shndx < elf_header.e_shnum)
+                       sec_name
+                         = SECTION_NAME (section_headers + psym->st_shndx);
                      else if (psym->st_shndx == SHN_ABS)
                        sec_name = "ABS";
                      else if (psym->st_shndx == SHN_COMMON)
@@ -1295,6 +1306,11 @@ dump_relocations (FILE *file,
                               && elf_header.e_ident[EI_OSABI] == ELFOSABI_HPUX
                               && psym->st_shndx == SHN_IA_64_ANSI_COMMON)
                        sec_name = "ANSI_COM";
+                     else if (elf_header.e_machine == EM_IA_64
+                              && (elf_header.e_ident[EI_OSABI] 
+                                  == ELFOSABI_OPENVMS)
+                              && psym->st_shndx == SHN_IA_64_VMS_SYMVEC)
+                       sec_name = "VMS_SYMVEC";
                      else
                        {
                          sprintf (name_buf, "<section 0x%x>",
@@ -1329,8 +1345,14 @@ dump_relocations (FILE *file,
 
       putchar ('\n');
 
+#ifdef BFD64
       if (! is_32bit_elf && elf_header.e_machine == EM_MIPS)
        {
+         bfd_vma type2 = ELF64_MIPS_R_TYPE2 (info);
+         bfd_vma type3 = ELF64_MIPS_R_TYPE3 (info);
+         const char *rtype2 = elf_mips_reloc_type (type2);
+         const char *rtype3 = elf_mips_reloc_type (type3);
+
          printf ("                    Type2: ");
 
          if (rtype2 == NULL)
@@ -1349,11 +1371,10 @@ dump_relocations (FILE *file,
 
          putchar ('\n');
        }
+#endif /* BFD64 */
     }
 
   free (rels);
-
-  return 1;
 }
 
 static const char *
@@ -1483,7 +1504,37 @@ get_ia64_dynamic_type (unsigned long type)
 {
   switch (type)
     {
-    case DT_IA_64_PLT_RESERVE: return "IA_64_PLT_RESERVE";
+    case DT_IA_64_PLT_RESERVE:         return "IA_64_PLT_RESERVE";
+    case DT_IA_64_VMS_SUBTYPE:         return "VMS_SUBTYPE";
+    case DT_IA_64_VMS_IMGIOCNT:        return "VMS_IMGIOCNT";
+    case DT_IA_64_VMS_LNKFLAGS:        return "VMS_LNKFLAGS";
+    case DT_IA_64_VMS_VIR_MEM_BLK_SIZ: return "VMS_VIR_MEM_BLK_SIZ";
+    case DT_IA_64_VMS_IDENT:           return "VMS_IDENT";
+    case DT_IA_64_VMS_NEEDED_IDENT:    return "VMS_NEEDED_IDENT";
+    case DT_IA_64_VMS_IMG_RELA_CNT:    return "VMS_IMG_RELA_CNT";
+    case DT_IA_64_VMS_SEG_RELA_CNT:    return "VMS_SEG_RELA_CNT";
+    case DT_IA_64_VMS_FIXUP_RELA_CNT:  return "VMS_FIXUP_RELA_CNT";
+    case DT_IA_64_VMS_FIXUP_NEEDED:    return "VMS_FIXUP_NEEDED";
+    case DT_IA_64_VMS_SYMVEC_CNT:      return "VMS_SYMVEC_CNT";
+    case DT_IA_64_VMS_XLATED:          return "VMS_XLATED";
+    case DT_IA_64_VMS_STACKSIZE:       return "VMS_STACKSIZE";
+    case DT_IA_64_VMS_UNWINDSZ:        return "VMS_UNWINDSZ";
+    case DT_IA_64_VMS_UNWIND_CODSEG:   return "VMS_UNWIND_CODSEG";
+    case DT_IA_64_VMS_UNWIND_INFOSEG:  return "VMS_UNWIND_INFOSEG";
+    case DT_IA_64_VMS_LINKTIME:        return "VMS_LINKTIME";
+    case DT_IA_64_VMS_SEG_NO:          return "VMS_SEG_NO";
+    case DT_IA_64_VMS_SYMVEC_OFFSET:   return "VMS_SYMVEC_OFFSET";
+    case DT_IA_64_VMS_SYMVEC_SEG:      return "VMS_SYMVEC_SEG";
+    case DT_IA_64_VMS_UNWIND_OFFSET:   return "VMS_UNWIND_OFFSET";
+    case DT_IA_64_VMS_UNWIND_SEG:      return "VMS_UNWIND_SEG";
+    case DT_IA_64_VMS_STRTAB_OFFSET:   return "VMS_STRTAB_OFFSET";
+    case DT_IA_64_VMS_SYSVER_OFFSET:   return "VMS_SYSVER_OFFSET";
+    case DT_IA_64_VMS_IMG_RELA_OFF:    return "VMS_IMG_RELA_OFF";
+    case DT_IA_64_VMS_SEG_RELA_OFF:    return "VMS_SEG_RELA_OFF";
+    case DT_IA_64_VMS_FIXUP_RELA_OFF:  return "VMS_FIXUP_RELA_OFF";
+    case DT_IA_64_VMS_PLTGOT_OFFSET:   return "VMS_PLTGOT_OFFSET";
+    case DT_IA_64_VMS_PLTGOT_SEG:      return "VMS_PLTGOT_SEG";
+    case DT_IA_64_VMS_FPMODE:          return "VMS_FPMODE";
     default:
       return NULL;
     }
@@ -1649,6 +1700,9 @@ get_dynamic_type (unsigned long type)
            case EM_PARISC:
              result = get_parisc_dynamic_type (type);
              break;
+           case EM_IA_64:
+             result = get_ia64_dynamic_type (type);
+             break;
            default:
              result = NULL;
              break;
@@ -2181,6 +2235,9 @@ get_machine_flags (unsigned e_flags, unsigned e_machine)
            case E_MIPS_MACH_5500: strcat (buf, ", 5500"); break;
            case E_MIPS_MACH_SB1:  strcat (buf, ", sb1");  break;
            case E_MIPS_MACH_9000: strcat (buf, ", 9000"); break;
+           case E_MIPS_MACH_LS2E: strcat (buf, ", loongson-2e"); break;
+           case E_MIPS_MACH_LS2F: strcat (buf, ", loongson-2f"); break;
+           case E_MIPS_MACH_OCTEON: strcat (buf, ", octeon"); break;
            case 0:
            /* We simply ignore the field in this case to avoid confusion:
               MIPS ELF does not specify EF_MIPS_MACH, it is a GNU
@@ -2616,9 +2673,16 @@ get_ia64_section_type_name (unsigned int sh_type)
 
   switch (sh_type)
     {
-    case SHT_IA_64_EXT:                  return "IA_64_EXT";
-    case SHT_IA_64_UNWIND:       return "IA_64_UNWIND";
-    case SHT_IA_64_PRIORITY_INIT: return "IA_64_PRIORITY_INIT";
+    case SHT_IA_64_EXT:                       return "IA_64_EXT";
+    case SHT_IA_64_UNWIND:            return "IA_64_UNWIND";
+    case SHT_IA_64_PRIORITY_INIT:      return "IA_64_PRIORITY_INIT";
+    case SHT_IA_64_VMS_TRACE:          return "VMS_TRACE";
+    case SHT_IA_64_VMS_TIE_SIGNATURES: return "VMS_TIE_SIGNATURES";
+    case SHT_IA_64_VMS_DEBUG:          return "VMS_DEBUG";
+    case SHT_IA_64_VMS_DEBUG_STR:      return "VMS_DEBUG_STR";
+    case SHT_IA_64_VMS_LINKAGES:       return "VMS_LINKAGES";
+    case SHT_IA_64_VMS_SYMBOL_VECTOR:  return "VMS_SYMBOL_VECTOR";
+    case SHT_IA_64_VMS_FIXUP:          return "VMS_FIXUP";
     default:
       break;
     }
@@ -2722,7 +2786,24 @@ get_section_type_name (unsigned int sh_type)
          sprintf (buff, "LOPROC+%x", sh_type - SHT_LOPROC);
        }
       else if ((sh_type >= SHT_LOOS) && (sh_type <= SHT_HIOS))
-       sprintf (buff, "LOOS+%x", sh_type - SHT_LOOS);
+       {
+         const char *result;
+
+         switch (elf_header.e_machine)
+           {
+           case EM_IA_64:
+             result = get_ia64_section_type_name (sh_type);
+             break;
+           default:
+             result = NULL;
+             break;
+           }
+
+         if (result != NULL)
+           return result;
+
+         sprintf (buff, "LOOS+%x", sh_type - SHT_LOOS);
+       }
       else if ((sh_type >= SHT_LOUSER) && (sh_type <= SHT_HIUSER))
        sprintf (buff, "LOUSER+%x", sh_type - SHT_LOUSER);
       else
@@ -2991,22 +3072,18 @@ parse_args (int argc, char **argv)
                switch (optarg[index++])
                  {
                  case 'i':
-                 case 'I':
                    do_debug_info = 1;
                    break;
 
                  case 'a':
-                 case 'A':
                    do_debug_abbrevs = 1;
                    break;
 
                  case 'l':
-                 case 'L':
                    do_debug_lines = 1;
                    break;
 
                  case 'p':
-                 case 'P':
                    do_debug_pubnames = 1;
                    break;
 
@@ -3025,17 +3102,14 @@ parse_args (int argc, char **argv)
                    break;
 
                  case 'm':
-                 case 'M':
                    do_debug_macinfo = 1;
                    break;
 
                  case 's':
-                 case 'S':
                    do_debug_str = 1;
                    break;
 
                  case 'o':
-                 case 'O':
                    do_debug_loc = 1;
                    break;
 
@@ -3205,6 +3279,8 @@ process_file_header (void)
       return 0;
     }
 
+  init_dwarf_regnames (elf_header.e_machine);
+
   if (do_header)
     {
       int i;
@@ -3257,31 +3333,26 @@ process_file_header (void)
              (long) elf_header.e_shentsize);
       printf (_("  Number of section headers:         %ld"),
              (long) elf_header.e_shnum);
-      if (section_headers != NULL && elf_header.e_shnum == 0)
+      if (section_headers != NULL && elf_header.e_shnum == SHN_UNDEF)
        printf (" (%ld)", (long) section_headers[0].sh_size);
       putc ('\n', stdout);
       printf (_("  Section header string table index: %ld"),
              (long) elf_header.e_shstrndx);
-      if (section_headers != NULL && elf_header.e_shstrndx == SHN_XINDEX)
+      if (section_headers != NULL
+         && elf_header.e_shstrndx == (SHN_XINDEX & 0xffff))
        printf (" (%ld)", (long) section_headers[0].sh_link);
-      else if (elf_header.e_shstrndx != SHN_UNDEF
-              && (elf_header.e_shstrndx >= elf_header.e_shnum
-                  || (elf_header.e_shstrndx >= SHN_LORESERVE
-                      && elf_header.e_shstrndx <= SHN_HIRESERVE)))
+      else if (elf_header.e_shstrndx >= elf_header.e_shnum)
        printf (" <corrupt: out of range>");
       putc ('\n', stdout);
     }
 
   if (section_headers != NULL)
     {
-      if (elf_header.e_shnum == 0)
+      if (elf_header.e_shnum == SHN_UNDEF)
        elf_header.e_shnum = section_headers[0].sh_size;
-      if (elf_header.e_shstrndx == SHN_XINDEX)
+      if (elf_header.e_shstrndx == (SHN_XINDEX & 0xffff))
        elf_header.e_shstrndx = section_headers[0].sh_link;
-      else if (elf_header.e_shstrndx != SHN_UNDEF
-              && (elf_header.e_shstrndx >= elf_header.e_shnum
-                  || (elf_header.e_shstrndx >= SHN_LORESERVE
-                      && elf_header.e_shstrndx <= SHN_HIRESERVE)))
+      else if (elf_header.e_shstrndx >= elf_header.e_shnum)
        elf_header.e_shstrndx = SHN_UNDEF;
       free (section_headers);
       section_headers = NULL;
@@ -3530,6 +3601,11 @@ process_program_headers (FILE *file)
          if (dynamic_addr)
            error (_("more than one dynamic segment\n"));
 
+         /* By default, assume that the .dynamic section is the first
+            section in the DYNAMIC segment.  */
+         dynamic_addr = segment->p_offset;
+         dynamic_size = segment->p_filesz;
+
          /* Try to locate the .dynamic section. If there is
             a section header table, we can easily locate it.  */
          if (section_headers != NULL)
@@ -3544,23 +3620,21 @@ process_program_headers (FILE *file)
                }
 
              if (sec->sh_type == SHT_NOBITS)
-               break;
+               {
+                 dynamic_size = 0;
+                 break;
+               }
 
              dynamic_addr = sec->sh_offset;
              dynamic_size = sec->sh_size;
 
              if (dynamic_addr < segment->p_offset
                  || dynamic_addr > segment->p_offset + segment->p_filesz)
-               warn (_("the .dynamic section is not contained within the dynamic segment\n"));
+               warn (_("the .dynamic section is not contained"
+                       " within the dynamic segment\n"));
              else if (dynamic_addr > segment->p_offset)
-               warn (_("the .dynamic section is not the first section in the dynamic segment.\n"));
-           }
-         else
-           {
-             /* Otherwise, we can only assume that the .dynamic
-                section is the first section in the DYNAMIC segment.  */
-             dynamic_addr = segment->p_offset;
-             dynamic_size = segment->p_filesz;
+               warn (_("the .dynamic section is not the first section"
+                       " in the dynamic segment.\n"));
            }
          break;
 
@@ -3751,7 +3825,7 @@ get_32bit_elf_symbols (FILE *file, Elf_Internal_Shdr *section)
   shndx = NULL;
   if (symtab_shndx_hdr != NULL
       && (symtab_shndx_hdr->sh_link
-         == (unsigned long) SECTION_HEADER_NUM (section - section_headers)))
+         == (unsigned long) (section - section_headers)))
     {
       shndx = get_data (NULL, file, symtab_shndx_hdr->sh_offset,
                        1, symtab_shndx_hdr->sh_size, _("symtab shndx"));
@@ -3782,9 +3856,11 @@ get_32bit_elf_symbols (FILE *file, Elf_Internal_Shdr *section)
       psym->st_value = BYTE_GET (esyms[j].st_value);
       psym->st_size  = BYTE_GET (esyms[j].st_size);
       psym->st_shndx = BYTE_GET (esyms[j].st_shndx);
-      if (psym->st_shndx == SHN_XINDEX && shndx != NULL)
+      if (psym->st_shndx == (SHN_XINDEX & 0xffff) && shndx != NULL)
        psym->st_shndx
          = byte_get ((unsigned char *) &shndx[j], sizeof (shndx[j]));
+      else if (psym->st_shndx >= (SHN_LORESERVE & 0xffff))
+       psym->st_shndx += SHN_LORESERVE - (SHN_LORESERVE & 0xffff);
       psym->st_info  = BYTE_GET (esyms[j].st_info);
       psym->st_other = BYTE_GET (esyms[j].st_other);
     }
@@ -3814,7 +3890,7 @@ get_64bit_elf_symbols (FILE *file, Elf_Internal_Shdr *section)
   shndx = NULL;
   if (symtab_shndx_hdr != NULL
       && (symtab_shndx_hdr->sh_link
-         == (unsigned long) SECTION_HEADER_NUM (section - section_headers)))
+         == (unsigned long) (section - section_headers)))
     {
       shndx = get_data (NULL, file, symtab_shndx_hdr->sh_offset,
                        1, symtab_shndx_hdr->sh_size, _("symtab shndx"));
@@ -3845,9 +3921,11 @@ get_64bit_elf_symbols (FILE *file, Elf_Internal_Shdr *section)
       psym->st_info  = BYTE_GET (esyms[j].st_info);
       psym->st_other = BYTE_GET (esyms[j].st_other);
       psym->st_shndx = BYTE_GET (esyms[j].st_shndx);
-      if (psym->st_shndx == SHN_XINDEX && shndx != NULL)
+      if (psym->st_shndx == (SHN_XINDEX & 0xffff) && shndx != NULL)
        psym->st_shndx
          = byte_get ((unsigned char *) &shndx[j], sizeof (shndx[j]));
+      else if (psym->st_shndx >= (SHN_LORESERVE & 0xffff))
+       psym->st_shndx += SHN_LORESERVE - (SHN_LORESERVE & 0xffff);
       psym->st_value = BYTE_GET (esyms[j].st_value);
       psym->st_size  = BYTE_GET (esyms[j].st_size);
     }
@@ -3869,7 +3947,7 @@ get_elf_section_flags (bfd_vma sh_flags)
   bfd_vma os_flags = 0;
   bfd_vma proc_flags = 0;
   bfd_vma unknown_flags = 0;
-  const struct
+  static const struct
     {
       const char *str;
       int len;
@@ -3885,7 +3963,17 @@ get_elf_section_flags (bfd_vma sh_flags)
        { "LINK ORDER", 10 },
        { "OS NONCONF", 10 },
        { "GROUP", 5 },
-       { "TLS", 3 }
+       { "TLS", 3 },
+       /* IA-64 specific.  */
+       { "SHORT", 5 },
+       { "NORECOV", 7 },
+       /* IA-64 OpenVMS specific.  */
+       { "VMS_GLOBAL", 10 },
+       { "VMS_OVERLAID", 12 },
+       { "VMS_SHARED", 10 },
+       { "VMS_VECTOR", 10 },
+       { "VMS_ALLOC_64BIT", 15 },
+       { "VMS_PROTECTED", 13}
     };
 
   if (do_section_details)
@@ -3919,6 +4007,26 @@ get_elf_section_flags (bfd_vma sh_flags)
 
            default:
              index = -1;
+             if (elf_header.e_machine == EM_IA_64)
+               {
+                 if (flag == SHF_IA_64_SHORT)
+                   index = 10;
+                 else if (flag == SHF_IA_64_NORECOV)
+                   index = 11;
+#ifdef BFD64
+                 else if (elf_header.e_ident[EI_OSABI] == ELFOSABI_OPENVMS)
+                   switch (flag)
+                     {
+                     case SHF_IA_64_VMS_GLOBAL:      index = 12; break;
+                     case SHF_IA_64_VMS_OVERLAID:    index = 13; break;
+                     case SHF_IA_64_VMS_SHARED:      index = 14; break;
+                     case SHF_IA_64_VMS_VECTOR:      index = 15; break;
+                     case SHF_IA_64_VMS_ALLOC_64BIT: index = 16; break;
+                     case SHF_IA_64_VMS_PROTECTED:   index = 17; break;
+                     default:                        break;
+                     }
+#endif
+               }
              break;
            }
 
@@ -4063,9 +4171,9 @@ process_section_headers (FILE *file)
 
   /* Read in the string table, so that we have names to display.  */
   if (elf_header.e_shstrndx != SHN_UNDEF
-       && SECTION_HEADER_INDEX (elf_header.e_shstrndx) < elf_header.e_shnum)
+       && elf_header.e_shstrndx < elf_header.e_shnum)
     {
-      section = SECTION_HEADER (elf_header.e_shstrndx);
+      section = section_headers + elf_header.e_shstrndx;
 
       if (section->sh_size != 0)
        {
@@ -4118,6 +4226,16 @@ process_section_headers (FILE *file)
          eh_addr_size = 4;
          break;
        }
+      break;
+
+    case EM_M32C:
+      switch (elf_header.e_flags & EF_M32C_CPU_MASK)
+       {
+       case EF_M32C_CPU_M16C:
+         eh_addr_size = 2;
+         break;
+       }
+      break;
     }
 
 #define CHECK_ENTSIZE_VALUES(section, i, size32, size64) \
@@ -4269,7 +4387,7 @@ process_section_headers (FILE *file)
       if (do_section_details)
        {
          printf ("  [%2u] %s\n",
-                 SECTION_HEADER_NUM (i),
+                 i,
                  SECTION_NAME (section));
          if (is_32bit_elf || do_wide)
            printf ("       %-15.15s ",
@@ -4277,7 +4395,7 @@ process_section_headers (FILE *file)
        }
       else
        printf ("  [%2u] %-17.17s %-15.15s ",
-               SECTION_HEADER_NUM (i),
+               i,
                SECTION_NAME (section),
                get_section_type_name (section->sh_type));
 
@@ -4500,8 +4618,8 @@ process_section_groups (FILE *file)
          Elf_Internal_Sym *sym;
 
          /* Get the symbol table.  */
-         if (SECTION_HEADER_INDEX (section->sh_link) >= elf_header.e_shnum
-             || ((sec = SECTION_HEADER (section->sh_link))->sh_type
+         if (section->sh_link >= elf_header.e_shnum
+             || ((sec = section_headers + section->sh_link)->sh_type
                  != SHT_SYMTAB))
            {
              error (_("Bad sh_link in group section `%s'\n"), name);
@@ -4520,14 +4638,14 @@ process_section_groups (FILE *file)
 
          if (ELF_ST_TYPE (sym->st_info) == STT_SECTION)
            {
-             bfd_vma sec_index = SECTION_HEADER_INDEX (sym->st_shndx);
-             if (sec_index == 0)
+             if (sym->st_shndx == 0
+                 || sym->st_shndx >= elf_header.e_shnum)
                {
                  error (_("Bad sh_info in group section `%s'\n"), name);
                  continue;
                }
 
-             group_name = SECTION_NAME (section_headers + sec_index);
+             group_name = SECTION_NAME (section_headers + sym->st_shndx);
              strtab_sec = NULL;
              if (strtab)
                free (strtab);
@@ -4537,8 +4655,7 @@ process_section_groups (FILE *file)
          else
            {
              /* Get the string table.  */
-             if (SECTION_HEADER_INDEX (symtab_sec->sh_link)
-                 >= elf_header.e_shnum)
+             if (symtab_sec->sh_link >= elf_header.e_shnum)
                {
                  strtab_sec = NULL;
                  if (strtab)
@@ -4547,7 +4664,7 @@ process_section_groups (FILE *file)
                  strtab_size = 0;
                }
              else if (strtab_sec
-                      != (sec = SECTION_HEADER (symtab_sec->sh_link)))
+                      != (sec = section_headers + symtab_sec->sh_link))
                {
                  strtab_sec = sec;
                  if (strtab)
@@ -4586,27 +4703,20 @@ process_section_groups (FILE *file)
              entry = byte_get (indices, 4);
              indices += 4;
 
-             if (SECTION_HEADER_INDEX (entry) >= elf_header.e_shnum)
+             if (entry >= elf_header.e_shnum)
                {
                  error (_("section [%5u] in group section [%5u] > maximum section [%5u]\n"),
                         entry, i, elf_header.e_shnum - 1);
                  continue;
                }
-             else if (entry >= SHN_LORESERVE && entry <= SHN_HIRESERVE)
-               {
-                 error (_("invalid section [%5u] in group section [%5u]\n"),
-                        entry, i);
-                 continue;
-               }
 
-             if (section_headers_groups [SECTION_HEADER_INDEX (entry)]
-                 != NULL)
+             if (section_headers_groups [entry] != NULL)
                {
                  if (entry)
                    {
                      error (_("section [%5u] in group section [%5u] already in group section [%5u]\n"),
                             entry, i,
-                            section_headers_groups [SECTION_HEADER_INDEX (entry)]->group_index);
+                            section_headers_groups [entry]->group_index);
                      continue;
                    }
                  else
@@ -4618,18 +4728,17 @@ process_section_groups (FILE *file)
                      if (!warned)
                        {
                          error (_("section 0 in group section [%5u]\n"),
-                                section_headers_groups [SECTION_HEADER_INDEX (entry)]->group_index);
+                                section_headers_groups [entry]->group_index);
                          warned++;
                        }
                    }
                }
 
-             section_headers_groups [SECTION_HEADER_INDEX (entry)]
-               = group;
+             section_headers_groups [entry] = group;
 
              if (do_section_groups)
                {
-                 sec = SECTION_HEADER (entry);
+                 sec = section_headers + entry;
                  printf ("   [%5u]   %s\n", entry, SECTION_NAME (sec));
                }
 
@@ -4761,9 +4870,8 @@ process_relocs (FILE *file)
 
              is_rela = section->sh_type == SHT_RELA;
 
-             if (section->sh_link
-                 && SECTION_HEADER_INDEX (section->sh_link)
-                    < elf_header.e_shnum)
+             if (section->sh_link != 0
+                 && section->sh_link < elf_header.e_shnum)
                {
                  Elf_Internal_Shdr *symsec;
                  Elf_Internal_Sym *symtab;
@@ -4771,7 +4879,7 @@ process_relocs (FILE *file)
                  unsigned long strtablen = 0;
                  char *strtab = NULL;
 
-                 symsec = SECTION_HEADER (section->sh_link);
+                 symsec = section_headers + section->sh_link;
                  if (symsec->sh_type != SHT_SYMTAB
                      && symsec->sh_type != SHT_DYNSYM)
                     continue;
@@ -4782,10 +4890,10 @@ process_relocs (FILE *file)
                  if (symtab == NULL)
                    continue;
 
-                 if (SECTION_HEADER_INDEX (symsec->sh_link)
-                     < elf_header.e_shnum)
+                 if (symsec->sh_link != 0
+                     && symsec->sh_link < elf_header.e_shnum)
                    {
-                     strsec = SECTION_HEADER (symsec->sh_link);
+                     strsec = section_headers + symsec->sh_link;
 
                      strtab = get_data (NULL, file, strsec->sh_offset,
                                         1, strsec->sh_size,
@@ -5016,15 +5124,14 @@ slurp_ia64_unwind_table (FILE *file,
     }
   free (table);
 
-  /* Third, apply any relocations to the unwind table: */
-
+  /* Third, apply any relocations to the unwind table:  */
   for (relsec = section_headers;
        relsec < section_headers + elf_header.e_shnum;
        ++relsec)
     {
       if (relsec->sh_type != SHT_RELA
-         || SECTION_HEADER_INDEX (relsec->sh_info) >= elf_header.e_shnum
-         || SECTION_HEADER (relsec->sh_info) != sec)
+         || relsec->sh_info >= elf_header.e_shnum
+         || section_headers + relsec->sh_info != sec)
        continue;
 
       if (!slurp_rela_relocs (file, relsec->sh_offset, relsec->sh_size,
@@ -5033,16 +5140,8 @@ slurp_ia64_unwind_table (FILE *file,
 
       for (rp = rela; rp < rela + nrelas; ++rp)
        {
-         if (is_32bit_elf)
-           {
-             relname = elf_ia64_reloc_type (ELF32_R_TYPE (rp->r_info));
-             sym = aux->symtab + ELF32_R_SYM (rp->r_info);
-           }
-         else
-           {
-             relname = elf_ia64_reloc_type (ELF64_R_TYPE (rp->r_info));
-             sym = aux->symtab + ELF64_R_SYM (rp->r_info);
-           }
+         relname = elf_ia64_reloc_type (get_reloc_type (rp->r_info));
+         sym = aux->symtab + get_reloc_symindex (rp->r_info);
 
          if (! const_strneq (relname, "R_IA64_SEGREL"))
            {
@@ -5090,12 +5189,12 @@ ia64_process_unwind (FILE *file)
   for (i = 0, sec = section_headers; i < elf_header.e_shnum; ++i, ++sec)
     {
       if (sec->sh_type == SHT_SYMTAB
-         && SECTION_HEADER_INDEX (sec->sh_link) < elf_header.e_shnum)
+         && sec->sh_link < elf_header.e_shnum)
        {
          aux.nsyms = sec->sh_size / sec->sh_entsize;
          aux.symtab = GET_ELF_SYMBOLS (file, sec);
 
-         strsec = SECTION_HEADER (sec->sh_link);
+         strsec = section_headers + sec->sh_link;
          aux.strtab = get_data (NULL, file, strsec->sh_offset,
                                 1, strsec->sh_size, _("string table"));
          aux.strtab_size = aux.strtab != NULL ? strsec->sh_size : 0;
@@ -5130,7 +5229,7 @@ ia64_process_unwind (FILE *file)
 
          for (; g != NULL; g = g->next)
            {
-             sec = SECTION_HEADER (g->section_index);
+             sec = section_headers + g->section_index;
 
              if (streq (SECTION_NAME (sec), ELF_STRING_ia64_unwind_info))
                break;
@@ -5429,14 +5528,13 @@ slurp_hppa_unwind_table (FILE *file,
   free (table);
 
   /* Third, apply any relocations to the unwind table.  */
-
   for (relsec = section_headers;
        relsec < section_headers + elf_header.e_shnum;
        ++relsec)
     {
       if (relsec->sh_type != SHT_RELA
-         || SECTION_HEADER_INDEX (relsec->sh_info) >= elf_header.e_shnum
-         || SECTION_HEADER (relsec->sh_info) != sec)
+         || relsec->sh_info >= elf_header.e_shnum
+         || section_headers + relsec->sh_info != sec)
        continue;
 
       if (!slurp_rela_relocs (file, relsec->sh_offset, relsec->sh_size,
@@ -5445,16 +5543,8 @@ slurp_hppa_unwind_table (FILE *file,
 
       for (rp = rela; rp < rela + nrelas; ++rp)
        {
-         if (is_32bit_elf)
-           {
-             relname = elf_hppa_reloc_type (ELF32_R_TYPE (rp->r_info));
-             sym = aux->symtab + ELF32_R_SYM (rp->r_info);
-           }
-         else
-           {
-             relname = elf_hppa_reloc_type (ELF64_R_TYPE (rp->r_info));
-             sym = aux->symtab + ELF64_R_SYM (rp->r_info);
-           }
+         relname = elf_hppa_reloc_type (get_reloc_type (rp->r_info));
+         sym = aux->symtab + get_reloc_symindex (rp->r_info);
 
          /* R_PARISC_SEGREL32 or R_PARISC_SEGREL64.  */
          if (! const_strneq (relname, "R_PARISC_SEGREL"))
@@ -5505,12 +5595,12 @@ hppa_process_unwind (FILE *file)
   for (i = 0, sec = section_headers; i < elf_header.e_shnum; ++i, ++sec)
     {
       if (sec->sh_type == SHT_SYMTAB
-         && SECTION_HEADER_INDEX (sec->sh_link) < elf_header.e_shnum)
+         && sec->sh_link < elf_header.e_shnum)
        {
          aux.nsyms = sec->sh_size / sec->sh_entsize;
          aux.symtab = GET_ELF_SYMBOLS (file, sec);
 
-         strsec = SECTION_HEADER (sec->sh_link);
+         strsec = section_headers + sec->sh_link;
          aux.strtab = get_data (NULL, file, strsec->sh_offset,
                                 1, strsec->sh_size, _("string table"));
          aux.strtab_size = aux.strtab != NULL ? strsec->sh_size : 0;
@@ -6476,9 +6566,8 @@ process_version_sections (FILE *file)
            printf_vma (section->sh_addr);
            printf (_("  Offset: %#08lx  Link: %lx (%s)\n"),
                    (unsigned long) section->sh_offset, section->sh_link,
-                   SECTION_HEADER_INDEX (section->sh_link)
-                   < elf_header.e_shnum
-                   ? SECTION_NAME (SECTION_HEADER (section->sh_link))
+                   section->sh_link < elf_header.e_shnum
+                   ? SECTION_NAME (section_headers + section->sh_link)
                    : "<corrupt>");
 
            edefs = get_data (NULL, file, section->sh_offset, 1,
@@ -6579,9 +6668,8 @@ process_version_sections (FILE *file)
            printf_vma (section->sh_addr);
            printf (_("  Offset: %#08lx  Link to section: %ld (%s)\n"),
                    (unsigned long) section->sh_offset, section->sh_link,
-                   SECTION_HEADER_INDEX (section->sh_link)
-                   < elf_header.e_shnum
-                   ? SECTION_NAME (SECTION_HEADER (section->sh_link))
+                   section->sh_link < elf_header.e_shnum
+                   ? SECTION_NAME (section_headers + section->sh_link)
                    : "<corrupt>");
 
            eneed = get_data (NULL, file, section->sh_offset, 1,
@@ -6674,21 +6762,20 @@ process_version_sections (FILE *file)
            Elf_Internal_Shdr *string_sec;
            long off;
 
-           if (SECTION_HEADER_INDEX (section->sh_link) >= elf_header.e_shnum)
+           if (section->sh_link >= elf_header.e_shnum)
              break;
 
-           link_section = SECTION_HEADER (section->sh_link);
+           link_section = section_headers + section->sh_link;
            total = section->sh_size / sizeof (Elf_External_Versym);
 
-           if (SECTION_HEADER_INDEX (link_section->sh_link)
-               >= elf_header.e_shnum)
+           if (link_section->sh_link >= elf_header.e_shnum)
              break;
 
            found = 1;
 
            symbols = GET_ELF_SYMBOLS (file, link_section);
 
-           string_sec = SECTION_HEADER (link_section->sh_link);
+           string_sec = section_headers + link_section->sh_link;
 
            strtab = get_data (NULL, file, string_sec->sh_offset, 1,
                               string_sec->sh_size, _("version string table"));
@@ -6748,9 +6835,8 @@ process_version_sections (FILE *file)
 
                      check_def = 1;
                      check_need = 1;
-                     if (SECTION_HEADER_INDEX (symbols[cnt + j].st_shndx)
-                         >= elf_header.e_shnum
-                         || SECTION_HEADER (symbols[cnt + j].st_shndx)->sh_type
+                     if (symbols[cnt + j].st_shndx >= elf_header.e_shnum
+                         || section_headers[symbols[cnt + j].st_shndx].sh_type
                             != SHT_NOBITS)
                        {
                          if (symbols[cnt + j].st_shndx == SHN_UNDEF)
@@ -7034,11 +7120,11 @@ get_symbol_index_type (unsigned int type)
               && elf_header.e_machine == EM_MIPS)
        return "SUND";
       else if (type >= SHN_LOPROC && type <= SHN_HIPROC)
-       sprintf (buff, "PRC[0x%04x]", type);
+       sprintf (buff, "PRC[0x%04x]", type & 0xffff);
       else if (type >= SHN_LOOS && type <= SHN_HIOS)
-       sprintf (buff, "OS [0x%04x]", type);
-      else if (type >= SHN_LORESERVE && type <= SHN_HIRESERVE)
-       sprintf (buff, "RSV[0x%04x]", type);
+       sprintf (buff, "OS [0x%04x]", type & 0xffff);
+      else if (type >= SHN_LORESERVE)
+       sprintf (buff, "RSV[0x%04x]", type & 0xffff);
       else
        sprintf (buff, "%3d", type);
       break;
@@ -7084,6 +7170,39 @@ get_dynamic_data (FILE *file, unsigned int number, unsigned int ent_size)
   return i_data;
 }
 
+static void
+print_dynamic_symbol (bfd_vma si, unsigned long hn)
+{
+  Elf_Internal_Sym *psym;
+  int n;
+
+  psym = dynamic_symbols + si;
+
+  n = print_vma (si, DEC_5);
+  if (n < 5)
+    fputs ("     " + n, stdout);
+  printf (" %3lu: ", hn);
+  print_vma (psym->st_value, LONG_HEX);
+  putchar (' ');
+  print_vma (psym->st_size, DEC_5);
+
+  printf ("  %6s", get_symbol_type (ELF_ST_TYPE (psym->st_info)));
+  printf (" %6s",  get_symbol_binding (ELF_ST_BIND (psym->st_info)));
+  printf (" %3s",  get_symbol_visibility (ELF_ST_VISIBILITY (psym->st_other)));
+  /* Check to see if any other bits in the st_other field are set.
+     Note - displaying this information disrupts the layout of the
+     table being generated, but for the moment this case is very
+     rare.  */
+  if (psym->st_other ^ ELF_ST_VISIBILITY (psym->st_other))
+    printf (" [%s] ", get_symbol_other (psym->st_other ^ ELF_ST_VISIBILITY (psym->st_other)));
+  printf (" %3.3s ", get_symbol_index_type (psym->st_shndx));
+  if (VALID_DYNAMIC_NAME (psym->st_name))
+    print_symbol (25, GET_DYNAMIC_NAME (psym->st_name));
+  else
+    printf (" <corrupt: %14ld>", psym->st_name);
+  putchar ('\n');
+}
+
 /* Dump the symbol table.  */
 static int
 process_symbol_table (FILE *file)
@@ -7096,12 +7215,14 @@ process_symbol_table (FILE *file)
   bfd_vma ngnubuckets = 0;
   bfd_vma *gnubuckets = NULL;
   bfd_vma *gnuchains = NULL;
+  bfd_vma gnusymidx = 0;
 
   if (! do_syms && !do_histogram)
     return 1;
 
-  if (dynamic_info[DT_HASH] && ((do_using_dynamic && dynamic_strings != NULL)
-                               || do_histogram))
+  if (dynamic_info[DT_HASH]
+      && (do_histogram
+         || (do_using_dynamic && dynamic_strings != NULL)))
     {
       unsigned char nb[8];
       unsigned char nc[8];
@@ -7145,54 +7266,157 @@ process_symbol_table (FILE *file)
        return 0;
     }
 
-  if (do_syms
-      && dynamic_info[DT_HASH] && do_using_dynamic && dynamic_strings != NULL)
+  if (dynamic_info_DT_GNU_HASH
+      && (do_histogram
+         || (do_using_dynamic && dynamic_strings != NULL)))
     {
-      unsigned long hn;
-      bfd_vma si;
+      unsigned char nb[16];
+      bfd_vma i, maxchain = 0xffffffff, bitmaskwords;
+      bfd_vma buckets_vma;
+
+      if (fseek (file,
+                (archive_file_offset
+                 + offset_from_vma (file, dynamic_info_DT_GNU_HASH,
+                                    sizeof nb)),
+                SEEK_SET))
+       {
+         error (_("Unable to seek to start of dynamic information\n"));
+         return 0;
+       }
+
+      if (fread (nb, 16, 1, file) != 1)
+       {
+         error (_("Failed to read in number of buckets\n"));
+         return 0;
+       }
 
-      printf (_("\nSymbol table for image:\n"));
+      ngnubuckets = byte_get (nb, 4);
+      gnusymidx = byte_get (nb + 4, 4);
+      bitmaskwords = byte_get (nb + 8, 4);
+      buckets_vma = dynamic_info_DT_GNU_HASH + 16;
       if (is_32bit_elf)
-       printf (_("  Num Buc:    Value  Size   Type   Bind Vis      Ndx Name\n"));
+       buckets_vma += bitmaskwords * 4;
       else
-       printf (_("  Num Buc:    Value          Size   Type   Bind Vis      Ndx Name\n"));
+       buckets_vma += bitmaskwords * 8;
 
-      for (hn = 0; hn < nbuckets; hn++)
+      if (fseek (file,
+                (archive_file_offset
+                 + offset_from_vma (file, buckets_vma, 4)),
+                SEEK_SET))
        {
-         if (! buckets[hn])
-           continue;
+         error (_("Unable to seek to start of dynamic information\n"));
+         return 0;
+       }
+
+      gnubuckets = get_dynamic_data (file, ngnubuckets, 4);
+
+      if (gnubuckets == NULL)
+       return 0;
+
+      for (i = 0; i < ngnubuckets; i++)
+       if (gnubuckets[i] != 0)
+         {
+           if (gnubuckets[i] < gnusymidx)
+             return 0;
+
+           if (maxchain == 0xffffffff || gnubuckets[i] > maxchain)
+             maxchain = gnubuckets[i];
+         }
+
+      if (maxchain == 0xffffffff)
+       return 0;
 
-         for (si = buckets[hn]; si < nchains && si > 0; si = chains[si])
+      maxchain -= gnusymidx;
+
+      if (fseek (file,
+                (archive_file_offset
+                 + offset_from_vma (file, buckets_vma
+                                          + 4 * (ngnubuckets + maxchain), 4)),
+                SEEK_SET))
+       {
+         error (_("Unable to seek to start of dynamic information\n"));
+         return 0;
+       }
+
+      do
+       {
+         if (fread (nb, 4, 1, file) != 1)
            {
-             Elf_Internal_Sym *psym;
-             int n;
+             error (_("Failed to determine last chain length\n"));
+             return 0;
+           }
 
-             psym = dynamic_symbols + si;
+         if (maxchain + 1 == 0)
+           return 0;
 
-             n = print_vma (si, DEC_5);
-             if (n < 5)
-               fputs ("     " + n, stdout);
-             printf (" %3lu: ", hn);
-             print_vma (psym->st_value, LONG_HEX);
-             putchar (' ');
-             print_vma (psym->st_size, DEC_5);
+         ++maxchain;
+       }
+      while ((byte_get (nb, 4) & 1) == 0);
 
-             printf ("  %6s", get_symbol_type (ELF_ST_TYPE (psym->st_info)));
-             printf (" %6s",  get_symbol_binding (ELF_ST_BIND (psym->st_info)));
-             printf (" %3s",  get_symbol_visibility (ELF_ST_VISIBILITY (psym->st_other)));
-             /* Check to see if any other bits in the st_other field are set.
-                Note - displaying this information disrupts the layout of the
-                table being generated, but for the moment this case is very rare.  */
-             if (psym->st_other ^ ELF_ST_VISIBILITY (psym->st_other))
-               printf (" [%s] ", get_symbol_other (psym->st_other ^ ELF_ST_VISIBILITY (psym->st_other)));
-             printf (" %3.3s ", get_symbol_index_type (psym->st_shndx));
-             if (VALID_DYNAMIC_NAME (psym->st_name))
-               print_symbol (25, GET_DYNAMIC_NAME (psym->st_name));
-             else
-               printf (" <corrupt: %14ld>", psym->st_name);
-             putchar ('\n');
+      if (fseek (file,
+                (archive_file_offset
+                 + offset_from_vma (file, buckets_vma + 4 * ngnubuckets, 4)),
+                SEEK_SET))
+       {
+         error (_("Unable to seek to start of dynamic information\n"));
+         return 0;
+       }
+
+      gnuchains = get_dynamic_data (file, maxchain, 4);
+
+      if (gnuchains == NULL)
+       return 0;
+    }
+
+  if ((dynamic_info[DT_HASH] || dynamic_info_DT_GNU_HASH)
+      && do_syms
+      && do_using_dynamic
+      && dynamic_strings != NULL)
+    {
+      unsigned long hn;
+
+      if (dynamic_info[DT_HASH])
+       {
+         bfd_vma si;
+
+         printf (_("\nSymbol table for image:\n"));
+         if (is_32bit_elf)
+           printf (_("  Num Buc:    Value  Size   Type   Bind Vis      Ndx Name\n"));
+         else
+           printf (_("  Num Buc:    Value          Size   Type   Bind Vis      Ndx Name\n"));
+
+         for (hn = 0; hn < nbuckets; hn++)
+           {
+             if (! buckets[hn])
+               continue;
+
+             for (si = buckets[hn]; si < nchains && si > 0; si = chains[si])
+               print_dynamic_symbol (si, hn);
            }
        }
+
+      if (dynamic_info_DT_GNU_HASH)
+       {
+         printf (_("\nSymbol table of `.gnu.hash' for image:\n"));
+         if (is_32bit_elf)
+           printf (_("  Num Buc:    Value  Size   Type   Bind Vis      Ndx Name\n"));
+         else
+           printf (_("  Num Buc:    Value          Size   Type   Bind Vis      Ndx Name\n"));
+
+         for (hn = 0; hn < ngnubuckets; ++hn)
+           if (gnubuckets[hn] != 0)
+             {
+               bfd_vma si = gnubuckets[hn];
+               bfd_vma off = si - gnusymidx;
+
+               do
+                 {
+                   print_dynamic_symbol (si, hn);
+                   si++;
+                 }
+               while ((gnuchains[off++] & 1) == 0);
+             }
+       }
     }
   else if (do_syms && !do_using_dynamic)
     {
@@ -7230,11 +7454,11 @@ process_symbol_table (FILE *file)
              strtab = string_table;
              strtab_size = string_table_length;
            }
-         else if (SECTION_HEADER_INDEX (section->sh_link) < elf_header.e_shnum)
+         else if (section->sh_link < elf_header.e_shnum)
            {
              Elf_Internal_Shdr *string_sec;
 
-             string_sec = SECTION_HEADER (section->sh_link);
+             string_sec = section_headers + section->sh_link;
 
              strtab = get_data (NULL, file, string_sec->sh_offset,
                                 1, string_sec->sh_size, _("string table"));
@@ -7279,9 +7503,8 @@ process_symbol_table (FILE *file)
 
                  vers_data = byte_get (data, 2);
 
-                 is_nobits = (SECTION_HEADER_INDEX (psym->st_shndx)
-                              < elf_header.e_shnum
-                              && SECTION_HEADER (psym->st_shndx)->sh_type
+                 is_nobits = (psym->st_shndx < elf_header.e_shnum
+                              && section_headers[psym->st_shndx].sh_type
                                  == SHT_NOBITS);
 
                  check_def = (psym->st_shndx != SHN_UNDEF);
@@ -7477,113 +7700,17 @@ process_symbol_table (FILE *file)
 
   if (do_histogram && dynamic_info_DT_GNU_HASH)
     {
-      unsigned char nb[16];
-      bfd_vma i, maxchain = 0xffffffff, symidx, bitmaskwords;
       unsigned long *lengths;
       unsigned long *counts;
       unsigned long hn;
       unsigned long maxlength = 0;
       unsigned long nzero_counts = 0;
       unsigned long nsyms = 0;
-      bfd_vma buckets_vma;
 
-      if (fseek (file,
-                (archive_file_offset
-                 + offset_from_vma (file, dynamic_info_DT_GNU_HASH,
-                                    sizeof nb)),
-                SEEK_SET))
+      lengths = calloc (ngnubuckets, sizeof (*lengths));
+      if (lengths == NULL)
        {
-         error (_("Unable to seek to start of dynamic information\n"));
-         return 0;
-       }
-
-      if (fread (nb, 16, 1, file) != 1)
-       {
-         error (_("Failed to read in number of buckets\n"));
-         return 0;
-       }
-
-      ngnubuckets = byte_get (nb, 4);
-      symidx = byte_get (nb + 4, 4);
-      bitmaskwords = byte_get (nb + 8, 4);
-      buckets_vma = dynamic_info_DT_GNU_HASH + 16;
-      if (is_32bit_elf)
-       buckets_vma += bitmaskwords * 4;
-      else
-       buckets_vma += bitmaskwords * 8;
-
-      if (fseek (file,
-                (archive_file_offset
-                 + offset_from_vma (file, buckets_vma, 4)),
-                SEEK_SET))
-       {
-         error (_("Unable to seek to start of dynamic information\n"));
-         return 0;
-       }
-
-      gnubuckets = get_dynamic_data (file, ngnubuckets, 4);
-
-      if (gnubuckets == NULL)
-       return 0;
-
-      for (i = 0; i < ngnubuckets; i++)
-       if (gnubuckets[i] != 0)
-         {
-           if (gnubuckets[i] < symidx)
-             return 0;
-
-           if (maxchain == 0xffffffff || gnubuckets[i] > maxchain)
-             maxchain = gnubuckets[i];
-         }
-
-      if (maxchain == 0xffffffff)
-       return 0;
-
-      maxchain -= symidx;
-
-      if (fseek (file,
-                (archive_file_offset
-                 + offset_from_vma (file, buckets_vma
-                                          + 4 * (ngnubuckets + maxchain), 4)),
-                SEEK_SET))
-       {
-         error (_("Unable to seek to start of dynamic information\n"));
-         return 0;
-       }
-
-      do
-       {
-         if (fread (nb, 4, 1, file) != 1)
-           {
-             error (_("Failed to determine last chain length\n"));
-             return 0;
-           }
-
-         if (maxchain + 1 == 0)
-           return 0;
-
-         ++maxchain;
-       }
-      while ((byte_get (nb, 4) & 1) == 0);
-
-      if (fseek (file,
-                (archive_file_offset
-                 + offset_from_vma (file, buckets_vma + 4 * ngnubuckets, 4)),
-                SEEK_SET))
-       {
-         error (_("Unable to seek to start of dynamic information\n"));
-         return 0;
-       }
-
-      gnuchains = get_dynamic_data (file, maxchain, 4);
-
-      if (gnuchains == NULL)
-       return 0;
-
-      lengths = calloc (ngnubuckets, sizeof (*lengths));
-      if (lengths == NULL)
-       {
-         error (_("Out of memory\n"));
+         error (_("Out of memory\n"));
          return 0;
        }
 
@@ -7596,7 +7723,7 @@ process_symbol_table (FILE *file)
          {
            bfd_vma off, length = 1;
 
-           for (off = gnubuckets[hn] - symidx;
+           for (off = gnubuckets[hn] - gnusymidx;
                 (gnuchains[off] & 1) == 0; ++off)
              ++length;
            lengths[hn] = length;
@@ -7756,10 +7883,10 @@ dump_section_as_strings (Elf_Internal_Shdr *section, FILE *file)
        ++relsec)
     {
       if ((relsec->sh_type != SHT_RELA && relsec->sh_type != SHT_REL)
-         || SECTION_HEADER_INDEX (relsec->sh_info) >= elf_header.e_shnum
-         || SECTION_HEADER (relsec->sh_info) != section
+         || relsec->sh_info >= elf_header.e_shnum
+         || section_headers + relsec->sh_info != section
          || relsec->sh_size == 0
-         || SECTION_HEADER_INDEX (relsec->sh_link) >= elf_header.e_shnum)
+         || relsec->sh_link >= elf_header.e_shnum)
        continue;
 
       printf (_("  Note: This section has relocations against it, but these have NOT been applied to this dump.\n"));
@@ -7778,7 +7905,11 @@ dump_section_as_strings (Elf_Internal_Shdr *section, FILE *file)
 
       if (data < end)
        {
-         printf ("  [%6zx]  %s\n", data - start, data);
+#ifndef __MSVCRT__
+         printf ("  [%6tx]  %s\n", data - start, data);
+#else
+         printf ("  [%6Ix]  %s\n", (size_t) (data - start), data);
+#endif
          data += strlen (data);
          some_strings_shown = TRUE;
        }
@@ -7831,10 +7962,10 @@ dump_section_as_bytes (Elf_Internal_Shdr *section, FILE *file)
        ++relsec)
     {
       if ((relsec->sh_type != SHT_RELA && relsec->sh_type != SHT_REL)
-         || SECTION_HEADER_INDEX (relsec->sh_info) >= elf_header.e_shnum
-         || SECTION_HEADER (relsec->sh_info) != section
+         || relsec->sh_info >= elf_header.e_shnum
+         || section_headers + relsec->sh_info != section
          || relsec->sh_size == 0
-         || SECTION_HEADER_INDEX (relsec->sh_link) >= elf_header.e_shnum)
+         || relsec->sh_link >= elf_header.e_shnum)
        continue;
 
       printf (_(" NOTE: This section has relocations against it, but these have NOT been applied to this dump.\n"));
@@ -7886,95 +8017,344 @@ dump_section_as_bytes (Elf_Internal_Shdr *section, FILE *file)
   return 1;
 }
 
-/* Return the number of bytes affected by a given reloc.
-   This information is architecture and reloc dependent.
-   Returns 4 by default, although this is not always correct.
-   It should return 0 if a decision cannot be made.
-   FIXME: This is not the correct way to solve this problem.
-   The proper way is to have target specific reloc sizing functions
-   created by the reloc-macros.h header, in the same way that it
-   already creates the reloc naming functions.  */
+/* Returns TRUE iff RELOC_TYPE is a 32-bit absolute RELA relocation used in
+   DWARF debug sections.  This is a target specific test.  Note - we do not
+   go through the whole including-target-headers-multiple-times route, (as
+   we have already done with <elf/h8.h>) because this would become very
+   messy and even then this function would have to contain target specific
+   information (the names of the relocs instead of their numeric values).
+   FIXME: This is not the correct way to solve this problem.  The proper way
+   is to have target specific reloc sizing and typing functions created by
+   the reloc-macros.h header, in the same way that it already creates the
+   reloc naming functions.  */
 
-static unsigned int
-get_reloc_size (Elf_Internal_Rela * reloc)
+static bfd_boolean
+is_32bit_abs_reloc (unsigned int reloc_type)
 {
   switch (elf_header.e_machine)
     {
+    case EM_386:
+    case EM_486:
+      return reloc_type == 1; /* R_386_32.  */
+    case EM_68K:
+      return reloc_type == 1; /* R_68K_32.  */
+    case EM_860:
+      return reloc_type == 1; /* R_860_32.  */
+    case EM_ALPHA:
+      return reloc_type == 1; /* XXX Is this right ?  */
+    case EM_ARC:
+      return reloc_type == 1; /* R_ARC_32.  */
+    case EM_ARM:
+      return reloc_type == 2; /* R_ARM_ABS32 */
+    case EM_AVR_OLD: 
+    case EM_AVR:
+      return reloc_type == 1;
+    case EM_BLACKFIN:
+      return reloc_type == 0x12; /* R_byte4_data.  */
+    case EM_CRIS:
+      return reloc_type == 3; /* R_CRIS_32.  */
+    case EM_CR16:
+      return reloc_type == 3; /* R_CR16_NUM32.  */
+    case EM_CRX:
+      return reloc_type == 15; /* R_CRX_NUM32.  */
+    case EM_CYGNUS_FRV:
+      return reloc_type == 1;
+    case EM_CYGNUS_D10V:
+    case EM_D10V:
+      return reloc_type == 6; /* R_D10V_32.  */
+    case EM_CYGNUS_D30V:
+    case EM_D30V:
+      return reloc_type == 12; /* R_D30V_32_NORMAL.  */
+    case EM_DLX:
+      return reloc_type == 3; /* R_DLX_RELOC_32.  */
+    case EM_CYGNUS_FR30:
+    case EM_FR30:
+      return reloc_type == 3; /* R_FR30_32.  */
     case EM_H8S:
     case EM_H8_300:
     case EM_H8_300H:
-    case EM_H8_500:
-      switch (ELF32_R_TYPE (reloc->r_info))
-       {
-         /* PR gas/3800 - without this information we do not correctly
-            decode the debug information generated by the h8300 assembler.  */
-       case R_H8_DIR16:
-         return 2;
-       default:
-         return 4;
-       }
+      return reloc_type == 1; /* R_H8_DIR32.  */
+    case EM_IA_64:
+      return reloc_type == 0x65; /* R_IA64_SECREL32LSB.  */
+    case EM_IP2K_OLD:
+    case EM_IP2K:
+      return reloc_type == 2; /* R_IP2K_32.  */
+    case EM_IQ2000:
+      return reloc_type == 2; /* R_IQ2000_32.  */
+    case EM_M32C:
+      return reloc_type == 3; /* R_M32C_32.  */
+    case EM_M32R:
+      return reloc_type == 34; /* R_M32R_32_RELA.  */
+    case EM_MCORE:
+      return reloc_type == 1; /* R_MCORE_ADDR32.  */
+    case EM_CYGNUS_MEP:
+      return reloc_type == 4; /* R_MEP_32.  */
+    case EM_MIPS:
+      return reloc_type == 2; /* R_MIPS_32.  */
+    case EM_MMIX:
+      return reloc_type == 4; /* R_MMIX_32.  */
+    case EM_CYGNUS_MN10200:
+    case EM_MN10200:
+      return reloc_type == 1; /* R_MN10200_32.  */
+    case EM_CYGNUS_MN10300:
+    case EM_MN10300:
+      return reloc_type == 1; /* R_MN10300_32.  */
+    case EM_MSP430_OLD:
+    case EM_MSP430:
+      return reloc_type == 1; /* R_MSP43_32.  */
+    case EM_MT:
+      return reloc_type == 2; /* R_MT_32.  */
+    case EM_ALTERA_NIOS2:
+    case EM_NIOS32:
+      return reloc_type == 1; /* R_NIOS_32.  */
+    case EM_OPENRISC:
+    case EM_OR32:
+      return reloc_type == 1; /* R_OR32_32.  */
+    case EM_PARISC:
+      return reloc_type == 1; /* R_PARISC_DIR32.  */
+    case EM_PJ:
+    case EM_PJ_OLD:
+      return reloc_type == 1; /* R_PJ_DATA_DIR32.  */
+    case EM_PPC64:
+      return reloc_type == 1; /* R_PPC64_ADDR32.  */
+    case EM_PPC:
+      return reloc_type == 1; /* R_PPC_ADDR32.  */
+    case EM_S370:
+      return reloc_type == 1; /* R_I370_ADDR31.  */
+    case EM_S390_OLD:
+    case EM_S390:
+      return reloc_type == 4; /* R_S390_32.  */
+    case EM_SCORE:
+      return reloc_type == 8; /* R_SCORE_ABS32.  */
+    case EM_SH:
+      return reloc_type == 1; /* R_SH_DIR32.  */
+    case EM_SPARC32PLUS:
+    case EM_SPARCV9:
+    case EM_SPARC:
+      return reloc_type == 3 /* R_SPARC_32.  */
+       || reloc_type == 23; /* R_SPARC_UA32.  */
+    case EM_SPU:
+      return reloc_type == 6; /* R_SPU_ADDR32 */
+    case EM_CYGNUS_V850:
+    case EM_V850:
+      return reloc_type == 6; /* R_V850_ABS32.  */
+    case EM_VAX:
+      return reloc_type == 1; /* R_VAX_32.  */
+    case EM_X86_64:
+      return reloc_type == 10; /* R_X86_64_32.  */
+    case EM_XSTORMY16:
+      return reloc_type == 1; /* R_XSTROMY16_32.  */
+    case EM_XTENSA_OLD:
+    case EM_XTENSA:
+      return reloc_type == 1; /* R_XTENSA_32.  */
+
     default:
-      /* FIXME: We need to extend this switch statement to cope with other
-        architecture's relocs.  (When those relocs are used against debug
-        sections, and when their size is not 4).  But see the multiple
-        inclusions of <elf/h8.h> for an example of the hoops that we need
-        to jump through in order to obtain the reloc numbers.  */
-      return 4;
+      error (_("Missing knowledge of 32-bit reloc types used in DWARF sections of machine number %d\n"),
+            elf_header.e_machine);
+      abort ();
     }
 }
 
-/* Apply addends of RELA relocations.  */
+/* Like is_32bit_abs_reloc except that it returns TRUE iff RELOC_TYPE is
+   a 32-bit pc-relative RELA relocation used in DWARF debug sections.  */
 
-static int
-debug_apply_rela_addends (void *file,
-                         Elf_Internal_Shdr *section,
-                         unsigned char *start)
+static bfd_boolean
+is_32bit_pcrel_reloc (unsigned int reloc_type)
+{
+  switch (elf_header.e_machine)
+    {
+    case EM_386:
+    case EM_486:
+      return reloc_type == 2;  /* R_386_PC32.  */
+    case EM_68K:
+      return reloc_type == 4;  /* R_68K_PC32.  */
+    case EM_ALPHA:
+      return reloc_type == 10; /* R_ALPHA_SREL32.  */
+    case EM_ARM:
+      return reloc_type == 3;  /* R_ARM_REL32 */
+    case EM_PARISC:
+      return reloc_type == 0;  /* R_PARISC_NONE.  *//* FIXME: This reloc is generated, but it may be a bug.  */
+    case EM_PPC:
+      return reloc_type == 26; /* R_PPC_REL32.  */
+    case EM_PPC64:
+      return reloc_type == 26; /* R_PPC64_REL32.  */
+    case EM_S390_OLD:
+    case EM_S390:
+      return reloc_type == 5;  /* R_390_PC32.  */
+    case EM_SH:
+      return reloc_type == 2;  /* R_SH_REL32.  */
+    case EM_SPARC32PLUS:
+    case EM_SPARCV9:
+    case EM_SPARC:
+      return reloc_type == 6;  /* R_SPARC_DISP32.  */
+    case EM_SPU:
+      return reloc_type == 13; /* R_SPU_REL32.  */
+    case EM_X86_64:
+      return reloc_type == 2;  /* R_X86_64_PC32.  */
+    case EM_XTENSA_OLD:
+    case EM_XTENSA:
+      return reloc_type == 14; /* R_XTENSA_32_PCREL.  */
+    default:
+      /* Do not abort or issue an error message here.  Not all targets use
+        pc-relative 32-bit relocs in their DWARF debug information and we
+        have already tested for target coverage in is_32bit_abs_reloc.  A
+        more helpful warning message will be generated by
+        debug_apply_relocations anyway, so just return.  */
+      return FALSE;
+    }
+}
+
+/* Like is_32bit_abs_reloc except that it returns TRUE iff RELOC_TYPE is
+   a 64-bit absolute RELA relocation used in DWARF debug sections.  */
+
+static bfd_boolean
+is_64bit_abs_reloc (unsigned int reloc_type)
+{
+  switch (elf_header.e_machine)
+    {
+    case EM_ALPHA:
+      return reloc_type == 2; /* R_ALPHA_REFQUAD.  */
+    case EM_IA_64:
+      return reloc_type == 0x27; /* R_IA64_DIR64LSB.  */
+    case EM_PARISC:
+      return reloc_type == 80; /* R_PARISC_DIR64.  */
+    case EM_PPC64:
+      return reloc_type == 38; /* R_PPC64_ADDR64.  */
+    case EM_SPARC32PLUS:
+    case EM_SPARCV9:
+    case EM_SPARC:
+      return reloc_type == 54; /* R_SPARC_UA64.  */
+    case EM_X86_64:
+      return reloc_type == 1; /* R_X86_64_64.  */
+    case EM_S390_OLD:
+    case EM_S390:
+      return reloc_type == 22; /* R_S390_64 */
+    default:
+      return FALSE;
+    }
+}
+
+/* Like is_32bit_abs_reloc except that it returns TRUE iff RELOC_TYPE is
+   a 16-bit absolute RELA relocation used in DWARF debug sections.  */
+
+static bfd_boolean
+is_16bit_abs_reloc (unsigned int reloc_type)
+{
+  switch (elf_header.e_machine)
+    {
+    case EM_AVR_OLD:
+    case EM_AVR:
+      return reloc_type == 4; /* R_AVR_16.  */
+    case EM_CYGNUS_D10V:
+    case EM_D10V:
+      return reloc_type == 3; /* R_D10V_16.  */
+    case EM_H8S:
+    case EM_H8_300:
+    case EM_H8_300H:
+      return reloc_type == R_H8_DIR16;
+    case EM_IP2K_OLD:
+    case EM_IP2K:
+      return reloc_type == 1; /* R_IP2K_16.  */
+    case EM_M32C:
+      return reloc_type == 1; /* R_M32C_16 */
+    case EM_MSP430_OLD:
+    case EM_MSP430:
+      return reloc_type == 5; /* R_MSP430_16_BYTE.  */
+    case EM_ALTERA_NIOS2:
+    case EM_NIOS32:
+      return reloc_type == 9; /* R_NIOS_16.  */
+    default:
+      return FALSE;
+    }
+}
+
+/* Apply relocations to a debug section.  */
+
+static void
+debug_apply_relocations (void *file,
+                        Elf_Internal_Shdr *section,
+                        unsigned char *start)
 {
   Elf_Internal_Shdr *relsec;
   unsigned char *end = start + section->sh_size;
 
-  if (!is_relocatable)
-    return 1;
-
-  /* SH uses RELA but uses in place value instead of the addend field.  */
-  if (elf_header.e_machine == EM_SH)
-    return 0;
+  if (elf_header.e_type != ET_REL)
+    return;
 
+  /* Find the reloc section associated with the debug section.  */
   for (relsec = section_headers;
        relsec < section_headers + elf_header.e_shnum;
        ++relsec)
     {
-      unsigned long nrelas;
-      Elf_Internal_Rela *rela, *rp;
+      bfd_boolean is_rela;
+      unsigned long num_relocs;
+      Elf_Internal_Rela *relocs, *rp;
       Elf_Internal_Shdr *symsec;
       Elf_Internal_Sym *symtab;
       Elf_Internal_Sym *sym;
 
-      if (relsec->sh_type != SHT_RELA
-         || SECTION_HEADER_INDEX (relsec->sh_info) >= elf_header.e_shnum
-         || SECTION_HEADER (relsec->sh_info) != section
+      if ((relsec->sh_type != SHT_RELA && relsec->sh_type != SHT_REL)
+         || relsec->sh_info >= elf_header.e_shnum
+         || section_headers + relsec->sh_info != section
          || relsec->sh_size == 0
-         || SECTION_HEADER_INDEX (relsec->sh_link) >= elf_header.e_shnum)
+         || relsec->sh_link >= elf_header.e_shnum)
        continue;
 
-      if (!slurp_rela_relocs (file, relsec->sh_offset, relsec->sh_size,
-                             &rela, &nrelas))
-       return 0;
+      is_rela = relsec->sh_type == SHT_RELA;
 
-      symsec = SECTION_HEADER (relsec->sh_link);
-      symtab = GET_ELF_SYMBOLS (file, symsec);
-
-      for (rp = rela; rp < rela + nrelas; ++rp)
+      if (is_rela)
+       {
+         if (!slurp_rela_relocs (file, relsec->sh_offset, relsec->sh_size,
+                                 & relocs, & num_relocs))
+           return;
+       }
+      else
        {
-         unsigned char *loc;
-         unsigned int reloc_size;
+         if (!slurp_rel_relocs (file, relsec->sh_offset, relsec->sh_size,
+                                & relocs, & num_relocs))
+           return;
+       }
+
+      /* SH uses RELA but uses in place value instead of the addend field.  */
+      if (elf_header.e_machine == EM_SH)
+       is_rela = FALSE;
+
+      symsec = section_headers + relsec->sh_link;
+      symtab = GET_ELF_SYMBOLS (file, symsec);
 
-         reloc_size = get_reloc_size (rp);
-         if (reloc_size == 0)
+      for (rp = relocs; rp < relocs + num_relocs; ++rp)
+       {
+         bfd_vma         addend;
+         unsigned int    reloc_type;
+         unsigned int    reloc_size;
+         unsigned char * loc;
+
+         /* 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 (!is_32bit_elf
+             && 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));
+
+         reloc_type = get_reloc_type (rp->r_info);
+
+         if (is_32bit_abs_reloc (reloc_type)
+             || is_32bit_pcrel_reloc (reloc_type))
+           reloc_size = 4;
+         else if (is_64bit_abs_reloc (reloc_type))
+           reloc_size = 8;
+         else if (is_16bit_abs_reloc (reloc_type))
+           reloc_size = 2;
+         else
            {
-             warn (_("skipping relocation of unknown size against offset 0x%lx in section %s\n"),
-                   (unsigned long) rp->r_offset,
-                   SECTION_NAME (section));
+             warn (_("unable to apply unsupported reloc type %d to section %s\n"),
+                   reloc_type, SECTION_NAME (section));
              continue;
            }
 
@@ -7987,63 +8367,41 @@ debug_apply_rela_addends (void *file,
              continue;
            }
 
-         if (is_32bit_elf)
+         sym = symtab + get_reloc_symindex (rp->r_info);
+
+         /* If the reloc has a symbol associated with it,
+            make sure that it is of an appropriate type.  */
+         if (sym != symtab
+             && ELF_ST_TYPE (sym->st_info) != STT_SECTION
+             /* Relocations against symbols without type can happen.
+                Gcc -feliminate-dwarf2-dups may generate symbols
+                without type for debug info.  */
+             && ELF_ST_TYPE (sym->st_info) != STT_NOTYPE
+             /* Relocations against object symbols can happen,
+                eg when referencing a global array.  For an
+                example of this see the _clz.o binary in libgcc.a.  */
+             && ELF_ST_TYPE (sym->st_info) != STT_OBJECT)
            {
-             sym = symtab + ELF32_R_SYM (rp->r_info);
-
-             if (ELF32_R_SYM (rp->r_info) != 0
-                 && ELF32_ST_TYPE (sym->st_info) != STT_SECTION
-                 /* Relocations against symbols without type can happen.
-                    Gcc -feliminate-dwarf2-dups may generate symbols
-                    without type for debug info.  */
-                 && ELF32_ST_TYPE (sym->st_info) != STT_NOTYPE
-                 /* Relocations against object symbols can happen,
-                    eg when referencing a global array.  For an
-                    example of this see the _clz.o binary in libgcc.a.  */
-                 && ELF32_ST_TYPE (sym->st_info) != STT_OBJECT)
-               {
-                 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;
-               }
-           }
-         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
-                 && ELF64_ST_TYPE (sym->st_info) != STT_SECTION
-                 && ELF64_ST_TYPE (sym->st_info) != STT_NOTYPE
-                 && ELF64_ST_TYPE (sym->st_info) != STT_OBJECT)
-               {
-                 warn (_("skipping unexpected symbol type %s in relocation in section .rela.%s\n"),
-                       get_symbol_type (ELF64_ST_TYPE (sym->st_info)),
-                       SECTION_NAME (section));
-                 continue;
-               }
+             warn (_("skipping unexpected symbol type %s in %ld'th relocation in section %s\n"),
+                   get_symbol_type (ELF_ST_TYPE (sym->st_info)),
+                   (long int)(rp - relocs),
+                   SECTION_NAME (relsec));
+             continue;
            }
 
-         byte_put (loc, rp->r_addend, reloc_size);
+         addend = is_rela ? rp->r_addend : byte_get (loc, reloc_size);
+         
+         if (is_32bit_pcrel_reloc (reloc_type))
+           byte_put (loc, (addend + sym->st_value) - rp->r_offset,
+                     reloc_size);
+         else
+           byte_put (loc, addend + sym->st_value, reloc_size);
        }
 
       free (symtab);
-      free (rela);
+      free (relocs);
       break;
     }
-  return 1;
 }
 
 int
@@ -8069,7 +8427,7 @@ load_debug_section (enum dwarf_section_display_enum debug, void *file)
                             sec->sh_size, buf);
 
   if (debug_displays [debug].relocate)
-    debug_apply_rela_addends (file, sec, section->start);
+    debug_apply_relocations (file, sec, section->start);
 
   return section->start != NULL;
 }
@@ -8231,8 +8589,8 @@ static const char *arm_attr_tag_CPU_arch[] =
 static const char *arm_attr_tag_ARM_ISA_use[] = {"No", "Yes"};
 static const char *arm_attr_tag_THUMB_ISA_use[] =
   {"No", "Thumb-1", "Thumb-2"};
-/* FIXME: VFPv3 encoding was extrapolated!  */
-static const char *arm_attr_tag_VFP_arch[] = {"No", "VFPv1", "VFPv2", "VFPv3"};
+static const char *arm_attr_tag_VFP_arch[] =
+  {"No", "VFPv1", "VFPv2", "VFPv3", "VFPv3-D16"};
 static const char *arm_attr_tag_WMMX_arch[] = {"No", "WMMXv1"};
 static const char *arm_attr_tag_NEON_arch[] = {"No", "NEONv1"};
 static const char *arm_attr_tag_ABI_PCS_config[] =
@@ -8508,6 +8866,32 @@ display_power_gnu_attribute (unsigned char *p, int tag)
       return p;
    }
 
+  if (tag == Tag_GNU_Power_ABI_Vector)
+    {
+      val = read_uleb128 (p, &len);
+      p += len;
+      printf ("  Tag_GNU_Power_ABI_Vector: ");
+      switch (val)
+       {
+       case 0:
+         printf ("Any\n");
+         break;
+       case 1:
+         printf ("Generic\n");
+         break;
+       case 2:
+         printf ("AltiVec\n");
+         break;
+       case 3:
+         printf ("SPE\n");
+         break;
+       default:
+         printf ("??? (%d)\n", val);
+         break;
+       }
+      return p;
+   }
+
   if (tag & 1)
     type = 1; /* String.  */
   else
@@ -8556,6 +8940,9 @@ display_mips_gnu_attribute (unsigned char *p, int tag)
        case 3:
          printf ("Soft float\n");
          break;
+       case 4:
+         printf ("64-bit float (-mips32r2 -mfp64)\n");
+         break;
        default:
          printf ("??? (%d)\n", val);
          break;
@@ -9153,7 +9540,7 @@ process_gnu_liblist (FILE *file)
       switch (section->sh_type)
        {
        case SHT_GNU_LIBLIST:
-         if (SECTION_HEADER_INDEX (section->sh_link) >= elf_header.e_shnum)
+         if (section->sh_link >= elf_header.e_shnum)
            break;
 
          elib = get_data (NULL, file, section->sh_offset, 1, section->sh_size,
@@ -9161,7 +9548,7 @@ process_gnu_liblist (FILE *file)
 
          if (elib == NULL)
            break;
-         string_sec = SECTION_HEADER (section->sh_link);
+         string_sec = section_headers + section->sh_link;
 
          strtab = get_data (NULL, file, string_sec->sh_offset, 1,
                             string_sec->sh_size, _("liblist string table"));
@@ -9238,6 +9625,8 @@ get_note_type (unsigned e_type)
        return _("NT_TASKSTRUCT (task structure)");
       case NT_PRXFPREG:
        return _("NT_PRXFPREG (user_xfpregs structure)");
+      case NT_PPC_VMX:
+       return _("NT_PPC_VMX (ppc Altivec registers)");
       case NT_PSTATUS:
        return _("NT_PSTATUS (pstatus structure)");
       case NT_FPREGS:
@@ -9646,8 +10035,6 @@ get_file_header (FILE *file)
        get_64bit_section_headers (file, 1);
     }
 
-  is_relocatable = elf_header.e_type == ET_REL;
-
   return 1;
 }
 
This page took 0.051667 seconds and 4 git commands to generate.