Gentoo Websites Logo
Go to: Gentoo Home Documentation Forums Lists Bugs Planet Store Wiki Get Gentoo!
Bug 772854 - media-video/ffmpeg-4.3.2[abi_x86_32] fails to build with LTO (swscale_template.c:705:5: error: ‘asm’ operand has impossible constraints)
Summary: media-video/ffmpeg-4.3.2[abi_x86_32] fails to build with LTO (swscale_templat...
Status: RESOLVED FIXED
Alias: None
Product: Gentoo Linux
Classification: Unclassified
Component: Current packages (show other bugs)
Hardware: All Linux
: Normal normal (vote)
Assignee: Gentoo Media-video project
URL:
Whiteboard:
Keywords:
Depends on:
Blocks: lto
  Show dependency tree
 
Reported: 2021-02-25 08:27 UTC by Paolo Pedroni
Modified: 2024-02-02 01:26 UTC (History)
5 users (show)

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


Attachments
ffmpeg-4.3.2:20210225-080227.log.gz (ffmpeg-4.3.2:20210225-080227.log.gz,127.28 KB, application/gzip)
2021-02-25 08:27 UTC, Paolo Pedroni
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Paolo Pedroni 2021-02-25 08:27:54 UTC
Created attachment 688302 [details]
ffmpeg-4.3.2:20210225-080227.log.gz

src/libswscale/x86/swscale_template.c: In function ‘yuv2bgr24_X_ar_mmxext’:
src/libswscale/x86/swscale_template.c:705:5: error: ‘asm’ operand has impossible constraints
  705 |     YSCALEYUV2PACKEDX_ACCURATE
      |     ^
make[1]: *** [/var/tmp/portage/media-video/ffmpeg-4.3.2/temp/ccOiTkqB.mk:5: /var/tmp/portage/media-video/ffmpeg-4.3.2/temp/libswscale.so.5.QEVW8z.ltrans1.ltrans.o] Error 1
make[1]: *** Waiting for unfinished jobs....
src/libswscale/x86/rgb2rgb_template.c: In function ‘rgb24toyv12_3dnow’:
src/libswscale/x86/rgb2rgb_template.c:1665:9: error: ‘asm’ operand has impossible constraints
 1665 |         __asm__ volatile(
      |         ^
make[1]: *** [/var/tmp/portage/media-video/ffmpeg-4.3.2/temp/ccOiTkqB.mk:8: /var/tmp/portage/media-video/ffmpeg-4.3.2/temp/libswscale.so.5.QEVW8z.ltrans2.ltrans.o] Error 1
lto-wrapper: fatal error: make returned 2 exit status
compilation terminated.
/usr/lib/gcc/x86_64-pc-linux-gnu/9.3.0/../../../../x86_64-pc-linux-gnu/bin/ld: fatal error: lto-wrapper failed
collect2: error: ld returned 1 exit status
distcc[8597] ERROR: compile (null) on localhost failed
make: *** [/var/tmp/portage/media-video/ffmpeg-4.3.2/work/ffmpeg-4.3.2/ffbuild/library.mak:103: libswscale/libswscale.so.5] Error 1

Without USE=abi_x86_32 it builds and tests fine with LTO enabled.

# emerge --info =media-video/ffmpeg-4.3.2
Portage 3.0.13 (python 3.8.7-final-0, default/linux/amd64/17.1/desktop/plasma/systemd, gcc-9.3.0, glibc-2.32-r6, 5.4.97-gentoo x86_64)
=================================================================
                         System Settings
=================================================================
System uname: Linux-5.4.97-gentoo-x86_64-AMD_Phenom-tm-_II_X6_1100T_Processor-with-glibc2.2.5
KiB Mem:    16138524 total,   5477968 free
KiB Swap:   12550140 total,  12536828 free
Timestamp of repository gentoo: Tue, 23 Feb 2021 09:15:01 +0000
Head commit of repository gentoo: 2c9af82a813cefade57143d2cdf9681f60afaca4
sh dash 0.5.11.3-r1
ld GNU gold (Gentoo 2.35.1 p2 2.35.1) 1.16
distcc 3.3.3 x86_64-pc-linux-gnu [enabled]
ccache version 4.1 [disabled]
app-shells/bash:          5.0_p18::gentoo
dev-java/java-config:     2.3.1::gentoo
dev-lang/perl:            5.30.3::gentoo
dev-lang/python:          2.7.18-r6::gentoo, 3.8.7-r1::gentoo, 3.9.1-r1::gentoo
dev-util/ccache:          4.1::gentoo
dev-util/cmake:           3.18.5::gentoo
sys-apps/baselayout:      2.7::gentoo
sys-apps/sandbox:         2.20::gentoo
sys-devel/autoconf:       2.13-r1::gentoo, 2.69-r5::gentoo
sys-devel/automake:       1.16.2-r1::gentoo
sys-devel/binutils:       2.35.1-r1::gentoo
sys-devel/gcc:            9.3.0-r2::gentoo
sys-devel/gcc-config:     2.3.2-r1::gentoo
sys-devel/libtool:        2.4.6-r6::gentoo
sys-devel/make:           4.3::gentoo
sys-kernel/linux-headers: 5.4-r1::gentoo (virtual/os-headers)
sys-libs/glibc:           2.32-r6::gentoo
Repositories:

gentoo
    location: /usr/portage
    sync-type: rsync
    sync-uri: rsync://rsync.europe.gentoo.org/gentoo-portage
    priority: -1000
    sync-rsync-extra-opts: 
    sync-rsync-verify-max-age: 24
    sync-rsync-verify-jobs: 1
    sync-rsync-verify-metamanifest: yes

x-portage
    location: /usr/local/portage
    masters: gentoo
    priority: 0

ACCEPT_KEYWORDS="amd64"
ACCEPT_LICENSE="* -@EULA"
CBUILD="x86_64-pc-linux-gnu"
CFLAGS="-O2 -pipe -frecord-gcc-switches -march=amdfam10 -flto=6"
CHOST="x86_64-pc-linux-gnu"
CONFIG_PROTECT="/etc /usr/lib64/libreoffice/program/sofficerc /usr/share/config /usr/share/gnupg/qualified.txt"
CONFIG_PROTECT_MASK="/etc/ca-certificates.conf /etc/dconf /etc/env.d /etc/fonts/fonts.conf /etc/gconf /etc/gentoo-release /etc/revdep-rebuild /etc/sandbox.d /etc/terminfo"
CXXFLAGS="-O2 -pipe -frecord-gcc-switches -march=amdfam10 -flto=6"
DISTDIR="/usr/portage/distfiles"
EMERGE_DEFAULT_OPTS="--keep-going y --with-bdeps y"
ENV_UNSET="CARGO_HOME DBUS_SESSION_BUS_ADDRESS DISPLAY GOBIN GOPATH PERL5LIB PERL5OPT PERLPREFIX PERL_CORE PERL_MB_OPT PERL_MM_OPT XAUTHORITY XDG_CACHE_HOME XDG_CONFIG_HOME XDG_DATA_HOME XDG_RUNTIME_DIR"
FCFLAGS="-O2 -pipe -frecord-gcc-switches -march=amdfam10 -flto=6"
FEATURES="assume-digests binpkg-docompress binpkg-dostrip binpkg-logs cgroup compress-build-logs config-protect-if-modified distcc distlocks ebuild-locks ipc-sandbox merge-sync multilib-strict network-sandbox news parallel-fetch pid-sandbox preserve-libs protect-owned qa-unresolved-soname-deps sandbox sfperms split-elog split-log strict test unknown-features-warn unmerge-logs unmerge-orphans userfetch userpriv usersandbox usersync xattr"
FFLAGS="-O2 -pipe -frecord-gcc-switches -march=amdfam10 -flto=6"
GENTOO_MIRRORS="http://mirrors.soeasyto.com/distfiles.gentoo.org/ http://mirrors.evowise.com/gentoo/ http://gentoo.modulix.net/gentoo/ https://mirrors.soeasyto.com/distfiles.gentoo.org/ https://mirrors.evowise.com/gentoo/"
LANG="it_IT.UTF-8"
LDFLAGS="-Wl,-O1 -Wl,--as-needed -Wl,--hash-style=gnu -Wl,--sort-common -flto=6"
LINGUAS="it it_IT"
MAKEOPTS="-j19 -l6"
PKGDIR="/usr/portage/packages"
PORTAGE_CONFIGROOT="/"
PORTAGE_RSYNC_OPTS="--recursive --links --safe-links --perms --times --omit-dir-times --compress --force --whole-file --delete --stats --human-readable --timeout=180 --exclude=/distfiles --exclude=/local --exclude=/packages --exclude=/.git"
PORTAGE_TMPDIR="/var/tmp"
USE="X a52 aac aalib acl acpi activities adns alsa amd64 ao audiofile bash-completion bluetooth branding brotli bzip2 cairo caps cdda cddb cdparanoia cdr cli crypt css cups curl dbus declarative dga djvu dri dts dvd dvdr emboss encode exif expat fbcon ffmpeg fftw flac fontconfig fortran ftp gd gdbm geoip gif gimp gmp gnutls gphoto2 gpm graphviz gtk gui handbook iconv icu idn imagemagick imlib introspection ipv6 java javascript jbig jemalloc jpeg jpeg2k kde kipi kwallet lame lcms libass libglvnd libnotify libsamplerate libtirpc lm_sensors lua lzma lzo mad mmap mng mp3 mp4 mpeg mplayer multilib musicbrainz ncurses nls nptl nsplugin offensive ogg openal opengl openmp pam pango pcre pdf phonon plasma png policykit postscript ppds pulseaudio qml qt5 rdesktop readline recode samba sctp sdl seccomp sndfile sockets speex spell split-usr sqlite sqlite3 ssl startup-notification svg symlink syslog systemd sysvipc taglib telemetry test theora threads tidy tiff truetype udev udisks unicode upower usb vaapi vala vdpau verify-sig vim-syntax vnc vorbis wavpack wayland widgets win32codecs wmf wxwidgets x264 xattr xcb xine xml xpm xscreensaver xv xvid yahoo zlib zstd" ABI_X86="64" ADA_TARGET="gnat_2018" ALSA_CARDS="hda-intel virmidi" APACHE2_MODULES="authn_core authz_core socache_shmcb unixd actions alias auth_basic authn_alias authn_anon authn_dbm authn_default authn_file authz_dbm authz_default authz_groupfile authz_host authz_owner authz_user autoindex cache cgi cgid dav dav_fs dav_lock deflate dir disk_cache env expires ext_filter file_cache filter headers include info log_config logio mem_cache mime mime_magic negotiation rewrite setenvif speling status unique_id userdir usertrack vhost_alias" CALLIGRA_FEATURES="karbon sheets words" CAMERAS="ptp2" COLLECTD_PLUGINS="df interface irq load memory rrdtool swap syslog" CPU_FLAGS_X86="3dnow 3dnowext mmx mmxext popcnt sse sse2 sse3 sse4a" CURL_SSL="gnutls" ELIBC="glibc" GPSD_PROTOCOLS="ashtech aivdm earthmate evermore fv18 garmin garmintxt gpsclock greis isync itrax mtk3301 nmea ntrip navcom oceanserver oldstyle oncore rtcm104v2 rtcm104v3 sirf skytraq superstar2 timing tsip tripmate tnt ublox ubx" GRUB_PLATFORMS="pc" INPUT_DEVICES="libinput" KERNEL="linux" L10N="it en" LCD_DEVICES="bayrad cfontz cfontz633 glk hd44780 lb216 lcdm001 mtxorb ncurses text" LIBREOFFICE_EXTENSIONS="presenter-console presenter-minimizer" LUA_SINGLE_TARGET="lua5-1" LUA_TARGETS="lua5-1" OFFICE_IMPLEMENTATION="libreoffice" PHP_TARGETS="php7-3 php7-4" POSTGRES_TARGETS="postgres10 postgres11" PYTHON_SINGLE_TARGET="python3_8" PYTHON_TARGETS="python3_8" RUBY_TARGETS="ruby26" USERLAND="GNU" VIDEO_CARDS="radeon r600" XTABLES_ADDONS="quota2 psd pknock lscan length2 ipv4options ipset ipp2p iface geoip fuzzy condition tee tarpit sysrq steal rawnat logmark ipmark dhcpmac delude chaos account"
Unset:  CC, CPPFLAGS, CTARGET, CXX, INSTALL_MASK, LC_ALL, PORTAGE_BINHOST, PORTAGE_BUNZIP2_COMMAND, PORTAGE_COMPRESS, PORTAGE_COMPRESS_FLAGS, PORTAGE_RSYNC_EXTRA_OPTS

=================================================================
                        Package Settings
=================================================================

media-video/ffmpeg-4.3.2::gentoo was built with the following:
USE="X alsa amr bs2b bzip2 cdio chromium dav1d doc encode fdk fontconfig frei0r fribidi gmp gnutls gpl hardcoded-tables iconv jpeg2k kvazaar libass libilbc libsoxr libxml2 lzma mp3 network openal opengl openssl opus postproc pulseaudio rav1e samba sdl speex ssh svg test theora threads truetype vaapi vdpau vorbis vpx webp x264 x265 xvid zlib -amrenc (-appkit) -bluray -chromaprint -codec2 -cpudetection -cuda -debug -flite -gcrypt -gme -gsm -iec61883 -ieee1394 -jack -ladspa -libaom -libaribb24 -libcaca -libdrm (-libressl) -librtmp -libtesseract -libv4l -lv2 (-mipsdspr1) (-mipsdspr2) (-mipsfpu) (-mmal) -modplug -opencl -openh264 -oss -pic -rubberband -snappy -sndio -srt -static-libs -twolame -v4l -vidstab -vulkan -zeromq -zimg -zvbi" ABI_X86="(64) -32 (-x32)" CPU_FLAGS_X86="3dnow 3dnowext mmx mmxext sse sse2 sse3 -aes -avx -avx2 -fma3 -fma4 -sse4_1 -sse4_2 -ssse3 -xop" FFTOOLS="aviocat cws2fws ffescape ffeval ffhash fourcc2pixfmt graph2dot ismindex pktdumper qt-faststart sidxindex trasher" VIDEO_CARDS="-nvidia"

# emerge -1pqv =media-video/ffmpeg-4.3.2
[ebuild   R   ] media-video/ffmpeg-4.3.2  USE="X alsa amr bs2b bzip2 cdio chromium dav1d doc encode fdk fontconfig fribidi gmp gnutls gpl hardcoded-tables iconv jpeg2k kvazaar libass libilbc libsoxr libxml2 lzma mp3 network openal opengl openssl opus postproc pulseaudio rav1e samba sdl speex ssh svg test theora threads truetype vdpau vorbis vpx webp x264 x265 xvid zlib -amrenc (-appkit) -bluray -chromaprint -codec2 -cpudetection -cuda -debug -flite -frei0r* -gcrypt -gme -gsm -iec61883 -ieee1394 -jack -ladspa -libaom -libaribb24 -libcaca -libdrm (-libressl) -librtmp -libtesseract -libv4l -lv2 (-mipsdspr1) (-mipsdspr2) (-mipsfpu) (-mmal) -modplug -opencl -openh264 -oss -pic -rubberband -snappy -sndio -srt -static-libs -twolame -v4l -vaapi* -vidstab -vulkan -zeromq -zimg -zvbi" ABI_X86="32* (64) (-x32)" CPU_FLAGS_X86="3dnow 3dnowext mmx mmxext sse sse2 sse3 -aes -avx -avx2 -fma3 -fma4 -sse4_1 -sse4_2 -ssse3 -xop" FFTOOLS="aviocat cws2fws ffescape ffeval ffhash fourcc2pixfmt graph2dot ismindex pktdumper qt-faststart sidxindex trasher" VIDEO_CARDS="-nvidia"
Comment 1 B. Gazotti 2022-01-07 00:35:33 UTC
Same issue here, but with ffmpeg-4.4.1-r1, GCC 11.2. Enabling the "pic" USE flag allows the build to proceed, by disabling the problematic inline assembly code, but I fear that in doing that we would sacrifice quite a bit of performance in the resulting binaries, would we not?
Comment 2 Adrien Dessemond 2022-07-01 20:47:25 UTC
Issue still valid with GCC 12.1 and media-video/ffmpeg-4.4.2
Same fix: activate the "pic" use flag.

Should I open another bug for that one?
Comment 3 Matt Turner gentoo-dev 2022-07-26 04:45:25 UTC
Confirmed. The code in question is protected by

#if HAVE_6REGS
...
#endif

and HAVE_6REGS is defined as

#define HAVE_6REGS (ARCH_X86_64 || (HAVE_EBX_AVAILABLE || HAVE_EBP_AVAILABLE))

I think that when compiling with -flto, due to compiler optimizations, too many registers are used and the compiler isn't able to allocate registers for the asm() statement.

With LTO and interprocedural optimizations, I'm not sure the HAVE_EBX_AVAILABLE or HAVE_EBP_AVAILABLE macros can possibly be accurate. It looks like they're determined at configure time by simple tests.

I assume USE=pic avoids the problem by causing configure to detect that EBX is not usable (since EBX is the PIC register when code is compiled with -fPIC) and therefore disables the code in question.

My question is: is it possible to determine whether EBX/EBP are usable in complex programs under interprocedural optimizations by only simple configure tests?
Comment 4 Matt Turner gentoo-dev 2022-07-26 04:52:09 UTC
I should also say: given that this happens on x86-32, we probably shouldn't care about performance at all, but only about the fact that it produces a compile error for amd64/multilib users.

Two possible solutions:

- enable USE=pic if we see -flto in CFLAGS and $ABI==x86
- disable LTO if $ABI==x86.

Might be safer to just disable LTO on x86.
Comment 5 Sam James archtester Gentoo Infrastructure gentoo-dev Security 2022-07-26 05:09:07 UTC
(In reply to Matt Turner from comment #4)
> I should also say: given that this happens on x86-32, we probably shouldn't
> care about performance at all, but only about the fact that it produces a
> compile error for amd64/multilib users.
> 
> Two possible solutions:
> 
> - enable USE=pic if we see -flto in CFLAGS and $ABI==x86
> - disable LTO if $ABI==x86.
> 
> Might be safer to just disable LTO on x86.

Let's do the latter I think. I'll do it now. Thanks for the analysis!
Comment 6 Larry the Git Cow gentoo-dev 2022-07-26 05:12:08 UTC
The bug has been closed via the following commit(s):

https://gitweb.gentoo.org/repo/gentoo.git/commit/?id=96916fe72cce91a116f67db7ce00c4fdec143a1a

commit 96916fe72cce91a116f67db7ce00c4fdec143a1a
Author:     Sam James <sam@gentoo.org>
AuthorDate: 2022-07-26 05:11:02 +0000
Commit:     Sam James <sam@gentoo.org>
CommitDate: 2022-07-26 05:11:02 +0000

    media-video/ffmpeg: disable LTO for x86 builds
    
    I can't do better than Matt's analysis in the bug, so just go read
    that if curious for backstory.
    
    Closes: https://bugs.gentoo.org/772854
    Thanks-to: Matt Turner <mattst88@gentoo.org>
    Signed-off-by: Sam James <sam@gentoo.org>

 media-video/ffmpeg/ffmpeg-4.4.2.ebuild | 6 +++---
 media-video/ffmpeg/ffmpeg-5.0.1.ebuild | 6 +++---
 media-video/ffmpeg/ffmpeg-9999.ebuild  | 6 +++---
 3 files changed, 9 insertions(+), 9 deletions(-)