Blame SOURCES/gdb-rhbz1320945-power9-11of38.patch

01917d
commit cd21f5daad4335b50366b838664ade64bec29957
01917d
Author: Nick Clifton <nickc@redhat.com>
01917d
Date:   Thu Jan 15 16:22:55 2015 +0000
01917d
01917d
    Fix memory access violations triggered by running objdump on fuzzed binaries.
01917d
    
01917d
            PR binutils/17512
01917d
            * elf-m10300.c (mn10300_info_to_howto): Replace assertion with an
01917d
            error message.  Never return an invalid howto pointer.
01917d
            * elf32-cr16.c (cr16_info_to_howto): Likewise.
01917d
            * elf32-crx.c (elf_crx_info_to_howto): Likewise.
01917d
            * elf32-i370.c (i370_elf_info_to_howto): Likewise.
01917d
            * elf32-mcore.c (mcore_elf_info_to_howto): Likewise.
01917d
            * elf32-microblaze.c (microblaze_elf_info_to_howto): Likewise.
01917d
            * elf32-mips.c (mips_elf32_rtype_to_howto): Likewise.
01917d
            * elf32-pj.c (pj_elf_info_to_howto): Likewise.
01917d
            * elf32-ppc.c (ppc_elf_info_to_howto): Likewise.
01917d
            * elf32-spu.c (spu_elf_info_to_howto): Likewise.
01917d
            * elf32-v850.c (v850_elf_info_to_howto_rela): Likewise.
01917d
            * elf32-vax.c (rtype_to_howto): Likewise.
01917d
            * elf64-alpha.c (elf64_alpha_info_to_howto): Likewise.
01917d
            * elf64-mips.c (mips_elf64_rtype_to_howto): Likewise.
01917d
            * elfn32-mips.c (sh_elf_info_to_howto): Likewise.
01917d
            * elf32-sh.c (sh_elf_info_to_howto): Likewise.
01917d
            (sh_elf_reloc): Check that the reloc is in range.
01917d
            * reloc.c (bfd_perform_relocation): Check that the section is big
01917d
            enough for the entire reloc.
01917d
            (bfd_generic_get_relocated_section_contents): Report unexpected
01917d
            return values from perform_reloc.
01917d
01917d
### a/bfd/ChangeLog
01917d
### b/bfd/ChangeLog
01917d
## -1,5 +1,31 @@
01917d
 2015-01-15  Nick Clifton  <nickc@redhat.com>
01917d
 
01917d
+	PR binutils/17512
01917d
+	* elf-m10300.c (mn10300_info_to_howto): Replace assertion with an
01917d
+	error message.  Never return an invalid howto pointer.
01917d
+	* elf32-cr16.c (cr16_info_to_howto): Likewise.
01917d
+	* elf32-crx.c (elf_crx_info_to_howto): Likewise.
01917d
+	* elf32-i370.c (i370_elf_info_to_howto): Likewise.
01917d
+	* elf32-mcore.c (mcore_elf_info_to_howto): Likewise.
01917d
+	* elf32-microblaze.c (microblaze_elf_info_to_howto): Likewise.
01917d
+	* elf32-mips.c (mips_elf32_rtype_to_howto): Likewise.
01917d
+	* elf32-pj.c (pj_elf_info_to_howto): Likewise.
01917d
+	* elf32-ppc.c (ppc_elf_info_to_howto): Likewise.
01917d
+	* elf32-spu.c (spu_elf_info_to_howto): Likewise.
01917d
+	* elf32-v850.c (v850_elf_info_to_howto_rela): Likewise.
01917d
+	* elf32-vax.c (rtype_to_howto): Likewise.
01917d
+	* elf64-alpha.c (elf64_alpha_info_to_howto): Likewise.
01917d
+	* elf64-mips.c (mips_elf64_rtype_to_howto): Likewise.
01917d
+	* elfn32-mips.c (sh_elf_info_to_howto): Likewise.
01917d
+	* elf32-sh.c (sh_elf_info_to_howto): Likewise.
01917d
+	(sh_elf_reloc): Check that the reloc is in range.
01917d
+	* reloc.c (bfd_perform_relocation): Check that the section is big
01917d
+	enough for the entire reloc.
01917d
+	(bfd_generic_get_relocated_section_contents): Report unexpected
01917d
+	return values from perform_reloc.
01917d
+
01917d
+2015-01-15  Nick Clifton  <nickc@redhat.com>
01917d
+
01917d
 	* elf32-msp430.c (msp430_elf_relax_section): Skip unhandled
