5
我堅持使用以下兩個文件,即Mcrt1.o和Scrt1.o。任何人都可以幫助讓我知道這兩個文件是什麼。如何使用它?以gcrt1.o爲例,在使用-pg選項編譯性能測試時,這非常有用。謝謝Mcrt1.o和Scrt1.o的用法是什麼?
我堅持使用以下兩個文件,即Mcrt1.o和Scrt1.o。任何人都可以幫助讓我知道這兩個文件是什麼。如何使用它?以gcrt1.o爲例,在使用-pg選項編譯性能測試時,這非常有用。謝謝Mcrt1.o和Scrt1.o的用法是什麼?
形式*crt*.o
的文件總是C運行時啓動代碼(大量的C運行時往往存在於庫中,啓動代碼是一個始終需要的對象文件)。
各種類型的描述可以發現here,下面複製,使答案自成體系。首先是一些定義:
Mini FAQ about the misc libc/gcc crt files.
Some definitions:
PIC - position independent code (-fPIC)
PIE - position independent executable (-fPIE -pie)
crt - C runtime
然後各種啓動目標文件:
crt0.o
Older style of the initial runtime code ? Usually not generated anymore
with Linux toolchains, but often found in bare metal toolchains. Serves
same purpose as crt1.o (see below).
crt1.o
Newer style of the initial runtime code. Contains the _start symbol which
sets up the env with argc/argv/libc _init/libc _fini before jumping to the
libc main. glibc calls this file 'start.S'.
crti.o
Defines the function prolog; _init in the .init section and _fini in the
.fini section. glibc calls this 'initfini.c'.
crtn.o
Defines the function epilog. glibc calls this 'initfini.c'.
Scrt1.o
Used in place of crt1.o when generating PIEs.
gcrt1.o
Used in place of crt1.o when generating code with profiling information.
Compile with -pg. Produces output suitable for the gprof util.
Mcrt1.o
Like gcrt1.o, but is used with the prof utility. glibc installs this as
a dummy file as it's useless on linux systems.
和其他一些人:
crtbegin.o
GCC uses this to find the start of the constructors.
crtbeginS.o
Used in place of crtbegin.o when generating shared objects/PIEs.
crtbeginT.o
Used in place of crtbegin.o when generating static executables.
crtend.o
GCC uses this to find the start of the destructors.
crtendS.o
Used in place of crtend.o when generating shared objects/PIEs.
最後,共同的連接順序:
General linking order:
crt1.o crti.o crtbegin.o [-L paths] [user objects] [gcc libs]
[C libs] [gcc libs] crtend.o crtn.o
我不不知道我們將使用Scrt1.oi不是crt1.o? – Daniel 2013-05-08 09:17:37