gpt4 book ai didi

c - Mcrt1.o和Scrt1.o有什么用?

转载 作者:IT王子 更新时间:2023-10-29 00:46:52 26 4
gpt4 key购买 nike

我坚持使用以下两个文件,即 Mcrt1.o 和 Scrt1.o。谁能帮忙告诉我这两个文件是做什么用的。如何使用它?以gcrt1.o为例,在编译时加上-pg选项进行性能测试时非常有用。谢谢

最佳答案

*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

关于c - Mcrt1.o和Scrt1.o有什么用?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16436035/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com