diff --git a/gcc/config.in b/gcc/config.in index 22a4e6b..9313e36 100644 --- a/gcc/config.in +++ b/gcc/config.in @@ -618,6 +618,13 @@ #endif +/* Define if your assembler supports relocs needed by global dynamic for tiny + code model. */ +#ifndef USED_FOR_TARGET +#undef HAVE_AS_TINY_TLSGD_RELOCS +#endif + + /* Define if your assembler and linker support thread-local storage. */ #ifndef USED_FOR_TARGET #undef HAVE_AS_TLS diff --git a/gcc/config/aarch64/aarch64-protos.h b/gcc/config/aarch64/aarch64-protos.h index 8fbc204..bdcb9a0 100644 --- a/gcc/config/aarch64/aarch64-protos.h +++ b/gcc/config/aarch64/aarch64-protos.h @@ -74,6 +74,7 @@ enum aarch64_symbol_context SYMBOL_SMALL_TLSGD SYMBOL_SMALL_TLSDESC SYMBOL_SMALL_GOTTPREL + SYMBOL_TINY_TLSGD SYMBOL_TINY_TLSIE SYMBOL_TLSLE12 SYMBOL_TLSLE24 @@ -115,6 +116,7 @@ enum aarch64_symbol_type SYMBOL_SMALL_GOTTPREL, SYMBOL_TINY_ABSOLUTE, SYMBOL_TINY_GOT, + SYMBOL_TINY_TLSGD, SYMBOL_TINY_TLSIE, SYMBOL_TLSLE12, SYMBOL_TLSLE24, diff --git a/gcc/config/aarch64/aarch64.c b/gcc/config/aarch64/aarch64.c index 988062c..610f3db 100644 --- a/gcc/config/aarch64/aarch64.c +++ b/gcc/config/aarch64/aarch64.c @@ -1024,6 +1024,7 @@ aarch64_load_symref_appropriately (rtx dest, rtx imm, return; } + case SYMBOL_TINY_TLSGD: case SYMBOL_SMALL_TLSGD: { rtx_insn *insns; @@ -1031,7 +1032,10 @@ aarch64_load_symref_appropriately (rtx dest, rtx imm, rtx resolver = aarch64_tls_get_addr (); start_sequence (); - aarch64_emit_call_insn (gen_tlsgd_small (result, imm, resolver)); + if (type == SYMBOL_SMALL_TLSGD) + aarch64_emit_call_insn (gen_tlsgd_small (result, imm, resolver)); + else + aarch64_emit_call_insn (gen_tlsgd_tiny (result, imm, resolver)); insns = get_insns (); end_sequence (); @@ -1719,6 +1723,7 @@ aarch64_expand_mov_immediate (rtx dest, rtx imm) case SYMBOL_SMALL_GOT_28K: case SYMBOL_SMALL_GOT_4G: case SYMBOL_TINY_GOT: + case SYMBOL_TINY_TLSGD: case SYMBOL_TINY_TLSIE: if (offset != const0_rtx) { @@ -4594,6 +4599,7 @@ aarch64_print_operand (FILE *f, rtx x, char code) break; case SYMBOL_SMALL_TLSGD: + case SYMBOL_TINY_TLSGD: asm_fprintf (asm_out_file, ":tlsgd:"); break; @@ -8755,6 +8761,22 @@ aarch64_classify_tls_symbol (rtx x) switch (tls_kind) { case TLS_MODEL_GLOBAL_DYNAMIC: + if (TARGET_TLS_DESC) + return SYMBOL_SMALL_TLSDESC; + + /* Traditional model. */ + switch (aarch64_cmodel) + { + case AARCH64_CMODEL_TINY: + case AARCH64_CMODEL_TINY_PIC: +#ifdef HAVE_AS_TINY_TLSGD_RELOCS + return SYMBOL_TINY_TLSGD; +#else + return SYMBOL_SMALL_TLSGD; +#endif + default: + return SYMBOL_SMALL_TLSGD; + } case TLS_MODEL_LOCAL_DYNAMIC: return TARGET_TLS_DESC ? SYMBOL_SMALL_TLSDESC : SYMBOL_SMALL_TLSGD; diff --git a/gcc/config/aarch64/aarch64.md b/gcc/config/aarch64/aarch64.md index cf787d8..e722590 100644 --- a/gcc/config/aarch64/aarch64.md +++ b/gcc/config/aarch64/aarch64.md @@ -4485,6 +4485,17 @@ [(set_attr "type" "call") (set_attr "length" "16")]) +(define_insn "tlsgd_tiny" + [(set (match_operand 0 "register_operand" "") + (call (mem:DI (match_operand:DI 2 "" "")) (const_int 1))) + (unspec:DI [(match_operand:DI 1 "aarch64_valid_symref" "S")] UNSPEC_GOTTINYTLS) + (clobber (reg:DI LR_REGNUM)) + ] + "" + "adr\tx0, %A1;bl\t%2;nop"; + [(set_attr "type" "multiple") + (set_attr "length" "12")]) + (define_insn "tlsie_small_" [(set (match_operand:PTR 0 "register_operand" "=r") (unspec:PTR [(match_operand 1 "aarch64_tls_ie_symref" "S")] diff --git a/gcc/configure b/gcc/configure index cf685f2..82fb331 100755 --- a/gcc/configure +++ b/gcc/configure @@ -24308,6 +24308,41 @@ if test $gcc_cv_as_aarch64_picreloc = yes; then $as_echo "#define HAVE_AS_SMALL_PIC_RELOCS 1" >>confdefs.h fi + # Check if we have binutils support for relocations types needed by TLSGD + # for tiny code model. + { $as_echo "$as_me:${as_lineno-$LINENO}: checking assembler for global dynamic for tiny relocs" >&5 +$as_echo_n "checking assembler for global dynamic for tiny relocs... " >&6; } +if test "${gcc_cv_as_aarch64_gdtinyreloc+set}" = set; then : + $as_echo_n "(cached) " >&6 +else + gcc_cv_as_aarch64_gdtinyreloc=no + if test x$gcc_cv_as != x; then + $as_echo ' + .text + adr x0, :tlsgd:globalsym + ' > conftest.s + if { ac_try='$gcc_cv_as $gcc_cv_as_flags -o conftest.o conftest.s >&5' + { { eval echo "\"\$as_me\":${as_lineno-$LINENO}: \"$ac_try\""; } >&5 + (eval $ac_try) 2>&5 + ac_status=$? + $as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5 + test $ac_status = 0; }; } + then + gcc_cv_as_aarch64_gdtinyreloc=yes + else + echo "configure: failed program was" >&5 + cat conftest.s >&5 + fi + rm -f conftest.o conftest.s + fi +fi +{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $gcc_cv_as_aarch64_gdtinyreloc" >&5 +$as_echo "$gcc_cv_as_aarch64_gdtinyreloc" >&6; } +if test $gcc_cv_as_aarch64_gdtinyreloc = yes; then + +$as_echo "#define HAVE_AS_TINY_TLSGD_RELOCS 1" >>confdefs.h + +fi # Enable default workaround for AArch64 Cortex-A53 erratum 835769. # Check whether --enable-fix-cortex-a53-835769 was given. if test "${enable_fix_cortex_a53_835769+set}" = set; then : diff --git a/gcc/configure.ac b/gcc/configure.ac index 846651d..675b249 100644 --- a/gcc/configure.ac +++ b/gcc/configure.ac @@ -3601,6 +3601,14 @@ case "$target" in ldr x0, [[x2, #:gotpage_lo15:globalsym]] ],,[AC_DEFINE(HAVE_AS_SMALL_PIC_RELOCS, 1, [Define if your assembler supports relocs needed by -fpic.])]) + # Check if we have binutils support for relocations types needed by TLSGD + # for tiny code model. + gcc_GAS_CHECK_FEATURE([global dynamic for tiny relocs], gcc_cv_as_aarch64_gdtinyreloc,,, + [ + .text + adr x0, :tlsgd:globalsym + ],,[AC_DEFINE(HAVE_AS_TINY_TLSGD_RELOCS, 1, + [Define if your assembler supports relocs needed by global dynamic for tiny code model.])]) # Enable default workaround for AArch64 Cortex-A53 erratum 835769. AC_ARG_ENABLE(fix-cortex-a53-835769, [ diff --git a/gcc/testsuite/gcc.target/aarch64/tlsgd_small_1.c b/gcc/testsuite/gcc.target/aarch64/tlsgd_small_1.c new file mode 100644 index 0000000..a808440 --- /dev/null +++ b/gcc/testsuite/gcc.target/aarch64/tlsgd_small_1.c @@ -0,0 +1,9 @@ +/* { dg-do run } */ +/* { dg-require-effective-target tls_native } */ +/* { dg-options "-O2 -ftls-model=global-dynamic -fpic -mtls-dialect=trad --save-temps" } */ + +#include "tls_1.x" + +/* { dg-final { scan-assembler-times "adrp\tx\[0-9\]+, :tlsgd:" 2 } } */ +/* { dg-final { scan-assembler-times "bl\t__tls_get_addr" 2 } } */ +/* { dg-final { cleanup-saved-temps } } */ diff --git a/gcc/testsuite/gcc.target/aarch64/tlsgd_tiny_1.c b/gcc/testsuite/gcc.target/aarch64/tlsgd_tiny_1.c new file mode 100644 index 0000000..b4170c2 --- /dev/null +++ b/gcc/testsuite/gcc.target/aarch64/tlsgd_tiny_1.c @@ -0,0 +1,10 @@ +/* { dg-do run } */ +/* { dg-require-effective-target tls_native } */ +/* { dg-require-effective-target aarch64_tlsgdtiny } */ +/* { dg-options "-O2 -ftls-model=global-dynamic -fpic -mtls-dialect=trad -mcmodel=tiny --save-temps" } */ + +#include "tls_1.x" + +/* { dg-final { scan-assembler-times "adr\tx\[0-9\]+, :tlsgd:" 2 } } */ +/* { dg-final { scan-assembler-times "bl\t__tls_get_addr" 2 } } */ +/* { dg-final { cleanup-saved-temps } } */ diff --git a/gcc/testsuite/lib/target-supports.exp b/gcc/testsuite/lib/target-supports.exp index 728d020..76951a0 100644 --- a/gcc/testsuite/lib/target-supports.exp +++ b/gcc/testsuite/lib/target-supports.exp @@ -994,6 +994,19 @@ proc check_effective_target_aarch64_tlsle32 { } { } } +# On AArch64, instruction sequence for TLS GD on tiny code model will utilize +# the relocation modifier ":tlsgd:" together with ADR, it's only supported +# in binutils higher than 2.25. + +proc check_effective_target_aarch64_tlsgdtiny { } { + if { [istarget aarch64*-*-*] } { + return [check_no_compiler_messages aarch64_tlsgdtiny object { + void foo (void) { asm ("adr x1,:tlsgd:t1"); } + }] + } else { + return 0 + } +} # Return 1 if -shared is supported, as in no warnings or errors # emitted, 0 otherwise.