about summary refs log tree commit diff
diff options
context:
space:
mode:
authorH.J. Lu <hjl.tools@gmail.com>2012-10-05 10:20:39 -0700
committerH.J. Lu <hjl.tools@gmail.com>2012-10-05 10:20:39 -0700
commit9cee55856438b714fa1efa45d8b7c1857467f4ca (patch)
tree450926ee00a192c70e6591d5fa4ebeded76d02f1
parent28234b077ec6667b5dd0a6b60c6d8dbd9e28f6e1 (diff)
downloadglibc-9cee55856438b714fa1efa45d8b7c1857467f4ca.tar.gz
glibc-9cee55856438b714fa1efa45d8b7c1857467f4ca.tar.xz
glibc-9cee55856438b714fa1efa45d8b7c1857467f4ca.zip
Set up the data structures for vDSO in libc.a
-rw-r--r--ChangeLog15
-rw-r--r--elf/dl-support.c9
-rw-r--r--elf/dynamic-link.h145
-rw-r--r--elf/get-dynamic-info.h161
-rw-r--r--elf/rtld.c96
-rw-r--r--elf/setup-vdso.h119
6 files changed, 307 insertions, 238 deletions
diff --git a/ChangeLog b/ChangeLog
index 3d3fa6ddf1..090efd0de4 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,18 @@
+2012-10-05  H.J. Lu  <hongjiu.lu@intel.com>
+
+	[BZ #14557]
+	* elf/dl-support.c (_dl_sysinfo_map): New.
+	Include "get-dynamic-info.h" and "setup-vdso.h".
+	(_dl_non_dynamic_init): Call setup_vdso.
+	* elf/dynamic-link.h: Don't include <assert.h>.
+	(elf_get_dynamic_info): Moved to ...
+	* elf/get-dynamic-info.h: Here.  New file.
+	* elf/dynamic-link.h: Include "get-dynamic-info.h".
+	* elf/rtld.c (dl_main): Break out vDSO setup code into ...
+	* elf/setup-vdso.h: Here.  New file.
+	* elf/rtld.c: Include "setup-vdso.h".
+	(dl_main): Call setup_vdso.
+
 2012-10-05  Joseph Myers  <joseph@codesourcery.com>
 
 	* math/libm-test.inc: List nexttoward, cimag, clog10, conf and
diff --git a/elf/dl-support.c b/elf/dl-support.c
index 2bb468a5fb..424ca6ddea 100644
--- a/elf/dl-support.c
+++ b/elf/dl-support.c
@@ -161,6 +161,11 @@ uintptr_t _dl_sysinfo = DL_SYSINFO_DEFAULT;
 #if defined NEED_DL_SYSINFO || defined NEED_DL_SYSINFO_DSO
 /* Address of the ELF headers in the vsyscall page.  */
 const ElfW(Ehdr) *_dl_sysinfo_dso;
+
+struct link_map *_dl_sysinfo_map;
+
+# include "get-dynamic-info.h"
+# include "setup-vdso.h"
 #endif
 
 /* During the program run we must not modify the global data of
@@ -266,6 +271,10 @@ _dl_non_dynamic_init (void)
 
   _dl_verbose = *(getenv ("LD_WARN") ?: "") == '\0' ? 0 : 1;
 
+  /* Set up the data structures for the system-supplied DSO early,
+     so they can influence _dl_init_paths.  */
+  setup_vdso (NULL, NULL);
+
   /* Initialize the data structures for the search paths for shared
      objects.  */
   _dl_init_paths (getenv ("LD_LIBRARY_PATH"));
diff --git a/elf/dynamic-link.h b/elf/dynamic-link.h
index d982c52ed3..ad30d23a7f 100644
--- a/elf/dynamic-link.h
+++ b/elf/dynamic-link.h
@@ -42,7 +42,6 @@
 int internal_function _dl_try_allocate_static_tls (struct link_map *map);
 
 #include <elf.h>
-#include <assert.h>
 
 #ifdef RESOLVE_MAP
 /* We pass reloc_addr as a pointer to void, as opposed to a pointer to
@@ -88,149 +87,7 @@ elf_machine_lazy_rel (struct link_map *map,
 
 #include <dl-machine.h>
 
-
-/* Read the dynamic section at DYN and fill in INFO with indices DT_*.  */
-#ifndef RESOLVE_MAP
-static
-#else
-auto
-#endif
-inline void __attribute__ ((unused, always_inline))
-elf_get_dynamic_info (struct link_map *l, ElfW(Dyn) *temp)
-{
-  ElfW(Dyn) *dyn = l->l_ld;
-  ElfW(Dyn) **info;
-#if __ELF_NATIVE_CLASS == 32
-  typedef Elf32_Word d_tag_utype;
-#elif __ELF_NATIVE_CLASS == 64
-  typedef Elf64_Xword d_tag_utype;
-#endif
-
-#ifndef RTLD_BOOTSTRAP
-  if (dyn == NULL)
-    return;
-#endif
-
-  info = l->l_info;
-
-  while (dyn->d_tag != DT_NULL)
-    {
-      if ((d_tag_utype) dyn->d_tag < DT_NUM)
-	info[dyn->d_tag] = dyn;
-      else if (dyn->d_tag >= DT_LOPROC &&
-	       dyn->d_tag < DT_LOPROC + DT_THISPROCNUM)
-	info[dyn->d_tag - DT_LOPROC + DT_NUM] = dyn;
-      else if ((d_tag_utype) DT_VERSIONTAGIDX (dyn->d_tag) < DT_VERSIONTAGNUM)
-	info[VERSYMIDX (dyn->d_tag)] = dyn;
-      else if ((d_tag_utype) DT_EXTRATAGIDX (dyn->d_tag) < DT_EXTRANUM)
-	info[DT_EXTRATAGIDX (dyn->d_tag) + DT_NUM + DT_THISPROCNUM
-	     + DT_VERSIONTAGNUM] = dyn;
-      else if ((d_tag_utype) DT_VALTAGIDX (dyn->d_tag) < DT_VALNUM)
-	info[DT_VALTAGIDX (dyn->d_tag) + DT_NUM + DT_THISPROCNUM
-	     + DT_VERSIONTAGNUM + DT_EXTRANUM] = dyn;
-      else if ((d_tag_utype) DT_ADDRTAGIDX (dyn->d_tag) < DT_ADDRNUM)
-	info[DT_ADDRTAGIDX (dyn->d_tag) + DT_NUM + DT_THISPROCNUM
-	     + DT_VERSIONTAGNUM + DT_EXTRANUM + DT_VALNUM] = dyn;
-      ++dyn;
-    }
-
-#define DL_RO_DYN_TEMP_CNT	8
-
-#ifndef DL_RO_DYN_SECTION
-  /* Don't adjust .dynamic unnecessarily.  */
-  if (l->l_addr != 0)
-    {
-      ElfW(Addr) l_addr = l->l_addr;
-      int cnt = 0;
-
-# define ADJUST_DYN_INFO(tag) \
-      do								      \
-	if (info[tag] != NULL)						      \
-	  {								      \
-	    if (temp)							      \
-	      {								      \
-		temp[cnt].d_tag = info[tag]->d_tag;			      \
-		temp[cnt].d_un.d_ptr = info[tag]->d_un.d_ptr + l_addr;	      \
-		info[tag] = temp + cnt++;				      \
-	      }								      \
-	    else							      \
-	      info[tag]->d_un.d_ptr += l_addr;				      \
-	  }								      \
-      while (0)
-
-      ADJUST_DYN_INFO (DT_HASH);
-      ADJUST_DYN_INFO (DT_PLTGOT);
-      ADJUST_DYN_INFO (DT_STRTAB);
-      ADJUST_DYN_INFO (DT_SYMTAB);
-# if ! ELF_MACHINE_NO_RELA
-      ADJUST_DYN_INFO (DT_RELA);
-# endif
-# if ! ELF_MACHINE_NO_REL
-      ADJUST_DYN_INFO (DT_REL);
-# endif
-      ADJUST_DYN_INFO (DT_JMPREL);
-      ADJUST_DYN_INFO (VERSYMIDX (DT_VERSYM));
-      ADJUST_DYN_INFO (DT_ADDRTAGIDX (DT_GNU_HASH) + DT_NUM + DT_THISPROCNUM
-		       + DT_VERSIONTAGNUM + DT_EXTRANUM + DT_VALNUM);
-# undef ADJUST_DYN_INFO
-      assert (cnt <= DL_RO_DYN_TEMP_CNT);
-    }
-#endif
-  if (info[DT_PLTREL] != NULL)
-    {
-#if ELF_MACHINE_NO_RELA
-      assert (info[DT_PLTREL]->d_un.d_val == DT_REL);
-#elif ELF_MACHINE_NO_REL
-      assert (info[DT_PLTREL]->d_un.d_val == DT_RELA);
-#else
-      assert (info[DT_PLTREL]->d_un.d_val == DT_REL
-	      || info[DT_PLTREL]->d_un.d_val == DT_RELA);
-#endif
-    }
-#if ! ELF_MACHINE_NO_RELA
-  if (info[DT_RELA] != NULL)
-    assert (info[DT_RELAENT]->d_un.d_val == sizeof (ElfW(Rela)));
-# endif
-# if ! ELF_MACHINE_NO_REL
-  if (info[DT_REL] != NULL)
-    assert (info[DT_RELENT]->d_un.d_val == sizeof (ElfW(Rel)));
-#endif
-#ifdef RTLD_BOOTSTRAP
-  /* Only the bind now flags are allowed.  */
-  assert (info[VERSYMIDX (DT_FLAGS_1)] == NULL
-	  || (info[VERSYMIDX (DT_FLAGS_1)]->d_un.d_val & ~DF_1_NOW) == 0);
-  assert (info[DT_FLAGS] == NULL
-	  || (info[DT_FLAGS]->d_un.d_val & ~DF_BIND_NOW) == 0);
-  /* Flags must not be set for ld.so.  */
-  assert (info[DT_RUNPATH] == NULL);
-  assert (info[DT_RPATH] == NULL);
-#else
-  if (info[DT_FLAGS] != NULL)
-    {
-      /* Flags are used.  Translate to the old form where available.
-	 Since these l_info entries are only tested for NULL pointers it
-	 is ok if they point to the DT_FLAGS entry.  */
-      l->l_flags = info[DT_FLAGS]->d_un.d_val;
-
-      if (l->l_flags & DF_SYMBOLIC)
-	info[DT_SYMBOLIC] = info[DT_FLAGS];
-      if (l->l_flags & DF_TEXTREL)
-	info[DT_TEXTREL] = info[DT_FLAGS];
-      if (l->l_flags & DF_BIND_NOW)
-	info[DT_BIND_NOW] = info[DT_FLAGS];
-    }
-  if (info[VERSYMIDX (DT_FLAGS_1)] != NULL)
-    {
-      l->l_flags_1 = info[VERSYMIDX (DT_FLAGS_1)]->d_un.d_val;
-
-      if (l->l_flags_1 & DF_1_NOW)
-	info[DT_BIND_NOW] = info[VERSYMIDX (DT_FLAGS_1)];
-    }
-  if (info[DT_RUNPATH] != NULL)
-    /* If both RUNPATH and RPATH are given, the latter is ignored.  */
-    info[DT_RPATH] = NULL;
-#endif
-}
+#include "get-dynamic-info.h"
 
 #ifdef RESOLVE_MAP
 
diff --git a/elf/get-dynamic-info.h b/elf/get-dynamic-info.h
new file mode 100644
index 0000000000..ffac75f635
--- /dev/null
+++ b/elf/get-dynamic-info.h
@@ -0,0 +1,161 @@
+/* Read the dynamic section at DYN and fill in INFO with indices DT_*.
+   Copyright (C) 2012 Free Software Foundation, Inc.
+   This file is part of the GNU C Library.
+
+   The GNU C Library is free software; you can redistribute it and/or
+   modify it under the terms of the GNU Lesser General Public
+   License as published by the Free Software Foundation; either
+   version 2.1 of the License, or (at your option) any later version.
+
+   The GNU C Library is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+   Lesser General Public License for more details.
+
+   You should have received a copy of the GNU Lesser General Public
+   License along with the GNU C Library; if not, see
+   <http://www.gnu.org/licenses/>.  */
+
+#include <assert.h>
+
+#ifndef RESOLVE_MAP
+static
+#else
+auto
+#endif
+inline void __attribute__ ((unused, always_inline))
+elf_get_dynamic_info (struct link_map *l, ElfW(Dyn) *temp)
+{
+  ElfW(Dyn) *dyn = l->l_ld;
+  ElfW(Dyn) **info;
+#if __ELF_NATIVE_CLASS == 32
+  typedef Elf32_Word d_tag_utype;
+#elif __ELF_NATIVE_CLASS == 64
+  typedef Elf64_Xword d_tag_utype;
+#endif
+
+#ifndef RTLD_BOOTSTRAP
+  if (dyn == NULL)
+    return;
+#endif
+
+  info = l->l_info;
+
+  while (dyn->d_tag != DT_NULL)
+    {
+      if ((d_tag_utype) dyn->d_tag < DT_NUM)
+	info[dyn->d_tag] = dyn;
+      else if (dyn->d_tag >= DT_LOPROC &&
+	       dyn->d_tag < DT_LOPROC + DT_THISPROCNUM)
+	info[dyn->d_tag - DT_LOPROC + DT_NUM] = dyn;
+      else if ((d_tag_utype) DT_VERSIONTAGIDX (dyn->d_tag) < DT_VERSIONTAGNUM)
+	info[VERSYMIDX (dyn->d_tag)] = dyn;
+      else if ((d_tag_utype) DT_EXTRATAGIDX (dyn->d_tag) < DT_EXTRANUM)
+	info[DT_EXTRATAGIDX (dyn->d_tag) + DT_NUM + DT_THISPROCNUM
+	     + DT_VERSIONTAGNUM] = dyn;
+      else if ((d_tag_utype) DT_VALTAGIDX (dyn->d_tag) < DT_VALNUM)
+	info[DT_VALTAGIDX (dyn->d_tag) + DT_NUM + DT_THISPROCNUM
+	     + DT_VERSIONTAGNUM + DT_EXTRANUM] = dyn;
+      else if ((d_tag_utype) DT_ADDRTAGIDX (dyn->d_tag) < DT_ADDRNUM)
+	info[DT_ADDRTAGIDX (dyn->d_tag) + DT_NUM + DT_THISPROCNUM
+	     + DT_VERSIONTAGNUM + DT_EXTRANUM + DT_VALNUM] = dyn;
+      ++dyn;
+    }
+
+#define DL_RO_DYN_TEMP_CNT	8
+
+#ifndef DL_RO_DYN_SECTION
+  /* Don't adjust .dynamic unnecessarily.  */
+  if (l->l_addr != 0)
+    {
+      ElfW(Addr) l_addr = l->l_addr;
+      int cnt = 0;
+
+# define ADJUST_DYN_INFO(tag) \
+      do								      \
+	if (info[tag] != NULL)						      \
+	  {								      \
+	    if (temp)							      \
+	      {								      \
+		temp[cnt].d_tag = info[tag]->d_tag;			      \
+		temp[cnt].d_un.d_ptr = info[tag]->d_un.d_ptr + l_addr;	      \
+		info[tag] = temp + cnt++;				      \
+	      }								      \
+	    else							      \
+	      info[tag]->d_un.d_ptr += l_addr;				      \
+	  }								      \
+      while (0)
+
+      ADJUST_DYN_INFO (DT_HASH);
+      ADJUST_DYN_INFO (DT_PLTGOT);
+      ADJUST_DYN_INFO (DT_STRTAB);
+      ADJUST_DYN_INFO (DT_SYMTAB);
+# if ! ELF_MACHINE_NO_RELA
+      ADJUST_DYN_INFO (DT_RELA);
+# endif
+# if ! ELF_MACHINE_NO_REL
+      ADJUST_DYN_INFO (DT_REL);
+# endif
+      ADJUST_DYN_INFO (DT_JMPREL);
+      ADJUST_DYN_INFO (VERSYMIDX (DT_VERSYM));
+      ADJUST_DYN_INFO (DT_ADDRTAGIDX (DT_GNU_HASH) + DT_NUM + DT_THISPROCNUM
+		       + DT_VERSIONTAGNUM + DT_EXTRANUM + DT_VALNUM);
+# undef ADJUST_DYN_INFO
+      assert (cnt <= DL_RO_DYN_TEMP_CNT);
+    }
+#endif
+  if (info[DT_PLTREL] != NULL)
+    {
+#if ELF_MACHINE_NO_RELA
+      assert (info[DT_PLTREL]->d_un.d_val == DT_REL);
+#elif ELF_MACHINE_NO_REL
+      assert (info[DT_PLTREL]->d_un.d_val == DT_RELA);
+#else
+      assert (info[DT_PLTREL]->d_un.d_val == DT_REL
+	      || info[DT_PLTREL]->d_un.d_val == DT_RELA);
+#endif
+    }
+#if ! ELF_MACHINE_NO_RELA
+  if (info[DT_RELA] != NULL)
+    assert (info[DT_RELAENT]->d_un.d_val == sizeof (ElfW(Rela)));
+# endif
+# if ! ELF_MACHINE_NO_REL
+  if (info[DT_REL] != NULL)
+    assert (info[DT_RELENT]->d_un.d_val == sizeof (ElfW(Rel)));
+#endif
+#ifdef RTLD_BOOTSTRAP
+  /* Only the bind now flags are allowed.  */
+  assert (info[VERSYMIDX (DT_FLAGS_1)] == NULL
+	  || (info[VERSYMIDX (DT_FLAGS_1)]->d_un.d_val & ~DF_1_NOW) == 0);
+  assert (info[DT_FLAGS] == NULL
+	  || (info[DT_FLAGS]->d_un.d_val & ~DF_BIND_NOW) == 0);
+  /* Flags must not be set for ld.so.  */
+  assert (info[DT_RUNPATH] == NULL);
+  assert (info[DT_RPATH] == NULL);
+#else
+  if (info[DT_FLAGS] != NULL)
+    {
+      /* Flags are used.  Translate to the old form where available.
+	 Since these l_info entries are only tested for NULL pointers it
+	 is ok if they point to the DT_FLAGS entry.  */
+      l->l_flags = info[DT_FLAGS]->d_un.d_val;
+
+      if (l->l_flags & DF_SYMBOLIC)
+	info[DT_SYMBOLIC] = info[DT_FLAGS];
+      if (l->l_flags & DF_TEXTREL)
+	info[DT_TEXTREL] = info[DT_FLAGS];
+      if (l->l_flags & DF_BIND_NOW)
+	info[DT_BIND_NOW] = info[DT_FLAGS];
+    }
+  if (info[VERSYMIDX (DT_FLAGS_1)] != NULL)
+    {
+      l->l_flags_1 = info[VERSYMIDX (DT_FLAGS_1)]->d_un.d_val;
+
+      if (l->l_flags_1 & DF_1_NOW)
+	info[DT_BIND_NOW] = info[VERSYMIDX (DT_FLAGS_1)];
+    }
+  if (info[DT_RUNPATH] != NULL)
+    /* If both RUNPATH and RPATH are given, the latter is ignored.  */
+    info[DT_RPATH] = NULL;
+#endif
+}
diff --git a/elf/rtld.c b/elf/rtld.c
index 8a0264504b..b0126e51af 100644
--- a/elf/rtld.c
+++ b/elf/rtld.c
@@ -873,6 +873,7 @@ security_init (void)
   _dl_random = NULL;
 }
 
