Gentoo Websites Logo
Go to: Gentoo Home Documentation Forums Lists Bugs Planet Store Wiki Get Gentoo!
Bug 830165 - media-video/ffmpeg, media-video/ffmpeg-chromium does not compile with "-march=native" on ARM64 (--cpu=host not supported with compiler aarch64-unknown-linux-gnu-gcc)
Summary: media-video/ffmpeg, media-video/ffmpeg-chromium does not compile with "-march...
Status: CONFIRMED
Alias: None
Product: Gentoo Linux
Classification: Unclassified
Component: Current packages (show other bugs)
Hardware: ARM64 Linux
: Normal normal (vote)
Assignee: Gentoo Media-video project
URL:
Whiteboard:
Keywords:
: 852803 852818 (view as bug list)
Depends on:
Blocks:
 
Reported: 2021-12-28 10:26 UTC by Norman Rieß
Modified: 2024-03-12 03:05 UTC (History)
11 users (show)

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


Attachments
ffmpeg build log (ffmpeg_build.log,6.20 KB, text/plain)
2021-12-28 10:35 UTC, Norman Rieß
Details
Build log for media-video/ffmpeg-4.4.1-r2 with no march/mtune set (build.log,6.31 KB, text/plain)
2022-03-09 14:54 UTC, Peer
Details
ffbuild/config.log (config.log,272.57 KB, text/plain)
2022-03-09 15:44 UTC, Peer
Details
Dirty workaround (apple-gcc.patch,486 bytes, patch)
2023-09-30 15:54 UTC, Mart Raudsepp
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Norman Rieß 2021-12-28 10:26:36 UTC
media-video/ffmpeg-4.4.1-r1 fails to build on arm64 with error message:

--cpu=host not supported with compiler aarch64-unknown-linux-gnu-gcc

COMMON_FLAGS without "-march=native" leads to a successfull build.


Emerge info:

Portage 3.0.28 (python 3.9.9-final-0, default/linux/arm64/17.0/desktop, gcc-11.2.0, glibc-2.33-r7, 5.15.11-gentoo-dist aarch64)
=================================================================
System uname: Linux-5.15.11-gentoo-dist-aarch64-with-glibc2.33
KiB Mem:     8129872 total,   3086312 free
KiB Swap:    4194300 total,   4189180 free
Timestamp of repository gentoo: Mon, 27 Dec 2021 10:45:01 +0000
Head commit of repository gentoo: 2b54c183b1dac234b44a88187722fe093900d4b5
sh bash 5.1_p8
ld GNU ld (Gentoo 2.37_p1 p0) 2.37
app-misc/pax-utils:        1.3.3::gentoo
app-shells/bash:           5.1_p8::gentoo
dev-lang/perl:             5.34.0-r3::gentoo
dev-lang/python:           3.9.9::gentoo, 3.10.0_p1::gentoo
dev-lang/rust:             1.56.1::gentoo
dev-util/cmake:            3.21.4::gentoo
dev-util/meson:            0.59.4::gentoo
sys-apps/baselayout:       2.7-r3::gentoo
sys-apps/openrc:           0.44.10::gentoo
sys-apps/sandbox:          2.25::gentoo
sys-devel/autoconf:        2.13-r1::gentoo, 2.71-r1::gentoo
sys-devel/automake:        1.16.4::gentoo
sys-devel/binutils:        2.37_p1::gentoo
sys-devel/binutils-config: 5.4::gentoo
sys-devel/gcc:             11.2.0::gentoo
sys-devel/gcc-config:      2.4::gentoo
sys-devel/libtool:         2.4.6-r6::gentoo
sys-devel/lld:             13.0.0::gentoo
sys-devel/llvm:            13.0.0::gentoo
sys-devel/make:            4.3::gentoo
sys-kernel/linux-headers:  5.15-r1::gentoo (virtual/os-headers)
sys-libs/glibc:            2.33-r7::gentoo
Repositories:

gentoo
    location: /var/db/repos/gentoo
    sync-type: rsync
    sync-uri: rsync://heimdall.smash-net.org/gentoo-portage
    priority: -1000
    sync-rsync-verify-jobs: 1
    sync-rsync-extra-opts:
    sync-rsync-verify-metamanifest: yes
    sync-rsync-verify-max-age: 24

