PR23430, Indices misspelled
[deliverable/binutils-gdb.git] / binutils / readelf.c
index eecc05b3fa65246809004ca651e9799ba958ffd3..7c5a0266bddf92162b1d915be051926a17fffb67 100644 (file)
 #include "elf/m32r.h"
 #include "elf/m68k.h"
 #include "elf/m68hc11.h"
+#include "elf/s12z.h"
 #include "elf/mcore.h"
 #include "elf/mep.h"
 #include "elf/metag.h"
 #include "elf/mt.h"
 #include "elf/msp430.h"
 #include "elf/nds32.h"
+#include "elf/nfp.h"
 #include "elf/nios2.h"
 #include "elf/or1k.h"
 #include "elf/pj.h"
@@ -776,6 +778,7 @@ guess_is_rela (unsigned int e_machine)
     case EM_CYGNUS_M32R:
     case EM_SCORE:
     case EM_XGATE:
+    case EM_NFP:
       return FALSE;
 
       /* Targets that use RELA relocations.  */
@@ -1272,6 +1275,10 @@ dump_relocations (Filedata *          filedata,
          rtype = elf_m68hc11_reloc_type (type);
          break;
 
+       case EM_S12Z:
+         rtype = elf_s12z_reloc_type (type);
+         break;
+
        case EM_68K:
          rtype = elf_m68k_reloc_type (type);
          break;
@@ -1560,6 +1567,13 @@ dump_relocations (Filedata *          filedata,
        case EM_TI_PRU:
          rtype = elf_pru_reloc_type (type);
          break;
+
+       case EM_NFP:
+         if (EF_NFP_MACH (filedata->file_header.e_flags) == E_NFP_MACH_3200)
+           rtype = elf_nfp3200_reloc_type (type);
+         else
+           rtype = elf_nfp_reloc_type (type);
+         break;
        }
 
       if (rtype == NULL)
@@ -2472,6 +2486,7 @@ get_machine_name (unsigned e_machine)
     case EM_RISCV:             return "RISC-V";
     case EM_LANAI:             return "Lanai 32-bit processor";
     case EM_BPF:               return "Linux BPF";
+    case EM_NFP:               return "Netronome Flow Processor";
 
       /* Large numbers...  */
     case EM_MT:                 return "Morpho Techologies MT processor";
@@ -2485,6 +2500,7 @@ get_machine_name (unsigned e_machine)
     case EM_CYGNUS_MEP:         return "Toshiba MeP Media Engine";
     case EM_ADAPTEVA_EPIPHANY: return "Adapteva EPIPHANY";
     case EM_CYGNUS_FRV:                return "Fujitsu FR-V";
+    case EM_S12Z:               return "Freescale S12Z";
 
     default:
       snprintf (buff, sizeof (buff), _("<unknown>: 0x%x"), e_machine);
@@ -3440,10 +3456,25 @@ get_machine_flags (Filedata * filedata, unsigned e_flags, unsigned e_machine)
          decode_NDS32_machine_flags (e_flags, buf, sizeof buf);
          break;
 
+       case EM_NFP:
+         switch (EF_NFP_MACH (e_flags))
+           {
+           case E_NFP_MACH_3200:
+             strcat (buf, ", NFP-32xx");
+             break;
+           case E_NFP_MACH_6000:
+             strcat (buf, ", NFP-6xxx");
+             break;
+           }
+         break;
+
        case EM_RISCV:
          if (e_flags & EF_RISCV_RVC)
            strcat (buf, ", RVC");
 
+         if (e_flags & EF_RISCV_RVE)
+           strcat (buf, ", RVE");
+
          switch (e_flags & EF_RISCV_FLOAT_ABI)
            {
            case EF_RISCV_FLOAT_ABI_SOFT:
@@ -4135,6 +4166,18 @@ get_msp430x_section_type_name (unsigned int sh_type)
     }
 }
 
