include/elf/
[deliverable/binutils-gdb.git] / binutils / readelf.c
index 1631a94dcccc9366e7a1731bdbd2d42fcb196198..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)
     {
@@ -990,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 "
@@ -1276,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)
@@ -1303,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>",
@@ -1496,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;
     }
@@ -1662,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;
@@ -2196,6 +2237,7 @@ get_machine_flags (unsigned e_flags, unsigned e_machine)
            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
@@ -2631,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;
     }
@@ -2737,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
@@ -3006,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;
 
@@ -3040,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;
 
@@ -3220,6 +3279,8 @@ process_file_header (void)
       return 0;
     }
 
+  init_dwarf_regnames (elf_header.e_machine);
+
   if (do_header)
     {
       int i;
@@ -3272,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;
@@ -3769,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"));
@@ -3800,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);
     }
@@ -3832,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"));
@@ -3863,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);
     }
@@ -3887,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;
@@ -3903,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)
@@ -3937,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;
            }
 
@@ -4081,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)
        {
@@ -4136,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) \
@@ -4287,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 ",
@@ -4295,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));
 
@@ -4518,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);
@@ -4538,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);
@@ -4555,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)
@@ -4565,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)
@@ -4604,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
@@ -4636,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));
                }
 
@@ -4779,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;
@@ -4789,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;
@@ -4800,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,
@@ -5040,8 +5130,8 @@ slurp_ia64_unwind_table (FILE *file,
        ++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,
@@ -5099,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;
@@ -5139,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;
@@ -5443,8 +5533,8 @@ slurp_hppa_unwind_table (FILE *file,
        ++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,
@@ -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;
@@ -7368,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"));
@@ -7417,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);
@@ -7798,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"));
@@ -7820,7 +7905,11 @@ dump_section_as_strings (Elf_Internal_Shdr *section, FILE *file)
 
       if (data < end)
        {
+#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;
        }
@@ -7873,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"));
@@ -8166,6 +8255,8 @@ is_16bit_abs_reloc (unsigned int reloc_type)
     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.  */
@@ -8203,10 +8294,10 @@ debug_apply_relocations (void *file,
       Elf_Internal_Sym *sym;
 
       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;
 
       is_rela = relsec->sh_type == SHT_RELA;
@@ -8228,7 +8319,7 @@ debug_apply_relocations (void *file,
       if (elf_header.e_machine == EM_SH)
        is_rela = FALSE;
 
-      symsec = SECTION_HEADER (relsec->sh_link);
+      symsec = section_headers + relsec->sh_link;
       symtab = GET_ELF_SYMBOLS (file, symsec);
 
       for (rp = relocs; rp < relocs + num_relocs; ++rp)
@@ -8498,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[] =
@@ -9449,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,
@@ -9457,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"));
This page took 0.036686 seconds and 4 git commands to generate.