01917d
 	relocs.  Include PC-relative adjustment for R_MSP430X_ABS16
01917d
 	relaxation.
01917d
--- a/bfd/elf-m10300.c
01917d
+++ b/bfd/elf-m10300.c
01917d
@@ -806,7 +806,13 @@ mn10300_info_to_howto (bfd *abfd ATTRIBUTE_UNUSED,
01917d
   unsigned int r_type;
01917d
 
01917d
   r_type = ELF32_R_TYPE (dst->r_info);
01917d
-  BFD_ASSERT (r_type < (unsigned int) R_MN10300_MAX);
01917d
+  if (r_type >= R_MN10300_MAX)
01917d
+    {
01917d
+      (*_bfd_error_handler) (_("%A: unrecognised MN10300 reloc number: %d"),
01917d
+			     abfd, r_type);
01917d
+      bfd_set_error (bfd_error_bad_value);
01917d
+      r_type = R_MN10300_NONE;
01917d
+    }
01917d
   cache_ptr->howto = elf_mn10300_howto_table + r_type;
01917d
 }
01917d
 
01917d
--- a/bfd/elf32-cr16.c
01917d
+++ b/bfd/elf32-cr16.c
01917d
@@ -673,7 +673,13 @@ elf_cr16_info_to_howto (bfd *abfd ATTRIBUTE_UNUSED, arelent *cache_ptr,
01917d
 {
01917d
   unsigned int r_type = ELF32_R_TYPE (dst->r_info);
01917d
 
01917d
-  BFD_ASSERT (r_type < (unsigned int) R_CR16_MAX);
01917d
+  if (r_type >= R_CR16_MAX)
01917d
+    {
01917d
+      (*_bfd_error_handler) (_("%A: unrecognised CR16 reloc number: %d"),
01917d
+			     abfd, r_type);
01917d
+      bfd_set_error (bfd_error_bad_value);
01917d
+      r_type = R_CR16_NONE;
01917d
+    }
01917d
   cache_ptr->howto = cr16_elf_howto_table + r_type;
01917d
 }
01917d
 
01917d
--- a/bfd/elf32-crx.c
01917d
+++ b/bfd/elf32-crx.c
01917d
@@ -423,7 +423,13 @@ elf_crx_info_to_howto (bfd *abfd ATTRIBUTE_UNUSED, arelent *cache_ptr,
01917d
 		       Elf_Internal_Rela *dst)
01917d
 {
01917d
   unsigned int r_type = ELF32_R_TYPE (dst->r_info);
01917d
-  BFD_ASSERT (r_type < (unsigned int) R_CRX_MAX);
01917d
+  if (r_type >= R_CRX_MAX)
01917d
+    {
01917d
+      (*_bfd_error_handler) (_("%A: unrecognised CRX reloc number: %d"),
01917d
+			     abfd, r_type);
01917d
+      bfd_set_error (bfd_error_bad_value);
01917d
+      r_type = R_CRX_NONE;
01917d
+    }
01917d
   cache_ptr->howto = &crx_elf_howto_table[r_type];
01917d
 }
01917d
 
01917d
--- a/bfd/elf32-i370.c
01917d
+++ b/bfd/elf32-i370.c
01917d
@@ -294,12 +294,21 @@ i370_elf_info_to_howto (bfd *abfd ATTRIBUTE_UNUSED,
01917d
 			arelent *cache_ptr,
01917d
 			Elf_Internal_Rela *dst)
01917d
 {
01917d
+  unsigned int r_type;
01917d
+
01917d
   if (!i370_elf_howto_table[ R_I370_ADDR31 ])
01917d
     /* Initialize howto table.  */
01917d
     i370_elf_howto_init ();
01917d
 
01917d
-  BFD_ASSERT (ELF32_R_TYPE (dst->r_info) < (unsigned int) R_I370_max);
01917d
-  cache_ptr->howto = i370_elf_howto_table[ELF32_R_TYPE (dst->r_info)];
01917d
+  r_type = ELF32_R_TYPE (dst->r_info);
01917d
+  if (r_type >= R_I370_max)
01917d
+    {
01917d
+      (*_bfd_error_handler) (_("%A: unrecognised I370 reloc number: %d"),
01917d
+			     abfd, r_type);
01917d
+      bfd_set_error (bfd_error_bad_value);
01917d
+      r_type = R_I370_NONE;
01917d
+    }
01917d
+  cache_ptr->howto = i370_elf_howto_table[r_type];
01917d
 }
01917d
 
01917d
 /* Hack alert --  the following several routines look generic to me ...
01917d
--- a/bfd/elf32-mcore.c
01917d
+++ b/bfd/elf32-mcore.c
01917d
@@ -340,13 +340,22 @@ mcore_elf_info_to_howto (bfd * abfd ATTRIBUTE_UNUSED,
01917d
 			 arelent * cache_ptr,
01917d
 			 Elf_Internal_Rela * dst)
01917d
 {
01917d
+  unsigned int r_type;
01917d
+
01917d
   if (! mcore_elf_howto_table [R_MCORE_PCRELIMM8BY4])
01917d
     /* Initialize howto table if needed.  */
01917d
     mcore_elf_howto_init ();
01917d
 
01917d
-  BFD_ASSERT (ELF32_R_TYPE (dst->r_info) < (unsigned int) R_MCORE_max);
01917d
+  r_type = ELF32_R_TYPE (dst->r_info);
01917d
+  if (r_type >= R_MCORE_max)
01917d
+    {
01917d
+      (*_bfd_error_handler) (_("%A: unrecognised MCore reloc number: %d"),
01917d
+			     abfd, r_type);
01917d
+      bfd_set_error (bfd_error_bad_value);
01917d
+      r_type = R_MCORE_NONE;
01917d
+    }
01917d
 
01917d
-  cache_ptr->howto = mcore_elf_howto_table [ELF32_R_TYPE (dst->r_info)];
01917d
+  cache_ptr->howto = mcore_elf_howto_table [r_type];
01917d
 }
