[binutils-gdb] xtensa: move dynamic relocations sections consistency check

Max Filippov jcmvbkbc@sourceware.org
Mon Jul 23 19:07:00 GMT 2018


https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;h=f82863d797e461b936dff2b659a3aa65088ee87e

commit f82863d797e461b936dff2b659a3aa65088ee87e
Author: Max Filippov <jcmvbkbc@gmail.com>
Date:   Sun Jul 22 18:59:11 2018 -0700

    xtensa: move dynamic relocations sections consistency check
    
    The function elf_xtensa_finish_dynamic_sections checks that sizes of
    sections .rela.dyn and .rela.plt match number of corresponding relocation
    records, but the check is only done when .rela.plt is non-empty, so, e.g.
    it is never run for the static PIE.
    Rearrange the test so that .rela.dyn and .rela.plt are checked always.
    
    bfd/
    2018-07-23  Max Filippov  <jcmvbkbc@gmail.com>
    
    	* elf32-xtensa.c (elf_xtensa_finish_dynamic_sections): Move
    	relocation sections consistency check to always check both
    	.rela.dyn and .rela.plt when they exist. Rearrange variable
    	definition and assignment places.

Diff:
---
 bfd/ChangeLog      |  7 +++++++
 bfd/elf32-xtensa.c | 22 +++++++++++-----------
 2 files changed, 18 insertions(+), 11 deletions(-)

diff --git a/bfd/ChangeLog b/bfd/ChangeLog
index 3bdd2aa..370289d 100644
--- a/bfd/ChangeLog
+++ b/bfd/ChangeLog
@@ -1,5 +1,12 @@
 2018-07-23  Max Filippov  <jcmvbkbc@gmail.com>
 
+	* elf32-xtensa.c (elf_xtensa_finish_dynamic_sections): Move
+	relocation sections consistency check to always check both
+	.rela.dyn and .rela.plt when they exist. Rearrange variable
+	definition and assignment places.
+
+2018-07-23  Max Filippov  <jcmvbkbc@gmail.com>
+
 	* elf32-xtensa.c (shrink_dynamic_reloc_sections): Shrink dynamic
 	relocations section for dynamic undefined weak symbols when
 	linking a shared object.
diff --git a/bfd/elf32-xtensa.c b/bfd/elf32-xtensa.c
index a4b046e..cf085b7 100644
--- a/bfd/elf32-xtensa.c
+++ b/bfd/elf32-xtensa.c
@@ -3156,7 +3156,7 @@ elf_xtensa_finish_dynamic_sections (bfd *output_bfd,
 {
   struct elf_xtensa_link_hash_table *htab;
   bfd *dynobj;
-  asection *sdyn, *srelplt, *sgot, *sxtlit, *sgotloc;
+  asection *sdyn, *srelplt, *srelgot, *sgot, *sxtlit, *sgotloc;
   Elf32_External_Dyn *dyncon, *dynconend;
   int num_xtlit_entries = 0;
 
@@ -3186,15 +3186,15 @@ elf_xtensa_finish_dynamic_sections (bfd *output_bfd,
     }
 
   srelplt = htab->elf.srelplt;
+  srelgot = htab->elf.srelgot;
   if (srelplt && srelplt->size != 0)
     {
-      asection *sgotplt, *srelgot, *spltlittbl;
+      asection *sgotplt, *spltlittbl;
       int chunk, plt_chunks, plt_entries;
       Elf_Internal_Rela irela;
       bfd_byte *loc;
       unsigned rtld_reloc;
 
-      srelgot = htab->elf.srelgot;
       spltlittbl = htab->spltlittbl;
       BFD_ASSERT (srelgot != NULL && spltlittbl != NULL);
 
@@ -3260,14 +3260,6 @@ elf_xtensa_finish_dynamic_sections (bfd *output_bfd,
 		      spltlittbl->contents + (chunk * 8) + 4);
 	}
 
-      /* All the dynamic relocations have been emitted at this point.
-	 Make sure the relocation sections are the correct size.  */
-      if (srelgot->size != (sizeof (Elf32_External_Rela)
-			    * srelgot->reloc_count)
-	  || srelplt->size != (sizeof (Elf32_External_Rela)
-			       * srelplt->reloc_count))
-	abort ();
-
      /* The .xt.lit.plt section has just been modified.  This must
 	happen before the code below which combines adjacent literal
 	table entries, and the .xt.lit.plt contents have to be forced to
@@ -3282,6 +3274,14 @@ elf_xtensa_finish_dynamic_sections (bfd *output_bfd,
       spltlittbl->flags &= ~SEC_HAS_CONTENTS;
     }
 
+  /* All the dynamic relocations have been emitted at this point.
+     Make sure the relocation sections are the correct size.  */
+  if ((srelgot && srelgot->size != (sizeof (Elf32_External_Rela)
+				    * srelgot->reloc_count))
+      || (srelplt && srelplt->size != (sizeof (Elf32_External_Rela)
+				       * srelplt->reloc_count)))
+    abort ();
+
   /* Combine adjacent literal table entries.  */
   BFD_ASSERT (! bfd_link_relocatable (info));
   sxtlit = bfd_get_section_by_name (output_bfd, ".xt.lit");



More information about the Binutils-cvs mailing list