public inbox for libc-alpha@sourceware.org
 help / color / mirror / Atom feed
* elf: sort tunables list from ld.so
@ 2024-06-07 21:22 DJ Delorie
  2024-06-08  1:34 ` DJ Delorie
  0 siblings, 1 reply; 6+ messages in thread
From: DJ Delorie @ 2024-06-07 21:22 UTC (permalink / raw)
  To: libc-alpha


sort output from "ld.so --list-tunables"

diff --git a/elf/dl-tunables.c b/elf/dl-tunables.c
index 147cc4cf23..f79fa0827e 100644
--- a/elf/dl-tunables.c
+++ b/elf/dl-tunables.c
@@ -357,9 +357,28 @@ __tunables_init (char **envp)
 void
 __tunables_print (void)
 {
-  for (int i = 0; i < array_length (tunable_list); i++)
+  int i, j;
+  int sortmap [array_length (tunable_list)];
+
+  for (i = 0; i < array_length (tunable_list); i++)
+    sortmap [i] = i;
+  /* Quick bubble sort is sufficient.  */
+  for (i = 0; i < array_length (tunable_list) - 1; i++)
+    for (j = i+1; j < array_length (tunable_list); j++)
+      {
+	const char *ni = tunable_list[sortmap[i]].name;
+	const char *nj = tunable_list[sortmap[j]].name;
+	if (strcmp (ni, nj) > 0)
+	  {
+	    int t = sortmap[i];
+	    sortmap[i] = sortmap[j];
+	    sortmap[j] = t;
+	  }
+      }
+
+  for (i = 0; i < array_length (tunable_list); i++)
     {
-      const tunable_t *cur = &tunable_list[i];
+      const tunable_t *cur = &tunable_list[sortmap[i]];
       if (cur->type.type_code == TUNABLE_TYPE_STRING
 	  && cur->val.strval.str == NULL)
 	_dl_printf ("%s:\n", cur->name);


^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2024-06-11  6:24 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-06-07 21:22 elf: sort tunables list from ld.so DJ Delorie
2024-06-08  1:34 ` DJ Delorie
2024-06-08  8:08   ` Andreas Schwab
2024-06-09 12:55   ` Florian Weimer
2024-06-10 18:04     ` DJ Delorie
2024-06-11  6:24       ` Florian Weimer

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).