RISC-V: Treat R_RISCV_CALL and R_RISCV_CALL_PLT as the same in check_relocs.
authorNelson Chu <nelson.chu@sifive.com>
Wed, 26 Aug 2020 08:19:13 +0000 (01:19 -0700)
committerNelson Chu <nelson.chu@sifive.com>
Fri, 28 Aug 2020 01:37:35 +0000 (09:37 +0800)
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.

<https://sourceware.org/pipermail/libc-alpha/2020-August/117214.html>

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/ChangeLog
bfd/elfnn-riscv.c
ld/ChangeLog
ld/testsuite/ld-riscv-elf/lib-nopic-01a.s
ld/testsuite/ld-riscv-elf/lib-nopic-01b.d
ld/testsuite/ld-riscv-elf/lib-nopic-01b.s

index 7700973bf966fda5f9e4534a4163e1b7338a4f38..cbec1c5eecb6691713d1c43145747c4f429cc7bd 100644 (file)
@@ -1,3 +1,10 @@
+2020-08-28  Nelson Chu  <nelson.chu@sifive.com>
+
+       * 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.
+
 2020-08-27  John David Anglin  <danglin@gcc.gnu.org>
 
        PR 26356
index 5af1b1c3ff336e74e6d65ea3a96dc1ee447bf75e..e6c5d1fba5ad74851c34b3ebf4c3d741a6b9b120 100644 (file)
@@ -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,
index 7881dd1f0fce646087427b6340f487068b877645..787d7605f5de580b95eb993dd77a11d2e6a0009c 100644 (file)
@@ -1,3 +1,10 @@
+2020-08-28  Nelson Chu  <nelson.chu@sifive.com>
+
+       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.
+
 2020-08-27  Jozef Lawrynowicz  <jozef.l@mittosystems.com>
 
        * emultempl/msp430.em: Remove unused variable "buf".
index c95cda05d2427e070bae2c2c4ebf04ee13d696d6..632875d423af4f8753fb9ad336d1fcba145465b7 100644 (file)
@@ -4,6 +4,6 @@
        .globl  func1
        .type   func1, @function
 func1:
-       call    func2
+       jal     func2
        jr      ra
        .size   func1, .-func1
index 0d758a40d60134e997a7481c5f5b09d2b3c4c306..1c2c907fc308334627dab63dec998f9ceba31ac5 100644 (file)
@@ -2,4 +2,4 @@
 #source: lib-nopic-01b.s
 #as:
 #ld: -shared tmpdir/lib-nopic-01a.so
-#error: .*relocation R_RISCV_CALL against `func1' can not be used when making a shared object; recompile with -fPIC
+#error: .*relocation R_RISCV_JAL against `func1' can not be used when making a shared object; recompile with -fPIC
index 97fe1374e4fa9e287f7ac5243af1ce58b1202e5a..ea7b02988951d94406db961be7d7a034cef13de7 100644 (file)
@@ -4,6 +4,6 @@
        .globl  func2
        .type   func2, @function
 func2:
-       call    func1
+       jal     func1
        jr      ra
        .size   func2, .-func2