01917d
 
01917d
 /* The RELOCATE_SECTION function is called by the ELF backend linker
01917d
--- a/bfd/elf32-microblaze.c
01917d
+++ b/bfd/elf32-microblaze.c
01917d
@@ -643,13 +643,22 @@ microblaze_elf_info_to_howto (bfd * abfd ATTRIBUTE_UNUSED,
01917d
 			      arelent * cache_ptr,
01917d
 			      Elf_Internal_Rela * dst)
01917d
 {
01917d
+  unsigned int r_type;
01917d
+
01917d
   if (!microblaze_elf_howto_table [R_MICROBLAZE_32])
01917d
     /* Initialize howto table if needed.  */
01917d
     microblaze_elf_howto_init ();
01917d
 
01917d
-  BFD_ASSERT (ELF32_R_TYPE (dst->r_info) < (unsigned int) R_MICROBLAZE_max);
01917d
+  r_type = ELF32_R_TYPE (dst->r_info);
01917d
+  if (r_type >= R_MICROBLAZE_max)
01917d
+    {
01917d
+      (*_bfd_error_handler) (_("%A: unrecognised MicroBlaze reloc number: %d"),
01917d
+			     abfd, r_type);
01917d
+      bfd_set_error (bfd_error_bad_value);
01917d
+      r_type = R_MICROBLAZE_NONE;
01917d
+    }
01917d
 
