[PATCH] AArch64: Add ifunc masking tunable

Wilco Dijkstra Wilco.Dijkstra@arm.com
Wed Jun 17 12:11:21 GMT 2026


Remove the glibc.cpu.name tunable since it's unused and out of date.
Add a new feature to adjust ifunc selection for debugging and benchmarking
(undocumented since this is for developers only).  If a flag bit is set,
consider the feature disabled and defer to a more generic ifunc (-1 is
the same as --disable-multiarch).

OK for commit?

---

diff --git a/manual/tunables.texi b/manual/tunables.texi
index e0f141077b133a6b6d5f5f76028e65025c7047b6..2e846e9a173a0228e169e84b7b87ba3e76b7d1e7 100644
--- a/manual/tunables.texi
+++ b/manual/tunables.texi
@@ -465,16 +465,6 @@ indicates that the process may use device memory.
 This tunable is specific to powerpc, powerpc64 and powerpc64le.
 @end deftp
 
-@deftp Tunable glibc.cpu.name
-The @code{glibc.cpu.name=xxx} tunable allows the user to tell @theglibc{} to
-assume that the CPU is @code{xxx} where xxx may have one of these values:
-@code{generic}, @code{thunderxt88}, @code{thunderx2t99},
-@code{thunderx2t99p1}, @code{ares}, @code{emag}, @code{kunpeng},
-@code{a64fx}.
-
-This tunable is specific to aarch64.
-@end deftp
-
 @deftp Tunable glibc.cpu.x86_data_cache_size
 The @code{glibc.cpu.x86_data_cache_size} tunable allows the user to set
 data cache size in bytes for use in memory and string routines.
