public inbox for libc-alpha@sourceware.org
 help / color / mirror / Atom feed
* [PATCH 3/4] Make LD_HWCAP_MASK usable for static binaries
  2017-05-25 20:27 [PATCH v3 0/4] aarch64: Allow overriding HWCAP_CPUID feature check Siddhesh Poyarekar
@ 2017-05-25 20:27 ` Siddhesh Poyarekar
  2017-05-25 20:27 ` [PATCH 2/4] aarch64: Allow overriding HWCAP_CPUID feature check using HWCAP_MASK Siddhesh Poyarekar
                   ` (3 subsequent siblings)
  4 siblings, 0 replies; 10+ messages in thread
From: Siddhesh Poyarekar @ 2017-05-25 20:27 UTC (permalink / raw)
  To: libc-alpha; +Cc: adhemerval.zanella

The LD_HWCAP_MASK environment variable was ignored in static binaries,
which is inconsistent with the behaviour of dynamically linked
binaries.  This seems to have been because of the inability of
ld_hwcap_mask being read early enough to influence anything but now
that it is in tunables, the mask is usable in static binaries as well.

This feature is important for aarch64, which relies on HWCAP_CPUID
being masked out to disable multiarch.  A sanity test on x86_64 shows
that there are no failures.  Likewise for aarch64.

	* elf/dl-hwcaps.h [HAVE_TUNABLES]: Always read hwcap_mask.
	* sysdeps/sparc/sparc32/dl-machine.h [HAVE_TUNABLES]:
	Likewise.
	* sysdeps/x86/cpu-features.c (init_cpu_features): Always set
	up hwcap and hwcap_mask.
---
 elf/dl-hwcaps.h                    | 14 +++++++-------
 sysdeps/sparc/sparc32/dl-machine.h |  2 +-
 sysdeps/x86/cpu-features.c         |  8 +++-----
 3 files changed, 11 insertions(+), 13 deletions(-)

diff --git a/elf/dl-hwcaps.h b/elf/dl-hwcaps.h
index 169ad1b..a8060d5 100644
--- a/elf/dl-hwcaps.h
+++ b/elf/dl-hwcaps.h
@@ -18,13 +18,13 @@
 
 #include <elf/dl-tunables.h>
 
-#ifdef SHARED
-# if HAVE_TUNABLES
-#  define GET_HWCAP_MASK() TUNABLE_GET (glibc, tune, hwcap_mask, uint64_t)
+#if HAVE_TUNABLES
+# define GET_HWCAP_MASK() TUNABLE_GET (glibc, tune, hwcap_mask, uint64_t)
+#else
+# ifdef SHARED
+#   define GET_HWCAP_MASK() GLRO(dl_hwcap_mask)
 # else
-#  define GET_HWCAP_MASK() GLRO(dl_hwcap_mask)
+/* HWCAP_MASK is ignored in static binaries when built without tunables.  */
+#  define GET_HWCAP_MASK() (0)
 # endif
-#else
-/* HWCAP_MASK is ignored in static binaries.  */
-# define GET_HWCAP_MASK() (0)
 #endif
diff --git a/sysdeps/sparc/sparc32/dl-machine.h b/sysdeps/sparc/sparc32/dl-machine.h
index f9ae133..95f6732 100644
--- a/sysdeps/sparc/sparc32/dl-machine.h
+++ b/sysdeps/sparc/sparc32/dl-machine.h
@@ -37,7 +37,7 @@ elf_machine_matches_host (const Elf32_Ehdr *ehdr)
     return 1;
   else if (ehdr->e_machine == EM_SPARC32PLUS)
     {
-#ifdef SHARED
+#if HAVE_TUNABLES || defined SHARED
       uint64_t hwcap_mask = GET_HWCAP_MASK();
       return GLRO(dl_hwcap) & hwcap_mask & HWCAP_SPARC_V9;
 #else
diff --git a/sysdeps/x86/cpu-features.c b/sysdeps/x86/cpu-features.c
index 4fe58bf..4288001 100644
--- a/sysdeps/x86/cpu-features.c
+++ b/sysdeps/x86/cpu-features.c
@@ -312,17 +312,16 @@ no_cpuid:
   cpu_features->model = model;
   cpu_features->kind = kind;
 
-#if IS_IN (rtld)
   /* Reuse dl_platform, dl_hwcap and dl_hwcap_mask for x86.  */
   GLRO(dl_platform) = NULL;
   GLRO(dl_hwcap) = 0;
-#if !HAVE_TUNABLES
+#if !HAVE_TUNABLES && defined SHARED
   /* The glibc.tune.hwcap_mask tunable is initialized already, so no need to do
      this.  */
   GLRO(dl_hwcap_mask) = HWCAP_IMPORTANT;
 #endif
 
-# ifdef __x86_64__
+#ifdef __x86_64__
   if (cpu_features->kind == arch_kind_intel)
     {
       if (CPU_FEATURES_ARCH_P (cpu_features, AVX512F_Usable)
@@ -352,7 +351,7 @@ no_cpuid:
 	  && CPU_FEATURES_CPU_P (cpu_features, POPCNT))
 	GLRO(dl_platform) = "haswell";
     }
-# else
+#else
   if (CPU_FEATURES_CPU_P (cpu_features, SSE2))
     GLRO(dl_hwcap) |= HWCAP_X86_SSE2;
 
@@ -360,6 +359,5 @@ no_cpuid:
     GLRO(dl_platform) = "i686";
   else if (CPU_FEATURES_ARCH_P (cpu_features, I586))
     GLRO(dl_platform) = "i586";
-# endif
 #endif
 }
-- 
2.7.4

^ permalink raw reply	[flat|nested] 10+ messages in thread

* [PATCH 4/4] aarch64: Add hwcap string routines
  2017-05-25 20:27 [PATCH v3 0/4] aarch64: Allow overriding HWCAP_CPUID feature check Siddhesh Poyarekar
  2017-05-25 20:27 ` [PATCH 3/4] Make LD_HWCAP_MASK usable for static binaries Siddhesh Poyarekar
  2017-05-25 20:27 ` [PATCH 2/4] aarch64: Allow overriding HWCAP_CPUID feature check using HWCAP_MASK Siddhesh Poyarekar
@ 2017-05-25 20:27 ` Siddhesh Poyarekar
  2017-05-25 20:27 ` [PATCH 1/4] tunables: Use glibc.tune.hwcap_mask tunable instead of _dl_hwcap_mask Siddhesh Poyarekar
  2017-05-26 20:13 ` [PATCH v3 0/4] aarch64: Allow overriding HWCAP_CPUID feature check Steve Ellcey
  4 siblings, 0 replies; 10+ messages in thread
