548bcb
commit 2208066603a136f95cfb815ca9281262e6465784
548bcb
Author: Szabolcs Nagy <szabolcs.nagy@arm.com>
548bcb
Date:   Thu Feb 11 13:24:47 2021 +0000
548bcb
548bcb
    elf: Remove lazy tlsdesc relocation related code
548bcb
    
548bcb
    Remove generic tlsdesc code related to lazy tlsdesc processing since
548bcb
    lazy tlsdesc relocation is no longer supported.  This includes removing
548bcb
    GL(dl_load_lock) from _dl_make_tlsdesc_dynamic which is only called at
548bcb
    load time when that lock is already held.
548bcb
    
548bcb
    Added a documentation comment too.
548bcb
    
548bcb
    Reviewed-by: Adhemerval Zanella  <adhemerval.zanella@linaro.org>
548bcb
548bcb
diff --git a/elf/tlsdeschtab.h b/elf/tlsdeschtab.h
548bcb
index fea9eefe72edcd6b..c20857e5b4264f00 100644
548bcb
--- a/elf/tlsdeschtab.h
548bcb
+++ b/elf/tlsdeschtab.h
548bcb
@@ -78,6 +78,10 @@ map_generation (struct link_map *map)
548bcb
   return GL(dl_tls_generation) + 1;
548bcb
 }
548bcb
 
548bcb
+/* Returns the data pointer for a given map and tls offset that is used
548bcb
+   to fill in one of the GOT entries referenced by a TLSDESC relocation
548bcb
+   when using dynamic TLS.  This requires allocation, returns NULL on
548bcb
+   allocation failure.  */
548bcb
 void *
548bcb
 _dl_make_tlsdesc_dynamic (struct link_map *map, size_t ti_offset)
548bcb
 {
548bcb
@@ -85,18 +89,12 @@ _dl_make_tlsdesc_dynamic (struct link_map *map, size_t ti_offset)
548bcb
   void **entry;
548bcb
   struct tlsdesc_dynamic_arg *td, test;
548bcb
 
548bcb
-  /* FIXME: We could use a per-map lock here, but is it worth it?  */
548bcb
-  __rtld_lock_lock_recursive (GL(dl_load_lock));
548bcb
-
548bcb
   ht = map->l_mach.tlsdesc_table;
548bcb
   if (! ht)
548bcb
     {
548bcb
       ht = htab_create ();
548bcb
       if (! ht)
548bcb
-	{
548bcb
-	  __rtld_lock_unlock_recursive (GL(dl_load_lock));
548bcb
-	  return 0;
548bcb
-	}
548bcb
+	return 0;
548bcb
       map->l_mach.tlsdesc_table = ht;
548bcb
     }
548bcb
 
548bcb
@@ -104,15 +102,11 @@ _dl_make_tlsdesc_dynamic (struct link_map *map, size_t ti_offset)
548bcb
   test.tlsinfo.ti_offset = ti_offset;
548bcb
   entry = htab_find_slot (ht, &test, 1, hash_tlsdesc, eq_tlsdesc);
548bcb
   if (! entry)
548bcb
-    {
548bcb
-      __rtld_lock_unlock_recursive (GL(dl_load_lock));
548bcb
-      return 0;
548bcb
-    }
548bcb
+    return 0;
548bcb
 
548bcb
   if (*entry)
548bcb
     {
548bcb
       td = *entry;
548bcb
-      __rtld_lock_unlock_recursive (GL(dl_load_lock));
548bcb
       return td;
548bcb
     }
548bcb
 
548bcb
@@ -122,44 +116,9 @@ _dl_make_tlsdesc_dynamic (struct link_map *map, size_t ti_offset)
548bcb
      thread.  */
548bcb
   td->gen_count = map_generation (map);
548bcb
   td->tlsinfo = test.tlsinfo;
548bcb
-
548bcb
-  __rtld_lock_unlock_recursive (GL(dl_load_lock));
548bcb
   return td;
548bcb
 }
548bcb
 
548bcb
 # endif /* SHARED */
548bcb
 
