From 3b1450b38c644f99aa2e211747b428b9f8d15cca Mon Sep 17 00:00:00 2001 From: Nelson Chu Date: Wed, 26 Aug 2020 01:19:13 -0700 Subject: RISC-V: Treat R_RISCV_CALL and R_RISCV_CALL_PLT as the same in check_relocs. In fact, we can treate these two relocation as the same one in the riscv_elf_check_relocs. I have heard that RISC-V lld had made this improvement, and so had GNU AARCH64, they only need R_AARCH64_CALL26 for calls rather than two seperate relocations. Beside, the following PLT issue for RISC-V 32-bit glibc seems to be fixed by applying at least this patch. I have ran the toolchain regression, and everything seems fine for now. bfd/ * elfnn-riscv.c (riscv_elf_check_relocs): Treat R_RISCV_CALL and R_RISCV_CALL_PLT as the same in the riscv_elf_check_relocs. (riscv_elf_relocate_section): Remove the R_RISCV_CALL for the unresolved reloc checks. ld/ testsuite/ld-riscv-elf/lib-nopic-01a.s: Use R_RISCV_JAL rather than R_RISCV_CALL. testsuite/ld-riscv-elf/lib-nopic-01b.d: Likewise. testsuite/ld-riscv-elf/lib-nopic-01b.s: Likewise. --- bfd/elfnn-riscv.c | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) (limited to 'bfd/elfnn-riscv.c') diff --git a/bfd/elfnn-riscv.c b/bfd/elfnn-riscv.c index 5af1b1c..e6c5d1f 100644 --- a/bfd/elfnn-riscv.c +++ b/bfd/elfnn-riscv.c @@ -557,21 +557,23 @@ riscv_elf_check_relocs (bfd *abfd, struct bfd_link_info *info, return FALSE; break; + case R_RISCV_CALL: case R_RISCV_CALL_PLT: - /* This symbol requires a procedure linkage table entry. We + /* These symbol requires a procedure linkage table entry. We actually build the entry in adjust_dynamic_symbol, - because this might be a case of linking PIC code without + because these might be a case of linking PIC code without linking in any dynamic objects, in which case we don't need to generate a procedure linkage table after all. */ - if (h != NULL) - { - h->needs_plt = 1; - h->plt.refcount += 1; - } + /* If it is a local symbol, then we resolve it directly + without creating a PLT entry. */ + if (h == NULL) + continue; + + h->needs_plt = 1; + h->plt.refcount += 1; break; - case R_RISCV_CALL: case R_RISCV_JAL: case R_RISCV_BRANCH: case R_RISCV_RVC_BRANCH: @@ -2189,7 +2191,6 @@ riscv_elf_relocate_section (bfd *output_bfd, { switch (r_type) { - case R_RISCV_CALL: case R_RISCV_JAL: case R_RISCV_RVC_JUMP: if (asprintf (&msg_buf, -- cgit v1.1