+#include "setup-vdso.h"
 
 /* The library search path.  */
 static const char *library_path attribute_relro;
@@ -1329,102 +1330,9 @@ of this helper program; chances are you did not intend to run this program.\n\
     }
 
   struct link_map **first_preload = &GL(dl_rtld_map).l_next;
-#if defined NEED_DL_SYSINFO || defined NEED_DL_SYSINFO_DSO
   /* Set up the data structures for the system-supplied DSO early,
      so they can influence _dl_init_paths.  */
-  if (GLRO(dl_sysinfo_dso) != NULL)
-    {
-      /* Do an abridged version of the work _dl_map_object_from_fd would do
-	 to map in the object.  It's already mapped and prelinked (and
-	 better be, since it's read-only and so we couldn't relocate it).
-	 We just want our data structures to describe it as if we had just
-	 mapped and relocated it normally.  */
-      struct link_map *l = _dl_new_object ((char *) "", "", lt_library, NULL,
-					   0, LM_ID_BASE);
-      if (__builtin_expect (l != NULL, 1))
-	{
-	  static ElfW(Dyn) dyn_temp[DL_RO_DYN_TEMP_CNT] attribute_relro;
-
-	  l->l_phdr = ((const void *) GLRO(dl_sysinfo_dso)
-		       + GLRO(dl_sysinfo_dso)->e_phoff);
-	  l->l_phnum = GLRO(dl_sysinfo_dso)->e_phnum;
-	  for (uint_fast16_t i = 0; i < l->l_phnum; ++i)
-	    {
-	      const ElfW(Phdr) *const ph = &l->l_phdr[i];
-	      if (ph->p_type == PT_DYNAMIC)
-		{
-		  l->l_ld = (void *) ph->p_vaddr;
-		  l->l_ldnum = ph->p_memsz / sizeof (ElfW(Dyn));
-		}
-	      else if (ph->p_type == PT_LOAD)
-		{
-		  if (! l->l_addr)
-		    l->l_addr = ph->p_vaddr;
-		  if (ph->p_vaddr + ph->p_memsz >= l->l_map_end)
-		    l->l_map_end = ph->p_vaddr + ph->p_memsz;
-		  if ((ph->p_flags & PF_X)
-			   && ph->p_vaddr + ph->p_memsz >= l->l_text_end)
-		    l->l_text_end = ph->p_vaddr + ph->p_memsz;
-		}
-	      else
-		/* There must be no TLS segment.  */
-		assert (ph->p_type != PT_TLS);
-	    }
-	  l->l_map_start = (ElfW(Addr)) GLRO(dl_sysinfo_dso);
-	  l->l_addr = l->l_map_start - l->l_addr;
-	  l->l_map_end += l->l_addr;
-	  l->l_text_end += l->l_addr;
-	  l->l_ld = (void *) ((ElfW(Addr)) l->l_ld + l->l_addr);
-	  elf_get_dynamic_info (l, dyn_temp);
-	  _dl_setup_hash (l);
-	  l->l_relocated = 1;
-
-	  /* The vDSO is always used.  */
-	  l->l_used = 1;
-
-	  /* Initialize l_local_scope to contain just this map.  This allows
-	     the use of dl_lookup_symbol_x to resolve symbols within the vdso.
-	     So we create a single entry list pointing to l_real as its only
-	     element */
-	  l->l_local_scope[0]->r_nlist = 1;
-	  l->l_local_scope[0]->r_list = &l->l_real;
-
-	  /* Now that we have the info handy, use the DSO image's soname
-	     so this object can be looked up by name.  Note that we do not
-	     set l_name here.  That field gives the file name of the DSO,
-	     and this DSO is not associated with any file.  */
-	  if (l->l_info[DT_SONAME] != NULL)
-	    {
-	      /* Work around a kernel problem.  The kernel cannot handle
-		 addresses in the vsyscall DSO pages in writev() calls.  */
-	      const char *dsoname = ((char *) D_PTR (l, l_info[DT_STRTAB])
-				     + l->l_info[DT_SONAME]->d_un.d_val);
-	      size_t len = strlen (dsoname);
-	      char *copy = malloc (len);
-	      if (copy == NULL)
-		_dl_fatal_printf ("out of memory\n");
-	      l->l_libname->name = l->l_name = memcpy (copy, dsoname, len);
-	    }
-
-	  /* Add the vDSO to the object list.  */
-	  _dl_add_to_namespace_list (l, LM_ID_BASE);
-
-	  /* Rearrange the list so this DSO appears after rtld_map.  */
-	  assert (l->l_next == NULL);
-	  assert (l->l_prev == main_map);
-	  GL(dl_rtld_map).l_next = l;
-	  l->l_prev = &GL(dl_rtld_map);
-	  first_preload = &l->l_next;
-
-	  /* We have a prelinked DSO preloaded by the system.  */
-	  GLRO(dl_sysinfo_map) = l;
-# ifdef NEED_DL_SYSINFO
-	  if (GLRO(dl_sysinfo) == DL_SYSINFO_DEFAULT)
-	    GLRO(dl_sysinfo) = GLRO(dl_sysinfo_dso)->e_entry + l->l_addr;
-# endif
-	}
-    }
-#endif
+  setup_vdso (main_map, &first_preload);
 
 #ifdef DL_SYSDEP_OSCHECK
   DL_SYSDEP_OSCHECK (_dl_fatal_printf);
