Line
Link Here
|
0 |
-- a/elf/dl-deps.c |
0 |
++ b/elf/dl-deps.c |
Lines 617-677
Filters not supported with LD_TRACE_PRELINKING"));
Link Here
|
617 |
map->l_searchlist.r_list[i]->l_reserved = 0; |
617 |
map->l_searchlist.r_list[i]->l_reserved = 0; |
618 |
} |
618 |
} |
619 |
|
619 |
|
620 |
/* Now determine the order in which the initialization has to happen. */ |
620 |
/* Sort the initializer list to take dependencies into account. The binary |
|
|
621 |
itself will always be initialize last. */ |
621 |
memcpy (l_initfini, map->l_searchlist.r_list, |
622 |
memcpy (l_initfini, map->l_searchlist.r_list, |
622 |
nlist * sizeof (struct link_map *)); |
623 |
nlist * sizeof (struct link_map *)); |
623 |
|
624 |
if (__builtin_expect (nlist > 1, 1)) |
624 |
/* We can skip looking for the binary itself which is at the front |
|
|
625 |
of the search list. */ |
626 |
assert (nlist > 1); |
627 |
i = 1; |
628 |
bool seen[nlist]; |
629 |
memset (seen, false, nlist * sizeof (seen[0])); |
630 |
while (1) |
631 |
{ |
625 |
{ |
632 |
/* Keep track of which object we looked at this round. */ |
626 |
/* We can skip looking for the binary itself which is at the front |
633 |
seen[i] = true; |
627 |
of the search list. */ |
634 |
struct link_map *thisp = l_initfini[i]; |
628 |
i = 1; |
635 |
|
629 |
bool seen[nlist]; |
636 |
/* Find the last object in the list for which the current one is |
630 |
memset (seen, false, nlist * sizeof (seen[0])); |
637 |
a dependency and move the current object behind the object |
631 |
while (1) |
638 |
with the dependency. */ |
|
|
639 |
unsigned int k = nlist - 1; |
640 |
while (k > i) |
641 |
{ |
632 |
{ |
642 |
struct link_map **runp = l_initfini[k]->l_initfini; |
633 |
/* Keep track of which object we looked at this round. */ |
643 |
if (runp != NULL) |
634 |
seen[i] = true; |
644 |
/* Look through the dependencies of the object. */ |
635 |
struct link_map *thisp = l_initfini[i]; |
645 |
while (*runp != NULL) |
636 |
|
646 |
if (__builtin_expect (*runp++ == thisp, 0)) |
637 |
/* Find the last object in the list for which the current one is |
647 |
{ |
638 |
a dependency and move the current object behind the object |
648 |
/* Move the current object to the back past the last |
639 |
with the dependency. */ |
649 |
object with it as the dependency. */ |
640 |
unsigned int k = nlist - 1; |
650 |
memmove (&l_initfini[i], &l_initfini[i + 1], |
641 |
while (k > i) |
651 |
(k - i) * sizeof (l_initfini[0])); |
642 |
{ |
652 |
l_initfini[k] = thisp; |
643 |
struct link_map **runp = l_initfini[k]->l_initfini; |
653 |
|
644 |
if (runp != NULL) |
654 |
if (seen[i + 1]) |
645 |
/* Look through the dependencies of the object. */ |
|
|
646 |
while (*runp != NULL) |
647 |
if (__builtin_expect (*runp++ == thisp, 0)) |
655 |
{ |
648 |
{ |
656 |
++i; |
649 |
/* Move the current object to the back past the last |
657 |
goto next_clear; |
650 |
object with it as the dependency. */ |
|
|
651 |
memmove (&l_initfini[i], &l_initfini[i + 1], |
652 |
(k - i) * sizeof (l_initfini[0])); |
653 |
l_initfini[k] = thisp; |
654 |
|
655 |
if (seen[i + 1]) |
656 |
{ |
657 |
++i; |
658 |
goto next_clear; |
659 |
} |
660 |
|
661 |
memmove (&seen[i], &seen[i + 1], |
662 |
(k - i) * sizeof (seen[0])); |
663 |
seen[k] = true; |
664 |
|
665 |
goto next; |
658 |
} |
666 |
} |
659 |
|
667 |
|
660 |
memmove (&seen[i], &seen[i + 1], (k - i) * sizeof (seen[0])); |
668 |
--k; |
661 |
seen[k] = true; |
669 |
} |
662 |
|
670 |
|
663 |
goto next; |
671 |
if (++i == nlist) |
664 |
} |
672 |
break; |
|
|
673 |
next_clear: |
674 |
memset (&seen[i], false, (nlist - i) * sizeof (seen[0])); |
665 |
|
675 |
|
666 |
--k; |
676 |
next:; |
667 |
} |
677 |
} |
668 |
|
|
|
669 |
if (++i == nlist) |
670 |
break; |
671 |
next_clear: |
672 |
memset (&seen[i], false, (nlist - i) * sizeof (seen[0])); |
673 |
|
674 |
next:; |
675 |
} |
678 |
} |
676 |
|
679 |
|
677 |
/* Terminate the list of dependencies. */ |
680 |
/* Terminate the list of dependencies. */ |
678 |
-- a/elf/dl-fini.c |
681 |
++ b/elf/dl-fini.c |
Lines 33-41
internal_function
Link Here
|
33 |
_dl_sort_fini (struct link_map *l, struct link_map **maps, size_t nmaps, |
33 |
_dl_sort_fini (struct link_map *l, struct link_map **maps, size_t nmaps, |
34 |
char *used, Lmid_t ns) |
34 |
char *used, Lmid_t ns) |
35 |
{ |
35 |
{ |
|
|
36 |
/* A list of one element need not be sorted. */ |
37 |
if (nmaps == 1) |
38 |
return; |
39 |
|
36 |
/* We can skip looking for the binary itself which is at the front |
40 |
/* We can skip looking for the binary itself which is at the front |
37 |
of the search list for the main namespace. */ |
41 |
of the search list for the main namespace. */ |
38 |
assert (nmaps > 1); |
|
|
39 |
unsigned int i = ns == LM_ID_BASE; |
42 |
unsigned int i = ns == LM_ID_BASE; |
40 |
bool seen[nmaps]; |
43 |
bool seen[nmaps]; |
41 |
memset (seen, false, nmaps * sizeof (seen[0])); |
44 |
memset (seen, false, nmaps * sizeof (seen[0])); |
Lines 195-203
_dl_fini (void)
Link Here
|
195 |
assert (ns == LM_ID_BASE || i == nloaded || i == nloaded - 1); |
198 |
assert (ns == LM_ID_BASE || i == nloaded || i == nloaded - 1); |
196 |
nmaps = i; |
199 |
nmaps = i; |
197 |
|
200 |
|
198 |
if (nmaps > 1) |
201 |
/* Now we have to do the sorting. */ |
199 |
/* Now we have to do the sorting. */ |
202 |
_dl_sort_fini (GL(dl_ns)[ns]._ns_loaded, maps, nmaps, NULL, ns); |
200 |
_dl_sort_fini (GL(dl_ns)[ns]._ns_loaded, maps, nmaps, NULL, ns); |
|
|
201 |
|
203 |
|
202 |
/* We do not rely on the linked list of loaded object anymore from |
204 |
/* We do not rely on the linked list of loaded object anymore from |
203 |
this point on. We have our own list here (maps). The various |
205 |
this point on. We have our own list here (maps). The various |