Skip to content

Commit 3932899

Browse files
committed
LoongArch: Added support for loading __get_tls_addr symbol address using call36.
gcc/ChangeLog: * config/loongarch/loongarch.cc (loongarch_call_tls_get_addr): Add support for call36. gcc/testsuite/ChangeLog: * gcc.target/loongarch/explicit-relocs-medium-call36-auto-tls-ld-gd.c: New test.
1 parent 5fbd802 commit 3932899

File tree

2 files changed

+21
-6
lines changed

2 files changed

+21
-6
lines changed

gcc/config/loongarch/loongarch.cc

+16-6
Original file line numberDiff line numberDiff line change
@@ -2807,17 +2807,27 @@ loongarch_call_tls_get_addr (rtx sym, enum loongarch_symbol_type type, rtx v0)
28072807

28082808
case CMODEL_MEDIUM:
28092809
{
2810-
rtx reg = gen_reg_rtx (Pmode);
28112810
if (la_opt_explicit_relocs != EXPLICIT_RELOCS_NONE)
28122811
{
2813-
emit_insn (gen_pcalau12i (Pmode, reg, loongarch_tls_symbol));
2814-
rtx call = gen_call_value_internal_1 (Pmode, v0, reg,
2815-
loongarch_tls_symbol,
2816-
const0_rtx);
2817-
insn = emit_call_insn (call);
2812+
rtx call;
2813+
2814+
if (HAVE_AS_SUPPORT_CALL36)
2815+
call = gen_call_value_internal (v0, loongarch_tls_symbol,
2816+
const0_rtx);
2817+
else
2818+
{
2819+
rtx reg = gen_reg_rtx (Pmode);
2820+
emit_insn (gen_pcalau12i (Pmode, reg,
2821+
loongarch_tls_symbol));
2822+
call = gen_call_value_internal_1 (Pmode, v0, reg,
2823+
loongarch_tls_symbol,
2824+
const0_rtx);
2825+
}
2826+
insn = emit_call_insn (call);
28182827
}
28192828
else
28202829
{
2830+
rtx reg = gen_reg_rtx (Pmode);
28212831
emit_move_insn (reg, loongarch_tls_symbol);
28222832
insn = emit_call_insn (gen_call_value_internal (v0,
28232833
reg,
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
/* { dg-do compile } */
2+
/* { dg-options "-O2 -fPIC -mexplicit-relocs=auto -mcmodel=medium -fplt" } */
3+
/* { dg-final { scan-assembler "pcaddu18i\t\\\$r1,%call36\\\(__tls_get_addr\\\)" { target { tls_native && loongarch_call36_support } } } } */
4+
5+
#include "./explicit-relocs-auto-tls-ld-gd.c"

0 commit comments

Comments
 (0)