[binutils-gdb/binutils-2_35-branch] Partially fix a quadratic slowdown when processing secondary relocations for inputs with lots of sec

Nick Clifton nickc@sourceware.org
Thu Sep 3 15:01:53 GMT 2020


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

commit 790244d25897928fd5c950ee4e4ef84e3e9fd6ed
Author: Nick Clifton <nickc@redhat.com>
Date:   Thu Sep 3 16:00:48 2020 +0100

    Partially fix a quadratic slowdown when processing secondary relocations for inputs with lots of sections.
    
            PR 26406
            * elf-bfd.h (struct bfd_elf_section_data): Add
            has_secondary_relocs field.
            * elf.c (_bfd_elf_copy_special_section_fields): Set the
            has_secondary_relocs field for sections which have associated
            secondary relocs.
            * elfcode.h (elf_write_relocs): Only call write_secondary_relocs
            on sections which have associated secondary relocs.

Diff:
---
 bfd/ChangeLog | 14 ++++++++++++++
 bfd/elf-bfd.h |  5 +++++
 bfd/elf.c     | 22 ++++++++++++++++------
 bfd/elfcode.h |  3 ++-
 4 files changed, 37 insertions(+), 7 deletions(-)

diff --git a/bfd/ChangeLog b/bfd/ChangeLog
index c42edbb4529..d1e262a08a0 100644
--- a/bfd/ChangeLog
+++ b/bfd/ChangeLog
@@ -1,3 +1,17 @@
+2020-09-03  Nick Clifton  <nickc@redhat.com>
+
+	Backport from mainline:
+	2020-08-20  Nick Clifton  <nickc@redhat.com>
+
+	PR 26406
+	* elf-bfd.h (struct bfd_elf_section_data): Add
+	has_secondary_relocs field.
+	* elf.c (_bfd_elf_copy_special_section_fields): Set the
+	has_secondary_relocs field for sections which have associated
+	secondary relocs.
+	* elfcode.h (elf_write_relocs): Only call write_secondary_relocs
+	on sections which have associated secondary relocs.
+
 2020-08-26  David Faust  <david.faust@oracle.com>
 
 	* archures.c (bfd_mach_xbpf): Define.
diff --git a/bfd/elf-bfd.h b/bfd/elf-bfd.h
index 1576724511d..c203e089525 100644
--- a/bfd/elf-bfd.h
+++ b/bfd/elf-bfd.h
@@ -1745,6 +1745,11 @@ struct bfd_elf_section_data
   /* Link from a text section to its .eh_frame_entry section.  */
   asection *eh_frame_entry;
 
+  /* TRUE if the section has secondary reloc sections associated with it.
+     FIXME: In the future it might be better to change this into a list
+     of secondary reloc sections, making lookup easier and faster.  */
+  bfd_boolean has_secondary_relocs;
+
   /* A pointer used for various section optimizations.  */
   void *sec_info;
 };
diff --git a/bfd/elf.c b/bfd/elf.c
index 9ca42e10d8e..fe375e7346e 100644
--- a/bfd/elf.c
+++ b/bfd/elf.c
@@ -12665,6 +12665,7 @@ _bfd_elf_copy_special_section_fields (const bfd *   ibfd ATTRIBUTE_UNUSED,
 {
   asection * isec;
   asection * osec;
+  struct bfd_elf_section_data * esd;
 
   if (isection == NULL)
     return FALSE;
@@ -12680,8 +12681,9 @@ _bfd_elf_copy_special_section_fields (const bfd *   ibfd ATTRIBUTE_UNUSED,
   if (osec == NULL)
     return FALSE;
 
-  BFD_ASSERT (elf_section_data (osec)->sec_info == NULL);
-  elf_section_data (osec)->sec_info = elf_section_data (isec)->sec_info;
+  esd = elf_section_data (osec);
+  BFD_ASSERT (esd->sec_info == NULL);
+  esd->sec_info = elf_section_data (isec)->sec_info;
   osection->sh_type = SHT_RELA;
   osection->sh_link = elf_onesymtab (obfd);
   if (osection->sh_link == 0)
@@ -12721,18 +12723,26 @@ _bfd_elf_copy_special_section_fields (const bfd *   ibfd ATTRIBUTE_UNUSED,
       return FALSE;
     }
 
-  osection->sh_info =
-    elf_section_data (isection->bfd_section->output_section)->this_idx;
-
+  esd = elf_section_data (isection->bfd_section->output_section);
+  BFD_ASSERT (esd != NULL);
+  osection->sh_info = esd->this_idx;
+  esd->has_secondary_relocs = TRUE;
 #if DEBUG_SECONDARY_RELOCS
   fprintf (stderr, "update header of %s, sh_link = %u, sh_info = %u\n",
 	   osec->name, osection->sh_link, osection->sh_info);
+  fprintf (stderr, "mark section %s as having secondary relocs\n",
+	   bfd_section_name (isection->bfd_section->output_section));
 #endif
 
   return TRUE;
 }
 
-/* Write out a secondary reloc section.  */
+/* Write out a secondary reloc section.
+
+   FIXME: Currently this function can result in a serious performance penalty
+   for files with secondary relocs and lots of sections.  The proper way to
+   fix this is for _bfd_elf_copy_special_section_fields() to chain secondary
+   relocs together and then to have this function just walk that chain.  */
 
 bfd_boolean
 _bfd_elf_write_secondary_reloc_section (bfd *abfd, asection *sec)
diff --git a/bfd/elfcode.h b/bfd/elfcode.h
index 2e2c5343f2c..f4a7829f270 100644
--- a/bfd/elfcode.h
+++ b/bfd/elfcode.h
@@ -987,7 +987,8 @@ elf_write_relocs (bfd *abfd, asection *sec, void *data)
       (*swap_out) (abfd, &src_rela, dst_rela);
     }
 
-  if (!bed->write_secondary_relocs (abfd, sec))
+  if (elf_section_data (sec)->has_secondary_relocs
+      && !bed->write_secondary_relocs (abfd, sec))
     {
       *failedp = TRUE;
       return;


More information about the Binutils-cvs mailing list