01917d
-  cache_ptr->howto = microblaze_elf_howto_table [ELF32_R_TYPE (dst->r_info)];
01917d
+  cache_ptr->howto = microblaze_elf_howto_table [r_type];
01917d
 }
01917d
 
01917d
 /* Microblaze ELF local labels start with 'L.' or '$L', not '.L'.  */
01917d
--- a/bfd/elf32-mips.c
01917d
+++ b/bfd/elf32-mips.c
01917d
@@ -2204,7 +2204,12 @@ mips_elf32_rtype_to_howto (unsigned int r_type,
01917d
 	return &elf_micromips_howto_table_rel[r_type - R_MICROMIPS_min];
01917d
       if (r_type >= R_MIPS16_min && r_type < R_MIPS16_max)
01917d
         return &elf_mips16_howto_table_rel[r_type - R_MIPS16_min];
01917d
-      BFD_ASSERT (r_type < (unsigned int) R_MIPS_max);
01917d
+      if (r_type >= (unsigned int) R_MIPS_max)
01917d
+	{
01917d
+	  (*_bfd_error_handler) (_("Unrecognised MIPS reloc number: %d"), r_type);
01917d
+	  bfd_set_error (bfd_error_bad_value);
01917d
+	  r_type = R_MIPS_NONE;
01917d
+	}
01917d
       return &elf_mips_howto_table_rel[r_type];
01917d
     }
01917d
 }
01917d
--- a/bfd/elf32-pj.c
01917d
+++ b/bfd/elf32-pj.c
01917d
@@ -319,7 +319,13 @@ pj_elf_info_to_howto (bfd *abfd ATTRIBUTE_UNUSED,
01917d
 
01917d
   r = ELF32_R_TYPE (dst->r_info);
01917d
 
01917d
-  BFD_ASSERT (r < (unsigned int) R_PJ_max);
01917d
+  if (r >= R_PJ_max)
01917d
+    {
01917d
+      (*_bfd_error_handler) (_("%A: unrecognised PicoJava reloc number: %d"),
01917d
+			     abfd, r);
01917d
+      bfd_set_error (bfd_error_bad_value);
01917d
+      r = R_PJ_NONE;
01917d
+    }
01917d
 
01917d
   cache_ptr->howto = &pj_elf_howto_table[r];
01917d
 }
01917d
--- a/bfd/elf32-ppc.c
01917d
+++ b/bfd/elf32-ppc.c
01917d
@@ -2019,19 +2019,28 @@ ppc_elf_info_to_howto (bfd *abfd ATTRIBUTE_UNUSED,
01917d
 		       arelent *cache_ptr,
01917d
 		       Elf_Internal_Rela *dst)
