[PATCH 0/5] readelf.c: Consolidating get_[32|64]bit_XXX into get_XXX

"H.J. Lu" <[email protected]>
Newsgroups gmane.comp.gnu.binutils
Message-ID <[email protected]>
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 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.

H.J. Lu (5):
  readelf: Consolidate get_[32|64]bit_section_headers
  readelf: Use BYTE_GET_SIZE in RELR relocation processing
  readelf: Consolidate get_[32|64]bit_program_headers
  readelf: Consolidate get_[32|64]bit_elf_symbols
  readelf: Consolidate get_[32|64]bit_dynamic_section

 binutils/elfcomm.h |   6 +
 binutils/readelf.c | 587 ++++++++++++---------------------------------
 2 files changed, 154 insertions(+), 439 deletions(-)

-- 
2.55.0
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.