Improve "unrecognized relocation" error messages to add the suggestion that the linke...
authorNick Clifton <nickc@redhat.com>
Mon, 24 Jul 2017 10:27:33 +0000 (11:27 +0100)
committerNick Clifton <nickc@redhat.com>
Mon, 24 Jul 2017 10:27:33 +0000 (11:27 +0100)
PR 21803
* reloc.c (_bfd_unrecognized_reloc): New function.  Reports
an unrecognized reloc and sets the bfd_error value.
* libbfd.h: Regenerate.
* elf32-arm.c (elf32_arm_final_link_relocate): Use the new
function.
* elf32-i386.c (elf_i386_relocate_section): Likewise.
* elf32-tilepro.c (tilepro_elf_relocate_section): Likewise.
* elf64-x86-64.c (elf_x86_64_relocate_section): Likewise.
* elfnn-aarch64.c (elfNN_aarch64_relocate_section): Likewise.
* elfxx-tilegx.c (tilegx_elf_relocate_section): Likewise.

bfd/ChangeLog
bfd/elf32-arm.c
bfd/elf32-i386.c
bfd/elf32-tilepro.c
bfd/elf64-x86-64.c
bfd/elfnn-aarch64.c
bfd/elfxx-tilegx.c
bfd/libbfd.h
bfd/reloc.c

index 66d812468ec90fc3e39dc0f24362f274b1bf50fe..e3da4f508db7872d5c48790cf9511a3e98af00d7 100644 (file)
@@ -1,3 +1,17 @@
+2017-07-24  Nick Clifton  <nickc@redhat.com>
+
+       PR 21803
+       * reloc.c (_bfd_unrecognized_reloc): New function.  Reports
+       an unrecognized reloc and sets the bfd_error value.
+       * libbfd.h: Regenerate.
+       * elf32-arm.c (elf32_arm_final_link_relocate): Use the new
+       function.
+       * elf32-i386.c (elf_i386_relocate_section): Likewise.
+       * elf32-tilepro.c (tilepro_elf_relocate_section): Likewise.
+       * elf64-x86-64.c (elf_x86_64_relocate_section): Likewise.
+       * elfnn-aarch64.c (elfNN_aarch64_relocate_section): Likewise.
+       * elfxx-tilegx.c (tilegx_elf_relocate_section): Likewise.
+
 2017-07-23  Alan Modra  <amodra@gmail.com>
 
        * elf64-ppc.c (ppc64_elf_size_stubs): Correct advance to
index e8c346d869ef0ddb111f57fdeadc56ecfa7777fe..bad8540c6fd31efd0cd170b3154659a1421f20b3 100644 (file)
@@ -9906,6 +9906,7 @@ elf32_arm_final_link_relocate (reloc_howto_type *           howto,
     return bfd_reloc_notsupported;
 
   BFD_ASSERT (is_arm_elf (input_bfd));
+  BFD_ASSERT (howto != NULL);
 
   /* Some relocation types map to different relocations depending on the
      target.  We pick the right one here.  */
@@ -12289,8 +12290,10 @@ elf32_arm_relocate_section (bfd *                  output_bfd,
          || r_type == R_ARM_GNU_VTINHERIT)
        continue;
 
-      bfd_reloc.howto = elf32_arm_howto_from_type (r_type);
-      howto = bfd_reloc.howto;
+      howto = bfd_reloc.howto = elf32_arm_howto_from_type (r_type);
+
+      if (howto == NULL)
+       return _bfd_unrecognized_reloc (input_bfd, input_section, r_type);
 
       h = NULL;
       sym = NULL;
index 9d9c8abcc326dfc06a8094f7e4bbe0afea00bad8..37099b755742fb5065704937103fb9b63691d63f 100644 (file)
@@ -3939,14 +3939,8 @@ elf_i386_relocate_section (bfd *output_bfd,
              >= R_386_ext - R_386_standard)
          && ((indx = r_type - R_386_tls_offset) - R_386_ext
              >= R_386_ext2 - R_386_ext))
-       {
-         _bfd_error_handler
-           /* xgettext:c-format */
-           (_("%B: unrecognized relocation (0x%x) in section `%A'"),
-            input_bfd, r_type, input_section);
-         bfd_set_error (bfd_error_bad_value);
-         return FALSE;
-       }
+       return _bfd_unrecognized_reloc (input_bfd, input_section, r_type);
+
       howto = elf_howto_table + indx;
 
       r_symndx = ELF32_R_SYM (rel->r_info);
