public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
From: Jiong Wang <jiong.wang@arm.com>
To: gcc-patches <gcc-patches@gcc.gnu.org>
Subject: [AArch64][TLSGD][2/2] Implement TLS GD traditional for tiny code model
Date: Thu, 27 Aug 2015 10:04:00 -0000	[thread overview]
Message-ID: <n9937z53viw.fsf@arm.com> (raw)
In-Reply-To: <n994mjl3vmw.fsf@arm.com>

[-- Attachment #1: Type: text/plain, Size: 955 bytes --]


As described this is the main implementaion patch.

2015-08-26  Jiong Wang  <jiong.wang@arm.com>

gcc/
  * configure.ac: Add check for binutils global dynamic tiny code model
  relocation support.
  * configure: Regenerate.
  * config.in: Regenerate.
  * config/aarch64/aarch64.md (tlsgd_tiny): New define_insn.
  * config/aarch64/aarch64-protos.h (aarch64_symbol_type): New
  enumeration SYMBOL_TINY_TLSGD.
  (aarch64_symbol_context): New comment on SYMBOL_TINY_TLSGD.
  * config/aarch64/aarch64.c (aarch64_classify_tls_symbol): Support
  SYMBOL_TINY_TLSGD.
  (aarch64_print_operand): Likewise.
  (aarch64_expand_mov_immediate): Likewise.
  (aarch64_load_symref_appropriately): Likewise.

gcc/testsuite/
  * lib/target-supports.exp (check_effective_target_aarch64_tlsgdtiny):
  New effective check.
  * gcc.target/aarch64/tlsgd_small_1.c: New testcase.
  * gcc.target/aarch64/tlsgd_tiny_1.c: Likewise.

-- 
Regards,
Jiong


[-- Attachment #2: gdt2.patch --]
[-- Type: text/x-diff, Size: 8517 bytes --]

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_<mode>"
   [(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.
 

  reply	other threads:[~2015-08-27  9:55 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-06-19 14:59 [AArch64][TLSGD Trad][1/2] Generalize TLS Global Dynamic support for all memory mode Jiong Wang
2015-08-27  9:55 ` [AArch64][TLSGD][1/2] Remove unncessary define_expand for TLS GD traditional Jiong Wang
2015-08-27 10:04   ` Jiong Wang [this message]
2015-10-06 13:32     ` [AArch64][TLSGD][2/2] Implement TLS GD traditional for tiny code model Marcus Shawcroft
2015-11-05 14:57       ` Jiong Wang
2015-11-13 15:22         ` Jiong Wang
2015-12-03 10:42           ` [Ping^2][AArch64][TLSGD][2/2] " Jiong Wang
2015-10-06 11:40   ` [AArch64][TLSGD][1/2] Remove unncessary define_expand for TLS GD traditional Marcus Shawcroft

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=n9937z53viw.fsf@arm.com \
    --to=jiong.wang@arm.com \
    --cc=gcc-patches@gcc.gnu.org \
    /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).