From: Michael Matz <matz@sourceware.org>
To: bfd-cvs@sourceware.org
Subject: [binutils-gdb] bfd: use less memory in string merging
Date: Thu, 9 Nov 2023 16:44:56 +0000 (GMT) [thread overview]
Message-ID: <20231109164456.7F6603858CDB@sourceware.org> (raw)
https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;h=21160d8a18dc21aafb8ab1026e13e5c524954a46
commit 21160d8a18dc21aafb8ab1026e13e5c524954a46
Author: Michael Matz <matz@suse.de>
Date: Tue Nov 7 17:12:46 2023 +0100
bfd: use less memory in string merging
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.
Diff:
---
bfd/merge.c | 14 ++++++++++++++
1 file changed, 14 insertions(+)
diff --git a/bfd/merge.c b/bfd/merge.c
index 61ffab4d706..eeaa1a01fe3 100644
--- a/bfd/merge.c
+++ b/bfd/merge.c
@@ -711,6 +711,7 @@ record_section (struct sec_merge_info *sinfo,
unsigned int align;
bfd_size_type amt;
bfd_byte *contents;
+ void *tmpptr;
amt = sec->size;
if (sec->flags & SEC_STRINGS)
@@ -771,6 +772,19 @@ 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;
+ tmpptr = bfd_realloc (secinfo->map, amt * sizeof(secinfo->map[0]));
+ if (tmpptr)
+ secinfo->map = tmpptr;
+ tmpptr = bfd_realloc (secinfo->map_ofs, amt * sizeof(secinfo->map_ofs[0]));
+ if (tmpptr)
+ secinfo->map_ofs = tmpptr;
+
/*printf ("ZZZ %s:%s %u entries\n", sec->owner->filename, sec->name,
(unsigned)secinfo->noffsetmap);*/
reply other threads:[~2023-11-09 16:44 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20231109164456.7F6603858CDB@sourceware.org \
--to=matz@sourceware.org \
--cc=bfd-cvs@sourceware.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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).