From: Siddhesh Poyarekar @ 2017-05-25 20:27 UTC (permalink / raw)
  To: libc-alpha; +Cc: adhemerval.zanella

Add support for routines in dl-procinfo.h to show string versions of
HWCAP entries when a program is invoked with the LD_SHOW_AUXV
environment variable set and also to aid in path resolution for
ldconfig.

	* sysdeps/unix/sysv/linux/aarch64/dl-procinfo.c
	(_dl_aarch64_cap_flags): New array.
	* sysdeps/unix/sysv/linux/aarch64/dl-procinfo.h
	(_dl_hwcap_string, _dl_string_hwcap, _dl_procinfo): Implement
	functions.
---
 sysdeps/unix/sysv/linux/aarch64/dl-procinfo.c | 15 +++++++
 sysdeps/unix/sysv/linux/aarch64/dl-procinfo.h | 58 +++++++++++++++++++++++----
 2 files changed, 65 insertions(+), 8 deletions(-)

diff --git a/sysdeps/unix/sysv/linux/aarch64/dl-procinfo.c b/sysdeps/unix/sysv/linux/aarch64/dl-procinfo.c
index 438046a..bc37bad 100644
--- a/sysdeps/unix/sysv/linux/aarch64/dl-procinfo.c
+++ b/sysdeps/unix/sysv/linux/aarch64/dl-procinfo.c
@@ -56,5 +56,20 @@ PROCINFO_CLASS struct cpu_features _dl_aarch64_cpu_features
 # endif
 #endif
 
+#if !defined PROCINFO_DECL && defined SHARED
+  ._dl_aarch64_cap_flags
+#else
+PROCINFO_CLASS const char _dl_aarch64_cap_flags[13][10]
+#endif
+#ifndef PROCINFO_DECL
+= { "fp", "asimd", "evtstrm", "aes", "pmull", "sha1", "sha2", "crc32",
+    "atomics", "fphp", "asimdhp", "cpuid", "asimdrdm"}
+#endif
+#if !defined SHARED || defined PROCINFO_DECL
+;
+#else
+,
+#endif
+
 #undef PROCINFO_DECL
 #undef PROCINFO_CLASS
diff --git a/sysdeps/unix/sysv/linux/aarch64/dl-procinfo.h b/sysdeps/unix/sysv/linux/aarch64/dl-procinfo.h
index 7a60d72..cdb36d3 100644
--- a/sysdeps/unix/sysv/linux/aarch64/dl-procinfo.h
+++ b/sysdeps/unix/sysv/linux/aarch64/dl-procinfo.h
@@ -20,25 +20,67 @@
 #define _DL_PROCINFO_H	1
 
 #include <sys/auxv.h>
+#include <unistd.h>
+#include <ldsodefs.h>
+#include <sysdep.h>
 
 /* We cannot provide a general printing function.  */
