[binutils-gdb] bfd: stop over-allocating aux entries for COFF section symbols

Jan Beulich via Binutils-cvs <[email protected]>
Newsgroups gmane.comp.gnu.binutils.cvs
Message-ID <[email protected]>
https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;h=f0673ba49593da2300e77d65146312a646ea9d44

commit f0673ba49593da2300e77d65146312a646ea9d44
Author: Oleg Tolmatcev <[email protected]>
Date:   Wed Aug 26 08:58:30 2026 +0200

    bfd: stop over-allocating aux entries for COFF section symbols
    
    coff_new_section_hook allocated ten combined_entry_type slots for every
    section symbol, behind a comment conceding that the ten was a guess and
    should not be a constant.  Nothing in BFD sets n_numaux above 1 on a
    section symbol, and nothing indexes the array past native[1], so eight
    of the ten were never touched on any target.
    
    This runs once per input section, so it significantly reduces peak
    memory usage.
    
    bfd/
            * coffcode.h (coff_new_section_hook): Allocate one syment plus
            one aux entry rather than ten.
    
    Signed-off-by: Oleg Tolmatcev <[email protected]>

Diff:
---
 bfd/coffcode.h | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/bfd/coffcode.h b/bfd/coffcode.h
index fc429c73b61..ff3528d9f3a 100644
--- a/bfd/coffcode.h
+++ b/bfd/coffcode.h
@@ -1831,9 +1831,9 @@ coff_new_section_hook (bfd * abfd, asection * section)
   /* Allocate aux records for section symbols, to store size and
      related info.
 
-     @@ The 10 is a guess at a plausible maximum number of aux entries
-     (but shouldn't be a constant).  */
-  amt = sizeof (combined_entry_type) * 10;
+     One syment plus one aux: nothing sets n_numaux above 1 on a
+     section symbol, or indexes this array past native[1].  */
+  amt = sizeof (*native) * 2;
   native = (combined_entry_type *) bfd_zalloc (abfd, amt);
   if (native == NULL)
     return false;
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.