Skip to content

Commit

Permalink
LoongArch: Get __tls_get_addr address through got table when disable …
Browse files Browse the repository at this point in the history
…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.
  • Loading branch information
chenglulu326 committed Aug 18, 2022
1 parent dca7479 commit b7d62c5
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 2 deletions.
14 changes: 12 additions & 2 deletions gcc/config/loongarch/loongarch.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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 ();
Expand Down
12 changes: 12 additions & 0 deletions gcc/testsuite/gcc.target/loongarch/tls-gd-noplt.c
Original file line number Diff line number Diff line change
@@ -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;
}

0 comments on commit b7d62c5

Please sign in to comment.