-#define _dl_procinfo(type, word) -1
+static inline int
+__attribute__ ((unused))
+_dl_procinfo (unsigned int type, unsigned long int word)
+{
+  /* This table should match the information from arch/arm64/kernel/cpuinfo.c
+     in the kernel sources.  */
+  int i;
 
-/* There are no hardware capabilities defined.  */
-#define _dl_hwcap_string(idx) ""
+  /* Fallback to unknown output mechanism.  */
+  if (type == AT_HWCAP2)
+    return -1;
+
+  _dl_printf ("AT_HWCAP:   ");
+
+  for (i = 0; i < 32; ++i)
+    if (word & (1 << i))
+      _dl_printf (" %s", GLRO(dl_aarch64_cap_flags)[i]);
+
+  _dl_printf ("\n");
+
+  return 0;
+}
+
+static inline const char *
+__attribute__ ((unused))
+_dl_hwcap_string (int idx)
+{
+  return GLRO(dl_aarch64_cap_flags)[idx];
+};
+
+
+/* 13 HWCAP bits set.  */
+#define _DL_HWCAP_COUNT 13
+
+/* Low 13 bits are allocated in HWCAP.  */
+#define _DL_HWCAP_LAST 12
 
 /* HWCAP_CPUID should be available by default to influence IFUNC as well as
    library search.  */
 #define HWCAP_IMPORTANT HWCAP_CPUID
 
+static inline int
+__attribute__ ((unused))
+_dl_string_hwcap (const char *str)
+{
+  for (int i = 0; i < _DL_HWCAP_COUNT; i++)
+    {
+      if (strcmp (str, _dl_hwcap_string (i)) == 0)
+	return i;
+    }
+  return -1;
+};
+
 /* There're no platforms to filter out.  */
 #define _DL_HWCAP_PLATFORM 0
 
-/* We don't have any hardware capabilities.  */
-#define _DL_HWCAP_COUNT 0
-
-#define _dl_string_hwcap(str) (-1)
-
 #define _dl_string_platform(str) (-1)
 
 #endif /* dl-procinfo.h */
-- 
2.7.4

^ permalink raw reply	[flat|nested] 10+ messages in thread

* [PATCH v3 0/4] aarch64: Allow overriding HWCAP_CPUID feature check
@ 2017-05-25 20:27 Siddhesh Poyarekar
  2017-05-25 20:27 ` [PATCH 3/4] Make LD_HWCAP_MASK usable for static binaries Siddhesh Poyarekar
                   ` (4 more replies)
  0 siblings, 5 replies; 10+ messages in thread
From: Siddhesh Poyarekar @ 2017-05-25 20:27 UTC (permalink / raw)
  To: libc-alpha; +Cc: adhemerval.zanella

Hi,

Here is another take at the remaining patches to allow overriding HWCAP_CPUID
feature check.  Changes from the previous version:

 - Added convenience macro to get dl_hwcap_mask
 - Disable reading LD_HWCAP_MASK in static binaries when tunables are disabled
 - Enable reading LD_HWCAP_MASK in static binaries when tunables are enabled
 - Fix x86 exponential behaviour with ld_hwcap_mask set to a high value on
   static binaries
 - Add patch to write hwcap strings to LD_SHOW_AUXV and for ldconfig

I have not reposted the earlier 1/5, 2/5 and 4/5 since they have been acked.
I'll push them in together with all these patches since it did not make sense to
put them in isolation.

Tested on x86_64 and aarch64.


Siddhesh Poyarekar (4):
  tunables: Use glibc.tune.hwcap_mask tunable instead of _dl_hwcap_mask
  aarch64: Allow overriding HWCAP_CPUID feature check using HWCAP_MASK
  Make LD_HWCAP_MASK usable for static binaries
  aarch64: Add hwcap string routines

 elf/dl-cache.c                                 |  5 +-
 elf/dl-hwcaps.c                                | 11 +++-
 elf/dl-hwcaps.h                                | 30 +++++++++
 elf/dl-support.c                               |  2 +
 elf/dl-tunables.h                              |  2 +
 elf/rtld.c                                     |  4 ++
 sysdeps/generic/ldsodefs.h                     |  2 +
 sysdeps/sparc/sparc32/dl-machine.h             |  6 +-
 sysdeps/unix/sysv/linux/aarch64/cpu-features.c | 10 +--
 sysdeps/unix/sysv/linux/aarch64/dl-procinfo.c  | 15 +++++
 sysdeps/unix/sysv/linux/aarch64/dl-procinfo.h  | 86 ++++++++++++++++++++++++++
 sysdeps/x86/cpu-features.c                     | 10 +--
 12 files changed, 170 insertions(+), 13 deletions(-)
 create mode 100644 elf/dl-hwcaps.h
 create mode 100644 sysdeps/unix/sysv/linux/aarch64/dl-procinfo.h

-- 
2.7.4

^ permalink raw reply	[flat|nested] 10+ messages in thread

* [PATCH 1/4] tunables: Use glibc.tune.hwcap_mask tunable instead of _dl_hwcap_mask
  2017-05-25 20:27 [PATCH v3 0/4] aarch64: Allow overriding HWCAP_CPUID feature check Siddhesh Poyarekar
                   ` (2 preceding siblings ...)
  2017-05-25 20:27 ` [PATCH 4/4] aarch64: Add hwcap string routines Siddhesh Poyarekar