diff --git a/sysdeps/aarch64/dl-tunables.list b/sysdeps/aarch64/dl-tunables.list
index a2ccba0b293a2d728ec6986f7ddd5b9793c1de17..90f5b383f652e6b538f9fdc3d56f000600c4b95c 100644
--- a/sysdeps/aarch64/dl-tunables.list
+++ b/sysdeps/aarch64/dl-tunables.list
@@ -18,8 +18,10 @@
 
 glibc {
   cpu {
-    name {
-      type: STRING
+    ifunc {
+      type: INT_32
+      minval: -1
+      default: 0
     }
     aarch64_bti {
       type: UINT_64
diff --git a/sysdeps/unix/sysv/linux/aarch64/Makefile b/sysdeps/unix/sysv/linux/aarch64/Makefile
index d1fcb48aa250dffd8b7e5b41f5b290512dc797e2..7e17e7741f8ecd26a71dbc0ec78c50dfc7f31fcb 100644
--- a/sysdeps/unix/sysv/linux/aarch64/Makefile
+++ b/sysdeps/unix/sysv/linux/aarch64/Makefile
@@ -9,16 +9,6 @@ modules-names += \
 LDFLAGS-tst-tlsdesc-pac = -rdynamic
 
 $(objpfx)tst-tlsdesc-pac.out: $(objpfx)tst-tlsdesc-pac-mod.so
-
-ifeq (yes,$(enable-static-pie))
-tests += \
-  tst-cpu-tunable-static-pie \
-  # tests
-tests-static += \
-  tst-cpu-tunable-static-pie \
-  # tests-static
-tst-cpu-tunable-static-pie-TUNABLES = glibc.cpu.name=generic
-endif
 endif
 
 ifeq ($(subdir),misc)
diff --git a/sysdeps/unix/sysv/linux/aarch64/cpu-features.c b/sysdeps/unix/sysv/linux/aarch64/cpu-features.c
index 9a87332ac49c0272930200ece5276eb5a4a2fae4..06b1ce7ab7501dbb5cc68e19bcb206ed1a336d31 100644
--- a/sysdeps/unix/sysv/linux/aarch64/cpu-features.c
+++ b/sysdeps/unix/sysv/linux/aarch64/cpu-features.c
@@ -33,56 +33,13 @@
    to see when pointer have been correctly tagged.  */
 #define MTE_ALLOWED_TAGS (0xfffe << PR_MTE_TAG_SHIFT)
 
-static const char cpu_list_name[] = {
-  "kunpeng920\0"
-  "kunpeng950\0"
-  "a64fx\0"
-  "generic\0",
-};
-
-static const uint64_t cpu_list_midr[] = {
-  0x481FD010,
-  0x480FD060,
-  0x460F0010,
-  0x0,
-};
-
-static uint64_t
-get_midr_from_mcpu (const struct tunable_str_t *mcpu)
-{
-  const char *name = cpu_list_name;
-  size_t offset = 0;
-  for (int i = 0; i < array_length (cpu_list_midr); i++)
-    {
-      size_t len = strlen (name);
-      if (tunable_strcmp (mcpu, cpu_list_name + offset, len))
-	return cpu_list_midr[i];
-      offset += len;
-    }
-  return UINT64_MAX;
-}
-
 static inline void
 init_cpu_features (struct cpu_features *cpu_features)
 {
-  register uint64_t midr = UINT64_MAX;
-
-  /* Get the tunable override.  */
-  const struct tunable_str_t *mcpu = TUNABLE_GET (glibc, cpu, name,
-						  struct tunable_str_t *,
-						  NULL);
-  if (mcpu != NULL)
-    midr = get_midr_from_mcpu (mcpu);
-
-  /* If there was no useful tunable override, query the MIDR if the kernel
-     allows it.  */
-  if (midr == UINT64_MAX)
-    {
-      if (GLRO (dl_hwcap) & HWCAP_CPUID)
-	asm volatile ("mrs %0, midr_el1" : "=r"(midr));
-      else
-	midr = 0;
-    }
+  uint64_t midr = 0;
+
+  if (GLRO (dl_hwcap) & HWCAP_CPUID)
+    asm volatile ("mrs %0, midr_el1" : "=r"(midr));
 
   cpu_features->midr_el1 = midr;
 
@@ -108,4 +65,20 @@ init_cpu_features (struct cpu_features *cpu_features)
   if (GLRO (dl_hwcap) & HWCAP_GCS)
     /* GCS status may be updated later by binary compatibility checks.  */
     GL (dl_aarch64_gcs) = TUNABLE_GET (glibc, cpu, aarch64_gcs, uint64_t, 0);
+
+  /* Mask to change ifunc selection to more generic versions.  */
+  int mask = TUNABLE_GET (glibc, cpu, ifunc, int, NULL);
+  if (mask != 0)
+    {
+      if (mask & 1)
+	cpu_features->midr_el1 = 0;
+      if (mask & 2)
+	cpu_features->zva_size = 0;
+      if (mask & 4)
+	cpu_features->sve = false;
+      if (mask & 8)
+	cpu_features->sve2 = false;
+      if (mask & 16)
+	cpu_features->mops = false;
+    }
 }
diff --git a/sysdeps/unix/sysv/linux/aarch64/tst-cpu-tunable-static-pie.c b/sysdeps/unix/sysv/linux/aarch64/tst-cpu-tunable-static-pie.c
deleted file mode 100644
index 561eaf3bdb07b6fa03975e3a2fcf55fe17d34702..0000000000000000000000000000000000000000
--- a/sysdeps/unix/sysv/linux/aarch64/tst-cpu-tunable-static-pie.c
+++ /dev/null
@@ -1,26 +0,0 @@
-/* Test that the glibc.cpu.name tunable is parsed correctly during early
-   startup of a static PIE binary (bug 34205).
-   Copyright (C) 2026 Free Software Foundation, Inc.
-   This file is part of the GNU C Library.
-
-   The GNU C Library is free software; you can redistribute it and/or
-   modify it under the terms of the GNU Lesser General Public
-   License as published by the Free Software Foundation; either
-   version 2.1 of the License, or (at your option) any later version.
-
-   The GNU C Library is distributed in the hope that it will be useful,
-   but WITHOUT ANY WARRANTY; without even the implied warranty of
-   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
-   Lesser General Public License for more details.
-
-   You should have received a copy of the GNU Lesser General Public
-   License along with the GNU C Library; if not, see
-   <https://www.gnu.org/licenses/>.  */
-
-static int
-do_test (void)
-{
-  return 0;
-}
-
-#include <support/test-driver.c>



More information about the Libc-alpha mailing list