76b6d9
Maintain an explicit order of tunables, so that the tunable_list
76b6d9
array and the tunable_id_t constant can remain consistent over time.
76b6d9
76b6d9
Related to this upstream bug:
76b6d9
76b6d9
  Internal tunables ABI depends on awk array iteration order
76b6d9
  <https://sourceware.org/bugzilla/show_bug.cgi?id=30027>
76b6d9
76b6d9
The new dl-tunables.list files are already on the sysdeps search
76b6d9
path, which is why the existing Makeconfig rule picks them up.
76b6d9
The files for RHEL 8.7.z were created by applying the gen-tunables.awk
76b6d9
part of this patch to RHEL 8.7.0 (glibc-2.28-211.el8_7, to be precise).
76b6d9
The sysdeps/unix/sysv/linux/**/dl-tunables.list files were created
76b6d9
based on the generated error message during the RHEL 8.7.z build.
76b6d9
Afterwards, the glibc.rtld.dynamic_sort tunable was added at the
76b6d9
end of the files, for the RHEL 8.8.0 build.
76b6d9
76b6d9
Going forward, new tunables will have to be added manually to the end
76b6d9
of those files.  Existing tunables should not be deleted.  For
76b6d9
deletion, the script would have to be extended to be able to create
76b6d9
gaps in the tunable_list array.
76b6d9
76b6d9
diff --git a/scripts/gen-tunables.awk b/scripts/gen-tunables.awk
76b6d9
index 622199061a140ccd..8ebfb560976ead41 100644
76b6d9
--- a/scripts/gen-tunables.awk
76b6d9
+++ b/scripts/gen-tunables.awk
76b6d9
@@ -12,6 +12,7 @@ BEGIN {
76b6d9
   tunable=""
76b6d9
   ns=""
76b6d9
   top_ns=""
76b6d9
+  tunable_order_count = 0
76b6d9
 }
76b6d9
 
76b6d9
 # Skip over blank lines and comments.
76b6d9
@@ -78,6 +79,37 @@ $1 == "}" {
76b6d9
   next
76b6d9
 }
76b6d9
 
76b6d9
+$1 == "@order" {
76b6d9
+    if (top_ns != "") {
76b6d9
+	printf("%s:%d: error: invalid @order directive inside namespace %s\n",
76b6d9
+               FILENAME, FNR, top_ns) > "/dev/stderr"
76b6d9
+	exit 1
76b6d9
+    }
76b6d9
+    if (NF != 2) {
76b6d9
+	printf("%s:%d: error: invalid argument count in @order directive\n",
76b6d9
+               FILENAME, FNR) > "/dev/stderr"
76b6d9
+        exit 1
76b6d9
+    }
76b6d9
+    order_arg = $2
76b6d9
+    if (split(order_arg, indices, /\./) != 3) {
76b6d9
+	printf("%s:%d: error: invalid tunable syntax in @order directive\n",
76b6d9
+               FILENAME, FNR) > "/dev/stderr"
76b6d9
+        exit 1
76b6d9
+    }
76b6d9
+    t = indices[1]
76b6d9
+    n = indices[2]
76b6d9
+    m = indices[3]
76b6d9
+    if ((t, n, m) in tunable_order) {
76b6d9
+	printf("%s:%d: error: duplicate\"@order %s\"\n" \
76b6d9
+               FILENAME, FNR, order_arg) > "/dev/stderr"
76b6d9
+        exit 1
76b6d9
+    }
76b6d9
+    ++tunable_order_count
76b6d9
+    tunable_order[t,n,m] = tunable_order_count
76b6d9
+    tunable_order_list[tunable_order_count] = t SUBSEP n SUBSEP m
76b6d9
+    next
76b6d9
+}
76b6d9
+
76b6d9
 # Everything else, which could either be a tunable without any attributes or a
76b6d9
 # tunable attribute.
