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