diff options
author | Timm Bäder <tbaeder@redhat.com> | 2020-11-23 13:27:10 +0100 |
---|---|---|
committer | Mark Wielaard <mark@klomp.org> | 2020-11-25 16:36:54 +0100 |
commit | 8331eaeb4ce4707154f8d2e1743a562d0d9bd945 (patch) | |
tree | 80421a5d88e94c96055dd9835a6c94c410130fbe /libdwfl | |
parent | b47b7aa0a731e4f50eb92adead67fd8d737d65ba (diff) | |
download | elfutils-8331eaeb4ce4707154f8d2e1743a562d0d9bd945.tar.gz |
segment_report_module: Unify d32/d64 loops
Just like we did before, use only one loop here and check for 32/64 bit
in the loop body. This way we only have one call site for consider_dyn
Signed-off-by: Timm Bäder <tbaeder@redhat.com>
Diffstat (limited to 'libdwfl')
-rw-r--r-- | libdwfl/ChangeLog | 5 | ||||
-rw-r--r-- | libdwfl/dwfl_segment_report_module.c | 30 |
2 files changed, 21 insertions, 14 deletions
diff --git a/libdwfl/ChangeLog b/libdwfl/ChangeLog index dd0d2817..0c66bed3 100644 --- a/libdwfl/ChangeLog +++ b/libdwfl/ChangeLog @@ -1,5 +1,10 @@ 2020-11-23 Timm Bäder <tbaeder@redhat.com> + * segment_report_module.c (dwfl_segment_report_module): Do one + loop check for d32/d64 arrays. + +2020-11-23 Timm Bäder <tbaeder@redhat.com> + * segment_report_module.c (dwfl_segment_report_module): Remove read_phdr, do check and call memory_callback directly. diff --git a/libdwfl/dwfl_segment_report_module.c b/libdwfl/dwfl_segment_report_module.c index 0729a8f8..2fb62bd9 100644 --- a/libdwfl/dwfl_segment_report_module.c +++ b/libdwfl/dwfl_segment_report_module.c @@ -792,20 +792,22 @@ dwfl_segment_report_module (Dwfl *dwfl, int ndx, const char *name, xlateto.d_buf = dyns; xlateto.d_size = dyn_filesz; - if (ei_class == ELFCLASS32) - { - if (elf32_xlatetom (&xlateto, &xlatefrom, ei_data) != NULL) - for (size_t i = 0; i < dyn_filesz / sizeof (Elf32_Dyn); ++i) - if (consider_dyn (d32[i].d_tag, d32[i].d_un.d_val)) - break; - } - else - { - if (elf64_xlatetom (&xlateto, &xlatefrom, ei_data) != NULL) - for (size_t i = 0; i < dyn_filesz / sizeof (Elf64_Dyn); ++i) - if (consider_dyn (d64[i].d_tag, d64[i].d_un.d_val)) - break; - } + bool is32 = (ei_class == ELFCLASS32); + if ((is32 && elf32_xlatetom (&xlateto, &xlatefrom, ei_data) != NULL) + || (!is32 && elf64_xlatetom (&xlateto, &xlatefrom, ei_data) != NULL)) + { + size_t n = (is32 + ? (dyn_filesz / sizeof (Elf32_Dyn)) + : (dyn_filesz / sizeof (Elf64_Dyn))); + for (size_t i = 0; i < n; ++i) + { + GElf_Sxword tag = is32 ? d32[i].d_tag : d64[i].d_tag; + GElf_Xword val = is32 ? d32[i].d_un.d_val : d64[i].d_un.d_val; + + if (consider_dyn (tag, val)) + break; + } + } free (dyns); } finish_portion (&dyn_data, &dyn_data_size); |