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

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