Ignore empty symtab sections
This patch prevents BFD from processing relocations in objects with empty symbol tables.
This patch addresses issues where BFD and GNU ld encounter errors when an empty .symtab section is present in ELF objects. It prevents BFD from attempting to handle relocations in such cases, similar to how missing .symtab sections are handled. The changes also improve error reporting and disable a test case on rx-elf that previously failed due to the issue.
In Details
This patch modifies bfd/elf.c to validate sh_info and sh_size for SHT_SYMTAB and SHT_DYNSYM sections. Previously, BFD might incorrectly process relocations when these sections were empty or malformed, leading to assertion failures or incorrect behavior in GNU ld. The change ensures that such sections are ignored if their size is less than the entry size, or if sh_info is zero, preventing downstream issues in relocation handling.
- .symtab
- A section in an ELF object file that contains the symbol table, which maps symbol names to their addresses and other information.
- BFD
- Binary File Descriptor library, a low-level interface used by binutils for manipulating object files.
- GNU ld
- The GNU linker, responsible for combining object files into executables or libraries.
- relocations
- Information in an object file that tells the linker how to adjust addresses when combining object files, especially in position-independent code.
- ELF
- Executable and Linkable Format, a standard file format for executables, object code, shared libraries, and core dumps on many Unix-like systems.
- SHT_SYMTAB
- A section header type in ELF that identifies a symbol table section.
- sh_info
- A field in an ELF section header that provides information specific to the section type, such as the index of the associated string table for a symbol table.
- sh_size
- A field in an ELF section header that indicates the size of the section in bytes.