From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 1123) id 7F6603858CDB; Thu, 9 Nov 2023 16:44:56 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 7F6603858CDB Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable From: Michael Matz To: bfd-cvs@sourceware.org Subject: [binutils-gdb] bfd: use less memory in string merging X-Act-Checkin: binutils-gdb X-Git-Author: Michael Matz X-Git-Refname: refs/heads/master X-Git-Oldrev: 836654b1177ab305c36fe7319f08f0ad5d4fac1b X-Git-Newrev: 21160d8a18dc21aafb8ab1026e13e5c524954a46 Message-Id: <20231109164456.7F6603858CDB@sourceware.org> Date: Thu, 9 Nov 2023 16:44:56 +0000 (GMT) X-BeenThere: binutils-cvs@sourceware.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Binutils-cvs mailing list List-Unsubscribe: , List-Archive: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 09 Nov 2023 16:44:56 -0000 https://sourceware.org/git/gitweb.cgi?p=3Dbinutils-gdb.git;h=3D21160d8a18dc= 21aafb8ab1026e13e5c524954a46 commit 21160d8a18dc21aafb8ab1026e13e5c524954a46 Author: Michael Matz Date: Tue Nov 7 17:12:46 2023 +0100 bfd: use less memory in string merging =20 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. =20 So instead of leaving the waste reallocate the maps to their final size once known. Now the link barely fits again. =20 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; =20 amt =3D sec->size; if (sec->flags & SEC_STRINGS) @@ -771,6 +772,19 @@ record_section (struct sec_merge_info *sinfo, =20 free (contents); contents =3D 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 =3D secinfo->noffsetmap + 1; + tmpptr =3D bfd_realloc (secinfo->map, amt * sizeof(secinfo->map[0])); + if (tmpptr) + secinfo->map =3D tmpptr; + tmpptr =3D bfd_realloc (secinfo->map_ofs, amt * sizeof(secinfo->map_ofs[= 0])); + if (tmpptr) + secinfo->map_ofs =3D tmpptr; + /*printf ("ZZZ %s:%s %u entries\n", sec->owner->filename, sec->name, (unsigned)secinfo->noffsetmap);*/