Bug 200609 - multimedia/ffmpeg crashes with SIGBUS on armv6
Summary: multimedia/ffmpeg crashes with SIGBUS on armv6
Status: Closed FIXED
Alias: None
Product: Ports & Packages
Classification: Unclassified
Component: Individual Port(s) (show other bugs)
Version: Latest
Hardware: Any Any
: --- Affects Many People
Assignee: Thomas Zander
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2015-06-03 02:04 UTC by Randy Westlund
Modified: 2017-11-30 08:43 UTC (History)
2 users (show)

See Also:
bugzilla: maintainer-feedback? (multimedia)


Attachments
poudriere build log for ffmpeg armv6 (111.75 KB, text/x-log)
2015-06-03 02:04 UTC, Randy Westlund
no flags Details
sigbus fix (650 bytes, patch)
2015-06-20 16:14 UTC, Mikael Urankar
no flags Details | Diff
update to fix_sigbus_patch (651 bytes, patch)
2015-06-22 00:28 UTC, Randy Westlund
no flags Details | Diff
ffmpeg_disable_arm_unalighed_patch (331 bytes, patch)
2015-08-16 05:28 UTC, Randy Westlund
no flags Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Randy Westlund 2015-06-03 02:04:07 UTC
Created attachment 157388 [details]
poudriere build log for ffmpeg armv6

ffmpeg-2.3.6_2,1 crashes with SIGBUS on armv6.

root@beaglebone:~ # uname -a
FreeBSD beaglebone.lan 10.1-RELEASE FreeBSD 10.1-RELEASE #0 r274401: Wed Nov 12 04:09:07 UTC 2014     root@releng1.nyi.freebsd.org:/usr/obj/arm.armv6/usr/src/sys/BEAGLEBONE  arm

Cross compiled with poudriere in a 10.1-RELEASE jail.

Options        :
        AACPLUS        : off
        ALSA           : off
        AMR_NB         : off
        AMR_WB         : off
        ASS            : off
        CDIO           : off
        CELT           : off
        DEBUG          : off
        DOCS           : on
        FAAC           : off
        FDK_AAC        : off
        FFSERVER       : on
        FONTCONFIG     : on
        FREETYPE       : on
        FREI0R         : on
        GNUTLS         : on
        GSM            : off
        ICONV          : on
        JACK           : off
        LAME           : off
        LIBBLURAY      : off
        LIBV4L         : on
        MODPLUG        : off
        OPENAL         : off
        OPENCV         : off
        OPENJPEG       : off
        OPENSSL        : off
        OPTIMIZED_CFLAGS: off
        OPUS           : off
        PULSEAUDIO     : off
        RTMP           : off
        SCHROEDINGER   : on
        SDL            : off
        SPEEX          : off
        THEORA         : on
        VAAPI          : off
        VDPAU          : off
        VORBIS         : on
        VO_AACENC      : off
        VO_AMRWBENC    : off
        VPX            : off
        X11GRAB        : off
        X264           : on
        X265           : off
        XVID           : on


The command I'm running:

root@beaglebone:~ # gdb -q ffmpeg
(gdb) r -pixel_format h264 -f v4l2 -s 640x480 -r 15 -i /dev/video0 -c copy http://10.0.0.1/feed1.ffm
Starting program: /usr/local/bin/ffmpeg -pixel_format h264 -f v4l2 -s 640x480 -r 15 -i /dev/video0 -c copy http://10.0.0.1/feed1.ffm
(no debugging symbols found)...(no debugging symbols found)...(no debugging symbols found)...(no debugging symbols found)...(no debugging symbols found)...(no debugging symbols found)...(no debugging symbols found)...(no debugging symbols found)...(no debugging symbols found)...(no debugging symbols found)...(no debugging symbols found)...(no debugging symbols found)...(no debugging symbols found)...(no debugging symbols found)...(no debugging symbols found)...ffmpeg version 2.3.6 Copyright (c) 2000-2014 the FFmpeg developers
  built on Jun  3 2015 01:18:01 with FreeBSD clang version 3.4.1 (tags/RELEASE_34/dot1-final 208032) 20140512
  configuration: --disable-libaacplus --disable-indev=alsa --disable-outdev=alsa --disable-libopencore-amrnb --disable-libopencore-amrwb --disable-libass --disable-libcdio --disable-libcelt --disable-libfaac --disable-libfdk-aac --enable-ffserver --enable-fontconfig --enable-libfreetype --enable-frei0r --disable-libgsm --enable-iconv --disable-indev=jack --disable-libmp3lame --disable-libbluray --enable-libv4l2 --disable-libmodplug --disable-openal --disable-indev=openal --disable-libopencv --disable-libopenjpeg --disable-libopus --disable-libpulse --disable-indev=pulse --disable-outdev=pulse --disable-librtmp --enable-libschroedinger --disable-libspeex --enable-libtheora --disable-vaapi --disable-vdpau --enable-libvorbis --disable-libvo-aacenc --disable-libvo-amrwbenc --disable-libvpx --enable-libx264 --disable-libx265 --enable-libxvid --enable-gnutls --disable-openssl --prefix=/usr/local --mandir=/usr/local/man --datadir=/usr/local/share/ffmpeg --enable-shared --enable-gpl --enable-postproc --enable-avfilter --enable-avresample --enable-pthreads --enable-memalign-hack --disable-libstagefright-h264 --disable-libutvideo --disable-libsoxr --cc=cc --extra-cflags='-I/usr/local/include/vorbis -I/usr/local/include' --extra-ldflags='-L/usr/local/lib ' --extra-libs=-lpthread --disable-debug --disable-sse --disable-mmx --disable-ffplay --disable-outdev=sdl
  libavutil      52. 92.100 / 52. 92.100
  libavcodec     55. 69.100 / 55. 69.100
  libavformat    55. 48.100 / 55. 48.100
  libavdevice    55. 13.102 / 55. 13.102
  libavfilter     4. 11.100 /  4. 11.100
  libavresample   1.  3.  0 /  1.  3.  0
  libswscale      2.  6.100 /  2.  6.100
  libswresample   0. 19.100 /  0. 19.100
  libpostproc    52.  3.100 / 52.  3.100

