This is the mail archive of the
libc-alpha@sourceware.org
mailing list for the glibc project.
[PATCH] Consolidate code to get hwcap_mask into GET_HWCAP_MASK macro
- From: Siddhesh Poyarekar <siddhesh at sourceware dot org>
- To: libc-alpha at sourceware dot org
- Cc: adhemerval dot zanella at linaro dot org
- Date: Fri, 19 May 2017 02:12:49 +0530
- Subject: [PATCH] Consolidate code to get hwcap_mask into GET_HWCAP_MASK macro
- Authentication-results: sourceware.org; auth=none
Consolidate the preprocessor conditionals to get the HWCAP_MASK with
or without tunables into a single macro defined in a new header file
dl-hwcaps.h.
* elf/dl-hwcaps.h: New file.
* elf/dl-hwcaps.c: Include dl-hwcaps.h.
(_dl_important_hwcaps) Use new GET_HWCAP_MASK macro.
* sysdeps/sparc/sparc32/dl-machine.h: Likewise.
* sysdeps/unix/sysv/linux/aarch64/cpu-features.c: Likewise.
---
elf/dl-hwcaps.c | 7 ++-----
elf/dl-hwcaps.h | 25 +++++++++++++++++++++++++
sysdeps/sparc/sparc32/dl-machine.h | 9 ++-------
sysdeps/unix/sysv/linux/aarch64/cpu-features.c | 9 ++-------
4 files changed, 31 insertions(+), 19 deletions(-)
create mode 100644 elf/dl-hwcaps.h
diff --git a/elf/dl-hwcaps.c b/elf/dl-hwcaps.c
index 2b9f7f1..a37a3ff 100644
--- a/elf/dl-hwcaps.c
+++ b/elf/dl-hwcaps.c
@@ -25,6 +25,7 @@
#include <dl-procinfo.h>
#include <dl-tunables.h>
+#include <dl-hwcaps.h>
#ifdef _DL_FIRST_PLATFORM
# define _DL_FIRST_EXTRA (_DL_FIRST_PLATFORM + _DL_PLATFORMS_COUNT)
@@ -38,11 +39,7 @@ internal_function
_dl_important_hwcaps (const char *platform, size_t platform_len, size_t *sz,
size_t *max_capstrlen)
{
-#if HAVE_TUNABLES
- uint64_t hwcap_mask = TUNABLE_GET (glibc, tune, hwcap_mask, uint64_t);
-#else
- uint64_t hwcap_mask = GLRO(dl_hwcap_mask);
-#endif
+ uint64_t hwcap_mask = GET_HWCAP_MASK();
/* Determine how many important bits are set. */
uint64_t masked = GLRO(dl_hwcap) & hwcap_mask;
size_t cnt = platform != NULL;
diff --git a/elf/dl-hwcaps.h b/elf/dl-hwcaps.h
new file mode 100644
index 0000000..0fd05ac
--- /dev/null
+++ b/elf/dl-hwcaps.h
@@ -0,0 +1,25 @@
+/* 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>
+
+#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
diff --git a/sysdeps/sparc/sparc32/dl-machine.h b/sysdeps/sparc/sparc32/dl-machine.h
index f5e8078..620cd2e 100644
--- a/sysdeps/sparc/sparc32/dl-machine.h
+++ b/sysdeps/sparc/sparc32/dl-machine.h
@@ -27,7 +27,7 @@
#include <sysdep.h>
#include <tls.h>
#include <dl-plt.h>
-#include <elf/dl-tunables.h>
+#include <elf/dl-hwcaps.h>
/* Return nonzero iff ELF header is compatible with the running host. */
static inline int
@@ -39,12 +39,7 @@ elf_machine_matches_host (const Elf32_Ehdr *ehdr)
{
/* XXX The following is wrong! Dave Miller rejected to implement it
correctly. If this causes problems shoot *him*! */
-#ifdef SHARED
-# if HAVE_TUNABLES
- uint64_t hwcap_mask = TUNABLE_GET (glibc, tune, hwcap_mask, uint64_t);
-# else
- uint64_t hwcap_mask = GLRO(dl_hwcap_mask);
-# endif
+ uint64_t hwcap_mask = GET_HWCAP_MASK();
return GLRO(dl_hwcap) & hwcap_mask & HWCAP_SPARC_V9;
#else
return GLRO(dl_hwcap) & HWCAP_SPARC_V9;
diff --git a/sysdeps/unix/sysv/linux/aarch64/cpu-features.c b/sysdeps/unix/sysv/linux/aarch64/cpu-features.c
index 0478fcc..ef6eecd 100644
--- a/sysdeps/unix/sysv/linux/aarch64/cpu-features.c
+++ b/sysdeps/unix/sysv/linux/aarch64/cpu-features.c
@@ -18,17 +18,12 @@
#include <cpu-features.h>
#include <sys/auxv.h>
-#include <elf/dl-tunables.h>
+#include <elf/dl-hwcaps.h>
static inline void
init_cpu_features (struct cpu_features *cpu_features)
{
-#if HAVE_TUNABLES
- uint64_t hwcap_mask = TUNABLE_GET (glibc, tune, hwcap_mask, uint64_t);
-#else
- uint64_t hwcap_mask = GLRO (dl_hwcap_mask);
-#endif
-
+ uint64_t hwcap_mask = GET_HWCAP_MASK();
uint64_t hwcap = GLRO (dl_hwcap) & hwcap_mask;
if (hwcap & HWCAP_CPUID)
--
2.7.4