[2.43] LoongArch: Add relaxation support for call36 that jump to PLT entry

Message ID 20241226061411.1645371-2-xry111@xry111.site
State New
Headers
Series [2.43] LoongArch: Add relaxation support for call36 that jump to PLT entry |

Commit Message

Xi Ruoyao Dec. 26, 2024, 6:14 a.m. UTC
  From: mengqinggang <mengqinggang@loongson.cn>

Part of commit a104f0a3e620 ("LoongArch: Add more relaxation support for
call36") in master.  This part is needed for 2.43 branch to fix a link
failure of QtWebEngine-6.8.1, which can be demonstrated with a reduced
test case (with -shared):

    .text
    .zero 1 << 27   # pretending we have a lot of code in .text
    .globl f        # preemptible, thus must be called via PLT
    f:
      move $a0, $r0
      ret
    g:
      pcaddu18i $t0, %call36(f)
      jr $t0

Signed-off-by: Xi Ruoyao <xry111@xry111.site>
---
 bfd/elfnn-loongarch.c | 5 +++++
 1 file changed, 5 insertions(+)


base-commit: 923497873f837bab74b6a850b63b46e27a79d924
  

Comments

Lulu Cai Dec. 30, 2024, 2:42 a.m. UTC | #1
Thanks, the patch has been pushed to binutils-2_43-branch.

On 12/26/24 2:14 PM, Xi Ruoyao wrote:
> From: mengqinggang <mengqinggang@loongson.cn>
>
> Part of commit a104f0a3e620 ("LoongArch: Add more relaxation support for
> call36") in master.  This part is needed for 2.43 branch to fix a link
> failure of QtWebEngine-6.8.1, which can be demonstrated with a reduced
> test case (with -shared):
>
>      .text
>      .zero 1 << 27   # pretending we have a lot of code in .text
>      .globl f        # preemptible, thus must be called via PLT
>      f:
>        move $a0, $r0
>        ret
>      g:
>        pcaddu18i $t0, %call36(f)
>        jr $t0
>
> Signed-off-by: Xi Ruoyao <xry111@xry111.site>
> ---
>   bfd/elfnn-loongarch.c | 5 +++++
>   1 file changed, 5 insertions(+)
>
> diff --git a/bfd/elfnn-loongarch.c b/bfd/elfnn-loongarch.c
> index 312707bb00b..f5ab02f82f7 100644
> --- a/bfd/elfnn-loongarch.c
> +++ b/bfd/elfnn-loongarch.c
> @@ -5410,6 +5410,11 @@ loongarch_elf_relax_section (bfd *abfd, asection *sec,
>   		    && GOT_TLS_GD_BOTH_P (tls_type))
>   		symval += 2 * GOT_ENTRY_SIZE;
>   	    }
> +	  else if (h->plt.offset != MINUS_ONE)
> +	    {
> +	      sym_sec = htab->elf.splt ? htab->elf.splt : htab->elf.iplt;
> +	      symval = h->plt.offset;
> +	    }
>   	  else if ((h->root.type == bfd_link_hash_defined
>   		  || h->root.type == bfd_link_hash_defweak)
>   		&& h->root.u.def.section != NULL
>
> base-commit: 923497873f837bab74b6a850b63b46e27a79d924
  

Patch

diff --git a/bfd/elfnn-loongarch.c b/bfd/elfnn-loongarch.c
index 312707bb00b..f5ab02f82f7 100644
--- a/bfd/elfnn-loongarch.c
+++ b/bfd/elfnn-loongarch.c
@@ -5410,6 +5410,11 @@  loongarch_elf_relax_section (bfd *abfd, asection *sec,
 		    && GOT_TLS_GD_BOTH_P (tls_type))
 		symval += 2 * GOT_ENTRY_SIZE;
 	    }
+	  else if (h->plt.offset != MINUS_ONE)
+	    {
+	      sym_sec = htab->elf.splt ? htab->elf.splt : htab->elf.iplt;
+	      symval = h->plt.offset;
+	    }
 	  else if ((h->root.type == bfd_link_hash_defined
 		  || h->root.type == bfd_link_hash_defweak)
 		&& h->root.u.def.section != NULL