aboutsummaryrefslogtreecommitdiff
path: root/bfd/elfnn-riscv.c
diff options
context:
space:
mode:
authorJim Wilson <jimw@sifive.com>2018-06-03 15:42:29 -0700
committerJim Wilson <jimw@sifive.com>2018-06-03 15:42:29 -0700
commitcf7a5066b92552b62ca4d247c241a19d1a6e599d (patch)
tree5b74f5f0143786dcfdc6afce24fd11fa0987250a /bfd/elfnn-riscv.c
parent137b5cbd204241ec47873c353cf7e41b47182d53 (diff)
downloadgdb-cf7a5066b92552b62ca4d247c241a19d1a6e599d.zip
gdb-cf7a5066b92552b62ca4d247c241a19d1a6e599d.tar.gz
gdb-cf7a5066b92552b62ca4d247c241a19d1a6e599d.tar.bz2
RISC-V: Handle out-of-range calls to undefined weak.
bfd/ PR ld/23244 * elfnn-riscv.c (riscv_elf_relocate_section) <R_RISCV_CALL>: Check for and handle an undefined weak with no PLT. ld/ * testsuite/ld-riscv-elf/ld-riscv-elf.exp: Run new weak ref tests. * testsuite/ld-riscv-elf/weakref.ld: New. * testsuite/ld-riscv-elf/weakref32.d: New. * testsuite/ld-riscv-elf/weakref32.s: New. * testsuite/ld-riscv-elf/weakref64.d: New. * testsuite/ld-riscv-elf/weakref64.s: New.
Diffstat (limited to 'bfd/elfnn-riscv.c')
-rw-r--r--bfd/elfnn-riscv.c18
1 files changed, 17 insertions, 1 deletions
diff --git a/bfd/elfnn-riscv.c b/bfd/elfnn-riscv.c
index a0bdee5..7b1ca47 100644
--- a/bfd/elfnn-riscv.c
+++ b/bfd/elfnn-riscv.c
@@ -1931,8 +1931,24 @@ riscv_elf_relocate_section (bfd *output_bfd,
}
break;
- case R_RISCV_CALL_PLT:
case R_RISCV_CALL:
+ /* Handle a call to an undefined weak function. This won't be
+ relaxed, so we have to handle it here. */
+ if (h != NULL && h->root.type == bfd_link_hash_undefweak
+ && h->plt.offset == MINUS_ONE)
+ {
+ /* We can use x0 as the base register. */
+ bfd_vma insn = bfd_get_32 (input_bfd,
+ contents + rel->r_offset + 4);
+ insn &= ~(OP_MASK_RS1 << OP_SH_RS1);
+ bfd_put_32 (input_bfd, insn, contents + rel->r_offset + 4);
+ /* Set the relocation value so that we get 0 after the pc
+ relative adjustment. */
+ relocation = sec_addr (input_section) + rel->r_offset;
+ }
+ /* Fall through. */
+
+ case R_RISCV_CALL_PLT:
case R_RISCV_JAL:
case R_RISCV_RVC_JUMP:
if (bfd_link_pic (info) && h != NULL && h->plt.offset != MINUS_ONE)