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