For R_RISCV_CALL and R_RISCV_CALL_PLT, in relax_pass 0 and relax_trip 2 of _bfd_riscv_relax_section, if benifical the auipc is replaced by zcmt instruction in _bfd_riscv_table_jump_mark.
But in relax_pass 1 of _bfd_riscv_relax_call, it seems the marked instruction fails to be relaxed to a zcmt insntruction if auipc+jalr could not be shortened to jal or jalr(near zero) due to the following condition check:
/* See if this function call can be shortened. */
if (!VALID_JTYPE_IMM (foff) && !(!bfd_link_pic (link_info) && near_zero)
&& link_info->relax_pass != 0)
return true;
Seems we need to move the following codes to the top of function to avoid being blocked by the condition above.
hi,
https://github.com/openhwgroup/corev-binutils-gdb/blob/development/bfd/elfnn-riscv.c
For R_RISCV_CALL and R_RISCV_CALL_PLT, in relax_pass 0 and relax_trip 2 of _bfd_riscv_relax_section, if benifical the auipc is replaced by zcmt instruction in _bfd_riscv_table_jump_mark.
But in relax_pass 1 of _bfd_riscv_relax_call, it seems the marked instruction fails to be relaxed to a zcmt insntruction if auipc+jalr could not be shortened to jal or jalr(near zero) due to the following condition check:
Seems we need to move the following codes to the top of function to avoid being blocked by the condition above.
BR Joshcafe