Question

It came up in another question: What are the programs and parts called by gcc (particularly when compiling C or C++) so that someone might engineer some scheme of intercepting and altering the flow for various custom coding purposes?

Was it helpful?

Solution

The compiler binaries are the "compiler driver" (i.e. gcc), and the compiler itself which also doubles as a preprocessor (cc1 or cc1plus). It also invokes the assembler (as), and the linker (ld). Additionally there's a tool called collect2 that assists during the link process in some cases.

If you want to see what the intermediate states and invocations are then do this:

gcc -save-temps -v .....

If you want to see the compiler's optimization passes, then use these options:

gcc -fdump-tree-all -fdump-rtl-all ....

This produces (vaguely) human readable dumps of the internal state for debugging purposes. It's nothing you could save and reload into the compiler later, that's for sure, but it's helpful if you plan to modify the compiler's source, or write a GCC plugin.

OTHER TIPS

Observe exactly what programs are called:

gcc -v main.c

The exact steps are determined by a spec file with format: https://gcc.gnu.org/onlinedocs/gcc-4.8.1/gcc/Spec-Files.html

View the default (hard-coded in GCC):

gcc -dumpspecs

Run your own spec file after the default one:

gcc -specs=file
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top