arrfab / rpms / glibc

Forked from rpms/glibc 4 years ago
Clone

Blame SOURCES/glibc-rh1020637.patch

147e83
commit acd98a8ed1460497e788c701eb92616f1df9b446
147e83
Author: Andreas Krebbel <krebbel@linux.vnet.ibm.com>
147e83
Date:   Fri Nov 29 09:57:04 2013 +0100
147e83
147e83
    [BZ #16214] S/390: Fix TLS GOT pointer setup.
147e83
147e83
diff --git glibc-2.17-c758a686/sysdeps/s390/Versions glibc-2.17-c758a686/sysdeps/s390/Versions
147e83
index e18617c..baf9842 100644
147e83
--- glibc-2.17-c758a686/sysdeps/s390/Versions
147e83
+++ glibc-2.17-c758a686/sysdeps/s390/Versions
147e83
@@ -3,4 +3,8 @@ ld {
147e83
     # runtime interface to TLS
147e83
     __tls_get_offset;
147e83
   }
147e83
+  GLIBC_PRIVATE {
147e83
+    # Exported by ld used by libc.
147e83
+    __tls_get_addr_internal;
147e83
+  }
147e83
 }
147e83
diff --git glibc-2.17-c758a686/sysdeps/s390/dl-tls.h glibc-2.17-c758a686/sysdeps/s390/dl-tls.h
147e83
index 68a5af4..52192a2 100644
147e83
--- glibc-2.17-c758a686/sysdeps/s390/dl-tls.h
147e83
+++ glibc-2.17-c758a686/sysdeps/s390/dl-tls.h
147e83
@@ -26,11 +26,26 @@ typedef struct
147e83
 
147e83
 
147e83
 #ifdef SHARED
147e83
-/* This is the prototype for the GNU version.  */
147e83
-extern void *__tls_get_addr (tls_index *ti) attribute_hidden;
147e83
+
147e83
 extern unsigned long __tls_get_offset (unsigned long got_offset);
147e83
 
147e83
 # ifdef IS_IN_rtld
147e83
+
147e83
+#  include <shlib-compat.h>
147e83
+
147e83
+extern void *__tls_get_addr (tls_index *ti) attribute_hidden;
147e83
+/* Make a temporary alias of __tls_get_addr to remove the hidden
147e83
+   attribute.  Then export __tls_get_addr as __tls_get_addr_internal
147e83
+   for use from libc.  We do not want to export __tls_get_addr, but we
147e83
+   do need to use it from libc when looking up the address of a TLS
147e83
+   variable. We don't use __tls_get_offset because it requires r12 to
147e83
+   be setup and that might not always be true. Either way it's more
147e83
+   optimal to use __tls_get_addr directly (that's what
147e83
+   __tls_get_offset does anyways).  */
147e83
+strong_alias (__tls_get_addr, __tls_get_addr_internal_tmp);
147e83
+versioned_symbol (ld, __tls_get_addr_internal_tmp,
147e83
+		  __tls_get_addr_internal, GLIBC_PRIVATE);
147e83
+
147e83
 /* The special thing about the s390 TLS ABI is that we do not have the
147e83
    standard __tls_get_addr function but the __tls_get_offset function
147e83
    which differs in two important aspects:
147e83
@@ -63,15 +78,21 @@ __tls_get_offset:\n\
147e83
 1:	.long	__tls_get_addr - 0b\n\
147e83
 ");
147e83
 #  endif
147e83
-# endif
147e83
+# else /* IS_IN_rtld */
147e83
+extern void *__tls_get_addr_internal (tls_index *ti);
147e83
+# endif /* !IS_IN_rtld */
147e83
 
147e83
 # define GET_ADDR_OFFSET \
147e83
   (ti->ti_offset - (unsigned long) __builtin_thread_pointer ())
147e83
 
