Correct upper bound check for relocation symbol indices in MIPS and Score
Relocation symbol index bounds are corrected for MIPS and Score ELF backends in BFD.
This change corrects the upper bound check for relocation symbol indices (r_symndx) in the MIPS and Score ELF backends within BFD. The previous logic used an incorrect offset, leading to potential validation errors. The updated code ensures that r_symndx is correctly compared against the total number of symbols, improving the accuracy of relocation processing for these architectures.
In Details
The check_relocs functions for MIPS (_bfd_mips_elf_check_relocs in elfxx-mips.c) and Score (s3_bfd_score_elf_check_relocs in elf32-score.c and s7_bfd_score_elf_check_relocs in elf32-score7.c) had an incorrect upper bound check for r_symndx. The code previously used extsymoff + NUM_SHDR_ENTRIES(symtab_hdr) as the limit. This commit corrects it to simply NUM_SHDR_ENTRIES(symtab_hdr), which accurately reflects the maximum valid symbol index in the symbol table. This ensures that relocations referencing symbols beyond the table are correctly identified as errors.
- r_symndx
- The symbol table index field within an ELF relocation entry. It indicates which symbol the relocation refers to.
- relocation
- 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.
- 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.
- MIPS
- Microprocessor without Interlocked Pipeline Stages. A family of Reduced Instruction Set Computing (RISC) architectures.
- Score
- A 32-bit RISC instruction set architecture developed by Star Semiconductor.