title: g++, static initialization and -nostdlib
body: <p>Compiling / linking with <code>-nostdlib</code> seems to prevent static initialization, even if I add my own crti.s and crtn.s with <code>.init</code>/<code>.fini</code> sections.</p>
  
  <p>Are there workarounds to make g++ generate static initialization code that is inserted in <code>.init</code> or that I can call manually?</p>
  
  <p>This is what I tried:</p>
  
  <pre><code>g++ -o test.o -c -fno-use-cxa-atexit test.cc  # has _start (entry point) 
                                                #   that calls _init and _main
  as -o crti.o crti.s      # has _init in section .init
  as -o crtn.o crtn.s
  g++ -o test ./crti.o test.o -nodefaultlibs -nostartfiles ./crtn.o
  </code></pre>
  
  <p><code>-nodefaultlibs</code> alone includes static initialization code and call, but forces use of libc-_start/_init.</p>
  
  <p><code>-nodefaultlibs -nostartfiles</code> allows me to use my own _start / _init, but does not include code or call to static initialization.</p>