This is the mail archive of the libc-alpha@sourceware.org mailing list for the glibc project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[PATCH 5/7] [BZ #18572] arm: Disable lazy initialization of tlsdesc entries


2017-10-23  Szabolcs Nagy  <szabolcs.nagy@arm.com>

	[BZ #18572]
	* sysdeps/arm/dl-machine.h (elf_machine_lazy_rel): Do symbol binding
	non-lazily for R_ARM_TLS_DESC.

>From 9732943ec024f2ea66f978cd4196ec6a71497358 Mon Sep 17 00:00:00 2001
From: Szabolcs Nagy <szabolcs.nagy@arm.com>
Date: Fri, 20 Oct 2017 17:35:12 +0100
Subject: [PATCH 5/7] [BZ #18572] arm: Disable lazy initialization of tlsdesc
 entries

Follow up to
https://sourceware.org/ml/libc-alpha/2015-11/msg00272.html

Always do tls descriptor initialization at load time during relocation
processing (as if DF_BIND_NOW were set for the binary) to avoid barriers
at every tls access.  This patch mimics bind-now semantics in the lazy
relocation code of the arm target (elf_machine_lazy_rel).

Ideally the static linker should be updated too to not emit tlsdesc
relocs in DT_REL*, so elf_machine_lazy_rel is not called on them at all.

	* sysdeps/arm/dl-machine.h (elf_machine_lazy_rel): Do symbol binding
	non-lazily for R_ARM_TLS_DESC.
---
 sysdeps/arm/dl-machine.h | 24 +++++++++++++++---------
 1 file changed, 15 insertions(+), 9 deletions(-)

diff --git a/sysdeps/arm/dl-machine.h b/sysdeps/arm/dl-machine.h
index bf5f5d205c..c59386f515 100644
--- a/sysdeps/arm/dl-machine.h
+++ b/sysdeps/arm/dl-machine.h
@@ -669,15 +669,21 @@ elf_machine_lazy_rel (struct link_map *map,
     }
   else if (__builtin_expect (r_type == R_ARM_TLS_DESC, 1))
     {
-      struct tlsdesc volatile *td =
-	(struct tlsdesc volatile *)reloc_addr;
-
-      /* The linker must have given us the parameter we need in the
-	 first GOT entry, and left the second one empty.  We fill the
-	 latter with the resolver address.  */
-      assert (td->entry == 0);
-      td->entry = (void*)(D_PTR (map, l_info[ADDRIDX (DT_TLSDESC_PLT)])
-			  + map->l_addr);
+      const Elf_Symndx symndx = ELFW (R_SYM) (reloc->r_info);
+      const ElfW (Sym) *symtab = (const void *)D_PTR (map, l_info[DT_SYMTAB]);
+      const ElfW (Sym) *sym = &symtab[symndx];
+      const struct r_found_version *version = NULL;
+
+      if (map->l_info[VERSYMIDX (DT_VERSYM)] != NULL)
+	{
+	  const ElfW (Half) *vernum =
+	    (const void *)D_PTR (map, l_info[VERSYMIDX (DT_VERSYM)]);
+	  version = &map->l_versions[vernum[symndx] & 0x7fff];
+	}
+
+      /* Always initialize TLS descriptors completely, because lazy
+	 initialization requires synchronization at every TLS access.  */
+      elf_machine_rel (map, reloc, sym, version, reloc_addr, skip_ifunc);
     }
   else
     _dl_reloc_bad_type (map, r_type, 1);
-- 
2.11.0


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]