This is the mail archive of the binutils@sourceware.org mailing list for the binutils project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[PATCH 1/6] PR binutils/22875: MIPS/ELF: Also fail with relocation placeholders


Do not consider placeholder EMPTY_HOWTO relocation entries valid in 
`rtype_to_howto' MIPS handlers.  Instead issue an unsupported relocation 
type error and return a NULL howto as with relocations outside the three 
ISA-specific min-max ranges.

	bfd/
	* elf32-mips.c (mips_elf32_rtype_to_howto): Also return 
	unsuccessfully for placeholder howtos.
	* elf64-mips.c (mips_elf64_rtype_to_howto): Likewise.
	* elfn32-mips.c (mips_elf_n32_rtype_to_howto): Likewise.
---
Hi,

 Regression-tested successfully; self-approved and will apply with the 
rest of the series.

  Maciej
---
 bfd/elf32-mips.c  |   23 +++++++++++++----------
 bfd/elf64-mips.c  |   34 ++++++++++++++++++++--------------
 bfd/elfn32-mips.c |   32 ++++++++++++++++++--------------
 3 files changed, 51 insertions(+), 38 deletions(-)

binutils-mips-bfd-unsupp-reloc.diff
Index: binutils/bfd/elf32-mips.c
===================================================================
--- binutils.orig/bfd/elf32-mips.c	2018-03-29 13:33:17.911059476 +0100
+++ binutils/bfd/elf32-mips.c	2018-03-29 13:33:24.932070367 +0100
@@ -2198,6 +2198,8 @@ mips_elf32_rtype_to_howto (bfd *abfd,
 			   unsigned int r_type,
 			   bfd_boolean rela_p ATTRIBUTE_UNUSED)
 {
+  reloc_howto_type *howto = NULL;
+
   switch (r_type)
     {
     case R_MIPS_GNU_VTINHERIT:
@@ -2216,17 +2218,18 @@ mips_elf32_rtype_to_howto (bfd *abfd,
       return &elf_mips_eh_howto;
     default:
       if (r_type >= R_MICROMIPS_min && r_type < R_MICROMIPS_max)
-	return &elf_micromips_howto_table_rel[r_type - R_MICROMIPS_min];
+	howto = &elf_micromips_howto_table_rel[r_type - R_MICROMIPS_min];
       if (r_type >= R_MIPS16_min && r_type < R_MIPS16_max)
-	return &elf_mips16_howto_table_rel[r_type - R_MIPS16_min];
-      if (r_type >= (unsigned int) R_MIPS_max)
-	{
-	  _bfd_error_handler (_("%pB: unsupported relocation type %#x"),
-			      abfd, r_type);
-	  bfd_set_error (bfd_error_bad_value);
-	  return NULL;
-	}
-      return &elf_mips_howto_table_rel[r_type];
+	howto = &elf_mips16_howto_table_rel[r_type - R_MIPS16_min];
+      if (r_type < R_MIPS_max)
+        howto = &elf_mips_howto_table_rel[r_type];
+      if (howto != NULL && howto->name != NULL)
+	return howto;
+
+      _bfd_error_handler (_("%pB: unsupported relocation type %#x"),
+			  abfd, r_type);
+      bfd_set_error (bfd_error_bad_value);
+      return NULL;
     }
 }
 
Index: binutils/bfd/elf64-mips.c
===================================================================
--- binutils.orig/bfd/elf64-mips.c	2018-03-29 13:30:22.527980345 +0100
+++ binutils/bfd/elf64-mips.c	2018-03-29 13:33:24.966479588 +0100
@@ -3572,6 +3572,8 @@ bfd_elf64_bfd_reloc_name_lookup (bfd *ab
 static reloc_howto_type *
 mips_elf64_rtype_to_howto (bfd *abfd, unsigned int r_type, bfd_boolean rela_p)
 {
+  reloc_howto_type *howto = NULL;
+
   switch (r_type)
     {
     case R_MIPS_GNU_VTINHERIT:
@@ -3595,29 +3597,33 @@ mips_elf64_rtype_to_howto (bfd *abfd, un
       if (r_type >= R_MICROMIPS_min && r_type < R_MICROMIPS_max)
 	{
 	  if (rela_p)
-	    return &micromips_elf64_howto_table_rela[r_type - R_MICROMIPS_min];
+	    howto
+	      = &micromips_elf64_howto_table_rela[r_type - R_MICROMIPS_min];
 	  else
-	    return &micromips_elf64_howto_table_rel[r_type - R_MICROMIPS_min];
+	    howto
+	      = &micromips_elf64_howto_table_rel[r_type - R_MICROMIPS_min];
 	}
       if (r_type >= R_MIPS16_min && r_type < R_MIPS16_max)
 	{
 	  if (rela_p)
-	    return &mips16_elf64_howto_table_rela[r_type - R_MIPS16_min];
+	    howto = &mips16_elf64_howto_table_rela[r_type - R_MIPS16_min];
 	  else
-	    return &mips16_elf64_howto_table_rel[r_type - R_MIPS16_min];
+	    howto = &mips16_elf64_howto_table_rel[r_type - R_MIPS16_min];
 	}
-      if (r_type >= R_MIPS_max)
+      if (r_type < R_MIPS_max)
 	{
-	  _bfd_error_handler (_("%pB: unsupported relocation type %#x"),
-			      abfd, r_type);
-	  bfd_set_error (bfd_error_bad_value);
-	  return NULL;
+	  if (rela_p)
+	    howto = &mips_elf64_howto_table_rela[r_type];
+	  else
+	    howto = &mips_elf64_howto_table_rel[r_type];
 	}
-      if (rela_p)
-	return &mips_elf64_howto_table_rela[r_type];
-      else
-	return &mips_elf64_howto_table_rel[r_type];
-      break;
+      if (howto != NULL && howto->name != NULL)
+	return howto;
+
+      _bfd_error_handler (_("%pB: unsupported relocation type %#x"),
+			  abfd, r_type);
+      bfd_set_error (bfd_error_bad_value);
+      return NULL;
     }
 }
 
Index: binutils/bfd/elfn32-mips.c
===================================================================
--- binutils.orig/bfd/elfn32-mips.c	2018-03-29 13:30:22.540061623 +0100
+++ binutils/bfd/elfn32-mips.c	2018-03-29 13:33:24.987986896 +0100
@@ -3402,6 +3402,8 @@ bfd_elf32_bfd_reloc_name_lookup (bfd *ab
 static reloc_howto_type *
 mips_elf_n32_rtype_to_howto (bfd *abfd, unsigned int r_type, bfd_boolean rela_p)
 {
+  reloc_howto_type *howto = NULL;
+
   switch (r_type)
     {
     case R_MIPS_GNU_VTINHERIT:
@@ -3425,29 +3427,31 @@ mips_elf_n32_rtype_to_howto (bfd *abfd, 
       if (r_type >= R_MICROMIPS_min && r_type < R_MICROMIPS_max)
 	{
 	  if (rela_p)
-	    return &elf_micromips_howto_table_rela[r_type - R_MICROMIPS_min];
+	    howto = &elf_micromips_howto_table_rela[r_type - R_MICROMIPS_min];
 	  else
-	    return &elf_micromips_howto_table_rel[r_type - R_MICROMIPS_min];
+	    howto = &elf_micromips_howto_table_rel[r_type - R_MICROMIPS_min];
 	}
       if (r_type >= R_MIPS16_min && r_type < R_MIPS16_max)
 	{
 	  if (rela_p)
-	    return &elf_mips16_howto_table_rela[r_type - R_MIPS16_min];
+	    howto = &elf_mips16_howto_table_rela[r_type - R_MIPS16_min];
 	  else
-	    return &elf_mips16_howto_table_rel[r_type - R_MIPS16_min];
+	    howto = &elf_mips16_howto_table_rel[r_type - R_MIPS16_min];
 	}
-      if (r_type >= R_MIPS_max)
+      if (r_type < R_MIPS_max)
 	{
-	  _bfd_error_handler (_("%pB: unsupported relocation type %#x"),
-			      abfd, r_type);
-	  bfd_set_error (bfd_error_bad_value);
-	  return NULL;
+	  if (rela_p)
+	    howto = &elf_mips_howto_table_rela[r_type];
+	  else
+	    howto = &elf_mips_howto_table_rel[r_type];
 	}
-      if (rela_p)
-	return &elf_mips_howto_table_rela[r_type];
-      else
-	return &elf_mips_howto_table_rel[r_type];
-      break;
+      if (howto != NULL && howto->name != NULL)
+	return howto;
+
+      _bfd_error_handler (_("%pB: unsupported relocation type %#x"),
+			  abfd, r_type);
+      bfd_set_error (bfd_error_bad_value);
+      return NULL;
     }
 }
 


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]