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 6CED3386F018 for ; Mon, 23 Nov 2020 12:27:44 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org 6CED3386F018 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-215-R18g2FVrMZOAt1YE39Mrvg-1; Mon, 23 Nov 2020 07:27:41 -0500 X-MC-Unique: R18g2FVrMZOAt1YE39Mrvg-1 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id C7287873166 for ; Mon, 23 Nov 2020 12:27:40 +0000 (UTC) Received: from hostfoo.redhat.com (ovpn-112-164.ams2.redhat.com [10.36.112.164]) by smtp.corp.redhat.com (Postfix) with ESMTP id 119651E2C8 for ; Mon, 23 Nov 2020 12:27:39 +0000 (UTC) From: tbaeder@redhat.com To: elfutils-devel@sourceware.org Subject: [PATCH 12/12] segment_report_module: Inline consider_phdr() into only caller Date: Mon, 23 Nov 2020 13:27:12 +0100 Message-Id: <20201123122712.3799676-13-tbaeder@redhat.com> In-Reply-To: <20201123122712.3799676-1-tbaeder@redhat.com> References: <20201123122712.3799676-1-tbaeder@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.23 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.4 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_NONE, 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: Mon, 23 Nov 2020 12:27:46 -0000 From: Timm Bäder Get rid of the nested function this way Signed-off-by: Timm Bäder --- libdwfl/dwfl_segment_report_module.c | 142 +++++++++++++-------------- 1 file changed, 66 insertions(+), 76 deletions(-) diff --git a/libdwfl/dwfl_segment_report_module.c b/libdwfl/dwfl_segment_report_module.c index 046d5381..26d4e80a 100644 --- a/libdwfl/dwfl_segment_report_module.c +++ b/libdwfl/dwfl_segment_report_module.c @@ -461,7 +461,7 @@ dwfl_segment_report_module (Dwfl *dwfl, int ndx, const char *name, /* NOTE if the number of sections is > 0xff00 then e_shnum is zero and the actual number would come from the section zero sh_size field. We ignore this here because getting shdrs - is just a nice bonus (see below in consider_phdr PT_LOAD + is just a nice bonus (see below in the type == PT_LOAD case where we trim the last segment). */ shdrs_end = ehdr.e32.e_shoff + ehdr.e32.e_shnum * ehdr.e32.e_shentsize; break; @@ -547,80 +547,6 @@ dwfl_segment_report_module (Dwfl *dwfl, int ndx, const char *name, build_id.len = 0; build_id.vaddr =0; - /* Consider each of the program headers we've read from the image. */ - inline void consider_phdr (GElf_Word type, - GElf_Addr vaddr, GElf_Xword memsz, - GElf_Off offset, GElf_Xword filesz, - GElf_Xword align) - { - switch (type) - { - case PT_DYNAMIC: - dyn_vaddr = vaddr; - dyn_filesz = filesz; - break; - - case PT_NOTE: - /* We calculate from the p_offset of the note segment, - because we don't yet know the bias for its p_vaddr. */ - consider_notes (dwfl, memory_callback, memory_callback_arg, - start + offset, filesz, align, - buffer, buffer_available, start, segment, - ei_data, &build_id, - &xlatefrom, &xlateto, - ehdr.e32.e_ident[EI_DATA]); - break; - - case PT_LOAD: - align = dwfl->segment_align > 1 ? dwfl->segment_align : align ?: 1; - - GElf_Addr vaddr_end = (vaddr + memsz + align - 1) & -align; - GElf_Addr filesz_vaddr = filesz < memsz ? vaddr + filesz : vaddr_end; - GElf_Off filesz_offset = filesz_vaddr - vaddr + offset; - - if (file_trimmed_end < offset + filesz) - { - file_trimmed_end = offset + filesz; - - /* Trim the last segment so we don't bother with zeros - in the last page that are off the end of the file. - However, if the extra bit in that page includes the - section headers, keep them. */ - if (shdrs_end <= filesz_offset && shdrs_end > file_trimmed_end) - { - filesz += shdrs_end - file_trimmed_end; - file_trimmed_end = shdrs_end; - } - } - - total_filesz += filesz; - - if (file_end < filesz_offset) - { - file_end = filesz_offset; - if (filesz_vaddr - start == filesz_offset) - contiguous = file_end; - } - - if (!found_bias && (offset & -align) == 0 - && likely (filesz_offset >= phoff + phnum * phentsize)) - { - bias = start - vaddr; - found_bias = true; - } - - if ((vaddr & -align) < module_start) - { - module_start = vaddr & -align; - module_address_sync = vaddr + memsz; - } - - if (module_end < vaddr_end) - module_end = vaddr_end; - break; - } - } - Elf32_Phdr *p32 = phdrsp; Elf64_Phdr *p64 = phdrsp; if ((ei_class == ELFCLASS32 @@ -632,6 +558,7 @@ dwfl_segment_report_module (Dwfl *dwfl, int ndx, const char *name, } else { + /* Consider each of the program headers we've read from the image. */ for (uint_fast16_t i = 0; i < phnum; ++i) { bool is32 = (ei_class == ELFCLASS32); @@ -642,7 +569,70 @@ dwfl_segment_report_module (Dwfl *dwfl, int ndx, const char *name, GElf_Xword filesz = is32 ? p32[i].p_filesz : p64[i].p_filesz; GElf_Xword align = is32 ? p32[i].p_align : p64[i].p_align; - consider_phdr (type, vaddr, memsz, offset, filesz, align); + if (type == PT_DYNAMIC) + { + dyn_vaddr = vaddr; + dyn_filesz = filesz; + } + else if (type == PT_NOTE) + { + /* We calculate from the p_offset of the note segment, + because we don't yet know the bias for its p_vaddr. */ + consider_notes (dwfl, memory_callback, memory_callback_arg, + start + offset, filesz, align, + buffer, buffer_available, start, segment, + ei_data, &build_id, + &xlatefrom, &xlateto, + ehdr.e32.e_ident[EI_DATA]); + } + else if (type == PT_LOAD) + { + align = dwfl->segment_align > 1 ? dwfl->segment_align : align ?: 1; + + GElf_Addr vaddr_end = (vaddr + memsz + align - 1) & -align; + GElf_Addr filesz_vaddr = filesz < memsz ? vaddr + filesz : vaddr_end; + GElf_Off filesz_offset = filesz_vaddr - vaddr + offset; + + if (file_trimmed_end < offset + filesz) + { + file_trimmed_end = offset + filesz; + + /* Trim the last segment so we don't bother with zeros + in the last page that are off the end of the file. + However, if the extra bit in that page includes the + section headers, keep them. */ + if (shdrs_end <= filesz_offset && shdrs_end > file_trimmed_end) + { + filesz += shdrs_end - file_trimmed_end; + file_trimmed_end = shdrs_end; + } + } + + total_filesz += filesz; + + if (file_end < filesz_offset) + { + file_end = filesz_offset; + if (filesz_vaddr - start == filesz_offset) + contiguous = file_end; + } + + if (!found_bias && (offset & -align) == 0 + && likely (filesz_offset >= phoff + phnum * phentsize)) + { + bias = start - vaddr; + found_bias = true; + } + + if ((vaddr & -align) < module_start) + { + module_start = vaddr & -align; + module_address_sync = vaddr + memsz; + } + + if (module_end < vaddr_end) + module_end = vaddr_end; + } } } -- 2.26.2