+static const char *
+get_nfp_section_type_name (unsigned int sh_type)
+{
+  switch (sh_type)
+    {
+    case SHT_NFP_MECONFIG:     return "NFP_MECONFIG";
+    case SHT_NFP_INITREG:      return "NFP_INITREG";
+    case SHT_NFP_UDEBUG:       return "NFP_UDEBUG";
+    default:                   return NULL;
+    }
+}
+
 static const char *
 get_v850_section_type_name (unsigned int sh_type)
 {
@@ -4174,7 +4217,7 @@ get_section_type_name (Filedata * filedata, unsigned int sh_type)
     case SHT_PREINIT_ARRAY:    return "PREINIT_ARRAY";
     case SHT_GNU_HASH:         return "GNU_HASH";
     case SHT_GROUP:            return "GROUP";
-    case SHT_SYMTAB_SHNDX:     return "SYMTAB SECTION INDICIES";
+    case SHT_SYMTAB_SHNDX:     return "SYMTAB SECTION INDICES";
     case SHT_GNU_verdef:       return "VERDEF";
     case SHT_GNU_verneed:      return "VERNEED";
     case SHT_GNU_versym:       return "VERSYM";
@@ -4221,6 +4264,9 @@ get_section_type_name (Filedata * filedata, unsigned int sh_type)
            case EM_MSP430:
              result = get_msp430x_section_type_name (sh_type);
              break;
+           case EM_NFP:
+             result = get_nfp_section_type_name (sh_type);
+             break;
            case EM_V800:
            case EM_V850:
            case EM_CYGNUS_V850:
@@ -5439,7 +5485,7 @@ get_32bit_elf_symbols (Filedata *           filedata,
          shndx = (Elf_External_Sym_Shndx *) get_data (NULL, filedata,
                                                       entry->hdr->sh_offset,
                                                       1, entry->hdr->sh_size,
-                                                      _("symbol table section indicies"));
+                                                      _("symbol table section indices"));
          if (shndx == NULL)
            goto exit_point;
          /* PR17531: file: heap-buffer-overflow */
@@ -5552,7 +5598,7 @@ get_64bit_elf_symbols (Filedata *           filedata,
          shndx = (Elf_External_Sym_Shndx *) get_data (NULL, filedata,
                                                       entry->hdr->sh_offset,
                                                       1, entry->hdr->sh_size,
-                                                      _("symbol table section indicies"));
+                                                      _("symbol table section indices"));
          if (shndx == NULL)
            goto exit_point;
          /* PR17531: file: heap-buffer-overflow */
@@ -6462,8 +6508,7 @@ process_section_headers (Filedata * filedata)
        }
       else if (do_section_details)
        {
-         printf ("       %-15.15s  ",
-                 get_section_type_name (filedata, section->sh_type));
+         putchar (' ');
          print_vma (section->sh_addr, LONG_HEX);
          if ((long) section->sh_offset == section->sh_offset)
            printf ("  %16.16lx", (unsigned long) section->sh_offset);
@@ -6797,7 +6842,7 @@ process_section_groups (Filedata * filedata)
                      error (_("section [%5u] in group section [%5u] > maximum section [%5u]\n"),
                             entry, i, filedata->file_header.e_shnum - 1);
                      if (num_group_errors == 10)
-                       warn (_("Further error messages about overlarge group section indicies suppressed\n"));
+                       warn (_("Further error messages about overlarge group section indices suppressed\n"));
                    }
                  continue;
                }
@@ -11220,7 +11265,7 @@ get_symbol_version_string (Filedata *                   filedata,
 
   vers_data = byte_get (data, 2);
 
-  if ((vers_data & VERSYM_HIDDEN) == 0 && vers_data <= 1)
+  if ((vers_data & VERSYM_HIDDEN) == 0 && vers_data == 0)
     return NULL;
 
   /* Usually we'd only see verdef for defined symbols, and verneed for
@@ -11255,12 +11300,14 @@ get_symbol_version_string (Filedata *                   filedata,
              ivd.vd_ndx = 0;
              ivd.vd_aux = 0;
              ivd.vd_next = 0;
+             ivd.vd_flags = 0;
            }
          else
            {
              ivd.vd_ndx = BYTE_GET (evd.vd_ndx);
              ivd.vd_aux = BYTE_GET (evd.vd_aux);
              ivd.vd_next = BYTE_GET (evd.vd_next);
+             ivd.vd_flags = BYTE_GET (evd.vd_flags);
            }
 
          off += ivd.vd_next;
@@ -11269,6 +11316,9 @@ get_symbol_version_string (Filedata *                   filedata,
 
       if (ivd.vd_ndx == (vers_data & VERSYM_VERSION))
        {
+         if (ivd.vd_ndx == 1 && ivd.vd_flags == VER_FLG_BASE) 
+           return NULL;
+
          off -= ivd.vd_next;
          off += ivd.vd_aux;
 
@@ -12271,6 +12321,8 @@ is_32bit_abs_reloc (Filedata * filedata, unsigned int reloc_type)
     case EM_68HC11:
     case EM_68HC12:
       return reloc_type == 6; /* R_M68HC11_32.  */
+    case EM_S12Z:
+      return reloc_type == 6; /* R_S12Z_EXT32.  */
     case EM_MCORE:
       return reloc_type == 1; /* R_MCORE_ADDR32.  */
     case EM_CYGNUS_MEP:
@@ -12606,6 +12658,8 @@ is_16bit_abs_reloc (Filedata * filedata, unsigned int reloc_type)
       return reloc_type == 9; /* R_NIOS_16.  */
     case EM_OR1K:
       return reloc_type == 2; /* R_OR1K_16.  */
+    case EM_RISCV:
+      return reloc_type == 55; /* R_RISCV_SET16.  */
     case EM_TI_PRU:
       return reloc_type == 8; /* R_PRU_BFD_RELOC_16.  */
     case EM_TI_C6000:
@@ -12622,6 +12676,36 @@ is_16bit_abs_reloc (Filedata * filedata, unsigned int reloc_type)
     }
 }
 
