更新时间:2023-12-01 19:18:28
第一部分是版本和编译器驱动程序的配置数据(这是 gcc
二进制文件,它实际上不是编译器本身):
的规范配置:../configure --prefix = / usr
线程模型:posix
gcc版本3.3.1
然后打印它用来调用真实编译器的命令 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
GNU C版本3.3.1(i686-pc-linux-gnu)
由GNU C版本3.3.1(i686-pc-linux-gnu)编译
GGC启发式:--param ggc-min-expand = 51
--param ggc-min-heapsize = 40036
然后
忽略不存在的目录/ c> cc1
告诉你它将搜索包含文件的目录。 usr / i686 / include
#include...搜索从这里开始:
#include< ...>搜索从这里开始:
/ usr / local / include
/ usr / include
/usr/lib/gcc-lib/i686/3.3.1/include
/ usr / include
搜索列表结束。
编译器现已完成,所以 gcc
as -V -Qy -o /tmp/ccQynbTm.o / tmp / cceCee26 .s
汇编程序为
,给出它的版本信息。
使用BFD版本2.12的GNU汇编器版本2.12.90.0.1(i386-linux)
.90.0.1 20020307 Debian / GNU
Linux
汇编器现在完成了如此操作 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
链接器不提供详细的输出(尝试 -Wl,-v
),所以就是这样。
crt文件的含义是C RunTime。它们是在程序开始时插入的一小段代码,并在最后。他们负责初始化你的全局变量,堆和堆栈。从 main
返回后,它们调用 atexit
函数。还有一些。
希望有帮助。
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.o
and crtn.o
and lc
and lgcc
do? Any other explanatory links are also welcome.
$ 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
The first part is the version and configuration data for the compiler driver (that's the gcc
binary, which is not actually the compiler itself):
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
:
/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 cc1
prints it's version and config info.
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 cc1
tells you what directories it will search for include files.
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 gcc
tells you the assembler command it will use.
as -V -Qy -o /tmp/ccQynbTm.o /tmp/cceCee26.s
And the assembler, as
, gives its version info.
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 gcc
gives the linker command. It's using collect2
as an intermediary to the real linker ld
, but that's not important here.
/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.
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 atexit
functions after you return from main
. And some more besides.
Hope that helps.