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

后端 未结 1 1046
被撕碎了的回忆
被撕碎了的回忆 2021-02-01 21:19

After compiling of c++ file (with global static object) I get in nm output this function:

 00000000 t _Z41__static_initialization_and_destruction_0i         


        
1条回答
  •  夕颜
    夕颜 (楼主)
    2021-02-01 21:35

    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.

    0 讨论(0)
提交回复
热议问题