bfd/elf: Don't read non-existing secondary relocs

Message ID alpine.LSU.2.22.394.2106071412340.3803@wotan.suse.de
State New
Headers show
Series
  • bfd/elf: Don't read non-existing secondary relocs
Related show

Commit Message

Michael Matz June 7, 2021, 2:13 p.m.
Without this we unconditionally try to slurp in secondary
relocs for each input section, leading to quadratic behaviour
even for strip(1).  On write-out we already used a flag to avoid
this.

So track existence of secondary relocs on read-in as well and
only slurp in when needed.  This still doesn't implement a proper
list of secondary reloc sections, and still would exhibit quadratic
behaviour if most input sections have a secondary reloc section.
But at least on normal input this avoid

bfd/
	* elf.c (bfd_section_from_shdr): Set has_secondary_relocs flag.
	(_bfd_elf_slurp_secondary_reloc_section): Use it for early-out.
---
 bfd/elf.c | 5 +++++
 1 file changed, 5 insertions(+)

-- 
2.23.0

Comments

Michael Matz June 7, 2021, 2:16 p.m. | #1
Hello,

On Mon, 7 Jun 2021, Michael Matz wrote:

> Without this we unconditionally try to slurp in secondary

> relocs for each input section, leading to quadratic behaviour

> even for strip(1).  On write-out we already used a flag to avoid

> this.

> 

> So track existence of secondary relocs on read-in as well and

> only slurp in when needed.  This still doesn't implement a proper

> list of secondary reloc sections, and still would exhibit quadratic

> behaviour if most input sections have a secondary reloc section.

> But at least on normal input this avoid


Hmm, consider this text to be amended thus: "[avoid]s any slowdown from 
trying to handle secondary relocation sections."


Ciao,
Michael.
Alan Modra via Binutils June 7, 2021, 3:12 p.m. | #2
Hi Michael,

> bfd/

> 	* elf.c (bfd_section_from_shdr): Set has_secondary_relocs flag.

> 	(_bfd_elf_slurp_secondary_reloc_section): Use it for early-out.


Approved - please apply.

Cheers
   Nick

Patch

diff --git a/bfd/elf.c b/bfd/elf.c
index a4cfaf1512f..de5abafabf0 100644
--- a/bfd/elf.c
+++ b/bfd/elf.c
@@ -2467,6 +2467,8 @@  bfd_section_from_shdr (bfd *abfd, unsigned int shindex)
 		     "for section %pA found - ignoring"),
 		   abfd, name, target_sect);
 	      }
+	    else
+	      esdt->has_secondary_relocs = true;
 	    goto success;
 	  }
 
@@ -12739,6 +12741,9 @@  _bfd_elf_slurp_secondary_reloc_section (bfd *       abfd,
 #endif
     r_sym = elf32_r_sym;
   
+  if (!elf_section_data (sec)->has_secondary_relocs)
+    return true;
+
   /* Discover if there are any secondary reloc sections
      associated with SEC.  */
   for (relsec = abfd->sections; relsec != NULL; relsec = relsec->next)