[PATCH] LoongArch: Detect relocations out of section range

Harshit Kumar harshit7kr@gmail.com
Fri Nov 20 10:37:44 GMT 2026


On Fri, Nov 20, 2026 at 07:36:28AM +1030, Alan Modra wrote:
> This is better done in relocate_section, unless loongarch reads
> section contents in check_relocs.  check_relocs is not called for some
> sections (see _bfd_elf_link_iterate_on_relocs), so for instance, debug
> sections won't have their relocations sanity checked.

The RFC I posted on Monday does this check for every ELF target where
the linker reads relocations (elf_link_read_relocs_from_section), so it
covers the sections check_relocs skips, and runs before relaxation:
https://inbox.sourceware.org/binutils/20261116184333.3297411-1-harshit7kr@gmail.com/

LoongArch is 15/17; the howto sizes cover the other relocations:
https://inbox.sourceware.org/binutils/20261116184333.3297411-16-harshit7kr@gmail.com/

With the series, a loongarch64 ld rejects the reloc-offset.s test from
this patch, and the same kind of relocation in .debug_info:

  dbg.o: bad reloc offset (0x1 + 0x8 > 0x1) for section `.debug_info'

mengqinggang, if the generic check is acceptable, this patch may not be
needed.  Comments on 15/17 would be very welcome.

Thanks,
Harshit



More information about the Binutils mailing list