ACCEPT_KEYWORDS="arm64"
ACCEPT_LICENSE="*"
CBUILD="aarch64-unknown-linux-gnu"
CFLAGS="-march=native -O2 -pipe"
CHOST="aarch64-unknown-linux-gnu"
CONFIG_PROTECT="/etc /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="-march=native -O2 -pipe"
DISTDIR="/var/cache/distfiles"
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="-march=native -O2 -pipe"
FEATURES="assume-digests binpkg-docompress binpkg-dostrip binpkg-logs config-protect-if-modified distlocks ebuild-locks fixlafiles ipc-sandbox merge-sync multilib-strict network-sandbox news parallel-fetch pid-sandbox preserve-libs protect-owned qa-unresolved-soname-deps sandbox sfperms strict unknown-features-warn unmerge-logs unmerge-orphans userfetch userpriv usersandbox usersync xattr"
FFLAGS="-march=native -O2 -pipe"
GENTOO_MIRRORS="http://distfiles.gentoo.org"
LANG="de_DE.utf8"
LDFLAGS="-Wl,-O1 -Wl,--as-needed"
LINGUAS="de"
MAKEOPTS="-j4"
PKGDIR="/var/cache/binpkgs"
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"
SHELL="/bin/bash"
USE="X a52 aac acl acpi alsa arm64 bluetooth branding bzip2 cairo cdda cdr cli crypt cups dbus dri dts dvdr elogind emboss encode exif flac fortran gdbm gif gpm gtk gui iconv icu ipv6 jpeg lcms libglvnd libnotify libtirpc mad mng mp3 mp4 mpeg ncurses nls nptl ogg opengl openmp pam pango pcre pdf png policykit ppds qt5 readline sdl seccomp spell split-usr ssl startup-notification svg tiff truetype udev udisks unicode upower usb vorbis wxwidgets x264 xattr xcb xml xv xvid zlib" ADA_TARGET="gnat_2020" 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" COLLECTD_PLUGINS="df interface irq load memory rrdtool swap syslog" CPU_FLAGS_ARM="edsp thumb thumb2 v4 v5 v6 v7 v8 vfp vfp-d32 vfpv3 vfpv4" 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="efi-64" INPUT_DEVICES="libinput" KERNEL="linux" L10N="de" 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="postgres12 postgres13" PYTHON_SINGLE_TARGET="python3_9" PYTHON_TARGETS="python3_9" RUBY_TARGETS="ruby26 ruby27" USERLAND="GNU" VIDEO_CARDS="fbdev dummy v4l" XTABLES_ADDONS="quota2 psd pknock lscan length2 ipv4options ipset ipp2p iface geoip fuzzy condition tee tarpit sysrq proto steal rawnat logmark ipmark dhcpmac delude chaos account"
Unset:  ADDR2LINE, AR, ARFLAGS, AS, ASFLAGS, CC, CCLD, CONFIG_SHELL, CPP, CPPFLAGS, CTARGET, CXX, CXXFILT, ELFEDIT, EMERGE_DEFAULT_OPTS, EXTRA_ECONF, F77FLAGS, FC, GCOV, GPROF, INSTALL_MASK, LC_ALL, LD, LEX, LFLAGS, LIBTOOL, MAKE, MAKEFLAGS, NM, OBJCOPY, OBJDUMP, PORTAGE_BINHOST, PORTAGE_BUNZIP2_COMMAND, PORTAGE_COMPRESS, PORTAGE_COMPRESS_FLAGS, PORTAGE_RSYNC_EXTRA_OPTS, RANLIB, READELF, RUSTFLAGS, SIZE, STRINGS, STRIP, YACC, YFLAGS
Comment 1 Sam James archtester Gentoo Infrastructure gentoo-dev Security 2021-12-28 10:27:32 UTC
Please do include the build.log of it failing too. I'm pretty sure i've built this on arm64 with -march=native which is interesting.
Comment 2 Norman Rieß 2021-12-28 10:35:28 UTC
Created attachment 760656 [details]
ffmpeg build log
Comment 3 Peer 2022-03-09 14:54:56 UTC
Created attachment 766642 [details]
Build log for media-video/ffmpeg-4.4.1-r2 with no march/mtune set

