Merge "[tls] Enable alignment checks and add dso test"
diff --git a/third_party/nacl-ported-tests/tls/BUILD.gn b/third_party/nacl-ported-tests/tls/BUILD.gn
index 826a200..d7b2214 100644
--- a/third_party/nacl-ported-tests/tls/BUILD.gn
+++ b/third_party/nacl-ported-tests/tls/BUILD.gn
@@ -41,6 +41,10 @@
     "TDATA_LARGE_ALIGN",
     "TBSS_LARGE_ALIGN",
   ],
+  [
+    "ExternLargeAlign",
+    "EXTERN_LARGE_ALIGN"
+  ]
 ]
 
 source_set("small_tests") {
@@ -53,6 +57,12 @@
   }
 }
 
+shared_library("page_align_tls_dso") {
+  sources = [
+    "dso.cc",
+  ]
+}
+
 foreach(casename_defines, defines_list) {
   case_name = casename_defines[0]
   casename_defines -= [ case_name ]
@@ -69,6 +79,9 @@
     deps = [
       "//third_party/gtest",
     ]
+    if (case_name == "ExternLargeAlign") {
+      deps += [ ":page_align_tls_dso" ]
+    }
     foreach(defines, casename_defines) {
       cflags_cc += [ "-D" + defines ]
     }
diff --git a/third_party/nacl-ported-tests/tls/dso.cc b/third_party/nacl-ported-tests/tls/dso.cc
new file mode 100644
index 0000000..cce3817
--- /dev/null
+++ b/third_party/nacl-ported-tests/tls/dso.cc
@@ -0,0 +1,7 @@
+// Copyright 2016 The Fuchsia Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "dso.h"
+
+alignas(0x2000) thread_local int extern_large_align_var = magic_constant;
diff --git a/third_party/nacl-ported-tests/tls/dso.h b/third_party/nacl-ported-tests/tls/dso.h
new file mode 100644
index 0000000..0869e23
--- /dev/null
+++ b/third_party/nacl-ported-tests/tls/dso.h
@@ -0,0 +1,3 @@
+constexpr int magic_constant = 12345;
+
+extern __attribute__((visibility("default"))) thread_local int extern_large_align_var;
diff --git a/third_party/nacl-ported-tests/tls/tls.cc b/third_party/nacl-ported-tests/tls/tls.cc
index 93af717..fc1fe3b 100644
--- a/third_party/nacl-ported-tests/tls/tls.cc
+++ b/third_party/nacl-ported-tests/tls/tls.cc
@@ -11,9 +11,6 @@
 #include <stdio.h>
 #include "gtest/gtest.h"
 
-// TODO(ZX-1646): Make this work on ARM64.
-#if !defined(__aarch64__)
-
 namespace {
 
 class TEST_NAME : public ::testing::Test {
@@ -60,6 +57,10 @@
 # endif
 #endif
 
+#ifdef EXTERN_LARGE_ALIGN
+#include "dso.h"
+#endif
+
 #ifdef WITH_PTHREAD
 static void *thread_proc(void *arg) {
   return arg;
@@ -102,6 +103,12 @@
   AlignCheck(&tbss3, 0x1000);
 # endif
 #endif
+
+#if EXTERN_LARGE_ALIGN
+  AlignCheck(&extern_large_align_var, 0x2000);
+  ASSERT_EQ(extern_large_align_var, magic_constant);
+#endif
+
 #ifdef WITH_PTHREAD
   /* This is dead code but it makes linker use pthread library */
   if (dummy == -1) {
@@ -109,5 +116,3 @@
   }
 #endif
 }
-
-#endif