correct ft32 reloc range test
[deliverable/binutils-gdb.git] / bfd / elf32-nds32.c
index 5ceb0a0b26f7b655de2ba773f65e8cc3ecb76693..e240d31032272f4457ace3c3a8262d908c28dc6a 100644 (file)
@@ -2884,8 +2884,8 @@ bfd_elf32_bfd_reloc_type_lookup (bfd *abfd ATTRIBUTE_UNUSED,
 
 /* Set the howto pointer for an NDS32 ELF reloc.  */
 
-static void
-nds32_info_to_howto_rel (bfd *abfd ATTRIBUTE_UNUSED, arelent *cache_ptr,
+static bfd_boolean
+nds32_info_to_howto_rel (bfd *abfd, arelent *cache_ptr,
                         Elf_Internal_Rela *dst)
 {
   enum elf_nds32_reloc_type r_type;
@@ -2894,20 +2894,33 @@ nds32_info_to_howto_rel (bfd *abfd ATTRIBUTE_UNUSED, arelent *cache_ptr,
   if (r_type > R_NDS32_GNU_VTENTRY)
     {
       /* xgettext:c-format */
-      _bfd_error_handler (_("%B: invalid NDS32 reloc number: %d"), abfd, r_type);
-      r_type = 0;
+      _bfd_error_handler (_("%pB: unsupported relocation type %#x"),
+                         abfd, r_type);
+      bfd_set_error (bfd_error_bad_value);
+      return FALSE;
     }
   cache_ptr->howto = bfd_elf32_bfd_reloc_type_table_lookup (r_type);
+  return TRUE;
 }
 
-static void
+static bfd_boolean
 nds32_info_to_howto (bfd *abfd ATTRIBUTE_UNUSED, arelent *cache_ptr,
                     Elf_Internal_Rela *dst)
 {
-  BFD_ASSERT ((ELF32_R_TYPE (dst->r_info) == R_NDS32_NONE)
-             || ((ELF32_R_TYPE (dst->r_info) > R_NDS32_GNU_VTENTRY)
-                 && (ELF32_R_TYPE (dst->r_info) < R_NDS32_max)));
-  cache_ptr->howto = bfd_elf32_bfd_reloc_type_table_lookup (ELF32_R_TYPE (dst->r_info));
+  unsigned int r_type = ELF32_R_TYPE (dst->r_info);
+
+  if ((r_type == R_NDS32_NONE)
+      || ((r_type > R_NDS32_GNU_VTENTRY)
+         && (r_type < R_NDS32_max)))
+    {
+      cache_ptr->howto = bfd_elf32_bfd_reloc_type_table_lookup (r_type);
+      return TRUE;
+    }
+
+  /* xgettext:c-format */
+  _bfd_error_handler (_("%pB: unsupported relocation type %#x"), abfd, r_type);
+  bfd_set_error (bfd_error_bad_value);
+  return FALSE;  
 }
 
 /* Support for core dump NOTE sections.
@@ -3229,7 +3242,7 @@ nds32_elf_final_sda_base (bfd *output_bfd, struct bfd_link_info *info,
        }
       else
        {
-         _bfd_error_handler (_("error: Can't find symbol: _SDA_BASE_."));
+         _bfd_error_handler (_("error: can't find symbol: %s"), "_SDA_BASE_");
          return bfd_reloc_dangerous;
        }
     }
@@ -3841,7 +3854,7 @@ maybe_set_textrel (struct elf_link_hash_entry *h, void *info_p)
 
       info->flags |= DF_TEXTREL;
       info->callbacks->minfo
-       (_("%B: dynamic relocation against `%T' in read-only section `%A'\n"),
+       (_("%pB: dynamic relocation against `%pT' in read-only section `%pA'\n"),
         sec->owner, h->root.root.string, sec);
 
       /* Not an error, just cut short the traversal.  */
@@ -4407,15 +4420,15 @@ nds32_elf_relocate_section (bfd *                  output_bfd ATTRIBUTE_UNUSED,
       /* Set the _ITB_BASE_.  */
       if (!nds32_elf_ex9_itb_base (info))
        {
-         _bfd_error_handler (_("%B: error: Cannot set _ITB_BASE_"),
-                             output_bfd);
+         _bfd_error_handler (_("%pB: error: cannot set %s"),
+                             output_bfd, "_ITB_BASE_");
          bfd_set_error (bfd_error_bad_value);
        }
     }
 
   if (table->target_optimize & NDS32_RELAX_JUMP_IFC_ON)
     if (!nds32_elf_ifc_reloc ())
-      _bfd_error_handler (_("error: IFC relocation error."));
+      _bfd_error_handler (_("error: IFC relocation error"));
 
  /* Relocation for .ex9.itable.  */
   if (table->target_optimize & NDS32_RELAX_EX9_ON
@@ -4449,7 +4462,7 @@ nds32_elf_relocate_section (bfd *            output_bfd ATTRIBUTE_UNUSED,
       if (r_type >= R_NDS32_max)
        {
          /* xgettext:c-format */
-         _bfd_error_handler (_("%B: error: unknown relocation type %d."),
+         _bfd_error_handler (_("%pB: unsupported relocation type %#x"),
                              input_bfd, r_type);
          bfd_set_error (bfd_error_bad_value);
          ret = FALSE;
@@ -4895,8 +4908,8 @@ nds32_elf_relocate_section (bfd *            output_bfd ATTRIBUTE_UNUSED,
          if (bfd_link_pic (info))
            {
              _bfd_error_handler
-               (_("%B: warning: cannot deal R_NDS32_25_ABS_RELA in shared "
-                  "mode."), input_bfd);
+               (_("%pB: warning: %s unsupported in shared mode"),
+                input_bfd, "R_NDS32_25_ABS_RELA");
              return FALSE;
            }
          break;
@@ -5029,7 +5042,7 @@ nds32_elf_relocate_section (bfd *            output_bfd ATTRIBUTE_UNUSED,
            {
              /* Incorrect alignment.  */
              _bfd_error_handler
-               (_("%B: warning: unaligned access to GOT entry."), input_bfd);
+               (_("%pB: warning: unaligned access to GOT entry"), input_bfd);
              ret = FALSE;
              r = bfd_reloc_dangerous;
              goto check_reloc;
@@ -5071,7 +5084,7 @@ handle_sda:
              if (r != bfd_reloc_ok)
                {
                  _bfd_error_handler
-                   (_("%B: warning: relocate SDA_BASE failed."), input_bfd);
+                   (_("%pB: warning: relocate SDA_BASE failed"), input_bfd);
                  ret = FALSE;
                  goto check_reloc;
                }
@@ -5093,7 +5106,8 @@ handle_sda:
                  /* Incorrect alignment.  */
                  _bfd_error_handler
                    /* xgettext:c-format */
-                   (_("%B(%A): warning: unaligned small data access of type %d."),
+                   (_("%pB(%pA): warning: unaligned small data access"
+                      " of type %d"),
                     input_bfd, input_section, r_type);
                  ret = FALSE;
                  goto check_reloc;
@@ -5841,7 +5855,7 @@ nds32_check_vec_size (bfd *ibfd)
        {
          _bfd_error_handler
            /* xgettext:c-format */
-           (_("%B: ISR vector size mismatch"
+           (_("%pB: ISR vector size mismatch"
               " with previous modules, previous %u-byte, current %u-byte"),
             ibfd,
             nds32_vec_size == 1 ? 4 : nds32_vec_size == 2 ? 16 : 0xffffffff,
@@ -5885,7 +5899,7 @@ nds32_elf_merge_private_bfd_data (bfd *ibfd, struct bfd_link_info *info)
   if (bfd_little_endian (ibfd) != bfd_little_endian (obfd))
     {
       _bfd_error_handler
-       (_("%B: warning: Endian mismatch with previous modules."), ibfd);
+       (_("%pB: warning: endian mismatch with previous modules"), ibfd);
 
       bfd_set_error (bfd_error_bad_value);
       return FALSE;
@@ -5895,8 +5909,8 @@ nds32_elf_merge_private_bfd_data (bfd *ibfd, struct bfd_link_info *info)
   if (in_version == E_NDS32_ELF_VER_1_2)
     {
       _bfd_error_handler
-       (_("%B: warning: Older version of object file encountered, "
-          "Please recompile with current tool chain."), ibfd);
+       (_("%pB: warning: older version of object file encountered, "
+          "please recompile with current tool chain"), ibfd);
     }
 
   /* We may need to merge V1 and V2 arch object files to V2.  */
@@ -5973,7 +5987,7 @@ nds32_elf_merge_private_bfd_data (bfd *ibfd, struct bfd_link_info *info)
   if ((in_flags & EF_NDS_ABI) != (out_flags & EF_NDS_ABI))
     {
       _bfd_error_handler
-       (_("%B: error: ABI mismatch with previous modules."), ibfd);
+       (_("%pB: error: ABI mismatch with previous modules"), ibfd);
 
       bfd_set_error (bfd_error_bad_value);
       return FALSE;
@@ -5984,7 +5998,8 @@ nds32_elf_merge_private_bfd_data (bfd *ibfd, struct bfd_link_info *info)
       if (((in_flags & EF_NDS_ARCH) != E_N1_ARCH))
        {
          _bfd_error_handler
-           (_("%B: error: Instruction set mismatch with previous modules."), ibfd);
+           (_("%pB: error: instruction set mismatch with previous modules"),
+            ibfd);
 
          bfd_set_error (bfd_error_bad_value);
          return FALSE;
@@ -6010,7 +6025,7 @@ nds32_elf_merge_private_bfd_data (bfd *ibfd, struct bfd_link_info *info)
       if (in_version != out_version)
        _bfd_error_handler
          /* xgettext:c-format */
-         (_("%B: warning: Incompatible elf-versions %s and  %s."),
+         (_("%pB: warning: incompatible elf-versions %s and %s"),
           ibfd, nds32_elfver_strtab[out_version],
           nds32_elfver_strtab[in_version]);
 
@@ -8532,7 +8547,8 @@ done_adjust_diff:
                  && (blank_t2->offset > raddr
                      || blank_t2->next->offset <= raddr))
                _bfd_error_handler
-                 (_("%B: Error: search_nds32_elf_blank reports wrong node\n"), abfd);
+                 (_("%pB: error: search_nds32_elf_blank reports wrong node"),
+                  abfd);
 
              /* Mark reloc in deleted portion as NONE.
                 For some relocs like R_NDS32_LABEL that doesn't modify the
@@ -8791,7 +8807,7 @@ relax_range_measurement (bfd *abfd)
 
 static const char * unrecognized_reloc_msg =
   /* xgettext:c-format */
-  N_("%B: warning: %s points to unrecognized reloc at %#Lx");
+  N_("%pB: warning: %s points to unrecognized reloc at %#" PRIx64);
 
 /* Relax LONGCALL1 relocation for nds32_elf_relax_section.  */
 
@@ -8844,7 +8860,7 @@ nds32_elf_relax_longcall1 (bfd *abfd, asection *sec, Elf_Internal_Rela *irel,
   if (hi_irelfn == irelend || lo_irelfn == irelend)
     {
       _bfd_error_handler (unrecognized_reloc_msg, abfd, "R_NDS32_LONGCALL1",
-                         irel->r_offset);
+                         (uint64_t) irel->r_offset);
       return FALSE;
     }
 
@@ -8925,7 +8941,7 @@ nds32_elf_relax_longcall2 (bfd *abfd, asection *sec, Elf_Internal_Rela *irel,
   if (i1_irelfn == irelend)
     {
       _bfd_error_handler (unrecognized_reloc_msg, abfd, "R_NDS32_LONGCALL2",
-                         irel->r_offset);
+                         (uint64_t) irel->r_offset);
       return FALSE;
     }
 
@@ -9031,7 +9047,7 @@ nds32_elf_relax_longcall3 (bfd *abfd, asection *sec, Elf_Internal_Rela *irel,
   if (hi_irelfn == irelend || lo_irelfn == irelend)
     {
       _bfd_error_handler (unrecognized_reloc_msg, abfd, "R_NDS32_LONGCALL3",
-                         irel->r_offset);
+                         (uint64_t) irel->r_offset);
       return FALSE;
     }
 
@@ -9165,7 +9181,7 @@ nds32_elf_relax_longjump1 (bfd *abfd, asection *sec, Elf_Internal_Rela *irel,
   if (hi_irelfn == irelend || lo_irelfn == irelend)
     {
       _bfd_error_handler (unrecognized_reloc_msg, abfd, "R_NDS32_LONGJUMP1",
-                         irel->r_offset);
+                         (uint64_t) irel->r_offset);
       return FALSE;
     }
 
@@ -9371,7 +9387,7 @@ nds32_elf_relax_longjump2 (bfd *abfd, asection *sec, Elf_Internal_Rela *irel,
   if (i2_irelfn == irelend || cond_irelfn == irelend)
     {
       _bfd_error_handler (unrecognized_reloc_msg, abfd, "R_NDS32_LONGJUMP2",
-                         irel->r_offset);
+                         (uint64_t) irel->r_offset);
       return FALSE;
     }
 
@@ -9563,7 +9579,7 @@ nds32_elf_relax_longjump3 (bfd *abfd, asection *sec, Elf_Internal_Rela *irel,
   if (hi_irelfn == irelend || lo_irelfn == irelend || cond_irelfn == irelend)
     {
       _bfd_error_handler (unrecognized_reloc_msg, abfd, "R_NDS32_LONGJUMP3",
-                         irel->r_offset);
+                         (uint64_t) irel->r_offset);
       return FALSE;
     }
 
@@ -9690,7 +9706,6 @@ nds32_elf_relax_longjump3 (bfd *abfd, asection *sec, Elf_Internal_Rela *irel,
     else
       {
        irel->r_info = ELF32_R_INFO (ELF32_R_SYM (irel->r_info), reloc);
-       irel->r_addend = irel->r_addend;
        hi_irelfn->r_info = ELF32_R_INFO (ELF32_R_SYM (hi_irelfn->r_info),
                                          cond_reloc);
       }
@@ -9743,7 +9758,7 @@ nds32_elf_relax_longcall4 (bfd *abfd, asection *sec, Elf_Internal_Rela *irel,
   if (hi_irel == irelend)
     {
       _bfd_error_handler (unrecognized_reloc_msg, abfd, "R_NDS32_LONGCALL4",
-                         irel->r_offset);
+                         (uint64_t) irel->r_offset);
       return FALSE;
     }
 
@@ -9773,7 +9788,7 @@ nds32_elf_relax_longcall4 (bfd *abfd, asection *sec, Elf_Internal_Rela *irel,
   if (ptr_irel == irelend || em_irel == irelend)
     {
       _bfd_error_handler (unrecognized_reloc_msg, abfd, "R_NDS32_LONGCALL4",
-                         irel->r_offset);
+                         (uint64_t) irel->r_offset);
       return FALSE;
     }
   /* Check these is enough space to insert jal in R_NDS32_EMPTY.  */
@@ -9844,7 +9859,7 @@ nds32_elf_relax_longcall5 (bfd *abfd, asection *sec, Elf_Internal_Rela *irel,
   if (cond_irel == irelend)
     {
       _bfd_error_handler (unrecognized_reloc_msg, abfd, "R_NDS32_LONGCALL5",
-                         irel->r_offset);
+                         (uint64_t) irel->r_offset);
       return FALSE;
     }
 
@@ -9922,7 +9937,7 @@ nds32_elf_relax_longcall6 (bfd *abfd, asection *sec, Elf_Internal_Rela *irel,
   if (em_irel == irelend)
     {
       _bfd_error_handler (unrecognized_reloc_msg, abfd, "R_NDS32_LONGCALL6",
-                         irel->r_offset);
+                         (uint64_t) irel->r_offset);
       return FALSE;
     }
 
@@ -9960,7 +9975,7 @@ nds32_elf_relax_longcall6 (bfd *abfd, asection *sec, Elf_Internal_Rela *irel,
       if (cond_irel == irelend)
        {
          _bfd_error_handler (unrecognized_reloc_msg, abfd,
-                             "R_NDS32_LONGCALL6", irel->r_offset);
+                             "R_NDS32_LONGCALL6", (uint64_t) irel->r_offset);
          return FALSE;
        }
       cond_irel->r_addend = 1;
@@ -10009,7 +10024,7 @@ nds32_elf_relax_longcall6 (bfd *abfd, asection *sec, Elf_Internal_Rela *irel,
       if (cond_irel == irelend)
        {
          _bfd_error_handler (unrecognized_reloc_msg, abfd,
-                             "R_NDS32_LONGCALL6", irel->r_offset);
+                             "R_NDS32_LONGCALL6", (uint64_t) irel->r_offset);
          return FALSE;
        }
       cond_irel->r_addend = 1;
@@ -10059,7 +10074,7 @@ nds32_elf_relax_longjump4 (bfd *abfd, asection *sec, Elf_Internal_Rela *irel,
   if (hi_irel == irelend)
     {
       _bfd_error_handler (unrecognized_reloc_msg, abfd, "R_NDS32_LONGJUMP4",
-                         irel->r_offset);
+                         (uint64_t) irel->r_offset);
       return FALSE;
     }
 
@@ -10081,7 +10096,7 @@ nds32_elf_relax_longjump4 (bfd *abfd, asection *sec, Elf_Internal_Rela *irel,
   if (ptr_irel == irelend || em_irel == irelend)
     {
       _bfd_error_handler (unrecognized_reloc_msg, abfd, "R_NDS32_LONGJUMP4",
-                         irel->r_offset);
+                         (uint64_t) irel->r_offset);
       return FALSE;
     }
 
@@ -10155,7 +10170,7 @@ nds32_elf_relax_longjump5 (bfd *abfd, asection *sec, Elf_Internal_Rela *irel,
   if (cond_irel == irelend)
     {
       _bfd_error_handler (unrecognized_reloc_msg, abfd, "R_NDS32_LONGJUMP5",
-                         irel->r_offset);
+                         (uint64_t) irel->r_offset);
       return FALSE;
     }
 
@@ -10284,7 +10299,7 @@ nds32_elf_relax_longjump6 (bfd *abfd, asection *sec, Elf_Internal_Rela *irel,
   if (em_irel == irelend)
     {
       _bfd_error_handler (unrecognized_reloc_msg, abfd, "R_NDS32_LONGJUMP6",
-                         irel->r_offset);
+                         (uint64_t) irel->r_offset);
       return FALSE;
     }
 
@@ -10454,7 +10469,7 @@ nds32_elf_relax_longjump7 (bfd *abfd, asection *sec, Elf_Internal_Rela *irel,
   if (cond_irel == irelend)
     {
       _bfd_error_handler (unrecognized_reloc_msg, abfd, "R_NDS32_LONGJUMP7",
-                         irel->r_offset);
+                         (uint64_t) irel->r_offset);
       return FALSE;
     }
 
@@ -10559,7 +10574,7 @@ nds32_elf_relax_loadstore (struct bfd_link_info *link_info, bfd *abfd,
   if (hi_irelfn == irelend)
     {
       _bfd_error_handler (unrecognized_reloc_msg, abfd, "R_NDS32_LOADSTORE",
-                         irel->r_offset);
+                         (uint64_t) irel->r_offset);
        return FALSE;
     }
 
@@ -11033,7 +11048,7 @@ nds32_elf_relax_ptr (bfd *abfd, asection *sec, Elf_Internal_Rela *irel,
   if (re_irel == irelend)
     {
       _bfd_error_handler (unrecognized_reloc_msg, abfd, "R_NDS32_PTR",
-                         irel->r_offset);
+                         (uint64_t) irel->r_offset);
       return FALSE;
     }
 
@@ -11652,7 +11667,7 @@ nds32_elf_pick_relax (bfd_boolean init, asection *sec, bfd_boolean *again,
          break;
        case NDS32_RELAX_JUMP_IFC_ROUND:
          if (!nds32_elf_ifc_finish (link_info))
-           _bfd_error_handler (_("error: Jump IFC Fail."));
+           _bfd_error_handler (_("error: jump IFC fail"));
          if (table->target_optimize & NDS32_RELAX_EX9_ON)
            {
              pass++;
@@ -11669,7 +11684,7 @@ nds32_elf_pick_relax (bfd_boolean init, asection *sec, bfd_boolean *again,
            {
              /* Do jump IFC optimization again.  */
              if (!nds32_elf_ifc_finish (link_info))
-               _bfd_error_handler (_("error: Jump IFC Fail."));
+               _bfd_error_handler (_("error: jump IFC fail"));
            }
          break;
        default:
@@ -11780,7 +11795,8 @@ nds32_elf_relax_section (bfd *abfd, asection *sec,
       /* Set the _ITB_BASE_.  */
       if (!nds32_elf_ex9_itb_base (link_info))
        {
-         _bfd_error_handler (_("%B: error: Cannot set _ITB_BASE_"), abfd);
+         _bfd_error_handler (_("%pB: error: cannot set %s"),
+                             abfd, "_ITB_BASE_");
          bfd_set_error (bfd_error_bad_value);
        }
     }
@@ -12526,7 +12542,7 @@ nds32_relax_fp_as_gp (struct bfd_link_info *link_info,
          /* Begin of the region.  */
          if (begin_rel)
            /* xgettext:c-format */
-           _bfd_error_handler (_("%B: Nested OMIT_FP in %A."), abfd, sec);
+           _bfd_error_handler (_("%pB: nested OMIT_FP in %pA"), abfd, sec);
 
          begin_rel = irel;
          nds32_fag_init (&fag_head);
@@ -12545,7 +12561,8 @@ nds32_relax_fp_as_gp (struct bfd_link_info *link_info,
          if (begin_rel == NULL)
            {
              /* xgettext:c-format */
-             _bfd_error_handler (_("%B: Unmatched OMIT_FP in %A."), abfd, sec);
+             _bfd_error_handler (_("%pB: unmatched OMIT_FP in %pA"),
+                                 abfd, sec);
              continue;
            }
 
@@ -12828,7 +12845,7 @@ nds32_elf_get_relocated_section_contents (bfd *abfd,
                     message instead.  */
                  link_info->callbacks->einfo
                    /* xgettext:c-format */
-                   (_("%X%P: %B(%A): relocation \"%R\" goes out of range\n"),
+                   (_("%X%P: %pB(%pA): relocation \"%pR\" goes out of range\n"),
                     abfd, input_section, * parent);
                  goto error_return;
 
@@ -14604,7 +14621,7 @@ nds32_elf_ex9_init (void)
                              sizeof (struct elf_nds32_code_hash_entry),
                              1023))
     {
-      _bfd_error_handler (_("Linker: cannot init ex9 hash table error \n"));
+      _bfd_error_handler (_("cannot init ex9 hash table error"));
       return FALSE;
     }
   return TRUE;
@@ -15013,7 +15030,7 @@ nds32_elf_ex9_reloc_jmp (struct bfd_link_info *link_info)
                                         (fix_ptr->sec->owner, fix_ptr->sec,
                                          &source_contents, TRUE))
                                    _bfd_error_handler
-                                     (_("Linker: error cannot fixed ex9 relocation \n"));
+                                     (_("error: cannot fix ex9 relocation"));
                                  if (temp_ptr->order < 32)
                                    insn_ex9 = INSN_EX9_IT_2;
                                  else
@@ -15238,10 +15255,12 @@ nds32_elf_ex9_build_hash_table (bfd *abfd, asection *sec,
                          /* Incorrect alignment.  */
                          _bfd_error_handler
                            /* xgettext:c-format */
-                           (_("%B: warning: unaligned small data access "
-                              "for entry: {%Ld, %Ld, %Ld}, addr = %#Lx, align = %#x"),
-                            abfd, irel->r_offset,
-                            irel->r_info, irel->r_addend, relocation, align);
+                           (_("%pB: warning: unaligned small data access "
+                              "for entry: {%" PRId64 ", %" PRId64 ", %" PRId64
+                              "}, addr = %#" PRIx64 ", align = %#x"),
+                            abfd, (int64_t) irel->r_offset,
+                            (int64_t) irel->r_info, (int64_t) irel->r_addend,
+                            (uint64_t) relocation, align);
                          off += 4;
                          continue;
                        }
This page took 0.03211 seconds and 4 git commands to generate.