Gentoo Websites Logo
Go to: Gentoo Home Documentation Forums Lists Bugs Planet Store Wiki Get Gentoo!
Bug 915384 - media-video/ffmpeg-4.4.4-r4: Crash when decoding AAC files with unset CPU_FLAGS_X86
Summary: media-video/ffmpeg-4.4.4-r4: Crash when decoding AAC files with unset CPU_FLA...
Status: IN_PROGRESS
Alias: None
Product: Gentoo Linux
Classification: Unclassified
Component: Current packages (show other bugs)
Hardware: AMD64 Linux
: Normal critical (vote)
Assignee: Gentoo Media-video project
URL:
Whiteboard:
Keywords:
: 918964 (view as bug list)
Depends on: 926151
Blocks: gcc-13
  Show dependency tree
 
Reported: 2023-10-08 14:27 UTC by realmariomario456
Modified: 2024-03-04 10:07 UTC (History)
4 users (show)

See Also:
Package list:
Runtime testing required: ---


Attachments
Backtrace (backtrace.log%0A,9.28 KB, text/plain)
2023-10-08 14:27 UTC, realmariomario456
Details
emerge --info (debug make.conf) (emerge-info-debug.txt,6.93 KB, text/plain)
2023-10-08 14:27 UTC, realmariomario456
Details
emerge --info (standard make.conf) (emerge-info.txt,6.89 KB, text/plain)
2023-10-08 14:28 UTC, realmariomario456
Details
strace (strace.log,159.79 KB, text/x-log)
2023-10-08 14:28 UTC, realmariomario456
Details
emerge -pv and emege --info for ffmpeg (ffmpeg_emerge_pv_info.txt,10.69 KB, text/plain)
2023-12-22 13:59 UTC, publiccontact2020
Details

Note You need to log in before you can comment on or make changes to this bug.
Description realmariomario456 2023-10-08 14:27:19 UTC
Created attachment 872336 [details]
Backtrace

This wasn't happening to me before, but now when FFmpeg tries to decode AAC (always with the FFmpeg command-line tool, most of the time with Audacity) it results in a crash. I've attached a full backtrace, strace and two emerge --infos (one is for my debugging make.conf, the other is for my standard make.conf) in this bug report. I assure this bug happens with both of my make.confs.
Comment 1 realmariomario456 2023-10-08 14:27:45 UTC
Created attachment 872337 [details]
emerge --info (debug make.conf)
Comment 2 realmariomario456 2023-10-08 14:28:08 UTC
Created attachment 872338 [details]
emerge --info (standard make.conf)
Comment 3 realmariomario456 2023-10-08 14:28:29 UTC
Created attachment 872339 [details]
strace
Comment 4 Sam James archtester Gentoo Infrastructure gentoo-dev Security 2023-10-09 00:55:44 UTC
Thanks.

We've seen this come up a few times recently.

My guess is the reason it's happening (more) now is gcc 13 being recently stabled.

It seems to be related to a mismatch between CPU_FLAGS_X86 and CFLAGS -march. Someone gave us Valgrind output before and it looked fairly clearly like an alignment problem.

For a workaround: please set CPU_FLAGS_X86 per app-portage/cpuid2cpuflags output.
Comment 5 Paul Zander 2023-10-09 08:37:53 UTC
From your emerge --info:
> CPU_FLAGS_X86="mmx mmxext sse sse2"
So that's the immediate cause.
Comment 6 realmariomario456 2023-10-25 20:09:08 UTC
(In reply to Sam James from comment #4)
> Thanks.
> 
> We've seen this come up a few times recently.
> 
> My guess is the reason it's happening (more) now is gcc 13 being recently
> stabled.
> 
> It seems to be related to a mismatch between CPU_FLAGS_X86 and CFLAGS
> -march. Someone gave us Valgrind output before and it looked fairly clearly
> like an alignment problem.
> 
> For a workaround: please set CPU_FLAGS_X86 per app-portage/cpuid2cpuflags
> output.

(In reply to Paul Zander from comment #5)
> From your emerge --info:
> > CPU_FLAGS_X86="mmx mmxext sse sse2"
> So that's the immediate cause.

Sorry for the late reply, I wasn't bothered to se CPU_FLAGS_X86 until now. But I've set it and the crash went away. This seems to prove that the crash is ebuild or GCC 13-related.
Comment 7 Matthias Hanft 2023-10-29 16:48:45 UTC
Can confirm a) the error and b) the workaround.

With gcc 12, everything runs fine - just like that.

With gcc 13 and just the usual

CFLAGS="-march=native -O2 -pipe"
CXXFLAGS="${CFLAGS}"
MAKEOPTS="-j2"
CHOST="x86_64-pc-linux-gnu"

I get

Oct 29 11:16:08 home01 kernel: traps: minidlnad[11961] general protection fault ip:7f44fcc1e2ea sp:7f44fbf48e20 error:0 in 
libavcodec.so.60.3.100[7f44fcbb2000+73b000]

and

Oct 29 17:02:12 home01 kernel: traps: ffmpeg[25236] general protection fault ip:7f349ddb12ea sp:7fff1726b400 error:0 in libavcodec.so.60.3.100[7f349dd45000+73b000]

With gcc 13 and additional