+/* Like is_32bit_abs_reloc except that it returns TRUE iff RELOC_TYPE is
+   a 8-bit absolute RELA relocation used in DWARF debug sections.  */
+
+static bfd_boolean
+is_8bit_abs_reloc (Filedata * filedata, unsigned int reloc_type)
+{
+  switch (filedata->file_header.e_machine)
+    {
+    case EM_RISCV:
+      return reloc_type == 54; /* R_RISCV_SET8.  */
+    default:
+      return FALSE;
+    }
+}
+
+/* Like is_32bit_abs_reloc except that it returns TRUE iff RELOC_TYPE is
+   a 6-bit absolute RELA relocation used in DWARF debug sections.  */
+
+static bfd_boolean
+is_6bit_abs_reloc (Filedata * filedata, unsigned int reloc_type)
+{
+  switch (filedata->file_header.e_machine)
+    {
+    case EM_RISCV:
+      return reloc_type == 53; /* R_RISCV_SET6.  */
+    default:
+      return FALSE;
+    }
+}
+
 /* Like is_32bit_abs_reloc except that it returns TRUE iff RELOC_TYPE is
    a 32-bit inplace add RELA relocation used in DWARF debug sections.  */
 
@@ -12750,6 +12834,21 @@ is_8bit_inplace_sub_reloc (Filedata * filedata, unsigned int reloc_type)
     }
 }
 
+/* Like is_32bit_abs_reloc except that it returns TRUE iff RELOC_TYPE is
+   a 6-bit inplace sub RELA relocation used in DWARF debug sections.  */
+
+static bfd_boolean
+is_6bit_inplace_sub_reloc (Filedata * filedata, unsigned int reloc_type)
+{
+  switch (filedata->file_header.e_machine)
+    {
+    case EM_RISCV:
+      return reloc_type == 52; /* R_RISCV_SUB6.  */
+    default:
+      return FALSE;
+    }
+}
+
 /* Returns TRUE iff RELOC_TYPE is a NONE relocation used for discarded
    relocation entries (possibly formerly used for SHT_GROUP sections).  */
 
@@ -12953,6 +13052,9 @@ apply_relocations (Filedata *                 filedata,
            reloc_size = 3;
          else if (is_16bit_abs_reloc (filedata, reloc_type))
            reloc_size = 2;
+         else if (is_8bit_abs_reloc (filedata, reloc_type)
+                  || is_6bit_abs_reloc (filedata, reloc_type))
+           reloc_size = 1;
          else if ((reloc_subtract = is_32bit_inplace_sub_reloc (filedata,
                                                                 reloc_type))
                   || is_32bit_inplace_add_reloc (filedata, reloc_type))
@@ -12981,6 +13083,12 @@ apply_relocations (Filedata *                 filedata,
              reloc_size = 1;
              reloc_inplace = TRUE;
            }
+         else if ((reloc_subtract = is_6bit_inplace_sub_reloc (filedata,
+                                                               reloc_type)))
+           {
+             reloc_size = 1;
+             reloc_inplace = TRUE;
+           }
          else
            {
              static unsigned int prev_reloc = 0;
@@ -13053,7 +13161,12 @@ apply_relocations (Filedata *                 filedata,
                   || filedata->file_header.e_machine == EM_CYGNUS_D30V)
                  && reloc_type == 12)
              || reloc_inplace)
