g++ __static_initialization_and_destruction_0(int, int) - what is it
After compiling of c++ file (with global static object) I get in 开发者_JS百科nm
output this function:
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()
Can I disable generation of this function (and calling a __cxa_atexit()
) and put all constructor and destructor calls to .ctors
and .dtors
sections?
This doc file seems to tell ya all you'd wanna know about those functions: 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.
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.
精彩评论