Blame SOURCES/0002-eal-fix-build-on-FreeBSD.patch

a6040a
From a5c9b9278cd4fa0b61db045ed19df449f07ab139 Mon Sep 17 00:00:00 2001
a6040a
From: Thomas Monjalon <thomas@monjalon.net>
a6040a
Date: Fri, 27 Apr 2018 03:49:19 +0200
a6040a
Subject: [PATCH 2/2] eal: fix build on FreeBSD
a6040a
a6040a
The auxiliary vector read is implemented only for Linux.
a6040a
It could be done with procstat_getauxv() for FreeBSD.
a6040a
a6040a
Since the commit below, the auxiliary vector functions
a6040a
are compiled for every architectures, including x86
a6040a
which is tested with FreeBSD.
a6040a
a6040a
This patch is moving the Linux implementation in Linux directory,
a6040a
and adding a fake/empty implementation for FreeBSD.
a6040a
a6040a
Fixes: 2ed9bf330709 ("eal: abstract away the auxiliary vector")
a6040a
a6040a
Signed-off-by: Thomas Monjalon <thomas@monjalon.net>
a6040a
Acked-by: Maxime Coquelin <maxime.coquelin@redhat.com>
a6040a
---
a6040a
 lib/librte_eal/bsdapp/eal/Makefile          |  1 +
a6040a
 lib/librte_eal/bsdapp/eal/eal_cpuflags.c    | 21 ++++++
a6040a
 lib/librte_eal/common/eal_common_cpuflags.c | 79 -------------------
a6040a
 lib/librte_eal/linuxapp/eal/Makefile        |  1 +
a6040a
 lib/librte_eal/linuxapp/eal/eal_cpuflags.c  | 84 +++++++++++++++++++++
a6040a
 7 files changed, 109 insertions(+), 79 deletions(-)
a6040a
 create mode 100644 lib/librte_eal/bsdapp/eal/eal_cpuflags.c
a6040a
 create mode 100644 lib/librte_eal/linuxapp/eal/eal_cpuflags.c
a6040a
a6040a
diff --git a/lib/librte_eal/bsdapp/eal/Makefile b/lib/librte_eal/bsdapp/eal/Makefile
a6040a
index 200285e01..3fd33f1e4 100644
a6040a
--- a/lib/librte_eal/bsdapp/eal/Makefile
a6040a
+++ b/lib/librte_eal/bsdapp/eal/Makefile
a6040a
@@ -25,6 +25,7 @@ LIBABIVER := 7
a6040a
 
a6040a
 # specific to bsdapp exec-env
a6040a
 SRCS-$(CONFIG_RTE_EXEC_ENV_BSDAPP) := eal.c
a6040a
+SRCS-$(CONFIG_RTE_EXEC_ENV_BSDAPP) += eal_cpuflags.c
a6040a
 SRCS-$(CONFIG_RTE_EXEC_ENV_BSDAPP) += eal_memory.c
a6040a
 SRCS-$(CONFIG_RTE_EXEC_ENV_BSDAPP) += eal_hugepage_info.c
a6040a
 SRCS-$(CONFIG_RTE_EXEC_ENV_BSDAPP) += eal_thread.c
a6040a
diff --git a/lib/librte_eal/bsdapp/eal/eal_cpuflags.c b/lib/librte_eal/bsdapp/eal/eal_cpuflags.c
a6040a
new file mode 100644
a6040a
index 000000000..69b161ea6
a6040a
--- /dev/null
a6040a
+++ b/lib/librte_eal/bsdapp/eal/eal_cpuflags.c
a6040a
@@ -0,0 +1,21 @@
a6040a
+/* SPDX-License-Identifier: BSD-3-Clause
a6040a
+ * Copyright 2018 Mellanox Technologies, Ltd
a6040a
+ */
a6040a
+
a6040a
+#include <rte_common.h>
a6040a
+#include <rte_cpuflags.h>
a6040a
+
a6040a
+unsigned long
a6040a
+rte_cpu_getauxval(unsigned long type __rte_unused)
a6040a
+{
a6040a
+	/* not implemented */
a6040a
+	return 0;
a6040a
+}
a6040a
+
a6040a
+int
a6040a
+rte_cpu_strcmp_auxval(unsigned long type __rte_unused,
a6040a
+		const char *str __rte_unused)
a6040a
+{
a6040a
+	/* not implemented */
a6040a
+	return -1;
a6040a
+}
a6040a
diff --git a/lib/librte_eal/common/eal_common_cpuflags.c b/lib/librte_eal/common/eal_common_cpuflags.c
a6040a
index 6a9dbaeb1..3a055f7c7 100644
a6040a
--- a/lib/librte_eal/common/eal_common_cpuflags.c
a6040a
+++ b/lib/librte_eal/common/eal_common_cpuflags.c
a6040a
@@ -2,90 +2,11 @@
a6040a
  *   OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
