From patchwork Sun Dec 18 10:12:12 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alan Modra X-Patchwork-Id: 34303 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:e747:0:0:0:0:0 with SMTP id c7csp1861999wrn; Sun, 18 Dec 2022 02:12:40 -0800 (PST) X-Google-Smtp-Source: AMrXdXsX7jWT4ctpgF7mHoHcbbq6b8q29tpyYRaKtzQblHw441e5AA/mPR4SmCbgfawcMWpmiWAo X-Received: by 2002:a05:6402:743:b0:475:c640:ddd2 with SMTP id p3-20020a056402074300b00475c640ddd2mr6655843edy.26.1671358360182; Sun, 18 Dec 2022 02:12:40 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1671358360; cv=none; d=google.com; s=arc-20160816; b=Cyr2jHqJn+6nPjEuPKhj5ye2s0GnEgObjIF84qt8/MCInUhpb60MMMY3fpFcBHldTC HrHduxXNuQdv/258wtRwNAWrQlUYH1rF/dFYf4jaKZ6dnVWpK9FugmC/lzjeLHARSQnV c4+flZhUPNvyL24CNnUDAWNSJsWO7vrKodMbUsxHL6c1lFpMMYyDPwqc4FHS2wB6Es+F 3t7FEzMEaAscYNy8EdOf1cvkDECzPyQl58ToLY1C6/tsGrULIGbJ9Yd0RCQYIFORHN9S y9hFm1WuIfeoJNs8RyQfuQF01tg3511ReZYPLi+VwcZjCZRYv5JYbb/jOHtR0ccys+Qr +1HQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:reply-to:from:list-subscribe:list-help:list-post :list-archive:list-unsubscribe:list-id:precedence :content-disposition:mime-version:message-id:subject:to:date :dmarc-filter:delivered-to:dkim-signature:dkim-filter; bh=w1DPNAyDU3sShv5jR1d5VYggpSw6w6XX+4RHU41V3Ig=; b=yz2RxtHwhrExO8giY379bkT0/go8yMUfeZcETlhSx9t7oqxK6hqDxv8lFK4NALd3he CFPlU66/BV+yXaSGKYsmFa5q486/J0I46rP7OzFK3kL6EUWz+yTLbEtyy91DiPHK2mHc wgxGvfViL0jMnAMaaEfID2yH7CPIPTzX762LoERKS5hmadv0V0Kqv1GM9/etPHztPwYF 69a8Dz6uQ6u8Uvve6+QIgAirozE3DrKtBr/FZCM0oam+APz99I06L9ZzXVYr0qveXngn yJG1uSowSaXQPjd1lc4mvvKnFFJNjARpkk5jnksU5Xi3+SW2c6Hi32tbHS3U9QM+vR6H L0NA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@sourceware.org header.s=default header.b=re97ZYDU; spf=pass (google.com: domain of binutils-bounces+ouuuleilei=gmail.com@sourceware.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) smtp.mailfrom="binutils-bounces+ouuuleilei=gmail.com@sourceware.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=sourceware.org Received: from sourceware.org (server2.sourceware.org. [2620:52:3:1:0:246e:9693:128c]) by mx.google.com with ESMTPS id xg1-20020a170907320100b007c10a0c31a3si5838194ejb.425.2022.12.18.02.12.40 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 18 Dec 2022 02:12:40 -0800 (PST) Received-SPF: pass (google.com: domain of binutils-bounces+ouuuleilei=gmail.com@sourceware.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) client-ip=2620:52:3:1:0:246e:9693:128c; Authentication-Results: mx.google.com; dkim=pass header.i=@sourceware.org header.s=default header.b=re97ZYDU; spf=pass (google.com: domain of binutils-bounces+ouuuleilei=gmail.com@sourceware.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) smtp.mailfrom="binutils-bounces+ouuuleilei=gmail.com@sourceware.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 0218B388DFD9 for ; Sun, 18 Dec 2022 10:12:39 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 0218B388DFD9 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1671358359; bh=w1DPNAyDU3sShv5jR1d5VYggpSw6w6XX+4RHU41V3Ig=; h=Date:To:Subject:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:From; b=re97ZYDU83yXmk6+6MBHB6aFCGER7zsevdDoQVhZDjzOoL6C7UxFPPUsxEWtWkFW0 FedTTIjWtwmJRKPcMBmrSP+Vv9M72yFM+W/2glAR8OcbNKm6l3DP2xHBy7MvIXoQiG OsrphAbA6D/RFlDu8oyyXkHHZ1ltWUUM6nt6rFnQ= X-Original-To: binutils@sourceware.org Delivered-To: binutils@sourceware.org Received: from mail-pj1-x102a.google.com (mail-pj1-x102a.google.com [IPv6:2607:f8b0:4864:20::102a]) by sourceware.org (Postfix) with ESMTPS id 048A7388DFE3 for ; Sun, 18 Dec 2022 10:12:16 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 048A7388DFE3 Received: by mail-pj1-x102a.google.com with SMTP id o1-20020a17090a678100b00219cf69e5f0so10283333pjj.2 for ; Sun, 18 Dec 2022 02:12:15 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-disposition:mime-version:message-id:subject:to:from:date :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=w1DPNAyDU3sShv5jR1d5VYggpSw6w6XX+4RHU41V3Ig=; b=BhAe+bWL1Iz2Tlzth3oyW5JgqEfodzNEVagzBKoC8xC9G5OkDuA2bnicAAtqIZZ+ef 67IOStjv1JTcstWxWN6wzUXDCgD4NLZm6ft14s79VqkuusfFCmNTjkKnSFtpx+kvygWo mHIRhCbTR0+PnfHoC9PoyhZqtcSfh7VJPOlUjpbrqirrIoHXeeFqzgkOeRb06aiko/qP 8Aa0kgAFKXTTGaY2mMJAlfQaouznBubF53vkhi1Y3rl9P28yXrgUwaLRwwEB+K0wvdTT fIN2v35Gdt2eQeqiaNCaX4CyWn7C7EeaSpy16rpTKodcoGD/xg0uf5B6n6pZXsk3DgGM p0hg== X-Gm-Message-State: ANoB5pk5cE78ZK5kzi1Xq0pXf1/8F9UbmbE3TTV1lIug7NY1SfRzUQ3z rbynsz/LfYUVPncZQLwDZ+kfkPesvNo= X-Received: by 2002:a17:902:8494:b0:188:4bba:9d29 with SMTP id c20-20020a170902849400b001884bba9d29mr40996335plo.15.1671358334828; Sun, 18 Dec 2022 02:12:14 -0800 (PST) Received: from squeak.grove.modra.org ([2406:3400:51d:8cc0:131b:2705:9610:b847]) by smtp.gmail.com with ESMTPSA id h14-20020a170902f54e00b0018957322953sm4810530plf.45.2022.12.18.02.12.14 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 18 Dec 2022 02:12:14 -0800 (PST) Received: by squeak.grove.modra.org (Postfix, from userid 1000) id 0BF821142D3B; Sun, 18 Dec 2022 20:42:12 +1030 (ACDT) Date: Sun, 18 Dec 2022 20:42:12 +1030 To: binutils@sourceware.org Subject: Comment bfd_get_section_limit_octets and bfd_get_section_alloc_size Message-ID: MIME-Version: 1.0 Content-Disposition: inline X-Spam-Status: No, score=-3035.3 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, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: binutils@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Binutils mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Alan Modra via Binutils From: Alan Modra Reply-To: Alan Modra Errors-To: binutils-bounces+ouuuleilei=gmail.com@sourceware.org Sender: "Binutils" X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1752546264264565632?= X-GMAIL-MSGID: =?utf-8?q?1752546264264565632?= * bfd.c (bfd_get_section_limit_octets): Add comment. (bfd_get_section_alloc_size): Likewise. * libbfd.c (_bfd_generic_get_section_contents): Use bfd_get_section_limit_octets. * section.c (bfd_get_section_contents): Likewise. * bfd-in2.h: Regenerate. diff --git a/bfd/bfd-in2.h b/bfd/bfd-in2.h index f4d531f5bf8..053eccf2837 100644 --- a/bfd/bfd-in2.h +++ b/bfd/bfd-in2.h @@ -6946,6 +6946,8 @@ bfd_set_asymbol_name (asymbol *sy, const char *name) sy->name = name; } +/* For input sections return the original size on disk of the + section. For output sections return the current size. */ static inline bfd_size_type bfd_get_section_limit_octets (const bfd *abfd, const asection *sec) { @@ -6962,6 +6964,9 @@ bfd_get_section_limit (const bfd *abfd, const asection *sec) / bfd_octets_per_byte (abfd, sec)); } +/* For input sections return the larger of the current size and the + original size on disk of the section. For output sections return + the current size. */ static inline bfd_size_type bfd_get_section_alloc_size (const bfd *abfd, const asection *sec) { diff --git a/bfd/bfd.c b/bfd/bfd.c index 97ce2b10450..e1759ed670e 100644 --- a/bfd/bfd.c +++ b/bfd/bfd.c @@ -502,6 +502,8 @@ CODE_FRAGMENT . sy->name = name; .} . +.{* For input sections return the original size on disk of the +. section. For output sections return the current size. *} .static inline bfd_size_type .bfd_get_section_limit_octets (const bfd *abfd, const asection *sec) .{ @@ -518,6 +520,9 @@ CODE_FRAGMENT . / bfd_octets_per_byte (abfd, sec)); .} . +.{* For input sections return the larger of the current size and the +. original size on disk of the section. For output sections return +. the current size. *} .static inline bfd_size_type .bfd_get_section_alloc_size (const bfd *abfd, const asection *sec) .{ diff --git a/bfd/libbfd.c b/bfd/libbfd.c index d33f3416206..0026c377862 100644 --- a/bfd/libbfd.c +++ b/bfd/libbfd.c @@ -943,15 +943,7 @@ _bfd_generic_get_section_contents (bfd *abfd, return false; } - /* We do allow reading of a section after bfd_final_link has - written the contents out to disk. In that situation, rawsize is - just a stale version of size, so ignore it. Otherwise we must be - reading an input section, where rawsize, if different to size, - is the on-disk size. */ - if (abfd->direction != write_direction && section->rawsize != 0) - sz = section->rawsize; - else - sz = section->size; + sz = bfd_get_section_limit_octets (abfd, section); if (offset + count < count || offset + count > sz || (abfd->my_archive != NULL diff --git a/bfd/section.c b/bfd/section.c index a49778eb333..893fc91b3df 100644 --- a/bfd/section.c +++ b/bfd/section.c @@ -1550,10 +1550,7 @@ bfd_get_section_contents (bfd *abfd, return true; } - if (abfd->direction != write_direction && section->rawsize != 0) - sz = section->rawsize; - else - sz = section->size; + sz = bfd_get_section_limit_octets (abfd, section); if ((bfd_size_type) offset > sz || count > sz - offset || count != (size_t) count)