commit:     60b38d402d8674ea08c9b69cf3147e0b92ab87c2
Author:     Sam James <sam <AT> gentoo <DOT> org>
AuthorDate: Wed Mar 15 02:13:59 2023 +0000
Commit:     Sam James <sam <AT> gentoo <DOT> org>
CommitDate: Wed Mar 15 02:14:48 2023 +0000
URL:        https://gitweb.gentoo.org/repo/gentoo.git/commit/?id=60b38d40

media-video/ffmpeg: fix build on register-starved x86

Newer compilers may optimise such that < 7 registers are free on 32-bit x86
and then we get an "invalid asm" error. This is https://bugs.gentoo.org/901099
and https://trac.ffmpeg.org/ticket/8903.

Making matters worse, GCC sometimes hangs on invalid asm, so this also
mitigates a hang with e.g. -O3 -march=znver1. See https://bugs.gentoo.org/900937
and https://gcc.gnu.org/bugzilla/show_bug.cgi?id=109137.

In future, we may want to adjust the definition of HAVE_7REGS to just exclude
32-bit x86, but that's a big sledgehammer, so let's avoid it for now until we 
have
a reply on the upstream ffmpeg bug.

Thanks to Ninpo.

Bug: https://trac.ffmpeg.org/ticket/8903
Bug: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=109137
Bug: https://bugs.gentoo.org/900937
Closes: https://bugs.gentoo.org/901099
Signed-off-by: Sam James <sam <AT> gentoo.org>

 media-video/ffmpeg/ffmpeg-4.4.3.ebuild             |  3 ++-
 media-video/ffmpeg/ffmpeg-5.1.2-r1.ebuild          |  3 ++-
 media-video/ffmpeg/ffmpeg-6.0.ebuild               |  3 ++-
 .../ffmpeg-4.4.3-get_cabac_inline_x86-32-bit.patch | 24 +++++++++++++++++++++
 .../ffmpeg-5.1.2-get_cabac_inline_x86-32-bit.patch | 25 ++++++++++++++++++++++
 5 files changed, 55 insertions(+), 3 deletions(-)

diff --git a/media-video/ffmpeg/ffmpeg-4.4.3.ebuild 
b/media-video/ffmpeg/ffmpeg-4.4.3.ebuild
index 3a700cb2f82f..1eaa8af96b91 100644
--- a/media-video/ffmpeg/ffmpeg-4.4.3.ebuild
+++ b/media-video/ffmpeg/ffmpeg-4.4.3.ebuild
@@ -1,4 +1,4 @@
-# Copyright 1999-2022 Gentoo Authors
+# Copyright 1999-2023 Gentoo Authors
 # Distributed under the terms of the GNU General Public License v2
 
 EAPI=8
