title: GCC Linker : how to generate a report of per file contribution on output sections
body: <p>Recently I meet a problem when trying to link my program. It report <code>.text</code> can't fit in specified memory region. Obviously the source code grows too large to be linked in limited memory region.</p>
  
  <p>What I want to do now is to analyze which file contribute most significantly to the ".text" section so that follow up code optimization can be performed. I tried many ways but don't make it.</p>
  
  <ul>
  <li><code>nm -s output.elf</code> gives size of each symbol, but don't group the symbol under each source file.</li>
  <li><code>nm -s file.obj</code> go through every object file don't work because <code>-fdata-section</code> <code>-ffunction-section</code> <code>-Wl</code> are specified, so not all content in an object file will get linked to final output</li>
  <li><code>readelf -s output.elf</code> gives information from file to file, but it simply list symbols under each file and their size. A script can be written to sum all the size under a file, but the total value seems wrong, an obvious error here is some symbols may point to the same memory location, so the same memory region may be calculated many times.</li>
  </ul>
  
  <p>When gcc link do its work, it should know all the details of what is extracted from a object file and put to the output section, but seems it don't provide a switch to generate a detail report (Or am I missing something?) </p>
  
  <p>Is there any tool which can do this job?</p>