Blame SOURCES/glibc-rh970791.patch

147e83
#
147e83
# Patch provided by Ulrich Drepper in BZ#919562.
147e83
#
147e83
# Patch has not been sent upstream.
147e83
#
147e83
# 2013-03-08  Ulrich Drepper  <drepper@gmail.com>
147e83
#
147e83
#	* elf/rtld.c (dl_main): Correctly determine when the application
147e83
#	required DSOs with TLS and bump the generation counter in that
147e83
#	case.  The current condition does not account for an audit
147e83
#	module using TLS.
147e83
#	* elf/dl-tls.c (_dl_count_modids): New function.
147e83
#	(_dl_allocate_tls_init): Add assertion to check TLS
147e83
#	generation.
147e83
#	* sysdeps/generic/ldsodefs.h: Declare _dl_count_modids.
147e83
#	* elf/Makefile: Add rules to build and run tst-audit9.
147e83
#	* elf/tst-audit9.c: New file.
147e83
#	* elf/tst-auditmod9a.c: New file.
147e83
#	* elf/tst-auditmod9b.c: New file.
147e83
#
147e83
diff -urN glibc-2.17-c758a686/elf/dl-tls.c glibc-2.17-c758a686/elf/dl-tls.c
147e83
--- glibc-2.17-c758a686/elf/dl-tls.c	2013-04-24 16:06:10.410756438 -0400
147e83
+++ glibc-2.17-c758a686/elf/dl-tls.c	2013-04-24 16:06:49.092604707 -0400
147e83
@@ -109,6 +109,28 @@
147e83
 }
147e83
 
147e83
 
147e83
+size_t
147e83
+internal_function
147e83
+_dl_count_modids (void)
147e83
+{
147e83
+  if (! __builtin_expect (GL(dl_tls_dtv_gaps), true))
147e83
+    return GL(dl_tls_max_dtv_idx);
147e83
+
147e83
+  size_t n = 0;
147e83
+  struct dtv_slotinfo_list *runp = GL(dl_tls_dtv_slotinfo_list);
147e83
+  while (runp != NULL)
147e83
+    {
147e83
+      for (size_t i = 0; i < runp->len; ++i)
147e83
+	if (runp->slotinfo[i].map != NULL)
147e83
+	  ++n;
147e83
+
147e83
+      runp = runp->next;
147e83
+    }
147e83
+
147e83
+  return n;
147e83
+}
147e83
+
147e83
+
147e83
 #ifdef SHARED
147e83
 void
147e83
 internal_function
147e83
@@ -411,6 +433,7 @@
147e83
 
147e83
 	  /* Keep track of the maximum generation number.  This might
147e83
 	     not be the generation counter.  */
147e83
+	  assert (listp->slotinfo[cnt].gen <= GL(dl_tls_generation));
147e83
 	  maxgen = MAX (maxgen, listp->slotinfo[cnt].gen);
147e83
 
147e83
 	  if (map->l_tls_offset == NO_TLS_OFFSET
147e83
diff -urN glibc-2.17-c758a686/elf/Makefile glibc-2.17-c758a686/elf/Makefile
147e83
--- glibc-2.17-c758a686/elf/Makefile	2013-04-24 16:06:10.408756448 -0400
147e83
+++ glibc-2.17-c758a686/elf/Makefile	2013-04-24 16:07:29.475457962 -0400
147e83
@@ -198,7 +200,7 @@
147e83
 	 tst-dlmodcount tst-dlopenrpath tst-deep1 \
147e83
 	 tst-dlmopen1 tst-dlmopen2 tst-dlmopen3 \
147e83
 	 unload3 unload4 unload5 unload6 unload7 unload8 tst-global1 order2 \
147e83
-	 tst-audit1 tst-audit2 tst-audit8 \
147e83
+	 tst-audit1 tst-audit2 tst-audit8 tst-audit9 \
147e83
 	 tst-stackguard1 tst-addr1 tst-thrlock \
147e83
 	 tst-unique1 tst-unique2 tst-unique3 tst-unique4 \
147e83
 	 tst-initorder tst-initorder2 tst-relsort1
147e83
@@ -251,7 +253,8 @@
147e83
 		unload8mod1 unload8mod1x unload8mod2 unload8mod3 \
147e83
 		order2mod1 order2mod2 order2mod3 order2mod4 \
147e83
 		tst-unique1mod1 tst-unique1mod2 \
147e83
-		tst-unique2mod1 tst-unique2mod2 \
147e83
+		tst-unique2mod1 tst-unique2mod2 \
147e83
+		tst-auditmod9a tst-auditmod9b \
147e83
 		tst-unique3lib tst-unique3lib2 \
147e83
 		tst-unique4lib \
147e83
 		tst-initordera1 tst-initorderb1 \
147e83
@@ -574,6 +577,8 @@
147e83
 ifuncmod1.so-no-z-defs = yes
147e83
 ifuncmod5.so-no-z-defs = yes
147e83
 ifuncmod6.so-no-z-defs = yes
147e83
+tst-auditmod9a.so-no-z-defs = yes
147e83
+tst-auditmod9b.so-no-z-defs = yes
147e83
 
147e83
 ifeq ($(build-shared),yes)
147e83
 # Build all the modules even when not actually running test programs.
147e83
@@ -1015,6 +1020,10 @@
147e83
 $(objpfx)tst-audit7.out: $(objpfx)tst-auditmod7b.so
147e83
 tst-audit7-ENV = LD_AUDIT=$(objpfx)tst-auditmod7b.so
147e83
 
147e83
+$(objpfx)tst-audit9: $(libdl)
147e83
+$(objpfx)tst-audit9.out: $(objpfx)tst-auditmod9a.so $(objpfx)tst-auditmod9b.so
147e83
+tst-audit9-ENV = LD_AUDIT=$(objpfx)tst-auditmod9a.so
147e83
+
147e83
 $(objpfx)tst-audit8: $(common-objpfx)math/libm.so
147e83
 $(objpfx)tst-audit8.out: $(objpfx)tst-auditmod1.so
147e83
 tst-audit8-ENV = LD_AUDIT=$(objpfx)tst-auditmod1.so
147e83
diff -urN glibc-2.17-c758a686/elf/rtld.c glibc-2.17-c758a686/elf/rtld.c
147e83
--- glibc-2.17-c758a686/elf/rtld.c	2013-04-24 16:06:10.410756438 -0400
147e83
+++ glibc-2.17-c758a686/elf/rtld.c	2013-04-24 16:06:49.096604693 -0400
147e83
@@ -1637,6 +1637,10 @@
147e83
 	}