Program received signal SIGBUS, Bus error.
0x207ef140 in avpriv_find_start_code () from /usr/local/lib/libavcodec.so.55
(gdb) 

(gdb) bt
#0  0x207ef140 in avpriv_find_start_code () from /usr/local/lib/libavcodec.so.55
#1  0x204cca3c in avpriv_h264_has_num_reorder_frames () from /usr/local/lib/libavcodec.so.55
#2  0x204cca3c in avpriv_h264_has_num_reorder_frames () from /usr/local/lib/libavcodec.so.55



It may be related to the following bug, but I don't believe those optimization flags are enabled.

http://lists.freebsd.org/pipermail/freebsd-toolchain/2013-September/001032.html

https://llvm.org/bugs/show_bug.cgi?id=12250


Poudriere build log attached.
Comment 1 Randy Westlund 2015-06-16 12:01:31 UTC
I get the same SIGBUS crash when I build this with GCC 4.9 instead of clang.

https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=200714

I don't know how to investigate this further.
Comment 2 Mikael Urankar freebsd_committer freebsd_triage 2015-06-20 16:14:43 UTC
Created attachment 157896 [details]
sigbus fix

Hi,

The crash is caused by an unaligned access:

0x20213778 <adts_aac_probe+96>: ldrh    r1, [r7]
r7             0x22c6d811       583456785

Can you try the attached patch, It should also fix the build with gcc (make CC=gcc48)
Comment 3 Randy Westlund 2015-06-22 00:28:56 UTC
Created attachment 157963 [details]
update to fix_sigbus_patch

