propose to tighten condition for calls of _bfd_riscv_table_jump_mark for R_RISCV_CALL/R_RISCV_CALL_PLT/R_RISCV_JAL only
Created by: JoshCafe
hi
https://github.com/openhwgroup/corev-binutils-gdb/blob/development/bfd/elfnn-riscv.c
In relax pass 0 and relax_trip 2 of _bfd_riscv_relax_section, if table jump can save size, and then we replace all targeted instructions/instruction pairs(e.g. auipc+jalr or jal) to zcmt instructions by _bfd_riscv_table_jump_mark function.
But seems we try to call _bfd_riscv_table_jump_mark for all kinds of relocation types, which exposes a risk to replace an un-targeted instruction with a zcmt instruction.
So propose to tighten condition for calls of _bfd_riscv_table_jump_mark for R_RISCV_CALL/R_RISCV_CALL_PLT/R_RISCV_JAL only.
relax_func = NULL;
if (info->relax_pass == 0)
{
if (!riscv_use_table_jump (info))
return true;
if (info->relax_trip == 0)
{
if (type == R_RISCV_CALL
|| type == R_RISCV_CALL_PLT)
relax_func = _bfd_riscv_relax_call;
else if (type == R_RISCV_JAL)
relax_func = _bfd_riscv_record_jal;
else
continue;
*again = true;
}
else if (info->relax_trip == 2) // tighten condition for R_RISCV_CALL/R_RISCV_CALL_PLT/R_RISCV_JAL only
relax_func = _bfd_riscv_table_jump_mark;
}