https://sourceware.org/bugzilla/show_bug.cgi?id=34356
Bug ID: 34356
Summary: Duplicated codes in readelf.c
Product: binutils
Version: 2.47 (HEAD)
Status: NEW
Severity: normal
Priority: P2
Component: binutils
Assignee: unassigned at sourceware dot org
Reporter: hjl.tools at gmail dot com
Target Milestone: ---
There are duplicated codes in readelf.c:
1. get_32bit_dynamic_section and get_64bit_dynamic_section.
2. get_32bit_elf_symbols and get_64bit_elf_symbols.
3. get_32bit_program_headers and get_64bit_program_headers.
4. get_32bit_section_headers and get_64bit_section_headers.
These functions are very similar. They copy external representations,
which are different, Elf32_External_XXX vs Elf64_External_XXX, to internal
representations, using BYTE_GET. BYTE_GET is defined as
#define BYTE_GET(field) byte_get (field, sizeof (field))
and used as
internal[i].field = BYTE_GET (external[i].field);
where external[i].field can have different sizes and offsets between
Elf32_External_XXX and Elf64_External_XXX. We can add a new macro
#define BYTE_GET_SIZE(var, ptr, size) \
{ \
(var) = byte_get (ptr, (size)); \
ptr += (size); \
}
and replace
internal[i].field1 = BYTE_GET (external[i].field1);
internal[i].field2 = BYTE_GET (external[i].field2);
with
ptr = external;
...
BYTE_GET_SIZE (internal[i].field1, ptr, sizeof external field1);
BYTE_GET_SIZE (internal[i].field2, ptr, sizeof external field2);
...
Then we can remove duplicated codes by consolidating get_32bit_XXX and
get_64bit_XXX into get_XXX.
--
You are receiving this mail because:
You are on the CC list for the bug.