From: Lulu Cheng <chenglulu@loongson.cn>
To: gcc-patches@gcc.gnu.org
Cc: xry111@xry111.site, i@xen0n.name, xuchenghua@loongson.cn,
Lulu Cheng <chenglulu@loongson.cn>
Subject: [PATCH] LoongArch: Get __tls_get_addr address through got table when disable plt.
Date: Thu, 11 Aug 2022 19:35:28 +0800 [thread overview]
Message-ID: <20220811113527.286471-1-chenglulu@loongson.cn> (raw)
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
next reply other threads:[~2022-08-11 11:42 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-08-11 11:35 Lulu Cheng [this message]
2022-08-18 2:11 ` [commited PATCH] " Lulu Cheng
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20220811113527.286471-1-chenglulu@loongson.cn \
--to=chenglulu@loongson.cn \
--cc=gcc-patches@gcc.gnu.org \
--cc=i@xen0n.name \
--cc=xry111@xry111.site \
--cc=xuchenghua@loongson.cn \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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).