public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [PATCH] LoongArch: Get __tls_get_addr address through got table when disable plt.
@ 2022-08-11 11:35 Lulu Cheng
  2022-08-18  2:11 ` [commited PATCH] " Lulu Cheng
  0 siblings, 1 reply; 2+ messages in thread
From: Lulu Cheng @ 2022-08-11 11:35 UTC (permalink / raw)
  To: gcc-patches; +Cc: xry111, i, xuchenghua, Lulu Cheng

thread.c:

__attribute__ ((tls_model ("global-dynamic"))) __thread int a;

void
test (void)
{
  a = 10;
}

Compile the tests with -fno-plt, error message is as follows:

thread.c: In function 'test':
thread.c:7:1: error: unrecognizable insn:
    7 | }
      | ^
(call_insn/u 7 6 8 2 (parallel [
            (set (reg:DI 4 $r4)
                (call (mem:SI (symbol_ref:DI ("__tls_get_addr") [flags 0x41] <function_decl 0x7f30ce305400 __tls_get_addr>) [0  S4 A8])
                    (const_int 0 [0])))
            (clobber (reg:SI 1 $r1))
        ]) "thread.c":5:5 -1
     (expr_list:REG_EH_REGION (const_int -2147483648 [0xffffffff80000000])
        (nil))
    (expr_list (use (reg:DI 4 $r4))
        (nil)))
during RTL pass: vregs
thread.c:7:1: internal compiler error: in extract_insn, at recog.cc:2791


-------------------------

Fix bug, ICE with tls gd var with -fno-plt.

gcc/ChangeLog:

	* config/loongarch/loongarch.cc (loongarch_call_tls_get_addr):
	Get __tls_get_addr address through got table when disable plt.

gcc/testsuite/ChangeLog:

	* gcc.target/loongarch/tls-gd-noplt.c: New test.
---
 gcc/config/loongarch/loongarch.cc                 | 14 ++++++++++++--
 gcc/testsuite/gcc.target/loongarch/tls-gd-noplt.c | 12 ++++++++++++
 2 files changed, 24 insertions(+), 2 deletions(-)
 create mode 100644 gcc/testsuite/gcc.target/loongarch/tls-gd-noplt.c

diff --git a/gcc/config/loongarch/loongarch.cc b/gcc/config/loongarch/loongarch.cc
index 5c9a33c14f7..8d8232e5805 100644
--- a/gcc/config/loongarch/loongarch.cc
+++ b/gcc/config/loongarch/loongarch.cc
@@ -2297,8 +2297,18 @@ loongarch_call_tls_get_addr (rtx sym, enum loongarch_symbol_type type, rtx v0)
   else
     gcc_unreachable ();
 
-  insn = emit_call_insn (gen_call_value_internal (v0, loongarch_tls_symbol,
-						  const0_rtx));
+  if (flag_plt)
+    insn = emit_call_insn (gen_call_value_internal (v0, loongarch_tls_symbol,
+						    const0_rtx));
+  else
+    {
+      rtx dest = gen_reg_rtx (Pmode);
+      rtx high = gen_reg_rtx (Pmode);
+      loongarch_emit_move (high, gen_rtx_HIGH (Pmode, loongarch_tls_symbol));
+      emit_insn (gen_ld_from_got (Pmode, dest, high, loongarch_tls_symbol));
+      insn = emit_call_insn (gen_call_value_internal (v0, dest, const0_rtx));
+    }
+
   RTL_CONST_CALL_P (insn) = 1;
   use_reg (&CALL_INSN_FUNCTION_USAGE (insn), a0);
   insn = get_insns ();
diff --git a/gcc/testsuite/gcc.target/loongarch/tls-gd-noplt.c b/gcc/testsuite/gcc.target/loongarch/tls-gd-noplt.c
new file mode 100644
index 00000000000..a71bb48676d
--- /dev/null
+++ b/gcc/testsuite/gcc.target/loongarch/tls-gd-noplt.c
@@ -0,0 +1,12 @@
+/* { dg-do compile } */
+/* { dg-options "-O2 -fno-plt" } */
+/* { dg-final { scan-assembler "pcalau12i\t.*%got_pc_hi20\\(__tls_get_addr\\)" } } */
+
+__attribute__ ((tls_model ("global-dynamic"))) __thread int a;
+
+void
+test (void)
+{
+  a = 10;
+}
+
-- 
2.31.1


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

* Re: [commited PATCH] LoongArch: Get __tls_get_addr address through got table when disable plt.
  2022-08-11 11:35 [PATCH] LoongArch: Get __tls_get_addr address through got table when disable plt Lulu Cheng
@ 2022-08-18  2:11 ` Lulu Cheng
  0 siblings, 0 replies; 2+ messages in thread
