]> git.ipfire.org Git - thirdparty/binutils-gdb.git/commitdiff
PR23980, assertion fail
authorAlan Modra <amodra@gmail.com>
Mon, 17 Dec 2018 22:50:06 +0000 (09:20 +1030)
committerAlan Modra <amodra@gmail.com>
Tue, 18 Dec 2018 00:17:02 +0000 (10:47 +1030)
All of the backend relocate_section functions that interpret reloc
numbers assuming the input file is of the expected type (ie. same as
output or very similar) really ought to be checking input file type.
Not many do, and those that do currently just assert.  This patch
replaces the assertion with a more graceful exit.

PR 23980
* elf32-i386.c (elf_i386_relocate_section): Exit with wrong format
error rather than asserting input file is as expected.
* elf32-s390.c (elf_s390_relocate_section): Likewise.
* elf32-sh.c (sh_elf_relocate_section): Likewise.
* elf32-xtensa.c (elf_xtensa_relocate_section): Likewise.
* elf64-ppc.c (ppc64_elf_relocate_section): Likewise.
* elf64-s390.c (elf_s390_relocate_section): Likewise.
* elf64-x86-64.c (elf_x86_64_relocate_section): Likewise.
* elf32-ppc.c (ppc_elf_relocate_section): Exit with wrong format
error if input file is not ppc32 ELF.

bfd/ChangeLog
bfd/elf32-i386.c
bfd/elf32-ppc.c
bfd/elf32-s390.c
bfd/elf32-sh.c
bfd/elf32-xtensa.c
bfd/elf64-ppc.c
bfd/elf64-s390.c
bfd/elf64-x86-64.c

index f8e936f92b8577976a1f53f83e85c48c1b2a0cbd..8fcdb59648b600ce59776eff508c147bfbf829ab 100644 (file)
@@ -1,3 +1,17 @@
+2018-12-18  Alan Modra  <amodra@gmail.com>
+
+       PR 23980
+       * elf32-i386.c (elf_i386_relocate_section): Exit with wrong format
+       error rather than asserting input file is as expected.
+       * elf32-s390.c (elf_s390_relocate_section): Likewise.
+       * elf32-sh.c (sh_elf_relocate_section): Likewise.
+       * elf32-xtensa.c (elf_xtensa_relocate_section): Likewise.
+       * elf64-ppc.c (ppc64_elf_relocate_section): Likewise.
+       * elf64-s390.c (elf_s390_relocate_section): Likewise.
+       * elf64-x86-64.c (elf_x86_64_relocate_section): Likewise.
+       * elf32-ppc.c (ppc_elf_relocate_section): Exit with wrong format
+       error if input file is not ppc32 ELF.
+
 2018-12-18  Alan Modra  <amodra@gmail.com>
 
        PR 23980
