From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: 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 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=gmail.com Received: by mail-pj1-x102a.google.com with SMTP id o1-20020a17090a678100b00219cf69e5f0so10283333pjj.2 for ; Sun, 18 Dec 2022 02:12:15 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=content-disposition:mime-version:message-id:subject:to:from:date :from:to:cc:subject:date:message-id:reply-to; bh=w1DPNAyDU3sShv5jR1d5VYggpSw6w6XX+4RHU41V3Ig=; b=D7M3413DVvlndJwcHmx5i3hBufj4fZbAormEvkJLhsIOKTLzaoXIhCz4Y86uVEGmAU 36HsTKkp75cCwFrMAU25m+WUbQ+TU8Lj89efyLFzjDOIAzgYPjbaZBo+0xFd85xpoaOh 6bHYBB4AlMibZdHT37mmUOHMXCwW2IMLH9WTdOtGsUiIJukbJ6z8MJuZ9d0llHNRNdUe 9ahYjHjd3r3H1DRt682hs++O2vSVPB5TiJTyX17kNjqTU8SCbgT+W99nIo48mZW88azk tUYWq3QL9TTaGtFBjsbGbW6IdQGF8E+WjZ9QC5fPhd6YaO0e8Yb2whv+ApcfcxE1/TJk 1yQw== 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-Google-Smtp-Source: AA0mqf7KwIiHAZ3u6BFOlQCgYQsSx+F5DN/pww2NF5i0DXeDj9TvtYjKbVV0vnd0AHtuTdjOX61u0Q== 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 From: Alan Modra To: binutils@sourceware.org Subject: Comment bfd_get_section_limit_octets and bfd_get_section_alloc_size Message-ID: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii 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 List-Id: * 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) -- Alan Modra Australia Development Lab, IBM