147e83
     }
147e83
 
147e83
+  /* Keep track of the currently loaded modules to count how many
147e83
+     non-audit modules which use TLS are loaded.  */
147e83
+  size_t count_modids = _dl_count_modids ();
147e83
+
147e83
   /* Set up debugging before the debugger is notified for the first time.  */
147e83
 #ifdef ELF_MACHINE_DEBUG_SETUP
147e83
   /* Some machines (e.g. MIPS) don't use DT_DEBUG in this way.  */
147e83
@@ -2281,7 +2285,8 @@
147e83
 # define NONTLS_INIT_TP do { } while (0)
147e83
 #endif
147e83
 
147e83
-  if (!was_tls_init_tp_called && GL(dl_tls_max_dtv_idx) > 0)
147e83
+  if ((!was_tls_init_tp_called && GL(dl_tls_max_dtv_idx) > 0)
147e83
+      || count_modids != _dl_count_modids ())
147e83
     ++GL(dl_tls_generation);
147e83
 
147e83
   /* Now that we have completed relocation, the initializer data
147e83
diff -urN glibc-2.17-c758a686/elf/tst-audit9.c glibc-2.17-c758a686/elf/tst-audit9.c
147e83
--- glibc-2.17-c758a686/elf/tst-audit9.c	1969-12-31 19:00:00.000000000 -0500
147e83
+++ glibc-2.17-c758a686/elf/tst-audit9.c	2013-04-24 16:06:49.096604693 -0400
147e83
@@ -0,0 +1,8 @@
147e83
+#include <dlfcn.h>
147e83
+
147e83
+int main(void)
147e83
+{
147e83
+  void *h = dlopen("$ORIGIN/tst-auditmod9b.so", RTLD_LAZY);
147e83
+  int (*fp)(void) = dlsym(h, "f");
147e83
+  return fp() - 1;
147e83
+}
147e83
diff -urN glibc-2.17-c758a686/elf/tst-auditmod9a.c glibc-2.17-c758a686/elf/tst-auditmod9a.c
147e83
--- glibc-2.17-c758a686/elf/tst-auditmod9a.c	1969-12-31 19:00:00.000000000 -0500
147e83
+++ glibc-2.17-c758a686/elf/tst-auditmod9a.c	2013-04-24 16:06:49.097604689 -0400
147e83
@@ -0,0 +1,16 @@
147e83
+#include <stdint.h>
147e83
+
147e83
+__thread int var;
147e83
+
147e83
+unsigned int
147e83
+la_version (unsigned int v)
147e83
+{
147e83
+  return v;
147e83
+}
147e83
+
147e83
+void
147e83
+la_activity (uintptr_t *cookie, unsigned int flag)
147e83
+{
147e83
+  ++var;
147e83
+}
147e83
+
147e83
diff -urN glibc-2.17-c758a686/elf/tst-auditmod9b.c glibc-2.17-c758a686/elf/tst-auditmod9b.c
147e83
--- glibc-2.17-c758a686/elf/tst-auditmod9b.c	1969-12-31 19:00:00.000000000 -0500
147e83
+++ glibc-2.17-c758a686/elf/tst-auditmod9b.c	2013-04-24 16:06:49.097604689 -0400
147e83
@@ -0,0 +1,6 @@
147e83
+__thread int a;
147e83
+
147e83
+int f(void)
147e83
+{
147e83
+  return ++a;
147e83
+}
147e83
diff -urN glibc-2.17-c758a686/sysdeps/generic/ldsodefs.h glibc-2.17-c758a686/sysdeps/generic/ldsodefs.h
147e83
--- glibc-2.17-c758a686/sysdeps/generic/ldsodefs.h	2013-04-24 16:06:10.545755798 -0400
147e83
+++ glibc-2.17-c758a686/sysdeps/generic/ldsodefs.h	2013-04-24 16:06:49.098604686 -0400
147e83
@@ -1031,6 +1031,9 @@
147e83
 /* Determine next available module ID.  */
147e83
 extern size_t _dl_next_tls_modid (void) internal_function attribute_hidden;
147e83
 
147e83
+/* Count the modules with TLS segments.  */
147e83
+extern size_t _dl_count_modids (void) internal_function attribute_hidden;
147e83
+
147e83
 /* Calculate offset of the TLS blocks in the static TLS block.  */
147e83
 extern void _dl_determine_tlsoffset (void) internal_function attribute_hidden;
147e83