C++ g++ __static_initialization_and_destruction_0(int, int) - 它是什么
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/2434505/
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
g++ __static_initialization_and_destruction_0(int, int) - what is it
提问by osgx
After compiling of c++ file (with global static object) I get in nm
output this function:
编译 c++ 文件(带有全局静态对象)后,我得到了nm
这个函数的输出:
00000000 t _Z41__static_initialization_and_destruction_0ii
__static_initialization_and_destruction_0(int, int) /* after c++filt */
What is it? It will call __cxa_atexit()
它是什么?它会调用__cxa_atexit()
Can I disable generation of this function (and calling a __cxa_atexit()
) and put all constructor and destructor calls to .ctors
and .dtors
sections?
我可以禁用此函数的生成(并调用 a __cxa_atexit()
)并将所有构造函数和析构函数调用放到.ctors
和.dtors
部分吗?
采纳答案by Xepo
This doc file seems to tell ya all you'd wanna know about those functions: http://www.nsnam.org/docs/linker-problems.doc
这个文档文件似乎告诉你所有你想知道的关于这些功能的信息:http: //www.nsnam.org/docs/linker-problems.doc
From what I can grok, gcc creates a __static_initialization_and_destruction_0
for every translation unit that needs static constructors to be called. Then it places __do_global_ctors_aux
into the .ctors
section, which then calls __static_initialization_and_destruction_0
on each translation unit.
据我所知,gcc__static_initialization_and_destruction_0
为每个需要调用静态构造函数的翻译单元创建了一个。然后它__do_global_ctors_aux
放入.ctors
部分,然后调用__static_initialization_and_destruction_0
每个翻译单元。
The issue seems to be a lot more complex than that though; gcc has to deal with individual object files in an archive, and I think this is how they keep the linker from optimizing out those calls.
不过,这个问题似乎要复杂得多;gcc 必须处理存档中的单个目标文件,我认为这就是它们防止链接器优化这些调用的方式。