From: Lulu Cheng @ 2022-08-18  2:11 UTC (permalink / raw)
  To: gcc-patches; +Cc: xry111, i, xuchenghua

2022/8/11 下午7:35, Lulu Cheng 写道:
> thread.c:
>
> __attribute__ ((tls_model ("global-dynamic"))) __thread int a;
>
> void
> test (void)
> {
>    a = 10;
> }
>
> Compile the tests with -fno-plt, error message is as follows:
>
> thread.c: In function 'test':
> thread.c:7:1: error: unrecognizable insn:
>      7 | }
>        | ^
> (call_insn/u 7 6 8 2 (parallel [
>              (set (reg:DI 4 $r4)
>                  (call (mem:SI (symbol_ref:DI ("__tls_get_addr") [flags 0x41] <function_decl 0x7f30ce305400 __tls_get_addr>) [0  S4 A8])
>                      (const_int 0 [0])))
>              (clobber (reg:SI 1 $r1))
>          ]) "thread.c":5:5 -1
>       (expr_list:REG_EH_REGION (const_int -2147483648 [0xffffffff80000000])
>          (nil))
>      (expr_list (use (reg:DI 4 $r4))
>          (nil)))
> during RTL pass: vregs
> thread.c:7:1: internal compiler error: in extract_insn, at recog.cc:2791
>
>
> -------------------------
>
> Fix bug, ICE with tls gd var with -fno-plt.
>
> gcc/ChangeLog:
>
> 	* config/loongarch/loongarch.cc (loongarch_call_tls_get_addr):
> 	Get __tls_get_addr address through got table when disable plt.
>
> gcc/testsuite/ChangeLog:
>
> 	* gcc.target/loongarch/tls-gd-noplt.c: New test.
> ---
>   gcc/config/loongarch/loongarch.cc                 | 14 ++++++++++++--
>   gcc/testsuite/gcc.target/loongarch/tls-gd-noplt.c | 12 ++++++++++++
>   2 files changed, 24 insertions(+), 2 deletions(-)
>   create mode 100644 gcc/testsuite/gcc.target/loongarch/tls-gd-noplt.c
>
> diff --git a/gcc/config/loongarch/loongarch.cc b/gcc/config/loongarch/loongarch.cc
> index 5c9a33c14f7..8d8232e5805 100644
> --- a/gcc/config/loongarch/loongarch.cc
> +++ b/gcc/config/loongarch/loongarch.cc
> @@ -2297,8 +2297,18 @@ loongarch_call_tls_get_addr (rtx sym, enum loongarch_symbol_type type, rtx v0)
>     else
>       gcc_unreachable ();
>   
> -  insn = emit_call_insn (gen_call_value_internal (v0, loongarch_tls_symbol,
> -						  const0_rtx));
> +  if (flag_plt)
> +    insn = emit_call_insn (gen_call_value_internal (v0, loongarch_tls_symbol,
> +						    const0_rtx));
> +  else
> +    {
> +      rtx dest = gen_reg_rtx (Pmode);
> +      rtx high = gen_reg_rtx (Pmode);
> +      loongarch_emit_move (high, gen_rtx_HIGH (Pmode, loongarch_tls_symbol));
> +      emit_insn (gen_ld_from_got (Pmode, dest, high, loongarch_tls_symbol));
> +      insn = emit_call_insn (gen_call_value_internal (v0, dest, const0_rtx));
> +    }
> +
>     RTL_CONST_CALL_P (insn) = 1;
>     use_reg (&CALL_INSN_FUNCTION_USAGE (insn), a0);
>     insn = get_insns ();
> diff --git a/gcc/testsuite/gcc.target/loongarch/tls-gd-noplt.c b/gcc/testsuite/gcc.target/loongarch/tls-gd-noplt.c
> new file mode 100644
> index 00000000000..a71bb48676d
> --- /dev/null
> +++ b/gcc/testsuite/gcc.target/loongarch/tls-gd-noplt.c
> @@ -0,0 +1,12 @@
> +/* { dg-do compile } */
> +/* { dg-options "-O2 -fno-plt" } */
> +/* { dg-final { scan-assembler "pcalau12i\t.*%got_pc_hi20\\(__tls_get_addr\\)" } } */
> +
> +__attribute__ ((tls_model ("global-dynamic"))) __thread int a;
> +
> +void
> +test (void)
> +{
> +  a = 10;
> +}
> +


Pushed r13-2104.



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

end of thread, other threads:[~2022-08-18  2:11 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-08-11 11:35 [PATCH] LoongArch: Get __tls_get_addr address through got table when disable plt Lulu Cheng
2022-08-18  2:11 ` [commited PATCH] " Lulu Cheng

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).