Pārlūkot izejas kodu

package/x265: fix runtime issue on ARMv6, ensure correctness on ARMv7

The build logic in source/cmake/FindNeon.cmake caused the x265 build
system to always think that the CPU supports neon: it was looking in
/proc/cpuinfo, which of course is wrong when cross-compilation, but
then the sequence of grep was interacting badly with CMake, causing
the build system to always conclude that the CPU supports NEON.

This causes runtime issues on ARMv6.

Setting -DCROSS_COMPILE_ARM=1 fixes this, as it tells the x265 build
system we are cross-compiling and it skips its bogus NEON check. So
for ARMv6, we pass -DCROSS_COMPILE_ARM=1.

But then, we still want NEON for ARMv7 processors with NEON, so this
commit adds a patch that allows to explicitly specify whether the CPU
supports NEON, in the -DCROSS_COMPILE_ARM=1 case, and we use this
option when BR2_ARM_CPU_HAS_NEON.

For those wondering why -DCROSS_COMPILE_ARM=1 is not passed for all
ARM platforms: it's because from the perspective of x265, only ARM >=
v6 is ARM: it has assembly code that needs at least ARMv6. Earlier ARM
platforms are not detected as ARM by the x265 build logic, and
therefore fallback on generic code.

This has been build-tested on:
- ARMv5: generic code is used, no assembly
- ARMv6: assembly code is used, but not with NEON support
- ARMv7 with NEON: assembly code is used, with NEON support

Reported-by: David Barbion <davidb@230ruedubac.fr>
Signed-off-by: Thomas Petazzoni <thomas.petazzoni@bootlin.com>
Thomas Petazzoni 1 gadu atpakaļ
vecāks
revīzija
1fbd26f831

+ 40 - 0
package/x265/0002-source-CMakeLists.txt-allow-setting-CPU_HAS_NEON-whe.patch

@@ -0,0 +1,40 @@
+From 0088d29e7c75ea7f100a100aea4e2a797469427f Mon Sep 17 00:00:00 2001
+From: Thomas Petazzoni <thomas.petazzoni@bootlin.com>
+Date: Sat, 13 Jul 2024 10:10:54 +0200
+Subject: [PATCH] source/CMakeLists.txt: allow setting CPU_HAS_NEON when
+ CROSS_COMPILE_ARM
+
+The logic in source/cmake/FindNeon.cmake is not appropriate for
+cross-compilation scenarios, so in order to allow cross-compiling for
+ARM, CROSS_COMPILE_ARM needs to be defined. However that currently
+doesn't allow the enabling of NEON support, so let's allow the user to
+manually set CPU_HAS_NEON in this case.
+
+Upstream: https://bitbucket.org/multicoreware/x265_git/pull-requests/26
+Signed-off-by: Thomas Petazzoni <thomas.petazzoni@bootlin.com>
+---
+ source/CMakeLists.txt | 7 ++++++-
+ 1 file changed, 6 insertions(+), 1 deletion(-)
+
+diff --git a/source/CMakeLists.txt b/source/CMakeLists.txt
+index a34bf4d4f..072bf62ab 100755
+--- a/source/CMakeLists.txt
++++ b/source/CMakeLists.txt
+@@ -239,8 +239,13 @@ if(GCC)
+         endif()
+     endif()
+     if(ARM AND CROSS_COMPILE_ARM)
+-        set(ARM_ARGS -fPIC)
+         message(STATUS "cross compile arm")
++        if(CPU_HAS_NEON)
++          set(ARM_ARGS -mfpu=neon -fPIC)
++          add_definitions(-DHAVE_NEON)
++        else()
++	  set(ARM_ARGS -fPIC)
++	endif()
+     elseif(ARM)
+         if(ARM64)
+             set(ARM_ARGS -fPIC)
+-- 
+2.45.2
+

+ 14 - 0
package/x265/x265.mk

@@ -13,6 +13,20 @@ X265_CPE_ID_VENDOR = multicorewareinc
 X265_SUBDIR = source
 X265_INSTALL_STAGING = YES
 
+# For CPUs before ARMv6, x265 does not consider them "ARM" but generic
+# CPUs for which no optimized assembly is provided, hence we don't
+# pass -DCROSS_COMPILE_ARM=1.
+ifeq ($(BR2_ARM_CPU_ARMV6),y)
+X265_CONF_OPTS += -DCROSS_COMPILE_ARM=1
+endif
+
+ifeq ($(BR2_ARM_CPU_ARMV7A),y)
+X265_CONF_OPTS += -DCROSS_COMPILE_ARM=1
+ifeq ($(BR2_ARM_CPU_HAS_NEON),y)
+X265_CONF_OPTS += -DCPU_HAS_NEON=1
+endif
+endif
+
 ifeq ($(BR2_i386)$(BR2_x86_64),y)
 X265_DEPENDENCIES += host-nasm
 endif