Files
binutils-gdb/include/elf
Kito Cheng 44c3932467 RISC-V: Add second-pass relaxation for JAL to C.J/C.JAL
When linker relaxation converts CALL (auipc+jalr, 8 bytes) to JAL
(4 bytes), further relaxation to C.J or C.JAL (2 bytes) may become
possible as code shrinks and jump distances decrease.

This patch adds _bfd_riscv_relax_jal to perform this second-pass
relaxation.  To enable this, we introduce R_RISCV_DELETE_AND_RELAX,
a new internal relocation that combines piecewise deletion with
preservation of relaxation capability.  When _bfd_riscv_relax_call
relaxes CALL to JAL, it marks the deletion as R_RISCV_DELETE_AND_RELAX
instead of R_RISCV_DELETE.  After the piecewise deletion is resolved,
R_RISCV_DELETE_AND_RELAX is converted back to R_RISCV_RELAX at the
JAL instruction offset, allowing _bfd_riscv_relax_jal to further
relax JAL to C.J/C.JAL.

C.JAL is only available on RV32 (rd=ra), while C.J is available on
both RV32 and RV64 (rd=x0).

Changes since v1:
- Use R_RISCV_DELETE_AND_RELAX with piecewise deletion instead of
  calling _riscv_relax_delete_immediate directly, to maintain
  relaxation performance.
- Add preserve_relax parameter to riscv_relax_delete_bytes to
  simplify the logic in _bfd_riscv_relax_call.
2026-01-15 12:04:57 +08:00
..