548bcb
-/* The idea of the following two functions is to stop multiple threads
548bcb
-   from attempting to resolve the same TLS descriptor without busy
548bcb
-   waiting.  Ideally, we should be able to release the lock right
548bcb
-   after changing td->entry, and then using say a condition variable
548bcb
-   or a futex wake to wake up any waiting threads, but let's try to
548bcb
-   avoid introducing such dependencies.  */
548bcb
-
548bcb
-static int
548bcb
-__attribute__ ((unused))
548bcb
-_dl_tlsdesc_resolve_early_return_p (struct tlsdesc volatile *td, void *caller)
548bcb
-{
548bcb
-  if (caller != atomic_load_relaxed (&td->entry))
548bcb
-    return 1;
548bcb
-
548bcb
-  __rtld_lock_lock_recursive (GL(dl_load_lock));
548bcb
-  if (caller != atomic_load_relaxed (&td->entry))
548bcb
-    {
548bcb
-      __rtld_lock_unlock_recursive (GL(dl_load_lock));
548bcb
-      return 1;
548bcb
-    }
548bcb
-
548bcb
-  atomic_store_relaxed (&td->entry, _dl_tlsdesc_resolve_hold);
548bcb
-
548bcb
-  return 0;
548bcb
-}
548bcb
-
548bcb
-static void
548bcb
-__attribute__ ((unused))
548bcb
-_dl_tlsdesc_wake_up_held_fixups (void)
548bcb
-{
548bcb
-  __rtld_lock_unlock_recursive (GL(dl_load_lock));
548bcb
-}
548bcb
-
548bcb
 #endif
548bcb
diff --git a/sysdeps/aarch64/tlsdesc.c b/sysdeps/aarch64/tlsdesc.c
548bcb
index 357465f23d76e2bd..1ead73ab8250e29c 100644
548bcb
--- a/sysdeps/aarch64/tlsdesc.c
548bcb
+++ b/sysdeps/aarch64/tlsdesc.c
548bcb
@@ -22,7 +22,6 @@
548bcb
 #include <tls.h>
548bcb
 #include <dl-tlsdesc.h>
548bcb
 #include <dl-unmap-segments.h>
548bcb
-#define _dl_tlsdesc_resolve_hold 0
548bcb
 #include <tlsdeschtab.h>
548bcb
 
548bcb
 /* Unmap the dynamic object, but also release its TLS descriptor table
548bcb
diff --git a/sysdeps/arm/tlsdesc.c b/sysdeps/arm/tlsdesc.c
548bcb
index d142d7a2c91e9adb..b78e3f65785bf587 100644
548bcb
--- a/sysdeps/arm/tlsdesc.c
548bcb
+++ b/sysdeps/arm/tlsdesc.c
548bcb
@@ -20,7 +20,6 @@
548bcb
 #include <tls.h>
548bcb
 #include <dl-tlsdesc.h>
548bcb
 #include <dl-unmap-segments.h>
548bcb
-#define _dl_tlsdesc_resolve_hold 0
548bcb
 #include <tlsdeschtab.h>
548bcb
 
548bcb
 /* Unmap the dynamic object, but also release its TLS descriptor table
548bcb
diff --git a/sysdeps/i386/tlsdesc.c b/sysdeps/i386/tlsdesc.c
548bcb
index 1b4227c8381e1b3d..c242ffce726d50e4 100644
548bcb
--- a/sysdeps/i386/tlsdesc.c
548bcb
+++ b/sysdeps/i386/tlsdesc.c
548bcb
@@ -20,7 +20,6 @@
548bcb
 #include <tls.h>
548bcb
 #include <dl-tlsdesc.h>
548bcb
 #include <dl-unmap-segments.h>
548bcb
-#define _dl_tlsdesc_resolve_hold 0
548bcb
 #include <tlsdeschtab.h>
548bcb
 
548bcb
 /* Unmap the dynamic object, but also release its TLS descriptor table
548bcb
diff --git a/sysdeps/x86_64/tlsdesc.c b/sysdeps/x86_64/tlsdesc.c
548bcb
index 61a19ae26944c84f..a9325827d0e5e31b 100644
548bcb
--- a/sysdeps/x86_64/tlsdesc.c
548bcb
+++ b/sysdeps/x86_64/tlsdesc.c
548bcb
@@ -20,7 +20,6 @@
548bcb
 #include <tls.h>
548bcb
 #include <dl-tlsdesc.h>
548bcb
 #include <dl-unmap-segments.h>
548bcb
-#define _dl_tlsdesc_resolve_hold 0
548bcb
 #include <tlsdeschtab.h>
548bcb
 
548bcb
 /* Unmap the dynamic object, but also release its TLS descriptor table