binutils Newspaper
OCTOBER 6, 2026
elf — Proposed — Sentiment 5 / 10

elf: Set this_idx to -1 for invalid relocations

Fixes redundant error reporting for invalid relocation symbol indices in the ELF linker.

This patch addresses an issue in the binutils ELF linker where invalid relocation symbol indices cause the linker to report the same error twice. The fix modifies elf_link_read_relocs_from_section to set this_idx to -1 for invalid relocations and return false if this_idx is negative, preventing subsequent erroneous checks.

In the Thread 2 participants
  1. H.J. Lu <hjl.tools@gmail.com> proposer

    Submits a patch to prevent redundant error reporting of invalid relocation symbol indices by setting `this_idx` to -1 and returning `false` on error.

    “When invalid relocation is reported by elf_link_read_relocs_from_section called from lang_gc_sections: ld: pr34448-bug_18.o: bad reloc symbol index (0xf2000005 >= 0x13) for offset 0x4 in section `.text.get_tls[get_tls]' the same error is reported again: ld: pr34448-bug_18.o: bad reloc symbol index (0xf2000005 >= 0x13) for offset 0x4 in section `.text.get_tls[get_tls]' from lang_check_relocs s…”
  2. H.J. Lu <hjl.tools@gmail.com> proposer

    Withdraws the previous patch and announces an intention to post a different fix for the same issue.

    “I withdrew this patch. I will post a different fix.”

Technical Tradeoffs

  • Correcting the error reporting mechanism to avoid redundant messages.
  • Ensuring that invalid relocation data does not lead to misinterpretation or repeated errors.
  • Maintaining the linker's ability to halt on fatal errors.

In Details

This patch addresses a bug in the ELF linker (ld) where an invalid relocation symbol index, detected during garbage collection of sections, triggers a fatal error message. The error is then reported again because lang_gc_sections doesn't halt the linker. The fix involves modifying elf_link_read_relocs_from_section to signal an invalid index by setting this_idx to -1, which will prevent the subsequent redundant error report.

For Context
relocation
Information in an object file that describes how to modify parts of the code or data when linking, such as resolving symbol addresses.
symbol index
An identifier or pointer within the symbol table of an object file, used to refer to a specific symbol (e.g., a function or variable).
garbage collection (GC) of sections
A linker process that identifies and removes unused sections from an executable to reduce its size.
ELF
Executable and Linkable Format, a common standard file format for object files, executables, and shared libraries on Unix-like systems.
Filed Under: binutilselflinkerrelocationsbugfix