01917d
 {
01917d
+  unsigned int r_type;
01917d
+
01917d
   /* Initialize howto table if not already done.  */
01917d
   if (!ppc_elf_howto_table[R_PPC_ADDR32])
01917d
     ppc_elf_howto_init ();
01917d
 
01917d
-  BFD_ASSERT (ELF32_R_TYPE (dst->r_info) < (unsigned int) R_PPC_max);
01917d
-  cache_ptr->howto = ppc_elf_howto_table[ELF32_R_TYPE (dst->r_info)];
01917d
+  r_type = ELF32_R_TYPE (dst->r_info);
01917d
+  if (r_type >= R_PPC_max)
01917d
+    {
01917d
+      (*_bfd_error_handler) (_("%A: unrecognised PPC reloc number: %d"),
01917d
+			     abfd, r_type);
01917d
+      bfd_set_error (bfd_error_bad_value);
01917d
+      r_type = R_PPC_NONE;
01917d
+    }
01917d
+  cache_ptr->howto = ppc_elf_howto_table[r_type];
01917d
 
01917d
   /* Just because the above assert didn't trigger doesn't mean that
01917d
      ELF32_R_TYPE (dst->r_info) is necessarily a valid relocation.  */
01917d
   if (!cache_ptr->howto)
01917d
     {
01917d
       (*_bfd_error_handler) (_("%B: invalid relocation type %d"),
01917d
-                             abfd, ELF32_R_TYPE (dst->r_info));
01917d
+                             abfd, r_type);
01917d
       bfd_set_error (bfd_error_bad_value);
01917d
 
01917d
       cache_ptr->howto = ppc_elf_howto_table[R_PPC_NONE];
01917d
--- a/bfd/elf32-sh.c
01917d
+++ b/bfd/elf32-sh.c
01917d
@@ -255,6 +255,13 @@ sh_elf_reloc (bfd *abfd, arelent *reloc_entry, asymbol *symbol_in,
01917d
       && bfd_is_und_section (symbol_in->section))
01917d
     return bfd_reloc_undefined;
01917d
 
01917d
+  /* PR 17512: file: 9891ca98.  */
01917d
+  if (addr > bfd_get_section_limit (abfd, input_section)
01917d
+      - bfd_get_reloc_size (reloc_entry->howto)
01917d
+      || bfd_get_reloc_size (reloc_entry->howto)
01917d
+      > bfd_get_section_limit (abfd, input_section))
01917d
+    return bfd_reloc_outofrange;
01917d
+
01917d
   if (bfd_is_com_section (symbol_in->section))
01917d
     sym_value = 0;
01917d
   else
01917d
@@ -474,13 +481,19 @@ sh_elf_info_to_howto (bfd *abfd, arelent *cache_ptr, Elf_Internal_Rela *dst)
01917d
 
01917d
   r = ELF32_R_TYPE (dst->r_info);
01917d
 
01917d
-  BFD_ASSERT (r < (unsigned int) R_SH_max);
01917d
-  BFD_ASSERT (r < R_SH_FIRST_INVALID_RELOC || r > R_SH_LAST_INVALID_RELOC);
01917d
-  BFD_ASSERT (r < R_SH_FIRST_INVALID_RELOC_2 || r > R_SH_LAST_INVALID_RELOC_2);
01917d
-  BFD_ASSERT (r < R_SH_FIRST_INVALID_RELOC_3 || r > R_SH_LAST_INVALID_RELOC_3);
01917d
-  BFD_ASSERT (r < R_SH_FIRST_INVALID_RELOC_4 || r > R_SH_LAST_INVALID_RELOC_4);
01917d
-  BFD_ASSERT (r < R_SH_FIRST_INVALID_RELOC_5 || r > R_SH_LAST_INVALID_RELOC_5);
01917d
-  BFD_ASSERT (r < R_SH_FIRST_INVALID_RELOC_6 || r > R_SH_LAST_INVALID_RELOC_6);
01917d
+  if (r >= R_SH_max
01917d
+      || (r >= R_SH_FIRST_INVALID_RELOC   && r <= R_SH_LAST_INVALID_RELOC)
01917d
+      || (r >= R_SH_FIRST_INVALID_RELOC_2 && r <= R_SH_LAST_INVALID_RELOC_2)
01917d
+      || (r >= R_SH_FIRST_INVALID_RELOC_3 && r <= R_SH_LAST_INVALID_RELOC_3)
01917d
+      || (r >= R_SH_FIRST_INVALID_RELOC_4 && r <= R_SH_LAST_INVALID_RELOC_4)
01917d
+      || (r >= R_SH_FIRST_INVALID_RELOC_5 && r <= R_SH_LAST_INVALID_RELOC_5)
01917d
+      || (r >= R_SH_FIRST_INVALID_RELOC_6 && r <= R_SH_LAST_INVALID_RELOC_6))
01917d
+    {
01917d
+      (*_bfd_error_handler) (_("%A: unrecognised SH reloc number: %d"),
01917d
+			     abfd, r);
01917d
+      bfd_set_error (bfd_error_bad_value);
01917d
+      r = R_SH_NONE;
01917d
+    }
01917d
 
01917d
   cache_ptr->howto = get_howto_table (abfd) + r;
01917d
 }
