[PATCH v2 2/8] RISC-V: Treat R_RISCV_CALL and R_RISCV_CALL_PLT as the same.
Fangrui Song
i@maskray.me
Tue Aug 11 05:25:39 GMT 2020
On 2020-08-06, Nelson Chu wrote:
> 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 ++++++++++---------
> ld/testsuite/ld-riscv-elf/lib-nopic-01a.s | 2 +-
> ld/testsuite/ld-riscv-elf/lib-nopic-01b.d | 2 +-
> ld/testsuite/ld-riscv-elf/lib-nopic-01b.s | 2 +-
> 4 files changed, 13 insertions(+), 12 deletions(-)
>
>diff --git a/bfd/elfnn-riscv.c b/bfd/elfnn-riscv.c
>index fee169c..94ee184 100644
>--- a/bfd/elfnn-riscv.c
>+++ b/bfd/elfnn-riscv.c
>@@ -705,18 +705,21 @@ 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 symbols require 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_JAL:
>@@ -728,7 +731,6 @@ riscv_elf_check_relocs (bfd *abfd, struct bfd_link_info *info,
> break;
> goto static_reloc;
>
>- case R_RISCV_CALL:
> case R_RISCV_PCREL_HI20:
> /* In shared libraries, these relocs are known to bind locally,
> except IFUNC symbol. */
>@@ -2669,7 +2671,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,
>diff --git a/ld/testsuite/ld-riscv-elf/lib-nopic-01a.s b/ld/testsuite/ld-riscv-elf/lib-nopic-01a.s
>index c95cda0..632875d 100644
>--- a/ld/testsuite/ld-riscv-elf/lib-nopic-01a.s
>+++ b/ld/testsuite/ld-riscv-elf/lib-nopic-01a.s
>@@ -4,6 +4,6 @@
> .globl func1
> .type func1, @function
> func1:
>- call func2
>+ jal func2
> jr ra
> .size func1, .-func1
>diff --git a/ld/testsuite/ld-riscv-elf/lib-nopic-01b.d b/ld/testsuite/ld-riscv-elf/lib-nopic-01b.d
>index 0d758a4..1c2c907 100644
>--- a/ld/testsuite/ld-riscv-elf/lib-nopic-01b.d
>+++ b/ld/testsuite/ld-riscv-elf/lib-nopic-01b.d
>@@ -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
>diff --git a/ld/testsuite/ld-riscv-elf/lib-nopic-01b.s b/ld/testsuite/ld-riscv-elf/lib-nopic-01b.s
>index 97fe137..ea7b029 100644
>--- a/ld/testsuite/ld-riscv-elf/lib-nopic-01b.s
>+++ b/ld/testsuite/ld-riscv-elf/lib-nopic-01b.s
>@@ -4,6 +4,6 @@
> .globl func2
> .type func2, @function
> func2:
>- call func1
>+ jal func1
> jr ra
> .size func2, .-func2
>--
>2.7.4
>
Happy to see this:)
I think this is not tightly connected to the rest of the ifunc patch
series?
More information about the Binutils
mailing list