What are GCC's passes and invoked programs?

假如想象 提交于 2019-12-07 11:07:20

问题


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?


回答1:


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.




回答2:


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


来源:https://stackoverflow.com/questions/9169380/what-are-gccs-passes-and-invoked-programs

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!