ce426f
From a06663ebed17775761f501e5f0cdddff159959ac Mon Sep 17 00:00:00 2001
ce426f
From: Adhemerval Zanella <azanella@linux.vnet.ibm.com>
ce426f
Date: Tue, 23 Jul 2013 07:39:57 -0500
ce426f
Subject: [PATCH 42/42] PowerPC: use _dl_static_init to set GLRO(gl_pagesize)
ce426f
ce426f
This patch fixes dlfcn/tststatic5 for PowerPC where pagesize
ce426f
variable was not properly initialized in certain cases. This patch
ce426f
is based on other architecture code.
ce426f
(cherry picked from commit 7b1f8b581f9387230788e4d8a67cdbcf464dac85)
ce426f
---
ce426f
 sysdeps/unix/sysv/linux/powerpc/Makefile    |  6 +++
ce426f
 sysdeps/unix/sysv/linux/powerpc/Versions    |  6 +++
ce426f
 sysdeps/unix/sysv/linux/powerpc/dl-static.c | 84 +++++++++++++++++++++++++++++
ce426f
 sysdeps/unix/sysv/linux/powerpc/ldsodefs.h  | 33 ++++++++++++
ce426f
 5 files changed, 137 insertions(+)
ce426f
 create mode 100644 sysdeps/unix/sysv/linux/powerpc/dl-static.c
ce426f
 create mode 100644 sysdeps/unix/sysv/linux/powerpc/ldsodefs.h
ce426f
ce426f
diff --git glibc-2.17-c758a686/sysdeps/unix/sysv/linux/powerpc/Makefile glibc-2.17-c758a686/sysdeps/unix/sysv/linux/powerpc/Makefile
ce426f
index 4ff7e84..cf4de97 100644
ce426f
--- glibc-2.17-c758a686/sysdeps/unix/sysv/linux/powerpc/Makefile
ce426f
+++ glibc-2.17-c758a686/sysdeps/unix/sysv/linux/powerpc/Makefile
ce426f
@@ -15,6 +15,12 @@ endif
ce426f
 
ce426f
 ifeq ($(subdir),elf)
ce426f
 sysdep_routines += dl-vdso
ce426f
+ifeq ($(build-shared),yes)
ce426f
+# This is needed for DSO loading from static binaries.
ce426f
+sysdep-dl-routines += dl-static
ce426f
+sysdep_routines += dl-static
ce426f
+sysdep-rtld-routines += dl-static
ce426f
+endif
ce426f
 endif
ce426f
 
ce426f
 ifeq ($(subdir),misc)
