binutils Newspaper
JULY 29, 2026
readelf Proposed

readelf: Consolidate get_[32|64]bit_section_headers

Consolidates 32-bit and 64-bit section header reading functions into one in readelf.

This patch consolidates the get_32bit_section_headers and get_64bit_section_headers functions in readelf.c into a single get_section_headers function. The new function handles both 32-bit and 64-bit ELF section headers, utilizing the BYTE_GET_SIZE macro for reading external ELF section header fields. This consolidation aims to reduce code duplication and enhance maintainability within the readelf utility, addressing PR binutils/34356.

In Details

This is the first patch in a series to refactor readelf's ELF file parsing. It merges the distinct functions for reading 32-bit and 64-bit ELF section headers (get_32bit_section_headers and get_64bit_section_headers) into a single get_section_headers function. This generalized function uses the BYTE_GET_SIZE macro to read header fields from the external ELF file, providing a unified approach and eliminating redundant code. This change is part of the effort to address PR binutils/34356.

For Context
readelf
A utility that displays information about ELF files, including section header details.
section headers
Data structures within an ELF file that describe each section, such as its name, type, size, and memory address.
ELF
Executable and Linkable Format, a standard file format for executables, object code, shared libraries, and core dumps on many Unix-like systems.
consolidation
The process of merging multiple functions or code blocks into a single, more efficient one.
BYTE_GET_SIZE
A macro likely used to read a value of a specific size from a byte buffer and advance the buffer pointer.
Filed Under: readelfelfsection headersrefactoringcode consolidation