aboutsummaryrefslogtreecommitdiff
path: root/bfd/elfnn-riscv.c
diff options
context:
space:
mode:
authorJim Wilson <jimw@sifive.com>2018-09-24 14:36:41 -0700
committerJim Wilson <jimw@sifive.com>2018-09-24 14:36:41 -0700
commita05f27b68934c2ea3efa028a0af2cd968db1bd2d (patch)
tree5566ae2facd3f0026b745544a67aa6b7c7a6da6c /bfd/elfnn-riscv.c
parent551703cfd409faca433626a0af077a43011381b7 (diff)
downloadgdb-a05f27b68934c2ea3efa028a0af2cd968db1bd2d.zip
gdb-a05f27b68934c2ea3efa028a0af2cd968db1bd2d.tar.gz
gdb-a05f27b68934c2ea3efa028a0af2cd968db1bd2d.tar.bz2
RISC-V: For PCREL_LO12, fix addend handling in auipc lookup.
bfd/ * elfnn-riscv.c (_bfd_riscv_relax_pc) <R_RISCV_PCREL_LO12_I>: New local hi_sec_off which is symbol address with addend subtracted. Use in riscv_find_pcgp_hi_reloc and riscv_record_pcgp_lo_reloc calls.
Diffstat (limited to 'bfd/elfnn-riscv.c')
-rw-r--r--bfd/elfnn-riscv.c9
1 files changed, 7 insertions, 2 deletions
diff --git a/bfd/elfnn-riscv.c b/bfd/elfnn-riscv.c
index 63ff07e..f3e2cc7 100644
--- a/bfd/elfnn-riscv.c
+++ b/bfd/elfnn-riscv.c
@@ -3226,11 +3226,16 @@ _bfd_riscv_relax_pc (bfd *abfd,
case R_RISCV_PCREL_LO12_I:
case R_RISCV_PCREL_LO12_S:
{
+ /* If the %lo has an addend, it isn't for the label pointing at the
+ hi part instruction, but rather for the symbol pointed at by the
+ hi part instruction. So we must subtract it here for the lookup.
+ It is still used below in the final symbol address. */
+ bfd_vma hi_sec_off = symval - sec_addr (sym_sec) - rel->r_addend;
riscv_pcgp_hi_reloc *hi = riscv_find_pcgp_hi_reloc (pcgp_relocs,
- symval - sec_addr(sym_sec));
+ hi_sec_off);
if (hi == NULL)
{
- riscv_record_pcgp_lo_reloc (pcgp_relocs, symval - sec_addr(sym_sec));
+ riscv_record_pcgp_lo_reloc (pcgp_relocs, hi_sec_off);
return TRUE;
}