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.
2009-03-31 Ulrich Drepper <drepper@redhat.com>
+ * 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.
/* 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
__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)))
/* 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
#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
/* 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
}
#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 ();
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
/* 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
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));
/* 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@redhat.com>, 2001.
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. */
/* 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@rabi.columbia.edu>, 1999.
}
/* 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;
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)
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. */
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
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);
}
/* 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);
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);
/* 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];
/* 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;
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;
/* 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;
/* 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
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
/* 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
+ ._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
#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;
/* 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