public inbox for binutils@sourceware.org
 help / color / mirror / Atom feed
* [PATCH] LoongArch: gas: Fix the types of symbols referred with %le_*_r in the symtab
@ 2024-02-02 13:00 Xi Ruoyao
  2024-02-04  6:18 ` mengqinggang
  0 siblings, 1 reply; 2+ messages in thread
From: Xi Ruoyao @ 2024-02-02 13:00 UTC (permalink / raw)
  To: binutils; +Cc: mengqinggang, changjiachen, Nick Clifton, Xi Ruoyao

When a symbol is referred with %le_{hi20,lo12,add}_r, it's definitely a
TLS symbol and we should set its type to TLS in the symtab.  Otherwise
when building Perl with gcc-14 -flto, we get:

/usr/bin/ld: PL_current_context: TLS definition in
./miniperl.ltrans0.ltrans.o section .tbss mismatches non-TLS reference
in ./miniperl.ltrans1.ltrans.o

A minimal reproducer:

    $ cat t1.s
    .section .tbss
    .globl x
    x: .word 0
    $ cat t2.s
    f:
      lu12i.w $a0, %le_hi20_r(x)
      add.d   $a0, $a0, $tp, %le_add_r(x)
      li.w    $a1, 1
      st.w    $a1, $a0, %le_lo12_r(x)
    $ gas/as-new t1.s -o t1.o
    $ gas/as-new t2.s -o t2.o
    $ ld/ld-new t1.o t2.o
    ld/ld-new: x: TLS definition in t1.o section .tbss mismatches
    non-TLS reference in t2.o

Unfortunately this was undetected before Binutils-2.42 release because
GCC < 14 does not use %le_*_r, and without LTO it's very rare to have a
TLS LE definition and its reference in two different translation units.
So this fix should be backported to Binutils-2.42 branch too.

Signed-off-by: Xi Ruoyao <xry111@xry111.site>
---
 gas/config/tc-loongarch.c                       | 3 +++
 gas/testsuite/gas/loongarch/tls_le_r_sym_type.d | 3 +++
 gas/testsuite/gas/loongarch/tls_le_r_sym_type.s | 6 ++++++
 3 files changed, 12 insertions(+)
 create mode 100644 gas/testsuite/gas/loongarch/tls_le_r_sym_type.d
 create mode 100644 gas/testsuite/gas/loongarch/tls_le_r_sym_type.s

diff --git a/gas/config/tc-loongarch.c b/gas/config/tc-loongarch.c
index e0aff36bbbb..91f5f1d0681 100644
--- a/gas/config/tc-loongarch.c
+++ b/gas/config/tc-loongarch.c
@@ -1340,6 +1340,9 @@ md_apply_fix (fixS *fixP, valueT *valP, segT seg ATTRIBUTE_UNUSED)
     case BFD_RELOC_LARCH_TLS_DESC_LO12:
     case BFD_RELOC_LARCH_TLS_DESC64_LO20:
     case BFD_RELOC_LARCH_TLS_DESC64_HI12:
+    case BFD_RELOC_LARCH_TLS_LE_ADD_R:
+    case BFD_RELOC_LARCH_TLS_LE_HI20_R:
+    case BFD_RELOC_LARCH_TLS_LE_LO12_R:
       /* Add tls lo (got_lo reloc type).  */
       if (fixP->fx_addsy == NULL)
 	as_bad_where (fixP->fx_file, fixP->fx_line,
diff --git a/gas/testsuite/gas/loongarch/tls_le_r_sym_type.d b/gas/testsuite/gas/loongarch/tls_le_r_sym_type.d
new file mode 100644
index 00000000000..43bcd789769
--- /dev/null
+++ b/gas/testsuite/gas/loongarch/tls_le_r_sym_type.d
@@ -0,0 +1,3 @@
+#readelf: -s
+#...
+.*TLS[ \t]+GLOBAL[ \t]+DEFAULT[ \t]+UND[ \t]+x
diff --git a/gas/testsuite/gas/loongarch/tls_le_r_sym_type.s b/gas/testsuite/gas/loongarch/tls_le_r_sym_type.s
new file mode 100644
index 00000000000..3ccedae921f
--- /dev/null
+++ b/gas/testsuite/gas/loongarch/tls_le_r_sym_type.s
@@ -0,0 +1,6 @@
+f:
+  lu12i.w	$a0, %le_hi20_r(x)
+  add.d		$a0, $a0, $tp, %le_add_r(x)
+  li.w		$a1, 1
+  st.w		$a1, $a0, %le_lo12_r(x)
+  ret
-- 
2.43.0


^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: [PATCH] LoongArch: gas: Fix the types of symbols referred with %le_*_r in the symtab
  2024-02-02 13:00 [PATCH] LoongArch: gas: Fix the types of symbols referred with %le_*_r in the symtab Xi Ruoyao
@ 2024-02-04  6:18 ` mengqinggang
  0 siblings, 0 replies; 2+ messages in thread
