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

大憨熊 提交于 2019-12-20 09:55:46

问题


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?


回答1:


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.



来源:https://stackoverflow.com/questions/2434505/g-static-initialization-and-destruction-0int-int-what-is-it

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!