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 [63.128.21.124]) by sourceware.org (Postfix) with ESMTP id 33499386183F for ; Fri, 8 Jan 2021 08:05:00 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org 33499386183F 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-198-y934SqMnMVay3KhIBs2IEQ-1; Fri, 08 Jan 2021 03:04:58 -0500 X-MC-Unique: y934SqMnMVay3KhIBs2IEQ-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 986D5107ACE3 for ; Fri, 8 Jan 2021 08:04:57 +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 668ED6A8F0 for ; Fri, 8 Jan 2021 08:04:56 +0000 (UTC) From: tbaeder@redhat.com To: elfutils-devel@sourceware.org Subject: [PATCH 1/4] strip: Replace nested check_preserved function with loop Date: Fri, 8 Jan 2021 09:04:46 +0100 Message-Id: <20210108080449.2201310-2-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.1 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_H4, 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:03 -0000 From: Timm Bäder Signed-off-by: Timm Bäder --- src/strip.c | 37 +++++++++++++++++++++---------------- 1 file changed, 21 insertions(+), 16 deletions(-) diff --git a/src/strip.c b/src/strip.c index 7ce14ab8..c971b6c2 100644 --- a/src/strip.c +++ b/src/strip.c @@ -1535,25 +1535,30 @@ handle_elf (int fd, Elf *elf, const char *prefix, const char *fname, files by setting the .debug_data pointer to the original file's .data pointer. Below, we'll copy the section contents. */ + size_t shdr_indices[2] = { shdr_info[cnt].shdr.sh_link, 0 }; + int n = 1; - inline void check_preserved (size_t i) - { - if (i != 0 && i < shnum + 2 && shdr_info[i].idx != 0 - && shdr_info[i].debug_data == NULL) - { - if (shdr_info[i].data == NULL) - shdr_info[i].data = elf_getdata (shdr_info[i].scn, NULL); - if (shdr_info[i].data == NULL) - INTERNAL_ERROR (fname); + if (SH_INFO_LINK_P (&shdr_info[cnt].shdr)) + { + shdr_indices[1] = shdr_info[cnt].shdr.sh_info; + n++; + } - shdr_info[i].debug_data = shdr_info[i].data; - changes |= i < cnt; - } - } + for (int j = 0; j < n; j++) + { + size_t i = shdr_indices[j]; + if (i != 0 && i < shnum + 2 && shdr_info[i].idx != 0 + && shdr_info[i].debug_data == NULL) + { + if (shdr_info[i].data == NULL) + shdr_info[i].data = elf_getdata (shdr_info[i].scn, NULL); + if (shdr_info[i].data == NULL) + INTERNAL_ERROR (fname); - check_preserved (shdr_info[cnt].shdr.sh_link); - if (SH_INFO_LINK_P (&shdr_info[cnt].shdr)) - check_preserved (shdr_info[cnt].shdr.sh_info); + shdr_info[i].debug_data = shdr_info[i].data; + changes |= i < cnt; + } + } } } } -- 2.26.2