@ 2017-05-25 20:27 ` Siddhesh Poyarekar
  2017-05-30 21:21   ` Adhemerval Zanella
  2017-05-26 20:13 ` [PATCH v3 0/4] aarch64: Allow overriding HWCAP_CPUID feature check Steve Ellcey
  4 siblings, 1 reply; 10+ messages in thread
From: Siddhesh Poyarekar @ 2017-05-25 20:27 UTC (permalink / raw)
  To: libc-alpha; +Cc: adhemerval.zanella

Drop _dl_hwcap_mask when building with tunables.  This completes the
transition of hwcap_mask reading from _dl_hwcap_mask to tunables.

	* elf/dl-hwcaps.h: New file.
	* elf/dl-hwcaps.c: Include it.
	(_dl_important_hwcaps)[HAVE_TUNABLES]: Read and update
	glibc.tune.hwcap_mask.
	* elf/dl-cache.c: Include dl-hwcaps.h.
	(_dl_load_cache_lookup)[HAVE_TUNABLES]: Read
	glibc.tune.hwcap_mask.
	* sysdeps/sparc/sparc32/dl-machine.h: Likewise.
	* elf/dl-support.c (_dl_hwcap2)[HAVE_TUNABLES]: Drop
	_dl_hwcap_mask.
	* elf/dl-tunables.c (__tunable_set_val): Make a hidden alias.
	* elf/dl-tunables.h (__tunable_set_val): Likewise.
	* elf/rtld.c (rtld_global_ro)[HAVE_TUNABLES]: Drop
	_dl_hwcap_mask.
	(process_envvars)[HAVE_TUNABLES]: Likewise.
	* sysdeps/generic/ldsodefs.h (rtld_global_ro)[HAVE_TUNABLES]:
	Likewise.
	* sysdeps/x86/cpu-features.c (init_cpu_features): Don't
	initialize dl_hwcap_mask when tunables are enabled.
---
 elf/dl-cache.c                     |  5 ++++-
 elf/dl-hwcaps.c                    | 11 +++++++++--
 elf/dl-hwcaps.h                    | 30 ++++++++++++++++++++++++++++++
 elf/dl-support.c                   |  2 ++
 elf/dl-tunables.h                  |  2 ++
 elf/rtld.c                         |  4 ++++
 sysdeps/generic/ldsodefs.h         |  2 ++
 sysdeps/sparc/sparc32/dl-machine.h |  4 +++-
 sysdeps/x86/cpu-features.c         |  4 ++++
 9 files changed, 60 insertions(+), 4 deletions(-)
 create mode 100644 elf/dl-hwcaps.h

diff --git a/elf/dl-cache.c b/elf/dl-cache.c
index 017c78a..e9632da 100644
--- a/elf/dl-cache.c
+++ b/elf/dl-cache.c
@@ -24,6 +24,7 @@
 #include <dl-procinfo.h>
 #include <stdint.h>
 #include <_itoa.h>
+#include <dl-hwcaps.h>
 
 #ifndef _DL_PLATFORMS_COUNT
 # define _DL_PLATFORMS_COUNT 0
@@ -258,8 +259,10 @@ _dl_load_cache_lookup (const char *name)
       if (platform != (uint64_t) -1)
 	platform = 1ULL << platform;
 
+      uint64_t hwcap_mask = GET_HWCAP_MASK();
+
 #define _DL_HWCAP_TLS_MASK (1LL << 63)
-      uint64_t hwcap_exclude = ~((GLRO(dl_hwcap) & GLRO(dl_hwcap_mask))
+      uint64_t hwcap_exclude = ~((GLRO(dl_hwcap) & hwcap_mask)
 				 | _DL_HWCAP_PLATFORM | _DL_HWCAP_TLS_MASK);
 
       /* Only accept hwcap if it's for the right platform.  */
diff --git a/elf/dl-hwcaps.c b/elf/dl-hwcaps.c
index c437397..ab7492f 100644
--- a/elf/dl-hwcaps.c
+++ b/elf/dl-hwcaps.c
@@ -24,6 +24,7 @@
 #include <ldsodefs.h>
 
 #include <dl-procinfo.h>
+#include <dl-hwcaps.h>
 
 #ifdef _DL_FIRST_PLATFORM
 # define _DL_FIRST_EXTRA (_DL_FIRST_PLATFORM + _DL_PLATFORMS_COUNT)
@@ -37,8 +38,9 @@ internal_function
 _dl_important_hwcaps (const char *platform, size_t platform_len, size_t *sz,
 		      size_t *max_capstrlen)
 {
+  uint64_t hwcap_mask = GET_HWCAP_MASK();
   /* Determine how many important bits are set.  */
-  uint64_t masked = GLRO(dl_hwcap) & GLRO(dl_hwcap_mask);
+  uint64_t masked = GLRO(dl_hwcap) & hwcap_mask;
   size_t cnt = platform != NULL;
   size_t n, m;
   size_t total;
@@ -125,7 +127,12 @@ _dl_important_hwcaps (const char *platform, size_t platform_len, size_t *sz,
 	 LD_HWCAP_MASK environment variable (or default HWCAP_IMPORTANT).
 	 So there is no way to request ignoring an OS-supplied dsocap
 	 string and bit like you can ignore an OS-supplied HWCAP bit.  */
-      GLRO(dl_hwcap_mask) |= (uint64_t) mask << _DL_FIRST_EXTRA;
+      hwcap_mask |= (uint64_t) mask << _DL_FIRST_EXTRA;
+#if HAVE_TUNABLES
+      TUNABLE_UPDATE_VAL (glibc, tune, hwcap_mask, hwcap_mask, uint64_t);
+#else
+      GLRO(dl_hwcap_mask) = hwcap_mask;
+#endif
       size_t len;
       for (const char *p = dsocaps; p < dsocaps + dsocapslen; p += len + 1)
 	{
diff --git a/elf/dl-hwcaps.h b/elf/dl-hwcaps.h
new file mode 100644
index 0000000..169ad1b
--- /dev/null
+++ b/elf/dl-hwcaps.h
@@ -0,0 +1,30 @@
+/* Hardware capability support for run-time dynamic loader.
+   Copyright (C) 2017 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
+   <http://www.gnu.org/licenses/>.  */
+
+#include <elf/dl-tunables.h>
+
+#ifdef SHARED
+# if HAVE_TUNABLES
+#  define GET_HWCAP_MASK() TUNABLE_GET (glibc, tune, hwcap_mask, uint64_t)
+# else
+#  define GET_HWCAP_MASK() GLRO(dl_hwcap_mask)
+# endif
+#else
+/* HWCAP_MASK is ignored in static binaries.  */
+# define GET_HWCAP_MASK() (0)
+#endif
diff --git a/elf/dl-support.c b/elf/dl-support.c
index 3c46a7a..c22be85 100644
--- a/elf/dl-support.c
+++ b/elf/dl-support.c
@@ -164,6 +164,7 @@ uint64_t _dl_hwcap2 __attribute__ ((nocommon));
 /* The value of the FPU control word the kernel will preset in hardware.  */
 fpu_control_t _dl_fpu_control = _FPU_DEFAULT;
 
+#if !HAVE_TUNABLES
 /* This is not initialized to HWCAP_IMPORTANT, matching the definition
    of _dl_important_hwcaps, below, where no hwcap strings are ever
    used.  This mask is still used to mediate the lookups in the cache
@@ -171,6 +172,7 @@ fpu_control_t _dl_fpu_control = _FPU_DEFAULT;
    LD_HWCAP_MASK environment variable here), there is no real point in
    setting _dl_hwcap nonzero below, but we do anyway.  */
 uint64_t _dl_hwcap_mask __attribute__ ((nocommon));
+#endif
 
 /* Prevailing state of the stack.  Generally this includes PF_X, indicating it's
  * executable but this isn't true for all platforms.  */
diff --git a/elf/dl-tunables.h b/elf/dl-tunables.h
index 298b361..4d0a1ab 100644
--- a/elf/dl-tunables.h
+++ b/elf/dl-tunables.h
@@ -70,6 +70,8 @@ extern void __tunables_init (char **);
 extern void __tunable_set_val (tunable_id_t, void *, tunable_callback_t);
 extern void __tunable_update_val (tunable_id_t, void *);
 
+rtld_hidden_proto (__tunable_set_val)
+
 /* Get and return a tunable value.  */
 # define TUNABLE_GET(__top, __ns, __id, __type) \
 ({									      \
diff --git a/elf/rtld.c b/elf/rtld.c
index 319ef06..3746653 100644
--- a/elf/rtld.c
+++ b/elf/rtld.c
@@ -159,7 +159,9 @@ struct rtld_global_ro _rtld_global_ro attribute_relro =
     ._dl_debug_fd = STDERR_FILENO,
     ._dl_use_load_bias = -2,
     ._dl_correct_cache_id = _DL_CACHE_DEFAULT_ID,
+#if !HAVE_TUNABLES
     ._dl_hwcap_mask = HWCAP_IMPORTANT,
+#endif
     ._dl_lazy = 1,
     ._dl_fpu_control = _FPU_DEFAULT,
     ._dl_pagesize = EXEC_PAGESIZE,
@@ -2402,6 +2404,7 @@ process_envvars (enum mode *modep)
 	    _dl_show_auxv ();
 	  break;
 
+#if !HAVE_TUNABLES
 	case 10:
 	  /* Mask for the important hardware capabilities.  */
 	  if (!__libc_enable_secure
@@ -2409,6 +2412,7 @@ process_envvars (enum mode *modep)
 	    GLRO(dl_hwcap_mask) = __strtoul_internal (&envline[11], NULL,
 						      0, 0);
 	  break;
+#endif
 
 	case 11:
 	  /* Path where the binary is found.  */
diff --git a/sysdeps/generic/ldsodefs.h b/sysdeps/generic/ldsodefs.h
index f26a8b2..695ac24 100644
--- a/sysdeps/generic/ldsodefs.h
+++ b/sysdeps/generic/ldsodefs.h
@@ -515,8 +515,10 @@ struct rtld_global_ro
   /* Mask for hardware capabilities that are available.  */
   EXTERN uint64_t _dl_hwcap;
 
+#if !HAVE_TUNABLES
   /* Mask for important hardware capabilities we honour. */
   EXTERN uint64_t _dl_hwcap_mask;
+#endif
 
 #ifdef HAVE_AUX_VECTOR
   /* Pointer to the auxv list supplied to the program at startup.  */
diff --git a/sysdeps/sparc/sparc32/dl-machine.h b/sysdeps/sparc/sparc32/dl-machine.h
index e17ac8e..f9ae133 100644
--- a/sysdeps/sparc/sparc32/dl-machine.h
+++ b/sysdeps/sparc/sparc32/dl-machine.h
@@ -27,6 +27,7 @@
 #include <sysdep.h>
 #include <tls.h>
 #include <dl-plt.h>
+#include <elf/dl-hwcaps.h>
 
 /* Return nonzero iff ELF header is compatible with the running host.  */
 static inline int
@@ -37,7 +38,8 @@ elf_machine_matches_host (const Elf32_Ehdr *ehdr)
   else if (ehdr->e_machine == EM_SPARC32PLUS)
     {
 #ifdef SHARED
-      return GLRO(dl_hwcap) & GLRO(dl_hwcap_mask) & HWCAP_SPARC_V9;
+      uint64_t hwcap_mask = GET_HWCAP_MASK();
+      return GLRO(dl_hwcap) & hwcap_mask & HWCAP_SPARC_V9;
 #else
       return GLRO(dl_hwcap) & HWCAP_SPARC_V9;
 #endif
diff --git a/sysdeps/x86/cpu-features.c b/sysdeps/x86/cpu-features.c
index b481f50..4fe58bf 100644
--- a/sysdeps/x86/cpu-features.c
+++ b/sysdeps/x86/cpu-features.c
@@ -316,7 +316,11 @@ no_cpuid:
   /* Reuse dl_platform, dl_hwcap and dl_hwcap_mask for x86.  */
   GLRO(dl_platform) = NULL;
   GLRO(dl_hwcap) = 0;
+#if !HAVE_TUNABLES
+  /* The glibc.tune.hwcap_mask tunable is initialized already, so no need to do
+     this.  */
   GLRO(dl_hwcap_mask) = HWCAP_IMPORTANT;
+#endif
 
 # ifdef __x86_64__
   if (cpu_features->kind == arch_kind_intel)
-- 
2.7.4

^ permalink raw reply	[flat|nested] 10+ messages in thread

* [PATCH 2/4] aarch64: Allow overriding HWCAP_CPUID feature check using HWCAP_MASK
  2017-05-25 20:27 [PATCH v3 0/4] aarch64: Allow overriding HWCAP_CPUID feature check Siddhesh Poyarekar
  2017-05-25 20:27 ` [PATCH 3/4] Make LD_HWCAP_MASK usable for static binaries Siddhesh Poyarekar
