|
|
b40826 |
diff -rup a/elf/dl-close.c b/elf/dl-close.c
|
|
|
b40826 |
--- a/elf/dl-close.c 2012-01-19 12:59:42.759484350 -0700
|
|
|
b40826 |
+++ b/elf/dl-close.c 2012-01-19 14:10:20.439263806 -0700
|
|
|
b40826 |
@@ -223,7 +223,7 @@ _dl_close_worker (struct link_map *map)
|
|
|
b40826 |
}
|
|
|
b40826 |
|
|
|
b40826 |
/* Sort the entries. */
|
|
|
b40826 |
- _dl_sort_fini (ns->_ns_loaded, maps, nloaded, used, nsid);
|
|
|
b40826 |
+ _dl_sort_fini (maps, nloaded, used, nsid);
|
|
|
b40826 |
|
|
|
b40826 |
/* Call all termination functions at once. */
|
|
|
b40826 |
#ifdef SHARED
|
|
|
b40826 |
diff -rup a/elf/dl-deps.c b/elf/dl-deps.c
|
|
|
b40826 |
--- a/elf/dl-deps.c 2012-01-19 12:59:42.716484301 -0700
|
|
|
b40826 |
+++ b/elf/dl-deps.c 2012-01-19 13:52:35.223720556 -0700
|
|
|
b40826 |
@@ -614,51 +614,67 @@ Filters not supported with LD_TRACE_PREL
|
|
|
b40826 |
map->l_searchlist.r_list[i]->l_reserved = 0;
|
|
|
b40826 |
}
|
|
|
b40826 |
|
|
|
b40826 |
- /* Now determine the order in which the initialization has to happen. */
|
|
|
b40826 |
+ /* Sort the initializer list to take dependencies into account. The binary
|
|
|
b40826 |
+ itself will always be initialize last. */
|
|
|
b40826 |
memcpy (l_initfini, map->l_searchlist.r_list,
|
|
|
b40826 |
nlist * sizeof (struct link_map *));
|
|
|
b40826 |
- /* We can skip looking for the binary itself which is at the front
|
|
|
b40826 |
- of the search list. Look through the list backward so that circular
|
|
|
b40826 |
- dependencies are not changing the order. */
|
|
|
b40826 |
- for (i = 1; i < nlist; ++i)
|
|
|
b40826 |
+ if (__builtin_expect (nlist > 1, 1))
|
|
|
b40826 |
{
|
|
|
b40826 |
- struct link_map *l = map->l_searchlist.r_list[i];
|
|
|
b40826 |
- unsigned int j;
|
|
|
b40826 |
- unsigned int k;
|
|
|
b40826 |
-
|
|
|
b40826 |
- /* Find the place in the initfini list where the map is currently
|
|
|
b40826 |
- located. */
|
|
|
b40826 |
- for (j = 1; l_initfini[j] != l; ++j)
|
|
|
b40826 |
- ;
|
|
|
b40826 |
-
|
|
|
b40826 |
- /* Find all object for which the current one is a dependency and
|
|
|
b40826 |
- move the found object (if necessary) in front. */
|
|
|
b40826 |
- for (k = j + 1; k < nlist; ++k)
|
|
|
b40826 |
+ /* We can skip looking for the binary itself which is at the front
|
|
|
b40826 |
+ of the search list. */
|
|
|
b40826 |
+ i = 1;
|
|
|
b40826 |
+ unsigned int seen[nlist];
|
|
|
b40826 |
+ memset (seen, 0, nlist * sizeof (seen[0]));
|
|
|
b40826 |
+ while (1)
|
|
|
b40826 |
{
|
|
|
b40826 |
- struct link_map **runp;
|
|
|
b40826 |
-
|
|
|
b40826 |
- runp = l_initfini[k]->l_initfini;
|
|
|
b40826 |
- if (runp != NULL)
|
|
|
b40826 |
+ /* Keep track of which object we looked at this round. */
|
|
|
b40826 |
+ ++seen[i];
|
|
|
b40826 |
+ struct link_map *thisp = l_initfini[i];
|
|
|
b40826 |
+
|
|
|
b40826 |
+ /* Find the last object in the list for which the current one is
|
|
|
b40826 |
+ a dependency and move the current object behind the object
|
|
|
b40826 |
+ with the dependency. */
|
|
|
b40826 |
+ unsigned int k = nlist - 1;
|
|
|
b40826 |
+ while (k > i)
|
|
|
b40826 |
{
|
|
|
b40826 |
- while (*runp != NULL)
|
|
|
b40826 |
- if (__builtin_expect (*runp++ == l, 0))
|
|
|
b40826 |
- {
|
|
|
b40826 |
- struct link_map *here = l_initfini[k];
|
|
|
b40826 |
-
|
|
|
b40826 |
- /* Move it now. */
|
|
|
b40826 |
- memmove (&l_initfini[j] + 1, &l_initfini[j],
|
|
|
b40826 |
- (k - j) * sizeof (struct link_map *));
|
|
|
b40826 |
- l_initfini[j] = here;
|
|
|
b40826 |
-
|
|
|
b40826 |
- /* Don't insert further matches before the last
|
|
|
b40826 |
- entry moved to the front. */
|
|
|
b40826 |
- ++j;
|
|
|
b40826 |
+ struct link_map **runp = l_initfini[k]->l_initfini;
|
|
|
b40826 |
+ if (runp != NULL)
|
|
|
b40826 |
+ /* Look through the dependencies of the object. */
|
|
|
b40826 |
+ while (*runp != NULL)
|
|
|
b40826 |
+ if (__builtin_expect (*runp++ == thisp, 0))
|
|
|
b40826 |
+ {
|
|
|
b40826 |
+ /* Move the current object to the back past the last
|
|
|
b40826 |
+ object with it as the dependency. */
|
|
|
b40826 |
+ memmove (&l_initfini[i], &l_initfini[i + 1],
|
|
|
b40826 |
+ (k - i) * sizeof (l_initfini[0]));
|
|
|
b40826 |
+ l_initfini[k] = thisp;
|
|
|
b40826 |
+
|
|
|
b40826 |
+ if (seen[i + 1] > nlist - i - 2)
|
|
|
b40826 |
+ {
|
|
|
b40826 |
+ ++i;
|
|
|
b40826 |
+ goto next_clear;
|
|
|
b40826 |
+ }
|
|
|
b40826 |
+
|
|
|
b40826 |
+ unsigned int this_seen = seen[i];
|
|
|
b40826 |
+ memmove (&seen[i], &seen[i + 1],
|
|
|
b40826 |
+ (k - i) * sizeof (seen[0]));
|
|
|
b40826 |
+ seen[k] = this_seen;
|
|
|
b40826 |
+
|
|
|
b40826 |
+ goto next;
|
|
|
b40826 |
+ }
|
|
|
b40826 |
|
|
|
b40826 |
- break;
|
|
|
b40826 |
- }
|
|
|
b40826 |
+ --k;
|
|
|
b40826 |
}
|
|
|
b40826 |
+
|
|
|
b40826 |
+ if (++i == nlist)
|
|
|
b40826 |
+ break;
|
|
|
b40826 |
+ next_clear:
|
|
|
b40826 |
+ memset (&seen[i], 0, (nlist - i) * sizeof (seen[0]));
|
|
|
b40826 |
+
|
|
|
b40826 |
+ next:;
|
|
|
b40826 |
}
|
|
|
b40826 |
}
|
|
|
b40826 |
+
|
|
|
b40826 |
/* Terminate the list of dependencies. */
|
|
|
b40826 |
l_initfini[nlist] = NULL;
|
|
|
b40826 |
atomic_write_barrier ();
|
|
|
b40826 |
diff -rup a/elf/dl-fini.c b/elf/dl-fini.c
|
|
|
b40826 |
--- a/elf/dl-fini.c 2010-05-04 05:27:23.000000000 -0600
|
|
|
b40826 |
+++ b/elf/dl-fini.c 2012-01-19 13:56:38.653842046 -0700
|
|
|
b40826 |
@@ -1,5 +1,6 @@
|
|
|
b40826 |
/* Call the termination functions of loaded shared objects.
|
|
|
b40826 |
- Copyright (C) 1995,96,1998-2002,2004-2005,2009 Free Software Foundation, Inc.
|
|
|
b40826 |
+ Copyright (C) 1995,96,1998-2002,2004-2005,2009,2011
|
|
|
b40826 |
+ Free Software Foundation, Inc.
|
|
|
b40826 |
This file is part of the GNU C Library.
|
|
|
b40826 |
|
|
|
b40826 |
The GNU C Library is free software; you can redistribute it and/or
|
|
|
b40826 |
@@ -29,89 +30,100 @@ typedef void (*fini_t) (void);
|
|
|
b40826 |
|
|
|
b40826 |
void
|
|
|
b40826 |
internal_function
|
|
|
b40826 |
-_dl_sort_fini (struct link_map *l, struct link_map **maps, size_t nmaps,
|
|
|
b40826 |
- char *used, Lmid_t ns)
|
|
|
b40826 |
+_dl_sort_fini (struct link_map **maps, size_t nmaps, char *used, Lmid_t ns)
|
|
|
b40826 |
{
|
|
|
b40826 |
- if (ns == LM_ID_BASE)
|
|
|
b40826 |
- /* The main executable always comes first. */
|
|
|
b40826 |
- l = l->l_next;
|
|
|
b40826 |
-
|
|
|
b40826 |
- for (; l != NULL; l = l->l_next)
|
|
|
b40826 |
- /* Do not handle ld.so in secondary namespaces and object which
|
|
|
b40826 |
- are not removed. */
|
|
|
b40826 |
- if (l == l->l_real && l->l_idx != -1)
|
|
|
b40826 |
- {
|
|
|
b40826 |
- /* Find the place in the 'maps' array. */
|
|
|
b40826 |
- unsigned int j;
|
|
|
b40826 |
- for (j = ns == LM_ID_BASE ? 1 : 0; maps[j] != l; ++j)
|
|
|
b40826 |
- assert (j < nmaps);
|
|
|
b40826 |
-
|
|
|
b40826 |
- /* Find all object for which the current one is a dependency
|
|
|
b40826 |
- and move the found object (if necessary) in front. */
|
|
|
b40826 |
- for (unsigned int k = j + 1; k < nmaps; ++k)
|
|
|
b40826 |
- {
|
|
|
b40826 |
- struct link_map **runp = maps[k]->l_initfini;
|
|
|
b40826 |
- if (runp != NULL)
|
|
|
b40826 |
- {
|
|
|
b40826 |
- while (*runp != NULL)
|
|
|
b40826 |
- if (*runp == l)
|
|
|
b40826 |
- {
|
|
|
b40826 |
- struct link_map *here = maps[k];
|
|
|
b40826 |
+ /* A list of one element need not be sorted. */
|
|
|
b40826 |
+ if (nmaps == 1)
|
|
|
b40826 |
+ return;
|
|
|
b40826 |
+
|
|
|
b40826 |
+ /* We can skip looking for the binary itself which is at the front
|
|
|
b40826 |
+ of the search list for the main namespace. */
|
|
|
b40826 |
+ unsigned int i = ns == LM_ID_BASE;
|
|
|
b40826 |
+ unsigned int seen[nmaps];
|
|
|
b40826 |
+ memset (seen, 0, nmaps * sizeof (seen[0]));
|
|
|
b40826 |
+ while (1)
|
|
|
b40826 |
+ {
|
|
|
b40826 |
+ /* Keep track of which object we looked at this round. */
|
|
|
b40826 |
+ ++seen[i];
|
|
|
b40826 |
+ struct link_map *thisp = maps[i];
|
|
|
b40826 |
+
|
|
|
b40826 |
+ /* Do not handle ld.so in secondary namespaces and object which
|
|
|
b40826 |
+ are not removed. */
|
|
|
b40826 |
+ if (thisp != thisp->l_real || thisp->l_idx == -1)
|
|
|
b40826 |
+ goto skip;
|
|
|
b40826 |
+
|
|
|
b40826 |
+ /* Find the last object in the list for which the current one is
|
|
|
b40826 |
+ a dependency and move the current object behind the object
|
|
|
b40826 |
+ with the dependency. */
|
|
|
b40826 |
+ unsigned int k = nmaps - 1;
|
|
|
b40826 |
+ while (k > i)
|
|
|
b40826 |
+ {
|
|
|
b40826 |
+ struct link_map **runp = maps[k]->l_initfini;
|
|
|
b40826 |
+ if (runp != NULL)
|
|
|
b40826 |
+ /* Look through the dependencies of the object. */
|
|
|
b40826 |
+ while (*runp != NULL)
|
|
|
b40826 |
+ if (__builtin_expect (*runp++ == thisp, 0))
|
|
|
b40826 |
+ {
|
|
|
b40826 |
+ move:
|
|
|
b40826 |
+ /* Move the current object to the back past the last
|
|
|
b40826 |
+ object with it as the dependency. */
|
|
|
b40826 |
+ memmove (&maps[i], &maps[i + 1],
|
|
|
b40826 |
+ (k - i) * sizeof (maps[0]));
|
|
|
b40826 |
+ maps[k] = thisp;
|
|
|
b40826 |
|
|
|
b40826 |
- /* Move it now. */
|
|
|
b40826 |
- memmove (&maps[j] + 1,
|
|
|
b40826 |
- &maps[j], (k - j) * sizeof (struct link_map *));
|
|
|
b40826 |
- maps[j] = here;
|
|
|
b40826 |
+ if (used != NULL)
|
|
|
b40826 |
+ {
|
|
|
b40826 |
+ char here_used = used[i];
|
|
|
b40826 |
+ memmove (&used[i], &used[i + 1],
|
|
|
b40826 |
+ (k - i) * sizeof (used[0]));
|
|
|
b40826 |
+ used[k] = here_used;
|
|
|
b40826 |
+ }
|
|
|
b40826 |
|
|
|
b40826 |
- if (used != NULL)
|
|
|
b40826 |
- {
|
|
|
b40826 |
- char here_used = used[k];
|
|
|
b40826 |
+ if (seen[i + 1] > nmaps - i - 2)
|
|
|
b40826 |
+ {
|
|
|
b40826 |
+ ++i;
|
|
|
b40826 |
+ goto next_clear;
|
|
|
b40826 |
+ }
|
|
|
b40826 |
|
|
|
b40826 |
- memmove (&used[j] + 1,
|
|
|
b40826 |
- &used[j], (k - j) * sizeof (char));
|
|
|
b40826 |
- used[j] = here_used;
|
|
|
b40826 |
- }
|
|
|
b40826 |
+ unsigned int this_seen = seen[i];
|
|
|
b40826 |
+ memmove (&seen[i], &seen[i + 1], (k - i) * sizeof (seen[0]));
|
|
|
b40826 |
+ seen[k] = this_seen;
|
|
|
b40826 |
|
|
|
b40826 |
- ++j;
|
|
|
b40826 |
+ goto next;
|
|
|
b40826 |
+ }
|
|
|
b40826 |
|
|
|
b40826 |
- break;
|
|
|
b40826 |
- }
|
|
|
b40826 |
- else
|
|
|
b40826 |
- ++runp;
|
|
|
b40826 |
- }
|
|
|
b40826 |
-
|
|
|
b40826 |
- if (__builtin_expect (maps[k]->l_reldeps != NULL, 0))
|
|
|
b40826 |
- {
|
|
|
b40826 |
- unsigned int m = maps[k]->l_reldeps->act;
|
|
|
b40826 |
- struct link_map **relmaps = &maps[k]->l_reldeps->list[0];
|
|
|
b40826 |
+ if (__builtin_expect (maps[k]->l_reldeps != NULL, 0))
|
|
|
b40826 |
+ {
|
|
|
b40826 |
+ unsigned int m = maps[k]->l_reldeps->act;
|
|
|
b40826 |
+ struct link_map **relmaps = &maps[k]->l_reldeps->list[0];
|
|
|
b40826 |
|
|
|
b40826 |
- while (m-- > 0)
|
|
|
b40826 |
+ /* Look through the relocation dependencies of the object. */
|
|
|
b40826 |
+ while (m-- > 0)
|
|
|
b40826 |
+ if (__builtin_expect (relmaps[m] == thisp, 0))
|
|
|
b40826 |
{
|
|
|
b40826 |
- if (relmaps[m] == l)
|
|
|
b40826 |
- {
|
|
|
b40826 |
- struct link_map *here = maps[k];
|
|
|
b40826 |
-
|
|
|
b40826 |
- /* Move it now. */
|
|
|
b40826 |
- memmove (&maps[j] + 1,
|
|
|
b40826 |
- &maps[j],
|
|
|
b40826 |
- (k - j) * sizeof (struct link_map *));
|
|
|
b40826 |
- maps[j] = here;
|
|
|
b40826 |
-
|
|
|
b40826 |
- if (used != NULL)
|
|
|
b40826 |
- {
|
|
|
b40826 |
- char here_used = used[k];
|
|
|
b40826 |
-
|
|
|
b40826 |
- memmove (&used[j] + 1,
|
|
|
b40826 |
- &used[j], (k - j) * sizeof (char));
|
|
|
b40826 |
- used[j] = here_used;
|
|
|
b40826 |
- }
|
|
|
b40826 |
-
|
|
|
b40826 |
- break;
|
|
|
b40826 |
- }
|
|
|
b40826 |
+ /* If a cycle exists with a link time dependency,
|
|
|
b40826 |
+ preserve the latter. */
|
|
|
b40826 |
+ struct link_map **runp = thisp->l_initfini;
|
|
|
b40826 |
+ if (runp != NULL)
|
|
|
b40826 |
+ while (*runp != NULL)
|
|
|
b40826 |
+ if (__builtin_expect (*runp++ == maps[k], 0))
|
|
|
b40826 |
+ goto ignore;
|
|
|
b40826 |
+ goto move;
|
|
|
b40826 |
}
|
|
|
b40826 |
- }
|
|
|
b40826 |
- }
|
|
|
b40826 |
- }
|
|
|
b40826 |
+ ignore:;
|
|
|
b40826 |
+ }
|
|
|
b40826 |
+
|
|
|
b40826 |
+ --k;
|
|
|
b40826 |
+ }
|
|
|
b40826 |
+
|
|
|
b40826 |
+ skip:
|
|
|
b40826 |
+ if (++i == nmaps)
|
|
|
b40826 |
+ break;
|
|
|
b40826 |
+ next_clear:
|
|
|
b40826 |
+ memset (&seen[i], 0, (nmaps - i) * sizeof (seen[0]));
|
|
|
b40826 |
+
|
|
|
b40826 |
+ next:;
|
|
|
b40826 |
+ }
|
|
|
b40826 |
}
|
|
|
b40826 |
|
|
|
b40826 |
|
|
|
b40826 |
@@ -196,9 +208,8 @@ _dl_fini (void)
|
|
|
b40826 |
assert (ns == LM_ID_BASE || i == nloaded || i == nloaded - 1);
|
|
|
b40826 |
nmaps = i;
|
|
|
b40826 |
|
|
|
b40826 |
- if (nmaps != 0)
|
|
|
b40826 |
- /* Now we have to do the sorting. */
|
|
|
b40826 |
- _dl_sort_fini (GL(dl_ns)[ns]._ns_loaded, maps, nmaps, NULL, ns);
|
|
|
b40826 |
+ /* Now we have to do the sorting. */
|
|
|
b40826 |
+ _dl_sort_fini (maps, nmaps, NULL, ns);
|
|
|
b40826 |
|
|
|
b40826 |
/* We do not rely on the linked list of loaded object anymore from
|
|
|
b40826 |
this point on. We have our own list here (maps). The various
|
|
|
b40826 |
diff -rup a/sysdeps/generic/ldsodefs.h b/sysdeps/generic/ldsodefs.h
|
|
|
b40826 |
--- a/sysdeps/generic/ldsodefs.h 2012-01-19 12:59:42.446483997 -0700
|
|
|
b40826 |
+++ b/sysdeps/generic/ldsodefs.h 2012-01-19 14:16:36.242453532 -0700
|
|
|
b40826 |
@@ -947,7 +947,7 @@ extern void _dl_init (struct link_map *m
|
|
|
b40826 |
extern void _dl_fini (void) internal_function;
|
|
|
b40826 |
|
|
|
b40826 |
/* Sort array MAPS according to dependencies of the contained objects. */
|
|
|
b40826 |
-extern void _dl_sort_fini (struct link_map *l, struct link_map **maps,
|
|
|
b40826 |
+extern void _dl_sort_fini (struct link_map **maps,
|
|
|
b40826 |
size_t nmaps, char *used, Lmid_t ns)
|
|
|
b40826 |
internal_function;
|
|
|
b40826 |
|