[buildroot] $(STRIP) --strip-unneeded on a SHARED library...WHY?

Mike Frysinger vapier at gentoo.org
Tue Dec 6 18:21:40 UTC 2005


On Tue, Dec 06, 2005 at 09:20:01AM -0800, John Z. Bohach wrote:
> On Tuesday 06 December 2005 08:44, Paul Fox wrote:
> > we use --strip-unneeded too, and it's fine.  but it's fine for
> > runtime.  is it perhaps the case that libraries stripped like
> > that can no longer be used in development?
> 
> BINGO.  Executables that have been linked have addresses hardwired where the 
> symbols were.

no, that isnt how linking works

executables store a list of all needed external symbols and a list of
all needed libraries

for example:
$ echo 'int foo() { return 123; }' > libfoo.c
$ gcc -fPIC -shared -s libfoo.c -o libfoo.so
$ strip --strip-unneeded libfoo.so
$ readelf -s libfoo.so | grep foo
    16: 0000000000000678    11 FUNC    GLOBAL DEFAULT   10 foo

$ cat << EOF > striptest.c
#include <stdio.h>
extern int foo(void);
int main() { printf("%i\n", foo()); return 0; }
EOF
$ gcc striptest.c -L. -Wl,-rpath,. -lfoo -o striptest
$ readelf -a striptest | grep foo
 0x0000000000000001 (NEEDED)             Shared library: [libfoo.so]
     7: 0000000000000000    11 FUNC    GLOBAL DEFAULT  UND foo
$ ./striptest
123

seems to me it worked just fine
-mike



More information about the busybox mailing list