@ 2017-05-25 20:27 ` Siddhesh Poyarekar
  2017-05-25 20:27 ` [PATCH 4/4] aarch64: Add hwcap string routines Siddhesh Poyarekar
                   ` (2 subsequent siblings)
  4 siblings, 0 replies; 10+ messages in thread
From: Siddhesh Poyarekar @ 2017-05-25 20:27 UTC (permalink / raw)
  To: libc-alpha; +Cc: adhemerval.zanella

Now that LD_HWCAP_MASK (or glibc.tune.hwcap_mask) is read early enough
to influence cpu feature check in aarch64, use it to influence
multiarch selection.  Setting LD_HWCAP_MASK such that it clears
HWCAP_CPUID will now disable multiarch for the binary.

HWCAP_CPUID is also now set in HWCAP_IMPORTANT so that it is set by
default.  With this patch, this feature is only usable with
dyanmically linked binaries because LD_HWCAP_MASK is not read for
static binaries.  A future patch fixes that.

	* sysdeps/unix/sysv/linux/aarch64/cpu-features.c
	(init_cpu_features): Use glibc.tune.hwcap_mask.
	* sysdeps/unix/sysv/linux/aarch64/dl-procinfo.h: New file.
---
 sysdeps/unix/sysv/linux/aarch64/cpu-features.c | 10 +++---
 sysdeps/unix/sysv/linux/aarch64/dl-procinfo.h  | 44 ++++++++++++++++++++++++++
 2 files changed, 50 insertions(+), 4 deletions(-)
 create mode 100644 sysdeps/unix/sysv/linux/aarch64/dl-procinfo.h

diff --git a/sysdeps/unix/sysv/linux/aarch64/cpu-features.c b/sysdeps/unix/sysv/linux/aarch64/cpu-features.c
index 7025062..ef6eecd 100644
--- a/sysdeps/unix/sysv/linux/aarch64/cpu-features.c
+++ b/sysdeps/unix/sysv/linux/aarch64/cpu-features.c
@@ -18,18 +18,20 @@
 
 #include <cpu-features.h>
 #include <sys/auxv.h>
+#include <elf/dl-hwcaps.h>
 
 static inline void
 init_cpu_features (struct cpu_features *cpu_features)
 {
-  if (GLRO(dl_hwcap) & HWCAP_CPUID)
+  uint64_t hwcap_mask = GET_HWCAP_MASK();
+  uint64_t hwcap = GLRO (dl_hwcap) & hwcap_mask;
+
+  if (hwcap & HWCAP_CPUID)
     {
       register uint64_t id = 0;
       asm volatile ("mrs %0, midr_el1" : "=r"(id));
       cpu_features->midr_el1 = id;
     }
   else
-    {
-      cpu_features->midr_el1 = 0;
-    }
+    cpu_features->midr_el1 = 0;
 }
diff --git a/sysdeps/unix/sysv/linux/aarch64/dl-procinfo.h b/sysdeps/unix/sysv/linux/aarch64/dl-procinfo.h
new file mode 100644
index 0000000..7a60d72
--- /dev/null
+++ b/sysdeps/unix/sysv/linux/aarch64/dl-procinfo.h
@@ -0,0 +1,44 @@
+/* Processor capability information handling macros - aarch64 version.
+   Copyright (C) 2017 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
+   <http://www.gnu.org/licenses/>.  */
+
+#ifndef _DL_PROCINFO_H
+#define _DL_PROCINFO_H	1
+
+#include <sys/auxv.h>
+
+/* We cannot provide a general printing function.  */
+#define _dl_procinfo(type, word) -1
+
+/* There are no hardware capabilities defined.  */
+#define _dl_hwcap_string(idx) ""
+
+/* HWCAP_CPUID should be available by default to influence IFUNC as well as
+   library search.  */
+#define HWCAP_IMPORTANT HWCAP_CPUID
+
+/* There're no platforms to filter out.  */
+#define _DL_HWCAP_PLATFORM 0
+
+/* We don't have any hardware capabilities.  */
+#define _DL_HWCAP_COUNT 0
+
+#define _dl_string_hwcap(str) (-1)
+
+#define _dl_string_platform(str) (-1)
+
+#endif /* dl-procinfo.h */
-- 
2.7.4

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [PATCH v3 0/4] aarch64: Allow overriding HWCAP_CPUID feature check
  2017-05-25 20:27 [PATCH v3 0/4] aarch64: Allow overriding HWCAP_CPUID feature check Siddhesh Poyarekar
                   ` (3 preceding siblings ...)
  2017-05-25 20:27 ` [PATCH 1/4] tunables: Use glibc.tune.hwcap_mask tunable instead of _dl_hwcap_mask Siddhesh Poyarekar
@ 2017-05-26 20:13 ` Steve Ellcey
  4 siblings, 0 replies; 10+ messages in thread
