Gentoo Websites Logo
Go to: Gentoo Home Documentation Forums Lists Bugs Planet Store Wiki Get Gentoo!
Bug 507742 (PR42444) - sys-devel/gcc: later -march options don't override -march=native
Summary: sys-devel/gcc: later -march options don't override -march=native
Status: RESOLVED FIXED
Alias: PR42444
Product: Gentoo Linux
Classification: Unclassified
Component: Current packages (show other bugs)
Hardware: All Linux
: Normal normal (vote)
Assignee: Gentoo Toolchain Maintainers
URL: http://gcc.gnu.org/PR42444
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2014-04-15 17:38 UTC by Robin Johnson
Modified: 2023-09-28 11:55 UTC (History)
1 user (show)

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


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Robin Johnson archtester Gentoo Infrastructure gentoo-dev Security 2014-04-15 17:38:07 UTC
Possibly a bug in GCC's handling of march=native.

I was building an extra binpkg of glibc for use testing in a VM, and appended my CFLAGS+CXXFLAGS with: "-march=x86-64 -mtune=generic"

CFLAGS="-march=native -O2 -pipe -march=x86-64 -mtune=generic" \
CXXFLAGS="-march=native -O2 -pipe -march=x86-64 -mtune=generic" \
emerge glibc

The resulting glibc (libc.a is the easiest to check) contains usages of AVX instructions, despite the latter -march explicitly not having AVX.

It seems that the -march=native was expanded BEFORE being cancelled by -march=x86, and this leads to having -march=corei7-avx .. -mavx .. -march=x64-64 and the latter does NOT disable AVX usage.

With tracing, I managed to capture GCC invocation of cc1 this that shows the problem superbly:
portage   6310  6307  0 09:30 pts/38   00:00:00 /usr/x86_64-pc-linux-gnu/gcc-bin/4.8.2/x86_64-pc-linux-gnu-gcc -m64 -c -std=gnu99 -fgnu89-inline -O2 -Wall -Winline -Wwrite-strings -fmerge-all-constants -fno-strict-aliasing -frounding-math -march=native -march=x86-64 -mtune=generic -pipe -Wstrict-prototypes -Wno-write-strings -Wno-char-subscripts -U_FORTIFY_SOURCE -DLOCALEDIR="/usr/lib64/locale" -DLOCALE_ALIAS_PATH="/usr/share/locale" -Iprograms -I../include -I/dev/shm/portage/sys-libs/glibc-2.18-r1/work/build-amd64-x86_64-pc-linux-gnu-nptl/locale -I/dev/shm/portage/sys-libs/glibc-2.18-r1/work/build-amd64-x86_64-pc-linux-gnu-nptl -I../sysdeps/unix/sysv/linux/x86_64/64/nptl -I../sysdeps/unix/sysv/linux/x86_64/64 -I../nptl/sysdeps/unix/sysv/linux/x86_64 -I../nptl/sysdeps/unix/sysv/linux/x86 -I../sysdeps/unix/sysv/linux/x86 -I../sysdeps/unix/sysv/linux/x86_64 -I../sysdeps/unix/sysv/linux/wordsize-64 -I../nptl/sysdeps/unix/sysv/linux -I../nptl/sysdeps/pthread -I../sysdeps/pthread -I../ports/sysdeps/unix/sysv/linux -I../sysdeps/unix/sysv/linux -I../sysdeps/gnu -I../sysdeps/unix/inet -I../nptl/sysdeps/unix/sysv -I../ports/sysdeps/unix/sysv -I../sysdeps/unix/sysv -I../sysdeps/unix/x86_64 -I../nptl/sysdeps/unix -I../ports/sysdeps/unix -I../sysdeps/unix -I../sysdeps/posix -I../nptl/sysdeps/x86_64/64 -I../sysdeps/x86_64/64 -I../sysdeps/x86_64/fpu/multiarch -I../sysdeps/x86_64/fpu -I../sysdeps/x86/fpu -I../sysdeps/x86_64/multiarch -I../nptl/sysdeps/x86_64 -I../sysdeps/x86_64 -I../sysdeps/x86 -I../sysdeps/ieee754/ldbl-96 -I../sysdeps/ieee754/dbl-64/wordsize-64 -I../sysdeps/ieee754/dbl-64 -I../sysdeps/ieee754/flt-32 -I../sysdeps/wordsize-64 -I../sysdeps/ieee754 -I../sysdeps/generic -I../nptl -I../ports -I.. -I../libio -I. -nostdinc -isystem /usr/lib/gcc/x86_64-pc-linux-gnu/4.8.2/include -isystem /usr/lib/gcc/x86_64-pc-linux-gnu/4.8.2/include-fixed -isystem /usr/include -D_LIBC_REENTRANT -include ../include/libc-symbols.h -DLOCALE_PATH="/usr/lib64/locale:/usr/share/i18n" -DCHARMAP_PATH="/usr/share/i18n/charmaps" -DREPERTOIREMAP_PATH="/usr/share/i18n/repertoiremaps" -DLOCSRCDIR="/usr/share/i18n/locales" -DHAVE_CONFIG_H -DNOT_IN_libc -MD -MP -MF /dev/shm/portage/sys-libs/glibc-2.18-r1/work/build-amd64-x86_64-pc-linux-gnu-nptl/locale/locfile.o.dt -MT /dev/shm/portage/sys-libs/glibc-2.18-r1/work/build-amd64-x86_64-pc-linux-gnu-nptl/locale/locfile.o -E programs/locfile.c

