Refactor readelf code for better organization
Code organization in readelf improved by moving function definitions.
The readelf utility’s source code has been refactored to improve organization. Function definitions like get_program_headers and get_dynamic_section are now placed immediately after their bitness-dependent helpers. This change also moves get_section_headers and get_elf_symbols to group related functionalities and removes the need for certain forward declarations.
In Details
In binutils/readelf.c, this commit reorganizes function placement. get_program_headers() and get_dynamic_section() are moved to appear after the readelf-nn.c inclusion, which defines bitness-specific helpers. Similarly, get_section_headers() and get_elf_symbols() are relocated to keep related code together. This refactoring eliminates forward declarations for get_program_headers, get_dynamic_section, and validate_section_info by defining them in proximity to their usage.
- readelf
- A utility in GNU Binutils that displays information about ELF (Executable and Linkable Format) files. It can show details about sections, symbols, dynamic linking information, and more.
- ELF
- Executable and Linkable Format. A common standard file format for executables, object code, shared libraries, and core dumps on Unix-like operating systems.
- forward declaration
- A declaration of an identifier (like a function or variable) that appears before its full definition. It informs the compiler about the identifier's existence, type, and signature, allowing it to be used before its definition.
- bitness-dependent
- Refers to code that behaves differently or uses different data types depending on whether the system is 32-bit or 64-bit. In the context of ELF files, this applies to structures and offsets that vary between ELF32 and ELF64 formats.