public inbox for binutils@sourceware.org
 help / color / mirror / Atom feed
* [PATCH] ld: aarch64: Improve TLS relaxation condition
@ 2022-07-08 12:52 Matthew Malcomson
  2022-07-29 10:27 ` Nick Clifton
  0 siblings, 1 reply; 2+ messages in thread
From: Matthew Malcomson @ 2022-07-08 12:52 UTC (permalink / raw)
  To: binutils; +Cc: Richard.Earnshaw

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

In aarch64_tls_transition_without_check and elfNN_aarch64_tls_relax we
choose whether to perform a relaxation to an IE access model or an LE
access model based on whether the symbol itself is marked as local (i.e.
`h == NULL`).

This is problematic in two ways.  The first is that sometimes a global
dynamic access can be relaxed to an initial exec access when creating a
shared library, and if that happens on a local symbol then we currently
relax it to a local exec access instead.  This usually does not happen
since we only relax an access if aarch64_can_relax_tls returns true and
aarch64_can_relax_tls does not have the same problem.  However, it can
happen when we have seen both an IE and GD access on the same symbol.
This case is exercised in the newly added testcase tls-relax-gd-ie-2.

The second problem is that deciding based on whether the symbol is local
misses the case when the symbol is global but is still non-interposable
and known to be located in the executable.  This happens on all global
symbols in executables.
This case is exercised in the newly added testcase tls-relax-ie-le-4.

Here we adjust the condition we base our relaxation on so that we relax
to local-exec if we are creating an executable and the relevant symbol
we're accessing is stored inside that executable.

-- Updating tests for new relaxation criteria

Many of the tests added to check our relaxation to IE were implemented
by taking advantage of the fact that we did not relax a global symbol
defined in an executable.

Since a global symbol defined in an executable is still not
interposable, we know that a TLS version of such a symbol will be in the
main TLS block.  This means that we can perform a stronger relaxation on
such symbols and relax their accesses to a local-exec access.

Hence we have to update all tests that relied on the older suboptimal
decision making.

The two cases when we still would want to relax a general dynamic access
to an initial exec one are:
1) When in a shared library and accessing a symbol which we have already
   seen accessed with an initial exec access sequence.
2) When in an executable and accessing a symbol defined in a shared
   library.

Both of these require shared library support, which means that these
tests are now only available on targets with that.

I have chosen to switch the existing testcases from a plain executable
to one dynamically linked to a shared object as that doesn't require
changing the testcases quite so much (just requires accessing a
different variable rather than requiring adding another code sequence).

The tls-relax-all testcase was an outlier to the above approach, since
it included a general dynamic access to both a local and global symbol
and inspected for the difference accordingly.


###############     Attachment also inlined for ease of reply    ###############


diff --git a/bfd/elfnn-aarch64.c b/bfd/elfnn-aarch64.c
index 251a27edb571a91fc51a2d0de2613f72c29e299d..c675292d232abdde37d6996b3883929ce896e924 100644
--- a/bfd/elfnn-aarch64.c
+++ b/bfd/elfnn-aarch64.c
@@ -4898,60 +4898,62 @@ aarch64_calculate_got_entry_vma (struct elf_link_hash_entry *h,
 
 static bfd_reloc_code_real_type
 aarch64_tls_transition_without_check (bfd_reloc_code_real_type r_type,
-				      struct elf_link_hash_entry *h)
+				      struct elf_link_hash_entry *h,
+				      struct bfd_link_info *info)
 {
-  bool is_local = h == NULL;
+  bool local_exec = bfd_link_executable (info)
+    && SYMBOL_REFERENCES_LOCAL (info, h);
 
   switch (r_type)
     {
     case BFD_RELOC_AARCH64_TLSDESC_ADR_PAGE21:
     case BFD_RELOC_AARCH64_TLSGD_ADR_PAGE21:
-      return (is_local
+      return (local_exec
 	      ? BFD_RELOC_AARCH64_TLSLE_MOVW_TPREL_G1
 	      : BFD_RELOC_AARCH64_TLSIE_ADR_GOTTPREL_PAGE21);
 
     case BFD_RELOC_AARCH64_TLSDESC_ADR_PREL21:
-      return (is_local
+      return (local_exec
 	      ? BFD_RELOC_AARCH64_TLSLE_MOVW_TPREL_G0_NC
 	      : r_type);
 
     case BFD_RELOC_AARCH64_TLSDESC_LD_PREL19:
-      return (is_local
+      return (local_exec
 	      ? BFD_RELOC_AARCH64_TLSLE_MOVW_TPREL_G1
 	      : BFD_RELOC_AARCH64_TLSIE_LD_GOTTPREL_PREL19);
 
     case BFD_RELOC_AARCH64_TLSDESC_LDR:
-      return (is_local
+      return (local_exec
 	      ? BFD_RELOC_AARCH64_TLSLE_MOVW_TPREL_G0_NC
 	      : BFD_RELOC_AARCH64_NONE);
 
     case BFD_RELOC_AARCH64_TLSDESC_OFF_G0_NC:
-      return (is_local
+      return (local_exec
 	      ? BFD_RELOC_AARCH64_TLSLE_MOVW_TPREL_G1_NC
 	      : BFD_RELOC_AARCH64_TLSIE_MOVW_GOTTPREL_G0_NC);
 
     case BFD_RELOC_AARCH64_TLSDESC_OFF_G1:
-      return (is_local
+      return (local_exec
 	      ? BFD_RELOC_AARCH64_TLSLE_MOVW_TPREL_G2
 	      : BFD_RELOC_AARCH64_TLSIE_MOVW_GOTTPREL_G1);
 
     case BFD_RELOC_AARCH64_TLSDESC_LDNN_LO12_NC:
     case BFD_RELOC_AARCH64_TLSGD_ADD_LO12_NC:
-      return (is_local
+      return (local_exec
 	      ? BFD_RELOC_AARCH64_TLSLE_MOVW_TPREL_G0_NC
 	      : BFD_RELOC_AARCH64_TLSIE_LDNN_GOTTPREL_LO12_NC);
 
     case BFD_RELOC_AARCH64_TLSIE_ADR_GOTTPREL_PAGE21:
-      return is_local ? BFD_RELOC_AARCH64_TLSLE_MOVW_TPREL_G1 : r_type;
+      return local_exec ? BFD_RELOC_AARCH64_TLSLE_MOVW_TPREL_G1 : r_type;
 
     case BFD_RELOC_AARCH64_TLSIE_LDNN_GOTTPREL_LO12_NC:
-      return is_local ? BFD_RELOC_AARCH64_TLSLE_MOVW_TPREL_G0_NC : r_type;
+      return local_exec ? BFD_RELOC_AARCH64_TLSLE_MOVW_TPREL_G0_NC : r_type;
 
     case BFD_RELOC_AARCH64_TLSIE_LD_GOTTPREL_PREL19:
       return r_type;
 
     case BFD_RELOC_AARCH64_TLSGD_ADR_PREL21:
-      return (is_local
+      return (local_exec
 	      ? BFD_RELOC_AARCH64_TLSLE_ADD_TPREL_HI12
 	      : BFD_RELOC_AARCH64_TLSIE_LD_GOTTPREL_PREL19);
 
@@ -4964,16 +4966,16 @@ aarch64_tls_transition_without_check (bfd_reloc_code_real_type r_type,
     case BFD_RELOC_AARCH64_TLSLD_ADD_LO12_NC:
     case BFD_RELOC_AARCH64_TLSLD_ADR_PAGE21:
     case BFD_RELOC_AARCH64_TLSLD_ADR_PREL21:
-      return is_local ? BFD_RELOC_AARCH64_NONE : r_type;
+      return local_exec ? BFD_RELOC_AARCH64_NONE : r_type;
 
 #if ARCH_SIZE == 64
     case BFD_RELOC_AARCH64_TLSGD_MOVW_G0_NC:
-      return is_local
+      return local_exec
 	? BFD_RELOC_AARCH64_TLSLE_MOVW_TPREL_G1_NC
 	: BFD_RELOC_AARCH64_TLSIE_MOVW_GOTTPREL_G0_NC;
 
     case BFD_RELOC_AARCH64_TLSGD_MOVW_G1:
-      return is_local
+      return local_exec
 	? BFD_RELOC_AARCH64_TLSLE_MOVW_TPREL_G2
 	: BFD_RELOC_AARCH64_TLSIE_MOVW_GOTTPREL_G1;
 #endif
@@ -5082,7 +5084,7 @@ aarch64_tls_transition (bfd *input_bfd,
   if (! aarch64_can_relax_tls (input_bfd, info, bfd_r_type, h, r_symndx))
     return bfd_r_type;
 
-  return aarch64_tls_transition_without_check (bfd_r_type, h);
+  return aarch64_tls_transition_without_check (bfd_r_type, h, info);
 }
 
 /* Return the base VMA address which should be subtracted from real addresses
@@ -6321,9 +6323,11 @@ static bfd_reloc_status_type
 elfNN_aarch64_tls_relax (struct elf_aarch64_link_hash_table *globals,
 			 bfd *input_bfd, asection *input_section,
 			 bfd_byte *contents, Elf_Internal_Rela *rel,
-			 struct elf_link_hash_entry *h)
+			 struct elf_link_hash_entry *h,
+			 struct bfd_link_info *info)
 {
-  bool is_local = h == NULL;
+  bool local_exec = bfd_link_executable (info)
+    && SYMBOL_REFERENCES_LOCAL (info, h);
   unsigned int r_type = ELFNN_R_TYPE (rel->r_info);
   unsigned long insn;
 
@@ -6333,7 +6337,7 @@ elfNN_aarch64_tls_relax (struct elf_aarch64_link_hash_table *globals,
     {
     case BFD_RELOC_AARCH64_TLSDESC_ADR_PAGE21:
     case BFD_RELOC_AARCH64_TLSGD_ADR_PAGE21:
-      if (is_local)
+      if (local_exec)
 	{
 	  /* GD->LE relaxation:
 	     adrp x0, :tlsgd:var     =>   movz R0, :tprel_g1:var
@@ -6362,7 +6366,7 @@ elfNN_aarch64_tls_relax (struct elf_aarch64_link_hash_table *globals,
       break;
 
     case BFD_RELOC_AARCH64_TLSDESC_LD_PREL19:
-      if (is_local)
+      if (local_exec)
 	{
 	  /* Tiny TLSDESC->LE relaxation:
 	     ldr   x1, :tlsdesc:var	 =>  movz  R0, #:tprel_g1:var
@@ -6404,7 +6408,7 @@ elfNN_aarch64_tls_relax (struct elf_aarch64_link_hash_table *globals,
 	}
 
     case BFD_RELOC_AARCH64_TLSGD_ADR_PREL21:
-      if (is_local)
+      if (local_exec)
 	{
 	  /* Tiny GD->LE relaxation:
 	     adr x0, :tlsgd:var	     =>	  mrs  x1, tpidr_el0
@@ -6456,7 +6460,7 @@ elfNN_aarch64_tls_relax (struct elf_aarch64_link_hash_table *globals,
       BFD_ASSERT (rel->r_offset + 12 == rel[2].r_offset);
       BFD_ASSERT (ELFNN_R_TYPE (rel[2].r_info) == AARCH64_R (CALL26));
 
-      if (is_local)
+      if (local_exec)
 	{
 	  /* Large GD->LE relaxation:
 	     movz x0, #:tlsgd_g1:var	=> movz x0, #:tprel_g2:var, lsl #32
@@ -6500,7 +6504,7 @@ elfNN_aarch64_tls_relax (struct elf_aarch64_link_hash_table *globals,
       return bfd_reloc_continue;
 
     case BFD_RELOC_AARCH64_TLSDESC_LDNN_LO12_NC:
-      if (is_local)
+      if (local_exec)
 	{
 	  /* GD->LE relaxation:
 	     ldr xd, [x0, #:tlsdesc_lo12:var]   =>   movk x0, :tprel_g0_nc:var
@@ -6521,7 +6525,7 @@ elfNN_aarch64_tls_relax (struct elf_aarch64_link_hash_table *globals,
 	}
 
     case BFD_RELOC_AARCH64_TLSGD_ADD_LO12_NC:
-      if (is_local)
+      if (local_exec)
 	{
 	  /* GD->LE relaxation
 	     add  x0, #:tlsgd_lo12:var	=> movk R0, :tprel_g0_nc:var
@@ -6574,7 +6578,7 @@ elfNN_aarch64_tls_relax (struct elf_aarch64_link_hash_table *globals,
       return bfd_reloc_ok;
 
     case BFD_RELOC_AARCH64_TLSDESC_LDR:
-      if (is_local)
+      if (local_exec)
 	{
 	  /* GD->LE relaxation:
 	     ldr xd, [gp, xn]   =>   movk R0, #:tprel_g0_nc:var
@@ -6601,12 +6605,12 @@ elfNN_aarch64_tls_relax (struct elf_aarch64_link_hash_table *globals,
 	 movk xd, #:tlsdesc_off_g0_nc:var => movk Rd, #:gottprel_g0_nc:var
 
 	 Where R is x for lp64 mode, and w for ILP32 mode.  */
-      if (is_local)
+      if (local_exec)
 	bfd_putl32 (ldr_hw_R0, contents + rel->r_offset);
       return bfd_reloc_continue;
 
     case BFD_RELOC_AARCH64_TLSDESC_OFF_G1:
-      if (is_local)
+      if (local_exec)
 	{
 	  /* GD->LE relaxation:
 	     movz xd, #:tlsdesc_off_g1:var => movz R0, #:tprel_g2:var, lsl #32
@@ -6631,7 +6635,7 @@ elfNN_aarch64_tls_relax (struct elf_aarch64_link_hash_table *globals,
 	 adrp xd, :gottprel:var   =>   movz Rd, :tprel_g1:var
 
 	 Where R is x for lp64 mode, and w for ILP32 mode.  */
-      if (is_local)
+      if (local_exec)
 	{
 	  insn = bfd_getl32 (contents + rel->r_offset);
 	  bfd_putl32 (movz_R0 | (insn & 0x1f), contents + rel->r_offset);
@@ -6646,7 +6650,7 @@ elfNN_aarch64_tls_relax (struct elf_aarch64_link_hash_table *globals,
 	 ldr  xd, [xm, #:gottprel_lo12:var]   =>   movk Rd, :tprel_g0_nc:var
 
 	 Where R is x for lp64 mode, and w for ILP32 mode.  */
-      if (is_local)
+      if (local_exec)
 	{
 	  insn = bfd_getl32 (contents + rel->r_offset);
 	  bfd_putl32 (movk_R0 | (insn & 0x1f), contents + rel->r_offset);
@@ -6659,7 +6663,7 @@ elfNN_aarch64_tls_relax (struct elf_aarch64_link_hash_table *globals,
 	 bl   __tls_get_addr => add R0, R0, TCB_SIZE
 
 	 Where R is x for lp64 mode, and w for ilp32 mode.  */
-      if (is_local)
+      if (local_exec)
 	{
 	  BFD_ASSERT (rel->r_offset + 4 == rel[1].r_offset);
 	  BFD_ASSERT (ELFNN_R_TYPE (rel[1].r_info) == AARCH64_R (CALL26));
@@ -6676,7 +6680,7 @@ elfNN_aarch64_tls_relax (struct elf_aarch64_link_hash_table *globals,
       /* LD->LE relaxation (small):
 	 adrp  x0, :tlsldm:x       => mrs x0, tpidr_el0
        */
-      if (is_local)
+      if (local_exec)
 	{
 	  bfd_putl32 (0xd53bd040, contents + rel->r_offset);
 	  return bfd_reloc_ok;
@@ -6689,7 +6693,7 @@ elfNN_aarch64_tls_relax (struct elf_aarch64_link_hash_table *globals,
 	 bl   __tls_get_addr       => nop
 
 	 Where R is x for lp64 mode, and w for ilp32 mode.  */
-      if (is_local)
+      if (local_exec)
 	{
 	  BFD_ASSERT (rel->r_offset + 4 == rel[1].r_offset);
 	  BFD_ASSERT (ELFNN_R_TYPE (rel[1].r_info) == AARCH64_R (CALL26));
@@ -6863,7 +6867,7 @@ elfNN_aarch64_relocate_section (bfd *output_bfd,
 	  BFD_ASSERT (howto != NULL);
 	  r_type = howto->type;
 	  r = elfNN_aarch64_tls_relax (globals, input_bfd, input_section,
-				       contents, rel, h);
+				       contents, rel, h, info);
 	  unresolved_reloc = 0;
 	}
       else
diff --git a/ld/testsuite/ld-aarch64/aarch64-elf.exp b/ld/testsuite/ld-aarch64/aarch64-elf.exp
index 3c45f87151f82b2a3a5fcb10cea4b0cab534ab40..337beadcbfe5d7ea54a7bba45017b10bb1604cb0 100644
--- a/ld/testsuite/ld-aarch64/aarch64-elf.exp
+++ b/ld/testsuite/ld-aarch64/aarch64-elf.exp
@@ -273,17 +273,8 @@ run_dump_test "tls-relax-gd-le-ilp32"
 run_dump_test "tls-relax-gdesc-le"
 run_dump_test "tls-relax-gdesc-le-now"
 run_dump_test "tls-relax-gdesc-le-ilp32"
-run_dump_test "tls-relax-gd-ie"
-run_dump_test "tls-relax-gd-ie-ilp32"
-run_dump_test_lp64 "tls-relax-large-gd-ie"
-run_dump_test_lp64 "tls-relax-large-gd-ie-be"
 run_dump_test_lp64 "tls-relax-large-gd-le"
 run_dump_test_lp64 "tls-relax-large-gd-le-be"
-run_dump_test_lp64 "tls-relax-large-desc-ie"
-run_dump_test_lp64 "tls-relax-large-desc-ie-be"
-run_dump_test_lp64 "tls-relax-large-desc-le"
-run_dump_test_lp64 "tls-relax-large-desc-le-be"
-run_dump_test "tls-relax-gdesc-ie"
 run_dump_test "tls-relax-ie-le"
 run_dump_test "tls-relax-ie-le-ilp32"
 run_dump_test "tls-relax-ld-le-small"
@@ -292,7 +283,6 @@ run_dump_test "tls-relax-ld-le-tiny"
 run_dump_test "tls-relax-ld-le-tiny-ilp32"
 run_dump_test "tls-desc-ie"
 run_dump_test "tls-desc-ie-ilp32"
-run_dump_test "tls-relax-gdesc-ie-2"
 run_dump_test "tls-relax-gdesc-le-2"
 run_dump_test "tls-relax-gdesc-le-2-ilp32"
 run_dump_test "tls-relax-ie-le-2"
@@ -300,13 +290,9 @@ run_dump_test "tls-relax-ie-le-2-ilp32"
 run_dump_test "tls-relax-ie-le-3"
 run_dump_test "tls-relax-ie-le-3-ilp32"
 run_dump_test "tls-tiny-gd"
-run_dump_test "tls-tiny-gd-ie"
-run_dump_test "tls-tiny-gd-ie-ilp32"
 run_dump_test "tls-tiny-gd-le"
 run_dump_test "tls-tiny-gd-le-ilp32"
 run_dump_test "tls-tiny-desc"
-run_dump_test "tls-tiny-desc-ie"
-run_dump_test "tls-tiny-desc-ie-ilp32"
 run_dump_test "tls-tiny-desc-le"
 run_dump_test "tls-tiny-desc-le-ilp32"
 run_dump_test "tls-tiny-ie"
@@ -331,6 +317,33 @@ run_dump_test "protected-data"
 run_dump_test_lp64 "pr22764"
 run_dump_test_lp64 "pr20402"
 
+if {[check_shared_lib_support]
+    && [ld_assemble $as $srcdir/$subdir/tls-sharedlib.s tmpdir/tls-sharedlib.o]
+    && [ld_link $ld tmpdir/tls-sharedlib.so "-shared tmpdir/tls-sharedlib.o"] } {
+      run_dump_test "tls-relax-gd-ie"
+      run_dump_test_lp64 "tls-relax-large-gd-ie"
+      run_dump_test_lp64 "tls-relax-large-gd-ie-be"
+      run_dump_test_lp64 "tls-relax-large-desc-ie"
+      run_dump_test_lp64 "tls-relax-large-desc-ie-be"
+      run_dump_test_lp64 "tls-relax-large-desc-le"
+      run_dump_test_lp64 "tls-relax-large-desc-le-be"
+      run_dump_test "tls-relax-gdesc-ie"
+      run_dump_test "tls-relax-gdesc-ie-2"
+      run_dump_test "tls-tiny-gd-ie"
+      run_dump_test "tls-tiny-desc-ie"
+}
+if {[check_shared_lib_support]
+    && [ld_assemble_flags $as -mabi=ilp32 $srcdir/$subdir/tls-sharedlib.s tmpdir/tls-sharedlib.o]
+    && [ld_link $ld tmpdir/tls-sharedlib-ilp32.so "-shared tmpdir/tls-sharedlib.o -m [aarch64_choose_ilp32_emul]"] } {
+      run_dump_test "tls-relax-gd-ie-ilp32"
+      run_dump_test "tls-tiny-gd-ie-ilp32"
+      run_dump_test "tls-tiny-desc-ie-ilp32"
+}
+run_dump_test "tls-relax-gd-ie-2"
+run_dump_test "tls-relax-gd-ie-3"
+run_dump_test "tls-relax-ie-le-4"
+run_dump_test "tls-gd-symbolic"
+
 # ifunc tests
 run_dump_test "ifunc-1"
 run_dump_test "ifunc-1-local"
diff --git a/ld/testsuite/ld-aarch64/tls-gd-symbolic.d b/ld/testsuite/ld-aarch64/tls-gd-symbolic.d
new file mode 100644
index 0000000000000000000000000000000000000000..d6732acdaf1543ffd51fe23d0da5633ecbe04d14
--- /dev/null
+++ b/ld/testsuite/ld-aarch64/tls-gd-symbolic.d
@@ -0,0 +1,20 @@
+# Testcase to show that -Bsymbolic does not trigger any relaxation from general
+# dynamic or initial exec for global symbols.
+#target: [check_shared_lib_support]
+#ld: -shared -Bsymbolic
+#objdump: -d -j .text
+
+.*:     file format .*
+
+
+Disassembly of section \.text:
+
+[0-9a-f]+ <_test_tls_desc>:
+ +[0-9a-f]+:	........ 	adrp	x0, .*
+ +[0-9a-f]+:	........ 	ldr	x1, \[x0, #.*\]
+ +[0-9a-f]+:	........ 	add	x0, x0, .*
+ +[0-9a-f]+:	d63f0020 	blr	x1
+
+[0-9a-f]+ <_test_tls_desc2>:
+ +[0-9a-f]+:	........ 	adrp	x0, .*
+ +[0-9a-f]+:	........ 	ldr	x0, \[x0, #.*\]
diff --git a/ld/testsuite/ld-aarch64/tls-gd-symbolic.s b/ld/testsuite/ld-aarch64/tls-gd-symbolic.s
new file mode 100644
index 0000000000000000000000000000000000000000..d2ca5dac7be2aeab897d9e7b0d8ec30afc7cec19
--- /dev/null
+++ b/ld/testsuite/ld-aarch64/tls-gd-symbolic.s
@@ -0,0 +1,27 @@
+	# Demonstrating TLS relaxation behavior for -Bsymbolic linking.
+	# (i.e. no extra relaxation when using -Bsymbolic).
+        .global tlsdescvar
+        .global tlsdescvar2
+        .section        .tbss,"awT",%nobits
+        .align  2
+        .type   tlsdescvar, %object
+        .size   tlsdescvar, 4
+tlsdescvar:
+        .zero   4
+        .type   tlsdescvar2, %object
+        .size   tlsdescvar2, 4
+tlsdescvar2:
+        .zero   4
+.text
+_test_tls_desc:
+
+        adrp  x0, :tlsdesc:tlsdescvar
+        ldr   x1, [x0, :tlsdesc_lo12:tlsdescvar]
+        add   x0, x0, :tlsdesc_lo12:tlsdescvar
+        .tlsdesccall tlsdescvar
+        blr   x1
+
+_test_tls_desc2:
+
+        adrp    x0, :gottprel:tlsdescvar2
+        ldr     x0, [x0, #:gottprel_lo12:tlsdescvar2]
diff --git a/ld/testsuite/ld-aarch64/tls-relax-all-ilp32.d b/ld/testsuite/ld-aarch64/tls-relax-all-ilp32.d
index 1cb4ef4261307c13139707ad27b8e85bbe11b0a9..62faed4b73aac484119ed18dbc7f588f6ec8c794 100644
--- a/ld/testsuite/ld-aarch64/tls-relax-all-ilp32.d
+++ b/ld/testsuite/ld-aarch64/tls-relax-all-ilp32.d
@@ -5,8 +5,8 @@
 #...
  +10000:	a9bf7bfd 	stp	x29, x30, \[sp, #-16\]!
  +10004:	910003fd 	mov	x29, sp
- +10008:	90000080 	adrp	x0, 20000 <_GLOBAL_OFFSET_TABLE_>
- +1000c:	b9400400 	ldr	w0, \[x0, #4\]
+ +10008:	52a00000 	movz	w0, #0x0, lsl #16
+ +1000c:	72800100 	movk	w0, #0x8
  +10010:	d503201f 	nop
  +10014:	d503201f 	nop
  +10018:	d53bd041 	mrs	x1, tpidr_el0
@@ -20,8 +20,8 @@
  +10038:	8b000040 	add	x0, x2, x0
  +1003c:	b9400000 	ldr	w0, \[x0\]
  +10040:	0b000021 	add	w1, w1, w0
- +10044:	90000080 	adrp	x0, 20000 <_GLOBAL_OFFSET_TABLE_>
- +10048:	b9400800 	ldr	w0, \[x0, #8\]
+ +10044:	52a00000 	movz	w0, #0x0, lsl #16
+ +10048:	72800200 	movk	w0, #0x10
  +1004c:	d53bd041 	mrs	x1, tpidr_el0
  +10050:	0b000020 	add	w0, w1, w0
  +10054:	b9400000 	ldr	w0, \[x0\]
diff --git a/ld/testsuite/ld-aarch64/tls-relax-all.d b/ld/testsuite/ld-aarch64/tls-relax-all.d
index 59421864f9558050bf1d2ae1cab794bf54ac30df..1262a99a6a0debb22256903a25e9075f1666543b 100644
--- a/ld/testsuite/ld-aarch64/tls-relax-all.d
+++ b/ld/testsuite/ld-aarch64/tls-relax-all.d
@@ -4,8 +4,8 @@
 #...
  +10000:	a9bf7bfd 	stp	x29, x30, \[sp, #-16\]!
  +10004:	910003fd 	mov	x29, sp
- +10008:	90000080 	adrp	x0, 20000 <_GLOBAL_OFFSET_TABLE_>
- +1000c:	f9400400 	ldr	x0, \[x0, #8\]
+ +10008:	d2a00000 	movz	x0, #0x0, lsl #16
+ +1000c:	f2800200 	movk	x0, #0x10
  +10010:	d503201f 	nop
  +10014:	d503201f 	nop
  +10018:	d53bd041 	mrs	x1, tpidr_el0
@@ -19,8 +19,8 @@
  +10038:	8b000040 	add	x0, x2, x0
  +1003c:	b9400000 	ldr	w0, \[x0\]
  +10040:	0b000021 	add	w1, w1, w0
- +10044:	90000080 	adrp	x0, 20000 <_GLOBAL_OFFSET_TABLE_>
- +10048:	f9400800 	ldr	x0, \[x0, #16\]
+ +10044:	d2a00000 	movz	x0, #0x0, lsl #16
+ +10048:	f2800300 	movk	x0, #0x18
  +1004c:	d53bd041 	mrs	x1, tpidr_el0
  +10050:	8b000020 	add	x0, x1, x0
  +10054:	b9400000 	ldr	w0, \[x0\]
diff --git a/ld/testsuite/ld-aarch64/tls-relax-gd-ie-2.d b/ld/testsuite/ld-aarch64/tls-relax-gd-ie-2.d
new file mode 100644
index 0000000000000000000000000000000000000000..f0281b77579d2587062517be9513e7ad76d39a22
--- /dev/null
+++ b/ld/testsuite/ld-aarch64/tls-relax-gd-ie-2.d
@@ -0,0 +1,27 @@
+# The linker recognises that if we have one IE access to a TLS symbol then all
+# accesses to that symbol could be IE.  Here we are also interested to check
+# the linker does not also decide that a second access to that symbol could be
+# LE.
+#target: [check_shared_lib_support]
+#ld: -shared
+#objdump: -dr
+
+.*:     file format .*
+
+
+Disassembly of section \.text:
+
+[0-9a-f]+ <foo>:
+ +[0-9a-f]+:	d2800000 	mov	x0, #0x0                   	// #0
+ +[0-9a-f]+:	d53bd041 	mrs	x1, tpidr_el0
+ +[0-9a-f]+:	.* 	adrp	x0, .*
+ +[0-9a-f]+:	.* 	ldr	x0, \[x0, #.*\]
+ +[0-9a-f]+:	b8606820 	ldr	w0, \[x1, x0\]
+ +[0-9a-f]+:	d53bd041 	mrs	x1, tpidr_el0
+ +[0-9a-f]+:	910003fd 	mov	x29, sp
+ +[0-9a-f]+:	.* 	adrp	x0, .*
+ +[0-9a-f]+:	.* 	ldr	x0, \[x0, #.*\]
+ +[0-9a-f]+:	d503201f 	nop
+ +[0-9a-f]+:	d503201f 	nop
+ +[0-9a-f]+:	b8606820 	ldr	w0, \[x1, x0\]
+ +[0-9a-f]+:	d65f03c0 	ret
diff --git a/ld/testsuite/ld-aarch64/tls-relax-gd-ie-2.s b/ld/testsuite/ld-aarch64/tls-relax-gd-ie-2.s
new file mode 100644
index 0000000000000000000000000000000000000000..568ceb4857cf98e411ccee0d4b62898d1b3c3b22
--- /dev/null
+++ b/ld/testsuite/ld-aarch64/tls-relax-gd-ie-2.s
@@ -0,0 +1,34 @@
+        .section        .tbss,"awT",@nobits
+        .align  2
+        .type   y, %object
+        .size   y, 4
+y:
+        .zero   4
+
+
+
+
+        .text
+        .global foo
+        .type foo, @function
+foo:
+	# Access the local symbol with an IE access.
+        mov     x0, 0
+        mrs     x1, tpidr_el0
+        adrp    x0, :gottprel:y
+        ldr     x0, [x0, #:gottprel_lo12:y]
+        ldr     w0, [x1, x0]
+
+	# Also access the same symbol with a General Dynamic access.
+	# The linker should be able to recognise that if we're already
+	# accessing this symbol with an Initial Exec access then this General
+	# Dynamic access could be relaxed to an Initial Exec one too.
+        mrs     x1, tpidr_el0
+        mov     x29, sp
+        adrp    x0, :tlsdesc:y
+        ldr     x2, [x0, #:tlsdesc_lo12:y]
+        add     x0, x0, :tlsdesc_lo12:y
+        .tlsdesccall    y
+        blr     x2
+        ldr     w0, [x1, x0]
+        ret
diff --git a/ld/testsuite/ld-aarch64/tls-relax-gd-ie-3.d b/ld/testsuite/ld-aarch64/tls-relax-gd-ie-3.d
new file mode 100644
index 0000000000000000000000000000000000000000..2e45ec90d1a853d58834b219bf9ff0fa6847db60
--- /dev/null
+++ b/ld/testsuite/ld-aarch64/tls-relax-gd-ie-3.d
@@ -0,0 +1,29 @@
+# The linker recognises that if we have one IE access to a TLS symbol then all
+# accesses to that symbol could be IE.  Here we are also interested to check
+# the linker does not also decide that a second access to that symbol could be
+# LE.
+#source: tls-relax-gd-ie-2.s
+#target: [check_shared_lib_support]
+#ld: -shared -Bsymbolic
+#objdump: -dr
+
+.*:     file format .*
+
+
+Disassembly of section \.text:
+
+[0-9a-f]+ <foo>:
+ +[0-9a-f]+:	d2800000 	mov	x0, #0x0                   	// #0
+ +[0-9a-f]+:	d53bd041 	mrs	x1, tpidr_el0
+ +[0-9a-f]+:	.* 	adrp	x0, .*
+ +[0-9a-f]+:	.* 	ldr	x0, \[x0, #.*\]
+ +[0-9a-f]+:	b8606820 	ldr	w0, \[x1, x0\]
+ +[0-9a-f]+:	d53bd041 	mrs	x1, tpidr_el0
+ +[0-9a-f]+:	910003fd 	mov	x29, sp
+ +[0-9a-f]+:	.* 	adrp	x0, .*
+ +[0-9a-f]+:	.* 	ldr	x0, \[x0, #.*\]
+ +[0-9a-f]+:	d503201f 	nop
+ +[0-9a-f]+:	d503201f 	nop
+ +[0-9a-f]+:	b8606820 	ldr	w0, \[x1, x0\]
+ +[0-9a-f]+:	d65f03c0 	ret
+
diff --git a/ld/testsuite/ld-aarch64/tls-relax-gd-ie-ilp32.d b/ld/testsuite/ld-aarch64/tls-relax-gd-ie-ilp32.d
index ab08c6161b9330110a9ffbb33eb6d44b0a8e8ac7..340206a9e2bbd37534eb3a1fed79e6386480aed3 100644
--- a/ld/testsuite/ld-aarch64/tls-relax-gd-ie-ilp32.d
+++ b/ld/testsuite/ld-aarch64/tls-relax-gd-ie-ilp32.d
@@ -1,6 +1,6 @@
 #source: tls-relax-gd-ie.s
 #as: -mabi=ilp32
-#ld: -m [aarch64_choose_ilp32_emul] -T relocs-ilp32.ld -e0
+#ld: -m [aarch64_choose_ilp32_emul] -T relocs-ilp32.ld -e0 tmpdir/tls-sharedlib-ilp32.so
 #objdump: -dr
 #...
  +10000:	90000080 	adrp	x0, 20000 <_GLOBAL_OFFSET_TABLE_>
diff --git a/ld/testsuite/ld-aarch64/tls-relax-gd-ie.d b/ld/testsuite/ld-aarch64/tls-relax-gd-ie.d
index f80bb9077705d83e793fcdd6b45169ac82a24aa9..0c03290e0a9cca61baab061e0b24475f9a8f00ab 100644
--- a/ld/testsuite/ld-aarch64/tls-relax-gd-ie.d
+++ b/ld/testsuite/ld-aarch64/tls-relax-gd-ie.d
@@ -1,5 +1,5 @@
 #source: tls-relax-gd-ie.s
-#ld: -T relocs.ld -e0
+#ld: -T relocs.ld -e0 tmpdir/tls-sharedlib.so
 #objdump: -dr
 #...
  +10000:	90000080 	adrp	x0, 20000 <_GLOBAL_OFFSET_TABLE_>
diff --git a/ld/testsuite/ld-aarch64/tls-relax-gd-ie.s b/ld/testsuite/ld-aarch64/tls-relax-gd-ie.s
index 88c7eec73e43afb680a6c1c9051bf5485491fa1e..afe076c8c8203ee547e84ccab544b67e388279d3 100644
--- a/ld/testsuite/ld-aarch64/tls-relax-gd-ie.s
+++ b/ld/testsuite/ld-aarch64/tls-relax-gd-ie.s
@@ -1,7 +1,3 @@
-	.global	var
-	.section	.tdata,"awT",%progbits
-var:
-	.word	2
 	.text
 	adrp	x0, :tlsgd:var
 	add	x0, x0, :tlsgd_lo12:var
diff --git a/ld/testsuite/ld-aarch64/tls-relax-gdesc-ie-2.d b/ld/testsuite/ld-aarch64/tls-relax-gdesc-ie-2.d
index 2b8e346fc66c79c3d992714da7a876dc83c0b5ee..f13263f201ff781b0c8c41f468c069ee71c4fd61 100644
--- a/ld/testsuite/ld-aarch64/tls-relax-gdesc-ie-2.d
+++ b/ld/testsuite/ld-aarch64/tls-relax-gdesc-ie-2.d
@@ -1,5 +1,5 @@
 #source: tls-relax-gdesc-ie-2.s
-#ld: -T relocs.ld -e0
+#ld: -T relocs.ld -e0 tmpdir/tls-sharedlib.so
 #objdump: -dr
 #...
  +10000:	90000080 	adrp	x0, 20000 <_GLOBAL_OFFSET_TABLE_>
diff --git a/ld/testsuite/ld-aarch64/tls-relax-gdesc-ie-2.s b/ld/testsuite/ld-aarch64/tls-relax-gdesc-ie-2.s
index 790b6c6eb8bb4b9c2efa0688f46a5413d8231f78..f7be57c320716d6c56559d2ebfa181a2944bdb88 100644
--- a/ld/testsuite/ld-aarch64/tls-relax-gdesc-ie-2.s
+++ b/ld/testsuite/ld-aarch64/tls-relax-gdesc-ie-2.s
@@ -1,9 +1,5 @@
 // Test TLS Desc to TLS IE relaxation when instructions are not consecutive.
 
-	.global	var
-	.section	.tdata
-var:
-	.word	2
 	.text
 	adrp	x0, :tlsdesc:var
 	nop
@@ -20,5 +16,4 @@ var:
 	mrs	x1, tpidr_el0
 	add	x0, x1, x0
 	ldr	w0, [x0]
-	.global	var
 	.section	.tdata
diff --git a/ld/testsuite/ld-aarch64/tls-relax-gdesc-ie.d b/ld/testsuite/ld-aarch64/tls-relax-gdesc-ie.d
index 86277f82565c401aa6d2b4b365e2c9c8bc8ccfe6..1ace84858a32e1ef0336cf24f7017a55ccbb611e 100644
--- a/ld/testsuite/ld-aarch64/tls-relax-gdesc-ie.d
+++ b/ld/testsuite/ld-aarch64/tls-relax-gdesc-ie.d
@@ -1,5 +1,5 @@
 #source: tls-relax-gdesc-ie.s
-#ld: -T relocs.ld -e0
+#ld: -T relocs.ld -e0 tmpdir/tls-sharedlib.so
 #objdump: -dr
 #...
  +10000:	90000080 	adrp	x0, 20000 <_GLOBAL_OFFSET_TABLE_>
diff --git a/ld/testsuite/ld-aarch64/tls-relax-gdesc-ie.s b/ld/testsuite/ld-aarch64/tls-relax-gdesc-ie.s
index 38b372132f49c926be8d6527bce9d203b794a4b5..089d36c9cc8a9f4dd9f6cfe71996bdbdd9b68502 100644
--- a/ld/testsuite/ld-aarch64/tls-relax-gdesc-ie.s
+++ b/ld/testsuite/ld-aarch64/tls-relax-gdesc-ie.s
@@ -1,7 +1,3 @@
-	.global	var
-	.section	.tdata
-var:
-	.word	2
 	.text
 	adrp	x0, :tlsdesc:var
 	ldr	x17, [x0, #:tlsdesc_lo12:var]
diff --git a/ld/testsuite/ld-aarch64/tls-relax-ie-le-4.d b/ld/testsuite/ld-aarch64/tls-relax-ie-le-4.d
new file mode 100644
index 0000000000000000000000000000000000000000..e2bc5f1530440d19077c455db5783ef10da24bf2
--- /dev/null
+++ b/ld/testsuite/ld-aarch64/tls-relax-ie-le-4.d
@@ -0,0 +1,20 @@
+# We already test that we relax an access to a local symbol, this testcase
+# checks that we relax an access to a global-binding symbol if the static linker
+# knows that the symbol will resolve to the executable local value.
+#
+# The access should be relaxed to a LE access.
+#ld:
+#objdump: -d
+
+.*:     file format .*
+
+
+Disassembly of section \.text:
+
+[0-9a-f]+ <_start>:
+ +[0-9a-f]+:	d2800000 	mov	x0, #0x0                   	// #0
+ +[0-9a-f]+:	d53bd041 	mrs	x1, tpidr_el0
+ +[0-9a-f]+:	d2a00000 	movz	x0, #0x0, lsl #16
+ +[0-9a-f]+:	f2800200 	movk	x0, #0x10
+ +[0-9a-f]+:	b8606820 	ldr	w0, \[x1, x0\]
+ +[0-9a-f]+:	d65f03c0 	ret
diff --git a/ld/testsuite/ld-aarch64/tls-relax-ie-le-4.s b/ld/testsuite/ld-aarch64/tls-relax-ie-le-4.s
new file mode 100644
index 0000000000000000000000000000000000000000..e151cd4efd6cc729d220ceea5f318ecd3a8ed3d8
--- /dev/null
+++ b/ld/testsuite/ld-aarch64/tls-relax-ie-le-4.s
@@ -0,0 +1,22 @@
+# Test TLS IE to TLS LE relaxation for global symbols.
+        .section        .tbss,"awT",@nobits
+        .global x
+        .align  2
+        .type   x, %object
+        .size   x, 4
+x:
+        .zero   4
+
+
+
+        .text
+        .global _start
+        .type _start, @function
+_start:
+        mov     x0, 0
+        mrs     x1, tpidr_el0
+        adrp    x0, :gottprel:x
+        ldr     x0, [x0, #:gottprel_lo12:x]
+        ldr     w0, [x1, x0]
+        ret
+
diff --git a/ld/testsuite/ld-aarch64/tls-relax-large-desc-ie.d b/ld/testsuite/ld-aarch64/tls-relax-large-desc-ie.d
index 21ad5e5a18c265e5e095b2053752a578d689d411..cb546ad74e6da35e7d3cd4f56ba62af52afebc22 100644
--- a/ld/testsuite/ld-aarch64/tls-relax-large-desc-ie.d
+++ b/ld/testsuite/ld-aarch64/tls-relax-large-desc-ie.d
@@ -1,5 +1,5 @@
 #source: tls-relax-large-desc-ie.s
-#ld: -T relocs.ld -e0
+#ld: -T relocs.ld -e0 tmpdir/tls-sharedlib.so
 #notarget: aarch64_be-*-*
 #objdump: -dr
 #...
diff --git a/ld/testsuite/ld-aarch64/tls-relax-large-desc-ie.s b/ld/testsuite/ld-aarch64/tls-relax-large-desc-ie.s
index a4d1e00086ad3ed3818eb73b4aba606cb0de6cf7..98dc2a571d5836b60f05cb9daf47b385456a3ee2 100644
--- a/ld/testsuite/ld-aarch64/tls-relax-large-desc-ie.s
+++ b/ld/testsuite/ld-aarch64/tls-relax-large-desc-ie.s
@@ -1,8 +1,3 @@
-	.global var
-	.section	.tdata,"awT",%progbits
-var:
-	.word 2
-
 	.text
 test:
 	ldr x1, .Lgot
diff --git a/ld/testsuite/ld-aarch64/tls-relax-large-gd-ie.d b/ld/testsuite/ld-aarch64/tls-relax-large-gd-ie.d
index 2b398dbb9c6ce48f48f258e3ed337dcd383af82c..740178d46105483fa4176b1a4c77ebac459ef846 100644
--- a/ld/testsuite/ld-aarch64/tls-relax-large-gd-ie.d
+++ b/ld/testsuite/ld-aarch64/tls-relax-large-gd-ie.d
@@ -1,5 +1,5 @@
 #source: tls-relax-large-gd-ie.s
-#ld: -T relocs.ld -e0
+#ld: -T relocs.ld -e0 tmpdir/tls-sharedlib.so
 #notarget: aarch64_be-*-*
 #objdump: -dr
 #...
diff --git a/ld/testsuite/ld-aarch64/tls-relax-large-gd-ie.s b/ld/testsuite/ld-aarch64/tls-relax-large-gd-ie.s
index 8e0310d6b3f8caecdbfc2bdd3f310b6ee3942d80..d35aace776ee0bc327cfa1cf258c8ce687865d7a 100644
--- a/ld/testsuite/ld-aarch64/tls-relax-large-gd-ie.s
+++ b/ld/testsuite/ld-aarch64/tls-relax-large-gd-ie.s
@@ -1,8 +1,3 @@
-	.global var
-	.section	.tdata,"awT",%progbits
-var:
-	.word	2
-
 	.text
 test:
 	ldr	x1, .Lgot
diff --git a/ld/testsuite/ld-aarch64/tls-sharedlib.s b/ld/testsuite/ld-aarch64/tls-sharedlib.s
new file mode 100644
index 0000000000000000000000000000000000000000..8838b9f23484ac6c0535c43256818050fbf3a4fd
--- /dev/null
+++ b/ld/testsuite/ld-aarch64/tls-sharedlib.s
@@ -0,0 +1,4 @@
+    .global var
+    .section  .tdata,"awT",@progbits
+var:
+    .word 2
diff --git a/ld/testsuite/ld-aarch64/tls-tiny-desc-ie-ilp32.d b/ld/testsuite/ld-aarch64/tls-tiny-desc-ie-ilp32.d
index ebbaf854baa9548503d0eeac351ab3ee6e330183..3dffa1b85e6376fd72970ba79ecf8d42640173ae 100644
--- a/ld/testsuite/ld-aarch64/tls-tiny-desc-ie-ilp32.d
+++ b/ld/testsuite/ld-aarch64/tls-tiny-desc-ie-ilp32.d
@@ -1,12 +1,12 @@
 #source: tls-tiny-desc-ie.s
 #as: -mabi=ilp32
-#ld: -m [aarch64_choose_ilp32_emul] -T relocs-ilp32.ld -e0
+#ld: -m [aarch64_choose_ilp32_emul] -T relocs-ilp32.ld -e0 tmpdir/tls-sharedlib-ilp32.so
 #objdump: -dr
 #...
 
 Disassembly of section .text:
 
 00010000 \<test\>:
- +10000:	18080020 	ldr	w0, 20004 \<_GLOBAL_OFFSET_TABLE_\+0x4\>
+ +10000:	18080020 	ldr	w0, 20004 \<var\>
  +10004:	d503201f 	nop
  +10008:	d503201f 	nop
diff --git a/ld/testsuite/ld-aarch64/tls-tiny-desc-ie.d b/ld/testsuite/ld-aarch64/tls-tiny-desc-ie.d
index 0088539d6bfae0bdfc70c86afeaf7f1d16305d12..e759ae94576ccca484a9690d1334032f97df6fd6 100644
--- a/ld/testsuite/ld-aarch64/tls-tiny-desc-ie.d
+++ b/ld/testsuite/ld-aarch64/tls-tiny-desc-ie.d
@@ -1,11 +1,11 @@
 #source: tls-tiny-desc-ie.s
-#ld: -T relocs.ld -e0
+#ld: -T relocs.ld -e0 tmpdir/tls-sharedlib.so
 #objdump: -dr
 #...
 
 Disassembly of section .text:
 
 0000000000010000 \<test\>:
- +10000:	58080040 	ldr	x0, 20008 \<_GLOBAL_OFFSET_TABLE_\+0x8\>
+ +10000:	58080040 	ldr	x0, 20008 \<var\>
  +10004:	d503201f 	nop
  +10008:	d503201f 	nop
diff --git a/ld/testsuite/ld-aarch64/tls-tiny-desc-ie.s b/ld/testsuite/ld-aarch64/tls-tiny-desc-ie.s
index 520cd4e85b29f8c3acc912d2d31b902b91ee337e..fcc970f6d8f46b7c57724b55c857dcee77bc0722 100644
--- a/ld/testsuite/ld-aarch64/tls-tiny-desc-ie.s
+++ b/ld/testsuite/ld-aarch64/tls-tiny-desc-ie.s
@@ -1,12 +1,3 @@
-        .global var
-
-        .section .tbss,"awT",%nobits
-        .align  2
-        .type   var, %object
-        .size   var, 4
-var:
-	.zero   4
-
 	.text
 test:
         ldr	x1, :tlsdesc:var
diff --git a/ld/testsuite/ld-aarch64/tls-tiny-gd-ie-ilp32.d b/ld/testsuite/ld-aarch64/tls-tiny-gd-ie-ilp32.d
index 1ea61103b47ba1a23703be914da5f5f1008a9cb1..6317152eb1ecc8830d8a0b736276c4ef19301d58 100644
--- a/ld/testsuite/ld-aarch64/tls-tiny-gd-ie-ilp32.d
+++ b/ld/testsuite/ld-aarch64/tls-tiny-gd-ie-ilp32.d
@@ -1,12 +1,12 @@
 #source: tls-tiny-gd-ie.s
 #as: -mabi=ilp32
-#ld: -m [aarch64_choose_ilp32_emul] -T relocs-ilp32.ld -e0
+#ld: -m [aarch64_choose_ilp32_emul] -T relocs-ilp32.ld -e0 tmpdir/tls-sharedlib-ilp32.so
 #objdump: -dr
 #...
 
 Disassembly of section .text:
 
 00010000 \<test\>:
- +10000:	18080020 	ldr	w0, 20004 \<_GLOBAL_OFFSET_TABLE_\+0x4\>
+ +10000:	18080020 	ldr	w0, 20004 \<var\>
  +10004:	d53bd041 	mrs	x1, tpidr_el0
  +10008:	0b000020 	add	w0, w1, w0
diff --git a/ld/testsuite/ld-aarch64/tls-tiny-gd-ie.d b/ld/testsuite/ld-aarch64/tls-tiny-gd-ie.d
index 629d90c942d34845e700b935ef2701d06235b7dd..66b996e6f4abc279d96be510956eff0c606ab240 100644
--- a/ld/testsuite/ld-aarch64/tls-tiny-gd-ie.d
+++ b/ld/testsuite/ld-aarch64/tls-tiny-gd-ie.d
@@ -1,11 +1,11 @@
 #source: tls-tiny-gd-ie.s
-#ld: -T relocs.ld -e0
+#ld: -T relocs.ld -e0 tmpdir/tls-sharedlib.so
 #objdump: -dr
 #...
 
 Disassembly of section .text:
 
 0000000000010000 \<test\>:
- +10000:	58080040 	ldr	x0, 20008 \<_GLOBAL_OFFSET_TABLE_\+0x8\>
+ +10000:	58080040 	ldr	x0, 20008 \<var\>
  +10004:	d53bd041 	mrs	x1, tpidr_el0
  +10008:	8b000020 	add	x0, x1, x0
diff --git a/ld/testsuite/ld-aarch64/tls-tiny-gd-ie.s b/ld/testsuite/ld-aarch64/tls-tiny-gd-ie.s
index 4dc7e66bbdb7d7c01754aebcdaf4b1328667e143..3ae4a0cc9fe1329140c60ed9424b80e8b4669da3 100644
--- a/ld/testsuite/ld-aarch64/tls-tiny-gd-ie.s
+++ b/ld/testsuite/ld-aarch64/tls-tiny-gd-ie.s
@@ -1,12 +1,3 @@
-        .global var
-
-        .section .tbss,"awT",%nobits
-        .align  2
-        .type   var, %object
-        .size   var, 4
-var:
-	.zero   4
-
 	.text
 test:
         adr x0, :tlsgd:var




[-- Attachment #2: local-exec-tls.patch --]
[-- Type: text/plain, Size: 31688 bytes --]

diff --git a/bfd/elfnn-aarch64.c b/bfd/elfnn-aarch64.c
index 251a27edb571a91fc51a2d0de2613f72c29e299d..c675292d232abdde37d6996b3883929ce896e924 100644
--- a/bfd/elfnn-aarch64.c
+++ b/bfd/elfnn-aarch64.c
@@ -4898,60 +4898,62 @@ aarch64_calculate_got_entry_vma (struct elf_link_hash_entry *h,
 
 static bfd_reloc_code_real_type
 aarch64_tls_transition_without_check (bfd_reloc_code_real_type r_type,
-				      struct elf_link_hash_entry *h)
+				      struct elf_link_hash_entry *h,
+				      struct bfd_link_info *info)
 {
-  bool is_local = h == NULL;
+  bool local_exec = bfd_link_executable (info)
+    && SYMBOL_REFERENCES_LOCAL (info, h);
 
   switch (r_type)
     {
     case BFD_RELOC_AARCH64_TLSDESC_ADR_PAGE21:
     case BFD_RELOC_AARCH64_TLSGD_ADR_PAGE21:
-      return (is_local
+      return (local_exec
 	      ? BFD_RELOC_AARCH64_TLSLE_MOVW_TPREL_G1
 	      : BFD_RELOC_AARCH64_TLSIE_ADR_GOTTPREL_PAGE21);
 
     case BFD_RELOC_AARCH64_TLSDESC_ADR_PREL21:
-      return (is_local
+      return (local_exec
 	      ? BFD_RELOC_AARCH64_TLSLE_MOVW_TPREL_G0_NC
 	      : r_type);
 
     case BFD_RELOC_AARCH64_TLSDESC_LD_PREL19:
-      return (is_local
+      return (local_exec
 	      ? BFD_RELOC_AARCH64_TLSLE_MOVW_TPREL_G1
 	      : BFD_RELOC_AARCH64_TLSIE_LD_GOTTPREL_PREL19);
 
     case BFD_RELOC_AARCH64_TLSDESC_LDR:
-      return (is_local
+      return (local_exec
 	      ? BFD_RELOC_AARCH64_TLSLE_MOVW_TPREL_G0_NC
 	      : BFD_RELOC_AARCH64_NONE);
 
     case BFD_RELOC_AARCH64_TLSDESC_OFF_G0_NC:
-      return (is_local
+      return (local_exec
 	      ? BFD_RELOC_AARCH64_TLSLE_MOVW_TPREL_G1_NC
 	      : BFD_RELOC_AARCH64_TLSIE_MOVW_GOTTPREL_G0_NC);
 
     case BFD_RELOC_AARCH64_TLSDESC_OFF_G1:
-      return (is_local
+      return (local_exec
 	      ? BFD_RELOC_AARCH64_TLSLE_MOVW_TPREL_G2
 	      : BFD_RELOC_AARCH64_TLSIE_MOVW_GOTTPREL_G1);
 
     case BFD_RELOC_AARCH64_TLSDESC_LDNN_LO12_NC:
     case BFD_RELOC_AARCH64_TLSGD_ADD_LO12_NC:
-      return (is_local
+      return (local_exec
 	      ? BFD_RELOC_AARCH64_TLSLE_MOVW_TPREL_G0_NC
 	      : BFD_RELOC_AARCH64_TLSIE_LDNN_GOTTPREL_LO12_NC);
 
     case BFD_RELOC_AARCH64_TLSIE_ADR_GOTTPREL_PAGE21:
-      return is_local ? BFD_RELOC_AARCH64_TLSLE_MOVW_TPREL_G1 : r_type;
+      return local_exec ? BFD_RELOC_AARCH64_TLSLE_MOVW_TPREL_G1 : r_type;
 
     case BFD_RELOC_AARCH64_TLSIE_LDNN_GOTTPREL_LO12_NC:
-      return is_local ? BFD_RELOC_AARCH64_TLSLE_MOVW_TPREL_G0_NC : r_type;
+      return local_exec ? BFD_RELOC_AARCH64_TLSLE_MOVW_TPREL_G0_NC : r_type;
 
     case BFD_RELOC_AARCH64_TLSIE_LD_GOTTPREL_PREL19:
       return r_type;
 
     case BFD_RELOC_AARCH64_TLSGD_ADR_PREL21:
-      return (is_local
+      return (local_exec
 	      ? BFD_RELOC_AARCH64_TLSLE_ADD_TPREL_HI12
 	      : BFD_RELOC_AARCH64_TLSIE_LD_GOTTPREL_PREL19);
 
@@ -4964,16 +4966,16 @@ aarch64_tls_transition_without_check (bfd_reloc_code_real_type r_type,
     case BFD_RELOC_AARCH64_TLSLD_ADD_LO12_NC:
     case BFD_RELOC_AARCH64_TLSLD_ADR_PAGE21:
     case BFD_RELOC_AARCH64_TLSLD_ADR_PREL21:
-      return is_local ? BFD_RELOC_AARCH64_NONE : r_type;
+      return local_exec ? BFD_RELOC_AARCH64_NONE : r_type;
 
 #if ARCH_SIZE == 64
     case BFD_RELOC_AARCH64_TLSGD_MOVW_G0_NC:
-      return is_local
+      return local_exec
 	? BFD_RELOC_AARCH64_TLSLE_MOVW_TPREL_G1_NC
 	: BFD_RELOC_AARCH64_TLSIE_MOVW_GOTTPREL_G0_NC;
 
     case BFD_RELOC_AARCH64_TLSGD_MOVW_G1:
-      return is_local
+      return local_exec
 	? BFD_RELOC_AARCH64_TLSLE_MOVW_TPREL_G2
 	: BFD_RELOC_AARCH64_TLSIE_MOVW_GOTTPREL_G1;
 #endif
@@ -5082,7 +5084,7 @@ aarch64_tls_transition (bfd *input_bfd,
   if (! aarch64_can_relax_tls (input_bfd, info, bfd_r_type, h, r_symndx))
     return bfd_r_type;
 
-  return aarch64_tls_transition_without_check (bfd_r_type, h);
+  return aarch64_tls_transition_without_check (bfd_r_type, h, info);
 }
 
 /* Return the base VMA address which should be subtracted from real addresses
@@ -6321,9 +6323,11 @@ static bfd_reloc_status_type
 elfNN_aarch64_tls_relax (struct elf_aarch64_link_hash_table *globals,
 			 bfd *input_bfd, asection *input_section,
 			 bfd_byte *contents, Elf_Internal_Rela *rel,
-			 struct elf_link_hash_entry *h)
+			 struct elf_link_hash_entry *h,
+			 struct bfd_link_info *info)
 {
-  bool is_local = h == NULL;
+  bool local_exec = bfd_link_executable (info)
+    && SYMBOL_REFERENCES_LOCAL (info, h);
   unsigned int r_type = ELFNN_R_TYPE (rel->r_info);
   unsigned long insn;
 
@@ -6333,7 +6337,7 @@ elfNN_aarch64_tls_relax (struct elf_aarch64_link_hash_table *globals,
     {
     case BFD_RELOC_AARCH64_TLSDESC_ADR_PAGE21:
     case BFD_RELOC_AARCH64_TLSGD_ADR_PAGE21:
-      if (is_local)
+      if (local_exec)
 	{
 	  /* GD->LE relaxation:
 	     adrp x0, :tlsgd:var     =>   movz R0, :tprel_g1:var
@@ -6362,7 +6366,7 @@ elfNN_aarch64_tls_relax (struct elf_aarch64_link_hash_table *globals,
       break;
 
     case BFD_RELOC_AARCH64_TLSDESC_LD_PREL19:
-      if (is_local)
+      if (local_exec)
 	{
 	  /* Tiny TLSDESC->LE relaxation:
 	     ldr   x1, :tlsdesc:var	 =>  movz  R0, #:tprel_g1:var
@@ -6404,7 +6408,7 @@ elfNN_aarch64_tls_relax (struct elf_aarch64_link_hash_table *globals,
 	}
 
     case BFD_RELOC_AARCH64_TLSGD_ADR_PREL21:
-      if (is_local)
+      if (local_exec)
 	{
 	  /* Tiny GD->LE relaxation:
 	     adr x0, :tlsgd:var	     =>	  mrs  x1, tpidr_el0
@@ -6456,7 +6460,7 @@ elfNN_aarch64_tls_relax (struct elf_aarch64_link_hash_table *globals,
       BFD_ASSERT (rel->r_offset + 12 == rel[2].r_offset);
       BFD_ASSERT (ELFNN_R_TYPE (rel[2].r_info) == AARCH64_R (CALL26));
 
-      if (is_local)
+      if (local_exec)
 	{
 	  /* Large GD->LE relaxation:
 	     movz x0, #:tlsgd_g1:var	=> movz x0, #:tprel_g2:var, lsl #32
@@ -6500,7 +6504,7 @@ elfNN_aarch64_tls_relax (struct elf_aarch64_link_hash_table *globals,
       return bfd_reloc_continue;
 
     case BFD_RELOC_AARCH64_TLSDESC_LDNN_LO12_NC:
-      if (is_local)
+      if (local_exec)
 	{
 	  /* GD->LE relaxation:
 	     ldr xd, [x0, #:tlsdesc_lo12:var]   =>   movk x0, :tprel_g0_nc:var
@@ -6521,7 +6525,7 @@ elfNN_aarch64_tls_relax (struct elf_aarch64_link_hash_table *globals,
 	}
 
     case BFD_RELOC_AARCH64_TLSGD_ADD_LO12_NC:
-      if (is_local)
+      if (local_exec)
 	{
 	  /* GD->LE relaxation
 	     add  x0, #:tlsgd_lo12:var	=> movk R0, :tprel_g0_nc:var
@@ -6574,7 +6578,7 @@ elfNN_aarch64_tls_relax (struct elf_aarch64_link_hash_table *globals,
       return bfd_reloc_ok;
 
     case BFD_RELOC_AARCH64_TLSDESC_LDR:
-      if (is_local)
+      if (local_exec)
 	{
 	  /* GD->LE relaxation:
 	     ldr xd, [gp, xn]   =>   movk R0, #:tprel_g0_nc:var
@@ -6601,12 +6605,12 @@ elfNN_aarch64_tls_relax (struct elf_aarch64_link_hash_table *globals,
 	 movk xd, #:tlsdesc_off_g0_nc:var => movk Rd, #:gottprel_g0_nc:var
 
 	 Where R is x for lp64 mode, and w for ILP32 mode.  */
-      if (is_local)
+      if (local_exec)
 	bfd_putl32 (ldr_hw_R0, contents + rel->r_offset);
       return bfd_reloc_continue;
 
     case BFD_RELOC_AARCH64_TLSDESC_OFF_G1:
-      if (is_local)
+      if (local_exec)
 	{
 	  /* GD->LE relaxation:
 	     movz xd, #:tlsdesc_off_g1:var => movz R0, #:tprel_g2:var, lsl #32
@@ -6631,7 +6635,7 @@ elfNN_aarch64_tls_relax (struct elf_aarch64_link_hash_table *globals,
 	 adrp xd, :gottprel:var   =>   movz Rd, :tprel_g1:var
 
 	 Where R is x for lp64 mode, and w for ILP32 mode.  */
-      if (is_local)
+      if (local_exec)
 	{
 	  insn = bfd_getl32 (contents + rel->r_offset);
 	  bfd_putl32 (movz_R0 | (insn & 0x1f), contents + rel->r_offset);
@@ -6646,7 +6650,7 @@ elfNN_aarch64_tls_relax (struct elf_aarch64_link_hash_table *globals,
 	 ldr  xd, [xm, #:gottprel_lo12:var]   =>   movk Rd, :tprel_g0_nc:var
 
 	 Where R is x for lp64 mode, and w for ILP32 mode.  */
-      if (is_local)
+      if (local_exec)
 	{
 	  insn = bfd_getl32 (contents + rel->r_offset);
 	  bfd_putl32 (movk_R0 | (insn & 0x1f), contents + rel->r_offset);
@@ -6659,7 +6663,7 @@ elfNN_aarch64_tls_relax (struct elf_aarch64_link_hash_table *globals,
 	 bl   __tls_get_addr => add R0, R0, TCB_SIZE
 
 	 Where R is x for lp64 mode, and w for ilp32 mode.  */
-      if (is_local)
+      if (local_exec)
 	{
 	  BFD_ASSERT (rel->r_offset + 4 == rel[1].r_offset);
 	  BFD_ASSERT (ELFNN_R_TYPE (rel[1].r_info) == AARCH64_R (CALL26));
@@ -6676,7 +6680,7 @@ elfNN_aarch64_tls_relax (struct elf_aarch64_link_hash_table *globals,
       /* LD->LE relaxation (small):
 	 adrp  x0, :tlsldm:x       => mrs x0, tpidr_el0
        */
-      if (is_local)
+      if (local_exec)
 	{
 	  bfd_putl32 (0xd53bd040, contents + rel->r_offset);
 	  return bfd_reloc_ok;
@@ -6689,7 +6693,7 @@ elfNN_aarch64_tls_relax (struct elf_aarch64_link_hash_table *globals,
 	 bl   __tls_get_addr       => nop
 
 	 Where R is x for lp64 mode, and w for ilp32 mode.  */
-      if (is_local)
+      if (local_exec)
 	{
 	  BFD_ASSERT (rel->r_offset + 4 == rel[1].r_offset);
 	  BFD_ASSERT (ELFNN_R_TYPE (rel[1].r_info) == AARCH64_R (CALL26));
@@ -6863,7 +6867,7 @@ elfNN_aarch64_relocate_section (bfd *output_bfd,
 	  BFD_ASSERT (howto != NULL);
 	  r_type = howto->type;
 	  r = elfNN_aarch64_tls_relax (globals, input_bfd, input_section,
-				       contents, rel, h);
+				       contents, rel, h, info);
 	  unresolved_reloc = 0;
 	}
       else
diff --git a/ld/testsuite/ld-aarch64/aarch64-elf.exp b/ld/testsuite/ld-aarch64/aarch64-elf.exp
index 3c45f87151f82b2a3a5fcb10cea4b0cab534ab40..337beadcbfe5d7ea54a7bba45017b10bb1604cb0 100644
--- a/ld/testsuite/ld-aarch64/aarch64-elf.exp
+++ b/ld/testsuite/ld-aarch64/aarch64-elf.exp
@@ -273,17 +273,8 @@ run_dump_test "tls-relax-gd-le-ilp32"
 run_dump_test "tls-relax-gdesc-le"
 run_dump_test "tls-relax-gdesc-le-now"
 run_dump_test "tls-relax-gdesc-le-ilp32"
-run_dump_test "tls-relax-gd-ie"
-run_dump_test "tls-relax-gd-ie-ilp32"
-run_dump_test_lp64 "tls-relax-large-gd-ie"
-run_dump_test_lp64 "tls-relax-large-gd-ie-be"
 run_dump_test_lp64 "tls-relax-large-gd-le"
 run_dump_test_lp64 "tls-relax-large-gd-le-be"
-run_dump_test_lp64 "tls-relax-large-desc-ie"
-run_dump_test_lp64 "tls-relax-large-desc-ie-be"
-run_dump_test_lp64 "tls-relax-large-desc-le"
-run_dump_test_lp64 "tls-relax-large-desc-le-be"
-run_dump_test "tls-relax-gdesc-ie"
 run_dump_test "tls-relax-ie-le"
 run_dump_test "tls-relax-ie-le-ilp32"
 run_dump_test "tls-relax-ld-le-small"
@@ -292,7 +283,6 @@ run_dump_test "tls-relax-ld-le-tiny"
 run_dump_test "tls-relax-ld-le-tiny-ilp32"
 run_dump_test "tls-desc-ie"
 run_dump_test "tls-desc-ie-ilp32"
-run_dump_test "tls-relax-gdesc-ie-2"
 run_dump_test "tls-relax-gdesc-le-2"
 run_dump_test "tls-relax-gdesc-le-2-ilp32"
 run_dump_test "tls-relax-ie-le-2"
@@ -300,13 +290,9 @@ run_dump_test "tls-relax-ie-le-2-ilp32"
 run_dump_test "tls-relax-ie-le-3"
 run_dump_test "tls-relax-ie-le-3-ilp32"
 run_dump_test "tls-tiny-gd"
-run_dump_test "tls-tiny-gd-ie"
-run_dump_test "tls-tiny-gd-ie-ilp32"
 run_dump_test "tls-tiny-gd-le"
 run_dump_test "tls-tiny-gd-le-ilp32"
 run_dump_test "tls-tiny-desc"
-run_dump_test "tls-tiny-desc-ie"
-run_dump_test "tls-tiny-desc-ie-ilp32"
 run_dump_test "tls-tiny-desc-le"
 run_dump_test "tls-tiny-desc-le-ilp32"
 run_dump_test "tls-tiny-ie"
@@ -331,6 +317,33 @@ run_dump_test "protected-data"
 run_dump_test_lp64 "pr22764"
 run_dump_test_lp64 "pr20402"
 
+if {[check_shared_lib_support]
+    && [ld_assemble $as $srcdir/$subdir/tls-sharedlib.s tmpdir/tls-sharedlib.o]
+    && [ld_link $ld tmpdir/tls-sharedlib.so "-shared tmpdir/tls-sharedlib.o"] } {
+      run_dump_test "tls-relax-gd-ie"
+      run_dump_test_lp64 "tls-relax-large-gd-ie"
+      run_dump_test_lp64 "tls-relax-large-gd-ie-be"
+      run_dump_test_lp64 "tls-relax-large-desc-ie"
+      run_dump_test_lp64 "tls-relax-large-desc-ie-be"
+      run_dump_test_lp64 "tls-relax-large-desc-le"
+      run_dump_test_lp64 "tls-relax-large-desc-le-be"
+      run_dump_test "tls-relax-gdesc-ie"
+      run_dump_test "tls-relax-gdesc-ie-2"
+      run_dump_test "tls-tiny-gd-ie"
+      run_dump_test "tls-tiny-desc-ie"
+}
+if {[check_shared_lib_support]
+    && [ld_assemble_flags $as -mabi=ilp32 $srcdir/$subdir/tls-sharedlib.s tmpdir/tls-sharedlib.o]
+    && [ld_link $ld tmpdir/tls-sharedlib-ilp32.so "-shared tmpdir/tls-sharedlib.o -m [aarch64_choose_ilp32_emul]"] } {
+      run_dump_test "tls-relax-gd-ie-ilp32"
+      run_dump_test "tls-tiny-gd-ie-ilp32"
+      run_dump_test "tls-tiny-desc-ie-ilp32"
+}
+run_dump_test "tls-relax-gd-ie-2"
+run_dump_test "tls-relax-gd-ie-3"
+run_dump_test "tls-relax-ie-le-4"
+run_dump_test "tls-gd-symbolic"
+
 # ifunc tests
 run_dump_test "ifunc-1"
 run_dump_test "ifunc-1-local"
diff --git a/ld/testsuite/ld-aarch64/tls-gd-symbolic.d b/ld/testsuite/ld-aarch64/tls-gd-symbolic.d
new file mode 100644
index 0000000000000000000000000000000000000000..d6732acdaf1543ffd51fe23d0da5633ecbe04d14
--- /dev/null
+++ b/ld/testsuite/ld-aarch64/tls-gd-symbolic.d
@@ -0,0 +1,20 @@
+# Testcase to show that -Bsymbolic does not trigger any relaxation from general
+# dynamic or initial exec for global symbols.
+#target: [check_shared_lib_support]
+#ld: -shared -Bsymbolic
+#objdump: -d -j .text
+
+.*:     file format .*
+
+
+Disassembly of section \.text:
+
+[0-9a-f]+ <_test_tls_desc>:
+ +[0-9a-f]+:	........ 	adrp	x0, .*
+ +[0-9a-f]+:	........ 	ldr	x1, \[x0, #.*\]
+ +[0-9a-f]+:	........ 	add	x0, x0, .*
+ +[0-9a-f]+:	d63f0020 	blr	x1
+
+[0-9a-f]+ <_test_tls_desc2>:
+ +[0-9a-f]+:	........ 	adrp	x0, .*
+ +[0-9a-f]+:	........ 	ldr	x0, \[x0, #.*\]
diff --git a/ld/testsuite/ld-aarch64/tls-gd-symbolic.s b/ld/testsuite/ld-aarch64/tls-gd-symbolic.s
new file mode 100644
index 0000000000000000000000000000000000000000..d2ca5dac7be2aeab897d9e7b0d8ec30afc7cec19
--- /dev/null
+++ b/ld/testsuite/ld-aarch64/tls-gd-symbolic.s
@@ -0,0 +1,27 @@
+	# Demonstrating TLS relaxation behavior for -Bsymbolic linking.
+	# (i.e. no extra relaxation when using -Bsymbolic).
+        .global tlsdescvar
+        .global tlsdescvar2
+        .section        .tbss,"awT",%nobits
+        .align  2
+        .type   tlsdescvar, %object
+        .size   tlsdescvar, 4
+tlsdescvar:
+        .zero   4
+        .type   tlsdescvar2, %object
+        .size   tlsdescvar2, 4
+tlsdescvar2:
+        .zero   4
+.text
+_test_tls_desc:
+
+        adrp  x0, :tlsdesc:tlsdescvar
+        ldr   x1, [x0, :tlsdesc_lo12:tlsdescvar]
+        add   x0, x0, :tlsdesc_lo12:tlsdescvar
+        .tlsdesccall tlsdescvar
+        blr   x1
+
+_test_tls_desc2:
+
+        adrp    x0, :gottprel:tlsdescvar2
+        ldr     x0, [x0, #:gottprel_lo12:tlsdescvar2]
diff --git a/ld/testsuite/ld-aarch64/tls-relax-all-ilp32.d b/ld/testsuite/ld-aarch64/tls-relax-all-ilp32.d
index 1cb4ef4261307c13139707ad27b8e85bbe11b0a9..62faed4b73aac484119ed18dbc7f588f6ec8c794 100644
--- a/ld/testsuite/ld-aarch64/tls-relax-all-ilp32.d
+++ b/ld/testsuite/ld-aarch64/tls-relax-all-ilp32.d
@@ -5,8 +5,8 @@
 #...
  +10000:	a9bf7bfd 	stp	x29, x30, \[sp, #-16\]!
  +10004:	910003fd 	mov	x29, sp
- +10008:	90000080 	adrp	x0, 20000 <_GLOBAL_OFFSET_TABLE_>
- +1000c:	b9400400 	ldr	w0, \[x0, #4\]
+ +10008:	52a00000 	movz	w0, #0x0, lsl #16
+ +1000c:	72800100 	movk	w0, #0x8
  +10010:	d503201f 	nop
  +10014:	d503201f 	nop
  +10018:	d53bd041 	mrs	x1, tpidr_el0
@@ -20,8 +20,8 @@
  +10038:	8b000040 	add	x0, x2, x0
  +1003c:	b9400000 	ldr	w0, \[x0\]
  +10040:	0b000021 	add	w1, w1, w0
- +10044:	90000080 	adrp	x0, 20000 <_GLOBAL_OFFSET_TABLE_>
- +10048:	b9400800 	ldr	w0, \[x0, #8\]
+ +10044:	52a00000 	movz	w0, #0x0, lsl #16
+ +10048:	72800200 	movk	w0, #0x10
  +1004c:	d53bd041 	mrs	x1, tpidr_el0
  +10050:	0b000020 	add	w0, w1, w0
  +10054:	b9400000 	ldr	w0, \[x0\]
diff --git a/ld/testsuite/ld-aarch64/tls-relax-all.d b/ld/testsuite/ld-aarch64/tls-relax-all.d
index 59421864f9558050bf1d2ae1cab794bf54ac30df..1262a99a6a0debb22256903a25e9075f1666543b 100644
--- a/ld/testsuite/ld-aarch64/tls-relax-all.d
+++ b/ld/testsuite/ld-aarch64/tls-relax-all.d
@@ -4,8 +4,8 @@
 #...
  +10000:	a9bf7bfd 	stp	x29, x30, \[sp, #-16\]!
  +10004:	910003fd 	mov	x29, sp
- +10008:	90000080 	adrp	x0, 20000 <_GLOBAL_OFFSET_TABLE_>
- +1000c:	f9400400 	ldr	x0, \[x0, #8\]
+ +10008:	d2a00000 	movz	x0, #0x0, lsl #16
+ +1000c:	f2800200 	movk	x0, #0x10
  +10010:	d503201f 	nop
  +10014:	d503201f 	nop
  +10018:	d53bd041 	mrs	x1, tpidr_el0
@@ -19,8 +19,8 @@
  +10038:	8b000040 	add	x0, x2, x0
  +1003c:	b9400000 	ldr	w0, \[x0\]
  +10040:	0b000021 	add	w1, w1, w0
- +10044:	90000080 	adrp	x0, 20000 <_GLOBAL_OFFSET_TABLE_>
- +10048:	f9400800 	ldr	x0, \[x0, #16\]
+ +10044:	d2a00000 	movz	x0, #0x0, lsl #16
+ +10048:	f2800300 	movk	x0, #0x18
  +1004c:	d53bd041 	mrs	x1, tpidr_el0
  +10050:	8b000020 	add	x0, x1, x0
  +10054:	b9400000 	ldr	w0, \[x0\]
diff --git a/ld/testsuite/ld-aarch64/tls-relax-gd-ie-2.d b/ld/testsuite/ld-aarch64/tls-relax-gd-ie-2.d
new file mode 100644
index 0000000000000000000000000000000000000000..f0281b77579d2587062517be9513e7ad76d39a22
--- /dev/null
+++ b/ld/testsuite/ld-aarch64/tls-relax-gd-ie-2.d
@@ -0,0 +1,27 @@
+# The linker recognises that if we have one IE access to a TLS symbol then all
+# accesses to that symbol could be IE.  Here we are also interested to check
+# the linker does not also decide that a second access to that symbol could be
+# LE.
+#target: [check_shared_lib_support]
+#ld: -shared
+#objdump: -dr
+
+.*:     file format .*
+
+
+Disassembly of section \.text:
+
+[0-9a-f]+ <foo>:
+ +[0-9a-f]+:	d2800000 	mov	x0, #0x0                   	// #0
+ +[0-9a-f]+:	d53bd041 	mrs	x1, tpidr_el0
+ +[0-9a-f]+:	.* 	adrp	x0, .*
+ +[0-9a-f]+:	.* 	ldr	x0, \[x0, #.*\]
+ +[0-9a-f]+:	b8606820 	ldr	w0, \[x1, x0\]
+ +[0-9a-f]+:	d53bd041 	mrs	x1, tpidr_el0
+ +[0-9a-f]+:	910003fd 	mov	x29, sp
+ +[0-9a-f]+:	.* 	adrp	x0, .*
+ +[0-9a-f]+:	.* 	ldr	x0, \[x0, #.*\]
+ +[0-9a-f]+:	d503201f 	nop
+ +[0-9a-f]+:	d503201f 	nop
+ +[0-9a-f]+:	b8606820 	ldr	w0, \[x1, x0\]
+ +[0-9a-f]+:	d65f03c0 	ret
diff --git a/ld/testsuite/ld-aarch64/tls-relax-gd-ie-2.s b/ld/testsuite/ld-aarch64/tls-relax-gd-ie-2.s
new file mode 100644
index 0000000000000000000000000000000000000000..568ceb4857cf98e411ccee0d4b62898d1b3c3b22
--- /dev/null
+++ b/ld/testsuite/ld-aarch64/tls-relax-gd-ie-2.s
@@ -0,0 +1,34 @@
+        .section        .tbss,"awT",@nobits
+        .align  2
+        .type   y, %object
+        .size   y, 4
+y:
+        .zero   4
+
+
+
+
+        .text
+        .global foo
+        .type foo, @function
+foo:
+	# Access the local symbol with an IE access.
+        mov     x0, 0
+        mrs     x1, tpidr_el0
+        adrp    x0, :gottprel:y
+        ldr     x0, [x0, #:gottprel_lo12:y]
+        ldr     w0, [x1, x0]
+
+	# Also access the same symbol with a General Dynamic access.
+	# The linker should be able to recognise that if we're already
+	# accessing this symbol with an Initial Exec access then this General
+	# Dynamic access could be relaxed to an Initial Exec one too.
+        mrs     x1, tpidr_el0
+        mov     x29, sp
+        adrp    x0, :tlsdesc:y
+        ldr     x2, [x0, #:tlsdesc_lo12:y]
+        add     x0, x0, :tlsdesc_lo12:y
+        .tlsdesccall    y
+        blr     x2
+        ldr     w0, [x1, x0]
+        ret
diff --git a/ld/testsuite/ld-aarch64/tls-relax-gd-ie-3.d b/ld/testsuite/ld-aarch64/tls-relax-gd-ie-3.d
new file mode 100644
index 0000000000000000000000000000000000000000..2e45ec90d1a853d58834b219bf9ff0fa6847db60
--- /dev/null
+++ b/ld/testsuite/ld-aarch64/tls-relax-gd-ie-3.d
@@ -0,0 +1,29 @@
+# The linker recognises that if we have one IE access to a TLS symbol then all
+# accesses to that symbol could be IE.  Here we are also interested to check
+# the linker does not also decide that a second access to that symbol could be
+# LE.
+#source: tls-relax-gd-ie-2.s
+#target: [check_shared_lib_support]
+#ld: -shared -Bsymbolic
+#objdump: -dr
+
+.*:     file format .*
+
+
+Disassembly of section \.text:
+
+[0-9a-f]+ <foo>:
+ +[0-9a-f]+:	d2800000 	mov	x0, #0x0                   	// #0
+ +[0-9a-f]+:	d53bd041 	mrs	x1, tpidr_el0
+ +[0-9a-f]+:	.* 	adrp	x0, .*
+ +[0-9a-f]+:	.* 	ldr	x0, \[x0, #.*\]
+ +[0-9a-f]+:	b8606820 	ldr	w0, \[x1, x0\]
+ +[0-9a-f]+:	d53bd041 	mrs	x1, tpidr_el0
+ +[0-9a-f]+:	910003fd 	mov	x29, sp
+ +[0-9a-f]+:	.* 	adrp	x0, .*
+ +[0-9a-f]+:	.* 	ldr	x0, \[x0, #.*\]
+ +[0-9a-f]+:	d503201f 	nop
+ +[0-9a-f]+:	d503201f 	nop
+ +[0-9a-f]+:	b8606820 	ldr	w0, \[x1, x0\]
+ +[0-9a-f]+:	d65f03c0 	ret
+
diff --git a/ld/testsuite/ld-aarch64/tls-relax-gd-ie-ilp32.d b/ld/testsuite/ld-aarch64/tls-relax-gd-ie-ilp32.d
index ab08c6161b9330110a9ffbb33eb6d44b0a8e8ac7..340206a9e2bbd37534eb3a1fed79e6386480aed3 100644
--- a/ld/testsuite/ld-aarch64/tls-relax-gd-ie-ilp32.d
+++ b/ld/testsuite/ld-aarch64/tls-relax-gd-ie-ilp32.d
@@ -1,6 +1,6 @@
 #source: tls-relax-gd-ie.s
 #as: -mabi=ilp32
-#ld: -m [aarch64_choose_ilp32_emul] -T relocs-ilp32.ld -e0
+#ld: -m [aarch64_choose_ilp32_emul] -T relocs-ilp32.ld -e0 tmpdir/tls-sharedlib-ilp32.so
 #objdump: -dr
 #...
  +10000:	90000080 	adrp	x0, 20000 <_GLOBAL_OFFSET_TABLE_>
diff --git a/ld/testsuite/ld-aarch64/tls-relax-gd-ie.d b/ld/testsuite/ld-aarch64/tls-relax-gd-ie.d
index f80bb9077705d83e793fcdd6b45169ac82a24aa9..0c03290e0a9cca61baab061e0b24475f9a8f00ab 100644
--- a/ld/testsuite/ld-aarch64/tls-relax-gd-ie.d
+++ b/ld/testsuite/ld-aarch64/tls-relax-gd-ie.d
@@ -1,5 +1,5 @@
 #source: tls-relax-gd-ie.s
-#ld: -T relocs.ld -e0
+#ld: -T relocs.ld -e0 tmpdir/tls-sharedlib.so
 #objdump: -dr
 #...
  +10000:	90000080 	adrp	x0, 20000 <_GLOBAL_OFFSET_TABLE_>
diff --git a/ld/testsuite/ld-aarch64/tls-relax-gd-ie.s b/ld/testsuite/ld-aarch64/tls-relax-gd-ie.s
index 88c7eec73e43afb680a6c1c9051bf5485491fa1e..afe076c8c8203ee547e84ccab544b67e388279d3 100644
--- a/ld/testsuite/ld-aarch64/tls-relax-gd-ie.s
+++ b/ld/testsuite/ld-aarch64/tls-relax-gd-ie.s
@@ -1,7 +1,3 @@
-	.global	var
-	.section	.tdata,"awT",%progbits
-var:
-	.word	2
 	.text
 	adrp	x0, :tlsgd:var
 	add	x0, x0, :tlsgd_lo12:var
diff --git a/ld/testsuite/ld-aarch64/tls-relax-gdesc-ie-2.d b/ld/testsuite/ld-aarch64/tls-relax-gdesc-ie-2.d
index 2b8e346fc66c79c3d992714da7a876dc83c0b5ee..f13263f201ff781b0c8c41f468c069ee71c4fd61 100644
--- a/ld/testsuite/ld-aarch64/tls-relax-gdesc-ie-2.d
+++ b/ld/testsuite/ld-aarch64/tls-relax-gdesc-ie-2.d
@@ -1,5 +1,5 @@
 #source: tls-relax-gdesc-ie-2.s
-#ld: -T relocs.ld -e0
+#ld: -T relocs.ld -e0 tmpdir/tls-sharedlib.so
 #objdump: -dr
 #...
  +10000:	90000080 	adrp	x0, 20000 <_GLOBAL_OFFSET_TABLE_>
diff --git a/ld/testsuite/ld-aarch64/tls-relax-gdesc-ie-2.s b/ld/testsuite/ld-aarch64/tls-relax-gdesc-ie-2.s
index 790b6c6eb8bb4b9c2efa0688f46a5413d8231f78..f7be57c320716d6c56559d2ebfa181a2944bdb88 100644
--- a/ld/testsuite/ld-aarch64/tls-relax-gdesc-ie-2.s
+++ b/ld/testsuite/ld-aarch64/tls-relax-gdesc-ie-2.s
@@ -1,9 +1,5 @@
 // Test TLS Desc to TLS IE relaxation when instructions are not consecutive.
 
-	.global	var
-	.section	.tdata
-var:
-	.word	2
 	.text
 	adrp	x0, :tlsdesc:var
 	nop
@@ -20,5 +16,4 @@ var:
 	mrs	x1, tpidr_el0
 	add	x0, x1, x0
 	ldr	w0, [x0]
-	.global	var
 	.section	.tdata
diff --git a/ld/testsuite/ld-aarch64/tls-relax-gdesc-ie.d b/ld/testsuite/ld-aarch64/tls-relax-gdesc-ie.d
index 86277f82565c401aa6d2b4b365e2c9c8bc8ccfe6..1ace84858a32e1ef0336cf24f7017a55ccbb611e 100644
--- a/ld/testsuite/ld-aarch64/tls-relax-gdesc-ie.d
+++ b/ld/testsuite/ld-aarch64/tls-relax-gdesc-ie.d
@@ -1,5 +1,5 @@
 #source: tls-relax-gdesc-ie.s
-#ld: -T relocs.ld -e0
+#ld: -T relocs.ld -e0 tmpdir/tls-sharedlib.so
 #objdump: -dr
 #...
  +10000:	90000080 	adrp	x0, 20000 <_GLOBAL_OFFSET_TABLE_>
diff --git a/ld/testsuite/ld-aarch64/tls-relax-gdesc-ie.s b/ld/testsuite/ld-aarch64/tls-relax-gdesc-ie.s
index 38b372132f49c926be8d6527bce9d203b794a4b5..089d36c9cc8a9f4dd9f6cfe71996bdbdd9b68502 100644
--- a/ld/testsuite/ld-aarch64/tls-relax-gdesc-ie.s
+++ b/ld/testsuite/ld-aarch64/tls-relax-gdesc-ie.s
@@ -1,7 +1,3 @@
-	.global	var
-	.section	.tdata
-var:
-	.word	2
 	.text
 	adrp	x0, :tlsdesc:var
 	ldr	x17, [x0, #:tlsdesc_lo12:var]
diff --git a/ld/testsuite/ld-aarch64/tls-relax-ie-le-4.d b/ld/testsuite/ld-aarch64/tls-relax-ie-le-4.d
new file mode 100644
index 0000000000000000000000000000000000000000..e2bc5f1530440d19077c455db5783ef10da24bf2
--- /dev/null
+++ b/ld/testsuite/ld-aarch64/tls-relax-ie-le-4.d
@@ -0,0 +1,20 @@
+# We already test that we relax an access to a local symbol, this testcase
+# checks that we relax an access to a global-binding symbol if the static linker
+# knows that the symbol will resolve to the executable local value.
+#
+# The access should be relaxed to a LE access.
+#ld:
+#objdump: -d
+
+.*:     file format .*
+
+
+Disassembly of section \.text:
+
+[0-9a-f]+ <_start>:
+ +[0-9a-f]+:	d2800000 	mov	x0, #0x0                   	// #0
+ +[0-9a-f]+:	d53bd041 	mrs	x1, tpidr_el0
+ +[0-9a-f]+:	d2a00000 	movz	x0, #0x0, lsl #16
+ +[0-9a-f]+:	f2800200 	movk	x0, #0x10
+ +[0-9a-f]+:	b8606820 	ldr	w0, \[x1, x0\]
+ +[0-9a-f]+:	d65f03c0 	ret
diff --git a/ld/testsuite/ld-aarch64/tls-relax-ie-le-4.s b/ld/testsuite/ld-aarch64/tls-relax-ie-le-4.s
new file mode 100644
index 0000000000000000000000000000000000000000..e151cd4efd6cc729d220ceea5f318ecd3a8ed3d8
--- /dev/null
+++ b/ld/testsuite/ld-aarch64/tls-relax-ie-le-4.s
@@ -0,0 +1,22 @@
+# Test TLS IE to TLS LE relaxation for global symbols.
+        .section        .tbss,"awT",@nobits
+        .global x
+        .align  2
+        .type   x, %object
+        .size   x, 4
+x:
+        .zero   4
+
+
+
+        .text
+        .global _start
+        .type _start, @function
+_start:
+        mov     x0, 0
+        mrs     x1, tpidr_el0
+        adrp    x0, :gottprel:x
+        ldr     x0, [x0, #:gottprel_lo12:x]
+        ldr     w0, [x1, x0]
+        ret
+
diff --git a/ld/testsuite/ld-aarch64/tls-relax-large-desc-ie.d b/ld/testsuite/ld-aarch64/tls-relax-large-desc-ie.d
index 21ad5e5a18c265e5e095b2053752a578d689d411..cb546ad74e6da35e7d3cd4f56ba62af52afebc22 100644
--- a/ld/testsuite/ld-aarch64/tls-relax-large-desc-ie.d
+++ b/ld/testsuite/ld-aarch64/tls-relax-large-desc-ie.d
@@ -1,5 +1,5 @@
 #source: tls-relax-large-desc-ie.s
-#ld: -T relocs.ld -e0
+#ld: -T relocs.ld -e0 tmpdir/tls-sharedlib.so
 #notarget: aarch64_be-*-*
 #objdump: -dr
 #...
diff --git a/ld/testsuite/ld-aarch64/tls-relax-large-desc-ie.s b/ld/testsuite/ld-aarch64/tls-relax-large-desc-ie.s
index a4d1e00086ad3ed3818eb73b4aba606cb0de6cf7..98dc2a571d5836b60f05cb9daf47b385456a3ee2 100644
--- a/ld/testsuite/ld-aarch64/tls-relax-large-desc-ie.s
+++ b/ld/testsuite/ld-aarch64/tls-relax-large-desc-ie.s
@@ -1,8 +1,3 @@
-	.global var
-	.section	.tdata,"awT",%progbits
-var:
-	.word 2
-
 	.text
 test:
 	ldr x1, .Lgot
diff --git a/ld/testsuite/ld-aarch64/tls-relax-large-gd-ie.d b/ld/testsuite/ld-aarch64/tls-relax-large-gd-ie.d
index 2b398dbb9c6ce48f48f258e3ed337dcd383af82c..740178d46105483fa4176b1a4c77ebac459ef846 100644
--- a/ld/testsuite/ld-aarch64/tls-relax-large-gd-ie.d
+++ b/ld/testsuite/ld-aarch64/tls-relax-large-gd-ie.d
@@ -1,5 +1,5 @@
 #source: tls-relax-large-gd-ie.s
-#ld: -T relocs.ld -e0
+#ld: -T relocs.ld -e0 tmpdir/tls-sharedlib.so
 #notarget: aarch64_be-*-*
 #objdump: -dr
 #...
diff --git a/ld/testsuite/ld-aarch64/tls-relax-large-gd-ie.s b/ld/testsuite/ld-aarch64/tls-relax-large-gd-ie.s
index 8e0310d6b3f8caecdbfc2bdd3f310b6ee3942d80..d35aace776ee0bc327cfa1cf258c8ce687865d7a 100644
--- a/ld/testsuite/ld-aarch64/tls-relax-large-gd-ie.s
+++ b/ld/testsuite/ld-aarch64/tls-relax-large-gd-ie.s
@@ -1,8 +1,3 @@
-	.global var
-	.section	.tdata,"awT",%progbits
-var:
-	.word	2
-
 	.text
 test:
 	ldr	x1, .Lgot
diff --git a/ld/testsuite/ld-aarch64/tls-sharedlib.s b/ld/testsuite/ld-aarch64/tls-sharedlib.s
new file mode 100644
index 0000000000000000000000000000000000000000..8838b9f23484ac6c0535c43256818050fbf3a4fd
--- /dev/null
+++ b/ld/testsuite/ld-aarch64/tls-sharedlib.s
@@ -0,0 +1,4 @@
+    .global var
+    .section  .tdata,"awT",@progbits
+var:
+    .word 2
diff --git a/ld/testsuite/ld-aarch64/tls-tiny-desc-ie-ilp32.d b/ld/testsuite/ld-aarch64/tls-tiny-desc-ie-ilp32.d
index ebbaf854baa9548503d0eeac351ab3ee6e330183..3dffa1b85e6376fd72970ba79ecf8d42640173ae 100644
--- a/ld/testsuite/ld-aarch64/tls-tiny-desc-ie-ilp32.d
+++ b/ld/testsuite/ld-aarch64/tls-tiny-desc-ie-ilp32.d
@@ -1,12 +1,12 @@
 #source: tls-tiny-desc-ie.s
 #as: -mabi=ilp32
-#ld: -m [aarch64_choose_ilp32_emul] -T relocs-ilp32.ld -e0
+#ld: -m [aarch64_choose_ilp32_emul] -T relocs-ilp32.ld -e0 tmpdir/tls-sharedlib-ilp32.so
 #objdump: -dr
 #...
 
 Disassembly of section .text:
 
 00010000 \<test\>:
- +10000:	18080020 	ldr	w0, 20004 \<_GLOBAL_OFFSET_TABLE_\+0x4\>
+ +10000:	18080020 	ldr	w0, 20004 \<var\>
  +10004:	d503201f 	nop
  +10008:	d503201f 	nop
diff --git a/ld/testsuite/ld-aarch64/tls-tiny-desc-ie.d b/ld/testsuite/ld-aarch64/tls-tiny-desc-ie.d
index 0088539d6bfae0bdfc70c86afeaf7f1d16305d12..e759ae94576ccca484a9690d1334032f97df6fd6 100644
--- a/ld/testsuite/ld-aarch64/tls-tiny-desc-ie.d
+++ b/ld/testsuite/ld-aarch64/tls-tiny-desc-ie.d
@@ -1,11 +1,11 @@
 #source: tls-tiny-desc-ie.s
-#ld: -T relocs.ld -e0
+#ld: -T relocs.ld -e0 tmpdir/tls-sharedlib.so
 #objdump: -dr
 #...
 
 Disassembly of section .text:
 
 0000000000010000 \<test\>:
- +10000:	58080040 	ldr	x0, 20008 \<_GLOBAL_OFFSET_TABLE_\+0x8\>
+ +10000:	58080040 	ldr	x0, 20008 \<var\>
  +10004:	d503201f 	nop
  +10008:	d503201f 	nop
diff --git a/ld/testsuite/ld-aarch64/tls-tiny-desc-ie.s b/ld/testsuite/ld-aarch64/tls-tiny-desc-ie.s
index 520cd4e85b29f8c3acc912d2d31b902b91ee337e..fcc970f6d8f46b7c57724b55c857dcee77bc0722 100644
--- a/ld/testsuite/ld-aarch64/tls-tiny-desc-ie.s
+++ b/ld/testsuite/ld-aarch64/tls-tiny-desc-ie.s
@@ -1,12 +1,3 @@
-        .global var
-
-        .section .tbss,"awT",%nobits
-        .align  2
-        .type   var, %object
-        .size   var, 4
-var:
-	.zero   4
-
 	.text
 test:
         ldr	x1, :tlsdesc:var
diff --git a/ld/testsuite/ld-aarch64/tls-tiny-gd-ie-ilp32.d b/ld/testsuite/ld-aarch64/tls-tiny-gd-ie-ilp32.d
index 1ea61103b47ba1a23703be914da5f5f1008a9cb1..6317152eb1ecc8830d8a0b736276c4ef19301d58 100644
--- a/ld/testsuite/ld-aarch64/tls-tiny-gd-ie-ilp32.d
+++ b/ld/testsuite/ld-aarch64/tls-tiny-gd-ie-ilp32.d
@@ -1,12 +1,12 @@
 #source: tls-tiny-gd-ie.s
 #as: -mabi=ilp32
-#ld: -m [aarch64_choose_ilp32_emul] -T relocs-ilp32.ld -e0
+#ld: -m [aarch64_choose_ilp32_emul] -T relocs-ilp32.ld -e0 tmpdir/tls-sharedlib-ilp32.so
 #objdump: -dr
 #...
 
 Disassembly of section .text:
 
 00010000 \<test\>:
- +10000:	18080020 	ldr	w0, 20004 \<_GLOBAL_OFFSET_TABLE_\+0x4\>
+ +10000:	18080020 	ldr	w0, 20004 \<var\>
  +10004:	d53bd041 	mrs	x1, tpidr_el0
  +10008:	0b000020 	add	w0, w1, w0
diff --git a/ld/testsuite/ld-aarch64/tls-tiny-gd-ie.d b/ld/testsuite/ld-aarch64/tls-tiny-gd-ie.d
index 629d90c942d34845e700b935ef2701d06235b7dd..66b996e6f4abc279d96be510956eff0c606ab240 100644
--- a/ld/testsuite/ld-aarch64/tls-tiny-gd-ie.d
+++ b/ld/testsuite/ld-aarch64/tls-tiny-gd-ie.d
@@ -1,11 +1,11 @@
 #source: tls-tiny-gd-ie.s
-#ld: -T relocs.ld -e0
+#ld: -T relocs.ld -e0 tmpdir/tls-sharedlib.so
 #objdump: -dr
 #...
 
 Disassembly of section .text:
 
 0000000000010000 \<test\>:
- +10000:	58080040 	ldr	x0, 20008 \<_GLOBAL_OFFSET_TABLE_\+0x8\>
+ +10000:	58080040 	ldr	x0, 20008 \<var\>
  +10004:	d53bd041 	mrs	x1, tpidr_el0
  +10008:	8b000020 	add	x0, x1, x0
diff --git a/ld/testsuite/ld-aarch64/tls-tiny-gd-ie.s b/ld/testsuite/ld-aarch64/tls-tiny-gd-ie.s
index 4dc7e66bbdb7d7c01754aebcdaf4b1328667e143..3ae4a0cc9fe1329140c60ed9424b80e8b4669da3 100644
--- a/ld/testsuite/ld-aarch64/tls-tiny-gd-ie.s
+++ b/ld/testsuite/ld-aarch64/tls-tiny-gd-ie.s
@@ -1,12 +1,3 @@
-        .global var
-
-        .section .tbss,"awT",%nobits
-        .align  2
-        .type   var, %object
-        .size   var, 4
-var:
-	.zero   4
-
 	.text
 test:
         adr x0, :tlsgd:var




^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: [PATCH] ld: aarch64: Improve TLS relaxation condition
  2022-07-08 12:52 [PATCH] ld: aarch64: Improve TLS relaxation condition Matthew Malcomson
@ 2022-07-29 10:27 ` Nick Clifton
  0 siblings, 0 replies; 2+ messages in thread
From: Nick Clifton @ 2022-07-29 10:27 UTC (permalink / raw)
  To: Matthew Malcomson, binutils; +Cc: Richard.Earnshaw

Hi Matthew,

> Here we adjust the condition we base our relaxation on so that we relax
> to local-exec if we are creating an executable and the relevant symbol
> we're accessing is stored inside that executable.

Patch approved for the mainline - please apply.

I think that we should hold off from applying it to the 2.39 branch however,
just in case the patch introduces new problems.  Lets try it out in the
mainline code for a while and then include it in the 2.40 release.

Cheers
   Nick


^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2022-07-29 10:27 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-07-08 12:52 [PATCH] ld: aarch64: Improve TLS relaxation condition Matthew Malcomson
2022-07-29 10:27 ` Nick Clifton

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).