| Message ID | 20260820192914.1514-2-oleg.tolmatcev@gmail.com |
|---|---|
| State | New |
| Headers |
Return-Path: <binutils-bounces~patchwork=sourceware.org@sourceware.org> X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from vm01.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id D77134B99F4F for <patchwork@sourceware.org>; Thu, 20 Aug 2026 19:31:42 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org D77134B99F4F Authentication-Results: sourceware.org; dkim=pass (2048-bit key, unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20251104 header.b=P/SQP5+D X-Original-To: binutils@sourceware.org Delivered-To: binutils@sourceware.org Received: from mail-wm1-x32a.google.com (mail-wm1-x32a.google.com [IPv6:2a00:1450:4864:20::32a]) by sourceware.org (Postfix) with ESMTPS id B0C2C4BA79A1 for <binutils@sourceware.org>; Thu, 20 Aug 2026 19:31:09 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org B0C2C4BA79A1 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=gmail.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org B0C2C4BA79A1 Authentication-Results: sourceware.org; arc=none smtp.remote-ip=2a00:1450:4864:20::32a ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1787254269; cv=none; b=N6TnFv2N2q+Vm0il+NEKa7Jm+TDUbl18Fpnpipha13V3eXAjbk+mnNDXMHlIzKnpXjjjY+2SvyGBMEIZU+n/QQy24KkhCeWsKjO8QLUAQT4a6ESjNIfCIvFPMMlWbbDMIeVkowEdSMd8mvxCQizyR7UJxh3pGqh1FrWjZGWoip8= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1787254269; c=relaxed/simple; bh=6nvNNvX7WAcZD/AaQx4rFK4cTsDAj6fD+O5aryq2SWQ=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=iDjOAUZP6oqxmo521ZNaIE7nUmZCwhnZFnvtea8s3y7vo4+WMxd7G5tGn7infJm560clWo0QGkBLTvhZxFYQwED8Pit1++WLb7Ivaz9ny948Pqnp3+g9c1NKj2Sgv9eApgK70G9f8LeVptjTSkIbXeXA1sR601skUH+MqCbTQW0= ARC-Authentication-Results: i=1; sourceware.org; dkim=pass (2048-bit key, unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20251104 header.b=P/SQP5+D DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org B0C2C4BA79A1 Received: by mail-wm1-x32a.google.com with SMTP id 5b1f17b1804b1-498028b3d5eso2566075e9.1 for <binutils@sourceware.org>; Thu, 20 Aug 2026 12:31:09 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1787254269; x=1787859069; darn=sourceware.org; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to:content-type; bh=aV1DbZD4NdHdoFFAy1hbnoZJRZ9wFniVV1Blq2k/BSY=; b=P/SQP5+DKn49bALGxufTkFlohUPBV6FZJPOEvlXVYB7Wz5w6WN9LV6Y+8mbZmuUNty LglB5cdpLBJcTBdny5F8yN9rMs3weeRnsn7lkeuu+NwUywphz6/mN4mUn58jDfHKIbRP n2D6ymKVP0YYoOHqNLTFnHiBRW1OUq8JwOBCIyiLHat/OTKds7ViWZnzl8P0SLJ6WHei hceSmqXAud4clyucb3/6RAyNYFggYo/3z1JFiqzJCzcisp8MKxjIYE7E+dA8FTIuCf8u nguAKPg6EVeOkSLPaHANrHvaiO42DtH/msrPMQBM1LyYvajm8gDqMJfgKakWeaa1kV8f IGPg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1787254269; x=1787859069; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-gg:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to:content-type; bh=aV1DbZD4NdHdoFFAy1hbnoZJRZ9wFniVV1Blq2k/BSY=; b=XtdjkuIRPByDGBsOkCsqHaIgj6gwQQY1KeuJMdlrWRhCL+lCACmWz4BcX6wZ/VXVFL Y/PdHIZk+ZglO3bak+/nI3P6rrGYW2U/vAXSereFxpGlZUGbReDb44VCdMOrkM5aKlcy KJcKkGGgPm/FsKTdd7MyM3Y1/SBziTMFtkQkpajzs0+SBAD90K+cvtF6flyYm7nVwksG tGn2ObA8Qsh2Ssn5LSHQGLBmGvzy4nsp4G6HwtszQCGu+ujM3BL2bdBXswgQ7q6pTHRF gOtuagKGoDEP0wBPaBK+NssUBsPXOuIUos7ztS19hqtIgATJXHRsWDvNC6hmm3FcERnQ Fqjg== X-Gm-Message-State: AOJu0Yz2CuQi0g0kqisPDFkMADMKlzG8vJ+Uk48pLciurp33Vk77j9ky McMf0hhK2d3pH8eovSYglct2UguQRe+vWlKMDrORws+4+2dctcpy0lLUK60MTw== X-Gm-Gg: AR+sD11Q+ENmb/SvahbQ4e+l6RqsD6YQk/aHcElwtCpbAP0oiSoQ45R1Dc6XfIscvIU oGglIuF1/WAuMKM9qhNHtrgX0V0VhQK0J2J1UMLIz0U4+Vb7Sldq2WVFeth8bCOJ9Zyctlhegl0 nYufoX2epl0nzT2/QT9JjwDQB/Q7MsWeNhK98yhdUhqMehFv68YWucootnbPo4qhGOVbS22dscf 3AuFJANcSgWMU9khQRKk76uGkAgvv6r6aZuDvLUKWW3A6lyYqL9OwX8EAg5sa6Cl9Z+CzpUR+QS zSiox9RvY3AtsOnpsuGdTWUK1C7r00i1Esgs99MYPi+4gGLESyXWxPN33s1DXxwJovwsNQ/vc4K lLFMt+AnDi9ON+zbBiHBf4gNCPrBO4cothpKLZPEx+m/n6GcAcMEY2kBVMqhffu98Lzee+SHHfN 2IiUcy+GLwCT72VieB143I1vSUrUOBbfIMozdVUSY54AOFHWBR+xyLW7XGDps3X1UaVN+KsCOF0 ARZwQZMQput1PWBYzu+Ijlty7TqG6Zai2NXF84bojQn4aF5gtwnvsri3yc= X-Received: by 2002:a05:600c:8b0f:b0:496:c379:b2a1 with SMTP id 5b1f17b1804b1-499b82e8e92mr27155285e9.2.1787254268545; Thu, 20 Aug 2026 12:31:08 -0700 (PDT) Received: from Mein-PC (p200300ed8f249a004c41707296444ab9.dip0.t-ipconnect.de. [2003:ed:8f24:9a00:4c41:7072:9644:4ab9]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-499b910292csm2943125e9.10.2026.08.20.12.31.08 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 20 Aug 2026 12:31:08 -0700 (PDT) From: Oleg Tolmatcev <oleg.tolmatcev@gmail.com> To: binutils@sourceware.org Cc: Oleg Tolmatcev <oleg.tolmatcev@gmail.com> Subject: [PATCH] bfd: stop over-allocating aux entries for COFF section symbols Date: Thu, 20 Aug 2026 21:29:15 +0200 Message-ID: <20260820192914.1514-2-oleg.tolmatcev@gmail.com> X-Mailer: git-send-email 2.55.0.windows.3 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-11.2 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, FREEMAIL_FROM, GIT_PATCH_0, RCVD_IN_DNSWL_NONE, RCVD_IN_PBL, SPF_HELO_NONE, SPF_PASS, TXREP shortcircuit=no autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on sourceware.org X-BeenThere: binutils@sourceware.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Binutils mailing list <binutils.sourceware.org> List-Unsubscribe: <https://sourceware.org/mailman/options/binutils>, <mailto:binutils-request@sourceware.org?subject=unsubscribe> List-Archive: <https://sourceware.org/pipermail/binutils/> List-Post: <mailto:binutils@sourceware.org> List-Help: <mailto:binutils-request@sourceware.org?subject=help> List-Subscribe: <https://sourceware.org/mailman/listinfo/binutils>, <mailto:binutils-request@sourceware.org?subject=subscribe> Errors-To: binutils-bounces~patchwork=sourceware.org@sourceware.org |
| Series |
bfd: stop over-allocating aux entries for COFF section symbols
|
|
Checks
| Context | Check | Description |
|---|---|---|
| linaro-tcwg-bot/tcwg_binutils_build--master-arm | success | Build passed |
| linaro-tcwg-bot/tcwg_binutils_build--master-aarch64 | success | Build passed |
| linaro-tcwg-bot/tcwg_binutils_check--master-aarch64 | success | Test passed |
| linaro-tcwg-bot/tcwg_binutils_check--master-arm | success | Test passed |
Commit Message
Oleg Tolmatcev
Aug. 20, 2026, 7:29 p.m. UTC
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 <oleg.tolmatcev@gmail.com>
---
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.
Comments
On 20.08.2026 21:29, Oleg Tolmatcev wrote: > 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 <oleg.tolmatcev@gmail.com> Fundamentally okay, one comment though: > --- 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; sizeof(<type>) is generally at risk of going out of sync with the type of the variable that is really meant to be used. Since you're already touching that line, may I suggest to switch to amt = sizeof (*native) * 2; ? Again - if that's okay with you, I can replace the piece of code while committing. Jan
пт, 21 авг. 2026 г. в 14:00, Jan Beulich <jbeulich@suse.com>: > > On 20.08.2026 21:29, Oleg Tolmatcev wrote: > > 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 <oleg.tolmatcev@gmail.com> > > Fundamentally okay, one comment though: > > > --- 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; > > sizeof(<type>) is generally at risk of going out of sync with the type > of the variable that is really meant to be used. Since you're already > touching that line, may I suggest to switch to > > amt = sizeof (*native) * 2; > > ? Again - if that's okay with you, I can replace the piece of code while > committing. > > Jan I am of course okay with it. Thank you. Oleg
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;