-           addend += byte_get (rloc, reloc_size);
+           {
+             if (is_6bit_inplace_sub_reloc (filedata, reloc_type))
+               addend += byte_get (rloc, reloc_size) & 0x3f;
+             else
+               addend += byte_get (rloc, reloc_size);
+           }
 
          if (is_32bit_pcrel_reloc (filedata, reloc_type)
              || is_64bit_pcrel_reloc (filedata, reloc_type))
@@ -13064,6 +13177,16 @@ apply_relocations (Filedata *                 filedata,
              byte_put (rloc, (addend + sym->st_value) - rp->r_offset,
                        reloc_size);
            }
+         else if (is_6bit_abs_reloc (filedata, reloc_type)
+                  || is_6bit_inplace_sub_reloc (filedata, reloc_type))
+           {
+             if (reloc_subtract)
+               addend -= sym->st_value;
+             else
+               addend += sym->st_value;
+             addend = (addend & 0x3f) | (byte_get (rloc, reloc_size) & 0xc0);
+             byte_put (rloc, addend, reloc_size);
+           }
          else if (reloc_subtract)
            byte_put (rloc, addend - sym->st_value, reloc_size);
          else
@@ -15456,6 +15579,12 @@ print_mips_ases (unsigned int mask)
     fputs ("\n\tXPA ASE", stdout);
   if (mask & AFL_ASE_MIPS16E2)
     fputs ("\n\tMIPS16e2 ASE", stdout);
+  if (mask & AFL_ASE_CRC)
+    fputs ("\n\tCRC ASE", stdout);
+  if (mask & AFL_ASE_GINV)
+    fputs ("\n\tGINV ASE", stdout);
+  if (mask & AFL_ASE_LOONGSON_MMI)
+    fputs ("\n\tLoongson MMI ASE", stdout);
   if (mask == 0)
     fprintf (stdout, "\n\t%s", _("None"));
   else if ((mask & ~AFL_ASE_MASK) != 0)
@@ -16552,7 +16681,7 @@ get_note_type (Filedata * filedata, unsigned e_type)
       case NT_PPC_TM_CVMX:
        return _("NT_PPC_TM_CVMX (ppc checkpointed Altivec registers)");
       case NT_PPC_TM_CVSX:
-       return _("NT_PPC_TM_VSX (ppc checkpointed VSX registers)");
+       return _("NT_PPC_TM_CVSX (ppc checkpointed VSX registers)");
       case NT_PPC_TM_SPR:
        return _("NT_PPC_TM_SPR (ppc TM special purpose registers)");
       case NT_PPC_TM_CTAR:
@@ -17577,6 +17706,20 @@ get_symbol_for_build_attribute (Filedata *       filedata,
   return saved_sym;
 }
 
+/* Returns true iff addr1 and addr2 are in the same section.  */
+
+static bfd_boolean
+same_section (Filedata * filedata, unsigned long addr1, unsigned long addr2)
+{
+  Elf_Internal_Shdr * a1;
+  Elf_Internal_Shdr * a2;
+
+  a1 = find_section_by_address (filedata, addr1);
+  a2 = find_section_by_address (filedata, addr2);
+  
+  return a1 == a2 && a1 != NULL;
+}
+
 static bfd_boolean
 print_gnu_build_attribute_description (Elf_Internal_Note *  pnote,
                                       Filedata *           filedata)
@@ -17658,8 +17801,14 @@ print_gnu_build_attribute_description (Elf_Internal_Note *  pnote,
 
   if (is_open_attr)
     {
-      /* FIXME: Need to properly allow for section alignment.  16 is just the alignment used on x86_64.  */
-      if (global_end > 0 && start > BFD_ALIGN (global_end, 16))
+      /* FIXME: Need to properly allow for section alignment.
+        16 is just the alignment used on x86_64.  */
+      if (global_end > 0
+         && start > BFD_ALIGN (global_end, 16)
+         /* Build notes are not guaranteed to be organised in order of
+            increasing address, but we should find the all of the notes
+            for one section in the same place.  */
+         && same_section (filedata, start, global_end))
        warn (_("Gap in build notes detected from %#lx to %#lx\n"),
              global_end + 1, start - 1);
 
@@ -18878,7 +19027,7 @@ process_archive (Filedata * filedata, bfd_boolean is_thin_archive)
              l += strnlen (arch.sym_table + l, arch.sym_size - l) + 1;
            }
 
-         if (arch.uses_64bit_indicies)
+         if (arch.uses_64bit_indices)
            l = (l + 7) & ~ 7;
          else
            l += l & 1;
This page took 0.034128 seconds and 4 git commands to generate.