How can I find out what the -march
default argument is for the current architecture if I don't supply any?
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
.
gcc -dumpmachine
before but couldn't remember the argument name. However I can't do a easy search in the man page for the correct argument sometimes. Maybe I should change "avoids another read of" to "avoids another search through" ;) –
Sabrasabre mingw32
and I don't see any option to find whether it means i386 or i486 or i686 or what (unlike cygwin gcc for mingw, which says i686-pc-mingw). –
Horrify echo | gcc -v -E - 2>&1 | grep cc1
shown in another answer will reveal what the specs file is using. –
Felodese gcc -dumpmachine
just give you the target by which your gcc was built for? I'm not sure it gives you the exact architecture of your machine. –
Excavate -march
value, which is what the question is about. The question is not about the exact architecture of the machine, it's about the default settings for a particular build of GCC, which depends on the target GCC was built for, and other configure options ... as the answer explains. –
Stringboard gcc -dumpversion
–
Digestible 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.
-m32
and -m64
can be used on the gcc
invocation to ask for either 32-bit or 64-bit (default) targets. –
Felodese 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.
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.
-march
? –
Cellarage x86_64
. But that is a general one. A full list can be found int the GCC manual: gcc.gnu.org/onlinedocs/gcc-5.1.0/gcc/…. –
Bearskin 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.
© 2022 - 2024 — McMap. All rights reserved.
gcc -dumpmachine
options is perfect. Another example of how a two second search on stackoverflow avoids another read of the gcc man page! – Sabrasabre