binutils Newspaper
NOVEMBER 30, 2026
binutils — Proposed

Correct r_symndx upper bound check in MIPS and Score relocations

Fixes an incorrect upper bound check for `r_symndx` in MIPS and Score ELF relocation processing.

This patch corrects an off-by-one error in the check_relocs functions for MIPS and Score ELF targets. The r_symndx field in relocation entries should not exceed the number of symbols available in the symbol table. The previous check incorrectly included an extsymoff offset that was not relevant for calculating the upper bound, leading to potential misinterpretation of symbol indices. A later patch will remove these checks entirely.

In Details

The check_relocs function in BFD's ELF backends verifies relocation entries. For MIPS and Score, the check for the upper bound of r_symndx was flawed. The sym_hashes array is indexed by r_symndx - extsymoff and has a size related to NUM_SHDR_ENTRIES. The patch corrects the check from r_symndx >= extsymoff + NUM_SHDR_ENTRIES to r_symndx >= NUM_SHDR_ENTRIES, aligning it with how sym_hashes is indexed and sized, and preventing out-of-bounds access or incorrect validation.

For Context
r_symndx
The symbol table index field within an ELF relocation entry.
MIPS
A Reduced Instruction Set Computing (RISC) architecture, commonly used in embedded systems and historically in workstations.
Score
A 32-bit RISC processor architecture.
ELF
Executable and Linkable Format, a standard file format for executables, object code, shared libraries, and core dumps on many Unix-like systems.
BFD
Binary File Descriptor library, a low-level interface used by binutils for manipulating object files.
relocation entry
Data within an object file that specifies how to modify addresses in code or data when the object is linked, especially for position-independent code.
extsymoff
An offset related to the external symbol table in ELF files, used for indexing.
NUM_SHDR_ENTRIES
A macro likely representing the number of section header entries in an ELF file.
Filed Under: elfrelocationsmipsscorebugfix