Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

g++ __static_initialization_and_destruction_0(int, int) - what is it

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 */

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?

like image 954
osgx Avatar asked Mar 12 '10 17:03

osgx


1 Answers

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.

like image 171
Xepo Avatar answered Nov 07 '22 18:11

Xepo