title: What sections make up the size of an executable?
body: <p>I'm running a little test while trying to understand a <a href="https://stackoverflow.com/questions/14366582/why-would-changing-a-structure-size-change-the-size-of-an-executable">larger problem</a>. Here's my test env:</p>
  
  <p><strong>head.h</strong>:</p>
  
  <pre><code>#define MAX_BUFSIZE 500
  
  typedef struct {
      int head;
      int tail;
      int status;
      int active;
      void * dev[MAX_BUFSIZE];
      char free[MAX_BUFSIZE];
      int count;
  } msg_fifo_t;
  
  extern msg_fifo_t TxBufx[];
  extern msg_fifo_t Rx_Buf[];
  </code></pre>
  
  <p><strong>test.c</strong>:</p>
  
  <pre><code>#include &lt;stdio.h&gt;
  #include "head.h"
  
  //msg_fifo_t TxBufx[10];  // This is the important line
  
  int main(int argc, char * argv[])
  {
      // This part isn't really important...
      printf("Hello Test\n");
  
      return 0;
   }
  </code></pre>
  
  <p>So I used these files and ran three tests to see what sizes I got - </p>
  
  <p>test #1 (code as is above):</p>
  
  <pre><code>&gt; gcc -Os test.c
  &gt; ls -al a.out
  -rwxrwxr-x 1 mike mike 7158 Jan 17 11:13 a.out
  &gt; size a.out
  text   data     bss     dec    hex   filename
  1170    256       8    1434    59a   a.out
  </code></pre>
  
  <p>test #2 (uncomment the "important" line):</p>
  
  <pre><code>&gt; gcc -Os test.c
  &gt; ls -al a.out
  -rwxrwxr-x 1 mike mike 7181 Jan 17 11:14 a.out
  &gt; size a.out
  text   data     bss     dec    hex   filename
  1170    256   25208   26634   680a   a.out
  </code></pre>
  
  <p>test #3 (uncomment the "important" line and change <code>TxBufx</code> size to 100)</p>
  
  <pre><code>&gt; gcc -Os test.c
  &gt; ls -al a.out
  -rwxrwxr-x 1 mike mike 7181 Jan 17 11:14 a.out
  &gt; size a.out
  text   data     bss     dec    hex   filename
  1170    256  252008  253434  3ddfa   a.out
  </code></pre>
  
  <p>So now my questions:</p>
  
  <ul>
  <li><p>It would appear that bss size has almost no bearing on the "size" of an executable (as reported from the <code>ls -al</code> command) - Can anyone explain to me why that is?</p></li>
  <li><p>Is that trait specific to the compiler/linker/or platform? </p></li>
  <li><p>Is there a better tool than <code>size</code> to understand what is happening here? (meaning what is really making up the 7181 bytes that is my executable?)</p></li>
  </ul>