CPU_FLAGS_X86="aes avx avx2 f16c fma3 mmx mmxext pclmul popcnt rdrand sse sse2 sse3 sse4_1 sse4_2 ssse3"

(the output of cpuid2cpuflags), everything runs fine with gcc 13, too.

Here are the cpu_flags differences (equery u ffmpeg):

 U I
 - - cpu_flags_x86_3dnow    : Use the 3DNow! instruction set
 - - cpu_flags_x86_3dnowext : Use the Enhanced 3DNow! instruction set
 + - cpu_flags_x86_aes      : Enable support for Intel's AES instruction set (AES-NI)
 + - cpu_flags_x86_avx      : Adds support for Advanced Vector Extensions instructions
 + - cpu_flags_x86_avx2     : Adds support for Advanced Vector Extensions 2 instructions
 + - cpu_flags_x86_fma3     : Use the Fused Multiply Add 3 instruction set ([fma] in cpuinfo)
 - - cpu_flags_x86_fma4     : Use the Fused Multiply Add 4 instruction set
 + + cpu_flags_x86_mmx      : Use the MMX instruction set
 + + cpu_flags_x86_mmxext   : Use the Extended MMX instruction set (a subset of SSE) ([mmxext] or
                              [sse] in cpuinfo)
 + + cpu_flags_x86_sse      : Use the SSE instruction set
 + + cpu_flags_x86_sse2     : Use the SSE2 instruction set
 + - cpu_flags_x86_sse3     : Use the SSE3 instruction set ([pni] in cpuinfo, NOT ssse3)
 + - cpu_flags_x86_sse4_1   : Enable SSE4.1 instruction support
 + - cpu_flags_x86_sse4_2   : Enable SSE4.2 instruction support
 + - cpu_flags_x86_ssse3    : Use the SSSE3 instruction set (NOT sse3/pni)
 - - cpu_flags_x86_xop      : Enable the XOP instruction set

(column "I" is the standard installation without CPU_FLAGS_X86)

Thank you for the workaround, now I can delete gcc 12.
Comment 9 Paul Zander 2023-12-18 12:03:29 UTC
*** Bug 918964 has been marked as a duplicate of this bug. ***
Comment 10 publiccontact2020 2023-12-19 15:59:56 UTC Comment hidden (obsolete)
Comment 11 Paul Zander 2023-12-19 21:14:50 UTC Comment hidden (obsolete)
Comment 12 publiccontact2020 2023-12-20 16:58:49 UTC Comment hidden (obsolete)
Comment 13 Paul Zander 2023-12-21 15:10:32 UTC
Follow https://wiki.gentoo.org/wiki/CPU_FLAGS_*#Invocation.

Putting `CPU_FLAGS_X86=` in make.conf is the old method that still works but often leads to confusion.

Otherwise join #gentoo on irc and get help there.
Comment 14 publiccontact2020 2023-12-21 17:28:45 UTC Comment hidden (obsolete)
Comment 15 Paul Zander 2023-12-21 18:22:47 UTC Comment hidden (obsolete)
Comment 16 publiccontact2020 2023-12-22 13:59:16 UTC Comment hidden (obsolete)
Comment 17 Sam James archtester Gentoo Infrastructure gentoo-dev Security 2023-12-22 14:31:57 UTC Comment hidden (obsolete)
Comment 18 Larry the Git Cow gentoo-dev 2024-02-29 05:44:48 UTC
The bug has been referenced in the following commit(s):

https://gitweb.gentoo.org/repo/gentoo.git/commit/?id=4e4da320675b49841b4e7f477a6efe3c0413f674

commit 4e4da320675b49841b4e7f477a6efe3c0413f674
Author:     Sam James <sam@gentoo.org>
AuthorDate: 2024-02-29 05:42:04 +0000
Commit:     Sam James <sam@gentoo.org>
CommitDate: 2024-02-29 05:44:22 +0000

    media-video/ffmpeg: fix crash when CPU_FLAGS_x86 and CFLAGS disagree
    
    When CPU_FLAGS_X86 was set to the default for amd64 and CFLAGS was higher
    with e.g. -march=native including AVX, we could get crashes because we disable
    intrinsics which would otherwise adjust the alignment ffmpeg requests.
    
    Backport an upstream patch for more sensible behaviour.
    
    Note that the upstream patch doesn't apply to 4.4.x but I haven't tried
    to backport it manually. Someone is welcome to, but 4.4.x should really be
    on its way out by now.
    
    Bug: https://trac.ffmpeg.org/ticket/10549
    Bug: https://bugs.gentoo.org/915384
    Signed-off-by: Sam James <sam@gentoo.org>

 media-video/ffmpeg/ffmpeg-6.0.1-r3.ebuild          | 607 ++++++++++++++++++++
 media-video/ffmpeg/ffmpeg-6.1.1-r4.ebuild          | 614 +++++++++++++++++++++
 .../ffmpeg/files/ffmpeg-6.0.1-alignment.patch      | 114 ++++
 3 files changed, 1335 insertions(+)
Comment 19 Sam James archtester Gentoo Infrastructure gentoo-dev Security 2024-02-29 05:45:09 UTC
I'll leave this open for a little bit for visibility and in case anyone wants to do the 4.4.x backport.