01917d
--- a/bfd/elf32-spu.c
01917d
+++ b/bfd/elf32-spu.c
01917d
@@ -151,7 +151,14 @@ spu_elf_info_to_howto (bfd *abfd ATTRIBUTE_UNUSED,
01917d
   enum elf_spu_reloc_type r_type;
01917d
 
01917d
   r_type = (enum elf_spu_reloc_type) ELF32_R_TYPE (dst->r_info);
01917d
-  BFD_ASSERT (r_type < R_SPU_max);
01917d
+  /* PR 17512: file: 90c2a92e.  */
01917d
+  if (r_type >= R_SPU_max)
01917d
+    {
01917d
+      (*_bfd_error_handler) (_("%A: unrecognised SPU reloc number: %d"),
01917d
+			     abfd, r_type);
01917d
+      bfd_set_error (bfd_error_bad_value);
01917d
+      r_type = R_SPU_NONE;
01917d
+    }
01917d
   cache_ptr->howto = &elf_howto_table[(int) r_type];
01917d
 }
01917d
 
01917d
--- a/bfd/elf32-v850.c
01917d
+++ b/bfd/elf32-v850.c
01917d
@@ -1914,7 +1914,11 @@ v850_elf_info_to_howto_rela (bfd *abfd ATTRIBUTE_UNUSED,
01917d
   unsigned int r_type;
01917d
 
01917d
   r_type = ELF32_R_TYPE (dst->r_info);
01917d
-  BFD_ASSERT (r_type < (unsigned int) R_V850_max);
01917d
+  if (r_type >= (unsigned int) R_V850_max)
01917d
+    {
01917d
+      _bfd_error_handler (_("%A: invalid V850 reloc number: %d"), abfd, r_type);
01917d
+      r_type = 0;
01917d
+    }
01917d
   cache_ptr->howto = &v850_elf_howto_table[r_type];
01917d
 }
01917d
 
01917d
--- a/bfd/elf32-vax.c
01917d
+++ b/bfd/elf32-vax.c
01917d
@@ -283,8 +283,17 @@ static void
01917d
 rtype_to_howto (bfd *abfd ATTRIBUTE_UNUSED, arelent *cache_ptr,
01917d
 		Elf_Internal_Rela *dst)
01917d
 {
01917d
-  BFD_ASSERT (ELF32_R_TYPE(dst->r_info) < (unsigned int) R_VAX_max);
01917d
-  cache_ptr->howto = &howto_table[ELF32_R_TYPE(dst->r_info)];
01917d
+  unsigned int r_type;
01917d
+
01917d
+  r_type = ELF32_R_TYPE (dst->r_info);
01917d
+  if (r_type >= R_VAX_max)
01917d
+    {
01917d
+      (*_bfd_error_handler) (_("%A: unrecognised VAX reloc number: %d"),
01917d
+			     abfd, r_type);
01917d
+      bfd_set_error (bfd_error_bad_value);
01917d
+      r_type = R_VAX_NONE;
01917d
+    }
01917d
+  cache_ptr->howto = &howto_table[r_type];
01917d
 }
01917d
 
01917d
 #define elf_info_to_howto rtype_to_howto
01917d
--- a/bfd/elf64-alpha.c
01917d
+++ b/bfd/elf64-alpha.c
01917d
@@ -1105,7 +1105,14 @@ elf64_alpha_info_to_howto (bfd *abfd ATTRIBUTE_UNUSED, arelent *cache_ptr,
01917d
 			   Elf_Internal_Rela *dst)
