6ca6e8
Maintain an explicit order of tunables, so that the tunable_list
6ca6e8
array and the tunable_id_t constant can remain consistent over time.
6ca6e8
6ca6e8
Related to this upstream bug:
6ca6e8
6ca6e8
  Internal tunables ABI depends on awk array iteration order
6ca6e8
  <https://sourceware.org/bugzilla/show_bug.cgi?id=30027>
6ca6e8
6ca6e8
The new dl-tunables.list files are already on the sysdeps search
6ca6e8
path, which is why the existing Makeconfig rule picks them up.
6ca6e8
The files for RHEL 9.1z were created by applying the gen-tunables.awk
6ca6e8
part of this patch to RHEL 9.1.0 (glibc-2.34-40.el9_2.1, to be
6ca6e8
precise).  The sysdeps/unix/sysv/linux/**/dl-tunables.list files were
6ca6e8
created based on the generated error message during the RHEL 9.1.z
6ca6e8
build.
6ca6e8
6ca6e8
Going forward, new tunables will have to be added manually to the end
6ca6e8
of those files.  Existing tunables should not be deleted.  For
6ca6e8
deletion, the script would have to be extended to be able to create
6ca6e8
gaps in the tunable_list array.
6ca6e8
6ca6e8
diff --git a/scripts/gen-tunables.awk b/scripts/gen-tunables.awk
6ca6e8
index fa63e86d1a51fe61..c5445e95f9fc36e7 100644
6ca6e8
--- a/scripts/gen-tunables.awk
6ca6e8
+++ b/scripts/gen-tunables.awk
6ca6e8
@@ -14,6 +14,7 @@ BEGIN {
6ca6e8
   top_ns=""
6ca6e8
   max_name_len=0
6ca6e8
   max_alias_len=0
6ca6e8
+  tunable_order_count = 0
6ca6e8
 }
6ca6e8
 
6ca6e8
 # Skip over blank lines and comments.
6ca6e8
@@ -83,6 +84,37 @@ $1 == "}" {
6ca6e8
   next
6ca6e8
 }
6ca6e8
 
6ca6e8
+$1 == "@order" {
6ca6e8
+    if (top_ns != "") {
6ca6e8
+	printf("%s:%d: error: invalid @order directive inside namespace %s\n",
6ca6e8
+               FILENAME, FNR, top_ns) > "/dev/stderr"
6ca6e8
+	exit 1
6ca6e8
+    }
6ca6e8
+    if (NF != 2) {
6ca6e8
+	printf("%s:%d: error: invalid argument count in @order directive\n",
6ca6e8
+               FILENAME, FNR) > "/dev/stderr"
6ca6e8
+        exit 1
6ca6e8
+    }
6ca6e8
+    order_arg = $2
6ca6e8
+    if (split(order_arg, indices, /\./) != 3) {
6ca6e8
+	printf("%s:%d: error: invalid tunable syntax in @order directive\n",
6ca6e8
+               FILENAME, FNR) > "/dev/stderr"
6ca6e8
+        exit 1
6ca6e8
+    }
6ca6e8
+    t = indices[1]
6ca6e8
+    n = indices[2]
6ca6e8
+    m = indices[3]
6ca6e8
+    if ((t, n, m) in tunable_order) {
6ca6e8
+	printf("%s:%d: error: duplicate\"@order %s\"\n" \
6ca6e8
+               FILENAME, FNR, order_arg) > "/dev/stderr"
6ca6e8
+        exit 1
6ca6e8
+    }
6ca6e8
+    ++tunable_order_count
6ca6e8
+    tunable_order[t,n,m] = tunable_order_count
6ca6e8
+    tunable_order_list[tunable_order_count] = t SUBSEP n SUBSEP m
6ca6e8
+    next
6ca6e8
+}
6ca6e8
+
6ca6e8
 # Everything else, which could either be a tunable without any attributes or a
6ca6e8
 # tunable attribute.
