Gentoo Websites Logo
Go to: Gentoo Home Documentation Forums Lists Bugs Planet Store Wiki Get Gentoo!
Bug 886484 - sys-devel/gcc - Generates invalid -march option when ARMv8 sha3 extensions present
Summary: sys-devel/gcc - Generates invalid -march option when ARMv8 sha3 extensions pr...
Status: CONFIRMED
Alias: None
Product: Gentoo Linux
Classification: Unclassified
Component: Current packages (show other bugs)
Hardware: ARM64 Linux
: Normal normal (vote)
Assignee: Gentoo Toolchain Maintainers
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2022-12-17 18:21 UTC by Leonid Kopylov
Modified: 2022-12-18 17:41 UTC (History)
2 users (show)

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


Attachments
build.log (build.log,10.04 KB, text/plain)
2022-12-17 18:21 UTC, Leonid Kopylov
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Leonid Kopylov 2022-12-17 18:21:01 UTC
# emerge -pqv '=app-crypt/rhash-1.4.3::gentoo'
[ebuild  N    ] app-crypt/rhash-1.4.3  USE="nls ssl -debug -static-libs"

# emerge --info '=app-crypt/rhash-1.4.3::gentoo'
Portage 3.0.41 (python 3.10.9-final-0, default/linux/arm64/17.0/systemd/merged-usr, gcc-12, glibc-2.36-r6, 6.1.0-gentoo-arm64 aarch64)
=================================================================
                         System Settings
=================================================================
System uname: Linux-6.1.0-gentoo-arm64-aarch64-with-glibc2.36
KiB Mem:    32818988 total,  24345532 free
KiB Swap:    8388604 total,   8388604 free
Timestamp of repository gentoo: Sat, 17 Dec 2022 16:30:01 +0000
Head commit of repository gentoo: 48ec3b8115eca5ecf31d0e539c74e083ec1d6791
sh bash 5.2_p15
ld GNU ld (Gentoo 2.39 p5) 2.39.0
ccache version 4.7.4 [disabled]
app-misc/pax-utils:        1.3.5::gentoo
app-shells/bash:           5.2_p15::gentoo
dev-lang/perl:             5.36.0-r1::gentoo
dev-lang/python:           3.10.9::gentoo, 3.11.1::gentoo, 3.12.0_alpha3-r1::gentoo
dev-util/ccache:           4.7.4::gentoo
dev-util/cmake:            3.25.1::gentoo
dev-util/meson:            0.64.1::gentoo
sys-apps/baselayout:       2.9::gentoo
sys-apps/sandbox:          2.29::gentoo
sys-apps/systemd:          252.3::gentoo
sys-devel/autoconf:        2.71-r5::gentoo
sys-devel/automake:        1.16.5::gentoo
sys-devel/binutils:        2.39-r4::gentoo
sys-devel/binutils-config: 5.4.1::gentoo
sys-devel/gcc:             11.3.1_p20221209::gentoo, 12.2.1_p20221210::gentoo
sys-devel/gcc-config:      2.8::gentoo
sys-devel/libtool:         2.4.7-r1::gentoo
sys-devel/make:            4.4::gentoo
sys-kernel/linux-headers:  6.1::gentoo (virtual/os-headers)
sys-libs/glibc:            2.36-r6::gentoo
Repositories:

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

