0
votes

my question could be bit dummy, but i always had this question in my mind.

How does the gcc at compile time determines for which target machine/processor is it getting build-ed for ?

Are the instructions generated by gcc/g++ are target system independent ?

For example i have a x86_64 machine with intel based , AMD based , Motorola based system etc...

Do all the processors have the same instruction set and opcode associated with it ?

if not the machine-code/binary generated by gcc have some kind of a runtime check ?

Thanks in advance for the answer.

1

1 Answers

0
votes

This is a bit complicated. It depends on how GCC was configured and compiled during installation. On my Ubuntu 16.04 x64 system there is a GCC installation.

If in terminal I type gcc -v, I'll get --target=x86_64-linux-gnu, which means GCC will produce code for x64 Linux. --host=x86_64-linux-gnu means GCC itself is x64 linux application. More of this at the link.

Another useful output to look at is --with-multilib-list=m32,m64,mx32 - it means I could compile for default 64bit application together with two types of 32bit applications (-m32 and -mx32).

Last but not least is --with-tune=generic, which means apps will be compiled for some generic x64 platform and user should be able to run them anywhere on x64 Linux box.

THere are two options to override - -march and -mtune. Arch option will tell compiler to use intruction specific for a given CPU. Tune will tune the code generation to fit best given CPU. CPU is either specific platform (like, say, sandybridge), generic platform (usually a default) or native, where GCC during compilation will check the host CPU and perform code generation/tuning for it.

Last set of option covers the setting for FPU - you could select which unit to use (x87 or SSE2+), instruction set (SSE2, 3, 4, AVX) etc. MOre into the this link.