76b6d9
 {
76b6d9
@@ -137,6 +169,31 @@ END {
76b6d9
     exit 1
76b6d9
   }
76b6d9
 
76b6d9
+  missing_order = 0
76b6d9
+  for (tnm in types) {
76b6d9
+      if (!(tnm in tunable_order)) {
76b6d9
+	  if (!missing_order) {
76b6d9
+	      print "error: Missing @order directives:" > "/dev/stderr"
76b6d9
+	      missing_order = 1
76b6d9
+	  }
76b6d9
+	  split(tnm, indices, SUBSEP)
76b6d9
+	  printf("@order %s.%s.%s\n", indices[1], indices[2], indices[3]) \
76b6d9
+	      > "/dev/stderr"
76b6d9
+      }
76b6d9
+  }
76b6d9
+  for (i = 1; i <= tunable_order_count; ++i) {
76b6d9
+    tnm = tunable_order_list[i]
76b6d9
+    if (!(tnm in types)) {
76b6d9
+	split(tnm, indices, SUBSEP)
76b6d9
+	printf("error: tunable in \"@order %s.%s.%s\" not known\n", \
76b6d9
+	       indices[1], indices[2], indices[3]) > "/dev/stderr"
76b6d9
+	missing_order = 1
76b6d9
+    }
76b6d9
+  }
76b6d9
+  if (missing_order) {
76b6d9
+      exit 1
76b6d9
+  }
76b6d9
+
76b6d9
   print "/* AUTOGENERATED by gen-tunables.awk.  */"
76b6d9
   print "#ifndef _TUNABLES_H_"
76b6d9
   print "# error \"Do not include this file directly.\""
76b6d9
@@ -147,7 +204,8 @@ END {
76b6d9
   # Now, the enum names
76b6d9
   print "\ntypedef enum"
76b6d9
   print "{"
76b6d9
-  for (tnm in types) {
76b6d9
+  for (i = 1; i <= tunable_order_count; ++i) {
76b6d9
+    tnm = tunable_order_list[i]
76b6d9
     split (tnm, indices, SUBSEP);
76b6d9
     t = indices[1];
76b6d9
     n = indices[2];
76b6d9
@@ -159,7 +217,8 @@ END {
76b6d9
   # Finally, the tunable list.
76b6d9
   print "\n#ifdef TUNABLES_INTERNAL"
76b6d9
   print "static tunable_t tunable_list[] attribute_relro = {"
76b6d9
-  for (tnm in types) {
76b6d9
+  for (i = 1; i <= tunable_order_count; ++i) {
76b6d9
+    tnm = tunable_order_list[i]
76b6d9
     split (tnm, indices, SUBSEP);
76b6d9
     t = indices[1];
76b6d9
     n = indices[2];
76b6d9
diff --git a/sysdeps/unix/sysv/linux/aarch64/dl-tunables.list b/sysdeps/unix/sysv/linux/aarch64/dl-tunables.list
76b6d9
new file mode 100644
76b6d9
index 0000000000000000..5c3c5292025607a1
76b6d9
--- /dev/null
76b6d9
+++ b/sysdeps/unix/sysv/linux/aarch64/dl-tunables.list
76b6d9
@@ -0,0 +1,26 @@
76b6d9
+# Order of tunables in RHEL 8.7.0.
76b6d9
+@order glibc.rtld.nns
76b6d9
+@order glibc.elision.skip_lock_after_retries
76b6d9
+@order glibc.malloc.trim_threshold
76b6d9
+@order glibc.malloc.perturb
76b6d9
+@order glibc.cpu.name
76b6d9
+@order glibc.elision.tries
76b6d9
+@order glibc.elision.enable
76b6d9
+@order glibc.malloc.mxfast
76b6d9
+@order glibc.elision.skip_lock_busy
76b6d9
+@order glibc.malloc.top_pad
76b6d9
+@order glibc.cpu.hwcap_mask
76b6d9
+@order glibc.malloc.mmap_max
76b6d9
+@order glibc.elision.skip_trylock_internal_abort
76b6d9
+@order glibc.malloc.tcache_unsorted_limit
76b6d9
+@order glibc.elision.skip_lock_internal_abort
76b6d9
+@order glibc.malloc.arena_max
76b6d9
+@order glibc.malloc.mmap_threshold
76b6d9
+@order glibc.malloc.tcache_count
76b6d9
+@order glibc.malloc.arena_test
76b6d9
+@order glibc.rtld.optional_static_tls
76b6d9
+@order glibc.malloc.tcache_max
76b6d9
+@order glibc.malloc.check
76b6d9
+
76b6d9
+# Tunables added in RHEL 8.8.0
76b6d9
+@order glibc.rtld.dynamic_sort
76b6d9
diff --git a/sysdeps/unix/sysv/linux/i386/dl-tunables.list b/sysdeps/unix/sysv/linux/i386/dl-tunables.list
76b6d9
new file mode 100644
76b6d9
index 0000000000000000..b9cad4af62d9f2e5
76b6d9
--- /dev/null
76b6d9
+++ b/sysdeps/unix/sysv/linux/i386/dl-tunables.list
76b6d9
@@ -0,0 +1,33 @@
76b6d9
+# Order of tunables in RHEL 8.7.0.
76b6d9
+@order glibc.rtld.nns
76b6d9
+@order glibc.elision.skip_lock_after_retries
76b6d9
+@order glibc.malloc.trim_threshold
76b6d9
+@order glibc.malloc.perturb
76b6d9
+@order glibc.cpu.x86_shared_cache_size
76b6d9
+@order glibc.elision.tries
76b6d9
+@order glibc.elision.enable
76b6d9
+@order glibc.cpu.x86_rep_movsb_threshold
76b6d9
+@order glibc.malloc.mxfast
76b6d9
+@order glibc.elision.skip_lock_busy
76b6d9
+@order glibc.malloc.top_pad
76b6d9
+@order glibc.cpu.x86_rep_stosb_threshold
76b6d9
+@order glibc.cpu.x86_non_temporal_threshold
76b6d9
+@order glibc.cpu.x86_shstk
76b6d9
+@order glibc.cpu.hwcap_mask
76b6d9
+@order glibc.malloc.mmap_max
76b6d9
+@order glibc.elision.skip_trylock_internal_abort
76b6d9
+@order glibc.malloc.tcache_unsorted_limit
76b6d9
+@order glibc.cpu.x86_ibt
76b6d9
+@order glibc.cpu.hwcaps
76b6d9
+@order glibc.elision.skip_lock_internal_abort
76b6d9
+@order glibc.malloc.arena_max
76b6d9
+@order glibc.malloc.mmap_threshold
76b6d9
+@order glibc.cpu.x86_data_cache_size
76b6d9
+@order glibc.malloc.tcache_count
76b6d9
+@order glibc.malloc.arena_test
76b6d9
+@order glibc.rtld.optional_static_tls
76b6d9
+@order glibc.malloc.tcache_max
76b6d9
+@order glibc.malloc.check
76b6d9
+
76b6d9
+# Tunables added in RHEL 8.8.0
76b6d9
+@order glibc.rtld.dynamic_sort
76b6d9
diff --git a/sysdeps/unix/sysv/linux/powerpc/powerpc64/le/dl-tunables.list b/sysdeps/unix/sysv/linux/powerpc/powerpc64/le/dl-tunables.list
76b6d9
new file mode 100644
76b6d9
index 0000000000000000..ee1e6fca95e1f2da
76b6d9
--- /dev/null
76b6d9
+++ b/sysdeps/unix/sysv/linux/powerpc/powerpc64/le/dl-tunables.list
76b6d9
@@ -0,0 +1,26 @@
76b6d9
+# Order of tunables in RHEL 8.7.0.
76b6d9
+@order glibc.rtld.nns
76b6d9
+@order glibc.elision.skip_lock_after_retries
76b6d9
+@order glibc.malloc.trim_threshold
76b6d9
+@order glibc.malloc.perturb
76b6d9
+@order glibc.elision.tries
76b6d9
+@order glibc.elision.enable
76b6d9
+@order glibc.malloc.mxfast
76b6d9
+@order glibc.elision.skip_lock_busy
76b6d9
+@order glibc.malloc.top_pad
76b6d9
+@order glibc.cpu.hwcap_mask
76b6d9
+@order glibc.malloc.mmap_max
76b6d9
+@order glibc.elision.skip_trylock_internal_abort
76b6d9
+@order glibc.malloc.tcache_unsorted_limit
76b6d9
+@order glibc.elision.skip_lock_internal_abort
76b6d9
+@order glibc.malloc.arena_max
76b6d9
+@order glibc.malloc.mmap_threshold
76b6d9
+@order glibc.cpu.cached_memopt
76b6d9
+@order glibc.malloc.tcache_count
76b6d9
+@order glibc.malloc.arena_test
76b6d9
+@order glibc.rtld.optional_static_tls
76b6d9
+@order glibc.malloc.tcache_max
76b6d9
+@order glibc.malloc.check
76b6d9
+
76b6d9
+# Tunables added in RHEL 8.8.0
76b6d9
+@order glibc.rtld.dynamic_sort
76b6d9
diff --git a/sysdeps/unix/sysv/linux/s390/s390-64/dl-tunables.list b/sysdeps/unix/sysv/linux/s390/s390-64/dl-tunables.list
76b6d9
new file mode 100644
76b6d9
index 0000000000000000..099e28d8f8e67944
76b6d9
--- /dev/null
76b6d9
+++ b/sysdeps/unix/sysv/linux/s390/s390-64/dl-tunables.list
76b6d9
@@ -0,0 +1,25 @@
76b6d9
+# Order of tunables in RHEL 8.7.0.
76b6d9
+@order glibc.rtld.nns
76b6d9
+@order glibc.elision.skip_lock_after_retries
76b6d9
+@order glibc.malloc.trim_threshold
76b6d9
+@order glibc.malloc.perturb
76b6d9
+@order glibc.elision.tries
76b6d9
+@order glibc.elision.enable
76b6d9
+@order glibc.malloc.mxfast
76b6d9
+@order glibc.elision.skip_lock_busy
76b6d9
+@order glibc.malloc.top_pad
76b6d9
+@order glibc.cpu.hwcap_mask
76b6d9
+@order glibc.malloc.mmap_max
76b6d9
+@order glibc.elision.skip_trylock_internal_abort
76b6d9
+@order glibc.malloc.tcache_unsorted_limit
76b6d9
+@order glibc.elision.skip_lock_internal_abort
76b6d9
+@order glibc.malloc.arena_max
76b6d9
+@order glibc.malloc.mmap_threshold
76b6d9
+@order glibc.malloc.tcache_count
76b6d9
+@order glibc.malloc.arena_test
76b6d9
+@order glibc.rtld.optional_static_tls
76b6d9
+@order glibc.malloc.tcache_max
76b6d9
+@order glibc.malloc.check
76b6d9
+
76b6d9
+# Tunables added in RHEL 8.8.0
76b6d9
+@order glibc.rtld.dynamic_sort
76b6d9
diff --git a/sysdeps/unix/sysv/linux/x86_64/64/dl-tunables.list b/sysdeps/unix/sysv/linux/x86_64/64/dl-tunables.list
76b6d9
new file mode 100644
76b6d9
index 0000000000000000..b9cad4af62d9f2e5
76b6d9
--- /dev/null
76b6d9
+++ b/sysdeps/unix/sysv/linux/x86_64/64/dl-tunables.list
76b6d9
@@ -0,0 +1,33 @@
76b6d9
+# Order of tunables in RHEL 8.7.0.
76b6d9
+@order glibc.rtld.nns
76b6d9
+@order glibc.elision.skip_lock_after_retries
76b6d9
+@order glibc.malloc.trim_threshold
76b6d9
+@order glibc.malloc.perturb
76b6d9
+@order glibc.cpu.x86_shared_cache_size
76b6d9
+@order glibc.elision.tries
76b6d9
+@order glibc.elision.enable
76b6d9
+@order glibc.cpu.x86_rep_movsb_threshold
76b6d9
+@order glibc.malloc.mxfast
76b6d9
+@order glibc.elision.skip_lock_busy
76b6d9
+@order glibc.malloc.top_pad
76b6d9
+@order glibc.cpu.x86_rep_stosb_threshold
76b6d9
+@order glibc.cpu.x86_non_temporal_threshold
76b6d9
+@order glibc.cpu.x86_shstk
76b6d9
+@order glibc.cpu.hwcap_mask
76b6d9
+@order glibc.malloc.mmap_max
76b6d9
+@order glibc.elision.skip_trylock_internal_abort
76b6d9
+@order glibc.malloc.tcache_unsorted_limit
76b6d9
+@order glibc.cpu.x86_ibt
76b6d9
+@order glibc.cpu.hwcaps
76b6d9
+@order glibc.elision.skip_lock_internal_abort
76b6d9
+@order glibc.malloc.arena_max
76b6d9
+@order glibc.malloc.mmap_threshold
76b6d9
+@order glibc.cpu.x86_data_cache_size
76b6d9
+@order glibc.malloc.tcache_count
76b6d9
+@order glibc.malloc.arena_test
76b6d9
+@order glibc.rtld.optional_static_tls
76b6d9
+@order glibc.malloc.tcache_max
76b6d9
+@order glibc.malloc.check
76b6d9
+
76b6d9
+# Tunables added in RHEL 8.8.0
76b6d9
+@order glibc.rtld.dynamic_sort