Blame SOURCES/glibc-rh1103874.patch

147e83
diff -pruN glibc-2.17-c758a686/nptl/sysdeps/pthread/unwind-forcedunwind.c glibc-2.17-c758a686/nptl/sysdeps/pthread/unwind-forcedunwind.c
147e83
--- glibc-2.17-c758a686/nptl/sysdeps/pthread/unwind-forcedunwind.c	2010-05-04 16:57:23.000000000 +0530
147e83
+++ glibc-2.17-c758a686/nptl/sysdeps/pthread/unwind-forcedunwind.c	2014-06-02 23:00:02.901013275 +0530
147e83
@@ -45,8 +45,10 @@ pthread_cancel_init (void)
147e83
 
147e83
   if (__builtin_expect (libgcc_s_handle != NULL, 1))
147e83
     {
147e83
-      /* Force gcc to reload all values.  */
147e83
-      asm volatile ("" ::: "memory");
147e83
+      /* Order reads so as to prevent speculation of loads
147e83
+	 of libgcc_s_{resume,personality,forcedunwind,getcfa}
147e83
+	 to points prior to the write barrier.  */
147e83
+      atomic_read_barrier ();
147e83
       return;
147e83
     }
147e83
 
147e83
@@ -72,9 +74,14 @@ pthread_cancel_init (void)
147e83
   libgcc_s_forcedunwind = forcedunwind;
147e83
   PTR_MANGLE (getcfa);
147e83
   libgcc_s_getcfa = getcfa;
147e83
-  /* Make sure libgcc_s_handle is written last.  Otherwise,
147e83
-     pthread_cancel_init might return early even when the pointer the
147e83
-     caller is interested in is not initialized yet.  */
147e83
+  /* At the point at which any thread writes the handle
147e83
+     to libgcc_s_handle, the initialization is complete.
147e83
+     The writing of libgcc_s_handle is atomic. All other
147e83
+     threads reading libgcc_s_handle do so atomically. Any
147e83
+     thread that does not execute this function must issue
147e83
+     a read barrier to ensure that all of the above has
147e83
+     actually completed and that the values of the
147e83
+     function pointers are correct.   */
147e83
   atomic_write_barrier ();
147e83
   libgcc_s_handle = handle;
147e83
 }
147e83
@@ -91,13 +98,19 @@ __unwind_freeres (void)
147e83
     }
147e83
 }
147e83
 
