diff options
author | Lulu Cheng <chenglulu@loongson.cn> | 2022-08-18 09:57:14 +0800 |
---|---|---|
committer | Lulu Cheng <chenglulu@loongson.cn> | 2022-08-18 10:02:00 +0800 |
commit | b7d62c551f34bbb6b519160b98d73e1bc5484719 (patch) | |
tree | 285565180668ed37ee8243c21d6ff01efb8c95f0 | |
parent | dca74793cd42ce4c5319943a516cc5ea7265b6f7 (diff) | |
download | gcc-b7d62c551f34bbb6b519160b98d73e1bc5484719.zip gcc-b7d62c551f34bbb6b519160b98d73e1bc5484719.tar.gz gcc-b7d62c551f34bbb6b519160b98d73e1bc5484719.tar.bz2 |
LoongArch: Get __tls_get_addr address through got table when disable plt.
Fix bug, ICE with tls gd/ld 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.
-rw-r--r-- | gcc/config/loongarch/loongarch.cc | 14 | ||||
-rw-r--r-- | gcc/testsuite/gcc.target/loongarch/tls-gd-noplt.c | 12 |
2 files changed, 24 insertions, 2 deletions
diff --git a/gcc/config/loongarch/loongarch.cc b/gcc/config/loongarch/loongarch.cc index 7968734..2437814 100644 --- a/gcc/config/loongarch/loongarch.cc +++ b/gcc/config/loongarch/loongarch.cc @@ -2448,8 +2448,18 @@ loongarch_call_tls_get_addr (rtx sym, enum loongarch_symbol_type type, rtx v0) 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 0000000..32a0acf --- /dev/null +++ b/gcc/testsuite/gcc.target/loongarch/tls-gd-noplt.c @@ -0,0 +1,12 @@ +/* { dg-do compile } */ +/* { dg-options "-O2 -fno-plt -mcmodel=normal" } */ +/* { 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; +} + |