From: Steve Ellcey @ 2017-05-26 20:13 UTC (permalink / raw)
  To: Siddhesh Poyarekar, libc-alpha; +Cc: adhemerval.zanella

On Fri, 2017-05-26 at 01:55 +0530, Siddhesh Poyarekar wrote:
> 
> I have not reposted the earlier 1/5, 2/5 and 4/5 since they have been acked.
> I'll push them in together with all these patches since it did not make sense to
> put them in isolation.
> 
> Tested on x86_64 and aarch64.

Siddhesh, does this mean that if I apply these four patches plus
patches 1, 2, and 4 from the earlier set (https://sourceware.org/ml/lib
c-alpha/2017-05/msg00570.html) then I should get the override
functionality?

I have applied those patches, the earlier patch 1 of 5 did not apply
cleanly but I think I fixed that by hand correctly and I had to fix up
the documentation problem that was mentioned in the email but the
override is not working correctly for me (or I am misunderstanding
things).

I wrote a small program to call __libc_ifunc_impl_list and see what
memcpy versions were available on thunderx.  I see both versions but
the usable flag is 0 for the thunderx version on my thunderx machine
even if I do not set HWCAP_MASK to anything.  When I build the library
with out --enable-tunable, then I get a usable flag of 1 for both
versions of memcpy which is what I would expect.  Are there any other
patches I need?