6ca6e8
 {
6ca6e8
@@ -145,6 +177,31 @@ END {
6ca6e8
     exit 1
6ca6e8
   }
6ca6e8
 
6ca6e8
+  missing_order = 0
6ca6e8
+  for (tnm in types) {
6ca6e8
+      if (!(tnm in tunable_order)) {
6ca6e8
+	  if (!missing_order) {
6ca6e8
+	      print "error: Missing @order directives:" > "/dev/stderr"
6ca6e8
+	      missing_order = 1
6ca6e8
+	  }
6ca6e8
+	  split(tnm, indices, SUBSEP)
6ca6e8
+	  printf("@order %s.%s.%s\n", indices[1], indices[2], indices[3]) \
6ca6e8
+	      > "/dev/stderr"
6ca6e8
+      }
6ca6e8
+  }
6ca6e8
+  for (i = 1; i <= tunable_order_count; ++i) {
6ca6e8
+    tnm = tunable_order_list[i]
6ca6e8
+    if (!(tnm in types)) {
6ca6e8
+	split(tnm, indices, SUBSEP)
6ca6e8
+	printf("error: tunable in \"@order %s.%s.%s\" not known\n", \
6ca6e8
+	       indices[1], indices[2], indices[3]) > "/dev/stderr"
6ca6e8
+	missing_order = 1
6ca6e8
+    }
6ca6e8
+  }
6ca6e8
+  if (missing_order) {
6ca6e8
+      exit 1
6ca6e8
+  }
6ca6e8
+
6ca6e8
   print "/* AUTOGENERATED by gen-tunables.awk.  */"
6ca6e8
   print "#ifndef _TUNABLES_H_"
6ca6e8
   print "# error \"Do not include this file directly.\""
6ca6e8
@@ -155,7 +212,8 @@ END {
6ca6e8
   # Now, the enum names
6ca6e8
   print "\ntypedef enum"
6ca6e8
   print "{"
6ca6e8
-  for (tnm in types) {
6ca6e8
+  for (i = 1; i <= tunable_order_count; ++i) {
6ca6e8
+    tnm = tunable_order_list[i]
6ca6e8
     split (tnm, indices, SUBSEP);
6ca6e8
     t = indices[1];
6ca6e8
     n = indices[2];
6ca6e8
@@ -171,7 +229,8 @@ END {
6ca6e8
   print "# include \"dl-tunable-types.h\""
6ca6e8
   # Finally, the tunable list.
6ca6e8
   print "static tunable_t tunable_list[] attribute_relro = {"
6ca6e8
-  for (tnm in types) {
6ca6e8
+  for (i = 1; i <= tunable_order_count; ++i) {
6ca6e8
+    tnm = tunable_order_list[i]
6ca6e8
     split (tnm, indices, SUBSEP);
6ca6e8
     t = indices[1];
6ca6e8
     n = indices[2];
6ca6e8
diff --git a/sysdeps/unix/sysv/linux/aarch64/dl-tunables.list b/sysdeps/unix/sysv/linux/aarch64/dl-tunables.list
6ca6e8
new file mode 100644
6ca6e8
index 0000000000000000..d9d62499be4d67cb
6ca6e8
--- /dev/null
6ca6e8
+++ b/sysdeps/unix/sysv/linux/aarch64/dl-tunables.list
6ca6e8
@@ -0,0 +1,28 @@
6ca6e8
+# Order of tunables in RHEL 9.1.z.
6ca6e8
+@order glibc.rtld.nns
6ca6e8
+@order glibc.elision.skip_lock_after_retries
6ca6e8
+@order glibc.malloc.trim_threshold
6ca6e8
+@order glibc.malloc.perturb
6ca6e8
+@order glibc.pthread.rseq
6ca6e8
+@order glibc.cpu.name
6ca6e8
+@order glibc.mem.tagging
6ca6e8
+@order glibc.elision.tries
6ca6e8
+@order glibc.elision.enable
6ca6e8
+@order glibc.malloc.mxfast
6ca6e8
+@order glibc.rtld.dynamic_sort
6ca6e8
+@order glibc.elision.skip_lock_busy
6ca6e8
+@order glibc.malloc.top_pad
6ca6e8
+@order glibc.pthread.stack_cache_size
6ca6e8
+@order glibc.cpu.hwcap_mask
6ca6e8
+@order glibc.malloc.mmap_max
6ca6e8
+@order glibc.elision.skip_trylock_internal_abort
6ca6e8
+@order glibc.malloc.tcache_unsorted_limit
6ca6e8
+@order glibc.elision.skip_lock_internal_abort
6ca6e8
+@order glibc.malloc.arena_max
6ca6e8
+@order glibc.malloc.mmap_threshold
6ca6e8
+@order glibc.malloc.tcache_count
6ca6e8
+@order glibc.malloc.arena_test
6ca6e8
+@order glibc.pthread.mutex_spin_count
6ca6e8
+@order glibc.rtld.optional_static_tls
6ca6e8
+@order glibc.malloc.tcache_max
6ca6e8
+@order glibc.malloc.check
6ca6e8
diff --git a/sysdeps/unix/sysv/linux/i386/dl-tunables.list b/sysdeps/unix/sysv/linux/i386/dl-tunables.list
6ca6e8
new file mode 100644
6ca6e8
index 0000000000000000..e83962ec3af11691
6ca6e8
--- /dev/null
6ca6e8
+++ b/sysdeps/unix/sysv/linux/i386/dl-tunables.list
6ca6e8
@@ -0,0 +1,35 @@
6ca6e8
+# Order of tunables in RHEL 9.1.z.
6ca6e8
+@order glibc.rtld.nns
6ca6e8
+@order glibc.elision.skip_lock_after_retries
6ca6e8
+@order glibc.malloc.trim_threshold
6ca6e8
+@order glibc.malloc.perturb
6ca6e8
+@order glibc.cpu.x86_shared_cache_size
6ca6e8
+@order glibc.pthread.rseq
6ca6e8
+@order glibc.mem.tagging
6ca6e8
+@order glibc.elision.tries
6ca6e8
+@order glibc.elision.enable
6ca6e8
+@order glibc.cpu.x86_rep_movsb_threshold
6ca6e8
+@order glibc.malloc.mxfast
6ca6e8
+@order glibc.rtld.dynamic_sort
6ca6e8
+@order glibc.elision.skip_lock_busy
6ca6e8
+@order glibc.malloc.top_pad
6ca6e8
+@order glibc.cpu.x86_rep_stosb_threshold
6ca6e8
+@order glibc.cpu.x86_non_temporal_threshold
6ca6e8
+@order glibc.cpu.x86_shstk
6ca6e8
+@order glibc.pthread.stack_cache_size
6ca6e8
+@order glibc.cpu.hwcap_mask
6ca6e8
+@order glibc.malloc.mmap_max
6ca6e8
+@order glibc.elision.skip_trylock_internal_abort
6ca6e8
+@order glibc.malloc.tcache_unsorted_limit
6ca6e8
+@order glibc.cpu.x86_ibt
6ca6e8
+@order glibc.cpu.hwcaps
6ca6e8
+@order glibc.elision.skip_lock_internal_abort
6ca6e8
+@order glibc.malloc.arena_max
6ca6e8
+@order glibc.malloc.mmap_threshold
6ca6e8
+@order glibc.cpu.x86_data_cache_size
6ca6e8
+@order glibc.malloc.tcache_count
6ca6e8
+@order glibc.malloc.arena_test
6ca6e8
+@order glibc.pthread.mutex_spin_count
6ca6e8
+@order glibc.rtld.optional_static_tls
6ca6e8
+@order glibc.malloc.tcache_max
6ca6e8
+@order glibc.malloc.check
6ca6e8
diff --git a/sysdeps/unix/sysv/linux/powerpc/powerpc64/le/dl-tunables.list b/sysdeps/unix/sysv/linux/powerpc/powerpc64/le/dl-tunables.list
6ca6e8
new file mode 100644
6ca6e8
index 0000000000000000..8f01840ef57874e7
6ca6e8
--- /dev/null
6ca6e8
+++ b/sysdeps/unix/sysv/linux/powerpc/powerpc64/le/dl-tunables.list
6ca6e8
@@ -0,0 +1,28 @@
6ca6e8
+# Order of tunables in RHEL 9.1.z.
6ca6e8
+@order glibc.rtld.nns
6ca6e8
+@order glibc.elision.skip_lock_after_retries
6ca6e8
+@order glibc.malloc.trim_threshold
6ca6e8
+@order glibc.malloc.perturb
6ca6e8
+@order glibc.pthread.rseq
6ca6e8
+@order glibc.mem.tagging
6ca6e8
+@order glibc.elision.tries
6ca6e8
+@order glibc.elision.enable
6ca6e8
+@order glibc.malloc.mxfast
6ca6e8
+@order glibc.rtld.dynamic_sort
6ca6e8
+@order glibc.elision.skip_lock_busy
6ca6e8
+@order glibc.malloc.top_pad
6ca6e8
+@order glibc.pthread.stack_cache_size
6ca6e8
+@order glibc.cpu.hwcap_mask
6ca6e8
+@order glibc.malloc.mmap_max
6ca6e8
+@order glibc.elision.skip_trylock_internal_abort
6ca6e8
+@order glibc.malloc.tcache_unsorted_limit
6ca6e8
+@order glibc.elision.skip_lock_internal_abort
6ca6e8
+@order glibc.malloc.arena_max
6ca6e8
+@order glibc.malloc.mmap_threshold
6ca6e8
+@order glibc.cpu.cached_memopt
6ca6e8
+@order glibc.malloc.tcache_count
6ca6e8
+@order glibc.malloc.arena_test
6ca6e8
+@order glibc.pthread.mutex_spin_count
6ca6e8
+@order glibc.rtld.optional_static_tls
6ca6e8
+@order glibc.malloc.tcache_max
6ca6e8
+@order glibc.malloc.check
6ca6e8
diff --git a/sysdeps/unix/sysv/linux/s390/s390-64/dl-tunables.list b/sysdeps/unix/sysv/linux/s390/s390-64/dl-tunables.list
6ca6e8
new file mode 100644
6ca6e8
index 0000000000000000..c3bc83f33910af22
6ca6e8
--- /dev/null
6ca6e8
+++ b/sysdeps/unix/sysv/linux/s390/s390-64/dl-tunables.list
6ca6e8
@@ -0,0 +1,27 @@
6ca6e8
+# Order of tunables in RHEL 9.1.z.
6ca6e8
+@order glibc.rtld.nns
6ca6e8
+@order glibc.elision.skip_lock_after_retries
6ca6e8
+@order glibc.malloc.trim_threshold
6ca6e8
+@order glibc.malloc.perturb
6ca6e8
+@order glibc.pthread.rseq
6ca6e8
+@order glibc.mem.tagging
6ca6e8
+@order glibc.elision.tries
6ca6e8
+@order glibc.elision.enable
6ca6e8
+@order glibc.malloc.mxfast
6ca6e8
+@order glibc.rtld.dynamic_sort
6ca6e8
+@order glibc.elision.skip_lock_busy
6ca6e8
+@order glibc.malloc.top_pad
6ca6e8
+@order glibc.pthread.stack_cache_size
6ca6e8
+@order glibc.cpu.hwcap_mask
6ca6e8
+@order glibc.malloc.mmap_max
6ca6e8
+@order glibc.elision.skip_trylock_internal_abort
6ca6e8
+@order glibc.malloc.tcache_unsorted_limit
6ca6e8
+@order glibc.elision.skip_lock_internal_abort
6ca6e8
+@order glibc.malloc.arena_max
6ca6e8
+@order glibc.malloc.mmap_threshold
6ca6e8
+@order glibc.malloc.tcache_count
6ca6e8
+@order glibc.malloc.arena_test
6ca6e8
+@order glibc.pthread.mutex_spin_count
6ca6e8
+@order glibc.rtld.optional_static_tls
6ca6e8
+@order glibc.malloc.tcache_max
6ca6e8
+@order glibc.malloc.check
6ca6e8
diff --git a/sysdeps/unix/sysv/linux/x86_64/64/dl-tunables.list b/sysdeps/unix/sysv/linux/x86_64/64/dl-tunables.list
6ca6e8
new file mode 100644
6ca6e8
index 0000000000000000..e83962ec3af11691
6ca6e8
--- /dev/null
6ca6e8
+++ b/sysdeps/unix/sysv/linux/x86_64/64/dl-tunables.list
6ca6e8
@@ -0,0 +1,35 @@
6ca6e8
+# Order of tunables in RHEL 9.1.z.
6ca6e8
+@order glibc.rtld.nns
6ca6e8
+@order glibc.elision.skip_lock_after_retries
6ca6e8
+@order glibc.malloc.trim_threshold
6ca6e8
+@order glibc.malloc.perturb
6ca6e8
+@order glibc.cpu.x86_shared_cache_size
6ca6e8
+@order glibc.pthread.rseq
6ca6e8
+@order glibc.mem.tagging
6ca6e8
+@order glibc.elision.tries
6ca6e8
+@order glibc.elision.enable
6ca6e8
+@order glibc.cpu.x86_rep_movsb_threshold
6ca6e8
+@order glibc.malloc.mxfast
6ca6e8
+@order glibc.rtld.dynamic_sort
6ca6e8
+@order glibc.elision.skip_lock_busy
6ca6e8
+@order glibc.malloc.top_pad
6ca6e8
+@order glibc.cpu.x86_rep_stosb_threshold
6ca6e8
+@order glibc.cpu.x86_non_temporal_threshold
6ca6e8
+@order glibc.cpu.x86_shstk
6ca6e8
+@order glibc.pthread.stack_cache_size
6ca6e8
+@order glibc.cpu.hwcap_mask
6ca6e8
+@order glibc.malloc.mmap_max
6ca6e8
+@order glibc.elision.skip_trylock_internal_abort
6ca6e8
+@order glibc.malloc.tcache_unsorted_limit
6ca6e8
+@order glibc.cpu.x86_ibt
6ca6e8
+@order glibc.cpu.hwcaps
6ca6e8
+@order glibc.elision.skip_lock_internal_abort
6ca6e8
+@order glibc.malloc.arena_max
6ca6e8
+@order glibc.malloc.mmap_threshold
6ca6e8
+@order glibc.cpu.x86_data_cache_size
6ca6e8
+@order glibc.malloc.tcache_count
6ca6e8
+@order glibc.malloc.arena_test
6ca6e8
+@order glibc.pthread.mutex_spin_count
6ca6e8
+@order glibc.rtld.optional_static_tls
6ca6e8
+@order glibc.malloc.tcache_max
6ca6e8
+@order glibc.malloc.check