]> git.ipfire.org Git - thirdparty/binutils-gdb.git/blobdiff - binutils/readelf.c
* readelf.c (process_section_headers): Add H8/300 support.
[thirdparty/binutils-gdb.git] / binutils / readelf.c
index 04f64adca05ef2486975e270539b9bb45a7d26d0..8550ce4c584180ad39cf2eacd35b0874d60f388e 100644 (file)
@@ -222,9 +222,11 @@ static void (*byte_put) (unsigned char *, bfd_vma, int);
 
 #define UNKNOWN -1
 
-#define SECTION_NAME(X)        ((X) == NULL ? "<none>" : \
-                        ((X)->sh_name >= string_table_length \
-                         ? "<corrupt>" : string_table + (X)->sh_name))
+#define SECTION_NAME(X)        \
+  ((X) == NULL ? "<none>" \
+  : string_table == NULL ? "<no-name>" \
+  : ((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)                                \
@@ -1695,6 +1697,7 @@ get_machine_name (unsigned e_machine)
     case EM_BLACKFIN:          return "Analog Devices Blackfin";
     case EM_NIOS32:            return "Altera Nios";
     case EM_ALTERA_NIOS2:      return "Altera Nios II";
+    case EM_XC16X:             return "Infineon Technologies xc16x";
     default:
       snprintf (buff, sizeof (buff), _("<unknown>: %x"), e_machine);
       return buff;
@@ -1792,6 +1795,11 @@ decode_ARM_machine_flags (unsigned e_flags, char buf[])
 
     case EF_ARM_EABI_VER4:
       strcat (buf, ", Version4 EABI");
+      goto eabi;
+
+    case EF_ARM_EABI_VER5:
+      strcat (buf, ", Version5 EABI");
+    eabi:
       while (e_flags)
        {
          unsigned flag;
@@ -1940,10 +1948,60 @@ get_machine_flags (unsigned e_flags, unsigned e_machine)
          break;
 
        case EM_68K:
-         if (e_flags & EF_CPU32)
+         if (e_flags & EF_M68K_CPU32)
            strcat (buf, ", cpu32");
-         if (e_flags & EF_M68000)
+         if (e_flags & EF_M68K_M68000)
            strcat (buf, ", m68000");
+         if (e_flags & EF_M68K_ISA_MASK)
+           {
+             char const *isa = _("unknown");
+             char const *mac = _("unknown mac");
+             char const *additional = NULL;
+      
+             switch (e_flags & EF_M68K_ISA_MASK)
+               {
+               case EF_M68K_ISA_A_NODIV:
+                 isa = "A";
+                 additional = ", nodiv";
+                 break;
+               case EF_M68K_ISA_A:
+                 isa = "A";
+                 break;
+               case EF_M68K_ISA_A_PLUS:
+                 isa = "A+";
+                 break;
+               case EF_M68K_ISA_B_NOUSP:
+                 isa = "B";
+                 additional = ", nousp";
+                 break;
+               case EF_M68K_ISA_B:
+                 isa = "B";
+                 break;
+               }
+             strcat (buf, ", cf, isa ");
+             strcat (buf, isa);
+             if (additional)
+               strcat (buf, additional);
+             if (e_flags & EF_M68K_FLOAT)
+               strcat (buf, ", float");
+             switch (e_flags & EF_M68K_MAC_MASK)
+               {
+               case 0:
+                 mac = NULL;
+                 break;
+               case EF_M68K_MAC:
+                 mac = "mac";
+                 break;
+               case EF_M68K_EMAC:
+                 mac = "emac";
+                 break;
+               }
+             if (mac)
+               {
+                 strcat (buf, ", ");
+                 strcat (buf, mac);
+               }
+           }
          break;
 
        case EM_PPC:
@@ -2081,6 +2139,12 @@ get_machine_flags (unsigned e_flags, unsigned e_machine)
            case EF_SH4_NOFPU: strcat (buf, ", sh4-nofpu"); break;
            case EF_SH4A_NOFPU: strcat (buf, ", sh4a-nofpu"); break;
            case EF_SH2A_NOFPU: strcat (buf, ", sh2a-nofpu"); break;
+           case EF_SH3_NOMMU: strcat (buf, ", sh3-nommu"); break;
+           case EF_SH4_NOMMU_NOFPU: strcat (buf, ", sh4-nommu-nofpu"); break;
+           case EF_SH2A_SH4_NOFPU: strcat (buf, ", sh2a-nofpu-or-sh4-nommu-nofpu"); break;
+           case EF_SH2A_SH3_NOFPU: strcat (buf, ", sh2a-nofpu-or-sh3-nommu"); break;
+           case EF_SH2A_SH4: strcat (buf, ", sh2a-or-sh4"); break;
+           case EF_SH2A_SH3E: strcat (buf, ", sh2a-or-sh3e"); break;
            default: strcat (buf, ", unknown ISA"); break;
            }
 
@@ -3080,6 +3144,11 @@ process_file_header (void)
              (long) elf_header.e_shstrndx);
       if (section_headers != NULL && elf_header.e_shstrndx == SHN_XINDEX)
        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)))
