e354a5
commit 4c38c1a229bc3628269ad98bd7e8d31d118d91f6
e354a5
Author: Florian Weimer <fweimer@redhat.com>
e354a5
Date:   Fri Dec 4 09:13:43 2020 +0100
e354a5
e354a5
    powerpc64le: Add glibc-hwcaps support
e354a5
    
e354a5
    The "power10" and "power9" subdirectories are selected in a way
e354a5
    that matches the -mcpu=power10 and -mcpu=power9 options of GCC.
e354a5
e354a5
diff --git a/elf/Makefile b/elf/Makefile
e354a5
index 7f2fc73877f0a4c8..57e3a8982297f79a 100644
e354a5
--- a/elf/Makefile
e354a5
+++ b/elf/Makefile
e354a5
@@ -1751,7 +1751,7 @@ $(objpfx)argv0test.out: tst-rtld-argv0.sh $(objpfx)ld.so \
e354a5
 # glibc-hwcaps mechanism for this architecture).  Used to obtain test
e354a5
 # coverage for some glibc-hwcaps tests for the widest possible range
e354a5
 # of systems.
e354a5
-glibc-hwcaps-first-subdirs-for-tests = x86-64-v2
e354a5
+glibc-hwcaps-first-subdirs-for-tests = power9 x86-64-v2
e354a5
 
e354a5
 # The test modules are parameterized by preprocessor macros.
e354a5
 LDFLAGS-libmarkermod1-1.so += -Wl,-soname,libmarkermod1.so
e354a5
diff --git a/elf/tst-glibc-hwcaps-cache.script b/elf/tst-glibc-hwcaps-cache.script
e354a5
index 66d6942402b7233b..6a4675f9bd30e02f 100644
e354a5
--- a/elf/tst-glibc-hwcaps-cache.script
e354a5
+++ b/elf/tst-glibc-hwcaps-cache.script
e354a5
@@ -5,6 +5,12 @@ cp $B/elf/libmarkermod2-1.so $L/libmarkermod2.so
e354a5
 cp $B/elf/libmarkermod3-1.so $L/libmarkermod3.so
e354a5
 cp $B/elf/libmarkermod4-1.so $L/libmarkermod4.so
e354a5
 
e354a5
+mkdirp 0770 $L/glibc-hwcaps/power9
e354a5
+cp $B/elf/libmarkermod2-2.so $L/glibc-hwcaps/power9/libmarkermod2.so
e354a5
+mkdirp 0770 $L/glibc-hwcaps/power10
e354a5
+cp $B/elf/libmarkermod3-2.so $L/glibc-hwcaps/power9/libmarkermod3.so
e354a5
+cp $B/elf/libmarkermod3-3.so $L/glibc-hwcaps/power10/libmarkermod3.so
e354a5
+
e354a5
 mkdirp 0770 $L/glibc-hwcaps/x86-64-v2
e354a5
 cp $B/elf/libmarkermod2-2.so $L/glibc-hwcaps/x86-64-v2/libmarkermod2.so
e354a5
 mkdirp 0770 $L/glibc-hwcaps/x86-64-v3
e354a5
diff --git a/sysdeps/powerpc/powerpc64/le/Makefile b/sysdeps/powerpc/powerpc64/le/Makefile
e354a5
index f59db1ca3c8ed454..7a4be6bfef729914 100644
e354a5
--- a/sysdeps/powerpc/powerpc64/le/Makefile
e354a5
+++ b/sysdeps/powerpc/powerpc64/le/Makefile
e354a5
@@ -82,3 +82,31 @@ CFLAGS-printf_fp.c = -mfloat128
e354a5
 CFLAGS-printf_fphex.c = -mfloat128
e354a5
 CFLAGS-printf_size.c = -mfloat128
e354a5
 endif
