From 1104df157fa02eab8d0688f2870183e787b98b7e Mon Sep 17 00:00:00 2001
From: "H.J. Lu" <hjl.tools@gmail.com>
Date: Tue, 4 Jul 2017 15:56:57 -0700
Subject: [PATCH] x86-64: Treat ___tls_get_addr like __tls_get_addr

On x86-64, __tls_get_addr realigns stack so that binaries compiled by
GCCs older than GCC 4.9.4:

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=58066

continue to work even if vector instructions are used by functions called
from __tls_get_addr, which assumes 16-byte stack alignment as specified
by x86-64 psABI.

An alternative interface, ___tls_get_addr, is added, which doesn't
realign stack.  GCC 4.9.4 and newer can generate call to ___tls_get_addr,
instead of __tls_get_addr and Linker treats ___tls_get_addr just like
__tls_get_addr.  The weakref assembly directive is extended to redirect
__tls_get_addr to ___tls_get_addr to work with GCC which doesn't support
__tls_get_addr.

bfd/

	* elf64-x86-64.c (elf_x86_64_check_tls_transition): Also check
	___tls_get_addr.

gas/

	* config/tc-i386.c (x86_64_elf_frob_symbol): New function.
	* config/tc-i386.h (obj_frob_symbol): New.
	(x86_64_elf_frob_symbol): Likewise.
	* testsuite/gas/i386/i386.exp: Run x86-64-tls-1a, x86-64-tls-1b,
	x86-64-tls-2a and x86-64-tls-2b.
	* testsuite/gas/i386/ilp32/x86-64-tls-1.s: New file.
	* testsuite/gas/i386/ilp32/x86-64-tls-1a.d: Likewise.
	* testsuite/gas/i386/ilp32/x86-64-tls-1b.d: Likewise.
	* testsuite/gas/i386/ilp32/x86-64-tls-2.s: Likewise.
	* testsuite/gas/i386/ilp32/x86-64-tls-2a.d: Likewise.
	* testsuite/gas/i386/ilp32/x86-64-tls-2b.d: Likewise.
	* testsuite/gas/i386/x86-64-tls-1.s: Likewise.
	* testsuite/gas/i386/x86-64-tls-1a.d: Likewise.
	* testsuite/gas/i386/x86-64-tls-1b.d: Likewise.
	* testsuite/gas/i386/x86-64-tls-2.s: Likewise.
	* testsuite/gas/i386/x86-64-tls-2a.d: Likewise.
	* testsuite/gas/i386/x86-64-tls-2b.d: Likewise.

ld/

	* testsuite/ld-x86-64/tlsbin2aligned-nacl.rd: New file.
	* testsuite/ld-x86-64/tlsbin2aligned.rd: Likewise.
	* testsuite/ld-x86-64/tlsbinaligned-nacl.rd: Likewise.
	* testsuite/ld-x86-64/tlsbinaligned.rd: Likewise.
	* testsuite/ld-x86-64/tlsbinpic2aligned.s: Likewise.
	* testsuite/ld-x86-64/tlsbinpicaligned.s: Likewise.
	* testsuite/ld-x86-64/tlsgd10aligned.s: Likewise.
	* testsuite/ld-x86-64/tlsgd11aligned.s: Likewise.
	* testsuite/ld-x86-64/tlsgd12aligned.d: Likewise.
	* testsuite/ld-x86-64/tlsgd12aligned.s: Likewise.
	* testsuite/ld-x86-64/tlsgd13aligned.d: Likewise.
	* testsuite/ld-x86-64/tlsgd13aligned.s: Likewise.
	* testsuite/ld-x86-64/tlsgd14aligned.s: Likewise.
	* testsuite/ld-x86-64/tlsgd1aligned.s: Likewise.
	* testsuite/ld-x86-64/tlsgd2aligned.d: Likewise.
	* testsuite/ld-x86-64/tlsgd2aligned.s: Likewise.
	* testsuite/ld-x86-64/tlsgd3aligned.d: Likewise.
	* testsuite/ld-x86-64/tlsgd3aligned.s: Likewise.
	* testsuite/ld-x86-64/tlsgd4aligned.s: Likewise.
	* testsuite/ld-x86-64/tlsgd5aaligned.s: Likewise.
	* testsuite/ld-x86-64/tlsgd5caligned.s: Likewise.
	* testsuite/ld-x86-64/tlsgd6aaligned.s: Likewise.
	* testsuite/ld-x86-64/tlsgd6caligned.s: Likewise.
	* testsuite/ld-x86-64/tlsgd7aligned.s: Likewise.
	* testsuite/ld-x86-64/tlsgd8aligned.s: Likewise.
	* testsuite/ld-x86-64/tlsgd9aligned.s: Likewise.
	* testsuite/ld-x86-64/tlsgdescaligned-nacl.rd: Likewise.
	* testsuite/ld-x86-64/tlsgdescaligned.dd: Likewise.
	* testsuite/ld-x86-64/tlsgdescaligned.rd: Likewise.
	* testsuite/ld-x86-64/tlsgdescaligned.s: Likewise.
	* testsuite/ld-x86-64/tlsld1aligned.s: Likewise.
	* testsuite/ld-x86-64/tlsld2aligned.s: Likewise.
	* testsuite/ld-x86-64/tlsld3aligned.s: Likewise.
	* testsuite/ld-x86-64/tlsld4aligned.s: Likewise.
	* testsuite/ld-x86-64/tlsld5aligned.s: Likewise.
	* testsuite/ld-x86-64/tlsld6aligned.s: Likewise.
	* testsuite/ld-x86-64/tlslibaligned.s: Likewise.
	* testsuite/ld-x86-64/tlspic1aligned.s: Likewise.
	* testsuite/ld-x86-64/tlspic2aligned-nacl.rd: Likewise.
	* testsuite/ld-x86-64/tlspic2aligned.rd: Likewise.
	* testsuite/ld-x86-64/tlspic2aligned.sd: Likewise.
	* testsuite/ld-x86-64/tlspic3aligned.s: Likewise.
	* testsuite/ld-x86-64/tlspicaligned-nacl.rd: Likewise.
	* testsuite/ld-x86-64/tlspicaligned.rd: Likewise.
	* testsuite/ld-x86-64/tlspie1aligned.d: Likewise.
	* testsuite/ld-x86-64/tlspie1aligned.s: Likewise.
	* testsuite/ld-x86-64/tlspie2aaligned.d: Likewise.
	* testsuite/ld-x86-64/tlspie2aligned.s: Likewise.
	* testsuite/ld-x86-64/tlspie2baligned.d: Likewise.
	* testsuite/ld-x86-64/tlspie2caligned.d: Likewise.
	* testsuite/ld-x86-64/x86-64.exp: Run ___tls_get_addr tests.
---
 bfd/elf64-x86-64.c                             |   4 +-
 gas/config/tc-i386.c                           |  16 +++
 gas/config/tc-i386.h                           |   6 +
 gas/testsuite/gas/i386/i386.exp                |   5 +
 gas/testsuite/gas/i386/ilp32/x86-64-tls-1.s    |   8 ++
 gas/testsuite/gas/i386/ilp32/x86-64-tls-1a.d   |   5 +
 gas/testsuite/gas/i386/ilp32/x86-64-tls-1b.d   |  12 ++
 gas/testsuite/gas/i386/ilp32/x86-64-tls-2.s    |   9 ++
 gas/testsuite/gas/i386/ilp32/x86-64-tls-2a.d   |   4 +
 gas/testsuite/gas/i386/ilp32/x86-64-tls-2b.d   |  12 ++
 gas/testsuite/gas/i386/x86-64-tls-1.s          |   8 ++
 gas/testsuite/gas/i386/x86-64-tls-1a.d         |   5 +
 gas/testsuite/gas/i386/x86-64-tls-1b.d         |  12 ++
 gas/testsuite/gas/i386/x86-64-tls-2.s          |   9 ++
 gas/testsuite/gas/i386/x86-64-tls-2a.d         |   4 +
 gas/testsuite/gas/i386/x86-64-tls-2b.d         |  12 ++
 ld/testsuite/ld-x86-64/tlsbin2aligned-nacl.rd  | 143 ++++++++++++++++++++++
 ld/testsuite/ld-x86-64/tlsbin2aligned.rd       | 141 +++++++++++++++++++++
 ld/testsuite/ld-x86-64/tlsbinaligned-nacl.rd   | 150 +++++++++++++++++++++++
 ld/testsuite/ld-x86-64/tlsbinaligned.rd        | 148 ++++++++++++++++++++++
 ld/testsuite/ld-x86-64/tlsbinpic2aligned.s     |   2 +
 ld/testsuite/ld-x86-64/tlsbinpicaligned.s      |   2 +
 ld/testsuite/ld-x86-64/tlsgd10aligned.s        |   2 +
 ld/testsuite/ld-x86-64/tlsgd11aligned.s        |   2 +
 ld/testsuite/ld-x86-64/tlsgd12aligned.d        |   4 +
 ld/testsuite/ld-x86-64/tlsgd12aligned.s        |   2 +
 ld/testsuite/ld-x86-64/tlsgd13aligned.d        |   4 +
 ld/testsuite/ld-x86-64/tlsgd13aligned.s        |   2 +
 ld/testsuite/ld-x86-64/tlsgd14aligned.s        |   2 +
 ld/testsuite/ld-x86-64/tlsgd1aligned.s         |   2 +
 ld/testsuite/ld-x86-64/tlsgd2aligned.d         |   4 +
 ld/testsuite/ld-x86-64/tlsgd2aligned.s         |   2 +
 ld/testsuite/ld-x86-64/tlsgd3aligned.d         |   4 +
 ld/testsuite/ld-x86-64/tlsgd3aligned.s         |   2 +
 ld/testsuite/ld-x86-64/tlsgd4aligned.s         |   2 +
 ld/testsuite/ld-x86-64/tlsgd5aaligned.s        |   2 +
 ld/testsuite/ld-x86-64/tlsgd5caligned.s        |   2 +
 ld/testsuite/ld-x86-64/tlsgd6aaligned.s        |   2 +
 ld/testsuite/ld-x86-64/tlsgd6caligned.s        |   2 +
 ld/testsuite/ld-x86-64/tlsgd7aligned.s         |   2 +
 ld/testsuite/ld-x86-64/tlsgd8aligned.s         |   2 +
 ld/testsuite/ld-x86-64/tlsgd9aligned.s         |   2 +
 ld/testsuite/ld-x86-64/tlsgdescaligned-nacl.rd | 103 ++++++++++++++++
 ld/testsuite/ld-x86-64/tlsgdescaligned.dd      | 163 +++++++++++++++++++++++++
 ld/testsuite/ld-x86-64/tlsgdescaligned.rd      | 101 +++++++++++++++
 ld/testsuite/ld-x86-64/tlsgdescaligned.s       |   2 +
 ld/testsuite/ld-x86-64/tlsld1aligned.s         |   2 +
 ld/testsuite/ld-x86-64/tlsld2aligned.s         |   2 +
 ld/testsuite/ld-x86-64/tlsld3aligned.s         |   2 +
 ld/testsuite/ld-x86-64/tlsld4aligned.s         |   2 +
 ld/testsuite/ld-x86-64/tlsld5aligned.s         |   2 +
 ld/testsuite/ld-x86-64/tlsld6aligned.s         |   2 +
 ld/testsuite/ld-x86-64/tlslibaligned.s         |  18 +++
 ld/testsuite/ld-x86-64/tlspic1aligned.s        |   2 +
 ld/testsuite/ld-x86-64/tlspic2aligned-nacl.rd  | 145 ++++++++++++++++++++++
 ld/testsuite/ld-x86-64/tlspic2aligned.rd       | 139 +++++++++++++++++++++
 ld/testsuite/ld-x86-64/tlspic2aligned.sd       |  20 +++
 ld/testsuite/ld-x86-64/tlspic3aligned.s        |   2 +
 ld/testsuite/ld-x86-64/tlspicaligned-nacl.rd   | 144 ++++++++++++++++++++++
 ld/testsuite/ld-x86-64/tlspicaligned.rd        | 142 +++++++++++++++++++++
 ld/testsuite/ld-x86-64/tlspie1aligned.d        |   6 +
 ld/testsuite/ld-x86-64/tlspie1aligned.s        |  58 +++++++++
 ld/testsuite/ld-x86-64/tlspie2aaligned.d       |   6 +
 ld/testsuite/ld-x86-64/tlspie2aligned.s        |  58 +++++++++
 ld/testsuite/ld-x86-64/tlspie2baligned.d       |  28 +++++
 ld/testsuite/ld-x86-64/tlspie2caligned.d       |  28 +++++
 ld/testsuite/ld-x86-64/x86-64.exp              | 111 +++++++++++++++++
 67 files changed, 2052 insertions(+), 1 deletion(-)
 create mode 100644 gas/testsuite/gas/i386/ilp32/x86-64-tls-1.s
 create mode 100644 gas/testsuite/gas/i386/ilp32/x86-64-tls-1a.d
 create mode 100644 gas/testsuite/gas/i386/ilp32/x86-64-tls-1b.d
 create mode 100644 gas/testsuite/gas/i386/ilp32/x86-64-tls-2.s
 create mode 100644 gas/testsuite/gas/i386/ilp32/x86-64-tls-2a.d
 create mode 100644 gas/testsuite/gas/i386/ilp32/x86-64-tls-2b.d
 create mode 100644 gas/testsuite/gas/i386/x86-64-tls-1.s
 create mode 100644 gas/testsuite/gas/i386/x86-64-tls-1a.d
 create mode 100644 gas/testsuite/gas/i386/x86-64-tls-1b.d
 create mode 100644 gas/testsuite/gas/i386/x86-64-tls-2.s
 create mode 100644 gas/testsuite/gas/i386/x86-64-tls-2a.d
 create mode 100644 gas/testsuite/gas/i386/x86-64-tls-2b.d
 create mode 100644 ld/testsuite/ld-x86-64/tlsbin2aligned-nacl.rd
 create mode 100644 ld/testsuite/ld-x86-64/tlsbin2aligned.rd
 create mode 100644 ld/testsuite/ld-x86-64/tlsbinaligned-nacl.rd
 create mode 100644 ld/testsuite/ld-x86-64/tlsbinaligned.rd
 create mode 100644 ld/testsuite/ld-x86-64/tlsbinpic2aligned.s
 create mode 100644 ld/testsuite/ld-x86-64/tlsbinpicaligned.s
 create mode 100644 ld/testsuite/ld-x86-64/tlsgd10aligned.s
 create mode 100644 ld/testsuite/ld-x86-64/tlsgd11aligned.s
 create mode 100644 ld/testsuite/ld-x86-64/tlsgd12aligned.d
 create mode 100644 ld/testsuite/ld-x86-64/tlsgd12aligned.s
 create mode 100644 ld/testsuite/ld-x86-64/tlsgd13aligned.d
 create mode 100644 ld/testsuite/ld-x86-64/tlsgd13aligned.s
 create mode 100644 ld/testsuite/ld-x86-64/tlsgd14aligned.s
 create mode 100644 ld/testsuite/ld-x86-64/tlsgd1aligned.s
 create mode 100644 ld/testsuite/ld-x86-64/tlsgd2aligned.d
 create mode 100644 ld/testsuite/ld-x86-64/tlsgd2aligned.s
 create mode 100644 ld/testsuite/ld-x86-64/tlsgd3aligned.d
 create mode 100644 ld/testsuite/ld-x86-64/tlsgd3aligned.s
 create mode 100644 ld/testsuite/ld-x86-64/tlsgd4aligned.s
 create mode 100644 ld/testsuite/ld-x86-64/tlsgd5aaligned.s
 create mode 100644 ld/testsuite/ld-x86-64/tlsgd5caligned.s
 create mode 100644 ld/testsuite/ld-x86-64/tlsgd6aaligned.s
 create mode 100644 ld/testsuite/ld-x86-64/tlsgd6caligned.s
 create mode 100644 ld/testsuite/ld-x86-64/tlsgd7aligned.s
 create mode 100644 ld/testsuite/ld-x86-64/tlsgd8aligned.s
 create mode 100644 ld/testsuite/ld-x86-64/tlsgd9aligned.s
 create mode 100644 ld/testsuite/ld-x86-64/tlsgdescaligned-nacl.rd
 create mode 100644 ld/testsuite/ld-x86-64/tlsgdescaligned.dd
 create mode 100644 ld/testsuite/ld-x86-64/tlsgdescaligned.rd
 create mode 100644 ld/testsuite/ld-x86-64/tlsgdescaligned.s
 create mode 100644 ld/testsuite/ld-x86-64/tlsld1aligned.s
 create mode 100644 ld/testsuite/ld-x86-64/tlsld2aligned.s
 create mode 100644 ld/testsuite/ld-x86-64/tlsld3aligned.s
 create mode 100644 ld/testsuite/ld-x86-64/tlsld4aligned.s
 create mode 100644 ld/testsuite/ld-x86-64/tlsld5aligned.s
 create mode 100644 ld/testsuite/ld-x86-64/tlsld6aligned.s
 create mode 100644 ld/testsuite/ld-x86-64/tlslibaligned.s
 create mode 100644 ld/testsuite/ld-x86-64/tlspic1aligned.s
 create mode 100644 ld/testsuite/ld-x86-64/tlspic2aligned-nacl.rd
 create mode 100644 ld/testsuite/ld-x86-64/tlspic2aligned.rd
 create mode 100644 ld/testsuite/ld-x86-64/tlspic2aligned.sd
 create mode 100644 ld/testsuite/ld-x86-64/tlspic3aligned.s
 create mode 100644 ld/testsuite/ld-x86-64/tlspicaligned-nacl.rd
 create mode 100644 ld/testsuite/ld-x86-64/tlspicaligned.rd
 create mode 100644 ld/testsuite/ld-x86-64/tlspie1aligned.d
 create mode 100644 ld/testsuite/ld-x86-64/tlspie1aligned.s
 create mode 100644 ld/testsuite/ld-x86-64/tlspie2aaligned.d
 create mode 100644 ld/testsuite/ld-x86-64/tlspie2aligned.s
 create mode 100644 ld/testsuite/ld-x86-64/tlspie2baligned.d
 create mode 100644 ld/testsuite/ld-x86-64/tlspie2caligned.d

