RISC-V: Support PCREL_* relocations agaist weak undefined symbols
I recently modified our Linux port's base address such the absolute
address 0 is no longer addressable as a 32-bit PC-relative offset.
Since Linux links a weak undefined symbol in an intermediate binary, it
needs to be able to reference absolute address 0.
This patch changes R_RISCV_PCREL_* relocations to absolute relocations
while resolving them in order to allow these symbols to be referenced in
PC-relative programs linked at high addresses. Note that this doesn't
apply to PIC, which also uses PC-relative relocations, just to
position-dependent objects, which we use to allow programs to be linked
at high addresses.
In case some of our embedded users are using R_RISCV_PCREL_* as a hacked
up method of getting position-independent binaries (which can work if
you have very simple programs), we only convert the relocations when the
PC-relative version would overflow.
bfd/ChangeLog:
2017-09-07 Palmer Dabbelt <palmer@dabbelt.com>
* elfnn-riscv.c (riscv_zero_pcrel_hi_reloc): New function.
(riscv_record_pcrel_hi_reloc): Add absolute argument.
(riscv_elf_relocate_section): Call riscv_zero_pcrel_hi_reloc for
R_RISCV_PCREL_HI20 relocs, and pass the result to
riscv_record_pcrel_hi_reloc.