+       printf (" <corrupt: out of range>");
       putc ('\n', stdout);
     }
 
@@ -3089,6 +3158,11 @@ process_file_header (void)
        elf_header.e_shnum = section_headers[0].sh_size;
       if (elf_header.e_shstrndx == SHN_XINDEX)
        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)))
+       elf_header.e_shstrndx = SHN_UNDEF;
       free (section_headers);
       section_headers = NULL;
     }
@@ -3404,20 +3478,7 @@ process_program_headers (FILE *file)
 
          for (j = 1; j < elf_header.e_shnum; j++, section++)
            {
-             if (section->sh_size > 0
-                 /* PT_DYNAMIC segment contains only SHT_DYNAMIC
-                    sections.  */
-                 && (segment->p_type != PT_DYNAMIC
-                     || section->sh_type == SHT_DYNAMIC)
-                 /* Compare allocated sections by VMA, unallocated
-                    sections by file offset.  */
-                 && (section->sh_flags & SHF_ALLOC
-                     ? (section->sh_addr >= segment->p_vaddr
-                        && section->sh_addr + section->sh_size
-                        <= segment->p_vaddr + segment->p_memsz)
-                     : ((bfd_vma) section->sh_offset >= segment->p_offset
-                        && (section->sh_offset + section->sh_size
-                            <= segment->p_offset + segment->p_filesz))))
+             if (ELF_IS_SECTION_IN_SEGMENT_MEMORY(section, segment))
                printf ("%s ", SECTION_NAME (section));
            }
 
@@ -3871,7 +3932,8 @@ process_section_headers (FILE *file)
     return 0;
 
   /* Read in the string table, so that we have names to display.  */
-  if (SECTION_HEADER_INDEX (elf_header.e_shstrndx) < elf_header.e_shnum)
+  if (elf_header.e_shstrndx != SHN_UNDEF
+       && SECTION_HEADER_INDEX (elf_header.e_shstrndx) < elf_header.e_shnum)
     {
       section = SECTION_HEADER (elf_header.e_shstrndx);
 
@@ -3909,6 +3971,23 @@ process_section_headers (FILE *file)
          && find_section (".gcc_compiled_long32") == NULL)
        eh_addr_size = 8;
       break;
+
+    case EM_H8_300:
+    case EM_H8_300H:
+      switch (elf_header.e_flags & EF_H8_MACH)
+       {
+       case E_H8_MACH_H8300:
+       case E_H8_MACH_H8300HN:
+       case E_H8_MACH_H8300SN:
+       case E_H8_MACH_H8300SXN:
+         eh_addr_size = 2;
+         break;
+       case E_H8_MACH_H8300H:
+       case E_H8_MACH_H8300S:
+       case E_H8_MACH_H8300SX:
+         eh_addr_size = 4;
+         break;
+       }
     }
 
 #define CHECK_ENTSIZE_VALUES(section, i, size32, size64) \
@@ -7682,7 +7761,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"};
-static const char *arm_attr_tag_VFP_arch[] = {"No", "VFPv1", "VFPv2"};
+/* FIXME: VFPv3 encoding was extrapolated!  */
+static const char *arm_attr_tag_VFP_arch[] = {"No", "VFPv1", "VFPv2", "VFPv3"};
 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[] =
@@ -7724,7 +7804,7 @@ static const char *arm_attr_tag_ABI_FP_optimization_goals[] =
 
 #define LOOKUP(id, name) \
   {id, #name, 0x80 | ARRAY_SIZE(arm_attr_tag_##name), arm_attr_tag_##name}
-static arm_attr_public_tag arm_attr_public_tags[] = 
+static arm_attr_public_tag arm_attr_public_tags[] =
 {
   {4, "CPU_raw_name", 1, NULL},
   {5, "CPU_name", 1, NULL},
@@ -7901,7 +7981,7 @@ process_arm_specific (FILE *file)
 
       contents = get_data (NULL, file, sect->sh_offset, 1, sect->sh_size,
                           _("attributes"));
-      
+
       if (!contents)
        continue;
       p = contents;
@@ -7991,7 +8071,7 @@ process_arm_specific (FILE *file)
        {
          printf (_("Unknown format '%c'\n"), *p);
        }
-       
+
       free(contents);
     }
   return 1;
@@ -8915,7 +8995,7 @@ process_object (char *file_name, FILE *file)
       assert (num_dump_sects >= num_cmdline_dump_sects);
       memcpy (dump_sects, cmdline_dump_sects, num_cmdline_dump_sects);
     }
-  
+
   if (! process_file_header ())
     return 1;
 
@@ -9161,7 +9241,7 @@ process_archive (char *file_name, FILE *file)
 
       archive_file_offset = ftell (file);
       archive_file_size = strtoul (arhdr.ar_size, NULL, 10);
-      
+
       ret |= process_object (namealc, file);
 
       free (namealc);