LoongArch: Detect relocations out of section range
Adds checks in the LoongArch ELF relocation process to detect and reject relocations that extend beyond their section boundaries.
This patch introduces a check within the LoongArch ELF relocation processing to identify and reject relocations whose fields extend outside the bounds of their respective input sections. It utilizes bfd_reloc_offset_in_range for this validation and skips certain relocation types like R_LARCH_NONE and R_LARCH_RELAX. New test cases are included to verify this functionality.
- proposer
Submits a revised patch to implement relocation range checking for LoongArch ELF files, placing the check within `relocate_section` as suggested.
“Use bfd_reloc_offset_in_range in loongarch_elf_relocate_section to reject input relocations whose fields extend outside their section. ... v1 -> v2: - Check in relocate_section as Alan suggested.”
In Details
This patch modifies bfd/elfnn-loongarch.c to use bfd_reloc_offset_in_range within loongarch_elf_relocate_section. The goal is to validate that input relocations, when their size is considered, do not extend beyond the end of the input section they are associated with. This prevents potential issues in later linking stages caused by invalid relocation offsets. The patch also adds new test cases in ld/testsuite/ld-loongarch-elf/ to cover this scenario.
- Relocation
- A process performed by the linker to adjust symbolic addresses in object code after it has been combined. Relocations indicate where in the code addresses need to be updated.
- ELF
- Executable and Linkable Format. A standard file format for object code, executables, and shared libraries on many Unix-like systems.
- R_LARCH_NONE
- A LoongArch relocation type that indicates no operation is needed; it's a placeholder or might be used in specific contexts.
- R_LARCH_RELAX
- A LoongArch relocation type used for instruction relaxation, where the linker might adjust instruction encodings for performance or size.
- bfd_reloc_offset_in_range
- A BFD library function that checks if a given relocation offset, considering its size, falls within the bounds of a specified section.