arrfab / rpms / glibc

Forked from rpms/glibc 5 years ago
Clone

Blame SOURCES/glibc-rh1445781-2.patch

147e83
commit 58007e9e68913290b1f4f73afc1055f779a8ed5d
147e83
Author: H.J. Lu <hjl.tools@gmail.com>
147e83
Date:   Thu May 28 05:06:27 2015 -0700
147e83
147e83
    Make sure that calloc is called at least once
147e83
    
147e83
    PLT relocations aren't required when -z now used.
147e83
    
147e83
    
147e83
    	[BZ #18422]
147e83
    	* Makefile ($(objpfx)tst-audit2): Depend on $(libdl).
147e83
    	($(objpfx)tst-audit2.out): Also depend on
147e83
    	$(objpfx)tst-auditmod9b.so.
147e83
    	* elf/tst-audit2.c: Include <dlfcn.h>.
147e83
    	(calloc_called): New.
147e83
    	(calloc): Allow to be called more than once.
147e83
    	(do_test): dllopen/dlclose $ORIGIN/tst-auditmod9b.so.
147e83
147e83
diff -rup a/elf/Makefile b/elf/Makefile
147e83
--- a/elf/Makefile	2017-10-04 16:42:22.000000000 -0400
147e83
+++ b/elf/Makefile	2017-10-05 17:40:38.402451971 -0400
147e83
@@ -1020,7 +1020,8 @@ $(objpfx)tst-dlmopen3.out: $(objpfx)tst-
147e83
 $(objpfx)tst-audit1.out: $(objpfx)tst-auditmod1.so
147e83
 tst-audit1-ENV = LD_AUDIT=$(objpfx)tst-auditmod1.so
147e83
 
147e83
-$(objpfx)tst-audit2.out: $(objpfx)tst-auditmod1.so
147e83
+$(objpfx)tst-audit2: $(libdl)
147e83
+$(objpfx)tst-audit2.out: $(objpfx)tst-auditmod1.so $(objpfx)tst-auditmod9b.so
147e83
 tst-audit2-ENV = LD_AUDIT=$(objpfx)tst-auditmod1.so
147e83
 
147e83
 $(objpfx)tst-audit3: $(objpfx)tst-auditmod3a.so
147e83
diff -rup a/elf/tst-audit2.c b/elf/tst-audit2.c
147e83
--- a/elf/tst-audit2.c	2017-10-04 16:42:18.000000000 -0400
147e83
+++ b/elf/tst-audit2.c	2017-10-05 17:40:51.570518031 -0400
147e83
@@ -3,26 +3,35 @@
147e83
 #include <stdio.h>
147e83
 #include <stdlib.h>
147e83
 #include <string.h>
147e83
+#include <dlfcn.h>
147e83
 
147e83
 #define MAGIC1 0xabcdef72
147e83
 #define MAGIC2 0xd8675309
147e83
 static __thread unsigned int magic[] = { MAGIC1, MAGIC2 };
147e83
+static __thread int calloc_called;
147e83
 
147e83
 #undef calloc
147e83
 
147e83
 /* This calloc definition will be called by the dynamic linker itself.
147e83
-   We test that it has initialized our TLS block by the time it does so.  */
147e83
+   We test that interposed calloc is called by the dynamic loader, and
147e83
+   that TLS is fully initialized by then.  */
147e83
 
147e83
 void *
147e83
 calloc (size_t n, size_t m)
147e83
 {
147e83
-  if (magic[0] != MAGIC1 || magic[1] != MAGIC2)
147e83
+  if (!calloc_called)
147e83
     {
147e83
-      printf ("{%x, %x} != {%x, %x}\n", magic[0], magic[1], MAGIC1, MAGIC2);
147e83
-      abort ();
147e83
+      /* Allow our calloc to be called more than once.  */
147e83
+      calloc_called = 1;
147e83
+      if (magic[0] != MAGIC1 || magic[1] != MAGIC2)
147e83
+	{
147e83
+	  printf ("{%x, %x} != {%x, %x}\n",
147e83
+		  magic[0], magic[1], MAGIC1, MAGIC2);
147e83
+	  abort ();
147e83
+	}
147e83
+      magic[0] = MAGIC2;
147e83
+      magic[1] = MAGIC1;
147e83
     }
147e83
-  magic[0] = MAGIC2;
147e83
-  magic[1] = MAGIC1;
147e83
 
147e83
   n *= m;
147e83
   void *ptr = malloc (n);
147e83
@@ -34,6 +43,11 @@ calloc (size_t n, size_t m)
147e83
 static int
147e83
 do_test (void)
147e83
 {
147e83
+  /* Make sure that our calloc is called from the dynamic linker at least
147e83
+     once.  */
147e83
+  void *h = dlopen("$ORIGIN/tst-auditmod9b.so", RTLD_LAZY);
147e83
+  if (h != NULL)
147e83
+    dlclose (h);
147e83
   if (magic[1] != MAGIC1 || magic[0] != MAGIC2)
147e83
     {
147e83
       printf ("{%x, %x} != {%x, %x}\n", magic[0], magic[1], MAGIC2, MAGIC1);