01917d
 {
01917d
   unsigned r_type = ELF64_R_TYPE(dst->r_info);
01917d
-  BFD_ASSERT (r_type < (unsigned int) R_ALPHA_max);
01917d
+
01917d
+  if (r_type >= R_ALPHA_max)
01917d
+    {
01917d
+      (*_bfd_error_handler) (_("%A: unrecognised Alpha reloc number: %d"),
01917d
+			     abfd, r_type);
01917d
+      bfd_set_error (bfd_error_bad_value);
01917d
+      r_type = R_ALPHA_NONE;
01917d
+    }
01917d
   cache_ptr->howto = &elf64_alpha_howto_table[r_type];
01917d
 }
01917d
 
01917d
--- a/bfd/elf64-mips.c
01917d
+++ b/bfd/elf64-mips.c
01917d
@@ -3585,7 +3585,12 @@ mips_elf64_rtype_to_howto (unsigned int r_type, bfd_boolean rela_p)
01917d
 	  else
01917d
 	    return &mips16_elf64_howto_table_rel[r_type - R_MIPS16_min];
01917d
 	}
01917d
-      BFD_ASSERT (r_type < (unsigned int) R_MIPS_max);
01917d
+      if (r_type >= R_MIPS_max)
01917d
+	{
01917d
+	  (*_bfd_error_handler) (_("unrecognised MIPS reloc number: %d"), r_type);
01917d
+	  bfd_set_error (bfd_error_bad_value);
01917d
+	  r_type = R_MIPS_NONE;
01917d
+	}
01917d
       if (rela_p)
01917d
 	return &mips_elf64_howto_table_rela[r_type];
01917d
       else
01917d
--- a/bfd/elfn32-mips.c
01917d
+++ b/bfd/elfn32-mips.c
01917d
@@ -3403,7 +3403,12 @@ mips_elf_n32_rtype_to_howto (unsigned int r_type, bfd_boolean rela_p)
01917d
 	  else
01917d
 	    return &elf_mips16_howto_table_rel[r_type - R_MIPS16_min];
01917d
 	}
01917d
-      BFD_ASSERT (r_type < (unsigned int) R_MIPS_max);
01917d
+      if (r_type >= R_MIPS_max)
01917d
+	{
01917d
+	  (*_bfd_error_handler) (_("unrecognised MIPS reloc number: %d"), r_type);
01917d
+	  bfd_set_error (bfd_error_bad_value);
01917d
+	  r_type = R_MIPS_NONE;
01917d
+	}
01917d
       if (rela_p)
01917d
 	return &elf_mips_howto_table_rela[r_type];
01917d
       else
01917d
--- a/bfd/reloc.c
01917d
+++ b/bfd/reloc.c
01917d
@@ -623,7 +623,10 @@ bfd_perform_relocation (bfd *abfd,
01917d
       /* PR 17512: file: c146ab8b.
01917d
 	 PR 17512: file: 46dff27f.
01917d
 	 Include the size of the reloc in the test for out of range addresses.  */
01917d
-      - bfd_get_reloc_size (howto))
01917d
+      - bfd_get_reloc_size (howto)
01917d
+      /* PR 17512: file: 38e53ebf
01917d
+	 Add make sure that there is enough room for the relocation to be applied.  */
01917d
+      || bfd_get_reloc_size (howto) > bfd_get_section_limit (abfd, input_section))
01917d
     return bfd_reloc_outofrange;
01917d
 
01917d
   /* Work out which section the relocation is targeted at and the
01917d
@@ -7691,7 +7694,11 @@ bfd_generic_get_relocated_section_contents (bfd *abfd,
01917d
 		  goto error_return;
01917d
 
01917d
 		default:
01917d
-		  abort ();
01917d
+		  /* PR 17512; file: 90c2a92e.
01917d
+		     Report unexpected results, without aborting.  */
01917d
+		  link_info->callbacks->einfo
01917d
+		    (_("%X%P: %B(%A): relocation \"%R\" returns an unrecognized value %x\n"),
01917d
+		     abfd, input_section, * parent, r);
01917d
 		  break;
01917d
 		}
01917d