riscv: check relaxation delete range, propagate failures
Enhances RISC-V relaxation handling by validating deletion ranges and propagating errors.
This patch, the final in a series (v2 8/8), strengthens the relaxation process for RISC-V binaries by adding range validation to byte deletion operations within _riscv_relax_delete_bytes. It utilizes _bfd_elf_relax_delete_range_ok to ensure deletions occur within valid bounds before calculating how many bytes to move. Furthermore, the patch ensures that any failures during this deletion process are propagated to the calling functions (_bfd_riscv_relax_tlsdesc and _bfd_riscv_relax_pc). A new DejaGnu regression test (riscv-relax-underflow.exp) is included to specifically check for and prevent relaxation underflow issues.
- proposer
Submits the final patch in a series to improve RISC-V relaxation by validating deletion ranges, propagating failures, and adding a regression test.
“In _riscv_relax_delete_bytes, validate deletion range using _bfd_elf_relax_delete_range_ok before computing bytes_to_move. Propagate deletion return values to callers in _bfd_riscv_relax_tlsdesc and _bfd_riscv_relax_pc. Add DejaGnu regression test ld-riscv-elf/riscv-relax-underflow.exp.”
In Details
This patch is part of a series addressing relaxation issues in the RISC-V linker backend of binutils. Specifically, it targets the _riscv_relax_delete_bytes function, which is responsible for removing code bytes during relaxation. The key changes are: 1) Introducing a call to _bfd_elf_relax_delete_range_ok to validate the addr, count, and toaddr parameters before performing the deletion, preventing potential underflows or out-of-bounds operations. 2) Ensuring that the boolean return value of _riscv_relax_delete_bytes is checked and propagated by its callers, `_bfd_riscv_relax_tlsd…
- relaxation
- A process in linkers where the linker adjusts machine code after initial assembly to resolve symbolic addresses and optimize code, often involving changing instruction lengths or operand values.
- RISC-V
- An open-standard instruction set architecture (ISA) based on reduced instruction set computer principles. Binutils provides linker support for RISC-V.
- linker
- A program that combines one or more object files (produced by an assembler or compiler) into a single executable file, library file, or another object file. It resolves symbolic references between files.
- underflow
- In this context, an underflow during relaxation likely refers to an operation that results in an invalid or nonsensical memory address or size calculation, potentially due to incorrect calculations or boundary violations.
- DejaGnu
- A testing framework developed by the Free Software Foundation for testing C compilers and other programming tools. It provides a common infrastructure for writing test harnesses.
- BFD
- Binutils 'Binary File Descriptor' library. It provides a common interface for reading and writing various object file formats, including ELF files used by RISC-V.