[binutils-gdb/binutils-2_36-branch] PR27259, SHF_LINK_ORDER self-link

Alan Modra amodra@sourceware.org
Fri Jan 29 22:37:52 GMT 2021


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

commit fe0e833171513c1d89668bc5f454192d2db39bce
Author: Alan Modra <amodra@gmail.com>
Date:   Thu Jan 28 10:30:36 2021 +1030

    PR27259, SHF_LINK_ORDER self-link
    
    This stops ld from endless looping on SHF_LINK_ORDER sh_link loops.
    
    bfd/
            PR 27259
            * elflink.c (_bfd_elf_gc_mark_extra_sections): Use linker_mark to
            prevent endless looping of linked-to sections.
    ld/
            PR 27259
            * ldelf.c (ldelf_before_place_orphans): Use linker_mark to
            prevent endless looping of linked-to sections.
    
    (cherry picked from commit def97fb945a98544938087eff3111e16ce58da6d)

Diff:
---
 bfd/ChangeLog |  6 ++++++
 bfd/elflink.c | 24 ++++++++++++++++--------
 ld/ChangeLog  |  6 ++++++
 ld/ldelf.c    | 21 ++++++++++++++-------
 4 files changed, 42 insertions(+), 15 deletions(-)

diff --git a/bfd/ChangeLog b/bfd/ChangeLog
index 18d48ace726..08d28999487 100644
--- a/bfd/ChangeLog
+++ b/bfd/ChangeLog
@@ -1,3 +1,9 @@
+2021-01-28  Alan Modra  <amodra@gmail.com>
+
+	PR 27259
+	* elflink.c (_bfd_elf_gc_mark_extra_sections): Use linker_mark to
+	prevent endless looping of linked-to sections.
+
 2021-01-29  Alan Modra  <amodra@gmail.com>
 
 	PR 27271
diff --git a/bfd/elflink.c b/bfd/elflink.c
index 45ecd770046..e7b96f8ca86 100644
--- a/bfd/elflink.c
+++ b/bfd/elflink.c
@@ -13827,15 +13827,23 @@ _bfd_elf_gc_mark_extra_sections (struct bfd_link_info *info,
 	      /* Since all sections, except for backend specific ones,
 		 have been garbage collected, call mark_hook on this
 		 section if any of its linked-to sections is marked.  */
-	      asection *linked_to_sec = elf_linked_to_section (isec);
-	      for (; linked_to_sec != NULL;
+	      asection *linked_to_sec;
+	      for (linked_to_sec = elf_linked_to_section (isec);
+		   linked_to_sec != NULL && !linked_to_sec->linker_mark;
 		   linked_to_sec = elf_linked_to_section (linked_to_sec))
-		if (linked_to_sec->gc_mark)
-		  {
-		    if (!_bfd_elf_gc_mark (info, isec, mark_hook))
-		      return FALSE;
-		    break;
-		  }
+		{
+		  if (linked_to_sec->gc_mark)
+		    {
+		      if (!_bfd_elf_gc_mark (info, isec, mark_hook))
+			return FALSE;
+		      break;
+		    }
+		  linked_to_sec->linker_mark = 1;
+		}
+	      for (linked_to_sec = elf_linked_to_section (isec);
+		   linked_to_sec != NULL && linked_to_sec->linker_mark;
+		   linked_to_sec = elf_linked_to_section (linked_to_sec))
+		linked_to_sec->linker_mark = 0;
 	    }
 
 	  if (!debug_frag_seen
diff --git a/ld/ChangeLog b/ld/ChangeLog
index 2ac80ea2761..ff2ee9668ce 100644
--- a/ld/ChangeLog
+++ b/ld/ChangeLog
@@ -1,3 +1,9 @@
+2021-01-28  Alan Modra  <amodra@gmail.com>
+
+	PR 27259
+	* ldelf.c (ldelf_before_place_orphans): Use linker_mark to
+	prevent endless looping of linked-to sections.
+
 2021-01-29  Alan Modra  <amodra@gmail.com>
 
 	* testsuite/ld-tic6x/tic6x.exp: Add pr27271 test.
diff --git a/ld/ldelf.c b/ld/ldelf.c
index f7407ab55a7..28974968251 100644
--- a/ld/ldelf.c
+++ b/ld/ldelf.c
@@ -2188,14 +2188,21 @@ ldelf_before_place_orphans (void)
 	       been discarded.  */
 	    asection *linked_to_sec;
 	    for (linked_to_sec = elf_linked_to_section (isec);
-		 linked_to_sec != NULL;
+		 linked_to_sec != NULL && !linked_to_sec->linker_mark;
 		 linked_to_sec = elf_linked_to_section (linked_to_sec))
-	      if (discarded_section (linked_to_sec))
-		{
-		  isec->output_section = bfd_abs_section_ptr;
-		  isec->flags |= SEC_EXCLUDE;
-		  break;
-		}
+	      {
+		if (discarded_section (linked_to_sec))
+		  {
+		    isec->output_section = bfd_abs_section_ptr;
+		    isec->flags |= SEC_EXCLUDE;
+		    break;
+		  }
+		linked_to_sec->linker_mark = 1;
+	      }
+	    for (linked_to_sec = elf_linked_to_section (isec);
+		 linked_to_sec != NULL && linked_to_sec->linker_mark;
+		 linked_to_sec = elf_linked_to_section (linked_to_sec))
+	      linked_to_sec->linker_mark = 0;
 	  }
       }
 }


More information about the Binutils-cvs mailing list