-fPIC is currently filtered on the ffmpeg ebuild, to workaround some of the in-line assembler that fails to compile. However this workaround silently inverts what the user requested, so is not ideal. I've worked up a patch to fix the code so that it does compile with -fPIC, it works for me. This allows -fPIC to be removed from the filter-flags - which is always a good thing (perhaps all the "use <arch> && append-flags -fPIC" lines can also be removed as a result, isn't it on by default on those arches?). I've tested very coarsely using vlc to play a DVD and stream it in various formats and at least libavcodec seems ok which is where most of the fixes are. Couldn't find something that used libpostproc, so I'm not sure if that's ok or not. There are several bugs against this, however they've been marked as fixed with the filtering (#62477, #45576 are relevant). I've opened a new bug; please point out if I should have appended an existing bug. There are several types of fix included in the patch: 1) Fix '#ifdef PIC' to '#ifdef __PIC__'. Affects libavcoded/i386/dsputil_mmx.c, libavcodec/i386/dsputil_mmx_rnd.h which are only relevant to the x86 arch, and libavcodec/msmpeg4.c. 2) libavcodec/msmpeg4.c - alternate C code is already provided, and I couldn't convince myself that the effort required to mangle the asm code would lead to significantly faster code than the C. Using the alternate C code meant just changing PIC to __PIC__ as (1) so this seems the most sensible approach. 3) libavcodec/i386/mpegvideo_mmx_template.c, libavcodec/libpostproc/postprocess_template.c changes are due to the reservation by gcc of the ebx register when PIC is enabled. The compiler rejects code it can't handle with the "can't find a register in class" error. The fixes in these files are either (a) split long chunks of assembler into smaller pieces, where splitting reduces the number of register parameters on each pice, or (b) changing a register parameter ("r") to memory ("m"), save/restore ebx across the asm, move the memory parameter to ebx and use ebx in place of the parameter reference. The fixes are all written so that when fPIC is not in play, the code takes its previous form. It would probably be a good idea if someone with solid gcc x86 asm experience could check through the changes described in (3). Reproducible: Always Steps to Reproduce: 1. 2. 3.
Created attachment 42071 [details, diff] Fixes for -fPIC compilation problems
Created attachment 42072 [details, diff] Fixes for -fPIC compilation problems (correct file this time, I hope)
Sorry guys, I've messed up somewhere - it doesn't work (yet). Ignore me for now, I'll come back when I've worked out what's up.
Created attachment 42074 [details, diff] Fixes -fPIC compilation problems - third time lucky :) OK; sorry about that - this is the one. I've tried various encoding schemes, and it works as well with the patch as without.
Kevin, your patch isn't supposed to fix this, right? ;-) gcc -DHAVE_CONFIG_H -I. -I. -I../.. -I../../libavcodec -DHAVE_AV_CONFIG_H=1 -msse -march=pentium4 -pipe -MT libmmxsse_la-dsputil_mmx.lo -MD -MP -MF .deps/libmmxsse_la-dsputil_mmx.Tpo -c dsputil_mmx.c -fPIC -DPIC -o .libs/libmmxsse_la-dsputil_mmx.o dsputil_mmx.c: In function `h263_h_loop_filter_mmx': dsputil_mmx.c:614: error: can't find a register in class `GENERAL_REGS' while reloading `asm' make[8]: *** [libmmxsse_la-dsputil_mmx.lo] Error 1 make[8]: Leaving directory `/var/tmp/portage/gst-plugins-ffmpeg-0.8.2/work/gst-ffmpeg-0.8.2/gst-libs/ext/ffmpeg/libavcodec/i386' make[7]: *** [all-recursive] Error 1 aquarius ffmpeg # pwd /var/tmp/portage/gst-plugins-ffmpeg-0.8.2/work/gst-ffmpeg-0.8.2/gst-libs/ext/ffmpeg aquarius ffmpeg # patch -p2 < /root/ffmpeg.patch patching file libavcodec/i386/dsputil_mmx.c Hunk #1 succeeded at 55 (offset -2 lines). patching file libavcodec/i386/dsputil_mmx_rnd.h patching file libavcodec/i386/mpegvideo_mmx_template.c patching file libavcodec/libpostproc/postprocess_template.c Hunk #1 succeeded at 2622 (offset -545 lines). Hunk #2 succeeded at 2686 (offset -545 lines). Hunk #3 succeeded at 2709 (offset -545 lines). Hunk #4 succeeded at 2726 (offset -545 lines). Hunk #5 succeeded at 2743 (offset -545 lines). patching file libavcodec/msmpeg4.c Hunk #1 succeeded at 731 (offset 15 lines). aquarius ffmpeg # aquarius ffmpeg # gcc --version gcc (GCC) 3.3.4 20040623 (Gentoo Linux 3.3.4-r1, ssp-3.3.2-2, pie-8.7.6) Copyright (C) 2003 Free Software Foundation, Inc. This is free software; see the source for copying conditions. There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. aquarius ffmpeg # $ emerge info Portage 2.0.51-r3 (default-linux/x86/2004.0, gcc-3.3.4, glibc-2.3.4.20040808-r1, 2.6.10-rc2 i686) ================================================================= System uname: 2.6.10-rc2 i686 Intel(R) Pentium(R) 4 CPU 3.00GHz Gentoo Base System version 1.4.16 Autoconf: sys-devel/autoconf-2.59-r5 Automake: sys-devel/automake-1.8.5-r1 Binutils: sys-devel/binutils-2.14.90.0.8-r1 Headers: sys-kernel/linux-headers-2.4.19-r1,sys-kernel/linux-headers-2.4.21-r1 Libtools: sys-devel/libtool-1.5.2-r5 ACCEPT_KEYWORDS="x86" AUTOCLEAN="yes" CFLAGS="-msse3 -O3 -fomit-frame-pointer -march=pentium4 -funroll-loops -pipe" CHOST="i686-pc-linux-gnu" COMPILER="" CONFIG_PROTECT="/etc /usr/X11R6/lib/X11/xkb /usr/kde/2/share/config /usr/kde/3.3/env /usr/kde/3.3/share/config /usr/kd e/3.3/shutdown /usr/kde/3/share/config /usr/share/config /usr/share/texmf/dvipdfm/config/ /usr/share/texmf/dvips/confi g/ /usr/share/texmf/tex/generic/config/ /usr/share/texmf/tex/platex/config/ /usr/share/texmf/xdvi/ /var/bind /var/qmai l/alias /var/qmail/control" CONFIG_PROTECT_MASK="/etc/afs/C /etc/afs/afsws /etc/gconf /etc/terminfo /etc/env.d" CXXFLAGS="-msse3 -O3 -fomit-frame-pointer -march=pentium4 -funroll-loops -pipe" DISTDIR="/usr/portage/distfiles" FEATURES="autoaddcvs autoconfig ccache distlocks sandbox sfperms" GENTOO_MIRRORS="http://gentoo.mirror.icd.hu/ http://ftp-stud.fht-esslingen.de/pub/Mirrors/gentoo/ http://gd.tuwien.ac. at/opsys/linux/gentoo/ ftp://ftp.tu-clausthal.de/pub/linux/gentoo/" MAKEOPTS="-j3" PKGDIR="/usr/portage/packages" PORTAGE_TMPDIR="/var/tmp" PORTDIR="/usr/portage" PORTDIR_OVERLAY="" SYNC="rsync://rsync.gentoo.org/gentoo-portage" USE="FFmpeg X Xaw3d aalib acpi adns afs alsa apache2 apm arts ati avi berkdb bidi bitmap-fonts bonobo caca cdparanoia cdr crypt cscope cups curl dga directfb divx divx4 divx4linux divx5 divx5linux doc dvb dvd dvdr dvdread emacs emacs-w3 encode esd ethereal evo f77 faad faad2 fam fame fbcon ffmpeg flac flash foomaticdb fortran fvwm fvwm2 gb gd gdbm ggi gif gphoto2 gpm gstreamer gtk gtk2 gtkhtml guile i8x0 imagemagick imlib imlib2 innodb java jpeg junit lcms ldap leim l ibg++ libwww live lpthread lzo lzw-tiff mad mcal mesa mikmod mmx mmx2 motif mozilla mpeg mule mysql ncurses network nl s oggvorbis opengl oss pam pda pdflib perl php php4 plotutils png ppds pthread pthreads python qt qtx quicktime readli ne rtc ruby samba sasl scanner sdl slang slp speex spell sse sse2 sse3 ssl svga tcltk tcpd tetex theora thread threads tiff truetype unicode usb v4l v4l2 win32 winvidix wmf x86 xml xml2 xmms xosd xv xvid xvmc zeo zlib video_cards_radeon linguas_cs linguas_cz linguas_en"
Actually, this builds fine for me: emerge =media-libs/gst-plugins-0.8.5-r1 (although might eb related to -O3 and -O2 zapped by the ebuild). I won't spoil this thread with gst-plugins. ;-) I have used your patch for ffmpeg-0.4.9_pre1 and it works great. OK, by default the ebuild for thsi version zaps -fPIC. I tried the ebuild as it was provided, but without your patch I couldn't proceed. Then I edited the ebuild to allow -fPIC and it compiled fine only with your patch (again). Then I allowed optimization with configure flag and again, with your path it compiled fine. gcc -Wall -msse3 -O3 -fomit-frame-pointer -march=pentium4 -funroll-loops -pipe -fPIC -DHAVE_AV_CONFIG_H -I.. -D_FILE_OFFSET_BITS=64 -D_LARGEFILE_SOURCE -D_GNU_SOURCE -c -o msmpeg4.o msmpeg4.c msmpeg4.c: In function `msmpeg4_pred_dc': msmpeg4.c:720: error: can't find a register in class `BREG' while reloading `asm' wmv2.c: At top level: wmv2.c:104: warning: `wmv2_encode_end' defined but not used make[1]: *** [msmpeg4.o] Error 1 make[1]: Leaving directory `/var/tmp/portage/ffmpeg-0.4.9_pre1/work/ffmpeg-0.4.9-pre1/libavcodec' make: *** [lib] Error 2 !!! ERROR: media-video/ffmpeg-0.4.9_pre1 failed. !!! Function src_compile, Line 76, Exitcode 2 !!! make failed. !!! If you need support, post the topmost build error, NOT this status message. aquarius / # cd /var/tmp/portage/ffmpeg-0.4.9_pre1/work/ffmpeg-0.4.9-pre1 aquarius ffmpeg-0.4.9-pre1 # patch -p2 < /root/ffmpeg.patch patching file libavcodec/i386/dsputil_mmx.c patching file libavcodec/i386/dsputil_mmx_rnd.h patching file libavcodec/i386/mpegvideo_mmx_template.c patching file libavcodec/libpostproc/postprocess_template.c patching file libavcodec/msmpeg4.c aquarius ffmpeg-0.4.9-pre1 # make make -C libavcodec all make[1]: Entering directory `/var/tmp/portage/ffmpeg-0.4.9_pre1/work/ffmpeg-0.4.9-pre1/libavcodec' gcc -Wall -msse3 -O3 -fomit-frame-pointer -march=pentium4 -funroll-loops -pipe -fPIC -DHAVE_AV_CONFIG_H -I.. -D_FILE_OFFSET_BITS=64 -D_LARGEFILE_SOURCE -D_GNU_SOURCE -c -o msmpeg4.o msmpeg4.c wmv2.c:104: warning: `wmv2_encode_end' defined but not used gcc -Wall -msse3 -O3 -fomit-frame-pointer -march=pentium4 -funroll-loops -pipe -fPIC -DHAVE_AV_CONFIG_H -I.. -D_FILE_OFFSET_BITS=64 -D_LARGEFILE_SOURCE -D_GNU_SOURCE -c -o h263dec.o h263dec.c [... and continues happily]
Created attachment 52440 [details, diff] Ebuild patch to fix ffmpeg on PIC platforms. This patch to the 0.4.6_pre1 ebuild fixes ffmpeg so that libraries are properly PIC, without textrels. All these changes are conditional on 'use pic || use !mmx' - i.e. if the user has requested pic, or if mmx is not requested. This means that the fixes are applied on arches that don't have mmx (thus sorting out bug #16281 properly, I think). The modifications are: 1) Change ifdef PIC to ifdef __PIC__ in libavcodec - ifdef PIC is only sensible if using libtool to build shared libraries, and this package doesn't use libtool. 2) Library makefiles modified to add '-fPIC', otherwise the objects are built as non-PIC code causing textrels in the generated libraries 3) libavcode/liba52 modified to use the HAVE_MMX definition to decide whether to build the accelerated assembler code which is not suitable for proper shared libraries (causes textrels). This means that configure --disable-mmx starts to do what it says on the tin. 4) Add '--disable-mmx' to configure options. This patch doesn't attempt to hack the actual assembler code (unlike the previous patch); the hardened team figure that is better left upstream and I concur.
Created attachment 52485 [details, diff] Patch againsg 0.4.9_p20050226 Same as above but for latest ebuild (0.4.9_p20050226).
Thanks, ready and in cvs! Tested with hardened compile and a couple o runtime avi tests using ffplay.