diff --git a/elf/setup-vdso.h b/elf/setup-vdso.h
new file mode 100644
index 0000000000..1b969a0718
--- /dev/null
+++ b/elf/setup-vdso.h
@@ -0,0 +1,119 @@
+/* Set up the data structures for the system-supplied DSO.
+   Copyright (C) 2012 Free Software Foundation, Inc.
+   This file is part of the GNU C Library.
+
+   The GNU C Library is free software; you can redistribute it and/or
+   modify it under the terms of the GNU Lesser General Public
+   License as published by the Free Software Foundation; either
+   version 2.1 of the License, or (at your option) any later version.
+
+   The GNU C Library is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+   Lesser General Public License for more details.
+
+   You should have received a copy of the GNU Lesser General Public
+   License along with the GNU C Library; if not, see
+   <http://www.gnu.org/licenses/>.  */
+
+static inline void __attribute__ ((always_inline))
+setup_vdso (struct link_map *main_map __attribute__ ((unused)),
+	    struct link_map ***first_preload __attribute__ ((unused)))
+{
+#if defined NEED_DL_SYSINFO || defined NEED_DL_SYSINFO_DSO
+  if (GLRO(dl_sysinfo_dso) == NULL)
+    return;
+
+  /* Do an abridged version of the work _dl_map_object_from_fd would do
+     to map in the object.  It's already mapped and prelinked (and
+     better be, since it's read-only and so we couldn't relocate it).
+     We just want our data structures to describe it as if we had just
+     mapped and relocated it normally.  */
+  struct link_map *l = _dl_new_object ((char *) "", "", lt_library, NULL,
+				       0, LM_ID_BASE);
+  if (__builtin_expect (l != NULL, 1))
+    {
+      static ElfW(Dyn) dyn_temp[DL_RO_DYN_TEMP_CNT] attribute_relro;
+
+      l->l_phdr = ((const void *) GLRO(dl_sysinfo_dso)
+		   + GLRO(dl_sysinfo_dso)->e_phoff);
+      l->l_phnum = GLRO(dl_sysinfo_dso)->e_phnum;
+      for (uint_fast16_t i = 0; i < l->l_phnum; ++i)
+	{
+	  const ElfW(Phdr) *const ph = &l->l_phdr[i];
+	  if (ph->p_type == PT_DYNAMIC)
+	    {
+	      l->l_ld = (void *) ph->p_vaddr;
+	      l->l_ldnum = ph->p_memsz / sizeof (ElfW(Dyn));
+	    }
+	  else if (ph->p_type == PT_LOAD)
+	    {
+	      if (! l->l_addr)
+		l->l_addr = ph->p_vaddr;
+	      if (ph->p_vaddr + ph->p_memsz >= l->l_map_end)
+		l->l_map_end = ph->p_vaddr + ph->p_memsz;
+	      if ((ph->p_flags & PF_X)
+		  && ph->p_vaddr + ph->p_memsz >= l->l_text_end)
+		l->l_text_end = ph->p_vaddr + ph->p_memsz;
+	    }
+	  else
+	    /* There must be no TLS segment.  */
+	    assert (ph->p_type != PT_TLS);
+	}
+      l->l_map_start = (ElfW(Addr)) GLRO(dl_sysinfo_dso);
+      l->l_addr = l->l_map_start - l->l_addr;
+      l->l_map_end += l->l_addr;
+      l->l_text_end += l->l_addr;
+      l->l_ld = (void *) ((ElfW(Addr)) l->l_ld + l->l_addr);
+      elf_get_dynamic_info (l, dyn_temp);
+      _dl_setup_hash (l);
+      l->l_relocated = 1;
+
+      /* The vDSO is always used.  */
+      l->l_used = 1;
+
+      /* Initialize l_local_scope to contain just this map.  This allows
+	 the use of dl_lookup_symbol_x to resolve symbols within the vdso.
+	 So we create a single entry list pointing to l_real as its only
+	 element */
+      l->l_local_scope[0]->r_nlist = 1;
+      l->l_local_scope[0]->r_list = &l->l_real;
+
+      /* Now that we have the info handy, use the DSO image's soname
+	 so this object can be looked up by name.  Note that we do not
+	 set l_name here.  That field gives the file name of the DSO,
+	 and this DSO is not associated with any file.  */
+      if (l->l_info[DT_SONAME] != NULL)
+	{
+	  /* Work around a kernel problem.  The kernel cannot handle
+	     addresses in the vsyscall DSO pages in writev() calls.  */
+	  const char *dsoname = ((char *) D_PTR (l, l_info[DT_STRTAB])
+				 + l->l_info[DT_SONAME]->d_un.d_val);
+	  size_t len = strlen (dsoname);
+	  char *copy = malloc (len);
+	  if (copy == NULL)
+	    _dl_fatal_printf ("out of memory\n");
+	  l->l_libname->name = l->l_name = memcpy (copy, dsoname, len);
+	}
+
+      /* Add the vDSO to the object list.  */
+      _dl_add_to_namespace_list (l, LM_ID_BASE);
+
+# ifdef IS_IN_rtld
+      /* Rearrange the list so this DSO appears after rtld_map.  */
+      assert (l->l_next == NULL);
+      assert (l->l_prev == main_map);
+      GL(dl_rtld_map).l_next = l;
+      l->l_prev = &GL(dl_rtld_map);
+      *first_preload = &l->l_next;
+# endif
+
+      /* We have a prelinked DSO preloaded by the system.  */
+      GLRO(dl_sysinfo_map) = l;
+# ifdef NEED_DL_SYSINFO
+      if (GLRO(dl_sysinfo) == DL_SYSINFO_DEFAULT)
+	GLRO(dl_sysinfo) = GLRO(dl_sysinfo_dso)->e_entry + l->l_addr;
+# endif
+    }
+#endif
+}