From: tbaeder@redhat.com
To: elfutils-devel@sourceware.org
Subject: [PATCH 2/3] link_map: Pull read_addrs() in file scope
Date: Tue, 1 Dec 2020 09:38:53 +0100 [thread overview]
Message-ID: <20201201083854.1870943-3-tbaeder@redhat.com> (raw)
In-Reply-To: <20201201083854.1870943-1-tbaeder@redhat.com>
From: Timm Bäder <tbaeder@redhat.com>
Get rid of another nested function this way
---
libdwfl/link_map.c | 114 ++++++++++++++++++++++++++-------------------
1 file changed, 66 insertions(+), 48 deletions(-)
diff --git a/libdwfl/link_map.c b/libdwfl/link_map.c
index 5c39c631..64baaec4 100644
--- a/libdwfl/link_map.c
+++ b/libdwfl/link_map.c
@@ -237,6 +237,64 @@ release_buffer (Dwfl *dwfl,
return result;
}
+static inline bool
+read_addrs (Dwfl *dwfl,
+ Dwfl_Memory_Callback *memory_callback,
+ void *memory_callback_arg,
+ void **buffer,
+ size_t *buffer_available,
+ GElf_Addr vaddr, GElf_Addr *read_vaddr,
+ size_t n,
+ uint_fast8_t elfclass,
+ uint_fast8_t elfdata,
+ GElf_Addr *addrs /* [4] */)
+{
+ size_t nb = n * addrsize (elfclass); /* Address words -> bytes to read. */
+
+ /* Read a new buffer if the old one doesn't cover these words. */
+ if (buffer == NULL
+ || vaddr < *read_vaddr
+ || vaddr - (*read_vaddr) + nb > *buffer_available)
+ {
+ release_buffer (dwfl, memory_callback, memory_callback_arg,
+ buffer, buffer_available, 0);
+
+ *read_vaddr = vaddr;
+ int segndx = INTUSE(dwfl_addrsegment) (dwfl, vaddr, NULL);
+ if (unlikely (segndx < 0)
+ || unlikely (! (*memory_callback) (dwfl, segndx,
+ buffer, buffer_available,
+ vaddr, nb, memory_callback_arg)))
+ return true;
+ }
+
+ Elf32_Addr (*a32)[n] = vaddr - (*read_vaddr) + *buffer;
+ Elf64_Addr (*a64)[n] = (void *) a32;
+
+ if (elfclass == ELFCLASS32)
+ {
+ if (elfdata == ELFDATA2MSB)
+ for (size_t i = 0; i < n; ++i)
+ addrs[i] = BE32 (read_4ubyte_unaligned_noncvt (&(*a32)[i]));
+ else
+ for (size_t i = 0; i < n; ++i)
+ addrs[i] = LE32 (read_4ubyte_unaligned_noncvt (&(*a32)[i]));
+ }
+ else
+ {
+ if (elfdata == ELFDATA2MSB)
+ for (size_t i = 0; i < n; ++i)
+ addrs[i] = BE64 (read_8ubyte_unaligned_noncvt (&(*a64)[i]));
+ else
+ for (size_t i = 0; i < n; ++i)
+ addrs[i] = LE64 (read_8ubyte_unaligned_noncvt (&(*a64)[i]));
+ }
+
+ return false;
+}
+
+
+
/* Report a module for each struct link_map in the linked list at r_map
in the struct r_debug at R_DEBUG_VADDR. For r_debug_info description
see dwfl_link_map_report in libdwflP.h. If R_DEBUG_INFO is not NULL then no
@@ -262,54 +320,12 @@ report_r_debug (uint_fast8_t elfclass, uint_fast8_t elfdata,
void *buffer = NULL;
size_t buffer_available = 0;
- GElf_Addr addrs[4];
- inline bool read_addrs (GElf_Addr vaddr, size_t n)
- {
- size_t nb = n * addrsize (elfclass); /* Address words -> bytes to read. */
-
- /* Read a new buffer if the old one doesn't cover these words. */
- if (buffer == NULL
- || vaddr < read_vaddr
- || vaddr - read_vaddr + nb > buffer_available)
- {
- release_buffer (dwfl, memory_callback, memory_callback_arg,
- &buffer, &buffer_available, 0);
-
- read_vaddr = vaddr;
- int segndx = INTUSE(dwfl_addrsegment) (dwfl, vaddr, NULL);
- if (unlikely (segndx < 0)
- || unlikely (! (*memory_callback) (dwfl, segndx,
- &buffer, &buffer_available,
- vaddr, nb, memory_callback_arg)))
- return true;
- }
-
- Elf32_Addr (*a32)[n] = vaddr - read_vaddr + buffer;
- Elf64_Addr (*a64)[n] = (void *) a32;
-
- if (elfclass == ELFCLASS32)
- {
- if (elfdata == ELFDATA2MSB)
- for (size_t i = 0; i < n; ++i)
- addrs[i] = BE32 (read_4ubyte_unaligned_noncvt (&(*a32)[i]));
- else
- for (size_t i = 0; i < n; ++i)
- addrs[i] = LE32 (read_4ubyte_unaligned_noncvt (&(*a32)[i]));
- }
- else
- {
- if (elfdata == ELFDATA2MSB)
- for (size_t i = 0; i < n; ++i)
- addrs[i] = BE64 (read_8ubyte_unaligned_noncvt (&(*a64)[i]));
- else
- for (size_t i = 0; i < n; ++i)
- addrs[i] = LE64 (read_8ubyte_unaligned_noncvt (&(*a64)[i]));
- }
-
- return false;
- }
+ GElf_Addr addrs[4] = { 0, 0, 0, 0 };
- if (unlikely (read_addrs (read_vaddr, 1)))
+ if (unlikely (read_addrs (dwfl, memory_callback, memory_callback_arg,
+ &buffer, &buffer_available,
+ read_vaddr, &read_vaddr, 1,
+ elfclass, elfdata, addrs)))
release_buffer (dwfl, memory_callback, memory_callback_arg,
&buffer, &buffer_available, -1);
@@ -326,7 +342,9 @@ report_r_debug (uint_fast8_t elfclass, uint_fast8_t elfdata,
size_t iterations = 0;
while (next != 0 && ++iterations < dwfl->lookup_elts)
{
- if (read_addrs (next, 4))
+ if (read_addrs (dwfl, memory_callback, memory_callback_arg,
+ &buffer, &buffer_available,
+ next, &read_vaddr, 4, elfclass, elfdata, addrs))
return release_buffer (dwfl, memory_callback, memory_callback_arg,
&buffer, &buffer_available, -1);
--
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 ` tbaeder [this message]
2020-12-01 8:38 ` [PATCH 3/3] link_map: Inline consider_phdr() into only caller tbaeder
2020-12-06 13:39 ` 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-3-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).