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

Oleg Tolmatcev <[email protected]>
Newsgroups gmane.comp.gnu.binutils
Message-ID <[email protected]>
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]>
---
 bfd/coffcode.h | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

In one of my tests this reduces peak memory usage by 23%: 1497 MB out of 6532 MB.

diff --git a/bfd/coffcode.h b/bfd/coffcode.h
index 964d2c3e173..6875f856c08 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 (combined_entry_type) * 2;
   native = (combined_entry_type *) bfd_zalloc (abfd, amt);
   if (native == NULL)
     return false;
-- 
2.55.0.windows.3
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.