portage   6315  6310  0 09:30 pts/38   00:00:00 /usr/libexec/gcc/x86_64-pc-linux-gnu/4.8.2/cc1 -E -quiet -nostdinc -I programs -I ../include -I /dev/shm/portage/sys-libs/glibc-2.18-r1/work/build-amd64-x86_64-pc-linux-gnu-nptl/locale -I /dev/shm/portage/sys-libs/glibc-2.18-r1/work/build-amd64-x86_64-pc-linux-gnu-nptl -I ../sysdeps/unix/sysv/linux/x86_64/64/nptl -I ../sysdeps/unix/sysv/linux/x86_64/64 -I ../nptl/sysdeps/unix/sysv/linux/x86_64 -I ../nptl/sysdeps/unix/sysv/linux/x86 -I ../sysdeps/unix/sysv/linux/x86 -I ../sysdeps/unix/sysv/linux/x86_64 -I ../sysdeps/unix/sysv/linux/wordsize-64 -I ../nptl/sysdeps/unix/sysv/linux -I ../nptl/sysdeps/pthread -I ../sysdeps/pthread -I ../ports/sysdeps/unix/sysv/linux -I ../sysdeps/unix/sysv/linux -I ../sysdeps/gnu -I ../sysdeps/unix/inet -I ../nptl/sysdeps/unix/sysv -I ../ports/sysdeps/unix/sysv -I ../sysdeps/unix/sysv -I ../sysdeps/unix/x86_64 -I ../nptl/sysdeps/unix -I ../ports/sysdeps/unix -I ../sysdeps/unix -I ../sysdeps/posix -I ../nptl/sysdeps/x86_64/64 -I ../sysdeps/x86_64/64 -I ../sysdeps/x86_64/fpu/multiarch -I ../sysdeps/x86_64/fpu -I ../sysdeps/x86/fpu -I ../sysdeps/x86_64/multiarch -I ../nptl/sysdeps/x86_64 -I ../sysdeps/x86_64 -I ../sysdeps/x86 -I ../sysdeps/ieee754/ldbl-96 -I ../sysdeps/ieee754/dbl-64/wordsize-64 -I ../sysdeps/ieee754/dbl-64 -I ../sysdeps/ieee754/flt-32 -I ../sysdeps/wordsize-64 -I ../sysdeps/ieee754 -I ../sysdeps/generic -I ../nptl -I ../ports -I .. -I ../libio -I . -MD locfile.d -MF /dev/shm/portage/sys-libs/glibc-2.18-r1/work/build-amd64-x86_64-pc-linux-gnu-nptl/locale/locfile.o.dt -MP -MT /dev/shm/portage/sys-libs/glibc-2.18-r1/work/build-amd64-x86_64-pc-linux-gnu-nptl/locale/locfile.o -U _FORTIFY_SOURCE -D LOCALEDIR="/usr/lib64/locale" -D LOCALE_ALIAS_PATH="/usr/share/locale" -D _LIBC_REENTRANT -D LOCALE_PATH="/usr/lib64/locale:/usr/share/i18n" -D CHARMAP_PATH="/usr/share/i18n/charmaps" -D REPERTOIREMAP_PATH="/usr/share/i18n/repertoiremaps" -D LOCSRCDIR="/usr/share/i18n/locales" -D HAVE_CONFIG_H -D NOT_IN_libc -isystem /usr/lib/gcc/x86_64-pc-linux-gnu/4.8.2/include -isystem /usr/lib/gcc/x86_64-pc-linux-gnu/4.8.2/include-fixed -isystem /usr/include -include ../include/libc-symbols.h programs/locfile.c -march=corei7-avx -mcx16 -msahf -mno-movbe -maes -mpclmul -mpopcnt -mno-abm -mno-lwp -mno-fma -mno-fma4 -mno-xop -mno-bmi -mno-bmi2 -mno-tbm -mavx -mno-avx2 -msse4.2 -msse4.1 -mno-lzcnt -mno-rtm -mno-hle -mno-rdrnd -mno-f16c -mno-fsgsbase -mno-rdseed -mno-prfchw -mno-adx -mfxsr -mxsave -mxsaveopt -m64 -march=x86-64 -mtune=generic -std=gnu99 -Wall -Winline -Wstrict-prototypes -Wno-write-strings -Wno-char-subscripts -fgnu89-inline -fmerge-all-constants -fno-strict-aliasing -frounding-math -O2
Comment 1 SpanKY gentoo-dev 2014-04-15 18:04:33 UTC
can you clarify the failure case exactly ?  glibc itself containing AVX is not a bug.  with multiarch/ifunc support, glibc will include many optimized routines for ISA extensions and then decide at runtime which to use.  so it'll include a variety of string/mem funcs that use various vector sets (SSE/AVX/etc...), but it isn't a problem.
Comment 2 Ryan Hill (RETIRED) gentoo-dev 2014-04-16 00:47:52 UTC
He's saying this shouldn't happen:

