Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

gcc/g++ output type

Tags:

c++

c

gcc

I know this is a very basic question but when I compile my c/c++ code with gcc/g++ what exactly is the type of the intermediate output before assembler comes into play to generate the machine code ? Is it something like X86 instructions ?

like image 365
Cemre Mengü Avatar asked Feb 11 '12 20:02

Cemre Mengü


1 Answers

GCC's processing chain is as follows:

  • your source code

  • preprocessed source code (expand macros and includes, strip comments) (-E, .ii)

  • compile to assembly (-S, .s)

  • assemble to binary (-c, .o)

  • link to executable

At each stage I've listed the relevant compiler flags that make the process stop there, as well as the corresponding file suffix.

If you compile with -flto, then object files will be embellished with GIMPLE bytecode, which is a type of low-level intermediate format, the purpose of which is to delay the actual final compilation to the linking stage, which allows for link-time optimizations.

The "compiling" stage proper is the actual heavy lifting part. The preprocessor is essentially a separate, independent tool (although its behaviour is mandated by the C and C++ standards), and the assembler and linker are acutally separate, free-standing tools that basically just implement, respectively, the hardware's binary instruction format and the operating system's loadable executable format.

like image 51
Kerrek SB Avatar answered Nov 04 '22 01:11

Kerrek SB