title: How to debug static initialization problems?
body: <p>I'm having a hard time debugging this issue: <a href="https://github.com/cnjinhao/nana/issues/445" rel="nofollow noreferrer">https://github.com/cnjinhao/nana/issues/445</a></p>
  
  <p>I have <a href="https://stackoverflow.com/questions/56628469/is-lto-allowed-to-remove-unused-global-object-if-there-is-code-in-a-different-tr">previously asked about LTO vs static object initialization</a> and edited the library's code to implement Meyer's singletons so that the correct order of initialization happens. Hello worlds still crash, although library's functions have mostly dissappeared from stack traces:</p>
  
  <pre class="lang-cpp prettyprint-override"><code>#include &lt;nana/paint/graphics.hpp&gt;
  int main()
  {
      nana::paint::font f;
  }
  </code></pre>
  
  <pre><code>Thread 1 received signal SIGSEGV, Segmentation fault.
  (gdb) bt
  #0  0x00000000004985cf in std::type_info::operator==(std::type_info const&amp;) const ()
  #1  0x0000000000455180 in __cxxabiv1::__vmi_class_type_info::__do_dyncast(long long, __cxxabiv1::__class_type_info::__sub_kind, __cxxabiv1::__class_type_info const*, void const*, __cxxabiv1::__class_type_info const*, void const*, __cxxabiv1::__class_type_info::__dyncast_result&amp;) const ()
  #2  0x00000000004eae07 in __dynamic_cast ()
  #3  0x00000000004e6625 in bool std::has_facet&lt;std::ctype&lt;char&gt; &gt;(std::locale const&amp;) ()
  #4  0x00000000004e1f74 in std::basic_ios&lt;char, std::char_traits&lt;char&gt; &gt;::_M_cache_locale(std::locale const&amp;) ()
  #5  0x00000000004e20c0 in std::basic_ios&lt;char, std::char_traits&lt;char&gt; &gt;::init(std::basic_streambuf&lt;char, std::char_traits&lt;char&gt; &gt;*) ()
  #6  0x00000000004dfe2b in std::ios_base::Init::Init() ()
  #7  0x0000000000431f2f in __static_initialization_and_destruction_0(int, int) [clone .lto_priv.4] ()
  #8  0x0000000000431f59 in _GLOBAL__sub_I__ZN4nana6detail18drawable_impl_typeC2Ev ()
  #9  0x00000000004398c9 in global constructors keyed to 65535_0_objects.a_0x8e.19316 ()
  #10 0x00000000004432b3 in __do_global_ctors ()
      at E:/GitHub/MINGW-packages/mingw-w64-crt-git/src/mingw-w64/mingw-w64-crt/crt/gccmain.c:67
  #11 0x00000000004432fb in __main ()
      at E:/GitHub/MINGW-packages/mingw-w64-crt-git/src/mingw-w64/mingw-w64-crt/crt/gccmain.c:83
  #12 0x000000000040131c in __tmainCRTStartup ()
      at E:/GitHub/MINGW-packages/mingw-w64-crt-git/src/mingw-w64/mingw-w64-crt/crt/crtexe.c:329
  #13 0x00000000004014c9 in mainCRTStartup ()
      at E:/GitHub/MINGW-packages/mingw-w64-crt-git/src/mingw-w64/mingw-w64-crt/crt/crtexe.c:223
  </code></pre>
  
  <p>Compiling with <code>-O0 -g -fno-omit-frame-pointer -fno-inline -D_FORTIFY_SOURCE=2 -D_GLIBCXX_ASSERTIONS -fasynchronous-unwind-tables -fstack-clash-protection</code> have resulted in somewhat longer stack traces, but still nothing to search for.</p>
  
  <p>Even if I stuff the library with unbuffered debug prints nothing appears on the screen - the programs seems to crash before even first global object is constructed. I have used <code>strace</code> (from Git Bash) and verified that the executable loads all correct shared libraries.</p>
  
  <p>I'm looking for anything that could help me debug the issue. Unfortunately this is a Windows-only crash so running this with uftrace or sanitizers is not possible. Using GCC 8.3.1.</p>