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