diff mbox series

elf: sort tunables list from ld.so

Message ID xntti4v46l.fsf@greed.delorie.com
State New
Headers show
Series elf: sort tunables list from ld.so | expand

Commit Message

DJ Delorie June 7, 2024, 9:22 p.m. UTC
sort output from "ld.so --list-tunables"

Comments

Andreas Schwab June 8, 2024, 8:08 a.m. UTC | #1
On Jun 07 2024, DJ Delorie wrote:

> /usr/bin/ld: /build/libc.a(dl-tunables.o): unsupported non-PIC call to IFUNC `strcmp'

Add sysdeps/i386/i686/multiarch/rtld-strcmp.c
diff mbox series

Patch

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);