Blame SOURCES/0014-build-fix-architecture-detection.patch

b4fabd
From ff77a85c28564d939d554ba264480d1876cbc316 Mon Sep 17 00:00:00 2001
b4fabd
From: Thomas Petazzoni <thomas.petazzoni@free-electrons.com>
b4fabd
Date: Sat, 6 Aug 2016 11:02:43 +0200
b4fabd
Subject: [PATCH 14/16] build: fix architecture detection
b4fabd
b4fabd
The current architecture detection, based on the "host_cpu" part of the
b4fabd
tuple does not work properly for a number of reason:
b4fabd
b4fabd
 - The code assumes that if host_cpu starts with "arm" then ARM
b4fabd
   instructions are available, which is incorrect. Indeed, Cortex-M
b4fabd
   platforms can run Linux, they are ARM platforms (so host_cpu = arm),
b4fabd
   but they don't support ARM instructions: they support only the
b4fabd
   Thumb-2 instruction set.
b4fabd
b4fabd
 - The armv7 case is also not very useful, as it is not standard at all
b4fabd
   to pass armv7 as host_cpu even if the host system is actually ARMv7
b4fabd
   based.
b4fabd
b4fabd
 - For the same reason, the armv8 case is not very useful: ARMv8 is
b4fabd
   AArch64, and there is already a separate case to handle this
b4fabd
   architecture.
b4fabd
b4fabd
So, this commit moves away from a host_cpu based logic, and instead
b4fabd
tests using AC_CHECK_DECLS() the built-in definitions of the compiler:
b4fabd
b4fabd
 - If we have __ARM_ARCH_ISA_ARM defined, then it's an ARM processor
b4fabd
   that supports the ARM instruction set (this allows to exclude Thumb-2
b4fabd
   only processors).
b4fabd
b4fabd
 - If we have __ARM_ARCH_7A__, then we have an ARMv7-A processor, and
b4fabd
   we can enable the corresponding optimizations
b4fabd
b4fabd
 - Same for __aarch64__, __i386__ and __x86_64__.
b4fabd
b4fabd
In addition, we remove the AC_MSG_ERROR() that makes the build fail for
b4fabd
all architectures but the ones that are explicitly supported. Indeed,
b4fabd
webrtc-audio-processing builds just fine for other architectures (tested
b4fabd
on MIPS), it's just that none of the architecture-specific optimizations
b4fabd
will be used.
b4fabd
b4fabd
Signed-off-by: Thomas Petazzoni <thomas.petazzoni@free-electrons.com>
b4fabd
---
b4fabd
 configure.ac | 35 +++++++++++------------------------
b4fabd
 1 file changed, 11 insertions(+), 24 deletions(-)
b4fabd
b4fabd
diff --git a/configure.ac b/configure.ac
b4fabd
index b4b9ddf..acbb3e2 100644
b4fabd
--- a/configure.ac
b4fabd
+++ b/configure.ac
b4fabd
@@ -83,30 +83,17 @@ AC_SUBST(PLATFORM_CFLAGS)
b4fabd
 AM_CONDITIONAL(HAVE_POSIX, [test "x${HAVE_POSIX}" = "x1"])
b4fabd
 AM_CONDITIONAL(HAVE_WIN, [test "x${HAVE_WIN}" = "x1"])
b4fabd
 
b4fabd
-AS_CASE(["${host_cpu}"],
b4fabd
-    [i?86|x86_64],
b4fabd
-        [
b4fabd
-         HAVE_X86=1
b4fabd
-        ],
b4fabd
-    [armv7*|armv8*],
b4fabd
-        [
b4fabd
-         HAVE_ARM=1
b4fabd
-         HAVE_ARMV7=1
b4fabd
-         ARCH_CFLAGS="-DWEBRTC_ARCH_ARM -DWEBRTC_ARCH_ARM_V7"
b4fabd
-        ],
b4fabd
-    [arm*],
b4fabd
-        [
b4fabd
-         HAVE_ARM=1
b4fabd
-         ARCH_CFLAGS="-DWEBRTC_ARCH_ARM"
b4fabd
-        ],
b4fabd
-    [aarch64*],
b4fabd
-        [
b4fabd
-         HAVE_NEON=1
b4fabd
-         ARCH_CFLAGS="-DWEBRTC_HAS_NEON -DWEBRTC_ARCH_ARM64"
b4fabd
-        ],
b4fabd
-    # FIXME: Add MIPS support, see webrtc/BUILD.gn for defines
b4fabd
-    [AC_MSG_ERROR([Unsupported CPU type $host_cpu])]
b4fabd
-)
b4fabd
+# Testing __ARM_ARCH_ISA_ARM since the code contains ARM instructions,
b4fabd
+# which don't work on Thumb-2 only platforms (ARMv7-M).
b4fabd
+AC_CHECK_DECLS([__ARM_ARCH_ISA_ARM],
b4fabd
+	[HAVE_ARM=1; ARCH_CFLAGS="${ARCH_CFLAGS} -DWEBRTC_ARCH_ARM"])
b4fabd
+AC_CHECK_DECLS([__ARM_ARCH_7A__],
b4fabd
+	[HAVE_ARMV7=1; ARCH_CFLAGS="${ARCH_CFLAGS} -DWEBRTC_ARCH_ARM_V7"])
b4fabd
+AC_CHECK_DECLS([__aarch64__],
b4fabd
+	[HAVE_NEON=1; ARCH_CFLAGS="${ARCH_CFLAGS} -DWEBRTC_HAS_NEON -DWEBRTC_ARCH_ARM64"])
b4fabd
+AC_CHECK_DECLS([__i386__], [HAVE_X86=1])
b4fabd
+AC_CHECK_DECLS([__x86_64__], [HAVE_X86=1])
b4fabd
+
b4fabd
 AM_CONDITIONAL(HAVE_X86, [test "x${HAVE_X86}" = "x1"])
b4fabd
 AM_CONDITIONAL(HAVE_ARM, [test "x${HAVE_ARM}" = "x1"])
b4fabd
 AM_CONDITIONAL(HAVE_ARMV7, [test "x${HAVE_ARMV7}" = "x1"])
b4fabd
-- 
b4fabd
2.14.3
b4fabd