简体   繁体   English

分析结果中的 _init 是什么

[英]What is _init in profiling result

I've seen a strange function (_init) in my profile results :我在我的个人资料结果中看到了一个奇怪的函数 (_init):

在此处输入图片说明

In the parent function there is a uint64_t initialization and some math operations (sum, multiply, ...).在父函数中有一个uint64_t初始化和一些数学运算(求和、乘法等)。

What is this _init function?这个_init函数是什么? Is it related to that uint64_t init?它与那个uint64_t init有关吗?

Edit: I am using gcc version 8.3.0编辑:我使用的是gcc version 8.3.0

_init is a function that gets called when a shared library is loaded. _init是一个在加载共享库时调用的函数。 In our example, it will depend on what library you are linking against (running ldd against the binary should give you some hints).在我们的示例中,这将取决于您链接的库(对二进制文件运行ldd应该会给您一些提示)。

As a side-note, the _init and _fini functions are obsolete now and should be replaced by __attribute__ ((constructor)) and __attribute__ ((destructor)) .作为旁注, _init_fini函数现在已经过时,应该由__attribute__ ((constructor))__attribute__ ((destructor))代替。 To quote from thedocumentation 5.2.1 :引用文档 5.2.1

5.2.1. 5.2.1. Special functions _init and _fini (OBSOLETE/DANGEROUS)特殊函数 _init 和 _fini(过时/危险)

Historically there have been two special functions, _init and _fini that can be used to control constructors and destructors.历史上有两个特殊函数 _init 和 _fini 可用于控制构造函数和析构函数。 However, they are obsolete, and their use can lead to unpredicatable results.但是,它们已经过时,使用它们会导致不可预测的结果。 Your libraries should not use these;你的图书馆不应该使用这些; use the function attributes constructor and destructor above instead.改用上面的函数属性构造函数和析构函数。

If you must work with old systems or code that used _init or _fini, here's how they worked.如果您必须使用使用 _init 或 _fini 的旧系统或代码,以下是它们的工作方式。 Two special functions were defined for initializing and finalizing a module: _init and _fini.为初始化和结束模块定义了两个特殊函数:_init 和 _fini。 If a function ``_init'' is exported in a library, then it is called when the library is first opened (via dlopen() or simply as a shared library).如果函数 ``_init'' 被导出到库中,那么它会在库第一次打开时被调用(通过 dlopen() 或简单地作为共享库)。 In a C program, this just means that you defined some function named _init.在 C 程序中,这仅意味着您定义了一些名为 _init 的函数。 There is a corresponding function called _fini, which is called whenever a client finishes using the library (via a call dlclose() that brings its reference count to zero, or on normal exit of the program).有一个名为 _fini 的相应函数,每当客户端完成使用库时都会调用该函数(通过调用 dlclose() 使其引用计数为零,或者在程序正常退出时)。 The C prototypes for these functions are:这些函数的 C 原型是:

 void _init(void); void _fini(void);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM