title: Correct usage of strip tool
body: <p>Unpacked <a href="https://releases.linaro.org/components/toolchain/binaries/" rel="nofollow noreferrer">Linaro GCC 6.2-2016.11</a> toolchain occupies almost 3.4 GB of disc space and I want to make it smaller. My target is <em>armv7-a+vfpv3+hard_float</em> so I have already removed things I do not need (like <code>ld.gold</code>, libraries for <code>Thumb</code>, <code>v8-a</code>, <code>v7ve</code> etc) but it still occupies almost 1 GB.</p>
  
  <p>So I want to use <a href="https://sourceware.org/binutils/docs/binutils/strip.html" rel="nofollow noreferrer"><code>strip</code></a> tool to remove redundant information from its binaries.</p>
  
  <p>My main question is <strong>how to use <em>strip</em> safety, correctly and efficiently in this case?</strong></p>
  
  <p>In general we have different binary files in toolchain to which we can apply <code>strip</code>: <code>*.exe</code>, <code>*.a</code>, <code>*.o</code>.</p>
  
  <p>As I can judge I can apply <code>strip -s</code> (remove all symbols) only to <code>*.exe</code> files (i.g. <em>arm-eabi-gcc.exe</em>). <strong>Am I right?</strong></p>
  
  <p><strong>Is it possible to apply <code>strip</code> to libraries (i.g. <em>libgcc.a</em>)?</strong>
  As I understood (see example above) symbols in libraries may be needed for further processing.</p>
  
  <p><strong>If yes, should I use <code>--strip-debug</code> instead (remove debugging symbols only)?</strong></p>
  
  <p>Example below illustrates these questions and reveals more.</p>
  
  <p>Assume that we have three files:</p>
  
  <pre><code>// main.c:
  #include "libgcc_test.h"
  int main(void)
  {
      do_something();
      return 0;
  }
  
  // libgcc_test.c:
  void do_something(void)
  {
      return;
  }
  
  // libgcc_test.h:
  void do_something(void);
  </code></pre>
  
  <p>In general we just compile each file separately to get object files which can be linked together:</p>
  
  <pre><code>$ ./arm-eabi-gcc.exe main.c -c
  $ ./arm-eabi-gcc.exe libgcc_test.c -c
  </code></pre>
  
  <p>By analyzing object files we can see that <em>do_something</em> symbol is defined in <em>libgcc_test.o</em> and undefined in <em>main.o</em>, as expected:</p>
  
  <pre><code>$ ./arm-eabi-nm.exe main.o
           U do_something
  00000000 T main
  
  $ ./arm-eabi-nm.exe libgcc_test.o
  00000000 T do_something
  </code></pre>
  
  <p>If we apply <code>strip -s</code> to both files or only to <em>main.o</em> and try to link them, it works:</p>
  
  <pre><code>$ ./arm-eabi-nm.exe main.o
  arm-eabi-nm.exe: main.o: no symbols
  $ ./arm-eabi-nm.exe libgcc_test.o
  arm-eabi-nm.exe: libgcc_test.o: no symbols
  $ ./arm-eabi-ld.exe libgcc_test.o main.o -o main
  arm-eabi-ld.exe: warning: cannot find entry symbol _start; defaulting to 00008000
  </code></pre>
  
  <p>But if we apply <code>strip -s</code> only to <em>libgcc_test.o</em>, linker produces error message:</p>
  
  <pre><code>$ ./arm-eabi-strip.exe -s libgcc_test.o
  $ ./arm-eabi-ld.exe libgcc_test.o main.o -o main
  arm-eabi-ld.exe: warning: cannot find entry symbol _start; defaulting to 00008000
  main.o: In function `main':
  main.c:(.text+0x8): undefined reference to `do_something' 
  </code></pre>
  
  <p>As I understand presence of unresolved symbol in an object file forces linker to resolve it. <strong>What happens if I remove this symbol from an object file before linking?</strong></p>
  
  <p><strong>Is it correct and safe to remove symbols from object files before linking them together? If yes, which symbols can be removed?</strong></p>
  
  <p>In real project if we apply <code>strip -s</code> to toolchain libraries (<em>libgcc.a</em>, <em>libc.a</em>, <em>libm.a</em>, <em>librdimon.a</em> etc) it similarly produces a lot of <code>"undefined reference to..."</code> messages during linking stage.</p>
  
  <p>But if we use <code>--strip-debug</code> option, linker produces messages for libraries like <code>skipping incompatible libgcc.a when searching for -lgcc</code>. If we revert libraries, it is linked successfuly.</p>
  
  <p><strong>What does <code>skipping incompatible...</code> message mean in this case?</strong></p>
  
  <p>Thank you for help.</p>