From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [216.205.24.124]) by sourceware.org (Postfix) with ESMTP id A5072394C046 for ; Fri, 8 Jan 2021 08:05:04 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org A5072394C046 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-483-jvl-xPl5OSmt6ye4JCSYgA-1; Fri, 08 Jan 2021 03:05:01 -0500 X-MC-Unique: jvl-xPl5OSmt6ye4JCSYgA-1 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id E4AD2107ACE4 for ; Fri, 8 Jan 2021 08:05:00 +0000 (UTC) Received: from hostfoo.redhat.com (ovpn-112-148.ams2.redhat.com [10.36.112.148]) by smtp.corp.redhat.com (Postfix) with ESMTP id 55ED61840B for ; Fri, 8 Jan 2021 08:04:59 +0000 (UTC) From: tbaeder@redhat.com To: elfutils-devel@sourceware.org Subject: [PATCH 3/4] strip: Pull update_section_size() into file scope Date: Fri, 8 Jan 2021 09:04:48 +0100 Message-Id: <20210108080449.2201310-4-tbaeder@redhat.com> In-Reply-To: <20210108080449.2201310-1-tbaeder@redhat.com> References: <20210108080449.2201310-1-tbaeder@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-14.7 required=5.0 tests=BAYES_00, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, RCVD_IN_DNSWL_LOW, RCVD_IN_MSPIKE_H3, RCVD_IN_MSPIKE_WL, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.2 X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on server2.sourceware.org X-BeenThere: elfutils-devel@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Elfutils-devel mailing list List-Unsubscribe: , List-Archive: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 08 Jan 2021 08:05:15 -0000 From: Timm Bäder Get rid of a nested function this way. Signed-off-by: Timm Bäder --- src/strip.c | 51 ++++++++++++++++++++++++++++----------------------- 1 file changed, 28 insertions(+), 23 deletions(-) diff --git a/src/strip.c b/src/strip.c index 71913fac..e608dc5e 100644 --- a/src/strip.c +++ b/src/strip.c @@ -939,6 +939,31 @@ handle_debug_relocs (Elf *elf, Ebl *ebl, Elf *new_elf, return 0; } +/* Update section headers when the data size has changed. + We also update the SHT_NOBITS section in the debug + file so that the section headers match in sh_size. */ +static inline void +update_section_size (Elf_Scn *scn, + const Elf_Data *newdata, + Elf *debugelf, + size_t cnt, + const char *fname) +{ + GElf_Shdr shdr_mem; + GElf_Shdr *shdr = gelf_getshdr (scn, &shdr_mem); + shdr->sh_size = newdata->d_size; + (void) gelf_update_shdr (scn, shdr); + if (debugelf != NULL) + { + /* libelf will use d_size to set sh_size. */ + Elf_Data *debugdata = elf_getdata (elf_getscn (debugelf, + cnt), NULL); + if (debugdata == NULL) + INTERNAL_ERROR (fname); + debugdata->d_size = newdata->d_size; + } +} + /* Maximum size of array allocated on stack. */ #define MAX_STACK_ALLOC (400 * 1024) @@ -2150,26 +2175,6 @@ handle_elf (int fd, Elf *elf, const char *prefix, const char *fname, /* Find all relocation sections which use this symbol table. */ for (cnt = 1; cnt <= shdridx; ++cnt) { - /* Update section headers when the data size has changed. - We also update the SHT_NOBITS section in the debug - file so that the section headers match in sh_size. */ - inline void update_section_size (const Elf_Data *newdata) - { - GElf_Shdr shdr_mem; - GElf_Shdr *shdr = gelf_getshdr (scn, &shdr_mem); - shdr->sh_size = newdata->d_size; - (void) gelf_update_shdr (scn, shdr); - if (debugelf != NULL) - { - /* libelf will use d_size to set sh_size. */ - Elf_Data *debugdata = elf_getdata (elf_getscn (debugelf, - cnt), NULL); - if (debugdata == NULL) - INTERNAL_ERROR (fname); - debugdata->d_size = newdata->d_size; - } - } - if (shdr_info[cnt].idx == 0 && debug_fname == NULL) /* Ignore sections which are discarded. When we are saving a relocation section in a separate debug file, we must fix up @@ -2299,7 +2304,7 @@ handle_elf (int fd, Elf *elf, const char *prefix, const char *fname, * sizeof (Elf32_Word)); elf_assert (n_size <= hashd->d_size); hashd->d_size = n_size; - update_section_size (hashd); + update_section_size (scn, hashd, debugelf, cnt, fname); /* Clear the arrays. */ memset (bucket, '\0', @@ -2361,7 +2366,7 @@ handle_elf (int fd, Elf *elf, const char *prefix, const char *fname, * sizeof (Elf64_Xword)); elf_assert (n_size <= hashd->d_size); hashd->d_size = n_size; - update_section_size (hashd); + update_section_size (scn, hashd, debugelf, cnt, fname); /* Clear the arrays. */ memset (bucket, '\0', @@ -2435,7 +2440,7 @@ handle_elf (int fd, Elf *elf, const char *prefix, const char *fname, / gelf_fsize (elf, symd->d_type, 1, EV_CURRENT), EV_CURRENT); - update_section_size (verd); + update_section_size (scn, verd, debugelf, cnt, fname); break; case SHT_GROUP: -- 2.26.2