e354a5
+
e354a5
+ifeq ($(subdir),elf)
e354a5
+$(objpfx)tst-glibc-hwcaps: \
e354a5
+  $(objpfx)libmarkermod2-1.so $(objpfx)libmarkermod3-1.so
e354a5
+$(objpfx)tst-glibc-hwcaps.out: \
e354a5
+  $(objpfx)libmarkermod2.so \
e354a5
+    $(objpfx)glibc-hwcaps/power9/libmarkermod2.so \
e354a5
+  $(objpfx)libmarkermod3.so \
e354a5
+    $(objpfx)glibc-hwcaps/power9/libmarkermod3.so \
e354a5
+    $(objpfx)glibc-hwcaps/power10/libmarkermod3.so \
e354a5
+
e354a5
+$(objpfx)glibc-hwcaps/power9/libmarkermod2.so: $(objpfx)libmarkermod2-2.so
e354a5
+	$(make-target-directory)
e354a5
+	cp $< $@
e354a5
+$(objpfx)glibc-hwcaps/power9/libmarkermod3.so: $(objpfx)libmarkermod3-2.so
e354a5
+	$(make-target-directory)
e354a5
+	cp $< $@
e354a5
+$(objpfx)glibc-hwcaps/power10/libmarkermod3.so: $(objpfx)libmarkermod3-3.so
e354a5
+	$(make-target-directory)
e354a5
+	cp $< $@
e354a5
+
e354a5
+ifeq (no,$(build-hardcoded-path-in-tests))
e354a5
+# This is an ld.so.cache test, and RPATH/RUNPATH in the executable
e354a5
+# interferes with its test objectives.
e354a5
+tests-container += tst-glibc-hwcaps-cache
e354a5
+endif
e354a5
+
e354a5
+endif # $(subdir) == elf
e354a5
diff --git a/sysdeps/powerpc/powerpc64/le/dl-hwcaps-subdirs.c b/sysdeps/powerpc/powerpc64/le/dl-hwcaps-subdirs.c
e354a5
new file mode 100644
e354a5
index 0000000000000000..6a21d77649f44dd4
e354a5
--- /dev/null
e354a5
+++ b/sysdeps/powerpc/powerpc64/le/dl-hwcaps-subdirs.c
e354a5
@@ -0,0 +1,46 @@
e354a5
+/* Architecture-specific glibc-hwcaps subdirectories.  powerpc64le version.
e354a5
+   Copyright (C) 2020 Free Software Foundation, Inc.
e354a5
+   This file is part of the GNU C Library.
e354a5
+
e354a5
+   The GNU C Library is free software; you can redistribute it and/or
e354a5
+   modify it under the terms of the GNU Lesser General Public
e354a5
+   License as published by the Free Software Foundation; either
e354a5
+   version 2.1 of the License, or (at your option) any later version.
e354a5
+
e354a5
+   The GNU C Library is distributed in the hope that it will be useful,
e354a5
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
e354a5
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
e354a5
+   Lesser General Public License for more details.
e354a5
+
e354a5
+   You should have received a copy of the GNU Lesser General Public
e354a5
+   License along with the GNU C Library; if not, see
e354a5
+   <https://www.gnu.org/licenses/>.  */
e354a5
+
e354a5
+#include <dl-hwcaps.h>
e354a5
+#include <ldsodefs.h>
e354a5
+
e354a5
+const char _dl_hwcaps_subdirs[] = "power10:power9";
e354a5
+enum { subdirs_count = 2 }; /* Number of components in _dl_hwcaps_subdirs.  */
e354a5
+
e354a5
+uint32_t
e354a5
+_dl_hwcaps_subdirs_active (void)
e354a5
+{
e354a5
+  int active = 0;
e354a5
+
e354a5
+  /* Test in reverse preference order.  Altivec and VSX are implied by
e354a5
+     the powerpc64le ABI definition.  */
e354a5
+
e354a5
+  /* POWER9.  GCC enables float128 hardware support for -mcpu=power9.  */
e354a5
+  if ((GLRO (dl_hwcap2) & PPC_FEATURE2_ARCH_3_00) == 0
e354a5
+      || (GLRO (dl_hwcap2) & PPC_FEATURE2_HAS_IEEE128) == 0)
e354a5
+    return _dl_hwcaps_subdirs_build_bitmask (subdirs_count, active);
e354a5
+  ++active;
e354a5
+
e354a5
+  /* POWER10.  GCC defines __MMA__ for -mcpu=power10.  */
e354a5
+  if ((GLRO (dl_hwcap2) & PPC_FEATURE2_ARCH_3_1) == 0
e354a5
+      || (GLRO (dl_hwcap2) & PPC_FEATURE2_MMA) == 0)
e354a5
+    return _dl_hwcaps_subdirs_build_bitmask (subdirs_count, active);
e354a5
+  ++active;
e354a5
+
e354a5
+  return _dl_hwcaps_subdirs_build_bitmask (subdirs_count, active);
e354a5
+}
e354a5
diff --git a/sysdeps/powerpc/powerpc64/le/tst-glibc-hwcaps.c b/sysdeps/powerpc/powerpc64/le/tst-glibc-hwcaps.c
e354a5
new file mode 100644
e354a5
index 0000000000000000..e510fca80a22aaeb
e354a5
--- /dev/null
e354a5
+++ b/sysdeps/powerpc/powerpc64/le/tst-glibc-hwcaps.c
e354a5
@@ -0,0 +1,54 @@
e354a5
+/* glibc-hwcaps subdirectory test.  powerpc64le version.
e354a5
+   Copyright (C) 2020 Free Software Foundation, Inc.
e354a5
+   This file is part of the GNU C Library.
e354a5
+
e354a5
+   The GNU C Library is free software; you can redistribute it and/or
e354a5
+   modify it under the terms of the GNU Lesser General Public
e354a5
+   License as published by the Free Software Foundation; either
e354a5
+   version 2.1 of the License, or (at your option) any later version.
e354a5
+
e354a5
+   The GNU C Library is distributed in the hope that it will be useful,
e354a5
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
e354a5
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
e354a5
+   Lesser General Public License for more details.
e354a5
+
e354a5
+   You should have received a copy of the GNU Lesser General Public
e354a5
+   License along with the GNU C Library; if not, see
e354a5
+   <https://www.gnu.org/licenses/>.  */
e354a5
+
e354a5
+#include <stdio.h>
e354a5
+#include <string.h>
e354a5
+#include <support/check.h>
e354a5
+#include <sys/auxv.h>
e354a5
+#include <sys/param.h>
e354a5
+
e354a5
+extern int marker2 (void);
e354a5
+extern int marker3 (void);
e354a5
+
e354a5
+/* Return the POWER level, 8 for the baseline.  */
e354a5
+static int
e354a5
+compute_level (void)
e354a5
+{
e354a5
+  const char *platform = (const char *) getauxval (AT_PLATFORM);
e354a5
+  if (strcmp (platform, "power8") == 0)
e354a5
+    return 8;
e354a5
+  if (strcmp (platform, "power9") == 0)
e354a5
+    return 9;
e354a5
+  if (strcmp (platform, "power10") == 0)
e354a5
+    return 10;
e354a5
+  printf ("warning: unrecognized AT_PLATFORM value: %s\n", platform);
e354a5
+  /* Assume that the new platform supports POWER10.  */
e354a5
+  return 10;
e354a5
+}
e354a5
+
e354a5
+static int
e354a5
+do_test (void)
e354a5
+{
e354a5
+  int level = compute_level ();
e354a5
+  printf ("info: detected POWER level: %d\n", level);
e354a5
+  TEST_COMPARE (marker2 (), MIN (level - 7, 2));
e354a5
+  TEST_COMPARE (marker3 (), MIN (level - 7, 3));
e354a5
+  return 0;
e354a5
+}
e354a5
+
e354a5
+#include <support/test-driver.c>