147e83
-void
147e83
-_Unwind_Resume (struct _Unwind_Exception *exc)
147e83
+static __always_inline void
147e83
+_maybe_pthread_cancel_init (void)
147e83
 {
147e83
   if (__builtin_expect (libgcc_s_handle == NULL, 0))
147e83
     pthread_cancel_init ();
147e83
   else
147e83
     atomic_read_barrier ();
147e83
+}
147e83
+
147e83
+void
147e83
+_Unwind_Resume (struct _Unwind_Exception *exc)
147e83
+{
147e83
+  _maybe_pthread_cancel_init ();
147e83
 
147e83
   void (*resume) (struct _Unwind_Exception *exc) = libgcc_s_resume;
147e83
   PTR_DEMANGLE (resume);
147e83
@@ -108,10 +123,7 @@ __gcc_personality_v0 (int version, _Unwi
147e83
 		      struct _Unwind_Exception *ue_header,
147e83
 		      struct _Unwind_Context *context)
147e83
 {
147e83
-  if (__builtin_expect (libgcc_s_handle == NULL, 0))
147e83
-    pthread_cancel_init ();
147e83
-  else
147e83
-    atomic_read_barrier ();
147e83
+  _maybe_pthread_cancel_init ();
147e83
 
147e83
   _Unwind_Reason_Code (*personality)
147e83
     (int, _Unwind_Action, _Unwind_Exception_Class, struct _Unwind_Exception *,
147e83
@@ -122,10 +136,7 @@ _Unwind_Reason_Code
147e83
 _Unwind_ForcedUnwind (struct _Unwind_Exception *exc, _Unwind_Stop_Fn stop,
147e83
 		      void *stop_argument)
147e83
 {
147e83
-  if (__builtin_expect (libgcc_s_handle == NULL, 0))
147e83
-    pthread_cancel_init ();
147e83
-  else
147e83
-    atomic_read_barrier ();
147e83
+  _maybe_pthread_cancel_init ();
147e83
 
147e83
   _Unwind_Reason_Code (*forcedunwind)
147e83
     (struct _Unwind_Exception *, _Unwind_Stop_Fn, void *)
147e83
@@ -135,10 +148,7 @@ _Unwind_ForcedUnwind (struct _Unwind_Exc
147e83
 _Unwind_Word
147e83
 _Unwind_GetCFA (struct _Unwind_Context *context)
147e83
 {
147e83
-  if (__builtin_expect (libgcc_s_handle == NULL, 0))
147e83
-    pthread_cancel_init ();
147e83
-  else
147e83
-    atomic_read_barrier ();
147e83
+  _maybe_pthread_cancel_init ();
147e83
 
147e83
   _Unwind_Word (*getcfa) (struct _Unwind_Context *) = libgcc_s_getcfa;
147e83
   PTR_DEMANGLE (getcfa);
147e83
diff -pruN glibc-2.17-c758a686/sysdeps/gnu/unwind-resume.c glibc-2.17-c758a686/sysdeps/gnu/unwind-resume.c
147e83
--- glibc-2.17-c758a686/sysdeps/gnu/unwind-resume.c	2010-05-04 16:57:23.000000000 +0530
147e83
+++ glibc-2.17-c758a686/sysdeps/gnu/unwind-resume.c	2014-06-02 23:02:26.812007078 +0530
147e83
@@ -20,8 +20,11 @@
147e83
 #include <dlfcn.h>
147e83
 #include <stdio.h>
147e83
 #include <unwind.h>
147e83
+#include <pthreadP.h>
147e83
+#include <sysdep.h>
147e83
 #include <gnu/lib-names.h>
147e83
 
147e83
+static void *libgcc_s_handle;
147e83
 static void (*libgcc_s_resume) (struct _Unwind_Exception *exc);
147e83
 static _Unwind_Reason_Code (*libgcc_s_personality)
147e83
   (int, _Unwind_Action, _Unwind_Exception_Class, struct _Unwind_Exception *,
147e83
@@ -42,13 +45,32 @@ init (void)
147e83
 
147e83
   libgcc_s_resume = resume;
147e83
   libgcc_s_personality = personality;
147e83
+  atomic_write_barrier ();
147e83
+  /* At the point at which any thread writes the handle
147e83
+     to libgcc_s_handle, the initialization is complete.
147e83
+     The writing of libgcc_s_handle is atomic. All other
147e83
+     threads reading libgcc_s_handle do so atomically. Any
147e83
+     thread that does not execute this function must issue
147e83
+     a read barrier to ensure that all of the above has
147e83
+     actually completed and that the values of the
147e83
+     function pointers are correct.   */
147e83
+  libgcc_s_handle = handle;
147e83
 }
147e83
 
147e83
+static __always_inline void
147e83
+_maybe_init (void)
147e83
+{
147e83
+  if (__builtin_expect (libgcc_s_handle == NULL, 0))
147e83
+    init ();
147e83
+  else
147e83
+    atomic_read_barrier ();
147e83
+}
147e83
+
147e83
+
147e83
 void
147e83
 _Unwind_Resume (struct _Unwind_Exception *exc)
147e83
 {
147e83
-  if (__builtin_expect (libgcc_s_resume == NULL, 0))
147e83
-    init ();
147e83
+  _maybe_init ();
147e83
   libgcc_s_resume (exc);
147e83
 }
147e83
 
147e83
@@ -58,8 +80,7 @@ __gcc_personality_v0 (int version, _Unwi
147e83
                       struct _Unwind_Exception *ue_header,
147e83
                       struct _Unwind_Context *context)
147e83
 {
147e83
-  if (__builtin_expect (libgcc_s_personality == NULL, 0))
147e83
-    init ();
147e83
+  _maybe_init ();
147e83
   return libgcc_s_personality (version, actions, exception_class,
147e83
 			       ue_header, context);
147e83
 }