On my KVM hosted gentoo on armv8-a machine (Apple M1) this also fails without any -march or -mtune
Comment 4 Sam James archtester Gentoo Infrastructure gentoo-dev Security 2022-03-09 14:59:51 UTC
(In reply to Peer from comment #3)
> Created attachment 766642 [details]
> Build log for media-video/ffmpeg-4.4.1-r2 with no march/mtune set
> 
> On my KVM hosted gentoo on armv8-a machine (Apple M1) this also fails
> without any -march or -mtune

Could you share ffbuild/config.log too?
Comment 5 Peer 2022-03-09 15:44:13 UTC
Created attachment 766650 [details]
ffbuild/config.log

please be aware that the compile was run with
CFLAGS="-O2 -pipe" emerge --ignore-default-opts media-video/ffmpeg
Comment 6 Sam James archtester Gentoo Infrastructure gentoo-dev Security 2022-03-09 15:46:11 UTC
Thanks.

See also: https://forums.gentoo.org/viewtopic-t-1069866-start-0.html.
Comment 7 Sam James archtester Gentoo Infrastructure gentoo-dev Security 2022-06-18 16:48:45 UTC
*** Bug 852803 has been marked as a duplicate of this bug. ***
Comment 8 Sam James archtester Gentoo Infrastructure gentoo-dev Security 2022-06-18 16:48:51 UTC
*** Bug 852818 has been marked as a duplicate of this bug. ***
Comment 9 Red 2022-11-16 23:29:27 UTC
I am also hitting this issue. With both 4.4.2 and 4.4.3. I am surprised 4.4.2 is stabilized regardless of this bug. 

I have been looking for a definition on what the build system uses --cpu for, but can't seem to find it documented anywhere. Does it do anything -march=native and --disable-runtime-cpudetect doesn't? Does it select the cpu for the disabled runtime checks?

Assuming it does something, I still vote having this configure flag(s) not added on arm64 for the time being. Not that I don't want the deeper issue to be resolved ofc
Comment 10 Red 2022-11-16 23:41:29 UTC
I just saw the forum post you sent sam_, missed that earlier. If the issue here is really the ffmpeg build system not knowing my cpu, this error message is fairly misleading.

I also just noticed that I'm the first person to hit this in half a year. Attaching my emerge --info:

(CPU is a snapdragon 662)

Portage 3.0.38.1 (python 3.10.8-final-0, default/linux/arm64/17.0, gcc-11.3.0, glibc-2.35-r8, 4.19.157-perf-halium-qx1050 aarch64)
=================================================================
System uname: Linux-4.19.157-perf-halium-qx1050-aarch64-with-glibc2.35
KiB Mem:     5802660 total,   1359588 free
KiB Swap:    3145724 total,   2271524 free
Timestamp of repository gentoo: Wed, 16 Nov 2022 17:30:01 +0000
Head commit of repository gentoo: 25080fed8a2e6f4d603bed188342b9569d960b3e
sh bash 5.1_p16-r2
ld GNU ld (Gentoo 2.38 p4) 2.38
app-misc/pax-utils:        1.3.5::gentoo
app-shells/bash:           5.1_p16-r2::gentoo
dev-java/java-config:      2.3.1::gentoo
dev-lang/perl:             5.34.1-r4::gentoo
dev-lang/python:           2.7.18_p16::gentoo, 3.10.8_p2::gentoo, 3.11.0_p1::gentoo
dev-lang/rust:             1.64.0-r1::gentoo
dev-util/cmake:            3.24.2::gentoo
dev-util/meson:            0.63.2-r1::gentoo
sys-apps/baselayout:       2.8::gentoo
sys-apps/openrc:           0.45.2-r1::gentoo
sys-apps/sandbox:          2.29::gentoo
sys-devel/autoconf:        2.13-r6::gentoo, 2.71-r1::gentoo
sys-devel/automake:        1.16.5::gentoo
sys-devel/binutils:        2.38-r2::gentoo
sys-devel/binutils-config: 5.4.1::gentoo
sys-devel/gcc:             11.3.0::gentoo
sys-devel/gcc-config:      2.8::gentoo
sys-devel/libtool:         2.4.7::gentoo
sys-devel/make:            4.3::gentoo
sys-kernel/linux-headers:  5.15-r3::gentoo (virtual/os-headers)
sys-libs/glibc:            2.35-r8::gentoo
Repositories:

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

ACCEPT_KEYWORDS="arm64"
ACCEPT_LICENSE="@FREE"
CBUILD="aarch64-unknown-linux-gnu"
CFLAGS="-O3 -march=native -flto -pipe"
CHOST="aarch64-unknown-linux-gnu"
CONFIG_PROTECT="/etc /usr/share/gnupg/qualified.txt"
CONFIG_PROTECT_MASK="/etc/ca-certificates.conf /etc/env.d /etc/fonts/fonts.conf /etc/gconf /etc/gentoo-release /etc/revdep-rebuild /etc/sandbox.d /etc/terminfo"
CXXFLAGS="-O3 -march=native -flto -pipe"
DISTDIR="/var/cache/distfiles"
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 XDG_STATE_HOME"
FCFLAGS="-O3 -march=native -flto -pipe"
FEATURES="assume-digests binpkg-docompress binpkg-dostrip binpkg-logs binpkg-multi-instance buildpkg-live config-protect-if-modified distlocks ebuild-locks fixlafiles ipc-sandbox merge-sync multilib-strict network-sandbox news parallel-fetch pid-sandbox preserve-libs protect-owned qa-unresolved-soname-deps sandbox sfperms strict unknown-features-warn unmerge-logs unmerge-orphans usersandbox usersync xattr"
FFLAGS="-O3 -march=native -flto -pipe"
GENTOO_MIRRORS="http://distfiles.gentoo.org"
LANG="en_US.utf8"
LDFLAGS="-Wl,-O1 -Wl,--as-needed"
MAKEOPTS="-j7"
PKGDIR="/var/cache/binpkgs"
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"
SHELL="/bin/bash"
USE="X acl arm64 bzip2 cli crypt dri fortran gdbm iconv ipv6 libglvnd libtirpc ncurses nls nptl openmp pam pcre readline seccomp split-usr ssl test-rust unicode wayland xattr zlib" ADA_TARGET="gnat_2020" 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" COLLECTD_PLUGINS="df interface irq load memory rrdtool swap syslog" CPU_FLAGS_ARM="edsp thumb thumb2 v4 v5 v6 v7 v8 vfp vfp-d32 vfpv3 vfpv4" 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" INPUT_DEVICES="libinput" KERNEL="linux" 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-4 php8-0" POSTGRES_TARGETS="postgres12 postgres13" PYTHON_SINGLE_TARGET="python3_10" PYTHON_TARGETS="python3_10" RUBY_TARGETS="ruby27" USERLAND="GNU" VIDEO_CARDS="fbdev dummy v4l" XTABLES_ADDONS="quota2 psd pknock lscan length2 ipv4options ipset ipp2p iface geoip fuzzy condition tee tarpit sysrq proto steal rawnat logmark ipmark dhcpmac delude chaos account"
Unset:  ADDR2LINE, AR, ARFLAGS, AS, ASFLAGS, CC, CCLD, CONFIG_SHELL, CPP, CPPFLAGS, CTARGET, CXX, CXXFILT, ELFEDIT, EMERGE_DEFAULT_OPTS, EXTRA_ECONF, F77FLAGS, FC, GCOV, GPROF, INSTALL_MASK, LC_ALL, LD, LEX, LFLAGS, LIBTOOL, LINGUAS, MAKE, MAKEFLAGS, NM, OBJCOPY, OBJDUMP, PORTAGE_BINHOST, PORTAGE_BUNZIP2_COMMAND, PORTAGE_COMPRESS, PORTAGE_COMPRESS_FLAGS, PORTAGE_RSYNC_EXTRA_OPTS, RANLIB, READELF, RUSTFLAGS, SIZE, STRINGS, STRIP, YACC, YFLAGS
Comment 11 Mart Raudsepp gentoo-dev 2023-09-30 15:54:09 UTC
Created attachment 871837 [details, diff]
Dirty workaround

I get the same issue on a Apple M2.

The problem for me is basically this:

# gcc -v -E -x c /dev/null -o /dev/null -march=native 2>&1 | grep /cc1
 /usr/libexec/gcc/aarch64-unknown-linux-gnu/13/cc1 -E -quiet -v /dev/null -o /dev/null -mlittle-endian -mabi=lp64 -dumpbase null
# gcc -v -E -x c /dev/null -o /dev/null -mcpu=native 2>&1 | grep /cc1
 /usr/libexec/gcc/aarch64-unknown-linux-gnu/13/cc1 -E -quiet -v /dev/null -o /dev/null -mlittle-endian -mabi=lp64 -dumpbase null
# gcc -v -E -x c /dev/null -o /dev/null -march=native -mcpu=native 2>&1 | grep /cc1
 /usr/libexec/gcc/aarch64-unknown-linux-gnu/13/cc1 -E -quiet -v /dev/null -o /dev/null -mlittle-endian -mabi=lp64 -march=armv8-a+crc+lse+rcpc+rdma+dotprod+aes+sha3+fp16fml+sb+ssbs+i8mm+bf16+flagm+pauth -dumpbase null

See how it repeats -march= with some values only when BOTH -march and -mcpu are given. My understanding is that -mcpu should be enough. I think this might be a combination of https://gcc.gnu.org/bugzilla/show_bug.cgi?id=110901 and gcc just not knowing anything about the Apple CPUs or something along those lines.
If you are on arm64, then you should look at -mcpu if your intention is to get the most optimized code for the given CPU - -march=native alone does NOT provide that on Aarch64 GCC.

The ffmpeg configure test does not use provided CFLAGS and makes separate tests for -march=native and -mcpu=native, trying to find a -march= and -mcpu= (respectively) from the output. Thus I hacked around it with the attached patch, but it's very dirty one and mustn't be used generically as it breaks amd64, etc. Maybe a suitable generically applicable workaround would be to add a third test for gcc that would also test with both -march=native and -mcpu=native and then try to find -march from the output. I didn't bother with this, because

1. It's questionable check in ffmpeg configure in the first place - we should understand why it's even doing these checks
2. It feels like it's an underlying gcc bug to be fixed
Comment 12 Mart Raudsepp gentoo-dev 2023-09-30 15:58:54 UTC
My case does not feel relevant to the original report, as I don't see how COMMON_FLAGS would affect what I found, but it feels relevant to comment #3 case.
Comment 13 Sam James archtester Gentoo Infrastructure gentoo-dev Security 2024-01-07 16:08:45 UTC
(In reply to Mart Raudsepp from comment #11)
> Created attachment 871837 [details, diff] [details, diff]
> Dirty workaround
> [...]

Filed as https://gcc.gnu.org/bugzilla/show_bug.cgi?id=113257.
Comment 14 Morgan Wahl 2024-03-01 02:15:37 UTC
I ran into this error on a RK3399 (in a pinebook pro). My COMMON_FLAGS is `-Os -pipe -march=native`.

Playing with `gcc -v` I see `-march=native` and `-mcpu=native` both result in the same thing: `-mcpu=cortex-a72.cortex-a53+crc+crypto`. This is true when they are used separate or together.

I worked around the problem by creating a /etc/portage/env/ffmpeg.conf with:

# ffmpeg configure does weird stuff that doesn't work with -march=native on arm64
COMMON_FLAGS="-Os -pipe -mcpu=cortex-a72.cortex-a53+crc+crypto"
CFLAGS="${COMMON_FLAGS}"
CXXFLAGS="${COMMON_FLAGS}"
FCFLAGS="${COMMON_FLAGS}"
FFLAGS="${COMMON_FLAGS}"

And then reference that in /etc/portage/package.env/ .
Comment 15 Jean-Claude Gervais 2024-03-12 01:54:43 UTC
Can confirm this also manifests when compiling on arm64.

Workaround of removing -march=native from common flags and instead replacing with -mtune=cortex-a72 does indeed permit the package to build.