Good question.
My intuition was that it would go check /proc/cpuinfo
. Actually it depends on the architecture it has been compiled to run on. It seems like host_detect_local_cpu
is the function responsible for that. Its job is to replace -march=native
by either the good -march=<...>
or a set of flags (-mmmx
, -mno-avx
, etc) that match as closely as possible the current cpu. Examples for i386
and arm
. i386
uses cpuid
directly to check for each and every possible feature. arm
checks in /proc/cpuinfo
for the CPU part
line and has a table that maps from a CPU part value to a generation of the architecture and use this directly in -march=<...>
.
Just for fun I check on other architectures (I am not familiar with them).
- solaris on
sparc
: uses the kstat
interface
- linux on
sparc
: uses /proc/cpuinfo
alpha
: uses the implver
instruction
- darwin on
rs6000
: uses the hw.cpusubtype
system call
- freebsd on
rs6000
: uses hardcoded powerpc
- linux on
rs6000
: checks in /proc/self/auxv
for the platform value in the elf interpreter of its own process
- aix on
rs6000
: uses _system_configuration
(apparently a global structure)