$ echo "" | gcc -march=native -march=x86-64 -v -E - 2>&1 | grep cc1
 /usr/libexec/gcc/x86_64-pc-linux-gnu/4.9.0-pre9999/cc1 -E -quiet -v - -march=ivybridge -mmmx -mno-3dnow -msse -msse2 -msse3 -mssse3 -mno-sse4a -mcx16 -msahf -mno-movbe -maes -mno-sha -mpclmul -mpopcnt -mno-abm -mno-lwp -mno-fma -mno-fma4 -mno-xop -mno-bmi -mno-bmi2 -mno-tbm -mavx -mno-avx2 -msse4.2 -msse4.1 -mno-lzcnt -mno-rtm -mno-hle -mrdrnd -mf16c -mfsgsbase -mno-rdseed -mno-prfchw -mno-adx -mfxsr -mxsave -mxsaveopt -mno-avx512f -mno-avx512er -mno-avx512cd -mno-avx512pf -mno-prefetchwt1 --param l1-cache-size=32 --param l1-cache-line-size=64 --param l2-cache-size=8192 -mtune=ivybridge -march=x86-64

-march=x86-64 should override -march=native and it shouldn't be expanded at all.
Comment 3 Ryan Hill (RETIRED) gentoo-dev 2014-04-16 00:54:56 UTC
Course the interim solution is "stop doing that". ;)
Comment 4 Sergei Trofimovich (RETIRED) gentoo-dev 2019-05-04 20:49:10 UTC
There is a chance https://gcc.gnu.org/PR69471 fixed -march=native ordering properly. Released with gcc-9.1.0.