Correct test for valid use of .dynsym
Improves the validation logic for using the dynamic symbol table (.dynsym) in ELF objects.
This patch revises the validation logic within bfd_elf_get_elf_syms when the dynamic symbol table (.dynsym) is used. Previously, it checked for an exact match between dt_symtab_count and the sum of symcount and symoffset. The updated check correctly handles cases where only a portion of .dynsym is relevant by ensuring symoffset is within bounds and that symcount does not exceed the available entries remaining in dt_symtab_count after symoffset.
- proposer
Proposes a more robust check for using the dynamic symbol table (.dynsym) in ELF objects.
“* elf.c (bfd_elf_get_elf_syms): Allow partial use of .dynsym when using the dynamic symbol table.”
In Details
The patch modifies bfd/elf.c's bfd_elf_get_elf_syms function. When elf_use_dt_symtab_p(ibfd) is true, the original check elf_tdata(ibfd)->dt_symtab_count != symcount + symoffset was too strict. The new condition symoffset >= elf_tdata(ibfd)->dt_symtab_count || symcount > elf_tdata(ibfd)->dt_symtab_count - symoffset correctly validates that the requested symbol range (symoffset to symoffset + symcount) is contained within the available dynamic symbol table entries.
- .dynsym
- The dynamic symbol table section in an ELF object file. It contains symbols that are visible to the dynamic linker and are used for dynamic linking.
- ELF
- Executable and Linkable Format. A standard file format for object files, executables, shared libraries, and core dumps on many Unix-like systems.
- Symbol Table
- A data structure within an object file or executable that maps symbol names to their addresses and other attributes, used by linkers and debuggers.
- Dynamic Linker
- A program that resolves symbols and performs relocations for dynamically linked executables and libraries at runtime.
- bfd_elf_get_elf_syms
- A BFD library function that likely retrieves symbol table information from an ELF object file.