title: Why do program-level constructors get called by `__libc_csu_init` but destructors don't get called by `__libc_csu_fini`?
body: <p>Here's a simple program:</p>
  
  <pre class="lang-cpp prettyprint-override"><code>void __attribute__ ((constructor)) dumb_constructor(){}
  
  void __attribute__ ((destructor)) dumb_destructor(){}
  
  int main() {}
  </code></pre>
  
  <p>I compile it with the following flags:</p>
  
  <pre><code>g++ -O0 -fverbose-asm -no-pie -g -o main main.cpp 
  </code></pre>
  
  <p>I check with <code>gdb</code> that <code>__libc_csu_init</code> is calling the function I tagged w/ constructor:</p>
  
  <pre><code>Breakpoint 1, dumb_constructor () at main.cpp:1
  1   void __attribute__ ((constructor)) dumb_constructor(){}
  (gdb) bt
  #0  dumb_constructor () at main.cpp:1
  #1  0x000000000040116d in __libc_csu_init ()
  #2  0x00007ffff7abcfb0 in __libc_start_main () from /usr/lib/libc.so.6
  #3  0x000000000040104e in _start ()
  </code></pre>
  
  <p>and I assume that <code>destructor</code> attribute would mean <code>dumb_destructor()</code> would be called during <code>__libc_csu_fini</code>, but that's not happening:</p>
  
  <pre><code>Breakpoint 1, dumb_destructor () at main.cpp:3
  3   void __attribute__ ((destructor)) dumb_destructor(){}
  (gdb) bt
  #0  dumb_destructor () at main.cpp:3
  #1  0x00007ffff7fe242b in _dl_fini () from /lib64/ld-linux-x86-64.so.2
  #2  0x00007ffff7ad4537 in __run_exit_handlers () from /usr/lib/libc.so.6
  #3  0x00007ffff7ad46ee in exit () from /usr/lib/libc.so.6
  #4  0x00007ffff7abd02a in __libc_start_main () from /usr/lib/libc.so.6
  #5  0x000000000040104e in _start ()
  </code></pre>
  
  <p>I sanity checked that <code>__libc_csu_fini</code> really isn't doing anything with objdump and it really is a stub:</p>
  
  <pre><code>0000000000401190 &lt;__libc_csu_fini&gt;:
    401190:   f3 0f 1e fa             endbr64 
    401194:   c3                      ret    
  
  </code></pre>
  
  <p>Why do we call this <code>_dl_fini</code>? <em>What is <code>_dl_fini</code></em>? Why is it being inconsistent and not calling <code>__libc_csu_fini</code>?</p>