diff options
author | Jim Wilson <jimw@sifive.com> | 2018-06-03 15:42:29 -0700 |
---|---|---|
committer | Jim Wilson <jimw@sifive.com> | 2018-06-03 15:42:29 -0700 |
commit | cf7a5066b92552b62ca4d247c241a19d1a6e599d (patch) | |
tree | 5b74f5f0143786dcfdc6afce24fd11fa0987250a /bfd | |
parent | 137b5cbd204241ec47873c353cf7e41b47182d53 (diff) | |
download | gdb-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')
-rw-r--r-- | bfd/ChangeLog | 4 | ||||
-rw-r--r-- | bfd/elfnn-riscv.c | 18 |
2 files changed, 21 insertions, 1 deletions
diff --git a/bfd/ChangeLog b/bfd/ChangeLog index 250e416..a8f4688 100644 --- a/bfd/ChangeLog +++ b/bfd/ChangeLog @@ -1,5 +1,9 @@ 2018-06-03 Jim Wilson <jimw@sifive.com> + PR ld/23244 + * elfnn-riscv.c (riscv_elf_relocate_section) <R_RISCV_CALL>: Check + for and handle an undefined weak with no PLT. + PR ld/22756 * elfnn-riscv.c (riscv_relax_delete_bytes): Add versioned_hidden check to code that ignores duplicate symbols. 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) |