a6040a
  */
a6040a
 
a6040a
-#include <elf.h>
a6040a
-#include <fcntl.h>
a6040a
 #include <stdio.h>
a6040a
-#include <string.h>
a6040a
-#include <sys/stat.h>
a6040a
-#include <sys/types.h>
a6040a
-#include <unistd.h>
a6040a
-
a6040a
-#if defined(__GLIBC__) && defined(__GLIBC_PREREQ)
a6040a
-#if __GLIBC_PREREQ(2, 16)
a6040a
-#include <sys/auxv.h>
a6040a
-#define HAS_AUXV 1
a6040a
-#endif
a6040a
-#endif
a6040a
 
a6040a
 #include <rte_common.h>
a6040a
 #include <rte_cpuflags.h>
a6040a
 
a6040a
-#ifndef HAS_AUXV
a6040a
-static unsigned long
a6040a
-getauxval(unsigned long type __rte_unused)
a6040a
-{
a6040a
-	errno = ENOTSUP;
a6040a
-	return 0;
a6040a
-}
a6040a
-#endif
a6040a
-
a6040a
-#ifdef RTE_ARCH_64
a6040a
-typedef Elf64_auxv_t Internal_Elfx_auxv_t;
a6040a
-#else
a6040a
-typedef Elf32_auxv_t Internal_Elfx_auxv_t;
a6040a
-#endif
a6040a
-
a6040a
-
a6040a
-/**
a6040a
- * Provides a method for retrieving values from the auxiliary vector and
a6040a
- * possibly running a string comparison.
a6040a
- *
a6040a
- * @return Always returns a result.  When the result is 0, check errno
a6040a
- * to see if an error occurred during processing.
a6040a
- */
a6040a
-static unsigned long
a6040a
-_rte_cpu_getauxval(unsigned long type, const char *str)
a6040a
-{
a6040a
-	unsigned long val;
a6040a
-
a6040a
-	errno = 0;
a6040a
-	val = getauxval(type);
a6040a
-
a6040a
-	if (!val && (errno == ENOTSUP || errno == ENOENT)) {
a6040a
-		int auxv_fd = open("/proc/self/auxv", O_RDONLY);
a6040a
-		Internal_Elfx_auxv_t auxv;
a6040a
-
a6040a
-		if (auxv_fd == -1)
a6040a
-			return 0;
a6040a
-
a6040a
-		errno = ENOENT;
a6040a
-		while (read(auxv_fd, &auxv, sizeof(auxv)) == sizeof(auxv)) {
a6040a
-			if (auxv.a_type == type) {
a6040a
-				errno = 0;
a6040a
-				val = auxv.a_un.a_val;
a6040a
-				if (str)
a6040a
-					val = strcmp((const char *)val, str);
a6040a
-				break;
a6040a
-			}
a6040a
-		}
a6040a
-		close(auxv_fd);
a6040a
-	}
a6040a
-
a6040a
-	return val;
a6040a
-}
a6040a
-
a6040a
-unsigned long
a6040a
-rte_cpu_getauxval(unsigned long type)
a6040a
-{
a6040a
-	return _rte_cpu_getauxval(type, NULL);
a6040a
-}
a6040a
-
a6040a
-int
a6040a
-rte_cpu_strcmp_auxval(unsigned long type, const char *str)
a6040a
-{
a6040a
-	return _rte_cpu_getauxval(type, str);
a6040a
-}
a6040a
-
a6040a
 /**
a6040a
  * Checks if the machine is adequate for running the binary. If it is not, the
a6040a
  * program exits with status 1.
a6040a
diff --git a/lib/librte_eal/linuxapp/eal/Makefile b/lib/librte_eal/linuxapp/eal/Makefile
a6040a
index 45517a27b..3719ec9d7 100644
a6040a
--- a/lib/librte_eal/linuxapp/eal/Makefile
a6040a
+++ b/lib/librte_eal/linuxapp/eal/Makefile
a6040a
@@ -30,6 +30,7 @@ endif
a6040a
 
a6040a
 # specific to linuxapp exec-env
a6040a
 SRCS-$(CONFIG_RTE_EXEC_ENV_LINUXAPP) := eal.c
a6040a
+SRCS-$(CONFIG_RTE_EXEC_ENV_LINUXAPP) += eal_cpuflags.c
a6040a
 SRCS-$(CONFIG_RTE_EXEC_ENV_LINUXAPP) += eal_hugepage_info.c
a6040a
 SRCS-$(CONFIG_RTE_EXEC_ENV_LINUXAPP) += eal_memory.c
a6040a
 SRCS-$(CONFIG_RTE_EXEC_ENV_LINUXAPP) += eal_thread.c
a6040a
diff --git a/lib/librte_eal/linuxapp/eal/eal_cpuflags.c b/lib/librte_eal/linuxapp/eal/eal_cpuflags.c
a6040a
new file mode 100644
a6040a
index 000000000..d38296e1e
a6040a
--- /dev/null
a6040a
+++ b/lib/librte_eal/linuxapp/eal/eal_cpuflags.c
a6040a
@@ -0,0 +1,84 @@
a6040a
+/* SPDX-License-Identifier: BSD-3-Clause
a6040a
+ * Copyright 2018 Red Hat, Inc.
a6040a
+ */
a6040a
+
a6040a
+#include <elf.h>
a6040a
+#include <fcntl.h>
a6040a
+#include <string.h>
a6040a
+#include <sys/stat.h>
a6040a
+#include <sys/types.h>
a6040a
+#include <unistd.h>
a6040a
+
a6040a
+#if defined(__GLIBC__) && defined(__GLIBC_PREREQ)
a6040a
+#if __GLIBC_PREREQ(2, 16)
a6040a
+#include <sys/auxv.h>
a6040a
+#define HAS_AUXV 1
a6040a
+#endif
a6040a
+#endif
a6040a
+
a6040a
+#include <rte_cpuflags.h>
a6040a
+
a6040a
+#ifndef HAS_AUXV
a6040a
+static unsigned long
a6040a
+getauxval(unsigned long type __rte_unused)
a6040a
+{
a6040a
+	errno = ENOTSUP;
a6040a
+	return 0;
a6040a
+}
a6040a
+#endif
a6040a
+
a6040a
+#ifdef RTE_ARCH_64
a6040a
+typedef Elf64_auxv_t Internal_Elfx_auxv_t;
a6040a
+#else
a6040a
+typedef Elf32_auxv_t Internal_Elfx_auxv_t;
a6040a
+#endif
a6040a
+
a6040a
+/**
a6040a
+ * Provides a method for retrieving values from the auxiliary vector and
a6040a
+ * possibly running a string comparison.
a6040a
+ *
a6040a
+ * @return Always returns a result.  When the result is 0, check errno
a6040a
+ * to see if an error occurred during processing.
a6040a
+ */
a6040a
+static unsigned long
a6040a
+_rte_cpu_getauxval(unsigned long type, const char *str)
a6040a
+{
a6040a
+	unsigned long val;
a6040a
+
a6040a
+	errno = 0;
a6040a
+	val = getauxval(type);
a6040a
+
a6040a
+	if (!val && (errno == ENOTSUP || errno == ENOENT)) {
a6040a
+		int auxv_fd = open("/proc/self/auxv", O_RDONLY);
a6040a
+		Internal_Elfx_auxv_t auxv;
a6040a
+
a6040a
+		if (auxv_fd == -1)
a6040a
+			return 0;
a6040a
+
a6040a
+		errno = ENOENT;
a6040a
+		while (read(auxv_fd, &auxv, sizeof(auxv)) == sizeof(auxv)) {
a6040a
+			if (auxv.a_type == type) {
a6040a
+				errno = 0;
a6040a
+				val = auxv.a_un.a_val;
a6040a
+				if (str)
a6040a
+					val = strcmp((const char *)val, str);
a6040a
+				break;
a6040a
+			}
a6040a
+		}
a6040a
+		close(auxv_fd);
a6040a
+	}
a6040a
+
a6040a
+	return val;
a6040a
+}
a6040a
+
a6040a
+unsigned long
a6040a
+rte_cpu_getauxval(unsigned long type)
a6040a
+{
a6040a
+	return _rte_cpu_getauxval(type, NULL);
a6040a
+}
a6040a
+
a6040a
+int
a6040a
+rte_cpu_strcmp_auxval(unsigned long type, const char *str)
a6040a
+{
a6040a
+	return _rte_cpu_getauxval(type, str);
a6040a
+}
a6040a
-- 
a6040a
2.17.0
a6040a