Apply a workaround to mitigate a quadratic performance hit in the linker when writing...
authorNick Clifton <nickc@redhat.com>
Thu, 20 Aug 2020 09:19:47 +0000 (10:19 +0100)
committerNick Clifton <nickc@redhat.com>
Thu, 20 Aug 2020 09:19:47 +0000 (10:19 +0100)
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.

bfd/ChangeLog
bfd/elf-bfd.h
bfd/elf.c
bfd/elfcode.h

index 4106b52a996e9b4dfae43d7aded1f667498dcb74..8c43a163fc4b5cfc7c36d688536b6889a34ceb58 100644 (file)
@@ -1,3 +1,14 @@
+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-15  Alan Modra  <amodra@gmail.com>
 
        * elf32-frv.c (elf32_frv_add_symbol_hook): Set SEC_SMALL_DATA on
index cd352d2a8e07f1b3a97965a75ed865d9a6bab007..eebdf9ac738d55d781ac95d3d813eb51a48300c1 100644 (file)
@@ -1756,6 +1756,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;
 };
index 54c72043418b04770f51c18252a14af0e23c52f3..ecd9217b34d237a92f7eeb3989fe2c5ed007f9c6 100644 (file)
--- a/bfd/elf.c
+++ b/bfd/elf.c
@@ -12714,6 +12714,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;
@@ -12729,8 +12730,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)
@@ -12770,18 +12772,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)
index 84b08b57ebce9a9df05fd968ed26417a105f4419..2ed2f135c347444d9cb98fdbfee9d579c4303d06 100644 (file)
@@ -999,7 +999,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;
This page took 0.242143 seconds and 4 git commands to generate.