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