index 177471777df4a679139ef4ba2e23af7e299846a7..7fe6afb8cfc5a8c8d1bd67f71aef2a008a9318fd 100644 (file)
@@ -2028,7 +2028,11 @@ elf_i386_relocate_section (bfd *output_bfd,
   if (htab == NULL)
     return FALSE;
 
-  BFD_ASSERT (is_x86_elf (input_bfd, htab));
+  if (!is_x86_elf (input_bfd, htab))
+    {
+      bfd_set_error (bfd_error_wrong_format);
+      return FALSE;
+    }
 
   symtab_hdr = &elf_symtab_hdr (input_bfd);
   sym_hashes = elf_sym_hashes (input_bfd);
index 6b6043a0da5d94ea62ec54282038213f86480c87..2f699652363e786bc3bb72575611e500926310b8 100644 (file)
@@ -7025,6 +7025,12 @@ ppc_elf_relocate_section (bfd *output_bfd,
                      (bfd_link_relocatable (info)) ? " (relocatable)" : "");
 #endif
 
+  if (!is_ppc_elf (input_bfd))
+    {
+      bfd_set_error (bfd_error_wrong_format);
+      return FALSE;
+    }
+
   got2 = bfd_get_section_by_name (input_bfd, ".got2");
 
   /* Initialize howto table if not already done.  */
index 448c64dcfce0b96a2f34d58f64edefcc039b0abb..75db448e581705ecac04ebf85eda3648385124f0 100644 (file)
@@ -2165,7 +2165,11 @@ elf_s390_relocate_section (bfd *output_bfd,
   Elf_Internal_Rela *rel;
   Elf_Internal_Rela *relend;
 
-  BFD_ASSERT (is_s390_elf (input_bfd));
+  if (!is_s390_elf (input_bfd))
+    {
+      bfd_set_error (bfd_error_wrong_format);
+      return FALSE;
+    }
 
   htab = elf_s390_hash_table (info);
   symtab_hdr = &elf_symtab_hdr (input_bfd);
index 1b391090d8e5258ca9cf6d7b091c36f52bd5eafc..bcfcec70d0a72a797f5dbcb748be792e51a279e9 100644 (file)
@@ -3510,7 +3510,11 @@ sh_elf_relocate_section (bfd *output_bfd, struct bfd_link_info *info,
   unsigned isec_segment, got_segment, plt_segment, check_segment[2];
   bfd_boolean fdpic_p = FALSE;
 
-  BFD_ASSERT (is_sh_elf (input_bfd));
+  if (!is_sh_elf (input_bfd))
+    {
+      bfd_set_error (bfd_error_wrong_format);
+      return FALSE;
+    }
 
   htab = sh_elf_hash_table (info);
   if (htab != NULL)
index de960cd3b8fcae1ee87b2eb08e050fe4539e8bee..05db733862b095ed5f6a4fbe4fc554e3484a3240 100644 (file)
@@ -2459,7 +2459,11 @@ elf_xtensa_relocate_section (bfd *output_bfd,
   if (!xtensa_default_isa)
     xtensa_default_isa = xtensa_isa_init (0, 0);
 
-  BFD_ASSERT (is_xtensa_elf (input_bfd));
+  if (!is_xtensa_elf (input_bfd))
+    {
+      bfd_set_error (bfd_error_wrong_format);
+      return FALSE;
+    }
 
   htab = elf_xtensa_hash_table (info);
   if (htab == NULL)
index 31a3edfdae749eb5724a6f730e1b0f2f5d6ec624..2f4cfaaf338e8de246b7120e176da989e5d5b8d1 100644 (file)
@@ -13360,7 +13360,11 @@ ppc64_elf_relocate_section (bfd *output_bfd,
   if (input_section->owner == htab->params->stub_bfd)
     return TRUE;
 
-  BFD_ASSERT (is_ppc64_elf (input_bfd));
+  if (!is_ppc64_elf (input_bfd))
+    {
+      bfd_set_error (bfd_error_wrong_format);
+      return FALSE;
+    }
 
   local_got_ents = elf_local_got_ents (input_bfd);
   TOCstart = elf_gp (output_bfd);
index c2a2955b36bc521d68ec68353acb6f973cc09e09..b05df50f71e7ce8673188092ce7c0579dcf712e0 100644 (file)
@@ -2119,7 +2119,11 @@ elf_s390_relocate_section (bfd *output_bfd,
   Elf_Internal_Rela *rel;
   Elf_Internal_Rela *relend;
 
-  BFD_ASSERT (is_s390_elf (input_bfd));
+  if (!is_s390_elf (input_bfd))
+    {
+      bfd_set_error (bfd_error_wrong_format);
+      return FALSE;
+    }
 
   htab = elf_s390_hash_table (info);
   if (htab == NULL)
index 4dcab4347882d97b12c046528896ec572839256c..8e886b00c4853978892cc26354002b022afa8097 100644 (file)
@@ -2389,7 +2389,11 @@ elf_x86_64_relocate_section (bfd *output_bfd,
   if (htab == NULL)
     return FALSE;
 
-  BFD_ASSERT (is_x86_elf (input_bfd, htab));
+  if (!is_x86_elf (input_bfd, htab))
+    {
+      bfd_set_error (bfd_error_wrong_format);
+      return FALSE;
+    }
 
   plt_entry_size = htab->plt.plt_entry_size;
   symtab_hdr = &elf_symtab_hdr (input_bfd);