g ++ __static_initialization_and_destruction_0(int,int) - 是什么 [英] g++ __static_initialization_and_destruction_0(int, int) - what is it
问题描述
编译c ++文件(使用全局静态对象)后,我在 nm
中输出此函数:
After compiling of c++ file (with global static object) I get in nm
output this function:
00000000 t _Z41__static_initialization_and_destruction_0ii
__static_initialization_and_destruction_0(int, int) /* after c++filt */
这是什么?它将调用 __ cxa_atexit()
我可以禁用此函数的生成> __ cxa_atexit()),并将所有构造函数和析构函数调用放置到 .ctors
和 .dtors
section
Can I disable generation of this function (and calling a __cxa_atexit()
) and put all constructor and destructor calls to .ctors
and .dtors
sections?
推荐答案
这个文件似乎告诉你所有你想知道的函数:http://www.nsnam.org/docs/linker-problems.doc
This doc file seems to tell ya all you'd wanna know about those functions: http://www.nsnam.org/docs/linker-problems.doc
从我可以grok,gcc为每个需要静态构造函数的翻译单元创建一个 __ static_initialization_and_destruction_0
。然后将 __ do_global_ctors_aux
放入 .ctors
部分,然后调用 __ static_initialization_and_destruction_0
每个翻译单位。
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必须处理归档中的各个目标文件,我认为这是他们如何防止链接器优化这些调用。
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.
这篇关于g ++ __static_initialization_and_destruction_0(int,int) - 是什么的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!