diff mbox series

<sys/platform/x86.h>: Pass index_cpu_##name [BZ #27104]

Message ID 20201222113940.2828450-1-hjl.tools@gmail.com
State Superseded
Headers show
Series <sys/platform/x86.h>: Pass index_cpu_##name [BZ #27104] | expand

Commit Message

H.J. Lu Dec. 22, 2020, 11:39 a.m. UTC
Pass index_cpu_##name to __x86_get_cpu_features in HAS_CPU_FEATURE and
CPU_FEATURE_USABLE so that applications compiled against the glibc header
files with a larger COMMON_CPUID_INDEX_MAX work with an older glibc
binary with a smaller COMMON_CPUID_INDEX_MAX.
---
 sysdeps/x86/Makefile                        | 13 +++++--
 sysdeps/x86/sys/platform/x86.h              |  4 +--
 sysdeps/x86/tst-get-cpu-features-2-static.c |  1 +
 sysdeps/x86/tst-get-cpu-features-2.c        | 38 +++++++++++++++++++++
 4 files changed, 51 insertions(+), 5 deletions(-)
 create mode 100644 sysdeps/x86/tst-get-cpu-features-2-static.c
 create mode 100644 sysdeps/x86/tst-get-cpu-features-2.c
diff mbox series

Patch

diff --git a/sysdeps/x86/Makefile b/sysdeps/x86/Makefile
index 081cc72e93..e50db29f31 100644
--- a/sysdeps/x86/Makefile
+++ b/sysdeps/x86/Makefile
@@ -6,9 +6,16 @@  ifeq ($(subdir),elf)
 sysdep-dl-routines += dl-get-cpu-features
 sysdep_headers += sys/platform/x86.h
 
-tests += tst-get-cpu-features tst-get-cpu-features-static \
-	 tst-cpu-features-cpuinfo tst-cpu-features-supports
-tests-static += tst-get-cpu-features-static
+tests += \
+  tst-get-cpu-features-2 \
+  tst-get-cpu-features-2-static \
+  tst-get-cpu-features \
+  tst-get-cpu-features-static \
+  tst-cpu-features-cpuinfo \
+  tst-cpu-features-supports
+tests-static += \
+  tst-get-cpu-features-2-static \
+  tst-get-cpu-features-static
 endif
 
 ifeq ($(subdir),math)
diff --git a/sysdeps/x86/sys/platform/x86.h b/sysdeps/x86/sys/platform/x86.h
index 3ef92b04e8..e0baf357ad 100644
--- a/sysdeps/x86/sys/platform/x86.h
+++ b/sysdeps/x86/sys/platform/x86.h
@@ -87,13 +87,13 @@  extern const struct cpu_features *__x86_get_cpu_features (unsigned int)
 #define HAS_CPU_FEATURE(name)					\
   (__extension__						\
    ({ const struct cpu_features *__ptr =			\
-	__x86_get_cpu_features (COMMON_CPUID_INDEX_MAX);	\
+	__x86_get_cpu_features (index_cpu_##name);		\
       __ptr && CPU_FEATURE_CPU_P (__ptr, name); }))
 /* CPU_FEATURE_USABLE evaluates to true if the feature is usable.  */
 #define CPU_FEATURE_USABLE(name)				\
   (__extension__						\
    ({ const struct cpu_features *__ptr =			\
-	__x86_get_cpu_features (COMMON_CPUID_INDEX_MAX);	\
+	__x86_get_cpu_features (index_cpu_##name);		\
       __ptr && CPU_FEATURE_USABLE_P (__ptr, name); }))
 
 /* CPU features.  */
diff --git a/sysdeps/x86/tst-get-cpu-features-2-static.c b/sysdeps/x86/tst-get-cpu-features-2-static.c
new file mode 100644
index 0000000000..a86383ab62
--- /dev/null
+++ b/sysdeps/x86/tst-get-cpu-features-2-static.c
@@ -0,0 +1 @@ 
+#include "tst-get-cpu-features-2.c"
diff --git a/sysdeps/x86/tst-get-cpu-features-2.c b/sysdeps/x86/tst-get-cpu-features-2.c
new file mode 100644
index 0000000000..2c8cc1bf19
--- /dev/null
+++ b/sysdeps/x86/tst-get-cpu-features-2.c
@@ -0,0 +1,38 @@ 
+/* Forward compatibility test case for __x86_get_cpu_features interface
+   Copyright (C) 2020 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/>.  */
+
+#include <stdlib.h>
+#include <stdio.h>
+#define COMMON_CPUID_INDEX_MAX __rename_COMMON_CPUID_INDEX_MAX
+#include <sys/platform/x86.h>
+#undef COMMON_CPUID_INDEX_MAX
+#define COMMON_CPUID_INDEX_MAX (__rename_COMMON_CPUID_INDEX_MAX + 1)
+#include <support/check.h>
+
+static int
+do_test (void)
+{
+#ifdef __SSE2__
+  TEST_VERIFY_EXIT (HAS_CPU_FEATURE (SSE2));
+  TEST_VERIFY_EXIT (CPU_FEATURE_USABLE (SSE2));
+#endif
+
+  return 0;
+}
+
+#include <support/test-driver.c>