]> git.ipfire.org Git - thirdparty/glibc.git/commitdiff
tunables: sort tunables list (BZ 30027)
authorDJ Delorie <dj@redhat.com>
Tue, 11 Jun 2024 23:28:36 +0000 (19:28 -0400)
committerDJ Delorie <dj@redhat.com>
Wed, 12 Jun 2024 18:45:18 +0000 (14:45 -0400)
Sort tunables list at the time it's generated.  Note: adding new
tunables will cause other tunable IDs to change, but that was
the case before anyway.  POSIX does not guarantee the order of "foo
in bar" AWK operators, so the order was indeterminate before anyway.
Even depending on the order to be the same across multiple calls,
such as in this script, is undefined, so sorting the list resolves
that also.

Note that sorting is not dependent on the user's locale.

Makeconfig
scripts/gen-tunables.awk

index 29819363da8246e76b7255c389526d8e19b029a8..2d4343b604334c791bd97b485520e724974dd724 100644 (file)
@@ -1265,7 +1265,7 @@ $(common-objpfx)dl-tunable-list.stmp: \
                $(..)elf/dl-tunables.list \
                $(wildcard $(subdirs:%=$(..)%/dl-tunables.list)) \
                $(wildcard $(sysdirs:%=%/dl-tunables.list))
-       $(AWK) -f $^ > ${@:stmp=T}
+       LC_ALL=C $(AWK) -f $^ > ${@:stmp=T}
        $(move-if-change) ${@:stmp=T} ${@:stmp=h}
        touch $@
 
index fc3b41376fec80309298b2a8139761cfaa202e92..d9f326b63b25805f1b616211bc1d60961b8a3c49 100644 (file)
@@ -131,6 +131,11 @@ END {
     exit 1
   }
 
+  # TYPES is an associative array where the index is the data
+  # TYPESA is an indexed array where the value is the data
+  # We sort TYPESA
+  typecount = asorti (types, typesa)
+
   print "/* AUTOGENERATED by gen-tunables.awk.  */"
   print "#ifndef _TUNABLES_H_"
   print "# error \"Do not include this file directly.\""
@@ -141,7 +146,8 @@ END {
   # Now, the enum names
   print "\ntypedef enum"
   print "{"
-  for (tnm in types) {
+  for (i = 1; i <= typecount; i++) {
+    tnm = typesa[i];
     split (tnm, indices, SUBSEP);
     t = indices[1];
     n = indices[2];
@@ -157,7 +163,8 @@ END {
   print "# include \"dl-tunable-types.h\""
   # Finally, the tunable list.
   print "static tunable_t tunable_list[] attribute_relro __attribute_used__ = {"
-  for (tnm in types) {
+  for (i = 1; i <= typecount; i++) {
+    tnm = typesa[i];
     split (tnm, indices, SUBSEP);
     t = indices[1];
     n = indices[2];
@@ -172,7 +179,8 @@ END {
   # Map of tunable with environment variables aliases used during parsing.  */
   print "\nstatic const tunable_id_t tunable_env_alias_list[] ="
   printf "{\n"
-  for (tnm in types) {
+  for (i = 1; i <= typecount; i++) {
+    tnm = typesa[i];
     split (tnm, indices, SUBSEP);
     t = indices[1];
     n = indices[2];