ACCEPT_KEYWORDS="arm64 ~arm64"
ACCEPT_LICENSE="* -@EULA"
CBUILD="aarch64-unknown-linux-gnu"
CFLAGS="-march=armv8-a+crypto+crc+lse+rcpc+rdma+dotprod+sha3+fp16fml+sb+ssbs+flagm+pauth -O2 -pipe -fomit-frame-pointer"
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/texmf/language.dat.d /etc/texmf/language.def.d /etc/texmf/updmap.d /etc/texmf/web2c"
CXXFLAGS="-march=armv8-a+crypto+crc+lse+rcpc+rdma+dotprod+sha3+fp16fml+sb+ssbs+flagm+pauth -O2 -pipe -fomit-frame-pointer"
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="-march=armv8-a+crypto+crc+lse+rcpc+rdma+dotprod+sha3+fp16fml+sb+ssbs+flagm+pauth -O2 -pipe -fomit-frame-pointer"
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 strict-keepdir unknown-features-warn unmerge-logs unmerge-orphans userfetch userpriv usersandbox usersync xattr"
FFLAGS="-march=armv8-a+crypto+crc+lse+rcpc+rdma+dotprod+sha3+fp16fml+sb+ssbs+flagm+pauth -O2 -pipe -fomit-frame-pointer"
GENTOO_MIRRORS="https://mirror.isoc.org.il/pub/gentoo/"
LANG="en_US.utf8"
LC_ALL="en_US.UTF-8"
LDFLAGS="-Wl,-O1 -Wl,--as-needed"
LEX="flex"
MAKEOPTS="-j6"
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 audit berkdb bluetooth btrfs bzip2 cgi cli crypt cryptsetup curl dbi dbus device-mapper doc dri examples experimental extra extras fontconfig fortran games gcrypt gd gdbm gmp gnutls go gpg gpm graphite graphviz gssapi highlight http iconv icu idn ipv6 json kerberos libglvnd libtirpc lmdb lua lvm lz4 lzma lzo magic mbedtls memcached ncurses netlink nettle nls nptl nss offensive openmp openssl pam pcap pcre perl pkcs11 plugins policykit python qrcode rdma readline redis sdl seccomp smtp snmp source sqlite ssh ssl symlink syslog systemd tcl test-rust tools truetype udev unicode utils vala xattr xml yaml zlib zstd" ADA_TARGET="gnat_2021" 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 stage" COLLECTD_PLUGINS="df interface irq load memory rrdtool swap syslog" CPU_FLAGS_ARM="edsp thumb vfp vfpv3 vfpv4 vfp-d32 aes sha1 sha2 crc32 v4 v5 v6 v7 v8 thumb2" 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="evdev libinput" KERNEL="linux" L10N="en en-US he ru" LCD_DEVICES="bayrad cfontz cfontz633 glk hd44780 lb216 lcdm001 mtxorb ncurses text" LIBREOFFICE_EXTENSIONS="nlpsolver" 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 ruby30 ruby31" USERLAND="GNU" VIDEO_CARDS="virgl" 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, LD, 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 1 Leonid Kopylov 2022-12-17 18:21:22 UTC
Created attachment 843223 [details]
build.log
Comment 2 James Le Cuirot gentoo-dev 2022-12-17 22:02:51 UTC
Your CFLAGS are broken. See man gcc.

       sha3
           Enable the sha512 and sha3 crypto extension.  This also enables Advanced SIMD instructions. Use of this option with architectures prior to Armv8.2-A is not supported.