(In reply to mikael.urankar from comment #2)

After your patch:

===>  Configuring for ffmpeg-2.3.6_4,1
env: -no-integrated-as: No such file or directory
===>  Script "configure" failed unexpectedly.
Please report the problem to multimedia@FreeBSD.org [maintainer] and attach
the "/usr/ports/multimedia/ffmpeg/work/ffmpeg-2.3.6/config.err" including the 
output of the failure of your make command. Also, it might be a good idea to
provide an overview of all packages installed on your system (e.g. a
/usr/local/sbin/pkg-static info -g -Ea).
*** Error code 1

Stop.
make[1]: stopped in /usr/ports/multimedia/ffmpeg
*** Error code 1

Stop.
make: stopped in /usr/ports/multimedia/ffmpeg
root@beaglebone:/usr/ports/multimedia/ffmpeg # 


I removed a tab character from the second CONFIGURE_ENV line and it built successfully with Clang.  The SIGBUS is gone.  Updated patch attached.


When I build with make USE_GCC=4.9, it still passes -no-integrated-as to GCC, which causes the build to fail.  Shouldn't USE_GCC set CHOSEN_COMPILER_TYPE?
Comment 4 Mikael Urankar freebsd_committer freebsd_triage 2015-06-22 17:14:47 UTC
(In reply to Randy Westlund from comment #3)
From the porters handbook: USE_GCC The port requires GCC (gcc or g++) to build.
It is not the case here as we can build ffmpeg with clang, if you want to compile the port with gcc you have to use 'make CC=gcc48'

Sorry for the extra tab and thanks for fixing my patch :-)
Comment 5 Randy Westlund 2015-06-22 17:27:01 UTC
(In reply to mikael.urankar from comment #4)
Thanks for the clarification.  I haven't finished reading the Porter's Handbook yet.

I can confirm that this patch resolves both this PR and https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=200714.
Comment 6 Thomas Zander freebsd_committer freebsd_triage 2015-07-11 14:15:52 UTC
Is this patch still needed with the most recent ffmpeg?
Comment 7 Randy Westlund 2015-07-11 15:23:12 UTC
(In reply to Thomas Zander from comment #6)

I don't have the hardware with me to test it, but I'm sure that it is still necessary.  ARM doesn't like the unaligned memory accesses.

Committing this patch will resolve both this PR and https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=200714.
Comment 8 Mikael Urankar freebsd_committer freebsd_triage 2015-07-11 15:43:23 UTC
I will give it a shot today
Comment 9 Mikael Urankar freebsd_committer freebsd_triage 2015-07-11 17:00:51 UTC
I still see the sigbus without the patch.
With the patch I have the following error now:

ffmpeg -i test.mp4 test.wav
Illegal instruction (core dumped)

#0  0x2048cb90 in avcodec_register_all () from /usr/local/lib/libavcodec.so.56
(gdb) disassemble $pc-16 $pc+16
Dump of assembler code from 0x2048cb80 to 0x2048cba0:
0x2048cb80 <avcodec_register_all+100232>:       flds    s0, [r9, #-4]
0x2048cb84 <avcodec_register_all+100236>:       flds    s1, [r9, #-12]
0x2048cb88 <avcodec_register_all+100240>:       flds    s2, [r2, #12]
0x2048cb8c <avcodec_register_all+100244>:       flds    s3, [r2, #4]
0x2048cb90 <avcodec_register_all+100248>:       fmuls   s8, s0, s16
0x2048cb94 <avcodec_register_all+100252>:       fldmias r7!, {s20-s21}
0x2048cb98 <avcodec_register_all+100256>:       fldmdbs r11!, {s22-s23}
0x2048cb9c <avcodec_register_all+100260>:       flds    s4, [r2]
Comment 10 Randy Westlund 2015-07-12 00:45:31 UTC
Bummer.  I won't have access to any ARM hardware until the 22nd.  I can only help test after that :/
Comment 11 Randy Westlund 2015-08-16 05:28:21 UTC
Created attachment 159912 [details]
ffmpeg_disable_arm_unalighed_patch

Just tested with ffmpeg-2.7.2,1.  I still see the SIGBUS with the version in the tree.

I've modified the patch to work with the current version of ffmpeg (part of it was committed in PR 200714).  With the patch, ffmpeg works for me on my beaglebone black.  I ran the following two commands for testing:

ffmpeg -i test.mp4 test.wav
ffmpeg -i test.wav -strict -2 test2.mp4
Comment 12 commit-hook freebsd_committer freebsd_triage 2015-08-16 16:01:04 UTC
A commit references this bug:

Author: riggs
Date: Sun Aug 16 16:00:17 UTC 2015
New revision: 394414
URL: https://svnweb.freebsd.org/changeset/ports/394414

Log:
  Fix SIGBUS crashes on several popular ARM SoCs

  PR:		200609
  Submitted by:	rwestlun@gmail.com
  MFH:		2015Q3

Changes:
  head/multimedia/ffmpeg/Makefile
Comment 13 Thomas Zander freebsd_committer freebsd_triage 2015-08-16 16:02:29 UTC
Thanks for testing, submitting and staying on top of this.
Comment 14 commit-hook freebsd_committer freebsd_triage 2015-08-17 18:58:26 UTC
A commit references this bug:

Author: riggs
Date: Mon Aug 17 18:58:19 UTC 2015
New revision: 394522
URL: https://svnweb.freebsd.org/changeset/ports/394522

Log:
  MFH: r394414

  Fix SIGBUS crashes on several popular ARM SoCs

  PR:		200609
  Submitted by:	rwestlun@gmail.com
  Approved by:	ports-secteam (delphij)

Changes:
_U  branches/2015Q3/
  branches/2015Q3/multimedia/ffmpeg/Makefile
Comment 15 commit-hook freebsd_committer freebsd_triage 2017-11-30 08:43:32 UTC
A commit references this bug:

Author: jbeich
Date: Thu Nov 30 08:42:33 UTC 2017
New revision: 455179
URL: https://svnweb.freebsd.org/changeset/ports/455179

Log:
  multimedia/ffmpeg: unaligned access on armv6 should work after base r300701

  Reported by:	mmel
  PR:		200609 (ping)

Changes:
  head/multimedia/ffmpeg/Makefile