[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[commits] r8206 - in /fsf/trunk/libc: ./ elf/ sysdeps/generic/



Author: eglibc
Date: Wed Apr  1 00:04:09 2009
New Revision: 8206

Log:
Import glibc-mainline for 2009-04-01

Modified:
    fsf/trunk/libc/ChangeLog
    fsf/trunk/libc/elf/dl-addr.c
    fsf/trunk/libc/elf/dl-caller.c
    fsf/trunk/libc/elf/dl-close.c
    fsf/trunk/libc/elf/dl-fini.c
    fsf/trunk/libc/elf/dl-iteratephdr.c
    fsf/trunk/libc/elf/dl-libc.c
    fsf/trunk/libc/elf/dl-load.c
    fsf/trunk/libc/elf/dl-minimal.c
    fsf/trunk/libc/elf/dl-misc.c
    fsf/trunk/libc/elf/dl-open.c
    fsf/trunk/libc/elf/dl-support.c
    fsf/trunk/libc/elf/dl-sym.c
    fsf/trunk/libc/elf/rtld.c
    fsf/trunk/libc/sysdeps/generic/ldsodefs.h

Modified: fsf/trunk/libc/ChangeLog
==============================================================================
--- fsf/trunk/libc/ChangeLog (original)
+++ fsf/trunk/libc/ChangeLog Wed Apr  1 00:04:09 2009
@@ -1,3 +1,24 @@
+2009-03-31  Ulrich Drepper  <drepper@xxxxxxxxxx>
+
+	* elf/dl-open.c: Keep track of used name spaces and only iterate over
+	those which are used.
+	* elf/dl-addr.c: Likewise.
+	* elf/dl-caller.c: Likewise.
+	* elf/dl-fini.c: Likewise.
+	* elf/dl-iteratephdr.c: Likewise.
+	* elf/dl-libc.c: Likewise.
+	* elf/dl-load.c: Likewise.
+	* elf/dl-support.c: Likewise.
+	* elf/dl-sym.c: Likewise.
+	* elf/rtld.c: Likewise.
+	* sysdeps/generic/ldsodefs.h: Likewise.
+
+	* elf/dl-load.c: Remove support for systems without MAP_ANON.
+	* elf/dl-minimal.c: Likewise.
+	* elf/dl-misc.c: Likewise.
+	* elf/rtld.c: Likewise.
+	* sysdeps/generic/ldsodefs.h: Likewise.
+
 2009-03-30  Ulrich Drepper  <drepper@xxxxxxxxxx>
 
 	* elf/do-lookup.h (do_lookup_x): Minor optimization and cleanup.

Modified: fsf/trunk/libc/elf/dl-addr.c
==============================================================================
--- fsf/trunk/libc/elf/dl-addr.c (original)
+++ fsf/trunk/libc/elf/dl-addr.c Wed Apr  1 00:04:09 2009
@@ -1,5 +1,5 @@
 /* Locate the shared object symbol nearest a given address.
-   Copyright (C) 1996-2004, 2005, 2006, 2007 Free Software Foundation, Inc.
+   Copyright (C) 1996-2007, 2009 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
@@ -132,7 +132,7 @@
   __rtld_lock_lock_recursive (GL(dl_load_lock));
 
   /* Find the highest-addressed object that ADDRESS is not below.  */
-  for (Lmid_t ns = 0; ns < DL_NNS; ++ns)
+  for (Lmid_t ns = 0; ns < GL(dl_nns); ++ns)
     for (struct link_map *l = GL(dl_ns)[ns]._ns_loaded; l; l = l->l_next)
       if (addr >= l->l_map_start && addr < l->l_map_end
 	  && (l->l_contiguous || _dl_addr_inside_object (l, addr)))

Modified: fsf/trunk/libc/elf/dl-caller.c
==============================================================================
--- fsf/trunk/libc/elf/dl-caller.c (original)
+++ fsf/trunk/libc/elf/dl-caller.c Wed Apr  1 00:04:09 2009
@@ -1,5 +1,5 @@
 /* Check whether caller comes from the right place.
-   Copyright (C) 2004 Free Software Foundation, Inc.
+   Copyright (C) 2004, 2009 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
@@ -35,7 +35,7 @@
 #endif
   static const char expected4[] = LD_SO;
 
-  for (Lmid_t ns = 0; ns < DL_NNS; ++ns)
+  for (Lmid_t ns = 0; ns < GL(dl_nns); ++ns)
     for (struct link_map *l = GL(dl_ns)[ns]._ns_loaded; l != NULL;
 	 l = l->l_next)
       if (caller >= (const void *) l->l_map_start

Modified: fsf/trunk/libc/elf/dl-close.c
==============================================================================
--- fsf/trunk/libc/elf/dl-close.c (original)
+++ fsf/trunk/libc/elf/dl-close.c Wed Apr  1 00:04:09 2009
@@ -1,5 +1,5 @@
 /* Close a shared object opened by `_dl_open'.
-   Copyright (C) 1996-2005, 2006, 2007 Free Software Foundation, Inc.
+   Copyright (C) 1996-2007, 2009 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
@@ -695,6 +695,18 @@
     }
 #endif
 
+  if (__builtin_expect (ns->_ns_loaded == NULL, 0)
+      && nsid == GL(dl_nns) - 1)
+    do
+      {
+	--GL(dl_nns);
+#ifndef SHARED
+	if (GL(dl_nns) == 0)
+	  break;
+#endif
+      }
+    while (GL(dl_ns)[GL(dl_nns) - 1]._ns_loaded == NULL);
+
   /* Notify the debugger those objects are finalized and gone.  */
   r->r_state = RT_CONSISTENT;
   _dl_debug_state ();
@@ -763,7 +775,7 @@
 
 libc_freeres_fn (free_mem)
 {
-  for (Lmid_t nsid = 0; nsid < DL_NNS; ++nsid)
+  for (Lmid_t nsid = 0; nsid < GL(dl_nns); ++nsid)
     if (__builtin_expect (GL(dl_ns)[nsid]._ns_global_scope_alloc, 0) != 0
 	&& (GL(dl_ns)[nsid]._ns_main_searchlist->r_nlist
 	    // XXX Check whether we need NS-specific initial_searchlist

Modified: fsf/trunk/libc/elf/dl-fini.c
==============================================================================
--- fsf/trunk/libc/elf/dl-fini.c (original)
+++ fsf/trunk/libc/elf/dl-fini.c Wed Apr  1 00:04:09 2009
@@ -1,5 +1,5 @@
 /* Call the termination functions of loaded shared objects.
-   Copyright (C) 1995,96,1998-2002,2004, 2005 Free Software Foundation, Inc.
+   Copyright (C) 1995,96,1998-2002,2004-2005,2009 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
@@ -140,7 +140,7 @@
   int do_audit = 0;
  again:
 #endif
-  for (Lmid_t ns = DL_NNS - 1; ns >= 0; --ns)
+  for (Lmid_t ns = GL(dl_nns) - 1; ns >= 0; --ns)
     {
       /* Protect against concurrent loads and unloads.  */
       __rtld_lock_lock_recursive (GL(dl_load_lock));

Modified: fsf/trunk/libc/elf/dl-iteratephdr.c
==============================================================================
--- fsf/trunk/libc/elf/dl-iteratephdr.c (original)
+++ fsf/trunk/libc/elf/dl-iteratephdr.c Wed Apr  1 00:04:09 2009
@@ -1,5 +1,5 @@
 /* Get loaded objects program headers.
-   Copyright (C) 2001-2004,2006,2007,2008 Free Software Foundation, Inc.
+   Copyright (C) 2001-2004, 2006-2008, 2009 Free Software Foundation, Inc.
    This file is part of the GNU C Library.
    Contributed by Jakub Jelinek <jakub@xxxxxxxxxx>, 2001.
 
@@ -47,7 +47,7 @@
   const void *caller = RETURN_ADDRESS (0);
   size_t nloaded = GL(dl_ns)[0]._ns_nloaded;
   Lmid_t ns = 0;
-  for (Lmid_t cnt = DL_NNS - 1; cnt > 0; --cnt)
+  for (Lmid_t cnt = GL(dl_nns) - 1; cnt > 0; --cnt)
     for (struct link_map *l = GL(dl_ns)[cnt]._ns_loaded; l; l = l->l_next)
       {
 	/* We have to count the total number of loaded objects.  */

Modified: fsf/trunk/libc/elf/dl-libc.c
==============================================================================
--- fsf/trunk/libc/elf/dl-libc.c (original)
+++ fsf/trunk/libc/elf/dl-libc.c Wed Apr  1 00:04:09 2009
@@ -1,5 +1,5 @@
 /* Handle loading and unloading shared objects for internal libc purposes.
-   Copyright (C) 1999-2002,2004,2005,2006 Free Software Foundation, Inc.
+   Copyright (C) 1999-2002,2004,2005,2006,2009 Free Software Foundation, Inc.
    This file is part of the GNU C Library.
    Contributed by Zack Weinberg <zack@xxxxxxxxxxxxxxxxx>, 1999.
 
@@ -236,7 +236,7 @@
     }
 
   /* Remove all additional names added to the objects.  */
-  for (Lmid_t ns = 0; ns < DL_NNS; ++ns)
+  for (Lmid_t ns = 0; ns < GL(dl_nns); ++ns)
     for (l = GL(dl_ns)[ns]._ns_loaded; l != NULL; l = l->l_next)
       {
 	struct libname_list *lnp = l->l_libname->next;

Modified: fsf/trunk/libc/elf/dl-load.c
==============================================================================
--- fsf/trunk/libc/elf/dl-load.c (original)
+++ fsf/trunk/libc/elf/dl-load.c Wed Apr  1 00:04:09 2009
@@ -84,14 +84,6 @@
 #endif
 
 #define STRING(x) __STRING (x)
-
-#ifdef MAP_ANON
-/* The fd is not examined when using MAP_ANON.  */
-# define ANONFD -1
-#else
-int _dl_zerofd = -1;
-# define ANONFD _dl_zerofd
-#endif
 
 /* Handle situations where we have a preferred location in memory for
    the shared objects.  */
@@ -1312,7 +1304,7 @@
 		caddr_t mapat;
 		mapat = __mmap ((caddr_t) zeropage, zeroend - zeropage,
 				c->prot, MAP_ANON|MAP_PRIVATE|MAP_FIXED,
-				ANONFD, 0);
+				-1, 0);
 		if (__builtin_expect (mapat == MAP_FAILED, 0))
 		  {
 		    errstring = N_("cannot map zero-fill pages");
@@ -1967,7 +1959,7 @@
   struct filebuf fb;
 
   assert (nsid >= 0);
-  assert (nsid < DL_NNS);
+  assert (nsid < GL(dl_nns));
 
   /* Look for this name among those already loaded.  */
   for (l = GL(dl_ns)[nsid]._ns_loaded; l; l = l->l_next)

Modified: fsf/trunk/libc/elf/dl-minimal.c
==============================================================================
--- fsf/trunk/libc/elf/dl-minimal.c (original)
+++ fsf/trunk/libc/elf/dl-minimal.c Wed Apr  1 00:04:09 2009
@@ -1,5 +1,5 @@
 /* Minimal replacements for basic facilities used in the dynamic linker.
-   Copyright (C) 1995-1998,2000-2002,2004-2006,2007
+   Copyright (C) 1995-1998,2000-2002,2004-2006,2007,2009
    Free Software Foundation, Inc.
    This file is part of the GNU C Library.
 
@@ -51,16 +51,6 @@
 void * weak_function
 __libc_memalign (size_t align, size_t n)
 {
-#ifdef MAP_ANON
-#define	_dl_zerofd (-1)
-#else
-  extern int _dl_zerofd;
-
-  if (_dl_zerofd == -1)
-    _dl_zerofd = _dl_sysdep_open_zero_fill ();
-#define MAP_ANON 0
-#endif
-
   if (alloc_end == 0)
     {
       /* Consume any unused space in the last page of our data segment.  */
@@ -87,7 +77,7 @@
 	  nup = GLRO(dl_pagesize);
 	}
       page = __mmap (0, nup, PROT_READ|PROT_WRITE,
-		     MAP_ANON|MAP_PRIVATE, _dl_zerofd, 0);
+		     MAP_ANON|MAP_PRIVATE, -1, 0);
       if (page == MAP_FAILED)
 	return NULL;
       if (page != alloc_end)

Modified: fsf/trunk/libc/elf/dl-misc.c
==============================================================================
--- fsf/trunk/libc/elf/dl-misc.c (original)
+++ fsf/trunk/libc/elf/dl-misc.c Wed Apr  1 00:04:09 2009
@@ -1,5 +1,5 @@
 /* Miscellaneous support functions for dynamic linker
-   Copyright (C) 1997-2002, 2003, 2004, 2006 Free Software Foundation, Inc.
+   Copyright (C) 1997-2004, 2006, 2009 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
@@ -33,17 +33,6 @@
 #include <sysdep.h>
 #include <stdio-common/_itoa.h>
 #include <bits/libc-lock.h>
-
-#ifndef MAP_ANON
-/* This is the only dl-sysdep.c function that is actually needed at run-time
-   by _dl_map_object.  */
-
-int
-_dl_sysdep_open_zero_fill (void)
-{
-  return __open ("/dev/zero", O_RDONLY);
-}
-#endif
 
 /* Read the whole contents of FILE into new mmap'd space with given
    protections.  *SIZEP gets the size of the file.  On error MAP_FAILED

Modified: fsf/trunk/libc/elf/dl-open.c
==============================================================================
--- fsf/trunk/libc/elf/dl-open.c (original)
+++ fsf/trunk/libc/elf/dl-open.c Wed Apr  1 00:04:09 2009
@@ -206,9 +206,6 @@
   struct dl_open_args *args = a;
   const char *file = args->file;
   int mode = args->mode;
-  struct link_map *new;
-  unsigned int i;
-  bool any_tls = false;
   struct link_map *call_map = NULL;
 
   /* Check whether _dl_open() has been called from a valid DSO.  */
@@ -231,7 +228,7 @@
       call_map = GL(dl_ns)[LM_ID_BASE]._ns_loaded;
 
       struct link_map *l;
-      for (Lmid_t ns = 0; ns < DL_NNS; ++ns)
+      for (Lmid_t ns = 0; ns < GL(dl_nns); ++ns)
 	for (l = GL(dl_ns)[ns]._ns_loaded; l != NULL; l = l->l_next)
 	  if (caller_dlopen >= (const void *) l->l_map_start
 	      && caller_dlopen < (const void *) l->l_map_end
@@ -262,15 +259,14 @@
   if (__builtin_expect (dst != NULL, 0))
     {
       size_t len = strlen (file);
-      size_t required;
-      char *new_file;
 
       /* Determine how much space we need.  We have to allocate the
 	 memory locally.  */
-      required = DL_DST_REQUIRED (call_map, file, len, _dl_dst_count (dst, 0));
+      size_t required = DL_DST_REQUIRED (call_map, file, len,
+					 _dl_dst_count (dst, 0));
 
       /* Get space for the new file name.  */
-      new_file = (char *) alloca (required + 1);
+      char *new_file = (char *) alloca (required + 1);
 
       /* Generate the new file name.  */
       _dl_dst_substitute (call_map, file, new_file, 0);
@@ -289,6 +285,7 @@
     }
 
   /* Load the named object.  */
+  struct link_map *new;
   args->map = new = _dl_map_object (call_map, file, 0, lt_loaded, 0,
 				    mode | __RTLD_CALLMAP, args->nsid);
 
@@ -330,7 +327,7 @@
 		       mode & (__RTLD_DLOPEN | RTLD_DEEPBIND | __RTLD_AUDIT));
 
   /* So far, so good.  Now check the versions.  */
-  for (i = 0; i < new->l_searchlist.r_nlist; ++i)
+  for (unsigned int i = 0; i < new->l_searchlist.r_nlist; ++i)
     if (new->l_searchlist.r_list[i]->l_real->l_versions == NULL)
       (void) _dl_check_map_versions (new->l_searchlist.r_list[i]->l_real,
 				     0, 0);
@@ -412,7 +409,8 @@
 
   /* If the file is not loaded now as a dependency, add the search
      list of the newly loaded object to the scope.  */
-  for (i = 0; i < new->l_searchlist.r_nlist; ++i)
+  bool any_tls = false;
+  for (unsigned int i = 0; i < new->l_searchlist.r_nlist; ++i)
     {
       struct link_map *imap = new->l_searchlist.r_list[i];
 
@@ -552,10 +550,10 @@
   /* Make sure we are alone.  */
   __rtld_lock_lock_recursive (GL(dl_load_lock));
 
-  if (nsid == LM_ID_NEWLM)
+  if (__builtin_expect (nsid == LM_ID_NEWLM, 0))
     {
       /* Find a new namespace.  */
-      for (nsid = 1; nsid < DL_NNS; ++nsid)
+      for (nsid = 1; nsid < GL(dl_nns); ++nsid)
 	if (GL(dl_ns)[nsid]._ns_loaded == NULL)
 	  break;
 
@@ -567,17 +565,25 @@
 	  _dl_signal_error (EINVAL, file, NULL, N_("\
 no more namespaces available for dlmopen()"));
 	}
+
+      if (nsid == GL(dl_nns))
+	++GL(dl_nns);
 
       _dl_debug_initialize (0, nsid)->r_state = RT_CONSISTENT;
     }
   /* Never allow loading a DSO in a namespace which is empty.  Such
      direct placements is only causing problems.  Also don't allow
      loading into a namespace used for auditing.  */
-  else if (nsid != LM_ID_BASE && nsid != __LM_ID_CALLER
+  else if (__builtin_expect (nsid != LM_ID_BASE && nsid != __LM_ID_CALLER, 0)
 	   && (GL(dl_ns)[nsid]._ns_nloaded == 0
 	       || GL(dl_ns)[nsid]._ns_loaded->l_auditing))
     _dl_signal_error (EINVAL, file, NULL,
 		      N_("invalid target namespace in dlmopen()"));
+#ifndef SHARED
+  else if (nsid == LM_ID_BASE && GL(dl_ns)[LM_ID_BASE]._ns_loaded == NULL
+	   && GL(dl_nns) == 0)
+    GL(dl_nns) = 1;
+#endif
 
   struct dl_open_args args;
   args.file = file;

Modified: fsf/trunk/libc/elf/dl-support.c
==============================================================================
--- fsf/trunk/libc/elf/dl-support.c (original)
+++ fsf/trunk/libc/elf/dl-support.c Wed Apr  1 00:04:09 2009
@@ -70,6 +70,7 @@
 
 /* Namespace information.  */
 struct link_namespaces _dl_ns[DL_NNS];
+size_t _dl_nns;
 
 /* Incremented whenever something may have been added to dl_loaded. */
 unsigned long long _dl_load_adds;

Modified: fsf/trunk/libc/elf/dl-sym.c
==============================================================================
--- fsf/trunk/libc/elf/dl-sym.c (original)
+++ fsf/trunk/libc/elf/dl-sym.c Wed Apr  1 00:04:09 2009
@@ -1,5 +1,5 @@
 /* Look up a symbol in a shared object loaded by `dlopen'.
-   Copyright (C) 1999-2002,2004,2006,2007 Free Software Foundation, Inc.
+   Copyright (C) 1999-2002,2004,2006,2007,2009 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
@@ -95,7 +95,7 @@
   struct link_map *match = GL(dl_ns)[LM_ID_BASE]._ns_loaded;
 
   /* Find the highest-addressed object that CALLER is not below.  */
-  for (Lmid_t ns = 0; ns < DL_NNS; ++ns)
+  for (Lmid_t ns = 0; ns < GL(dl_nns); ++ns)
     for (struct link_map *l = GL(dl_ns)[ns]._ns_loaded; l != NULL;
 	 l = l->l_next)
       if (caller >= l->l_map_start && caller < l->l_map_end

Modified: fsf/trunk/libc/elf/rtld.c
==============================================================================
--- fsf/trunk/libc/elf/rtld.c (original)
+++ fsf/trunk/libc/elf/rtld.c Wed Apr  1 00:04:09 2009
@@ -24,7 +24,7 @@
 #include <stdlib.h>
 #include <string.h>
 #include <unistd.h>
-#include <sys/mman.h>		/* Check if MAP_ANON is defined.  */
+#include <sys/mman.h>
 #include <sys/param.h>
 #include <sys/stat.h>
 #include <ldsodefs.h>
@@ -125,8 +125,9 @@
     /* Default presumption without further information is executable stack.  */
     ._dl_stack_flags = PF_R|PF_W|PF_X,
 #ifdef _LIBC_REENTRANT
-    ._dl_load_lock = _RTLD_LOCK_RECURSIVE_INITIALIZER
-#endif
+    ._dl_load_lock = _RTLD_LOCK_RECURSIVE_INITIALIZER,
+#endif
+    ._dl_nns = 1
   };
 /* If we would use strong_alias here the compiler would see a
    non-hidden definition.  This would undo the effect of the previous
@@ -1782,12 +1783,6 @@
   for (i = main_map->l_searchlist.r_nlist; i > 0; )
     main_map->l_searchlist.r_list[--i]->l_global = 1;
 
-#ifndef MAP_ANON
-  /* We are done mapping things, so close the zero-fill descriptor.  */
-  __close (_dl_zerofd);
-  _dl_zerofd = -1;
-#endif
-
   /* Remove _dl_rtld_map from the chain.  */
   GL(dl_rtld_map).l_prev->l_next = GL(dl_rtld_map).l_next;
   if (GL(dl_rtld_map).l_next != NULL)
@@ -2759,7 +2754,7 @@
 #endif
 
   unsigned long int num_relative_relocations = 0;
-  for (Lmid_t ns = 0; ns < DL_NNS; ++ns)
+  for (Lmid_t ns = 0; ns < GL(dl_nns); ++ns)
     {
       if (GL(dl_ns)[ns]._ns_loaded == NULL)
 	continue;

Modified: fsf/trunk/libc/sysdeps/generic/ldsodefs.h
==============================================================================
--- fsf/trunk/libc/sysdeps/generic/ldsodefs.h (original)
+++ fsf/trunk/libc/sysdeps/generic/ldsodefs.h Wed Apr  1 00:04:09 2009
@@ -386,6 +386,8 @@
     /* Keep track of changes to each namespace' list.  */
     struct r_debug _ns_debug;
   } _dl_ns[DL_NNS];
+  /* One higher than index of last used namespace.  */
+  EXTERN size_t _dl_nns;
 
   /* During the program run we must not modify the global data of
      loaded shared object simultanously in two threads.  Therefore we
@@ -398,11 +400,6 @@
 
   /* Incremented whenever something may have been added to dl_loaded.  */
   EXTERN unsigned long long _dl_load_adds;
-
-#ifndef MAP_ANON
-  /* File descriptor referring to the zero-fill device.  */
-  EXTERN int _dl_zerofd;
-#endif
 
   /* The object to be initialized first.  */
   EXTERN struct link_map *_dl_initfirst;