Linker relaxation may change relocations (offsets and types). However,
when --emit-relocs is used, relocations are simply copied from the input
section causing a mismatch with the corresponding (relaxed) code
section.
This patch fixes this as follows: for non-relocatable RISC-V binaries,
InputSection::copyRelocations reads relocations from the relocated
section's relocations array (since this gets updated by the relaxation
code). For all other cases, relocations are read from the input section
directly as before.
In order to reuse as much code as possible, and to keep the diff small,
the original InputSection::copyRelocations is changed to accept the
relocations as a range of Relocation objects. This means that, in the
general case when reading from the input section, raw relocations need
to be converted to Relocations first, which introduces quite a bit of
boiler plate. It also means there's a slight code size increase due to
the extra instantiations of copyRelocations (for both range types).
Isn’t that true of other architectures though? TLS relaxations, GOT->PCREL relaxation, …