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