147e83
-# define __TLS_GET_ADDR(__ti) \
147e83
-  ({ extern char _GLOBAL_OFFSET_TABLE_[] attribute_hidden;		  \
147e83
-     (void *) __tls_get_offset ((char *) (__ti) - _GLOBAL_OFFSET_TABLE_)  \
147e83
-     + (unsigned long) __builtin_thread_pointer (); })
147e83
+/* Use the privately exported __tls_get_addr_internal instead of
147e83
+   __tls_get_offset in order to avoid the __tls_get_offset special
147e83
+   linkage requiring the GOT pointer to be set up in r12.  The
147e83
+   compiler will take care of setting up r12 only if itself issued the
147e83
+   __tls_get_offset call.  */
147e83
+# define __TLS_GET_ADDR(__ti)					\
147e83
+  ({ (void *) __tls_get_addr_internal ((char *) (__ti))		\
147e83
+      + (unsigned long) __builtin_thread_pointer (); })
147e83
 
147e83
 #endif
147e83
 
147e83
diff --git glibc-2.17-c758a686/sysdeps/s390/s390-32/tls-macros.h glibc-2.17-c758a686/sysdeps/s390/s390-32/tls-macros.h
147e83
index 8a0ad58..a592d81 100644
147e83
--- glibc-2.17-c758a686/sysdeps/s390/s390-32/tls-macros.h
147e83
+++ glibc-2.17-c758a686/sysdeps/s390/s390-32/tls-macros.h
147e83
@@ -8,12 +8,15 @@
147e83
 
147e83
 #ifdef PIC
147e83
 # define TLS_IE(x) \
147e83
-  ({ unsigned long __offset;						      \
147e83
+  ({ unsigned long __offset, __got;					      \
147e83
      asm ("bras %0,1f\n"						      \
147e83
-	  "0:\t.long " #x "@gotntpoff\n"				      \
147e83
-	  "1:\tl %0,0(%0)\n\t"						      \
147e83
-	  "l %0,0(%0,%%r12):tls_load:" #x				      \
147e83
-	  : "=&a" (__offset) : : "cc" );				      \
147e83
+	  "0:\t.long _GLOBAL_OFFSET_TABLE_-0b\n\t"			      \
147e83
+	  ".long " #x "@gotntpoff\n"					      \
147e83
+	  "1:\tl %1,0(%0)\n\t"						      \
147e83
+	  "la %1,0(%1,%0)\n\t"						      \
147e83
+	  "l %0,4(%0)\n\t"						      \
147e83
+	  "l %0,0(%0,%1):tls_load:" #x "\n"				      \
147e83
+	  : "=&a" (__offset), "=&a" (__got) : : "cc" );			      \
147e83
      (int *) (__builtin_thread_pointer() + __offset); })
147e83
 #else
147e83
 # define TLS_IE(x) \
147e83
diff --git glibc-2.17-c758a686/sysdeps/s390/s390-64/tls-macros.h glibc-2.17-c758a686/sysdeps/s390/s390-64/tls-macros.h
147e83
index be8aa6c..3c59436 100644
147e83
--- glibc-2.17-c758a686/sysdeps/s390/s390-64/tls-macros.h
147e83
+++ glibc-2.17-c758a686/sysdeps/s390/s390-64/tls-macros.h
147e83
@@ -8,12 +8,13 @@
147e83
 
147e83
 #ifdef PIC
147e83
 # define TLS_IE(x) \
147e83
-  ({ unsigned long __offset;						      \
147e83
-     asm ("bras %0,1f\n"						      \
147e83
-	  "0:\t.quad " #x "@gotntpoff\n"				      \
147e83
-	  "1:\tlg %0,0(%0)\n\t"						      \
147e83
-	  "lg %0,0(%0,%%r12):tls_load:" #x				      \
147e83
-	  : "=&a" (__offset) : : "cc" );				      \
147e83
+  ({ unsigned long __offset, __got;					      \
147e83
+     asm ("bras %0,0f\n\t"						      \
147e83
+	  ".quad " #x "@gotntpoff\n"					      \
147e83
+	  "0:\tlarl %1,_GLOBAL_OFFSET_TABLE_\n\t"			      \
147e83
+	  "lg %0,0(%0)\n\t"						      \
147e83
+	  "lg %0,0(%0,%1):tls_load:" #x	"\n"				      \
147e83
+	  : "=&a" (__offset), "=&a" (__got) : : "cc" );			      \
147e83
      (int *) (__builtin_thread_pointer() + __offset); })
147e83
 #else
147e83
 # define TLS_IE(x) \