Prevent BFD from processing relocations in ELF files with empty symbol tables
Binutils BFD now rejects ELF object files with empty symbol tables when processing relocations.
This commit prevents BFD from attempting to process relocations in ELF object files that have an empty symbol table section. Such files can cause confusion because the linking process relies on a valid symbol table, particularly for the STN_UNDEF symbol. BFD now treats empty symbol tables similarly to missing ones, reporting an error and avoiding incorrect processing, which resolves several PRs related to malformed object files.
In Details
The bfd_section_from_shdr function in bfd/elf.c is updated to reject sections of type SHT_SYMTAB or SHT_DYNSYM if they are empty (i.e., sh_entsize is 0 or sh_size is 0). Previously, BFD might have attempted to use these empty sections, leading to errors when processing relocations that expect a valid symbol table, especially the STN_UNDEF symbol. This change aligns BFD's behavior with the requirement for a non-empty symbol table when relocations are present, fixing PRs 34835, 13962, and 7023.
- relocations
- Information in an object file that describes how to modify certain addresses or symbols when linking. For example, a relocation entry might indicate that a specific address needs to be updated with the actual address of a function.
- symbol table
- A data structure within an object file that lists all the symbols (e.g., function names, variable names) defined or referenced by the code. It's crucial for linking and debugging.
- STN_UNDEF
- A special symbol table index in ELF that represents an undefined symbol, typically a function or variable that is defined in another object file or shared library.
- ELF
- Executable and Linkable Format. A common standard file format for executables, object code, shared libraries, and core dumps on Unix-like systems.
- BFD
- Binary File Descriptor library. A library used by GNU Binutils to provide a generic interface for reading and writing various binary file formats, including ELF.