After compiling of c++ file (with global static object) I get in nm
output this function:
00000000 t _Z41__static_initialization_and_destruction_0i
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.