diff --git a/bfd/elf64-x86-64.c b/bfd/elf64-x86-64.c
index 8cef9f5..7b1adc1 100644
--- a/bfd/elf64-x86-64.c
+++ b/bfd/elf64-x86-64.c
@@ -1678,8 +1678,10 @@ elf_x86_64_check_tls_transition (bfd *abfd,
 	    {
 	      /* Use strncmp to check __tls_get_addr since
 		 __tls_get_addr may be versioned.  */
-	      if (strncmp (h->root.root.string, "__tls_get_addr", 14)
+	      if ((strncmp (h->root.root.string, "__tls_get_addr", 14)
 		  == 0)
+		  || (strncmp (h->root.root.string, "___tls_get_addr",
+			       15) == 0))
 		{
 		  eh->tls_get_addr = 1;
 		  tls_get_addr = TRUE;
diff --git a/gas/config/tc-i386.c b/gas/config/tc-i386.c
index 456be9e..738c4cb 100644
--- a/gas/config/tc-i386.c
+++ b/gas/config/tc-i386.c
@@ -11152,6 +11152,22 @@ tc_pe_dwarf2_emit_offset (symbolS *symbol, unsigned int size)
 #endif
 
 #if defined (OBJ_ELF) || defined (OBJ_MAYBE_ELF)
+/* Support for __tls_get_addr -> ___tls_get_addr redirection.  */
+
+void
+x86_64_elf_frob_symbol (symbolS *symp, int *puntp)
+{
+  if (flag_code == CODE_64BIT
+      && S_IS_WEAKREFD (symp)
+      && strcmp (S_GET_NAME (symp), "___tls_get_addr") == 0)
+    {
+      /* Turn weakrefd ___tls_get_addr into reference to non-weak
+         ___tls_get_addr.  */
+      S_CLEAR_WEAKREFD (symp);
+    }
+  elf_frob_symbol (symp, puntp);
+}
+
 /* For ELF on x86-64, add support for SHF_X86_64_LARGE.  */
 
 bfd_vma
diff --git a/gas/config/tc-i386.h b/gas/config/tc-i386.h
index f54924c..78ed2c9 100644
--- a/gas/config/tc-i386.h
+++ b/gas/config/tc-i386.h
@@ -307,6 +307,12 @@ extern int i386_elf_section_type (const char *, size_t);
 extern void i386_solaris_fix_up_eh_frame (segT);
 #endif
 
+#if defined (OBJ_ELF) || defined (OBJ_MAYBE_ELF)
+/* Support for __tls_get_addr -> ___tls_get_addr redirection.  */
+#define obj_frob_symbol(sym, punt) x86_64_elf_frob_symbol ((sym), &(punt))
+extern void x86_64_elf_frob_symbol (symbolS *, int *);
+#endif
+
 /* Support for SHF_X86_64_LARGE */
 extern bfd_vma x86_64_section_word (char *, size_t);
 extern bfd_vma x86_64_section_letter (int, const char **);
diff --git a/gas/testsuite/gas/i386/i386.exp b/gas/testsuite/gas/i386/i386.exp
index 67a7a13..0d912bd 100644
--- a/gas/testsuite/gas/i386/i386.exp
+++ b/gas/testsuite/gas/i386/i386.exp
@@ -868,6 +868,11 @@ if [expr ([istarget "i*86-*-*"] || [istarget "x86_64-*-*"]) && [gas_64_check]] t
 	run_dump_test "x86-64-gotpcrel-no-relax"
 
 	run_dump_test "x86-64-addend"
+
+	run_dump_test "x86-64-tls-1a"
+	run_dump_test "x86-64-tls-1b"
+	run_dump_test "x86-64-tls-2a"
+	run_dump_test "x86-64-tls-2b"
     }
 
     set ASFLAGS "$old_ASFLAGS"
diff --git a/gas/testsuite/gas/i386/ilp32/x86-64-tls-1.s b/gas/testsuite/gas/i386/ilp32/x86-64-tls-1.s
new file mode 100644
index 0000000..b4bcceb
--- /dev/null
+++ b/gas/testsuite/gas/i386/ilp32/x86-64-tls-1.s
@@ -0,0 +1,8 @@
+	.weakref __tls_get_addr, ___tls_get_addr
+	.text
+	.globl	bar
+	.type	bar, @function
+bar:
+	call	__tls_get_addr@PLT
+	ret
+	.size	bar, .-bar
diff --git a/gas/testsuite/gas/i386/ilp32/x86-64-tls-1a.d b/gas/testsuite/gas/i386/ilp32/x86-64-tls-1a.d
new file mode 100644
index 0000000..98ce313
--- /dev/null
+++ b/gas/testsuite/gas/i386/ilp32/x86-64-tls-1a.d
@@ -0,0 +1,5 @@
+#source: x86-64-tls-1.s
+#nm: --undefined-only
+
+ +U _GLOBAL_OFFSET_TABLE_
+ +U ___tls_get_addr
diff --git a/gas/testsuite/gas/i386/ilp32/x86-64-tls-1b.d b/gas/testsuite/gas/i386/ilp32/x86-64-tls-1b.d
new file mode 100644
index 0000000..38c17e8
--- /dev/null
+++ b/gas/testsuite/gas/i386/ilp32/x86-64-tls-1b.d
@@ -0,0 +1,12 @@
+#source: x86-64-tls-1.s
+#objdump: -dwr
+
+.*: +file format .*
+
+
+Disassembly of section \.text:
+
+0+ <bar>:
+ +[a-f0-9]+:	e8 00 00 00 00       	callq  5 <bar\+0x5>	1: R_X86_64_PLT32	___tls_get_addr-0x4
+ +[a-f0-9]+:	c3                   	retq   
+#pass
diff --git a/gas/testsuite/gas/i386/ilp32/x86-64-tls-2.s b/gas/testsuite/gas/i386/ilp32/x86-64-tls-2.s
new file mode 100644
index 0000000..283f814
--- /dev/null
+++ b/gas/testsuite/gas/i386/ilp32/x86-64-tls-2.s
@@ -0,0 +1,9 @@
+	.weakref __tls_get_addr, ___tls_get_addr
+	.text
+	.p2align 4,,15
+	.globl	bar
+	.type	bar, @function
+bar:
+	movq	x, %rax
+	ret
+	.size	bar, .-bar
diff --git a/gas/testsuite/gas/i386/ilp32/x86-64-tls-2a.d b/gas/testsuite/gas/i386/ilp32/x86-64-tls-2a.d
new file mode 100644
index 0000000..e82727e
--- /dev/null
+++ b/gas/testsuite/gas/i386/ilp32/x86-64-tls-2a.d
@@ -0,0 +1,4 @@
+#source: x86-64-tls-2.s
+#nm: --undefined-only
+
+ +U x
diff --git a/gas/testsuite/gas/i386/ilp32/x86-64-tls-2b.d b/gas/testsuite/gas/i386/ilp32/x86-64-tls-2b.d
new file mode 100644
index 0000000..6650712
--- /dev/null
+++ b/gas/testsuite/gas/i386/ilp32/x86-64-tls-2b.d
@@ -0,0 +1,12 @@
+#source: x86-64-tls-2.s
+#objdump: -dwr
+
+.*: +file format .*
+
+
+Disassembly of section \.text:
+
+0+ <bar>:
+ +[a-f0-9]+:	48 8b 04 25 00 00 00 00 	mov    0x0,%rax	4: R_X86_64_32S	x
+ +[a-f0-9]+:	c3                   	retq   
+#pass
diff --git a/gas/testsuite/gas/i386/x86-64-tls-1.s b/gas/testsuite/gas/i386/x86-64-tls-1.s
new file mode 100644
index 0000000..b4bcceb
--- /dev/null
+++ b/gas/testsuite/gas/i386/x86-64-tls-1.s
@@ -0,0 +1,8 @@
+	.weakref __tls_get_addr, ___tls_get_addr
+	.text
+	.globl	bar
+	.type	bar, @function
+bar:
+	call	__tls_get_addr@PLT
+	ret
+	.size	bar, .-bar
diff --git a/gas/testsuite/gas/i386/x86-64-tls-1a.d b/gas/testsuite/gas/i386/x86-64-tls-1a.d
new file mode 100644
index 0000000..98ce313
--- /dev/null
+++ b/gas/testsuite/gas/i386/x86-64-tls-1a.d
@@ -0,0 +1,5 @@
+#source: x86-64-tls-1.s
+#nm: --undefined-only
+
+ +U _GLOBAL_OFFSET_TABLE_
+ +U ___tls_get_addr
diff --git a/gas/testsuite/gas/i386/x86-64-tls-1b.d b/gas/testsuite/gas/i386/x86-64-tls-1b.d
new file mode 100644
index 0000000..38c17e8
--- /dev/null
+++ b/gas/testsuite/gas/i386/x86-64-tls-1b.d
@@ -0,0 +1,12 @@
+#source: x86-64-tls-1.s
+#objdump: -dwr
+
+.*: +file format .*
+
+
+Disassembly of section \.text:
+
+0+ <bar>:
+ +[a-f0-9]+:	e8 00 00 00 00       	callq  5 <bar\+0x5>	1: R_X86_64_PLT32	___tls_get_addr-0x4
+ +[a-f0-9]+:	c3                   	retq   
+#pass
diff --git a/gas/testsuite/gas/i386/x86-64-tls-2.s b/gas/testsuite/gas/i386/x86-64-tls-2.s
new file mode 100644
index 0000000..283f814
--- /dev/null
+++ b/gas/testsuite/gas/i386/x86-64-tls-2.s
@@ -0,0 +1,9 @@
+	.weakref __tls_get_addr, ___tls_get_addr
+	.text
+	.p2align 4,,15
+	.globl	bar
+	.type	bar, @function
+bar:
+	movq	x, %rax
+	ret
+	.size	bar, .-bar
diff --git a/gas/testsuite/gas/i386/x86-64-tls-2a.d b/gas/testsuite/gas/i386/x86-64-tls-2a.d
new file mode 100644
index 0000000..e82727e
--- /dev/null
+++ b/gas/testsuite/gas/i386/x86-64-tls-2a.d
@@ -0,0 +1,4 @@
+#source: x86-64-tls-2.s
+#nm: --undefined-only
+
+ +U x
diff --git a/gas/testsuite/gas/i386/x86-64-tls-2b.d b/gas/testsuite/gas/i386/x86-64-tls-2b.d
new file mode 100644
index 0000000..6650712
--- /dev/null
+++ b/gas/testsuite/gas/i386/x86-64-tls-2b.d
@@ -0,0 +1,12 @@
+#source: x86-64-tls-2.s
+#objdump: -dwr
+
+.*: +file format .*
+
+
+Disassembly of section \.text:
+
+0+ <bar>:
+ +[a-f0-9]+:	48 8b 04 25 00 00 00 00 	mov    0x0,%rax	4: R_X86_64_32S	x
+ +[a-f0-9]+:	c3                   	retq   
+#pass
diff --git a/ld/testsuite/ld-x86-64/tlsbin2aligned-nacl.rd b/ld/testsuite/ld-x86-64/tlsbin2aligned-nacl.rd
new file mode 100644
index 0000000..60c5e1e
--- /dev/null
+++ b/ld/testsuite/ld-x86-64/tlsbin2aligned-nacl.rd
@@ -0,0 +1,143 @@
+#source: tlsbinpic2aligned.s
+#source: tlsbin.s
+#as: --64
+#ld: -shared -melf_x86_64_nacl --no-ld-generated-unwind-info
+#readelf: -WSsrl
+#target: x86_64-*-nacl*
+
+There are [0-9]+ section headers, starting at offset 0x[0-9a-f]+:
+
+Section Headers:
+ +\[Nr\] Name +Type +Address +Off +Size +ES Flg Lk Inf Al
+ +\[[ 0-9]+\] +NULL +0+ 0+ 0+ 00 +0 +0 +0
+ +\[[ 0-9]+\] .text +PROGBITS +0+20000 [0-9a-f]+ 0+233 00 +AX +0 +0 +4096
+ +\[[ 0-9]+\] .interp +.*
+ +\[[ 0-9]+\] .hash +.*
+ +\[[ 0-9]+\] .dynsym +.*
+ +\[[ 0-9]+\] .dynstr +.*
+ +\[[ 0-9]+\] .rela.dyn +.*
+ +\[[ 0-9]+\] .tdata +PROGBITS +0+100303b8 [0-9a-f]+ 0+60 00 WAT +0 +0 +1
+ +\[[ 0-9]+\] .tbss +NOBITS +0+10030418 [0-9a-f]+ 0+40 00 WAT +0 +0 +1
+ +\[[ 0-9]+\] .dynamic +DYNAMIC +0+10030418 [0-9a-f]+ 0+100 10 +WA +5 +0 +8
+ +\[[ 0-9]+\] .got +PROGBITS +0+10030518 [0-9a-f]+ 0+28 08 +WA +0 +0 +8
+ +\[[ 0-9]+\] .got.plt +PROGBITS +0+10030540 [0-9a-f]+ 0+18 08 +WA +0 +0 +8
+ +\[[ 0-9]+\] .symtab +.*
+ +\[[ 0-9]+\] .strtab +.*
+ +\[[ 0-9]+\] .shstrtab +.*
+Key to Flags:
+#...
+
+Elf file type is EXEC \(Executable file\)
+Entry point 0x2013b
+There are [0-9]+ program headers, starting at offset [0-9]+
+
+Program Headers:
+ +Type +Offset +VirtAddr +PhysAddr +FileSiz +MemSiz +Flg Align
+ +PHDR.*
+ +INTERP.*
+.*Requesting program interpreter.*
+ +LOAD +0x0+10000 0x0+20000 0x0+20000 0x0+10000 0x0+10000 R E +0x10000
+ +LOAD +0x0+ 0x0+10020000 0x0+10020000 0x0+3b8 0x0+3b8 R +0x10000
+ +LOAD +0x0+3b8 0x0+100303b8 0x0+100303b8 0x0+1a0 0x0+1a0 RW +0x10000
+ +DYNAMIC +0x0+418 0x0+10030418 0x0+10030418 0x0+100 0x0+100 RW +0x8
+ +TLS +0x0+3b8 0x0+100303b8 0x0+100303b8 0x0+60 0x0+a0 R +0x1
+
+ Section to Segment mapping:
+ +Segment Sections...
+ +00 *
+ +01 +.interp *
+ +02 +.text *
+ +03 +.interp .hash .dynsym .dynstr .rela.dyn *
+ +04 +.tdata .dynamic .got .got.plt *
+ +05 +.dynamic *
+ +06 +.tdata .tbss *
+
+Relocation section '.rela.dyn' at offset 0x[0-9a-f]+ contains 5 entries:
+ +Offset +Info +Type +Symbol's Value +Symbol's Name \+ Addend
+[0-9a-f ]+R_X86_64_TPOFF64 +0+ sG5 \+ 0
+[0-9a-f ]+R_X86_64_TPOFF64 +0+ sG2 \+ 0
+[0-9a-f ]+R_X86_64_TPOFF64 +0+ sG6 \+ 0
+[0-9a-f ]+R_X86_64_TPOFF64 +0+ sG1 \+ 0
+[0-9a-f ]+R_X86_64_GLOB_DAT +0+ ___tls_get_addr \+ 0
+
+Symbol table '\.dynsym' contains [0-9]+ entries:
+ +Num: +Value +Size +Type +Bind +Vis +Ndx +Name
+.* NOTYPE +LOCAL +DEFAULT +UND *
+.* TLS +GLOBAL +DEFAULT +UND sG5
+.* TLS +GLOBAL +DEFAULT +UND sG2
+.* NOTYPE +GLOBAL +DEFAULT +11 __bss_start
+.* TLS +GLOBAL +DEFAULT +UND sG6
+.* TLS +GLOBAL +DEFAULT +UND sG1
+.* NOTYPE +GLOBAL +DEFAULT +11 _edata
+.* NOTYPE +GLOBAL +DEFAULT +11 _end
+.* FUNC +GLOBAL +DEFAULT +UND ___tls_get_addr
+
+Symbol table '\.symtab' contains [0-9]+ entries:
+ +Num: +Value +Size +Type +Bind +Vis +Ndx +Name
+.* NOTYPE +LOCAL +DEFAULT +UND *
+.* SECTION +LOCAL +DEFAULT +1 *
+.* SECTION +LOCAL +DEFAULT +2 *
+.* SECTION +LOCAL +DEFAULT +3 *
+.* SECTION +LOCAL +DEFAULT +4 *
+.* SECTION +LOCAL +DEFAULT +5 *
+.* SECTION +LOCAL +DEFAULT +6 *
+.* SECTION +LOCAL +DEFAULT +7 *
+.* SECTION +LOCAL +DEFAULT +8 *
+.* SECTION +LOCAL +DEFAULT +9 *
+.* SECTION +LOCAL +DEFAULT +10 *
+.* SECTION +LOCAL +DEFAULT +11 *
+.* FILE +LOCAL +DEFAULT +ABS tmpdir/tlsbinpic2aligned.o
+.* TLS +LOCAL +DEFAULT +7 sl1
+.* TLS +LOCAL +DEFAULT +7 sl2
+.* TLS +LOCAL +DEFAULT +7 sl3
+.* TLS +LOCAL +DEFAULT +7 sl4
+.* TLS +LOCAL +DEFAULT +7 sl5
+.* TLS +LOCAL +DEFAULT +7 sl6
+.* TLS +LOCAL +DEFAULT +7 sl7
+.* TLS +LOCAL +DEFAULT +7 sl8
+.* FILE +LOCAL +DEFAULT +ABS tmpdir/tlsbin.o
+.* TLS +LOCAL +DEFAULT +8 bl1
+.* TLS +LOCAL +DEFAULT +8 bl2
+.* TLS +LOCAL +DEFAULT +8 bl3
+.* TLS +LOCAL +DEFAULT +8 bl4
+.* TLS +LOCAL +DEFAULT +8 bl5
+.* TLS +LOCAL +DEFAULT +8 bl6
+.* TLS +LOCAL +DEFAULT +8 bl7
+.* TLS +LOCAL +DEFAULT +8 bl8
+.* FILE +LOCAL +DEFAULT +ABS 
+.* OBJECT +LOCAL +DEFAULT +9 _DYNAMIC
+.* OBJECT +LOCAL +DEFAULT +11 _GLOBAL_OFFSET_TABLE_
+.* TLS +GLOBAL +DEFAULT +7 sg8
+.* TLS +GLOBAL +DEFAULT +8 bg8
+.* TLS +GLOBAL +DEFAULT +8 bg6
+.* TLS +GLOBAL +DEFAULT +UND sG5
+.* TLS +GLOBAL +DEFAULT +8 bg3
+.* TLS +GLOBAL +DEFAULT +7 sg3
+.* TLS +GLOBAL +HIDDEN +7 sh3
+.* TLS +GLOBAL +DEFAULT +UND sG2
+.* TLS +GLOBAL +DEFAULT +7 sg4
+.* TLS +GLOBAL +DEFAULT +7 sg5
+.* TLS +GLOBAL +DEFAULT +8 bg5
+.* TLS +GLOBAL +HIDDEN +7 sh7
+.* TLS +GLOBAL +HIDDEN +7 sh8
+.* TLS +GLOBAL +DEFAULT +7 sg1
+.* FUNC +GLOBAL +DEFAULT +1 _start
+.* TLS +GLOBAL +HIDDEN +7 sh4
+.* TLS +GLOBAL +DEFAULT +8 bg7
+.* TLS +GLOBAL +HIDDEN +7 sh5
+.* NOTYPE +GLOBAL +DEFAULT +11 __bss_start
+.* TLS +GLOBAL +DEFAULT +UND sG6
+.* FUNC +GLOBAL +DEFAULT +1 fn2
+.* TLS +GLOBAL +DEFAULT +7 sg2
+.* TLS +GLOBAL +DEFAULT +UND sG1
+.* TLS +GLOBAL +HIDDEN +7 sh1
+.* TLS +GLOBAL +DEFAULT +7 sg6
+.* TLS +GLOBAL +DEFAULT +7 sg7
+.* NOTYPE +GLOBAL +DEFAULT +11 _edata
+.* NOTYPE +GLOBAL +DEFAULT +11 _end
+.* TLS +GLOBAL +HIDDEN +7 sh2
+.* TLS +GLOBAL +HIDDEN +7 sh6
+.* TLS +GLOBAL +DEFAULT +8 bg2
+.* TLS +GLOBAL +DEFAULT +8 bg1
+.* FUNC +GLOBAL +DEFAULT +UND ___tls_get_addr
+.* TLS +GLOBAL +DEFAULT +8 bg4
diff --git a/ld/testsuite/ld-x86-64/tlsbin2aligned.rd b/ld/testsuite/ld-x86-64/tlsbin2aligned.rd
new file mode 100644
index 0000000..dfa8473
--- /dev/null
+++ b/ld/testsuite/ld-x86-64/tlsbin2aligned.rd
@@ -0,0 +1,141 @@
+#source: tlsbinpic2aligned.s
+#source: tlsbin.s
+#as: --64
+#ld: -shared -melf_x86_64 --no-ld-generated-unwind-info
+#readelf: -WSsrl
+#target: x86_64-*-*
+
+There are [0-9]+ section headers, starting at offset 0x[0-9a-f]+:
+
+Section Headers:
+ +\[Nr\] Name +Type +Address +Off +Size +ES Flg Lk Inf Al
+ +\[[ 0-9]+\] +NULL +0+ 0+ 0+ 00 +0 +0 +0
+ +\[[ 0-9]+\] .interp +.*
+ +\[[ 0-9]+\] .hash +.*
+ +\[[ 0-9]+\] .dynsym +.*
+ +\[[ 0-9]+\] .dynstr +.*
+ +\[[ 0-9]+\] .rela.dyn +.*
+ +\[[ 0-9]+\] .text +PROGBITS +0+401000 0+1000 0+233 00 +AX +0 +0 +4096
+ +\[[ 0-9]+\] .tdata +PROGBITS +0+601233 0+1233 0+60 00 WAT +0 +0 +1
+ +\[[ 0-9]+\] .tbss +NOBITS +0+601293 0+1293 0+40 00 WAT +0 +0 +1
+ +\[[ 0-9]+\] .dynamic +DYNAMIC +0+601298 0+1298 0+100 10 +WA +4 +0 +8
+ +\[[ 0-9]+\] .got +PROGBITS +0+601398 0+1398 0+28 08 +WA +0 +0 +8
+ +\[[ 0-9]+\] .got.plt +PROGBITS +0+6013c0 0+13c0 0+18 08 +WA +0 +0 +8
+ +\[[ 0-9]+\] .symtab +.*
+ +\[[ 0-9]+\] .strtab +.*
+ +\[[ 0-9]+\] .shstrtab +.*
+Key to Flags:
+#...
+
+Elf file type is EXEC \(Executable file\)
+Entry point 0x40113b
+There are [0-9]+ program headers, starting at offset [0-9]+
+
+Program Headers:
+ +Type +Offset +VirtAddr +PhysAddr +FileSiz +MemSiz +Flg Align
+ +PHDR.*
+ +INTERP.*
+.*Requesting program interpreter.*
+ +LOAD +0x0+ 0x0+400000 0x0+400000 0x0+1233 0x0+1233 R E 0x200000
+ +LOAD +0x0+1233 0x0+601233 0x0+601233 0x0+1a5 0x0+1a5 RW +0x200000
+ +DYNAMIC +0x0+1298 0x0+601298 0x0+601298 0x0+100 0x0+100 RW +0x8
+ +TLS +0x0+1233 0x0+601233 0x0+601233 0x0+60 0x0+a0 R +0x1
+
+ Section to Segment mapping:
+ +Segment Sections...
+ +00 *
+ +01 +.interp *
+ +02 +.interp .hash .dynsym .dynstr .rela.dyn .text *
+ +03 +.tdata .dynamic .got .got.plt *
+ +04 +.dynamic *
+ +05 +.tdata .tbss *
+
+Relocation section '.rela.dyn' at offset 0x[0-9a-f]+ contains 5 entries:
+ +Offset +Info +Type +Symbol's Value +Symbol's Name \+ Addend
+[0-9a-f ]+R_X86_64_TPOFF64 +0+ sG5 \+ 0
+[0-9a-f ]+R_X86_64_TPOFF64 +0+ sG2 \+ 0
+[0-9a-f ]+R_X86_64_TPOFF64 +0+ sG6 \+ 0
+[0-9a-f ]+R_X86_64_TPOFF64 +0+ sG1 \+ 0
+[0-9a-f ]+R_X86_64_GLOB_DAT +0+ ___tls_get_addr \+ 0
+
+Symbol table '\.dynsym' contains [0-9]+ entries:
+ +Num: +Value +Size +Type +Bind +Vis +Ndx +Name
+.* NOTYPE +LOCAL +DEFAULT +UND *
+.* TLS +GLOBAL +DEFAULT +UND sG5
+.* TLS +GLOBAL +DEFAULT +UND sG2
+.* NOTYPE +GLOBAL +DEFAULT +11 __bss_start
+.* TLS +GLOBAL +DEFAULT +UND sG6
+.* TLS +GLOBAL +DEFAULT +UND sG1
+.* NOTYPE +GLOBAL +DEFAULT +11 _edata
+.* NOTYPE +GLOBAL +DEFAULT +11 _end
+.* FUNC +GLOBAL +DEFAULT +UND ___tls_get_addr
+
+Symbol table '\.symtab' contains [0-9]+ entries:
+ +Num: +Value +Size +Type +Bind +Vis +Ndx +Name
+.* NOTYPE +LOCAL +DEFAULT +UND *
+.* SECTION +LOCAL +DEFAULT +1 *
+.* SECTION +LOCAL +DEFAULT +2 *
+.* SECTION +LOCAL +DEFAULT +3 *
+.* SECTION +LOCAL +DEFAULT +4 *
+.* SECTION +LOCAL +DEFAULT +5 *
+.* SECTION +LOCAL +DEFAULT +6 *
+.* SECTION +LOCAL +DEFAULT +7 *
+.* SECTION +LOCAL +DEFAULT +8 *
+.* SECTION +LOCAL +DEFAULT +9 *
+.* SECTION +LOCAL +DEFAULT +10 *
+.* SECTION +LOCAL +DEFAULT +11 *
+.* FILE +LOCAL +DEFAULT +ABS tmpdir/tlsbinpic2aligned.o
+.* TLS +LOCAL +DEFAULT +7 sl1
+.* TLS +LOCAL +DEFAULT +7 sl2
+.* TLS +LOCAL +DEFAULT +7 sl3
+.* TLS +LOCAL +DEFAULT +7 sl4
+.* TLS +LOCAL +DEFAULT +7 sl5
+.* TLS +LOCAL +DEFAULT +7 sl6
+.* TLS +LOCAL +DEFAULT +7 sl7
+.* TLS +LOCAL +DEFAULT +7 sl8
+.* FILE +LOCAL +DEFAULT +ABS tmpdir/tlsbin.o
+.* TLS +LOCAL +DEFAULT +8 bl1
+.* TLS +LOCAL +DEFAULT +8 bl2
+.* TLS +LOCAL +DEFAULT +8 bl3
+.* TLS +LOCAL +DEFAULT +8 bl4
+.* TLS +LOCAL +DEFAULT +8 bl5
+.* TLS +LOCAL +DEFAULT +8 bl6
+.* TLS +LOCAL +DEFAULT +8 bl7
+.* TLS +LOCAL +DEFAULT +8 bl8
+.* FILE +LOCAL +DEFAULT +ABS 
+.* OBJECT +LOCAL +DEFAULT +9 _DYNAMIC
+.* OBJECT +LOCAL +DEFAULT +11 _GLOBAL_OFFSET_TABLE_
+.* TLS +GLOBAL +DEFAULT +7 sg8
+.* TLS +GLOBAL +DEFAULT +8 bg8
+.* TLS +GLOBAL +DEFAULT +8 bg6
+.* TLS +GLOBAL +DEFAULT +UND sG5
+.* TLS +GLOBAL +DEFAULT +8 bg3
+.* TLS +GLOBAL +DEFAULT +7 sg3
+.* TLS +GLOBAL +HIDDEN +7 sh3
+.* TLS +GLOBAL +DEFAULT +UND sG2
+.* TLS +GLOBAL +DEFAULT +7 sg4
+.* TLS +GLOBAL +DEFAULT +7 sg5
+.* TLS +GLOBAL +DEFAULT +8 bg5
+.* TLS +GLOBAL +HIDDEN +7 sh7
+.* TLS +GLOBAL +HIDDEN +7 sh8
+.* TLS +GLOBAL +DEFAULT +7 sg1
+.* FUNC +GLOBAL +DEFAULT +6 _start
+.* TLS +GLOBAL +HIDDEN +7 sh4
+.* TLS +GLOBAL +DEFAULT +8 bg7
+.* TLS +GLOBAL +HIDDEN +7 sh5
+.* NOTYPE +GLOBAL +DEFAULT +11 __bss_start
+.* TLS +GLOBAL +DEFAULT +UND sG6
+.* FUNC +GLOBAL +DEFAULT +6 fn2
+.* TLS +GLOBAL +DEFAULT +7 sg2
+.* TLS +GLOBAL +DEFAULT +UND sG1
+.* TLS +GLOBAL +HIDDEN +7 sh1
+.* TLS +GLOBAL +DEFAULT +7 sg6
+.* TLS +GLOBAL +DEFAULT +7 sg7
+.* NOTYPE +GLOBAL +DEFAULT +11 _edata
+.* NOTYPE +GLOBAL +DEFAULT +11 _end
+.* TLS +GLOBAL +HIDDEN +7 sh2
+.* TLS +GLOBAL +HIDDEN +7 sh6
+.* TLS +GLOBAL +DEFAULT +8 bg2
+.* TLS +GLOBAL +DEFAULT +8 bg1
+.* FUNC +GLOBAL +DEFAULT +UND ___tls_get_addr
+.* TLS +GLOBAL +DEFAULT +8 bg4
diff --git a/ld/testsuite/ld-x86-64/tlsbinaligned-nacl.rd b/ld/testsuite/ld-x86-64/tlsbinaligned-nacl.rd
new file mode 100644
index 0000000..4057bf4
--- /dev/null
+++ b/ld/testsuite/ld-x86-64/tlsbinaligned-nacl.rd
@@ -0,0 +1,150 @@
+#source: tlsbinpicaligned.s
+#source: tlsbin.s
+#as: --64
+#ld: -shared -melf_x86_64_nacl --no-ld-generated-unwind-info
+#readelf: -WSsrl
+#target: x86_64-*-nacl*
+
+There are [0-9]+ section headers, starting at offset 0x[0-9a-f]+:
+
+Section Headers:
+ +\[Nr\] Name +Type +Address +Off +Size +ES Flg Lk Inf Al
+ +\[[ 0-9]+\] +NULL +0+ 0+ 0+ 00 +0 +0 +0
+ +\[[ 0-9]+\] .plt +.*
+ +\[[ 0-9]+\] .text +PROGBITS +0+21000 [0-9a-f]+ 0+231 00 +AX +0 +0 +4096
+ +\[[ 0-9]+\] .interp +.*
+ +\[[ 0-9]+\] .hash +.*
+ +\[[ 0-9]+\] .dynsym +.*
+ +\[[ 0-9]+\] .dynstr +.*
+ +\[[ 0-9]+\] .rela.dyn +.*
+ +\[[ 0-9]+\] .rela.plt +.*
+ +\[[ 0-9]+\] .tdata +PROGBITS +0+100303b8 [0-9a-f]+ 0+60 00 WAT +0 +0 +1
+ +\[[ 0-9]+\] .tbss +NOBITS +0+10030418 [0-9a-f]+ 0+40 00 WAT +0 +0 +1
+ +\[[ 0-9]+\] .dynamic +DYNAMIC +0+10030418 [0-9a-f]+ 0+140 10 +WA +6 +0 +8
+ +\[[ 0-9]+\] .got +PROGBITS +0+10030558 [0-9a-f]+ 0+20 08 +WA +0 +0 +8
+ +\[[ 0-9]+\] .got.plt +PROGBITS +0+10030578 [0-9a-f]+ 0+20 08 +WA +0 +0 +8
+ +\[[ 0-9]+\] .symtab +.*
+ +\[[ 0-9]+\] .strtab +.*
+ +\[[ 0-9]+\] .shstrtab +.*
+Key to Flags:
+#...
+
+Elf file type is EXEC \(Executable file\)
+Entry point 0x21139
+There are [0-9]+ program headers, starting at offset [0-9]+
+
+Program Headers:
+ +Type +Offset +VirtAddr +PhysAddr +FileSiz +MemSiz +Flg Align
+ +PHDR.*
+ +INTERP.*
+.*Requesting program interpreter.*
+ +LOAD +0x0+10000 0x0+20000 0x0+20000 0x0+10000 0x0+10000 R E +0x10000
+ +LOAD +0x0+ 0x0+10020000 0x0+10020000 0x0+3b8 0x0+3b8 R +0x10000
+ +LOAD +0x0+3b8 0x0+100303b8 0x0+100303b8 0x0+1e0 0x0+1e0 RW +0x10000
+ +DYNAMIC +0x0+418 0x0+10030418 0x0+10030418 0x0+140 0x0+140 RW +0x8
+ +TLS +0x0+3b8 0x0+100303b8 0x0+100303b8 0x0+60 0x0+a0 R +0x1
+
+ Section to Segment mapping:
+ +Segment Sections...
+ +00 *
+ +01 +.interp *
+ +02 +.plt .text *
+ +03 +.interp .hash .dynsym .dynstr .rela.dyn .rela.plt *
+ +04 +.tdata .dynamic .got .got.plt *
+ +05 +.dynamic *
+ +06 +.tdata .tbss *
+
+Relocation section '.rela.dyn' at offset 0x[0-9a-f]+ contains 4 entries:
+ +Offset +Info +Type +Symbol's Value +Symbol's Name \+ Addend
+[0-9a-f ]+R_X86_64_TPOFF64 +0+ sG5 \+ 0
+[0-9a-f ]+R_X86_64_TPOFF64 +0+ sG2 \+ 0
+[0-9a-f ]+R_X86_64_TPOFF64 +0+ sG6 \+ 0
+[0-9a-f ]+R_X86_64_TPOFF64 +0+ sG1 \+ 0
+
+Relocation section '.rela.plt' at offset 0x[0-9a-f]+ contains 1 entries:
+ +Offset +Info +Type +Symbol's Value +Symbol's Name \+ Addend
+[0-9a-f ]+R_X86_64_JUMP_SLOT[0-9a-f ]+___tls_get_addr \+ 0
+
+Symbol table '\.dynsym' contains [0-9]+ entries:
+ +Num: +Value +Size +Type +Bind +Vis +Ndx +Name
+.* NOTYPE +LOCAL +DEFAULT +UND *
+.* TLS +GLOBAL +DEFAULT +UND sG5
+.* TLS +GLOBAL +DEFAULT +UND sG2
+.* NOTYPE +GLOBAL +DEFAULT +13 __bss_start
+.* TLS +GLOBAL +DEFAULT +UND sG6
+.* TLS +GLOBAL +DEFAULT +UND sG1
+.* NOTYPE +GLOBAL +DEFAULT +13 _edata
+.* NOTYPE +GLOBAL +DEFAULT +13 _end
+.* FUNC +GLOBAL +DEFAULT +UND ___tls_get_addr
+
+Symbol table '\.symtab' contains [0-9]+ entries:
+ +Num: +Value +Size +Type +Bind +Vis +Ndx +Name
+.* NOTYPE +LOCAL +DEFAULT +UND *
+.* SECTION +LOCAL +DEFAULT +1 *
+.* SECTION +LOCAL +DEFAULT +2 *
+.* SECTION +LOCAL +DEFAULT +3 *
+.* SECTION +LOCAL +DEFAULT +4 *
+.* SECTION +LOCAL +DEFAULT +5 *
+.* SECTION +LOCAL +DEFAULT +6 *
+.* SECTION +LOCAL +DEFAULT +7 *
+.* SECTION +LOCAL +DEFAULT +8 *
+.* SECTION +LOCAL +DEFAULT +9 *
+.* SECTION +LOCAL +DEFAULT +10 *
+.* SECTION +LOCAL +DEFAULT +11 *
+.* SECTION +LOCAL +DEFAULT +12 *
+.* SECTION +LOCAL +DEFAULT +13 *
+.* FILE +LOCAL +DEFAULT +ABS tmpdir/tlsbinpicaligned.o
+.* TLS +LOCAL +DEFAULT +9 sl1
+.* TLS +LOCAL +DEFAULT +9 sl2
+.* TLS +LOCAL +DEFAULT +9 sl3
+.* TLS +LOCAL +DEFAULT +9 sl4
+.* TLS +LOCAL +DEFAULT +9 sl5
+.* TLS +LOCAL +DEFAULT +9 sl6
+.* TLS +LOCAL +DEFAULT +9 sl7
+.* TLS +LOCAL +DEFAULT +9 sl8
+.* FILE +LOCAL +DEFAULT +ABS tmpdir/tlsbin.o
+.* TLS +LOCAL +DEFAULT +10 bl1
+.* TLS +LOCAL +DEFAULT +10 bl2
+.* TLS +LOCAL +DEFAULT +10 bl3
+.* TLS +LOCAL +DEFAULT +10 bl4
+.* TLS +LOCAL +DEFAULT +10 bl5
+.* TLS +LOCAL +DEFAULT +10 bl6
+.* TLS +LOCAL +DEFAULT +10 bl7
+.* TLS +LOCAL +DEFAULT +10 bl8
+.* FILE +LOCAL +DEFAULT +ABS 
+.* OBJECT +LOCAL +DEFAULT +11 _DYNAMIC
+.* OBJECT +LOCAL +DEFAULT +13 _GLOBAL_OFFSET_TABLE_
+.* TLS +GLOBAL +DEFAULT +9 sg8
+.* TLS +GLOBAL +DEFAULT +10 bg8
+.* TLS +GLOBAL +DEFAULT +10 bg6
+.* TLS +GLOBAL +DEFAULT +UND sG5
+.* TLS +GLOBAL +DEFAULT +10 bg3
+.* TLS +GLOBAL +DEFAULT +9 sg3
+.* TLS +GLOBAL +HIDDEN +9 sh3
+.* TLS +GLOBAL +DEFAULT +UND sG2
+.* TLS +GLOBAL +DEFAULT +9 sg4
+.* TLS +GLOBAL +DEFAULT +9 sg5
+.* TLS +GLOBAL +DEFAULT +10 bg5
+.* TLS +GLOBAL +HIDDEN +9 sh7
+.* TLS +GLOBAL +HIDDEN +9 sh8
+.* TLS +GLOBAL +DEFAULT +9 sg1
+.* FUNC +GLOBAL +DEFAULT +2 _start
+.* TLS +GLOBAL +HIDDEN +9 sh4
+.* TLS +GLOBAL +DEFAULT +10 bg7
+.* TLS +GLOBAL +HIDDEN +9 sh5
+.* NOTYPE +GLOBAL +DEFAULT +13 __bss_start
+.* TLS +GLOBAL +DEFAULT +UND sG6
+.* FUNC +GLOBAL +DEFAULT +2 fn2
+.* TLS +GLOBAL +DEFAULT +9 sg2
+.* TLS +GLOBAL +DEFAULT +UND sG1
+.* TLS +GLOBAL +HIDDEN +9 sh1
+.* TLS +GLOBAL +DEFAULT +9 sg6
+.* TLS +GLOBAL +DEFAULT +9 sg7
+.* NOTYPE +GLOBAL +DEFAULT +13 _edata
+.* NOTYPE +GLOBAL +DEFAULT +13 _end
+.* TLS +GLOBAL +HIDDEN +9 sh2
+.* TLS +GLOBAL +HIDDEN +9 sh6
+.* TLS +GLOBAL +DEFAULT +10 bg2
+.* TLS +GLOBAL +DEFAULT +10 bg1
+.* FUNC +GLOBAL +DEFAULT +UND ___tls_get_addr
+.* TLS +GLOBAL +DEFAULT +10 bg4
diff --git a/ld/testsuite/ld-x86-64/tlsbinaligned.rd b/ld/testsuite/ld-x86-64/tlsbinaligned.rd
new file mode 100644
index 0000000..92af41b
--- /dev/null
+++ b/ld/testsuite/ld-x86-64/tlsbinaligned.rd
@@ -0,0 +1,148 @@
+#source: tlsbinpicaligned.s
+#source: tlsbin.s
+#as: --64
+#ld: -shared -melf_x86_64 --no-ld-generated-unwind-info
+#readelf: -WSsrl
+#target: x86_64-*-*
+
+There are [0-9]+ section headers, starting at offset 0x[0-9a-f]+:
+
+Section Headers:
+ +\[Nr\] Name +Type +Address +Off +Size +ES Flg Lk Inf Al
+ +\[[ 0-9]+\] +NULL +0+ 0+ 0+ 00 +0 +0 +0
+ +\[[ 0-9]+\] .interp +.*
+ +\[[ 0-9]+\] .hash +.*
+ +\[[ 0-9]+\] .dynsym +.*
+ +\[[ 0-9]+\] .dynstr +.*
+ +\[[ 0-9]+\] .rela.dyn +.*
+ +\[[ 0-9]+\] .rela.plt +.*
+ +\[[ 0-9]+\] .plt +.*
+ +\[[ 0-9]+\] .text +PROGBITS +0+401000 0+1000 0+231 00 +AX +0 +0 +4096
+ +\[[ 0-9]+\] .tdata +PROGBITS +0+601231 0+1231 0+60 00 WAT +0 +0 +1
+ +\[[ 0-9]+\] .tbss +NOBITS +0+601291 0+1291 0+40 00 WAT +0 +0 +1
+ +\[[ 0-9]+\] .dynamic +DYNAMIC +0+601298 0+1298 0+140 10 +WA +4 +0 +8
+ +\[[ 0-9]+\] .got +PROGBITS +0+6013d8 0+13d8 0+20 08 +WA +0 +0 +8
+ +\[[ 0-9]+\] .got.plt +PROGBITS +0+6013f8 0+13f8 0+20 08 +WA +0 +0 +8
+ +\[[ 0-9]+\] .symtab +.*
+ +\[[ 0-9]+\] .strtab +.*
+ +\[[ 0-9]+\] .shstrtab +.*
+Key to Flags:
+#...
+
+Elf file type is EXEC \(Executable file\)
+Entry point 0x401139
+There are [0-9]+ program headers, starting at offset [0-9]+
+
+Program Headers:
+ +Type +Offset +VirtAddr +PhysAddr +FileSiz +MemSiz +Flg Align
+ +PHDR.*
+ +INTERP.*
+.*Requesting program interpreter.*
+ +LOAD +0x0+ 0x0+400000 0x0+400000 0x0+1231 0x0+1231 R E 0x200000
+ +LOAD +0x0+1231 0x0+601231 0x0+601231 0x0+1e7 0x0+1e7 RW +0x200000
+ +DYNAMIC +0x0+1298 0x0+601298 0x0+601298 0x0+140 0x0+140 RW +0x8
+ +TLS +0x0+1231 0x0+601231 0x0+601231 0x0+60 0x0+a0 R +0x1
+
+ Section to Segment mapping:
+ +Segment Sections...
+ +00 *
+ +01 +.interp *
+ +02 +.interp .hash .dynsym .dynstr .rela.dyn .rela.plt .plt .text *
+ +03 +.tdata .dynamic .got .got.plt *
+ +04 +.dynamic *
+ +05 +.tdata .tbss *
+
+Relocation section '.rela.dyn' at offset 0x[0-9a-f]+ contains 4 entries:
+ +Offset +Info +Type +Symbol's Value +Symbol's Name \+ Addend
+[0-9a-f ]+R_X86_64_TPOFF64 +0+ sG5 \+ 0
+[0-9a-f ]+R_X86_64_TPOFF64 +0+ sG2 \+ 0
+[0-9a-f ]+R_X86_64_TPOFF64 +0+ sG6 \+ 0
+[0-9a-f ]+R_X86_64_TPOFF64 +0+ sG1 \+ 0
+
+Relocation section '.rela.plt' at offset 0x[0-9a-f]+ contains 1 entries:
+ +Offset +Info +Type +Symbol's Value +Symbol's Name \+ Addend
+[0-9a-f ]+R_X86_64_JUMP_SLOT[0-9a-f ]+___tls_get_addr \+ 0
+
+Symbol table '\.dynsym' contains [0-9]+ entries:
+ +Num: +Value +Size +Type +Bind +Vis +Ndx +Name
+.* NOTYPE +LOCAL +DEFAULT +UND *
+.* TLS +GLOBAL +DEFAULT +UND sG5
+.* TLS +GLOBAL +DEFAULT +UND sG2
+.* NOTYPE +GLOBAL +DEFAULT +13 __bss_start
+.* TLS +GLOBAL +DEFAULT +UND sG6
+.* TLS +GLOBAL +DEFAULT +UND sG1
+.* NOTYPE +GLOBAL +DEFAULT +13 _edata
+.* NOTYPE +GLOBAL +DEFAULT +13 _end
+.* FUNC +GLOBAL +DEFAULT +UND ___tls_get_addr
+
+Symbol table '\.symtab' contains [0-9]+ entries:
+ +Num: +Value +Size +Type +Bind +Vis +Ndx +Name
+.* NOTYPE +LOCAL +DEFAULT +UND *
+.* SECTION +LOCAL +DEFAULT +1 *
+.* SECTION +LOCAL +DEFAULT +2 *
+.* SECTION +LOCAL +DEFAULT +3 *
+.* SECTION +LOCAL +DEFAULT +4 *
+.* SECTION +LOCAL +DEFAULT +5 *
+.* SECTION +LOCAL +DEFAULT +6 *
+.* SECTION +LOCAL +DEFAULT +7 *
+.* SECTION +LOCAL +DEFAULT +8 *
+.* SECTION +LOCAL +DEFAULT +9 *
+.* SECTION +LOCAL +DEFAULT +10 *
+.* SECTION +LOCAL +DEFAULT +11 *
+.* SECTION +LOCAL +DEFAULT +12 *
+.* SECTION +LOCAL +DEFAULT +13 *
+.* FILE +LOCAL +DEFAULT +ABS tmpdir/tlsbinpicaligned.o
+.* TLS +LOCAL +DEFAULT +9 sl1
+.* TLS +LOCAL +DEFAULT +9 sl2
+.* TLS +LOCAL +DEFAULT +9 sl3
+.* TLS +LOCAL +DEFAULT +9 sl4
+.* TLS +LOCAL +DEFAULT +9 sl5
+.* TLS +LOCAL +DEFAULT +9 sl6
+.* TLS +LOCAL +DEFAULT +9 sl7
+.* TLS +LOCAL +DEFAULT +9 sl8
+.* FILE +LOCAL +DEFAULT +ABS tmpdir/tlsbin.o
+.* TLS +LOCAL +DEFAULT +10 bl1
+.* TLS +LOCAL +DEFAULT +10 bl2
+.* TLS +LOCAL +DEFAULT +10 bl3
+.* TLS +LOCAL +DEFAULT +10 bl4
+.* TLS +LOCAL +DEFAULT +10 bl5
+.* TLS +LOCAL +DEFAULT +10 bl6
+.* TLS +LOCAL +DEFAULT +10 bl7
+.* TLS +LOCAL +DEFAULT +10 bl8
+.* FILE +LOCAL +DEFAULT +ABS 
+.* OBJECT +LOCAL +DEFAULT +11 _DYNAMIC
+.* OBJECT +LOCAL +DEFAULT +13 _GLOBAL_OFFSET_TABLE_
+.* TLS +GLOBAL +DEFAULT +9 sg8
+.* TLS +GLOBAL +DEFAULT +10 bg8
+.* TLS +GLOBAL +DEFAULT +10 bg6
+.* TLS +GLOBAL +DEFAULT +UND sG5
+.* TLS +GLOBAL +DEFAULT +10 bg3
+.* TLS +GLOBAL +DEFAULT +9 sg3
+.* TLS +GLOBAL +HIDDEN +9 sh3
+.* TLS +GLOBAL +DEFAULT +UND sG2
+.* TLS +GLOBAL +DEFAULT +9 sg4
+.* TLS +GLOBAL +DEFAULT +9 sg5
+.* TLS +GLOBAL +DEFAULT +10 bg5
+.* TLS +GLOBAL +HIDDEN +9 sh7
+.* TLS +GLOBAL +HIDDEN +9 sh8
+.* TLS +GLOBAL +DEFAULT +9 sg1
+.* FUNC +GLOBAL +DEFAULT +8 _start
+.* TLS +GLOBAL +HIDDEN +9 sh4
+.* TLS +GLOBAL +DEFAULT +10 bg7
+.* TLS +GLOBAL +HIDDEN +9 sh5
+.* NOTYPE +GLOBAL +DEFAULT +13 __bss_start
+.* TLS +GLOBAL +DEFAULT +UND sG6
+.* FUNC +GLOBAL +DEFAULT +8 fn2
+.* TLS +GLOBAL +DEFAULT +9 sg2
+.* TLS +GLOBAL +DEFAULT +UND sG1
+.* TLS +GLOBAL +HIDDEN +9 sh1
+.* TLS +GLOBAL +DEFAULT +9 sg6
+.* TLS +GLOBAL +DEFAULT +9 sg7
+.* NOTYPE +GLOBAL +DEFAULT +13 _edata
+.* NOTYPE +GLOBAL +DEFAULT +13 _end
+.* TLS +GLOBAL +HIDDEN +9 sh2
+.* TLS +GLOBAL +HIDDEN +9 sh6
+.* TLS +GLOBAL +DEFAULT +10 bg2
+.* TLS +GLOBAL +DEFAULT +10 bg1
+.* FUNC +GLOBAL +DEFAULT +UND ___tls_get_addr
+.* TLS +GLOBAL +DEFAULT +10 bg4
diff --git a/ld/testsuite/ld-x86-64/tlsbinpic2aligned.s b/ld/testsuite/ld-x86-64/tlsbinpic2aligned.s
new file mode 100644
index 0000000..1105bb5
--- /dev/null
+++ b/ld/testsuite/ld-x86-64/tlsbinpic2aligned.s
@@ -0,0 +1,2 @@
+.weakref __tls_get_addr, ___tls_get_addr
+.include "tlsbinpic2.s"
diff --git a/ld/testsuite/ld-x86-64/tlsbinpicaligned.s b/ld/testsuite/ld-x86-64/tlsbinpicaligned.s
new file mode 100644
index 0000000..1707b88
--- /dev/null
+++ b/ld/testsuite/ld-x86-64/tlsbinpicaligned.s
@@ -0,0 +1,2 @@
+.weakref __tls_get_addr, ___tls_get_addr
+.include "tlsbinpic.s"
diff --git a/ld/testsuite/ld-x86-64/tlsgd10aligned.s b/ld/testsuite/ld-x86-64/tlsgd10aligned.s
new file mode 100644
index 0000000..d8cdde7
--- /dev/null
+++ b/ld/testsuite/ld-x86-64/tlsgd10aligned.s
@@ -0,0 +1,2 @@
+.weakref __tls_get_addr, ___tls_get_addr
+.include "tlsgd10.s"
diff --git a/ld/testsuite/ld-x86-64/tlsgd11aligned.s b/ld/testsuite/ld-x86-64/tlsgd11aligned.s
new file mode 100644
index 0000000..e93c88b
--- /dev/null
+++ b/ld/testsuite/ld-x86-64/tlsgd11aligned.s
@@ -0,0 +1,2 @@
+.weakref __tls_get_addr, ___tls_get_addr
+.include "tlsgd11.s"
diff --git a/ld/testsuite/ld-x86-64/tlsgd12aligned.d b/ld/testsuite/ld-x86-64/tlsgd12aligned.d
new file mode 100644
index 0000000..def1264
--- /dev/null
+++ b/ld/testsuite/ld-x86-64/tlsgd12aligned.d
@@ -0,0 +1,4 @@
+#name: TLS GD->IE transition check without PLT (aligned)
+#as: --64 -I $srcdir/$subdir
+#ld: -melf_x86_64
+#error: .*TLS transition from R_X86_64_TLSGD to R_X86_64_GOTTPOFF against `foo'.*failed.*
diff --git a/ld/testsuite/ld-x86-64/tlsgd12aligned.s b/ld/testsuite/ld-x86-64/tlsgd12aligned.s
new file mode 100644
index 0000000..9eb3d30
--- /dev/null
+++ b/ld/testsuite/ld-x86-64/tlsgd12aligned.s
@@ -0,0 +1,2 @@
+.weakref __tls_get_addr, ___tls_get_addr
+.include "tlsgd12.s"
diff --git a/ld/testsuite/ld-x86-64/tlsgd13aligned.d b/ld/testsuite/ld-x86-64/tlsgd13aligned.d
new file mode 100644
index 0000000..ae272f2
--- /dev/null
+++ b/ld/testsuite/ld-x86-64/tlsgd13aligned.d
@@ -0,0 +1,4 @@
+#name: TLS GD->LE transition check without PLT (aligned)
+#as: --64 -I $srcdir/$subdir
+#ld: -melf_x86_64
+#error: .*TLS transition from R_X86_64_TLSGD to R_X86_64_TPOFF32 against `foo'.*failed.*
diff --git a/ld/testsuite/ld-x86-64/tlsgd13aligned.s b/ld/testsuite/ld-x86-64/tlsgd13aligned.s
new file mode 100644
index 0000000..d6bc0f7
--- /dev/null
+++ b/ld/testsuite/ld-x86-64/tlsgd13aligned.s
@@ -0,0 +1,2 @@
+.weakref __tls_get_addr, ___tls_get_addr
+.include "tlsgd13.s"
diff --git a/ld/testsuite/ld-x86-64/tlsgd14aligned.s b/ld/testsuite/ld-x86-64/tlsgd14aligned.s
new file mode 100644
index 0000000..03205a9
--- /dev/null
+++ b/ld/testsuite/ld-x86-64/tlsgd14aligned.s
@@ -0,0 +1,2 @@
+.weakref __tls_get_addr, ___tls_get_addr
+.include "tlsgd14.s"
diff --git a/ld/testsuite/ld-x86-64/tlsgd1aligned.s b/ld/testsuite/ld-x86-64/tlsgd1aligned.s
new file mode 100644
index 0000000..2b0e2e5
--- /dev/null
+++ b/ld/testsuite/ld-x86-64/tlsgd1aligned.s
@@ -0,0 +1,2 @@
+.weakref __tls_get_addr, ___tls_get_addr
+.include "tlsgd1.s"
diff --git a/ld/testsuite/ld-x86-64/tlsgd2aligned.d b/ld/testsuite/ld-x86-64/tlsgd2aligned.d
new file mode 100644
index 0000000..045a953
--- /dev/null
+++ b/ld/testsuite/ld-x86-64/tlsgd2aligned.d
@@ -0,0 +1,4 @@
+#name: TLS GD->IE transition check (aligned)
+#as: --64 -I $srcdir/$subdir
+#ld: -melf_x86_64
+#error: .*TLS transition from R_X86_64_TLSGD to R_X86_64_GOTTPOFF against `foo'.*failed.*
diff --git a/ld/testsuite/ld-x86-64/tlsgd2aligned.s b/ld/testsuite/ld-x86-64/tlsgd2aligned.s
new file mode 100644
index 0000000..739351c
--- /dev/null
+++ b/ld/testsuite/ld-x86-64/tlsgd2aligned.s
@@ -0,0 +1,2 @@
+.weakref __tls_get_addr, ___tls_get_addr
+.include "tlsgd2.s"
diff --git a/ld/testsuite/ld-x86-64/tlsgd3aligned.d b/ld/testsuite/ld-x86-64/tlsgd3aligned.d
new file mode 100644
index 0000000..316de0e
--- /dev/null
+++ b/ld/testsuite/ld-x86-64/tlsgd3aligned.d
@@ -0,0 +1,4 @@
+#name: TLS GD->LE transition check (aligned)
+#as: --64 -I $srcdir/$subdir
+#ld: -melf_x86_64
+#error: .*TLS transition from R_X86_64_TLSGD to R_X86_64_TPOFF32 against `foo'.*failed.*
diff --git a/ld/testsuite/ld-x86-64/tlsgd3aligned.s b/ld/testsuite/ld-x86-64/tlsgd3aligned.s
new file mode 100644
index 0000000..369d761
--- /dev/null
+++ b/ld/testsuite/ld-x86-64/tlsgd3aligned.s
@@ -0,0 +1,2 @@
+.weakref __tls_get_addr, ___tls_get_addr
+.include "tlsgd3.s"
diff --git a/ld/testsuite/ld-x86-64/tlsgd4aligned.s b/ld/testsuite/ld-x86-64/tlsgd4aligned.s
new file mode 100644
index 0000000..b973cbe
--- /dev/null
+++ b/ld/testsuite/ld-x86-64/tlsgd4aligned.s
@@ -0,0 +1,2 @@
+.weakref __tls_get_addr, ___tls_get_addr
+.include "tlsgd4.s"
diff --git a/ld/testsuite/ld-x86-64/tlsgd5aaligned.s b/ld/testsuite/ld-x86-64/tlsgd5aaligned.s
new file mode 100644
index 0000000..30a688c
--- /dev/null
+++ b/ld/testsuite/ld-x86-64/tlsgd5aaligned.s
@@ -0,0 +1,2 @@
+.weakref __tls_get_addr, ___tls_get_addr
+.include "tlsgd5a.s"
diff --git a/ld/testsuite/ld-x86-64/tlsgd5caligned.s b/ld/testsuite/ld-x86-64/tlsgd5caligned.s
new file mode 100644
index 0000000..fc56c65
--- /dev/null
+++ b/ld/testsuite/ld-x86-64/tlsgd5caligned.s
@@ -0,0 +1,2 @@
+.weakref __tls_get_addr, ___tls_get_addr
+.include "tlsgd5c.s"
diff --git a/ld/testsuite/ld-x86-64/tlsgd6aaligned.s b/ld/testsuite/ld-x86-64/tlsgd6aaligned.s
new file mode 100644
index 0000000..d780fdd
--- /dev/null
+++ b/ld/testsuite/ld-x86-64/tlsgd6aaligned.s
@@ -0,0 +1,2 @@
+.weakref __tls_get_addr, ___tls_get_addr
+.include "tlsgd6a.s"
diff --git a/ld/testsuite/ld-x86-64/tlsgd6caligned.s b/ld/testsuite/ld-x86-64/tlsgd6caligned.s
new file mode 100644
index 0000000..a5feba1
--- /dev/null
+++ b/ld/testsuite/ld-x86-64/tlsgd6caligned.s
@@ -0,0 +1,2 @@
+.weakref __tls_get_addr, ___tls_get_addr
+.include "tlsgd6c.s"
diff --git a/ld/testsuite/ld-x86-64/tlsgd7aligned.s b/ld/testsuite/ld-x86-64/tlsgd7aligned.s
new file mode 100644
index 0000000..9731307
--- /dev/null
+++ b/ld/testsuite/ld-x86-64/tlsgd7aligned.s
@@ -0,0 +1,2 @@
+.weakref __tls_get_addr, ___tls_get_addr
+.include "tlsgd7.s"
diff --git a/ld/testsuite/ld-x86-64/tlsgd8aligned.s b/ld/testsuite/ld-x86-64/tlsgd8aligned.s
new file mode 100644
index 0000000..8781b49
--- /dev/null
+++ b/ld/testsuite/ld-x86-64/tlsgd8aligned.s
@@ -0,0 +1,2 @@
+.weakref __tls_get_addr, ___tls_get_addr
+.include "tlsgd8.s"
diff --git a/ld/testsuite/ld-x86-64/tlsgd9aligned.s b/ld/testsuite/ld-x86-64/tlsgd9aligned.s
new file mode 100644
index 0000000..210053c
--- /dev/null
+++ b/ld/testsuite/ld-x86-64/tlsgd9aligned.s
@@ -0,0 +1,2 @@
+.weakref __tls_get_addr, ___tls_get_addr
+.include "tlsgd9.s"
diff --git a/ld/testsuite/ld-x86-64/tlsgdescaligned-nacl.rd b/ld/testsuite/ld-x86-64/tlsgdescaligned-nacl.rd
new file mode 100644
index 0000000..c627bfb
--- /dev/null
+++ b/ld/testsuite/ld-x86-64/tlsgdescaligned-nacl.rd
@@ -0,0 +1,103 @@
+#source: tlsgdescaligned.s
+#as: --64
+#ld: -shared -melf64_x86_64_nacl --no-ld-generated-unwind-info
+#readelf: -WSsrl
+#target: x86_64-*-nacl*
+
+There are [0-9]+ section headers, starting at offset 0x[0-9a-f]+:
+
+Section Headers:
+ +\[Nr\] Name +Type +Address +Off +Size +ES Flg Lk Inf Al
+ +\[[ 0-9]+\] +NULL +0+ 0+ 0+ 0+ +0 +0 +0
+ +\[[ 0-9]+\] \.plt +.*
+ +\[[ 0-9]+\] \.text +.*
+ +\[[ 0-9]+\] \.hash +.*
+ +\[[ 0-9]+\] \.dynsym +.*
+ +\[[ 0-9]+\] \.dynstr +.*
+ +\[[ 0-9]+\] \.rela.dyn +.*
+ +\[[ 0-9]+\] \.rela.plt +.*
+ +\[[ 0-9]+\] \.dynamic +.*
+ +\[[ 0-9]+\] \.got +.*
+ +\[[ 0-9]+\] \.got.plt +.*
+ +\[[ 0-9]+\] \.symtab +.*
+ +\[[ 0-9]+\] \.strtab +.*
+ +\[[ 0-9]+\] \.shstrtab +.*
+Key to Flags:
+#...
+
+Elf file type is DYN \(Shared object file\)
+Entry point 0x[0-9a-f]+
+There are [0-9]+ program headers, starting at offset [0-9]+
+
+Program Headers:
+ +Type +Offset +VirtAddr +PhysAddr +FileSiz +MemSiz +Flg Align
+ +LOAD.*
+ +LOAD.*
+ +LOAD.*
+ +DYNAMIC.*
+
+ Section to Segment mapping:
+ +Segment Sections...
+ +00 +.plt .text *
+ +01 +.hash .dynsym .dynstr .rela.dyn .rela.plt *
+ +02 +.dynamic .got .got.plt *
+ +03 +.dynamic *
+
+Relocation section '.rela.dyn' at offset 0x[0-9a-f]+ contains 8 entries:
+ +Offset +Info +Type +Symbol's Value +Symbol's Name \+ Addend
+[0-9a-f]+ +0+100000012 R_X86_64_TPOFF64 +0+ sG3 \+ 0
+[0-9a-f]+ +0+200000012 R_X86_64_TPOFF64 +0+ sG5 \+ 0
+[0-9a-f]+ +0+300000010 R_X86_64_DTPMOD64 +0+ sG2 \+ 0
+[0-9a-f]+ +0+300000011 R_X86_64_DTPOFF64 +0+ sG2 \+ 0
+[0-9a-f]+ +0+400000012 R_X86_64_TPOFF64 +0+ sG4 \+ 0
+[0-9a-f]+ +0+600000012 R_X86_64_TPOFF64 +0+ sG6 \+ 0
+[0-9a-f]+ +0+800000010 R_X86_64_DTPMOD64 +0+ sG1 \+ 0
+[0-9a-f]+ +0+800000011 R_X86_64_DTPOFF64 +0+ sG1 \+ 0
+
+Relocation section '.rela.plt' at offset 0x[0-9a-f]+ contains 3 entries:
+ +Offset +Info +Type +Symbol's Value +Symbol's Name \+ Addend
+[0-9a-f]+ +0+b00000007 R_X86_64_JUMP_SLOT +0+ ___tls_get_addr \+ 0
+[0-9a-f]+ +0+800000024 R_X86_64_TLSDESC +0+ sG1 \+ 0
+[0-9a-f]+ +0+300000024 R_X86_64_TLSDESC +0+ sG2 \+ 0
+
+Symbol table '\.dynsym' contains [0-9]+ entries:
+ +Num: +Value +Size +Type +Bind +Vis +Ndx +Name
+ +[0-9]+: 0+ +0 +NOTYPE +LOCAL +DEFAULT +UND *
+ +[0-9]+: 0+ +0 +TLS +GLOBAL +DEFAULT +UND sG3
+ +[0-9]+: 0+ +0 +TLS +GLOBAL +DEFAULT +UND sG5
+ +[0-9]+: 0+ +0 +TLS +GLOBAL +DEFAULT +UND sG2
+ +[0-9]+: 0+ +0 +TLS +GLOBAL +DEFAULT +UND sG4
+ +[0-9]+: [0-9a-f]+ +0 +NOTYPE +GLOBAL +DEFAULT +10 __bss_start
+ +[0-9]+: 0+ +0 +TLS +GLOBAL +DEFAULT +UND sG6
+ +[0-9]+: [0-9a-f]+ +0 +FUNC +GLOBAL +DEFAULT +2 fc1
+ +[0-9]+: 0+ +0 +TLS +GLOBAL +DEFAULT +UND sG1
+ +[0-9]+: [0-9a-f]+ +0 +NOTYPE +GLOBAL +DEFAULT +10 _edata
+ +[0-9]+: [0-9a-f]+ +0 +NOTYPE +GLOBAL +DEFAULT +10 _end
+ +[0-9]+: 0+ +0 +NOTYPE +GLOBAL +DEFAULT +UND ___tls_get_addr
+
+Symbol table '\.symtab' contains [0-9]+ entries:
+ +Num: +Value +Size +Type +Bind +Vis +Ndx +Name
+ +[0-9]+: 0+ +0 +NOTYPE +LOCAL +DEFAULT +UND *
+ +[0-9]+: [0-9a-f]+ +0 +SECTION +LOCAL +DEFAULT +1 *
+ +[0-9]+: [0-9a-f]+ +0 +SECTION +LOCAL +DEFAULT +2 *
+ +[0-9]+: [0-9a-f]+ +0 +SECTION +LOCAL +DEFAULT +3 *
+ +[0-9]+: [0-9a-f]+ +0 +SECTION +LOCAL +DEFAULT +4 *
+ +[0-9]+: [0-9a-f]+ +0 +SECTION +LOCAL +DEFAULT +5 *
+ +[0-9]+: [0-9a-f]+ +0 +SECTION +LOCAL +DEFAULT +6 *
+ +[0-9]+: [0-9a-f]+ +0 +SECTION +LOCAL +DEFAULT +7 *
+ +[0-9]+: [0-9a-f]+ +0 +SECTION +LOCAL +DEFAULT +8 *
+ +[0-9]+: [0-9a-f]+ +0 +SECTION +LOCAL +DEFAULT +9 *
+ +[0-9]+: [0-9a-f]+ +0 +SECTION +LOCAL +DEFAULT +10 *
+ +[0-9]+: [0-9a-f]+ +0 +OBJECT +LOCAL +DEFAULT +8 _DYNAMIC
+ +[0-9]+: [0-9a-f]+ +0 +OBJECT +LOCAL +DEFAULT +10 _GLOBAL_OFFSET_TABLE_
+ +[0-9]+: 0+ +0 +TLS +GLOBAL +DEFAULT +UND sG3
+ +[0-9]+: 0+ +0 +TLS +GLOBAL +DEFAULT +UND sG5
+ +[0-9]+: 0+ +0 +TLS +GLOBAL +DEFAULT +UND sG2
+ +[0-9]+: 0+ +0 +TLS +GLOBAL +DEFAULT +UND sG4
+ +[0-9]+: [0-9a-f]+ +0 +NOTYPE +GLOBAL +DEFAULT +10 __bss_start
+ +[0-9]+: 0+ +0 +TLS +GLOBAL +DEFAULT +UND sG6
+ +[0-9]+: [0-9a-f]+ +0 +FUNC +GLOBAL +DEFAULT +2 fc1
+ +[0-9]+: 0+ +0 +TLS +GLOBAL +DEFAULT +UND sG1
+ +[0-9]+: [0-9a-f]+ +0 +NOTYPE +GLOBAL +DEFAULT +10 _edata
+ +[0-9]+: [0-9a-f]+ +0 +NOTYPE +GLOBAL +DEFAULT +10 _end
+ +[0-9]+: 0+ +0 +NOTYPE +GLOBAL +DEFAULT +UND ___tls_get_addr
diff --git a/ld/testsuite/ld-x86-64/tlsgdescaligned.dd b/ld/testsuite/ld-x86-64/tlsgdescaligned.dd
new file mode 100644
index 0000000..7b2f514
--- /dev/null
+++ b/ld/testsuite/ld-x86-64/tlsgdescaligned.dd
@@ -0,0 +1,163 @@
+#source: tlsgdescaligned.s
+#as: --64
+#ld: -shared -melf_x86_64 --no-ld-generated-unwind-info
+#objdump: -drj.text -Mintel64
+#target: x86_64-*-*
+
+.*: +file format elf64-x86-64.*
+
+Disassembly of section .text:
+
+0+[0-9a-f]+ <fc1>:
+ +[0-9a-f]+:	55[ 	]+push   %rbp
+ +[0-9a-f]+:	48 89 e5[ 	]+mov    %rsp,%rbp
+ +[0-9a-f]+:	90[ 	]+nop *
+ +[0-9a-f]+:	90[ 	]+nop *
+ +[0-9a-f]+:	90[ 	]+nop *
+ +[0-9a-f]+:	90[ 	]+nop *
+# IE
+ +[0-9a-f]+:	64 48 8b 0c 25 00 00[ 	]+mov    %fs:0x0,%rcx
+ +[0-9a-f]+:	00 00 *
+ +[0-9a-f]+:	90[ 	]+nop *
+ +[0-9a-f]+:	90[ 	]+nop *
+ +[0-9a-f]+:	48 03 0d ([0-9a-f]{2} ){4}[ 	]+add    0x[0-9a-f]+\(%rip\),%rcx +# [0-9a-f]+ <.*>
+#				-> R_X86_64_TPOFF64	sG3
+ +[0-9a-f]+:	90[ 	]+nop *
+ +[0-9a-f]+:	90[ 	]+nop *
+ +[0-9a-f]+:	90[ 	]+nop *
+ +[0-9a-f]+:	90[ 	]+nop *
+# IE
+ +[0-9a-f]+:	64 48 8b 0c 25 00 00[ 	]+mov    %fs:0x0,%rcx
+ +[0-9a-f]+:	00 00 *
+ +[0-9a-f]+:	90[ 	]+nop *
+ +[0-9a-f]+:	90[ 	]+nop *
+ +[0-9a-f]+:	48 03 0d ([0-9a-f]{2} ){4}[ 	]+add    0x[0-9a-f]+\(%rip\),%rcx +# [0-9a-f]+ <.*>
+#				-> R_X86_64_TPOFF64	sG4
+ +[0-9a-f]+:	90[ 	]+nop *
+ +[0-9a-f]+:	90[ 	]+nop *
+ +[0-9a-f]+:	90[ 	]+nop *
+ +[0-9a-f]+:	90[ 	]+nop *
+# GD, gd first
+ +[0-9a-f]+:	66 48 8d 3d ([0-9a-f]{2} ){3}[ 	]+data16 lea 0x[0-9a-f]+\(%rip\),%rdi +# [0-9a-f]+ <.*>
+ +[0-9a-f]+:	[0-9a-f]{2} *
+#				-> R_X86_64_DTPMOD64	sG1
+ +[0-9a-f]+:	66 66 48 e8 ([0-9a-f]{2} ){3}[ 	]+data16 data16 rex.W callq [0-9a-f]+ <___tls_get_addr@plt>
+ +[0-9a-f]+:	[0-9a-f]{2} *
+#				-> R_X86_64_JUMP_SLOT	___tls_get_addr
+ +[0-9a-f]+:	90[ 	]+nop *
+ +[0-9a-f]+:	90[ 	]+nop *
+ +[0-9a-f]+:	90[ 	]+nop *
+ +[0-9a-f]+:	90[ 	]+nop *
+ +[0-9a-f]+:	48 8d 05 ([0-9a-f]{2} ){4}[ 	]+lea    0x[0-9a-f]+\(%rip\),%rax +# [0-9a-f]+ <.*>
+#				-> R_X86_64_TLSDESC	sG1
+ +[0-9a-f]+:	ff 10[ 	]+callq  \*\(%rax\)
+ +[0-9a-f]+:	90[ 	]+nop *
+ +[0-9a-f]+:	90[ 	]+nop *
+ +[0-9a-f]+:	90[ 	]+nop *
+ +[0-9a-f]+:	90[ 	]+nop *
+# GD, desc first
+ +[0-9a-f]+:	48 8d 05 ([0-9a-f]{2} ){4}[ 	]+lea    0x[0-9a-f]+\(%rip\),%rax +# [0-9a-f]+ <.*>
+#				-> R_X86_64_TLSDESC	sG2
+ +[0-9a-f]+:	ff 10[ 	]+callq  \*\(%rax\)
+ +[0-9a-f]+:	90[ 	]+nop *
+ +[0-9a-f]+:	90[ 	]+nop *
+ +[0-9a-f]+:	90[ 	]+nop *
+ +[0-9a-f]+:	90[ 	]+nop *
+ +[0-9a-f]+:	66 48 8d 3d ([0-9a-f]{2} ){3}[ 	]+data16 lea 0x[0-9a-f]+\(%rip\),%rdi +# [0-9a-f]+ <.*>
+ +[0-9a-f]+:	[0-9a-f]{2} *
+#				-> R_X86_64_DTPMOD64	sG2
+ +[0-9a-f]+:	66 66 48 e8 ([0-9a-f]{2} ){3}[ 	]+data16 data16 rex.W callq [0-9a-f]+ <___tls_get_addr@plt>
+ +[0-9a-f]+:	[0-9a-f]{2} *
+#				-> R_X86_64_JUMP_SLOT	___tls_get_addr
+ +[0-9a-f]+:	90[ 	]+nop *
+ +[0-9a-f]+:	90[ 	]+nop *
+ +[0-9a-f]+:	90[ 	]+nop *
+ +[0-9a-f]+:	90[ 	]+nop *
+# GD -> IE, gd first, after IE use
+ +[0-9a-f]+:	64 48 8b 04 25 00 00[ 	]+mov    %fs:0x0,%rax
+ +[0-9a-f]+:	00 00 *
+ +[0-9a-f]+:	48 03 05 ([0-9a-f]{2} ){4}[ 	]+add    0x[0-9a-f]+\(%rip\),%rax +# [0-9a-f]+ <.*>
+#				-> R_X86_64_TPOFF64	sG3
+ +[0-9a-f]+:	90[ 	]+nop *
+ +[0-9a-f]+:	90[ 	]+nop *
+ +[0-9a-f]+:	90[ 	]+nop *
+ +[0-9a-f]+:	90[ 	]+nop *
+ +[0-9a-f]+:	48 8b 05 ([0-9a-f]{2} ){4}[ 	]+mov    0x[0-9a-f]+\(%rip\),%rax +# [0-9a-f]+ <.*>
+#				-> R_X86_64_TPOFF64	sG3
+ +[0-9a-f]+:	66 90[ 	]+xchg   %ax,%ax
+ +[0-9a-f]+:	90[ 	]+nop *
+ +[0-9a-f]+:	90[ 	]+nop *
+ +[0-9a-f]+:	90[ 	]+nop *
+ +[0-9a-f]+:	90[ 	]+nop *
+# GD -> IE, desc first, after IE use
+ +[0-9a-f]+:	48 8b 05 ([0-9a-f]{2} ){4}[ 	]+mov    0x[0-9a-f]+\(%rip\),%rax +# [0-9a-f]+ <.*>
+#				-> R_X86_64_TPOFF64	sG4
+ +[0-9a-f]+:	66 90[ 	]+xchg   %ax,%ax
+ +[0-9a-f]+:	90[ 	]+nop *
+ +[0-9a-f]+:	90[ 	]+nop *
+ +[0-9a-f]+:	90[ 	]+nop *
+ +[0-9a-f]+:	90[ 	]+nop *
+ +[0-9a-f]+:	64 48 8b 04 25 00 00[ 	]+mov    %fs:0x0,%rax
+ +[0-9a-f]+:	00 00 *
+ +[0-9a-f]+:	48 03 05 ([0-9a-f]{2} ){4}[ 	]+add    0x[0-9a-f]+\(%rip\),%rax +# [0-9a-f]+ <.*>
+#				-> R_X86_64_TPOFF64	sG4
+ +[0-9a-f]+:	90[ 	]+nop *
+ +[0-9a-f]+:	90[ 	]+nop *
+ +[0-9a-f]+:	90[ 	]+nop *
+ +[0-9a-f]+:	90[ 	]+nop *
+# GD -> IE, gd first, before IE use
+ +[0-9a-f]+:	64 48 8b 04 25 00 00[ 	]+mov    %fs:0x0,%rax
+ +[0-9a-f]+:	00 00 *
+ +[0-9a-f]+:	48 03 05 ([0-9a-f]{2} ){4}[ 	]+add    0x[0-9a-f]+\(%rip\),%rax +# [0-9a-f]+ <.*>
+#				-> R_X86_64_TPOFF64	sG5
+ +[0-9a-f]+:	90[ 	]+nop *
+ +[0-9a-f]+:	90[ 	]+nop *
+ +[0-9a-f]+:	90[ 	]+nop *
+ +[0-9a-f]+:	90[ 	]+nop *
+ +[0-9a-f]+:	48 8b 05 ([0-9a-f]{2} ){4}[ 	]+mov    0x[0-9a-f]+\(%rip\),%rax +# [0-9a-f]+ <.*>
+#				-> R_X86_64_TPOFF64	sG5
+ +[0-9a-f]+:	66 90[ 	]+xchg   %ax,%ax
+ +[0-9a-f]+:	90[ 	]+nop *
+ +[0-9a-f]+:	90[ 	]+nop *
+ +[0-9a-f]+:	90[ 	]+nop *
+ +[0-9a-f]+:	90[ 	]+nop *
+# GD -> IE, desc first, before IE use
+ +[0-9a-f]+:	48 8b 05 ([0-9a-f]{2} ){4}[ 	]+mov    0x[0-9a-f]+\(%rip\),%rax +# [0-9a-f]+ <.*>
+#				-> R_X86_64_TPOFF64	sG6
+ +[0-9a-f]+:	66 90[ 	]+xchg   %ax,%ax
+ +[0-9a-f]+:	90[ 	]+nop *
+ +[0-9a-f]+:	90[ 	]+nop *
+ +[0-9a-f]+:	90[ 	]+nop *
+ +[0-9a-f]+:	90[ 	]+nop *
+ +[0-9a-f]+:	64 48 8b 04 25 00 00[ 	]+mov    %fs:0x0,%rax
+ +[0-9a-f]+:	00 00 *
+ +[0-9a-f]+:	48 03 05 ([0-9a-f]{2} ){4}[ 	]+add    0x[0-9a-f]+\(%rip\),%rax +# [0-9a-f]+ <.*>
+#				-> R_X86_64_TPOFF64	sG6
+ +[0-9a-f]+:	90[ 	]+nop *
+ +[0-9a-f]+:	90[ 	]+nop *
+ +[0-9a-f]+:	90[ 	]+nop *
+ +[0-9a-f]+:	90[ 	]+nop *
+# IE
+ +[0-9a-f]+:	64 48 8b 0c 25 00 00[ 	]+mov    %fs:0x0,%rcx
+ +[0-9a-f]+:	00 00 *
+ +[0-9a-f]+:	90[ 	]+nop *
+ +[0-9a-f]+:	90[ 	]+nop *
+ +[0-9a-f]+:	48 03 0d ([0-9a-f]{2} ){4}[ 	]+add    0x[0-9a-f]+\(%rip\),%rcx +# [0-9a-f]+ <.*>
+#				-> R_X86_64_TPOFF64	sG5
+ +[0-9a-f]+:	90[ 	]+nop *
+ +[0-9a-f]+:	90[ 	]+nop *
+ +[0-9a-f]+:	90[ 	]+nop *
+ +[0-9a-f]+:	90[ 	]+nop *
+# IE
+ +[0-9a-f]+:	64 48 8b 0c 25 00 00[ 	]+mov    %fs:0x0,%rcx
+ +[0-9a-f]+:	00 00 *
+ +[0-9a-f]+:	90[ 	]+nop *
+ +[0-9a-f]+:	90[ 	]+nop *
+ +[0-9a-f]+:	48 03 0d ([0-9a-f]{2} ){4}[ 	]+add    0x[0-9a-f]+\(%rip\),%rcx +# [0-9a-f]+ <.*>
+#				-> R_X86_64_TPOFF64	sG6
+ +[0-9a-f]+:	90[ 	]+nop *
+ +[0-9a-f]+:	90[ 	]+nop *
+ +[0-9a-f]+:	90[ 	]+nop *
+ +[0-9a-f]+:	90[ 	]+nop *
+ +[0-9a-f]+:	c9[ 	]+leaveq *
+ +[0-9a-f]+:	c3[ 	]+retq *
diff --git a/ld/testsuite/ld-x86-64/tlsgdescaligned.rd b/ld/testsuite/ld-x86-64/tlsgdescaligned.rd
new file mode 100644
index 0000000..3ff0ebd
--- /dev/null
+++ b/ld/testsuite/ld-x86-64/tlsgdescaligned.rd
@@ -0,0 +1,101 @@
+#source: tlsgdescaligned.s
+#as: --64
+#ld: -shared -melf64_x86_64 --no-ld-generated-unwind-info
+#readelf: -WSsrl
+#target: x86_64-*-*
+
+There are [0-9]+ section headers, starting at offset 0x[0-9a-f]+:
+
+Section Headers:
+ +\[Nr\] Name +Type +Address +Off +Size +ES Flg Lk Inf Al
+ +\[[ 0-9]+\] +NULL +0+ 0+ 0+ 0+ +0 +0 +0
+ +\[[ 0-9]+\] \.hash +.*
+ +\[[ 0-9]+\] \.dynsym +.*
+ +\[[ 0-9]+\] \.dynstr +.*
+ +\[[ 0-9]+\] \.rela.dyn +.*
+ +\[[ 0-9]+\] \.rela.plt +.*
+ +\[[ 0-9]+\] \.plt +.*
+ +\[[ 0-9]+\] \.text +.*
+ +\[[ 0-9]+\] \.dynamic +.*
+ +\[[ 0-9]+\] \.got +.*
+ +\[[ 0-9]+\] \.got.plt +.*
+ +\[[ 0-9]+\] \.symtab +.*
+ +\[[ 0-9]+\] \.strtab +.*
+ +\[[ 0-9]+\] \.shstrtab +.*
+Key to Flags:
+#...
+
+Elf file type is DYN \(Shared object file\)
+Entry point 0x[0-9a-f]+
+There are [0-9]+ program headers, starting at offset [0-9]+
+
+Program Headers:
+ +Type +Offset +VirtAddr +PhysAddr +FileSiz +MemSiz +Flg Align
+ +LOAD.*
+ +LOAD.*
+ +DYNAMIC.*
+
+ Section to Segment mapping:
+ +Segment Sections...
+ +00 +.hash .dynsym .dynstr .rela.dyn .rela.plt .plt .text *
+ +01 +.dynamic .got .got.plt *
+ +02 +.dynamic *
+
+Relocation section '.rela.dyn' at offset 0x[0-9a-f]+ contains 8 entries:
+ +Offset +Info +Type +Symbol's Value +Symbol's Name \+ Addend
+[0-9a-f]+ +0+100000012 R_X86_64_TPOFF64 +0+ sG3 \+ 0
+[0-9a-f]+ +0+200000012 R_X86_64_TPOFF64 +0+ sG5 \+ 0
+[0-9a-f]+ +0+300000010 R_X86_64_DTPMOD64 +0+ sG2 \+ 0
+[0-9a-f]+ +0+300000011 R_X86_64_DTPOFF64 +0+ sG2 \+ 0
+[0-9a-f]+ +0+400000012 R_X86_64_TPOFF64 +0+ sG4 \+ 0
+[0-9a-f]+ +0+600000012 R_X86_64_TPOFF64 +0+ sG6 \+ 0
+[0-9a-f]+ +0+800000010 R_X86_64_DTPMOD64 +0+ sG1 \+ 0
+[0-9a-f]+ +0+800000011 R_X86_64_DTPOFF64 +0+ sG1 \+ 0
+
+Relocation section '.rela.plt' at offset 0x[0-9a-f]+ contains 3 entries:
+ +Offset +Info +Type +Symbol's Value +Symbol's Name \+ Addend
+[0-9a-f]+ +0+b00000007 R_X86_64_JUMP_SLOT +0+ ___tls_get_addr \+ 0
+[0-9a-f]+ +0+800000024 R_X86_64_TLSDESC +0+ sG1 \+ 0
+[0-9a-f]+ +0+300000024 R_X86_64_TLSDESC +0+ sG2 \+ 0
+
+Symbol table '\.dynsym' contains [0-9]+ entries:
+ +Num: +Value +Size +Type +Bind +Vis +Ndx +Name
+ +[0-9]+: 0+ +0 +NOTYPE +LOCAL +DEFAULT +UND *
+ +[0-9]+: 0+ +0 +TLS +GLOBAL +DEFAULT +UND sG3
+ +[0-9]+: 0+ +0 +TLS +GLOBAL +DEFAULT +UND sG5
+ +[0-9]+: 0+ +0 +TLS +GLOBAL +DEFAULT +UND sG2
+ +[0-9]+: 0+ +0 +TLS +GLOBAL +DEFAULT +UND sG4
+ +[0-9]+: [0-9a-f]+ +0 +NOTYPE +GLOBAL +DEFAULT +10 __bss_start
+ +[0-9]+: 0+ +0 +TLS +GLOBAL +DEFAULT +UND sG6
+ +[0-9]+: [0-9a-f]+ +0 +FUNC +GLOBAL +DEFAULT +7 fc1
+ +[0-9]+: 0+ +0 +TLS +GLOBAL +DEFAULT +UND sG1
+ +[0-9]+: [0-9a-f]+ +0 +NOTYPE +GLOBAL +DEFAULT +10 _edata
+ +[0-9]+: [0-9a-f]+ +0 +NOTYPE +GLOBAL +DEFAULT +10 _end
+ +[0-9]+: 0+ +0 +NOTYPE +GLOBAL +DEFAULT +UND ___tls_get_addr
+
+Symbol table '\.symtab' contains [0-9]+ entries:
+ +Num: +Value +Size +Type +Bind +Vis +Ndx +Name
+ +[0-9]+: 0+ +0 +NOTYPE +LOCAL +DEFAULT +UND *
+ +[0-9]+: [0-9a-f]+ +0 +SECTION +LOCAL +DEFAULT +1 *
+ +[0-9]+: [0-9a-f]+ +0 +SECTION +LOCAL +DEFAULT +2 *
+ +[0-9]+: [0-9a-f]+ +0 +SECTION +LOCAL +DEFAULT +3 *
+ +[0-9]+: [0-9a-f]+ +0 +SECTION +LOCAL +DEFAULT +4 *
+ +[0-9]+: [0-9a-f]+ +0 +SECTION +LOCAL +DEFAULT +5 *
+ +[0-9]+: [0-9a-f]+ +0 +SECTION +LOCAL +DEFAULT +6 *
+ +[0-9]+: [0-9a-f]+ +0 +SECTION +LOCAL +DEFAULT +7 *
+ +[0-9]+: [0-9a-f]+ +0 +SECTION +LOCAL +DEFAULT +8 *
+ +[0-9]+: [0-9a-f]+ +0 +SECTION +LOCAL +DEFAULT +9 *
+ +[0-9]+: [0-9a-f]+ +0 +SECTION +LOCAL +DEFAULT +10 *
+ +[0-9]+: [0-9a-f]+ +0 +OBJECT +LOCAL +DEFAULT +8 _DYNAMIC
+ +[0-9]+: [0-9a-f]+ +0 +OBJECT +LOCAL +DEFAULT +10 _GLOBAL_OFFSET_TABLE_
+ +[0-9]+: 0+ +0 +TLS +GLOBAL +DEFAULT +UND sG3
+ +[0-9]+: 0+ +0 +TLS +GLOBAL +DEFAULT +UND sG5
+ +[0-9]+: 0+ +0 +TLS +GLOBAL +DEFAULT +UND sG2
+ +[0-9]+: 0+ +0 +TLS +GLOBAL +DEFAULT +UND sG4
+ +[0-9]+: [0-9a-f]+ +0 +NOTYPE +GLOBAL +DEFAULT +10 __bss_start
+ +[0-9]+: 0+ +0 +TLS +GLOBAL +DEFAULT +UND sG6
+ +[0-9]+: [0-9a-f]+ +0 +FUNC +GLOBAL +DEFAULT +7 fc1
+ +[0-9]+: 0+ +0 +TLS +GLOBAL +DEFAULT +UND sG1
+ +[0-9]+: [0-9a-f]+ +0 +NOTYPE +GLOBAL +DEFAULT +10 _edata
+ +[0-9]+: [0-9a-f]+ +0 +NOTYPE +GLOBAL +DEFAULT +10 _end
+ +[0-9]+: 0+ +0 +NOTYPE +GLOBAL +DEFAULT +UND ___tls_get_addr
diff --git a/ld/testsuite/ld-x86-64/tlsgdescaligned.s b/ld/testsuite/ld-x86-64/tlsgdescaligned.s
new file mode 100644
index 0000000..932ac79
--- /dev/null
+++ b/ld/testsuite/ld-x86-64/tlsgdescaligned.s
@@ -0,0 +1,2 @@
+.weakref __tls_get_addr, ___tls_get_addr
+.include "tlsgdesc.s"
diff --git a/ld/testsuite/ld-x86-64/tlsld1aligned.s b/ld/testsuite/ld-x86-64/tlsld1aligned.s
new file mode 100644
index 0000000..17f5687
--- /dev/null
+++ b/ld/testsuite/ld-x86-64/tlsld1aligned.s
@@ -0,0 +1,2 @@
+.weakref __tls_get_addr, ___tls_get_addr
+.include "tlsld1.s"
diff --git a/ld/testsuite/ld-x86-64/tlsld2aligned.s b/ld/testsuite/ld-x86-64/tlsld2aligned.s
new file mode 100644
index 0000000..3f021de
--- /dev/null
+++ b/ld/testsuite/ld-x86-64/tlsld2aligned.s
@@ -0,0 +1,2 @@
+.weakref __tls_get_addr, ___tls_get_addr
+.include "tlsld2.s"
diff --git a/ld/testsuite/ld-x86-64/tlsld3aligned.s b/ld/testsuite/ld-x86-64/tlsld3aligned.s
new file mode 100644
index 0000000..b0fdc6f
--- /dev/null
+++ b/ld/testsuite/ld-x86-64/tlsld3aligned.s
@@ -0,0 +1,2 @@
+.weakref __tls_get_addr, ___tls_get_addr
+.include "tlsld3.s"
diff --git a/ld/testsuite/ld-x86-64/tlsld4aligned.s b/ld/testsuite/ld-x86-64/tlsld4aligned.s
new file mode 100644
index 0000000..79ece97
--- /dev/null
+++ b/ld/testsuite/ld-x86-64/tlsld4aligned.s
@@ -0,0 +1,2 @@
+.weakref __tls_get_addr, ___tls_get_addr
+.include "tlsld4.s"
diff --git a/ld/testsuite/ld-x86-64/tlsld5aligned.s b/ld/testsuite/ld-x86-64/tlsld5aligned.s
new file mode 100644
index 0000000..796efb7
--- /dev/null
+++ b/ld/testsuite/ld-x86-64/tlsld5aligned.s
@@ -0,0 +1,2 @@
+.weakref __tls_get_addr, ___tls_get_addr
+.include "tlsld5.s"
diff --git a/ld/testsuite/ld-x86-64/tlsld6aligned.s b/ld/testsuite/ld-x86-64/tlsld6aligned.s
new file mode 100644
index 0000000..5b6ca41
--- /dev/null
+++ b/ld/testsuite/ld-x86-64/tlsld6aligned.s
@@ -0,0 +1,2 @@
+.weakref __tls_get_addr, ___tls_get_addr
+.include "tlsld6.s"
diff --git a/ld/testsuite/ld-x86-64/tlslibaligned.s b/ld/testsuite/ld-x86-64/tlslibaligned.s
new file mode 100644
index 0000000..2f0370c
--- /dev/null
+++ b/ld/testsuite/ld-x86-64/tlslibaligned.s
@@ -0,0 +1,18 @@
+	.section ".tdata", "awT", @progbits
+	.globl sG1, sG2, sG3, sG4, sG5, sG6, sG7, sG8
+sG1:	.long 513
+sG2:	.long 514
+sG3:	.long 515
+sG4:	.long 516
+sG5:	.long 517
+sG6:	.long 518
+sG7:	.long 519
+sG8:	.long 520
+
+	.text
+	/* Dummy.  */
+	.globl ___tls_get_addr
+	.type   ___tls_get_addr,@function
+___tls_get_addr:
+	movq	%rdi, %rax
+	ret
diff --git a/ld/testsuite/ld-x86-64/tlspic1aligned.s b/ld/testsuite/ld-x86-64/tlspic1aligned.s
new file mode 100644
index 0000000..9c002eb
--- /dev/null
+++ b/ld/testsuite/ld-x86-64/tlspic1aligned.s
@@ -0,0 +1,2 @@
+.weakref __tls_get_addr, ___tls_get_addr
+.include "tlspic1.s"
diff --git a/ld/testsuite/ld-x86-64/tlspic2aligned-nacl.rd b/ld/testsuite/ld-x86-64/tlspic2aligned-nacl.rd
new file mode 100644
index 0000000..9e6b66d
--- /dev/null
+++ b/ld/testsuite/ld-x86-64/tlspic2aligned-nacl.rd
@@ -0,0 +1,145 @@
+#source: tlspic3aligned.s
+#source: tlspic2.s
+#as: --64
+#ld: -shared -melf_x86_64_nacl --no-ld-generated-unwind-info
+#readelf: -WSsrl
+#target: x86_64-*-nacl*
+
+There are [0-9]+ section headers, starting at offset 0x[0-9a-f]+:
+
+Section Headers:
+ +\[Nr\] Name +Type +Address +Off +Size +ES Flg Lk Inf Al
+ +\[[ 0-9]+\] +NULL +0+ 0+ 0+ 00 +0 +0 +0
+ +\[[ 0-9]+\] .plt +.*
+ +\[[ 0-9]+\] .text +PROGBITS +0+1000 [0-9a-f]+ 0+31a 00 +AX +0 +0 4096
+ +\[[ 0-9]+\] .hash +.*
+ +\[[ 0-9]+\] .dynsym +.*
+ +\[[ 0-9]+\] .dynstr +.*
+ +\[[ 0-9]+\] .rela.dyn +.*
+ +\[[ 0-9]+\] .rela.plt +.*
+ +\[[ 0-9]+\] .tdata +PROGBITS +0+100104c8 [0-9a-f]+ 0+60 00 WAT +0 +0 +1
+ +\[[ 0-9]+\] .tbss +NOBITS +0+10010528 [0-9a-f]+ 0+20 00 WAT +0 +0 +1
+ +\[[ 0-9]+\] .dynamic +DYNAMIC +0+10010528 [0-9a-f]+ 0+130 10 +WA +5 +0 +8
+ +\[[ 0-9]+\] .got +PROGBITS +0+10010658 [0-9a-f]+ 0+98 08 +WA +0 +0 +8
+ +\[[ 0-9]+\] .got.plt +PROGBITS +0+100106f0 [0-9a-f]+ 0+20 08 +WA +0 +0 +8
+ +\[[ 0-9]+\] .symtab +.*
+ +\[[ 0-9]+\] .strtab +.*
+ +\[[ 0-9]+\] .shstrtab +.*
+Key to Flags:
+#...
+
+Elf file type is DYN \(Shared object file\)
+Entry point 0x1000
+There are [0-9]+ program headers, starting at offset [0-9]+
+
+Program Headers:
+ +Type +Offset +VirtAddr +PhysAddr +FileSiz +MemSiz +Flg Align
+ +LOAD +0x0+10000 0x0+ 0x0+ 0x[0-9a-f]+ 0x[0-9a-f]+ R E 0x10000
+ +LOAD +0x0+ 0x0+10000000 0x0+10000000 0x0+4c8 0x0+4c8 R +0x10000
+ +LOAD +0x0+4c8 0x0+100104c8 0x0+100104c8 0x0+248 0x0+248 RW +0x10000
+ +DYNAMIC +0x0+528 0x0+10010528 0x0+10010528 0x0+130 0x0+130 RW +0x8
+ +TLS +0x0+4c8 0x0+100104c8 0x0+100104c8 0x0+60 0x0+80 R +0x1
+
+ Section to Segment mapping:
+ +Segment Sections...
+ +00 +.plt .text *
+ +01 +.hash .dynsym .dynstr .rela.dyn .rela.plt *
+ +02 +.tdata .dynamic .got .got.plt *
+ +03 +.dynamic *
+ +04 +.tdata .tbss *
+
+Relocation section '.rela.dyn' at offset 0x[0-9a-f]+ contains 15 entries:
+ +Offset +Info +Type +Symbol's Value +Symbol's Name \+ Addend
+[0-9a-f ]+R_X86_64_DTPMOD64 +0
+[0-9a-f ]+R_X86_64_TPOFF64 +24
+[0-9a-f ]+R_X86_64_TPOFF64 +30
+[0-9a-f ]+R_X86_64_DTPMOD64 +0
+[0-9a-f ]+R_X86_64_DTPMOD64 +0
+[0-9a-f ]+R_X86_64_TPOFF64 +64
+[0-9a-f ]+R_X86_64_TPOFF64 +50
+[0-9a-f ]+R_X86_64_TPOFF64 +70
+[0-9a-f ]+R_X86_64_DTPMOD64 +0
+[0-9a-f ]+R_X86_64_TPOFF64 +44
+[0-9a-f ]+R_X86_64_TPOFF64 +0+10 sg5 \+ 0
+[0-9a-f ]+R_X86_64_DTPMOD64 +0+ sg1 \+ 0
+[0-9a-f ]+R_X86_64_DTPOFF64 +0+ sg1 \+ 0
+[0-9a-f ]+R_X86_64_TPOFF64 +0+4 sg2 \+ 0
+[0-9a-f ]+R_X86_64_GLOB_DAT +0+ ___tls_get_addr \+ 0
+
+Relocation section '.rela.plt' at offset 0x[0-9a-f]+ contains 1 entries:
+ +Offset +Info +Type +Symbol's Value +Symbol's Name \+ Addend
+[0-9a-f ]+R_X86_64_JUMP_SLOT +0+ ___tls_get_addr \+ 0
+
+Symbol table '\.dynsym' contains [0-9]+ entries:
+ +Num: +Value +Size +Type +Bind +Vis +Ndx +Name
+.* NOTYPE +LOCAL +DEFAULT +UND *
+.* TLS +GLOBAL +DEFAULT +8 sg8
+.* TLS +GLOBAL +DEFAULT +8 sg3
+.* TLS +GLOBAL +DEFAULT +8 sg4
+.* TLS +GLOBAL +DEFAULT +8 sg5
+.* TLS +GLOBAL +DEFAULT +8 sg1
+.* FUNC +GLOBAL +DEFAULT +2 fn1
+.* NOTYPE +GLOBAL +DEFAULT +12 __bss_start
+.* TLS +GLOBAL +DEFAULT +8 sg2
+.* TLS +GLOBAL +DEFAULT +8 sg6
+.* TLS +GLOBAL +DEFAULT +8 sg7
+.* NOTYPE +GLOBAL +DEFAULT +12 _edata
+.* NOTYPE +GLOBAL +DEFAULT +12 _end
+.* NOTYPE +GLOBAL +DEFAULT +UND ___tls_get_addr
+
+Symbol table '\.symtab' contains [0-9]+ entries:
+ +Num: +Value +Size +Type +Bind +Vis +Ndx +Name
+.* NOTYPE +LOCAL +DEFAULT +UND *
+.* SECTION +LOCAL +DEFAULT +1 *
+.* SECTION +LOCAL +DEFAULT +2 *
+.* SECTION +LOCAL +DEFAULT +3 *
+.* SECTION +LOCAL +DEFAULT +4 *
+.* SECTION +LOCAL +DEFAULT +5 *
+.* SECTION +LOCAL +DEFAULT +6 *
+.* SECTION +LOCAL +DEFAULT +7 *
+.* SECTION +LOCAL +DEFAULT +8 *
+.* SECTION +LOCAL +DEFAULT +9 *
+.* SECTION +LOCAL +DEFAULT +10 *
+.* SECTION +LOCAL +DEFAULT +11 *
+.* SECTION +LOCAL +DEFAULT +12 *
+.* FILE +LOCAL +DEFAULT +ABS tmpdir/tlspic3aligned.o
+.* TLS +LOCAL +DEFAULT +8 sl1
+.* TLS +LOCAL +DEFAULT +8 sl2
+.* TLS +LOCAL +DEFAULT +8 sl3
+.* TLS +LOCAL +DEFAULT +8 sl4
+.* TLS +LOCAL +DEFAULT +8 sl5
+.* TLS +LOCAL +DEFAULT +8 sl6
+.* TLS +LOCAL +DEFAULT +8 sl7
+.* TLS +LOCAL +DEFAULT +8 sl8
+.* FILE +LOCAL +DEFAULT +ABS 
+.* TLS +LOCAL +DEFAULT +9 sH1
+.* OBJECT +LOCAL +DEFAULT +10 _DYNAMIC
+.* TLS +LOCAL +DEFAULT +8 sh3
+.* TLS +LOCAL +DEFAULT +9 sH2
+.* TLS +LOCAL +DEFAULT +9 sH7
+.* TLS +LOCAL +DEFAULT +8 sh7
+.* TLS +LOCAL +DEFAULT +8 sh8
+.* TLS +LOCAL +DEFAULT +9 sH4
+.* TLS +LOCAL +DEFAULT +8 sh4
+.* TLS +LOCAL +DEFAULT +9 sH3
+.* TLS +LOCAL +DEFAULT +8 sh5
+.* TLS +LOCAL +DEFAULT +9 sH5
+.* TLS +LOCAL +DEFAULT +9 sH6
+.* TLS +LOCAL +DEFAULT +9 sH8
+.* TLS +LOCAL +DEFAULT +8 sh1
+.* OBJECT +LOCAL +DEFAULT +12 _GLOBAL_OFFSET_TABLE_
+.* TLS +LOCAL +DEFAULT +8 sh2
+.* TLS +LOCAL +DEFAULT +8 sh6
+.* TLS +GLOBAL +DEFAULT +8 sg8
+.* TLS +GLOBAL +DEFAULT +8 sg3
+.* TLS +GLOBAL +DEFAULT +8 sg4
+.* TLS +GLOBAL +DEFAULT +8 sg5
+.* TLS +GLOBAL +DEFAULT +8 sg1
+.* FUNC +GLOBAL +DEFAULT +2 fn1
+.* NOTYPE +GLOBAL +DEFAULT +12 __bss_start
+.* TLS +GLOBAL +DEFAULT +8 sg2
+.* TLS +GLOBAL +DEFAULT +8 sg6
+.* TLS +GLOBAL +DEFAULT +8 sg7
+.* NOTYPE +GLOBAL +DEFAULT +12 _edata
+.* NOTYPE +GLOBAL +DEFAULT +12 _end
+.* NOTYPE +GLOBAL +DEFAULT +UND ___tls_get_addr
diff --git a/ld/testsuite/ld-x86-64/tlspic2aligned.rd b/ld/testsuite/ld-x86-64/tlspic2aligned.rd
new file mode 100644
index 0000000..b360a30
--- /dev/null
+++ b/ld/testsuite/ld-x86-64/tlspic2aligned.rd
@@ -0,0 +1,139 @@
+#source: tlspic3aligned.s
+#source: tlspic2.s
+#as: --64
+#ld: -shared -melf_x86_64 --no-ld-generated-unwind-info
+#readelf: -WSsrl
+#target: x86_64-*-*
+
+There are [0-9]+ section headers, starting at offset 0x[0-9a-f]+:
+
+Section Headers:
+ +\[Nr\] Name +Type +Address +Off +Size +ES Flg Lk Inf Al
+ +\[[ 0-9]+\] +NULL +0+ 0+ 0+ 00 +0 +0 +0
+ +\[[ 0-9]+\] .hash +.*
+ +\[[ 0-9]+\] .dynsym +.*
+ +\[[ 0-9]+\] .dynstr +.*
+ +\[[ 0-9]+\] .rela.dyn +.*
+ +\[[ 0-9]+\] .plt +.*
+ +\[[ 0-9]+\] .plt.got +.*
+ +\[[ 0-9]+\] .text +PROGBITS +0+1000 0+1000 0+31a 00 +AX +0 +0 4096
+ +\[[ 0-9]+\] .tdata +PROGBITS +0+20131a 0+131a 0+60 00 WAT +0 +0 +1
+ +\[[ 0-9]+\] .tbss +NOBITS +0+20137a 0+137a 0+20 00 WAT +0 +0 +1
+ +\[[ 0-9]+\] .dynamic +DYNAMIC +0+201380 0+1380 0+100 10 +WA +3 +0 +8
+ +\[[ 0-9]+\] .got +PROGBITS +0+201480 0+1480 0+98 08 +WA +0 +0 +8
+ +\[[ 0-9]+\] .got.plt +PROGBITS +0+201518 0+1518 0+18 08 +WA +0 +0 +8
+ +\[[ 0-9]+\] .symtab +.*
+ +\[[ 0-9]+\] .strtab +.*
+ +\[[ 0-9]+\] .shstrtab +.*
+Key to Flags:
+#...
+
+Elf file type is DYN \(Shared object file\)
+Entry point 0x1000
+There are [0-9]+ program headers, starting at offset [0-9]+
+
+Program Headers:
+ +Type +Offset +VirtAddr +PhysAddr +FileSiz +MemSiz +Flg Align
+ +LOAD +0x0+ 0x0+ 0x0+ 0x[0-9a-f]+ 0x[0-9a-f]+ R E 0x200000
+ +LOAD +0x0+131a 0x0+20131a 0x0+20131a 0x0+216 0x0+216 RW +0x200000
+ +DYNAMIC +0x0+1380 0x0+201380 0x0+201380 0x0+100 0x0+100 RW +0x8
+ +TLS +0x0+131a 0x0+20131a 0x0+20131a 0x0+60 0x0+80 R +0x1
+
+ Section to Segment mapping:
+ +Segment Sections...
+ +00 +.hash .dynsym .dynstr .rela.dyn .plt .plt.got .text *
+ +01 +.tdata .dynamic .got .got.plt *
+ +02 +.dynamic *
+ +03 +.tdata .tbss *
+
+Relocation section '.rela.dyn' at offset 0x[0-9a-f]+ contains 15 entries:
+ +Offset +Info +Type +Symbol's Value +Symbol's Name \+ Addend
+[0-9a-f ]+R_X86_64_DTPMOD64 +0
+[0-9a-f ]+R_X86_64_TPOFF64 +24
+[0-9a-f ]+R_X86_64_TPOFF64 +30
+[0-9a-f ]+R_X86_64_DTPMOD64 +0
+[0-9a-f ]+R_X86_64_DTPMOD64 +0
+[0-9a-f ]+R_X86_64_TPOFF64 +64
+[0-9a-f ]+R_X86_64_TPOFF64 +50
+[0-9a-f ]+R_X86_64_TPOFF64 +70
+[0-9a-f ]+R_X86_64_DTPMOD64 +0
+[0-9a-f ]+R_X86_64_TPOFF64 +44
+[0-9a-f ]+R_X86_64_TPOFF64 +0+10 sg5 \+ 0
+[0-9a-f ]+R_X86_64_DTPMOD64 +0+ sg1 \+ 0
+[0-9a-f ]+R_X86_64_DTPOFF64 +0+ sg1 \+ 0
+[0-9a-f ]+R_X86_64_TPOFF64 +0+4 sg2 \+ 0
+[0-9a-f ]+R_X86_64_GLOB_DAT +0+ ___tls_get_addr \+ 0
+
+Symbol table '\.dynsym' contains [0-9]+ entries:
+ +Num: +Value +Size +Type +Bind +Vis +Ndx +Name
+.* NOTYPE +LOCAL +DEFAULT +UND *
+.* TLS +GLOBAL +DEFAULT +8 sg8
+.* TLS +GLOBAL +DEFAULT +8 sg3
+.* TLS +GLOBAL +DEFAULT +8 sg4
+.* TLS +GLOBAL +DEFAULT +8 sg5
+.* TLS +GLOBAL +DEFAULT +8 sg1
+.* FUNC +GLOBAL +DEFAULT +7 fn1
+.* NOTYPE +GLOBAL +DEFAULT +12 __bss_start
+.* TLS +GLOBAL +DEFAULT +8 sg2
+.* TLS +GLOBAL +DEFAULT +8 sg6
+.* TLS +GLOBAL +DEFAULT +8 sg7
+.* NOTYPE +GLOBAL +DEFAULT +12 _edata
+.* NOTYPE +GLOBAL +DEFAULT +12 _end
+.* NOTYPE +GLOBAL +DEFAULT +UND ___tls_get_addr
+
+Symbol table '\.symtab' contains [0-9]+ entries:
+ +Num: +Value +Size +Type +Bind +Vis +Ndx +Name
+.* NOTYPE +LOCAL +DEFAULT +UND *
+.* SECTION +LOCAL +DEFAULT +1 *
+.* SECTION +LOCAL +DEFAULT +2 *
+.* SECTION +LOCAL +DEFAULT +3 *
+.* SECTION +LOCAL +DEFAULT +4 *
+.* SECTION +LOCAL +DEFAULT +5 *
+.* SECTION +LOCAL +DEFAULT +6 *
+.* SECTION +LOCAL +DEFAULT +7 *
+.* SECTION +LOCAL +DEFAULT +8 *
+.* SECTION +LOCAL +DEFAULT +9 *
+.* SECTION +LOCAL +DEFAULT +10 *
+.* SECTION +LOCAL +DEFAULT +11 *
+.* SECTION +LOCAL +DEFAULT +12 *
+.* FILE +LOCAL +DEFAULT +ABS tmpdir/tlspic3aligned.o
+.* TLS +LOCAL +DEFAULT +8 sl1
+.* TLS +LOCAL +DEFAULT +8 sl2
+.* TLS +LOCAL +DEFAULT +8 sl3
+.* TLS +LOCAL +DEFAULT +8 sl4
+.* TLS +LOCAL +DEFAULT +8 sl5
+.* TLS +LOCAL +DEFAULT +8 sl6
+.* TLS +LOCAL +DEFAULT +8 sl7
+.* TLS +LOCAL +DEFAULT +8 sl8
+.* FILE +LOCAL +DEFAULT +ABS 
+.* TLS +LOCAL +DEFAULT +9 sH1
+.* OBJECT +LOCAL +DEFAULT +10 _DYNAMIC
+.* TLS +LOCAL +DEFAULT +8 sh3
+.* TLS +LOCAL +DEFAULT +9 sH2
+.* TLS +LOCAL +DEFAULT +9 sH7
+.* TLS +LOCAL +DEFAULT +8 sh7
+.* TLS +LOCAL +DEFAULT +8 sh8
+.* TLS +LOCAL +DEFAULT +9 sH4
+.* TLS +LOCAL +DEFAULT +8 sh4
+.* TLS +LOCAL +DEFAULT +9 sH3
+.* TLS +LOCAL +DEFAULT +8 sh5
+.* TLS +LOCAL +DEFAULT +9 sH5
+.* TLS +LOCAL +DEFAULT +9 sH6
+.* TLS +LOCAL +DEFAULT +9 sH8
+.* TLS +LOCAL +DEFAULT +8 sh1
+.* OBJECT +LOCAL +DEFAULT +12 _GLOBAL_OFFSET_TABLE_
+.* TLS +LOCAL +DEFAULT +8 sh2
+.* TLS +LOCAL +DEFAULT +8 sh6
+.* TLS +GLOBAL +DEFAULT +8 sg8
+.* TLS +GLOBAL +DEFAULT +8 sg3
+.* TLS +GLOBAL +DEFAULT +8 sg4
+.* TLS +GLOBAL +DEFAULT +8 sg5
+.* TLS +GLOBAL +DEFAULT +8 sg1
+.* FUNC +GLOBAL +DEFAULT +7 fn1
+.* NOTYPE +GLOBAL +DEFAULT +12 __bss_start
+.* TLS +GLOBAL +DEFAULT +8 sg2
+.* TLS +GLOBAL +DEFAULT +8 sg6
+.* TLS +GLOBAL +DEFAULT +8 sg7
+.* NOTYPE +GLOBAL +DEFAULT +12 _edata
+.* NOTYPE +GLOBAL +DEFAULT +12 _end
+.* NOTYPE +GLOBAL +DEFAULT +UND ___tls_get_addr
diff --git a/ld/testsuite/ld-x86-64/tlspic2aligned.sd b/ld/testsuite/ld-x86-64/tlspic2aligned.sd
new file mode 100644
index 0000000..39ed610
--- /dev/null
+++ b/ld/testsuite/ld-x86-64/tlspic2aligned.sd
@@ -0,0 +1,20 @@
+#source: tlspic3.s
+#source: tlspic2.s
+#as: --64
+#ld: -shared -melf_x86_64 --no-ld-generated-unwind-info
+#objdump: -sj.got
+#target: x86_64-*-*
+
+.*: +file format elf64-x86-64.*
+
+Contents of section .got:
+ [0-9a-f]+ 00000000 00000000 20000000 00000000  .*
+ [0-9a-f]+ 00000000 00000000 00000000 00000000  .*
+ [0-9a-f]+ 00000000 00000000 00000000 00000000  .*
+ [0-9a-f]+ 00000000 00000000 60000000 00000000  .*
+ [0-9a-f]+ 00000000 00000000 00000000 00000000  .*
+ [0-9a-f]+ 00000000 00000000 00000000 00000000  .*
+ [0-9a-f]+ 00000000 00000000 00000000 00000000  .*
+ [0-9a-f]+ 00000000 00000000 00000000 00000000  .*
+ [0-9a-f]+ 40000000 00000000 00000000 00000000  .*
+ [0-9a-f]+ 00000000 00000000 +.*
diff --git a/ld/testsuite/ld-x86-64/tlspic3aligned.s b/ld/testsuite/ld-x86-64/tlspic3aligned.s
new file mode 100644
index 0000000..8b3e721
--- /dev/null
+++ b/ld/testsuite/ld-x86-64/tlspic3aligned.s
@@ -0,0 +1,2 @@
+.weakref __tls_get_addr, ___tls_get_addr
+.include "tlspic3.s"
diff --git a/ld/testsuite/ld-x86-64/tlspicaligned-nacl.rd b/ld/testsuite/ld-x86-64/tlspicaligned-nacl.rd
new file mode 100644
index 0000000..099baa9
--- /dev/null
+++ b/ld/testsuite/ld-x86-64/tlspicaligned-nacl.rd
@@ -0,0 +1,144 @@
+#source: tlspic1aligned.s
+#source: tlspic2.s
+#as: --64
+#ld: -shared -melf_x86_64_nacl --no-ld-generated-unwind-info
+#readelf: -WSsrl
+#target: x86_64-*-nacl*
+
+There are [0-9]+ section headers, starting at offset 0x[0-9a-f]+:
+
+Section Headers:
+ +\[Nr\] Name +Type +Address +Off +Size +ES Flg Lk Inf Al
+ +\[[ 0-9]+\] +NULL +0+ 0+ 0+ 00 +0 +0 +0
+ +\[[ 0-9]+\] .plt +.*
+ +\[[ 0-9]+\] .text +PROGBITS +0+1000 [0-9a-f]+ 0+31a 00 +AX +0 +0 4096
+ +\[[ 0-9]+\] .hash +.*
+ +\[[ 0-9]+\] .dynsym +.*
+ +\[[ 0-9]+\] .dynstr +.*
+ +\[[ 0-9]+\] .rela.dyn +.*
+ +\[[ 0-9]+\] .rela.plt +.*
+ +\[[ 0-9]+\] .tdata +PROGBITS +0+100104b0 [0-9a-f]+ 0+60 00 WAT +0 +0 +1
+ +\[[ 0-9]+\] .tbss +NOBITS +0+10010510 [0-9a-f]+ 0+20 00 WAT +0 +0 +1
+ +\[[ 0-9]+\] .dynamic +DYNAMIC +0+10010510 [0-9a-f]+ 0+130 10 +WA +5 +0 +8
+ +\[[ 0-9]+\] .got +PROGBITS +0+10010640 [0-9a-f]+ 0+90 08 +WA +0 +0 +8
+ +\[[ 0-9]+\] .got.plt +PROGBITS +0+100106d0 [0-9a-f]+ 0+20 08 +WA +0 +0 +8
+ +\[[ 0-9]+\] .symtab +.*
+ +\[[ 0-9]+\] .strtab +.*
+ +\[[ 0-9]+\] .shstrtab +.*
+Key to Flags:
+#...
+
+Elf file type is DYN \(Shared object file\)
+Entry point 0x1000
+There are [0-9]+ program headers, starting at offset [0-9]+
+
+Program Headers:
+ +Type +Offset +VirtAddr +PhysAddr +FileSiz +MemSiz +Flg Align
+ +LOAD +0x0+10000 0x0+ 0x0+ 0x[0-9a-f]+ 0x[0-9a-f]+ R E 0x10000
+ +LOAD +0x0+ 0x0+10000000 0x0+10000000 0x0+4b0 0x0+4b0 R +0x10000
+ +LOAD +0x0+4b0 0x0+100104b0 0x0+100104b0 0x0+240 0x0+240 RW +0x10000
+ +DYNAMIC +0x0+510 0x0+10010510 0x0+10010510 0x0+130 0x0+130 RW +0x8
+ +TLS +0x0+4b0 0x0+100104b0 0x0+100104b0 0x0+60 0x0+80 R +0x1
+
+ Section to Segment mapping:
+ +Segment Sections...
+ +00 +.plt .text *
+ +01 +.hash .dynsym .dynstr .rela.dyn .rela.plt *
+ +02 +.tdata .dynamic .got .got.plt *
+ +03 +.dynamic *
+ +04 +.tdata .tbss *
+
+Relocation section '.rela.dyn' at offset 0x[0-9a-f]+ contains 14 entries:
+ +Offset +Info +Type +Symbol's Value +Symbol's Name \+ Addend
+[0-9a-f ]+R_X86_64_DTPMOD64 +0
+[0-9a-f ]+R_X86_64_TPOFF64 +24
+[0-9a-f ]+R_X86_64_TPOFF64 +30
+[0-9a-f ]+R_X86_64_DTPMOD64 +0
+[0-9a-f ]+R_X86_64_DTPMOD64 +0
+[0-9a-f ]+R_X86_64_TPOFF64 +64
+[0-9a-f ]+R_X86_64_TPOFF64 +50
+[0-9a-f ]+R_X86_64_TPOFF64 +70
+[0-9a-f ]+R_X86_64_DTPMOD64 +0
+[0-9a-f ]+R_X86_64_TPOFF64 +44
+[0-9a-f ]+R_X86_64_TPOFF64 +0+10 sg5 \+ 0
+[0-9a-f ]+R_X86_64_DTPMOD64 +0+ sg1 \+ 0
+[0-9a-f ]+R_X86_64_DTPOFF64 +0+ sg1 \+ 0
+[0-9a-f ]+R_X86_64_TPOFF64 +0+4 sg2 \+ 0
+
+Relocation section '.rela.plt' at offset 0x[0-9a-f]+ contains 1 entries:
+ +Offset +Info +Type +Symbol's Value +Symbol's Name \+ Addend
+[0-9a-f ]+R_X86_64_JUMP_SLOT +0+ ___tls_get_addr \+ 0
+
+Symbol table '\.dynsym' contains [0-9]+ entries:
+ +Num: +Value +Size +Type +Bind +Vis +Ndx +Name
+.* NOTYPE +LOCAL +DEFAULT +UND *
+.* TLS +GLOBAL +DEFAULT +8 sg8
+.* TLS +GLOBAL +DEFAULT +8 sg3
+.* TLS +GLOBAL +DEFAULT +8 sg4
+.* TLS +GLOBAL +DEFAULT +8 sg5
+.* TLS +GLOBAL +DEFAULT +8 sg1
+.* FUNC +GLOBAL +DEFAULT +2 fn1
+.* NOTYPE +GLOBAL +DEFAULT +12 __bss_start
+.* TLS +GLOBAL +DEFAULT +8 sg2
+.* TLS +GLOBAL +DEFAULT +8 sg6
+.* TLS +GLOBAL +DEFAULT +8 sg7
+.* NOTYPE +GLOBAL +DEFAULT +12 _edata
+.* NOTYPE +GLOBAL +DEFAULT +12 _end
+.* NOTYPE +GLOBAL +DEFAULT +UND ___tls_get_addr
+
+Symbol table '\.symtab' contains [0-9]+ entries:
+ +Num: +Value +Size +Type +Bind +Vis +Ndx +Name
+.* NOTYPE +LOCAL +DEFAULT +UND *
+.* SECTION +LOCAL +DEFAULT +1 *
+.* SECTION +LOCAL +DEFAULT +2 *
+.* SECTION +LOCAL +DEFAULT +3 *
+.* SECTION +LOCAL +DEFAULT +4 *
+.* SECTION +LOCAL +DEFAULT +5 *
+.* SECTION +LOCAL +DEFAULT +6 *
+.* SECTION +LOCAL +DEFAULT +7 *
+.* SECTION +LOCAL +DEFAULT +8 *
+.* SECTION +LOCAL +DEFAULT +9 *
+.* SECTION +LOCAL +DEFAULT +10 *
+.* SECTION +LOCAL +DEFAULT +11 *
+.* SECTION +LOCAL +DEFAULT +12 *
+.* FILE +LOCAL +DEFAULT +ABS tmpdir/tlspic1aligned.o
+.* TLS +LOCAL +DEFAULT +8 sl1
+.* TLS +LOCAL +DEFAULT +8 sl2
+.* TLS +LOCAL +DEFAULT +8 sl3
+.* TLS +LOCAL +DEFAULT +8 sl4
+.* TLS +LOCAL +DEFAULT +8 sl5
+.* TLS +LOCAL +DEFAULT +8 sl6
+.* TLS +LOCAL +DEFAULT +8 sl7
+.* TLS +LOCAL +DEFAULT +8 sl8
+.* FILE +LOCAL +DEFAULT +ABS 
+.* TLS +LOCAL +DEFAULT +9 sH1
+.* OBJECT +LOCAL +DEFAULT +10 _DYNAMIC
+.* TLS +LOCAL +DEFAULT +8 sh3
+.* TLS +LOCAL +DEFAULT +9 sH2
+.* TLS +LOCAL +DEFAULT +9 sH7
+.* TLS +LOCAL +DEFAULT +8 sh7
+.* TLS +LOCAL +DEFAULT +8 sh8
+.* TLS +LOCAL +DEFAULT +9 sH4
+.* TLS +LOCAL +DEFAULT +8 sh4
+.* TLS +LOCAL +DEFAULT +9 sH3
+.* TLS +LOCAL +DEFAULT +8 sh5
+.* TLS +LOCAL +DEFAULT +9 sH5
+.* TLS +LOCAL +DEFAULT +9 sH6
+.* TLS +LOCAL +DEFAULT +9 sH8
+.* TLS +LOCAL +DEFAULT +8 sh1
+.* OBJECT +LOCAL +DEFAULT +12 _GLOBAL_OFFSET_TABLE_
+.* TLS +LOCAL +DEFAULT +8 sh2
+.* TLS +LOCAL +DEFAULT +8 sh6
+.* TLS +GLOBAL +DEFAULT +8 sg8
+.* TLS +GLOBAL +DEFAULT +8 sg3
+.* TLS +GLOBAL +DEFAULT +8 sg4
+.* TLS +GLOBAL +DEFAULT +8 sg5
+.* TLS +GLOBAL +DEFAULT +8 sg1
+.* FUNC +GLOBAL +DEFAULT +2 fn1
+.* NOTYPE +GLOBAL +DEFAULT +12 __bss_start
+.* TLS +GLOBAL +DEFAULT +8 sg2
+.* TLS +GLOBAL +DEFAULT +8 sg6
+.* TLS +GLOBAL +DEFAULT +8 sg7
+.* NOTYPE +GLOBAL +DEFAULT +12 _edata
+.* NOTYPE +GLOBAL +DEFAULT +12 _end
+.* NOTYPE +GLOBAL +DEFAULT +UND ___tls_get_addr
diff --git a/ld/testsuite/ld-x86-64/tlspicaligned.rd b/ld/testsuite/ld-x86-64/tlspicaligned.rd
new file mode 100644
index 0000000..f1c39c9
--- /dev/null
+++ b/ld/testsuite/ld-x86-64/tlspicaligned.rd
@@ -0,0 +1,142 @@
+#source: tlspic1aligned.s
+#source: tlspic2.s
+#as: --64
+#ld: -shared -melf_x86_64 --no-ld-generated-unwind-info
+#readelf: -WSsrl
+#target: x86_64-*-*
+
+There are [0-9]+ section headers, starting at offset 0x[0-9a-f]+:
+
+Section Headers:
+ +\[Nr\] Name +Type +Address +Off +Size +ES Flg Lk Inf Al
+ +\[[ 0-9]+\] +NULL +0+ 0+ 0+ 00 +0 +0 +0
+ +\[[ 0-9]+\] .hash +.*
+ +\[[ 0-9]+\] .dynsym +.*
+ +\[[ 0-9]+\] .dynstr +.*
+ +\[[ 0-9]+\] .rela.dyn +.*
+ +\[[ 0-9]+\] .rela.plt +.*
+ +\[[ 0-9]+\] .plt +.*
+ +\[[ 0-9]+\] .text +PROGBITS +0+1000 0+1000 0+31a 00 +AX +0 +0 4096
+ +\[[ 0-9]+\] .tdata +PROGBITS +0+20131a 0+131a 0+60 00 WAT +0 +0 +1
+ +\[[ 0-9]+\] .tbss +NOBITS +0+20137a 0+137a 0+20 00 WAT +0 +0 +1
+ +\[[ 0-9]+\] .dynamic +DYNAMIC +0+201380 0+1380 0+130 10 +WA +3 +0 +8
+ +\[[ 0-9]+\] .got +PROGBITS +0+2014b0 0+14b0 0+90 08 +WA +0 +0 +8
+ +\[[ 0-9]+\] .got.plt +PROGBITS +0+201540 0+1540 0+20 08 +WA +0 +0 +8
+ +\[[ 0-9]+\] .symtab +.*
+ +\[[ 0-9]+\] .strtab +.*
+ +\[[ 0-9]+\] .shstrtab +.*
+Key to Flags:
+#...
+
+Elf file type is DYN \(Shared object file\)
+Entry point 0x1000
+There are [0-9]+ program headers, starting at offset [0-9]+
+
+Program Headers:
+ +Type +Offset +VirtAddr +PhysAddr +FileSiz +MemSiz +Flg Align
+ +LOAD +0x0+ 0x0+ 0x0+ 0x[0-9a-f]+ 0x[0-9a-f]+ R E 0x200000
+ +LOAD +0x0+131a 0x0+20131a 0x0+20131a 0x0+246 0x0+246 RW +0x200000
+ +DYNAMIC +0x0+1380 0x0+201380 0x0+201380 0x0+130 0x0+130 RW +0x8
+ +TLS +0x0+131a 0x0+20131a 0x0+20131a 0x0+60 0x0+80 R +0x1
+
+ Section to Segment mapping:
+ +Segment Sections...
+ +00 +.hash .dynsym .dynstr .rela.dyn .rela.plt .plt .text *
+ +01 +.tdata .dynamic .got .got.plt *
+ +02 +.dynamic *
+ +03 +.tdata .tbss *
+
+Relocation section '.rela.dyn' at offset 0x[0-9a-f]+ contains 14 entries:
+ +Offset +Info +Type +Symbol's Value +Symbol's Name \+ Addend
+[0-9a-f ]+R_X86_64_DTPMOD64 +0
+[0-9a-f ]+R_X86_64_TPOFF64 +24
+[0-9a-f ]+R_X86_64_TPOFF64 +30
+[0-9a-f ]+R_X86_64_DTPMOD64 +0
+[0-9a-f ]+R_X86_64_DTPMOD64 +0
+[0-9a-f ]+R_X86_64_TPOFF64 +64
+[0-9a-f ]+R_X86_64_TPOFF64 +50
+[0-9a-f ]+R_X86_64_TPOFF64 +70
+[0-9a-f ]+R_X86_64_DTPMOD64 +0
+[0-9a-f ]+R_X86_64_TPOFF64 +44
+[0-9a-f ]+R_X86_64_TPOFF64 +0+10 sg5 \+ 0
+[0-9a-f ]+R_X86_64_DTPMOD64 +0+ sg1 \+ 0
+[0-9a-f ]+R_X86_64_DTPOFF64 +0+ sg1 \+ 0
+[0-9a-f ]+R_X86_64_TPOFF64 +0+4 sg2 \+ 0
+
+Relocation section '.rela.plt' at offset 0x[0-9a-f]+ contains 1 entries:
+ +Offset +Info +Type +Symbol's Value +Symbol's Name \+ Addend
+[0-9a-f ]+R_X86_64_JUMP_SLOT +0+ ___tls_get_addr \+ 0
+
+Symbol table '\.dynsym' contains [0-9]+ entries:
+ +Num: +Value +Size +Type +Bind +Vis +Ndx +Name
+.* NOTYPE +LOCAL +DEFAULT +UND *
+.* TLS +GLOBAL +DEFAULT +8 sg8
+.* TLS +GLOBAL +DEFAULT +8 sg3
+.* TLS +GLOBAL +DEFAULT +8 sg4
+.* TLS +GLOBAL +DEFAULT +8 sg5
+.* TLS +GLOBAL +DEFAULT +8 sg1
+.* FUNC +GLOBAL +DEFAULT +7 fn1
+.* NOTYPE +GLOBAL +DEFAULT +12 __bss_start
+.* TLS +GLOBAL +DEFAULT +8 sg2
+.* TLS +GLOBAL +DEFAULT +8 sg6
+.* TLS +GLOBAL +DEFAULT +8 sg7
+.* NOTYPE +GLOBAL +DEFAULT +12 _edata
+.* NOTYPE +GLOBAL +DEFAULT +12 _end
+.* NOTYPE +GLOBAL +DEFAULT +UND ___tls_get_addr
+
+Symbol table '\.symtab' contains [0-9]+ entries:
+ +Num: +Value +Size +Type +Bind +Vis +Ndx +Name
+.* NOTYPE +LOCAL +DEFAULT +UND *
+.* SECTION +LOCAL +DEFAULT +1 *
+.* SECTION +LOCAL +DEFAULT +2 *
+.* SECTION +LOCAL +DEFAULT +3 *
+.* SECTION +LOCAL +DEFAULT +4 *
+.* SECTION +LOCAL +DEFAULT +5 *
+.* SECTION +LOCAL +DEFAULT +6 *
+.* SECTION +LOCAL +DEFAULT +7 *
+.* SECTION +LOCAL +DEFAULT +8 *
+.* SECTION +LOCAL +DEFAULT +9 *
+.* SECTION +LOCAL +DEFAULT +10 *
+.* SECTION +LOCAL +DEFAULT +11 *
+.* SECTION +LOCAL +DEFAULT +12 *
+.* FILE +LOCAL +DEFAULT +ABS tmpdir/tlspic1aligned.o
+.* TLS +LOCAL +DEFAULT +8 sl1
+.* TLS +LOCAL +DEFAULT +8 sl2
+.* TLS +LOCAL +DEFAULT +8 sl3
+.* TLS +LOCAL +DEFAULT +8 sl4
+.* TLS +LOCAL +DEFAULT +8 sl5
+.* TLS +LOCAL +DEFAULT +8 sl6
+.* TLS +LOCAL +DEFAULT +8 sl7
+.* TLS +LOCAL +DEFAULT +8 sl8
+.* FILE +LOCAL +DEFAULT +ABS 
+.* TLS +LOCAL +DEFAULT +9 sH1
+.* OBJECT +LOCAL +DEFAULT +10 _DYNAMIC
+.* TLS +LOCAL +DEFAULT +8 sh3
+.* TLS +LOCAL +DEFAULT +9 sH2
+.* TLS +LOCAL +DEFAULT +9 sH7
+.* TLS +LOCAL +DEFAULT +8 sh7
+.* TLS +LOCAL +DEFAULT +8 sh8
+.* TLS +LOCAL +DEFAULT +9 sH4
+.* TLS +LOCAL +DEFAULT +8 sh4
+.* TLS +LOCAL +DEFAULT +9 sH3
+.* TLS +LOCAL +DEFAULT +8 sh5
+.* TLS +LOCAL +DEFAULT +9 sH5
+.* TLS +LOCAL +DEFAULT +9 sH6
+.* TLS +LOCAL +DEFAULT +9 sH8
+.* TLS +LOCAL +DEFAULT +8 sh1
+.* OBJECT +LOCAL +DEFAULT +12 _GLOBAL_OFFSET_TABLE_
+.* TLS +LOCAL +DEFAULT +8 sh2
+.* TLS +LOCAL +DEFAULT +8 sh6
+.* TLS +GLOBAL +DEFAULT +8 sg8
+.* TLS +GLOBAL +DEFAULT +8 sg3
+.* TLS +GLOBAL +DEFAULT +8 sg4
+.* TLS +GLOBAL +DEFAULT +8 sg5
+.* TLS +GLOBAL +DEFAULT +8 sg1
+.* FUNC +GLOBAL +DEFAULT +7 fn1
+.* NOTYPE +GLOBAL +DEFAULT +12 __bss_start
+.* TLS +GLOBAL +DEFAULT +8 sg2
+.* TLS +GLOBAL +DEFAULT +8 sg6
+.* TLS +GLOBAL +DEFAULT +8 sg7
+.* NOTYPE +GLOBAL +DEFAULT +12 _edata
+.* NOTYPE +GLOBAL +DEFAULT +12 _end
+.* NOTYPE +GLOBAL +DEFAULT +UND ___tls_get_addr
diff --git a/ld/testsuite/ld-x86-64/tlspie1aligned.d b/ld/testsuite/ld-x86-64/tlspie1aligned.d
new file mode 100644
index 0000000..e06e8b1
--- /dev/null
+++ b/ld/testsuite/ld-x86-64/tlspie1aligned.d
@@ -0,0 +1,6 @@
+#name: TLS with PIE
+#as: --64
+#ld: -melf_x86_64 -pie
+#readelf: -r
+
+There are no relocations in this file.
diff --git a/ld/testsuite/ld-x86-64/tlspie1aligned.s b/ld/testsuite/ld-x86-64/tlspie1aligned.s
new file mode 100644
index 0000000..2e9db66
--- /dev/null
+++ b/ld/testsuite/ld-x86-64/tlspie1aligned.s
@@ -0,0 +1,58 @@
+	.text
+	.globl __tls_get_addr
+	.type	__tls_get_addr, @function
+__tls_get_addr:
+	ret
+	.size	__tls_get_addr, .-__tls_get_addr
+.globl _start
+	.type	_start, @function
+_start:
+	movq	foo3@GOTTPOFF(%rip), %rax
+	pushq	%rbx
+	movl	%fs:foo2@TPOFF, %ebx
+	addl	%fs:foo1@TPOFF, %ebx
+	addl	%fs:(%rax), %ebx
+	leaq	foo4@TLSLD(%rip), %rdi
+	call	__tls_get_addr@PLT
+	addl	foo4@DTPOFF(%rax), %ebx
+	.byte	0x66
+	leaq	foo5@TLSGD(%rip), %rdi
+	.value	0x6666
+	rex64
+	call	__tls_get_addr@PLT
+	addl	(%rax), %ebx
+	movl	%ebx, %eax
+	popq	%rbx
+	ret
+	.size	_start, .-_start
+.globl foo1
+	.section	.tbss,"awT",@nobits
+	.align 4
+	.type	foo1, @object
+	.size	foo1, 4
+foo1:
+	.zero	4
+.globl foo2
+	.align 4
+	.type	foo2, @object
+	.size	foo2, 4
+foo2:
+	.zero	4
+.globl foo3
+	.align 4
+	.type	foo3, @object
+	.size	foo3, 4
+foo3:
+	.zero	4
+.globl foo4
+	.align 4
+	.type	foo4, @object
+	.size	foo4, 4
+foo4:
+	.zero	4
+.globl foo5
+	.align 4
+	.type	foo5, @object
+	.size	foo5, 4
+foo5:
+	.zero	4
diff --git a/ld/testsuite/ld-x86-64/tlspie2aaligned.d b/ld/testsuite/ld-x86-64/tlspie2aaligned.d
new file mode 100644
index 0000000..586b388
--- /dev/null
+++ b/ld/testsuite/ld-x86-64/tlspie2aaligned.d
@@ -0,0 +1,6 @@
+#source: tlspie2aligned.s
+#as: --64 -mrelax-relocations=yes
+#ld: -melf_x86_64 -pie
+#readelf: -r
+
+There are no relocations in this file.
diff --git a/ld/testsuite/ld-x86-64/tlspie2aligned.s b/ld/testsuite/ld-x86-64/tlspie2aligned.s
new file mode 100644
index 0000000..e4737b8
--- /dev/null
+++ b/ld/testsuite/ld-x86-64/tlspie2aligned.s
@@ -0,0 +1,58 @@
+	.text
+	.globl ___tls_get_addr
+	.type	___tls_get_addr, @function
+___tls_get_addr:
+	ret
+	.size	___tls_get_addr, .-___tls_get_addr
+.globl _start
+	.type	_start, @function
+_start:
+	movq	foo3@GOTTPOFF(%rip), %rax
+	pushq	%rbx
+	movl	%fs:foo2@TPOFF, %ebx
+	addl	%fs:foo1@TPOFF, %ebx
+	addl	%fs:(%rax), %ebx
+	leaq	foo4@TLSLD(%rip), %rdi
+	call	*___tls_get_addr@GOTPCREL(%rip)
+	addl	foo4@DTPOFF(%rax), %ebx
+	.byte	0x66
+	leaq	foo5@TLSGD(%rip), %rdi
+	.byte	0x66
+	rex64
+	call	*___tls_get_addr@GOTPCREL(%rip)
+	addl	(%rax), %ebx
+	movl	%ebx, %eax
+	popq	%rbx
+	ret
+	.size	_start, .-_start
+.globl foo1
+	.section	.tbss,"awT",@nobits
+	.align 4
+	.type	foo1, @object
+	.size	foo1, 4
+foo1:
+	.zero	4
+.globl foo2
+	.align 4
+	.type	foo2, @object
+	.size	foo2, 4
+foo2:
+	.zero	4
+.globl foo3
+	.align 4
+	.type	foo3, @object
+	.size	foo3, 4
+foo3:
+	.zero	4
+.globl foo4
+	.align 4
+	.type	foo4, @object
+	.size	foo4, 4
+foo4:
+	.zero	4
+.globl foo5
+	.align 4
+	.type	foo5, @object
+	.size	foo5, 4
+foo5:
+	.zero	4
diff --git a/ld/testsuite/ld-x86-64/tlspie2baligned.d b/ld/testsuite/ld-x86-64/tlspie2baligned.d
new file mode 100644
index 0000000..86169d3
--- /dev/null
+++ b/ld/testsuite/ld-x86-64/tlspie2baligned.d
@@ -0,0 +1,28 @@
+#source: tlspie2aligned.s
+#as: --64 -mrelax-relocations=yes
+#ld: -melf_x86_64 -pie
+#objdump: -dwr
+
+.*: +file format .*
+
+
+Disassembly of section .text:
+
+[a-f0-9]+ <___tls_get_addr>:
+[ 	]*[a-f0-9]+:	c3                   	retq   
+
+[a-f0-9]+ <_start>:
+[ 	]*[a-f0-9]+:	48 c7 c0 f4 ff ff ff 	mov    \$0xfffffffffffffff4,%rax
+[ 	]*[a-f0-9]+:	53                   	push   %rbx
+[ 	]*[a-f0-9]+:	64 8b 1c 25 f0 ff ff ff 	mov    %fs:0xfffffffffffffff0,%ebx
+[ 	]*[a-f0-9]+:	64 03 1c 25 ec ff ff ff 	add    %fs:0xffffffffffffffec,%ebx
+[ 	]*[a-f0-9]+:	64 03 18             	add    %fs:\(%rax\),%ebx
+[ 	]*[a-f0-9]+:	66 66 66 66 64 48 8b 04 25 00 00 00 00 	data16 data16 data16 data16 mov %fs:0x0,%rax
+[ 	]*[a-f0-9]+:	03 98 f8 ff ff ff    	add    -0x8\(%rax\),%ebx
+[ 	]*[a-f0-9]+:	64 48 8b 04 25 00 00 00 00 	mov    %fs:0x0,%rax
+[ 	]*[a-f0-9]+:	48 8d 80 fc ff ff ff 	lea    -0x4\(%rax\),%rax
+[ 	]*[a-f0-9]+:	03 18                	add    \(%rax\),%ebx
+[ 	]*[a-f0-9]+:	89 d8                	mov    %ebx,%eax
+[ 	]*[a-f0-9]+:	5b                   	pop    %rbx
+[ 	]*[a-f0-9]+:	c3                   	retq   
+#pass
diff --git a/ld/testsuite/ld-x86-64/tlspie2caligned.d b/ld/testsuite/ld-x86-64/tlspie2caligned.d
new file mode 100644
index 0000000..5cc853f
--- /dev/null
+++ b/ld/testsuite/ld-x86-64/tlspie2caligned.d
@@ -0,0 +1,28 @@
+#source: tlspie2aligned.s
+#as: --64 -mrelax-relocations=yes
+#ld: -melf_x86_64 -pie -z call-nop=suffix-nop
+#objdump: -dwr
+
+.*: +file format .*
+
+
+Disassembly of section .text:
+
+[a-f0-9]+ <___tls_get_addr>:
+[ 	]*[a-f0-9]+:	c3                   	retq   
+
+[a-f0-9]+ <_start>:
+[ 	]*[a-f0-9]+:	48 c7 c0 f4 ff ff ff 	mov    \$0xfffffffffffffff4,%rax
+[ 	]*[a-f0-9]+:	53                   	push   %rbx
+[ 	]*[a-f0-9]+:	64 8b 1c 25 f0 ff ff ff 	mov    %fs:0xfffffffffffffff0,%ebx
+[ 	]*[a-f0-9]+:	64 03 1c 25 ec ff ff ff 	add    %fs:0xffffffffffffffec,%ebx
+[ 	]*[a-f0-9]+:	64 03 18             	add    %fs:\(%rax\),%ebx
+[ 	]*[a-f0-9]+:	66 66 66 66 64 48 8b 04 25 00 00 00 00 	data16 data16 data16 data16 mov %fs:0x0,%rax
+[ 	]*[a-f0-9]+:	03 98 f8 ff ff ff    	add    -0x8\(%rax\),%ebx
+[ 	]*[a-f0-9]+:	64 48 8b 04 25 00 00 00 00 	mov    %fs:0x0,%rax
+[ 	]*[a-f0-9]+:	48 8d 80 fc ff ff ff 	lea    -0x4\(%rax\),%rax
+[ 	]*[a-f0-9]+:	03 18                	add    \(%rax\),%ebx
+[ 	]*[a-f0-9]+:	89 d8                	mov    %ebx,%eax
+[ 	]*[a-f0-9]+:	5b                   	pop    %rbx
+[ 	]*[a-f0-9]+:	c3                   	retq   
+#pass
diff --git a/ld/testsuite/ld-x86-64/x86-64.exp b/ld/testsuite/ld-x86-64/x86-64.exp
index 9b83e1c..c3a7455 100644
--- a/ld/testsuite/ld-x86-64/x86-64.exp
+++ b/ld/testsuite/ld-x86-64/x86-64.exp
@@ -55,6 +55,12 @@ set x86_64tests {
      {{readelf -WSsrl tlspic.rd} {objdump -drj.text\ -Mintel64 tlspic.dd}
       {objdump -sj.got tlspic.sd} {objdump -sj.tdata tlspic.td}}
       "libtlspic.so"}
+    {"TLS -fpic -shared transitions (aligned)"
+     "-shared -melf_x86_64 --no-ld-generated-unwind-info" ""
+     "--64" {tlspic1aligned.s tlspic2.s}
+     {{readelf -WSsrl tlspicaligned.rd} {objdump -drj.text\ -Mintel64 tlspic.dd}
+      {objdump -sj.got tlspic.sd} {objdump -sj.tdata tlspic.td}}
+      "libtlspic.so"}
     {"TLS -fpic -shared transitions with r15 as GOT base"
      "-shared -melf_x86_64 --no-ld-generated-unwind-info" ""
      "--64 -mrelax-relocations=yes"
@@ -62,6 +68,13 @@ set x86_64tests {
      {{readelf -WSsrl tlspic2.rd} {objdump -drj.text\ -Mintel64 tlspic2.dd}
       {objdump -sj.got tlspic2.sd} {objdump -sj.tdata tlspic2.td}}
       "libtlspic2.so"}
+    {"TLS -fpic -shared transitions with r15 as GOT base (aligned)"
+     "-shared -melf_x86_64 --no-ld-generated-unwind-info" ""
+     "--64 -mrelax-relocations=yes"
+     {tlspic3aligned.s tlspic2.s}
+     {{readelf -WSsrl tlspic2aligned.rd} {objdump -drj.text\ -Mintel64 tlspic2.dd}
+      {objdump -sj.got tlspic2aligned.sd} {objdump -sj.tdata tlspic2.td}}
+      "libtlspic2aligned.so"}
     {"TLS descriptor -fpic -shared transitions"
      "-shared -melf_x86_64 --no-ld-generated-unwind-info" ""
      "--64" {tlsdesc.s tlspic2.s}
@@ -70,18 +83,32 @@ set x86_64tests {
       {objdump -drj.plt tlsdesc.pd}} "libtlsdesc.so"}
     {"Helper shared library" "-shared -melf_x86_64" ""
      "--64" {tlslib.s} {} "libtlslib.so"}
+    {"Helper shared library (aligned)" "-shared -melf_x86_64" ""
+     "--64" {tlslibaligned.s} {} "libtlslibaligned.so"}
     {"TLS -fpic and -fno-pic exec transitions"
      "-melf_x86_64 tmpdir/libtlslib.so --no-ld-generated-unwind-info" ""
      "--64" {tlsbinpic.s tlsbin.s}
      {{readelf -WSsrl tlsbin.rd} {objdump -drj.text tlsbin.dd}
       {objdump -sj.got tlsbin.sd} {objdump -sj.tdata tlsbin.td}}
       "tlsbin"}
+    {"TLS -fpic and -fno-pic exec transitions (aligned)"
+     "-melf_x86_64 tmpdir/libtlslibaligned.so --no-ld-generated-unwind-info" ""
+     "--64" {tlsbinpicaligned.s tlsbin.s}
+     {{readelf -WSsrl tlsbinaligned.rd} {objdump -drj.text tlsbin.dd}
+      {objdump -sj.got tlsbin.sd} {objdump -sj.tdata tlsbin.td}}
+      "tlsbinaligned"}
     {"TLS -fpic and -fno-pic exec transitions without PLT"
      "-melf_x86_64 tmpdir/libtlslib.so --no-ld-generated-unwind-info" ""
      "-mrelax-relocations=yes --64" {tlsbinpic2.s tlsbin.s}
      {{readelf -WSsrl tlsbin2.rd} {objdump -drj.text tlsbin2.dd}
       {objdump -sj.got tlsbin2.sd} {objdump -sj.tdata tlsbin2.td}}
       "tlsbin2"}
+    {"TLS -fpic and -fno-pic exec transitions without PLT (aligned)"
+     "-melf_x86_64 tmpdir/libtlslibaligned.so --no-ld-generated-unwind-info" ""
+     "-mrelax-relocations=yes --64" {tlsbinpic2aligned.s tlsbin.s}
+     {{readelf -WSsrl tlsbin2aligned.rd} {objdump -drj.text tlsbin2.dd}
+      {objdump -sj.got tlsbin2.sd} {objdump -sj.tdata tlsbin2.td}}
+      "tlsbin2aligned"}
     {"TLS descriptor -fpic and -fno-pic exec transitions"
      "-melf_x86_64 tmpdir/libtlslib.so --no-ld-generated-unwind-info" ""
      "--64" {tlsbindesc.s tlsbin.s}
@@ -93,15 +120,27 @@ set x86_64tests {
      "--64" {tlsgdesc.s}
      {{readelf -WSsrl tlsgdesc.rd} {objdump -drj.text\ -Mintel64 tlsgdesc.dd}}
       "libtlsgdesc.so"}
+    {"TLS with global dynamic and descriptors (aligned)"
+     "-shared -melf_x86_64 --no-ld-generated-unwind-info" ""
+     "--64" {tlsgdescaligned.s}
+     {{readelf -WSsrl tlsgdescaligned.rd}
+      {objdump -drj.text\ -Mintel64 tlsgdescaligned.dd}}
+      "libtlsgdescaligned.so"}
     {"TLS in debug sections" "-melf_x86_64" ""
      "--64" {tlsg.s}
      {{objdump -sj.debug_foobar tlsg.sd}} "tlsg"}
     {"TLS GD->LE transition" "-melf_x86_64" ""
      "--64" {tlsgd1.s}
      {{objdump -dwr tlsgd1.dd}} "tlsgd1"}
+    {"TLS GD->LE transition (aligned)" "-melf_x86_64" ""
+     "--64" {tlsgd1aligned.s}
+     {{objdump -dwr tlsgd1.dd}} "tlsgd1aligned"}
     {"TLS LD->LE transition" "-melf_x86_64" ""
      "--64" {tlsld1.s}
      {{objdump -dwr tlsld1.dd}} "tlsld1"}
+    {"TLS LD->LE transition (aligned)" "-melf_x86_64" ""
+     "--64" {tlsld1aligned.s}
+     {{objdump -dwr tlsld1.dd}} "tlsld1aligned"}
     {"TLS IE->LE transition" "-melf_x86_64" ""
      "--64" {tlsie1.s}
      {{objdump -dwr tlsie1.dd}} "tlsie1"}
@@ -123,65 +162,129 @@ set x86_64tests {
     {"TLS X32 GD->LE transition" "-melf32_x86_64" ""
      "--x32" {tlsgd4.s}
      {{objdump -dwr tlsgd4.dd}} "tlsgd4"}
+    {"TLS X32 GD->LE transition (aligned)" "-melf32_x86_64" ""
+     "--x32" {tlsgd4aligned.s}
+     {{objdump -dwr tlsgd4.dd}} "tlsgd4aligned"}
     {"Helper TLS GD->IE transition DSO" "-shared -melf_x86_64" ""
      "--64" {tlsgd5b.s} {} "libtlsgd5.so"}
     {"TLS GD->IE transition" "-melf_x86_64 tmpdir/libtlsgd5.so" ""
      "--64" {tlsgd5a.s}
      {{objdump -dwr tlsgd5.dd}} "tlsgd5a"}
+    {"TLS GD->IE transition (aligned)"
+     "-melf_x86_64 tmpdir/libtlsgd5.so" ""
+     "--64" {tlsgd5aaligned.s}
+     {{objdump -dwr tlsgd5.dd}} "tlsgd5aaligned"}
     {"TLS GD->IE transition without PLT"
      "-melf_x86_64 tmpdir/libtlsgd5.so" ""
      "-mrelax-relocations=yes --64" {tlsgd5c.s}
      {{objdump -dwr tlsgd5.dd}} "tlsgd5b"}
+    {"TLS GD->IE transition without PLT (aligned)"
+     "-melf_x86_64 tmpdir/libtlsgd5.so" ""
+     "-mrelax-relocations=yes --64" {tlsgd5caligned.s}
+     {{objdump -dwr tlsgd5.dd}} "tlsgd5baligned"}
     {"Helper TLS X32 GD->IE transition DSO" "-shared -melf32_x86_64" ""
      "--x32" {tlsgd6b.s} {} "libtlsgd6.so"}
     {"TLS X32 GD->IE transition" "-melf32_x86_64 tmpdir/libtlsgd6.so" ""
      "--x32" {tlsgd6a.s}
      {{objdump -dwr tlsgd6.dd}} "tlsgd6a"}
+    {"TLS X32 GD->IE transition (aligned)"
+     "-melf32_x86_64 tmpdir/libtlsgd6.so" ""
+     "--x32" {tlsgd6aaligned.s}
+     {{objdump -dwr tlsgd6.dd}} "tlsgd6aaligned"}
     {"TLS X32 GD->IE transition without PLT"
      "-melf32_x86_64 tmpdir/libtlsgd6.so" ""
      "-mrelax-relocations=yes --x32" {tlsgd6c.s}
      {{objdump -dwr tlsgd6.dd}} "tlsgd6b"}
+    {"TLS X32 GD->IE transition without PLT (aligned)"
+     "-melf32_x86_64 tmpdir/libtlsgd6.so" ""
+     "-mrelax-relocations=yes --x32" {tlsgd6caligned.s}
+     {{objdump -dwr tlsgd6.dd}} "tlsgd6baligned"}
     {"TLS X32 LD->LE transition" "-melf32_x86_64" ""
      "--x32" {tlsld2.s}
      {{objdump -dwr tlsld2.dd}} "tlsld2"}
+    {"TLS X32 LD->LE transition (aligned)"
+     "-melf32_x86_64" ""
+     "--x32" {tlsld2aligned.s}
+     {{objdump -dwr tlsld2.dd}} "tlsld2aligned"}
     {"TLS -mcmodel=large GD->LE transition" "-melf_x86_64" ""
      "--64" {tlsgd7.s}
      {{objdump -dwr tlsgd7.dd}} "tlsgd7"}
+    {"TLS -mcmodel=large GD->LE transition (aligned)"
+     "-melf_x86_64" ""
+     "--64" {tlsgd7aligned.s}
+     {{objdump -dwr tlsgd7.dd}} "tlsgd7aligned"}
     {"TLS -mcmodel=large LD->LE transition" "-melf_x86_64" ""
      "--64" {tlsld3.s}
      {{objdump -dwr tlsld3.dd}} "tlsld3"}
+    {"TLS -mcmodel=large LD->LE transition (aligned)" "-melf_x86_64" ""
+     "--64" {tlsld3aligned.s}
+     {{objdump -dwr tlsld3.dd}} "tlsld3aligned"}
     {"TLS -mcmodel=large LD->LE transition with r15 as GOT base"
      "-melf_x86_64" ""
      "--64" {tlsld4.s}
      {{objdump -dwr tlsld4.dd}} "tlsld4"}
+    {"TLS -mcmodel=large LD->LE transition with r15 as GOT base (aligned)"
+     "-melf_x86_64" ""
+     "--64" {tlsld4aligned.s}
+     {{objdump -dwr tlsld4.dd}} "tlsld4"}
     {"TLS LD->LE transition without PLT"
      "-melf_x86_64" ""
      "--64 -mrelax-relocations=yes"
      {tlsld5.s}
      {{objdump -dwr tlsld5.dd}} "tlsld5"}
+    {"TLS LD->LE transition without PLT (aligned)"
+     "-melf_x86_64" ""
+     "--64 -mrelax-relocations=yes"
+     {tlsld5aligned.s}
+     {{objdump -dwr tlsld5.dd}} "tlsld5aligned"}
     {"TLS X32 LD->LE transition without PLT" "-melf32_x86_64" ""
      "--x32 -mrelax-relocations=yes"
      {tlsld6.s}
      {{objdump -dwr tlsld6.dd}} "tlsld6"}
+    {"TLS X32 LD->LE transition without PLT (aligned)"
+     "-melf32_x86_64" ""
+     "--x32 -mrelax-relocations=yes"
+     {tlsld6aligned.s}
+     {{objdump -dwr tlsld6.dd}} "tlsld6aligned"}
     {"TLS -mcmodel=large GD->IE transition" "-melf_x86_64 tmpdir/libtlsgd5.so" ""
      "--64" {tlsgd8.s}
      {{objdump -dwrj.text tlsgd8.dd}} "tlsgd8"}
+    {"TLS -mcmodel=large GD->IE transition (aligned)"
+     "-melf_x86_64 tmpdir/libtlsgd5.so" ""
+     "--64" {tlsgd8aligned.s}
+     {{objdump -dwrj.text tlsgd8.dd}} "tlsgd8aligned"}
     {"TLS -mcmodel=large GD->LE transition with r15 as GOT base"
      "-melf_x86_64" ""
      "--64" {tlsgd9.s}
      {{objdump -dwr tlsgd9.dd}} "tlsgd9"}
+    {"TLS -mcmodel=large GD->LE transition with r15 as GOT base (aligned)"
+     "-melf_x86_64" ""
+     "--64" {tlsgd9aligned.s}
+     {{objdump -dwr tlsgd9.dd}} "tlsgd9aligned"}
     {"TLS -mcmodel=large GD->IE transition with r15 as GOT base"
      "-melf_x86_64 tmpdir/libtlsgd5.so" ""
      "--64" {tlsgd10.s}
      {{objdump -dwrj.text tlsgd10.dd}} "tlsgd10"}
+    {"TLS -mcmodel=large GD->IE transition with r15 as GOT base (aligned)"
+     "-melf_x86_64 tmpdir/libtlsgd5.so" ""
+     "--64" {tlsgd10aligned.s}
+     {{objdump -dwrj.text tlsgd10.dd}} "tlsgd10aligned"}
     {"TLS GD->LE transition without PLT"
      "-melf_x86_64" ""
      "--64" {tlsgd11.s}
      {{objdump -dwr tlsgd11.dd}} "tlsgd11"}
+    {"TLS GD->LE transition without PLT (aligned)"
+     "-melf_x86_64" ""
+     "--64" {tlsgd11aligned.s}
+     {{objdump -dwr tlsgd11.dd}} "tlsgd11aligned"}
     {"TLS X32 GD->LE transition without PLT"
      "-melf32_x86_64" ""
      "--x32" {tlsgd14.s}
      {{objdump -dwr tlsgd14.dd}} "tlsgd14"}
+    {"TLS X32 GD->LE transition without PLT (aligned)"
+     "-melf32_x86_64" ""
+     "--x32" {tlsgd14aligned.s}
+     {{objdump -dwr tlsgd14.dd}} "tlsgd14aligned"}
      {"build 32-bit object with 33 locals" "-melf_x86_64 -e 0" "" "--32" {32bit.s} {{ ld incompatible.l }} "dummy" }
      {"build 64-bit object" "-melf_x86_64 -e 0 --defsym foo=1" "" "--64" {64bit.s} {} "dummy" }
      {"link mixed objects"  "-melf_x86_64 -e 0 tmpdir/32bit.o tmpdir/64bit.o" "" "" {} { { ld incompatible.l } } "mixed"}
@@ -270,9 +373,13 @@ run_dump_test "abs-l1om"
 run_dump_test "pcrel8"
 run_dump_test "pcrel16"
 run_dump_test "tlsgd2"
+run_dump_test "tlsgd2aligned"
 run_dump_test "tlsgd3"
+run_dump_test "tlsgd3aligned"
 run_dump_test "tlsgd12"
+run_dump_test "tlsgd12aligned"
 run_dump_test "tlsgd13"
+run_dump_test "tlsgd13aligned"
 run_dump_test "tlsie2"
 run_dump_test "tlsie3"
 run_dump_test "hidden1"
@@ -293,9 +400,13 @@ run_dump_test "protected7a"
 run_dump_test "protected7b"
 run_dump_test "tlsle1"
 run_dump_test "tlspie1"
+run_dump_test "tlspie1aligned"
 run_dump_test "tlspie2a"
+run_dump_test "tlspie2aaligned"
 run_dump_test "tlspie2b"
+run_dump_test "tlspie2baligned"
 run_dump_test "tlspie2c"
+run_dump_test "tlspie2caligned"
 run_dump_test "unique1"
 run_dump_test "nogot1"
 run_dump_test "nogot2"
-- 
2.9.4
