public inbox for binutils@sourceware.org
 help / color / mirror / Atom feed
* bfd: use less memory in string merging
@ 2023-11-07 16:51 Michael Matz
  2023-11-08  7:41 ` Jan Beulich
  0 siblings, 1 reply; 5+ messages in thread
From: Michael Matz @ 2023-11-07 16:51 UTC (permalink / raw)
  To: binutils

the offset-to-entry mappings are allocated in blocks, which may
become a bit wasteful in case there are extremely many small
input files or sections.  This made it so that a large project
(Qt5WebEngine) didn't build anymore on x86 32bit due to address
space limits.  It barely fit into address space before the new
string merging, and then got pushed over the limit by this.

So instead of leaving the waste reallocate the maps to their final
size once known.  Now the link barely fits again.

bfd/
    * merge.c (record_section): Reallocate offset maps to their
    final size.
---

regtested on many targets, okay for master?

 bfd/merge.c | 12 ++++++++++++
 1 file changed, 12 insertions(+)

diff --git a/bfd/merge.c b/bfd/merge.c
index 4aa2f838679..ccefb707c47 100644
--- a/bfd/merge.c
+++ b/bfd/merge.c
@@ -767,6 +767,18 @@ record_section (struct sec_merge_info *sinfo,
 
   free (contents);
   contents = NULL;
+
+  /* We allocate the ofsmap arrays in blocks of 2048 elements.
+     In case we have very many small input files/sections,
+     this might waste large amounts of memory, so reallocate these
+     arrays here to their true size.  */
+  amt = secinfo->noffsetmap + 1;
+  secinfo->map_ofs = bfd_realloc (secinfo->map_ofs,
+				  amt * sizeof(secinfo->map_ofs[0]));
+  BFD_ASSERT (secinfo->map_ofs);
+  secinfo->map = bfd_realloc (secinfo->map, amt * sizeof(secinfo->map[0]));
+  BFD_ASSERT (secinfo->map);
+
   /*printf ("ZZZ %s:%s %u entries\n", sec->owner->filename, sec->name,
 	  (unsigned)secinfo->noffsetmap);*/
 
-- 
2.42.0

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2023-11-09 16:45 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-11-07 16:51 bfd: use less memory in string merging Michael Matz
2023-11-08  7:41 ` Jan Beulich
2023-11-08 13:39   ` Michael Matz
2023-11-09  7:59     ` Jan Beulich
2023-11-09 16:45       ` Michael Matz

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).