Steve Ellcey
sellcey@cavium.com

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [PATCH 1/4] tunables: Use glibc.tune.hwcap_mask tunable instead of _dl_hwcap_mask
  2017-05-25 20:27 ` [PATCH 1/4] tunables: Use glibc.tune.hwcap_mask tunable instead of _dl_hwcap_mask Siddhesh Poyarekar
@ 2017-05-30 21:21   ` Adhemerval Zanella
  2017-05-31  0:30     ` Siddhesh Poyarekar
  0 siblings, 1 reply; 10+ messages in thread
From: Adhemerval Zanella @ 2017-05-30 21:21 UTC (permalink / raw)
  To: Siddhesh Poyarekar, libc-alpha



On 25/05/2017 17:25, Siddhesh Poyarekar wrote:
> +
> +#include <elf/dl-tunables.h>
> +
> +#ifdef SHARED
> +# if HAVE_TUNABLES
> +#  define GET_HWCAP_MASK() TUNABLE_GET (glibc, tune, hwcap_mask, uint64_t)
> +# else

I think this patchset is missing the previous TUNABLE_GET one [1] (build
fail with --enable-tunables).

[1] https://sourceware.org/ml/libc-alpha/2017-05/msg00575.html

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [PATCH 1/4] tunables: Use glibc.tune.hwcap_mask tunable instead of _dl_hwcap_mask
  2017-05-30 21:21   ` Adhemerval Zanella
