Linux GCC 详细模式输出说明

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/13440549/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-06 17:49:17  来源:igfitidea点击:

GCC verbose mode output explanation

linuxgccverbose

提问by Gomathi

I'm new to linux. Can anyone explain to me the following verbose mode output for my hello world program? Also, what do the files crt1.o, crti.o, crtend.o, crtbegin.oand crtn.oand lcand lgccdo? Any other explanatory links are also welcome.

我是 linux 新手。谁能向我解释我的 hello world 程序的以下详细模式输出?另外,文件crt1.o, crti.o, crtend.o, crtbegin.oand crtn.oand lcand 有lgcc什么作用?也欢迎任何其他解释性链接。

$ gcc -v hello.c

Reading specs from /usr/lib/gcc-lib/i686/3.3.1/specs
Configured with: ../configure --prefix=/usr
Thread model: posix
gcc version 3.3.1
 /usr/lib/gcc-lib/i686/3.3.1/cc1 -quiet -v -D__GNUC__=3 
 -D__GNUC_MINOR__=3 -D__GNUC_PATCHLEVEL__=1 
 hello.c -quiet -dumpbase hello.c -auxbase hello -Wall
 -version -o /tmp/cceCee26.s
GNU C version 3.3.1 (i686-pc-linux-gnu)
 compiled by GNU C version 3.3.1 (i686-pc-linux-gnu)
GGC heuristics: --param ggc-min-expand=51 
 --param ggc-min-heapsize=40036
ignoring nonexistent directory "/usr/i686/include"
#include "..." search starts here:
#include <...> search starts here:
 /usr/local/include
 /usr/include
 /usr/lib/gcc-lib/i686/3.3.1/include
 /usr/include
End of search list.
 as -V -Qy -o /tmp/ccQynbTm.o /tmp/cceCee26.s
GNU assembler version 2.12.90.0.1 (i386-linux)
using BFD version 2.12.90.0.1 20020307 Debian/GNU
Linux
/usr/lib/gcc-lib/i686/3.3.1/collect2
 --eh-frame-hdr -m elf_i386 -dynamic-linker
 /lib/ld-linux.so.2 /usr/lib/crt1.o /usr/lib/crti.o
 /usr/lib/gcc-lib/i686/3.3.1/crtbegin.o
 -L/usr/lib/gcc-lib/i686/3.3.1
 -L/usr/lib/gcc-lib/i686/3.3.1/../../.. /tmp/ccQynbTm.o
 -lgcc -lgcc_eh -lc -lgcc -lgcc_eh
 /usr/lib/gcc-lib/i686/3.3.1/crtend.o
 /usr/lib/crtn.o

采纳答案by ams

The first part is the version and configuration data for the compiler driver (that's the gccbinary, which is not actually the compiler itself):

第一部分是编译器驱动程序的版本和配置数据(即gcc二进制文件,实际上不是编译器本身):

Reading specs from /usr/lib/gcc-lib/i686/3.3.1/specs
Configured with: ../configure --prefix=/usr
Thread model: posix
gcc version 3.3.1

Then it prints the command it uses to call the real compiler, cc1:

然后它打印用于调用真正编译器的命令cc1

 /usr/lib/gcc-lib/i686/3.3.1/cc1 -quiet -v -D__GNUC__=3 
 -D__GNUC_MINOR__=3 -D__GNUC_PATCHLEVEL__=1 
 hello.c -quiet -dumpbase hello.c -auxbase hello -Wall
 -version -o /tmp/cceCee26.s

And cc1prints it's version and config info.

cc1打印它的版本和配置信息。

GNU C version 3.3.1 (i686-pc-linux-gnu)
 compiled by GNU C version 3.3.1 (i686-pc-linux-gnu)
GGC heuristics: --param ggc-min-expand=51 
 --param ggc-min-heapsize=40036

Then cc1tells you what directories it will search for include files.

然后cc1告诉您它将搜索包含文件的目录。

ignoring nonexistent directory "/usr/i686/include"
#include "..." search starts here:
#include <...> search starts here:
 /usr/local/include
 /usr/include
 /usr/lib/gcc-lib/i686/3.3.1/include
 /usr/include
End of search list.

The compiler is now complete, so gcctells you the assembler command it will use.

编译器现已完成,因此会gcc告诉您它将使用的汇编器命令。

 as -V -Qy -o /tmp/ccQynbTm.o /tmp/cceCee26.s

And the assembler, as, gives its version info.

汇编器,as,给出了它的版本信息。

GNU assembler version 2.12.90.0.1 (i386-linux)
using BFD version 2.12.90.0.1 20020307 Debian/GNU
Linux

The assembler is now done so gccgives the linker command. It's using collect2as an intermediary to the real linker ld, but that's not important here.

汇编器现已完成,因此gcc给出链接器命令。它collect2用作真正的链接器的中介ld,但这在这里并不重要。

/usr/lib/gcc-lib/i686/3.3.1/collect2
 --eh-frame-hdr -m elf_i386 -dynamic-linker
 /lib/ld-linux.so.2 /usr/lib/crt1.o /usr/lib/crti.o
 /usr/lib/gcc-lib/i686/3.3.1/crtbegin.o
 -L/usr/lib/gcc-lib/i686/3.3.1
 -L/usr/lib/gcc-lib/i686/3.3.1/../../.. /tmp/ccQynbTm.o
 -lgcc -lgcc_eh -lc -lgcc -lgcc_eh
 /usr/lib/gcc-lib/i686/3.3.1/crtend.o
 /usr/lib/crtn.o

The linker gives no verbose output (try -Wl,-v), so that's it.

链接器没有给出详细的输出( try -Wl,-v),就是这样。

The "crt" files mean "C RunTime". They are small sections of code inserted at the start of your program, and at the end. They take care of initialising your global variables, heap, and stack. They call atexitfunctions after you return from main. And some more besides.

“crt”文件的意思是“C RunTime”。它们是在程序开头和结尾插入的一小段代码。它们负责初始化全局变量、堆和堆栈。他们呼吁atexit函数你返回后main。还有一些。

Hope that helps.

希望有帮助。