@@ -333,6 +333,7 @@ PATCHES=(
        "${FILESDIR}"/chromium-r1.patch
        "${FILESDIR}"/${PN}-5.0-backport-ranlib-build-fix.patch
        "${FILESDIR}"/${P}-clang-14-ff_seek_frame_binary-crash.patch
+       "${FILESDIR}"/${PN}-4.4.3-get_cabac_inline_x86-32-bit.patch
 )
 
 MULTILIB_WRAPPED_HEADERS=(

diff --git a/media-video/ffmpeg/ffmpeg-5.1.2-r1.ebuild 
b/media-video/ffmpeg/ffmpeg-5.1.2-r1.ebuild
index ebfee785a3f4..3d21b79ce2d7 100644
--- a/media-video/ffmpeg/ffmpeg-5.1.2-r1.ebuild
+++ b/media-video/ffmpeg/ffmpeg-5.1.2-r1.ebuild
@@ -336,7 +336,8 @@ S=${WORKDIR}/${P/_/-}
 
 PATCHES=(
        "${FILESDIR}"/chromium-r1.patch
-       "${FILESDIR}/${P}-vulkan.patch"
+       "${FILESDIR}"/${P}-vulkan.patch
+       "${FILESDIR}"/${PN}-5.1.2-get_cabac_inline_x86-32-bit.patch
 )
 
 MULTILIB_WRAPPED_HEADERS=(

diff --git a/media-video/ffmpeg/ffmpeg-6.0.ebuild 
b/media-video/ffmpeg/ffmpeg-6.0.ebuild
index 5cc3230259b2..eee97981c06f 100644
--- a/media-video/ffmpeg/ffmpeg-6.0.ebuild
+++ b/media-video/ffmpeg/ffmpeg-6.0.ebuild
@@ -336,7 +336,8 @@ S=${WORKDIR}/${P/_/-}
 
 PATCHES=(
        "${FILESDIR}"/chromium-r1.patch
-       "${FILESDIR}/${P}-DECLARE_ALIGNED.patch"
+       "${FILESDIR}"/${P}-DECLARE_ALIGNED.patch
+       "${FILESDIR}"/${PN}-5.1.2-get_cabac_inline_x86-32-bit.patch
 )
 
 MULTILIB_WRAPPED_HEADERS=(

diff --git 
a/media-video/ffmpeg/files/ffmpeg-4.4.3-get_cabac_inline_x86-32-bit.patch 
b/media-video/ffmpeg/files/ffmpeg-4.4.3-get_cabac_inline_x86-32-bit.patch
new file mode 100644
index 000000000000..ed273975452d
--- /dev/null
+++ b/media-video/ffmpeg/files/ffmpeg-4.4.3-get_cabac_inline_x86-32-bit.patch
@@ -0,0 +1,24 @@
+https://bugs.gentoo.org/901099 and partly https://bugs.gentoo.org/900937.
+
+Newer compilers may optimise such that < 7 registers are free on 32-bit x86
+and then we get an "invalid asm" error. This is https://bugs.gentoo.org/901099
+and https://trac.ffmpeg.org/ticket/8903.
+
+Making matters worse, GCC sometimes hangs on invalid asm, so this also
+mitigates a hang with e.g. -O3 -march=znver1. See 
https://bugs.gentoo.org/900937
+and https://gcc.gnu.org/bugzilla/show_bug.cgi?id=109137.
+
+In future, we may want to adjust the definition of HAVE_7REGS to just exclude
+32-bit x86, but that's a big sledgehammer, so let's avoid it for now until we 
have
+a reply on the upstream ffmpeg bug.
+--- a/libavcodec/x86/cabac.h
++++ b/libavcodec/x86/cabac.h
+@@ -175,7 +175,7 @@
+ 
+ #endif /* BROKEN_RELOCATIONS */
+ 
+-#if HAVE_7REGS && !BROKEN_COMPILER
++#if HAVE_7REGS && !BROKEN_COMPILER && !ARCH_X86_32
+ #define get_cabac_inline get_cabac_inline_x86
+ static av_always_inline int get_cabac_inline_x86(CABACContext *c,
+                                                  uint8_t *const state)

diff --git 
a/media-video/ffmpeg/files/ffmpeg-5.1.2-get_cabac_inline_x86-32-bit.patch 
b/media-video/ffmpeg/files/ffmpeg-5.1.2-get_cabac_inline_x86-32-bit.patch
new file mode 100644
index 000000000000..40db3304b564
--- /dev/null
+++ b/media-video/ffmpeg/files/ffmpeg-5.1.2-get_cabac_inline_x86-32-bit.patch
@@ -0,0 +1,25 @@
+https://bugs.gentoo.org/901099 and partly https://bugs.gentoo.org/900937.
+
+Newer compilers may optimise such that < 7 registers are free on 32-bit x86
+and then we get an "invalid asm" error. This is https://bugs.gentoo.org/901099
+and https://trac.ffmpeg.org/ticket/8903.
+
+Making matters worse, GCC sometimes hangs on invalid asm, so this also
+mitigates a hang with e.g. -O3 -march=znver1. See 
https://bugs.gentoo.org/900937
+and https://gcc.gnu.org/bugzilla/show_bug.cgi?id=109137.
+
+In future, we may want to adjust the definition of HAVE_7REGS to just exclude
+32-bit x86, but that's a big sledgehammer, so let's avoid it for now until we 
have
+a reply on the upstream ffmpeg bug.
+--- a/libavcodec/x86/cabac.h
++++ b/libavcodec/x86/cabac.h
+@@ -175,7 +175,7 @@
+
+ #endif /* BROKEN_RELOCATIONS */
+
+-#if HAVE_7REGS && !BROKEN_COMPILER
++#if HAVE_7REGS && !BROKEN_COMPILER && !ARCH_X86_32
+ #define get_cabac_inline get_cabac_inline_x86
+ static
+ #if defined(_WIN32) && !defined(_WIN64) && defined(__clang__)
+

Reply via email to