readelf: Code rearrangement for readability
Refactors readelf.c to reduce `#ifdef` complexity and potentially improve code structure.
This patch attempts to reduce the amount of conditional compilation (#ifdef) in binutils/readelf.c by rearranging code. The goal is to improve readability and maintainability, though the author notes that a more extensive change like using function pointers for header reading was considered but deemed too complex to yield significant overall benefit.
In Details
The readelf.c source file handles the parsing and display of ELF (Executable and Linkable Format) file information. Due to the differences between 32-bit and 64-bit ELF formats, extensive use of #ifdef directives is often necessary to conditionally compile code paths. This patch aims to consolidate some of this conditional logic by restructuring the code, particularly around the functions responsible for reading program headers and section headers. The intent is to make the code cleaner without fundamentally altering its behavior or introducing new features.
- readelf
- A utility in GNU Binutils that displays information about ELF files (e.g., section headers, program headers, symbols).
- ELF
- Executable and Linkable Format, a standard file format for object files, executables, and core dumps on Unix-like systems.
- `#ifdef`
- A C preprocessor directive used for conditional compilation, allowing different code blocks to be included based on defined macros.
- program headers
- Structures within an ELF file that describe how the operating system should load segments of the executable into memory.
- section headers
- Structures within an ELF file that describe each section (e.g., code, data, symbols) in the object file.