@ 2017-05-31  0:30     ` Siddhesh Poyarekar
  2017-05-31  0:49       ` Adhemerval Zanella
  0 siblings, 1 reply; 10+ messages in thread
From: Siddhesh Poyarekar @ 2017-05-31  0:30 UTC (permalink / raw)
  To: Adhemerval Zanella, libc-alpha

On Wednesday 31 May 2017 02:51 AM, Adhemerval Zanella wrote:
> On 25/05/2017 17:25, Siddhesh Poyarekar wrote:
>> +
>> +#include <elf/dl-tunables.h>
>> +
>> +#ifdef SHARED
>> +# if HAVE_TUNABLES
>> +#  define GET_HWCAP_MASK() TUNABLE_GET (glibc, tune, hwcap_mask, uint64_t)
>> +# else
> 
> I think this patchset is missing the previous TUNABLE_GET one [1] (build
> fail with --enable-tunables).

I did not repost 1/5, 2/5 and 4/5 since they were already acked.  I can
post the whole set again if you want.

4/5 in fact is independent and can be pushed.

Siddhesh

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [PATCH 1/4] tunables: Use glibc.tune.hwcap_mask tunable instead of _dl_hwcap_mask
  2017-05-31  0:30     ` Siddhesh Poyarekar
@ 2017-05-31  0:49       ` Adhemerval Zanella
  2017-05-31  1:06         ` Siddhesh Poyarekar
  0 siblings, 1 reply; 10+ messages in thread
From: Adhemerval Zanella @ 2017-05-31  0:49 UTC (permalink / raw)
  To: siddhesh, libc-alpha



On 30/05/2017 21:30, Siddhesh Poyarekar wrote:
> On Wednesday 31 May 2017 02:51 AM, Adhemerval Zanella wrote:
>> On 25/05/2017 17:25, Siddhesh Poyarekar wrote:
>>> +
>>> +#include <elf/dl-tunables.h>
>>> +
>>> +#ifdef SHARED
>>> +# if HAVE_TUNABLES
>>> +#  define GET_HWCAP_MASK() TUNABLE_GET (glibc, tune, hwcap_mask, uint64_t)
>>> +# else
>>
>> I think this patchset is missing the previous TUNABLE_GET one [1] (build
>> fail with --enable-tunables).
> 
> I did not repost 1/5, 2/5 and 4/5 since they were already acked.  I can
> post the whole set again if you want.
> 
> 4/5 in fact is independent and can be pushed.

I would prefer to maintain consistence and avoid trying to figure out in
which order should I apply the patches to actually test it.  So If I get it
right, I need to apply v2 patch 1 and patch2, v3 patch 1 to 4, and finally
v2 patch 5? 

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [PATCH 1/4] tunables: Use glibc.tune.hwcap_mask tunable instead of _dl_hwcap_mask
  2017-05-31  0:49       ` Adhemerval Zanella
@ 2017-05-31  1:06         ` Siddhesh Poyarekar
  0 siblings, 0 replies; 10+ messages in thread
From: Siddhesh Poyarekar @ 2017-05-31  1:06 UTC (permalink / raw)
  To: Adhemerval Zanella, libc-alpha

On Wednesday 31 May 2017 06:18 AM, Adhemerval Zanella wrote:
> I would prefer to maintain consistence and avoid trying to figure out in
> which order should I apply the patches to actually test it.  So If I get it
> right, I need to apply v2 patch 1 and patch2, v3 patch 1 to 4, and finally
> v2 patch 5? 

I'll just push 4/5 and resend the series.  Sorry I didn't realize how
much of a bother this would be :)

Siddhesh

^ permalink raw reply	[flat|nested] 10+ messages in thread

end of thread, other threads:[~2017-05-31  1:06 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-05-25 20:27 [PATCH v3 0/4] aarch64: Allow overriding HWCAP_CPUID feature check Siddhesh Poyarekar
2017-05-25 20:27 ` [PATCH 3/4] Make LD_HWCAP_MASK usable for static binaries Siddhesh Poyarekar
2017-05-25 20:27 ` [PATCH 2/4] aarch64: Allow overriding HWCAP_CPUID feature check using HWCAP_MASK Siddhesh Poyarekar
2017-05-25 20:27 ` [PATCH 4/4] aarch64: Add hwcap string routines Siddhesh Poyarekar
2017-05-25 20:27 ` [PATCH 1/4] tunables: Use glibc.tune.hwcap_mask tunable instead of _dl_hwcap_mask Siddhesh Poyarekar
2017-05-30 21:21   ` Adhemerval Zanella
2017-05-31  0:30     ` Siddhesh Poyarekar
2017-05-31  0:49       ` Adhemerval Zanella
2017-05-31  1:06         ` Siddhesh Poyarekar
2017-05-26 20:13 ` [PATCH v3 0/4] aarch64: Allow overriding HWCAP_CPUID feature check Steve Ellcey

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).