readelf: Check for missing DT_REL and DT_RELA dynamic tags
readelf now properly errors out when essential relocation dynamic tags are absent.
The readelf utility previously did not explicitly check for the presence of DT_REL and DT_RELA dynamic tags, which are crucial for processing relocations. This commit modifies the process_relocs function to detect and report an error when these tags are missing, preventing potential issues with malformed ELF files.
In Details
The process_relocs function in readelf.c needs to ensure that DT_REL and DT_RELA dynamic tags are present to correctly parse relocation entries. Previously, the code would abort() if rel_type was reltype_unknown, but this did not cover the case where the tags themselves were entirely absent. This commit adds an explicit check and returns false (signaling an error) when these tags are missing, aligning with the expected behavior for malformed ELF files.
- readelf
- A utility that displays information about ELF (Executable and Linkable Format) files, including dynamic sections and relocation information.
- DT_REL
- A dynamic tag in an ELF file that specifies the location and size of the .rel relocation entries section.
- DT_RELA
- A dynamic tag in an ELF file that specifies the location and size of the .rela relocation entries section.
- dynamic tags
- Key-value pairs in the ELF dynamic section that provide essential information for the runtime linker and dynamic loader, such as the locations of symbols, libraries, and relocation entries.
- relocation entries
- Information in an object file that describes how to modify code or data references to point to the correct addresses after linking or loading.