How can I find out what the -march
default argument is for the current architecture if I don\'t supply any?
I think that the answer is there isn't any equivalent. Either you don't specify -march=
and the compiler uses the architecture's minimal instruction set, or you do specify -march=
and it uses features of whichever cpu model you ask for. So there is no way to write a -march=
option that is equivalent to omitting the -march
option.
Maybe if you explain what motivated the question we could improve on this answer.
Running the command
gcc -v
will show something like this:
COLLECT_GCC=gcc
COLLECT_LTO_WRAPPER=/usr/lib/gcc/x86_64-unknown-linux-gnu/4.7.1/lto-wrapper
Target: x86_64-unknown-linux-gnu
Configured with: /build/src/gcc-4.7.1/configure --prefix=/usr --libdir=/usr/lib --libexecdir=/usr/lib --mandir=/usr/share/man --infodir=/usr/share/info --with-bugurl=https://bugs.archlinux.org/ --enable-languages=c,c++,ada,fortran,go,lto,objc,obj-c++ --enable-shared --enable-threads=posix --with-system-zlib --enable-__cxa_atexit --disable-libunwind-exceptions --enable-clocale=gnu --disable-libstdcxx-pch --enable-libstdcxx-time --enable-gnu-unique-object --enable-linker-build-id --with-ppl --enable-cloog-backend=isl --disable-ppl-version-check --disable-cloog-version-check --enable-lto --enable-gold --enable-ld=default --enable-plugin --with-plugin-ld=ld.gold --with-linker-hash-style=gnu --enable-multilib --disable-libssp --disable-build-with-cxx --disable-build-poststage1-with-cxx --enable-checking=release
Thread model: posix
gcc versie 4.7.1 (GCC)
The Target:
line is what you want. You should be able to deduce enough information from this.
You can use gcc -Q --help=<type>
to list the current option values of the given <type>
. Thus:
$ gcc -Q --help=target | grep march
-march= x86-64
$ gcc -m32 -Q --help=target | grep march
-march= i686
$ i686-w64-mingw32-gcc -Q --help=target | grep march
-march= pentiumpro
Edit: Actually, this option is not as generally useful as it appears, because target-specific defaults are not reflected in the output.
I found this gem on the GCC mailing list that prints the default -march
and mtune
parameters:
$ echo | gcc -v -E - 2>&1 | grep cc1
/usr/lib/gcc/x86_64-unknown-linux-gnu/4.9.0/cc1 -E -quiet -v - -mtune=generic -march=x86-64
Basically, you are compiling an empty file from stdin and while doing so, you print the commands.
gcc -dumpmachine
gives you the target triplet, e.g. x86_64-unknown-linux-gnu
If gcc -v
shows GCC was configured with a --with-arch
option (or --with-arch-32
and/or --with-arch-64
) then that's what will be the default.
Without a --with-arch
option (and if there isn't a custom specs file in use) then the arch used will be the default for the target.
For x86, up to and including GCC 4.4, the default for 32-bit was -march=i386
and for 64-bit was -march=x86-64
(note the hyphen instead of underscore.)
For x86 with GCC 4.5 and later versions the default arch is inferred from the target triplet i.e. configuring for i586-pc-linux-gnu
means the default is -march=i586
, configuring for core2-pc-linux-gnu
means the default is -march=core2
.
Some other platforms also infer the default arch from the target triplet (and have done since before GCC 4.4) so e.g. ultrasparc2-sun-solaris2.10
implies -march=ultrasparc2
.