ce426f
diff --git glibc-2.17-c758a686/sysdeps/unix/sysv/linux/powerpc/Versions glibc-2.17-c758a686/sysdeps/unix/sysv/linux/powerpc/Versions
ce426f
index 289c4fe..9b583fb 100644
ce426f
--- glibc-2.17-c758a686/sysdeps/unix/sysv/linux/powerpc/Versions
ce426f
+++ glibc-2.17-c758a686/sysdeps/unix/sysv/linux/powerpc/Versions
ce426f
@@ -1,3 +1,9 @@
ce426f
+ld {
ce426f
+  GLIBC_PRIVATE {
ce426f
+  # used for loading by static libraries
ce426f
+    _dl_var_init;
ce426f
+  }
ce426f
+}
ce426f
 libc {
ce426f
   GLIBC_PRIVATE {
ce426f
     __vdso_get_tbfreq;
ce426f
diff --git glibc-2.17-c758a686/sysdeps/unix/sysv/linux/powerpc/dl-static.c glibc-2.17-c758a686/sysdeps/unix/sysv/linux/powerpc/dl-static.c
ce426f
new file mode 100644
ce426f
index 0000000..8289c61
ce426f
--- /dev/null
ce426f
+++ glibc-2.17-c758a686/sysdeps/unix/sysv/linux/powerpc/dl-static.c
ce426f
@@ -0,0 +1,84 @@
ce426f
+/* Variable initialization.  PowerPC version.
ce426f
+   Copyright (C) 2013 Free Software Foundation, Inc.
ce426f
+   This file is part of the GNU C Library.
ce426f
+
ce426f
+   The GNU C Library is free software; you can redistribute it and/or
ce426f
+   modify it under the terms of the GNU Lesser General Public
ce426f
+   License as published by the Free Software Foundation; either
ce426f
+   version 2.1 of the License, or (at your option) any later version.
ce426f
+
ce426f
+   The GNU C Library is distributed in the hope that it will be useful,
ce426f
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
ce426f
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
ce426f
+   Lesser General Public License for more details.
ce426f
+
ce426f
+   You should have received a copy of the GNU Lesser General Public
ce426f
+   License along with the GNU C Library.  If not, see
ce426f
+   <http://www.gnu.org/licenses/>.  */
ce426f
+
ce426f
+#include <ldsodefs.h>
ce426f
+
ce426f
+#ifdef SHARED
ce426f
+
ce426f
+void
ce426f
+_dl_var_init (void *array[])
ce426f
+{
ce426f
+  /* It has to match "variables" below. */
ce426f
+  enum
ce426f
+    {
ce426f
+      DL_PAGESIZE = 0
ce426f
+    };
ce426f
+
ce426f
+  GLRO(dl_pagesize) = *((size_t *) array[DL_PAGESIZE]);
ce426f
+}
ce426f
+
ce426f
+#else
ce426f
+
ce426f
+static void *variables[] =
ce426f
+{
ce426f
+  &GLRO(dl_pagesize)
ce426f
+};
ce426f
+
ce426f
+static void
ce426f
+_dl_unprotect_relro (struct link_map *l)
ce426f
+{
ce426f
+  ElfW(Addr) start = ((l->l_addr + l->l_relro_addr)
ce426f
+		      & ~(GLRO(dl_pagesize) - 1));
ce426f
+  ElfW(Addr) end = ((l->l_addr + l->l_relro_addr + l->l_relro_size)
ce426f
+		    & ~(GLRO(dl_pagesize) - 1));
ce426f
+
ce426f
+  if (start != end)
ce426f
+    __mprotect ((void *) start, end - start, PROT_READ | PROT_WRITE);
ce426f
+}
ce426f
+
ce426f
+void
ce426f
+_dl_static_init (struct link_map *l)
ce426f
+{
ce426f
+  struct link_map *rtld_map = l;
ce426f
+  struct r_scope_elem **scope;
ce426f
+  const ElfW(Sym) *ref = NULL;
ce426f
+  lookup_t loadbase;
ce426f
+  void (*f) (void *[]);
ce426f
+  size_t i;
ce426f
+
ce426f
+  loadbase = _dl_lookup_symbol_x ("_dl_var_init", l, &ref, l->l_local_scope,
ce426f
+				  NULL, 0, 1, NULL);
ce426f
+
ce426f
+  for (scope = l->l_local_scope; *scope != NULL; scope++)
ce426f
+    for (i = 0; i < (*scope)->r_nlist; i++)
ce426f
+      if ((*scope)->r_list[i] == loadbase)
ce426f
+	{
ce426f
+	  rtld_map = (*scope)->r_list[i];
ce426f
+	  break;
ce426f
+	}
ce426f
+
ce426f
+  if (ref != NULL)
ce426f
+    {
ce426f
+      f = (void (*) (void *[])) DL_SYMBOL_ADDRESS (loadbase, ref);
ce426f
+      _dl_unprotect_relro (rtld_map);
ce426f
+      f (variables);
ce426f
+      _dl_protect_relro (rtld_map);
ce426f
+    }
ce426f
+}
ce426f
+
ce426f
+#endif
ce426f
diff --git glibc-2.17-c758a686/sysdeps/unix/sysv/linux/powerpc/ldsodefs.h glibc-2.17-c758a686/sysdeps/unix/sysv/linux/powerpc/ldsodefs.h
ce426f
new file mode 100644
ce426f
index 0000000..fcedf32
ce426f
--- /dev/null
ce426f
+++ glibc-2.17-c758a686/sysdeps/unix/sysv/linux/powerpc/ldsodefs.h
ce426f
@@ -0,0 +1,33 @@
ce426f
+/* Run-time dynamic linker data structures for loaded ELF shared objects.
ce426f
+   PowerPC version.
ce426f
+   Copyright (C) 2013 Free Software Foundation, Inc.
ce426f
+   This file is part of the GNU C Library.
ce426f
+
ce426f
+   The GNU C Library is free software; you can redistribute it and/or
ce426f
+   modify it under the terms of the GNU Lesser General Public
ce426f
+   License as published by the Free Software Foundation; either
ce426f
+   version 2.1 of the License, or (at your option) any later version.
ce426f
+
ce426f
+   The GNU C Library is distributed in the hope that it will be useful,
ce426f
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
ce426f
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
ce426f
+   Lesser General Public License for more details.
ce426f
+
ce426f
+   You should have received a copy of the GNU Lesser General Public
ce426f
+   License along with the GNU C Library; if not, see
ce426f
+   <http://www.gnu.org/licenses/>.  */
ce426f
+
ce426f
+#ifndef _LDSODEFS_H
ce426f
+
ce426f
+/* Get the real definitions.  */
ce426f
+#include_next <ldsodefs.h>
ce426f
+
ce426f
+/* Now define our stuff.  */
ce426f
+
ce426f
+/* We need special support to initialize DSO loaded for statically linked
ce426f
+   binaries.  */
ce426f
+extern void _dl_static_init (struct link_map *map);
ce426f
+#undef DL_STATIC_INIT
ce426f
+#define DL_STATIC_INIT(map) _dl_static_init (map)
ce426f
+
ce426f
+#endif /* ldsodefs.h */
ce426f
-- 
ce426f
1.7.11.7
ce426f