index 976ce300757097c4ebf1e6abcaf546f49466fb85..13b9bb149972fd14f73f86323200e422e4483565 100644 (file)
@@ -2861,15 +2861,7 @@ tilepro_elf_relocate_section (bfd *output_bfd, struct bfd_link_info *info,
        continue;
 
       if ((unsigned int)r_type >= NELEMS(tilepro_elf_howto_table))
-       {
-          /* Not clear if we need to check here, but just be paranoid. */
-         _bfd_error_handler
-           /* xgettext:c-format */
-           (_("%B: unrecognized relocation (0x%x) in section `%A'"),
-            input_bfd, r_type, input_section);
-         bfd_set_error (bfd_error_bad_value);
-         return FALSE;
-       }
+       return _bfd_unrecognized_reloc (input_bfd, input_section, r_type);
 
       howto = tilepro_elf_howto_table + r_type;
 
index a13af126cace730f546344c1b6fc6ee9716c4b67..448599eb9b34c3985cd673902976575a2e27bf10 100644 (file)
@@ -4314,14 +4314,7 @@ elf_x86_64_relocate_section (bfd *output_bfd,
        }
 
       if (r_type >= (int) R_X86_64_standard)
-       {
-         _bfd_error_handler
-           /* xgettext:c-format */
-           (_("%B: unrecognized relocation (0x%x) in section `%A'"),
-            input_bfd, r_type, input_section);
-         bfd_set_error (bfd_error_bad_value);
-         return FALSE;
-       }
+       return _bfd_unrecognized_reloc (input_bfd, input_section, r_type);
 
       if (r_type != (int) R_X86_64_32
          || ABI_64_P (output_bfd))
index be2f89cfc30340ba69950b0a6db7b6b789b7cc9b..0d8332e69ce847e0a190ac5cf540eb9345ddb3a0 100644 (file)
@@ -6072,17 +6072,11 @@ elfNN_aarch64_relocate_section (bfd *output_bfd,
       r_symndx = ELFNN_R_SYM (rel->r_info);
       r_type = ELFNN_R_TYPE (rel->r_info);
 
-      bfd_reloc.howto = elfNN_aarch64_howto_from_type (r_type);
-      howto = bfd_reloc.howto;
+      howto = bfd_reloc.howto = elfNN_aarch64_howto_from_type (r_type);
 
       if (howto == NULL)
-       {
-         /* xgettext:c-format */
-         _bfd_error_handler
-           (_("%B: unrecognized relocation (0x%x) in section `%A'"),
-            input_bfd, r_type, input_section);
-         return FALSE;
-       }
+       return _bfd_unrecognized_reloc (input_bfd, input_section, r_type);
+
       bfd_r_type = elfNN_aarch64_bfd_reloc_from_howto (howto);
 
       h = NULL;
index 50543b9bac55c836a4864581585969953ace6fd5..390d0899caf798610e293af462fac3ab896e38d0 100644 (file)
@@ -3160,15 +3160,7 @@ tilegx_elf_relocate_section (bfd *output_bfd, struct bfd_link_info *info,
        continue;
 
       if ((unsigned int)r_type >= ARRAY_SIZE (tilegx_elf_howto_table))
-       {
-          /* Not clear if we need to check here, but just be paranoid. */
-         _bfd_error_handler
-           /* xgettext:c-format */
-           (_("%B: unrecognized relocation (0x%x) in section `%A'"),
-            input_bfd, r_type, input_section);
-         bfd_set_error (bfd_error_bad_value);
-         return FALSE;
-       }
+       return _bfd_unrecognized_reloc (input_bfd, input_section, r_type);
 
       howto = tilegx_elf_howto_table + r_type;
 
index 17acda5c3a64cd8f85f38d76bf2a1334ec30611c..196e1f014ba37131313c6135f041fc5131f37186 100644 (file)
@@ -3219,6 +3219,11 @@ void _bfd_generic_set_reloc
     arelent **relptr,
     unsigned int count);
 
+bfd_boolean _bfd_unrecognized_reloc
+   (bfd * abfd,
+    sec_ptr section,
+    unsigned int r_type);
+
 /* Extracted from archures.c.  */
 extern const bfd_arch_info_type bfd_default_arch_struct;
 const bfd_arch_info_type *bfd_default_compatible
index 8512261c66d1d5077395d4ac26604829f203f95c..97a17f51477ceb549d77c48c7a55d75224359289 100644 (file)
@@ -50,6 +50,7 @@ SECTION
 #include "bfd.h"
 #include "bfdlink.h"
 #include "libbfd.h"
+#include "bfdver.h"
 /*
 DOCDD
 INODE
@@ -8281,13 +8282,43 @@ DESCRIPTION
        Installs a new set of internal relocations in SECTION.
 */
 
-
-void _bfd_generic_set_reloc
-  (bfd *abfd ATTRIBUTE_UNUSED,
-   sec_ptr section,
-   arelent **relptr,
-   unsigned int count)
+void
+_bfd_generic_set_reloc (bfd *abfd ATTRIBUTE_UNUSED,
+                       sec_ptr section,
+                       arelent **relptr,
+                       unsigned int count)
 {
   section->orelocation = relptr;
   section->reloc_count = count;
 }
+
+/*
+INTERNAL_FUNCTION
+       _bfd_unrecognized_reloc
+
+SYNOPSIS
+       bfd_boolean _bfd_unrecognized_reloc
+         (bfd * abfd,
+          sec_ptr section,
+          unsigned int r_type);
+
+DESCRIPTION
+       Reports an unrecognized reloc.
+       Written as a function in order to reduce code duplication.
+       Returns FALSE so that it can be called from a return statement.
+*/
+
+bfd_boolean
+_bfd_unrecognized_reloc (bfd * abfd, sec_ptr section, unsigned int r_type)
+{
+   /* xgettext:c-format */
+  _bfd_error_handler (_("%B: unrecognized relocation (%#x) in section `%A'"),
+                     abfd, r_type, section);
+
+  /* PR 21803: Suggest the most likely cause of this error.  */
+  _bfd_error_handler (_("Is this version of the linker - %s - out of date ?"),
+                     BFD_VERSION_STRING);
+
+  bfd_set_error (bfd_error_bad_value);
+  return FALSE;
+}