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