From: mengqinggang @ 2024-02-04  6:18 UTC (permalink / raw)
  To: Xi Ruoyao, binutils; +Cc: changjiachen, Nick Clifton

Thank you very much, it has been applied to master and binutils 2.42 branch.


在 2024/2/2 下午9:00, Xi Ruoyao 写道:
> When a symbol is referred with %le_{hi20,lo12,add}_r, it's definitely a
> TLS symbol and we should set its type to TLS in the symtab.  Otherwise
> when building Perl with gcc-14 -flto, we get:
>
> /usr/bin/ld: PL_current_context: TLS definition in
> ./miniperl.ltrans0.ltrans.o section .tbss mismatches non-TLS reference
> in ./miniperl.ltrans1.ltrans.o
>
> A minimal reproducer:
>
>      $ cat t1.s
>      .section .tbss
>      .globl x
>      x: .word 0
>      $ cat t2.s
>      f:
>        lu12i.w $a0, %le_hi20_r(x)
>        add.d   $a0, $a0, $tp, %le_add_r(x)
>        li.w    $a1, 1
>        st.w    $a1, $a0, %le_lo12_r(x)
>      $ gas/as-new t1.s -o t1.o
>      $ gas/as-new t2.s -o t2.o
>      $ ld/ld-new t1.o t2.o
>      ld/ld-new: x: TLS definition in t1.o section .tbss mismatches
>      non-TLS reference in t2.o
>
> Unfortunately this was undetected before Binutils-2.42 release because
> GCC < 14 does not use %le_*_r, and without LTO it's very rare to have a
> TLS LE definition and its reference in two different translation units.
> So this fix should be backported to Binutils-2.42 branch too.
>
> Signed-off-by: Xi Ruoyao <xry111@xry111.site>
> ---
>   gas/config/tc-loongarch.c                       | 3 +++
>   gas/testsuite/gas/loongarch/tls_le_r_sym_type.d | 3 +++
>   gas/testsuite/gas/loongarch/tls_le_r_sym_type.s | 6 ++++++
>   3 files changed, 12 insertions(+)
>   create mode 100644 gas/testsuite/gas/loongarch/tls_le_r_sym_type.d
>   create mode 100644 gas/testsuite/gas/loongarch/tls_le_r_sym_type.s
>
> diff --git a/gas/config/tc-loongarch.c b/gas/config/tc-loongarch.c
> index e0aff36bbbb..91f5f1d0681 100644
> --- a/gas/config/tc-loongarch.c
> +++ b/gas/config/tc-loongarch.c
> @@ -1340,6 +1340,9 @@ md_apply_fix (fixS *fixP, valueT *valP, segT seg ATTRIBUTE_UNUSED)
>       case BFD_RELOC_LARCH_TLS_DESC_LO12:
>       case BFD_RELOC_LARCH_TLS_DESC64_LO20:
>       case BFD_RELOC_LARCH_TLS_DESC64_HI12:
> +    case BFD_RELOC_LARCH_TLS_LE_ADD_R:
> +    case BFD_RELOC_LARCH_TLS_LE_HI20_R:
> +    case BFD_RELOC_LARCH_TLS_LE_LO12_R:
>         /* Add tls lo (got_lo reloc type).  */
>         if (fixP->fx_addsy == NULL)
>   	as_bad_where (fixP->fx_file, fixP->fx_line,
> diff --git a/gas/testsuite/gas/loongarch/tls_le_r_sym_type.d b/gas/testsuite/gas/loongarch/tls_le_r_sym_type.d
> new file mode 100644
> index 00000000000..43bcd789769
> --- /dev/null
> +++ b/gas/testsuite/gas/loongarch/tls_le_r_sym_type.d
> @@ -0,0 +1,3 @@
> +#readelf: -s
> +#...
> +.*TLS[ \t]+GLOBAL[ \t]+DEFAULT[ \t]+UND[ \t]+x
> diff --git a/gas/testsuite/gas/loongarch/tls_le_r_sym_type.s b/gas/testsuite/gas/loongarch/tls_le_r_sym_type.s
> new file mode 100644
> index 00000000000..3ccedae921f
> --- /dev/null
> +++ b/gas/testsuite/gas/loongarch/tls_le_r_sym_type.s
> @@ -0,0 +1,6 @@
> +f:
> +  lu12i.w	$a0, %le_hi20_r(x)
> +  add.d		$a0, $a0, $tp, %le_add_r(x)
> +  li.w		$a1, 1
> +  st.w		$a1, $a0, %le_lo12_r(x)
> +  ret


^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2024-02-04  6:18 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-02-02 13:00 [PATCH] LoongArch: gas: Fix the types of symbols referred with %le_*_r in the symtab Xi Ruoyao
2024-02-04  6:18 ` mengqinggang

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).