Here we were leaving DECL_EXTERNAL set on the TLS init alias, so it wasn't getting emitted properly.

Tested x86_64-pc-linux-gnu, applying to trunk and 4.8.
commit e0343cda07dc6b8139eeb7c3a5f25891d48a6300
Author: Jason Merrill <ja...@redhat.com>
Date:   Fri Jan 31 10:54:49 2014 -0500

    	PR c++/55800
    	* decl2.c (get_tls_init_fn): Copy DECL_EXTERNAL from the variable.

diff --git a/gcc/cp/decl2.c b/gcc/cp/decl2.c
index b2103c8..2216591 100644
--- a/gcc/cp/decl2.c
+++ b/gcc/cp/decl2.c
@@ -2949,7 +2949,7 @@ get_tls_init_fn (tree var)
       TREE_PUBLIC (fn) = TREE_PUBLIC (var);
       DECL_ARTIFICIAL (fn) = true;
       DECL_COMDAT (fn) = DECL_COMDAT (var);
-      DECL_EXTERNAL (fn) = true;
+      DECL_EXTERNAL (fn) = DECL_EXTERNAL (var);
       if (DECL_ONE_ONLY (var))
 	make_decl_one_only (fn, cxx_comdat_group (fn));
       if (TREE_PUBLIC (var))
diff --git a/gcc/testsuite/g++.dg/tls/thread_local8.C b/gcc/testsuite/g++.dg/tls/thread_local8.C
new file mode 100644
index 0000000..206e7b3
--- /dev/null
+++ b/gcc/testsuite/g++.dg/tls/thread_local8.C
@@ -0,0 +1,11 @@
+// PR c++/55800
+// { dg-options "-std=c++11" }
+// { dg-require-alias "" }
+// { dg-final { scan-assembler "_ZTH12foo_instance" { target tls_native } } }
+
+struct foo
+{
+  foo();
+};
+
+thread_local foo foo_instance;

Reply via email to