binutils Newspaper
NOVEMBER 30, 2026
binutils — Proposed

Remove sym_hashes check in RELOC_FOR_GLOBAL_SYMBOL

Removes a redundant NULL check for `sym_hashes` in the `RELOC_FOR_GLOBAL_SYMBOL` macro.

This patch removes a check for sym_hashes == NULL from the RELOC_FOR_GLOBAL_SYMBOL macro within bfd/elf-bfd.h. The proposer argues that this check is now redundant because elf_link_read_relocs_from_section already ensures that sym_hashes is valid. The removed comment indicates this check dates back to the initial CRIS ELF commit and might have addressed other bugs related to NULL sym_hashes.

In the Thread 1 participant
  1. Alan Modra <amodra@gmail.com> proposer

    Removes a redundant NULL check for `sym_hashes` in the `RELOC_FOR_GLOBAL_SYMBOL` macro, stating it's now guaranteed to be non-NULL by other functions.

    “This should not be necessary with the sym_hashes check in elf_link_read_relocs_from_section. BTW, the comment removed traces all the way back to the initial cris commit (06c15ad74f39). NULL sys_hashes were likely caused by some other bug, such as not checking for the correct tdata.”

In Details

This patch cleans up the RELOC_FOR_GLOBAL_SYMBOL macro in bfd/elf-bfd.h by removing a sym_hashes == NULL check. This check was likely a safeguard against erroneous input or bugs in earlier ELF handling (specifically mentioning the CRIS commit). The removal implies that elf_link_read_relocs_from_section now reliably populates and validates sym_hashes, making the macro-level check unnecessary. The original comment suggests NULL sym_hashes might have indicated other deeper issues.

For Context
sym_hashes
Likely an array or hash table containing symbol information, used for efficient symbol lookup during linking.
RELOC_FOR_GLOBAL_SYMBOL
A macro in BFD used to process relocations that refer to global symbols.
NULL
A special pointer value that represents an invalid or uninitialized memory address. In C, it's typically defined as (void*)0.
elf_link_read_relocs_from_section
A BFD function responsible for reading and processing relocation entries from a specific section in an ELF object file.
CRIS
A 32-bit RISC instruction set architecture developed by Axis Communications. The reference to a CRIS commit suggests this check originated from early ELF support for that architecture.
Filed Under: cleanupmacrobinutils