s390: Rewrite emitted relocations when rewriting instructions
When the linker rewrites instructions it may need to rewrite the
associated relocations, so that when emitted with option --emit-relocs,
they make sense with the rewritten instructions. Otherwise post link
analysis and optimization tools may not be able to perform correct
modifications of executables.
Under certain conditions the linker rewrites:
- GOT access using lgrl to larl, changing the GOTENT to a PC32DBL reloc
- GOT access using lg to larl, changing the GOT20 to a PC32DBL reloc
- Relative long addressing instructions of weak symbols, which
definitively resolve to zero, to either (1) load address of zero,
(2) a NOP, or (3) a trapping instruction.
In case of a rewrite of GOT access using lgrl/lg to larl emit the
PC32DBL relocation. In case of a rewrite of relative long addressing
instructions of weak symbols, which definitively resolve to zero, emit
a NONE relocation and reset the symbol table index and addend. Update
the gotreloc* and weakundef* tests to check for the respective
relocations.
This aligns with how GNU linker behaves on x86-64, when rewriting
instructions/relocations in elf_x86_64_convert_load_reloc().