title: How to debug GCC/LD linking process for STL/C++
body: <p>I'm working on a bare-metal cortex-M3 in C++ for fun and profit. I use the STL library as I needed some containers. I thought that by simply providing my allocator it wouldn't add much code to the final binary, since you get only what you use.</p>
  
  <p>I actually didn't even expect any linking process at all with the STL
  (giving my allocator), as I thought it was all template code.</p>
  
  <p>I am compiling with <code>-fno-exception</code> by the way.</p>
  
  <p>Unfortunately, about 600KB or more are added to my binary. I looked up what symbols are included in the final binary with nm and it seemed a joke to me. The list is so long I won't try and past it. Although there are some weak symbols.</p>
  
  <p>I also looked in the .map file generated by the linker and I even found the scanf symbols</p>
  
  <pre><code>.text
  0x000158bc       0x30   /CodeSourcery/Sourcery_CodeBench_Lite_for_ARM_GNU_Linux/bin/../arm-none-linux-gnueabi/libc/usr/lib/libc.a(sscanf.o)
  0x000158bc                __sscanf
  0x000158bc                sscanf
  0x000158bc                _IO_sscanf
  </code></pre>
  
  <p>And:</p>
  
  <pre><code>$ arm-none-linux-gnueabi-nm binary | grep scanf
  000158bc T _IO_sscanf
  0003e5f4 T _IO_vfscanf
  0003e5f4 T _IO_vfscanf_internal
  000164a8 T _IO_vsscanf
  00046814 T ___vfscanf
  000158bc T __sscanf
  00046814 T __vfscanf
  000164a8 W __vsscanf
  000158bc T sscanf
  00046814 W vfscanf
  000164a8 W vsscanf
  </code></pre>
  
  <p>How can I debug this? For first I wanted to understand what exactly GCC is using for linking (I'm linking through GCC). I know that if symbol is found in a text segment, the
  whole segment is used, but still that's too much.</p>
  
  <p>Any suggestion on how to tackle this would really be appreciated.</p>
  
  <p>Thanks</p>