aboutsummaryrefslogtreecommitdiff
path: root/elf/dl-open.c
diff options
context:
space:
mode:
authorAndreas Schwab <schwab@suse.de>2017-11-07 15:24:19 +0100
committerAndreas Schwab <schwab@suse.de>2017-11-27 11:37:19 +0100
commitc2c299fd24e87b83c63191ff979d41a86b37d714 (patch)
tree47b1dcdd9bd9348b5a15f93b376a8e7d275a324b /elf/dl-open.c
parentde61465c04d36dadce2f4e7f78ebbe50bae6a21e (diff)
downloadglibc-c2c299fd24e87b83c63191ff979d41a86b37d714.tar
glibc-c2c299fd24e87b83c63191ff979d41a86b37d714.tar.gz
glibc-c2c299fd24e87b83c63191ff979d41a86b37d714.tar.bz2
glibc-c2c299fd24e87b83c63191ff979d41a86b37d714.zip
Consolidate link map sorting
Combine the four places where link maps are sorted into a single function. This also moves the logic to skip the first map (representing the main binary) to the callers.
Diffstat (limited to 'elf/dl-open.c')
-rw-r--r--elf/dl-open.c57
1 files changed, 3 insertions, 54 deletions
diff --git a/elf/dl-open.c b/elf/dl-open.c
index c539f10cf3..68907bf532 100644
--- a/elf/dl-open.c
+++ b/elf/dl-open.c
@@ -311,7 +311,7 @@ dl_open_worker (void *a)
/* Sort the objects by dependency for the relocation process. This
allows IFUNC relocations to work and it also means copy
relocation of dependencies are if necessary overwritten. */
- size_t nmaps = 0;
+ unsigned int nmaps = 0;
struct link_map *l = new;
do
{
@@ -330,62 +330,11 @@ dl_open_worker (void *a)
l = l->l_next;
}
while (l != NULL);
- if (nmaps > 1)
- {
- uint16_t seen[nmaps];
- memset (seen, '\0', sizeof (seen));
- size_t i = 0;
- while (1)
- {
- ++seen[i];
- struct link_map *thisp = maps[i];
-
- /* Find the last object in the list for which the current one is
- a dependency and move the current object behind the object
- with the dependency. */
- size_t k = nmaps - 1;
- while (k > i)
- {
- struct link_map **runp = maps[k]->l_initfini;
- if (runp != NULL)
- /* Look through the dependencies of the object. */
- while (*runp != NULL)
- if (__glibc_unlikely (*runp++ == thisp))
- {
- /* Move the current object to the back past the last
- object with it as the dependency. */
- memmove (&maps[i], &maps[i + 1],
- (k - i) * sizeof (maps[0]));
- maps[k] = thisp;
-
- if (seen[i + 1] > nmaps - i)
- {
- ++i;
- goto next_clear;
- }
-
- uint16_t this_seen = seen[i];
- memmove (&seen[i], &seen[i + 1],
- (k - i) * sizeof (seen[0]));
- seen[k] = this_seen;
-
- goto next;
- }
-
- --k;
- }
-
- if (++i == nmaps)
- break;
- next_clear:
- memset (&seen[i], 0, (nmaps - i) * sizeof (seen[0]));
- next:;
- }
- }
+ _dl_sort_maps (maps, nmaps, NULL, false);
int relocation_in_progress = 0;
- for (size_t i = nmaps; i-- > 0; )
+ for (unsigned int i = nmaps; i-- > 0; )
{
l = maps[i];