83f30e
commit dbb75513f5cf9285c77c9e55777c5c35b653f890
83f30e
Author: Florian Weimer <fweimer@redhat.com>
83f30e
Date:   Tue Sep 6 07:38:10 2022 +0200
83f30e
83f30e
    elf: Rename _dl_sort_maps parameter from skip to force_first
83f30e
    
83f30e
    The new implementation will not be able to skip an arbitrary number
83f30e
    of objects.
83f30e
    
83f30e
    Reviewed-by: Adhemerval Zanella  <adhemerval.zanella@linaro.org>
83f30e
83f30e
diff --git a/elf/dl-sort-maps.c b/elf/dl-sort-maps.c
83f30e
index 99354dc08a010dd3..7a586749adc3fa7d 100644
83f30e
--- a/elf/dl-sort-maps.c
83f30e
+++ b/elf/dl-sort-maps.c
83f30e
@@ -27,12 +27,12 @@
83f30e
    If FOR_FINI is true, this is called for finishing an object.  */
83f30e
 static void
83f30e
 _dl_sort_maps_original (struct link_map **maps, unsigned int nmaps,
83f30e
-			unsigned int skip, bool for_fini)
83f30e
+			bool force_first, bool for_fini)
83f30e
 {
83f30e
   /* Allows caller to do the common optimization of skipping the first map,
83f30e
      usually the main binary.  */
83f30e
-  maps += skip;
83f30e
-  nmaps -= skip;
83f30e
+  maps += force_first;
83f30e
+  nmaps -= force_first;
83f30e
 
83f30e
   /* A list of one element need not be sorted.  */
83f30e
   if (nmaps <= 1)
83f30e
@@ -182,7 +182,7 @@ dfs_traversal (struct link_map ***rpo, struct link_map *map,
83f30e
 
83f30e
 static void
83f30e
 _dl_sort_maps_dfs (struct link_map **maps, unsigned int nmaps,
83f30e
-		   unsigned int skip __attribute__ ((unused)), bool for_fini)
83f30e
+		   bool force_first __attribute__ ((unused)), bool for_fini)
83f30e
 {
83f30e
   for (int i = nmaps - 1; i >= 0; i--)
83f30e
     maps[i]->l_visited = 0;
83f30e
@@ -286,7 +286,7 @@ _dl_sort_maps_init (void)
83f30e
 
83f30e
 void
83f30e
 _dl_sort_maps (struct link_map **maps, unsigned int nmaps,
83f30e
-	       unsigned int skip, bool for_fini)
83f30e
+	       bool force_first, bool for_fini)
83f30e
 {
83f30e
   /* It can be tempting to use a static function pointer to store and call
83f30e
      the current selected sorting algorithm routine, but experimentation
83f30e
@@ -296,9 +296,9 @@ _dl_sort_maps (struct link_map **maps, unsigned int nmaps,
83f30e
      input cases. A simple if-case with direct function calls appears to
83f30e
      be the fastest.  */
83f30e
   if (__glibc_likely (GLRO(dl_dso_sort_algo) == dso_sort_algorithm_original))
83f30e
-    _dl_sort_maps_original (maps, nmaps, skip, for_fini);
83f30e
+    _dl_sort_maps_original (maps, nmaps, force_first, for_fini);
83f30e
   else
83f30e
-    _dl_sort_maps_dfs (maps, nmaps, skip, for_fini);
83f30e
+    _dl_sort_maps_dfs (maps, nmaps, force_first, for_fini);
83f30e
 }
83f30e
 
83f30e
 #endif /* HAVE_TUNABLES.  */
83f30e
diff --git a/sysdeps/generic/ldsodefs.h b/sysdeps/generic/ldsodefs.h
83f30e
index 9f09a4a280396659..2c1b4c47c6a6c643 100644
83f30e
--- a/sysdeps/generic/ldsodefs.h
83f30e
+++ b/sysdeps/generic/ldsodefs.h
83f30e
@@ -1056,9 +1056,11 @@ extern void _dl_init (struct link_map *main_map, int argc, char **argv,
83f30e
    initializer functions have completed.  */
83f30e
 extern void _dl_fini (void) attribute_hidden;
83f30e
 
83f30e
-/* Sort array MAPS according to dependencies of the contained objects.  */
83f30e
+/* Sort array MAPS according to dependencies of the contained objects.
83f30e
+   If FORCE_FIRST, MAPS[0] keeps its place even if the dependencies
83f30e
+   say otherwise.  */
83f30e
 extern void _dl_sort_maps (struct link_map **maps, unsigned int nmaps,
83f30e
-			   unsigned int skip, bool for_fini) attribute_hidden;
83f30e
+			   bool force_first, bool for_fini) attribute_hidden;
83f30e
 
83f30e
 /* The dynamic linker calls this function before and having changing
83f30e
    any shared object mappings.  The `r_state' member of `struct r_debug'