title: how to avoid objcopy blowing up the file?
body: <p>I use <code>objcopy</code> to extract/replace some section is an ELF file on a windows system.</p>
  
  <pre><code>&gt;objcopy.exe -V
  GNU objcopy 2.17.50 20060824
  Copyright 2005 Free Software Foundation, Inc.
  This program is free software; you may redistribute it under the terms of
  the GNU General Public License.  This program has absolutely no warranty.
  </code></pre>
  
  <p>This works in general.</p>
  
  <p>But my elf file contains debug information which I need to remove before delivery to decrese the filesize.</p>
  
  <p>I found tht option <code>-g</code> or <code>--strip-debug</code> should do what I want:</p>
  
  <pre><code>&gt;"objcopy.exe" --strip-debug -I elf32-big -O elf32-big with-debug.elf without-debug.elf
  </code></pre>
  
  <p>But it fails miserably. instead of making the file smaller it blows up the file size from ~20MB to 3GB before failing with:</p>
  
  <pre><code>objcopy.exe: without-debug.elf: File truncated
  objcopy.exe: without-debug.elf: No space left on device
  </code></pre>
  
  <p>how do I corectly remove debug information from ELF using objcopy?</p>
  
  <hr>
  
  <p>Don't know if this is important but objcopy issues some warnings for most ot the sections in the ELF like this:</p>
  
  <pre><code>BFD: without-debug.elf: warning: allocated section `.sdata' not in segment
  </code></pre>