In other words, you would need to put -march=armv8.2-a. Seriously though, stop trying to be smarter than the compiler and just pick the CPU you actually have, like -mcpu=cortex-a55. Please also try without exotic CFLAGS before filing another bug report.
Comment 3 Leonid Kopylov 2022-12-18 03:45:21 UTC
(In reply to James Le Cuirot from comment #2)
> Your CFLAGS are broken. See man gcc.
> 
>        sha3
>            Enable the sha512 and sha3 crypto extension.  This also enables
> Advanced SIMD instructions. Use of this option with architectures prior to
> Armv8.2-A is not supported.
> 
> In other words, you would need to put -march=armv8.2-a. Seriously though,
> stop trying to be smarter than the compiler and just pick the CPU you
> actually have, like -mcpu=cortex-a55. Please also try without exotic CFLAGS
> before filing another bug report.

it failed with -march=native, so i expanded it according to:

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


so what should i put in CFLAGS?
Comment 4 James Le Cuirot gentoo-dev 2022-12-18 09:29:19 UTC
Sorry. Please mention that in future so I don't jump to the wrong conclusion.

This sounds like a bug in GCC. It blew up the same way for me with the explicit flags but -march=native works here. I don't have sha3 in /proc/cpuinfo though. Please post yours and let us know what board and CPU you actually have. I'll pass this over to the toolchain folks.
Comment 5 Leonid Kopylov 2022-12-18 09:32:12 UTC
(In reply to James Le Cuirot from comment #4)
> Sorry. Please mention that in future so I don't jump to the wrong conclusion.
> 
> This sounds like a bug in GCC. It blew up the same way for me with the
> explicit flags but -march=native works here. I don't have sha3 in
> /proc/cpuinfo though. Please post yours and let us know what board and CPU
> you actually have. I'll pass this over to the toolchain folks.


i have Apple Mac Studio - M1 Max (Gentoo installed inside Parallels Desktop VM)


# cat /proc/cpuinfo
processor       : 0
BogoMIPS        : 48.00
Features        : fp asimd evtstrm aes pmull sha1 sha2 crc32 atomics fphp asimdhp cpuid asimdrdm jscvt fcma lrcpc dcpop sha3 asimddp sha512 asimdfhm dit uscat ilrcpc flagm ssbs sb paca pacg dcpodp flagm2 frint
CPU implementer : 0x41
CPU architecture: 8
CPU variant     : 0x0
CPU part        : 0x000
CPU revision    : 0
Comment 6 James Le Cuirot gentoo-dev 2022-12-18 10:48:04 UTC
Hmm, that complicates things. The last few fields being 0 there is probably related. The kernel is telling GCC it is the most basic ARMv8 CPU, except that it has all those extensions, which doesn't make sense. I cannot find a good example of what cpuinfo looks like on M1 bare metal. If it looked the same then it would be a kernel bug, although that seems unlikely. What seems more likely is that Parallels exposes bogus CPU info to the VM. I can see reports of Docker reporting similarly bogus information on M1 Macs. We cannot fix Parallels, so my suggestion would be to just not use -march=native. I'll let the toolchain folks decide though.
Comment 7 Leonid Kopylov 2022-12-18 17:41:23 UTC
(In reply to James Le Cuirot from comment #6)
> Hmm, that complicates things. The last few fields being 0 there is probably
> related. The kernel is telling GCC it is the most basic ARMv8 CPU, except
> that it has all those extensions, which doesn't make sense. I cannot find a
> good example of what cpuinfo looks like on M1 bare metal. If it looked the
> same then it would be a kernel bug, although that seems unlikely. What seems
> more likely is that Parallels exposes bogus CPU info to the VM. I can see
> reports of Docker reporting similarly bogus information on M1 Macs. We
> cannot fix Parallels, so my suggestion would be to just not use
> -march=native. I'll let the toolchain folks decide though.

i don't know if this can help, but using command from https://github.com/docker/for-mac/issues/6512 on macOS directly:

=> sysctl -a  hw.optional                                                                                                                                                                    

hw.optional.arm.FEAT_FlagM: 1
hw.optional.arm.FEAT_FlagM2: 1
hw.optional.arm.FEAT_FHM: 1
hw.optional.arm.FEAT_DotProd: 1
hw.optional.arm.FEAT_SHA3: 1
hw.optional.arm.FEAT_RDM: 1
hw.optional.arm.FEAT_LSE: 1
hw.optional.arm.FEAT_SHA256: 1
hw.optional.arm.FEAT_SHA512: 1
hw.optional.arm.FEAT_SHA1: 1
hw.optional.arm.FEAT_AES: 1
hw.optional.arm.FEAT_PMULL: 1
hw.optional.arm.FEAT_SPECRES: 0
hw.optional.arm.FEAT_SB: 1
hw.optional.arm.FEAT_FRINTTS: 1
hw.optional.arm.FEAT_LRCPC: 1
hw.optional.arm.FEAT_LRCPC2: 1
hw.optional.arm.FEAT_FCMA: 1
hw.optional.arm.FEAT_JSCVT: 1
hw.optional.arm.FEAT_PAuth: 1
hw.optional.arm.FEAT_PAuth2: 0
hw.optional.arm.FEAT_FPAC: 0
hw.optional.arm.FEAT_DPB: 1
hw.optional.arm.FEAT_DPB2: 1
hw.optional.arm.FEAT_BF16: 0
hw.optional.arm.FEAT_I8MM: 0
hw.optional.arm.FEAT_ECV: 1
hw.optional.arm.FEAT_LSE2: 1
hw.optional.arm.FEAT_CSV2: 1
hw.optional.arm.FEAT_CSV3: 1
hw.optional.arm.FEAT_DIT: 1
hw.optional.arm.FEAT_FP16: 1
hw.optional.arm.FEAT_SSBS: 1
hw.optional.arm.FEAT_BTI: 0
hw.optional.arm.FP_SyncExceptions: 1
hw.optional.floatingpoint: 1
hw.optional.neon: 1
hw.optional.neon_hpfp: 1
hw.optional.neon_fp16: 1
hw.optional.armv8_1_atomics: 1
hw.optional.armv8_2_fhm: 1
hw.optional.armv8_2_sha512: 1
hw.optional.armv8_2_sha3: 1
hw.optional.armv8_3_compnum: 1
hw.optional.watchpoint: 4
hw.optional.breakpoint: 6
hw.optional.armv8_crc32: 1
hw.optional.armv8_gpi: 1
hw.optional.AdvSIMD: 1
hw.optional.AdvSIMD_HPFPCvt: 1
hw.optional.ucnormal_mem: 1
hw.optional.arm64: 1