From: tbaeder@redhat.com
To: elfutils-devel@sourceware.org
Subject: [PATCH 3/3] link_map: Inline consider_phdr() into only caller
Date: Tue, 1 Dec 2020 09:38:54 +0100 [thread overview]
Message-ID: <20201201083854.1870943-4-tbaeder@redhat.com> (raw)
In-Reply-To: <20201201083854.1870943-1-tbaeder@redhat.com>
From: Timm Bäder <tbaeder@redhat.com>
This gets rid of the tested function and is shorter.
---
libdwfl/link_map.c | 66 ++++++++++++++++++----------------------------
1 file changed, 26 insertions(+), 40 deletions(-)
diff --git a/libdwfl/link_map.c b/libdwfl/link_map.c
index 64baaec4..8a19f358 100644
--- a/libdwfl/link_map.c
+++ b/libdwfl/link_map.c
@@ -793,31 +793,6 @@ dwfl_link_map_report (Dwfl *dwfl, const void *auxv, size_t auxv_size,
GElf_Xword dyn_filesz = 0;
GElf_Addr dyn_bias = (GElf_Addr) -1;
- inline bool consider_phdr (GElf_Word type,
- GElf_Addr vaddr, GElf_Xword filesz)
- {
- switch (type)
- {
- case PT_PHDR:
- if (dyn_bias == (GElf_Addr) -1
- /* Do a sanity check on the putative address. */
- && ((vaddr & (dwfl->segment_align - 1))
- == (phdr & (dwfl->segment_align - 1))))
- {
- dyn_bias = phdr - vaddr;
- return dyn_vaddr != 0;
- }
- break;
-
- case PT_DYNAMIC:
- dyn_vaddr = vaddr;
- dyn_filesz = filesz;
- return dyn_bias != (GElf_Addr) -1;
- }
-
- return false;
- }
-
if (phdr != 0 && phnum != 0)
{
Dwfl_Module *phdr_mod;
@@ -930,22 +905,33 @@ dwfl_link_map_report (Dwfl *dwfl, const void *auxv, size_t auxv_size,
? elf32_xlatetom : elf64_xlatetom)
(&out, &in, elfdata) != NULL))
{
- /* We are looking for PT_DYNAMIC. */
- if (elfclass == ELFCLASS32)
+ bool is32 = (elfclass == ELFCLASS32);
+ for (size_t i = 0; i < phnum; ++i)
{
- for (size_t i = 0; i < phnum; ++i)
- if (consider_phdr ((*p32)[i].p_type,
- (*p32)[i].p_vaddr,
- (*p32)[i].p_filesz))
- break;
- }
- else
- {
- for (size_t i = 0; i < phnum; ++i)
- if (consider_phdr ((*p64)[i].p_type,
- (*p64)[i].p_vaddr,
- (*p64)[i].p_filesz))
- break;
+ GElf_Word type = is32 ? (*p32)[i].p_type : (*p64)[i].p_type;
+ GElf_Addr vaddr = is32 ? (*p32)[i].p_vaddr : (*p64)[i].p_vaddr;
+ GElf_Xword filesz = is32 ? (*p32)[i].p_filesz : (*p64)[i].p_filesz;
+
+ if (type == PT_PHDR)
+ {
+ if (dyn_bias == (GElf_Addr) -1
+ /* Do a sanity check on the putative address. */
+ && ((vaddr & (dwfl->segment_align - 1))
+ == (phdr & (dwfl->segment_align - 1))))
+ {
+ dyn_bias = phdr - vaddr;
+ if (dyn_vaddr != 0)
+ break;
+ }
+
+ }
+ else if (type == PT_DYNAMIC)
+ {
+ dyn_vaddr = vaddr;
+ dyn_filesz = filesz;
+ if (dyn_bias != (GElf_Addr) -1)
+ break;
+ }
}
}
--
2.26.2
next prev parent reply other threads:[~2020-12-01 8:39 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-12-01 8:38 link_map: Remove nested functions tbaeder
2020-12-01 8:38 ` [PATCH 1/3] link_map: Pull release_buffer() into file scope tbaeder
2020-12-06 13:20 ` Mark Wielaard
2020-12-01 8:38 ` [PATCH 2/3] link_map: Pull read_addrs() in " tbaeder
2020-12-01 8:38 ` tbaeder [this message]
2020-12-06 13:39 ` [PATCH 3/3] link_map: Inline consider_phdr() into only caller Mark Wielaard
2020-12-06 13:41 ` link_map: Remove nested functions Mark Wielaard
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20201201083854.1870943-4-tbaeder@redhat.com \
--to=tbaeder@redhat.com \
--cc=elfutils-devel@sourceware.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).